Example #1
0
        private static void RunReadTest(string resourcePrefix)
        {
            const int BufferSize = 64;

            var armorStream  = CreateAsciiArmorReaderStreamFromResource(resourcePrefix + ".txt.asc");
            var binaryStream = GetTestDataAsStream(resourcePrefix + ".bin");

            var armorBuffer     = new byte[BufferSize];
            var binaryBuffer    = new byte[BufferSize];
            var armorBytesRead  = armorStream.Read(armorBuffer, 0, BufferSize);
            var binaryBytesRead = binaryStream.Read(binaryBuffer, 0, BufferSize);

            Assert2.AreBytesEqual(binaryBuffer, 0, armorBuffer, 0, binaryBytesRead);
            armorBytesRead.ShouldBe(binaryBytesRead);
            while (armorBytesRead == BufferSize)
            {
                armorBytesRead  = armorStream.Read(armorBuffer, 0, BufferSize);
                binaryBytesRead = binaryStream.Read(binaryBuffer, 0, BufferSize);
                armorBytesRead.ShouldBe(binaryBytesRead);
                Assert2.AreBytesEqual(binaryBuffer, 0, armorBuffer, 0, binaryBytesRead);
            }

            armorBytesRead = armorStream.Read(armorBuffer, 0, BufferSize);
            armorBytesRead.ShouldBe(0);
        }
Example #2
0
        public void ReadShouldReadBytesFromTheBuffer()
        {
            var buffer = new SimpleByteBuffer(8);

            var destination = new byte[8];

            buffer.Write(_BunchOfBytes, 0, 8);
            buffer.Read(destination, 0, 8).ShouldBe(8);

            Assert2.AreBytesEqual(_BunchOfBytes, 0, destination, 0, 8);
        }
Example #3
0
        public void ReadShouldReadBytesAtSpecifiedOffset()
        {
            var buffer = new SimpleByteBuffer(8);

            var destination = new byte[8];

            buffer.Write(_BunchOfBytes, 0, 8);
            buffer.Read(destination, 4, 4).ShouldBe(4);

            Assert2.AreBytesEqual(_BunchOfBytes, 0, destination, 4, 4);
        }
Example #4
0
        public void MultipleWritesShouldWriteDataSequentially()
        {
            var buffer = new SimpleByteBuffer(8);

            var destination = new byte[8];

            buffer.Write(_BunchOfBytes, 0, 4);
            buffer.Write(_BunchOfBytes, 4, 4);
            buffer.Read(destination, 0, 8).ShouldBe(8);

            Assert2.AreBytesEqual(_BunchOfBytes, 0, destination, 0, 8);
        }
Example #5
0
        public void MultipleReadsShouldReadDataSequentially()
        {
            var buffer = new SimpleByteBuffer(8);

            var destination1 = new byte[4];
            var destination2 = new byte[4];

            buffer.Write(_BunchOfBytes, 0, 8);
            buffer.Read(destination1, 0, 4).ShouldBe(4);
            buffer.Read(destination2, 0, 4).ShouldBe(4);

            Assert2.AreBytesEqual(_BunchOfBytes, 0, destination1, 0, 4);
            Assert2.AreBytesEqual(_BunchOfBytes, 4, destination2, 0, 4);
        }