mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
Transform check_ptr_eq into generic check_ptr (libtest)
This commit is contained in:
@@ -101,20 +101,13 @@ bool libtest_check_uint(char const* file, int line, bool pass, uintmax_t lhs, ui
|
||||
return pass;
|
||||
}
|
||||
|
||||
bool check_ptr_eq_impl(char const* file, int line, void const* expected, void const* actual)
|
||||
bool libtest_check_ptr(char const* file, int line, bool pass, void const* lhs, void const* rhs, char const* lhs_str,
|
||||
char const* op_str, char const* rhs_str)
|
||||
{
|
||||
bool const pass = expected == actual;
|
||||
|
||||
if (should_print(pass))
|
||||
{
|
||||
if (pass)
|
||||
{
|
||||
fprintf(stderr, "PASS %s:%d\n", file, line);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "FAIL %s:%d, expected \"%p\", got \"%p\"\n", file, line, expected, actual);
|
||||
}
|
||||
fprintf(stderr, "%s %s:%d: %s %s %s (%p %s %p)\n", pass ? "PASS" : "FAIL", file, line, lhs_str, op_str, rhs_str, lhs,
|
||||
op_str, rhs);
|
||||
}
|
||||
|
||||
return pass;
|
||||
|
||||
@@ -23,7 +23,6 @@ extern bool verbose;
|
||||
bool should_print(bool pass);
|
||||
|
||||
bool check_condition_impl(char const* file, int line, bool condition);
|
||||
bool check_ptr_eq_impl(char const* file, int line, void const* expected, void const* actual);
|
||||
|
||||
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);
|
||||
@@ -31,6 +30,8 @@ bool libtest_check_int(char const* file, int line, bool pass, intmax_t lhs, intm
|
||||
char const* op_str, char const* rhs_str);
|
||||
bool libtest_check_uint(char const* file, int line, bool pass, uintmax_t lhs, uintmax_t rhs, char const* lhs_str,
|
||||
char const* op_str, char const* rhs_str);
|
||||
bool libtest_check_ptr(char const* file, int line, bool pass, void const* lhs, void const* rhs, char const* lhs_str,
|
||||
char const* op_str, char const* rhs_str);
|
||||
|
||||
/***
|
||||
****
|
||||
@@ -96,12 +97,16 @@ bool libtest_check_uint(char const* file, int line, bool pass, uintmax_t lhs, ui
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define check_ptr_eq(expected, actual) \
|
||||
#define check_ptr(lhs, op, rhs) \
|
||||
do \
|
||||
{ \
|
||||
++current_test; \
|
||||
\
|
||||
if (!check_ptr_eq_impl(__FILE__, __LINE__, (expected), (actual))) \
|
||||
void const* const check_ptr_lhs = (lhs); \
|
||||
void const* const check_ptr_rhs = (rhs); \
|
||||
\
|
||||
if (!libtest_check_ptr(__FILE__, __LINE__, check_ptr_lhs op check_ptr_rhs, check_ptr_lhs, check_ptr_rhs, #lhs, #op, \
|
||||
#rhs)) \
|
||||
{ \
|
||||
return current_test; \
|
||||
} \
|
||||
|
||||
@@ -144,8 +144,8 @@ static int test_initial_scan(void)
|
||||
check(wd != NULL);
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(NULL, wd_data.dir);
|
||||
check_ptr_eq(NULL, wd_data.name);
|
||||
check_ptr(wd_data.dir, ==, NULL);
|
||||
check_ptr(wd_data.name, ==, NULL);
|
||||
|
||||
tr_watchdir_free(wd);
|
||||
reset_callback_data(&wd_data, TR_WATCHDIR_ACCEPT);
|
||||
@@ -161,7 +161,7 @@ static int test_initial_scan(void)
|
||||
check(wd != NULL);
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(wd, wd_data.dir);
|
||||
check_ptr(wd_data.dir, ==, wd);
|
||||
check_str(wd_data.name, ==, "test");
|
||||
|
||||
tr_watchdir_free(wd);
|
||||
@@ -191,28 +191,28 @@ static int test_watch(void)
|
||||
check(wd != NULL);
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(NULL, wd_data.dir);
|
||||
check_ptr_eq(NULL, wd_data.name);
|
||||
check_ptr(wd_data.dir, ==, NULL);
|
||||
check_ptr(wd_data.name, ==, NULL);
|
||||
|
||||
create_file(test_dir, "test");
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(wd, wd_data.dir);
|
||||
check_ptr(wd_data.dir, ==, wd);
|
||||
check_str(wd_data.name, ==, "test");
|
||||
|
||||
reset_callback_data(&wd_data, TR_WATCHDIR_IGNORE);
|
||||
create_file(test_dir, "test2");
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(wd, wd_data.dir);
|
||||
check_ptr(wd_data.dir, ==, wd);
|
||||
check_str(wd_data.name, ==, "test2");
|
||||
|
||||
reset_callback_data(&wd_data, TR_WATCHDIR_IGNORE);
|
||||
create_dir(test_dir, "test3");
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(NULL, wd_data.dir);
|
||||
check_ptr_eq(NULL, wd_data.name);
|
||||
check_ptr(wd_data.dir, ==, NULL);
|
||||
check_ptr(wd_data.name, ==, NULL);
|
||||
|
||||
tr_watchdir_free(wd);
|
||||
reset_callback_data(&wd_data, TR_WATCHDIR_ACCEPT);
|
||||
@@ -251,27 +251,27 @@ static int test_watch_two_dirs(void)
|
||||
check(wd2 != NULL);
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(NULL, wd1_data.dir);
|
||||
check_ptr_eq(NULL, wd1_data.name);
|
||||
check_ptr_eq(NULL, wd2_data.dir);
|
||||
check_ptr_eq(NULL, wd2_data.name);
|
||||
check_ptr(wd1_data.dir, ==, NULL);
|
||||
check_ptr(wd1_data.name, ==, NULL);
|
||||
check_ptr(wd2_data.dir, ==, NULL);
|
||||
check_ptr(wd2_data.name, ==, NULL);
|
||||
|
||||
create_file(dir1, "test");
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(wd1, wd1_data.dir);
|
||||
check_ptr(wd1_data.dir, ==, wd1);
|
||||
check_str(wd1_data.name, ==, "test");
|
||||
check_ptr_eq(NULL, wd2_data.dir);
|
||||
check_ptr_eq(NULL, wd2_data.name);
|
||||
check_ptr(wd2_data.dir, ==, NULL);
|
||||
check_ptr(wd2_data.name, ==, NULL);
|
||||
|
||||
reset_callback_data(&wd1_data, TR_WATCHDIR_ACCEPT);
|
||||
reset_callback_data(&wd2_data, TR_WATCHDIR_ACCEPT);
|
||||
create_file(dir2, "test2");
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(NULL, wd1_data.dir);
|
||||
check_ptr_eq(NULL, wd1_data.name);
|
||||
check_ptr_eq(wd2, wd2_data.dir);
|
||||
check_ptr(wd1_data.dir, ==, NULL);
|
||||
check_ptr(wd1_data.name, ==, NULL);
|
||||
check_ptr(wd2_data.dir, ==, wd2);
|
||||
check_str(wd2_data.name, ==, "test2");
|
||||
|
||||
reset_callback_data(&wd1_data, TR_WATCHDIR_IGNORE);
|
||||
@@ -280,9 +280,9 @@ static int test_watch_two_dirs(void)
|
||||
create_file(dir2, "test4");
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(wd1, wd1_data.dir);
|
||||
check_ptr(wd1_data.dir, ==, wd1);
|
||||
check_str(wd1_data.name, ==, "test3");
|
||||
check_ptr_eq(wd2, wd2_data.dir);
|
||||
check_ptr(wd2_data.dir, ==, wd2);
|
||||
check_str(wd2_data.name, ==, "test4");
|
||||
|
||||
reset_callback_data(&wd1_data, TR_WATCHDIR_ACCEPT);
|
||||
@@ -291,10 +291,10 @@ static int test_watch_two_dirs(void)
|
||||
create_dir(dir2, "test5");
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(wd1, wd1_data.dir);
|
||||
check_ptr(wd1_data.dir, ==, wd1);
|
||||
check_str(wd1_data.name, ==, "test5");
|
||||
check_ptr_eq(NULL, wd2_data.dir);
|
||||
check_ptr_eq(NULL, wd2_data.name);
|
||||
check_ptr(wd2_data.dir, ==, NULL);
|
||||
check_ptr(wd2_data.name, ==, NULL);
|
||||
|
||||
reset_callback_data(&wd1_data, TR_WATCHDIR_ACCEPT);
|
||||
reset_callback_data(&wd2_data, TR_WATCHDIR_ACCEPT);
|
||||
@@ -302,9 +302,9 @@ static int test_watch_two_dirs(void)
|
||||
create_file(dir2, "test6");
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(NULL, wd1_data.dir);
|
||||
check_ptr_eq(NULL, wd1_data.name);
|
||||
check_ptr_eq(wd2, wd2_data.dir);
|
||||
check_ptr(wd1_data.dir, ==, NULL);
|
||||
check_ptr(wd1_data.name, ==, NULL);
|
||||
check_ptr(wd2_data.dir, ==, wd2);
|
||||
check_str(wd2_data.name, ==, "test6");
|
||||
|
||||
reset_callback_data(&wd1_data, TR_WATCHDIR_ACCEPT);
|
||||
@@ -313,10 +313,10 @@ static int test_watch_two_dirs(void)
|
||||
create_dir(dir2, "test7");
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(NULL, wd1_data.dir);
|
||||
check_ptr_eq(NULL, wd1_data.name);
|
||||
check_ptr_eq(NULL, wd2_data.dir);
|
||||
check_ptr_eq(NULL, wd2_data.name);
|
||||
check_ptr(wd1_data.dir, ==, NULL);
|
||||
check_ptr(wd1_data.name, ==, NULL);
|
||||
check_ptr(wd2_data.dir, ==, NULL);
|
||||
check_ptr(wd2_data.name, ==, NULL);
|
||||
|
||||
tr_watchdir_free(wd2);
|
||||
reset_callback_data(&wd2_data, TR_WATCHDIR_ACCEPT);
|
||||
@@ -354,19 +354,19 @@ static int test_retry(void)
|
||||
check(wd != NULL);
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(NULL, wd_data.dir);
|
||||
check_ptr_eq(NULL, wd_data.name);
|
||||
check_ptr(wd_data.dir, ==, NULL);
|
||||
check_ptr(wd_data.name, ==, NULL);
|
||||
|
||||
create_file(test_dir, "test");
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(NULL, wd_data.dir);
|
||||
check_ptr_eq(NULL, wd_data.name);
|
||||
check_ptr(wd_data.dir, ==, NULL);
|
||||
check_ptr(wd_data.name, ==, NULL);
|
||||
|
||||
reset_callback_data(&wd_data, TR_WATCHDIR_ACCEPT);
|
||||
|
||||
process_events();
|
||||
check_ptr_eq(wd, wd_data.dir);
|
||||
check_ptr(wd_data.dir, ==, wd);
|
||||
check_str(wd_data.name, ==, "test");
|
||||
|
||||
tr_watchdir_free(wd);
|
||||
|
||||
Reference in New Issue
Block a user