2017-04-15 19:07:23 +00:00
|
|
|
package buf_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "v2ray.com/core/common/buf"
|
2017-10-24 14:15:35 +00:00
|
|
|
. "v2ray.com/ext/assert"
|
2017-04-15 19:07:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMultiBufferRead(t *testing.T) {
|
2017-10-24 14:15:35 +00:00
|
|
|
assert := With(t)
|
2017-04-15 19:07:23 +00:00
|
|
|
|
|
|
|
b1 := New()
|
|
|
|
b1.AppendBytes('a', 'b')
|
|
|
|
|
|
|
|
b2 := New()
|
|
|
|
b2.AppendBytes('c', 'd')
|
|
|
|
mb := NewMultiBufferValue(b1, b2)
|
|
|
|
|
|
|
|
bs := make([]byte, 32)
|
|
|
|
nBytes, err := mb.Read(bs)
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(err, IsNil)
|
|
|
|
assert(nBytes, Equals, 4)
|
|
|
|
assert(bs[:nBytes], Equals, []byte("abcd"))
|
2017-04-15 19:07:23 +00:00
|
|
|
}
|
2017-04-20 13:02:35 +00:00
|
|
|
|
|
|
|
func TestMultiBufferAppend(t *testing.T) {
|
2017-10-24 14:15:35 +00:00
|
|
|
assert := With(t)
|
2017-04-20 13:02:35 +00:00
|
|
|
|
|
|
|
var mb MultiBuffer
|
|
|
|
b := New()
|
|
|
|
b.AppendBytes('a', 'b')
|
|
|
|
mb.Append(b)
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(mb.Len(), Equals, 2)
|
2017-04-20 13:02:35 +00:00
|
|
|
}
|