Skip to content

Commit

Permalink
Factorize common test function
Browse files Browse the repository at this point in the history
  • Loading branch information
P-p-H-d committed Apr 13, 2024
1 parent 9d33c85 commit d466e76
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 35 deletions.
19 changes: 1 addition & 18 deletions tests/except-array.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,8 @@ static void test1(unsigned n)
fclose(f);
}

static void do_test1(void)
{
// Run once to get the number of exceptions point existing in the test service
test_obj_except__trigger_exception = 0;
test1(10);
test_obj_except__final_check();
int count = -test_obj_except__trigger_exception;
assert(count > 0);
// Run once again the test service, and for each registered exception point, throw an exception
for(int i = 1; i <= count; i++) {
test_obj_except__trigger_exception = i;
test1(10);
// Check there is no memory leak
test_obj_except__final_check();
}
}

int main(void)
{
do_test1();
do_test1(test1);
exit(0);
}
17 changes: 0 additions & 17 deletions tests/except-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,6 @@ static void test3(unsigned n)
}
}

static void do_test1(void (*test)(unsigned))
{
// Run once to get the number of exceptions point existing in the test service
test_obj_except__trigger_exception = 0;
test(10);
test_obj_except__final_check();
int count = -test_obj_except__trigger_exception;
assert(count > 0);
// Run once again the test service, and for each registered exception point, throw an exception
for(int i = 1; i <= count; i++) {
test_obj_except__trigger_exception = i;
test(10);
// Check there is no memory leak
test_obj_except__final_check();
}
}

int main(void)
{
do_test1(test1);
Expand Down
17 changes: 17 additions & 0 deletions tests/test-obj-except.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,23 @@ static inline void test_obj_except__str(string_t str, const test_obj_except__t z

#define M_OPL_test_obj_except__t() TEST_OBJ_EXCEPT_OPLIST

static void do_test1(void (*test)(unsigned))
{
// Run once to get the number of exceptions point existing in the test service
test_obj_except__trigger_exception = 0;
test(10);
test_obj_except__final_check();
int count = -test_obj_except__trigger_exception;
assert(count > 0);
// Run once again the test service, and for each registered exception point, throw an exception
for(int i = 1; i <= count; i++) {
test_obj_except__trigger_exception = i;
test(10);
// Check there is no memory leak
test_obj_except__final_check();
}
}

M_END_PROTECTED_CODE

#endif

0 comments on commit d466e76

Please sign in to comment.