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/>.
29 #include "bus-kernel.h"
39 static int test_proxy_acquired(sd_bus_message
*m
, void *userdata
, sd_bus_error
*error
) {
40 TestProxyMatch
*match
= userdata
;
44 r
= sd_bus_message_read(m
, "s", &name
);
47 if (!streq_ptr(match
->sender
, name
))
50 ++match
->matched_acquired
;
54 static void test_proxy_matched(void) {
55 _cleanup_bus_flush_close_unref_ sd_bus
*a
= NULL
;
56 _cleanup_free_
char *matchstr
= NULL
;
57 TestProxyMatch match
= {};
66 r
= sd_bus_set_address(a
, "unix:path=/var/run/dbus/system_bus_socket");
69 r
= sd_bus_set_bus_client(a
, true);
75 r
= sd_bus_get_unique_name(a
, &me
);
78 matchstr
= strjoin("type='signal',"
79 "member='NameAcquired',"
85 r
= sd_bus_add_match(a
, NULL
, matchstr
, test_proxy_acquired
, &match
);
88 r
= sd_bus_get_unique_name(a
, &match
.sender
);
91 /* barrier to guarantee proxy/dbus-daemon handled the previous data */
92 r
= sd_bus_call_method(a
,
93 "org.freedesktop.DBus",
94 "/org/freedesktop/DBus",
95 "org.freedesktop.DBus",
100 /* now we can be sure the Name* signals were sent */
102 r
= sd_bus_process(a
, NULL
);
106 assert_se(match
.matched_acquired
== 1);
109 int main(int argc
, char **argv
) {
110 if (access("/var/run/dbus/system_bus_socket", F_OK
) < 0)
111 return EXIT_TEST_SKIP
;
113 log_parse_environment();
115 test_proxy_matched();