[glib/wip/menus-rebase3] menu tests: keep mirror of proxy



commit 4cd876999d80f920d62672ec317602075454885e
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Nov 29 08:16:19 2011 -0500

    menu tests: keep mirror of proxy
    
    Create a 'mirror' model of the proxy for the testcase.  In addition to
    testing that the proxy model emits the proper signals this also keeps
    the proxy alive (by holding references to it from the mirror).
    
    The previous code would create the submenu proxies and destroy them
    right away (from the recursive step in the equality comparison
    functions).  This means that the subscription would go out over D-Bus
    and the proxy would be destroyed before it returned.  Keeping the model
    alive allows it to be actually updated.

 gio/tests/gmenumodel.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/gio/tests/gmenumodel.c b/gio/tests/gmenumodel.c
index 9934285..12e6124 100644
--- a/gio/tests/gmenumodel.c
+++ b/gio/tests/gmenumodel.c
@@ -546,6 +546,7 @@ test_random (void)
 struct roundtrip_state
 {
   RandomMenu *random;
+  MirrorMenu *proxy_mirror;
   GMenuProxy *proxy;
   GMainLoop *loop;
   GRand *rand;
@@ -558,7 +559,8 @@ roundtrip_step (gpointer data)
 {
   struct roundtrip_state *state = data;
 
-  if (check_menus_equal (G_MENU_MODEL (state->random), G_MENU_MODEL (state->proxy)))
+  if (check_menus_equal (G_MENU_MODEL (state->random), G_MENU_MODEL (state->proxy)) &&
+      check_menus_equal (G_MENU_MODEL (state->random), G_MENU_MODEL (state->proxy_mirror)))
     {
       state->success++;
       state->count = 0;
@@ -590,10 +592,11 @@ test_dbus_roundtrip (void)
 
   state.rand = g_rand_new_with_seed (g_test_rand_int ());
 
-  state.random = random_menu_new (state.rand, TOP_ORDER);
+  state.random = random_menu_new (state.rand, 2);
   g_menu_model_dbus_export_start (bus, "/", G_MENU_MODEL (state.random), NULL);
   g_assert (g_menu_model_dbus_export_query (G_MENU_MODEL (state.random), NULL, NULL));
   state.proxy = g_menu_proxy_get (bus, g_dbus_connection_get_unique_name (bus), "/");
+  state.proxy_mirror = mirror_menu_new (G_MENU_MODEL (state.proxy));
   state.count = 0;
   state.success = 0;
 
@@ -608,6 +611,7 @@ test_dbus_roundtrip (void)
   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_object_unref (state.proxy_mirror);
   g_rand_free (state.rand);
   g_object_unref (bus);
 }



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