Skip to content
Snippets Groups Projects
Commit c02eb599 authored by Simon McVittie's avatar Simon McVittie
Browse files

Merge branch 'wip/denittis/strv_equal' into 'master'

backports: Add g_strv_equal from GLib >= 2.60

See merge request GNOME/libglnx!48
parents 07e3e49d 52f66d48
No related branches found
No related tags found
1 merge request!584Update libglnx
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2015 Colin Walters <walters@verbum.org>
* Copyright (C) 2018 Endless OS Foundation, LLC
* SPDX-License-Identifier: LGPL-2.0-or-later
*
* This program is free software: you can redistribute it and/or modify
......@@ -60,3 +61,24 @@ glnx_set_object (GObject **object_ptr,
return TRUE;
}
#endif
#if !GLIB_CHECK_VERSION(2, 60, 0)
gboolean
_glnx_strv_equal (const gchar * const *strv1,
const gchar * const *strv2)
{
g_return_val_if_fail (strv1 != NULL, FALSE);
g_return_val_if_fail (strv2 != NULL, FALSE);
if (strv1 == strv2)
return TRUE;
for (; *strv1 != NULL && *strv2 != NULL; strv1++, strv2++)
{
if (!g_str_equal (*strv1, *strv2))
return FALSE;
}
return (*strv1 == NULL && *strv2 == NULL);
}
#endif
......@@ -3,6 +3,7 @@
* Copyright 1998 Manish Singh
* Copyright 1998 Tim Janik
* Copyright (C) 2015 Colin Walters <walters@verbum.org>
* Copyright (C) 2018 Endless OS Foundation, LLC
* Copyright 2017 Emmanuele Bassi
* SPDX-License-Identifier: LGPL-2.1-or-later
*
......@@ -79,6 +80,12 @@ gboolean glnx_set_object (GObject **object_ptr,
#define G_OPTION_FLAG_NONE ((GOptionFlags) 0)
#endif
#if !GLIB_CHECK_VERSION(2, 60, 0)
#define g_strv_equal _glnx_strv_equal
gboolean _glnx_strv_equal (const gchar * const *strv1,
const gchar * const *strv2);
#endif
#ifndef G_DBUS_METHOD_INVOCATION_HANDLED /* added in 2.68 */
#define G_DBUS_METHOD_INVOCATION_HANDLED TRUE
#endif
......
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright (C) 2018 Endless OS Foundation, LLC
* Copyright 2019 Emmanuel Fleury
* Copyright 2021 Collabora Ltd.
* SPDX-License-Identifier: LGPL-2.1-or-later AND LicenseRef-old-glib-tests
......@@ -66,10 +67,39 @@ test_steal_fd (void)
g_assert_cmpint (fd, ==, -1);
}
/* Test g_strv_equal() works for various inputs. */
static void
test_strv_equal (void)
{
const gchar *strv_empty[] = { NULL };
const gchar *strv_empty2[] = { NULL };
const gchar *strv_simple[] = { "hello", "you", NULL };
const gchar *strv_simple2[] = { "hello", "you", NULL };
const gchar *strv_simple_reordered[] = { "you", "hello", NULL };
const gchar *strv_simple_superset[] = { "hello", "you", "again", NULL };
const gchar *strv_another[] = { "not", "a", "coded", "message", NULL };
g_assert_true (g_strv_equal (strv_empty, strv_empty));
g_assert_true (g_strv_equal (strv_empty, strv_empty2));
g_assert_true (g_strv_equal (strv_empty2, strv_empty));
g_assert_false (g_strv_equal (strv_empty, strv_simple));
g_assert_false (g_strv_equal (strv_simple, strv_empty));
g_assert_true (g_strv_equal (strv_simple, strv_simple));
g_assert_true (g_strv_equal (strv_simple, strv_simple2));
g_assert_true (g_strv_equal (strv_simple2, strv_simple));
g_assert_false (g_strv_equal (strv_simple, strv_simple_reordered));
g_assert_false (g_strv_equal (strv_simple_reordered, strv_simple));
g_assert_false (g_strv_equal (strv_simple, strv_simple_superset));
g_assert_false (g_strv_equal (strv_simple_superset, strv_simple));
g_assert_false (g_strv_equal (strv_simple, strv_another));
g_assert_false (g_strv_equal (strv_another, strv_simple));
}
int main (int argc, char **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/mainloop/steal-fd", test_steal_fd);
g_test_add_func ("/strfuncs/memdup2", test_memdup2);
g_test_add_func ("/strfuncs/strv-equal", test_strv_equal);
return g_test_run();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment