1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-18 07:17:32 -05:00

more interface test

This commit is contained in:
Darien Raymond 2017-12-03 23:11:29 +01:00
parent b3e6994e52
commit 7709ee9b7f
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
5 changed files with 29 additions and 21 deletions

View File

@ -6,11 +6,6 @@ import (
"v2ray.com/core/common/errors" "v2ray.com/core/common/errors"
) )
var (
_ Reader = (*BytesToBufferReader)(nil)
_ io.Reader = (*BytesToBufferReader)(nil)
)
// BytesToBufferReader is a Reader that adjusts its reading speed automatically. // BytesToBufferReader is a Reader that adjusts its reading speed automatically.
type BytesToBufferReader struct { type BytesToBufferReader struct {
io.Reader io.Reader

View File

@ -70,3 +70,15 @@ func TestBytesReaderMultiBuffer(t *testing.T) {
assert(mb[0].String(), Equals, "abc") assert(mb[0].String(), Equals, "abc")
assert(mb[1].String(), Equals, "efg") assert(mb[1].String(), Equals, "efg")
} }
func TestReaderInterface(t *testing.T) {
assert := With(t)
assert((*BytesToBufferReader)(nil), Implements, (*io.Reader)(nil))
assert((*BytesToBufferReader)(nil), Implements, (*Reader)(nil))
assert((*BufferedReader)(nil), Implements, (*Reader)(nil))
assert((*BufferedReader)(nil), Implements, (*io.Reader)(nil))
assert((*BufferedReader)(nil), Implements, (*io.ByteReader)(nil))
assert((*BufferedReader)(nil), Implements, (*io.WriterTo)(nil))
}

View File

@ -6,12 +6,6 @@ import (
"v2ray.com/core/common/errors" "v2ray.com/core/common/errors"
) )
var (
_ io.ReaderFrom = (*BufferToBytesWriter)(nil)
_ io.Writer = (*BufferToBytesWriter)(nil)
_ Writer = (*BufferToBytesWriter)(nil)
)
// BufferToBytesWriter is a Writer that writes alloc.Buffer into underlying writer. // BufferToBytesWriter is a Writer that writes alloc.Buffer into underlying writer.
type BufferToBytesWriter struct { type BufferToBytesWriter struct {
io.Writer io.Writer
@ -39,13 +33,6 @@ func (w *BufferToBytesWriter) ReadFrom(reader io.Reader) (int64, error) {
return sc.Size, err return sc.Size, err
} }
var (
_ io.ReaderFrom = (*BufferedWriter)(nil)
_ io.Writer = (*BufferedWriter)(nil)
_ Writer = (*BufferedWriter)(nil)
_ io.ByteWriter = (*BufferedWriter)(nil)
)
// BufferedWriter is a Writer with internal buffer. // BufferedWriter is a Writer with internal buffer.
type BufferedWriter struct { type BufferedWriter struct {
writer Writer writer Writer
@ -173,7 +160,7 @@ func (w *seqWriter) WriteMultiBuffer(mb MultiBuffer) error {
return nil return nil
} }
type noOpWriter struct{} type noOpWriter byte
func (noOpWriter) WriteMultiBuffer(b MultiBuffer) error { func (noOpWriter) WriteMultiBuffer(b MultiBuffer) error {
b.Release() b.Release()
@ -203,8 +190,8 @@ func (noOpWriter) ReadFrom(reader io.Reader) (int64, error) {
var ( var (
// Discard is a Writer that swallows all contents written in. // Discard is a Writer that swallows all contents written in.
Discard Writer = noOpWriter{} Discard Writer = noOpWriter(0)
// DiscardBytes is an io.Writer that swallows all contents written in. // DiscardBytes is an io.Writer that swallows all contents written in.
DiscardBytes io.Writer = noOpWriter{} DiscardBytes io.Writer = noOpWriter(0)
) )

View File

@ -73,3 +73,16 @@ func TestDiscardBytesMultiBuffer(t *testing.T) {
assert(nBytes, Equals, int64(size)) assert(nBytes, Equals, int64(size))
assert(err, IsNil) assert(err, IsNil)
} }
func TestWriterInterface(t *testing.T) {
assert := With(t)
assert((*BufferToBytesWriter)(nil), Implements, (*Writer)(nil))
assert((*BufferToBytesWriter)(nil), Implements, (*io.Writer)(nil))
assert((*BufferToBytesWriter)(nil), Implements, (*io.ReaderFrom)(nil))
assert((*BufferedWriter)(nil), Implements, (*Writer)(nil))
assert((*BufferedWriter)(nil), Implements, (*io.Writer)(nil))
assert((*BufferedWriter)(nil), Implements, (*io.ReaderFrom)(nil))
assert((*BufferedWriter)(nil), Implements, (*io.ByteWriter)(nil))
}

View File

@ -38,4 +38,5 @@ func TestConnectionInterface(t *testing.T) {
assert((*Connection)(nil), Implements, (*io.Writer)(nil)) assert((*Connection)(nil), Implements, (*io.Writer)(nil))
assert((*Connection)(nil), Implements, (*io.Reader)(nil)) assert((*Connection)(nil), Implements, (*io.Reader)(nil))
assert((*Connection)(nil), Implements, (*buf.Reader)(nil)) assert((*Connection)(nil), Implements, (*buf.Reader)(nil))
assert((*Connection)(nil), Implements, (*buf.Writer)(nil))
} }