[glib/wip/gmenu: 33/59] Avoid cross-talk between tests



commit ee38f91dc8f17275b4cbfee838f84c9684043ae1
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Nov 28 07:51:57 2011 -0500

    Avoid cross-talk between tests
    
    Each test needs to remove the sources that it attaches
    to the default main context, or else things will work
    fine in isolation, but go bad in a full test run.

 gio/tests/gmenumodel.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/gio/tests/gmenumodel.c b/gio/tests/gmenumodel.c
index f7f6c55..12b11e1 100644
--- a/gio/tests/gmenumodel.c
+++ b/gio/tests/gmenumodel.c
@@ -584,6 +584,7 @@ test_dbus_roundtrip (void)
 {
   struct roundtrip_state state;
   GDBusConnection *bus;
+  guint id;
 
   bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
 
@@ -595,14 +596,16 @@ test_dbus_roundtrip (void)
   state.count = 0;
   state.success = 0;
 
-  g_timeout_add (10, roundtrip_step, &state);
+  id = g_timeout_add (10, roundtrip_step, &state);
 
   state.loop = g_main_loop_new (NULL, FALSE);
   g_main_loop_run (state.loop);
 
   g_main_loop_unref (state.loop);
+  g_source_remove (id);
   g_object_unref (state.proxy);
   g_menu_model_dbus_export_stop (G_MENU_MODEL (state.random));
+  g_assert (!g_menu_model_dbus_export_query (G_MENU_MODEL (state.random), NULL, NULL));
   g_object_unref (state.random);
   g_rand_free (state.rand);
   g_object_unref (bus);
@@ -627,7 +630,7 @@ stop_loop (gpointer data)
 
   g_main_loop_quit (loop);
 
-  return FALSE;
+  return G_SOURCE_REMOVE;
 }
 
 static void
@@ -638,6 +641,8 @@ test_dbus_subscriptions (void)
   GMenuProxy *proxy;
   GMainLoop *loop;
 
+  loop = g_main_loop_new (NULL, FALSE);
+
   bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
 
   menu = g_menu_new ();
@@ -655,7 +660,6 @@ test_dbus_subscriptions (void)
 
   g_assert_cmpint (items_changed_count, ==, 0);
 
-  loop = g_main_loop_new (NULL, FALSE);
   g_timeout_add (100, stop_loop, loop);
   g_main_loop_run (loop);
 
@@ -665,7 +669,6 @@ test_dbus_subscriptions (void)
   g_main_loop_run (loop);
 
   g_assert_cmpint (items_changed_count, ==, 1);
-
   g_assert_cmpint (g_menu_model_get_n_items (G_MENU_MODEL (proxy)), ==, 3);
 
   g_timeout_add (100, stop_loop, loop);
@@ -677,7 +680,7 @@ test_dbus_subscriptions (void)
   g_menu_remove (menu, 0);
   g_menu_remove (menu, 0);
 
-  g_timeout_add (100, stop_loop, loop);
+  g_timeout_add (200, stop_loop, loop);
   g_main_loop_run (loop);
 
   g_assert_cmpint (items_changed_count, ==, 6);
@@ -698,6 +701,8 @@ test_dbus_subscriptions (void)
 
   g_menu_model_dbus_export_stop (G_MENU_MODEL (menu));
   g_object_unref (menu);
+
+  g_main_loop_unref (loop);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]