Exemplo n.º 1
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());
        }
Exemplo n.º 2
0
        public void TestReadByteLengthSpecified()
        {
            var inner = new MemoryStream(new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07});
              var stream = new PartialStream(inner, 2, 4);

              foreach (var expected in new int[] {
            0x02, 0x03, 0x04, 0x05, -1,
              }) {
            Assert.AreEqual(expected, stream.ReadByte());
              }

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

              Assert.AreEqual(-1, stream.ReadByte());

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