summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2024-05-17 14:41:00 (GMT)
committerThomas Haller <thaller@redhat.com>2024-05-17 15:52:52 (GMT)
commit774863b4738a7e9af7bb82ca23011937e36538eb (patch)
treed8c52b4ab588c8b8866ba703e69cbd7f3930851c
parent45a10f9613f59fed9360935192ee6c34e74afeff (diff)
downloadlibnl-774863b4738a7e9af7bb82ca23011937e36538eb.zip
libnl-774863b4738a7e9af7bb82ca23011937e36538eb.tar.gz
libnl-774863b4738a7e9af7bb82ca23011937e36538eb.tar.bz2
tests: add helper functions for tests
-rw-r--r--tests/nl-test-util.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/nl-test-util.h b/tests/nl-test-util.h
index 94e265c..028a0df 100644
--- a/tests/nl-test-util.h
+++ b/tests/nl-test-util.h
@@ -51,6 +51,46 @@ _NL_AUTO_DEFINE_FCN_TYPED0(char **, _nltst_auto_strfreev_fcn, _nltst_strfreev);
/*****************************************************************************/
+#define __nltst_assert_nonnull(uniq, x) \
+ ({ \
+ typeof(x) _NL_UNIQ_T(_x, uniq) = (x); \
+ \
+ ck_assert_ptr_nonnull(_NL_UNIQ_T(_x, uniq)); \
+ \
+ _NL_UNIQ_T(_x, uniq); \
+ })
+
+#define _nltst_assert_nonnull(x) __nltst_assert_nonnull(_NL_UNIQ, x)
+
+static inline char *_nltst_strdup(const char *str)
+{
+ return str ? _nltst_assert_nonnull(strdup(str)) : NULL;
+}
+
+/*****************************************************************************/
+
+#define __nltst_sprintf_arr(uniq, arr, fmt, ...) \
+ ({ \
+ char *const _NL_UNIQ_T(arr, uniq) = (arr); \
+ int _NL_UNIQ_T(c, uniq); \
+ \
+ _NL_STATIC_ASSERT(sizeof(arr) > \
+ sizeof(_NL_UNIQ_T(arr, uniq))); \
+ \
+ _NL_UNIQ_T(c, uniq) = snprintf(_NL_UNIQ_T(arr, uniq), \
+ sizeof(arr), fmt, \
+ ##__VA_ARGS__); \
+ \
+ ck_assert_int_lt(_NL_UNIQ_T(c, uniq), sizeof(arr)); \
+ \
+ _NL_UNIQ_T(arr, uniq); \
+ })
+
+#define _nltst_sprintf_arr(arr, fmt, ...) \
+ __nltst_sprintf_arr(_NL_UNIQ, arr, fmt, ##__VA_ARGS__)
+
+/*****************************************************************************/
+
void _nltst_get_urandom(void *ptr, size_t len);
uint32_t _nltst_rand_u32(void);
@@ -368,6 +408,10 @@ void nltst_netns_leave(struct nltst_netns *nsdata);
/*****************************************************************************/
+#define _nltst_system(command) _nltst_assert_retcode(system(command))
+
+/*****************************************************************************/
+
void _nltst_object_identical(const void *a, const void *b);
char *_nltst_object_to_string(const struct nl_object *obj);