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.AreEqual(0, altView.Position);
            Assert.AreEqual(100, tss.Position);

            // Check I/O is synchronous
            byte[] buffer = new byte[200];
            tss.WriteByte(99);
            altView.Read(buffer, 0, 200);
            Assert.AreEqual(99, buffer[100]);

            // Check positions are updated correctly
            Assert.AreEqual(200, altView.Position);
            Assert.AreEqual(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.Fail("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.AreEqual(1, extents.Count);
            Assert.AreEqual(100, extents[0].Start);
            Assert.AreEqual(1, extents[0].Length);

            extents = new List <StreamExtent>(altView.GetExtentsInRange(10, 300));
            Assert.AreEqual(1, extents.Count);
            Assert.AreEqual(100, extents[0].Start);
            Assert.AreEqual(1, extents[0].Length);
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        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.AreEqual(0, altView.Position);
            Assert.AreEqual(100, tss.Position);

            // Check I/O is synchronous
            byte[] buffer = new byte[200];
            tss.WriteByte(99);
            altView.Read(buffer, 0, 200);
            Assert.AreEqual(99, buffer[100]);

            // Check positions are updated correctly
            Assert.AreEqual(200, altView.Position);
            Assert.AreEqual(101, tss.Position);
        }
Exemplo n.º 7
0
 public void OpenView()
 {
     ThreadSafeStream tss = new ThreadSafeStream(SparseStream.FromStream(Stream.Null, Ownership.None));
     SparseStream view = tss.OpenView();
 }
Exemplo n.º 8
0
        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.AreEqual(1, extents.Count);
            Assert.AreEqual(100, extents[0].Start);
            Assert.AreEqual(1, extents[0].Length);

            extents = new List<StreamExtent>(altView.GetExtentsInRange(10, 300));
            Assert.AreEqual(1, extents.Count);
            Assert.AreEqual(100, extents[0].Start);
            Assert.AreEqual(1, extents[0].Length);
        }
Exemplo n.º 9
0
        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.Fail("Disposed stream didn't stop view");
            }
            catch (ObjectDisposedException)
            {
            }
        }
 public void OpenView()
 {
     ThreadSafeStream tss  = new ThreadSafeStream(SparseStream.FromStream(Stream.Null, Ownership.None));
     SparseStream     view = tss.OpenView();
 }