From 9895be6eca0ab75621ff1a32864fc818fc785900 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 2 Jun 2017 12:22:59 +0100 Subject: [PATCH 8/9] test/dbus-daemon: Exercise the Peer interface Signed-off-by: Simon McVittie --- test/dbus-daemon.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index dc73d71c..a490248a 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -1049,6 +1049,110 @@ test_pending_fd_timeout (Fixture *f, #endif static void +test_peer_get_machine_id (Fixture *f, + gconstpointer context) +{ + const char *what_i_think; + const char *what_daemon_thinks; + DBusMessage *m = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, DBUS_INTERFACE_PEER, "GetMachineId"); + DBusPendingCall *pc = NULL; + DBusError error = DBUS_ERROR_INIT; + + if (f->skip) + return; + + what_i_think = dbus_get_local_machine_id (); + + if (what_i_think == NULL) + { + if (g_getenv ("DBUS_TEST_BUILDDIR") != NULL) + { + /* When running unit tests during make check, tolerate this */ + g_test_skip ("Machine UUID not available"); + return; + } + else + { + /* When running integration tests, don't tolerate it */ + g_error ("dbus not installed correctly: machine UUID not available"); + } + } + + /* Check that the dbus-daemon agrees with us. */ + + if (m == NULL || + !dbus_connection_send_with_reply (f->left_conn, m, &pc, + DBUS_TIMEOUT_USE_DEFAULT) || + pc == NULL) + g_error ("OOM"); + + dbus_message_unref (m); + m = NULL; + + if (dbus_pending_call_get_completed (pc)) + test_pending_call_store_reply (pc, &m); + else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply, + &m, NULL)) + g_error ("OOM"); + + while (m == NULL) + test_main_context_iterate (f->ctx, TRUE); + + if (!dbus_message_get_args (m, &error, + DBUS_TYPE_STRING, &what_daemon_thinks, + DBUS_TYPE_INVALID)) + g_error ("%s: %s", error.name, error.message); + + g_assert_cmpstr (what_i_think, ==, what_daemon_thinks); + g_assert_nonnull (what_daemon_thinks); + g_assert_cmpuint (strlen (what_daemon_thinks), ==, 32); + + dbus_message_unref (m); + dbus_pending_call_unref (pc); +} + +static void +test_peer_ping (Fixture *f, + gconstpointer context) +{ + DBusMessage *m = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, DBUS_INTERFACE_PEER, "Ping"); + DBusPendingCall *pc = NULL; + DBusError error = DBUS_ERROR_INIT; + + if (f->skip) + return; + + m = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, DBUS_INTERFACE_PEER, "Ping"); + + if (m == NULL || + !dbus_connection_send_with_reply (f->left_conn, m, &pc, + DBUS_TIMEOUT_USE_DEFAULT) || + pc == NULL) + g_error ("OOM"); + + dbus_message_unref (m); + m = NULL; + + if (dbus_pending_call_get_completed (pc)) + test_pending_call_store_reply (pc, &m); + else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply, + &m, NULL)) + g_error ("OOM"); + + while (m == NULL) + test_main_context_iterate (f->ctx, TRUE); + + if (!dbus_message_get_args (m, &error, DBUS_TYPE_INVALID)) + g_error ("%s: %s", error.name, error.message); + + dbus_message_unref (m); + dbus_pending_call_unref (pc); +} + +static void teardown (Fixture *f, gconstpointer context G_GNUC_UNUSED) { @@ -1197,6 +1301,9 @@ main (int argc, g_test_add ("/limits/max-names-per-connection", Fixture, &max_names_per_connection_config, setup, test_max_names_per_connection, teardown); + g_test_add ("/peer/ping", Fixture, NULL, setup, test_peer_ping, teardown); + g_test_add ("/peer/get-machine-id", Fixture, NULL, + setup, test_peer_get_machine_id, teardown); #if defined(DBUS_UNIX) && defined(HAVE_UNIX_FD_PASSING) && defined(HAVE_GIO_UNIX) g_test_add ("/limits/pending-fd-timeout", Fixture, -- 2.11.0