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
This commit is contained in:
Peter Bloomfield 2022-06-21 18:43:30 -04:00
parent a4fa456e67
commit 42826576a8

View File

@ -294,6 +294,41 @@ test_datalist_id_remove_multiple (void)
g_assert_cmpint (count, ==, 0); 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 int
main (int argc, char *argv[]) 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/id", test_datalist_id);
g_test_add_func ("/datalist/recursive-clear", test_datalist_clear); 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", 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 (); return g_test_run ();
} }