From 52d618989289f64dcd519608d55b94310cf3a647 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 15 Jan 2024 13:39:32 +0100 Subject: [PATCH] unit-tests: Use function pointers to test generic return_* helper functions These functions are declared without arguments, passing arguments to them causes warnings such as the following with newer compilers: passing arguments to 'return_null' without a prototype is deprecated in all versions of C and is not supported in C2x [-Werror,-Wdeprecated-non-prototype] We only use them via function pointers, which doesn't trigger any warnings and hopefully continues to work. --- src/libstrongswan/tests/suites/test_utils.c | 23 +++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/libstrongswan/tests/suites/test_utils.c b/src/libstrongswan/tests/suites/test_utils.c index 7aa20f27c9..e4463f2d00 100644 --- a/src/libstrongswan/tests/suites/test_utils.c +++ b/src/libstrongswan/tests/suites/test_utils.c @@ -54,24 +54,35 @@ END_TEST START_TEST(test_return_functions) { + void *(*test_ptr)(char*,int,void*,int,char*); + bool (*test_bool)(char*,int,void*,int,char*); + status_t (*test_status)(char*,int,void*,int,char*); + void (*test_void)(char*,int,void*,int,char*); + ck_assert(return_null() == NULL); - ck_assert(return_null("asdf", 5, NULL, 1, "qwer") == NULL); + test_ptr = (void*)return_null; + ck_assert(test_ptr("asdf", 5, NULL, 1, "qwer") == NULL); ck_assert(return_true() == TRUE); - ck_assert(return_true("asdf", 5, NULL, 1, "qwer") == TRUE); + test_bool = (void*)return_true; + ck_assert(test_bool("asdf", 5, NULL, 1, "qwer") == TRUE); ck_assert(return_false() == FALSE); - ck_assert(return_false("asdf", 5, NULL, 1, "qwer") == FALSE); + test_bool = (void*)return_false; + ck_assert(test_bool("asdf", 5, NULL, 1, "qwer") == FALSE); ck_assert(return_failed() == FAILED); - ck_assert(return_failed("asdf", 5, NULL, 1, "qwer") == FAILED); + test_status = (void*)return_failed; + ck_assert(test_status("asdf", 5, NULL, 1, "qwer") == FAILED); ck_assert(return_success() == SUCCESS); - ck_assert(return_success("asdf", 5, NULL, 1, "qwer") == SUCCESS); + test_status = (void*)return_success; + ck_assert(test_status("asdf", 5, NULL, 1, "qwer") == SUCCESS); /* just make sure this works */ nop(); - nop("asdf", 5, NULL, 1, "qwer"); + test_void = (void*)nop; + test_void("asdf", 5, NULL, 1, "qwer"); } END_TEST -- 2.47.2