From 11791cdeccd3e01f84dff614d344d4bda5d40a54 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 27 Aug 2019 17:34:39 +0200 Subject: [PATCH] test-bus-vtable: also print introspection for the fallback vtable This doesn't really test anything, it's just a trivial test that we get the expected output for a fallback vtable. --- src/libsystemd/sd-bus/test-bus-vtable.c | 26 ++++++++++++++++++++++++-- src/libsystemd/sd-bus/test-vtable-data.h | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/libsystemd/sd-bus/test-bus-vtable.c b/src/libsystemd/sd-bus/test-bus-vtable.c index d69ca6a..b635002 100644 --- a/src/libsystemd/sd-bus/test-bus-vtable.c +++ b/src/libsystemd/sd-bus/test-bus-vtable.c @@ -19,9 +19,24 @@ #define DEFAULT_BUS_PATH "unix:path=/run/dbus/system_bus_socket" +static struct context c = {}; +static int happy_finder_object = 0; + +static int happy_finder(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) { + assert(userdata); + assert(userdata == &c); + +#ifndef __cplusplus + log_info("%s called", __func__); +#endif + + happy_finder_object++; + *found = &happy_finder_object; + return 1; /* found */ +} + static void test_vtable(void) { sd_bus *bus = NULL; - struct context c = {}; int r; assert(sd_bus_new(&bus) >= 0); @@ -32,16 +47,23 @@ static void test_vtable(void) { assert(sd_bus_add_object_vtable(bus, NULL, "/foo", "org.freedesktop.systemd.testVtable221", (const sd_bus_vtable *)vtable_format_221, &c) >= 0); + assert(sd_bus_add_fallback_vtable(bus, NULL, "/fallback", "org.freedesktop.systemd.testVtable2", test_vtable_2, happy_finder, &c) >= 0); + assert(sd_bus_set_address(bus, DEFAULT_BUS_PATH) >= 0); r = sd_bus_start(bus); assert(r == 0 || /* success */ r == -ENOENT /* dbus is inactive */ ); #ifndef __cplusplus - _cleanup_free_ char *s = NULL; + _cleanup_free_ char *s, *s2; assert_se(introspect_path(bus, "/foo", NULL, false, true, NULL, &s, NULL) == 1); fputs(s, stdout); + + assert_se(introspect_path(bus, "/fallback", NULL, false, true, NULL, &s2, NULL) == 1); + fputs(s2, stdout); + + assert_se(happy_finder_object == 1); #endif sd_bus_unref(bus); diff --git a/src/libsystemd/sd-bus/test-vtable-data.h b/src/libsystemd/sd-bus/test-vtable-data.h index 333dbd5..bc89893 100644 --- a/src/libsystemd/sd-bus/test-vtable-data.h +++ b/src/libsystemd/sd-bus/test-vtable-data.h @@ -42,7 +42,7 @@ static const sd_bus_vtable test_vtable_1[] = { static const sd_bus_vtable test_vtable_2[] = { SD_BUS_VTABLE_START(0), - SD_BUS_METHOD("AlterSomething", "s", "s", handler, 0), + SD_BUS_METHOD("AlterSomething", "s", "s", handler, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("Exit", "", "", handler, 0), SD_BUS_METHOD_WITH_OFFSET("AlterSomething2", "s", "s", handler, 200, 0), SD_BUS_METHOD_WITH_OFFSET("Exit2", "", "", handler, 200, 0), -- 2.7.4