コード例 #1
0
ファイル: Peek.cs プロジェクト: veccsolutions/Vecc.Pdf
        public void StartsAtBeginningStaysAtBeginning()
        {
            var buffer = new byte[] { 0x01, 0x02, 0x03 };

            using (var memoryStream = new MemoryStream(buffer))
            {
                var reader = new PdfStreamReader(memoryStream, 512);
                Assert.Equal(0, reader.Position);

                var expected = 1;
                var actual   = reader.Peek();
                Assert.Equal(expected, actual);
                Assert.Equal(0, reader.Position);
            }
        }
コード例 #2
0
ファイル: Peek.cs プロジェクト: veccsolutions/Vecc.Pdf
        public void StartsAtMiddleStaysInMiddle()
        {
            var buffer = new byte[] { 0x01, 0x02, 0x03 };

            using (var memoryStream = new MemoryStream(buffer))
            {
                var reader = new PdfStreamReader(memoryStream, 512);
                reader.Seek(1, SeekOrigin.Begin);
                Assert.Equal(1, reader.Position);

                var expected = 2;
                var actual   = reader.Peek();
                Assert.Equal(expected, actual);
                Assert.Equal(1, reader.Position);
            }
        }
コード例 #3
0
ファイル: Peek.cs プロジェクト: veccsolutions/Vecc.Pdf
        public void ReadsLastByte()
        {
            var buffer = new byte[] { 0x01, 0x02, 0x03 };

            using (var memoryStream = new MemoryStream(buffer))
            {
                var reader = new PdfStreamReader(memoryStream, 512);
                reader.Seek(2, SeekOrigin.Begin);
                Assert.Equal(2, reader.Position);

                var expected = 3;
                var actual   = reader.Peek();
                Assert.Equal(expected, actual);
                Assert.Equal(2, reader.Position);
            }
        }
コード例 #4
0
ファイル: Peek.cs プロジェクト: veccsolutions/Vecc.Pdf
        public void StartsAtEndReturnsNegativeOne()
        {
            var buffer = new byte[] { 0x01, 0x02, 0x03 };

            using (var memoryStream = new MemoryStream(buffer))
            {
                var reader = new PdfStreamReader(memoryStream, 512);
                reader.Seek(3, SeekOrigin.Begin);
                Assert.Equal(3, reader.Position);

                var expected = -1;
                var actual   = reader.Peek();
                Assert.Equal(expected, actual);
                Assert.Equal(3, reader.Position);
            }
        }
コード例 #5
0
        public void StartsAtBeginningStaysAtBeginning()
        {
            var buffer = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };

            using (var memoryStream = new MemoryStream(buffer))
            {
                var reader     = new PdfStreamReader(memoryStream, 512);
                var readBuffer = new byte[2];

                Assert.Equal(0, reader.Position);

                var bytesRead = reader.Peek(readBuffer, 0, readBuffer.Length);
                Assert.Equal(0, reader.Position);
                Assert.Equal(2, bytesRead);
                Assert.Equal(new byte[] { 0x01, 0x02 }, readBuffer);
            }
        }
コード例 #6
0
        public void ReadsPartialAtEnd()
        {
            var buffer = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };

            using (var memoryStream = new MemoryStream(buffer))
            {
                var reader     = new PdfStreamReader(memoryStream, 512);
                var readBuffer = new byte[2];

                reader.Seek(4, SeekOrigin.Begin);
                Assert.Equal(4, reader.Position);

                var bytesRead = reader.Peek(readBuffer, 0, readBuffer.Length);
                Assert.Equal(4, reader.Position);
                Assert.Equal(1, bytesRead);
                Assert.Equal(new byte[] { 0x05, 0x00 }, readBuffer);
            }
        }
コード例 #7
0
        public void StartsAtMiddleStaysInMiddle()
        {
            var buffer = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };

            using (var memoryStream = new MemoryStream(buffer))
            {
                var reader     = new PdfStreamReader(memoryStream, 512);
                var readBuffer = new byte[2];

                reader.Seek(2, SeekOrigin.Begin);
                Assert.Equal(2, reader.Position);

                var bytesRead = reader.Peek(readBuffer, 0, readBuffer.Length);
                Assert.Equal(2, reader.Position);
                Assert.Equal(2, bytesRead);
                Assert.Equal(new byte[] { 0x03, 0x04 }, readBuffer);
            }
        }
コード例 #8
0
        public void StartsAtEndReturnsNegativeOne()
        {
            var buffer = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };

            using (var memoryStream = new MemoryStream(buffer))
            {
                var reader     = new PdfStreamReader(memoryStream, 512);
                var readBuffer = new byte[2];

                reader.Seek(5, SeekOrigin.Begin);
                Assert.Equal(5, reader.Position);

                var bytesRead = reader.Peek(readBuffer, 0, readBuffer.Length);
                Assert.Equal(5, reader.Position);
                Assert.Equal(-1, bytesRead);
                Assert.Equal(new byte[] { 0x00, 0x00 }, readBuffer);
            }
        }