gobject/tests: Exercise a floating object reaching last-unref

This was previously exercised (probably by mistake) in
gobject/tests/type.c, but without making any assertions about what
happened, and the test would fail under G_ENABLE_DIAGNOSTIC if GLib was
compiled with debug enabled.

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2022-09-21 11:13:39 +01:00
parent 25d21edb32
commit 0bba27eea9

View File

@ -336,6 +336,20 @@ test_initially_unowned (void)
g_assert_cmpint (obj->ref_count, ==, 1);
g_object_unref (obj);
if (g_test_undefined ())
{
obj = g_object_new (G_TYPE_INITIALLY_UNOWNED, NULL);
#ifdef G_ENABLE_DEBUG
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
"A floating object GInitiallyUnowned * was finalized*");
#endif
g_object_unref (obj);
#ifdef G_ENABLE_DEBUG
g_test_assert_expected_messages ();
#endif
}
}
static void
@ -945,6 +959,8 @@ main (int argc, char **argv)
{
g_test_init (&argc, &argv, NULL);
g_setenv ("G_ENABLE_DIAGNOSTIC", "1", TRUE);
g_test_add_func ("/type/fundamentals", test_fundamentals);
g_test_add_func ("/type/qdata", test_type_qdata);
g_test_add_func ("/type/query", test_type_query);