Exemplo n.º 1
0
        public void AppendByteBufferTest()
        {
            Packet writePacket = new Packet(packetOpcode);
            ByteBuffer buffer1 = new ByteBuffer();
            ByteBuffer buffer2 = new ByteBuffer();

            for (int i = 0; i < byteArrayValue.Length; i++)
            {
                writePacket.Write(byteArrayValue[i]);
                buffer1.Write(byteArrayValue[i]);
                buffer2.Write(byteArrayValue[byteArrayValue.Length - (i + 1)]);
            }

            writePacket.Write(buffer1);
            writePacket.Write(buffer2);

            Packet readPacket = new Packet(writePacket.Data);
            for (int i = 0; i < byteArrayValue.Length; i++)
                Assert.AreEqual(byteArrayValue[i], readPacket.ReadByte());

            for (int i = 0; i < byteArrayValue.Length; i++)
                Assert.AreEqual(byteArrayValue[i], readPacket.ReadByte());

            for (int i = byteArrayValue.Length - 1; i >= 0; i--)
                Assert.AreEqual(byteArrayValue[i], readPacket.ReadByte());

            readPacket.Dispose();
            writePacket.Dispose();
        }
Exemplo n.º 2
0
        public void WriteGuidTests()
        {
            Packet writePacket = new Packet(packetOpcode);
            writePacket.WriteGuidBitStreamInOrder(guidValues[0], 0, 1, 2, 3, 4, 5, 6, 7);
            writePacket.WriteGuidBitStreamInOrder(guidValues[1], 7, 6, 5);
            writePacket.WriteGuidBitStreamInOrder(guidValues[2], 0, 1, 2, 3);
            writePacket.WriteGuidBitStreamInOrder(guidValues[1], 4, 3, 2);
            writePacket.WriteGuidBitStreamInOrder(guidValues[2], 7, 6, 5, 4);
            writePacket.WriteGuidBitStreamInOrder(guidValues[1], 1, 0);
            writePacket.FlushBits(); // Not required as we've written the whole bytes (3 * 8 bits == 3 bytes)

            writePacket.WriteGuidByteStreamInOrder(guidValues[1], 0, 1, 2, 3, 4, 5, 6, 7);
            writePacket.WriteGuidByteStreamInOrder(guidValues[2], 7, 6);
            writePacket.WriteGuidByteStreamInOrder(guidValues[0], 0, 1, 2, 3, 7, 6, 5, 4);
            writePacket.WriteGuidByteStreamInOrder(guidValues[2], 5, 4, 3, 2, 1, 0);

            var guids = new Guid[3];
            for (int i = 0; i < guids.Length; i++)
                guids[i] = new Guid();

            Packet readPacket = new Packet(writePacket.Data);
            readPacket.ReadGuidBitStreamInOrder(guids[0], 0, 1, 2, 3, 4, 5, 6, 7);
            readPacket.ReadGuidBitStreamInOrder(guids[1], 7, 6, 5);
            readPacket.ReadGuidBitStreamInOrder(guids[2], 0, 1, 2, 3);
            readPacket.ReadGuidBitStreamInOrder(guids[1], 4, 3, 2);
            readPacket.ReadGuidBitStreamInOrder(guids[2], 7, 6, 5, 4);
            readPacket.ReadGuidBitStreamInOrder(guids[1], 1, 0);

            readPacket.ReadGuidByteStreamInOrder(guids[1], 0, 1, 2, 3, 4, 5, 6, 7);
            readPacket.ReadGuidByteStreamInOrder(guids[2], 7, 6);
            readPacket.ReadGuidByteStreamInOrder(guids[0], 0, 1, 2, 3, 7, 6, 5, 4);
            readPacket.ReadGuidByteStreamInOrder(guids[2], 5, 4, 3, 2, 1, 0);

            Assert.AreEqual(guidValues[0], guids[0]);
            Assert.AreEqual(guidValues[1], guids[1]);
            Assert.AreEqual(guidValues[2], guids[2]);

            readPacket.Dispose();
            writePacket.Dispose();
        }