예제 #1
0
        public void TestConstructNonNested()
        {
            var inner = new MemoryStream(new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07});
              var nestOuter = new PartialStream(inner, 1, 6);
              var nestInner = PartialStream.CreateNonNested(nestOuter, 1, 4);

              Assert.AreEqual(2, inner.Position);
              Assert.AreEqual(1, nestOuter.Position);
              Assert.AreEqual(0, nestInner.Position);

              Assert.IsNotInstanceOfType(typeof(PartialStream), nestInner.InnerStream);

              var buffer = new byte[inner.Length];

              nestInner.Position = 0;
              Assert.AreEqual(4, nestInner.Read(buffer, 0, buffer.Length));
              Assert.AreEqual(new byte[] {0x02, 0x03, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00}, buffer);

              nestOuter.Position = 0;
              Assert.AreEqual(6, nestOuter.Read(buffer, 0, buffer.Length));
              Assert.AreEqual(new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00, 0x00}, buffer);
        }
예제 #2
0
        public void TestReadLengthSpecified()
        {
            var inner = new MemoryStream(new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07});
              var stream = new PartialStream(inner, 2, 4);

              Assert.AreEqual(8, stream.InnerStream.Length);
              Assert.AreEqual(2, stream.InnerStream.Position);

              Assert.AreEqual(4, stream.Length);
              Assert.AreEqual(0, stream.Position);

              var buffer = new byte[2];

              Assert.AreEqual(2, stream.Read(buffer, 0, 2));
              Assert.AreEqual(new byte[] {0x02, 0x03}, buffer);

              Assert.AreEqual(4, stream.InnerStream.Position);
              Assert.AreEqual(2, stream.Position);

              Assert.AreEqual(0x04, stream.ReadByte());

              Assert.AreEqual(1, stream.Read(buffer, 0, 2));
              Assert.AreEqual(new byte[] {0x05, 0x03}, buffer);

              Assert.AreEqual(6, stream.InnerStream.Position);
              Assert.AreEqual(4, stream.Position);

              Assert.AreEqual(0, stream.Read(buffer, 0, 3));
              Assert.AreEqual(-1, stream.ReadByte());
        }
예제 #3
0
        public void TestReadAfterEndOfInnerStream()
        {
            var inner = new MemoryStream(new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07});
              var stream = new PartialStream(inner, inner.Length, 8);

              Assert.AreEqual(8, stream.Length);
              Assert.AreEqual(0, stream.Position);

              var buffer = new byte[2];

              Assert.AreEqual(0, stream.Read(buffer, 0, 2));
              Assert.AreEqual(0, stream.Position);
        }