[gtk/wip/chergert/action-parent: 4/4] actionmuxer: add test for action parent




commit 4a38abab016f7ace3991702134641728bd5cf915
Author: Christian Hergert <chergert redhat com>
Date:   Mon May 2 15:33:57 2022 -0700

    actionmuxer: add test for 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.

 testsuite/gtk/action.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
---
diff --git a/testsuite/gtk/action.c b/testsuite/gtk/action.c
index 95bb071d4b..dca6a9e713 100644
--- a/testsuite/gtk/action.c
+++ b/testsuite/gtk/action.c
@@ -717,6 +717,54 @@ 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 (void)
+{
+  static const GActionEntry test_actions[] = {
+    { "action1", test_action_parent_action1 },
+  };
+  GSimpleActionGroup *group;
+  GtkWidget *window;
+  GtkWidget *header;
+  GtkWidget *content;
+  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_LABEL, NULL);
+  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);
+
+  gtk_widget_insert_action_group (content, "test", G_ACTION_GROUP (group));
+  gtk_widget_activate_action (content, "test.action1", NULL);
+  g_assert_cmpint (count, ==, 1);
+
+  gtk_widget_insert_action_group (content, "test", NULL);
+  gtk_widget_activate_action (content, "test.action1", NULL);
+  g_assert_cmpint (count, ==, 1);
+
+  gtk_window_destroy (GTK_WINDOW (window));
+
+  g_assert_finalize_object (group);
+  g_assert_finalize_object (window);
+}
+
 int
 main (int   argc,
       char *argv[])
@@ -732,6 +780,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();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]