示例#1
0
        public void TestReadAndReadLine()
        {
            var data = new byte[] {0x00, 0x01, 0x02, 0x03, Octets.CR, Octets.LF, 0x04, 0x05};
              var stream = new StrictLineOrientedStream(new MemoryStream(data), 8);
              var buffer = new byte[8];

              stream.Read(buffer, 0, 5);

              Assert.AreEqual(ArrayExtensions.Slice(data, 0, 5), ArrayExtensions.Slice(buffer, 0, 5));
              Assert.AreEqual(ArrayExtensions.Slice(data, 5, 3), stream.ReadLine());
              Assert.IsNull(stream.ReadLine());
        }
示例#2
0
        public void TestReadToStreamBufferEmpty()
        {
            var data = new byte[] {0x00, 0x01, Octets.CR, Octets.LF, 0x02, 0x03, 0x04, Octets.CR, Octets.LF, 0x05, 0x06, 0x07};
              var stream = new StrictLineOrientedStream(new MemoryStream(data), 8);

              var copyStream = new MemoryStream();

              stream.Read(copyStream, 12L);

              copyStream.Close();

              Assert.AreEqual(data, copyStream.ToArray());
        }
示例#3
0
        public void TestReadToStreamLessThanBuffered()
        {
            var data = new byte[] {0x00, 0x01, Octets.CR, Octets.LF, 0x02, 0x03, 0x04, Octets.CR, Octets.LF, 0x05, 0x06, 0x07};
              var stream = new StrictLineOrientedStream(new MemoryStream(data), 16);

              var line = stream.ReadLine(true);

              Assert.AreEqual(data.Slice(0, 4), line);

              var copyStream = new MemoryStream();

              stream.Read(copyStream, 4L);

              copyStream.Close();

              Assert.AreEqual(data.Slice(4, 4), copyStream.ToArray());
        }