Use GTestDBus in all GDBus unit tests

To make port easier, this rewrites dbus-sessionbus.c using a
GTestDBus singleton internally.

https://bugzilla.gnome.org/show_bug.cgi?id=672985
This commit is contained in:
Xavier Claessens
2012-04-18 23:28:17 +02:00
parent 95bf3d1194
commit 415a8d81f6
22 changed files with 65 additions and 609 deletions

View File

@@ -157,109 +157,3 @@ _g_bus_get_priv (GBusType bus_type,
}
/* ---------------------------------------------------------------------------------------------------- */
#if 0
/* toggle refs are not easy to use (maybe not even safe) when multiple
* threads are involved so implement this by busy-waiting for now
*/
gboolean
_g_object_wait_for_single_ref_do (gpointer object)
{
guint num_ms_elapsed;
gboolean timed_out;
timed_out = FALSE;
num_ms_elapsed = 0;
while (TRUE)
{
if (G_OBJECT (object)->ref_count == 1)
goto out;
if (num_ms_elapsed > 30000)
{
timed_out = TRUE;
goto out;
}
usleep (10 * 1000);
num_ms_elapsed += 10;
}
out:
return timed_out;
}
#else
typedef struct
{
GMainLoop *loop;
gboolean timed_out;
} WaitSingleRefData;
static gboolean
on_wait_single_ref_timeout (gpointer user_data)
{
WaitSingleRefData *data = user_data;
data->timed_out = TRUE;
g_main_loop_quit (data->loop);
return TRUE;
}
static void
on_wait_for_single_ref_toggled (gpointer user_data,
GObject *object,
gboolean is_last_ref)
{
WaitSingleRefData *data = user_data;
g_main_loop_quit (data->loop);
}
gboolean
_g_object_wait_for_single_ref_do (gpointer object)
{
WaitSingleRefData data;
guint timeout_id;
data.timed_out = FALSE;
if (G_OBJECT (object)->ref_count == 1)
goto out;
data.loop = g_main_loop_new (NULL, FALSE);
timeout_id = g_timeout_add (30 * 1000,
on_wait_single_ref_timeout,
&data);
g_object_add_toggle_ref (G_OBJECT (object),
on_wait_for_single_ref_toggled,
&data);
/* the reference could have been removed between us checking the
* ref_count and the toggle ref being added
*/
if (G_OBJECT (object)->ref_count == 2)
goto single_ref_already;
g_object_unref (object);
g_main_loop_run (data.loop);
g_object_ref (object);
single_ref_already:
g_object_remove_toggle_ref (object,
on_wait_for_single_ref_toggled,
&data);
g_source_remove (timeout_id);
g_main_loop_unref (data.loop);
out:
if (data.timed_out)
{
g_printerr ("b ref_count is %d\n", G_OBJECT (object)->ref_count);
}
return data.timed_out;
}
#endif
/* ---------------------------------------------------------------------------------------------------- */