public void TestReadWriteOffset2() { int length = 100; int writeFrom = 27; BigMemoryStream stream = new BigMemoryStream(length); byte[] values = new byte[length]; for (byte i = 0; i < values.Length; i++) { values[i] = (byte)(i + 100); } List <byte> expected = Enumerable.Repeat((byte)0, writeFrom).ToList(); List <byte> expectedValues = values.Skip(writeFrom).Take(length - writeFrom).ToList(); expected.AddRange(expectedValues); stream.Write(values, writeFrom, length - writeFrom); //Back to the start to read the values back stream.Position = 0; byte[] buffer = new byte[length]; int numRead = stream.Read(buffer, writeFrom, length - writeFrom); CollectionAssert.AreEqual(expected, buffer); Assert.AreEqual(length - writeFrom, numRead); }
public void TestReadWriteOffset1() { BigMemoryStream stream = new BigMemoryStream(100); byte[] values = new byte[] { 1, 3, 7, 6, 8, 9, 2, 3, 5, 76, 34, 12, 55, 4 }; stream.Write(values, 3, 4); byte[] expected = values.Skip(3).Take(4).ToArray(); //Get just the bytes that were written byte[] actual1 = new byte[4]; stream.Position = 0; stream.Read(actual1, 0, 4); CollectionAssert.AreEqual(expected, actual1); //Get the bytes back using an offset on read too byte[] actual2 = new byte[values.Length]; stream.Position = 0; stream.Read(actual2, 3, 4); for (int i = 3; i < 7; i++) { Assert.AreEqual(values[i], actual2[i]); } }
public void TestReadWriteBigAboveIntegerIndex() { long length = 3L * 1024L * 1024L * 1024L; //3GiB long fromStreamPos = (long)int.MaxValue + 1000; BigMemoryStream stream = new BigMemoryStream(length); stream.Position = fromStreamPos; byte[] values = new byte[100]; for (byte i = 0; i < values.Length; i++) { values[i] = (byte)(i + 100); } stream.Write(values, 0, values.Length); //Back to the start (fromStreamPos) to read the values back stream.Position = fromStreamPos; byte[] buffer = new byte[values.Length]; stream.Read(buffer, 0, values.Length); CollectionAssert.AreEqual(values, buffer); }
public void TestPositionMovesOnWrite() { BigMemoryStream stream = new BigMemoryStream(100); stream.Position = 5; byte[] toWrite = new byte[10]; for (int i = 0; i < toWrite.Length; i++) { toWrite[i] = (byte)i; } stream.Write(toWrite, 0, toWrite.Length); Assert.AreEqual(15, stream.Position); }
public void TestReadWriteBig() { long length = 3L * 1024L * 1024L * 1024L; //3GiB BigMemoryStream stream = new BigMemoryStream(length); byte[] values = new byte[100]; for (byte i = 0; i < values.Length; i++) { values[i] = (byte)(i + 100); } stream.Write(values, 0, values.Length); //Back to the start to read the values back stream.Position = 0; byte[] buffer = new byte[values.Length]; stream.Read(buffer, 0, values.Length); CollectionAssert.AreEqual(values, buffer); }