From: Tobias Brunner Date: Mon, 15 Jan 2024 12:39:32 +0000 (+0100) Subject: unit-tests: Use function pointers to test generic return_* helper functions X-Git-Tag: android-2.5.0~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52d618989289f64dcd519608d55b94310cf3a647;p=thirdparty%2Fstrongswan.git 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. --- 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