Exemple #1
0
        public void PeekAtEndOfStreamThenReadBytes()
        {
            var str = "abcdefghijkl";

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                using (var bs = new BencodeStream(ms))
                {
                    bs.Read(12);
                    Assert.Equal(-1, bs.Peek());
                    Assert.Equal(0, bs.Read(4).Length);
                }
        }
Exemple #2
0
        public void EndOfStream()
        {
            var str = "Hello World!";

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                using (var bs = new BencodeStream(ms))
                {
                    bs.Read(12);
                    Assert.True(bs.EndOfStream);
                    Assert.Equal(-1, bs.Read());
                }
        }
Exemple #3
0
        public void ReadUnnaffectedByReadPrevious()
        {
            var str = "abcdefghijkl";

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                using (var bs = new BencodeStream(ms))
                {
                    Assert.Equal('a', bs.Read());
                    bs.ReadPrevious();
                    Assert.Equal('b', bs.Read());
                }
        }
Exemple #4
0
        public void ReadChangeStreamPosition()
        {
            var str = "Hello World!";

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                using (var bs = new BencodeStream(ms))
                {
                    Assert.Equal('H', bs.Read());
                    Assert.Equal('e', bs.Read());
                    bs.Position -= 1;
                    Assert.Equal('e', bs.Read());
                }
        }
Exemple #5
0
 public void ReadMoreBytesThanInStream()
 {
     using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("Hello World!")))
         using (var bs = new BencodeStream(ms))
         {
             var bytes = bs.Read(20);
             Assert.Equal(12, bytes.Length);
             Assert.Equal("Hello World!", Encoding.UTF8.GetString(bytes));
         }
 }
Exemple #6
0
 public void ReadZeroBytes()
 {
     using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("Hello World!")))
         using (var bs = new BencodeStream(ms))
         {
             var bytes = bs.Read(0);
             Assert.Equal(0, bytes.Length);
             Assert.Equal("", Encoding.UTF8.GetString(bytes));
         }
 }
Exemple #7
0
        public void PeekAreChangedAfterReadSingleByte()
        {
            var str = "abcdefghijkl";

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                using (var bs = new BencodeStream(ms))
                {
                    byte[] bytes;

                    Assert.Equal('a', bs.Peek());

                    bytes = bs.Read(1);
                    Assert.Equal('a', (char)bytes[0]);
                    Assert.Equal('b', bs.Peek());

                    bytes = bs.Read(1);
                    Assert.Equal('b', (char)bytes[0]);
                    Assert.Equal('c', bs.Peek());
                }
        }
Exemple #8
0
        public void PeekAndReadEqual()
        {
            var str = "Hello World!";

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                using (var bs = new BencodeStream(ms))
                {
                    Assert.Equal('H', bs.Peek());
                    Assert.Equal('H', bs.Read());
                }
        }
Exemple #9
0
        public void ReadPreviousChar()
        {
            var str = "Hello World!";

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                using (var bs = new BencodeStream(ms))
                {
                    Assert.Equal(default(char), bs.ReadPreviousChar());
                    bs.Read(1);
                    Assert.Equal('H', bs.ReadPreviousChar());
                }
        }
Exemple #10
0
        public void ReadPreviousUnaffectedByPeek()
        {
            var str = "Hello World!";

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                using (var bs = new BencodeStream(ms))
                {
                    bs.Read(1);
                    Assert.Equal('H', bs.ReadPrevious());
                    Assert.Equal('e', bs.Peek());
                    Assert.Equal('H', bs.ReadPrevious());
                }
        }
Exemple #11
0
        public void PeekAreChangedAfterRead()
        {
            var str = "abcdefghijkl";

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                using (var bs = new BencodeStream(ms))
                {
                    Assert.Equal('a', bs.Peek());
                    Assert.Equal('a', bs.Read());

                    Assert.Equal('b', bs.Peek());
                    Assert.Equal('b', bs.Read());

                    Assert.Equal('c', bs.Peek());
                    Assert.Equal('c', bs.Read());

                    Assert.Equal('d', bs.Peek());
                    Assert.Equal('d', bs.Read());

                    Assert.Equal('e', bs.Peek());
                    Assert.Equal('e', bs.Read());
                }
        }
Exemple #12
0
        public void ReadBytesChangesStreamPosition()
        {
            var str = "Hello World!";

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                using (var bs = new BencodeStream(ms))
                {
                    Assert.Equal(0, bs.Position);

                    var bytes = bs.Read(str.Length);
                    Assert.Equal(12, bytes.Length);
                    Assert.Equal(str, Encoding.UTF8.GetString(bytes));

                    Assert.Equal(12, bs.Position);
                }
        }
Exemple #13
0
        public void Read()
        {
            var str = "Hello World!";

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                using (var bs = new BencodeStream(ms))
                {
                    Assert.Equal('H', bs.Read());
                    Assert.Equal('e', bs.Read());
                    Assert.Equal('l', bs.Read());
                    Assert.Equal('l', bs.Read());
                    Assert.Equal('o', bs.Read());
                    Assert.Equal(' ', bs.Read());
                    Assert.Equal('W', bs.Read());
                    Assert.Equal('o', bs.Read());
                    Assert.Equal('r', bs.Read());
                    Assert.Equal('l', bs.Read());
                    Assert.Equal('d', bs.Read());
                    Assert.Equal('!', bs.Read());
                    Assert.Equal(-1, bs.Read());
                }
        }