예제 #1
0
        public void TestSeekEndLengthSpecified()
        {
            var inner = new MemoryStream(new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, false);
              var stream = new PartialStream(inner, 4, 4);

              // in range
              Assert.AreEqual(3L, stream.Seek(-1, SeekOrigin.End));
              Assert.AreEqual(3L, stream.Position);
              Assert.AreEqual(7L, stream.InnerStream.Position);

              // beyond the length
              Assert.AreEqual(8L, stream.Seek(4, SeekOrigin.End));
              Assert.AreEqual(8L, stream.Position);
              Assert.AreEqual(12L, stream.InnerStream.Position);

              // before start of stream
              try {
            stream.Seek(-5, SeekOrigin.End);
            Assert.Fail("IOException not thrown");
              }
              catch (IOException) {
              }

              Assert.AreEqual(8L, stream.Position);
              Assert.AreEqual(12L, stream.InnerStream.Position);
        }
예제 #2
0
        public void TestSeekCurrent()
        {
            var inner = new MemoryStream(new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, false);
              var stream = new PartialStream(inner, 4);

              // in range
              Assert.AreEqual(2L, stream.Seek(2, SeekOrigin.Current));
              Assert.AreEqual(2L, stream.Position);
              Assert.AreEqual(6L, stream.InnerStream.Position);

              // beyond the length
              Assert.AreEqual(10L, stream.Seek(8, SeekOrigin.Current));
              Assert.AreEqual(10L, stream.Position);
              Assert.AreEqual(14L, stream.InnerStream.Position);

              // before start of stream
              try {
            stream.Seek(-12, SeekOrigin.Current);
            Assert.Fail("IOException not thrown");
              }
              catch (IOException) {
              }

              Assert.AreEqual(10L, stream.Position);
              Assert.AreEqual(14L, stream.InnerStream.Position);
        }