Пример #1
0
        public void ReadExactlyZeroBytesToRead()
        {
            StreamStub input = new StreamStub();

            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            StreamUtil.ReadExactly(input, 0);
        }
Пример #2
0
 public void ReadExactlyZeroBytesToRead()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         StreamStub input = new StreamStub();
         input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
         StreamUtil.ReadExactly(input, 0);
     });
 }
Пример #3
0
        public void ReadExactlyExactlyRightAmountOfData()
        {
            StreamStub input = new StreamStub();

            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
            byte[] actual = StreamUtil.ReadExactly(input, 10);
            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
        }
Пример #4
0
        public void ReadFullyWithByteBuffer()
        {
            StreamStub input = new StreamStub();

            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
            byte[] actual = StreamUtil.ReadFully(input, new byte[8]);
            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
            Assert.AreEqual(8, input.LastReadSize);
        }
Пример #5
0
 public void CopyWithBufferSize()
 {
     StreamStub input = new StreamStub();
     input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
     input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
     MemoryStream output = new MemoryStream();
     StreamUtil.Copy(input, output, 6);
     Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, output.ToArray());
     Assert.AreEqual(6, input.LastReadSize);
 }
Пример #6
0
        public void ReadFullyWithDataDefaults()
        {
            StreamStub input = new StreamStub();

            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
            byte[] actual = StreamUtil.ReadFully(input);
            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
            Assert.AreEqual(8 * 1024, input.LastReadSize);
        }
Пример #7
0
        public void ReadExactlyExcessData()
        {
            StreamStub input = new StreamStub();

            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            input.AddReadData(new byte[] { 6, 7, 8, 9 });
            input.AddReadData(new byte[] { 10, 11, 12, 13, 14 });
            byte[] actual = StreamUtil.ReadExactly(input, 9);
            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, actual);
            Assert.AreEqual(4, input.LastReadSize);
        }
Пример #8
0
 public void ReadExactlyNotEnoughData()
 {
     Assert.Throws <EndOfStreamException>(() =>
     {
         StreamStub input = new StreamStub();
         input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
         input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
         byte[] actual = StreamUtil.ReadExactly(input, 11);
         Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
     });
 }
Пример #9
0
        public void CopyWithBufferSize()
        {
            StreamStub input = new StreamStub();

            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
            MemoryStream output = new MemoryStream();

            StreamUtil.Copy(input, output, 6);
            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, output.ToArray());
            Assert.AreEqual(6, input.LastReadSize);
        }
Пример #10
0
        public void CopyWithIBuffer()
        {
            CachingBufferManager.Options options = new CachingBufferManager.Options();
            options.MinBufferSize = 7;
            CachingBufferManager manager = new CachingBufferManager(options);

            StreamStub input = new StreamStub();
            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
            MemoryStream output = new MemoryStream();
            using (IBuffer buffer = manager.GetBuffer(10))
            {
                StreamUtil.Copy(input, output, buffer);
            }
            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, output.ToArray());
            Assert.AreEqual(14, input.LastReadSize);
        }
Пример #11
0
        public void ReadFullyWithOutCopying()
        {
            StreamStub input = new StreamStub();

            // The memory stream will expand to 256 bytes by default
            byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };
            for (int i = 0; i < 32; i++)
            {
                input.AddReadData(data);
            }
            byte[] actual = StreamUtil.ReadFully(input, new byte[8]);
            Assert.AreEqual(256, actual.Length);
            for (int i = 0; i < 256; i++)
            {
                Assert.AreEqual(i % 8, actual[i]);
            }
            Assert.AreEqual(8, input.LastReadSize);
        }
Пример #12
0
        public void ReadFullyWithIBuffer()
        {
            CachingBufferManager.Options options = new CachingBufferManager.Options();
            options.MinBufferSize = 7;
            CachingBufferManager manager = new CachingBufferManager(options);

            StreamStub input = new StreamStub();

            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
            byte[] actual;
            using (IBuffer buffer = manager.GetBuffer(10))
            {
                actual = StreamUtil.ReadFully(input, buffer);
            }
            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
            Assert.AreEqual(14, input.LastReadSize);
        }
Пример #13
0
        public void CopyWithIBuffer()
        {
            CachingBufferManager.Options options = new CachingBufferManager.Options();
            options.MinBufferSize = 7;
            CachingBufferManager manager = new CachingBufferManager(options);

            StreamStub input = new StreamStub();

            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
            MemoryStream output = new MemoryStream();

            using (IBuffer buffer = manager.GetBuffer(10))
            {
                StreamUtil.Copy(input, output, buffer);
            }
            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, output.ToArray());
            Assert.AreEqual(14, input.LastReadSize);
        }
Пример #14
0
        public void ReadFullyWithOutCopying()
        {
            StreamStub input = new StreamStub();

            // The memory stream will expand to 256 bytes by default
            byte[] data = new byte[]{0, 1, 2, 3, 4, 5, 6, 7};
            for (int i=0; i < 32; i++)
            {
                input.AddReadData(data);
            }
            byte[] actual = StreamUtil.ReadFully(input, new byte[8]);
            Assert.AreEqual(256, actual.Length);
            for (int i=0; i < 256; i++)
            {
                Assert.AreEqual (i%8, actual[i]);
            }
            Assert.AreEqual(8, input.LastReadSize);
        }
Пример #15
0
 public void ReadFullyWithByteBuffer()
 {
     StreamStub input = new StreamStub();
     input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
     input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
     byte[] actual = StreamUtil.ReadFully(input, new byte[8]); 
     Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
     Assert.AreEqual(8, input.LastReadSize);
 }
Пример #16
0
        public void ReadFullyWithIBuffer()
        {
            CachingBufferManager.Options options = new CachingBufferManager.Options();
            options.MinBufferSize = 7;
            CachingBufferManager manager = new CachingBufferManager(options);

            StreamStub input = new StreamStub();
            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
            byte[] actual;
            using (IBuffer buffer = manager.GetBuffer(10))
            {
                actual = StreamUtil.ReadFully(input, buffer);
            }
            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
            Assert.AreEqual(14, input.LastReadSize);
        }
Пример #17
0
 public void ReadFullyWithDataDefaults()
 {
     StreamStub input = new StreamStub();
     input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
     input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
     byte[] actual = StreamUtil.ReadFully(input);
     Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
     Assert.AreEqual(8*1024, input.LastReadSize);
 }
Пример #18
0
 public void ReadExactlyExcessData()
 {
     StreamStub input = new StreamStub();
     input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
     input.AddReadData(new byte[] { 6, 7, 8, 9 });
     input.AddReadData(new byte[] { 10, 11, 12, 13, 14 });
     byte[] actual = StreamUtil.ReadExactly(input, 9);
     Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, actual);
     Assert.AreEqual(4, input.LastReadSize);
 }
Пример #19
0
 public void ReadExactlyNotEnoughData()
 {
     StreamStub input = new StreamStub();
     input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
     input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
     byte[] actual = StreamUtil.ReadExactly(input, 11);
     Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
 }
Пример #20
0
 public void ReadExactlyZeroBytesToRead()
 {
     StreamStub input = new StreamStub();
     input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
     StreamUtil.ReadExactly(input, 0);
 }