diff options
-rw-r--r-- | tests/test_common.c | 14 | ||||
-rw-r--r-- | tests/test_common.h | 11 |
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/test_common.c b/tests/test_common.c index 7e994f36..2ce3a5da 100644 --- a/tests/test_common.c +++ b/tests/test_common.c @@ -147,6 +147,20 @@ int test_succ(int result, return !result; } +int test_fail(int result, + const char *preamble, const char *desc, const char *comment) +{ + if (result != 0) { + print_passed(preamble, desc, comment); + } else { + print_failed(preamble, desc, comment); + fprintf(stderr, + " Didn't expect SUCCESS (0), but got it\n"); + gTestSuccess = 0; + } + return result; +} + int test_true(int result, const char *preamble, const char *desc, const char *comment) { diff --git a/tests/test_common.h b/tests/test_common.h index e0d8ef3b..c3da8805 100644 --- a/tests/test_common.h +++ b/tests/test_common.h @@ -120,6 +120,17 @@ int test_succ(int result, #result " == 0", \ comment) +/* Return 1 if result is not 0 (VB2_SUCCESS or other), else return 1. + * Also update the global gTestSuccess flag if test fails. */ +int test_fail(int result, + const char *preamble, const char *desc, const char *comment); + +#define TEST_FAIL(result, comment) \ + test_fail(result, \ + __FILE__ ":" TOSTRING(__LINE__), \ + #result " != 0", \ + comment) + /* Return 1 if vb2ex_abort() was called, else return 0. * Also update the global gTestSuccess flag if test fails. */ int test_abort(int aborted, |