/[resiprocate]/main/resip/stack/test/tassert.h
ViewVC logotype

Contents of /main/resip/stack/test/tassert.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8457 - (show annotations) (download)
Tue Apr 21 18:05:20 2009 UTC (10 years, 7 months ago) by adam
File MIME type: text/plain
File size: 4717 byte(s)
Fixing misc warnings under gcc 4.0.1

1 #if !defined (TASSERT_HXX)
2 #define TASSERT_HXX
3
4 #include <list>
5
6 #if 0 // If you are having bib memory problems with your compiler - try putting this to 1
7 #define tassert assert
8 #else
9 #define tassert(expr) \
10 if ( tassert_enabled ) \
11 { \
12 if (!(expr)) \
13 { \
14 CritLog(<<"TESTASSERT: "#expr); \
15 tassert_enabled = 0; \
16 tassert_failure = 1; \
17 tassert_location.push_back(__LINE__); \
18 } \
19 } \
20 else \
21 { \
22 CritLog(<<"SUPRESSED: "#expr); \
23 }
24 #endif
25 #define tassert_broken(x) tassert(!(x))
26 #define tassert_reset() (tassert_enabled = 1, tassert_failure = 0)
27
28 #define tassert_verify(x) { \
29 CritLog(<<"TASSERT: Section " << (tassert_failure ? "FAILED":"PASSED")); \
30 assert(x > 0 && x <= tassert_ncases); \
31 tassert_results[x-1].result = !tassert_failure; \
32 tassert_results[x-1].ran = true; \
33 }
34
35
36 static int tassert_enabled = 1;
37 static int tassert_failure = 0;
38 static int tassert_stack[10];
39 const int tassert_nstack = sizeof(tassert_stack)/sizeof(*tassert_stack);
40 static int tassert_stack_ptr = 0;
41 const int tassert_max_cases = 100;
42 static int tassert_ncases = 0;
43 std::list<int> tassert_location;
44
45 static void * warning_suppressor[] =
46 {&tassert_stack_ptr, &tassert_ncases, &warning_suppressor};
47
48 struct _tassert {
49 bool ran;
50 bool result;
51 } tassert_results[tassert_max_cases];
52
53 #define tassert_push() \
54 { \
55 assert(tassert_stack_ptr < tassert_nstack - 2); \
56 tassert_stack[tassert_stack_ptr++] = tassert_enabled; \
57 tassert_stack[tassert_stack_ptr++] = tassert_failure; \
58 }
59
60
61 #define tassert_pop() \
62 { \
63 assert(tassert_stack_ptr > 1); \
64 tassert_failure = tassert_stack[--tassert_stack_ptr] ; \
65 tassert_enabled = tassert_stack[--tassert_stack_ptr]; \
66 }
67
68 #define tassert_init(nCases) \
69 { \
70 \
71 assert(nCases < tassert_max_cases); \
72 tassert_ncases = nCases; \
73 for (int i = 0 ; i < tassert_ncases ; i++) \
74 { \
75 tassert_results[i].ran = false; \
76 } \
77 }
78
79 #define tassert_report() \
80 { \
81 bool overall = true; \
82 while (!tassert_location.empty()) { \
83 int line = tassert_location.front(); \
84 tassert_location.pop_front(); \
85 CritLog(<<__FILE__<<", line " << line <<": test failed."); \
86 } \
87 for(int i = 0; i < tassert_ncases ; i++) \
88 { \
89 if (!tassert_results[i].ran) \
90 { \
91 CritLog(<<"CASE " << i+1 << ": no results reported!"); \
92 overall = false; \
93 } \
94 else \
95 { \
96 bool res = tassert_results[i].result; \
97 overall = overall && res; \
98 CritLog(<<"CASE "<<i+1<<": " << (res?"PASSED":"FAILED ***")); \
99 } \
100 } \
101 CritLog(<<"OVERALL RESULTS: " << (overall?"PASSED":"FAILED ***")); \
102 }
103
104 #endif
105

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27