public void BasicReadTest() { var result = new byte[TestData.Length]; using (var stream = new ProtoChannel.Util.RingMemoryStream(SmallBufferSize)) { stream.Write(TestData, 0, TestData.Length); stream.Position = 0; stream.Read(result, 0, result.Length); Assert.AreEqual(TestData, result); Assert.AreEqual(TestData.Length, stream.Position); Assert.AreEqual(TestData.Length, stream.Length); Assert.AreEqual(7, stream.PagesAllocated); Assert.AreEqual(28, stream.Capacity); } }
public void WriteInBytes() { using (var stream = new RingMemoryStream(SmallBufferSize)) { foreach (byte b in TestData) { stream.WriteByte(b); } stream.Position = 0; byte[] buffer = new byte[TestData.Length]; stream.Read(buffer, 0, buffer.Length); Assert.AreEqual(TestData, buffer); } }
public void NulLengthReadReturnsNul() { using (var stream = new RingMemoryStream(SmallBufferSize)) { Assert.AreEqual(0, stream.Read(new byte[0], 0, 0)); } }
public void ManualWrite() { using (var stream = new RingMemoryStream(SmallBufferSize)) { stream.Capacity++; var pages = stream.GetPages(0, stream.Capacity); Array.Copy(TestData, pages[0].Buffer, SmallBufferSize); stream.SetLength(SmallBufferSize); var readBuffer = new byte[SmallBufferSize]; stream.Read(readBuffer, 0, readBuffer.Length); var validateBuffer = new byte[SmallBufferSize]; Array.Copy(TestData, validateBuffer, SmallBufferSize); Assert.AreEqual(validateBuffer, readBuffer); } }
public void CorrectReadWhenNotOnPageBoundary() { using (var stream = new RingMemoryStream(SmallBufferSize)) { stream.Write(TestData, 0, TestData.Length); stream.Position = 1; var readBuffer = new byte[2]; stream.Read(readBuffer, 0, 2); } }