2017-03-27 09:26:44 +00:00
|
|
|
package buf_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
. "v2ray.com/core/common/buf"
|
|
|
|
"v2ray.com/core/testing/assert"
|
|
|
|
"v2ray.com/core/transport/ray"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMergingReader(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
|
|
|
stream := ray.NewStream(context.Background())
|
|
|
|
b1 := New()
|
|
|
|
b1.AppendBytes('a', 'b', 'c')
|
2017-04-15 19:07:23 +00:00
|
|
|
stream.Write(NewMultiBufferValue(b1))
|
2017-03-27 09:26:44 +00:00
|
|
|
|
|
|
|
b2 := New()
|
|
|
|
b2.AppendBytes('e', 'f', 'g')
|
2017-04-15 19:07:23 +00:00
|
|
|
stream.Write(NewMultiBufferValue(b2))
|
2017-03-27 09:26:44 +00:00
|
|
|
|
|
|
|
b3 := New()
|
|
|
|
b3.AppendBytes('h', 'i', 'j')
|
2017-04-15 19:07:23 +00:00
|
|
|
stream.Write(NewMultiBufferValue(b3))
|
2017-03-27 09:26:44 +00:00
|
|
|
|
|
|
|
reader := NewMergingReader(stream)
|
|
|
|
b, err := reader.Read()
|
|
|
|
assert.Error(err).IsNil()
|
2017-04-15 19:07:23 +00:00
|
|
|
assert.Int(b.Len()).Equals(9)
|
2017-03-27 09:26:44 +00:00
|
|
|
}
|