From 20068d9d0731b580d6d8218b97c482c0558149dd Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Mon, 25 Jul 2016 11:42:37 +0900 Subject: tests/ibus-engine-switch: Don't try to remove non-existing GSource ibus-engine-switch schedules an idle doing an engine switch, and also schedules a timeout after 1 microsecond which exits the main loop. Both of these callbacks will return FALSE, which detaches the associated GSource from the mainloop and destroys it. As the only way to exit the mainloop is when the timeout callback runs, we should not try to run g_source_remove(timeout_id) as it will already be gone, and this causes a warning. This commit reorders a bit to make the ordering between the idle and timeout more obvious, and it gets rid of the calls to g_source_remove() as they are needed. BUG=https://github.com/ibus/ibus/issues/1868 Review URL: https://codereview.appspot.com/103100044 --- bus/Makefile.am | 8 ++++++++ src/tests/ibus-engine-switch.c | 24 +++++++++++++++++------- src/tests/runtest | 1 + 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/bus/Makefile.am b/bus/Makefile.am index 4dabacf5..f032367c 100644 --- a/bus/Makefile.am +++ b/bus/Makefile.am @@ -113,6 +113,14 @@ TESTS = \ $(NULL) endif +TESTS_ENVIRONMENT = \ + top_builddir=$(top_builddir) \ + top_srcdir=$(top_srcdir) \ + builddir=$(builddir) \ + $(NULL) + +LOG_COMPILER = $(top_srcdir)/src/tests/runtest + noinst_PROGRAMS = $(TESTS) test_matchrule_DEPENDENCIES = \ diff --git a/src/tests/ibus-engine-switch.c b/src/tests/ibus-engine-switch.c index 4c99b79c..5c2bd516 100644 --- a/src/tests/ibus-engine-switch.c +++ b/src/tests/ibus-engine-switch.c @@ -44,26 +44,34 @@ change_context_engine (IBusInputContext *context) typedef struct { gint count; + guint timeout_id; + guint idle_id; } GlobalEngineChangedData; static void global_engine_changed_cb (IBusBus *bus, gchar *name, gpointer user_data) { GlobalEngineChangedData *data = (GlobalEngineChangedData *) user_data; - data->count++; + if (data->count++ == 0) + ibus_quit (); } static gboolean timeout_cb (gpointer user_data) { - ibus_quit (); + GlobalEngineChangedData *data = (GlobalEngineChangedData *) user_data; + if (data->count == 0) + ibus_quit (); + data->timeout_id = 0; return FALSE; } static gboolean change_global_engine_cb (gpointer user_data) { + GlobalEngineChangedData *data = (GlobalEngineChangedData *) user_data; change_global_engine (); + data->idle_id = 0; return FALSE; } @@ -71,7 +79,7 @@ static void test_global_engine (void) { GlobalEngineChangedData data; - guint handler_id, timeout_id, idle_id; + guint handler_id; if (!ibus_bus_get_use_global_engine (bus)) return; @@ -82,15 +90,17 @@ test_global_engine (void) "global-engine-changed", G_CALLBACK (global_engine_changed_cb), &data); - timeout_id = g_timeout_add_seconds (1, timeout_cb, &data); - idle_id = g_idle_add ((GSourceFunc) change_global_engine_cb, NULL); + data.timeout_id = g_timeout_add_seconds (1, timeout_cb, &data); + data.idle_id = g_idle_add ((GSourceFunc) change_global_engine_cb, &data); ibus_main (); g_assert_cmpint (data.count, ==, G_N_ELEMENTS (engine_names)); - g_source_remove (idle_id); - g_source_remove (timeout_id); + if (data.idle_id > 0) + g_source_remove (data.idle_id); + if (data.timeout_id > 0) + g_source_remove (data.timeout_id); g_signal_handler_disconnect (bus, handler_id); } diff --git a/src/tests/runtest b/src/tests/runtest index 66202810..81dc62d1 100755 --- a/src/tests/runtest +++ b/src/tests/runtest @@ -27,6 +27,7 @@ ibus-inputcontext ibus-inputcontext-create ibus-engine-switch ibus-compose +test-stress " # Portable replacement of basename. -- cgit v1.2.1