예제 #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));
            }
        }
예제 #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; }
                    );
            }
        }
예제 #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); }
                    );
            }
        }
예제 #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)); }
                    );
            }
        }
예제 #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);
            }
        }
예제 #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
                    );
            }
        }
예제 #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);
            }
        }
예제 #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
                    );
            }
        }
예제 #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)); }
        );
      }
    }
예제 #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; }
        );
      }
    }
예제 #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);
      }
    }
예제 #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);
      }
    }
예제 #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
        );
      }
    }
예제 #14
0
 public void TestThrowOnLengthChange() {
   using(MemoryStream memoryStream = new MemoryStream()) {
     PartialStream partialStream = new PartialStream(memoryStream, 0, 0);
     Assert.Throws<NotSupportedException>(
       delegate() { partialStream.SetLength(123); }
     );
   }
 }
예제 #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));
      }
    }
예제 #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); }
     );
   }
 }
예제 #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);
   }
 }
예제 #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
        );
      }
    }
예제 #19
0
 public void TestCompleteStreamProperty() {
   using(MemoryStream memoryStream = new MemoryStream()) {
     PartialStream partialStream = new PartialStream(memoryStream, 0, 0);
     Assert.AreSame(memoryStream, partialStream.CompleteStream);
   }
 }
예제 #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); }
        );
      }
    }
예제 #21
0
 public void TestFlush() {
   using(MemoryStream memoryStream = new MemoryStream()) {
     PartialStream partialStream = new PartialStream(memoryStream, 0, 0);
     partialStream.Flush();
   }
 }