2025-12-14 17:58:09 +01:00
|
|
|
#ifndef COSMS_CORE_TEST
|
|
|
|
|
#define COSMS_CORE_TEST
|
2025-12-09 22:07:16 +01:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2025-12-18 16:12:23 +01:00
|
|
|
#define COSMS_CORE_TEST_EXPORT_TEST(name) { #name, cosms_core_##name##_test }
|
|
|
|
|
#define COSMS_CORE_TEST_DEFINE(name) const char *cosms_core_##name##_test(void)
|
|
|
|
|
#define COSMS_CORE_TEST_TEST(name, implementation) const char *cosms_core_##name##_test(void) { \
|
2025-12-17 18:53:20 +01:00
|
|
|
implementation \
|
2025-12-14 17:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-18 16:12:23 +01:00
|
|
|
#define COSMS_CORE_TEST_EXPORT(name, ...) static const struct cosms_core_test cosms_core_test_##name[] = { \
|
|
|
|
|
__VA_ARGS__, \
|
|
|
|
|
0 \
|
2025-12-14 17:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-18 16:12:23 +01:00
|
|
|
#define COSMS_CORE_TEST_START static const struct cosms_core_test *cosms_core_test_tests[] = {
|
2025-12-14 17:58:09 +01:00
|
|
|
#define COSMS_CORE_TEST_IMPORT(name) cosms_core_test_##name
|
|
|
|
|
#define COSMS_CORE_TEST_END };
|
|
|
|
|
|
2025-12-18 16:12:23 +01:00
|
|
|
#define COSMS_CORE_TEST_RUN() \
|
|
|
|
|
for (unsigned long long index = 0; index < sizeof(cosms_core_test_tests) / sizeof(cosms_core_test_tests[0]); index += 1) { \
|
|
|
|
|
unsigned long long test_index = 0; \
|
|
|
|
|
struct cosms_core_test current_test = cosms_core_test_tests[index][test_index]; \
|
|
|
|
|
while (current_test.name != 0) { \
|
|
|
|
|
printf("[*] running test %s...", current_test.name); \
|
|
|
|
|
fflush(stdout); \
|
|
|
|
|
const char *result = current_test.function(); \
|
|
|
|
|
if (result == NULL) { \
|
|
|
|
|
printf("\r[PASS] test %s completed successfully!\n", current_test.name); \
|
|
|
|
|
} else { \
|
2025-12-18 22:36:14 +01:00
|
|
|
printf("\r[FAIL] test %s failed with error:\n\t%s\n", current_test.name, result); \
|
2025-12-18 16:12:23 +01:00
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
test_index += 1; \
|
|
|
|
|
current_test = cosms_core_test_tests[index][test_index]; \
|
|
|
|
|
} \
|
2025-12-14 17:58:09 +01:00
|
|
|
}
|
2025-12-09 22:07:16 +01:00
|
|
|
|
2025-12-18 16:12:23 +01:00
|
|
|
struct cosms_core_test {
|
|
|
|
|
const char *name;
|
|
|
|
|
const char *(*function)(void);
|
|
|
|
|
};
|
2025-12-11 00:11:23 +01:00
|
|
|
|
2025-12-13 18:36:48 +01:00
|
|
|
#endif
|