mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
tests: Fix g_source_remove() of non-existent source in gapplication test
If the timeout callback was executed, it would remove the timeout
source, leaving the `g_source_remove()` call in the main function with a
dangling source ID.
Fixes commit 73205b8bbd
.
Spotted in https://gitlab.gnome.org/GNOME/glib/-/jobs/2645271.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
parent
ed256d6447
commit
642ee744b8
@ -1071,6 +1071,8 @@ typedef struct
|
||||
{
|
||||
gboolean allow_replacement;
|
||||
GSubprocess *subprocess;
|
||||
GApplication *app; /* (not owned) */
|
||||
guint timeout_id;
|
||||
} TestReplaceData;
|
||||
|
||||
static void
|
||||
@ -1116,11 +1118,12 @@ activate (gpointer data)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
quit_already (gpointer data)
|
||||
quit_already (gpointer user_data)
|
||||
{
|
||||
GApplication *app = data;
|
||||
TestReplaceData *data = user_data;
|
||||
|
||||
g_application_quit (app);
|
||||
g_application_quit (data->app);
|
||||
data->timeout_id = 0;
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
@ -1159,22 +1162,22 @@ test_replace (gconstpointer data)
|
||||
gboolean name_lost = FALSE;
|
||||
TestReplaceData data;
|
||||
GTestDBus *bus;
|
||||
guint timeout_id = 0;
|
||||
|
||||
data.allow_replacement = allow;
|
||||
data.subprocess = NULL;
|
||||
data.timeout_id = 0;
|
||||
|
||||
bus = g_test_dbus_new (0);
|
||||
g_test_dbus_up (bus);
|
||||
|
||||
app = g_application_new ("org.gtk.TestApplication.Replace", allow ? G_APPLICATION_ALLOW_REPLACEMENT : G_APPLICATION_DEFAULT_FLAGS);
|
||||
app = data.app = g_application_new ("org.gtk.TestApplication.Replace", allow ? G_APPLICATION_ALLOW_REPLACEMENT : G_APPLICATION_DEFAULT_FLAGS);
|
||||
g_application_set_inactivity_timeout (app, 500);
|
||||
g_signal_connect (app, "name-lost", G_CALLBACK (name_was_lost), &name_lost);
|
||||
g_signal_connect (app, "startup", G_CALLBACK (startup_cb), &data);
|
||||
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
||||
|
||||
if (!allow)
|
||||
timeout_id = g_timeout_add_seconds (1, quit_already, app);
|
||||
data.timeout_id = g_timeout_add_seconds (1, quit_already, &data);
|
||||
|
||||
g_application_run (app, G_N_ELEMENTS (argv) - 1, argv);
|
||||
|
||||
@ -1184,7 +1187,7 @@ test_replace (gconstpointer data)
|
||||
else
|
||||
g_assert_false (name_lost);
|
||||
|
||||
g_clear_handle_id (&timeout_id, g_source_remove);
|
||||
g_clear_handle_id (&data.timeout_id, g_source_remove);
|
||||
g_object_unref (app);
|
||||
g_free (binpath);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user