Ejemplo n.º 1
0
        public void TestSeeking()
        {
            using (MemoryStream memoryStream = new MemoryStream()) {
                memoryStream.SetLength(20);
                PartialStream partialStream = new PartialStream(memoryStream, 0, 20);

                Assert.AreEqual(7, partialStream.Seek(-13, SeekOrigin.End));
                Assert.AreEqual(14, partialStream.Seek(7, SeekOrigin.Current));
                Assert.AreEqual(11, partialStream.Seek(11, SeekOrigin.Begin));
            }
        }
Ejemplo n.º 2
0
        public void TestThrowOnSetPositionOnUnseekableStream()
        {
            using (MemoryStream memoryStream = new MemoryStream()) {
                TestStream testStream = new TestStream(memoryStream, true, true, false);

                PartialStream partialStream = new PartialStream(testStream, 0, 0);
                Assert.Throws <NotSupportedException>(
                    delegate() { partialStream.Position = 0; }
                    );
            }
        }
Ejemplo n.º 3
0
        public void TestThrowOnExtendPartialStream()
        {
            using (MemoryStream memoryStream = new MemoryStream()) {
                memoryStream.SetLength(25);

                PartialStream partialStream = new PartialStream(memoryStream, 10, 10);
                partialStream.Position = 5;
                Assert.Throws <NotSupportedException>(
                    delegate() { partialStream.Write(new byte[] { 1, 2, 3, 4, 5, 6 }, 0, 6); }
                    );
            }
        }
Ejemplo n.º 4
0
        public void TestThrowOnReadFromUnreadableStream()
        {
            using (MemoryStream memoryStream = new MemoryStream()) {
                TestStream    testStream    = new TestStream(memoryStream, false, true, true);
                PartialStream partialStream = new PartialStream(testStream, 0, 0);

                byte[] test = new byte[10];
                Assert.Throws <NotSupportedException>(
                    delegate() { Console.WriteLine(partialStream.Read(test, 0, 10)); }
                    );
            }
        }
Ejemplo n.º 5
0
        public void TestSetPosition()
        {
            using (MemoryStream memoryStream = new MemoryStream()) {
                memoryStream.SetLength(123);
                PartialStream partialStream = new PartialStream(memoryStream, 23, 100);

                Assert.AreEqual(0, partialStream.Position);
                partialStream.Position = 7;
                Assert.AreEqual(partialStream.Position, 7);
                partialStream.Position = 14;
                Assert.AreEqual(partialStream.Position, 14);
            }
        }
Ejemplo n.º 6
0
        public void TestReadFromPartialStream()
        {
            using (MemoryStream memoryStream = new MemoryStream()) {
                memoryStream.SetLength(123);

                memoryStream.Position = 100;
                memoryStream.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10);

                PartialStream partialStream = new PartialStream(memoryStream, 95, 10);

                byte[] buffer    = new byte[15];
                int    bytesRead = partialStream.Read(buffer, 0, 15);

                Assert.AreEqual(10, bytesRead);
                Assert.AreEqual(
                    new byte[] { 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0 }, buffer
                    );
            }
        }
Ejemplo n.º 7
0
        public void TestGetPosition()
        {
            using (MemoryStream memoryStream = new MemoryStream()) {
                memoryStream.SetLength(123);
                PartialStream partialStream = new PartialStream(memoryStream, 23, 100);

                Assert.AreEqual(0, partialStream.Position);

                byte[] test      = new byte[10];
                int    bytesRead = partialStream.Read(test, 0, 10);

                Assert.AreEqual(10, bytesRead);
                Assert.AreEqual(10, partialStream.Position);

                bytesRead = partialStream.Read(test, 0, 10);

                Assert.AreEqual(10, bytesRead);
                Assert.AreEqual(20, partialStream.Position);
            }
        }
Ejemplo n.º 8
0
        public void TestWriteToPartialStream()
        {
            using (MemoryStream memoryStream = new MemoryStream()) {
                memoryStream.SetLength(123);

                memoryStream.Position = 60;
                memoryStream.Write(new byte[] { 11, 12, 13, 14, 15 }, 0, 5);

                PartialStream partialStream = new PartialStream(memoryStream, 50, 15);
                partialStream.Position = 3;
                partialStream.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10);

                byte[] buffer = new byte[17];
                memoryStream.Position = 49;
                int bytesRead = memoryStream.Read(buffer, 0, 17);

                Assert.AreEqual(17, bytesRead);
                Assert.AreEqual(
                    new byte[] { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 15, 0 },
                    buffer
                    );
            }
        }
Ejemplo n.º 9
0
    public void TestThrowOnReadFromUnreadableStream() {
      using(MemoryStream memoryStream = new MemoryStream()) {
        TestStream testStream = new TestStream(memoryStream, false, true, true);
        PartialStream partialStream = new PartialStream(testStream, 0, 0);

        byte[] test = new byte[10];
        Assert.Throws<NotSupportedException>(
          delegate() { Console.WriteLine(partialStream.Read(test, 0, 10)); }
        );
      }
    }
Ejemplo n.º 10
0
    public void TestThrowOnSetPositionOnUnseekableStream() {
      using(MemoryStream memoryStream = new MemoryStream()) {
        TestStream testStream = new TestStream(memoryStream, true, true, false);

        PartialStream partialStream = new PartialStream(testStream, 0, 0);
        Assert.Throws<NotSupportedException>(
          delegate() { partialStream.Position = 0; }
        );
      }
    }
