diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 4 | ||||
-rw-r--r-- | test/run-tests.c | 4 | ||||
-rw-r--r-- | test/run-tests.h | 6 | ||||
-rw-r--r-- | test/smoke-tests/app-window.js | 21 | ||||
-rw-r--r-- | test/test-application.c | 48 | ||||
-rw-r--r-- | test/test-window.c | 24 |
6 files changed, 104 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..96cd4b8 100644 --- a/test/run-tests.c +++ b/test/run-tests.c @@ -2,6 +2,7 @@ #include <glib-object.h> #include <glib.h> +#include <gtk/gtk.h> #include "run-tests.h" @@ -10,9 +11,12 @@ 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..1d4c402 100644 --- a/test/run-tests.h +++ b/test/run-tests.h @@ -3,7 +3,9 @@ #ifndef RUN_TESTS_H #define RUN_TESTS_H -void add_init_tests (void); -void add_hello_tests (void); +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..2b2411c --- /dev/null +++ b/test/test-application.c @@ -0,0 +1,48 @@ +/* Copyright 2013 Endless Mobile, Inc. */ + +#include <stdlib.h> +#include <gtk/gtk.h> +#include <endless/endless.h> + +#include "run-tests.h" + +#define TEST_APPLICATION_ID "com.endlessm.example.test" +#define EXPECTED_TWO_WINDOW_ERRMSG "*You should not add more than one application window*" + +static void +_two_windows_on_startup (EosApplication *app, gpointer data) +{ + 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); +} + +static void +test_undefined_two_windows (void) +{ + EosApplication *app = eos_application_new(TEST_APPLICATION_ID, 0); + g_signal_connect (app, "startup", + G_CALLBACK (_two_windows_on_startup), NULL); + + /* Unix-only test */ + if (g_test_trap_fork(0 /* timeout */, G_TEST_TRAP_SILENCE_STDERR)) + { + g_application_run (G_APPLICATION (app), 0, NULL); + exit (0); + } + + g_test_trap_assert_failed (); + g_test_trap_assert_stderr (EXPECTED_TWO_WINDOW_ERRMSG); +} + +void +add_application_tests (void) +{ + /* Tests for undefined behavior, i.e. programming errors */ + if (g_test_undefined ()) + g_test_add_func ("/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); +} |