示例#1
0
        private void CanEncode(int iNumberOfEntries)
        {
            // Add entries to pending
            RailPackedListOutgoing <Foo> list = new RailPackedListOutgoing <Foo>();

            for (int i = 0; i < iNumberOfEntries; ++i)
            {
                list.AddPending(poolMock.Object.Allocate());
            }

            Assert.Equal(iNumberOfEntries, elementsCreated);
            poolMock.Verify(p => p.Allocate(), Times.Exactly(iNumberOfEntries));
            poolMock.Verify(p => p.Deallocate(It.IsAny <Foo>()), Times.Never);

            // Encode
            RailBitBuffer buffer = new RailBitBuffer();

            list.Encode(
                buffer,
                RailConfig.PACKCAP_COMMANDS,
                RailConfig.MAXSIZE_COMMANDUPDATE,
                (foo, buf) => foo.WriteData(buf));
            Assert.False(buffer.Empty);
            poolMock.Verify(p => p.Allocate(), Times.Exactly(iNumberOfEntries));
            poolMock.Verify(p => p.Deallocate(It.IsAny <Foo>()), Times.Never);
            Assert.Equal(iNumberOfEntries, list.Sent.Count());

            // Clear the list. This should deallocate all sent objects.
            list.Clear();
            poolMock.Verify(p => p.Allocate(), Times.Exactly(iNumberOfEntries));
            poolMock.Verify(p => p.Deallocate(It.IsAny <Foo>()), Times.Exactly(iNumberOfEntries));
        }
示例#2
0
        private void CanDecode(int iNumberOfEntries)
        {
            // Add entries to pending
            RailPackedListOutgoing <Foo> list = new RailPackedListOutgoing <Foo>();

            for (int i = 0; i < iNumberOfEntries; ++i)
            {
                list.AddPending(poolMock.Object.Allocate());
            }

            Assert.Equal(iNumberOfEntries, elementsCreated);
            poolMock.Verify(p => p.Allocate(), Times.Exactly(iNumberOfEntries));
            poolMock.Verify(p => p.Deallocate(It.IsAny <Foo>()), Times.Never);

            // Encode
            RailBitBuffer buffer = new RailBitBuffer();

            list.Encode(
                buffer,
                RailConfig.PACKCAP_COMMANDS,
                RailConfig.MAXSIZE_COMMANDUPDATE,
                (foo, buf) => foo.WriteData(buf));
            Assert.False(buffer.Empty);
            poolMock.Verify(p => p.Allocate(), Times.Exactly(iNumberOfEntries));
            poolMock.Verify(p => p.Deallocate(It.IsAny <Foo>()), Times.Never);
            Assert.Equal(iNumberOfEntries, list.Sent.Count());

            RailPackedListIncoming <Foo> incoming = new RailPackedListIncoming <Foo>();

            incoming.Decode(
                buffer,
                b =>
            {
                Foo foo = poolMock.Object.Allocate();
                foo.ReadData(b);
                return(foo);
            });

            Assert.Equal(iNumberOfEntries, incoming.Received.Count());
        }
示例#3
0
 public RailPacketToClient()
 {
     deltas = new RailPackedListOutgoing <RailStateDelta>();
 }
示例#4
0
 public RailPacketToServer()
 {
     view           = new RailView();
     commandUpdates = new RailPackedListOutgoing <RailCommandUpdate>();
 }