Example #1
0
        public void Ref_CircularList()
        {
            var reader = new HessianDataBuilder()
                         // map
                         .WriteChar('M')
                         // type
                         .WriteChar('t').WriteBytes(0, 0x1A).WriteUtf8("com.caucho.test.LinkedList")
                         // head field
                         .WriteChar('S').WriteBytes(0, 0x04).WriteUtf8("head")
                         .WriteChar('I').WriteBytes(0, 0, 0, 0x01)
                         // tail field
                         .WriteChar('S').WriteBytes(0, 0x04).WriteUtf8("tail")
                         .WriteChar('R').WriteBytes(0, 0, 0, 0)
                         // map end
                         .WriteChar('z')
                         .ToReader();

            // expectation:
            //   head is an integer
            //   tail is object itself (circular ref)
            var expected = new com.caucho.test.LinkedList {
                head = 1
            };

            expected.tail = expected;

            var actual = (com.caucho.test.LinkedList) new HessianInputV1(reader).ReadObject();

            Assert.AreEqual(expected.head, actual.head);
            // check that ref was restored correctly
            Assert.AreSame(expected, expected.tail);
        }
Example #2
0
        public void Ref_CircularList()
        {
            var value = new com.caucho.test.LinkedList {
                head = 1
            };

            value.tail = value;

            var actual = Serialize(value);

            var expected = new HessianDataBuilder()
                           // map
                           .WriteChar('M')
                           // type
                           .WriteChar('t').WriteBytes(0, 0x1A).WriteUtf8("com.caucho.test.LinkedList")
                           // head field
                           .WriteChar('S').WriteBytes(0, 0x04).WriteUtf8("head")
                           .WriteChar('I').WriteBytes(0, 0, 0, 0x01)
                           // tail field
                           .WriteChar('S').WriteBytes(0, 0x04).WriteUtf8("tail")
                           .WriteChar('R').WriteBytes(0, 0, 0, 0)
                           // map end
                           .WriteChar('z')
                           .ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }