-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbor_test.go
56 lines (48 loc) · 1.14 KB
/
cbor_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
package senml
import "testing"
func TestEncodeCBORExamples(t *testing.T) {
for n, example := range testVectors {
b, err := EncodeCBOR(example.Result)
if err != nil {
t.Errorf("Error encoding %s: %s", n, err)
return
}
t.Logf("Result for %s (%v bytes): %x", n, len(b), b)
}
}
func TestDecodeCBORExamples(t *testing.T) {
AutoTime = false
for n, example := range testVectors {
if example.CBOR == nil {
continue
}
res, err := DecodeCBOR(example.CBOR)
if err != nil {
t.Errorf("Error decoding %s: %s", n, err)
continue
}
if !equal(res, example.Result) {
t.Errorf("Decode for example %s incorrect, got:\n%s\nexpected:\n%s", n, toString(res), toString(example.Result))
}
}
}
func BenchmarkEncodeCBOR(b *testing.B) {
v := "Multiple Measurements"
ms := testVectors[v].Result
for n := 0; n < b.N; n++ {
_, err := EncodeCBOR(ms)
if err != nil {
b.Fatalf("Error encoding %s: %s", v, err)
}
}
}
func BenchmarkDecodeCBOR(b *testing.B) {
v := "Multiple Data Points 2"
t := testVectors[v].CBOR
for n := 0; n < b.N; n++ {
_, err := DecodeCBOR(t)
if err != nil {
b.Fatalf("Error encoding %s: %s", v, err)
}
}
}