From 8072a97d30c0e3aaa9f02b89f53ae9af247e473b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 9 Jul 2010 16:47:45 -0500 Subject: Adding a new sample approver --- tests/Makefile.am | 16 +++++++++++ tests/test-approver.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 tests/test-approver.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 8d356bc..a920a20 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,6 @@ check_PROGRAMS = \ + test-approver \ test-libappindicator \ test-libappindicator-dbus-client \ test-libappindicator-dbus-server \ @@ -98,6 +99,21 @@ test_libappindicator_status_server_LDADD = \ $(INDICATOR_LIBS) \ $(top_builddir)/src/libappindicator.la +######################################### +## test-approver +######################################### + +test_approver_SOURCES = \ + test-approver.c + +test_approver_CFLAGS = \ + $(INDICATOR_CFLAGS) \ + -Wall -Werror \ + -I$(top_srcdir)/src + +test_approver_LDADD = \ + $(INDICATOR_LIBS) + ######################################### ## test-libappindicator-fallback ######################################### diff --git a/tests/test-approver.c b/tests/test-approver.c new file mode 100644 index 0000000..f411b0d --- /dev/null +++ b/tests/test-approver.c @@ -0,0 +1,74 @@ +#include +#include + +#define APPROVER_PATH "/my/approver" + +#define TEST_APPROVER_TYPE (test_approver_get_type ()) +#define TEST_APPROVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_APPROVER_TYPE, TestApprover)) +#define TEST_APPROVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_APPROVER_TYPE, TestApproverClass)) +#define IS_TEST_APPROVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_APPROVER_TYPE)) +#define IS_TEST_APPROVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_APPROVER_TYPE)) +#define TEST_APPROVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_APPROVER_TYPE, TestApproverClass)) + +typedef struct _TestApprover TestApprover; +typedef struct _TestApproverClass TestApproverClass; + +struct _TestApproverClass { + GObjectClass parent_class; +}; + +struct _TestApprover { + GObject parent; +}; + +GType test_approver_get_type (void); + +static void test_approver_class_init (TestApproverClass *klass); +static void test_approver_init (TestApprover *self); +static void _notification_approver_server_approve_item (void); + +#include "../src/notification-approver-server.h" + +G_DEFINE_TYPE (TestApprover, test_approver, G_TYPE_OBJECT); + +static void +test_approver_class_init (TestApproverClass *klass) +{ + dbus_g_object_type_install_info(TEST_APPROVER_TYPE, + &dbus_glib__notification_approver_server_object_info); + + return; +} + +static void +test_approver_init (TestApprover *self) +{ + DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + + dbus_g_connection_register_g_object(session_bus, + APPROVER_PATH, + G_OBJECT(self)); + + return; +} + +static void +_notification_approver_server_approve_item (void) +{ + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + TestApprover * approver = g_object_new(TEST_APPROVER_TYPE, NULL); + + GMainLoop * main_loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(main_loop); + + g_object_unref(approver); + + return 0; +} -- cgit v1.2.3 From fd3e18e471823583a29e673a639b9b14295b4a4c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 9 Jul 2010 20:44:07 -0500 Subject: Okay, so now we're detecing when the watcher comes up, and registering ourselves as the approver. --- tests/test-approver.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test-approver.c b/tests/test-approver.c index f411b0d..c51e1cb 100644 --- a/tests/test-approver.c +++ b/tests/test-approver.c @@ -1,6 +1,11 @@ #include #include +#include + +#include "notification-watcher-client.h" +#include "dbus-shared.h" + #define APPROVER_PATH "/my/approver" #define TEST_APPROVER_TYPE (test_approver_get_type ()) @@ -29,6 +34,10 @@ static void _notification_approver_server_approve_item (void); #include "../src/notification-approver-server.h" +GMainLoop * main_loop = NULL; +DBusGConnection * session_bus = NULL; +DBusGProxy * bus_proxy = NULL; + G_DEFINE_TYPE (TestApprover, test_approver, G_TYPE_OBJECT); static void @@ -43,8 +52,6 @@ test_approver_class_init (TestApproverClass *klass) static void test_approver_init (TestApprover *self) { - DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - dbus_g_connection_register_g_object(session_bus, APPROVER_PATH, G_OBJECT(self)); @@ -58,14 +65,48 @@ _notification_approver_server_approve_item (void) return; } +gint owner_count = 0; +gboolean +check_for_service (gpointer user_data) +{ + if (owner_count > 100) { + g_main_loop_quit(main_loop); + return FALSE; + } + + owner_count++; + + gboolean has_owner = FALSE; + org_freedesktop_DBus_name_has_owner(bus_proxy, "org.test", &has_owner, NULL); + + if (has_owner) { + const char * cats = NULL; + DBusGProxy * proxy = dbus_g_proxy_new_for_name(session_bus, + NOTIFICATION_WATCHER_DBUS_ADDR, + NOTIFICATION_WATCHER_DBUS_OBJ, + NOTIFICATION_WATCHER_DBUS_IFACE); + + org_kde_StatusNotifierWatcher_register_notification_approver (proxy, APPROVER_PATH, &cats, NULL); + return FALSE; + } + + return TRUE; +} + int main (int argc, char ** argv) { g_type_init(); + session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + TestApprover * approver = g_object_new(TEST_APPROVER_TYPE, NULL); - GMainLoop * main_loop = g_main_loop_new(NULL, FALSE); + bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + + g_timeout_add(100, check_for_service, NULL); + + main_loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(main_loop); g_object_unref(approver); -- cgit v1.2.3 From 018bf0e6f77b80643712712cf814b1fadbff288d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 9 Jul 2010 20:45:32 -0500 Subject: Helpful debug info --- tests/test-approver.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test-approver.c b/tests/test-approver.c index c51e1cb..127dc67 100644 --- a/tests/test-approver.c +++ b/tests/test-approver.c @@ -69,6 +69,8 @@ gint owner_count = 0; gboolean check_for_service (gpointer user_data) { + g_debug("Checking for Watcher"); + if (owner_count > 100) { g_main_loop_quit(main_loop); return FALSE; @@ -86,6 +88,7 @@ check_for_service (gpointer user_data) NOTIFICATION_WATCHER_DBUS_OBJ, NOTIFICATION_WATCHER_DBUS_IFACE); + g_debug("Registering Approver"); org_kde_StatusNotifierWatcher_register_notification_approver (proxy, APPROVER_PATH, &cats, NULL); return FALSE; } @@ -97,12 +100,13 @@ int main (int argc, char ** argv) { g_type_init(); + g_debug("Initing"); session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); TestApprover * approver = g_object_new(TEST_APPROVER_TYPE, NULL); - bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); g_timeout_add(100, check_for_service, NULL); -- cgit v1.2.3 From 5b41b1e87608bab6bacb62ea95dd1c0964ba8706 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 9 Jul 2010 20:49:26 -0500 Subject: Some more error handling and better debug messages. --- tests/test-approver.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test-approver.c b/tests/test-approver.c index 127dc67..df06df2 100644 --- a/tests/test-approver.c +++ b/tests/test-approver.c @@ -37,6 +37,7 @@ static void _notification_approver_server_approve_item (void); GMainLoop * main_loop = NULL; DBusGConnection * session_bus = NULL; DBusGProxy * bus_proxy = NULL; +gboolean passed = FALSE; G_DEFINE_TYPE (TestApprover, test_approver, G_TYPE_OBJECT); @@ -72,6 +73,7 @@ check_for_service (gpointer user_data) g_debug("Checking for Watcher"); if (owner_count > 100) { + g_warning("Couldn't find watcher after 100 tries."); g_main_loop_quit(main_loop); return FALSE; } @@ -79,7 +81,7 @@ check_for_service (gpointer user_data) owner_count++; gboolean has_owner = FALSE; - org_freedesktop_DBus_name_has_owner(bus_proxy, "org.test", &has_owner, NULL); + org_freedesktop_DBus_name_has_owner(bus_proxy, NOTIFICATION_WATCHER_DBUS_ADDR, &has_owner, NULL); if (has_owner) { const char * cats = NULL; @@ -89,7 +91,15 @@ check_for_service (gpointer user_data) NOTIFICATION_WATCHER_DBUS_IFACE); g_debug("Registering Approver"); - org_kde_StatusNotifierWatcher_register_notification_approver (proxy, APPROVER_PATH, &cats, NULL); + GError * error = NULL; + org_kde_StatusNotifierWatcher_register_notification_approver (proxy, APPROVER_PATH, &cats, &error); + + if (error != NULL) { + g_warning("Unable to register approver: %s", error->message); + g_error_free(error); + g_main_loop_quit(main_loop); + } + return FALSE; } @@ -99,10 +109,17 @@ check_for_service (gpointer user_data) int main (int argc, char ** argv) { + GError * error = NULL; + g_type_init(); g_debug("Initing"); - session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (error != NULL) { + g_warning("Unable to get session bus: %s", error->message); + g_error_free(error); + return -1; + } TestApprover * approver = g_object_new(TEST_APPROVER_TYPE, NULL); @@ -115,5 +132,9 @@ main (int argc, char ** argv) g_object_unref(approver); + if (!passed) { + return -1; + } + return 0; } -- cgit v1.2.3 From ed8163b9de3adf9883b2cf0c47c35bad2fe221ff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 9 Jul 2010 20:58:38 -0500 Subject: Making the registration async to clean things up, and async is better anyway. --- tests/test-approver.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/test-approver.c b/tests/test-approver.c index df06df2..fd90bf7 100644 --- a/tests/test-approver.c +++ b/tests/test-approver.c @@ -66,6 +66,21 @@ _notification_approver_server_approve_item (void) return; } +static void +register_cb (DBusGProxy * proxy, GError * error, gpointer user_data) +{ + if (error != NULL) { + g_warning("Unable to register approver: %s", error->message); + g_error_free(error); + g_main_loop_quit(main_loop); + return; + } + + g_debug("Building App Indicator"); + + return; +} + gint owner_count = 0; gboolean check_for_service (gpointer user_data) @@ -91,14 +106,7 @@ check_for_service (gpointer user_data) NOTIFICATION_WATCHER_DBUS_IFACE); g_debug("Registering Approver"); - GError * error = NULL; - org_kde_StatusNotifierWatcher_register_notification_approver (proxy, APPROVER_PATH, &cats, &error); - - if (error != NULL) { - g_warning("Unable to register approver: %s", error->message); - g_error_free(error); - g_main_loop_quit(main_loop); - } + org_kde_StatusNotifierWatcher_register_notification_approver_async (proxy, APPROVER_PATH, &cats, register_cb, NULL); return FALSE; } -- cgit v1.2.3 From d7c39d7b2654985016f533217e300b5dd5573020 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 9 Jul 2010 21:10:00 -0500 Subject: Building an application indicator too! --- tests/Makefile.am | 3 ++- tests/test-approver.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index a920a20..6ee3a02 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -112,7 +112,8 @@ test_approver_CFLAGS = \ -I$(top_srcdir)/src test_approver_LDADD = \ - $(INDICATOR_LIBS) + $(INDICATOR_LIBS) \ + $(top_builddir)/src/libappindicator.la ######################################### ## test-libappindicator-fallback diff --git a/tests/test-approver.c b/tests/test-approver.c index fd90bf7..609036c 100644 --- a/tests/test-approver.c +++ b/tests/test-approver.c @@ -5,9 +5,14 @@ #include "notification-watcher-client.h" #include "dbus-shared.h" +#include "app-indicator.h" #define APPROVER_PATH "/my/approver" +#define INDICATOR_ID "test-indicator-id" +#define INDICATOR_ICON "test-indicator-icon-name" +#define INDICATOR_CATEGORY APP_INDICATOR_CATEGORY_APPLICATION_STATUS + #define TEST_APPROVER_TYPE (test_approver_get_type ()) #define TEST_APPROVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_APPROVER_TYPE, TestApprover)) #define TEST_APPROVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_APPROVER_TYPE, TestApproverClass)) @@ -37,6 +42,7 @@ static void _notification_approver_server_approve_item (void); GMainLoop * main_loop = NULL; DBusGConnection * session_bus = NULL; DBusGProxy * bus_proxy = NULL; +AppIndicator * app_indicator = NULL; gboolean passed = FALSE; G_DEFINE_TYPE (TestApprover, test_approver, G_TYPE_OBJECT); @@ -77,6 +83,13 @@ register_cb (DBusGProxy * proxy, GError * error, gpointer user_data) } g_debug("Building App Indicator"); + app_indicator = app_indicator_new(INDICATOR_ID, INDICATOR_ICON, INDICATOR_CATEGORY); + + GtkWidget * menu = gtk_menu_new(); + GtkWidget * mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT, NULL); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi); + + app_indicator_set_menu(app_indicator, GTK_MENU(menu)); return; } -- cgit v1.2.3 From 0bf54f57b3212c020be3dd493829fa67516a7143 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 9 Jul 2010 21:14:25 -0500 Subject: Filling out the approver prototype --- tests/test-approver.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test-approver.c b/tests/test-approver.c index 609036c..44cd5b4 100644 --- a/tests/test-approver.c +++ b/tests/test-approver.c @@ -35,7 +35,7 @@ GType test_approver_get_type (void); static void test_approver_class_init (TestApproverClass *klass); static void test_approver_init (TestApprover *self); -static void _notification_approver_server_approve_item (void); +static gboolean _notification_approver_server_approve_item (TestApprover * ta, const gchar * id, const gchar * category, guint pid, const gchar * address, const gchar * path, gboolean * approved, GError ** error); #include "../src/notification-approver-server.h" @@ -66,10 +66,13 @@ test_approver_init (TestApprover *self) return; } -static void -_notification_approver_server_approve_item (void) +static gboolean +_notification_approver_server_approve_item (TestApprover * ta, const gchar * id, const gchar * category, guint pid, const gchar * address, const gchar * path, gboolean * approved, GError ** error) { - return; + *approved = TRUE; + + + return TRUE; } static void -- cgit v1.2.3 From 12c8596edf111ec4b087ce52f736e32f06638815 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 9 Jul 2010 21:15:49 -0500 Subject: Filling out the approve function. --- tests/test-approver.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/test-approver.c b/tests/test-approver.c index 44cd5b4..d52a13f 100644 --- a/tests/test-approver.c +++ b/tests/test-approver.c @@ -70,7 +70,13 @@ static gboolean _notification_approver_server_approve_item (TestApprover * ta, const gchar * id, const gchar * category, guint pid, const gchar * address, const gchar * path, gboolean * approved, GError ** error) { *approved = TRUE; + g_debug("Asked to approve indicator"); + if (g_strcmp0(id, INDICATOR_ID) == 0) { + passed = TRUE; + } + + g_main_loop_quit(main_loop); return TRUE; } -- cgit v1.2.3 From 3c43fed297b0804d6f2fd60dbcab68c3ed492047 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 9 Jul 2010 21:21:22 -0500 Subject: Building up to a formal test --- tests/Makefile.am | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 6ee3a02..35d557e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -115,6 +115,15 @@ test_approver_LDADD = \ $(INDICATOR_LIBS) \ $(top_builddir)/src/libappindicator.la +test-approver-tester: test-approver Makefile.am + @echo "#!/bin/bash" > $@ + @echo . $(srcdir)/run-xvfb.sh >> $@ + @echo $(DBUS_RUNNER) --task $(builddir)/test-approver --task-name Approver --task $(top_builddir)/src/indicator-application-service --task-name Service --ignore-return >> $@ + @chmod +x $@ + +TESTS += test-approver-tester + + ######################################### ## test-libappindicator-fallback ######################################### -- cgit v1.2.3 From 1b89529258a612d2df0e1114b708ad4ea61c59aa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 9 Jul 2010 21:23:59 -0500 Subject: Oops, with a menu we're all GTK now. --- tests/test-approver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test-approver.c b/tests/test-approver.c index d52a13f..30beb30 100644 --- a/tests/test-approver.c +++ b/tests/test-approver.c @@ -141,7 +141,7 @@ main (int argc, char ** argv) { GError * error = NULL; - g_type_init(); + gtk_init(&argc, &argv); g_debug("Initing"); session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); -- cgit v1.2.3 From 25b69bb08e3e5a3df7037f8ac786422ff53f6425 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 9 Jul 2010 21:35:45 -0500 Subject: Need the built headers too --- tests/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 35d557e..867d4de 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -109,7 +109,8 @@ test_approver_SOURCES = \ test_approver_CFLAGS = \ $(INDICATOR_CFLAGS) \ -Wall -Werror \ - -I$(top_srcdir)/src + -I$(top_srcdir)/src \ + -I$(top_builddir)/src test_approver_LDADD = \ $(INDICATOR_LIBS) \ -- cgit v1.2.3