From 42826576a882930c48bd7d95bc07f3354e51fde1 Mon Sep 17 00:00:00 2001 From: Peter Bloomfield Date: Tue, 21 Jun 2022 18:43:30 -0400 Subject: [PATCH] glib/tests/dataset: Test id_remove_multiple Test that destroy-funcs are called in the order that the keys are specified, not the order that they are found in the datalist. Helps https://gitlab.gnome.org/GNOME/glib/-/issues/2672 --- glib/tests/dataset.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/glib/tests/dataset.c b/glib/tests/dataset.c index 12eb33ab3..2897e6159 100644 --- a/glib/tests/dataset.c +++ b/glib/tests/dataset.c @@ -294,6 +294,41 @@ test_datalist_id_remove_multiple (void) g_assert_cmpint (count, ==, 0); } +static void +destroy_func (gpointer data) +{ + static int i = 0; + + i++; + g_assert_cmpint (GPOINTER_TO_INT (data), ==, i); +} + +static void +test_datalist_id_remove_multiple_destroy_order (void) +{ + /* Test that destroy-funcs are called in the order that the keys are + * specified, not the order that they are found in the datalist. */ + GData *list = NULL; + GQuark one = g_quark_from_static_string ("one"); + GQuark two = g_quark_from_static_string ("two"); + GQuark three = g_quark_from_static_string ("three"); + GQuark keys[] = { + one, + two, + three, + }; + + g_test_bug ("https://gitlab.gnome.org/GNOME/glib/issues/2672"); + + g_datalist_init (&list); + + g_datalist_id_set_data_full (&list, two, GINT_TO_POINTER (2), destroy_func); + g_datalist_id_set_data_full (&list, three, GINT_TO_POINTER (3), destroy_func); + g_datalist_id_set_data_full (&list, one, GINT_TO_POINTER (1), destroy_func); + + g_datalist_id_remove_multiple (&list, keys, G_N_ELEMENTS (keys)); +} + int main (int argc, char *argv[]) { @@ -310,6 +345,8 @@ main (int argc, char *argv[]) g_test_add_func ("/datalist/id", test_datalist_id); g_test_add_func ("/datalist/recursive-clear", test_datalist_clear); g_test_add_func ("/datalist/id-remove-multiple", test_datalist_id_remove_multiple); + g_test_add_func ("/datalist/id-remove-multiple-destroy-order", + test_datalist_id_remove_multiple_destroy_order); return g_test_run (); }