/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to tests/test_macros.h

  • Committer: Gustav Hartvigsson
  • Date: 2015-04-08 18:25:07 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20150408182507-094jw13yhmi3bhfu
* Added "check" target for testing.
* Changed SRC to SSTS_SRC for future proofing.
* Removed a few "_" from before some struct names. It is not needed.
* Re-wrote how s_object_to_string () works on SError's. Should be faster now, but less safe...
  * To make this work I added SErrorTypeName string array. (Need to surpress the errer it creats).
* Re-orderd SErrorType enum.
* Use s_string_new_fmt () the default method for s_object_to_string ().
* Changed to strdup in some functions in utils.c.
* Added s_current_time () function to get an ISO time string.
* Added some more documentation to utils.h
* !DEBUG -> DEBUG in utils.h
* Added more tests to the test suite.
* Re-Wrote test_macros.h to display time, making it a lil' bit nicer to look at.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#define __H_TEST_MACROS__
4
4
 
5
5
#include <stdio.h>
 
6
#include <time.h>
 
7
#include <stdatomic.h>
6
8
 
7
9
#ifndef RESET
8
10
/* Colour definitions for console prints */
25
27
#define BOLDWHITE   "\033[1m\033[37m"      /* Bold White */
26
28
#endif
27
29
 
28
 
#define setup_unit()            \
29
 
  unsigned int unit_retval = 0;
30
 
 
31
 
#define end_unit()    \
32
 
  return unit_retval;
33
 
 
34
 
#define setup_suite()                   \
35
 
  unsigned int total_fails = 0;         \
36
 
  unsigned int test_suites_failed = 0;  \
37
 
  unsigned int tmp_val;                 \
 
30
 
 
31
/******************************************************************************/
 
32
 
 
33
#define setup_suite(sn)                                         \
 
34
  char * current_time () {                                      \
 
35
     char * ret_val = malloc (21);                              \
 
36
     time_t t = time (NULL);                                    \
 
37
     strftime (ret_val, 50,"%F %T", localtime (&t));            \
 
38
     return ret_val;                                            \
 
39
  }                                                             \
 
40
  char * suit_name = sn;                                        \
 
41
  char * t_str = current_time();                                \
 
42
  fprintf (stdout, YELLOW "[%s]\n[STARTING TEST SUITE] %s\n"    \
 
43
  RESET, t_str, suit_name);                                     \
 
44
  free (t_str);                                                 \
 
45
  unsigned int total_fails = 0;                                 \
 
46
  unsigned int test_suites_failed = 0;                          \
 
47
  unsigned int tmp_val = 0;
38
48
 
39
49
#define end_suite()                                            \
40
50
  if (test_suites_failed > 0){                                 \
43
53
    " Number of tests failed (total): %d\n" RESET,             \
44
54
    test_suites_failed, total_fails);                          \
45
55
  } else {                                                     \
46
 
    fprintf (stdout, GREEN "[TEST SUITE PASSED]\n" RESET);     \
 
56
    fprintf (stdout, GREEN "[TEST SUITE PASSED] %s\n" RESET,   \
 
57
      suit_name);                                              \
47
58
  }                                                            \
48
59
  return total_fails + test_suites_failed;
49
60
 
 
61
/******************************************************************************/
 
62
 
 
63
#define setup_unit()            \
 
64
  unsigned int unit_retval = 0;
 
65
 
 
66
#define end_unit()    \
 
67
  return unit_retval;
 
68
 
50
69
#define test_fail(p, ...)\
51
70
  fprintf (stderr, RED "[FAILED][%s:%d, %s] " p " \n" RESET,   \
52
71
  __FILE__, __LINE__, __func__ , ##__VA_ARGS__)
63
82
      unit_retval++;                \
64
83
    }
65
84
 
66
 
#define test_unit(fun, name)                                     \
67
 
  tmp_val = fun;                                                 \
68
 
  if (tmp_val > 0) {                                             \
69
 
    total_fails =+ tmp_val;                                      \
70
 
    test_suites_failed++;                                        \
71
 
    fprintf (stderr, RED "[TEST UNIT FAIL] " name "\n" RESET);   \
72
 
  } else {                                                       \
73
 
    fprintf (stdout, GREEN "[TEST UNIT PASS] " name "\n" RESET); \
74
 
  }
 
85
 
 
86
/******************************************************************************/
 
87
 
 
88
 
 
89
#define test_unit(fun, name)                                    \
 
90
  t_str = current_time ();                                      \
 
91
  tmp_val = fun ();                                             \
 
92
  if (tmp_val > 0) {                                            \
 
93
    total_fails =+ tmp_val;                                     \
 
94
    test_suites_failed++;                                       \
 
95
    fprintf (stderr, RED "[%s]\n[TEST UNIT FAIL] %s\n" RESET,   \
 
96
     t_str, name);                                              \
 
97
  } else {                                                      \
 
98
    fprintf (stdout, GREEN "[%s]\n[TEST UNIT PASS] %s\n" RESET, \
 
99
      t_str, name);                                             \
 
100
  }                                                             \
 
101
  free (t_str);
75
102
 
76
103
#endif /* __H_TEST__ */