diff options
author | Christian Hergert <chergert@redhat.com> | 2022-05-02 15:33:57 -0700 |
---|---|---|
committer | Christian Hergert <chergert@redhat.com> | 2022-05-06 20:53:12 -0700 |
commit | b584250777b12f3905e52e0878a9c9140fc6e198 (patch) | |
tree | 0c44a39301a256436240090b898d54ddfce8c0a3 | |
parent | 3e76026ab462c219334d96a70076b7fdc3a7a9a2 (diff) | |
download | gtk+-wip/chergert/action-parent.tar.gz |
actionmuxer: add test for action parentwip/chergert/action-parent
This tests that the infrastructure for action muxer parents is working
by activating an action on a widget for which the action is defined on
a widget not in the ancestry.
-rw-r--r-- | testsuite/gtk/action.c | 106 | ||||
-rw-r--r-- | testsuite/gtk/meson.build | 2 |
2 files changed, 107 insertions, 1 deletions
diff --git a/testsuite/gtk/action.c b/testsuite/gtk/action.c index 95bb071d4b..7024f35341 100644 --- a/testsuite/gtk/action.c +++ b/testsuite/gtk/action.c @@ -15,6 +15,8 @@ */ #include <gtk/gtk.h> +#include "gtkwidgetprivate.h" + static void activate (GSimpleAction *action, GVariant *parameter, @@ -717,6 +719,109 @@ test_enabled (void) g_object_unref (g_object_ref_sink (text)); } +static void +test_action_parent_action1 (GSimpleAction *action, + GVariant *param, + gpointer user_data) +{ + guint *count = user_data; + (*count)++; +} + +static void +test_action_parent_action2 (GSimpleAction *action, + GVariant *param, + gpointer user_data) +{ + g_simple_action_set_state (action, param); +} + +static void +test_action_parent (void) +{ + static const GActionEntry test_actions[] = { + { "action1", test_action_parent_action1 }, + { "action2", test_action_parent_action2, "s", "'initial'", test_action_parent_action2 }, + }; + GSimpleActionGroup *group; + GAction *action2; + GtkWidget *window; + GtkWidget *header; + GtkWidget *content; + GtkWidget *label1; + GtkWidget *label2; + GVariant *state = NULL; + const GVariantType *state_type = NULL; + GtkActionMuxer *muxer; + guint count = 0; + + window = g_object_new (GTK_TYPE_WINDOW, NULL); + g_object_ref_sink (window); + + header = g_object_new (GTK_TYPE_BUTTON, NULL); + content = g_object_new (GTK_TYPE_BOX, NULL); + label1 = g_object_new (GTK_TYPE_LABEL, NULL); + label2 = g_object_new (GTK_TYPE_LABEL, NULL); + gtk_box_append (GTK_BOX (content), label1); + gtk_box_append (GTK_BOX (content), label2); + gtk_window_set_titlebar (GTK_WINDOW (window), header); + gtk_window_set_child (GTK_WINDOW (window), content); + group = g_simple_action_group_new (); + g_action_map_add_action_entries (G_ACTION_MAP (group), + test_actions, + G_N_ELEMENTS (test_actions), + &count); + action2 = g_action_map_lookup_action (G_ACTION_MAP (group), "action2"); + + gtk_widget_insert_action_group (content, "test", G_ACTION_GROUP (group)); + gtk_widget_activate_action (label1, "test.action1", NULL); + g_assert_cmpint (count, ==, 1); + + gtk_widget_activate_action (header, "test.action1", NULL); + g_assert_cmpint (count, ==, 1); + + gtk_widget_set_action_parent (header, label1); + gtk_widget_activate_action (header, "test.action1", NULL); + g_assert_cmpint (count, ==, 2); + + gtk_widget_activate_action (header, "test.action2", "s", "changed"); + g_assert_cmpstr ("changed", ==, g_variant_get_string (g_action_get_state (action2), NULL)); + muxer = _gtk_widget_get_action_muxer (header, FALSE); + gtk_action_muxer_query_action (muxer, "test.action2", NULL, NULL, &state_type, NULL, &state); + g_assert_nonnull (state_type); + g_assert_nonnull (state); + g_assert_cmpstr ((const char *)state_type, ==, "s"); + g_assert_cmpstr ("changed", ==, g_variant_get_string (state, NULL)); + g_variant_unref (state); + + gtk_widget_set_action_parent (header, label2); + gtk_widget_activate_action (header, "test.action1", NULL); + g_assert_cmpint (count, ==, 3); + + gtk_widget_set_action_parent (header, NULL); + gtk_widget_activate_action (header, "test.action1", NULL); + gtk_widget_activate_action (header, "test.action2", "s", "third"); + g_assert_cmpint (count, ==, 3); + g_assert_cmpstr ("changed", ==, g_variant_get_string (g_action_get_state (action2), NULL)); + + gtk_widget_set_action_parent (label2, header); + gtk_widget_activate_action (label2, "test.action1", NULL); + g_assert_cmpint (count, ==, 3); + + gtk_widget_insert_action_group (content, "test", NULL); + gtk_widget_activate_action (label1, "test.action1", NULL); + gtk_widget_activate_action (header, "test.action1", NULL); + g_assert_cmpint (count, ==, 3); + + gtk_widget_activate_action (label2, "test.action2", "s", "third"); + g_assert_cmpstr ("changed", ==, g_variant_get_string (g_action_get_state (action2), NULL)); + + gtk_window_destroy (GTK_WINDOW (window)); + + g_assert_finalize_object (group); + g_assert_finalize_object (window); +} + int main (int argc, char *argv[]) @@ -732,6 +837,7 @@ main (int argc, g_test_add_func ("/action/overlap2", test_overlap2); g_test_add_func ("/action/introspection", test_introspection); g_test_add_func ("/action/enabled", test_enabled); + g_test_add_func ("/action/action_parent", test_action_parent); return g_test_run(); } diff --git a/testsuite/gtk/meson.build b/testsuite/gtk/meson.build index 3324664cac..da513ef22b 100644 --- a/testsuite/gtk/meson.build +++ b/testsuite/gtk/meson.build @@ -23,7 +23,6 @@ tests = [ { 'name': 'accel' }, # sadly, mesons xfail support seems busted # { 'name': 'accessor-apis' }, - { 'name': 'action' }, { 'name': 'adjustment' }, { 'name': 'bitset' }, { @@ -105,6 +104,7 @@ tests = [ # Tests that test private apis and therefore are linked against libgtk-4.a internal_tests = [ + { 'name': 'action' }, { 'name': 'bitmask' }, { 'name': 'composetable', |