Merge branch 'th/test-weak-notify' into 'main'

[th/test-weak-notify] gobject/tests: add test checking that GWeakRef is cleared in GWeakNotify

See merge request GNOME/glib!3865
This commit is contained in:
Philip Withnall 2024-01-31 12:35:52 +00:00
commit 5f855022a6

View File

@ -105,6 +105,17 @@ weak_ref2 (gpointer data,
weak_ref2_notified = TRUE;
}
static void
weak_ref3 (gpointer data,
GObject *object)
{
GWeakRef *weak_ref = data;
g_assert_null (g_weak_ref_get (weak_ref));
weak_ref2_notified = TRUE;
}
static void
toggle_ref1 (gpointer data,
GObject *object,
@ -154,6 +165,7 @@ static void
test_references (void)
{
GObject *object;
GWeakRef weak_ref;
/* Test basic weak reference operation */
global_object = object = g_object_new (TEST_TYPE_OBJECT, NULL);
@ -191,6 +203,17 @@ test_references (void)
g_assert_true (weak_ref2_notified);
g_assert_true (object_destroyed);
/* Test that within a GWeakNotify the GWeakRef is NULL already. */
weak_ref2_notified = FALSE;
object = g_object_new (G_TYPE_OBJECT, NULL);
g_weak_ref_init (&weak_ref, object);
g_assert_true (object == g_weak_ref_get (&weak_ref));
g_object_weak_ref (object, weak_ref3, &weak_ref);
g_object_unref (object);
g_object_unref (object);
g_assert_true (weak_ref2_notified);
g_weak_ref_clear (&weak_ref);
/* Test basic toggle reference operation */
global_object = object = g_object_new (TEST_TYPE_OBJECT, NULL);