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)
|
|
|
|
}
|
|
|
|
t.Logf("Serialized receiver; %d bytes, hex:\n%x\n", len(b), b)
|
2016-01-19 08:26:28 +03:00
|
|
|
|
2016-01-19 10:28:14 +03:00
|
|
|
*rcv, err = ElkremReceiverFromBytes(b)
|
2016-01-19 08:26:28 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-01-19 10:28:14 +03:00
|
|
|
b2, err := rcv.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-01-19 10:28:14 +03:00
|
|
|
func SenderSerdesTest(t *testing.T, sndr *ElkremSender) {
|
|
|
|
b, err := sndr.ToBytes()
|
2016-01-19 08:04:53 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
t.Logf("Serialized sender; %d bytes, hex:\n%x\n", len(b), b)
|
2016-01-19 08:26:28 +03:00
|
|
|
|
2016-01-19 10:28:14 +03:00
|
|
|
*sndr, err = ElkremSenderFromBytes(b)
|
2016-01-19 08:26:28 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-01-19 10:28:14 +03:00
|
|
|
b2, err := sndr.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
|
|
|
}
|