public void Double_Short(double expected, byte[] bytes)
        {
            var data = new HessianDataBuilder().WriteBytes(bytes);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadDouble());
        }
        public void Int_ThreeOctet(int expected, byte[] bytes)
        {
            var data = new HessianDataBuilder().WriteBytes(bytes);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadInt());
        }
        public void Long_EightOctet(long expected, byte[] bytes)
        {
            var data = new HessianDataBuilder().WriteBytes(bytes);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadLong());
        }
Exemple #4
0
        public void BooleanFalse()
        {
            var data = new HessianDataBuilder()
                       .WriteChar('F');

            Assert.False((bool)new HessianInputV1(data.ToReader()).ReadObject());
            Assert.False(new HessianInputV1(data.ToReader()).ReadBool());
        }
Exemple #5
0
        public void Long300()
        {
            var data = new HessianDataBuilder()
                       .WriteChar('L').WriteBytes(0, 0, 0, 0, 0, 0, 0x01, 0x2C);

            Assert.AreEqual(300, new HessianInputV1(data.ToReader()).ReadObject());
            Assert.AreEqual(300, new HessianInputV1(data.ToReader()).ReadLong());
        }
Exemple #6
0
        public void Double12_25()
        {
            var data = new HessianDataBuilder()
                       .WriteChar('D').WriteBytes(0x40, 0x28, 0x80, 0, 0, 0, 0, 0);

            Assert.AreEqual(12.25, new HessianInputV1(data.ToReader()).ReadObject());
            Assert.AreEqual(12.25, new HessianInputV1(data.ToReader()).ReadDouble());
        }
        public void String_Short(string expected, byte[] bytes)
        {
            // can be up to 31 chars
            var data = new HessianDataBuilder().WriteBytes(bytes);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadString());
        }
        public void Double_One()
        {
            var expected = 1.0;

            var data = new HessianDataBuilder().WriteBytes(0x5c);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadDouble());
        }
        public void Double()
        {
            var expected = 10e50d;

            var data = new HessianDataBuilder()
                       .WriteChar('D').WriteBytes(0x4a, 0x85, 0x61, 0xd2, 0x76, 0xdd, 0xfd, 0xc0);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadDouble());
        }
        public void Double_Float()
        {
            var expected = 12.25d;

            var data = new HessianDataBuilder()
                       .WriteChar('D').WriteBytes(0x40, 0x28, 0x80, 0, 0, 0, 0, 0);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadDouble());
        }
        public void String_Long()
        {
            // can be up to 65535 chars
            var expected = string.Join("", Enumerable.Range(0, 65535).Select(i => (i % 10).ToString()));

            var data = new HessianDataBuilder()
                       .WriteChar('S').WriteBytes(0xff, 0xff).WriteUtf8(expected);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadString());
        }
