-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml_test.go
55 lines (48 loc) · 1.15 KB
/
xml_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
package senml
import "testing"
func TestEncodeXMLExamples(t *testing.T) {
for n, example := range testVectors {
b, err := EncodeXML(example.Result)
if err != nil {
t.Errorf("Error encoding %s: %s", n, err)
return
}
t.Logf("Result for %s (%v bytes): %s", n, len(b), b)
}
}
func TestDecodeXMLExamples(t *testing.T) {
AutoTime = false
for n, example := range testVectors {
if example.XML == "" {
continue
}
res, err := DecodeXML([]byte(example.XML))
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 BenchmarkEncodeXML(b *testing.B) {
v := "Multiple Measurements"
ms := testVectors[v].Result
for n := 0; n < b.N; n++ {
_, err := EncodeXML(ms)
if err != nil {
b.Fatalf("Error encoding %s: %s", v, err)
}
}
}
func BenchmarkDecodeXML(b *testing.B) {
v := "Multiple Data Points 2"
t := []byte(testVectors[v].XML)
for n := 0; n < b.N; n++ {
_, err := DecodeXML(t)
if err != nil {
b.Fatalf("Error encoding %s: %s", v, err)
}
}
}