Testing GObject Lifecycles

It's a good idea to test that the lifecycle of your object is what you expect when writing your unit tests with GTest (and I hope you do). Here is a quick way to do that.

static void
my_object_test (void)
{
    MyObject *obj = my_object_new();
    /* play with obj */
    g_object_add_weak_pointer(G_OBJECT(obj), (gpointer *)&obj);
    g_object_unref(obj);
    g_assert(!obj);
}

-- Christian Hergert 2012-12-13

Back to Index