]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd/sd-bus/test-bus-kernel-bloom.c
man: introduce new "Desktop" property for sessions
[thirdparty/systemd.git] / src / libsystemd / sd-bus / test-bus-kernel-bloom.c
CommitLineData
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
22#include "util.h"
23#include "log.h"
24
25#include "sd-bus.h"
26#include "bus-message.h"
27#include "bus-error.h"
28#include "bus-kernel.h"
40ca29a1 29#include "bus-util.h"
86312ab8
LP
30
31static void test_one(
32 const char *path,
33 const char *interface,
34 const char *member,
35 const char *arg0,
36 const char *match,
37 bool good) {
38
39 _cleanup_close_ int bus_ref = -1;
79ccff06 40 _cleanup_free_ char *name = NULL, *bus_name = NULL, *address = NULL;
86312ab8
LP
41 _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
42 sd_bus *a, *b;
43 int r;
44
79ccff06
ZJS
45 assert_se(asprintf(&name, "deine-mutter-%u", (unsigned) getpid()) >= 0);
46
47 bus_ref = bus_kernel_create_bus(name, false, &bus_name);
86312ab8
LP
48 if (bus_ref == -ENOENT)
49 exit(EXIT_TEST_SKIP);
50
51 assert_se(bus_ref >= 0);
52
53 address = strappend("kernel:path=", bus_name);
54 assert_se(address);
55
56 r = sd_bus_new(&a);
57 assert_se(r >= 0);
58
59 r = sd_bus_new(&b);
60 assert_se(r >= 0);
61
62 r = sd_bus_set_address(a, address);
63 assert_se(r >= 0);
64
65 r = sd_bus_set_address(b, address);
66 assert_se(r >= 0);
67
68 r = sd_bus_start(a);
69 assert_se(r >= 0);
70
71 r = sd_bus_start(b);
72 assert_se(r >= 0);
73
f11e11e3 74 log_debug("match");
86312ab8
LP
75 r = sd_bus_add_match(b, match, NULL, NULL);
76 assert_se(r >= 0);
77
f11e11e3 78 log_debug("signal");
86312ab8
LP
79 r = sd_bus_emit_signal(a, path, interface, member, "s", arg0);
80 assert_se(r >= 0);
81
82 r = sd_bus_process(b, &m);
83 assert_se(r >= 0 && (good == !!m));
84
85 sd_bus_unref(a);
86 sd_bus_unref(b);
87}
88
89int main(int argc, char *argv[]) {
90 log_set_max_level(LOG_DEBUG);
91
92 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "", true);
93 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar/waldo'", true);
94 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar/waldo/tuut'", false);
95 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "interface='waldo.com'", true);
96 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "member='Piep'", true);
97 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "member='Pi_ep'", false);
98 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "arg0='foobar'", true);
99 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "arg0='foo_bar'", false);
100 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar/waldo',interface='waldo.com',member='Piep',arg0='foobar'", true);
101 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar/waldo',interface='waldo.com',member='Piep',arg0='foobar2'", false);
102
f11e11e3
LP
103 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar/waldo'", true);
104 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar'", false);
105 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo'", false);
106 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/'", false);
107 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar/waldo/quux'", false);
108 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path_namespace='/foo/bar/waldo'", true);
109 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path_namespace='/foo/bar'", true);
110 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path_namespace='/foo'", true);
111 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path_namespace='/'", true);
112 test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path_namespace='/quux'", false);
113
86312ab8
LP
114 return 0;
115}