public void Decode_And_Encode_Same_Encoding_UTF8() { const string value = "ABCDEFGHØþ"; var bytesUtf8 = Encoding.UTF8.GetBytes(value); var output = new byte[bytesUtf8.Length]; Stream after = new TranscodingStream(new MemoryStream(bytesUtf8), Encoding.UTF8, Encoding.UTF8); var count = after.Read(output, 0, 40); Assert.IsTrue(ByteArrayCompare(output, bytesUtf8)); }
public void Decode_And_Encode_Same_Encoding_UTF16() { string value = "ABCDEFGHØþ"; byte[] bytesUTF16 = Encoding.Unicode.GetBytes(value); byte[] output = new byte[bytesUTF16.Length]; Stream after = new TranscodingStream(new MemoryStream(bytesUTF16), Encoding.Unicode, Encoding.Unicode); int count = after.Read(output, 0, 40); Assert.IsTrue(ByteArrayCompare(output, bytesUTF16)); }
public void SourceStreamIsShorterThanDestinationStream() { const string value = "A"; var bytesUtf8 = Encoding.UTF8.GetBytes(value); var expected = new byte[100]; expected[0] = 0x41; var output = new byte[100]; Stream after = new TranscodingStream(new MemoryStream(bytesUtf8), Encoding.GetEncoding(1252), Encoding.UTF8); var count = after.Read(output, 0, 100); Assert.IsTrue(ByteArrayCompare(output, expected)); }
public void NoFullRead2() { const string value = "BAA"; var bytesUtf8 = Encoding.UTF8.GetBytes(value); var expected = new byte[] { 0x00, 0x42 }; var output = new byte[2]; Stream after = new TranscodingStream(new MemoryStream(bytesUtf8), Encoding.UTF8, Encoding.UTF8); var count = after.Read(output, 1, 1); Assert.IsTrue(ByteArrayCompare(output, expected)); }
public void EmptyWrite() { const string value = ""; var bytesUtf8 = Encoding.UTF8.GetBytes(value); var expected = new byte[] { 0x41}; var output = new byte[9]; Stream after = new TranscodingStream(new MemoryStream(bytesUtf8), Encoding.GetEncoding(1252), Encoding.UTF8); var count = after.Read(output, 0, 1); Assert.AreEqual(0, after.Read(output, 0, 1)); }
public void NoFullRead() { string value = "AAA"; byte[] bytesUTF8 = Encoding.UTF8.GetBytes(value); byte[] expected = new byte[] { 0x41, 0x41}; byte[] output = new byte[2]; Stream after = new TranscodingStream(new MemoryStream(bytesUTF8), Encoding.UTF8, Encoding.UTF8); int count = after.Read(output, 0, 2); Assert.IsTrue(ByteArrayCompare(output, expected)); }