Esempio n. 1
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);
        }
Esempio n. 2
0
        public void ReadShouldReturnActualNumberOfBytesRead()
        {
            var buffer = new SimpleByteBuffer(8);

            buffer.Write(_BunchOfBytes, 0, 8);
            var destination = new byte[16];
            buffer.Read(destination, 0, 16).ShouldBe(8);
        }
Esempio n. 3
0
 public void ReadShouldReturnZeroIfNotDataIsAvailable()
 {
     var buffer = new SimpleByteBuffer(8);
     var destination = new byte[16];
     buffer.Read(destination, 0, 16).ShouldBe(0);
 }
Esempio n. 4
0
        public void ReadPositionAndWritePositionShouldResetWhenAllBytesAreRead()
        {
            var buffer = new SimpleByteBuffer(128);

            buffer.WritePosition.ShouldBe(0);
            buffer.Write(_BunchOfBytes, 0, 10);
            buffer.WritePosition.ShouldBe(10);
            buffer.Write(_BunchOfBytes, 0, 5);
            buffer.WritePosition.ShouldBe(15);
            buffer.Write(_BunchOfBytes, 0, 20);
            buffer.WritePosition.ShouldBe(35);

            var destination = new byte[20];
            buffer.ReadPosition.ShouldBe(0);
            buffer.Read(destination, 0, 20).ShouldBe(20);
            buffer.ReadPosition.ShouldBe(20);
            buffer.Read(destination, 0, 5).ShouldBe(5);
            buffer.ReadPosition.ShouldBe(25);
            buffer.Read(destination, 0, 10).ShouldBe(10);

            buffer.WritePosition.ShouldBe(0);
            buffer.ReadPosition.ShouldBe(0);
        }
Esempio n. 5
0
        public void BytesAvailableShouldReturnNumberOfBytesAvailableForReading()
        {
            var buffer = new SimpleByteBuffer(128);

            var destination = new byte[8];
            buffer.Write(_BunchOfBytes, 0, 10);
            buffer.Read(destination, 0, 4);
            buffer.Write(_BunchOfBytes, 0, 20);
            buffer.Read(destination, 0, 8);
            buffer.Write(_BunchOfBytes, 0, 5);
            buffer.Read(destination, 0, 2);

            buffer.BytesAvailable.ShouldBe(35 - 14);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }