Fix Windows issues with CUnit fixture initialization
Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
parent
ecaf72c003
commit
599bf311cf
2 changed files with 41 additions and 19 deletions
|
@ -17,7 +17,7 @@ typedef struct {
|
||||||
cu_test_fini_func_t fini;
|
cu_test_fini_func_t fini;
|
||||||
int disabled; /* Parsed by CMake, used at test registration in main. */
|
int disabled; /* Parsed by CMake, used at test registration in main. */
|
||||||
int timeout; /* Parsed by CMake, used at test registration in CMake. */
|
int timeout; /* Parsed by CMake, used at test registration in CMake. */
|
||||||
} cu_test_data_t;
|
} cu_data_t;
|
||||||
|
|
||||||
#define CU_InitName(suite) \
|
#define CU_InitName(suite) \
|
||||||
CU_Init_ ## suite
|
CU_Init_ ## suite
|
||||||
|
@ -41,28 +41,50 @@ typedef struct {
|
||||||
/* CU_Test generates a wrapper function that takes care of per-test
|
/* CU_Test generates a wrapper function that takes care of per-test
|
||||||
initialization and deinitialization, if provided in the CU_Test
|
initialization and deinitialization, if provided in the CU_Test
|
||||||
signature. */
|
signature. */
|
||||||
#define CU_Test(suite, test, ...) \
|
#define CU_Test(suite, test, ...) \
|
||||||
static void CU_TestName(suite, test)(void); \
|
static void CU_TestName(suite, test)(void); \
|
||||||
\
|
\
|
||||||
void CU_TestProxyName(suite, test)(void) { \
|
void CU_TestProxyName(suite, test)(void) { \
|
||||||
static const cu_test_data_t data = { __VA_ARGS__ }; \
|
cu_data_t data = CU_Fixture(__VA_ARGS__); \
|
||||||
\
|
\
|
||||||
if (data.init != NULL) { \
|
if (data.init != NULL) { \
|
||||||
data.init(); \
|
data.init(); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
CU_TestName(suite, test)(); \
|
CU_TestName(suite, test)(); \
|
||||||
\
|
\
|
||||||
if (data.fini != NULL) { \
|
if (data.fini != NULL) { \
|
||||||
data.fini(); \
|
data.fini(); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static void CU_TestName(suite, test)(void)
|
static void CU_TestName(suite, test)(void)
|
||||||
|
|
||||||
#define CU_TestDecl(suite, test) \
|
#define CU_TestDecl(suite, test) \
|
||||||
extern void CU_TestProxyName(suite, test)(void)
|
extern void CU_TestProxyName(suite, test)(void)
|
||||||
|
|
||||||
|
/* Microsoft Visual Studio does not like empty struct initializers, i.e.
|
||||||
|
no fixtures are specified. To work around that issue CU_Fixture inserts a
|
||||||
|
NULL initializer as fall back. */
|
||||||
|
#define CU_Comma() ,
|
||||||
|
#define CU_Reduce(one, ...) one
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
/* Microsoft Visual Studio does not expand __VA_ARGS__ correctly. */
|
||||||
|
#define CU_Fixture__(...) CU_Fixture____((__VA_ARGS__))
|
||||||
|
#define CU_Fixture____(tuple) CU_Fixture___ tuple
|
||||||
|
#else
|
||||||
|
#define CU_Fixture__(...) CU_Fixture___(__VA_ARGS__)
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
#define CU_Fixture___(throw, away, value, ...) value
|
||||||
|
|
||||||
|
#define CU_Fixture(...) \
|
||||||
|
CU_Fixture_( CU_Comma CU_Reduce(__VA_ARGS__,) (), __VA_ARGS__ )
|
||||||
|
|
||||||
|
#define CU_Fixture_(throwaway, ...) \
|
||||||
|
CU_Fixture__(throwaway, ((cu_data_t){ 0 }), ((cu_data_t){ __VA_ARGS__ }))
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -46,7 +46,7 @@ extern "C" {
|
||||||
static void CU_TestName(suite, test) signature; \
|
static void CU_TestName(suite, test) signature; \
|
||||||
\
|
\
|
||||||
void CU_TestProxyName(suite, test)(void) { \
|
void CU_TestProxyName(suite, test)(void) { \
|
||||||
static const cu_test_data_t data = { __VA_ARGS__ }; \
|
cu_data_t data = CU_Fixture(__VA_ARGS__); \
|
||||||
size_t i, n; \
|
size_t i, n; \
|
||||||
\
|
\
|
||||||
if (data.init != NULL) { \
|
if (data.init != NULL) { \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue