You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/common/buf/multi_buffer_test.go

50 lines
860 B

8 years ago
package buf_test
import (
7 years ago
"crypto/rand"
7 years ago
"io"
8 years ago
"testing"
7 years ago
"v2ray.com/core/common"
8 years ago
. "v2ray.com/core/common/buf"
. "v2ray.com/ext/assert"
8 years ago
)
func TestMultiBufferRead(t *testing.T) {
assert := With(t)
8 years ago
b1 := New()
b1.WriteString("ab")
8 years ago
b2 := New()
b2.WriteString("cd")
mb := MultiBuffer{b1, b2}
8 years ago
bs := make([]byte, 32)
_, nBytes := SplitBytes(mb, bs)
assert(nBytes, Equals, 4)
assert(bs[:nBytes], Equals, []byte("abcd"))
8 years ago
}
func TestMultiBufferAppend(t *testing.T) {
assert := With(t)
var mb MultiBuffer
b := New()
b.WriteString("ab")
mb = append(mb, b)
assert(mb.Len(), Equals, int32(2))
}
7 years ago
func TestMultiBufferSliceBySizeLarge(t *testing.T) {
assert := With(t)
lb := make([]byte, 8*1024)
common.Must2(io.ReadFull(rand.Reader, lb))
7 years ago
mb := MergeBytes(nil, lb)
7 years ago
mb, mb2 := SplitSize(mb, 1024)
assert(mb2.Len(), Equals, int32(1024))
7 years ago
}