about summary refs log tree commit diff
path: root/shared/nm-glib-aux/tests
diff options
context:
space:
mode:
Diffstat (limited to 'shared/nm-glib-aux/tests')
-rw-r--r--shared/nm-glib-aux/tests/meson.build12
-rw-r--r--shared/nm-glib-aux/tests/test-json-aux.c6
-rw-r--r--shared/nm-glib-aux/tests/test-shared-general.c78
3 files changed, 55 insertions, 41 deletions
diff --git a/shared/nm-glib-aux/tests/meson.build b/shared/nm-glib-aux/tests/meson.build
index 8136eff9..464f4e7c 100644
--- a/shared/nm-glib-aux/tests/meson.build
+++ b/shared/nm-glib-aux/tests/meson.build
@@ -1,13 +1,12 @@
-# SPDX-License-Identifier: LGPL-2.1+
+# SPDX-License-Identifier: LGPL-2.1-or-later
 
 exe = executable(
   'test-shared-general',
   'test-shared-general.c',
   c_args: [
-    '-DNETWORKMANAGER_COMPILATION_TEST',
-    '-DNETWORKMANAGER_COMPILATION=(NM_NETWORKMANAGER_COMPILATION_GLIB|NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG)',
+    '-DG_LOG_DOMAIN="test"',
   ],
-  dependencies: libnm_utils_base_dep,
+  dependencies: libnm_glib_aux_dep,
   link_with: libnm_systemd_logging_stub,
 )
 
@@ -23,11 +22,10 @@ if jansson_dep.found()
     'test-json-aux',
     'test-json-aux.c',
     c_args: [
-      '-DNETWORKMANAGER_COMPILATION_TEST',
-      '-DNETWORKMANAGER_COMPILATION=(NM_NETWORKMANAGER_COMPILATION_GLIB|NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG)',
+      '-DG_LOG_DOMAIN="test"',
     ],
     dependencies: [
-      libnm_utils_base_dep,
+      libnm_glib_aux_dep,
       jansson_dep,
       dl_dep,
     ],
diff --git a/shared/nm-glib-aux/tests/test-json-aux.c b/shared/nm-glib-aux/tests/test-json-aux.c
index 5331c015..b07d673f 100644
--- a/shared/nm-glib-aux/tests/test-json-aux.c
+++ b/shared/nm-glib-aux/tests/test-json-aux.c
@@ -1,8 +1,6 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#define NM_TEST_UTILS_NO_LIBNM 1
-
-#include "nm-default.h"
+#include "nm-glib-aux/nm-default-glib-i18n-prog.h"
 
 #include <jansson.h>
 
diff --git a/shared/nm-glib-aux/tests/test-shared-general.c b/shared/nm-glib-aux/tests/test-shared-general.c
index 84e0a6f0..f42c6fb1 100644
--- a/shared/nm-glib-aux/tests/test-shared-general.c
+++ b/shared/nm-glib-aux/tests/test-shared-general.c
@@ -1,11 +1,9 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 /*
  * Copyright (C) 2018 Red Hat, Inc.
  */
 
-#define NM_TEST_UTILS_NO_LIBNM 1
-
-#include "nm-default.h"
+#include "nm-glib-aux/nm-default-glib-i18n-prog.h"
 
 #include "nm-std-aux/unaligned.h"
 #include "nm-glib-aux/nm-random-utils.h"
@@ -364,8 +362,8 @@ test_strv_cmp(void)
         _strv_cmp_fuzz_input((a1), _l1, &_a1_free_shallow, &_a1_free_deep, &_a1, &_a1x);            \
         _strv_cmp_fuzz_input((a2), _l2, &_a2_free_shallow, &_a2_free_deep, &_a2, &_a2x);            \
                                                                                                     \
