示例#1
0
        public virtual void TestLinkOffset()
        {
            int linkOffset           = 7;
            MarshallingBuffer buffer = new MarshallingBuffer();

            buffer.WriteInt(Data1);
            buffer.WriteByte(Data2);
            MarshallingBuffer child = buffer.AddChild();

            child.WriteInt(Data3);
            child.WriteInt(Data4);
            MarshallingBuffer grandChild = child.AddChild();

            grandChild.WriteInt(Data5);
            buffer.MergeChildren(null, 0, linkOffset);
            ByteArrayBuffer content        = InspectContent(buffer);
            ByteArrayBuffer extendedBuffer = new ByteArrayBuffer(content.Length() + linkOffset
                                                                 );

            content.CopyTo(extendedBuffer, 0, linkOffset, content.Length());
            extendedBuffer.Seek(linkOffset);
            Assert.AreEqual(Data1, extendedBuffer.ReadInt());
            Assert.AreEqual(Data2, extendedBuffer.ReadByte());
            int address = extendedBuffer.ReadInt();

            extendedBuffer.Seek(address);
            Assert.AreEqual(Data3, extendedBuffer.ReadInt());
            Assert.AreEqual(Data4, extendedBuffer.ReadInt());
            address = extendedBuffer.ReadInt();
            extendedBuffer.Seek(address);
            Assert.AreEqual(Data5, extendedBuffer.ReadInt());
        }
        public virtual void TestCopy()
        {
            ByteArrayBuffer from = new ByteArrayBuffer(Readerlength);

            for (int i = 0; i < Readerlength; i++)
            {
                from.WriteByte((byte)i);
            }
            ByteArrayBuffer to = new ByteArrayBuffer(Readerlength - 1);

            from.CopyTo(to, 1, 2, 10);
            Assert.AreEqual(0, to.ReadByte());
            Assert.AreEqual(0, to.ReadByte());
            for (int i = 1; i <= 10; i++)
            {
                Assert.AreEqual((byte)i, to.ReadByte());
            }
            for (int i = 12; i < Readerlength - 1; i++)
            {
                Assert.AreEqual(0, to.ReadByte());
            }
        }