2016-05-12 06:24:41 +00:00
|
|
|
package alloc_test
|
2015-10-10 20:15:10 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-05-12 06:24:41 +00:00
|
|
|
. "github.com/v2ray/v2ray-core/common/alloc"
|
2015-12-02 14:27:18 +00:00
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
2015-10-10 20:15:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBufferClear(t *testing.T) {
|
2016-05-24 19:55:46 +00:00
|
|
|
assert := assert.On(t)
|
2015-10-10 20:15:10 +00: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) {
|
2016-05-24 19:55:46 +00:00
|
|
|
assert := assert.On(t)
|
2015-10-10 20:15:10 +00:00
|
|
|
|
|
|
|
buffer := NewBuffer()
|
|
|
|
defer buffer.Release()
|
|
|
|
|
|
|
|
assert.Bool(buffer.IsFull()).IsTrue()
|
|
|
|
|
|
|
|
buffer.Clear()
|
|
|
|
assert.Bool(buffer.IsFull()).IsFalse()
|
|
|
|
}
|
2016-01-31 20:24:40 +00:00
|
|
|
|
|
|
|
func TestBufferPrepend(t *testing.T) {
|
2016-05-24 19:55:46 +00:00
|
|
|
assert := assert.On(t)
|
2016-01-31 20:24:40 +00:00
|
|
|
|
|
|
|
buffer := NewBuffer().Clear()
|
|
|
|
defer buffer.Release()
|
|
|
|
|
|
|
|
buffer.Append([]byte{'a', 'b', 'c'})
|
|
|
|
buffer.Prepend([]byte{'x', 'y', 'z'})
|
|
|
|
|
|
|
|
assert.Int(buffer.Len()).Equals(6)
|
|
|
|
assert.Bytes(buffer.Value).Equals([]byte("xyzabc"))
|
|
|
|
|
|
|
|
buffer.Prepend([]byte{'u', 'v', 'w'})
|
|
|
|
assert.Bytes(buffer.Value).Equals([]byte("uvwxyzabc"))
|
|
|
|
}
|
2016-04-29 21:47:42 +00:00
|
|
|
|
|
|
|
func TestBufferString(t *testing.T) {
|
2016-05-24 19:55:46 +00:00
|
|
|
assert := assert.On(t)
|
2016-04-29 21:47:42 +00:00
|
|
|
|
|
|
|
buffer := NewBuffer().Clear()
|
|
|
|
defer buffer.Release()
|
|
|
|
|
|
|
|
buffer.AppendString("Test String")
|
2016-05-24 19:55:46 +00:00
|
|
|
assert.String(buffer.String()).Equals("Test String")
|
2016-04-29 21:47:42 +00:00
|
|
|
}
|