forked from godbus/dbus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sig_test.go
102 lines (93 loc) · 1.82 KB
/
sig_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package dbus
import (
"reflect"
"testing"
)
var sigTests = []struct {
vs []interface{}
sig Signature
}{
{
[]interface{}{new(int32)},
Signature{"i"},
},
{
[]interface{}{new(string)},
Signature{"s"},
},
{
[]interface{}{new(Signature)},
Signature{"g"},
},
{
[]interface{}{new([]int16)},
Signature{"an"},
},
{
[]interface{}{new(int16), new(uint32)},
Signature{"nu"},
},
{
[]interface{}{new(map[byte]Variant)},
Signature{"a{yv}"},
},
{
[]interface{}{new(Variant), new([]map[int32]string)},
Signature{"vaa{is}"},
},
}
func TestSig(t *testing.T) {
for i, v := range sigTests {
sig := SignatureOf(v.vs...)
if sig != v.sig {
t.Errorf("test %d: got %q, expected %q", i+1, sig.str, v.sig.str)
}
svs := v.sig.Values()
if len(svs) != len(v.vs) {
t.Errorf("test %d: got %d values, expected %d", i+1, len(svs), len(v.vs))
continue
}
for j := range svs {
if t1, t2 := reflect.TypeOf(svs[j]), reflect.TypeOf(v.vs[j]); t1 != t2 {
t.Errorf("test %d: got %s, expected %s", i+1, t1, t2)
}
}
}
}
func TestSigStructSlice(t *testing.T) {
sig := Signature{"a(i)"}
if reflect.TypeOf(sig.Values()[0]) != reflect.TypeOf(new([][]interface{})) {
t.Errorf("got type: %s", reflect.TypeOf(sig.Values()[0]))
}
}
var getSigTest = []interface{}{
[]struct {
b byte
i int32
t uint64
s string
}{},
map[string]Variant{},
}
func BenchmarkGetSignatureSimple(b *testing.B) {
for i := 0; i < b.N; i++ {
SignatureOf("", int32(0))
}
}
func BenchmarkGetSignatureLong(b *testing.B) {
for i := 0; i < b.N; i++ {
SignatureOf(getSigTest...)
}
}
func BenchmarkSignatureValuesSimple(b *testing.B) {
s := Signature{"si"}
for i := 0; i < b.N; i++ {
s.Values()
}
}
func BenchmarkSignatureValuesLong(b *testing.B) {
s := Signature{"a(bits)a{sv}"}
for i := 0; i < b.N; i++ {
s.Values()
}
}