示例#1
0
        public void Test_GetByteCount()
        {
            var ansel = new AnselEncoding();

            char[] chars = null;
            Assert.Throws(typeof(ArgumentNullException), () => { ansel.GetByteCount(chars, 0, 0); });
            chars = new char[] { ' ' };
            Assert.Throws(typeof(ArgumentOutOfRangeException), () => { ansel.GetByteCount(chars, -1, 0); });
            Assert.Throws(typeof(ArgumentOutOfRangeException), () => { ansel.GetByteCount(chars, 0, -1); });

            string s = null;

            Assert.Throws(typeof(ArgumentNullException), () => { ansel.GetByteCount(s); });
        }
示例#2
0
        public void Test_GetString()
        {
            var ansel = new AnselEncoding();

            char[] chars = null;
            Assert.Throws(typeof(ArgumentNullException), () => { ansel.GetByteCount(chars, 0, 0); });

            string s = null;

            Assert.Throws(typeof(ArgumentNullException), () => { ansel.GetByteCount(s); });

            byte[] bytes = null;

            Assert.Throws(typeof(ArgumentNullException), () => { ansel.GetString(null, 0, 0); });
            bytes = Encoding.GetEncoding(437).GetBytes("test");
            Assert.Throws(typeof(ArgumentOutOfRangeException), () => { ansel.GetString(bytes, -1, 0); });
            Assert.Throws(typeof(ArgumentOutOfRangeException), () => { ansel.GetString(bytes, 0, -1); });
            var res1 = ansel.GetString(bytes, 0, 0);

            Assert.AreEqual(string.Empty, res1);
            res1 = ansel.GetString(bytes, 0, bytes.Length);
            Assert.AreEqual("test", res1);
        }