summary refs log tree commit diff
path: root/src/libnm-glib-aux/nm-test-utils.h
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2023-08-09 21:55:35 +0200
committerMichael Biebl <biebl@debian.org>2023-08-09 21:55:35 +0200
commit05e4a733f2141995181a551854d5df929f084adf (patch)
tree83bb937740a6667525ba0df046748ecaa829c269 /src/libnm-glib-aux/nm-test-utils.h
parent14b0f3a9dc9ea90d60a3b057350fd4d637dc021a (diff)
New upstream version 1.44.0 upstream/1.44.0
Diffstat (limited to 'src/libnm-glib-aux/nm-test-utils.h')
-rw-r--r--src/libnm-glib-aux/nm-test-utils.h53
1 files changed, 50 insertions, 3 deletions
diff --git a/src/libnm-glib-aux/nm-test-utils.h b/src/libnm-glib-aux/nm-test-utils.h
index b65818e0..de6fd0f1 100644
--- a/src/libnm-glib-aux/nm-test-utils.h
+++ b/src/libnm-glib-aux/nm-test-utils.h
@@ -203,6 +203,54 @@
     }                                                             \
     G_STMT_END
 
+#define nmtst_assert_cmpmem(m1, l1, m2, l2)                                                     \
+    G_STMT_START                                                                                \
+    {                                                                                           \
+        const guint8 *const _m1 = (gpointer) (m1);                                              \
+        const guint8 *const _m2 = (gpointer) (m2);                                              \
+        const gsize         _l1 = (l1);                                                         \
+        const gsize         _l2 = (l2);                                                         \
+                                                                                                \
+        /* This is like g_assert_cmpmem(), however on failure it actually
+         * prints the compared buffer contents, which is useful for debugging
+         * the test failure. */                       \
+                                                                                                \
+        g_assert(_l1 == 0 || _m1);                                                              \
+        g_assert(_l2 == 0 || _m2);                                                              \
+                                                                                                \
+        if (_l1 != _l2 || (_l1 > 0 && memcmp(_m1, _m2, _l1) != 0)) {                            \
+            gs_free char *_s1 = NULL;                                                           \
+            gs_free char *_s2 = NULL;                                                           \
+                                                                                                \
+            g_error(                                                                            \
+                "ERROR: %s:%d : buffer [\"%s\" (%s, %zu bytes)] differs from [\"%s\" (%s, %zu " \
+                "bytes)]:\n"                                                                    \
+                "   a=[ \"%s\" ]\n"                                                             \
+                "   b=[ \"%s\" ]\n",                                                            \
+                __FILE__,                                                                       \
+                (int) __LINE__,                                                                 \
+                #m1,                                                                            \
+                #l1,                                                                            \
+                _l1,                                                                            \
+                #m2,                                                                            \
+                #l2,                                                                            \
+                _l2,                                                                            \
+                (_s1 = nm_utils_buf_utf8safe_escape_cp(                                         \
+                     _m1,                                                                       \
+                     _l1,                                                                       \
+                     NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL                                    \
+                         | NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_DOUBLE_QUOTE))                    \
+                    ?: "",                                                                      \
+                (_s2 = nm_utils_buf_utf8safe_escape_cp(                                         \
+                     _m2,                                                                       \
+                     _l2,                                                                       \
+                     NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL                                    \
+                         | NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_DOUBLE_QUOTE))                    \
+                    ?: "");                                                                     \
+        }                                                                                       \
+    }                                                                                           \
+    G_STMT_END
+
 /*****************************************************************************/
 
 /* Our nm-error error numbers use negative values to signal failure.
@@ -1249,7 +1297,7 @@ nmtst_stable_rand(guint64 seed, gpointer buf, gsize len)
 
 /**
  * nmtst_get_rand_word_length:
- * @rand: (allow-none): #GRand instance or %NULL to use the singleton.
+ * @rand: (nullable): #GRand instance or %NULL to use the singleton.
  *
  * Returns: a random integer >= 0, that most frequently is somewhere between
  * 0 and 16, but (with decreasing) probability, it can be larger. This can
@@ -2839,8 +2887,7 @@ _nmtst_variant_new_vardict(int dummy, ...)
     G_STMT_END
 #else
 #define _nmtst_assert_variant_bytestring_cmp_str(_ptr, _ptr2, _len) \
-    G_STMT_START                                                    \
-    {}                                                              \
+    G_STMT_START {}                                                 \
     G_STMT_END
 #endif