mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-03 14:42:10 +01:00
tests: Fix bad node ordering assumption
The tests were making assumptions about the order of the returned D-Bus introspection nodes. However, these are semantically unordered and changes to e.g. GHashTable would break the tests. Fix this by applying a sort prior to validation.
This commit is contained in:
parent
eed0f182fd
commit
0600dd3220
@ -337,6 +337,22 @@ introspect_callback (GDBusProxy *proxy,
|
|||||||
g_main_loop_quit (loop);
|
g_main_loop_quit (loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gint
|
||||||
|
compare_strings (gconstpointer a,
|
||||||
|
gconstpointer b)
|
||||||
|
{
|
||||||
|
const gchar *sa = *(const gchar **) a;
|
||||||
|
const gchar *sb = *(const gchar **) b;
|
||||||
|
|
||||||
|
/* Array terminator must sort last */
|
||||||
|
if (sa == NULL)
|
||||||
|
return 1;
|
||||||
|
if (sb == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return strcmp (sa, sb);
|
||||||
|
}
|
||||||
|
|
||||||
static gchar **
|
static gchar **
|
||||||
get_nodes_at (GDBusConnection *c,
|
get_nodes_at (GDBusConnection *c,
|
||||||
const gchar *object_path)
|
const gchar *object_path)
|
||||||
@ -390,6 +406,9 @@ get_nodes_at (GDBusConnection *c,
|
|||||||
g_free (xml_data);
|
g_free (xml_data);
|
||||||
g_dbus_node_info_unref (node_info);
|
g_dbus_node_info_unref (node_info);
|
||||||
|
|
||||||
|
/* Nodes are semantically unordered; sort array so tests can rely on order */
|
||||||
|
g_ptr_array_sort (p, compare_strings);
|
||||||
|
|
||||||
return (gchar **) g_ptr_array_free (p, FALSE);
|
return (gchar **) g_ptr_array_free (p, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1240,9 +1259,9 @@ test_object_registration (void)
|
|||||||
nodes = get_nodes_at (c, "/foo/dyna");
|
nodes = get_nodes_at (c, "/foo/dyna");
|
||||||
g_assert (nodes != NULL);
|
g_assert (nodes != NULL);
|
||||||
g_assert_cmpint (g_strv_length (nodes), ==, 3);
|
g_assert_cmpint (g_strv_length (nodes), ==, 3);
|
||||||
g_assert_cmpstr (nodes[0], ==, "lol");
|
g_assert_cmpstr (nodes[0], ==, "cat");
|
||||||
g_assert_cmpstr (nodes[1], ==, "cat");
|
g_assert_cmpstr (nodes[1], ==, "cheezburger");
|
||||||
g_assert_cmpstr (nodes[2], ==, "cheezburger");
|
g_assert_cmpstr (nodes[2], ==, "lol");
|
||||||
g_strfreev (nodes);
|
g_strfreev (nodes);
|
||||||
g_assert_cmpint (count_interfaces (c, "/foo/dyna/lol"), ==, 4);
|
g_assert_cmpint (count_interfaces (c, "/foo/dyna/lol"), ==, 4);
|
||||||
g_assert_cmpint (count_interfaces (c, "/foo/dyna/cat"), ==, 4);
|
g_assert_cmpint (count_interfaces (c, "/foo/dyna/cat"), ==, 4);
|
||||||
@ -1253,10 +1272,10 @@ test_object_registration (void)
|
|||||||
nodes = get_nodes_at (c, "/foo/dyna");
|
nodes = get_nodes_at (c, "/foo/dyna");
|
||||||
g_assert (nodes != NULL);
|
g_assert (nodes != NULL);
|
||||||
g_assert_cmpint (g_strv_length (nodes), ==, 4);
|
g_assert_cmpint (g_strv_length (nodes), ==, 4);
|
||||||
g_assert_cmpstr (nodes[0], ==, "lol");
|
g_assert_cmpstr (nodes[0], ==, "cat");
|
||||||
g_assert_cmpstr (nodes[1], ==, "cat");
|
g_assert_cmpstr (nodes[1], ==, "cheezburger");
|
||||||
g_assert_cmpstr (nodes[2], ==, "cheezburger");
|
g_assert_cmpstr (nodes[2], ==, "dynamicallycreated");
|
||||||
g_assert_cmpstr (nodes[3], ==, "dynamicallycreated");
|
g_assert_cmpstr (nodes[3], ==, "lol");
|
||||||
g_strfreev (nodes);
|
g_strfreev (nodes);
|
||||||
g_assert_cmpint (count_interfaces (c, "/foo/dyna/dynamicallycreated"), ==, 4);
|
g_assert_cmpint (count_interfaces (c, "/foo/dyna/dynamicallycreated"), ==, 4);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user