summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@redhat.com>2014-05-26 12:04:52 +0200
committerChristophe Fergeau <cfergeau@redhat.com>2014-05-26 14:53:30 +0200
commit87d153bd1d7c2fef46f7d8339d41f9cedaf1070c (patch)
treee86093b1d9f7e84487ab0975d7cf4b3e62eaba15
parent008c6941aaf20d83a246b5dd4fd38f61ea2fbca0 (diff)
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.
-rw-r--r--src/tests/ibus-config.c15
1 files 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);