diff options
author | Thomas Haller <thaller@redhat.com> | 2015-03-26 18:05:42 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-04-08 14:39:16 +0200 |
commit | 57453189e05067be831d61805fbd45c7565b0085 (patch) | |
tree | bd03013db746f0ae9f8d85ea51608dd39bcba43e /include | |
parent | ba8ce3bbe511a3df2b2b3c66eeb13429896c59b6 (diff) | |
download | NetworkManager-57453189e05067be831d61805fbd45c7565b0085.tar.gz |
test: add option in nmtst_platform_ip4_routes_equal() to ignore ordering
Same for nmtst_platform_ip6_routes_equal().
It's useful to check for equal routes ignoring the ordering.
Diffstat (limited to 'include')
-rw-r--r-- | include/nm-test-utils.h | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h index 157b3dbc73..87d6c72cae 100644 --- a/include/nm-test-utils.h +++ b/include/nm-test-utils.h @@ -686,14 +686,28 @@ nmtst_platform_ip6_route_full (const char *network, guint plen, const char *gate return route; } +inline static int +_nmtst_platform_ip4_routes_equal_sort (gconstpointer a, gconstpointer b, gpointer user_data) +{ + return nm_platform_ip4_route_cmp ((const NMPlatformIP4Route *) a, (const NMPlatformIP4Route *) b); +} + inline static void -nmtst_platform_ip4_routes_equal (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b, gsize len) +nmtst_platform_ip4_routes_equal (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b, gsize len, gboolean ignore_order) { gsize i; + gs_free const NMPlatformIP4Route *c_a = NULL, *c_b = NULL; g_assert (a); g_assert (b); + if (ignore_order) { + a = c_a = g_memdup (a, sizeof (NMPlatformIP4Route) * len); + b = c_b = g_memdup (b, sizeof (NMPlatformIP4Route) * len); + g_qsort_with_data (c_a, len, sizeof (NMPlatformIP4Route), _nmtst_platform_ip4_routes_equal_sort, NULL); + g_qsort_with_data (c_b, len, sizeof (NMPlatformIP4Route), _nmtst_platform_ip4_routes_equal_sort, NULL); + } + for (i = 0; i < len; i++) { if (nm_platform_ip4_route_cmp (&a[i], &b[i]) != 0) { g_error ("Error comparing IPv4 route[%lu]: %s vs %s", (long unsigned) i, @@ -707,14 +721,28 @@ nmtst_platform_ip4_routes_equal (const NMPlatformIP4Route *a, const NMPlatformIP } } +inline static int +_nmtst_platform_ip6_routes_equal_sort (gconstpointer a, gconstpointer b, gpointer user_data) +{ + return nm_platform_ip6_route_cmp ((const NMPlatformIP6Route *) a, (const NMPlatformIP6Route *) b); +} + inline static void -nmtst_platform_ip6_routes_equal (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b, gsize len) +nmtst_platform_ip6_routes_equal (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b, gsize len, gboolean ignore_order) { gsize i; + gs_free const NMPlatformIP6Route *c_a = NULL, *c_b = NULL; g_assert (a); g_assert (b); + if (ignore_order) { + a = c_a = g_memdup (a, sizeof (NMPlatformIP6Route) * len); + b = c_b = g_memdup (b, sizeof (NMPlatformIP6Route) * len); + g_qsort_with_data (c_a, len, sizeof (NMPlatformIP6Route), _nmtst_platform_ip6_routes_equal_sort, NULL); + g_qsort_with_data (c_b, len, sizeof (NMPlatformIP6Route), _nmtst_platform_ip6_routes_equal_sort, NULL); + } + for (i = 0; i < len; i++) { if (nm_platform_ip6_route_cmp (&a[i], &b[i]) != 0) { g_error ("Error comparing IPv6 route[%lu]: %s vs %s", (long unsigned) i, |