1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2015 David Herrmann <dh.herrmann@gmail.com>
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.
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.
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/>.
28 #include "alloc-util.h"
30 #include "bus-kernel.h"
40 static int test_proxy_acquired(sd_bus_message
*m
, void *userdata
, sd_bus_error
*error
) {
41 TestProxyMatch
*match
= userdata
;
45 r
= sd_bus_message_read(m
, "s", &name
);
48 if (!streq_ptr(match
->sender
, name
))
51 ++match
->matched_acquired
;
55 static void test_proxy_matched(void) {
56 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*a
= NULL
;
57 _cleanup_free_
char *matchstr
= NULL
;
58 TestProxyMatch match
= {};
67 r
= sd_bus_set_address(a
, "unix:path=/var/run/dbus/system_bus_socket");
70 r
= sd_bus_set_bus_client(a
, true);
76 r
= sd_bus_get_unique_name(a
, &me
);
79 matchstr
= strjoin("type='signal',"
80 "member='NameAcquired',"
86 r
= sd_bus_add_match(a
, NULL
, matchstr
, test_proxy_acquired
, &match
);
89 r
= sd_bus_get_unique_name(a
, &match
.sender
);
92 /* barrier to guarantee proxy/dbus-daemon handled the previous data */
93 r
= sd_bus_call_method(a
,
94 "org.freedesktop.DBus",
95 "/org/freedesktop/DBus",
96 "org.freedesktop.DBus",
101 /* now we can be sure the Name* signals were sent */
103 r
= sd_bus_process(a
, NULL
);
107 assert_se(match
.matched_acquired
== 1);
110 int main(int argc
, char **argv
) {
111 if (access("/var/run/dbus/system_bus_socket", F_OK
) < 0)
112 return EXIT_TEST_SKIP
;
114 log_parse_environment();
116 test_proxy_matched();