1 | #ifndef __cxxtest__TestSuite_cpp__ |
---|
2 | #define __cxxtest__TestSuite_cpp__ |
---|
3 | |
---|
4 | #include <cxxtest/TestSuite.h> |
---|
5 | |
---|
6 | namespace CxxTest |
---|
7 | { |
---|
8 | // |
---|
9 | // TestSuite members |
---|
10 | // |
---|
11 | TestSuite::~TestSuite() {} |
---|
12 | void TestSuite::setUp() {} |
---|
13 | void TestSuite::tearDown() {} |
---|
14 | |
---|
15 | // |
---|
16 | // Test-aborting stuff |
---|
17 | // |
---|
18 | static bool currentAbortTestOnFail = false; |
---|
19 | |
---|
20 | bool abortTestOnFail() |
---|
21 | { |
---|
22 | return currentAbortTestOnFail; |
---|
23 | } |
---|
24 | |
---|
25 | void setAbortTestOnFail( bool value ) |
---|
26 | { |
---|
27 | currentAbortTestOnFail = value; |
---|
28 | } |
---|
29 | |
---|
30 | void doAbortTest() |
---|
31 | { |
---|
32 | # if defined(_CXXTEST_HAVE_EH) |
---|
33 | if ( currentAbortTestOnFail ) |
---|
34 | throw AbortTest(); |
---|
35 | # endif // _CXXTEST_HAVE_EH |
---|
36 | } |
---|
37 | |
---|
38 | // |
---|
39 | // Max dump size |
---|
40 | // |
---|
41 | static unsigned currentMaxDumpSize = CXXTEST_MAX_DUMP_SIZE; |
---|
42 | |
---|
43 | unsigned maxDumpSize() |
---|
44 | { |
---|
45 | return currentMaxDumpSize; |
---|
46 | } |
---|
47 | |
---|
48 | void setMaxDumpSize( unsigned value ) |
---|
49 | { |
---|
50 | currentMaxDumpSize = value; |
---|
51 | } |
---|
52 | |
---|
53 | // |
---|
54 | // Some non-template functions |
---|
55 | // |
---|
56 | void doTrace( const char *file, unsigned line, const char *message ) |
---|
57 | { |
---|
58 | tracker().trace( file, line, message ); |
---|
59 | } |
---|
60 | |
---|
61 | void doWarn( const char *file, unsigned line, const char *message ) |
---|
62 | { |
---|
63 | tracker().warning( file, line, message ); |
---|
64 | } |
---|
65 | |
---|
66 | void doFailTest( const char *file, unsigned line, const char *message ) |
---|
67 | { |
---|
68 | tracker().failedTest( file, line, message ); |
---|
69 | TS_ABORT(); |
---|
70 | } |
---|
71 | |
---|
72 | void doFailAssert( const char *file, unsigned line, |
---|
73 | const char *expression, const char *message ) |
---|
74 | { |
---|
75 | if ( message ) |
---|
76 | tracker().failedTest( file, line, message ); |
---|
77 | tracker().failedAssert( file, line, expression ); |
---|
78 | TS_ABORT(); |
---|
79 | } |
---|
80 | |
---|
81 | bool sameData( const void *x, const void *y, unsigned size ) |
---|
82 | { |
---|
83 | if ( size == 0 ) |
---|
84 | return true; |
---|
85 | |
---|
86 | if ( x == y ) |
---|
87 | return true; |
---|
88 | |
---|
89 | if ( !x || !y ) |
---|
90 | return false; |
---|
91 | |
---|
92 | const char *cx = (const char *)x; |
---|
93 | const char *cy = (const char *)y; |
---|
94 | while ( size -- ) |
---|
95 | if ( *cx++ != *cy++ ) |
---|
96 | return false; |
---|
97 | |
---|
98 | return true; |
---|
99 | } |
---|
100 | |
---|
101 | void doAssertSameData( const char *file, unsigned line, |
---|
102 | const char *xExpr, const void *x, |
---|
103 | const char *yExpr, const void *y, |
---|
104 | const char *sizeExpr, unsigned size, |
---|
105 | const char *message ) |
---|
106 | { |
---|
107 | if ( !sameData( x, y, size ) ) { |
---|
108 | if ( message ) |
---|
109 | tracker().failedTest( file, line, message ); |
---|
110 | tracker().failedAssertSameData( file, line, xExpr, yExpr, sizeExpr, x, y, size ); |
---|
111 | TS_ABORT(); |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | void doFailAssertThrows( const char *file, unsigned line, |
---|
116 | const char *expr, const char *type, |
---|
117 | bool otherThrown, |
---|
118 | const char *message ) |
---|
119 | { |
---|
120 | if ( message ) |
---|
121 | tracker().failedTest( file, line, message ); |
---|
122 | |
---|
123 | tracker().failedAssertThrows( file, line, expr, type, otherThrown ); |
---|
124 | TS_ABORT(); |
---|
125 | } |
---|
126 | |
---|
127 | void doFailAssertThrowsNot( const char *file, unsigned line, |
---|
128 | const char *expression, const char *message ) |
---|
129 | { |
---|
130 | if ( message ) |
---|
131 | tracker().failedTest( file, line, message ); |
---|
132 | |
---|
133 | tracker().failedAssertThrowsNot( file, line, expression ); |
---|
134 | TS_ABORT(); |
---|
135 | } |
---|
136 | }; |
---|
137 | |
---|
138 | #endif // __cxxtest__TestSuite_cpp__ |
---|