Skip to content

Commit

Permalink
lib-test: add test_assert_failed_strcmp to expose strings.
Browse files Browse the repository at this point in the history
the macro is used to facilitate any test to show string comparision
contents when they doesn't match.
  • Loading branch information
Baofeng Wang authored and sirainen committed Jun 21, 2016
1 parent 9a0dba9 commit 9412c48
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib-test/test-common.c
Expand Up @@ -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)
{
Expand Down
9 changes: 9 additions & 0 deletions src/lib-test/test-common.h
Expand Up @@ -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);
Expand Down

0 comments on commit 9412c48

Please sign in to comment.