Exemplo n.º 1
0
 public void GetBuffer_calls_warmup_if_necessary()
 {
     int window = 100;
     var streamMock = new Mock<MemoryStream>(MockBehavior.Strict);
     SetupMockStreamRead(streamMock).Returns((byte[] s, int o, int l) => 50);
     var buf = new SlidingStreamBuffer(streamMock.Object, window);
     buf.GetBuffer();
     streamMock.VerifyAll();
 }
Exemplo n.º 2
0
 public void GetBuffer_returns_a_buffer_corresponding_to_GetNumBytesAvailable()
 {
     int window = 100;
     var streamMock = new Mock<MemoryStream>(MockBehavior.Strict);
     SetupMockStreamRead(streamMock).Returns((byte[] s, int o, int l) => 50);
     var buf = new SlidingStreamBuffer(streamMock.Object, window);
     buf.Warmup();
     streamMock.VerifyAll();
     Assert.AreEqual(buf.GetNumBytesAvailable(), buf.GetBuffer().Length);
 }
Exemplo n.º 3
0
 public void GetBuffer_returns_a_buffer_with_valid_data()
 {
     int window = 100;
     var buffer = new byte[window*2];
     for (int i = 0; i < buffer.Length; ++i) buffer[i] = (byte) (200 - i);
     var streamMock = new Mock<MemoryStream>(MockBehavior.Strict);
     SetupMockStreamRead(streamMock)
         .Returns((byte[] s, int o, int l) =>
                      {
                          int actualLength = MathEx.Bounded(0, Math.Min(l, buffer.Length), buffer.Length);
                          Array.Copy(buffer, 0, s, o, actualLength);
                          return actualLength;
                      });
     var buf = new SlidingStreamBuffer(streamMock.Object, window);
     buf.Warmup();
     VerifyBufferPartialEquality(buffer, buf.GetBuffer());
 }
Exemplo n.º 4
0
 public void GetBuffer_when_moved_beyond_end_of_stream_yields_empty_buffer()
 {
     int window = 10;
     var buffer = new byte[window*2];
     for (int i = 0; i < buffer.Length; ++i) buffer[i] = (byte) (200 - i);
     var buf = new SlidingStreamBuffer(new MemoryStream(buffer), window, window);
     buf.Warmup();
     buf.MoveForward(buffer.Length + 1);
     Assert.IsTrue(buf.GetBuffer().Length == 0);
 }