@@ -32,6 +32,7 @@
<!-- work around macro confusion -->
<define name="CMSG_FIRSTHDR" value="cmsg_firsthdr" />
<define name="CMSG_NXTHDR" value="cmsg_nxthdr" />
+ <define name="CM_VERSION_INT(a, b, c)" value="((a) << 16 | (b) << 8 | (c))" />
<!-- otherwise a lot of unused variables are shown for enable-small builds -->
<define name="DMSG_ALWAYS_AVAILABLE" value="1" />
<!-- cppcheck understands it directly in format string, but not
@@ -25,19 +25,22 @@
#endif
#include <stdarg.h>
-#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
-#include <setjmp.h>
-#include <stdint.h>
-#ifndef NO_CMOCKA
-#include <cmocka.h>
-#endif
#include "errlevel.h"
#include "error.h"
#include "mock_msg.h"
+#ifndef NO_CMOCKA
+#include <stddef.h>
+#include <setjmp.h>
+#include <stdint.h>
+#include <cmocka.h>
+
+#include "test_common.h"
+#endif
+
msglvl_t x_debug_level = 0; /* Default to (almost) no debugging output */
msglvl_t print_x_debug_level = 0;
@@ -115,7 +118,7 @@
void
assert_failed(const char *filename, int line, const char *condition)
{
- mock_assert(false, condition ? condition : "", filename, line);
+ mock_assert(false, condition ? condition : "", filename, (ovpn_cmocka_line_t)line);
/* Keep compiler happy. Should not happen, mock_assert() does not return */
exit(1);
}
@@ -20,6 +20,9 @@
* with this program; if not, see <https://www.gnu.org/licenses/>.
*/
+#ifndef TEST_COMMON_H
+#define TEST_COMMON_H
+
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
@@ -31,6 +34,7 @@
/* Do we use cmocka < 2.0.0? */
#ifndef HAVE_CMOCKA_VERSION_H
+
#define HAVE_OLD_CMOCKA_API 1
/* compat with various versions of cmocka.h
* Older versions have LargestIntegralType. Newer
@@ -50,6 +54,20 @@
#define cast_ptr_to_cmocka_value(x) (x)
#define assert_int_in_range(value, min, max) assert_in_range((value), (min), (max))
#define assert_uint_in_range(value, min, max) assert_in_range((value), (min), (max))
+
+typedef int ovpn_cmocka_line_t;
+
+#else
+
+#include <cmocka_version.h>
+
+/* handle differences in different 2.x versions */
+#if CMOCKA_VERSION_INT >= CM_VERSION_INT(2, 0, 3)
+typedef size_t ovpn_cmocka_line_t;
+#else
+typedef int ovpn_cmocka_line_t;
+#endif
+
#endif
/**
@@ -97,3 +115,5 @@
snprintf(buf, bufsize, "%s/%s", srcdir, filename);
}
+
+#endif
@@ -256,7 +256,7 @@
if (!mctx || EVP_DigestSignInit_ex(mctx, &pctx, mdname, NULL, NULL, pkey, params) <= 0)
{
- fail_msg("Failed to initialize EVP_DigestSignInit_ex()");
+ fail_msg("%s", "Failed to initialize EVP_DigestSignInit_ex()");
goto done;
}
@@ -266,7 +266,7 @@
if ((sig = test_calloc(1, siglen)) == NULL)
{
- fail_msg("Out of memory");
+ fail_msg("%s", "Out of memory");
}
assert_int_equal(EVP_DigestSign(mctx, sig, &siglen, (uint8_t *)test_msg, strlen(test_msg)), 1);