gboolean do_tests_func (gpointer data) { DBusError error; const gchar *bus_name; DBusMessage *message, *reply; gchar *expected_string; gchar *result_string; dbus_error_init (&error); bus_name = dbus_bus_get_unique_name (bus); /* --------------------------------------------------------*/ message = dbus_message_new_method_call (bus_name, TEST_OBJECT_PATH, TEST_INTERFACE_ONE, "null"); reply = send_and_allow_reentry (bus, message, NULL); dbus_message_unref (message); if (reply) dbus_message_unref (reply); /* --------------------------------------------------------*/ expected_string = TEST_INTERFACE_ONE; result_string = NULL; message = dbus_message_new_method_call (bus_name, TEST_OBJECT_PATH, TEST_INTERFACE_ONE, "getInterfaceOne"); reply = send_and_allow_reentry (bus, message, NULL); dbus_message_unref (message); dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &result_string, DBUS_TYPE_INVALID); dbus_message_unref (reply); if (g_strcmp0(expected_string, result_string)) { g_print ("Failed: reply to getInterfaceOne was %s; expected %s\n", result_string, expected_string); exit (1); } /* --------------------------------------------------------*/ g_main_loop_quit (main_loop); return FALSE; }
int main(int argc, const char *argv[]) { DBusError error; DBusMessage *message = NULL, *reply = NULL; const char *str; main_context = g_main_context_new (); dbus_error_init (&error); bus = dbus_bus_get (DBUS_BUS_SESSION, &error); if (!bus) { fprintf(stderr, "Couldn't connect to bus: %s\n", error.name); return 1; } dbus_connection_setup_with_g_main (bus, NULL); message = dbus_message_new_method_call ("org.freedesktop.DBus", "/org/freedesktop/DBus", DBUS_INTERFACE_DBUS, "GetId"); reply = send_and_allow_reentry (bus, message); if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { char *err; dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &err, DBUS_TYPE_INVALID); fprintf (stderr, "Got error: %s\n", err); return 1; } dbus_message_unref (reply); dbus_message_unref (message); message = dbus_message_new_method_call ("org.freedesktop.DBus", "/org/freedesktop/DBus", DBUS_INTERFACE_DBUS, "GetId"); reply = send_and_allow_reentry (bus, message); if (!reply) { fprintf(stderr, "Sorry; dbus wouldn't answer me: %s\n", error.message); exit(1); } if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { char *err; dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &err, DBUS_TYPE_INVALID); fprintf (stderr, "Got error: %s\n", err); return 1; } if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID)) { fprintf(stderr, "Sorry; can't communicate: %s\n", error.message); exit(1); } return 0; }