Esempio n. 1
0
		// bug #75065 and #73086.
		public void GetCharsFEFF ()
		{
			byte [] data = new byte [] {0xEF, 0xBB, 0xBF};
			Encoding enc = new UnixEncoding ();
			string s = enc.GetString (data);
			Assert.AreEqual (s, "\uFEFF");

			Encoding utf = enc;
			char[] testChars = {'\uFEFF','A'};

			byte[] bytes = utf.GetBytes(testChars);
			char[] chars = utf.GetChars(bytes);
			Assert.AreEqual ('\uFEFF', chars [0], "#1");
			Assert.AreEqual ('A', chars [1], "#2");
		}
Esempio n. 2
0
		public void TestThrowOnInvalid ()
		{
			UnixEncoding u = new UnixEncoding ();

			byte[] data = new byte [] { 0xC0, 0xAF };
			string s = u.GetString (data);
			Assert.AreEqual (4, s.Length);
			Assert.AreEqual (0x0000, (int) s [0]);
			Assert.AreEqual (0xC0,   (int) s [1]);
			Assert.AreEqual (0x0000, (int) s [2]);
			Assert.AreEqual (0xAF,   (int) s [3]);
			Assert.AreEqual ("\u0000\xC0\u0000\xAF", s, "Output-TestThrowOnInvalid");
			Assert.AreEqual (BitConverter.ToString (data), BitConverter.ToString (unix.GetBytes (s)), "Reconverted-TestThrowOnInvalid");

			data = new byte [] { 0x30, 0x31, 0xC0, 0xAF, 0x30, 0x32 };
			s = u.GetString (data);
			Assert.AreEqual (8, s.Length);
			Assert.AreEqual (0x30,   (int) s [0]);
			Assert.AreEqual (0x31,   (int) s [1]);
			Assert.AreEqual (0x0000, (int) s [2]);
			Assert.AreEqual (0xC0,   (int) s [3]);
			Assert.AreEqual (0x0000, (int) s [4]);
			Assert.AreEqual (0xAF,   (int) s [5]);
			Assert.AreEqual (0x30,   (int) s [6]);
			Assert.AreEqual (0x32,   (int) s [7]);

			Assert.AreEqual ("\x30\x31\u0000\xC0\u0000\xAF\x30\x32", s, "Output-TestThrowOnInvalid2");
			Assert.AreEqual (BitConverter.ToString (data), BitConverter.ToString (unix.GetBytes (s)), "Reconverted-TestThrowOnInvalid2");
		}