[glib/wip/smcv/deprecated-prop-followup: 3/5] gobject/tests: Exercise a floating object reaching last-unref




commit 0bba27eea981e90f3a16045c97355ebcabad9602
Author: Simon McVittie <smcv collabora com>
Date:   Wed Sep 21 11:13:39 2022 +0100

    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>

 gobject/tests/reference.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
---
diff --git a/gobject/tests/reference.c b/gobject/tests/reference.c
index c7afc8abd8..92080b7ffa 100644
--- a/gobject/tests/reference.c
+++ b/gobject/tests/reference.c
@@ -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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]