chiark / gitweb /
sysusers: fix uninitialized warning
[elogind.git] / src / libsystemd / sd-bus / test-bus-cleanup.c
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
30 static 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
37 static void test_bus_open(void) {
38         _cleanup_bus_unref_ sd_bus *bus = NULL;
39
40         assert_se(sd_bus_open_system(&bus) >= 0);
41         printf("after open: refcount %u\n", REFCNT_GET(bus->n_ref));
42 }
43
44 static void test_bus_new_method_call(void) {
45         sd_bus *bus = NULL;
46         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
47
48         assert_se(sd_bus_open_system(&bus) >= 0);
49
50         assert_se(sd_bus_message_new_method_call(bus, &m, "a.service.name", "/an/object/path", "an.interface.name", "AMethodName") >= 0);
51
52         printf("after message_new_method_call: refcount %u\n", REFCNT_GET(bus->n_ref));
53
54         sd_bus_unref(bus);
55         printf("after bus_unref: refcount %u\n", m->n_ref);
56 }
57
58 static void test_bus_new_signal(void) {
59         sd_bus *bus = NULL;
60         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
61
62         assert_se(sd_bus_open_system(&bus) >= 0);
63
64         assert_se(sd_bus_message_new_signal(bus, &m, "/an/object/path", "an.interface.name", "Name") >= 0);
65
66         printf("after message_new_signal: refcount %u\n", REFCNT_GET(bus->n_ref));
67
68         sd_bus_unref(bus);
69         printf("after bus_unref: refcount %u\n", m->n_ref);
70 }
71
72 int main(int argc, char **argv) {
73         log_parse_environment();
74         log_open();
75
76         test_bus_new();
77         test_bus_open();
78         test_bus_new_method_call();
79         test_bus_new_signal();
80 }