From 00bbe1537d9228d923f0ec97b14f94abed6fcc02 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 4 Jun 2018 13:02:50 +0100 Subject: [PATCH 28/40] test: Add an implementation of g_strv_contains() for GLib < 2.44 We still use Ubuntu 14.04 on Travis-CI, and that doesn't have g_strv_contains(). Signed-off-by: Simon McVittie --- test/test-utils-glib.c | 17 +++++++++++++++++ test/test-utils-glib.h | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index 81727a1d..ead2a801 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -817,3 +817,20 @@ test_sync_gdbus_connections (GDBusConnection *caller, g_test_message ("Synchronized caller %p with callee %p", caller, callee); } + +#if !GLIB_CHECK_VERSION(2, 44, 0) +gboolean +backported_g_strv_contains (const gchar * const *haystack, + const gchar *needle) +{ + const gchar * const *iter; + + for (iter = haystack; iter != NULL && *iter != NULL; iter++) + { + if (g_str_equal (needle, *iter)) + return TRUE; + } + + return FALSE; +} +#endif diff --git a/test/test-utils-glib.h b/test/test-utils-glib.h index 1795f741..f3e05ddd 100644 --- a/test/test-utils-glib.h +++ b/test/test-utils-glib.h @@ -119,6 +119,10 @@ backported_g_steal_pointer (gpointer pointer_to_pointer) *pp = NULL; return ret; } + +#define g_strv_contains(haystack, needle) backported_g_strv_contains (haystack, needle) +gboolean backported_g_strv_contains (const gchar * const *haystack, + const gchar *needle); #endif void test_store_result_cb (GObject *source_object, -- 2.17.0