Merge branch 'actions-test-fix' into 'main'

tests: Drop arbitrary and flaky waits from actions tests

See merge request GNOME/glib!2336
This commit is contained in:
Sebastian Dröge 2021-11-16 14:37:24 +00:00
commit 6a7187cae4

View File

@ -275,10 +275,12 @@ test_stateful (void)
if (g_test_undefined ())
{
GVariant *new_state = g_variant_ref_sink (g_variant_new_int32 (123));
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
"*assertion*g_variant_is_of_type*failed*");
g_simple_action_set_state (action, g_variant_new_int32 (123));
g_simple_action_set_state (action, new_state);
g_test_assert_expected_messages ();
g_variant_unref (new_state);
}
g_simple_action_set_state (action, g_variant_new_string ("hello"));
@ -292,10 +294,12 @@ test_stateful (void)
if (g_test_undefined ())
{
GVariant *new_state = g_variant_ref_sink (g_variant_new_int32 (123));
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
"*assertion*!= NULL*failed*");
g_simple_action_set_state (action, g_variant_new_int32 (123));
g_simple_action_set_state (action, new_state);
g_test_assert_expected_messages ();
g_variant_unref (new_state);
}
g_object_unref (action);
@ -536,6 +540,8 @@ count_activation (const gchar *action)
count = GPOINTER_TO_INT (g_hash_table_lookup (activation_counts, action));
count++;
g_hash_table_insert (activation_counts, (gpointer)action, GINT_TO_POINTER (count));
g_main_context_wakeup (NULL);
}
static gint
@ -742,6 +748,41 @@ call_describe (gpointer user_data)
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static void
action_added_removed_cb (GActionGroup *action_group,
char *action_name,
gpointer user_data)
{
guint *counter = user_data;
*counter = *counter + 1;
g_main_context_wakeup (NULL);
}
static void
action_enabled_changed_cb (GActionGroup *action_group,
char *action_name,
gboolean enabled,
gpointer user_data)
{
guint *counter = user_data;
*counter = *counter + 1;
g_main_context_wakeup (NULL);
}
static void
action_state_changed_cb (GActionGroup *action_group,
char *action_name,
GVariant *value,
gpointer user_data)
{
guint *counter = user_data;
*counter = *counter + 1;
g_main_context_wakeup (NULL);
}
static void
test_dbus_export (void)
{
@ -754,6 +795,8 @@ test_dbus_export (void)
GVariant *v;
guint id;
gchar **actions;
guint n_actions_added = 0, n_actions_enabled_changed = 0, n_actions_removed = 0, n_actions_state_changed = 0;
gulong added_signal_id, enabled_changed_signal_id, removed_signal_id, state_changed_signal_id;
loop = g_main_loop_new (NULL, FALSE);
@ -770,13 +813,19 @@ test_dbus_export (void)
g_assert_no_error (error);
proxy = g_dbus_action_group_get (bus, g_dbus_connection_get_unique_name (bus), "/");
added_signal_id = g_signal_connect (proxy, "action-added", G_CALLBACK (action_added_removed_cb), &n_actions_added);
enabled_changed_signal_id = g_signal_connect (proxy, "action-enabled-changed", G_CALLBACK (action_enabled_changed_cb), &n_actions_enabled_changed);
removed_signal_id = g_signal_connect (proxy, "action-removed", G_CALLBACK (action_added_removed_cb), &n_actions_removed);
state_changed_signal_id = g_signal_connect (proxy, "action-state-changed", G_CALLBACK (action_state_changed_cb), &n_actions_state_changed);
actions = g_action_group_list_actions (G_ACTION_GROUP (proxy));
g_assert_cmpint (g_strv_length (actions), ==, 0);
g_strfreev (actions);
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
/* Actions are queried from the bus asynchronously after the first
* list_actions() call. Wait for the expected signals then check again. */
while (n_actions_added < G_N_ELEMENTS (exported_entries))
g_main_context_iteration (NULL, TRUE);
actions = g_action_group_list_actions (G_ACTION_GROUP (proxy));
g_assert_cmpint (g_strv_length (actions), ==, G_N_ELEMENTS (exported_entries));
@ -795,54 +844,56 @@ test_dbus_export (void)
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
/* test that various changes get propagated from group to proxy */
n_actions_added = 0;
action = g_simple_action_new_stateful ("italic", NULL, g_variant_new_boolean (FALSE));
g_simple_action_group_insert (group, G_ACTION (action));
g_object_unref (action);
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
while (n_actions_added == 0)
g_main_context_iteration (NULL, TRUE);
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
action = G_SIMPLE_ACTION (g_simple_action_group_lookup (group, "cut"));
g_simple_action_set_enabled (action, FALSE);
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
while (n_actions_enabled_changed == 0)
g_main_context_iteration (NULL, TRUE);
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
action = G_SIMPLE_ACTION (g_simple_action_group_lookup (group, "bold"));
g_simple_action_set_state (action, g_variant_new_boolean (FALSE));
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
while (n_actions_state_changed == 0)
g_main_context_iteration (NULL, TRUE);
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
g_simple_action_group_remove (group, "italic");
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
while (n_actions_removed == 0)
g_main_context_iteration (NULL, TRUE);
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
/* test that activations and state changes propagate the other way */
n_actions_state_changed = 0;
g_assert_cmpint (activation_count ("copy"), ==, 0);
g_action_group_activate_action (G_ACTION_GROUP (proxy), "copy", NULL);
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
while (activation_count ("copy") == 0)
g_main_context_iteration (NULL, TRUE);
g_assert_cmpint (activation_count ("copy"), ==, 1);
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
n_actions_state_changed = 0;
g_assert_cmpint (activation_count ("bold"), ==, 0);
g_action_group_activate_action (G_ACTION_GROUP (proxy), "bold", NULL);
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
while (n_actions_state_changed == 0)
g_main_context_iteration (NULL, TRUE);
g_assert_cmpint (activation_count ("bold"), ==, 1);
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
@ -850,10 +901,11 @@ test_dbus_export (void)
g_assert_true (g_variant_get_boolean (v));
g_variant_unref (v);
n_actions_state_changed = 0;
g_action_group_change_action_state (G_ACTION_GROUP (proxy), "bold", g_variant_new_boolean (FALSE));
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
while (n_actions_state_changed == 0)
g_main_context_iteration (NULL, TRUE);
g_assert_cmpint (activation_count ("bold"), ==, 1);
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
@ -863,6 +915,10 @@ test_dbus_export (void)
g_dbus_connection_unexport_action_group (bus, id);
g_signal_handler_disconnect (proxy, added_signal_id);
g_signal_handler_disconnect (proxy, enabled_changed_signal_id);
g_signal_handler_disconnect (proxy, removed_signal_id);
g_signal_handler_disconnect (proxy, state_changed_signal_id);
g_object_unref (proxy);
g_object_unref (group);
g_main_loop_unref (loop);