diff options
Diffstat (limited to 'tests/test_common.h')
| -rw-r--r-- | tests/test_common.h | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/tests/test_common.h b/tests/test_common.h index ea35ecd..03511ef 100644 --- a/tests/test_common.h +++ b/tests/test_common.h | |||
| @@ -1,19 +1,41 @@ | |||
| 1 | #ifndef TEST_COMMON_H | 1 | #ifndef TEST_COMMON_H |
| 2 | #define TEST_COMMON_H | 2 | #define TEST_COMMON_H |
| 3 | 3 | ||
| 4 | /* | ||
| 5 | * Common utilities for testing. | ||
| 6 | * A VoidMethod can be used as a setup or teardown method for testing, see | ||
| 7 | * the TestSuite struct. A TestMethod takes a void pointer (usually cast | ||
| 8 | * to some data to be used for testing, but can also be ignored) and returns | ||
| 9 | * a bool: true for pass, false for fail. | ||
| 10 | * A Test consists of a name (string), a TestMethod and an array of void | ||
| 11 | * pointers that describe the test cases. Each element of this array is | ||
| 12 | * passed to the test method sequentially, and the test session stops on | ||
| 13 | * the first failure. | ||
| 14 | * A test suite is just a list of tests with a setup and a teardown method. | ||
| 15 | * The setup method is run once and for all before the first test, and the | ||
| 16 | * teardown is run at the end of the testsuite. | ||
| 17 | * Finally, a TestModule roughly corresponds to a test file. This type is | ||
| 18 | * only used in test.c to collect multiple test modules. | ||
| 19 | */ | ||
| 20 | |||
| 4 | typedef void (*VoidMethod)(void); | 21 | typedef void (*VoidMethod)(void); |
| 5 | typedef bool (*TestMethod)(void *); | 22 | typedef bool (*TestMethod)(void *); |
| 6 | 23 | ||
| 7 | typedef struct { | 24 | typedef struct { |
| 8 | char * name; | 25 | char * name; |
| 9 | TestMethod t; | 26 | TestMethod t; |
| 10 | void ** cases; | 27 | void ** cases; |
| 11 | } Test; | 28 | } Test; |
| 12 | 29 | ||
| 13 | typedef struct { | 30 | typedef struct { |
| 14 | VoidMethod setup; | 31 | VoidMethod setup; |
| 15 | Test ** tests; | 32 | Test ** tests; |
| 16 | VoidMethod teardown; | 33 | VoidMethod teardown; |
| 17 | } TestSuite; | 34 | } TestSuite; |
| 18 | 35 | ||
| 36 | typedef struct { | ||
| 37 | char * name; | ||
| 38 | TestSuite ** suites; | ||
| 39 | } TestModule; | ||
| 40 | |||
| 19 | #endif | 41 | #endif |
