diff options
author | Ryan Lortie <desrt@desrt.ca> | 2014-01-07 19:45:19 -0500 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2014-01-07 20:30:57 -0500 |
commit | 99ebb1cad2d8f4eec293bca02f73a450fac18577 (patch) | |
tree | 411e22b4dcae1a6da0a877f2cdb58fd5c54d86e8 /testsuite | |
parent | 2fd307fdb3d62312fe5c49f0abcb9f4577a1c9c7 (diff) | |
download | gtk+-99ebb1cad2d8f4eec293bca02f73a450fac18577.tar.gz |
app window: test actiongroup across destroy
Make sure that we don't violate the interface contract of GActionGroup
just because gtk_widget_destroy() was called.
https://bugzilla.gnome.org/show_bug.cgi?id=710351
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/gtk/Makefile.am | 1 | ||||
-rw-r--r-- | testsuite/gtk/gtkapplicationwindow.c | 81 |
2 files changed, 82 insertions, 0 deletions
diff --git a/testsuite/gtk/Makefile.am b/testsuite/gtk/Makefile.am index 077b4f3b10..daefbffe7d 100644 --- a/testsuite/gtk/Makefile.am +++ b/testsuite/gtk/Makefile.am @@ -39,6 +39,7 @@ TEST_PROGS += \ floating \ grid \ gtkmenu \ + gtkapplicationwindow \ keyhash \ listbox \ no-gtk-init \ diff --git a/testsuite/gtk/gtkapplicationwindow.c b/testsuite/gtk/gtkapplicationwindow.c new file mode 100644 index 0000000000..fa5f743cb6 --- /dev/null +++ b/testsuite/gtk/gtkapplicationwindow.c @@ -0,0 +1,81 @@ +#include <gtk/gtk.h> + +static void +removed (GActionGroup *group, + const gchar *name, + gpointer user_data) +{ + gboolean *was_removed = user_data; + + *was_removed = TRUE; +} + +static void +test_as_actiongroup (void) +{ + GSimpleAction *action; + gboolean was_removed; + gpointer window; + gchar **list; + + /* do a dummy round... */ + window = g_object_ref_sink (g_object_new (GTK_TYPE_APPLICATION_WINDOW, NULL)); + gtk_widget_destroy (window); + g_object_unref (window); + + /* create a window, add an action */ + window = g_object_ref_sink (g_object_new (GTK_TYPE_APPLICATION_WINDOW, NULL)); + action = g_simple_action_new ("foo", NULL); + g_action_map_add_action (window, G_ACTION (action)); + g_object_unref (action); + + /* check which actions we have in the group */ + list = g_action_group_list_actions (window); + g_assert_cmpstr (list[0], ==, "foo"); + g_assert_cmpstr (list[1], ==, NULL); + g_strfreev (list); + + /* make sure that destroying the window keeps our view of the actions + * consistent. + */ + g_signal_connect (window, "action-removed", G_CALLBACK (removed), &was_removed); + gtk_widget_destroy (window); + + /* One of two things will have happened, depending on the + * implementation. Both are valid: + * + * - we received a signal that the action was removed when we + * destroyed the window; or + * + * - the action is still available. + * + * Make sure we're in one of those states. + * + * This additionally ensures that calling into methods on the window + * will continue to work after it has been destroy (and not segfault). + */ + list = g_action_group_list_actions (window); + + if (was_removed == FALSE) + { + /* should still be here */ + g_assert_cmpstr (list[0], ==, "foo"); + g_assert_cmpstr (list[1], ==, NULL); + } + else + /* should be gone */ + g_assert_cmpstr (list[0], ==, NULL); + + g_object_unref (window); + g_strfreev (list); +} + +int +main (int argc, char **argv) +{ + gtk_test_init (&argc, &argv, NULL); + + g_test_add_func ("/gtkapplicationwindow/as-actiongroup", test_as_actiongroup); + + return g_test_run (); +} |