public void TestBasics()
		{
			using (SegmentedMemoryStream ms = new SegmentedMemoryStream())
			{
				Assert.IsTrue(ms.CanRead);
				Assert.IsTrue(ms.CanWrite);
				Assert.IsTrue(ms.CanSeek);
				ms.Flush();
			}
		}
		public void TestSetLength()
		{
			using (SegmentedMemoryStream ms = new SegmentedMemoryStream())
			{
				Assert.AreEqual(0L, ms.Length);
                Assert.AreEqual(0L, ms.Position);

                ms.SetLength(10);
                Assert.AreEqual(0L, ms.Position);
                Assert.AreEqual(10L, ms.Length);
                Assert.AreEqual(10L, ms.Seek(0, System.IO.SeekOrigin.End));
                
                ms.SetLength(100);
                Assert.AreEqual(10L, ms.Position);
                Assert.AreEqual(100L, ms.Length);
                Assert.AreEqual(100L, ms.Seek(0, System.IO.SeekOrigin.End));

                ms.SetLength(1);
                Assert.AreEqual(100L, ms.Position);
                Assert.AreEqual(1L, ms.Length);
                Assert.AreEqual(1L, ms.Seek(0, System.IO.SeekOrigin.End));
            }
		}
		public void TestSeek()
		{
			using (SegmentedMemoryStream ms = new SegmentedMemoryStream())
			{
				Assert.AreEqual(0L, ms.Length);
				Assert.AreEqual(0L, ms.Position);
				Assert.AreEqual(0L, ms.Seek(0, System.IO.SeekOrigin.Begin));
				Assert.AreEqual(0L, ms.Seek(0, System.IO.SeekOrigin.Current));
				Assert.AreEqual(0L, ms.Seek(0, System.IO.SeekOrigin.End));

				ms.Position = 42L;
				Assert.AreEqual(42L, ms.Length);
				Assert.AreEqual(42L, ms.Position);
				Assert.AreEqual(42L, ms.Seek(42, System.IO.SeekOrigin.Begin));
				Assert.AreEqual(42L, ms.Seek(0, System.IO.SeekOrigin.Current));
				Assert.AreEqual(42L, ms.Seek(0, System.IO.SeekOrigin.End));

				ms.Position = 0;
				Assert.AreEqual(0L, ms.Position);
				Assert.AreEqual(0L, ms.Seek(0, System.IO.SeekOrigin.Begin));
				Assert.AreEqual(0L, ms.Seek(0, System.IO.SeekOrigin.Current));
				Assert.AreEqual(0L, ms.Seek(-42, System.IO.SeekOrigin.End));
			}
		}
		public void TestBadLength()
		{
			SegmentedMemoryStream ms = new SegmentedMemoryStream();
			ms.SetLength(-1);
		}
		public void TestSeekError()
		{
			SegmentedMemoryStream ms = new SegmentedMemoryStream();
			ms.Position = -1;
		}
		public void TestDisposed()
		{
			SegmentedMemoryStream ms = new SegmentedMemoryStream();
			ms.Dispose();
			ms.Position = 5;
		}
		public void TestReadWrite()
		{
			using (SegmentedMemoryStream ms = new SegmentedMemoryStream(5))
			{
				Write(ms, "12345");
				Write(ms, "abcd");
				Write(ms, "ABCDEF");
				Write(ms, "12345");
				Write(ms, "");

				ms.Flush();
				Assert.AreEqual(20L, ms.Length);
				Assert.AreEqual(20L, ms.Position);

				ms.Position = 0;
				Assert.AreEqual("12345abcdABCDEF12345", Read(ms, (int)ms.Length));

				ms.Position = 5;
				Assert.AreEqual("a", Read(ms, 1));
				Assert.AreEqual("bcd", Read(ms, 3));
				Assert.AreEqual("ABCDEF", Read(ms, 6));
				Assert.AreEqual("12345", Read(ms, 5));
				Assert.AreEqual(0, ms.Read(new byte[10], 0, 10));
			}
		}
Example #8
0
 /// <summary> Creates a 'clone' of the stream sharing the same contents </summary>
 protected SegmentedMemoryStream(SegmentedMemoryStream from)
 {
     _contents = from._contents;
     _position = 0;
 }
 /// <summary> Creates a 'clone' of the stream sharing the same contents </summary>
 protected SegmentedMemoryStream(SegmentedMemoryStream from)
 {
     _contents = from._contents;
     _position = 0;
 }