aboutsummaryrefslogtreecommitdiff
path: root/tests/test-libappindicator-fallback-item.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-01-13 12:30:30 -0600
committerTed Gould <ted@gould.cx>2010-01-13 12:30:30 -0600
commit21c5cc4a70c060c12c3fa7082874724c6ac96706 (patch)
tree8eb50c8cc6f2ca9f3c2bdd8b75c6961b3b5e8858 /tests/test-libappindicator-fallback-item.c
parent5ca2ed3d2bb3672888620f17d91f215797d47dd8 (diff)
parentb1b9134542bd3bcfa6b5492f0a7f1b83cf0ec32f (diff)
downloadlibayatana-appindicator-21c5cc4a70c060c12c3fa7082874724c6ac96706.tar.gz
libayatana-appindicator-21c5cc4a70c060c12c3fa7082874724c6ac96706.tar.bz2
libayatana-appindicator-21c5cc4a70c060c12c3fa7082874724c6ac96706.zip
* Upstream update
* Fallback support
Diffstat (limited to 'tests/test-libappindicator-fallback-item.c')
-rw-r--r--tests/test-libappindicator-fallback-item.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c
new file mode 100644
index 0000000..291bc7c
--- /dev/null
+++ b/tests/test-libappindicator-fallback-item.c
@@ -0,0 +1,130 @@
+#include <glib.h>
+#include <glib-object.h>
+#include <libappindicator/app-indicator.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))
+#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;
+gboolean passed = FALSE;
+
+enum {
+ STATE_INIT,
+ STATE_FALLBACK,
+ STATE_UNFALLBACK,
+ STATE_REFALLBACK,
+ STATE_REUNFALLBACK
+};
+
+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;
+}
+
+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;
+}
+
+gboolean
+kill_func (gpointer data)
+{
+ g_debug("Kill Function");
+ g_main_loop_quit(mainloop);
+ return FALSE;
+}
+
+int
+main (int argc, char ** argv)
+{
+ 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);
+
+ 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;
+ }
+}