From 1652b3f7f01a8eb0b1bb0cec2dcbcd0d50f1a0b3 Mon Sep 17 00:00:00 2001 From: V2Ray Date: Sat, 10 Oct 2015 22:15:10 +0200 Subject: [PATCH] Test case for buffer --- common/alloc/buffer_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 common/alloc/buffer_test.go diff --git a/common/alloc/buffer_test.go b/common/alloc/buffer_test.go new file mode 100644 index 000000000..ab3da3c4f --- /dev/null +++ b/common/alloc/buffer_test.go @@ -0,0 +1,33 @@ +package alloc + +import ( + "testing" + + "github.com/v2ray/v2ray-core/testing/unit" +) + +func TestBufferClear(t *testing.T) { + assert := unit.Assert(t) + + buffer := NewBuffer().Clear() + defer buffer.Release() + + payload := "Bytes" + buffer.Append([]byte(payload)) + assert.Int(buffer.Len()).Equals(len(payload)) + + buffer.Clear() + assert.Int(buffer.Len()).Equals(0) +} + +func TestBufferIsFull(t *testing.T) { + assert := unit.Assert(t) + + buffer := NewBuffer() + defer buffer.Release() + + assert.Bool(buffer.IsFull()).IsTrue() + + buffer.Clear() + assert.Bool(buffer.IsFull()).IsFalse() +}