public void ViewIO() { SparseMemoryStream memStream = new SparseMemoryStream(); memStream.SetLength(1024); ThreadSafeStream tss = new ThreadSafeStream(memStream); SparseStream altView = tss.OpenView(); // Check positions are independant tss.Position = 100; Assert.Equal(0, altView.Position); Assert.Equal(100, tss.Position); // Check I/O is synchronous byte[] buffer = new byte[200]; tss.WriteByte(99); altView.Read(buffer, 0, 200); Assert.Equal(99, buffer[100]); // Check positions are updated correctly Assert.Equal(200, altView.Position); Assert.Equal(101, tss.Position); }
public void DisposeView() { SparseMemoryStream memStream = new SparseMemoryStream(new SparseMemoryBuffer(1), FileAccess.ReadWrite); memStream.SetLength(1024); ThreadSafeStream tss = new ThreadSafeStream(memStream); SparseStream altView = tss.OpenView(); altView.Dispose(); tss.ReadByte(); SparseStream altView2 = tss.OpenView(); altView2.ReadByte(); }
public void Dispose_StopsView() { SparseMemoryStream memStream = new SparseMemoryStream(new SparseMemoryBuffer(1), FileAccess.ReadWrite); memStream.SetLength(1024); ThreadSafeStream tss = new ThreadSafeStream(memStream); SparseStream altView = tss.OpenView(); tss.Dispose(); try { altView.ReadByte(); Assert.True(false, "Disposed stream didn't stop view"); } catch (ObjectDisposedException) { } }
public void Extents() { SparseMemoryStream memStream = new SparseMemoryStream(new SparseMemoryBuffer(1), FileAccess.ReadWrite); memStream.SetLength(1024); ThreadSafeStream tss = new ThreadSafeStream(memStream); SparseStream altView = tss.OpenView(); tss.Position = 100; tss.WriteByte(99); List <StreamExtent> extents = new List <StreamExtent>(altView.Extents); Assert.Equal(1, extents.Count); Assert.Equal(100, extents[0].Start); Assert.Equal(1, extents[0].Length); extents = new List <StreamExtent>(altView.GetExtentsInRange(10, 300)); Assert.Equal(1, extents.Count); Assert.Equal(100, extents[0].Start); Assert.Equal(1, extents[0].Length); }
public void OpenView() { ThreadSafeStream tss = new ThreadSafeStream(SparseStream.FromStream(Stream.Null, Ownership.None)); SparseStream view = tss.OpenView(); }