2015-10-10 16:15:10 -04:00
|
|
|
package alloc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-12-02 09:27:18 -05:00
|
|
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
2015-10-10 16:15:10 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBufferClear(t *testing.T) {
|
2015-12-02 09:27:18 -05:00
|
|
|
v2testing.Current(t)
|
2015-10-10 16:15:10 -04:00
|
|
|
|
|
|
|
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) {
|
2015-12-02 09:27:18 -05:00
|
|
|
v2testing.Current(t)
|
2015-10-10 16:15:10 -04:00
|
|
|
|
|
|
|
buffer := NewBuffer()
|
|
|
|
defer buffer.Release()
|
|
|
|
|
|
|
|
assert.Bool(buffer.IsFull()).IsTrue()
|
|
|
|
|
|
|
|
buffer.Clear()
|
|
|
|
assert.Bool(buffer.IsFull()).IsFalse()
|
|
|
|
}
|