示例#1
0
        public void bytebuf_base_setoffset_test()
        {
            IByteBuf buf = new AbstructByteBuf(256);

            buf.SetOffset(1);
            Assert.AreEqual(buf.Offset, 1);
            Assert.AreEqual(buf.Capacity, 255);

            try
            {
                buf.SetOffset(-1);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
            }

            try
            {
                buf.SetOffset(256);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
            }
        }
示例#2
0
        public void bytebuf_write_array_test()
        {
            IByteBuf buf = new AbstructByteBuf(256);

            byte[] arr = { 0, 1, 2, 3, 4 };

            buf.SetOffset(1);
            buf.Write(arr);

            Assert.AreEqual(buf.Offset, 1);
            Assert.AreEqual(buf.ReadIndex, 1);
            Assert.AreEqual(buf.WriteIndex, 6);
            Assert.AreEqual(buf.Readables(), 5);
            Assert.AreEqual(buf.Writeables(), 250);
        }
示例#3
0
        public void bytebuf_write_bytebuf_offset_test()
        {
            var buf1 = new AbstructByteBuf(256);
            var buf2 = new AbstructByteBuf(9);

            for (byte i = 0; i < 9; i++)
            {
                buf2.WriteByte(i);
            }

            buf1.SetOffset(1);
            buf1.Write(buf2, 7);

            Assert.AreEqual(buf1.Offset, 1);
            Assert.AreEqual(buf1.ReadIndex, 1);
            Assert.AreEqual(buf1.WriteIndex, 8);
            Assert.AreEqual(buf1.Readables(), 7);
            Assert.AreEqual(buf1.Writeables(), 248);
        }
示例#4
0
        public void bytebuf_base_return_test()
        {
            IByteBuf buf = new AbstructByteBuf(4);

            buf.SetOffset(1).WriteByte(1).ReadByte();

            Assert.AreEqual(buf.Offset, 1);
            Assert.AreEqual(buf.ReadIndex, 2);
            Assert.AreEqual(buf.WriteIndex, 2);
            Assert.AreEqual(buf.Readables(), 0);
            Assert.AreEqual(buf.Writeables(), 2);
            Assert.AreEqual(buf.Capacity, 3);

            buf.Return();

            Assert.AreEqual(buf.Offset, 0);
            Assert.AreEqual(buf.ReadIndex, 0);
            Assert.AreEqual(buf.WriteIndex, 0);
            Assert.AreEqual(buf.Readables(), 0);
            Assert.AreEqual(buf.Writeables(), 0);
            Assert.AreEqual(buf.Capacity, 0);
            Assert.AreEqual(buf.GetBytes(), AbstructByteBuf.Emtpy);
        }
示例#5
0
        public void bytebuf_writeread_int_test()
        {
            IByteBuf buf = new AbstructByteBuf(256);

            buf.SetOffset(1);
            buf.Write(1);

            Assert.AreEqual(buf.Offset, 1);
            Assert.AreEqual(buf.ReadIndex, 1);
            Assert.AreEqual(buf.WriteIndex, 5);
            Assert.AreEqual(buf.Readables(), 4);
            Assert.AreEqual(buf.Writeables(), 251);

            int b = buf.ReadInt32();

            Assert.AreEqual(b, 1);

            Assert.AreEqual(buf.Offset, 1);
            Assert.AreEqual(buf.ReadIndex, 5);
            Assert.AreEqual(buf.WriteIndex, 5);
            Assert.AreEqual(buf.Readables(), 0);
            Assert.AreEqual(buf.Writeables(), 251);
        }
示例#6
0
        public void bytebuf_writeread_byte_test()
        {
            IByteBuf buf = new AbstructByteBuf(256);

            buf.SetOffset(1);
            buf.WriteByte((byte)1);

            Assert.AreEqual(buf.Offset, 1);
            Assert.AreEqual(buf.ReadIndex, 1);
            Assert.AreEqual(buf.WriteIndex, 2);
            Assert.AreEqual(buf.Readables(), 1);
            Assert.AreEqual(buf.Writeables(), 254);

            byte b1 = buf.ReadByte();

            Assert.AreEqual(b1, 1);

            Assert.AreEqual(buf.Offset, 1);
            Assert.AreEqual(buf.ReadIndex, 2);
            Assert.AreEqual(buf.WriteIndex, 2);
            Assert.AreEqual(buf.Readables(), 0);
            Assert.AreEqual(buf.Writeables(), 254);
        }