@@ -36,7 +36,7 @@ namespace
36
36
37
37
const Case *case_current = NULL ;
38
38
size_t case_index = 0 ;
39
- control_t case_control = control_t ( REPEAT_SETUP_TEARDOWN) ;
39
+ base_control_t case_control = { REPEAT_SETUP_TEARDOWN, TIMEOUT_UNDECLR } ;
40
40
size_t case_repeat_count = 1 ;
41
41
42
42
void *case_timeout_handle = NULL ;
@@ -47,8 +47,13 @@ namespace
47
47
size_t case_failed = 0 ;
48
48
size_t case_failed_before = 0 ;
49
49
50
- handlers_t defaults = default_handlers;
51
- handlers_t handlers = defaults;
50
+ struct DefaultHandlers : public handlers_t {
51
+ DefaultHandlers () : handlers_t (default_handlers) { }
52
+ DefaultHandlers (const handlers_t & other) : handlers_t (other) { }
53
+ };
54
+
55
+ SingletonPtr<DefaultHandlers> defaults;
56
+ SingletonPtr<DefaultHandlers> handlers;
52
57
53
58
location_t location = LOCATION_UNKNOWN;
54
59
@@ -110,10 +115,10 @@ bool Harness::run(const Specification& specification)
110
115
return false ;
111
116
test_cases = specification.cases ;
112
117
test_length = specification.length ;
113
- defaults = specification.defaults ;
114
- handlers. test_setup = defaults. get_handler (specification.setup_handler );
115
- handlers. test_teardown = defaults. get_handler (specification.teardown_handler );
116
- handlers. test_failure = defaults. get_handler (specification.failure_handler );
118
+ * defaults. get () = specification.defaults ;
119
+ handlers-> test_setup = defaults-> get_handler (specification.setup_handler );
120
+ handlers-> test_teardown = defaults-> get_handler (specification.teardown_handler );
121
+ handlers-> test_failure = defaults-> get_handler (specification.failure_handler );
117
122
118
123
test_index_of_case = 0 ;
119
124
test_passed = 0 ;
@@ -127,16 +132,16 @@ bool Harness::run(const Specification& specification)
127
132
int setup_status = 0 ;
128
133
failure_t failure (REASON_NONE, location);
129
134
130
- if (handlers. test_setup ) {
131
- setup_status = handlers. test_setup (test_length);
135
+ if (handlers-> test_setup ) {
136
+ setup_status = handlers-> test_setup (test_length);
132
137
if (setup_status == STATUS_CONTINUE) setup_status = 0 ;
133
138
else if (setup_status < STATUS_CONTINUE) failure.reason = REASON_TEST_SETUP;
134
139
else if (setup_status > signed (test_length)) failure.reason = REASON_CASE_INDEX;
135
140
}
136
141
137
142
if (failure.reason != REASON_NONE) {
138
- if (handlers. test_failure ) handlers. test_failure (failure);
139
- if (handlers. test_teardown ) handlers. test_teardown (0 , 0 , failure);
143
+ if (handlers-> test_failure ) handlers-> test_failure (failure);
144
+ if (handlers-> test_teardown ) handlers-> test_teardown (0 , 0 , failure);
140
145
test_cases = NULL ;
141
146
exit (1 );
142
147
return true ;
@@ -150,8 +155,8 @@ bool Harness::run(const Specification& specification)
150
155
scheduler.post (run_next_case, 0 );
151
156
if (scheduler.run () != 0 ) {
152
157
failure.reason = REASON_SCHEDULER;
153
- if (handlers. test_failure ) handlers. test_failure (failure);
154
- if (handlers. test_teardown ) handlers. test_teardown (0 , 0 , failure);
158
+ if (handlers-> test_failure ) handlers-> test_failure (failure);
159
+ if (handlers-> test_teardown ) handlers-> test_teardown (0 , 0 , failure);
155
160
test_cases = NULL ;
156
161
exit (1 );
157
162
return true ;
@@ -167,8 +172,8 @@ void Harness::raise_failure(const failure_reason_t reason)
167
172
if (test_cases == NULL ) return ;
168
173
169
174
utest::v1::status_t fail_status = STATUS_ABORT;
170
- if (handlers. test_failure ) handlers. test_failure (failure_t (reason, location));
171
- if (handlers. case_failure ) fail_status = handlers. case_failure (case_current, failure_t (reason, location));
175
+ if (handlers-> test_failure ) handlers-> test_failure (failure_t (reason, location));
176
+ if (handlers-> case_failure ) fail_status = handlers-> case_failure (case_current, failure_t (reason, location));
172
177
173
178
{
174
179
UTEST_ENTER_CRITICAL_SECTION;
@@ -184,25 +189,25 @@ void Harness::raise_failure(const failure_reason_t reason)
184
189
}
185
190
186
191
if (fail_status == STATUS_ABORT || reason & REASON_CASE_SETUP) {
187
- if (handlers. case_teardown && location != LOCATION_CASE_TEARDOWN) {
192
+ if (handlers-> case_teardown && location != LOCATION_CASE_TEARDOWN) {
188
193
location_t fail_loc (location);
189
194
location = LOCATION_CASE_TEARDOWN;
190
195
191
- utest::v1::status_t teardown_status = handlers. case_teardown (case_current, case_passed, case_failed, failure_t (reason, fail_loc));
196
+ utest::v1::status_t teardown_status = handlers-> case_teardown (case_current, case_passed, case_failed, failure_t (reason, fail_loc));
192
197
if (teardown_status < STATUS_CONTINUE) raise_failure (REASON_CASE_TEARDOWN);
193
198
else if (teardown_status > signed (test_length)) raise_failure (REASON_CASE_INDEX);
194
199
else if (teardown_status >= 0 ) case_index = teardown_status - 1 ;
195
200
196
201
// Restore case failure location once we have dealt with case teardown
197
202
location = fail_loc;
198
- handlers. case_teardown = NULL ;
203
+ handlers-> case_teardown = NULL ;
199
204
}
200
205
}
201
206
if (fail_status == STATUS_ABORT) {
202
207
test_failed++;
203
208
failure_t fail (reason, location);
204
209
location = LOCATION_TEST_TEARDOWN;
205
- if (handlers. test_teardown ) handlers. test_teardown (test_passed, test_failed, fail);
210
+ if (handlers-> test_teardown ) handlers-> test_teardown (test_passed, test_failed, fail);
206
211
exit (test_failed);
207
212
die ();
208
213
}
@@ -218,8 +223,8 @@ void Harness::schedule_next_case()
218
223
if (case_control.repeat & REPEAT_SETUP_TEARDOWN || !(case_control.repeat & (REPEAT_ON_TIMEOUT | REPEAT_ON_VALIDATE))) {
219
224
location = LOCATION_CASE_TEARDOWN;
220
225
221
- if (handlers. case_teardown ) {
222
- utest::v1::status_t status = handlers. case_teardown (case_current, case_passed, case_failed,
226
+ if (handlers-> case_teardown ) {
227
+ utest::v1::status_t status = handlers-> case_teardown (case_current, case_passed, case_failed,
223
228
case_failed ? failure_t (REASON_CASES, LOCATION_UNKNOWN) : failure_t (REASON_NONE));
224
229
if (status < STATUS_CONTINUE) raise_failure (REASON_CASE_TEARDOWN);
225
230
else if (status > signed (test_length)) raise_failure (REASON_CASE_INDEX);
@@ -298,9 +303,9 @@ void Harness::run_next_case()
298
303
UTEST_LOG_FUNCTION ();
299
304
if (case_current < (test_cases + test_length))
300
305
{
301
- handlers. case_setup = defaults. get_handler (case_current->setup_handler );
302
- handlers. case_teardown = defaults. get_handler (case_current->teardown_handler );
303
- handlers. case_failure = defaults. get_handler (case_current->failure_handler );
306
+ handlers-> case_setup = defaults-> get_handler (case_current->setup_handler );
307
+ handlers-> case_teardown = defaults-> get_handler (case_current->teardown_handler );
308
+ handlers-> case_failure = defaults-> get_handler (case_current->failure_handler );
304
309
305
310
if (case_current->is_empty ()) {
306
311
location = LOCATION_UNKNOWN;
@@ -321,7 +326,7 @@ void Harness::run_next_case()
321
326
322
327
if (setup_repeat & REPEAT_SETUP_TEARDOWN) {
323
328
location = LOCATION_CASE_SETUP;
324
- if (handlers. case_setup && (handlers. case_setup (case_current, test_index_of_case) != STATUS_CONTINUE)) {
329
+ if (handlers-> case_setup && (handlers-> case_setup (case_current, test_index_of_case) != STATUS_CONTINUE)) {
325
330
raise_failure (REASON_CASE_SETUP);
326
331
schedule_next_case ();
327
332
return ;
@@ -361,9 +366,9 @@ void Harness::run_next_case()
361
366
UTEST_LEAVE_CRITICAL_SECTION;
362
367
}
363
368
}
364
- else if (handlers. test_teardown ) {
369
+ else if (handlers-> test_teardown ) {
365
370
location = LOCATION_TEST_TEARDOWN;
366
- handlers. test_teardown (test_passed, test_failed, test_failed ? failure_t (REASON_CASES, LOCATION_UNKNOWN) : failure_t (REASON_NONE));
371
+ handlers-> test_teardown (test_passed, test_failed, test_failed ? failure_t (REASON_CASES, LOCATION_UNKNOWN) : failure_t (REASON_NONE));
367
372
test_cases = NULL ;
368
373
exit (test_failed);
369
374
} else {
0 commit comments