unit-tests: Pass stringyfied assertion statement as non-format string argument
authorMartin Willi <martin@revosec.ch>
Wed, 15 Apr 2015 10:02:45 +0000 (12:02 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 15 Apr 2015 11:44:40 +0000 (13:44 +0200)
If the assertion contains a modulo (%) operation, test_fail_msg() handles
this as printf() format specifier. Pass the assertion string as argument for
an explicit "%s" in the format string, instead.

src/libstrongswan/tests/test_suite.h

index da57ab4..aedd8c0 100644 (file)
@@ -313,7 +313,7 @@ void test_fail_if_worker_failed();
        test_fail_if_worker_failed(); \
        if (!(x)) \
        { \
-               test_fail_msg(__FILE__, __LINE__, #x); \
+               test_fail_msg(__FILE__, __LINE__, "%s", #x); \
        } \
 })
 
@@ -329,7 +329,7 @@ void test_fail_if_worker_failed();
        test_fail_if_worker_failed(); \
        if (!(x)) \
        { \
-               test_fail_msg(__FILE__, __LINE__, #x ": " fmt, ##__VA_ARGS__); \
+               test_fail_msg(__FILE__, __LINE__, "%s: " fmt, #x, ##__VA_ARGS__); \
        } \
 })
 
@@ -349,7 +349,7 @@ void test_fail_if_worker_failed();
        test_fail_if_worker_failed(); \
        if (x) \
        { \
-               test_fail_msg(__FILE__, __LINE__, #x ": " fmt, ##__VA_ARGS__); \
+               test_fail_msg(__FILE__, __LINE__, "%s : " fmt, #x, ##__VA_ARGS__); \
        } \
 })
 #define fail_unless test_assert_msg