1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 static int callback(sd_bus_message
*m
, void *userdata
, sd_bus_error
*ret_error
) {
11 static void destroy_callback(void *userdata
) {
12 int *n_called
= userdata
;
17 static void test_destroy_callback(void) {
18 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
19 sd_bus_slot
*slot
= NULL
;
24 log_info("/* %s */", __func__
);
26 r
= bus_open_system_watch_bind_with_description(&bus
, "test-bus");
28 log_error_errno(r
, "Failed to connect to bus: %m");
32 r
= sd_bus_request_name_async(bus
, &slot
, "org.freedesktop.systemd.test-bus-util", 0, callback
, &n_called
);
35 assert_se(sd_bus_slot_get_destroy_callback(slot
, NULL
) == 0);
36 assert_se(sd_bus_slot_get_destroy_callback(slot
, &t
) == 0);
38 assert_se(sd_bus_slot_set_destroy_callback(slot
, destroy_callback
) == 0);
39 assert_se(sd_bus_slot_get_destroy_callback(slot
, NULL
) == 1);
40 assert_se(sd_bus_slot_get_destroy_callback(slot
, &t
) == 1);
41 assert_se(t
== destroy_callback
);
43 /* Force cleanup so we can look at n_called */
44 assert(n_called
== 0);
45 sd_bus_slot_unref(slot
);
46 assert(n_called
== 1);
49 int main(int argc
, char **argv
) {
50 test_setup_logging(LOG_DEBUG
);
52 test_destroy_callback();