Commit | Line | Data |
---|---|---|
80f575fc DM |
1 | #include <string.h> |
2 | #include <sys/time.h> | |
3 | ||
4 | #include "testframework.h" | |
5 | ||
6 | int help_mode=0; | |
7 | ||
8 | void unittest_help_mode(){ | |
9 | help_mode=1; | |
10 | } | |
11 | ||
12 | // returns 0 of not found and otherwise the index of the next element (possible argument) | |
13 | int contains(char **list, int len, const char *str, const char* descr) { | |
14 | if(help_mode) { | |
15 | printf("\t%s:\t%s\n",str, descr); | |
16 | return 0; | |
17 | } | |
18 | int i; | |
19 | for(i=0; i<len; i++) { | |
20 | if(strcmp(list[i],str) == 0) | |
21 | return i+1; | |
22 | } | |
23 | return 0; | |
24 | } | |
25 | ||
26 | int units_success; | |
27 | int units_failed; | |
28 | ||
29 | void unittest_init(){ | |
30 | units_success=0; | |
31 | units_failed=0; | |
32 | } | |
33 | ||
34 | int unittest_summary(){ | |
35 | fprintf(stderr, "*********** SUMMARY **************\n"); | |
36 | fprintf(stderr, "UNIT TESTs succeeded:\t %s%i/%i\033[0m\n", | |
37 | units_failed>0 ? "\033[1;31m" : "\033[1;32m", | |
38 | units_success, units_success + units_failed); | |
39 | return units_failed==0; | |
40 | ||
41 | } | |
42 | ||
43 | long timeOfDayinMS() { | |
44 | struct timeval t; | |
45 | gettimeofday(&t, 0); | |
46 | return t.tv_sec*1000 + t.tv_usec/1000; | |
47 | } | |
48 | ||
49 | //// INTERNALS | |
50 | int tests_success; | |
51 | int tests_failed; | |
52 | ||
53 | void tests_init(){ | |
54 | tests_success=0; | |
55 | tests_failed=0; | |
56 | } | |
57 | ||
58 | ||
59 | int test_summary(){ | |
60 | fprintf(stderr, "Tests checks succeeded: %i/%i", | |
61 | tests_success, tests_success + tests_failed); | |
62 | return tests_failed==0; | |
63 | } | |
64 | ||
65 | void test_fails (__const char *__assertion, __const char *__file, | |
66 | unsigned int __line, __const char *__function){ | |
67 | fprintf(stderr, "%s:%i: Test Failed: %s\n in Function %s", __file,__line,__assertion,__function); | |
68 | tests_failed++; | |
69 | } |