public void ReadTwoShorts() { using (var buffer = new HeapBuffer(4)) { for (ulong i = 0; i < 4; i++) { buffer[i] = (byte)(i + 1); } var reader = new CheckedReader(buffer); reader.ReadShort().Should().Be(0x0201); reader.ReadShort().Should().Be(0x0403); } }
public void ReadShortInCapacityPasses() { using (var buffer = new HeapBuffer(2)) { var reader = new CheckedReader(buffer); reader.ByteOffset = buffer.ByteCapacity - 2; reader.ReadShort(); } }
public void ReadShort(ulong offset, short expected) { using (var buffer = new HeapBuffer(4)) { for (ulong i = 0; i < 4; i++) { buffer[i] = (byte)(i + 1); } var reader = new CheckedReader(buffer); reader.ByteOffset = offset; reader.ReadShort().Should().Be(expected, $"offset is {offset}"); } }
public void ReadShortPastCapacityFails() { using (var buffer = new HeapBuffer(sizeof(short))) { var reader = new CheckedReader(buffer); Action action = () => reader.ReadShort(); for (uint i = 1; i < sizeof(short); i++) { reader.ByteOffset = buffer.ByteCapacity - i; action.Should().Throw <System.IO.EndOfStreamException>(); } } }