Example #1
0
        public void WriteReadBitDataTest()
        {
            Packet writePacket = new Packet(packetOpcode);
            writePacket.WriteBit(byteValue & 0x1);
            writePacket.WriteBit(byteValue & 0x2);
            writePacket.WriteBit(byteValue & 0x4);
            writePacket.WriteBit(byteValue & 0x8);
            writePacket.WriteBit(byteValue & 0x10);
            writePacket.WriteBit(byteValue & 0x20);
            writePacket.WriteBit(byteValue & 0x40);
            writePacket.WriteBit(byteValue & 0x80);
            writePacket.WriteBit(true);
            writePacket.WriteBit(false);
            writePacket.FlushBits();

            int bVal = 0;
            Packet readPacket = new Packet(writePacket.Data);
            for (int i = 0; i < 8; i++)
                if (readPacket.ReadBit())
                    bVal |= 1 << i;

            Assert.AreEqual(byteValue, bVal);
            Assert.IsTrue(readPacket.ReadBit());
            Assert.IsFalse(readPacket.ReadBit());

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