-        _c1 = _nm_utils_strv_cmp_n(_a1, _l1, _a2, _l2);                                             \
-        _c2 = _nm_utils_strv_cmp_n(_a2, _l2, _a1, _l1);                                             \
+        _c1 = nm_utils_strv_cmp_n(_a1, _l1, _a2, _l2);                                              \
+        _c2 = nm_utils_strv_cmp_n(_a2, _l2, _a1, _l1);                                              \
         if (equal) {                                                                                \
             g_assert_cmpint(_c1, ==, 0);                                                            \
             g_assert_cmpint(_c2, ==, 0);                                                            \
@@ -376,8 +374,8 @@ test_strv_cmp(void)
                                                                                                     \
         /* Compare with self. _strv_cmp_fuzz_input() randomly swapped the arguments (_a1 and _a1x).
          * Either way, the arrays must compare equal to their semantically equal alternative. */ \
-        g_assert_cmpint(_nm_utils_strv_cmp_n(_a1, _l1, _a1x, _l1), ==, 0);                          \
-        g_assert_cmpint(_nm_utils_strv_cmp_n(_a2, _l2, _a2x, _l2), ==, 0);                          \
+        g_assert_cmpint(nm_utils_strv_cmp_n(_a1, _l1, _a1x, _l1), ==, 0);                           \
+        g_assert_cmpint(nm_utils_strv_cmp_n(_a2, _l2, _a2x, _l2), ==, 0);                           \
                                                                                                     \
         _strv_cmp_free_deep(_a1_free_deep, _l1);                                                    \
         _strv_cmp_free_deep(_a2_free_deep, _l2);                                                    \
@@ -632,9 +630,10 @@ static NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(
     {"0", 0},
     {"1", 1},
     {"2", 2},
-    {"3", 3}, )
+    {"3", 3}, );
 
