From 25001b09fdf8d10b2c209bfedd882bd90bd5b08a Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 9 Aug 2023 14:41:14 +0200 Subject: tests/test-libappindicator.c: Drop unread value --- tests/test-libappindicator.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test-libappindicator.c b/tests/test-libappindicator.c index 68c6a93..0273398 100644 --- a/tests/test-libappindicator.c +++ b/tests/test-libappindicator.c @@ -68,15 +68,12 @@ test_libappindicator_prop_signals (void) gboolean signaled = FALSE; gulong handlerid; - handlerid = 0; handlerid = g_signal_connect(G_OBJECT(ci), "new-icon", G_CALLBACK(test_libappindicator_prop_signals_helper), &signaled); g_assert(handlerid != 0); - handlerid = 0; handlerid = g_signal_connect(G_OBJECT(ci), "new-attention-icon", G_CALLBACK(test_libappindicator_prop_signals_helper), &signaled); g_assert(handlerid != 0); - handlerid = 0; handlerid = g_signal_connect(G_OBJECT(ci), "new-status", G_CALLBACK(test_libappindicator_prop_signals_status_helper), &signaled); g_assert(handlerid != 0); -- cgit v1.2.3 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 --- CMakeLists.txt | 4 - src/dbus-shared.h | 19 +- tests/test-libappindicator-dbus-client.c | 501 ++++++++++++++------------ tests/test-libappindicator-fallback-item.c | 172 ++++----- tests/test-libappindicator-fallback-watcher.c | 135 ++++--- tests/test-libappindicator-status-client.c | 213 +++++------ 6 files changed, 567 insertions(+), 477 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fd080d..cd30268 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,10 +66,6 @@ elseif (FLAVOUR_GTK2) ) endif() -if(ENABLE_TESTS) - set(DEPS ${DEPS} dbus-1>=1.12 dbus-glib-1>=0.82) -endif() - include(GNUInstallDirs) find_package(PkgConfig REQUIRED) pkg_check_modules(PROJECT_DEPS REQUIRED ${DEPS}) diff --git a/src/dbus-shared.h b/src/dbus-shared.h index 23f44f0..1ec15b8 100644 --- a/src/dbus-shared.h +++ b/src/dbus-shared.h @@ -2,23 +2,30 @@ DBus defaults for everyone to share in the project. Copyright 2009 Canonical Ltd. +Copyright 2023 Robert Tari Authors: Ted Gould + Robert Tari -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published by the Free Software Foundation. -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along +You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#define DBUS_SERVICE_DBUS "org.freedesktop.DBus" +#define DBUS_PATH_DBUS "/org/freedesktop/DBus" +#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus" +#define DBUS_INTERFACE_PROPERTIES "org.freedesktop.DBus.Properties" +#define DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER 1 #define INDICATOR_APPLICATION_DBUS_ADDR "org.ayatana.indicator.application" #define INDICATOR_APPLICATION_DBUS_OBJ "/org/ayatana/indicator/application/service" diff --git a/tests/test-libappindicator-dbus-client.c b/tests/test-libappindicator-dbus-client.c index 18c6946..bc7626a 100644 --- a/tests/test-libappindicator-dbus-client.c +++ b/tests/test-libappindicator-dbus-client.c @@ -3,9 +3,11 @@ Tests for the libappindicator library that are over DBus. This is the client side of those tests. Copyright 2009 Canonical Ltd. +Copyright 2023 Robert Tari Authors: Ted Gould + Robert Tari This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published @@ -22,12 +24,8 @@ with this program. If not, see . #include -#include -#include -#include #include #include "test-defines.h" - #include "../src/dbus-shared.h" static GMainLoop * mainloop = NULL; @@ -37,254 +35,305 @@ static int propcount = 0; static void check_propcount (void) { - if (propcount >= 5) { - g_main_loop_quit(mainloop); - } - return; + if (propcount >= 5) { + g_main_loop_quit(mainloop); + } + return; } - -static void -prop_id_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data) +static void prop_id_cb (GObject *pObject, GAsyncResult *pResult, void *pUserata) { - propcount++; - - GError * error = NULL; - GValue value = {0}; - - if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &value, G_TYPE_INVALID)) { - g_warning("Getting ID failed: %s", error->message); - g_error_free(error); - passed = FALSE; - check_propcount(); - return; - } - - if (g_strcmp0(TEST_ID, g_value_get_string(&value))) { - g_debug("Property ID Returned: FAILED"); - passed = FALSE; - } else { - g_debug("Property ID Returned: PASSED"); - } - - check_propcount(); - return; + propcount++; + GError *pError = NULL; + GVariant *pParams = g_dbus_proxy_call_finish (G_DBUS_PROXY (pObject), pResult, &pError); + + if (pParams) + { + gchar *sInterface = NULL; + gchar *sId = NULL; + g_variant_get (pParams, "(ss)", &sInterface, &sId); + gint nComp = g_strcmp0 (TEST_ID, sId); + + if (nComp) + { + g_debug ("Property ID Returned: FAILED"); + passed = FALSE; + } + else + { + g_debug ("Property ID Returned: PASSED"); + } + + g_variant_unref (pParams); + } + + if (pError) + { + g_warning ("Getting ID failed: %s", pError->message); + g_error_free (pError); + passed = FALSE; + check_propcount(); + + return; + } + + check_propcount(); + + return; } -static void -prop_category_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data) +static void prop_category_cb (GObject *pObject, GAsyncResult *pResult, void *pUserata) { - propcount++; - - GError * error = NULL; - GValue value = {0}; - - if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &value, G_TYPE_INVALID)) { - g_warning("Getting category failed: %s", error->message); - g_error_free(error); - passed = FALSE; - check_propcount(); - return; - } - - if (g_strcmp0(TEST_CATEGORY_S, g_value_get_string(&value))) { - g_debug("Property category Returned: FAILED"); - passed = FALSE; - } else { - g_debug("Property category Returned: PASSED"); - } - - check_propcount(); - return; + propcount++; + GError *pError = NULL; + GVariant *pParams = g_dbus_proxy_call_finish (G_DBUS_PROXY (pObject), pResult, &pError); + + if (pParams) + { + gchar *sInterface = NULL; + gchar *sCategory = NULL; + g_variant_get (pParams, "(ss)", &sInterface, &sCategory); + gint nComp = g_strcmp0 (TEST_CATEGORY_S, sCategory); + + if (nComp) + { + g_debug ("Property category Returned: FAILED"); + passed = FALSE; + } + else + { + g_debug ("Property category Returned: PASSED"); + } + + g_variant_unref (pParams); + } + + if (pError) + { + g_warning ("Getting category failed: %s", pError->message); + g_error_free (pError); + passed = FALSE; + check_propcount(); + + return; + } + + check_propcount(); + + return; } -static void -prop_status_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data) +static void prop_status_cb (GObject *pObject, GAsyncResult *pResult, void *pUserata) { - propcount++; - - GError * error = NULL; - GValue value = {0}; - - if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &value, G_TYPE_INVALID)) { - g_warning("Getting status failed: %s", error->message); - g_error_free(error); - passed = FALSE; - check_propcount(); - return; - } - - if (g_strcmp0(TEST_STATE_S, g_value_get_string(&value))) { - g_debug("Property status Returned: FAILED"); - passed = FALSE; - } else { - g_debug("Property status Returned: PASSED"); - } - - check_propcount(); - return; + propcount++; + GError *pError = NULL; + GVariant *pParams = g_dbus_proxy_call_finish (G_DBUS_PROXY (pObject), pResult, &pError); + + if (pParams) + { + gchar *sInterface = NULL; + gchar *sStatus = NULL; + g_variant_get (pParams, "(ss)", &sInterface, &sStatus); + gint nComp = g_strcmp0 (TEST_STATE_S, sStatus); + + if (nComp) + { + g_debug ("Property status Returned: FAILED"); + passed = FALSE; + } + else + { + g_debug ("Property status Returned: PASSED"); + } + + g_variant_unref (pParams); + } + + if (pError) + { + g_warning ("Getting status failed: %s", pError->message); + g_error_free (pError); + passed = FALSE; + check_propcount(); + + return; + } + + check_propcount(); + + return; } -static void -prop_icon_name_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data) +static void prop_icon_name_cb (GObject *pObject, GAsyncResult *pResult, void *pUserata) { - propcount++; - - GError * error = NULL; - GValue value = {0}; - - if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &value, G_TYPE_INVALID)) { - g_warning("Getting icon name failed: %s", error->message); - g_error_free(error); - passed = FALSE; - check_propcount(); - return; - } - - if (g_strcmp0(TEST_ICON_NAME, g_value_get_string(&value))) { - g_debug("Property icon name Returned: FAILED"); - passed = FALSE; - } else { - g_debug("Property icon name Returned: PASSED"); - } - - check_propcount(); - return; + propcount++; + GError *pError = NULL; + GVariant *pParams = g_dbus_proxy_call_finish (G_DBUS_PROXY (pObject), pResult, &pError); + + if (pParams) + { + gchar *sInterface = NULL; + gchar *sIcon = NULL; + g_variant_get (pParams, "(ss)", &sInterface, &sIcon); + gint nComp = g_strcmp0 (TEST_ICON_NAME, sIcon); + + if (nComp) + { + g_debug ("Property icon name Returned: FAILED"); + passed = FALSE; + } + else + { + g_debug ("Property icon name Returned: PASSED"); + } + + g_variant_unref (pParams); + } + + if (pError) + { + g_warning ("Getting icon name failed: %s", pError->message); + g_error_free (pError); + passed = FALSE; + check_propcount(); + + return; + } + + check_propcount(); + + return; } -static void -prop_attention_icon_name_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data) +static void prop_attention_icon_name_cb (GObject *pObject, GAsyncResult *pResult, void *pUserata) { - propcount++; - - GError * error = NULL; - GValue value = {0}; - - if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &value, G_TYPE_INVALID)) { - g_warning("Getting attention icon name failed: %s", error->message); - g_error_free(error); - passed = FALSE; - check_propcount(); - return; - } - - if (g_strcmp0(TEST_ATTENTION_ICON_NAME, g_value_get_string(&value))) { - g_debug("Property attention icon name Returned: FAILED"); - passed = FALSE; - } else { - g_debug("Property attention icon name Returned: PASSED"); - } - - check_propcount(); - return; + propcount++; + GError *pError = NULL; + GVariant *pParams = g_dbus_proxy_call_finish (G_DBUS_PROXY (pObject), pResult, &pError); + + if (pParams) + { + gchar *sInterface = NULL; + gchar *sAttentionIcon = NULL; + g_variant_get (pParams, "(ss)", &sInterface, &sAttentionIcon); + gint nComp = g_strcmp0 (TEST_ATTENTION_ICON_NAME, sAttentionIcon); + + if (nComp) + { + g_debug ("Property attention icon name Returned: FAILED"); + passed = FALSE; + } + else + { + g_debug ("Property attention icon name Returned: PASSED"); + } + + g_variant_unref (pParams); + } + + if (pError) + { + g_warning ("Getting attention icon name failed: %s", pError->message); + g_error_free (pError); + passed = FALSE; + check_propcount(); + + return; + } + + check_propcount(); + + return; } gboolean kill_func (gpointer userdata) { - g_main_loop_quit(mainloop); - g_warning("Forced to Kill"); - passed = FALSE; - return FALSE; + g_main_loop_quit(mainloop); + g_warning("Forced to Kill"); + passed = FALSE; + return FALSE; } -static DBusHandlerResult -dbus_filter (DBusConnection * connection, DBusMessage * message, void * user_data) +static GDBusMessage* dbus_filter (GDBusConnection *pConnection, GDBusMessage *pMessage, gboolean bIncoming, void *pUserData) { - if (dbus_message_is_method_call(message, NOTIFICATION_WATCHER_DBUS_ADDR, "RegisterStatusNotifierItem")) { - DBusMessage * reply = dbus_message_new_method_return(message); - dbus_connection_send(connection, reply, NULL); - dbus_message_unref(reply); - return DBUS_HANDLER_RESULT_HANDLED; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + GDBusMessageType cType = g_dbus_message_get_message_type (pMessage); + const gchar *sInterface = g_dbus_message_get_interface (pMessage); + const gchar *sMember = g_dbus_message_get_member (pMessage); + int nInterfaceComp = g_strcmp0 (sInterface, NOTIFICATION_WATCHER_DBUS_ADDR); + int nMemberComp = g_strcmp0 (sMember, "RegisterStatusNotifierItem"); + + if (cType == G_DBUS_MESSAGE_TYPE_METHOD_CALL && nInterfaceComp == 0 && nMemberComp == 0) + { + GDBusMessage *pReply = g_dbus_message_new_method_reply (pMessage); + g_dbus_connection_send_message (pConnection, pReply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (pReply); + g_object_unref (pMessage); + pMessage = NULL; + } + + return pMessage; } gint main (gint argc, gchar * 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, NOTIFICATION_WATCHER_DBUS_ADDR, 0, &nameret, &error)) { - 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; - } - - dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL); - - g_usleep(500000); - - DBusGProxy * props = dbus_g_proxy_new_for_name_owner(session_bus, - ":1.2", - "/org/ayatana/NotificationItem/my_id", - DBUS_INTERFACE_PROPERTIES, - &error); - if (error != NULL) { - g_error("Unable to get property proxy: %s", error->message); - return 1; - } - - dbus_g_proxy_begin_call (props, - "Get", - prop_id_cb, - NULL, NULL, - G_TYPE_STRING, NOTIFICATION_ITEM_DBUS_IFACE, - G_TYPE_STRING, "Id", - G_TYPE_INVALID); - dbus_g_proxy_begin_call (props, - "Get", - prop_category_cb, - NULL, NULL, - G_TYPE_STRING, NOTIFICATION_ITEM_DBUS_IFACE, - G_TYPE_STRING, "Category", - G_TYPE_INVALID); - dbus_g_proxy_begin_call (props, - "Get", - prop_status_cb, - NULL, NULL, - G_TYPE_STRING, NOTIFICATION_ITEM_DBUS_IFACE, - G_TYPE_STRING, "Status", - G_TYPE_INVALID); - dbus_g_proxy_begin_call (props, - "Get", - prop_icon_name_cb, - NULL, NULL, - G_TYPE_STRING, NOTIFICATION_ITEM_DBUS_IFACE, - G_TYPE_STRING, "IconName", - G_TYPE_INVALID); - dbus_g_proxy_begin_call (props, - "Get", - prop_attention_icon_name_cb, - NULL, NULL, - G_TYPE_STRING, NOTIFICATION_ITEM_DBUS_IFACE, - G_TYPE_STRING, "AttentionIconName", - G_TYPE_INVALID); - - g_timeout_add_seconds(2, kill_func, NULL); - - mainloop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(mainloop); - - if (passed) { - g_debug("Quiting"); - return 0; - } else { - g_debug("Quiting as we're a failure"); - return 1; - } - return 0; + 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; + } + + GDBusConnection *pConnection = g_dbus_proxy_get_connection (pProxy); + guint nName = g_bus_own_name_on_connection (pConnection, NOTIFICATION_WATCHER_DBUS_ADDR, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL); + + if (!nName) + { + g_error ("Unable to call to request name"); + + return 1; + } + + if (nName != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) + { + g_error ("Unable to get name"); + + return 1; + } + + g_dbus_connection_add_filter (pConnection, dbus_filter, NULL, NULL); + g_usleep(500000); + GDBusProxy *pProps = g_dbus_proxy_new_sync (pConnection, G_DBUS_PROXY_FLAGS_NONE, NULL, ":1.2", "/org/ayatana/NotificationItem/my_id", DBUS_INTERFACE_PROPERTIES, NULL, &pError); + + if (pError != NULL) + { + g_error ("Unable to get property proxy: %s", pError->message); + g_error_free (pError); + + return 1; + } + + g_dbus_proxy_call (pProps, "Get", g_variant_new ("(ss)", NOTIFICATION_ITEM_DBUS_IFACE, "Id"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback) prop_id_cb, NULL); + g_dbus_proxy_call (pProps, "Get", g_variant_new ("(ss)", NOTIFICATION_ITEM_DBUS_IFACE, "Category"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback) prop_category_cb, NULL); + g_dbus_proxy_call (pProps, "Get", g_variant_new ("(ss)", NOTIFICATION_ITEM_DBUS_IFACE, "Status"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback) prop_status_cb, NULL); + g_dbus_proxy_call (pProps, "Get", g_variant_new ("(ss)", NOTIFICATION_ITEM_DBUS_IFACE, "IconName"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback) prop_icon_name_cb, NULL); + g_dbus_proxy_call (pProps, "Get", g_variant_new ("(ss)", NOTIFICATION_ITEM_DBUS_IFACE, "AttentionIconName"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback) prop_attention_icon_name_cb, NULL); + g_timeout_add_seconds(2, kill_func, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + if (passed) { + g_debug("Quiting"); + return 0; + } else { + g_debug("Quiting as we're a failure"); + return 1; + } + return 0; } 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; + } } diff --git a/tests/test-libappindicator-fallback-watcher.c b/tests/test-libappindicator-fallback-watcher.c index 2648902..9261571 100644 --- a/tests/test-libappindicator-fallback-watcher.c +++ b/tests/test-libappindicator-fallback-watcher.c @@ -3,9 +3,11 @@ This puts the NotificationWatcher on the bus, kinda. Enough to trick the Item into unfalling back. Copyright 2010 Canonical Ltd. +Copyright 2023 Robert Tari Authors: Ted Gould + Robert Tari This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published @@ -21,96 +23,111 @@ with this program. If not, see . */ #include -#include -#include -#include - +#include #include "../src/dbus-shared.h" gboolean kill_func (gpointer userdata); static GMainLoop * mainloop = NULL; -static DBusHandlerResult -dbus_filter (DBusConnection * connection, DBusMessage * message, void * user_data) +static GDBusMessage* dbus_filter (GDBusConnection *pConnection, GDBusMessage *pMessage, gboolean bIncoming, void *pUserData) { - if (dbus_message_is_method_call(message, NOTIFICATION_WATCHER_DBUS_ADDR, "RegisterStatusNotifierItem")) { - DBusMessage * reply = dbus_message_new_method_return(message); - dbus_connection_send(connection, reply, NULL); - dbus_message_unref(reply); - - /* Let the messages get out, but we're done at this point */ - g_timeout_add(50, kill_func, NULL); - - return DBUS_HANDLER_RESULT_HANDLED; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + GDBusMessageType cType = g_dbus_message_get_message_type (pMessage); + const gchar *sMember = g_dbus_message_get_member (pMessage); + int nMemberComp = g_strcmp0 (sMember, "RegisterStatusNotifierItem"); + + if (cType == G_DBUS_MESSAGE_TYPE_METHOD_CALL && nMemberComp == 0) + { + GDBusMessage *pReply = g_dbus_message_new_method_reply (pMessage); + g_dbus_connection_send_message (pConnection, pReply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (pReply); + g_timeout_add (50, kill_func, NULL); + g_object_unref (pMessage); + pMessage = NULL; + } + + return pMessage; } gboolean kill_func (gpointer userdata) { - g_main_loop_quit(mainloop); - return FALSE; + g_main_loop_quit(mainloop); + return FALSE; } int main (int argv, char ** argc) { - g_debug("Waiting to init."); + g_debug("Waiting to init."); + + 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; + } + + g_usleep (500000); + gboolean bOwner = FALSE; + GVariant *pResult = g_dbus_proxy_call_sync (pProxy, "NameHasOwner", g_variant_new ("(s)", "org.test"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &pError); + if (pResult) + { + g_variant_get (pResult, "(b)", &bOwner); + g_variant_unref (pResult); + } + else + { + g_error ("Error getting name owner: %s", pError->message); + g_error_free (pError); - 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; - } + return 1; + } - DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + if (!bOwner) + { + g_error ("Unable to get name owner"); - gboolean has_owner = FALSE; - gint owner_count = 0; - while (!has_owner && owner_count < 10000) { - org_freedesktop_DBus_name_has_owner(bus_proxy, "org.test", &has_owner, NULL); - owner_count++; - g_usleep(500000); - } + return 1; + } - if (owner_count == 10000) { - g_error("Unable to get name owner after 10000 tries"); - return 1; - } + g_usleep(500000); + g_debug("Initing"); - g_usleep(500000); + GDBusConnection *pConnection = g_dbus_proxy_get_connection (pProxy); + guint nName = g_bus_own_name_on_connection (pConnection, NOTIFICATION_WATCHER_DBUS_ADDR, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL); - g_debug("Initing"); + if (!nName) + { + g_error ("Unable to call to request name"); - guint nameret = 0; + return 1; + } - if (!org_freedesktop_DBus_request_name(bus_proxy, NOTIFICATION_WATCHER_DBUS_ADDR, 0, &nameret, &error)) { - g_error("Unable to call to request name"); - return 1; - } + if (nName != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) + { + g_error ("Unable to get name"); - if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - g_error("Unable to get name"); - return 1; - } + return 1; + } - dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL); + g_dbus_connection_add_filter (pConnection, dbus_filter, NULL, NULL); - /* This is the final kill function. It really shouldn't happen - unless we get an error. */ - g_timeout_add_seconds(20, kill_func, NULL); + /* This is the final kill function. It really shouldn't happen + unless we get an error. */ + g_timeout_add_seconds(20, kill_func, NULL); - g_debug("Entering Mainloop"); + g_debug("Entering Mainloop"); - mainloop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(mainloop); + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); - g_debug("Exiting"); + g_debug("Exiting"); - return 0; + return 0; } diff --git a/tests/test-libappindicator-status-client.c b/tests/test-libappindicator-status-client.c index cd60e6c..beeeaad 100644 --- a/tests/test-libappindicator-status-client.c +++ b/tests/test-libappindicator-status-client.c @@ -3,9 +3,11 @@ Tests for the libappindicator library that are over DBus. This is the client side of those tests. Copyright 2009 Canonical Ltd. +Copyright 2023 Robert Tari Authors: Ted Gould + Robert Tari This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published @@ -20,11 +22,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - #include -#include -#include -#include +#include #include "../src/dbus-shared.h" static GMainLoop * mainloop = NULL; @@ -37,115 +36,127 @@ static guint toggle_count = 0; #define ACTIVE_STR "Active" #define ATTN_STR "NeedsAttention" -static DBusHandlerResult -dbus_reg_filter (DBusConnection * connection, DBusMessage * message, void * user_data) +static GDBusMessage* dbus_reg_filter (GDBusConnection *pConnection, GDBusMessage *pMessage, gboolean bIncoming, void *pUserData) { - if (dbus_message_is_method_call(message, NOTIFICATION_WATCHER_DBUS_ADDR, "RegisterStatusNotifierItem")) { - DBusMessage * reply = dbus_message_new_method_return(message); - dbus_connection_send(connection, reply, NULL); - dbus_message_unref(reply); - return DBUS_HANDLER_RESULT_HANDLED; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + GDBusMessageType cType = g_dbus_message_get_message_type (pMessage); + const gchar *sInterface = g_dbus_message_get_interface (pMessage); + const gchar *sMember = g_dbus_message_get_member (pMessage); + int nInterfaceComp = g_strcmp0 (sInterface, NOTIFICATION_WATCHER_DBUS_ADDR); + int nMemberComp = g_strcmp0 (sMember, "RegisterStatusNotifierItem"); + + if (cType == G_DBUS_MESSAGE_TYPE_METHOD_CALL && nInterfaceComp == 0 && nMemberComp == 0) + { + GDBusMessage *pReply = g_dbus_message_new_method_reply (pMessage); + g_dbus_connection_send_message (pConnection, pReply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (pReply); + + g_object_unref (pMessage); + pMessage = NULL; + } + + return pMessage; } - -static DBusHandlerResult -dbus_filter (DBusConnection * connection, DBusMessage * message, void * user_data) +void onNewStatus (GDBusConnection* pConnection, const gchar *sSender, const gchar *sPath, const gchar *sInterface, const gchar *sSignal, GVariant *pParameters, gpointer pUserData) { - if (!dbus_message_is_signal(message, NOTIFICATION_ITEM_DBUS_IFACE, "NewStatus")) { - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - gchar * string; - - DBusError derror; - dbus_error_init(&derror); - if (!dbus_message_get_args(message, &derror, - DBUS_TYPE_STRING, &string, - DBUS_TYPE_INVALID)) { - g_warning("Couldn't get parameters"); - dbus_error_free(&derror); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - watchdog_hit = TRUE; - - if (g_strcmp0(string, ACTIVE_STR) == 0) { - if (active) { - g_warning("Got active when already active"); - passed = FALSE; - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - active = TRUE; - } else { - active = FALSE; - } - - toggle_count++; - - if (toggle_count == 100) { - g_main_loop_quit(mainloop); - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + const gchar *sParam = NULL; + g_variant_get (pParameters, "(s)", &sParam); + + if (!sParam) + { + g_warning ("Couldn't get parameter"); + + return; + } + + watchdog_hit = TRUE; + int nComp = g_strcmp0 (sParam, ACTIVE_STR); + + if (!nComp) + { + if (active) + { + g_warning ("Got active when already active"); + passed = FALSE; + + return; + } + + active = TRUE; + } + else + { + active = FALSE; + } + + toggle_count++; + + if (toggle_count == 100) + { + g_main_loop_quit (mainloop); + } } gboolean kill_func (gpointer userdata) { - if (watchdog_hit == FALSE) { - g_main_loop_quit(mainloop); - g_warning("Forced to Kill"); - g_warning("Toggle count: %d", toggle_count); - passed = FALSE; - return FALSE; - } - watchdog_hit = FALSE; - return TRUE; + if (watchdog_hit == FALSE) { + g_main_loop_quit(mainloop); + g_warning("Forced to Kill"); + g_warning("Toggle count: %d", toggle_count); + passed = FALSE; + return FALSE; + } + watchdog_hit = FALSE; + return TRUE; } gint main (gint argc, gchar * 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, NOTIFICATION_WATCHER_DBUS_ADDR, 0, &nameret, &error)) { - 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; - } - - dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_reg_filter, NULL, NULL); - - dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL); - dbus_bus_add_match(dbus_g_connection_get_connection(session_bus), "type='signal',interface='" NOTIFICATION_ITEM_DBUS_IFACE "',member='NewStatus'", NULL); - - watchdog_hit = TRUE; - g_timeout_add_seconds(20, kill_func, NULL); - - mainloop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(mainloop); - - if (passed) { - g_debug("Quiting"); - return 0; - } else { - g_debug("Quiting as we're a failure"); - return 1; - } - return 0; + 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; + } + + GDBusConnection *pConnection = g_dbus_proxy_get_connection (pProxy); + guint nName = g_bus_own_name_on_connection (pConnection, NOTIFICATION_WATCHER_DBUS_ADDR, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL); + + if (!nName) + { + g_error ("Unable to call to request name"); + + return 1; + } + + if (nName != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) + { + g_error ("Unable to get name"); + + return 1; + } + + g_dbus_connection_add_filter (pConnection, dbus_reg_filter, NULL, NULL); + g_dbus_connection_signal_subscribe (pConnection, NULL, NOTIFICATION_ITEM_DBUS_IFACE, "NewStatus", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, onNewStatus, NULL, NULL); + + watchdog_hit = TRUE; + g_timeout_add_seconds(20, kill_func, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + if (passed) { + g_debug("Quiting"); + return 0; + } else { + g_debug("Quiting as we're a failure"); + return 1; + } + return 0; } -- cgit v1.2.3 From 1ac50df408f9e0db2e65dca2a5a504c862ec3482 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 9 Aug 2023 14:48:56 +0200 Subject: debian/control: Drop libdbus-glib-1-dev and libdbus-1-dev --- debian/control | 2 -- 1 file changed, 2 deletions(-) diff --git a/debian/control b/debian/control index cd59fad..8f9cd58 100644 --- a/debian/control +++ b/debian/control @@ -27,8 +27,6 @@ Build-Depends: debhelper (>= 9), libgtk3.0-cil-dev [amd64 arm64 armel armhf i386 mipsel ppc64el s390x kfreebsd-amd64 kfreebsd-i386 powerpc ppc64], gtk-sharp2-gapi [amd64 arm64 armel armhf i386 mipsel ppc64el s390x kfreebsd-amd64 kfreebsd-i386 powerpc ppc64], libgtk2.0-cil-dev [amd64 arm64 armel armhf i386 mipsel ppc64el s390x kfreebsd-amd64 kfreebsd-i386 powerpc ppc64], - libdbus-1-dev, - libdbus-glib-1-dev (>= 0.82), libayatana-indicator-dev (>= 0.6.0-0~), libayatana-indicator3-dev (>= 0.6.0-0~), libdbusmenu-glib-dev (>= 0.5.90), -- cgit v1.2.3 From d6cdc24f310ce43f6f900cd929dfc57a4d7267bd Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 9 Aug 2023 14:52:38 +0200 Subject: .build.yml: Drop dbus-glib and dbus dependencies --- .build.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.build.yml b/.build.yml index d6a6b06..0158c64 100644 --- a/.build.yml +++ b/.build.yml @@ -16,7 +16,6 @@ requires: - gtk3 - glib2 - libdbusmenu-gtk3 - - dbus-glib - gobject-introspection - gtk3-docs @@ -48,8 +47,6 @@ requires: - libgtk3.0-cil-dev - gtk-sharp2-gapi - libgtk2.0-cil-dev - - libdbus-1-dev - - libdbus-glib-1-dev - libdbusmenu-glib-dev - libdbusmenu-gtk3-dev - libdbusmenu-gtk-dev @@ -84,8 +81,6 @@ requires: - libgtk3.0-cil-dev - gtk-sharp2-gapi - libgtk2.0-cil-dev - - libdbus-1-dev - - libdbus-glib-1-dev - libdbusmenu-glib-dev - libdbusmenu-gtk3-dev - libdbusmenu-gtk-dev -- cgit v1.2.3