#ifndef COSMS_CORE_TEST #define COSMS_CORE_TEST #include #include #define COSMS_CORE_TEST_FUNCTION_NAME(name) cosms_core_##name##_test #define COSMS_CORE_TEST_DEFINE(name) void cosms_core_##name##_test(void) #define COSMS_CORE_TEST_TEST(name, implementation) void cosms_core_##name##_test(void) { \ const char *cosms_core_test_name = #name; \ printf("----------------------------------------\n%s\n----------------------------------------\n", cosms_core_test_name); \ implementation \ } #define COSMS_CORE_TEST_SUB_TEST(name, implementation) { \ const char* cosms_core_sub_test_name = #name; \ printf("[*] running test %s...\n", cosms_core_sub_test_name); \ implementation \ } #define COSMS_CORE_TEST_EXPORT(name, ...) static const cosms_core_test cosms_core_test_##name[] = { \ __VA_ARGS__ \ } #define COSMS_CORE_TEST_START static const cosms_core_test *cosms_core_test_tests[] = { #define COSMS_CORE_TEST_IMPORT(name) cosms_core_test_##name #define COSMS_CORE_TEST_END }; #define COSMS_CORE_TEST_RUN() \ for (unsigned long long index = 0; index < sizeof(cosms_core_test_tests); index += 1) { \ for (unsigned long long test_index = 0; test_index < sizeof(cosms_core_test_tests[index]); test_index += 1) { \ cosms_core_test_tests[index][test_index](); \ } \ } #define COSMS_CORE_TEST_SUCCESS(test_name) printf("[+] test %s completed successfully!\n", test_name); typedef void (*cosms_core_test)(); static inline bool cosms_core_test_assert(const char *test_name, bool expression, const char *error_message) { if (!expression) { printf("[-] test %s failed with error: %s\n", test_name, error_message); return false; } return true; } #endif