mirror of
https://github.com/transmission/transmission
synced 2025-02-28 00:35:31 +00:00
Add generic check_bool
, extend check
to be more informative (libtest)
This commit is contained in:
parent
b1b5a577cf
commit
2a7cf67913
2 changed files with 36 additions and 7 deletions
|
@ -50,13 +50,23 @@ bool should_print(bool pass)
|
|||
#endif
|
||||
}
|
||||
|
||||
bool check_condition_impl(char const* file, int line, bool condition)
|
||||
bool libtest_check(char const* file, int line, bool pass, bool condition, char const* condition_str)
|
||||
{
|
||||
bool const pass = condition;
|
||||
|
||||
if (should_print(pass))
|
||||
{
|
||||
fprintf(stderr, "%s %s:%d\n", pass ? "PASS" : "FAIL", file, line);
|
||||
fprintf(stderr, "%s %s:%d: %s (%s)\n", pass ? "PASS" : "FAIL", file, line, condition_str, condition ? "true": "false");
|
||||
}
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
bool libtest_check_bool(char const* file, int line, bool pass, bool lhs, bool rhs, char const* lhs_str, char const* op_str,
|
||||
char const* rhs_str)
|
||||
{
|
||||
if (should_print(pass))
|
||||
{
|
||||
fprintf(stderr, "%s %s:%d: %s %s %s (%s %s %s)\n", pass ? "PASS" : "FAIL", file, line, lhs_str, op_str, rhs_str,
|
||||
lhs ? "true" : "false", op_str, rhs ? "true" : "false");
|
||||
}
|
||||
|
||||
return pass;
|
||||
|
|
|
@ -22,8 +22,9 @@ extern bool verbose;
|
|||
|
||||
bool should_print(bool pass);
|
||||
|
||||
bool check_condition_impl(char const* file, int line, bool condition);
|
||||
|
||||
bool libtest_check(char const* file, int line, bool pass, bool condition, char const* condition_str);
|
||||
bool libtest_check_bool(char const* file, int line, bool pass, bool lhs, bool rhs, char const* lhs_str, char const* op_str,
|
||||
char const* rhs_str);
|
||||
bool libtest_check_str(char const* file, int line, bool pass, char const* lhs, char const* rhs, char const* lhs_str,
|
||||
char const* op_str, char const* rhs_str);
|
||||
bool libtest_check_int(char const* file, int line, bool pass, intmax_t lhs, intmax_t rhs, char const* lhs_str,
|
||||
|
@ -42,7 +43,25 @@ bool libtest_check_ptr(char const* file, int line, bool pass, void const* lhs, v
|
|||
{ \
|
||||
++current_test; \
|
||||
\
|
||||
if (!check_condition_impl(__FILE__, __LINE__, (condition))) \
|
||||
bool const check_result = (condition); \
|
||||
\
|
||||
if (!libtest_check(__FILE__, __LINE__, check_result, check_result, #condition)) \
|
||||
{ \
|
||||
return current_test; \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define check_bool(lhs, op, rhs) \
|
||||
do \
|
||||
{ \
|
||||
++current_test; \
|
||||
\
|
||||
bool const check_bool_lhs = (lhs); \
|
||||
bool const check_bool_rhs = (rhs); \
|
||||
\
|
||||
if (!libtest_check_bool(__FILE__, __LINE__, check_bool_lhs op check_bool_rhs, check_bool_lhs, check_bool_rhs, #lhs, \
|
||||
#op, #rhs)) \
|
||||
{ \
|
||||
return current_test; \
|
||||
} \
|
||||
|
|
Loading…
Reference in a new issue