public void bytebuf_base_init_test() { IByteBuf buf = new AbstructByteBuf(256); Assert.AreEqual(buf.Capacity, 256); Assert.AreEqual(buf.ReadIndex, 0); Assert.AreEqual(buf.WriteIndex, 0); Assert.AreEqual(buf.Readables(), 0); Assert.AreEqual(buf.Writeables(), 256); }
public void bytebuf_base_init_setbytes_offset_test() { IByteBuf buf = new AbstructByteBuf(); byte[] arr = new byte[256]; buf.SetBytes(arr, 10, 64); Assert.AreEqual(buf.Offset, 10); Assert.AreEqual(buf.ReadIndex, 10); Assert.AreEqual(buf.WriteIndex, 10); Assert.AreEqual(buf.Readables(), 0); Assert.AreEqual(buf.Writeables(), 64); }
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); }
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); }
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); }
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); }
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); }