Exemple #12
0
        public void Date()
        {
            // 9:51:31 May 8, 1998
            var data = new HessianDataBuilder()
                       .WriteChar('d').WriteBytes(0, 0, 0, 0xD0, 0x4B, 0x92, 0x84, 0xB8);

            var expected = new DateTime(1998, 5, 8, 9, 51, 31, DateTimeKind.Utc).ToLocalTime();

            Assert.AreEqual(expected, new HessianInputV1(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV1(data.ToReader()).ReadDate());
        }
        public void DateShort()
        {
            // short format should be used if no minute granularity is used

            // x4b x00 xe3 x83 x8f  # 09:51:00 May 8, 1998 UTC
            var data = new HessianDataBuilder()
                       .WriteBytes(0x4b).WriteBytes(0, 0xe3, 0x83, 0x8f);

            var expected = new DateTime(1998, 5, 8, 9, 51, 0, DateTimeKind.Utc).ToLocalTime();

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadDate());
        }
        public void String_Chunks()
        {
            // can be up to 65535 chars
            var chunk1   = string.Join("", Enumerable.Range(0, 65535).Select(i => (i % 10).ToString()));
            var chunk2   = string.Join("", Enumerable.Range(0, 65535).Select(i => (i % 10).ToString()));
            var chunk3   = string.Join("", Enumerable.Range(0, 1).Select(i => (i % 10).ToString()));
            var expected = chunk1 + chunk2 + chunk3;

            var data = new HessianDataBuilder()
                       .WriteBytes(0x52).WriteBytes(0xff, 0xff).WriteUtf8(chunk1)
                       .WriteBytes(0x52).WriteBytes(0xff, 0xff).WriteUtf8(chunk2)
                       .WriteBytes(0x01).WriteUtf8(chunk3);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadString());
        }
        public void List_Compact_Fixed_UsingTypeRef()
        {
            var first  = new int[] { 0, 1 };
            var second = new int[] { 2, 3, 4 };

            var data = new HessianDataBuilder()
                                                           // first list
                       .WriteBytes(0x72)                   // list tag
                       .WriteBytes(0x04).WriteUtf8("[int") // type
                       .WriteBytes(0x90)                   // int 0
                       .WriteBytes(0x91)                   // int 1
                                                           // second list
                       .WriteBytes(0x73)                   // list tag
                       .WriteBytes(0x90)                   // type ref 0 (above [int)
                       .WriteBytes(0x92)                   // int 2
                       .WriteBytes(0x93)                   // int 3
                       .WriteBytes(0x94);                  // int 4

            var input = new HessianInputV2(data.ToReader());

            CollectionAssert.AreEqual(
                first,
                (IEnumerable)input.ReadObject());

            CollectionAssert.AreEqual(
                second,
                (IEnumerable)input.ReadObject());
        }
        public void Binary_Medium()
        {
            // can be up to 1023 bytes
            var expected = Enumerable.Range(0, 1023).Select(i => (byte)i).ToArray();

            var data = new HessianDataBuilder()
                       .WriteBytes(0x37, 0xff).WriteBytes(expected);

            Assert.AreEqual(expected, new HessianInputV2(data.ToReader()).ReadObject());
        }
        public void Binary_Long()
        {
            // can be up to 1023 bytes
            var expected = Enumerable.Range(0, 65535).Select(i => (byte)i).ToArray();

            var data = new HessianDataBuilder()
                       .WriteChar('B').WriteBytes(0xff, 0xff).WriteBytes(expected);

            CollectionAssert.AreEqual(expected, (byte[])new HessianInputV2(data.ToReader()).ReadObject());
        }
