X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FTest%2FSystem.Text%2FASCIIEncodingTest.cs;h=f35a9d3883062cb04a0eaeeeff65f3ef43dc9116;hb=3fd54893bc792eee42164bfb605b418105a92f92;hp=16fca588d1e4a395222bdd3c7e335fba2b898143;hpb=aeb24275bce76a6fb32b7f9eb73fa0fa5746bcf2;p=mono.git diff --git a/mcs/class/corlib/Test/System.Text/ASCIIEncodingTest.cs b/mcs/class/corlib/Test/System.Text/ASCIIEncodingTest.cs index 16fca588d1e..f35a9d38830 100644 --- a/mcs/class/corlib/Test/System.Text/ASCIIEncodingTest.cs +++ b/mcs/class/corlib/Test/System.Text/ASCIIEncodingTest.cs @@ -119,6 +119,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 +246,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 ()