| 1 | #ifndef __TESTFRAMEWORK_H |
| 2 | #define __TESTFRAMEWORK_H |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <features.h> |
| 6 | |
| 7 | int contains(char **list, int len, const char *str, const char* descr); |
| 8 | void unittest_init(); |
| 9 | int unittest_summary(); |
| 10 | void unittest_help_mode(); |
| 11 | |
| 12 | long timeOfDayinMS(); |
| 13 | |
| 14 | |
| 15 | #define test_bool(expr) \ |
| 16 | ((expr) \ |
| 17 | ? tests_success++ \ |
| 18 | : test_fails (__STRING(expr), __FILE__, __LINE__, ___FUNCTION)) |
| 19 | |
| 20 | #define UNIT(func) \ |
| 21 | if(!help_mode){tests_init(); \ |
| 22 | fprintf(stderr,"\033[1;34m*** UNIT TEST %s ***\033[0m\n",__STRING(func)); \ |
| 23 | (func); \ |
| 24 | fprintf(stderr,"---->\t"); \ |
| 25 | if(test_summary()){ fprintf(stderr, "\t\t\033[1;32m PASSED\033[0m\n"); \ |
| 26 | units_success++; } \ |
| 27 | else { fprintf(stderr, "\t\t\033[1;31m FAILED\033[0m !!!!!\n"); \ |
| 28 | units_failed++; } \ |
| 29 | } |
| 30 | |
| 31 | #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L |
| 32 | # define ___FUNCTION __func__ |
| 33 | #else |
| 34 | # define ___FUNCTION ((__const char *) 0) |
| 35 | #endif |
| 36 | |
| 37 | |
| 38 | // INTERNALS |
| 39 | extern int units_success; |
| 40 | extern int units_failed; |
| 41 | extern int tests_success; |
| 42 | extern int tests_failed; |
| 43 | extern int help_mode; |
| 44 | |
| 45 | |
| 46 | void tests_init(); |
| 47 | |
| 48 | int test_summary(); |
| 49 | |
| 50 | void test_fails (__const char *__assertion, __const char *__file, |
| 51 | unsigned int __line, __const char *__function); |
| 52 | |
| 53 | |
| 54 | |
| 55 | #endif |