diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:35:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:35:18 +0000 |
commit | b750101eb236130cf056c675997decbac904cc49 (patch) | |
tree | a5df1a06754bdd014cb975c051c83b01c9a97532 /src/test/test-bus-util.c | |
parent | Initial commit. (diff) | |
download | systemd-b750101eb236130cf056c675997decbac904cc49.tar.xz systemd-b750101eb236130cf056c675997decbac904cc49.zip |
Adding upstream version 252.22.upstream/252.22
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-bus-util.c')
-rw-r--r-- | src/test/test-bus-util.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/test-bus-util.c b/src/test/test-bus-util.c new file mode 100644 index 0000000..2f52bca --- /dev/null +++ b/src/test/test-bus-util.c @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "bus-util.h" +#include "log.h" +#include "tests.h" + +static int callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { + return 1; +} + +static void destroy_callback(void *userdata) { + int *n_called = userdata; + + (*n_called) ++; +} + +TEST(destroy_callback) { + _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; + sd_bus_slot *slot = NULL; + sd_bus_destroy_t t; + + int r, n_called = 0; + + r = bus_open_system_watch_bind_with_description(&bus, "test-bus"); + if (r < 0) { + log_error_errno(r, "Failed to connect to bus: %m"); + return; + } + + r = sd_bus_request_name_async(bus, &slot, "org.freedesktop.systemd.test-bus-util", 0, callback, &n_called); + assert_se(r == 1); + + assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 0); + assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 0); + + assert_se(sd_bus_slot_set_destroy_callback(slot, destroy_callback) == 0); + assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 1); + assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 1); + assert_se(t == destroy_callback); + + /* Force cleanup so we can look at n_called */ + assert_se(n_called == 0); + sd_bus_slot_unref(slot); + assert_se(n_called == 1); +} + +DEFINE_TEST_MAIN(LOG_DEBUG); |