]>
Commit | Line | Data |
---|---|---|
6ee4f990 ZJS |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2013 Zbigniew Jędrzejewski-Szmek | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU Lesser General Public License as published by | |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public License | |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
18 | ***/ | |
19 | ||
20 | #include <stdio.h> | |
21 | ||
22 | #include "sd-bus.h" | |
07630cea | 23 | |
6ee4f990 ZJS |
24 | #include "bus-internal.h" |
25 | #include "bus-message.h" | |
07630cea | 26 | #include "bus-util.h" |
6ee4f990 ZJS |
27 | #include "refcnt.h" |
28 | ||
29 | static void test_bus_new(void) { | |
4afd3348 | 30 | _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL; |
6ee4f990 ZJS |
31 | |
32 | assert_se(sd_bus_new(&bus) == 0); | |
33 | printf("after new: refcount %u\n", REFCNT_GET(bus->n_ref)); | |
34 | } | |
35 | ||
8d1d1bf2 | 36 | static int test_bus_open(void) { |
a5fd31e6 | 37 | _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; |
8d1d1bf2 | 38 | int r; |
6ee4f990 | 39 | |
6349cda2 | 40 | r = sd_bus_open_user(&bus); |
945c2931 | 41 | if (IN_SET(r, -ECONNREFUSED, -ENOENT)) |
8d1d1bf2 ZJS |
42 | return r; |
43 | ||
44 | assert_se(r >= 0); | |
6ee4f990 | 45 | printf("after open: refcount %u\n", REFCNT_GET(bus->n_ref)); |
8d1d1bf2 ZJS |
46 | |
47 | return 0; | |
6ee4f990 ZJS |
48 | } |
49 | ||
50 | static void test_bus_new_method_call(void) { | |
51 | sd_bus *bus = NULL; | |
4afd3348 | 52 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; |
6ee4f990 | 53 | |
6349cda2 | 54 | assert_se(sd_bus_open_user(&bus) >= 0); |
6ee4f990 | 55 | |
151b9b96 | 56 | assert_se(sd_bus_message_new_method_call(bus, &m, "a.service.name", "/an/object/path", "an.interface.name", "AMethodName") >= 0); |
6ee4f990 ZJS |
57 | |
58 | printf("after message_new_method_call: refcount %u\n", REFCNT_GET(bus->n_ref)); | |
59 | ||
a5fd31e6 EV |
60 | sd_bus_flush_close_unref(bus); |
61 | printf("after bus_flush_close_unref: refcount %u\n", m->n_ref); | |
6ee4f990 ZJS |
62 | } |
63 | ||
64 | static void test_bus_new_signal(void) { | |
65 | sd_bus *bus = NULL; | |
4afd3348 | 66 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; |
6ee4f990 | 67 | |
6349cda2 | 68 | assert_se(sd_bus_open_user(&bus) >= 0); |
6ee4f990 | 69 | |
151b9b96 | 70 | assert_se(sd_bus_message_new_signal(bus, &m, "/an/object/path", "an.interface.name", "Name") >= 0); |
6ee4f990 ZJS |
71 | |
72 | printf("after message_new_signal: refcount %u\n", REFCNT_GET(bus->n_ref)); | |
73 | ||
a5fd31e6 EV |
74 | sd_bus_flush_close_unref(bus); |
75 | printf("after bus_flush_close_unref: refcount %u\n", m->n_ref); | |
6ee4f990 ZJS |
76 | } |
77 | ||
78 | int main(int argc, char **argv) { | |
8d1d1bf2 ZJS |
79 | int r; |
80 | ||
6ee4f990 ZJS |
81 | log_parse_environment(); |
82 | log_open(); | |
83 | ||
84 | test_bus_new(); | |
8d1d1bf2 ZJS |
85 | r = test_bus_open(); |
86 | if (r < 0) { | |
87 | log_info("Failed to connect to bus, skipping tests."); | |
88 | return EXIT_TEST_SKIP; | |
89 | } | |
90 | ||
6ee4f990 ZJS |
91 | test_bus_new_method_call(); |
92 | test_bus_new_signal(); | |
8d1d1bf2 ZJS |
93 | |
94 | return EXIT_SUCCESS; | |
6ee4f990 | 95 | } |