From 87d153bd1d7c2fef46f7d8339d41f9cedaf1070c Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Mon, 26 May 2014 12:04:52 +0200 Subject: tests/ibus-config Fix timeout_id handling tests/ibus-config queues a timeout whose callback calls g_main_loop_quit() before returning FALSE. After exiting the mainloop, g_source_remove(timeout_id) is called, but if the mainloop was exited through the timeout callback, the source will already have been removed. This commit makes sure we only try to call g_source_remove() on that timeout if we did not exit the mainloop through the timeout callback. --- src/tests/ibus-config.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/tests/ibus-config.c b/src/tests/ibus-config.c index 133e57a9..370212e9 100644 --- a/src/tests/ibus-config.c +++ b/src/tests/ibus-config.c @@ -135,6 +135,7 @@ test_config_set_get (void) typedef struct { GMainLoop *loop; + guint timeout_id; gchar *section; gchar *name; } WatchData; @@ -264,6 +265,7 @@ timeout_cb (gpointer user_data) { WatchData *data = (WatchData *) user_data; g_main_loop_quit (data->loop); + data->timeout_id = 0; return FALSE; } @@ -276,7 +278,6 @@ change_and_test (IBusConfig *config, WatchData *data) { gboolean retval; - guint timeout_id; GVariant *var; data->section = NULL; @@ -294,17 +295,21 @@ change_and_test (IBusConfig *config, g_variant_unref (var); } - timeout_id = g_timeout_add (1, timeout_cb, data); + data->timeout_id = g_timeout_add (1, timeout_cb, data); g_main_loop_run (data->loop); - g_source_remove (timeout_id); + if (data->timeout_id != 0) { + g_source_remove (data->timeout_id); + } retval = ibus_config_set_value (config, section, name, g_variant_new_int32 (1)); g_assert (retval); - timeout_id = g_timeout_add (1, timeout_cb, data); + data->timeout_id = g_timeout_add (1, timeout_cb, data); g_main_loop_run (data->loop); - g_source_remove (timeout_id); + if (data->timeout_id != 0) { + g_source_remove (data->timeout_id); + } g_assert_cmpstr (data->section, ==, expected_section); g_assert_cmpstr (data->name, ==, expected_name); -- cgit v1.2.3