summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2022-10-24 12:10:25 +0100
committerSimon McVittie <smcv@collabora.com>2022-10-28 12:07:45 +0100
commit5275410e6c61d520b8c4b8617faba46a37c65ca1 (patch)
tree9fe64f18a3f7a73cfcb573160f04a8eba12c5ac4
parent8a29325374fcc2dc847d65374d63b4401fc270a0 (diff)
downloadlibglnx-5275410e6c61d520b8c4b8617faba46a37c65ca1.tar.gz
tests: Add a simple test for g_memdup2, from GLib
Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r--LICENSES/LicenseRef-old-glib-tests.txt16
-rw-r--r--tests/meson.build1
-rw-r--r--tests/test-libglnx-backports.c36
3 files changed, 53 insertions, 0 deletions
diff --git a/LICENSES/LicenseRef-old-glib-tests.txt b/LICENSES/LicenseRef-old-glib-tests.txt
new file mode 100644
index 0000000..d78b443
--- /dev/null
+++ b/LICENSES/LicenseRef-old-glib-tests.txt
@@ -0,0 +1,16 @@
+This work is provided "as is"; redistribution and modification
+in whole or in part, in any medium, physical or electronic is
+permitted without restriction.
+
+This work is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+In no event shall the authors or contributors be liable for any
+direct, indirect, incidental, special, exemplary, or consequential
+damages (including, but not limited to, procurement of substitute
+goods or services; loss of use, data, or profits; or business
+interruption) however caused and on any theory of liability, whether
+in contract, strict liability, or tort (including negligence or
+otherwise) arising in any way out of the use of this software, even
+if advised of the possibility of such damage.
diff --git a/tests/meson.build b/tests/meson.build
index 2d0a976..2d32a23 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -33,6 +33,7 @@ if get_option('tests')
)
test_names = [
+ 'backports',
'errors',
'fdio',
'macros',
diff --git a/tests/test-libglnx-backports.c b/tests/test-libglnx-backports.c
new file mode 100644
index 0000000..c475cd4
--- /dev/null
+++ b/tests/test-libglnx-backports.c
@@ -0,0 +1,36 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ * Copyright 2019 Emmanuel Fleury
+ * SPDX-License-Identifier: LGPL-2.1-or-later AND LicenseRef-old-glib-tests
+ */
+
+#include "libglnx-config.h"
+#include "libglnx.h"
+
+/* Testing g_memdup2() function with various positive and negative cases */
+static void
+test_memdup2 (void)
+{
+ gchar *str_dup = NULL;
+ const gchar *str = "The quick brown fox jumps over the lazy dog";
+
+ /* Testing negative cases */
+ g_assert_null (g_memdup2 (NULL, 1024));
+ g_assert_null (g_memdup2 (str, 0));
+ g_assert_null (g_memdup2 (NULL, 0));
+
+ /* Testing normal usage cases */
+ str_dup = g_memdup2 (str, strlen (str) + 1);
+ g_assert_nonnull (str_dup);
+ g_assert_cmpstr (str, ==, str_dup);
+
+ g_free (str_dup);
+}
+
+int main (int argc, char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/strfuncs/memdup2", test_memdup2);
+ return g_test_run();
+}