From fdcd976dee120477b580ec6169e69ba580f7241e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 10 Mar 2014 20:07:40 +0000 Subject: [PATCH 17/23] tp_tests_assert_last_unref: add Some tests find this functionality useful. --- 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__ */ -- 1.9.0