menu tests: keep mirror of proxy
authorRyan Lortie <desrt@desrt.ca>
Tue, 29 Nov 2011 13:16:19 +0000 (08:16 -0500)
committerRyan Lortie <desrt@desrt.ca>
Thu, 8 Dec 2011 23:05:13 +0000 (18:05 -0500)
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

index 9934285..12e6124 100644 (file)
@@ -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);
 }