mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-30 14:05:26 -05:00
size encoder and decoder
This commit is contained in:
44
common/crypto/chunk_test.go
Normal file
44
common/crypto/chunk_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package crypto_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"v2ray.com/core/common/buf"
|
||||
. "v2ray.com/core/common/crypto"
|
||||
"v2ray.com/core/testing/assert"
|
||||
)
|
||||
|
||||
func TestChunkStreamIO(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
||||
cache := buf.NewLocal(8192)
|
||||
|
||||
writer := NewChunkStreamWriter(PlainChunkSizeParser{}, cache)
|
||||
reader := NewChunkStreamReader(PlainChunkSizeParser{}, cache)
|
||||
|
||||
b := buf.New()
|
||||
b.AppendBytes('a', 'b', 'c', 'd')
|
||||
assert.Error(writer.Write(buf.NewMultiBufferValue(b))).IsNil()
|
||||
|
||||
b = buf.New()
|
||||
b.AppendBytes('e', 'f', 'g')
|
||||
assert.Error(writer.Write(buf.NewMultiBufferValue(b))).IsNil()
|
||||
|
||||
assert.Error(writer.Write(buf.NewMultiBuffer())).IsNil()
|
||||
|
||||
assert.Int(cache.Len()).Equals(13)
|
||||
|
||||
mb, err := reader.Read()
|
||||
assert.Error(err).IsNil()
|
||||
assert.Int(mb.Len()).Equals(4)
|
||||
assert.Bytes(mb[0].Bytes()).Equals([]byte("abcd"))
|
||||
|
||||
mb, err = reader.Read()
|
||||
assert.Error(err).IsNil()
|
||||
assert.Int(mb.Len()).Equals(3)
|
||||
assert.Bytes(mb[0].Bytes()).Equals([]byte("efg"))
|
||||
|
||||
_, err = reader.Read()
|
||||
assert.Error(err).Equals(io.EOF)
|
||||
}
|
||||
Reference in New Issue
Block a user