]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd/sd-bus/test-bus-cleanup.c
tmpfiles: accurately report creation results
[thirdparty/systemd.git] / src / libsystemd / sd-bus / test-bus-cleanup.c
CommitLineData
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"
25#include "bus-util.h"
26#include "bus-internal.h"
27#include "bus-message.h"
28#include "refcnt.h"
29
30static void test_bus_new(void) {
31 _cleanup_bus_unref_ sd_bus *bus = NULL;
32
33 assert_se(sd_bus_new(&bus) == 0);
34 printf("after new: refcount %u\n", REFCNT_GET(bus->n_ref));
35}
36
8d1d1bf2 37static int test_bus_open(void) {
6ee4f990 38 _cleanup_bus_unref_ sd_bus *bus = NULL;
8d1d1bf2 39 int r;
6ee4f990 40
8d1d1bf2
ZJS
41 r = sd_bus_open_system(&bus);
42 if (r == -ECONNREFUSED || r == -ENOENT)
43 return r;
44
45 assert_se(r >= 0);
6ee4f990 46 printf("after open: refcount %u\n", REFCNT_GET(bus->n_ref));
8d1d1bf2
ZJS
47
48 return 0;
6ee4f990
ZJS
49}
50
51static void test_bus_new_method_call(void) {
52 sd_bus *bus = NULL;
53 _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
54
55 assert_se(sd_bus_open_system(&bus) >= 0);
56
151b9b96 57 assert_se(sd_bus_message_new_method_call(bus, &m, "a.service.name", "/an/object/path", "an.interface.name", "AMethodName") >= 0);
6ee4f990
ZJS
58
59 printf("after message_new_method_call: refcount %u\n", REFCNT_GET(bus->n_ref));
60
61 sd_bus_unref(bus);
62 printf("after bus_unref: refcount %u\n", m->n_ref);
63}
64
65static void test_bus_new_signal(void) {
66 sd_bus *bus = NULL;
67 _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
68
69 assert_se(sd_bus_open_system(&bus) >= 0);
70
151b9b96 71 assert_se(sd_bus_message_new_signal(bus, &m, "/an/object/path", "an.interface.name", "Name") >= 0);
6ee4f990
ZJS
72
73 printf("after message_new_signal: refcount %u\n", REFCNT_GET(bus->n_ref));
74
75 sd_bus_unref(bus);
76 printf("after bus_unref: refcount %u\n", m->n_ref);
77}
78
79int main(int argc, char **argv) {
8d1d1bf2
ZJS
80 int r;
81
6ee4f990
ZJS
82 log_parse_environment();
83 log_open();
84
85 test_bus_new();
8d1d1bf2
ZJS
86 r = test_bus_open();
87 if (r < 0) {
88 log_info("Failed to connect to bus, skipping tests.");
89 return EXIT_TEST_SKIP;
90 }
91
6ee4f990
ZJS
92 test_bus_new_method_call();
93 test_bus_new_signal();
8d1d1bf2
ZJS
94
95 return EXIT_SUCCESS;
6ee4f990 96}