From f3cf5352621a0fbf2c1e7f5c3f603fbac1a3b3f7 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 9 Aug 2023 14:45:34 +0200 Subject: Replace DBus-GLib with GDBus and drop libdus fixes https://github.com/AyatanaIndicators/libayatana-appindicator/issues/11 --- tests/test-libappindicator-fallback-item.c | 172 +++++++++++++++-------------- 1 file changed, 91 insertions(+), 81 deletions(-) (limited to 'tests/test-libappindicator-fallback-item.c') diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c index c87ef8c..3c6f630 100644 --- a/tests/test-libappindicator-fallback-item.c +++ b/tests/test-libappindicator-fallback-item.c @@ -1,8 +1,7 @@ #include #include -#include -#include #include +#include "../src/dbus-shared.h" #define TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE (test_libappindicator_fallback_item_get_type ()) #define TEST_LIBAPPINDICATOR_FALLBACK_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, TestLibappindicatorFallbackItem)) @@ -15,12 +14,12 @@ typedef struct _TestLibappindicatorFallbackItem TestLibappindicatorFallback typedef struct _TestLibappindicatorFallbackItemClass TestLibappindicatorFallbackItemClass; struct _TestLibappindicatorFallbackItemClass { - AppIndicatorClass parent_class; + AppIndicatorClass parent_class; }; struct _TestLibappindicatorFallbackItem { - AppIndicator parent; + AppIndicator parent; }; @@ -39,10 +38,10 @@ G_DEFINE_TYPE (TestLibappindicatorFallbackItem, test_libappindicator_fallback_it static void test_libappindicator_fallback_item_class_init (TestLibappindicatorFallbackItemClass *klass) { - AppIndicatorClass * aiclass = APP_INDICATOR_CLASS(klass); + AppIndicatorClass * aiclass = APP_INDICATOR_CLASS(klass); - aiclass->fallback = fallback; - aiclass->unfallback = unfallback; + aiclass->fallback = fallback; + aiclass->unfallback = unfallback; } static void @@ -54,11 +53,11 @@ GMainLoop * mainloop = NULL; gboolean passed = FALSE; enum { - STATE_INIT, - STATE_FALLBACK, - STATE_UNFALLBACK, - STATE_REFALLBACK, - STATE_REUNFALLBACK + STATE_INIT, + STATE_FALLBACK, + STATE_UNFALLBACK, + STATE_REFALLBACK, + STATE_REUNFALLBACK }; gint state = STATE_INIT; @@ -66,88 +65,99 @@ gint state = STATE_INIT; static GtkStatusIcon * fallback (AppIndicator * indicator) { - g_debug("Fallback"); - if (state == STATE_INIT) { - state = STATE_FALLBACK; - } else if (state == STATE_UNFALLBACK) { - state = STATE_REFALLBACK; - } else { - g_debug("Error, fallback in state: %d", state); - passed = FALSE; - } - return (GtkStatusIcon *)5; + g_debug("Fallback"); + if (state == STATE_INIT) { + state = STATE_FALLBACK; + } else if (state == STATE_UNFALLBACK) { + state = STATE_REFALLBACK; + } else { + g_debug("Error, fallback in state: %d", state); + passed = FALSE; + } + return (GtkStatusIcon *)5; } static void unfallback (AppIndicator * indicator, GtkStatusIcon * status_icon) { - g_debug("Unfallback"); - if (state == STATE_FALLBACK) { - state = STATE_UNFALLBACK; - } else if (state == STATE_REFALLBACK) { - state = STATE_REUNFALLBACK; - passed = TRUE; - g_main_loop_quit(mainloop); - } else { - g_debug("Error, unfallback in state: %d", state); - passed = FALSE; - } - return; + g_debug("Unfallback"); + if (state == STATE_FALLBACK) { + state = STATE_UNFALLBACK; + } else if (state == STATE_REFALLBACK) { + state = STATE_REUNFALLBACK; + passed = TRUE; + g_main_loop_quit(mainloop); + } else { + g_debug("Error, unfallback in state: %d", state); + passed = FALSE; + } + return; } gboolean kill_func (gpointer data) { - g_debug("Kill Function"); - g_main_loop_quit(mainloop); - return FALSE; + g_debug("Kill Function"); + g_main_loop_quit(mainloop); + return FALSE; } int main (int argc, char ** argv) { - gtk_init(&argc, &argv); - - GError * error = NULL; - DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); - if (error != NULL) { - g_error("Unable to get session bus: %s", error->message); - return 1; - } - - DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); - - guint nameret = 0; - - if (!org_freedesktop_DBus_request_name(bus_proxy, "org.test", 0, &nameret, NULL)) { - g_error("Unable to call to request name"); - return 1; - } - - if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - g_error("Unable to get name"); - return 1; - } - - TestLibappindicatorFallbackItem * item = g_object_new(TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, - "id", "test-id", - "category", "Other", - "icon-name", "bob", - NULL); - - GtkWidget * menu = gtk_menu_new(); - app_indicator_set_menu(APP_INDICATOR(item), GTK_MENU(menu)); - - g_timeout_add_seconds(20, kill_func, NULL); - - mainloop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(mainloop); - - g_object_unref(G_OBJECT(item)); - - if (passed) { - return 0; - } else { - return 1; - } + gtk_init(&argc, &argv); + GError *pError = NULL; + GDBusProxy *pProxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, NULL, &pError); + + if (pError != NULL) + { + g_error ("Unable to get session bus: %s", pError->message); + g_error_free (pError); + + return 1; + } + + GVariant *pResult = g_dbus_proxy_call_sync (pProxy, "RequestName", g_variant_new ("(su)", "org.test", 0), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &pError); + gint nName = 0; + + if (pResult) + { + g_variant_get (pResult, "(u)", &nName); + g_variant_unref (pResult); + } + else + { + g_error ("Unable to get name: %s", pError->message); + + return 1; + } + + if (nName != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) + { + g_error ("Unable to get name"); + + return 1; + } + + TestLibappindicatorFallbackItem * item = g_object_new(TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, + "id", "test-id", + "category", "Other", + "icon-name", "bob", + NULL); + + GtkWidget * menu = gtk_menu_new(); + app_indicator_set_menu(APP_INDICATOR(item), GTK_MENU(menu)); + + g_timeout_add_seconds(20, kill_func, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_object_unref(G_OBJECT(item)); + + if (passed) { + return 0; + } else { + return 1; + } } -- cgit v1.2.3