aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am21
-rw-r--r--tests/dummy-indicator-signaler.c2
-rw-r--r--tests/dummy-indicator-visible.c139
-rw-r--r--tests/test-loader.c90
4 files changed, 252 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c8a9ba7..9319087 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,6 +15,7 @@ lib_LTLIBRARIES = \
libdummy-indicator-null.la \
libdummy-indicator-signaler.la \
libdummy-indicator-simple.la \
+ libdummy-indicator-visible.la \
libdummy-indicator-entry-func.la
DBUS_RUNNER=dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf
@@ -184,6 +185,26 @@ libdummy_indicator_entry_func_la_LDFLAGS = \
-avoid-version
#############################
+# Dummy Indicator Visible
+#############################
+
+libdummy_indicator_visible_la_SOURCES = \
+ dummy-indicator-visible.c
+
+libdummy_indicator_visible_la_CFLAGS = \
+ -Wall -Werror \
+ $(LIBINDICATOR_CFLAGS) -I$(top_srcdir)
+
+libdummy_indicator_visible_la_LIBADD = \
+ $(LIBINDICATOR_LIBS) \
+ -L$(top_builddir)/libindicator/.libs \
+ $(INDICATOR_LIB)
+
+libdummy_indicator_visible_la_LDFLAGS = \
+ -module \
+ -avoid-version
+
+#############################
# Service Shutdown Timeout
#############################
diff --git a/tests/dummy-indicator-signaler.c b/tests/dummy-indicator-signaler.c
index 00eee3b..c7a5c1f 100644
--- a/tests/dummy-indicator-signaler.c
+++ b/tests/dummy-indicator-signaler.c
@@ -99,6 +99,8 @@ dummy_indicator_signaler_class_init (DummyIndicatorSignalerClass *klass)
io_class->get_image = get_icon;
io_class->get_menu = get_menu;
io_class->get_accessible_desc = get_accessible_desc;
+ io_class->entry_being_removed = NULL;
+ io_class->entry_was_added = NULL;
return;
}
diff --git a/tests/dummy-indicator-visible.c b/tests/dummy-indicator-visible.c
new file mode 100644
index 0000000..0bb9e89
--- /dev/null
+++ b/tests/dummy-indicator-visible.c
@@ -0,0 +1,139 @@
+/*
+Test for libindicator
+
+Copyright 2012 Canonical Ltd.
+
+Authors:
+ Charles Kerr <charles.kerr@canonical.com>
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+version 3.0 as published by the Free Software Foundation.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License version 3.0 for more details.
+
+You should have received a copy of the GNU General Public
+License along with this library. If not, see
+<http://www.gnu.org/licenses/>.
+*/
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "libindicator/indicator.h"
+#include "libindicator/indicator-object.h"
+
+#define DUMMY_INDICATOR_VISIBLE_TYPE (dummy_indicator_visible_get_type ())
+#define DUMMY_INDICATOR_VISIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DUMMY_INDICATOR_VISIBLE_TYPE, DummyIndicatorVisible))
+#define DUMMY_INDICATOR_VISIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DUMMY_INDICATOR_VISIBLE_TYPE, DummyIndicatorVisibleClass))
+#define IS_DUMMY_INDICATOR_VISIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DUMMY_INDICATOR_VISIBLE_TYPE))
+#define IS_DUMMY_INDICATOR_VISIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DUMMY_INDICATOR_VISIBLE_TYPE))
+#define DUMMY_INDICATOR_VISIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DUMMY_INDICATOR_VISIBLE_TYPE, DummyIndicatorVisibleClass))
+
+typedef struct _DummyIndicatorVisible DummyIndicatorVisible;
+typedef struct _DummyIndicatorVisibleClass DummyIndicatorVisibleClass;
+
+struct _DummyIndicatorVisibleClass {
+ IndicatorObjectClass parent_class;
+};
+
+struct _DummyIndicatorVisible {
+ IndicatorObject parent;
+};
+
+GType dummy_indicator_visible_get_type (void);
+
+INDICATOR_SET_VERSION
+INDICATOR_SET_TYPE(DUMMY_INDICATOR_VISIBLE_TYPE)
+
+GtkLabel *
+get_label (IndicatorObject * io)
+{
+ return GTK_LABEL(gtk_label_new("Visible Item"));
+}
+
+GtkImage *
+get_icon (IndicatorObject * io)
+{
+ return GTK_IMAGE(gtk_image_new());
+}
+
+GtkMenu *
+get_menu (IndicatorObject * io)
+{
+ GtkMenu * main_menu = GTK_MENU(gtk_menu_new());
+ GtkWidget * loading_item = gtk_menu_item_new_with_label("Loading...");
+ gtk_menu_shell_append(GTK_MENU_SHELL(main_menu), loading_item);
+ gtk_widget_show(GTK_WIDGET(loading_item));
+
+ return main_menu;
+}
+
+const gchar *
+get_accessible_desc (IndicatorObject * io)
+{
+ return "Visible Item";
+}
+
+static void dummy_indicator_visible_class_init (DummyIndicatorVisibleClass *klass);
+static void dummy_indicator_visible_init (DummyIndicatorVisible *self);
+static void dummy_indicator_visible_dispose (GObject *object);
+static void dummy_indicator_visible_finalize (GObject *object);
+
+G_DEFINE_TYPE (DummyIndicatorVisible, dummy_indicator_visible, INDICATOR_OBJECT_TYPE);
+
+static void
+dummy_indicator_entry_being_removed (IndicatorObject * io, IndicatorObjectEntry * entry)
+{
+ g_object_set_data(G_OBJECT(entry->label), "is-hidden", GINT_TO_POINTER(1));
+
+ INDICATOR_OBJECT_CLASS(dummy_indicator_visible_parent_class)->entry_being_removed (io, entry);
+}
+
+static void
+dummy_indicator_entry_was_added (IndicatorObject * io, IndicatorObjectEntry * entry)
+{
+ g_object_steal_data(G_OBJECT(entry->label), "is-hidden");
+
+ INDICATOR_OBJECT_CLASS(dummy_indicator_visible_parent_class)->entry_was_added (io, entry);
+}
+
+static void
+dummy_indicator_visible_class_init (DummyIndicatorVisibleClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = dummy_indicator_visible_dispose;
+ object_class->finalize = dummy_indicator_visible_finalize;
+
+ IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass);
+
+ io_class->get_label = get_label;
+ io_class->get_image = get_icon;
+ io_class->get_menu = get_menu;
+ io_class->get_accessible_desc = get_accessible_desc;
+ io_class->entry_being_removed = dummy_indicator_entry_being_removed;
+ io_class->entry_was_added = dummy_indicator_entry_was_added;
+}
+
+static void
+dummy_indicator_visible_init (DummyIndicatorVisible *self)
+{
+}
+
+static void
+dummy_indicator_visible_dispose (GObject *object)
+{
+
+ G_OBJECT_CLASS (dummy_indicator_visible_parent_class)->dispose (object);
+}
+
+static void
+dummy_indicator_visible_finalize (GObject *object)
+{
+
+ G_OBJECT_CLASS (dummy_indicator_visible_parent_class)->finalize (object);
+}
diff --git a/tests/test-loader.c b/tests/test-loader.c
index 2e9cf55..0ea3224 100644
--- a/tests/test-loader.c
+++ b/tests/test-loader.c
@@ -140,6 +140,95 @@ test_loader_filename_dummy_signaler (void)
return;
}
+/***
+****
+***/
+
+static void
+visible_entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer box)
+{
+ // make a frame for the entry, and add the frame to the box
+ GtkWidget * frame = gtk_frame_new (NULL);
+ GtkWidget * child = GTK_WIDGET(entry->label);
+ g_assert (child != NULL);
+ gtk_container_add (GTK_CONTAINER(frame), child);
+ gtk_box_pack_start (GTK_BOX(box), frame, FALSE, FALSE, 0);
+ g_object_set_data (G_OBJECT(child), "frame-parent", frame);
+}
+
+static void
+visible_entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer box)
+{
+ // destroy this entry's frame
+ gpointer parent = g_object_steal_data (G_OBJECT(entry->label), "frame-parent");
+ if (GTK_IS_WIDGET(parent))
+ gtk_widget_destroy(GTK_WIDGET(parent));
+}
+
+void
+test_loader_filename_dummy_visible (void)
+{
+ const GQuark is_hidden_quark = g_quark_from_static_string ("is-hidden");
+ IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-visible.so");
+ g_assert(object != NULL);
+
+ // create our local parent widgetry
+#if GTK_CHECK_VERSION(3,0,0)
+ GtkWidget * box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+#else
+ GtkWidget * box = gtk_hbox_new (TRUE, 0);
+#endif
+ g_signal_connect(object, INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED,
+ G_CALLBACK(visible_entry_added), box);
+ g_signal_connect(object, INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED,
+ G_CALLBACK(visible_entry_removed), box);
+
+ // on startup, DummyVisible has one entry and it has a label
+ GList * list = indicator_object_get_entries(object);
+ g_assert(g_list_length(list) == 1);
+ IndicatorObjectEntry * entry = list->data;
+ g_assert(entry != NULL);
+ g_list_free(list);
+ g_assert(GTK_IS_LABEL(entry->label));
+ GtkWidget * label = GTK_WIDGET(entry->label);
+ g_assert(g_object_get_qdata(G_OBJECT(label), is_hidden_quark) == NULL);
+
+ // add the inital entry to our local parent widgetry
+ visible_entry_added (object, entry, box);
+ entry = NULL;
+ list = gtk_container_get_children (GTK_CONTAINER(box));
+ g_assert(g_list_length(list) == 1);
+ g_list_free(list);
+
+ // hide the entries and confirm that the label survived
+ indicator_object_set_visible (object, FALSE);
+ while (g_main_context_pending(NULL))
+ g_main_context_iteration(NULL, TRUE);
+ g_assert(GTK_IS_LABEL(label));
+ g_assert(g_object_get_qdata(G_OBJECT(label), is_hidden_quark) != NULL);
+ list = gtk_container_get_children (GTK_CONTAINER(box));
+ g_assert(g_list_length(list) == 0);
+ g_list_free(list);
+
+ // restore the entries and confirm that the label survived
+ indicator_object_set_visible (object, TRUE);
+ while (g_main_context_pending(NULL))
+ g_main_context_iteration(NULL, TRUE);
+ g_assert(GTK_IS_LABEL(label));
+ g_assert(g_object_get_qdata(G_OBJECT(label), is_hidden_quark) == NULL);
+ list = gtk_container_get_children (GTK_CONTAINER(box));
+ g_assert(g_list_length(list) == 1);
+ g_list_free(list);
+
+ // cleanup
+ g_object_unref(object);
+ gtk_widget_destroy(box);
+}
+
+/***
+****
+***/
+
void
test_loader_filename_dummy_simple_location (void)
{
@@ -248,6 +337,7 @@ test_loader_creation_deletion_suite (void)
g_test_add_func ("/libindicator/loader/dummy/signaler", test_loader_filename_dummy_signaler);
g_test_add_func ("/libindicator/loader/dummy/entry_funcs", test_loader_entry_funcs);
g_test_add_func ("/libindicator/loader/dummy/entry_func_window", test_loader_entry_func_window);
+ g_test_add_func ("/libindicator/loader/dummy/visible", test_loader_filename_dummy_visible);
return;
}