Add helpers to verify refcounting in unit tests
@xclaesse
Submitted by Xavier Claessens Link to original bug (#726635)
Description
GTestDBus has internal code to wait for the last unref of the GDBusConnection singleton. Recently Simon McVittie added in tp-glib 2 simple functions that does the same kind of work. I think it would be nice to include them in glib.
The code can be found there: http://cgit.freedesktop.org/telepathy/telepathy-glib/tree/tests/lib/util.c?h=next#n764 and http://cgit.freedesktop.org/telepathy/telepathy-glib/tree/tests/lib/util.h?h=next#n111
tp_tests_assert_last_unref: In unit test teardown, it is good practice to verify we are releasing the latest ref on objects to avoid leaks.
tp_tests_await_last_unref: Iterate the main loop until the last unref of the object happens. Useful in the case the object has still pending async operations, like a DBus call. That implementation is much nicer than the code we have in GTestDBus actually. I would just add a g_get_monotonic_time() at each loop iteration and assert if it spend too much time waiting.
If we agree to include them in glib, I could provide a patch. Renaming them to g_assert_last_unref() and g_(assert?_)await_last_unref() maybe?