| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #ifndef STEST_H
- #define STEST_H
- #pragma once
- #include "config.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- /** simple unit test framework */
- // int f(st_case_set*);
- typedef struct st_case_set st_case_set;
- typedef int (*st_case_func)(st_case_set*);
- TOOLKIT_API st_case_set* st_init();
- TOOLKIT_API void st_term(st_case_set*);
- TOOLKIT_API int st_run(st_case_set*);
- TOOLKIT_API int st_add(st_case_set*, const char *key, st_case_func func);
- TOOLKIT_API int st_remove(st_case_set*, const char *key);
- TOOLKIT_API int st_remove_all(st_case_set*);
- TOOLKIT_API int st_fail_printf(st_case_set*, const char *, ...);
- TOOLKIT_API int st_fail_vprintf(st_case_set*, const char *, va_list arg);
- #define ST_BEGIN_MAIN() \
- int main() { \
- st_case_set *__cset = st_init();
- #define ST_ADD(f) \
- ST_DECLARE_CASE(f); \
- st_add(__cset, #f, &f);
- #define ST_REMOVE(f) \
- st_remove(__cset, #f);
- #define ST_END_MAIN() \
- st_run(__cset); \
- st_term(__cset); \
- getchar(); \
- return 0; \
- }
- #define ST_DECLARE_CASE(f) int f(st_case_set* __cset)
- #define ST_ASSERT(b, str, ...) \
- do { \
- if (!(b)) { \
- st_fail_printf(__cset, str, __VA_ARGS__); \
- return -1; \
- } \
- } while(0)
- #define ST_OK() \
- return 0
- #define ST_FAIL(str, ...) \
- st_fail_printf(__cset, str, __VA_ARGS__); \
- return -1;
- #ifdef __cplusplus
- } // extern "C" {
- #endif
- #endif // STEST_H
|