10
/* Colour definitions for console prints */
11
#define RESET "\033[0m"
12
#define BLACK "\033[30m" /* Black */
13
#define RED "\033[31m" /* Red */
14
#define GREEN "\033[32m" /* Green */
15
#define YELLOW "\033[33m" /* Yellow */
16
#define BLUE "\033[34m" /* Blue */
17
#define MAGENTA "\033[35m" /* Magenta */
18
#define CYAN "\033[36m" /* Cyan */
19
#define WHITE "\033[37m" /* White */
20
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
21
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
22
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
23
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
24
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
25
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
26
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
27
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
31
* http://stackoverflow.com/a/1551641
35
test_current_time () {
36
char * ret_val = malloc (50);
38
time_t t = time (NULL);
40
gettimeofday (&tv, NULL);
41
strftime (fmt, 50,"%Y-%m-%dT%H:%M:%S.%%i%z", localtime (&t));
42
snprintf(ret_val, 50, fmt, tv.tv_usec);
47
/******************************************************************************/
49
#define setup_suite(sn) \
50
char * suit_name = sn; \
51
char * t_str = test_current_time (); \
52
fprintf (stdout, MAGENTA "[%s]\n[STARTING TEST SUITE] %s\n" \
53
RESET, t_str, suit_name); \
55
unsigned int total_fails = 0; \
56
unsigned int test_suites_failed = 0; \
57
unsigned int tmp_val = 0;
60
if (test_suites_failed > 0){ \
61
fprintf (stderr, RED "[TEST SUITE FAILED]\n" \
62
" Number of failed suits: %d\n" \
63
" Number of tests failed (total): %d\n" RESET, \
64
test_suites_failed, total_fails); \
66
fprintf (stdout, GREEN "[TEST SUITE PASSED] %s\n" RESET, \
69
return total_fails + test_suites_failed;
71
/******************************************************************************/
73
#define setup_unit() \
74
unsigned int unit_retval = 0;
79
#define test_case(cond, p, ...) \
81
fprintf (stdout, GREEN "[PASS] " p " \n" RESET, \
84
fprintf (stderr, RED "[FAILED][%s:%d, %s] " p " \n" RESET, \
85
__FILE__, __LINE__, __func__ , ##__VA_ARGS__); \
90
/******************************************************************************/
93
#define test_unit(fun, name){ \
94
t_str = test_current_time (); \
95
fprintf (stdout, BLUE "[%s]\n[STARTING TEST UNIT] %s\n" RESET, t_str, name);\
97
free (t_str); t_str = test_current_time (); \
99
total_fails =+ tmp_val; \
100
test_suites_failed++; \
101
fprintf (stderr, RED "[%s]\n[TEST UNIT FAIL] %s\n" RESET, \
104
fprintf (stdout, GREEN "[%s]\n[TEST UNIT PASS] %s\n" RESET, \