mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-12-01 13:09:41 -06:00
Testing: Provide a test_destroy function/macro combination.
Works on GObjects. Asserts if the object isn't a GObject (which may be the case if it has already been finalized) or if the object's finalize method isn't called (indicating a leak). git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22114 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
777074f482
commit
0ecb61dd13
@ -548,4 +548,19 @@ test_signal_return_hits (TestSignal sigp)
|
||||
return sig->hits;
|
||||
}
|
||||
|
||||
static void
|
||||
notify_destroy (gpointer pdata, GObject *obj)
|
||||
{
|
||||
gboolean *data = (gboolean*)pdata;
|
||||
if (! (*data)) *data = TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
test_object_checked_destroy (GObject *obj)
|
||||
{
|
||||
gboolean is_destroyed = FALSE;
|
||||
if (!obj || ! G_IS_OBJECT (obj)) return FALSE;
|
||||
g_object_weak_ref (obj, notify_destroy, &is_destroyed);
|
||||
g_object_unref (obj);
|
||||
return is_destroyed;
|
||||
}
|
||||
|
@ -282,6 +282,25 @@ guint test_signal_return_hits (TestSignal sig);
|
||||
|
||||
void test_signal_free (TestSignal sig);
|
||||
|
||||
/* test_object_checked_destroy unrefs obj and returns true if its finalize
|
||||
* method was called.
|
||||
*/
|
||||
|
||||
gboolean test_object_checked_destroy (GObject *obj);
|
||||
|
||||
/**
|
||||
* test_destroy() ensures that a GObject is still alive at the time
|
||||
* it's called and that it is finalized. The first assertion will
|
||||
* trigger if you pass it a ponter which isn't a GObject -- which
|
||||
* could be the case if the object has already been finalized. Then it
|
||||
* calls test_object_checked_destroy() on it, asserting if the
|
||||
* finalize method wasn't called (which indicates a leak).
|
||||
*/
|
||||
|
||||
#define test_destroy(obj) \
|
||||
g_assert (obj != NULL && G_IS_OBJECT (obj)); \
|
||||
g_assert (test_object_checked_destroy (G_OBJECT (obj)))
|
||||
|
||||
/* For Scheme testing access:
|
||||
void gnc_log_init_filename_special (gchar *filename);
|
||||
void gnc_log_shutdown (void);
|
||||
|
Loading…
Reference in New Issue
Block a user