|
|
| 28 |
#include <limits> |
28 |
#include <limits> |
| 29 |
#include <stdint.h> |
29 |
#include <stdint.h> |
| 30 |
|
30 |
|
| 31 |
#include "ns3/system-wall-clock-ms.h" |
31 |
#include "system-wall-clock-ms.h" |
| 32 |
|
32 |
#include "deprecated.h" |
| 33 |
extern bool gBreakOnFailure; |
|
|
| 34 |
|
33 |
|
| 35 |
// |
34 |
// |
| 36 |
// Note on below macros: |
35 |
// Note on below macros: |
|
|
| 42 |
// defining a robust macro. |
41 |
// defining a robust macro. |
| 43 |
// |
42 |
// |
| 44 |
|
43 |
|
| 45 |
/** |
44 |
#define ASSERT_ON_FAILURE \ |
| 46 |
* \brief Convenience macro to extract the source directory of the current |
45 |
do { \ |
| 47 |
* source file. |
46 |
if (MustAssertOnFailure ()) \ |
| 48 |
* |
47 |
{ \ |
| 49 |
* \see TestCase::GetSourceDir |
48 |
*(int *)0 = 0; \ |
| 50 |
*/ |
49 |
} \ |
| 51 |
#define NS_TEST_SOURCEDIR \ |
50 |
} while (false) |
| 52 |
TestCase::GetSourceDir (__FILE__) |
51 |
|
|
|
52 |
#define CONTINUE_ON_FAILURE \ |
| 53 |
do { \ |
| 54 |
if (!MustContinueOnFailure ()) \ |
| 55 |
{ \ |
| 56 |
return; \ |
| 57 |
} \ |
| 58 |
} while (false) |
| 59 |
|
| 60 |
#define CONTINUE_ON_FAILURE_RETURNS_BOOL \ |
| 61 |
do { \ |
| 62 |
if (!MustContinueOnFailure ()) \ |
| 63 |
{ \ |
| 64 |
return IsStatusFailure (); \ |
| 65 |
} \ |
| 66 |
} while (false) |
| 67 |
|
| 68 |
|
| 53 |
|
69 |
|
| 54 |
// =========================================================================== |
70 |
// =========================================================================== |
| 55 |
// Test for equality (generic version) |
71 |
// Test for equality (generic version) |
|
|
| 58 |
/** |
74 |
/** |
| 59 |
* \internal |
75 |
* \internal |
| 60 |
*/ |
76 |
*/ |
| 61 |
#define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \ |
77 |
#define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \ |
| 62 |
do { \ |
78 |
do { \ |
| 63 |
if (!((actual) == (limit))) \ |
79 |
if (!((actual) == (limit))) \ |
| 64 |
{ \ |
80 |
{ \ |
| 65 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
81 |
ASSERT_ON_FAILURE; \ |
| 66 |
std::ostringstream msgStream; \ |
82 |
std::ostringstream msgStream; \ |
| 67 |
msgStream << msg; \ |
83 |
msgStream << msg; \ |
| 68 |
std::ostringstream actualStream; \ |
84 |
std::ostringstream actualStream; \ |
| 69 |
actualStream << actual; \ |
85 |
actualStream << actual; \ |
| 70 |
std::ostringstream limitStream; \ |
86 |
std::ostringstream limitStream; \ |
| 71 |
limitStream << limit; \ |
87 |
limitStream << limit; \ |
| 72 |
ReportTestFailure (std::string (# actual) + " (actual) == " + std::string (# limit) + " (limit)", \ |
88 |
ReportTestFailure (std::string (#actual) + " (actual) == " + \ |
| 73 |
actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
89 |
std::string (#limit) + " (limit)", \ |
| 74 |
if (!ContinueOnFailure ()) \ |
90 |
actualStream.str (), limitStream.str (), \ |
| 75 |
{ \ |
91 |
msgStream.str (), file, line); \ |
| 76 |
return; \ |
92 |
CONTINUE_ON_FAILURE; \ |
| 77 |
} \ |
93 |
} \ |
| 78 |
} \ |
94 |
} while (false) |
| 79 |
} while (false) |
|
|
| 80 |
|
95 |
|
| 81 |
/** |
96 |
/** |
| 82 |
* \brief Test that an actual and expected (limit) value are equal and report |
97 |
* \brief Test that an actual and expected (limit) value are equal and report |
|
|
| 110 |
/** |
125 |
/** |
| 111 |
* \internal |
126 |
* \internal |
| 112 |
*/ |
127 |
*/ |
| 113 |
#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \ |
128 |
#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \ |
| 114 |
do { \ |
129 |
do { \ |
| 115 |
if (!((actual) == (limit))) \ |
130 |
if (!((actual) == (limit))) \ |
| 116 |
{ \ |
131 |
{ \ |
| 117 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
132 |
ASSERT_ON_FAILURE; \ |
| 118 |
std::ostringstream msgStream; \ |
133 |
std::ostringstream msgStream; \ |
| 119 |
msgStream << msg; \ |
134 |
msgStream << msg; \ |
| 120 |
std::ostringstream actualStream; \ |
135 |
std::ostringstream actualStream; \ |
| 121 |
actualStream << actual; \ |
136 |
actualStream << actual; \ |
| 122 |
std::ostringstream limitStream; \ |
137 |
std::ostringstream limitStream; \ |
| 123 |
limitStream << limit; \ |
138 |
limitStream << limit; \ |
| 124 |
ReportTestFailure (std::string (# actual) + " (actual) == " + std::string (# limit) + " (limit)", \ |
139 |
ReportTestFailure (std::string (#actual) + " (actual) == " + \ |
| 125 |
actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
140 |
std::string (#limit) + " (limit)", \ |
| 126 |
if (!ContinueOnFailure ()) \ |
141 |
actualStream.str (), limitStream.str (), \ |
| 127 |
{ \ |
142 |
msgStream.str (), file, line); \ |
| 128 |
return true; \ |
143 |
CONTINUE_ON_FAILURE_RETURNS_BOOL; \ |
| 129 |
} \ |
144 |
} \ |
| 130 |
} \ |
145 |
} while (false) |
| 131 |
} while (false) |
|
|
| 132 |
|
146 |
|
| 133 |
/** |
147 |
/** |
| 134 |
* \brief Test that an actual and expected (limit) value are equal and report |
148 |
* \brief Test that an actual and expected (limit) value are equal and report |
|
|
| 168 |
* Required to avoid use of return statement which allows use in methods |
182 |
* Required to avoid use of return statement which allows use in methods |
| 169 |
* (esp. callbacks) returning void. |
183 |
* (esp. callbacks) returning void. |
| 170 |
*/ |
184 |
*/ |
| 171 |
#define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \ |
185 |
#define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \ |
| 172 |
do { \ |
186 |
do { \ |
| 173 |
if (!((actual) == (limit))) \ |
187 |
if (!((actual) == (limit))) \ |
| 174 |
{ \ |
188 |
{ \ |
| 175 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
189 |
ASSERT_ON_FAILURE; \ |
| 176 |
std::ostringstream msgStream; \ |
190 |
std::ostringstream msgStream; \ |
| 177 |
msgStream << msg; \ |
191 |
msgStream << msg; \ |
| 178 |
std::ostringstream actualStream; \ |
192 |
std::ostringstream actualStream; \ |
| 179 |
actualStream << actual; \ |
193 |
actualStream << actual; \ |
| 180 |
std::ostringstream limitStream; \ |
194 |
std::ostringstream limitStream; \ |
| 181 |
limitStream << limit; \ |
195 |
limitStream << limit; \ |
| 182 |
ReportTestFailure (std::string (# actual) + " (actual) == " + std::string (# limit) + " (limit)", \ |
196 |
ReportTestFailure (std::string (#actual) + " (actual) == " + \ |
| 183 |
actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
197 |
std::string (#limit) + " (limit)", \ |
| 184 |
} \ |
198 |
actualStream.str (), limitStream.str (), \ |
| 185 |
} while (false) |
199 |
msgStream.str (), file, line); \ |
|
|
200 |
} \ |
| 201 |
} while (false) |
| 186 |
|
202 |
|
| 187 |
/** |
203 |
/** |
| 188 |
* \brief Test that an actual and expected (limit) value are equal and report |
204 |
* \brief Test that an actual and expected (limit) value are equal and report |
|
|
| 221 |
/** |
237 |
/** |
| 222 |
* \internal |
238 |
* \internal |
| 223 |
*/ |
239 |
*/ |
| 224 |
#define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \ |
240 |
#define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \ |
| 225 |
do { \ |
241 |
do { \ |
| 226 |
if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \ |
242 |
if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \ |
| 227 |
{ \ |
243 |
{ \ |
| 228 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
244 |
ASSERT_ON_FAILURE; \ |
| 229 |
std::ostringstream msgStream; \ |
245 |
std::ostringstream msgStream; \ |
| 230 |
msgStream << msg; \ |
246 |
msgStream << msg; \ |
| 231 |
std::ostringstream actualStream; \ |
247 |
std::ostringstream actualStream; \ |
| 232 |
actualStream << actual; \ |
248 |
actualStream << actual; \ |
| 233 |
std::ostringstream limitStream; \ |
249 |
std::ostringstream limitStream; \ |
| 234 |
limitStream << limit << " +- " << tol; \ |
250 |
limitStream << limit << " +- " << tol; \ |
| 235 |
std::ostringstream condStream; \ |
251 |
std::ostringstream condStream; \ |
| 236 |
condStream << # actual << " (actual) < " << # limit << " (limit) + " << # tol << " (tol) && " << \ |
252 |
condStream << #actual << " (actual) < " << #limit \ |
| 237 |
# actual << " (actual) > " << # limit << " (limit) - " << # tol << " (tol)"; \ |
253 |
<< " (limit) + " << #tol << " (tol) && " \ |
| 238 |
ReportTestFailure (condStream.str (), actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
254 |
<< #actual << " (actual) > " << #limit \ |
| 239 |
if (!ContinueOnFailure ()) \ |
255 |
<< " (limit) - " << #tol << " (tol)"; \ |
| 240 |
{ \ |
256 |
ReportTestFailure (condStream.str (), actualStream.str (), \ |
| 241 |
return; \ |
257 |
limitStream.str (), msgStream.str (), \ |
| 242 |
} \ |
258 |
file, line); \ |
| 243 |
} \ |
259 |
CONTINUE_ON_FAILURE; \ |
| 244 |
} while (false) |
260 |
} \ |
|
|
261 |
} while (false) |
| 245 |
|
262 |
|
| 246 |
/** |
263 |
/** |
| 247 |
* \brief Test that actual and expected (limit) values are equal to plus or minus |
264 |
* \brief Test that actual and expected (limit) values are equal to plus or minus |
|
|
| 297 |
/** |
314 |
/** |
| 298 |
* \internal |
315 |
* \internal |
| 299 |
*/ |
316 |
*/ |
| 300 |
#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line) \ |
317 |
#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line) \ |
| 301 |
do { \ |
318 |
do { \ |
| 302 |
if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \ |
319 |
if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \ |
| 303 |
{ \ |
320 |
{ \ |
| 304 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
321 |
ASSERT_ON_FAILURE; \ |
| 305 |
std::ostringstream msgStream; \ |
322 |
std::ostringstream msgStream; \ |
| 306 |
msgStream << msg; \ |
323 |
msgStream << msg; \ |
| 307 |
std::ostringstream actualStream; \ |
324 |
std::ostringstream actualStream; \ |
| 308 |
actualStream << actual; \ |
325 |
actualStream << actual; \ |
| 309 |
std::ostringstream limitStream; \ |
326 |
std::ostringstream limitStream; \ |
| 310 |
limitStream << limit << " +- " << tol; \ |
327 |
limitStream << limit << " +- " << tol; \ |
| 311 |
std::ostringstream condStream; \ |
328 |
std::ostringstream condStream; \ |
| 312 |
condStream << # actual << " (actual) < " << # limit << " (limit) + " << # tol << " (tol) && " << \ |
329 |
condStream << #actual << " (actual) < " << #limit \ |
| 313 |
# actual << " (actual) > " << # limit << " (limit) - " << # tol << " (tol)"; \ |
330 |
<< " (limit) + " << #tol << " (tol) && " \ |
| 314 |
ReportTestFailure (condStream.str (), actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
331 |
<< #actual << " (actual) > " << #limit \ |
| 315 |
if (!ContinueOnFailure ()) \ |
332 |
<< " (limit) - " << #tol << " (tol)"; \ |
| 316 |
{ \ |
333 |
ReportTestFailure (condStream.str (), actualStream.str (), \ |
| 317 |
return true; \ |
334 |
limitStream.str (), msgStream.str (), \ |
| 318 |
} \ |
335 |
file, line); \ |
| 319 |
} \ |
336 |
CONTINUE_ON_FAILURE_RETURNS_BOOL; \ |
| 320 |
} while (false) |
337 |
} \ |
|
|
338 |
} while (false) |
| 321 |
|
339 |
|
| 322 |
/** |
340 |
/** |
| 323 |
* \brief Test that actual and expected (limit) values are equal to plus or minus |
341 |
* \brief Test that actual and expected (limit) values are equal to plus or minus |
|
|
| 379 |
* Required to avoid use of return statement which allows use in methods |
397 |
* Required to avoid use of return statement which allows use in methods |
| 380 |
* (esp. callbacks) returning void. |
398 |
* (esp. callbacks) returning void. |
| 381 |
*/ |
399 |
*/ |
| 382 |
#define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \ |
400 |
#define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \ |
| 383 |
do { \ |
401 |
do { \ |
| 384 |
if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \ |
402 |
if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \ |
| 385 |
{ \ |
403 |
{ \ |
| 386 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
404 |
ASSERT_ON_FAILURE; \ |
| 387 |
std::ostringstream msgStream; \ |
405 |
std::ostringstream msgStream; \ |
| 388 |
msgStream << msg; \ |
406 |
msgStream << msg; \ |
| 389 |
std::ostringstream actualStream; \ |
407 |
std::ostringstream actualStream; \ |
| 390 |
actualStream << actual; \ |
408 |
actualStream << actual; \ |
| 391 |
std::ostringstream limitStream; \ |
409 |
std::ostringstream limitStream; \ |
| 392 |
limitStream << limit << " +- " << tol; \ |
410 |
limitStream << limit << " +- " << tol; \ |
| 393 |
std::ostringstream condStream; \ |
411 |
std::ostringstream condStream; \ |
| 394 |
condStream << # actual << " (actual) < " << # limit << " (limit) + " << # tol << " (tol) && " << \ |
412 |
condStream << #actual << " (actual) < " << #limit \ |
| 395 |
# actual << " (actual) > " << # limit << " (limit) - " << # tol << " (tol)"; \ |
413 |
<< " (limit) + " << #tol << " (tol) && " \ |
| 396 |
ReportTestFailure (condStream.str (), actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
414 |
<< #actual << " (actual) > " << #limit \ |
| 397 |
} \ |
415 |
<< " (limit) - " << #tol << " (tol)"; \ |
| 398 |
} while (false) |
416 |
ReportTestFailure (condStream.str (), actualStream.str (), \ |
|
|
417 |
limitStream.str (), msgStream.str (), \ |
| 418 |
file, line); \ |
| 419 |
} \ |
| 420 |
} while (false) |
| 399 |
|
421 |
|
| 400 |
/** |
422 |
/** |
| 401 |
* \brief Test that actual and expected (limit) values are equal to plus or minus |
423 |
* \brief Test that actual and expected (limit) values are equal to plus or minus |
|
|
| 455 |
/** |
477 |
/** |
| 456 |
* \internal |
478 |
* \internal |
| 457 |
*/ |
479 |
*/ |
| 458 |
#define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \ |
480 |
#define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \ |
| 459 |
do { \ |
481 |
do { \ |
| 460 |
if (!((actual) != (limit))) \ |
482 |
if (!((actual) != (limit))) \ |
| 461 |
{ \ |
483 |
{ \ |
| 462 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
484 |
ASSERT_ON_FAILURE; \ |
| 463 |
std::ostringstream msgStream; \ |
485 |
std::ostringstream msgStream; \ |
| 464 |
msgStream << msg; \ |
486 |
msgStream << msg; \ |
| 465 |
std::ostringstream actualStream; \ |
487 |
std::ostringstream actualStream; \ |
| 466 |
actualStream << actual; \ |
488 |
actualStream << actual; \ |
| 467 |
std::ostringstream limitStream; \ |
489 |
std::ostringstream limitStream; \ |
| 468 |
limitStream << limit; \ |
490 |
limitStream << limit; \ |
| 469 |
ReportTestFailure (std::string (# actual) + " (actual) != " + std::string (# limit) + " (limit)", \ |
491 |
ReportTestFailure (std::string (#actual) + " (actual) != " + \ |
| 470 |
actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
492 |
std::string (#limit) + " (limit)", \ |
| 471 |
if (!ContinueOnFailure ()) \ |
493 |
actualStream.str (), limitStream.str (), \ |
| 472 |
{ \ |
494 |
msgStream.str (), file, line); \ |
| 473 |
return; \ |
495 |
CONTINUE_ON_FAILURE; \ |
| 474 |
} \ |
496 |
} \ |
| 475 |
} \ |
497 |
} while (false) |
| 476 |
} while (false) |
|
|
| 477 |
|
498 |
|
| 478 |
/** |
499 |
/** |
| 479 |
* \brief Test that an actual and expected (limit) value are equal and report |
500 |
* \brief Test that an actual and expected (limit) value are equal and report |
|
|
| 506 |
/** |
527 |
/** |
| 507 |
* \internal |
528 |
* \internal |
| 508 |
*/ |
529 |
*/ |
| 509 |
#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \ |
530 |
#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \ |
| 510 |
do { \ |
531 |
do { \ |
| 511 |
if (!((actual) != (limit))) \ |
532 |
if (!((actual) != (limit))) \ |
| 512 |
{ \ |
533 |
{ \ |
| 513 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
534 |
ASSERT_ON_FAILURE; \ |
| 514 |
std::ostringstream msgStream; \ |
535 |
std::ostringstream msgStream; \ |
| 515 |
msgStream << msg; \ |
536 |
msgStream << msg; \ |
| 516 |
std::ostringstream actualStream; \ |
537 |
std::ostringstream actualStream; \ |
| 517 |
actualStream << actual; \ |
538 |
actualStream << actual; \ |
| 518 |
std::ostringstream limitStream; \ |
539 |
std::ostringstream limitStream; \ |
| 519 |
limitStream << limit; \ |
540 |
limitStream << limit; \ |
| 520 |
ReportTestFailure (std::string (# actual) + " (actual) != " + std::string (# limit) + " (limit)", \ |
541 |
ReportTestFailure (std::string (#actual) + " (actual) != " + \ |
| 521 |
actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
542 |
std::string (#limit) + " (limit)", \ |
| 522 |
if (!ContinueOnFailure ()) \ |
543 |
actualStream.str (), limitStream.str (), \ |
| 523 |
{ \ |
544 |
msgStream.str (), file, line); \ |
| 524 |
return true; \ |
545 |
CONTINUE_ON_FAILURE_RETURNS_BOOL; \ |
| 525 |
} \ |
546 |
} \ |
| 526 |
} \ |
547 |
} while (false) |
| 527 |
} while (false) |
|
|
| 528 |
|
548 |
|
| 529 |
/** |
549 |
/** |
| 530 |
* \brief Test that an actual and expected (limit) value are equal and report |
550 |
* \brief Test that an actual and expected (limit) value are equal and report |
|
|
| 563 |
* Required to avoid use of return statement which allows use in methods |
583 |
* Required to avoid use of return statement which allows use in methods |
| 564 |
* (callbacks) returning void. |
584 |
* (callbacks) returning void. |
| 565 |
*/ |
585 |
*/ |
| 566 |
#define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \ |
586 |
#define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \ |
| 567 |
do { \ |
587 |
do { \ |
| 568 |
if (!((actual) != (limit))) \ |
588 |
if (!((actual) != (limit))) \ |
| 569 |
{ \ |
589 |
{ \ |
| 570 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
590 |
ASSERT_ON_FAILURE; \ |
| 571 |
std::ostringstream msgStream; \ |
591 |
std::ostringstream msgStream; \ |
| 572 |
msgStream << msg; \ |
592 |
msgStream << msg; \ |
| 573 |
std::ostringstream actualStream; \ |
593 |
std::ostringstream actualStream; \ |
| 574 |
actualStream << actual; \ |
594 |
actualStream << actual; \ |
| 575 |
std::ostringstream limitStream; \ |
595 |
std::ostringstream limitStream; \ |
| 576 |
limitStream << limit; \ |
596 |
limitStream << limit; \ |
| 577 |
ReportTestFailure (std::string (# actual) + " (actual) != " + std::string (# limit) + " (limit)", \ |
597 |
ReportTestFailure (std::string (#actual) + " (actual) != " + \ |
| 578 |
actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
598 |
std::string (#limit) + " (limit)", \ |
| 579 |
} \ |
599 |
actualStream.str (), limitStream.str (), \ |
| 580 |
} while (false) |
600 |
msgStream.str (), file, line); \ |
|
|
601 |
} \ |
| 602 |
} while (false) |
| 581 |
|
603 |
|
| 582 |
/** |
604 |
/** |
| 583 |
* \brief Test that an actual and expected (limit) value are equal and report |
605 |
* \brief Test that an actual and expected (limit) value are equal and report |
|
|
| 614 |
/** |
636 |
/** |
| 615 |
* \internal |
637 |
* \internal |
| 616 |
*/ |
638 |
*/ |
| 617 |
#define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \ |
639 |
#define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \ |
| 618 |
do { \ |
640 |
do { \ |
| 619 |
if (!((actual) < (limit))) \ |
641 |
if (!((actual) < (limit))) \ |
| 620 |
{ \ |
642 |
{ \ |
| 621 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
643 |
ASSERT_ON_FAILURE; \ |
| 622 |
std::ostringstream msgStream; \ |
644 |
std::ostringstream msgStream; \ |
| 623 |
msgStream << msg; \ |
645 |
msgStream << msg; \ |
| 624 |
std::ostringstream actualStream; \ |
646 |
std::ostringstream actualStream; \ |
| 625 |
actualStream << actual; \ |
647 |
actualStream << actual; \ |
| 626 |
std::ostringstream limitStream; \ |
648 |
std::ostringstream limitStream; \ |
| 627 |
limitStream << limit; \ |
649 |
limitStream << limit; \ |
| 628 |
ReportTestFailure (std::string (# actual) + " (actual) < " + std::string (# limit) + " (limit)", \ |
650 |
ReportTestFailure (std::string (#actual) + " (actual) < " + \ |
| 629 |
actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
651 |
std::string (#limit) + " (limit)", \ |
| 630 |
if (!ContinueOnFailure ()) \ |
652 |
actualStream.str (), limitStream.str (), \ |
| 631 |
{ \ |
653 |
msgStream.str (), file, line); \ |
| 632 |
return; \ |
654 |
CONTINUE_ON_FAILURE; \ |
| 633 |
} \ |
655 |
} \ |
| 634 |
} \ |
656 |
} while (false) |
| 635 |
} while (false) |
|
|
| 636 |
|
657 |
|
| 637 |
/** |
658 |
/** |
| 638 |
* \brief Test that an actual value is less than a limit and report and abort |
659 |
* \brief Test that an actual value is less than a limit and report and abort |
|
|
| 658 |
* Required to avoid use of return statement which allows use in methods |
679 |
* Required to avoid use of return statement which allows use in methods |
| 659 |
* (callbacks) returning void. |
680 |
* (callbacks) returning void. |
| 660 |
*/ |
681 |
*/ |
| 661 |
#define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \ |
682 |
#define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \ |
| 662 |
do { \ |
683 |
do { \ |
| 663 |
if (!((actual) < (limit))) \ |
684 |
if (!((actual) < (limit))) \ |
| 664 |
{ \ |
685 |
{ \ |
| 665 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
686 |
ASSERT_ON_FAILURE; \ |
| 666 |
std::ostringstream msgStream; \ |
687 |
std::ostringstream msgStream; \ |
| 667 |
msgStream << msg; \ |
688 |
msgStream << msg; \ |
| 668 |
std::ostringstream actualStream; \ |
689 |
std::ostringstream actualStream; \ |
| 669 |
actualStream << actual; \ |
690 |
actualStream << actual; \ |
| 670 |
std::ostringstream limitStream; \ |
691 |
std::ostringstream limitStream; \ |
| 671 |
limitStream << limit; \ |
692 |
limitStream << limit; \ |
| 672 |
ReportTestFailure (std::string (# actual) + " (actual) < " + std::string (# limit) + " (limit)", \ |
693 |
ReportTestFailure (std::string (#actual) + " (actual) < " + \ |
| 673 |
actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
694 |
std::string (#limit) + " (limit)", \ |
| 674 |
} \ |
695 |
actualStream.str (), limitStream.str (), \ |
| 675 |
} while (false) |
696 |
msgStream.str (), file, line); \ |
|
|
697 |
} \ |
| 698 |
} while (false) |
| 676 |
|
699 |
|
| 677 |
/** |
700 |
/** |
| 678 |
* \brief Test that an actual value is less than a limit and report if not. |
701 |
* \brief Test that an actual value is less than a limit and report if not. |
|
|
| 698 |
/** |
721 |
/** |
| 699 |
* \internal |
722 |
* \internal |
| 700 |
*/ |
723 |
*/ |
| 701 |
#define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \ |
724 |
#define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \ |
| 702 |
do { \ |
725 |
do { \ |
| 703 |
if (!((actual) > (limit))) \ |
726 |
if (!((actual) > (limit))) \ |
| 704 |
{ \ |
727 |
{ \ |
| 705 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
728 |
ASSERT_ON_FAILURE; \ |
| 706 |
std::ostringstream msgStream; \ |
729 |
std::ostringstream msgStream; \ |
| 707 |
msgStream << msg; \ |
730 |
msgStream << msg; \ |
| 708 |
std::ostringstream actualStream; \ |
731 |
std::ostringstream actualStream; \ |
| 709 |
actualStream << actual; \ |
732 |
actualStream << actual; \ |
| 710 |
std::ostringstream limitStream; \ |
733 |
std::ostringstream limitStream; \ |
| 711 |
limitStream << limit; \ |
734 |
limitStream << limit; \ |
| 712 |
ReportTestFailure (std::string (# actual) + " (actual) > " + std::string (# limit) + " (limit)", \ |
735 |
ReportTestFailure (std::string (#actual) + " (actual) > " + \ |
| 713 |
actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
736 |
std::string (#limit) + " (limit)", \ |
| 714 |
if (!ContinueOnFailure ()) \ |
737 |
actualStream.str (), limitStream.str (), \ |
| 715 |
{ \ |
738 |
msgStream.str (), file, line); \ |
| 716 |
return; \ |
739 |
CONTINUE_ON_FAILURE; \ |
| 717 |
} \ |
740 |
} \ |
| 718 |
} \ |
741 |
} while (false) |
| 719 |
} while (false) |
|
|
| 720 |
|
742 |
|
| 721 |
/** |
743 |
/** |
| 722 |
* \brief Test that an actual value is greater than a limit and report and abort |
744 |
* \brief Test that an actual value is greater than a limit and report and abort |
|
|
| 742 |
* Required to avoid use of return statement which allows use in methods |
764 |
* Required to avoid use of return statement which allows use in methods |
| 743 |
* (callbacks) returning void. |
765 |
* (callbacks) returning void. |
| 744 |
*/ |
766 |
*/ |
| 745 |
#define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \ |
767 |
#define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \ |
| 746 |
do { \ |
768 |
do { \ |
| 747 |
if (!((actual) > (limit))) \ |
769 |
if (!((actual) > (limit))) \ |
| 748 |
{ \ |
770 |
{ \ |
| 749 |
if (gBreakOnFailure) { *(int *)0 = 0; } \ |
771 |
ASSERT_ON_FAILURE; \ |
| 750 |
std::ostringstream msgStream; \ |
772 |
std::ostringstream msgStream; \ |
| 751 |
msgStream << msg; \ |
773 |
msgStream << msg; \ |
| 752 |
std::ostringstream actualStream; \ |
774 |
std::ostringstream actualStream; \ |
| 753 |
actualStream << actual; \ |
775 |
actualStream << actual; \ |
| 754 |
std::ostringstream limitStream; \ |
776 |
std::ostringstream limitStream; \ |
| 755 |
limitStream << limit; \ |
777 |
limitStream << limit; \ |
| 756 |
ReporTesttFailure (std::string (# actual) + " (actual) > " + std::string (# limit) + " (limit)", \ |
778 |
ReportTestFailure (std::string (#actual) + " (actual) > " + \ |
| 757 |
actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ |
779 |
std::string (#limit) + " (limit)", \ |
| 758 |
} \ |
780 |
actualStream.str (), limitStream.str (), \ |
| 759 |
} while (false) |
781 |
msgStream.str (), file, line); \ |
|
|
782 |
} \ |
| 783 |
} while (false) |
| 760 |
|
784 |
|
| 761 |
/** |
785 |
/** |
| 762 |
* \brief Test that an actual value is greater than a limit and report if not. |
786 |
* \brief Test that an actual value is greater than a limit and report if not. |
|
|
| 795 |
* \param epsilon The second of double precision floating point numberss to compare |
819 |
* \param epsilon The second of double precision floating point numberss to compare |
| 796 |
* \returns Returns true if the doubles are equal to a precision defined by epsilon |
820 |
* \returns Returns true if the doubles are equal to a precision defined by epsilon |
| 797 |
*/ |
821 |
*/ |
| 798 |
bool TestDoubleIsEqual (const double a, const double b, const double epsilon = std::numeric_limits<double>::epsilon ()); |
822 |
bool TestDoubleIsEqual (const double a, const double b, |
|
|
823 |
const double epsilon = std::numeric_limits<double>::epsilon ()); |
| 824 |
|
| 825 |
class TestRunnerImpl; |
| 799 |
|
826 |
|
| 800 |
/** |
827 |
/** |
| 801 |
* \brief A single test case. |
828 |
* \brief encapsulates test code |
|
|
829 |
* |
| 830 |
* To allow a new test to be run within the ns-3 test framework, users |
| 831 |
* need to create subclasses of this base class, override the DoRun method, |
| 832 |
* and use the NS_TEST_* macros within DoRun. |
| 802 |
*/ |
833 |
*/ |
| 803 |
class TestCase |
834 |
class TestCase |
| 804 |
{ |
835 |
{ |
| 805 |
public: |
836 |
public: |
| 806 |
TestCase (std::string name); |
|
|
| 807 |
virtual ~TestCase (); |
837 |
virtual ~TestCase (); |
| 808 |
|
838 |
|
| 809 |
/** |
|
|
| 810 |
* \brief Run this test case. |
| 811 |
*/ |
| 812 |
void Run (void); |
| 813 |
|
| 814 |
/** |
| 815 |
* \brief Set the verbosity of this test case. |
| 816 |
* \param verbose Whether or not to turn on any output the |
| 817 |
* test case may provide. |
| 818 |
*/ |
| 819 |
void SetVerbose (bool verbose); |
| 820 |
|
| 821 |
/** |
| 822 |
* \brief Tell the test case whether or not to continue testing if an error is |
| 823 |
* detected. |
| 824 |
* |
| 825 |
* Typically, test cases depend on some number of individual tests. Often, |
| 826 |
* these tests build on functionality that has been previously verified. In |
| 827 |
* this case, subsequent test failures may simply be alternate manifestations |
| 828 |
* of previously detected errors. Some developers may only be interested in |
| 829 |
* seeing the first failure. Other developers may want to see all the |
| 830 |
* information they can get, and want to see all failures. This is a matter |
| 831 |
* of individual preference, so we allow this behavior to be configured. |
| 832 |
* |
| 833 |
* \param continueOnFailure If true, run tests after a failure has been |
| 834 |
* detected, otherwise stop on the first error. |
| 835 |
*/ |
| 836 |
void SetContinueOnFailure (bool continueOnFailure); |
| 837 |
|
| 838 |
/** |
| 839 |
* \brief Set the name of this test case. |
| 840 |
*/ |
| 841 |
void SetName (std::string name); |
| 842 |
|
| 843 |
/** |
| 844 |
* \brief Get the name of this test case. |
| 845 |
*/ |
| 846 |
std::string GetName (void); |
| 847 |
|
| 848 |
/** |
| 849 |
* \brief Set the base directory of the ns-3 distribution. |
| 850 |
*/ |
| 851 |
void SetBaseDir (std::string dir); |
| 852 |
|
| 853 |
/** |
| 854 |
* \brief Get the base directory of the ns-3 distribution. |
| 855 |
*/ |
| 856 |
std::string GetBaseDir (void); |
| 857 |
|
| 858 |
/** |
| 859 |
* \brief Set the temporary file directory (where to write temporary files). |
| 860 |
*/ |
| 861 |
void SetTempDir (std::string dir); |
| 862 |
|
| 863 |
/** |
| 864 |
* \brief Get the temporary file directory . |
| 865 |
*/ |
| 866 |
std::string GetTempDir (void); |
| 867 |
|
| 868 |
/** |
| 869 |
* \brief Get the source directory of the current source file. |
| 870 |
* |
| 871 |
* One of the basic models of the test environment is that dedicated test- |
| 872 |
* and response vectors live in the same directory as the source file. So it |
| 873 |
* is a common operation to figure out what directory a given source file lives |
| 874 |
* in. |
| 875 |
* |
| 876 |
* __FILE__ provides almost all of what we need, but in the gnu toolchain it |
| 877 |
* comes out as something like "../src/core/pcap-file-test-suite.cc". |
| 878 |
* |
| 879 |
* We really don't want to have any dependency on the directory out of which a |
| 880 |
* test is run, so we ask that any test-runner give us the base directory of the |
| 881 |
* distribution, which is set via TestCase::SetBaseDir(). That string will look |
| 882 |
* something like "/home/user/repos/ns-3-allinone/ns-3-dev". |
| 883 |
* |
| 884 |
* This function stitches the two pieces together and removes the file name to |
| 885 |
* return something like "/home/user/repos/ns-3-allinone/ns-3-dev/src/core/". |
| 886 |
* |
| 887 |
* \param file The current source file name relative to the base directory. |
| 888 |
* \returns The current source directory. |
| 889 |
* |
| 890 |
* \warning Always call this function as GetSourceDir (__FILE__) or use the |
| 891 |
* convenience macro NS_TEST_SOURCEDIR. |
| 892 |
*/ |
| 893 |
std::string GetSourceDir (std::string file); |
| 894 |
|
| 895 |
/** |
| 896 |
* \brief Set the stream to which status and result messages will be written. |
| 897 |
* |
| 898 |
* We really don't want to have to pass an ofstream around to every function |
| 899 |
* and we especially don't want to have to make our clients plumb an ofstream |
| 900 |
* around so we need to save it. Since file streams are not designed to be |
| 901 |
* copied or assigned (what does it mean to have duplicate streams to a file) |
| 902 |
* we have to stash a pointer to the stream. |
| 903 |
* |
| 904 |
* \param ofs output file stream |
| 905 |
*/ |
| 906 |
void SetStream (std::ofstream *ofs); |
| 907 |
|
| 908 |
/** |
| 909 |
* \brief Get the stream to which status and result messages will be written. |
| 910 |
*/ |
| 911 |
std::ofstream *GetStream (void); |
| 912 |
|
| 913 |
/** |
| 914 |
* \brief Manually update the error status of this test case. |
| 915 |
* |
| 916 |
* This does a logical OR of the error argument with the current error status. |
| 917 |
* If the argument is false, it does nothing. If the argument is true, it |
| 918 |
* sets the error status to "an error has occurred." |
| 919 |
* |
| 920 |
* \param error The status to use to update the test case error status |
| 921 |
*/ |
| 922 |
void UpdateErrorStatus (bool error); |
| 923 |
|
| 924 |
/** |
| 925 |
* \brief Manually set the error status of this test case. |
| 926 |
* |
| 927 |
* This sets the current error status to the argument provided. Can be used |
| 928 |
* to reset any previous errors if the argument is false. |
| 929 |
* |
| 930 |
* \param error The status to use to set the test case error status |
| 931 |
*/ |
| 932 |
void SetErrorStatus (bool error); |
| 933 |
|
| 934 |
/** |
| 935 |
* \brief Get the error status of this test case. |
| 936 |
*/ |
| 937 |
bool GetErrorStatus (void); |
| 938 |
|
| 939 |
/** |
| 940 |
* \brief Should test cases continue running in the presence of errors? |
| 941 |
* \returns True if the test case should continue, false otherwise. |
| 942 |
*/ |
| 943 |
bool ContinueOnFailure (void); |
| 944 |
|
| 945 |
/** |
| 946 |
* \brief Issue a test report than the test suite has started running. |
| 947 |
*/ |
| 948 |
void ReportStart (void); |
| 949 |
|
| 950 |
/** |
| 951 |
* \brief Issue a test report than the test case has declared success. |
| 952 |
*/ |
| 953 |
void ReportCaseSuccess (void); |
| 954 |
|
| 955 |
/** |
| 956 |
* \brief Issue a test report than the test case has declared failure. |
| 957 |
*/ |
| 958 |
void ReportCaseFailure (void); |
| 959 |
|
| 960 |
/** |
| 961 |
* \brief Issue a test report than the test case has found an error and |
| 962 |
* report the details. |
| 963 |
*/ |
| 964 |
void ReportTestFailure (std::string cond, std::string actual, std::string limit, std::string message, |
| 965 |
std::string file, int32_t line); |
| 966 |
|
| 967 |
/** |
| 968 |
* \brief Issue a test report than the test case has completed its run. |
| 969 |
*/ |
| 970 |
void ReportEnd (void); |
| 971 |
|
| 972 |
protected: |
839 |
protected: |
| 973 |
/** |
840 |
/** |
| 974 |
* \internal |
841 |
* \param name the name of the new test created |
| 975 |
* \brief Implementation of reporting method for the start of the test case. |
|
|
| 976 |
*/ |
842 |
*/ |
| 977 |
virtual void DoReportStart (void); |
843 |
TestCase (std::string name); |
| 978 |
|
844 |
|
| 979 |
/** |
845 |
/** |
| 980 |
* \internal |
846 |
* \brief Add an individual test case to this test suite. |
| 981 |
* \brief Implementation of reporting method for success of the test case. |
847 |
* |
|
|
848 |
* \param testCase Pointer to the test case object to be added. |
| 982 |
*/ |
849 |
*/ |
| 983 |
virtual void DoReportCaseSuccess (void); |
850 |
void AddTestCase (TestCase *testCase); |
| 984 |
|
851 |
|
| 985 |
/** |
852 |
/** |
| 986 |
* \internal |
853 |
* \param directory the directory where the test data is located |
| 987 |
* \brief Implementation of reporting method for failure of the test case. |
854 |
* |
|
|
855 |
* In general, this method is invoked as SetDataDir (NS_TEST_SOURCEDIR); |
| 988 |
*/ |
856 |
*/ |
| 989 |
virtual void DoReportCaseFailure (void); |
857 |
void SetDataDir (std::string directory); |
| 990 |
|
858 |
|
| 991 |
/** |
859 |
/** |
| 992 |
* \internal |
860 |
* This method is deprecated. IsStatusFailure replaces it. |
| 993 |
* \brief Implementation of reporting method for failure of the test case. |
|
|
| 994 |
*/ |
861 |
*/ |
| 995 |
virtual void DoReportTestFailure (std::string cond, std::string actual, std::string limit, std::string message, |
862 |
bool GetErrorStatus (void) const NS_DEPRECATED; |
| 996 |
std::string file, int32_t line); |
863 |
/** |
|
|
864 |
* \return true if the tests have failed, false otherwise. |
| 865 |
*/ |
| 866 |
bool IsStatusFailure (void) const; |
| 867 |
/** |
| 868 |
* \return true if the tests have succeeded, false otherwise. |
| 869 |
*/ |
| 870 |
bool IsStatusSuccess (void) const; |
| 871 |
|
| 872 |
// The methods below are used only by test macros and should not |
| 873 |
// be used by normal users. |
| 874 |
void ReportTestFailure (std::string cond, std::string actual, |
| 875 |
std::string limit, std::string message, |
| 876 |
std::string file, int32_t line); |
| 877 |
bool MustAssertOnFailure (void) const; |
| 878 |
bool MustContinueOnFailure (void) const; |
| 879 |
std::string CreateDataDirFilename (std::string filename); |
| 880 |
std::string CreateTempDirFilename (std::string filename); |
| 881 |
private: |
| 882 |
friend class TestRunnerImpl; |
| 997 |
|
883 |
|
| 998 |
/** |
884 |
/** |
| 999 |
* \internal |
|
|
| 1000 |
* \brief Implementation of reporting method for the end of the test case. |
| 1001 |
*/ |
| 1002 |
virtual void DoReportEnd (void); |
| 1003 |
|
| 1004 |
/** |
| 1005 |
* \internal |
| 1006 |
* \brief Implementation to do any local setup required for this test case. |
885 |
* \brief Implementation to do any local setup required for this test case. |
|
|
886 |
* |
| 887 |
* Subclasses should override this method to perform any costly per-test setup |
| 888 |
* before DoRun is invoked. |
| 1007 |
*/ |
889 |
*/ |
| 1008 |
virtual void DoSetup (void); |
890 |
virtual void DoSetup (void); |
| 1009 |
|
891 |
|
| 1010 |
/** |
892 |
/** |
| 1011 |
* \internal |
|
|
| 1012 |
* \brief Implementation to actually run this test case. |
893 |
* \brief Implementation to actually run this test case. |
|
|
894 |
* |
| 895 |
* Subclasses should override this method to conduct their tests. |
| 1013 |
*/ |
896 |
*/ |
| 1014 |
virtual void DoRun (void) = 0; |
897 |
virtual void DoRun (void) = 0; |
| 1015 |
|
898 |
|
| 1016 |
/** |
899 |
/** |
| 1017 |
* \internal |
|
|
| 1018 |
* \brief Implementation to do any local setup required for this test case. |
900 |
* \brief Implementation to do any local setup required for this test case. |
|
|
901 |
* |
| 902 |
* Subclasses should override this method to perform any costly per-test teardown |
| 1019 |
*/ |
903 |
*/ |
| 1020 |
virtual void DoTeardown (void); |
904 |
virtual void DoTeardown (void); |
| 1021 |
|
905 |
|
| 1022 |
private: |
906 |
// forbid copying objects |
| 1023 |
TestCase (TestCase& tc); |
907 |
TestCase (TestCase& tc); |
| 1024 |
TestCase& operator= (TestCase& tc); |
908 |
TestCase& operator= (TestCase& tc); |
| 1025 |
|
909 |
|
| 1026 |
SystemWallClockMs m_msClock; |
910 |
// methods called by TestRunnerImpl |
|
|
911 |
void Run (TestRunnerImpl *runner); |
| 912 |
std::string GetName (void) const; |
| 913 |
bool IsFailed (void) const; |
| 914 |
|
| 915 |
|
| 916 |
struct Result; |
| 917 |
|
| 918 |
TestCase *m_parent; |
| 919 |
std::vector<TestCase *> m_children; |
| 920 |
std::string m_dataDir; |
| 921 |
TestRunnerImpl *m_runner; |
| 922 |
struct Result *m_result; |
| 1027 |
std::string m_name; |
923 |
std::string m_name; |
| 1028 |
bool m_verbose; |
|
|
| 1029 |
bool m_continueOnFailure; |
| 1030 |
bool m_detailsReported; |
| 1031 |
std::string m_basedir; |
| 1032 |
std::string m_tempdir; |
| 1033 |
std::ofstream *m_ofs; |
| 1034 |
bool m_error; |
| 1035 |
}; |
924 |
}; |
| 1036 |
|
925 |
|
| 1037 |
/** |
926 |
/** |
| 1038 |
* \brief A suite of tests to run. |
927 |
* \brief A suite of tests to run. |
| 1039 |
*/ |
928 |
*/ |
| 1040 |
class TestSuite |
929 |
class TestSuite : public TestCase |
| 1041 |
{ |
930 |
{ |
| 1042 |
public: |
931 |
public: |
| 1043 |
/** |
932 |
/** |
| 1044 |
* \enum TestType |
933 |
* \enum TestType |
| 1045 |
* \brief Type of test. |
934 |
* \brief Type of test. |
| 1046 |
*/ |
935 |
*/ |
| 1047 |
enum TestType { |
936 |
enum Type { |
|
|
937 |
ALL = 0, |
| 1048 |
BVT = 1, /**< This test suite implements a Build Verification Test */ |
938 |
BVT = 1, /**< This test suite implements a Build Verification Test */ |
| 1049 |
UNIT, /**< This test suite implements a Unit Test */ |
939 |
UNIT, /**< This test suite implements a Unit Test */ |
| 1050 |
SYSTEM, /**< This test suite implements a System Test */ |
940 |
SYSTEM, /**< This test suite implements a System Test */ |
|
|
| 1058 |
* \param name The name of the test suite. |
948 |
* \param name The name of the test suite. |
| 1059 |
* \param type The TestType of the test suite (defaults to UNIT test). |
949 |
* \param type The TestType of the test suite (defaults to UNIT test). |
| 1060 |
*/ |
950 |
*/ |
| 1061 |
TestSuite (std::string name, TestType type = UNIT); |
951 |
TestSuite (std::string name, Type type = UNIT); |
| 1062 |
|
|
|
| 1063 |
/** |
| 1064 |
* \brief Destroy a test suite. |
| 1065 |
*/ |
| 1066 |
virtual ~TestSuite (); |
| 1067 |
|
| 1068 |
/** |
| 1069 |
* \brief Run this test suite. |
| 1070 |
* |
| 1071 |
* \returns Boolean sense of "an error has occurred." |
| 1072 |
*/ |
| 1073 |
bool Run (void); |
| 1074 |
|
| 1075 |
/** |
| 1076 |
* \brief Add an individual test case to this test suite. |
| 1077 |
* |
| 1078 |
* \param testCase Pointer to the test case object to be added. |
| 1079 |
* \returns Integer assigned as identifer of the provided test case. |
| 1080 |
*/ |
| 1081 |
uint32_t AddTestCase (TestCase *testCase); |
| 1082 |
|
| 1083 |
/** |
| 1084 |
* \brief Get the number of test cases that have been added to this test suite. |
| 1085 |
* |
| 1086 |
* \returns Number of test cases in the suite. |
| 1087 |
*/ |
| 1088 |
uint32_t GetNTestCases (void); |
| 1089 |
|
| 1090 |
/** |
| 1091 |
* \brief Get the test case at index i. |
| 1092 |
*/ |
| 1093 |
TestCase *GetTestCase (uint32_t i); |
| 1094 |
|
952 |
|
| 1095 |
/** |
953 |
/** |
| 1096 |
* \brief get the kind of test this test suite implements |
954 |
* \brief get the kind of test this test suite implements |
| 1097 |
* |
955 |
* |
| 1098 |
* \returns the TestType of the suite. |
956 |
* \returns the Type of the suite. |
| 1099 |
*/ |
957 |
*/ |
| 1100 |
TestType GetTestType (void); |
958 |
TestSuite::Type GetTestType (void); |
| 1101 |
|
959 |
|
| 1102 |
/** |
960 |
private: |
| 1103 |
* \brief Set the verbosity of this test suite. |
|
|
| 1104 |
* \param verbose Whether or not to turn on any output the |
| 1105 |
* test case may provide. |
| 1106 |
*/ |
| 1107 |
void SetVerbose (bool verbose); |
| 1108 |
|
| 1109 |
/** |
| 1110 |
* \brief Tell the test suite and its test cases whether or not to continue |
| 1111 |
* testing if an error is detected. |
| 1112 |
* |
| 1113 |
* Typically, test suites depend on some number of test cases, which in turn |
| 1114 |
* depend on some number of individual tests. Often, these tests build on |
| 1115 |
* functionality that has been previously verified. In this case, subsequent |
| 1116 |
* test failures may simply be alternate manifestations of previously detected |
| 1117 |
* errors. Some developers may only be interested in seeing the first failure. |
| 1118 |
* Other developers may want to see all the information they can get, and want |
| 1119 |
* to see all failures. This is a matter of individual preference, so we allow |
| 1120 |
* this behavior to be configured. |
| 1121 |
* |
| 1122 |
* \param continueOnFailure If true, continue running test cases after a |
| 1123 |
* failure has been detected, otherwise stop on the |
| 1124 |
* first error. |
| 1125 |
*/ |
| 1126 |
void SetContinueOnFailure (bool continueOnFailure); |
| 1127 |
|
| 1128 |
/** |
| 1129 |
* \brief Set the name of this test suite. |
| 1130 |
*/ |
| 1131 |
void SetName (std::string name); |
| 1132 |
|
| 1133 |
/** |
| 1134 |
* \brief Get the name of this test suite. |
| 1135 |
*/ |
| 1136 |
std::string GetName (void); |
| 1137 |
|
| 1138 |
/** |
| 1139 |
* \brief Set the base directory of the ns-3 distribution. |
| 1140 |
*/ |
| 1141 |
void SetBaseDir (std::string basedir); |
| 1142 |
|
| 1143 |
/** |
| 1144 |
* \brief Get the base directory of the ns-3 distribution. |
| 1145 |
*/ |
| 1146 |
std::string GetBaseDir (void); |
| 1147 |
|
| 1148 |
/** |
| 1149 |
* \brief Set the temporary file directory (where to write temporary files). |
| 1150 |
*/ |
| 1151 |
void SetTempDir (std::string dir); |
| 1152 |
|
| 1153 |
/** |
| 1154 |
* \brief Get the temporary file directory. |
| 1155 |
*/ |
| 1156 |
std::string GetTempDir (void); |
| 1157 |
|
| 1158 |
/** |
| 1159 |
* \brief Set the stream to which status and result messages will be written. |
| 1160 |
* |
| 1161 |
* We really don't want to have to pass an ofstream around to every function |
| 1162 |
* and we especially don't want to have to make our clients plumb an ofstream |
| 1163 |
* around so we need to save it. Since file streams are not designed to be |
| 1164 |
* copied or assigned (what does it mean to have duplicate streams to a file) |
| 1165 |
* we have to stash a pointer to the stream. |
| 1166 |
* \param ofs output file stream |
| 1167 |
*/ |
| 1168 |
void SetStream (std::ofstream *ofs); |
| 1169 |
|
| 1170 |
/** |
| 1171 |
* \brief Manually update the error status of this test suite. |
| 1172 |
* |
| 1173 |
* This does a logical OR of the error argument with the current error status. |
| 1174 |
* If the argument is false, it does nothing. If the argument is true, it |
| 1175 |
* sets the error status to "an error has occurred." |
| 1176 |
* |
| 1177 |
* \param error The status to use to update the test suite error status |
| 1178 |
*/ |
| 1179 |
void UpdateErrorStatus (bool error); |
| 1180 |
|
| 1181 |
/** |
| 1182 |
* \brief Manually set the error status of this test suite. |
| 1183 |
* |
| 1184 |
* This sets the current error status to the argument provided. Can be used |
| 1185 |
* to reset any previous errors if the argument is false. |
| 1186 |
* |
| 1187 |
* \param error The status to use to set the test suite error status |
| 1188 |
*/ |
| 1189 |
void SetErrorStatus (bool error); |
| 1190 |
|
| 1191 |
/** |
| 1192 |
* \brief Get the error status of this test suite. |
| 1193 |
*/ |
| 1194 |
bool GetErrorStatus (void); |
| 1195 |
|
| 1196 |
/** |
| 1197 |
* \brief Should test suite continue running cases in the presence of errors? |
| 1198 |
* \returns True if the test suite should continue, false otherwise. |
| 1199 |
*/ |
| 1200 |
bool ContinueOnFailure (void); |
| 1201 |
|
| 1202 |
/** |
| 1203 |
* \brief Issue a test report than the test suite has started running. |
| 1204 |
*/ |
| 1205 |
void ReportStart (void); |
| 1206 |
|
| 1207 |
/** |
| 1208 |
* \brief Issue a test report than the test suite has declared success. |
| 1209 |
*/ |
| 1210 |
void ReportSuccess (void); |
| 1211 |
|
| 1212 |
/** |
| 1213 |
* \brief Issue a test report than the test suite has found an error. |
| 1214 |
*/ |
| 1215 |
void ReportFailure (void); |
| 1216 |
|
| 1217 |
/** |
| 1218 |
* \brief Issue a test report than the test suite has completed its run. |
| 1219 |
*/ |
| 1220 |
void ReportEnd (void); |
| 1221 |
|
| 1222 |
protected: |
| 1223 |
/** |
| 1224 |
* \internal |
| 1225 |
* \brief Implementation of reporting method for the start of the test suite. |
| 1226 |
*/ |
| 1227 |
virtual void DoReportStart (void); |
| 1228 |
|
| 1229 |
/** |
| 1230 |
* \internal |
| 1231 |
* \brief Implementation of reporting method for success of the test suite. |
| 1232 |
*/ |
| 1233 |
virtual void DoReportSuccess (void); |
| 1234 |
|
| 1235 |
/** |
| 1236 |
* \internal |
| 1237 |
* \brief Implementation of reporting method for failure of the test suite. |
| 1238 |
*/ |
| 1239 |
virtual void DoReportFailure (void); |
| 1240 |
|
| 1241 |
/** |
| 1242 |
* \internal |
| 1243 |
* \brief Implementation of reporting method for the end of the test suite. |
| 1244 |
*/ |
| 1245 |
virtual void DoReportEnd (void); |
| 1246 |
|
| 1247 |
/** |
| 1248 |
* \internal |
| 1249 |
* \brief Implementation to do any local setup required for this test suite. |
| 1250 |
*/ |
| 1251 |
virtual void DoSetup (void); |
| 1252 |
|
| 1253 |
/** |
| 1254 |
* \internal |
| 1255 |
* \brief Implementation to actually run this test suite. |
| 1256 |
*/ |
| 1257 |
virtual void DoRun (void); |
961 |
virtual void DoRun (void); |
| 1258 |
|
962 |
|
| 1259 |
/** |
|
|
| 1260 |
* \internal |
| 1261 |
* \brief Implementation to do any local setup required for this test suite. |
| 1262 |
*/ |
| 1263 |
virtual void DoTeardown (void); |
| 1264 |
|
963 |
|
| 1265 |
private: |
964 |
TestSuite::Type m_type; |
| 1266 |
TestSuite (TestSuite& ts); |
|
|
| 1267 |
TestSuite& operator= (TestSuite& ts); |
| 1268 |
|
| 1269 |
SystemWallClockMs m_msClock; |
| 1270 |
std::string m_name; |
| 1271 |
bool m_verbose; |
| 1272 |
bool m_continueOnFailure; |
| 1273 |
std::string m_basedir; |
| 1274 |
std::string m_tempdir; |
| 1275 |
std::ofstream *m_ofs; |
| 1276 |
bool m_error; |
| 1277 |
TestType m_type; |
| 1278 |
|
| 1279 |
typedef std::vector<TestCase *> TestCaseVector_t; |
| 1280 |
TestCaseVector_t m_tests; |
| 1281 |
}; |
965 |
}; |
| 1282 |
|
966 |
|
| 1283 |
/** |
967 |
/** |
|
|
| 1286 |
class TestRunner |
970 |
class TestRunner |
| 1287 |
{ |
971 |
{ |
| 1288 |
public: |
972 |
public: |
| 1289 |
static uint32_t AddTestSuite (TestSuite *testSuite); |
973 |
static int Run (int argc, char *argv[]); |
| 1290 |
static uint32_t GetNTestSuites (void); |
|
|
| 1291 |
static TestSuite *GetTestSuite (uint32_t n); |
| 1292 |
}; |
974 |
}; |
| 1293 |
|
975 |
|
| 1294 |
/** |
976 |
/** |
|
|
| 1313 |
TestVectors& operator= (const TestVectors& tv); |
995 |
TestVectors& operator= (const TestVectors& tv); |
| 1314 |
bool operator== (const TestVectors& tv) const; |
996 |
bool operator== (const TestVectors& tv) const; |
| 1315 |
|
997 |
|
| 1316 |
typedef std::vector<T> TestVector_t; |
998 |
typedef std::vector<T> TestVector; |
| 1317 |
TestVector_t m_vectors; |
999 |
TestVector m_vectors; |
| 1318 |
}; |
1000 |
}; |
| 1319 |
|
1001 |
|
| 1320 |
template <typename T> |
1002 |
template <typename T> |