forked from papamitra/go-dbus
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdbus_test.go
58 lines (51 loc) · 1.24 KB
/
dbus_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
package dbus
import (
"fmt"
"testing"
)
type callTest struct {
dest, path, iface, method string
args []interface{}
validate func([]interface{}) error
}
var callTests = []callTest{
{"org.freedesktop.Notifications", "/org/freedesktop/Notifications",
"org.freedesktop.Notifications", "Notify",
[]interface{}{
"go-dbus", uint32(0),
"info", "testing go-dbus", "test_body",
[]string{}, map[uint32]interface{}{},
int32(2000)},
func([]interface{}) error {
return nil
}},
}
func (test callTest) Call(c *Connection) error {
method, err := c.Object(test.dest, test.path).Interface(test.iface).Method(test.method)
if err != nil {
return err
}
out, err := c.Call(method, test.args...)
if err != nil {
return fmt.Errorf("failed Method.Call: %v", err)
}
if err = test.validate(out); err != nil {
err = fmt.Errorf("failed validation: %v", err)
}
return err
}
func TestDBus(t *testing.T) {
con, err := Connect(SessionBus)
if err != nil {
t.Fatal(err.Error())
}
if err = con.Authenticate(); err != nil {
t.Fatal("Failed Connection.Authenticate:", err.Error())
}
for i, test := range callTests {
err := test.Call(con)
if err != nil {
t.Errorf("callTest %d: %v", i, err)
}
}
}