コード例 #1
0
ファイル: StreamUtilTest.cs プロジェクト: genesissupsup/nkd
        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);
 }