diff options
-rw-r--r-- | source/kit_test/test.h | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/source/kit_test/test.h b/source/kit_test/test.h index 52a7b99..37abb9f 100644 --- a/source/kit_test/test.h +++ b/source/kit_test/test.h @@ -43,34 +43,41 @@ struct kit_tests_list { extern struct kit_tests_list kit_tests_list; -#ifdef _MSC_VER -# ifdef __cplusplus -# define KIT_EXTERN_C_ extern "C" -# else -# define KIT_EXTERN_C_ -# endif +#define KIT_TEST_CONCAT4_(a, b, c, d) a##b##c##d +#define KIT_TEST_CONCAT3_(a, b, c) KIT_TEST_CONCAT4_(a, b, _, c) -# pragma section(".CRT$XCU", read) -# define KIT_TEST_ON_START_2_(f, p) \ - KIT_EXTERN_C_ static void f(void); \ - __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ - __pragma(comment(linker, "/include:" p #f "_")) \ - KIT_EXTERN_C_ static void \ - f(void) -# ifdef _WIN64 -# define KIT_TEST_ON_START_(f) KIT_TEST_ON_START_2_(f, "") +#ifdef __cplusplus +# define KIT_TEST_ON_START_(f) \ + static void f(void); \ + static int KIT_TEST_CONCAT3_(_kit_test_init_, __LINE__, \ + f) = (f(), 0); \ + static void f(void) +#else +# ifdef _MSC_VER +# ifdef __cplusplus +# define KIT_EXTERN_C_ extern "C" +# else +# define KIT_EXTERN_C_ +# endif + +# pragma section(".CRT$XCU", read) +# define KIT_TEST_ON_START_2_(f, p) \ + static void f(void); \ + __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ + __pragma(comment(linker, "/include:" p #f "_")) static void f( \ + void) +# ifdef _WIN64 +# define KIT_TEST_ON_START_(f) KIT_TEST_ON_START_2_(f, "") +# else +# define KIT_TEST_ON_START_(f) KIT_TEST_ON_START_2_(f, "_") +# endif # else -# define KIT_TEST_ON_START_(f) KIT_TEST_ON_START_2_(f, "_") +# define KIT_TEST_ON_START_(f) \ + static void f(void) __attribute__((constructor)); \ + static void f(void) # endif -#else -# define KIT_TEST_ON_START_(f) \ - static void f(void) __attribute__((constructor)); \ - static void f(void) #endif -#define KIT_TEST_CONCAT4_(a, b, c, d) a##b##c##d -#define KIT_TEST_CONCAT3_(a, b, c) KIT_TEST_CONCAT4_(a, b, _, c) - #define KIT_TEST(name) \ static void KIT_TEST_CONCAT3_( \ kit_test_run_, __LINE__, KIT_TEST_FILE)(int, kit_test_report); \ |