diff options
author | Thomas Haller <thaller@redhat.com> | 2024-08-22 11:17:50 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2024-08-22 11:32:38 (GMT) |
commit | d94a3e81e0a6eafc06f182e49d5124a3bffe2bc3 (patch) | |
tree | 241e10e2cec9c525f86a5ffdf9535c7f542c5c5e | |
parent | 798278eabc5111588df8024a22df2644ca26ab31 (diff) | |
download | libnl-d94a3e81e0a6eafc06f182e49d5124a3bffe2bc3.zip libnl-d94a3e81e0a6eafc06f182e49d5124a3bffe2bc3.tar.gz libnl-d94a3e81e0a6eafc06f182e49d5124a3bffe2bc3.tar.bz2 |
tests: move definition of asserts in "tests/nl-test-util.h"
-rw-r--r-- | tests/nl-test-util.h | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/tests/nl-test-util.h b/tests/nl-test-util.h index b751cc5..dab934d 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(expr) \ + ({ \ + typeof(expr) _expr = (expr); \ + \ + if (!_expr) { \ + ck_assert_msg(0, "assert(%s) failed", #expr); \ + } \ + _expr; \ + }) + +#define _nltst_assert_errno(expr) \ + do { \ + if (expr) { \ + } else { \ + const int _errno = (errno); \ + \ + ck_assert_msg(0, "assert(%s) failed (errno=%d, %s)", \ + #expr, _errno, strerror(_errno)); \ + } \ + } while (0) + +#define _nltst_assert_retcode(expr) \ + do { \ + const int _r = (expr); \ + \ + if (_r < 0) { \ + ck_assert_msg( \ + 0, "command(%s) failed with return code %d", \ + #expr, _r); \ + } \ + if (_r > 0) { \ + ck_assert_msg( \ + 0, \ + "command(%s) has unexpected positive return code %d", \ + #expr, _r); \ + } \ + } while (0) + +/*****************************************************************************/ + #define __nltst_assert_nonnull(uniq, x) \ ({ \ typeof(x) _NL_UNIQ_T(_x, uniq) = (x); \ @@ -127,44 +167,6 @@ static inline bool _nltst_rand_bool(void) /*****************************************************************************/ -#define _nltst_assert(expr) \ - ({ \ - typeof(expr) _expr = (expr); \ - \ - if (!_expr) { \ - ck_assert_msg(0, "assert(%s) failed", #expr); \ - } \ - _expr; \ - }) - -#define _nltst_assert_errno(expr) \ - do { \ - if (expr) { \ - } else { \ - const int _errno = (errno); \ - \ - ck_assert_msg(0, "assert(%s) failed (errno=%d, %s)", \ - #expr, _errno, strerror(_errno)); \ - } \ - } while (0) - -#define _nltst_assert_retcode(expr) \ - do { \ - const int _r = (expr); \ - \ - if (_r < 0) { \ - ck_assert_msg( \ - 0, "command(%s) failed with return code %d", \ - #expr, _r); \ - } \ - if (_r > 0) { \ - ck_assert_msg( \ - 0, \ - "command(%s) has unexpected positive return code %d", \ - #expr, _r); \ - } \ - } while (0) - #define _nltst_close(fd) \ do { \ int _r; \ |