/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
6
#ifndef RESET
33 by Gustav Hartvigsson
* made test_macros.h a lil' bit more portable
7
/* Colour definitions for console prints */
8
#define RESET   "\033[0m"
9
#define BLACK   "\033[30m"      /* Black */
10
#define RED     "\033[31m"      /* Red */
11
#define GREEN   "\033[32m"      /* Green */
12
#define YELLOW  "\033[33m"      /* Yellow */
13
#define BLUE    "\033[34m"      /* Blue */
14
#define MAGENTA "\033[35m"      /* Magenta */
15
#define CYAN    "\033[36m"      /* Cyan */
16
#define WHITE   "\033[37m"      /* White */
17
#define BOLDBLACK   "\033[1m\033[30m"      /* Bold Black */
18
#define BOLDRED     "\033[1m\033[31m"      /* Bold Red */
19
#define BOLDGREEN   "\033[1m\033[32m"      /* Bold Green */
20
#define BOLDYELLOW  "\033[1m\033[33m"      /* Bold Yellow */
21
#define BOLDBLUE    "\033[1m\033[34m"      /* Bold Blue */
22
#define BOLDMAGENTA "\033[1m\033[35m"      /* Bold Magenta */
23
#define BOLDCYAN    "\033[1m\033[36m"      /* Bold Cyan */
24
#define BOLDWHITE   "\033[1m\033[37m"      /* Bold White */
25
#endif
26
27
#define setup_unit()            \
38 by Gustav Hartvigsson
* Formated the macros a bit
28
  unsigned int unit_retval = 0;
34 by Gustav Hartvigsson
* Finnished test suite
29
30
#define end_unit()    \
31
  return unit_retval;
32
33
#define setup_suite()                   \
38 by Gustav Hartvigsson
* Formated the macros a bit
34
  unsigned int total_fails = 0;         \
35
  unsigned int test_suites_failed = 0;  \
36
  unsigned int tmp_val;                 \
37
34 by Gustav Hartvigsson
* Finnished test suite
38
#define end_suite()                                            \
38 by Gustav Hartvigsson
* Formated the macros a bit
39
  if (test_suites_failed > 0){                                 \
40
    fprintf (stderr, RED "[TEST SUITE FAILED]\n"               \
41
    " Number of failed suits: %d\n"                            \
42
    " Number of tests failed (total): %d\n" RESET,             \
43
    test_suites_failed, total_fails);                          \
44
  } else {                                                     \
45
    fprintf (stdout, GREEN "[TEST SUITE PASSED]\n" RESET);     \
46
  }                                                            \
47
  return total_fails + test_suites_failed;
34 by Gustav Hartvigsson
* Finnished test suite
48
49
#define test_fail(p, ...)\
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
50
  fprintf (stderr, RED "[FAILED][%s:%d, %s] " p " \n" RESET,   \
38 by Gustav Hartvigsson
* Formated the macros a bit
51
  __FILE__, __LINE__, __func__ , ##__VA_ARGS__)
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
52
53
#define test_pass(p, ...)                            \
38 by Gustav Hartvigsson
* Formated the macros a bit
54
   fprintf (stdout, GREEN "[PASS] " p " \n" RESET,   \
55
   ##__VA_ARGS__)
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
56
57
#define test_case(cond, p)          \
34 by Gustav Hartvigsson
* Finnished test suite
58
    if (cond) {                     \
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
59
      test_pass(p);                 \
60
    } else {                        \
61
      test_fail(p);                 \
62
      unit_retval++;                \
38 by Gustav Hartvigsson
* Formated the macros a bit
63
    }
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
64
65
#define test_unit(fun, name)                                     \
38 by Gustav Hartvigsson
* Formated the macros a bit
66
  tmp_val = fun;                                                 \
67
  if (tmp_val > 0) {                                             \
68
    total_fails =+ tmp_val;                                      \
69
    test_suites_failed++;                                        \
70
    fprintf (stderr, RED "[TEST UNIT FAIL] " name "\n" RESET);   \
34 by Gustav Hartvigsson
* Finnished test suite
71
  } else {                                                       \
38 by Gustav Hartvigsson
* Formated the macros a bit
72
    fprintf (stdout, GREEN "[TEST UNIT PASS] " name "\n" RESET); \
34 by Gustav Hartvigsson
* Finnished test suite
73
  }
74
75
#endif /* __H_TEST__ */
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
76