Browse Source

Test case for buffer

V2Ray 10 năm trước cách đây
mục cha
commit
1652b3f7f0
1 tập tin đã thay đổi với 33 bổ sung0 xóa
  1. 33 0
      common/alloc/buffer_test.go

+ 33 - 0
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()
+}