From 09cb1a7d0825394a1b499adf8e697026c8666448 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 18 Feb 2021 14:23:50 +0200 Subject: [PATCH] lib-test: Add test_assert_ucmp[_idx]() These are the unsigned versions of test_assert_cmp*() --- src/lib-test/test-common.c | 15 +++++++++++++++ src/lib-test/test-common.h | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/lib-test/test-common.c b/src/lib-test/test-common.c index 484bee30f0..2b60fcc9e9 100644 --- a/src/lib-test/test-common.c +++ b/src/lib-test/test-common.c @@ -88,6 +88,21 @@ void test_assert_failed_cmp_intmax_idx(const char *code, const char *file, test_success = FALSE; } +void test_assert_failed_ucmp_intmax_idx(const char *code, const char *file, + unsigned int line, + uintmax_t src, uintmax_t dst, + const char *op, long long i) +{ + printf("%s:%u: Assert", file, line); + if (i == LLONG_MIN) + printf(" failed: %s\n", code); + else + printf("(#%lld) failed: %s\n", i, code); + printf(" %ju %s %ju is not true\n", src, op, dst); + fflush(stdout); + test_success = FALSE; +} + #ifdef DEBUG #include "randgen.h" static void diff --git a/src/lib-test/test-common.h b/src/lib-test/test-common.h index ae8cbffba6..5628250da0 100644 --- a/src/lib-test/test-common.h +++ b/src/lib-test/test-common.h @@ -56,6 +56,18 @@ void test_begin(const char *name); #_op, _idx); \ } STMT_END +#define test_assert_ucmp(_value1, _op, _value2) \ + test_assert_ucmp_idx(_value1, _op, _value2, LLONG_MIN) +#define test_assert_ucmp_idx(_value1, _op, _value2, _idx) STMT_START { \ + uintmax_t _temp_value1 = (_value1); \ + uintmax_t _temp_value2 = (_value2); \ + if (!(_value1 _op _value2)) \ + test_assert_failedu_cmp_intmax_idx( \ + #_value1 " " #_op " " #_value2, \ + __FILE__, __LINE__, _temp_value1, _temp_value2, \ + #_op, _idx); \ + } STMT_END + void test_assert_failed(const char *code, const char *file, unsigned int line); void test_assert_failed_idx(const char *code, const char *file, unsigned int line, long long i); void test_assert_failed_strcmp_idx(const char *code, const char *file, unsigned int line, @@ -64,6 +76,10 @@ void test_assert_failed_cmp_intmax_idx(const char *code, const char *file, unsigned int line, intmax_t src, intmax_t dst, const char *op, long long i); +void test_assert_failed_ucmp_intmax_idx(const char *code, const char *file, + unsigned int line, + uintmax_t src, uintmax_t dst, + const char *op, long long i); bool test_has_failed(void); /* If you're testing nasty cases which you want to warn, surround the noisy op with these */ void test_expect_errors(unsigned int expected); -- 2.47.3