[next] telepathy-glib: tp_tests_assert_last_unref: add

Simon McVittie smcv at kemper.freedesktop.org
Thu Mar 13 07:08:35 PDT 2014


Module: telepathy-glib
Branch: next
Commit: 38f54cf206ec4df13475f45ea0d666c00321eca6
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=38f54cf206ec4df13475f45ea0d666c00321eca6

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Mon Mar 10 20:07:40 2014 +0000

tp_tests_assert_last_unref: add

Some tests find this functionality useful.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=76000
Reviewed-by: Guillaume Desmottes

---

 tests/lib/util.c |   16 ++++++++++++++++
 tests/lib/util.h |   16 ++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/tests/lib/util.c b/tests/lib/util.c
index 4aaa9dc..7f23fd4 100644
--- a/tests/lib/util.c
+++ b/tests/lib/util.c
@@ -699,3 +699,19 @@ tp_tests_dup_channel_props_asv (TpChannel *channel)
 
   return asv;
 }
+
+void
+_tp_tests_assert_last_unref (gpointer obj,
+    const gchar *file,
+    int line)
+{
+  GWeakRef weak;
+
+  g_weak_ref_init (&weak, obj);
+  g_object_unref (obj);
+  obj = g_weak_ref_get (&weak);
+
+  if (obj != NULL)
+    g_error ("%s:%d: %s %p should not have had any more references",
+        file, line, G_OBJECT_TYPE_NAME (obj), obj);
+}
diff --git a/tests/lib/util.h b/tests/lib/util.h
index 74a0307..b82ead8 100644
--- a/tests/lib/util.h
+++ b/tests/lib/util.h
@@ -108,4 +108,20 @@ TpChannel *tp_tests_channel_new_from_properties (TpConnection *conn,
 
 GHashTable * tp_tests_dup_channel_props_asv (TpChannel *channel);
 
+#define tp_tests_assert_last_unref(op) \
+  G_STMT_START \
+    { \
+      gpointer _tmp; \
+      \
+      _tmp = *(op); \
+      *(op) = NULL; \
+      \
+      _tp_tests_assert_last_unref (_tmp, __FILE__, __LINE__); \
+    } \
+  G_STMT_END
+void _tp_tests_assert_last_unref (gpointer obj,
+    const gchar *file,
+    int line);
+
+
 #endif /* #ifndef __TP_TESTS_LIB_UTIL_H__ */



More information about the telepathy-commits mailing list