예제 #1
0
        public void Encode_ISO88591()
        {
            var encoding = Encoding.GetEncoding("ISO-8859-1");
            var blist = new BList { new BString("æøå äö èéê ñ", encoding) };

            Assert.AreNotEqual("l12:æøå äö èéê ñe", blist.Encode());
            Assert.AreEqual("l12:æøå äö èéê ñe", blist.Encode(encoding));
            Assert.AreNotEqual(blist.Encode(), blist.Encode(encoding));
        }
예제 #2
0
        public void Encode_Complex()
        {
            var blist = new BList
            {
                "spam",
                666,
                new BList
                {
                    "foo",
                    "bar",
                    123,
                    new BDictionary
                    {
                        {"more spam", "more eggs"}
                    }
                },
                "foobar",
                new BDictionary
                {
                    {"numbers", new BList {1, 2, 3}}
                }

            };

            var expected = "l4:spami666el3:foo3:bari123ed9:more spam9:more eggsee6:foobard7:numbersli1ei2ei3eeee";
            var actual = blist.Encode();

            Assert.AreEqual(expected, actual);
        }
예제 #3
0
        public void Encode_Simple()
        {
            var blist = new BList {"hello world", 987, "foobar"};

            var expected = "l11:hello worldi987e6:foobare";
            var actual = blist.Encode();

            Assert.AreEqual(expected, actual);
        }
예제 #4
0
        private void TestBList(List <BObject> testList)
        {
            BList bList = new BList(testList);

            byte[] encoded = bList.Encode();

            Assert.True(BObject.TryParse(encoded, out BList bObject));
            Assert.True(bList.Equals(bObject));

            using (MemoryStream ms = new MemoryStream())
            {
                bList.Encode(ms);
                encoded = ms.ToArray();
            }

            Assert.True(BObject.TryParse(encoded, out bObject));
            Assert.True(bList.Equals(bObject));

            Assert.Equal(encoded.Length, bList.GetEncodedSize());
        }
예제 #5
0
        public void BList_TooDeep()
        {
            BList list  = new BList();
            BList child = new BList();

            list.Add(child);
            for (int i = 0; i < BObject.RecursionLimit; i++)
            {
                BList subChild = new BList();
                child.Add(subChild);
                child = subChild;
            }

            Assert.Throws <StackOverflowException>(() =>
            {
                list.Encode();
            });
        }
예제 #6
0
 public void Encode_UTF8()
 {
     var blist = new BList { "æøå äö èéê ñ" };
     Assert.AreEqual("l21:æøå äö èéê ñe", blist.Encode());
     Assert.AreEqual("l21:æøå äö èéê ñe", blist.Encode(Encoding.UTF8));
     Assert.AreEqual(blist.Encode(), blist.Encode(Encoding.UTF8));
 }
예제 #7
0
 public void Encode_EmptyList()
 {
     var blist = new BList();
     Assert.AreEqual("le", blist.Encode());
 }