Esempio n. 1
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");
        }
Esempio n. 2
0
        public void TestEmptyString()
        {
            byte[]   data = new byte [] {};
            Encoding enc  = new UnixEncoding();

            string s = enc.GetString(data);

            Assert.AreEqual(s, "", "#1");
            char[] chars = enc.GetChars(data);
            Assert.AreEqual(chars.Length, 0, "#2");

            byte[] b1 = enc.GetBytes("");
            Assert.AreEqual(b1.Length, 0, "#3");
            byte[] b2 = enc.GetBytes(new char[] {});
            Assert.AreEqual(b2.Length, 0, "#3");
        }
Esempio n. 3
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. 4
0
        public void T1_Correct_GreekWord_kosme()
        {
            byte[] data = { 0xCE, 0xBA, 0xE1, 0xBD, 0xB9, 0xCF, 0x83, 0xCE, 0xBC, 0xCE, 0xB5 };
            string s    = unix.GetString(data);

            // cute but saving source code in unicode can be problematic
            // so we just ensure we can re-encode this
            Assert.AreEqual(BitConverter.ToString(data), BitConverter.ToString(unix.GetBytes(s)), "Reconverted");
        }