Fixed bias issue, some general cleanups.
[reservoir_sample] / test_suite.h
1 #ifndef TEST_SUITE_H_6XEHCUS5
2 #define TEST_SUITE_H_6XEHCUS5
3
4 #ifdef TEST
5
6 typedef struct test {
7 const char * const test_name;
8 int (* const test_fn)(void *test_data, void *suite_data);
9 int (* const test_pre_fn)(void *test_data, void *suite_data);
10 int (* const test_post_fn)(void *test_data, void *suite_data);
11 void *test_data;
12 } test_t;
13
14 /* define all of these within module to test */
15 extern test_t test_suite[];
16 extern int test_suite_pre(void *suite_data);
17 extern int test_suite_post(void *suite_data);
18 extern void *test_suite_data;
19
20 /* use these in tests */
21 void test_verbose(const char *fmt, ...) __attribute__((format(printf, 1, 2))); /* stdout only with -v flag */
22 void test_info(const char *fmt, ...) __attribute__((format(printf, 1, 2))); /* stdout */
23 void test_error(const char *fmt, ...) __attribute__((format(printf, 1, 2))); /* stderr */
24
25 #define TEST_VERBOSE(fmt,...) do { test_verbose("%s@%s:%d/%s/" fmt "\n", "verbose", __FILE__, __LINE__, __func__, ##__VA_ARGS__); } while (0)
26 #define TEST_INFO(fmt,...) do { test_info("%s@%s:%d/%s/" fmt "\n", "info", __FILE__, __LINE__, __func__, ##__VA_ARGS__); } while (0)
27 #define TEST_ERROR(fmt,...) do { test_error("%s@%s:%d/%s/" fmt "\n", "error", __FILE__, __LINE__, __func__, ##__VA_ARGS__); } while (0)
28
29 #else /* TEST */
30 #define TEST_VERBOSE(...)
31 #define TEST_INFO(...)
32 #define TEST_ERROR(...)
33 #endif /* TEST */
34
35 #endif /* TEST_SUITE_H_6XEHCUS5 */