public void TestGetBytes2(CodePageTestInfo cpInfo) { Encoding test_encoding = Encoding.GetEncoding(cpInfo.CodePage); byte[] bytes = test_encoding.GetBytes(testchars, 1, 1); Assert.AreEqual(1, bytes.Length, "#1"); Assert.AreEqual(testchars [1], (char)bytes [0], "#2"); }
public void TestGetChars2(CodePageTestInfo cpInfo) { Encoding test_encoding = Encoding.GetEncoding(cpInfo.CodePage); char[] chars = test_encoding.GetChars(testbytes, 1, 1); Assert.AreEqual(1, chars.Length, "#1"); Assert.AreEqual(testbytes [1], (byte)chars [0], "#2"); }
public void TestGetBytes5(CodePageTestInfo cpInfo) { Encoding test_encoding = Encoding.GetEncoding(cpInfo.CodePage); byte[] bytes = new Byte[1]; int cnt = test_encoding.GetBytes("Test", 1, 1, bytes, 0); Assert.AreEqual('e', (char)bytes [0], "#1"); }
public void TestEncoder(CodePageTestInfo cpInfo) { Encoding test_encoding = Encoding.GetEncoding(cpInfo.CodePage); byte[] bytes = new Byte[1]; int cnt = test_encoding.GetEncoder().GetBytes(testchars, 1, 1, bytes, 0, false); Assert.AreEqual(1, cnt, "#1"); Assert.AreEqual(testchars [1], (char)bytes [0], "#2"); }
public void TestDecoder(CodePageTestInfo cpInfo) { Encoding test_encoding = Encoding.GetEncoding(cpInfo.CodePage); char[] chars = new char[1]; int cnt = test_encoding.GetDecoder().GetChars(testbytes, 1, 1, chars, 0); Assert.AreEqual(1, cnt, "#1"); Assert.AreEqual(testbytes [1], (byte)chars [0], "#2"); }
public void TestGetChars1(CodePageTestInfo cpInfo) { Encoding test_encoding = Encoding.GetEncoding(cpInfo.CodePage); char[] chars = test_encoding.GetChars(testbytes); for (int i = 0; i < testbytes.Length; i++) { Assert.AreEqual(testbytes[i], (byte)chars[i]); } }
public void TestGetBytes6(CodePageTestInfo cpInfo) { Encoding test_encoding = Encoding.GetEncoding(cpInfo.CodePage); byte[] bytes = test_encoding.GetBytes("Test"); for (int i = 0; i < testchars.Length; i++) { Assert.AreEqual(testchars [i], (char)bytes [i]); } }
public void TestGetBytes3(CodePageTestInfo cpInfo) { Encoding test_encoding = Encoding.GetEncoding(cpInfo.CodePage); testchars[2] = (char)0x100; byte[] bytes = test_encoding.GetBytes(testchars); Assert.AreEqual('T', (char)bytes [0], "#1"); Assert.AreEqual('e', (char)bytes [1], "#2"); Assert.AreEqual(cpInfo.FFReplacementChar, (char)bytes [2], "#3"); Assert.AreEqual('t', (char)bytes [3], "#4"); }
public void DecoderFallback2(CodePageTestInfo cpInfo) { var bytes = new byte[] { 0x30, 0xa0, 0x31, 0xa8 }; var enc = (Encoding)Encoding.GetEncoding(cpInfo.CodePage).Clone(); enc.DecoderFallback = new TestFallbackDecoder(); var chars = new char [7]; var ret = enc.GetChars(bytes, 0, bytes.Length, chars, 0); }
public void EncoderFallback(CodePageTestInfo cpInfo) { if (cpInfo.SkipEncoderFallbackTest) { Assert.Ignore("Codepage indicates this test should be skipped."); } Encoding e = Encoding.GetEncoding(cpInfo.CodePage).Clone() as Encoding; e.EncoderFallback = new EncoderExceptionFallback(); e.GetBytes("\u24c8"); }
public void TestGetBytes7(CodePageTestInfo cpInfo) { if (cpInfo.SkipGetBytes7Test) { Assert.Ignore("Codepage indicates this test should be skipped."); } var test_encoding = Encoding.GetEncoding(cpInfo.CodePage); var expected = new byte [] { 0x3F, 0x20, cpInfo.SuperscriptFiveReplacementChar, 0x20, cpInfo.InfinityReplacementChar }; if (cpInfo.SupplementChar.HasValue) { var expectedNew = new byte [expected.Length + 1]; expected.CopyTo(expectedNew, 0); expectedNew [expected.Length] = cpInfo.SupplementChar.Value; expected = expectedNew; } var actual = test_encoding.GetBytes("\u24c8 \u2075 \u221e"); // normal replacement Assert.AreEqual(expected, actual, "#1"); expected = new byte [] { 0x3F, 0x3F }; actual = test_encoding.GetBytes("\ud83d\ude0a"); // surrogate pair replacement Assert.AreEqual(expected, actual, "#2"); expected = new byte [] { 0x3F, 0x3F, 0x20 }; actual = test_encoding.GetBytes("\ud83d\ude0a "); // surrogate pair replacement Assert.AreEqual(expected, actual, "#3"); expected = new byte [] { 0x20, 0x20, 0x3F, 0x3F, 0x20, 0x20 }; actual = test_encoding.GetBytes(" \ud83d\ude0a "); // surrogate pair replacement Assert.AreEqual(expected, actual, "#4"); expected = new byte [] { 0x20, 0x20, 0x3F, 0x3F, 0x20, 0x20 }; actual = test_encoding.GetBytes(" \ud834\udd1e "); // surrogate pair replacement Assert.AreEqual(expected, actual, "#5"); expected = new byte [] { 0x41, 0x42, 0x43, 0x00, 0x41, 0x42, 0x43 }; actual = test_encoding.GetBytes("ABC\0ABC"); // embedded zero byte not replaced Assert.AreEqual(expected, actual, "#6"); expected = new byte [] { 0x20, 0x20, 0x3F, 0x20, 0x20 }; actual = test_encoding.GetBytes(" \ud834 "); // invalid surrogate pair replacement Assert.AreEqual(expected, actual, "#7"); }
public void DecoderFallback3(CodePageTestInfo cpInfo) { var bytes = new byte[] { 0x30, 0xa0, 0x31, 0xa8 }; var enc = (Encoding)Encoding.GetEncoding(cpInfo.CodePage).Clone(); enc.DecoderFallback = new TestFallbackDecoder(); var chars = new char[] { '9', '8', '7', '6', '5' }; var ret = enc.GetChars(bytes, 0, bytes.Length, chars, 0); Assert.That(ret, Is.EqualTo(cpInfo.CharsWritten ?? 4), "ret"); Assert.That(chars [0], Is.EqualTo('0'), "chars[0]"); Assert.That(chars [1], Is.EqualTo(cpInfo.A0Char), "chars[1]"); Assert.That(chars [2], Is.EqualTo((cpInfo).OneChar ?? '1'), "chars[2]"); Assert.That(chars [3], Is.EqualTo((char)cpInfo.A8Char), "chars[3]"); Assert.That(chars [4], Is.EqualTo('5'), "chars[4]"); }
public void IsBrowserSave(CodePageTestInfo cpInfo) { Assert.AreEqual(cpInfo.IsBrowserSave, Encoding.GetEncoding(cpInfo.CodePage).IsBrowserSave); }
public void IsBrowserDisplay(CodePageTestInfo cpInfo) { Assert.AreEqual(cpInfo.IsBrowserDisplay, Encoding.GetEncoding(cpInfo.CodePage).IsBrowserDisplay); }