]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Use function pointers to test generic return_* helper functions
authorTobias Brunner <tobias@strongswan.org>
Mon, 15 Jan 2024 12:39:32 +0000 (13:39 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 16 Jan 2024 10:00:29 +0000 (11:00 +0100)
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

index 7aa20f27c9137571a3917e028b925cb8eff349a3..e4463f2d007a2069811fe74c2c8c733a7b159b80 100644 (file)
@@ -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