]>
Commit | Line | Data |
---|---|---|
558d2836 A |
1 | // |
2 | // hfs-tests.h | |
3 | // hfs | |
4 | // | |
5 | // Created by Chris Suter on 8/11/15. | |
6 | // | |
7 | // | |
8 | ||
9 | #ifndef hfs_tests_c | |
10 | #define hfs_tests_c | |
11 | ||
12 | #include <sys/cdefs.h> | |
13 | #include <stdbool.h> | |
14 | ||
15 | __BEGIN_DECLS | |
16 | ||
17 | typedef struct test_ctx { | |
18 | int reserved; | |
19 | } test_ctx_t; | |
20 | ||
21 | typedef int (* test_fn_t)(test_ctx_t *); | |
22 | ||
23 | typedef struct test { | |
24 | const char *name; | |
25 | test_fn_t test_fn; | |
26 | bool run_as_root; | |
27 | // Other attributes | |
28 | } test_t; | |
29 | ||
30 | #define TEST_DECL(test_name, ...) \ | |
31 | static int run_##test_name(test_ctx_t *); \ | |
32 | struct test test_##test_name = { \ | |
33 | .name = #test_name, \ | |
34 | .test_fn = run_##test_name, \ | |
35 | __VA_ARGS__ \ | |
36 | }; \ | |
37 | static __attribute__((constructor)) \ | |
38 | void register_test_##test_name(void) { \ | |
39 | register_test(&test_##test_name); \ | |
40 | } | |
41 | ||
42 | #ifndef TEST | |
43 | #define TEST(x, ...) TEST_DECL(x, ##__VA_ARGS__) | |
44 | #endif | |
45 | ||
46 | void register_test(test_t *test); | |
47 | ||
48 | __END_DECLS | |
49 | ||
50 | #endif /* hfs_tests_c */ |