-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathelement_test.go
39 lines (32 loc) · 973 Bytes
/
element_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
package tlv_test
import (
"testing"
"github.com/usnistgov/ndn-dpdk/ndn/ndntestvector"
"github.com/usnistgov/ndn-dpdk/ndn/tlv"
)
func TestElement(t *testing.T) {
assert, _ := makeAR(t)
for _, tt := range ndntestvector.TlvElementTests {
input := bytesFromHex(tt.Input)
var element tlv.Element
e := tlv.Decode(input, &element)
if tt.Bad {
assert.Error(e, tt.Input)
} else if assert.NoError(e, tt.Input) {
assert.Equal(len(input), element.Size(), tt.Input)
assert.Equal(tt.Type, element.Type, tt.Input)
value := bytesFromHex(tt.Value)
assert.Equal(len(value), element.Length(), tt.Input)
bytesEqual(assert, value, element.Value, tt.Input)
var nni tlv.NNI
if e := nni.UnmarshalBinary(value); e == nil {
assert.EqualValues(tt.Nni, nni, tt.Input)
assert.Equal(len(value), nni.Size())
nniV := nni.Encode(nil)
assert.Equal(value, nniV)
} else {
assert.True(tt.Nni == ndntestvector.NotNni, tt.Input)
}
}
}
}