Ejemplo n.º 11
0
    public void TestSetPosition() {
      using(MemoryStream memoryStream = new MemoryStream()) {
        memoryStream.SetLength(123);
        PartialStream partialStream = new PartialStream(memoryStream, 23, 100);

        Assert.AreEqual(0, partialStream.Position);
        partialStream.Position = 7;
        Assert.AreEqual(partialStream.Position, 7);
        partialStream.Position = 14;
        Assert.AreEqual(partialStream.Position, 14);
      }
    }
Ejemplo n.º 12
0
    public void TestGetPosition() {
      using(MemoryStream memoryStream = new MemoryStream()) {
        memoryStream.SetLength(123);
        PartialStream partialStream = new PartialStream(memoryStream, 23, 100);

        Assert.AreEqual(0, partialStream.Position);

        byte[] test = new byte[10];
        int bytesRead = partialStream.Read(test, 0, 10);

        Assert.AreEqual(10, bytesRead);
        Assert.AreEqual(10, partialStream.Position);

        bytesRead = partialStream.Read(test, 0, 10);

        Assert.AreEqual(10, bytesRead);
        Assert.AreEqual(20, partialStream.Position);
      }
    }
Ejemplo n.º 13
0
    public void TestWriteToPartialStream() {
      using(MemoryStream memoryStream = new MemoryStream()) {
        memoryStream.SetLength(123);

        memoryStream.Position = 60;
        memoryStream.Write(new byte[] { 11, 12, 13, 14, 15 }, 0, 5);

        PartialStream partialStream = new PartialStream(memoryStream, 50, 15);
        partialStream.Position = 3;
        partialStream.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10);

        byte[] buffer = new byte[17];
        memoryStream.Position = 49;
        int bytesRead = memoryStream.Read(buffer, 0, 17);

        Assert.AreEqual(17, bytesRead);
        Assert.AreEqual(
          new byte[] { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 15, 0 },
          buffer
        );
      }
    }
Ejemplo n.º 14
0
 public void TestThrowOnLengthChange() {
   using(MemoryStream memoryStream = new MemoryStream()) {
     PartialStream partialStream = new PartialStream(memoryStream, 0, 0);
     Assert.Throws<NotSupportedException>(
       delegate() { partialStream.SetLength(123); }
     );
   }
 }
Ejemplo n.º 15
0
    public void TestSeeking() {
      using(MemoryStream memoryStream = new MemoryStream()) {
        memoryStream.SetLength(20);
        PartialStream partialStream = new PartialStream(memoryStream, 0, 20);

        Assert.AreEqual(7, partialStream.Seek(-13, SeekOrigin.End));
        Assert.AreEqual(14, partialStream.Seek(7, SeekOrigin.Current));
        Assert.AreEqual(11, partialStream.Seek(11, SeekOrigin.Begin));
      }
    }
Ejemplo n.º 16
0
 public void TestThrowOnInvalidSeekReferencePoint() {
   using(MemoryStream memoryStream = new MemoryStream()) {
     PartialStream partialStream = new PartialStream(memoryStream, 0, 0);
     Assert.Throws<ArgumentException>(
       delegate() { partialStream.Seek(1, (SeekOrigin)12345); }
     );
   }
 }
Ejemplo n.º 17
0
 public void TestConstructor() {
   using(MemoryStream memoryStream = new MemoryStream()) {
     memoryStream.SetLength(123);
     PartialStream partialStream = new PartialStream(memoryStream, 23, 100);
     Assert.AreEqual(100, partialStream.Length);
   }
 }
Ejemplo n.º 18
0
    public void TestReadFromPartialStream() {
      using(MemoryStream memoryStream = new MemoryStream()) {
        memoryStream.SetLength(123);

        memoryStream.Position = 100;
        memoryStream.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10);

        PartialStream partialStream = new PartialStream(memoryStream, 95, 10);

        byte[] buffer = new byte[15];
        int bytesRead = partialStream.Read(buffer, 0, 15);

        Assert.AreEqual(10, bytesRead);
        Assert.AreEqual(
          new byte[] { 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0 }, buffer
        );
      }
    }
Ejemplo n.º 19
0
 public void TestCompleteStreamProperty() {
   using(MemoryStream memoryStream = new MemoryStream()) {
     PartialStream partialStream = new PartialStream(memoryStream, 0, 0);
     Assert.AreSame(memoryStream, partialStream.CompleteStream);
   }
 }
Ejemplo n.º 20
0
    public void TestThrowOnExtendPartialStream() {
      using(MemoryStream memoryStream = new MemoryStream()) {
        memoryStream.SetLength(25);

        PartialStream partialStream = new PartialStream(memoryStream, 10, 10);
        partialStream.Position = 5;
        Assert.Throws<NotSupportedException>(
          delegate() { partialStream.Write(new byte[] { 1, 2, 3, 4, 5, 6 }, 0, 6); }
        );
      }
    }
Ejemplo n.º 21
0
 public void TestFlush() {
   using(MemoryStream memoryStream = new MemoryStream()) {
     PartialStream partialStream = new PartialStream(memoryStream, 0, 0);
     partialStream.Flush();
   }
 }