summaryrefslogtreecommitdiffstats
path: root/source/test-impl.inc.h
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2026-06-27 22:53:26 -0500
committerLibravatar bigfoot547 <[email protected]>2026-06-27 22:53:26 -0500
commit40724faccacf055cd9f9bba4615b9f930be9b76b (patch)
tree8df1806ef766f14a935e98ad1a04e47714f5f858 /source/test-impl.inc.h
initial commit
Diffstat (limited to 'source/test-impl.inc.h')
-rw-r--r--source/test-impl.inc.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/source/test-impl.inc.h b/source/test-impl.inc.h
new file mode 100644
index 0000000..2ecb7a6
--- /dev/null
+++ b/source/test-impl.inc.h
@@ -0,0 +1,49 @@
+#ifndef ET__ALLOW_TEST_IMPL_INC
+#error "Do not include this file directly! Include test.h instead."
+#endif
+
+#undef ET__ALLOW_TEST_IMPL_INC
+
+/* This file will be included in .c files which implement tests. */
+#ifdef _CLANGD
+#include <gccore.h>
+#include "test.h"
+/* include stuff this file uses here to make clangd happy (will not be visible to test.h) */
+#endif
+
+struct et_test_state_private_base {
+ struct et_test_plan *plan;
+};
+
+/* function prototypes for test-internal stuff */
+int test_next(struct et_test_plan *plan, struct et_next_state *next_state);
+
+int test_state_init(const struct et_state *state, void *data, et_state_init_data init_data);
+void test_state_cleanup(const struct et_state *state, void *data);
+
+void test_plan_entry_set_error(struct et_test_plan_entry *entry, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
+void test_plan_entry_set_error_static(struct et_test_plan_entry *entry, const char *str);
+
+/* Expands to a struct initializer for a struct et_test */
+#define TEST_STRUCT_INIT_FULL(_namestr, _flags, _init_f, _tick_f, _cleanup_f, _private_type) \
+{ \
+ .parent = { \
+ .init_f = test_state_init, \
+ .tick_f = _tick_f, \
+ .cleanup_f = test_state_cleanup, \
+ .private_size = sizeof(_private_type), \
+ }, \
+ .name = _namestr, \
+ .flags = _flags \
+}
+
+#define TEST__STRUCT_NAME(_name) PASTE(TEST_SYM(_name), __struct)
+#define TEST__STRUCT_DEF(_name, _ini) static const struct et_test TEST__STRUCT_NAME(_name) = _ini
+#define TEST__STRUCT_SANITY_CHECK(_ty) static_assert(sizeof(_ty) >= sizeof(struct et_test_state_private_base), "private data type too small (does it include base?)")
+#define TEST__SYM_DEF(_name) const struct et_test *const TEST_SYM(_name) = &TEST__STRUCT_NAME(_name)
+#define TEST_DEF(_name, _namestr, _flags, _init_f, _tick_f, _cleanup_f, _private_type) \
+ TEST__STRUCT_SANITY_CHECK(_private_type); \
+ TEST__STRUCT_DEF(_name, TEST_STRUCT_INIT_FULL(_namestr, _flags, _init_f, _tick_f, _cleanup_f, _private_type)); \
+ TEST__SYM_DEF(_name)
+
+#define test_current(_plan) ((_plan)->tests + (_plan)->current_test)