summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am4
-rw-r--r--test/run-tests.c29
-rw-r--r--test/run-tests.h26
-rw-r--r--test/smoke-tests/app-window.js21
-rw-r--r--test/test-application.c46
-rw-r--r--test/test-window.c24
6 files changed, 147 insertions, 3 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 85c0fe7..0211c7e 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -10,7 +10,9 @@ TEST_LIBS = @EOS_SDK_LIBS@ $(top_builddir)/libendless-@EOS_SDK_API_VERSION@.la
test_run_tests_SOURCES = \
test/run-tests.c \
test/test-init.c \
- test/test-hello.c
+ test/test-hello.c \
+ test/test-application.c \
+ test/test-window.c
test_run_tests_CPPFLAGS = $(TEST_FLAGS)
test_run_tests_LDADD = $(TEST_LIBS)
diff --git a/test/run-tests.c b/test/run-tests.c
index ba016bc..aa6acbf 100644
--- a/test/run-tests.c
+++ b/test/run-tests.c
@@ -2,17 +2,46 @@
#include <glib-object.h>
#include <glib.h>
+#include <gtk/gtk.h>
+#include <endless/endless.h>
#include "run-tests.h"
+/* Test fixture for running a test from an EosApplication's "startup" handler */
+void
+app_window_test_fixture_setup (AppWindowTestFixture *fixture,
+ gconstpointer callback)
+{
+ fixture->app = eos_application_new (TEST_APPLICATION_ID, 0);
+ g_signal_connect(fixture->app, "startup", G_CALLBACK (callback),
+ NULL);
+}
+
+void
+app_window_test_fixture_test (AppWindowTestFixture *fixture,
+ gconstpointer unused)
+{
+ g_application_run (G_APPLICATION (fixture->app), 0, NULL);
+}
+
+void
+app_window_test_fixture_teardown (AppWindowTestFixture *fixture,
+ gconstpointer unused)
+{
+ g_object_unref (fixture->app);
+}
+
int
main (int argc,
char **argv)
{
g_test_init (&argc, &argv, NULL);
+ gtk_init (&argc, &argv);
add_init_tests ();
add_hello_tests ();
+ add_application_tests ();
+ add_window_tests ();
return g_test_run ();
}
diff --git a/test/run-tests.h b/test/run-tests.h
index 3efac9e..e60000f 100644
--- a/test/run-tests.h
+++ b/test/run-tests.h
@@ -3,7 +3,29 @@
#ifndef RUN_TESTS_H
#define RUN_TESTS_H
-void add_init_tests (void);
-void add_hello_tests (void);
+#define TEST_APPLICATION_ID "com.endlessm.example.test"
+
+#define ADD_APP_WINDOW_TEST(path, test_func) \
+ g_test_add ((path), AppWindowTestFixture, (test_func), \
+ app_window_test_fixture_setup, \
+ app_window_test_fixture_test, \
+ app_window_test_fixture_teardown);
+
+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 add_init_tests (void);
+void add_hello_tests (void);
+void add_application_tests (void);
+void add_window_tests (void);
#endif /* RUN_TESTS_H */
diff --git a/test/smoke-tests/app-window.js b/test/smoke-tests/app-window.js
new file mode 100644
index 0000000..ab89961
--- /dev/null
+++ b/test/smoke-tests/app-window.js
@@ -0,0 +1,21 @@
+// Copyright 2013 Endless Mobile, Inc.
+
+const Lang = imports.lang;
+const Endless = imports.gi.Endless;
+
+const TEST_APPLICATION_ID = 'com.endlessm.example.test';
+
+const TestApplication = new Lang.Class ({
+ Name: 'TestApplication',
+ Extends: Endless.Application,
+
+ vfunc_startup: function() {
+ this.parent();
+ this._window = new Endless.Window({application: this});
+ this._window.show_all();
+ },
+});
+
+let app = new TestApplication({ application_id: TEST_APPLICATION_ID,
+ flags: 0 });
+app.run(ARGV);
diff --git a/test/test-application.c b/test/test-application.c
new file mode 100644
index 0000000..e7f3aa1
--- /dev/null
+++ b/test/test-application.c
@@ -0,0 +1,46 @@
+/* Copyright 2013 Endless Mobile, Inc. */
+
+#include <stdlib.h>
+#include <gtk/gtk.h>
+#include <endless/endless.h>
+
+#include "run-tests.h"
+
+#define EXPECTED_TWO_WINDOW_ERRMSG "*You should not add more than one application window*"
+
+static void
+test_undefined_two_windows (EosApplication *app)
+{
+ /* Forking a test case from a signal handler is apparently not
+ deterministic */
+
+#if 0
+ /* Unix-only test */
+ if (g_test_trap_fork(0 /* timeout */, G_TEST_TRAP_SILENCE_STDERR))
+ {
+ GtkWidget *win1, *win2;
+
+ win1 = eos_window_new (app);
+ win2 = eos_window_new (app);
+
+ /* Destroy the windows so that the application exits */
+ gtk_widget_destroy (win1);
+ gtk_widget_destroy (win2);
+
+ exit (0);
+ }
+
+ g_test_trap_assert_failed ();
+ g_test_trap_assert_stderr (EXPECTED_TWO_WINDOW_ERRMSG);
+ gdk_flush ();
+#endif
+}
+
+void
+add_application_tests (void)
+{
+ /* Tests for undefined behavior, i.e. programming errors */
+ if (g_test_undefined ())
+ ADD_APP_WINDOW_TEST ("/application/two-windows",
+ test_undefined_two_windows);
+}
diff --git a/test/test-window.c b/test/test-window.c
new file mode 100644
index 0000000..831d94c
--- /dev/null
+++ b/test/test-window.c
@@ -0,0 +1,24 @@
+/* Copyright 2013 Endless Mobile, Inc. */
+
+#include <stdlib.h>
+#include <gtk/gtk.h>
+#include <endless/endless.h>
+
+#include "run-tests.h"
+
+static void
+test_assign_application (GApplication *app)
+{
+ GtkWidget *win = eos_window_new (EOS_APPLICATION (app));
+
+ g_assert(EOS_APPLICATION (app)
+ == EOS_APPLICATION (gtk_window_get_application (GTK_WINDOW (win))));
+
+ gtk_widget_destroy (win);
+}
+
+void
+add_window_tests (void)
+{
+ ADD_APP_WINDOW_TEST ("/window/assign-application", test_assign_application);
+}