public void ReadUntil_BufferHasData_WaitMore_Success() { StreamTester tester = new StreamTester(_stream); _stream.BufferOffset = 3; tester.ScheduleData(4); tester.ScheduleData(4); tester.ScheduleData(4); tester.StartAfter(200); byte[] buff = _stream.ReadUntil(9, 1000); tester.WaitForCompletion(); // data incoming --> (offset=3, length=4) // ReadUntil() consumes no data tester.AssertBufferStatus(INITAL_BUFFER_SIZE, 3, 4); // data incoming --> refill --> (offset=0, length=8) // ReadUntil() consumes no data tester.AssertBufferStatus(INITAL_BUFFER_SIZE, 0, 8); // data incoming --> extend buffer --> (offset=0, length=12) // ReadUntil() reads 9 bytes --> (offset=9, length=3) tester.AssertBufferStatus(INITAL_BUFFER_SIZE * 2, 9, 3); tester.AssertFinal(); Assert.AreEqual(9, buff.Length); CheckBufferContent(buff, 0, 9); }
public void ReadUntil_BufferHasData_WaitMore_Success() { StreamTester tester = new StreamTester(_stream); tester.ScheduleData(4); tester.ScheduleData(4); tester.ScheduleData(4); tester.StartAfter(200); byte[] buff = _stream.ReadUntil(9, 1000); tester.WaitForCompletion(); CollectionAssert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, }, buff); }
public void Buffer_AddSmallData_ExtendBuffer_BufferFull() { StreamTester tester = new StreamTester(_stream); tester.ScheduleData(7); tester.ScheduleData(INITAL_BUFFER_SIZE * 2 - 7); tester.StartAndWait(); // there was enough room tester.AssertBufferStatus(INITAL_BUFFER_SIZE, 0, 7); // buffer overflow -> extend tester.AssertBufferStatus(INITAL_BUFFER_SIZE * 2, 0, INITAL_BUFFER_SIZE * 2); tester.AssertFinal(); CheckBufferContent(_stream.DataBuffer, 0, INITAL_BUFFER_SIZE * 2); }
public void Buffer_AddLargeData() { StreamTester tester = new StreamTester(_stream); tester.ScheduleData(11); tester.StartAndWait(); // buffer overflow -> extend tester.AssertBufferStatus(INITAL_BUFFER_SIZE * 2, 0, 11); tester.AssertFinal(); CheckBufferContent(_stream.DataBuffer, 0, 11); }
public void ReadByte_WaitForData() { StreamTester tester = new StreamTester(_stream); tester.ScheduleData(1); tester.StartAfter(200); byte b = _stream.ReadByte(1000); tester.WaitForCompletion(); Assert.AreEqual((byte)1, b); }
public void Buffer_AddHugeData() { StreamTester tester = new StreamTester(_stream); tester.ScheduleData(21); tester.StartAndWait(); // buffer overflow -> extend to 20 -> extend to 40 tester.AssertBufferStatus(INITAL_BUFFER_SIZE * 4, 0, 21); tester.AssertFinal(); CheckBufferContent(_stream.DataBuffer, 0, 21); }
public void Buffer_AddSmallData() { StreamTester tester = new StreamTester(_stream); tester.ScheduleData(7); tester.StartAndWait(); // there was enough room tester.AssertBufferStatus(INITAL_BUFFER_SIZE, 0, 7); tester.AssertFinal(); CheckBufferContent(_stream.DataBuffer, 0, 7); }
public void Buffer_AddLargeData_Offset() { StreamTester tester = new StreamTester(_stream); _stream.BufferOffset = 3; tester.ScheduleData(11); tester.StartAndWait(); // buffer overflow -> extend tester.AssertBufferStatus(INITAL_BUFFER_SIZE * 2, 0, 11); tester.AssertFinal(); CheckBufferContent(_stream.DataBuffer, 0, 11); }
public void Buffer_AddSmallData_Refill_BufferFull() { StreamTester tester = new StreamTester(_stream); _stream.BufferOffset = 4; tester.ScheduleData(INITAL_BUFFER_SIZE); tester.StartAndWait(); // buffer overflow -> refill tester.AssertBufferStatus(INITAL_BUFFER_SIZE, 0, INITAL_BUFFER_SIZE); tester.AssertFinal(); CheckBufferContent(_stream.DataBuffer, 0, INITAL_BUFFER_SIZE); }
public void Read_WaitData_ReadPartial() { byte[] buff = new byte[2]; StreamTester tester = new StreamTester(_stream); tester.ScheduleData(5); // add [ 1, 2, 3, 4, 5 ] tester.StartAfter(200); int readLength = _stream.Read(buff, 1000); tester.WaitForCompletion(); Assert.AreEqual(2, readLength); CollectionAssert.AreEqual(new byte[] { 1, 2, }, buff); // remained data is [ 3, 4, 5 ] CollectionAssert.AreEqual(new byte[] { 3, 4, 5, }, _stream.DataBuffer); }
public void ReadByte_WaitForData() { StreamTester tester = new StreamTester(_stream); _stream.BufferOffset = 3; // offset=3, length=0 tester.ScheduleData(1); tester.StartAfter(200); byte b = _stream.ReadByte(1000); tester.WaitForCompletion(); // data incoming --> (offset=3, length=1) // ReadByte() obtains data --> (offset=4, length=0) tester.AssertBufferStatus(INITAL_BUFFER_SIZE, 4, 0); tester.AssertFinal(); Assert.AreEqual((byte)1, b); }
public void ReadUntil_ErrorWhileWaiting() { StreamTester tester = new StreamTester(_stream); tester.ScheduleData(6); tester.ScheduleChannelError(); tester.StartAfter(200); try { Assert.Catch <SCPClientInvalidStatusException>( () => _stream.ReadUntil(10, 1000) ); } finally { tester.WaitForCompletion(); } }
public void Read_WaitData_ReadAll() { byte[] buff = new byte[100]; StreamTester tester = new StreamTester(_stream); tester.ScheduleData(5); tester.StartAfter(200); int readLength = _stream.Read(buff, 1000); tester.WaitForCompletion(); Assert.AreEqual(5, readLength); Assert.AreEqual((byte)1, buff[0]); Assert.AreEqual((byte)2, buff[1]); Assert.AreEqual((byte)3, buff[2]); Assert.AreEqual((byte)4, buff[3]); Assert.AreEqual((byte)5, buff[4]); }
public void ReadUntil_ErrorWhileWaiting() { StreamTester tester = new StreamTester(_stream); _stream.BufferOffset = 3; // offset=3, length=0 tester.ScheduleData(6); tester.ScheduleChannelError(); tester.StartAfter(200); try { _stream.ReadUntil(10, 1000); } finally { tester.WaitForCompletion(); tester.AssertBufferStatus(INITAL_BUFFER_SIZE, 3, 6); tester.AssertBufferStatus(INITAL_BUFFER_SIZE, 3, 6); tester.AssertFinal(); } }
public void Read_WaitData_ReadAll() { byte[] buff = new byte[100]; StreamTester tester = new StreamTester(_stream); _stream.BufferOffset = 3; _stream.BufferLength = 0; tester.ScheduleData(5); tester.StartAfter(200); int readLength = _stream.Read(buff, 1000); tester.WaitForCompletion(); // data incoming --> (offset=3, length=5) // ReadByte() obtains data --> (offset=8, length=0) tester.AssertBufferStatus(INITAL_BUFFER_SIZE, 8, 0); tester.AssertFinal(); Assert.AreEqual(5, readLength); CheckBufferContent(buff, 0, 5); }
public void Read_WaitData_ReadPartial() { byte[] buff = new byte[2]; StreamTester tester = new StreamTester(_stream); _stream.BufferOffset = 3; _stream.BufferLength = 0; tester.ScheduleData(5); // add [ 1, 2, 3, 4, 5 ] tester.StartAfter(200); int readLength = _stream.Read(buff, 1000); tester.WaitForCompletion(); // data incoming --> (offset=3, length=5) // ReadByte() obtains data --> (offset=5, length=3) tester.AssertBufferStatus(INITAL_BUFFER_SIZE, 5, 3); tester.AssertFinal(); Assert.AreEqual(2, readLength); CheckBufferContent(buff, 0, 2); // remained data is [ 3, 4, 5 ] Assert.AreEqual(3, _stream.DataBuffer[5]); Assert.AreEqual(4, _stream.DataBuffer[6]); Assert.AreEqual(5, _stream.DataBuffer[7]); }