summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/run-tests.c48
-rw-r--r--test/run-tests.h19
-rw-r--r--test/test-window.c58
3 files changed, 65 insertions, 60 deletions
diff --git a/test/run-tests.c b/test/run-tests.c
index 1f07ea4..dec135a 100644
--- a/test/run-tests.c
+++ b/test/run-tests.c
@@ -31,6 +31,54 @@ app_window_test_fixture_teardown (AppWindowTestFixture *fixture,
g_object_unref (fixture->app);
}
+
+static void
+add_widget_to_list_cb (GtkWidget *widget,
+ gpointer data)
+{
+ GList **list = (GList**) data;
+ *list = g_list_append (*list, widget);
+}
+
+GList *
+container_get_all_children (GtkContainer *container)
+{
+ GList *children = NULL;
+ gtk_container_forall (container,
+ add_widget_to_list_cb,
+ &children);
+ return children;
+}
+
+static GtkWidget *
+container_find_descendant_with_type_recurse (GtkWidget *widget,
+ GType type)
+{
+ if (G_TYPE_CHECK_INSTANCE_TYPE (widget, type))
+ return widget;
+ if (GTK_IS_CONTAINER (widget))
+ {
+ GList *children = container_get_all_children (GTK_CONTAINER (widget));
+ for (guint i = 0; i < g_list_length (children); i++)
+ {
+ GtkWidget *descendant = container_find_descendant_with_type_recurse (g_list_nth_data (children, i),
+ type);
+ if (descendant != NULL)
+ return descendant;
+ }
+ }
+ return NULL;
+}
+
+/* Query all the descendants of container, return the first found of the desired
+ type, or null*/
+GtkWidget *
+container_find_descendant_with_type (GtkContainer *container,
+ GType type)
+{
+ return container_find_descendant_with_type_recurse (GTK_WIDGET (container), type);
+}
+
int
main (int argc,
char **argv)
diff --git a/test/run-tests.h b/test/run-tests.h
index dfd7d89..32caa7e 100644
--- a/test/run-tests.h
+++ b/test/run-tests.h
@@ -17,12 +17,19 @@ typedef struct
EosApplication *app;
} AppWindowTestFixture;
-void app_window_test_fixture_setup (AppWindowTestFixture *fixture,
- gconstpointer callback);
-void app_window_test_fixture_test (AppWindowTestFixture *fixture,
- gconstpointer unused);
-void app_window_test_fixture_teardown (AppWindowTestFixture *fixture,
- gconstpointer unused);
+void app_window_test_fixture_setup (AppWindowTestFixture *fixture,
+ gconstpointer callback);
+
+void app_window_test_fixture_test (AppWindowTestFixture *fixture,
+ gconstpointer unused);
+
+void app_window_test_fixture_teardown (AppWindowTestFixture *fixture,
+ gconstpointer unused);
+
+GList *container_get_all_children (GtkContainer *container);
+
+GtkWidget *container_find_descendant_with_type (GtkContainer *container,
+ GType type);
void add_init_tests (void);
void add_hello_tests (void);
diff --git a/test/test-window.c b/test/test-window.c
index 1ca81ea..dfb7a4e 100644
--- a/test/test-window.c
+++ b/test/test-window.c
@@ -75,70 +75,23 @@ test_screen_size (GApplication *app)
gtk_widget_destroy (win);
}
-/* Query all the children of win, including the internal children, to find the
-top bar */
-static void
-find_top_bar (GtkWidget *widget,
- GtkWidget **top_bar_return_location)
-{
- if (EOS_IS_TOP_BAR (widget))
- *top_bar_return_location = widget;
-}
-
static void
test_has_top_bar (GApplication *app)
{
GtkWidget *win = eos_window_new (EOS_APPLICATION (app));
- GtkWidget *top_bar = NULL;
-
- gtk_container_forall (GTK_CONTAINER (win), (GtkCallback)find_top_bar,
- &top_bar);
+ GtkWidget *top_bar = container_find_descendant_with_type (GTK_CONTAINER (win), EOS_TYPE_TOP_BAR);
g_assert (top_bar != NULL);
g_assert (EOS_IS_TOP_BAR (top_bar));
gtk_widget_destroy (win);
}
-/* Query all the children of overlay, including the internal children, to find the
-main area */
-static void
-find_main_area (GtkWidget *widget,
- GtkWidget **main_area_return_location)
-{
- if (EOS_IS_MAIN_AREA (widget))
- *main_area_return_location = widget;
-}
-
-/* Query all the children of win, including the internal children, to find the
-gtk overlay */
-static void
-find_overlay (GtkWidget *widget,
- GtkWidget **overlay_return_location)
-{
- if (GTK_IS_OVERLAY (widget))
- *overlay_return_location = widget;
-}
-
-static GtkWidget *
-get_main_area (GtkWidget *window)
-{
- GtkWidget *overlay = NULL;
- GtkWidget *main_area = NULL;
-
- gtk_container_forall (GTK_CONTAINER (window), (GtkCallback)find_overlay,
- &overlay);
- g_assert (overlay != NULL);
- gtk_container_forall (GTK_CONTAINER (overlay), (GtkCallback)find_main_area,
- &main_area);
- g_assert (main_area != NULL);
- return main_area;
-}
-
static void
test_has_main_area (GApplication *app)
{
GtkWidget *win = eos_window_new (EOS_APPLICATION (app));
- GtkWidget *main_area = get_main_area (win);
+ GtkWidget *main_area = container_find_descendant_with_type (GTK_CONTAINER (win), EOS_TYPE_MAIN_AREA);
+ g_assert (main_area != NULL);
g_assert (EOS_IS_MAIN_AREA (main_area));
gtk_widget_destroy (win);
@@ -197,10 +150,7 @@ test_main_area_widgets_visibility (GApplication *app)
{
GtkWidget *win = eos_window_new (EOS_APPLICATION (app));
EosPageManager *pm = eos_window_get_page_manager (EOS_WINDOW (win));
- GtkWidget *main_area = get_main_area (win);
-
- gtk_container_forall (GTK_CONTAINER (win), (GtkCallback)find_main_area,
- &main_area);
+ GtkWidget *main_area = container_find_descendant_with_type (GTK_CONTAINER (win), EOS_TYPE_MAIN_AREA);
GtkWidget *page0 = gtk_label_new ("no-no");
GtkWidget *page1 = gtk_label_new ("yes-no");