2016-05-11 13:54:20 -04:00
|
|
|
package io_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core/common/alloc"
|
|
|
|
. "github.com/v2ray/v2ray-core/common/io"
|
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
reader := NewAdaptiveReader(bytes.NewBuffer(rawContent))
|
|
|
|
b1, err := reader.Read()
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
assert.Bool(b1.IsFull()).IsTrue()
|
|
|
|
assert.Int(b1.Len()).Equals(alloc.BufferSize)
|
|
|
|
|
|
|
|
b2, err := reader.Read()
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
assert.Bool(b2.IsFull()).IsTrue()
|
|
|
|
assert.Int(b2.Len()).Equals(alloc.LargeBufferSize)
|
|
|
|
}
|