public virtual void TestShouldEncodeAndDecodeISO8859_1Text() { EncodedText encodedText = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, TEST_STRING); Assert.AreEqual(EncodedText.CHARSET_ISO_8859_1, encodedText.GetCharacterSet()); Assert.AreEqual(TEST_STRING, encodedText.ToString()); EncodedText encodedText2; byte[] bytes; // no bom & no terminator bytes = encodedText.ToBytes(); Assert.AreEqual(TEST_STRING_HEX_ISO8859_1, TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, bytes); Assert.AreEqual(encodedText, encodedText2); // bom & no terminator bytes = encodedText.ToBytes(true); Assert.AreEqual(TEST_STRING_HEX_ISO8859_1, TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, bytes); Assert.AreEqual(encodedText, encodedText2); // no bom & terminator bytes = encodedText.ToBytes(false, true); Assert.AreEqual(TEST_STRING_HEX_ISO8859_1 + " 00", TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, bytes); Assert.AreEqual(encodedText, encodedText2); // bom & terminator bytes = encodedText.ToBytes(true, true); Assert.AreEqual(TEST_STRING_HEX_ISO8859_1 + " 00", TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, bytes); Assert.AreEqual(encodedText, encodedText2); }
public virtual void TestShouldEncodeAndDecodeUTF16BEText() { EncodedText encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16BE, UNICODE_TEST_STRING); Assert.AreEqual(EncodedText.CHARSET_UTF_16BE, encodedText.GetCharacterSet()); Assert.AreEqual(UNICODE_TEST_STRING, encodedText.ToString()); byte[] bytes; EncodedText encodedText2; // no bom & no terminator bytes = encodedText.ToBytes(); Assert.AreEqual(UNICODE_TEST_STRING_HEX_UTF16BE, TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16BE, bytes); Assert.AreEqual(encodedText, encodedText2); // bom & no terminator bytes = encodedText.ToBytes(true); Assert.AreEqual("fe ff " + UNICODE_TEST_STRING_HEX_UTF16BE, TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16BE, bytes); Assert.AreEqual(encodedText, encodedText2); // no bom & terminator bytes = encodedText.ToBytes(false, true); Assert.AreEqual(UNICODE_TEST_STRING_HEX_UTF16BE + " 00 00", TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16BE, bytes); Assert.AreEqual(encodedText, encodedText2); // bom & terminator bytes = encodedText.ToBytes(true, true); Assert.AreEqual("fe ff " + UNICODE_TEST_STRING_HEX_UTF16BE + " 00 00", TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16BE, bytes); Assert.AreEqual(encodedText, encodedText2); }
public virtual void TestShouldStillReturnBytesWhenUnicodeStringIsEmpty() { EncodedText encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16, string.Empty); Assert.IsTrue(Arrays.Equals(new byte[] { }, encodedText.ToBytes(false, false))); Assert.IsTrue(Arrays.Equals(new byte[] { unchecked((byte)unchecked((int)(0xff))), unchecked((byte)unchecked((int)(0xfe))) }, encodedText.ToBytes(true, false))); Assert.IsTrue(Arrays.Equals(new byte[] { 0, 0 }, encodedText.ToBytes(false, true))); Assert.IsTrue(Arrays.Equals(new byte[] { unchecked((byte)unchecked((int)(0xff))), unchecked((byte)unchecked((int)(0xfe))), 0, 0 }, encodedText.ToBytes(true, true))); }
public virtual void TestShouldTranscodeFromOneEncodingToAnother() { EncodedText encodedText; encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_8, TestHelper.HexStringToBytes("43 61 66 c3 a9 20 50 61 72 61 64 69 73 6f")); encodedText.SetTextEncoding(EncodedText.TEXT_ENCODING_ISO_8859_1, true); Assert.AreEqual("43 61 66 e9 20 50 61 72 61 64 69 73 6f", TestHelper.BytesToHexString(encodedText.ToBytes())); encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_8, TestHelper.HexStringToBytes("43 61 66 c3 a9 20 50 61 72 61 64 69 73 6f")); encodedText.SetTextEncoding(EncodedText.TEXT_ENCODING_UTF_8, true); Assert.AreEqual("43 61 66 c3 a9 20 50 61 72 61 64 69 73 6f", TestHelper.BytesToHexString(encodedText.ToBytes())); encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_8, TestHelper.HexStringToBytes("43 61 66 c3 a9 20 50 61 72 61 64 69 73 6f")); encodedText.SetTextEncoding(EncodedText.TEXT_ENCODING_UTF_16, true); Assert.AreEqual("43 00 61 00 66 00 e9 00 20 00 50 00 61 00 72 00 61 00 64 00 69 00 73 00 6f 00", TestHelper.BytesToHexString(encodedText.ToBytes())); encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_8, TestHelper.HexStringToBytes("43 61 66 c3 a9 20 50 61 72 61 64 69 73 6f")); encodedText.SetTextEncoding(EncodedText.TEXT_ENCODING_UTF_16BE, true); Assert.AreEqual("00 43 00 61 00 66 00 e9 00 20 00 50 00 61 00 72 00 61 00 64 00 69 00 73 00 6f", TestHelper.BytesToHexString(encodedText.ToBytes())); }
public virtual void TestShouldStillReturnBytesWhenStringIsEmpty() { EncodedText encodedText = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, string.Empty); Assert.IsTrue(Arrays.Equals(new byte[] { }, encodedText.ToBytes(false, false))); Assert.IsTrue(Arrays.Equals(new byte[] { }, encodedText.ToBytes(true, false))); Assert.IsTrue(Arrays.Equals(new byte[] { 0 }, encodedText.ToBytes(false, true))); Assert.IsTrue(Arrays.Equals(new byte[] { 0 }, encodedText.ToBytes(true, true))); }