예제 #1
0
 public void TestReadWrite()
 {
     using (MemoryStream ms = new MemoryStream(SequencedBytes(20)))
         using (Stream s = new ClampedStream(ms, 10, 5))
         {
             byte[] test = new byte[200];
             Assert.AreEqual(5, s.Read(test, 0, 200));
             Array.Resize(ref test, 5);
             Assert.AreEqual(new byte[] { 10, 11, 12, 13, 14 }, test);
             s.Position = 0;
             s.Write(new byte[] { 1, 2, 3, 4, 5 }, 0, 5);
             s.Position = 0;
             Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5 }, IOStream.ReadAllBytes(s));
         }
 }
예제 #2
0
        public void TestPosition()
        {
            using (Stream s = new ClampedStream(new MemoryStream(SequencedBytes(20), false), 2, 10))
            {
                Assert.AreEqual(0, s.Position);
                Assert.AreEqual(2, s.ReadByte());
                s.Position = 0;
                Assert.AreEqual(0, s.Position);
                Assert.AreEqual(2, s.ReadByte());

                s.Position = 10;
                Assert.AreEqual(-1, s.ReadByte());
                Assert.AreEqual(10, s.Position);

                Assert.AreEqual(0, s.Read(new byte[10], 0, 10));
                Assert.AreEqual(10, s.Position);
            }
        }