From 06da78e1eaad8ffc4b1dfbfac1421093755e364a Mon Sep 17 00:00:00 2001 From: "P. F. Chimento" Date: Mon, 29 Apr 2013 16:21:43 +0200 Subject: Crash on eos_window_new (NULL) Creating a window that is not tied to an application should be a serious programming error. [#42] --- endless/eoswindow.c | 4 ++-- test/test-window.c | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/endless/eoswindow.c b/endless/eoswindow.c index 7cd7f28..f74911d 100644 --- a/endless/eoswindow.c +++ b/endless/eoswindow.c @@ -83,8 +83,8 @@ eos_window_set_property (GObject *object, gtk_window_set_application (GTK_WINDOW (self), GTK_APPLICATION (self->priv->application)); if (self->priv->application == NULL) - g_critical ("In order to create a window, you must have an application " - "for it to connect to."); + g_error ("In order to create a window, you must have an application " + "for it to connect to."); break; default: diff --git a/test/test-window.c b/test/test-window.c index 9127120..c7641bd 100644 --- a/test/test-window.c +++ b/test/test-window.c @@ -7,8 +7,8 @@ #include "run-tests.h" #define EXPECTED_NULL_APPLICATION_ERRMSG \ - "In order to create a window, you must have an application for it to " \ - "connect to." + "*In order to create a window, you must have an application for it to " \ + "connect to.*" static void test_assign_application (GApplication *app) @@ -24,18 +24,18 @@ test_assign_application (GApplication *app) static void test_application_not_null (GApplication *app) { - GtkWidget *win; - - g_test_expect_message (TEST_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, - EXPECTED_NULL_APPLICATION_ERRMSG); - - win = eos_window_new (NULL); + /* Unix-only test */ + if (g_test_trap_fork(0 /* timeout */, G_TEST_TRAP_SILENCE_STDERR)) + { + GtkWidget *win = eos_window_new (NULL); + gtk_widget_destroy (win); + exit (0); + } - g_test_assert_expected_messages (); + g_test_trap_assert_failed (); + g_test_trap_assert_stderr (EXPECTED_NULL_APPLICATION_ERRMSG); - gtk_widget_destroy (win); - g_application_release (app); - g_application_quit (app); /* Doesn't quit when win is destroyed */ + g_application_quit (app); /* No window, so otherwise won't quit */ } static void -- cgit v1.2.3 From 00a8455d3a641659333be649de00e2f1c0a3bc61 Mon Sep 17 00:00:00 2001 From: "P. F. Chimento" Date: Mon, 29 Apr 2013 16:22:33 +0200 Subject: Fix two-windows application test Figured it out while testing [#42] --- test/test-application.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/test/test-application.c b/test/test-application.c index e7f3aa1..7f291b1 100644 --- a/test/test-application.c +++ b/test/test-application.c @@ -9,38 +9,26 @@ #define EXPECTED_TWO_WINDOW_ERRMSG "*You should not add more than one application window*" static void -test_undefined_two_windows (EosApplication *app) +test_two_windows (EosApplication *app) { - /* Forking a test case from a signal handler is apparently not - deterministic */ + GtkWidget *win1 = eos_window_new (app); -#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); + GtkWidget *win2 = eos_window_new (app); gtk_widget_destroy (win2); - exit (0); } g_test_trap_assert_failed (); g_test_trap_assert_stderr (EXPECTED_TWO_WINDOW_ERRMSG); - gdk_flush (); -#endif + + gtk_widget_destroy (win1); } 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); + ADD_APP_WINDOW_TEST ("/application/two-windows", test_two_windows); } -- cgit v1.2.3