diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/meson.build | 1 | ||||
-rw-r--r-- | tests/test-libglnx-backports.c | 36 |
2 files changed, 37 insertions, 0 deletions
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(); +} |