Enable warning Wundef
It is better to use "#ifdef" for testing macros instead of "#if"
In header file, "#ifdef DOXYGEN" was used 30 times and "#if DOXYGEN"
23 times. This patch makes it consistent and enable warning Wundef to prevent
this kind of issues.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
diff --git a/cmake/Modules/DefineCompilerFlags.cmake b/cmake/Modules/DefineCompilerFlags.cmake
index 7b65720..4fb0aed 100644
--- a/cmake/Modules/DefineCompilerFlags.cmake
+++ b/cmake/Modules/DefineCompilerFlags.cmake
@@ -13,7 +13,7 @@
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -pedantic-errors")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wshadow -Wmissing-prototypes -Wdeclaration-after-statement")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused -Wfloat-equal -Wpointer-arith -Wwrite-strings -Wformat-security")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-format-attribute")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-format-attribute -Wundef")
# with -fPIC
check_c_compiler_flag("-fPIC" WITH_FPIC)
diff --git a/doc/index.html b/doc/index.html
index 8db0247..5f7c5a7 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -137,7 +137,7 @@
#include <assert.h>
// If unit testing is enabled override assert with mock_assert().
-#if UNIT_TESTING
+#ifdef UNIT_TESTING
extern void mock_assert(const int result, const char* const expression,
const char * const file, const int line);
#undef assert
@@ -285,7 +285,7 @@
<listing>
#include <malloc.h>
-#if UNIT_TESTING
+#ifdef UNIT_TESTING
extern void* _test_malloc(const size_t size, const char* file, const int line);
extern void* _test_calloc(const size_t number_of_elements, const size_t size,
const char* file, const int line);
diff --git a/example/allocate_module.c b/example/allocate_module.c
index 295e10e..3c4fb49 100644
--- a/example/allocate_module.c
+++ b/example/allocate_module.c
@@ -22,7 +22,7 @@
#include <sys/types.h>
#include <stdlib.h>
-#if UNIT_TESTING
+#ifdef UNIT_TESTING
extern void* _test_malloc(const size_t size, const char* file, const int line);
extern void* _test_calloc(const size_t number_of_elements, const size_t size,
const char* file, const int line);
diff --git a/example/assert_module.c b/example/assert_module.c
index bb75aaa..381069b 100644
--- a/example/assert_module.c
+++ b/example/assert_module.c
@@ -18,7 +18,7 @@
#include "assert_module.h"
/* If unit testing is enabled override assert with mock_assert(). */
-#if UNIT_TESTING
+#ifdef UNIT_TESTING
extern void mock_assert(const int result, const char* const expression,
const char * const file, const int line);
#undef assert
diff --git a/example/calculator.c b/example/calculator.c
index 684fb9b..307b551 100644
--- a/example/calculator.c
+++ b/example/calculator.c
@@ -28,7 +28,7 @@
#include <string.h>
/* If this is being built for a unit test. */
-#if UNIT_TESTING
+#ifdef UNIT_TESTING
/* Redirect printf to a function in the test application so it's possible to
* test the standard output. */
diff --git a/include/cmocka.h b/include/cmocka.h
index a3544b7..0047df9 100644
--- a/include/cmocka.h
+++ b/include/cmocka.h
@@ -384,7 +384,7 @@
cast_to_largest_integral_type(check_data), NULL, 0)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value is part of the provided
* array.
@@ -405,7 +405,7 @@
expect_in_set_count(function, parameter, value_array, 1)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value is part of the provided
* array.
@@ -431,7 +431,7 @@
sizeof(value_array) / sizeof((value_array)[0]), count)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value is not part of the
* provided array.
@@ -452,7 +452,7 @@
expect_not_in_set_count(function, parameter, value_array, 1)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value is not part of the
* provided array.
@@ -480,7 +480,7 @@
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check a parameter is inside a numerical range.
* The check would succeed if minimum <= value <= maximum.
@@ -503,7 +503,7 @@
expect_in_range_count(function, parameter, minimum, maximum, 1)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check a parameter is inside a
* numerical range. The check would succeed if minimum <= value <= maximum.
@@ -531,7 +531,7 @@
maximum, count)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check a parameter is outside a numerical range.
* The check would succeed if minimum > value > maximum.
@@ -554,7 +554,7 @@
expect_not_in_range_count(function, parameter, minimum, maximum, 1)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check a parameter is outside a
* numerical range. The check would succeed if minimum > value > maximum.
@@ -583,7 +583,7 @@
minimum, maximum, count)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if a parameter is the given value.
*
@@ -603,7 +603,7 @@
expect_value_count(function, parameter, value, 1)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check if a parameter is the given value.
*
@@ -628,7 +628,7 @@
cast_to_largest_integral_type(value), count)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if a parameter isn't the given value.
*
@@ -648,7 +648,7 @@
expect_not_value_count(function, parameter, value, 1)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check if a parameter isn't the given value.
*
@@ -673,7 +673,7 @@
cast_to_largest_integral_type(value), count)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value is equal to the
* provided string.
@@ -694,7 +694,7 @@
expect_string_count(function, parameter, string, 1)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value is equal to the
* provided string.
@@ -720,7 +720,7 @@
(const char*)(string), count)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value isn't equal to the
* provided string.
@@ -741,7 +741,7 @@
expect_not_string_count(function, parameter, string, 1)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value isn't equal to the
* provided string.
@@ -767,7 +767,7 @@
(const char*)(string), count)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter does match an area of memory.
*
@@ -789,7 +789,7 @@
expect_memory_count(function, parameter, memory, size, 1)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check if the parameter does match an area
* of memory.
@@ -817,7 +817,7 @@
(const void*)(memory), size, count)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter doesn't match an area of
* memory.
@@ -840,7 +840,7 @@
expect_not_memory_count(function, parameter, memory, size, 1)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check if the parameter doesn't match an
* area of memory.
@@ -869,7 +869,7 @@
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to check if a parameter (of any value) has been passed.
*
@@ -887,7 +887,7 @@
expect_any_count(function, parameter, 1)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check if a parameter (of any value) has
* been passed.
@@ -910,7 +910,7 @@
_expect_any(#function, #parameter, __FILE__, __LINE__, count)
#endif
-#if DOXYGEN
+#ifdef DOXYGEN
/**
* @brief Determine whether a function parameter is correct.
*
@@ -1431,7 +1431,7 @@
* @return A pointer to the allocated memory or NULL on error.
*
* @code
- * #if UNIT_TESTING
+ * #ifdef UNIT_TESTING
* extern void* _test_malloc(const size_t size, const char* file, const int line);
*
* #define malloc(size) _test_malloc(size, __FILE__, __LINE__)
@@ -1483,7 +1483,7 @@
#endif
/* Redirect malloc, calloc and free to the unit test allocators. */
-#if UNIT_TESTING
+#ifdef UNIT_TESTING
#define malloc test_malloc
#define calloc test_calloc
#define free test_free
@@ -1524,7 +1524,7 @@
* @param[in] line The line mock_assert() is called.
*
* @code
- * #if UNIT_TESTING
+ * #ifdef UNIT_TESTING
* extern void mock_assert(const int result, const char* const expression,
* const char * const file, const int line);
*
diff --git a/src/cmocka.c b/src/cmocka.c
index b4de262..76cd783 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -1697,7 +1697,7 @@
#ifdef _WIN32
handle_exceptions = !IsDebuggerPresent();
#endif /* _WIN32 */
-#if UNIT_TESTING_DEBUG
+#ifdef UNIT_TESTING_DEBUG
handle_exceptions = 0;
#endif /* UNIT_TESTING_DEBUG */