public void TestAvailable()
        {
            ByteQueueStream input = new ByteQueueStream();

            // buffer is empty
            Assert.AreEqual(0, input.Available);

            // after adding once
            input.Write(new byte[10]);
            Assert.AreEqual(10, input.Available);

            // after adding more than once
            input.Write(new byte[5]);
            Assert.AreEqual(15, input.Available);

            // after reading a single byte
            input.ReadByte();
            Assert.AreEqual(14, input.Available);

            // after reading into a byte array
            input.Read(new byte[4]);
            Assert.AreEqual(10, input.Available);

            input.Close(); // so compiler doesn't whine about a resource leak
        }
Exemple #2
0
        public void TestAvailable()
        {
            ByteQueueStream input = new ByteQueueStream();

            // buffer is empty
            Assert.AreEqual(0, input.Available);

            // after adding once
            input.Write(new byte[10]);
            Assert.AreEqual(10, input.Available);

            // after adding more than once
            input.Write(new byte[5]);
            Assert.AreEqual(15, input.Available);

            // after reading a single byte
            input.ReadByte();
            Assert.AreEqual(14, input.Available);

            // after reading into a byte array
            input.Read(new byte[4]);
            Assert.AreEqual(10, input.Available);

            input.Close(); // so compiler doesn't whine about a resource leak
        }
Exemple #3
0
 public virtual int ReadOutput(byte[] buffer, int offset, int length)
 {
     if (mBlocking)
     {
         throw new InvalidOperationException("Cannot use ReadOutput() in blocking mode! Use Stream instead.");
     }
     return(mOutputBuffer.Read(buffer, offset, length));
 }
Exemple #4
0
        public void TestReadArray()
        {
            ByteQueueStream input = new ByteQueueStream();

            input.Write(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });

            byte[] buffer = new byte[5];

            // read less than available into specified position
            Assert.AreEqual(1, input.Read(buffer, 2, 1));
            AssertArrayEquals(new byte[] { 0x00, 0x00, 0x01, 0x00, 0x00 }, buffer);

            // read equal to available
            Assert.AreEqual(5, input.Read(buffer));
            AssertArrayEquals(new byte[] { 0x02, 0x03, 0x04, 0x05, 0x06 }, buffer);

            // read more than available
            input.Write(new byte[] { 0x01, 0x02, 0x03 });
            Assert.AreEqual(3, input.Read(buffer));
            AssertArrayEquals(new byte[] { 0x01, 0x02, 0x03, 0x05, 0x06 }, buffer);

            input.Close(); // so compiler doesn't whine about a resource leak
        }
        public void TestReadArray()
        {
            ByteQueueStream input = new ByteQueueStream();
            input.Write(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });

            byte[] buffer = new byte[5];

            // read less than available into specified position
            Assert.AreEqual(1, input.Read(buffer, 2, 1));
            AssertArrayEquals(new byte[]{ 0x00, 0x00, 0x01, 0x00, 0x00 }, buffer);

            // read equal to available
            Assert.AreEqual(5, input.Read(buffer));
            AssertArrayEquals(new byte[]{ 0x02, 0x03, 0x04, 0x05, 0x06 }, buffer);

            // read more than available
            input.Write(new byte[]{ 0x01, 0x02, 0x03 });
            Assert.AreEqual(3, input.Read(buffer));
            AssertArrayEquals(new byte[]{ 0x01, 0x02, 0x03, 0x05, 0x06 }, buffer);

            input.Close(); // so compiler doesn't whine about a resource leak
        }