Encoder/bop3_test.go

76 lines
1.2 KiB
Go

package encoder
import (
"strings"
"testing"
)
func Test_BOP3(t *testing.T) {
was := pipeBuffSize
defer func() {
SetPipeBuffSize(int(was))
}()
cases := []struct {
bop BOP3
sz int
}{
{
sz: 500,
bop: &AES{Key: []byte("hi")},
},
{
sz: 10,
bop: &AES{Key: []byte("hi")},
},
{
sz: 500,
bop: &Zipper{},
},
{
sz: 10,
bop: &Zipper{},
},
{
sz: 500,
bop: &Salter{},
},
{
sz: 10,
bop: &Salter{},
},
}
for _, c := range cases {
SetPipeBuffSize(c.sz)
input := strings.Repeat("input", 5)
inch := make(chan []byte)
wrapch := c.bop.Wrap3(inch)
go func() {
for _, ch := range input {
inch <- []byte{byte(ch)}
}
close(inch)
}()
wrapped := ""
for o := range wrapch {
wrapped += string(o)
}
if len(wrapped) < 1 {
t.Errorf("%T : %s => 0 length", c, input)
continue
}
inunwrapch := make(chan []byte)
unwrapch := c.bop.Unwrap3(inunwrapch)
inunwrapch <- []byte(wrapped)
close(inunwrapch)
out := ""
for o := range unwrapch {
out += string(o)
}
if input != out {
t.Errorf("wrap3 failed for %T", c)
}
t.Logf("%T : %v : %s => (%v) => %s", c.bop, c.sz, input, len(wrapped), out)
}
}