public static void ReadWriteByteSafeBuffer() { var length = 1000; using (var buffer = new TestSafeBuffer(length)) { var stream = new UnmanagedMemoryStream(buffer, 0, (long)buffer.ByteLength, FileAccess.ReadWrite); Assert.Equal(stream.Length, length); var bytes = ArrayHelpers.CreateByteArray(length); for (int index = 0; index < length; index++) { stream.WriteByte(bytes[index]); } stream.Position = 0; for (int index = 0; index < length; index++) { int value = stream.ReadByte(); Assert.Equal(bytes[index], (byte)value); } var memory = buffer.ToArray(); Assert.True(ArrayHelpers.Comparer <byte>().Equals(bytes, memory)); } }
public static void WriteSafeBuffer() { var length = 1000; using (var buffer = new TestSafeBuffer(length)) { var stream = new UnmanagedMemoryStream(buffer, 0, (long)buffer.ByteLength, FileAccess.Write); Assert.Equal(stream.Length, length); var bytes = ArrayHelpers.CreateByteArray(length); var copy = bytes.Copy(); stream.Write(copy, 0, length); var memory = buffer.ToArray(); Assert.True(ArrayHelpers.Comparer <byte>().Equals(bytes, memory)); stream.Write(new byte[0], 0, 0); } }
public static void WriteSafeBuffer() { const int length = 1000; using (var buffer = new TestSafeBuffer(length)) { var stream = new UnmanagedMemoryStream(buffer, 0, (long)buffer.ByteLength, FileAccess.Write); Assert.Equal(stream.Length, length); var bytes = ArrayHelpers.CreateByteArray(length); var copy = bytes.Copy(); stream.Write(copy, 0, length); var memory = buffer.ToArray(); Assert.Equal(bytes, memory, ArrayHelpers.Comparer<byte>()); stream.Write(new byte[0], 0, 0); } }
public static void ReadWriteByteSafeBuffer() { const int length = 1000; using (var buffer = new TestSafeBuffer(length)) { var stream = new UnmanagedMemoryStream(buffer, 0, (long)buffer.ByteLength, FileAccess.ReadWrite); Assert.Equal(stream.Length, length); var bytes = ArrayHelpers.CreateByteArray(length); for (int index = 0; index < length; index++) { stream.WriteByte(bytes[index]); } stream.Position = 0; for (int index = 0; index < length; index++) { int value = stream.ReadByte(); Assert.Equal(bytes[index], (byte)value); } var memory = buffer.ToArray(); Assert.Equal(bytes, memory, ArrayHelpers.Comparer<byte>()); } }