summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/endless/Makefile.am.inc1
-rw-r--r--test/endless/run-tests.c1
-rw-r--r--test/endless/run-tests.h1
-rw-r--r--test/endless/test-custom-container.c83
-rw-r--r--test/smoke-tests/custom-container.js44
5 files changed, 130 insertions, 0 deletions
diff --git a/test/endless/Makefile.am.inc b/test/endless/Makefile.am.inc
index 2835934..8b78baf 100644
--- a/test/endless/Makefile.am.inc
+++ b/test/endless/Makefile.am.inc
@@ -12,6 +12,7 @@ test_endless_run_tests_SOURCES = \
$(ENDLESS_TESTS_DIRECTORY)/endless/test-action-menu.c \
$(ENDLESS_TESTS_DIRECTORY)/endless/test-action-button.c \
$(ENDLESS_TESTS_DIRECTORY)/endless/test-flexy-grid.c \
+ $(ENDLESS_TESTS_DIRECTORY)/endless/test-custom-container.c \
$(NULL)
test_endless_run_tests_CPPFLAGS = $(TEST_FLAGS)
test_endless_run_tests_LDADD = $(TEST_LIBS)
diff --git a/test/endless/run-tests.c b/test/endless/run-tests.c
index db9c289..4bc4006 100644
--- a/test/endless/run-tests.c
+++ b/test/endless/run-tests.c
@@ -111,6 +111,7 @@ main (int argc,
add_action_menu_tests ();
add_action_button_tests ();
add_flexy_grid_test ();
+ add_custom_container_tests ();
return g_test_run ();
}
diff --git a/test/endless/run-tests.h b/test/endless/run-tests.h
index 8947a5a..cb52ab7 100644
--- a/test/endless/run-tests.h
+++ b/test/endless/run-tests.h
@@ -41,5 +41,6 @@ void add_splash_page_manager_tests (void);
void add_action_menu_tests (void);
void add_action_button_tests (void);
void add_flexy_grid_test (void);
+void add_custom_container_tests (void);
#endif /* RUN_TESTS_H */
diff --git a/test/endless/test-custom-container.c b/test/endless/test-custom-container.c
new file mode 100644
index 0000000..42cf99f
--- /dev/null
+++ b/test/endless/test-custom-container.c
@@ -0,0 +1,83 @@
+/* Copyright 2014 Endless Mobile, Inc. */
+
+#include <gtk/gtk.h>
+#include <endless/endless.h>
+
+#include "run-tests.h"
+
+typedef struct
+{
+ GtkContainer *container;
+ GtkWidget *child1;
+ GtkWidget *child2;
+ GtkWidget *child3;
+} CustomContainerFixture;
+
+#define ADD_CUSTOM_CONTAINER_TEST(path, test_func) \
+ g_test_add ((path), CustomContainerFixture, NULL, \
+ custom_container_fixture_setup, \
+ (test_func), \
+ custom_container_fixture_teardown)
+
+
+static void
+custom_container_fixture_setup (CustomContainerFixture *fixture,
+ gconstpointer unused G_GNUC_UNUSED)
+{
+ // We acquire the widget ref so they don't automatically get destroyed after
+ // being removed from the container.
+ fixture->child1 = g_object_ref_sink (gtk_label_new ("1"));
+ fixture->child2 = g_object_ref_sink (gtk_label_new ("2"));
+ fixture->child3 = g_object_ref_sink (gtk_label_new ("3"));
+ fixture->container = GTK_CONTAINER (eos_custom_container_new ());
+}
+
+static void
+custom_container_fixture_teardown (CustomContainerFixture *fixture,
+ gconstpointer unused G_GNUC_UNUSED)
+{
+ gtk_widget_destroy (fixture->child1);
+ gtk_widget_destroy (fixture->child2);
+ gtk_widget_destroy (fixture->child3);
+ gtk_widget_destroy ((GtkWidget *) fixture->container);
+ g_object_unref (fixture->child1);
+ g_object_unref (fixture->child2);
+ g_object_unref (fixture->child3);
+}
+
+static void
+test_custom_container_add (CustomContainerFixture *fixture,
+ gconstpointer unused G_GNUC_UNUSED)
+{
+ gtk_container_add (fixture->container, fixture->child1);
+ gtk_container_add (fixture->container, fixture->child2);
+ gtk_container_add (fixture->container, fixture->child3);
+
+ g_assert (gtk_widget_get_parent (fixture->child1) == GTK_WIDGET (fixture->container));
+ GList *children = gtk_container_get_children (fixture->container);
+ g_assert (g_list_length (children) == 3);
+ g_assert (g_list_find (children, fixture->child1) != NULL);
+ g_assert (g_list_find (children, fixture->child2) != NULL);
+ g_assert (g_list_find (children, fixture->child3) != NULL);
+}
+
+static void
+test_custom_container_remove (CustomContainerFixture *fixture,
+ gconstpointer unused G_GNUC_UNUSED)
+{
+ gtk_container_add (fixture->container, fixture->child1);
+ gtk_container_add (fixture->container, fixture->child2);
+ gtk_container_add (fixture->container, fixture->child3);
+ gtk_container_remove (fixture->container, fixture->child2);
+
+ g_assert (gtk_widget_get_parent (fixture->child2) != GTK_WIDGET (fixture->container));
+ GList *children = gtk_container_get_children (fixture->container);
+ g_assert (g_list_find (children, fixture->child2) == NULL);
+}
+
+void
+add_custom_container_tests (void)
+{
+ ADD_CUSTOM_CONTAINER_TEST ("/custom-container/add", test_custom_container_add);
+ ADD_CUSTOM_CONTAINER_TEST ("/custom-container/remove", test_custom_container_remove);
+}
diff --git a/test/smoke-tests/custom-container.js b/test/smoke-tests/custom-container.js
new file mode 100644
index 0000000..679e0be
--- /dev/null
+++ b/test/smoke-tests/custom-container.js
@@ -0,0 +1,44 @@
+// Copyright 2014 Endless Mobile, Inc.
+
+const Lang = imports.lang;
+const Endless = imports.gi.Endless;
+const Gtk = imports.gi.Gtk;
+const GObject = imports.gi.GObject;
+
+const TEST_APPLICATION_ID = 'com.endlessm.example.test';
+
+const TestContainer = Lang.Class({
+ Name: 'TestContainer',
+ Extends: Endless.CustomContainer,
+
+ _init: function() {
+ this.parent();
+
+ this._frame = new Gtk.Frame();
+ this.add(this._frame);
+ },
+
+ vfunc_size_allocate: function (alloc) {
+ this.parent(alloc);
+ alloc.width = alloc.width / 2;
+ alloc.height = alloc.height / 2;
+ this._frame.size_allocate(alloc);
+ }
+});
+
+const TestApplication = new Lang.Class ({
+ Name: 'TestApplication',
+ Extends: Gtk.Application,
+
+ vfunc_startup: function() {
+ this.parent();
+ let window = new Gtk.Window();
+ window.add(new TestContainer());
+ window.show_all();
+ this.add_window(window);
+ }
+});
+
+let app = new TestApplication({ application_id: TEST_APPLICATION_ID,
+ flags: 0 });
+app.run(ARGV);