From 4a1b7228d3fd9cfa163082c2bbf5b2982c6b525b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 15:41:16 -0600 Subject: Getting the start of the fallback tests in place. --- tests/Makefile.am | 35 +++++++++++++ tests/test-libappindicator-fallback-watcher.c | 73 +++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 tests/test-libappindicator-fallback-watcher.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 845b41c..e5847c5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,6 +3,8 @@ check_PROGRAMS = \ test-libappindicator \ test-libappindicator-dbus-client \ test-libappindicator-dbus-server \ + test-libappindicator-fallback-watcher \ + test-libappindicator-fallback-item \ test-simple-app TESTS = @@ -58,6 +60,39 @@ test_libappindicator_dbus_server_LDADD = \ $(INDICATOR_LIBS) \ $(top_builddir)/src/libappindicator.la +######################################### +## test-libappindicator-fallback +######################################### + +test_libappindicator_fallback_watcher_SOURCES = \ + test-libappindicator-fallback-watcher.c + +test_libappindicator_fallback_watcher_CFLAGS = \ + $(INDICATOR_CFLAGS) \ + -Wall -Werror \ + -I$(top_srcdir)/src + +test_libappindicator_fallback_watcher_LDADD = \ + $(INDICATOR_LIBS) \ + $(top_builddir)/src/libappindicator.la + +test_libappindicator_fallback_item_SOURCES = \ + test-libappindicator-fallback-watcher.c + +test_libappindicator_fallback_item_CFLAGS = \ + $(INDICATOR_CFLAGS) \ + -Wall -Werror \ + -I$(top_srcdir)/src + +test_libappindicator_fallback_item_LDADD = \ + $(INDICATOR_LIBS) \ + $(top_builddir)/src/libappindicator.la + +test-libappindicator-fallback: test-libappindicator-fallback-watcher test-libappindicator-fallback-item Makefile.am + @echo "#!/bin/sh" > $@ + @echo $(DBUS_RUNNER) --task ./test-libappindicator-fallback-watcher --task-name Watcher --ignore-return --task ./test-libappindicator-fallback-item --task-name Item >> $@ + @chmod +x $@ + ######################################### ## Actual tests ######################################### diff --git a/tests/test-libappindicator-fallback-watcher.c b/tests/test-libappindicator-fallback-watcher.c new file mode 100644 index 0000000..67109e5 --- /dev/null +++ b/tests/test-libappindicator-fallback-watcher.c @@ -0,0 +1,73 @@ +/* +This puts the NotificationWatcher on the bus, kinda. Enough to +trick the Item into unfalling back. + +Copyright 2010 Canonical Ltd. + +Authors: + Ted Gould + +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 +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include +#include +#include + +#include "../src/dbus-shared.h" + +static GMainLoop * mainloop = NULL; + +gboolean +kill_func (gpointer userdata) +{ + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argv, char ** argc) +{ + g_type_init(); + + /* Wait 1/4 a second, which should trigger the fallback */ + g_usleep(250000); + + 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; + } + + /* After we've got the name, let it unfallback, and then we'll drop again */ + g_timeout_add(250, kill_func, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return 0; +} -- cgit v1.2.3 From 348bcfba144c1e2f3025352f23f038829558bc7f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:04:58 -0600 Subject: Woah, this is pretty sweet. I hope it works. --- tests/test-libappindicator-fallback-watcher.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/test-libappindicator-fallback-watcher.c b/tests/test-libappindicator-fallback-watcher.c index 67109e5..07d8da6 100644 --- a/tests/test-libappindicator-fallback-watcher.c +++ b/tests/test-libappindicator-fallback-watcher.c @@ -23,11 +23,25 @@ with this program. If not, see . #include #include #include +#include #include "../src/dbus-shared.h" static GMainLoop * mainloop = NULL; +static DBusHandlerResult +dbus_filter (DBusConnection * connection, DBusMessage * message, void * user_data) +{ + 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; +} + gboolean kill_func (gpointer userdata) { @@ -63,6 +77,8 @@ main (int argv, char ** argc) return 1; } + dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL); + /* After we've got the name, let it unfallback, and then we'll drop again */ g_timeout_add(250, kill_func, NULL); -- cgit v1.2.3 From cc31c237cd5da314e584570220bd0bf359b725be Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:31:59 -0600 Subject: Adding in the item side of things. --- tests/Makefile.am | 2 +- tests/test-libappindicator-fallback-item.c | 84 ++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 tests/test-libappindicator-fallback-item.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index e5847c5..f543e92 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -77,7 +77,7 @@ test_libappindicator_fallback_watcher_LDADD = \ $(top_builddir)/src/libappindicator.la test_libappindicator_fallback_item_SOURCES = \ - test-libappindicator-fallback-watcher.c + test-libappindicator-fallback-item.c test_libappindicator_fallback_item_CFLAGS = \ $(INDICATOR_CFLAGS) \ diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c new file mode 100644 index 0000000..02724fe --- /dev/null +++ b/tests/test-libappindicator-fallback-item.c @@ -0,0 +1,84 @@ +#include +#include +#include + +#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)) +#define TEST_LIBAPPINDICATOR_FALLBACK_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, TestLibappindicatorFallbackItemClass)) +#define IS_TEST_LIBAPPINDICATOR_FALLBACK_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE)) +#define IS_TEST_LIBAPPINDICATOR_FALLBACK_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE)) +#define TEST_LIBAPPINDICATOR_FALLBACK_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, TestLibappindicatorFallbackItemClass)) + +typedef struct _TestLibappindicatorFallbackItem TestLibappindicatorFallbackItem; +typedef struct _TestLibappindicatorFallbackItemClass TestLibappindicatorFallbackItemClass; + +struct _TestLibappindicatorFallbackItemClass { + AppIndicatorClass parent_class; + +}; + +struct _TestLibappindicatorFallbackItem { + AppIndicator parent; + +}; + +GType test_libappindicator_fallback_item_get_type (void); + +#define TEST_LIBAPPINDICATOR_FALLBACK_ITEM_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, TestLibappindicatorFallbackItemPrivate)) + +static void test_libappindicator_fallback_item_class_init (TestLibappindicatorFallbackItemClass *klass); +static void test_libappindicator_fallback_item_init (TestLibappindicatorFallbackItem *self); +static GtkStatusIcon * fallback (AppIndicator * indicator); +static void unfallback (AppIndicator * indicator, GtkStatusIcon * status_icon); + +G_DEFINE_TYPE (TestLibappindicatorFallbackItem, test_libappindicator_fallback_item, APP_INDICATOR_TYPE); + +static void +test_libappindicator_fallback_item_class_init (TestLibappindicatorFallbackItemClass *klass) +{ + AppIndicatorClass * aiclass = APP_INDICATOR_CLASS(klass); + + aiclass->fallback = fallback; + aiclass->unfallback = unfallback; +} + +static void +test_libappindicator_fallback_item_init (TestLibappindicatorFallbackItem *self) +{ +} + +GMainLoop * mainloop = NULL; + +static GtkStatusIcon * +fallback (AppIndicator * indicator) +{ + g_debug("Fallback"); + return NULL; +} + +static void +unfallback (AppIndicator * indicator, GtkStatusIcon * status_icon) +{ + g_debug("Unfallback"); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + TestLibappindicatorFallbackItem * item = g_object_new(TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE, + "id", "test-id", + "category", "other", + "icon-name", "bob", + NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_object_unref(G_OBJECT(item)); + + return 0; +} -- cgit v1.2.3 From d0abe1ebd34409a7074a39c6af017b2cfb49abf4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:36:26 -0600 Subject: Printing status in watcher --- tests/test-libappindicator-fallback-watcher.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/test-libappindicator-fallback-watcher.c b/tests/test-libappindicator-fallback-watcher.c index 07d8da6..90c7db8 100644 --- a/tests/test-libappindicator-fallback-watcher.c +++ b/tests/test-libappindicator-fallback-watcher.c @@ -54,9 +54,13 @@ main (int argv, char ** argc) { g_type_init(); + g_debug("Waiting to init."); + /* Wait 1/4 a second, which should trigger the fallback */ g_usleep(250000); + g_debug("Initing"); + GError * error = NULL; DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (error != NULL) { @@ -82,8 +86,12 @@ main (int argv, char ** argc) /* After we've got the name, let it unfallback, and then we'll drop again */ g_timeout_add(250, kill_func, NULL); + g_debug("Entering Mainloop"); + mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); + g_debug("Exiting"); + return 0; } -- cgit v1.2.3 From a216db21dd72d491edaca5c7746d3a2a23b17dd1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:39:27 -0600 Subject: Adding a kill function and letting the test fail over it. --- tests/test-libappindicator-fallback-item.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c index 02724fe..83dc876 100644 --- a/tests/test-libappindicator-fallback-item.c +++ b/tests/test-libappindicator-fallback-item.c @@ -49,6 +49,7 @@ test_libappindicator_fallback_item_init (TestLibappindicatorFallbackItem *self) } GMainLoop * mainloop = NULL; +gboolean passed = FALSE; static GtkStatusIcon * fallback (AppIndicator * indicator) @@ -64,6 +65,14 @@ unfallback (AppIndicator * indicator, GtkStatusIcon * status_icon) return; } +gboolean +kill_func (gpointer data) +{ + g_debug("Kill Function"); + g_main_loop_quit(mainloop); + return FALSE; +} + int main (int argc, char ** argv) { @@ -75,10 +84,16 @@ main (int argc, char ** argv) "icon-name", "bob", NULL); + g_timeout_add_seconds(1, kill_func, NULL); + mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); g_object_unref(G_OBJECT(item)); - return 0; + if (passed) { + return 0; + } else { + return 1; + } } -- cgit v1.2.3 From 9a2102419fa43910995539a90981727838cc6c40 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:44:13 -0600 Subject: Adding state transitions that'll get us to a passed state. --- tests/test-libappindicator-fallback-item.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c index 83dc876..ce3182c 100644 --- a/tests/test-libappindicator-fallback-item.c +++ b/tests/test-libappindicator-fallback-item.c @@ -51,10 +51,29 @@ test_libappindicator_fallback_item_init (TestLibappindicatorFallbackItem *self) GMainLoop * mainloop = NULL; gboolean passed = FALSE; +enum { + STATE_INIT, + STATE_FALLBACK, + STATE_UNFALLBACK, + STATE_REFALLBACK +}; + +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; + passed = TRUE; + g_main_loop_quit(mainloop); + } else { + g_debug("Error, fallback in state: %d", state); + passed = FALSE; + } return NULL; } @@ -62,6 +81,12 @@ static void unfallback (AppIndicator * indicator, GtkStatusIcon * status_icon) { g_debug("Unfallback"); + if (state == STATE_FALLBACK) { + state = STATE_UNFALLBACK; + } else { + g_debug("Error, unfallback in state: %d", state); + passed = FALSE; + } return; } -- cgit v1.2.3 From 7783a495fb275ce70757ea1d0fcec67e7855f2d9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 16:45:09 -0600 Subject: Adding the fallback test to the suite --- tests/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index f543e92..c94ebdd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -93,6 +93,8 @@ test-libappindicator-fallback: test-libappindicator-fallback-watcher test-libapp @echo $(DBUS_RUNNER) --task ./test-libappindicator-fallback-watcher --task-name Watcher --ignore-return --task ./test-libappindicator-fallback-item --task-name Item >> $@ @chmod +x $@ +TESTS += test-libappindicator-fallback + ######################################### ## Actual tests ######################################### -- cgit v1.2.3 From f55bf250c331a4384f00ada67df4ff525b8c4ffe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Jan 2010 17:00:56 -0600 Subject: Adding a menu so that the app indicator will init --- tests/test-libappindicator-fallback-item.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c index ce3182c..38fdeea 100644 --- a/tests/test-libappindicator-fallback-item.c +++ b/tests/test-libappindicator-fallback-item.c @@ -101,13 +101,16 @@ kill_func (gpointer data) int main (int argc, char ** argv) { - g_type_init(); + gtk_init(&argc, &argv); 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(1, kill_func, NULL); -- cgit v1.2.3 From 5898ca0cf3754ee733ba670feedf5046e921c6e7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 08:33:21 -0600 Subject: Making sure to return a value so that unfallback gets called. --- tests/test-libappindicator-fallback-item.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c index 38fdeea..1ff70c8 100644 --- a/tests/test-libappindicator-fallback-item.c +++ b/tests/test-libappindicator-fallback-item.c @@ -74,7 +74,7 @@ fallback (AppIndicator * indicator) g_debug("Error, fallback in state: %d", state); passed = FALSE; } - return NULL; + return (GtkStatusIcon *)5; } static void -- cgit v1.2.3 From 5d075987c3469ae7f1538143546e94d208abf1cf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 Jan 2010 11:35:42 -0600 Subject: Really we should have gotten the final cleanup unfallback, which we weren't testing for either. --- tests/test-libappindicator-fallback-item.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c index 1ff70c8..291bc7c 100644 --- a/tests/test-libappindicator-fallback-item.c +++ b/tests/test-libappindicator-fallback-item.c @@ -55,7 +55,8 @@ enum { STATE_INIT, STATE_FALLBACK, STATE_UNFALLBACK, - STATE_REFALLBACK + STATE_REFALLBACK, + STATE_REUNFALLBACK }; gint state = STATE_INIT; @@ -68,8 +69,6 @@ fallback (AppIndicator * indicator) state = STATE_FALLBACK; } else if (state == STATE_UNFALLBACK) { state = STATE_REFALLBACK; - passed = TRUE; - g_main_loop_quit(mainloop); } else { g_debug("Error, fallback in state: %d", state); passed = FALSE; @@ -83,6 +82,10 @@ 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; -- cgit v1.2.3