From 57a6baae85b7285b39b613ed2d23ef5b3aa3a277 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sat, 15 Dec 2018 18:25:41 +0100 Subject: [PATCH] Test FDN Daemon info --- src/dbus.c | 22 ++++++++++++---------- test/dbus.c | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index d5a7d9a..1b475b3 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -451,7 +451,7 @@ static void dbus_cb_name_acquired(GDBusConnection *connection, * If name or vendor specified, the name and vendor * will get additionally get via the FDN GetServerInformation method * - * @param connection The dbus connection + * @param connection The DBus connection * @param pid The place to report the PID to * @param name The place to report the name to, if not required set to NULL * @param vendor The place to report the vendor to, if not required set to NULL @@ -459,9 +459,9 @@ static void dbus_cb_name_acquired(GDBusConnection *connection, * @returns `true` on success, otherwise `false` */ static bool dbus_get_fdn_daemon_info(GDBusConnection *connection, - int *pid, - char **name, - char **vendor) + guint *pid, + char **name, + char **vendor) { g_return_val_if_fail(pid, false); g_return_val_if_fail(connection, false); @@ -542,17 +542,19 @@ static bool dbus_get_fdn_daemon_info(GDBusConnection *connection, return false; } - g_variant_get(pidinfo, "(u)", &pid); - g_object_unref(proxy_fdn); g_object_unref(proxy_dbus); g_free(owner); if (daemoninfo) g_variant_unref(daemoninfo); - if (pidinfo) - g_variant_unref(pidinfo); - return true; + if (pidinfo) { + g_variant_get(pidinfo, "(u)", &pid); + g_variant_unref(pidinfo); + return true; + } else { + return false; + } } @@ -562,7 +564,7 @@ static void dbus_cb_name_lost(GDBusConnection *connection, { if (connection) { char *name; - int pid; + unsigned int pid; if (dbus_get_fdn_daemon_info(connection, &pid, &name, NULL)) { DIE("Cannot acquire '"FDN_NAME"': " "Name is acquired by '%s' with PID '%d'.", name, pid); diff --git a/test/dbus.c b/test/dbus.c index ff69101..6131802 100644 --- a/test/dbus.c +++ b/test/dbus.c @@ -362,6 +362,29 @@ TEST test_close_and_signal(void) PASS(); } +TEST test_get_fdn_daemon_info(void) +{ + unsigned int pid_is; + pid_t pid_should; + char *name, *vendor; + GDBusConnection *conn; + + pid_should = getpid(); + conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); + + ASSERT(dbus_get_fdn_daemon_info(conn, &pid_is, &name, &vendor)); + + ASSERT_EQ_FMT(pid_should, pid_is, "%d"); + ASSERT_STR_EQ("dunst", name); + ASSERT_STR_EQ("knopwob", vendor); + + g_free(name); + g_free(vendor); + + g_object_unref(conn); + PASS(); +} + TEST assert_methodlists_sorted(void) { for (size_t i = 0; i+1 < G_N_ELEMENTS(methods_fdn); i++) { @@ -383,6 +406,8 @@ gpointer run_threaded_tests(gpointer data) { RUN_TEST(test_dbus_init); + RUN_TEST(test_get_fdn_daemon_info); + RUN_TEST(test_empty_notification); RUN_TEST(test_basic_notification); RUN_TEST(test_invalid_notification);