]>
Commit | Line | Data |
---|---|---|
86312ab8 LP |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2013 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
86312ab8 | 22 | #include "sd-bus.h" |
07630cea | 23 | |
86312ab8 | 24 | #include "bus-kernel.h" |
40ca29a1 | 25 | #include "bus-util.h" |
07630cea LP |
26 | #include "log.h" |
27 | #include "util.h" | |
86312ab8 | 28 | |
2e90f867 DH |
29 | static int test_match(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { |
30 | int *found = userdata; | |
31 | ||
32 | *found = 1; | |
33 | ||
34 | return 0; | |
35 | } | |
36 | ||
86312ab8 LP |
37 | static void test_one( |
38 | const char *path, | |
39 | const char *interface, | |
40 | const char *member, | |
1abe54d9 | 41 | bool as_list, |
86312ab8 LP |
42 | const char *arg0, |
43 | const char *match, | |
44 | bool good) { | |
45 | ||
46 | _cleanup_close_ int bus_ref = -1; | |
79ccff06 | 47 | _cleanup_free_ char *name = NULL, *bus_name = NULL, *address = NULL; |
86312ab8 LP |
48 | _cleanup_bus_message_unref_ sd_bus_message *m = NULL; |
49 | sd_bus *a, *b; | |
2e90f867 | 50 | int r, found = 0; |
86312ab8 | 51 | |
79ccff06 ZJS |
52 | assert_se(asprintf(&name, "deine-mutter-%u", (unsigned) getpid()) >= 0); |
53 | ||
54 | bus_ref = bus_kernel_create_bus(name, false, &bus_name); | |
86312ab8 LP |
55 | if (bus_ref == -ENOENT) |
56 | exit(EXIT_TEST_SKIP); | |
57 | ||
58 | assert_se(bus_ref >= 0); | |
59 | ||
60 | address = strappend("kernel:path=", bus_name); | |
61 | assert_se(address); | |
62 | ||
63 | r = sd_bus_new(&a); | |
64 | assert_se(r >= 0); | |
65 | ||
66 | r = sd_bus_new(&b); | |
67 | assert_se(r >= 0); | |
68 | ||
69 | r = sd_bus_set_address(a, address); | |
70 | assert_se(r >= 0); | |
71 | ||
72 | r = sd_bus_set_address(b, address); | |
73 | assert_se(r >= 0); | |
74 | ||
75 | r = sd_bus_start(a); | |
76 | assert_se(r >= 0); | |
77 | ||
78 | r = sd_bus_start(b); | |
79 | assert_se(r >= 0); | |
80 | ||
f11e11e3 | 81 | log_debug("match"); |
2e90f867 | 82 | r = sd_bus_add_match(b, NULL, match, test_match, &found); |
86312ab8 LP |
83 | assert_se(r >= 0); |
84 | ||
f11e11e3 | 85 | log_debug("signal"); |
1abe54d9 LP |
86 | |
87 | if (as_list) | |
88 | r = sd_bus_emit_signal(a, path, interface, member, "as", 1, arg0); | |
89 | else | |
90 | r = sd_bus_emit_signal(a, path, interface, member, "s", arg0); | |
86312ab8 LP |
91 | assert_se(r >= 0); |
92 | ||
93 | r = sd_bus_process(b, &m); | |
2e90f867 | 94 | assert_se(r >= 0 && good == !!found); |
86312ab8 LP |
95 | |
96 | sd_bus_unref(a); | |
97 | sd_bus_unref(b); | |
98 | } | |
99 | ||
100 | int main(int argc, char *argv[]) { | |
101 | log_set_max_level(LOG_DEBUG); | |
102 | ||
1abe54d9 LP |
103 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "", true); |
104 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo'", true); | |
105 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo/tuut'", false); | |
106 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "interface='waldo.com'", true); | |
107 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "member='Piep'", true); | |
108 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "member='Pi_ep'", false); | |
109 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "arg0='foobar'", true); | |
110 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "arg0='foo_bar'", false); | |
eccd47c5 | 111 | test_one("/foo/bar/waldo", "waldo.com", "Piep", true, "foobar", "arg0='foobar'", false); |
1abe54d9 | 112 | test_one("/foo/bar/waldo", "waldo.com", "Piep", true, "foobar", "arg0='foo_bar'", false); |
eccd47c5 LP |
113 | test_one("/foo/bar/waldo", "waldo.com", "Piep", true, "foobar", "arg0has='foobar'", true); |
114 | test_one("/foo/bar/waldo", "waldo.com", "Piep", true, "foobar", "arg0has='foo_bar'", false); | |
1abe54d9 LP |
115 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo',interface='waldo.com',member='Piep',arg0='foobar'", true); |
116 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo',interface='waldo.com',member='Piep',arg0='foobar2'", false); | |
117 | ||
118 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo'", true); | |
119 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar'", false); | |
120 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo'", false); | |
121 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/'", false); | |
122 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo/quux'", false); | |
123 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo/bar/waldo'", true); | |
124 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo/bar'", true); | |
125 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo'", true); | |
126 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/'", true); | |
127 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/quux'", false); | |
26589352 | 128 | test_one("/", "waldo.com", "Piep", false, "foobar", "path_namespace='/'", true); |
f11e11e3 | 129 | |
744dccdd DH |
130 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo/'", false); |
131 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/'", false); | |
132 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo/bar/waldo/'", false); | |
133 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo/'", true); | |
134 | ||
135 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo/bar/waldo", "arg0path='/foo/'", true); | |
136 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo", "arg0path='/foo'", true); | |
137 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo", "arg0path='/foo/bar/waldo'", false); | |
138 | test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo/", "arg0path='/foo/bar/waldo'", true); | |
139 | ||
86312ab8 LP |
140 | return 0; |
141 | } |