From d466e7670263a765ba47adf07240391b365b03cf Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 13 Apr 2024 08:19:05 +0200 Subject: [PATCH] Factorize common test function --- tests/except-array.c | 19 +------------------ tests/except-list.c | 17 ----------------- tests/test-obj-except.h | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 35 deletions(-) diff --git a/tests/except-array.c b/tests/except-array.c index 38c81338..360ee05b 100644 --- a/tests/except-array.c +++ b/tests/except-array.c @@ -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); } diff --git a/tests/except-list.c b/tests/except-list.c index b8b2f66a..60b3b92e 100644 --- a/tests/except-list.c +++ b/tests/except-list.c @@ -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); diff --git a/tests/test-obj-except.h b/tests/test-obj-except.h index bd309e06..064dac33 100644 --- a/tests/test-obj-except.h +++ b/tests/test-obj-except.h @@ -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