예제 #1
0
        public void Test_LARGE_BIG_EXT()
        {
            var enc1 = new byte[] { Constants.FORMAT_VERSION, Constants.LARGE_BIG_EXT,
                                    0, 0, 0, 1,
                                    0,
                                    1, };

            Assert.That(ETFCodec.Decode(enc1), Is.EqualTo(1));

            var enc2 = new byte[] { Constants.FORMAT_VERSION, Constants.LARGE_BIG_EXT,
                                    0, 0, 0, 8,
                                    0,
                                    255, 255, 255, 255,
                                    255, 255, 255, 255, };

            Assert.That(ETFCodec.Decode(enc2), Is.EqualTo(UInt64.MaxValue));

            var enc3 = new byte[] { Constants.FORMAT_VERSION, Constants.LARGE_BIG_EXT,
                                    0, 0, 0, 8,
                                    1,
                                    0, 0, 0, 0,
                                    0, 0, 0, 128, };

            Assert.That(ETFCodec.Decode(enc3), Is.EqualTo(Int64.MinValue));

            var enc4 = new byte[] { Constants.FORMAT_VERSION, Constants.LARGE_BIG_EXT,
                                    0, 0, 0, 8,
                                    1,
                                    1, 0, 0, 0,
                                    0, 0, 0, 128, };

            Assert.Throws <NotSupportedException> (() => { ETFCodec.Decode(enc4); });
        }
예제 #2
0
        public void TestFloat()
        {
            var inputs = new Dictionary <string, double> {
                { "     7.75000000000000000000e+00", 7.75 },
                { "    -7.75000000000000000000e+00", -7.75 },
                { "     8.00000000170000036009e-28", 0.00000000000000000000000000080000000017 },
                { "    -9.99999999999999929757e+44", -999999999999999999999999999999999999999999999.99 },
            };

            foreach (var entry in inputs)
            {
                var num = Encoding.ASCII.GetBytes(entry.Key);
                var enc = new byte[num.Length + 2];
                enc[0] = Constants.FORMAT_VERSION;
                enc[1] = Constants.FLOAT_EXT;
                Array.Copy(num, 0, enc, 2, num.Length);
                Assert.That(ETFCodec.Decode(enc), Is.EqualTo(entry.Value));
            }

            TestRoundtrip(new ArrayList()
            {
                1.234,
                1.234f,
                -4.567,
                -4.567f,
                Double.MinValue,
                Double.MaxValue,
                Double.Epsilon,
                Double.NaN,
                Double.NegativeInfinity,
                Double.PositiveInfinity,
            });
        }
예제 #3
0
        public void TestRoundtrip(object obj, Type expectType)
        {
            var encoded1  = ETFCodec.Encode(obj);
            var encoded2  = ETFCodec.Encode(obj);
            var reencoded = ETFCodec.Decode(encoded1);

            Assert.That(reencoded, Is.EqualTo(obj));

            // verify that decoding doesn't alter the encoded buffer
            Assert.That(encoded1, Is.EqualTo(encoded2));

            // verify that types remain what we expect
            if (expectType != null)
            {
                Assert.That(reencoded, Is.InstanceOf(expectType));
            }
        }
예제 #4
0
 public void TestEmptyList()
 {
     Assert.That(ETFCodec.Encode(new ArrayList()), Is.EqualTo(new byte[] { Constants.FORMAT_VERSION, Constants.NIL_EXT }));
 }
예제 #5
0
 public void TestBool()
 {
     Assert.Throws <NotSupportedException>(() => { ETFCodec.Encode(true); });
     Assert.Throws <NotSupportedException>(() => { ETFCodec.Encode(false); });
 }
예제 #6
0
 public void TestNull()
 {
     Assert.Throws <NotSupportedException>(() => { ETFCodec.Encode(null); });
 }
예제 #7
0
 object Roundtrip(object obj)
 {
     return(ETFCodec.Decode(ETFCodec.Encode(obj)));
 }
예제 #8
0
 public void TestString([Values("nonempty string", "unicode: ກ ຜ ໄ ໓", "")] string s)
 {
     Assert.That(Roundtrip(s), Is.EqualTo(ETFCodec.ToBytes(s)));
 }