62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package encoder
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func Test_BOP2(t *testing.T) {
|
|
cases := []struct {
|
|
bop BOP2
|
|
streamLength int
|
|
bufferCapacity int
|
|
}{
|
|
{
|
|
bop: &Salter{},
|
|
streamLength: 50000,
|
|
bufferCapacity: 100,
|
|
},
|
|
{
|
|
bop: &Salter{},
|
|
streamLength: 50,
|
|
bufferCapacity: 40,
|
|
},
|
|
{
|
|
bop: &AES{Key: []byte("key")},
|
|
streamLength: 50000,
|
|
bufferCapacity: 100,
|
|
},
|
|
{
|
|
bop: &AES{Key: []byte("key")},
|
|
streamLength: 50,
|
|
bufferCapacity: 40,
|
|
},
|
|
{
|
|
bop: &Zipper{},
|
|
streamLength: 50000,
|
|
bufferCapacity: 100,
|
|
},
|
|
{
|
|
bop: &Zipper{},
|
|
streamLength: 50,
|
|
bufferCapacity: 40,
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
SetPipeBuffSize(c.bufferCapacity)
|
|
inputString := strings.Repeat("hello world! ", c.streamLength)[:c.streamLength]
|
|
input := strings.NewReader(inputString)
|
|
wrappedReader := c.bop.Wrap2(input)
|
|
unwrappedReader := c.bop.Unwrap2(wrappedReader)
|
|
out, err := ioutil.ReadAll(unwrappedReader)
|
|
if err != nil {
|
|
t.Fatalf("failed to read from unwrapped: %v", err)
|
|
} else if string(out) != inputString {
|
|
t.Errorf("wrong output: wanted (%v), got (%v)", len(inputString), len(out))
|
|
}
|
|
t.Logf("%T : %v => ? => %v", c.bop, len(inputString), len(out))
|
|
}
|
|
}
|