2016-02-06 19:20:54 +01:00
|
|
|
package nametransform
|
2015-09-07 21:25:05 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2015-10-04 14:36:20 +02:00
|
|
|
"testing"
|
2015-09-07 21:25:05 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPad16(t *testing.T) {
|
|
|
|
var s [][]byte
|
|
|
|
s = append(s, []byte("foo"))
|
|
|
|
s = append(s, []byte("12345678901234567"))
|
|
|
|
s = append(s, []byte("12345678901234567abcdefg"))
|
2015-10-04 11:03:40 +02:00
|
|
|
|
2015-10-04 14:36:20 +02:00
|
|
|
for i := range s {
|
2015-09-07 21:25:05 +02:00
|
|
|
orig := s[i]
|
2016-02-06 20:22:45 +01:00
|
|
|
padded := pad16(orig)
|
2015-09-07 21:25:05 +02:00
|
|
|
if len(padded) <= len(orig) {
|
|
|
|
t.Errorf("Padded length not bigger than orig: %d", len(padded))
|
|
|
|
}
|
2015-10-04 14:36:20 +02:00
|
|
|
if len(padded)%16 != 0 {
|
2015-09-07 21:25:05 +02:00
|
|
|
t.Errorf("Length is not aligend: %d", len(padded))
|
|
|
|
}
|
2016-02-06 20:22:45 +01:00
|
|
|
unpadded, err := unPad16(padded)
|
2015-09-07 21:25:05 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error("unPad16 returned error:", err)
|
|
|
|
}
|
|
|
|
if len(unpadded) != len(orig) {
|
|
|
|
t.Errorf("Size mismatch: orig=%d unpadded=%d", len(s[i]), len(unpadded))
|
|
|
|
}
|
2015-10-04 14:36:20 +02:00
|
|
|
if !bytes.Equal(orig, unpadded) {
|
2015-09-07 21:25:05 +02:00
|
|
|
t.Error("Content mismatch orig vs unpadded")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|