Exemplo n.º 1
0
        static void test_read(SKStream bufferedStream, byte[] expectations, int bytesToRead)
        {
            // output for reading bufferedStream.
            var storage = new byte[bytesToRead];

            var bytesRead = bufferedStream.Read(storage, bytesToRead);

            Assert.True(bytesRead == bytesToRead || bufferedStream.IsAtEnd);
            Assert.Equal(expectations.Take(bytesRead), storage.Take(bytesRead));
        }
Exemplo n.º 2
0
        private int compare_peek_to_read(SKStream stream, int bytesToPeek)
        {
            Assert.True(bytesToPeek > 0);

            var peekStorage = SKData.Create(bytesToPeek);
            var readStorage = SKData.Create(bytesToPeek);

            var bytesPeeked = stream.Peek(peekStorage.Data, bytesToPeek);
            var bytesRead   = stream.Read(readStorage.Data, bytesToPeek);

            // bytesRead should only be less than attempted if the stream is at the
            // end.
            Assert.True(bytesRead == bytesToPeek || stream.IsAtEnd);

            // peek and read should behave the same, except peek returned to the
            // original position, so they read the same data.
            Assert.Equal(peekStorage.ToArray().Take(bytesPeeked), readStorage.ToArray().Take(bytesPeeked));

            // A stream should never be able to peek more than it can read.
            Assert.True(bytesRead >= bytesPeeked);

            return(bytesRead - bytesPeeked);
        }