-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathintrospect_test.go
78 lines (69 loc) · 2.13 KB
/
introspect_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
package dbus
import (
"testing"
)
var introStr = `
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/freedesktop/sample_object">
<interface name="org.freedesktop.SampleInterface">
<method name="Frobate">
<arg name="foo" type="i" direction="in"/>
<arg name="bar" type="s" direction="out"/>
<arg name="baz" type="a{us}" direction="out"/>
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
</method>
<method name="Bazify">
<arg name="bar" type="(iiu)" direction="in"/>
<arg name="bar" type="v" direction="out"/>
</method>
<method name="Mogrify">
<arg name="bar" type="(iiav)" direction="in"/>
</method>
<signal name="Changed">
<arg name="new_value" type="b"/>
</signal>
<property name="Bar" type="y" access="readwrite"/>
</interface>
<node name="child_of_sample_object"/>
<node name="another_child_of_sample_object"/>
</node>
`
func TestIntrospect(t *testing.T) {
intro, e := NewIntrospect(introStr)
if e != nil {
t.Error("Failed #1-1")
}
if intro == nil {
t.Error("Failed #1-2")
}
intf := intro.GetInterfaceData("org.freedesktop.SampleInterface")
if intf == nil {
t.Error("Failed #2-1")
}
if intf.GetName() != "org.freedesktop.SampleInterface" {
t.Error("Failed #2-2")
}
meth := intf.GetMethodData("Frobate")
if meth == nil {
t.Error("Failed #3-1")
}
if meth != nil && "sa{us}" != meth.GetOutSignature() {
t.Error("Failed #3-2")
}
nilmeth := intf.GetMethodData("Hoo") // unknown method name
if nilmeth != nil {
t.Error("Failed #3-3")
}
signal := intf.GetSignalData("Changed")
if signal == nil {
t.Error("Failed #4-1")
}
if signal != nil && "b" != signal.GetSignature() {
t.Error("Failed #4-2")
}
nilsignal := intf.GetSignalData("Hoo") // unknown signal name
if nilsignal != nil {
t.Error("Failed #4-3")
}
}