]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-test: Add test_assert_ucmp[_idx]()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 18 Feb 2021 12:23:50 +0000 (14:23 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 19 Feb 2021 07:01:01 +0000 (07:01 +0000)
These are the unsigned versions of test_assert_cmp*()

src/lib-test/test-common.c
src/lib-test/test-common.h

index 484bee30f0441976c5f5c562d4aefeeb0802c868..2b60fcc9e98628d4d37857bcf20efc4baa5e68fe 100644 (file)
@@ -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
index ae8cbffba6c447eceee4d55fd5183951558d9f84..5628250da0d2026addadda43d287414e9619ebd5 100644 (file)
@@ -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);