]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-test: add test_assert_failed_strcmp to expose strings.
authorBaofeng Wang <baofeng.wang@dovecot.fi>
Tue, 7 Jun 2016 13:01:03 +0000 (16:01 +0300)
committerGitLab <gitlab@git.dovecot.net>
Tue, 21 Jun 2016 07:44:18 +0000 (10:44 +0300)
the macro is used to facilitate any test to show string comparision
contents when they doesn't match.

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

index 04e61197acc474a6631e079278e412da2abf08bf..270e0effff40e18a808a8a1c94fcaa97dec03c65 100644 (file)
@@ -179,6 +179,15 @@ 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)
+{
+       printf("%s: Assert(#%u) failed: %s\n", file, line, code);
+       printf("        \"%s\" != \"%s\"\n", src, dst);
+       fflush(stdout);
+       test_success = FALSE;
+}
+
 static void
 test_dump_rand_state(void)
 {
index cbb02100738570fc24039814ae83d12c9eb39478..fc62afb52da2e6cad7b3c3b394da9af57334f269 100644 (file)
@@ -17,8 +17,17 @@ void test_begin(const char *name);
 #define test_assert_idx(code, i) STMT_START { \
                if (!(code)) test_assert_failed_idx(#code, __FILE__, __LINE__, i); \
        } STMT_END
+/* Additional parameters are s1 (source) and s2 (destination) string
+ * in strcmp().
+ */
+#define test_assert_strcmp(s1, s2) STMT_START { \
+               if ((strcmp(s1,s2) != 0)) test_assert_failed_strcmp("strcmp(" #s1 ","  #s2 ")", __FILE__, __LINE__, s1, s2); \
+       } 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);
 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);