-
Notifications
You must be signed in to change notification settings - Fork 5
/
params_test.go
82 lines (76 loc) · 1.91 KB
/
params_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package xmssmt
import (
"reflect"
"testing"
)
func TestBinaryUnmarshalingNamedParams(t *testing.T) {
for _, name := range ListNames() {
params := ParamsFromName(name)
if params == nil {
t.Fatalf("ParamsFromName(%s) is nil", name)
}
buf, err := params.MarshalBinary()
if err != nil {
t.Fatalf("ParamsFromName(%s).MarshalBinary(): %v ", name, err)
}
var params2 Params
err = params2.UnmarshalBinary(buf)
if err != nil {
t.Fatalf("%s: UnmarshalBinary(): %v ", name, err)
}
name2, _ := params2.LookupNameAndOid()
if name2 != name {
t.Fatalf("%s unmarshaled improperly to %s", name, name2)
}
}
}
func testBinaryUnmarshalingCustomParams(params *Params, t *testing.T) {
buf, err := params.MarshalBinary()
if err != nil {
t.Fatalf("MarshalBinary(): %v ", err)
}
var params2 Params
err = params2.UnmarshalBinary(buf)
if err != nil {
t.Fatalf("UnmarshalBinary(): %v ", err)
}
if !reflect.DeepEqual(*params, params2) {
t.Fatalf("Unmarshaling failed")
}
}
func TestBinaryUnmarshalingCustomParams(t *testing.T) {
for _, name := range ListNames() {
params := ParamsFromName(name)
if params == nil {
t.Fatalf("ParamsFromName(%s) is nil", name)
}
params.WotsW = 4
testBinaryUnmarshalingCustomParams(params, t)
params.WotsW = 256
testBinaryUnmarshalingCustomParams(params, t)
}
}
func TestParamsString(t *testing.T) {
for _, name := range ListNames() {
params := ParamsFromName(name)
if params == nil {
t.Fatalf("ParamsFromName(%s) is nil", name)
}
name2 := params.String()
if name != name2 {
t.Fatalf("ParamsFromName(%s) = %s", name, name2)
}
}
}
func TestParseParams(t *testing.T) {
for _, name := range ListNames() {
params := ParamsFromName(name)
params2, err := parseParamsFromName(name)
if err != nil {
t.Fatalf("Failed to parse %s: %v", name, err)
}
if *params != *params2 {
t.Fatalf("Parsed %s as %v instead of %v", name, params2, params)
}
}
}