2016-05-11 13:54:20 -04:00
|
|
|
package io_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/common/alloc"
|
|
|
|
. "v2ray.com/core/common/io"
|
|
|
|
"v2ray.com/core/testing/assert"
|
2016-05-11 13:54:20 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAdaptiveReader(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2016-05-11 13:54:20 -04:00
|
|
|
|
|
|
|
rawContent := make([]byte, 1024*1024)
|
2016-12-02 09:06:04 -05:00
|
|
|
buffer := bytes.NewBuffer(rawContent)
|
2016-05-11 13:54:20 -04:00
|
|
|
|
2016-12-02 09:06:04 -05:00
|
|
|
reader := NewAdaptiveReader(buffer)
|
2016-05-11 13:54:20 -04:00
|
|
|
b1, err := reader.Read()
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
assert.Bool(b1.IsFull()).IsTrue()
|
|
|
|
assert.Int(b1.Len()).Equals(alloc.BufferSize)
|
2016-12-02 09:06:04 -05:00
|
|
|
assert.Int(buffer.Len()).Equals(cap(rawContent) - alloc.BufferSize)
|
|
|
|
|
|
|
|
b2, err := reader.Read()
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
assert.Bool(b2.IsFull()).IsTrue()
|
2016-12-08 10:52:18 -05:00
|
|
|
assert.Int(buffer.Len()).Equals(1007616)
|
2016-05-11 13:54:20 -04:00
|
|
|
}
|