public void BufferCompareTo() { // Fill the this.random stuff var value = new byte[32]; this.random.NextBytes(value); // Prevent overflow / underflow if (value[0] == 0) { value[0]++; } else if (value[0] == 0xFF) { value[0]--; } this.buffer.SetIndex(0, value.Length); this.buffer.Set(0, value); Assert.Equal(0, ByteBufferUtil.Compare(this.buffer, Unpooled.WrappedBuffer(value))); value[0]++; Assert.True(ByteBufferUtil.Compare(this.buffer, Unpooled.WrappedBuffer(value)) < 0); value[0] -= 2; Assert.True(ByteBufferUtil.Compare(this.buffer, Unpooled.WrappedBuffer(value)) > 0); value[0]++; Assert.True(ByteBufferUtil.Compare(this.buffer, Unpooled.WrappedBuffer(value, 0, 31)) > 0); Assert.True(ByteBufferUtil.Compare(this.buffer.Slice(0, 31), Unpooled.WrappedBuffer(value)) < 0); }
public void TestCopyingToOutputStream() { IByteBuffer buf1 = Unpooled.DirectBuffer(10); IByteBuffer buf2 = Unpooled.Buffer(10); IByteBuffer buf3 = Unpooled.DirectBuffer(10); buf1.WriteBytes(Encoding.ASCII.GetBytes("a")); buf2.WriteBytes(Encoding.ASCII.GetBytes("b")); buf3.WriteBytes(Encoding.ASCII.GetBytes("c")); IByteBuffer composite = Unpooled.WrappedUnmodifiableBuffer(buf1, buf2, buf3); IByteBuffer copy = Unpooled.DirectBuffer(3); IByteBuffer copy2 = Unpooled.Buffer(3); var copyStream = new ByteBufferStream(copy); var copy2Stream = new ByteBufferStream(copy2); try { composite.GetBytes(0, copyStream, 3); composite.GetBytes(0, copy2Stream, 3); Assert.Equal(0, ByteBufferUtil.Compare(copy, composite)); Assert.Equal(0, ByteBufferUtil.Compare(copy2, composite)); Assert.Equal(0, ByteBufferUtil.Compare(copy, copy2)); } finally { copy.Release(); copy2.Release(); copyStream.Close(); copy2Stream.Close(); composite.Release(); } }
public void Compare2() { Assert.True(ByteBufferUtil.Compare( WrappedBuffer(new[] { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF }), WrappedBuffer(new [] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 })) > 0); Assert.True(ByteBufferUtil.Compare( WrappedBuffer(new [] { (byte)0xFF }), WrappedBuffer(new [] { (byte)0x00 })) > 0); }
public void TestCompare2() { IByteBuffer expected = WrappedBuffer(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }); IByteBuffer actual = WrappedBuffer(new byte[] { 0x00, 0x00, 0x00, 0x00 }); Assert.True(ByteBufferUtil.Compare(expected, actual) > 0); expected.Release(); actual.Release(); expected = WrappedBuffer(new byte[] { 0xFF }); actual = WrappedBuffer(new byte[] { 0x00 }); Assert.True(ByteBufferUtil.Compare(expected, actual) > 0); expected.Release(); actual.Release(); }
public void Compare() { IList <IByteBuffer> expected = new List <IByteBuffer>(); expected.Add(WrappedBuffer(new byte[] { 1 })); expected.Add(WrappedBuffer(new byte[] { 1, 2 })); expected.Add(WrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })); expected.Add(WrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 })); expected.Add(WrappedBuffer(new byte[] { 2 })); expected.Add(WrappedBuffer(new byte[] { 2, 3 })); expected.Add(WrappedBuffer(new byte[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 })); expected.Add(WrappedBuffer(new byte[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 })); expected.Add(WrappedBuffer(new byte[] { 2, 3, 4 }, 1, 1)); expected.Add(WrappedBuffer(new byte[] { 1, 2, 3, 4 }, 2, 2)); expected.Add(WrappedBuffer(new byte[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, 1, 10)); expected.Add(WrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, 2, 12)); expected.Add(WrappedBuffer(new byte[] { 2, 3, 4, 5 }, 2, 1)); expected.Add(WrappedBuffer(new byte[] { 1, 2, 3, 4, 5 }, 3, 2)); expected.Add(WrappedBuffer(new byte[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, 2, 10)); expected.Add(WrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 3, 12)); for (int i = 0; i < expected.Count; i++) { for (int j = 0; j < expected.Count; j++) { if (i == j) { Assert.Equal(0, ByteBufferUtil.Compare(expected[i], expected[j])); } else if (i < j) { Assert.True(ByteBufferUtil.Compare(expected[i], expected[j]) < 0); } else { Assert.True(ByteBufferUtil.Compare(expected[i], expected[j]) > 0); } } } foreach (IByteBuffer buffer in expected) { buffer.Release(); } }
public void TestCopyingToOtherBuffer() { IByteBuffer buf1 = Unpooled.DirectBuffer(10); IByteBuffer buf2 = Unpooled.Buffer(10); IByteBuffer buf3 = Unpooled.DirectBuffer(10); buf1.WriteBytes(Encoding.ASCII.GetBytes("a")); buf2.WriteBytes(Encoding.ASCII.GetBytes("b")); buf3.WriteBytes(Encoding.ASCII.GetBytes("c")); IByteBuffer composite = Unpooled.WrappedUnmodifiableBuffer(buf1, buf2, buf3); IByteBuffer copy = Unpooled.DirectBuffer(3); IByteBuffer copy2 = Unpooled.Buffer(3); copy.SetBytes(0, composite, 0, 3); copy2.SetBytes(0, composite, 0, 3); copy.SetWriterIndex(3); copy2.SetWriterIndex(3); Assert.Equal(0, ByteBufferUtil.Compare(copy, composite)); Assert.Equal(0, ByteBufferUtil.Compare(copy2, composite)); Assert.Equal(0, ByteBufferUtil.Compare(copy, copy2)); copy.Release(); copy2.Release(); composite.Release(); }