コード例 #1
0
        public void ReadBytesTest()
        {
            int bufferLength = 10;
            int chunkSize    = 2;

            byte[] input  = new byte[bufferLength];
            byte[] output = new byte[bufferLength];
            byte[] chunk  = new byte[chunkSize];

            for (int index = 0; index < bufferLength; index++)
            {
                input[index]  = (byte)(index + 10);
                output[index] = 0xff;
            }

            WangStream wangStream = new WangStream(input);
            int        read       = 0;

            while (wangStream.AvailableBytes() != 0)
            {
                Assert.IsFalse(wangStream.IsEnd());
                wangStream.ReadBytes(chunk, chunkSize);
                Array.Copy(chunk, 0, output, read, chunkSize);
                read += chunkSize;
            }

            Assert.IsTrue(wangStream.IsEnd());
            Assert.AreEqual(0, wangStream.AvailableBytes());
            Assert.AreEqual(bufferLength, output.Length);
            for (int index = 0; index < bufferLength; index++)
            {
                Assert.AreEqual(input[index], output[index]);
            }
        }
コード例 #2
0
        public void ReadInt32Test()
        {
            byte[] input = new byte[4] {
                0xff, 0xFF, 0xff, 0xFF
            };

            WangStream wangStream = new WangStream(input);

            Assert.IsFalse(wangStream.IsEnd());
            Assert.AreEqual(-1, wangStream.ReadInt32());
            Assert.AreEqual(0, wangStream.AvailableBytes());
            Assert.IsTrue(wangStream.IsEnd());
            Assert.AreEqual(0, wangStream.AvailableBytes());
        }
コード例 #3
0
        public void SkipBytesTest()
        {
            byte[] input = new byte[4] {
                1, 2, 3, 4
            };
            WangStream wangStream = new WangStream(input);

            Assert.IsFalse(wangStream.IsEnd());
            wangStream.SkipBytes(2);
            Assert.IsFalse(wangStream.IsEnd());
            Assert.AreEqual(2, wangStream.AvailableBytes());
            Assert.AreEqual(3, wangStream.ReadByte());
            Assert.IsFalse(wangStream.IsEnd());
            Assert.AreEqual(1, wangStream.AvailableBytes());
        }
コード例 #4
0
        public void ReadByteTest()
        {
            byte[] input = new byte[3] {
                1, 2, 3
            };

            WangStream wangStream = new WangStream(input);

            for (int index = 0; index < input.Length; index++)
            {
                Assert.IsFalse(wangStream.IsEnd());
                Assert.AreEqual(input.Length - index, wangStream.AvailableBytes());
                Assert.AreEqual(input[index], wangStream.ReadByte());
            }
            Assert.IsTrue(wangStream.IsEnd());
            Assert.AreEqual(0, wangStream.AvailableBytes());
        }