]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-test: test-common: Add test_assert_strcmp_idx macro
authorMarkus Valentin <markus.valentin@open-xchange.com>
Wed, 1 Apr 2020 08:42:56 +0000 (10:42 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 24 Apr 2020 12:00:22 +0000 (12:00 +0000)
This change allows to use test_assert_strcmp_idx to identify failing
strcmp tests when running a barrage of tests as in loop.

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

index 2cae8714e37a54763b5b6b4a07331246f7aac0af..59bd55937b7682b0e0ad4aed9370ee76a0ba2186 100644 (file)
@@ -51,10 +51,14 @@ void test_assert_failed_idx(const char *code, const char *file, unsigned int lin
        test_success = FALSE;
 }
 
-void test_assert_failed_strcmp(const char *code, const char *file, unsigned int line,
-                               const char * src, const char * dst)
+void test_assert_failed_strcmp_idx(const char *code, const char *file, unsigned int line,
+                                  const char * src, const char * dst, long long i)
 {
-       printf("%s: Assert(#%u) failed: %s\n", file, line, code);
+       printf("%s:%u: Assert", file, line);
+       if (i == LLONG_MIN)
+               printf(" failed: %s\n", code);
+       else
+               printf("(#%lld) failed: %s\n", i, code);
        if (src != NULL)
                printf("        \"%s\" != ", src);
        else
index 88bd7bace81a7f914a7f18e2ca72d3e064f4997b..1f1318fe6cf83281ce16f6dbddab5452665dfcfa 100644 (file)
@@ -29,13 +29,21 @@ void test_begin(const char *name);
  * in strcmp().
  */
 #define test_assert_strcmp(s1, s2) STMT_START { \
-               if ((null_strcmp(s1,s2) != 0)) test_assert_failed_strcmp("strcmp(" #s1 ","  #s2 ")", __FILE__, __LINE__, s1, s2); \
+               test_assert_strcmp_idx(s1, s2, LLONG_MIN); \
+       } STMT_END
+
+/* Same as test_assert_strcmp expect that it takes an additional i as input.
+ * When i is greater than or equals 0 it is used to identify the barrage of
+ * tests failed like in test_assert_idx.
+*/
+#define test_assert_strcmp_idx(s1, s2, i) STMT_START { \
+               if ((null_strcmp(s1,s2) != 0)) test_assert_failed_strcmp_idx("strcmp(" #s1 ","  #s2 ")", __FILE__, __LINE__, s1, s2, i); \
        } 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(const char *code, const char *file, unsigned int line,
-                               const char * src, const char * dst);
+void test_assert_failed_strcmp_idx(const char *code, const char *file, unsigned int line,
+                                  const char * src, const char * dst, 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);