This repository has been archived by the owner on Mar 3, 2022. It is now read-only.
forked from godbus/dbus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store_test.go
122 lines (110 loc) · 2.49 KB
/
store_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package dbus
import (
"reflect"
"testing"
)
func TestStoreStringToInterface(t *testing.T) {
var dest interface{}
err := Store([]interface{}{"foobar"}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest.(string)
}
func TestStoreVariantToInterface(t *testing.T) {
src := MakeVariant("foobar")
var dest interface{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest.(string)
}
func TestStoreMapStringToMapInterface(t *testing.T) {
src := map[string]string{"foo": "bar"}
dest := map[string]interface{}{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest["foo"].(string)
}
func TestStoreMapVariantToMapInterface(t *testing.T) {
src := map[string]Variant{"foo": MakeVariant("foobar")}
dest := map[string]interface{}{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest["foo"].(string)
}
func TestStoreSliceStringToSliceInterface(t *testing.T) {
src := []string{"foo"}
dest := []interface{}{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest[0].(string)
}
func TestStoreSliceVariantToSliceInterface(t *testing.T) {
src := []Variant{MakeVariant("foo")}
dest := []interface{}{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest[0].(string)
}
func TestStoreSliceVariantToSliceInterfaceMulti(t *testing.T) {
src := []Variant{MakeVariant("foo"), MakeVariant(int32(1))}
dest := []interface{}{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest[0].(string)
_ = dest[1].(int32)
}
func TestStoreNested(t *testing.T) {
src := map[string]interface{}{
"foo": []interface{}{"1", "2", "3", "5",
map[string]interface{}{
"bar": "baz",
},
},
"bar": map[string]interface{}{
"baz": "quux",
"quux": "quuz",
},
}
dest := map[string]interface{}{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(src, dest) {
t.Errorf("not equal: got '%v', want '%v'",
dest, src)
}
}
type testStruct1 struct {
V0 uint32
V1 bool
}
func TestStoreVariantStruct(t *testing.T) {
src := MakeVariantWithSignature([]interface{}{1, true}, Signature{"(ub)"})
dest := testStruct1{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(dest.V0, uint32(1)) {
t.Errorf("not equal: got '%v', want '%v'",
dest.V0, 1)
}
if !reflect.DeepEqual(dest.V1, true) {
t.Errorf("not equal: got '%v', want '%v'",
dest.V1, true)
}
}