]>
Commit | Line | Data |
---|---|---|
6ee4f990 ZJS |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2013 Zbigniew Jędrzejewski-Szmek | |
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 <stdio.h> | |
23 | ||
24 | #include "sd-bus.h" | |
07630cea | 25 | |
6ee4f990 ZJS |
26 | #include "bus-internal.h" |
27 | #include "bus-message.h" | |
07630cea | 28 | #include "bus-util.h" |
6ee4f990 ZJS |
29 | #include "refcnt.h" |
30 | ||
31 | static void test_bus_new(void) { | |
32 | _cleanup_bus_unref_ sd_bus *bus = NULL; | |
33 | ||
34 | assert_se(sd_bus_new(&bus) == 0); | |
35 | printf("after new: refcount %u\n", REFCNT_GET(bus->n_ref)); | |
36 | } | |
37 | ||
8d1d1bf2 | 38 | static int test_bus_open(void) { |
6ee4f990 | 39 | _cleanup_bus_unref_ sd_bus *bus = NULL; |
8d1d1bf2 | 40 | int r; |
6ee4f990 | 41 | |
8d1d1bf2 ZJS |
42 | r = sd_bus_open_system(&bus); |
43 | if (r == -ECONNREFUSED || r == -ENOENT) | |
44 | return r; | |
45 | ||
46 | assert_se(r >= 0); | |
6ee4f990 | 47 | printf("after open: refcount %u\n", REFCNT_GET(bus->n_ref)); |
8d1d1bf2 ZJS |
48 | |
49 | return 0; | |
6ee4f990 ZJS |
50 | } |
51 | ||
52 | static void test_bus_new_method_call(void) { | |
53 | sd_bus *bus = NULL; | |
54 | _cleanup_bus_message_unref_ sd_bus_message *m = NULL; | |
55 | ||
56 | assert_se(sd_bus_open_system(&bus) >= 0); | |
57 | ||
151b9b96 | 58 | assert_se(sd_bus_message_new_method_call(bus, &m, "a.service.name", "/an/object/path", "an.interface.name", "AMethodName") >= 0); |
6ee4f990 ZJS |
59 | |
60 | printf("after message_new_method_call: refcount %u\n", REFCNT_GET(bus->n_ref)); | |
61 | ||
62 | sd_bus_unref(bus); | |
63 | printf("after bus_unref: refcount %u\n", m->n_ref); | |
64 | } | |
65 | ||
66 | static void test_bus_new_signal(void) { | |
67 | sd_bus *bus = NULL; | |
68 | _cleanup_bus_message_unref_ sd_bus_message *m = NULL; | |
69 | ||
70 | assert_se(sd_bus_open_system(&bus) >= 0); | |
71 | ||
151b9b96 | 72 | assert_se(sd_bus_message_new_signal(bus, &m, "/an/object/path", "an.interface.name", "Name") >= 0); |
6ee4f990 ZJS |
73 | |
74 | printf("after message_new_signal: refcount %u\n", REFCNT_GET(bus->n_ref)); | |
75 | ||
76 | sd_bus_unref(bus); | |
77 | printf("after bus_unref: refcount %u\n", m->n_ref); | |
78 | } | |
79 | ||
80 | int main(int argc, char **argv) { | |
8d1d1bf2 ZJS |
81 | int r; |
82 | ||
6ee4f990 ZJS |
83 | log_parse_environment(); |
84 | log_open(); | |
85 | ||
86 | test_bus_new(); | |
8d1d1bf2 ZJS |
87 | r = test_bus_open(); |
88 | if (r < 0) { | |
89 | log_info("Failed to connect to bus, skipping tests."); | |
90 | return EXIT_TEST_SKIP; | |
91 | } | |
92 | ||
6ee4f990 ZJS |
93 | test_bus_new_method_call(); |
94 | test_bus_new_signal(); | |
8d1d1bf2 ZJS |
95 | |
96 | return EXIT_SUCCESS; | |
6ee4f990 | 97 | } |