1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/common/bufio/reader_test.go

38 lines
735 B
Go
Raw Normal View History

2016-12-09 07:17:34 -05:00
package bufio_test
2016-02-26 17:45:33 -05:00
import (
2016-12-09 06:08:25 -05:00
"crypto/rand"
2016-02-26 17:45:33 -05:00
"testing"
2016-12-09 05:35:27 -05:00
"v2ray.com/core/common/buf"
2016-12-09 07:17:34 -05:00
. "v2ray.com/core/common/bufio"
2016-08-20 14:55:45 -04:00
"v2ray.com/core/testing/assert"
2016-02-26 17:45:33 -05:00
)
func TestBufferedReader(t *testing.T) {
2016-05-24 15:55:46 -04:00
assert := assert.On(t)
2016-02-26 17:45:33 -05:00
2016-12-09 06:08:25 -05:00
content := buf.New()
2016-12-21 09:37:16 -05:00
assert.Error(content.AppendSupplier(buf.ReadFrom(rand.Reader))).IsNil()
2016-12-06 05:03:42 -05:00
2016-02-26 17:45:33 -05:00
len := content.Len()
2016-12-09 07:17:34 -05:00
reader := NewReader(content)
2016-02-26 17:45:33 -05:00
assert.Bool(reader.Cached()).IsTrue()
payload := make([]byte, 16)
nBytes, err := reader.Read(payload)
assert.Int(nBytes).Equals(16)
assert.Error(err).IsNil()
len2 := content.Len()
assert.Int(len - len2).GreaterThan(16)
nBytes, err = reader.Read(payload)
assert.Int(nBytes).Equals(16)
assert.Error(err).IsNil()
assert.Int(content.Len()).Equals(len2)
}