-    static void test_string_table_lookup(void)
+static void
+test_string_table_lookup(void)
 {
     const char *const args[] = {
         NULL,
@@ -762,25 +761,44 @@ test_nm_utils_get_next_realloc_size(void)
         }
 
         {
-            const gsize requested      = requested0;
-            const gsize reserved_true  = nm_utils_get_next_realloc_size(TRUE, requested);
-            const gsize reserved_false = nm_utils_get_next_realloc_size(FALSE, requested);
+            const gsize requested = requested0;
+            gsize       reserved_true;
+            gsize       reserved_false;
+            bool        truncated_true  = FALSE;
+            bool        truncated_false = FALSE;
+
+            if (sizeof(gsize) > 4 && requested > SIZE_MAX / 2u - 24u) {
+                reserved_false  = G_MAXSSIZE;
+                truncated_false = TRUE;
+            } else
+                reserved_false = nm_utils_get_next_realloc_size(FALSE, requested);
+
+            if (sizeof(gsize) > 4 && requested > SIZE_MAX - 0x1000u - 24u) {
+                reserved_true  = G_MAXSSIZE;
+                truncated_true = TRUE;
+            } else
+                reserved_true = nm_utils_get_next_realloc_size(TRUE, requested);
 
             g_assert_cmpuint(reserved_true, >, 0);
             g_assert_cmpuint(reserved_false, >, 0);
-            g_assert_cmpuint(reserved_true, >=, requested);
-            g_assert_cmpuint(reserved_false, >=, requested);
-            g_assert_cmpuint(reserved_false, >=, reserved_true);
+            if (!truncated_true)
+                g_assert_cmpuint(reserved_true, >=, requested);
+            if (!truncated_false)
+                g_assert_cmpuint(reserved_false, >=, requested);
+            if (!truncated_true && !truncated_false)
+                g_assert_cmpuint(reserved_false, >=, reserved_true);
 
             if (i < G_N_ELEMENTS(test_data)) {
-                g_assert_cmpuint(reserved_true, ==, test_data[i].reserved_true);
-                g_assert_cmpuint(reserved_false, ==, test_data[i].reserved_false);
+                if (!truncated_true)
+                    g_assert_cmpuint(reserved_true, ==, test_data[i].reserved_true);
+                if (!truncated_false)
+                    g_assert_cmpuint(reserved_false, ==, test_data[i].reserved_false);
             }
 
             /* reserved_false is generally the next power of two - 24. */
             if (reserved_false == G_MAXSIZE)
                 g_assert_cmpuint(requested, >, G_MAXSIZE / 2u - 24u);
-            else {
+            else if (!reserved_false) {
                 g_assert_cmpuint(reserved_false, <=, G_MAXSIZE - 24u);
                 if (reserved_false >= 40) {
                     const gsize _pow2 = reserved_false + 24u;
@@ -800,7 +818,7 @@ test_nm_utils_get_next_realloc_size(void)
             /* reserved_true is generally the next 4k border - 24. */
             if (reserved_true == G_MAXSIZE)
                 g_assert_cmpuint(requested, >, G_MAXSIZE - 0x1000u - 24u);
-            else {
+            else if (!truncated_true) {
                 g_assert_cmpuint(reserved_true, <=, G_MAXSIZE - 24u);
                 if (reserved_true > 8168u) {
                     const gsize page_border = reserved_true + 24u;
@@ -951,10 +969,10 @@ again:
         else
             g_assert(!data);
 
-        g_assert(_nm_utils_strv_cmp_n((const char *const *) strv->pdata,
-                                      strv->len,
-                                      (const char *const *) strv2->pdata,
-                                      strv2->len)
+        g_assert(nm_utils_strv_cmp_n((const char *const *) strv->pdata,
+                                     strv->len,
+                                     (const char *const *) strv2->pdata,
+                                     strv2->len)
                  == 0);
     }
 }
@@ -1050,7 +1068,7 @@ test_strv_dup_packed(void)
             g_assert(strv_cpy);
         g_assert(NM_PTRARRAY_LEN(strv_cpy) == strv_len);
         if (strv_cpy)
-            g_assert(_nm_utils_strv_equal((char **) strv_cpy, (char **) strv_src));
+            g_assert(nm_utils_strv_equal(strv_cpy, strv_src));
     }
 }
 
@@ -1189,8 +1207,8 @@ test_utils_hashtable_cmp(void)
             }
 
             g_assert(nm_utils_hashtable_same_keys(h1, h2));
-            g_assert(nm_utils_hashtable_equal(h1, h2, NULL, NULL));
-            g_assert(nm_utils_hashtable_equal(h1, h2, func_val_cmp, NULL));
+            g_assert(nm_utils_hashtable_cmp_equal(h1, h2, NULL, NULL));
+            g_assert(nm_utils_hashtable_cmp_equal(h1, h2, func_val_cmp, NULL));
             g_assert(nm_utils_hashtable_cmp(h1, h2, FALSE, func_key_cmp, NULL, NULL) == 0);
             g_assert(nm_utils_hashtable_cmp(h1, h2, TRUE, func_key_cmp, NULL, NULL) == 0);
             g_assert(nm_utils_hashtable_cmp(h1, h2, FALSE, func_key_cmp, func_val_cmp, NULL) == 0);
@@ -1220,16 +1238,16 @@ again:
 
             if (has_same_keys) {
                 g_assert(nm_utils_hashtable_same_keys(h1, h2));
-                g_assert(nm_utils_hashtable_equal(h1, h2, NULL, NULL));
+                g_assert(nm_utils_hashtable_cmp_equal(h1, h2, NULL, NULL));
                 g_assert(nm_utils_hashtable_cmp(h1, h2, FALSE, func_key_cmp, NULL, NULL) == 0);
                 g_assert(nm_utils_hashtable_cmp(h1, h2, TRUE, func_key_cmp, NULL, NULL) == 0);
             } else {
                 g_assert(!nm_utils_hashtable_same_keys(h1, h2));
-                g_assert(!nm_utils_hashtable_equal(h1, h2, NULL, NULL));
+                g_assert(!nm_utils_hashtable_cmp_equal(h1, h2, NULL, NULL));
                 g_assert(nm_utils_hashtable_cmp(h1, h2, FALSE, func_key_cmp, NULL, NULL) != 0);
                 g_assert(nm_utils_hashtable_cmp(h1, h2, TRUE, func_key_cmp, NULL, NULL) != 0);
             }
-            g_assert(!nm_utils_hashtable_equal(h1, h2, func_val_cmp, NULL));
+            g_assert(!nm_utils_hashtable_cmp_equal(h1, h2, func_val_cmp, NULL));
             g_assert(nm_utils_hashtable_cmp(h1, h2, FALSE, func_key_cmp, func_val_cmp, NULL) != 0);
             g_assert(nm_utils_hashtable_cmp(h1, h2, TRUE, func_key_cmp, func_val_cmp, NULL) != 0);
         }