aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2023-08-09 14:45:34 +0200
committerRobert Tari <robert@tari.in>2023-08-09 14:45:34 +0200
commitf3cf5352621a0fbf2c1e7f5c3f603fbac1a3b3f7 (patch)
treefa92dced677dfad2c170a5361bb7e225cee3bd80 /tests
parent25001b09fdf8d10b2c209bfedd882bd90bd5b08a (diff)
downloadlibayatana-appindicator-f3cf5352621a0fbf2c1e7f5c3f603fbac1a3b3f7.tar.gz
libayatana-appindicator-f3cf5352621a0fbf2c1e7f5c3f603fbac1a3b3f7.tar.bz2
libayatana-appindicator-f3cf5352621a0fbf2c1e7f5c3f603fbac1a3b3f7.zip
Replace DBus-GLib with GDBus and drop libdus
fixes https://github.com/AyatanaIndicators/libayatana-appindicator/issues/11
Diffstat (limited to 'tests')
-rw-r--r--tests/test-libappindicator-dbus-client.c501
-rw-r--r--tests/test-libappindicator-fallback-item.c172
-rw-r--r--tests/test-libappindicator-fallback-watcher.c135
-rw-r--r--tests/test-libappindicator-status-client.c213
4 files changed, 554 insertions, 467 deletions
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 <ted@canonical.com>
+ Robert Tari <robert@tari.in>
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 <http://www.gnu.org/licenses/>.
#include <glib.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-bindings.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <app-indicator.h>
#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 <glib.h>
#include <glib-object.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-bindings.h>
#include <app-indicator.h>
+#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 <ted@canonical.com>
+ Robert Tari <robert@tari.in>
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 <http://www.gnu.org/licenses/>.
*/
#include <glib.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-bindings.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
+#include <gio/gio.h>
#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 <ted@canonical.com>
+ Robert Tari <robert@tari.in>
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 <http://www.gnu.org/licenses/>.
*/
-
#include <glib.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-bindings.h>
-#include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
#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;
}