Merge pull request #3913 from omwok/master
[mono.git] / mcs / class / corlib / Test / System.Text / ASCIIEncodingTest.cs
index 16fca588d1e4a395222bdd3c7e335fba2b898143..ea6380d0977fc398fd018736c7ce5ec3fa2a386d 100644 (file)
@@ -10,10 +10,6 @@ using System.Text;
 using NUnit.Framework;
 using NUnit.Framework.Constraints;
 
-#if !MOBILE
-using NUnit.Framework.SyntaxHelpers;
-#endif
-
 namespace MonoTests.System.Text
 {
        [TestFixture]
@@ -119,6 +115,40 @@ namespace MonoTests.System.Text
                                Assert.AreEqual (testchars [i], (char) bytes [i]);
                }
 
+               [Test] // Test GetBytes(string)
+               public void TestGetBytes7 ()
+               {
+                       var latin1_encoding = Encoding.GetEncoding ("latin1");
+
+                       var expected = new byte [] { 0x3F, 0x20, 0x3F, 0x20, 0x3F };
+                       var actual = latin1_encoding.GetBytes("\u24c8 \u2075 \u221e"); // normal replacement
+                       Assert.AreEqual (expected, actual, "#1");
+
+                       expected = new byte [] { 0x3F, 0x3F };
+                       actual = latin1_encoding.GetBytes("\ud83d\ude0a"); // surrogate pair replacement
+                       Assert.AreEqual (expected, actual, "#2");
+
+                       expected = new byte [] { 0x3F, 0x3F, 0x20 };
+                       actual = latin1_encoding.GetBytes("\ud83d\ude0a "); // surrogate pair replacement
+                       Assert.AreEqual (expected, actual, "#3");
+
+                       expected = new byte [] { 0x20, 0x20, 0x3F, 0x3F, 0x20, 0x20 };
+                       actual = latin1_encoding.GetBytes("  \ud83d\ude0a  "); // surrogate pair replacement
+                       Assert.AreEqual (expected, actual, "#4");
+
+                       expected = new byte [] { 0x20, 0x20, 0x3F, 0x3F, 0x20, 0x20 };
+                       actual = latin1_encoding.GetBytes("  \ud834\udd1e  "); // surrogate pair replacement
+                       Assert.AreEqual (expected, actual, "#5");
+
+                       expected = new byte [] { 0x41, 0x42, 0x43, 0x00, 0x41, 0x42, 0x43 };
+                       actual = latin1_encoding.GetBytes("ABC\0ABC"); // embedded zero byte not replaced
+                       Assert.AreEqual (expected, actual, "#6");
+
+                       expected = new byte [] { 0x20, 0x20, 0x3F, 0x20, 0x20 };
+                       actual = latin1_encoding.GetBytes("  \ud834  "); // invalid surrogate pair replacement
+                       Assert.AreEqual (expected, actual, "#7");
+               }
+
                [Test] // Test GetChars(byte[])
                public void TestGetChars1 () 
                {
@@ -212,6 +242,15 @@ namespace MonoTests.System.Text
                        Assert.AreEqual (string.Empty, encoding.GetString (new byte [0], 0, 0), "#2");
                }
 
+               [Test]
+               [ExpectedException (typeof (EncoderFallbackException))]
+               public void EncoderFallback ()
+               {
+                       Encoding e = Encoding.ASCII.Clone () as Encoding;
+                       e.EncoderFallback = new EncoderExceptionFallback ();
+                       e.GetBytes ("\u24c8");
+               }
+
                [Test]
                [ExpectedException (typeof (DecoderFallbackException))]
                public void DecoderFallback ()