/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
1
#ifndef __H_TEST_MACROS__
34 by Gustav Hartvigsson
* Finnished test suite
2
#define __H_TEST_MACROS__
3
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
4
#include <stdio.h>
5
#include <time.h>
39 by Gustav Hartvigsson
* Added "check" target for testing.
6
#include <stdatomic.h>
7
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
8
#ifndef RESET
33 by Gustav Hartvigsson
* made test_macros.h a lil' bit more portable
9
/* Colour definitions for console prints */
10
#define RESET   "\033[0m"
11
#define BLACK   "\033[30m"      /* Black */
12
#define RED     "\033[31m"      /* Red */
13
#define GREEN   "\033[32m"      /* Green */
14
#define YELLOW  "\033[33m"      /* Yellow */
15
#define BLUE    "\033[34m"      /* Blue */
16
#define MAGENTA "\033[35m"      /* Magenta */
17
#define CYAN    "\033[36m"      /* Cyan */
18
#define WHITE   "\033[37m"      /* White */
19
#define BOLDBLACK   "\033[1m\033[30m"      /* Bold Black */
20
#define BOLDRED     "\033[1m\033[31m"      /* Bold Red */
21
#define BOLDGREEN   "\033[1m\033[32m"      /* Bold Green */
22
#define BOLDYELLOW  "\033[1m\033[33m"      /* Bold Yellow */
23
#define BOLDBLUE    "\033[1m\033[34m"      /* Bold Blue */
24
#define BOLDMAGENTA "\033[1m\033[35m"      /* Bold Magenta */
25
#define BOLDCYAN    "\033[1m\033[36m"      /* Bold Cyan */
26
#define BOLDWHITE   "\033[1m\033[37m"      /* Bold White */
27
#endif
28
29
39 by Gustav Hartvigsson
* Added "check" target for testing.
30
/******************************************************************************/
31
32
#define setup_suite(sn)                                         \
33
  char * current_time () {                                      \
34
     char * ret_val = malloc (21);                              \
35
     time_t t = time (NULL);                                    \
36
     strftime (ret_val, 50,"%F %T", localtime (&t));            \
37
     return ret_val;                                            \
38
  }                                                             \
39
  char * suit_name = sn;                                        \
40
  char * t_str = current_time();                                \
41
  fprintf (stdout, YELLOW "[%s]\n[STARTING TEST SUITE] %s\n"    \
42
  RESET, t_str, suit_name);                                     \
43
  free (t_str);                                                 \
44
  unsigned int total_fails = 0;                                 \
45
  unsigned int test_suites_failed = 0;                          \
46
  unsigned int tmp_val = 0;
47
34 by Gustav Hartvigsson
* Finnished test suite
48
#define end_suite()                                            \
38 by Gustav Hartvigsson
* Formated the macros a bit
49
  if (test_suites_failed > 0){                                 \
50
    fprintf (stderr, RED "[TEST SUITE FAILED]\n"               \
51
    " Number of failed suits: %d\n"                            \
52
    " Number of tests failed (total): %d\n" RESET,             \
53
    test_suites_failed, total_fails);                          \
54
  } else {                                                     \
55
    fprintf (stdout, GREEN "[TEST SUITE PASSED] %s\n" RESET,   \
39 by Gustav Hartvigsson
* Added "check" target for testing.
56
      suit_name);                                              \
57
  }                                                            \
38 by Gustav Hartvigsson
* Formated the macros a bit
58
  return total_fails + test_suites_failed;
34 by Gustav Hartvigsson
* Finnished test suite
59
60
/******************************************************************************/
39 by Gustav Hartvigsson
* Added "check" target for testing.
61
62
#define setup_unit()            \
63
  unsigned int unit_retval = 0;
64
65
#define end_unit()    \
66
  return unit_retval;
67
68
#define test_case(cond, p, ...)                                     \
47 by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h
69
    if (cond) {                                                     \
70
      fprintf (stdout, GREEN "[PASS] " p " \n" RESET,               \
71
               ##__VA_ARGS__);                                      \
72
    } else {                                                        \
73
      fprintf (stderr, RED "[FAILED][%s:%d, %s] " p " \n" RESET,    \
74
      __FILE__, __LINE__, __func__ , ##__VA_ARGS__);                \
75
      unit_retval++;                                                \
76
    }
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
77
78
39 by Gustav Hartvigsson
* Added "check" target for testing.
79
/******************************************************************************/
80
81
82
#define test_unit(fun, name)                                    \
83
  t_str = current_time ();                                      \
84
  tmp_val = fun ();                                             \
85
  if (tmp_val > 0) {                                            \
86
    total_fails =+ tmp_val;                                     \
87
    test_suites_failed++;                                       \
88
    fprintf (stderr, RED "[%s]\n[TEST UNIT FAIL] %s\n" RESET,   \
89
     t_str, name);                                              \
90
  } else {                                                      \
91
    fprintf (stdout, GREEN "[%s]\n[TEST UNIT PASS] %s\n" RESET, \
92
      t_str, name);                                             \
93
  }                                                             \
94
  free (t_str);
95
34 by Gustav Hartvigsson
* Finnished test suite
96
#endif /* __H_TEST__ */
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
97