Exemple #18
0
        public void Enum()
        {
            var expected = Color.GREEN;
            var data     = new HessianDataBuilder()
                           .WriteChar('M')
                           .WriteChar('t').WriteBytes(0, 0x0d).WriteUtf8("example.Color")
                           .WriteChar('S').WriteBytes(0, 0x04).WriteUtf8("name")
                           .WriteChar('S').WriteBytes(0, 0x05).WriteUtf8("GREEN")
                           .WriteChar('z');

            Assert.AreEqual(
                expected,
                new HessianInputV1(data.ToReader()).ReadObject());
        }
        public void List_Untyped_Variable()
        {
            var expected = new int[] { 0, 1 };

            var data = new HessianDataBuilder()
                       .WriteBytes(0x57) // list tag
                       .WriteBytes(0x90) // int 0
                       .WriteBytes(0x91) // int 1
                       .WriteChar('Z');  // end

            CollectionAssert.AreEqual(
                expected,
                (List <object>) new HessianInputV2(data.ToReader()).ReadObject());
        }
        public void List_Compact_Fixed()
        {
            var expected = new int[] { 0, 1 };

            var data = new HessianDataBuilder()
                       .WriteBytes(0x72)                   // list tag (length 2)
                       .WriteBytes(0x04).WriteUtf8("[int") // type
                       .WriteBytes(0x90)                   // int 0
                       .WriteBytes(0x91);                  // int 1

            CollectionAssert.AreEqual(
                expected,
                (int[])new HessianInputV2(data.ToReader(), TypeBindings.Java).ReadObject());
        }
        public void List_Compact_Untyped_Fixed()
        {
            var expected = new List <int> {
                0, 1
            };

            var data = new HessianDataBuilder()
                       .WriteBytes(0x7A)  // list tag (length 2)
                       .WriteBytes(0x90)  // int 0
                       .WriteBytes(0x91); // int 1

            CollectionAssert.AreEqual(
                expected,
                (List <int>) new HessianInputV2(data.ToReader()).ReadObject(typeof(List <int>)));
        }
        public void List_Variable()
        {
            var expected = new int[] { 0, 1 };

            var data = new HessianDataBuilder()
                       .WriteBytes(0x55)                   // list tag
                       .WriteBytes(0x04).WriteUtf8("[int") // type
                       .WriteBytes(0x90)                   // int 0
                       .WriteBytes(0x91)                   // int 1
                       .WriteChar('Z');                    // end

            CollectionAssert.AreEqual(
                expected,
                (List <int>) new HessianInputV2(data.ToReader()).ReadObject(typeof(List <int>)));
        }
        public void Binary_Chunks()
        {
            // can be up to 1023 bytes
            var chunk1   = Enumerable.Range(0, 65535).Select(i => (byte)i).ToArray();
            var chunk2   = Enumerable.Range(0, 65535).Select(i => (byte)i).ToArray();
            var chunk3   = Enumerable.Range(0, 1).Select(i => (byte)i).ToArray();
            var expected = chunk1.Concat(chunk2).Concat(chunk3).ToArray();

            var data = new HessianDataBuilder()
                       .WriteBytes(0x41).WriteBytes(0xff, 0xff).WriteBytes(chunk1)
                       .WriteBytes(0x41).WriteBytes(0xff, 0xff).WriteBytes(chunk2)
                       .WriteBytes(0x21).WriteBytes(chunk3);

            CollectionAssert.AreEqual(
                expected,
                (byte[])new HessianInputV2(data.ToReader()).ReadObject());
        }
        public void List_Fixed()
        {
            var expected = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };

            var data = new HessianDataBuilder()
                       .WriteChar('V')                     // list tag
                       .WriteBytes(0x04).WriteUtf8("[int") // type
                       .WriteBytes(0x98)                   // length 8 (must be longer than 7 to avoid compact)
                       .WriteBytes(0x90)                   // int 0
                       .WriteBytes(0x91)                   // int 1
                       .WriteBytes(0x92)                   // int 2
                       .WriteBytes(0x93)                   // int 3
                       .WriteBytes(0x94)                   // int 4
                       .WriteBytes(0x95)                   // int 5
                       .WriteBytes(0x96)                   // int 6
                       .WriteBytes(0x97);                  // int 7

            CollectionAssert.AreEqual(
                expected,
                (int[])new HessianInputV2(data.ToReader(), TypeBindings.Java).ReadObject());
        }
        public void List_Untyped_Fixed()
        {
            var expected = new List <int> {
                0, 1, 2, 3, 4, 5, 6, 7
            };

            var data = new HessianDataBuilder()
                       .WriteBytes(0x58)  // list tag
                       .WriteBytes(0x98)  // length 8 (must be longer than 7 to avoid compact)
                       .WriteBytes(0x90)  // int 0
                       .WriteBytes(0x91)  // int 1
                       .WriteBytes(0x92)  // int 2
                       .WriteBytes(0x93)  // int 3
                       .WriteBytes(0x94)  // int 4
                       .WriteBytes(0x95)  // int 5
                       .WriteBytes(0x96)  // int 6
                       .WriteBytes(0x97); // int 7

            CollectionAssert.AreEqual(
                expected,
                (int[])new HessianInputV2(data.ToReader()).ReadObject(typeof(int[])));
        }