v2ray-core/common/buf/reader_test.go

29 lines
601 B
Go
Raw Normal View History

2016-12-09 12:17:34 +00:00
package buf_test
2016-05-11 17:54:20 +00:00
import (
"bytes"
"testing"
2016-12-09 12:17:34 +00:00
. "v2ray.com/core/common/buf"
2016-08-20 18:55:45 +00:00
"v2ray.com/core/testing/assert"
2016-05-11 17:54:20 +00:00
)
func TestAdaptiveReader(t *testing.T) {
2016-05-24 19:55:46 +00:00
assert := assert.On(t)
2016-05-11 17:54:20 +00:00
rawContent := make([]byte, 1024*1024)
buffer := bytes.NewBuffer(rawContent)
2016-05-11 17:54:20 +00:00
2016-12-09 12:17:34 +00:00
reader := NewReader(buffer)
2016-05-11 17:54:20 +00:00
b1, err := reader.Read()
assert.Error(err).IsNil()
assert.Bool(b1.IsFull()).IsTrue()
2016-12-09 12:17:34 +00:00
assert.Int(b1.Len()).Equals(Size)
assert.Int(buffer.Len()).Equals(cap(rawContent) - Size)
b2, err := reader.Read()
assert.Error(err).IsNil()
assert.Bool(b2.IsFull()).IsTrue()
2016-12-08 15:52:18 +00:00
assert.Int(buffer.Len()).Equals(1007616)
2016-05-11 17:54:20 +00:00
}