2016-01-19 08:04:53 +03:00
|
|
|
package elkrem
|
|
|
|
|
2016-01-19 08:26:28 +03:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
2016-01-19 08:04:53 +03:00
|
|
|
|
2016-01-19 10:28:14 +03:00
|
|
|
func ReceiverSerdesTest(t *testing.T, rcv *ElkremReceiver) {
|
|
|
|
b, err := rcv.ToBytes()
|
2016-01-19 08:04:53 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-30 02:54:24 +03:00
|
|
|
t.Logf("rcv2 has len %d\n", len(rcv.s))
|
2016-01-19 08:04:53 +03:00
|
|
|
t.Logf("Serialized receiver; %d bytes, hex:\n%x\n", len(b), b)
|
2016-01-19 08:26:28 +03:00
|
|
|
|
2016-06-30 02:54:24 +03:00
|
|
|
rcv2, err := ElkremReceiverFromBytes(b)
|
2016-01-19 08:26:28 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-30 02:54:24 +03:00
|
|
|
t.Logf("rcv2 has len %d\n", len(rcv2.s))
|
|
|
|
b2, err := rcv2.ToBytes()
|
2016-01-19 08:26:28 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(b, b2) {
|
|
|
|
t.Fatalf("First and second serializations different")
|
|
|
|
}
|
2016-01-19 08:04:53 +03:00
|
|
|
}
|
|
|
|
|
2016-06-30 02:54:24 +03:00
|
|
|
//func SenderSerdesTest(t *testing.T, sndr *ElkremSender) {
|
|
|
|
// b, err := sndr.ToBytes()
|
|
|
|
// if err != nil {
|
|
|
|
// t.Fatal(err)
|
|
|
|
// }
|
|
|
|
// t.Logf("Serialized sender; %d bytes, hex:\n%x\n", len(b), b)
|
|
|
|
|
|
|
|
// *sndr, err = ElkremSenderFromBytes(b)
|
|
|
|
// if err != nil {
|
|
|
|
// t.Fatal(err)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// b2, err := sndr.ToBytes()
|
|
|
|
// if err != nil {
|
|
|
|
// t.Fatal(err)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if !bytes.Equal(b, b2) {
|
|
|
|
// t.Fatalf("First and second serializations different")
|
|
|
|
// }
|
|
|
|
//}
|