mirror of https://github.com/v2ray/v2ray-core
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.
38 lines
875 B
38 lines
875 B
package io_test
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/rand"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/v2ray/v2ray-core/common/alloc"
|
|
. "github.com/v2ray/v2ray-core/common/io"
|
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
|
)
|
|
|
|
func TestReaderAndWrite(t *testing.T) {
|
|
v2testing.Current(t)
|
|
|
|
size := 1024 * 1024
|
|
buffer := make([]byte, size)
|
|
nBytes, err := rand.Read(buffer)
|
|
assert.Int(nBytes).Equals(len(buffer))
|
|
assert.Error(err).IsNil()
|
|
|
|
readerBuffer := bytes.NewReader(buffer)
|
|
writerBuffer := bytes.NewBuffer(make([]byte, 0, size))
|
|
|
|
transportChan := make(chan *alloc.Buffer, 1024)
|
|
|
|
err = ReaderToChan(transportChan, NewAdaptiveReader(readerBuffer))
|
|
assert.Error(err).Equals(io.EOF)
|
|
close(transportChan)
|
|
|
|
err = ChanToRawWriter(writerBuffer, transportChan)
|
|
assert.Error(err).IsNil()
|
|
|
|
assert.Bytes(buffer).Equals(writerBuffer.Bytes())
|
|
}
|