1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package dbus
16
17 import (
18 "testing"
19 )
20
21 func TestNeedsEscape(t *testing.T) {
22
23 for want, vals := range map[bool][]byte{
24 false: []byte{'a', 'b', 'z', 'A', 'Q', '1', '4', '9'},
25 true: []byte{'#', '%', '$', '!', '.', '_', '-', '%', '\\'},
26 } {
27 for i := 1; i < 10; i++ {
28 for _, b := range vals {
29 got := needsEscape(i, b)
30 if got != want {
31 t.Errorf("needsEscape(%d, %c) returned %t, want %t", i, b, got, want)
32 }
33 }
34 }
35 }
36
37
38 for want, vals := range map[bool][]byte{
39 false: []byte{'A', 'a', 'e', 'x', 'Q', 'Z'},
40 true: []byte{'0', '4', '5', '9'},
41 } {
42 for _, b := range vals {
43 got := needsEscape(0, b)
44 if got != want {
45 t.Errorf("needsEscape(0, %c) returned %t, want %t", b, got, want)
46 }
47 }
48 }
49
50 }
51
52 func TestPathBusEscape(t *testing.T) {
53 for in, want := range map[string]string{
54 "": "_",
55 "foo.service": "foo_2eservice",
56 "foobar": "foobar",
57 "woof@woof.service": "woof_40woof_2eservice",
58 "0123456": "_30123456",
59 "account_db.service": "account_5fdb_2eservice",
60 "got-dashes": "got_2ddashes",
61 } {
62 got := PathBusEscape(in)
63 if got != want {
64 t.Errorf("bad result for PathBusEscape(%s): got %q, want %q", in, got, want)
65 }
66 }
67
68 }
69
70 func TestPathBusUnescape(t *testing.T) {
71 for in, want := range map[string]string{
72 "_": "",
73 "foo_2eservice": "foo.service",
74 "foobar": "foobar",
75 "woof_40woof_2eservice": "woof@woof.service",
76 "_30123456": "0123456",
77 "account_5fdb_2eservice": "account_db.service",
78 "got_2ddashes": "got-dashes",
79 "foobar_": "foobar_",
80 "foobar_2": "foobar_2",
81 } {
82 got := pathBusUnescape(in)
83 if got != want {
84 t.Errorf("bad result for pathBusUnescape(%s): got %q, want %q", in, got, want)
85 }
86 }
87 }
88
89
90 func TestNew(t *testing.T) {
91 _, err := New()
92
93 if err != nil {
94 t.Fatal(err)
95 }
96 }
97
View as plain text