diff options
| author | Michael Biebl <biebl@debian.org> | 2019-12-18 18:29:24 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2019-12-18 18:29:24 +0100 |
| commit | 28028b26b3371756811e95d894f709f4b1207c00 (patch) | |
| tree | 6fe7316fd743b51042db47601a8ef8814b3134ac /shared/nm-utils/tests/test-shared-general.c | |
| parent | e22609983008e1a669196ad64ba3a59ae8c76e0d (diff) | |
New upstream version 1.22.0 upstream/1.22.0
Diffstat (limited to 'shared/nm-utils/tests/test-shared-general.c')
| -rw-r--r-- | shared/nm-utils/tests/test-shared-general.c | 78 |
1 files changed, 62 insertions, 16 deletions
diff --git a/shared/nm-utils/tests/test-shared-general.c b/shared/nm-utils/tests/test-shared-general.c index 24affba7..34da19b3 100644 --- a/shared/nm-utils/tests/test-shared-general.c +++ b/shared/nm-utils/tests/test-shared-general.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2018 Red Hat, Inc. + * Copyright (C) 2018 Red Hat, Inc. */ #define NM_TEST_UTILS_NO_LIBNM 1 @@ -24,12 +10,38 @@ #include "nm-std-aux/unaligned.h" #include "nm-glib-aux/nm-random-utils.h" #include "nm-glib-aux/nm-time-utils.h" +#include "nm-glib-aux/nm-ref-string.h" #include "nm-utils/nm-test-utils.h" /*****************************************************************************/ static void +test_gpid (void) +{ + const int *int_ptr; + GPid pid = 42; + + /* We redefine G_PID_FORMAT, because it's only available since glib 2.53.5. + * + * Also, this is the format for GPid, which for glib is always a typedef + * for "int". Add a check for that here. + * + * G_PID_FORMAT is not about pid_t, which might be a smaller int, and which we would + * check with SIZEOF_PID_T. */ + G_STATIC_ASSERT (sizeof (GPid) == sizeof (int)); + + g_assert_cmpstr (""G_PID_FORMAT, ==, "i"); + + /* check that it's really "int". We will get a compiler warning, if that's not + * the case. */ + int_ptr = &pid; + g_assert_cmpint (*int_ptr, ==, 42); +} + +/*****************************************************************************/ + +static void test_monotonic_timestamp (void) { g_assert (nm_utils_get_monotonic_timestamp_s () > 0); @@ -510,12 +522,45 @@ test_nm_utils_bin2hexstr (void) /*****************************************************************************/ +static void +test_nm_ref_string (void) +{ + nm_auto_ref_string NMRefString *s1 = NULL; + NMRefString *s2; + + s1 = nm_ref_string_new ("hallo"); + g_assert (s1); + g_assert_cmpstr (s1->str, ==, "hallo"); + g_assert_cmpint (s1->len, ==, strlen ("hallo")); + + s2 = nm_ref_string_new ("hallo"); + g_assert (s2 == s1); + nm_ref_string_unref (s2); + + s2 = nm_ref_string_new (NULL); + g_assert (!s2); + nm_ref_string_unref (s2); + +#define STR_WITH_NUL "hallo\0test\0" + s2 = nm_ref_string_new_len (STR_WITH_NUL, NM_STRLEN (STR_WITH_NUL)); + g_assert (s2); + g_assert_cmpstr (s2->str, ==, "hallo"); + g_assert_cmpint (s2->len, ==, NM_STRLEN (STR_WITH_NUL)); + g_assert_cmpint (s2->len, >, strlen (s2->str)); + g_assert_cmpmem (s2->str, s2->len, STR_WITH_NUL, NM_STRLEN (STR_WITH_NUL)); + g_assert (s2->str[s2->len] == '\0'); + nm_ref_string_unref (s2); +} + +/*****************************************************************************/ + NMTST_DEFINE (); int main (int argc, char **argv) { nmtst_init (&argc, &argv, TRUE); + g_test_add_func ("/general/test_gpid", test_gpid); g_test_add_func ("/general/test_monotonic_timestamp", test_monotonic_timestamp); g_test_add_func ("/general/test_nmhash", test_nmhash); g_test_add_func ("/general/test_nm_make_strv", test_make_strv); @@ -526,6 +571,7 @@ int main (int argc, char **argv) g_test_add_func ("/general/test_strv_cmp", test_strv_cmp); g_test_add_func ("/general/test_strstrip_avoid_copy", test_strstrip_avoid_copy); g_test_add_func ("/general/test_nm_utils_bin2hexstr", test_nm_utils_bin2hexstr); + g_test_add_func ("/general/test_nm_ref_string", test_nm_ref_string); return g_test_run (); } |