A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
test.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#ifndef NS3_TEST_H
8#define NS3_TEST_H
9
11
12#include <fstream>
13#include <iostream>
14#include <limits>
15#include <list>
16#include <sstream>
17#include <stdint.h>
18#include <string>
19#include <vector>
20
21/**
22 * @file
23 * @ingroup testing
24 * @brief ns3::TestCase, ns3::TestSuite, ns3::TestRunner declarations,
25 * and \c NS_TEST_ASSERT macro definitions.
26 */
27
28/**
29 * @ingroup core
30 * @defgroup testing Testing
31 * @brief Tools to define and execute unit tests.
32 *
33 * This module lists the normal Testing API. Most of these
34 * macros forward to the implementation macros in testingimpl.
35 * You should generally use these macros only.
36 */
37/**
38 * @ingroup testing
39 * @defgroup testingimpl Testing Implementation
40 * @brief Internal implementation of the Testing system.
41 */
42
43namespace ns3
44{
45
46/** Namespace for test files, TestCases and TestSuites. */
47namespace tests
48{
49} // namespace tests
50
51//
52// Note on below macros:
53//
54// When multiple statements are used in a macro, they should be bound
55// together in a loop syntactically, so the macro can appear safely
56// inside if clauses or other places that expect a single statement or
57// a statement block. The "strange" do while construct is a generally
58// expected best practice for defining a robust macro.
59//
60
61/**
62 * @ingroup testing
63 * @brief Check if we should assert on errors, and do so
64 */
65#define ASSERT_ON_FAILURE \
66 do \
67 { \
68 if (MustAssertOnFailure()) \
69 { \
70 *(volatile int*)0 = 0; \
71 } \
72 } while (false)
73
74/**
75 * @ingroup testing
76 * @brief If we shouldn't continue on errors, return
77 */
78#define CONTINUE_ON_FAILURE \
79 do \
80 { \
81 if (!MustContinueOnFailure()) \
82 { \
83 return; \
84 } \
85 } while (false)
86
87/**
88 * @ingroup testing
89 * @brief If we shouldn't continue on errors, return test status
90 */
91#define CONTINUE_ON_FAILURE_RETURNS_BOOL \
92 do \
93 { \
94 if (!MustContinueOnFailure()) \
95 { \
96 return IsStatusFailure(); \
97 } \
98 } while (false)
99
100// ===========================================================================
101// Test for equality (generic version)
102// ===========================================================================
103
104/**
105 * @ingroup testing
106 *
107 * @brief Test that an actual and expected (limit) value are equal and
108 * report and abort if not.
109 *
110 * Check to see if the expected (limit) value is equal to the actual
111 * value found in a test case. If the two values are equal nothing
112 * happens, but if the comparison fails, an error is reported in a
113 * consistent way and the execution of the current test case is
114 * aborted.
115 *
116 * The message is interpreted as a stream, for example:
117 *
118 * @code
119 * NS_TEST_ASSERT_MSG_EQ (result, true,
120 * "cannot open file " << filename << " in test");
121 * @endcode
122 *
123 * is legal.
124 *
125 * @param [in] actual Expression for the actual value found during the test.
126 * @param [in] limit Expression for the expected value of the test.
127 * @param [in] msg Message that is output if the test does not pass.
128 *
129 * @warning Do not use this macro if you are comparing floating point
130 * numbers (float or double) as it is unlikely to do what you expect.
131 * Use NS_TEST_ASSERT_MSG_EQ_TOL instead.
132 */
133#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
134 do \
135 { \
136 if (!((actual) == (limit))) \
137 { \
138 ASSERT_ON_FAILURE; \
139 std::ostringstream msgStream; \
140 msgStream << msg; \
141 std::ostringstream actualStream; \
142 actualStream << (actual); \
143 std::ostringstream limitStream; \
144 limitStream << (limit); \
145 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
146 " (limit)", \
147 actualStream.str(), \
148 limitStream.str(), \
149 msgStream.str(), \
150 __FILE__, \
151 __LINE__); \
152 CONTINUE_ON_FAILURE; \
153 } \
154 } while (false)
155
156/**
157 * @ingroup testing
158 *
159 * @brief Test that an actual and expected (limit) value are equal and
160 * report and abort if not.
161 *
162 * Check to see if the expected (limit) value is equal to the actual
163 * value found in a test case. If the two values are equal nothing
164 * happens, but if the comparison fails, an error is reported in a
165 * consistent way and the execution of the current test case is
166 * aborted.
167 *
168 * The message is interpreted as a stream, for example:
169 *
170 * @code
171 * NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (result, true,
172 * "cannot open file " << filename << " in test");
173 * @endcode
174 *
175 * is legal.
176 *
177 * @param [in] actual Expression for the actual value found during the test.
178 * @param [in] limit Expression for the expected value of the test.
179 * @param [in] msg Message that is output if the test does not pass.
180 *
181 * @warning Do not use this macro if you are comparing floating point
182 * numbers (float or double) as it is unlikely to do what you expect.
183 * Use NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_TOL instead.
184 *
185 * This function returns a Boolean value.
186 *
187 */
188#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
189 do \
190 { \
191 if (!((actual) == (limit))) \
192 { \
193 ASSERT_ON_FAILURE; \
194 std::ostringstream msgStream; \
195 msgStream << msg; \
196 std::ostringstream actualStream; \
197 actualStream << (actual); \
198 std::ostringstream limitStream; \
199 limitStream << (limit); \
200 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
201 " (limit)", \
202 actualStream.str(), \
203 limitStream.str(), \
204 msgStream.str(), \
205 __FILE__, \
206 __LINE__); \
207 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
208 } \
209 } while (false)
210
211/**
212 * @ingroup testing
213 *
214 * @brief Test that an actual and expected (limit) value are equal and
215 * report if not.
216 *
217 * Check to see if the expected (limit) value is equal to the actual
218 * value found in a test case. If the two values are equal nothing
219 * happens, but if the comparison fails, an error is reported in a
220 * consistent way. EXPECT* macros do not return if an error is
221 * detected.
222 *
223 * The message is interpreted as a stream, for example:
224 *
225 * @code
226 * NS_TEST_EXPECT_MSG_EQ(result, true,
227 * "cannot open file " << filename << " in test");
228 * @endcode
229 *
230 * is legal.
231 *
232 * @param [in] actual Expression for the actual value found during the test.
233 * @param [in] limit Expression for the expected value of the test.
234 * @param [in] msg Message that is output if the test does not pass.
235 *
236 * @warning Do not use this macro if you are comparing floating point
237 * numbers (float or double) as it is unlikely to do what you expect.
238 * Use NS_TEST_EXPECT_MSG_EQ_TOL instead.
239 */
240#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
241 do \
242 { \
243 if (!((actual) == (limit))) \
244 { \
245 ASSERT_ON_FAILURE; \
246 std::ostringstream msgStream; \
247 msgStream << msg; \
248 std::ostringstream actualStream; \
249 actualStream << (actual); \
250 std::ostringstream limitStream; \
251 limitStream << (limit); \
252 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
253 " (limit)", \
254 actualStream.str(), \
255 limitStream.str(), \
256 msgStream.str(), \
257 __FILE__, \
258 __LINE__); \
259 } \
260 } while (false)
261
262// ===========================================================================
263// Test for equality with a provided tolerance (use for floating point
264// comparisons -- both float and double)
265// ===========================================================================
266
267/**
268 * @ingroup testing
269 *
270 * @brief Test that actual and expected (limit) values are equal to
271 * plus or minus some tolerance and report and abort if not.
272 *
273 * Check to see if the expected (limit) value is equal to the actual
274 * value found in a test case to some tolerance. This is not the same
275 * thing as asking if two floating point are equal to within some
276 * epsilon, but is useful for that case. This assertion is geared
277 * toward more of a measurement problem. Consider measuring a
278 * physical rod of some kind that you have ordered. You need to
279 * determine if it is "good." You want to measure the rod to an
280 * arbitrary precision of sixteen significant figures, you will
281 * measure the rod to determine if its length is within the tolerances
282 * you provided. For example, 12.00 inches plus or minus .005 inch
283 * may be just fine.
284 *
285 * In ns-3, you might want to measure a signal to noise ratio and
286 * check to see if the answer is what you expect. If you naively
287 * measure (double)1128.93 and compare this number with a constant
288 * 1128.93 you are almost certainly going to have your test fail
289 * because of floating point rounding errors. We provide a floating
290 * point comparison function ns3::TestDoubleIsEqual() but you will
291 * probably quickly find that is not what you want either. It may
292 * turn out to be the case that when you measured an SNR that printed
293 * as 1128.93, what was actually measured was something more like
294 * 1128.9287653857625442 for example. Given that the double epsilon
295 * is on the order of 0.0000000000000009, you would need to provide
296 * sixteen significant figures of expected value for this kind of test
297 * to pass even with a typical test for floating point "approximate
298 * equality." That is clearly not required or desired. You really
299 * want to be able to provide 1128.93 along with a tolerance just like
300 * you provided 12 inches +- 0.005 inch above.
301 *
302 * This assertion is designed for real measurements by taking into
303 * account measurement tolerances. By doing so it also automatically
304 * compensates for floating point rounding errors. If you really want
305 * to check floating point equality down to the
306 * numeric_limits<double>::epsilon () range, consider using
307 * ns3::TestDoubleIsEqual().
308 *
309 * @note Mixing signed and unsigned types can lead to misleading
310 * results.
311 *
312 * The message is interpreted as a stream, for example:
313 *
314 * @code
315 * NS_TEST_ASSERT_MSG_EQ_TOL (snr, 1128.93, 0.005,
316 * "wrong snr (" << snr << ") in test");
317 * @endcode
318 *
319 * is legal.
320 *
321 * @param [in] actual Expression for the actual value found during the test.
322 * @param [in] limit Expression for the expected value of the test.
323 * @param [in] tol Tolerance of the test.
324 * @param [in] msg Message that is output if the test does not pass.
325 */
326#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
327 do \
328 { \
329 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
330 { \
331 ASSERT_ON_FAILURE; \
332 std::ostringstream msgStream; \
333 msgStream << msg; \
334 std::ostringstream actualStream; \
335 actualStream << (actual); \
336 std::ostringstream limitStream; \
337 limitStream << (limit) << " +- " << tol; \
338 std::ostringstream condStream; \
339 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
340 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
341 << #tol << " (tol)"; \
342 ReportTestFailure(condStream.str(), \
343 actualStream.str(), \
344 limitStream.str(), \
345 msgStream.str(), \
346 __FILE__, \
347 __LINE__); \
348 CONTINUE_ON_FAILURE; \
349 } \
350 } while (false)
351
352/**
353 * @ingroup testing
354 *
355 * @brief Test that actual and expected (limit) values are equal to
356 * plus or minus some tolerance and report and abort if not.
357 *
358 * Check to see if the expected (limit) value is equal to the actual
359 * value found in a test case to some tolerance. This is not the same
360 * thing as asking if two floating point are equal to within some
361 * epsilon, but is useful for that case. This assertion is geared
362 * toward more of a measurement problem. Consider measuring a
363 * physical rod of some kind that you have ordered. You need to
364 * determine if it is "good." You want to measure the rod to an
365 * arbitrary precision of sixteen significant figures, you will
366 * measure the rod to determine if its length is within the tolerances
367 * you provided. For example, 12.00 inches plus or minus .005 inch
368 * may be just fine.
369 *
370 * In ns-3, you might want to measure a signal to noise ratio and
371 * check to see if the answer is what you expect. If you naively
372 * measure (double)1128.93 and compare this number with a constant
373 * 1128.93 you are almost certainly going to have your test fail
374 * because of floating point rounding errors. We provide a floating
375 * point comparison function ns3::TestDoubleIsEqual() but you will
376 * probably quickly find that is not what you want either. It may
377 * turn out to be the case that when you measured an SNR that printed
378 * as 1128.93, what was actually measured was something more like
379 * 1128.9287653857625442 for example. Given that the double epsilon
380 * is on the order of 0.0000000000000009, you would need to provide
381 * sixteen significant figures of expected value for this kind of test
382 * to pass even with a typical test for floating point "approximate
383 * equality." That is clearly not required or desired. You really
384 * want to be able to provide 1128.93 along with a tolerance just like
385 * you provided 12 inches +- 0.005 inch above.
386 *
387 * This assertion is designed for real measurements by taking into
388 * account measurement tolerances. By doing so it also automatically
389 * compensates for floating point rounding errors. If you really want
390 * to check floating point equality down to the
391 * numeric_limits<double>::epsilon () range, consider using
392 * ns3::TestDoubleIsEqual().
393 *
394 * @note Mixing signed and unsigned types can lead to misleading
395 * results.
396 *
397 * The message is interpreted as a stream, for example:
398 *
399 * @code
400 * NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL (snr, 1128.93, 0.005,
401 * "wrong snr (" << snr << ") in test");
402 * @endcode
403 *
404 * is legal.
405 *
406 * @param [in] actual Expression for the actual value found during the test.
407 * @param [in] limit Expression for the expected value of the test.
408 * @param [in] tol Tolerance of the test.
409 * @param [in] msg Message that is output if the test does not pass.
410 *
411 * This function returns a Boolean value.
412 *
413 */
414#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
415 do \
416 { \
417 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
418 { \
419 ASSERT_ON_FAILURE; \
420 std::ostringstream msgStream; \
421 msgStream << msg; \
422 std::ostringstream actualStream; \
423 actualStream << (actual); \
424 std::ostringstream limitStream; \
425 limitStream << (limit) << " +- " << tol; \
426 std::ostringstream condStream; \
427 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
428 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
429 << #tol << " (tol)"; \
430 ReportTestFailure(condStream.str(), \
431 actualStream.str(), \
432 limitStream.str(), \
433 msgStream.str(), \
434 __FILE__, \
435 __LINE__); \
436 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
437 } \
438 } while (false)
439
440/**
441 * @ingroup testing
442 *
443 * @brief Test that actual and expected (limit) values are equal to
444 * plus or minus some tolerance and report if not.
445 *
446 * Check to see if the expected (limit) value is equal to the actual
447 * value found in a test case to some tolerance. This is not the same
448 * thing as asking if two floating point are equal to within some
449 * epsilon, but is useful for that case. This assertion is geared
450 * toward more of a measurement problem. Consider measuring a
451 * physical rod of some kind that you have ordered. You need to
452 * determine if it is "good." You want to measure the rod to an
453 * arbitrary precision of sixteen significant figures, you will
454 * measure the rod to determine if its length is within the tolerances
455 * you provided. For example, 12.00 inches plus or minus .005 inch
456 * may be just fine.
457 *
458 * In ns-3, you might want to measure a signal to noise ratio and
459 * check to see if the answer is what you expect. If you naively
460 * measure (double)1128.93 and compare this number with a constant
461 * 1128.93 you are almost certainly going to have your test fail
462 * because of floating point rounding errors. We provide a floating
463 * point comparison function ns3::TestDoubleIsEqual() but you will
464 * probably quickly find that is not what you want either. It may
465 * turn out to be the case that when you measured an SNR that printed
466 * as 1128.93, what was actually measured was something more like
467 * 1128.9287653857625442 for example. Given that the double epsilon
468 * is on the order of 0.0000000000000009, you would need to provide
469 * sixteen significant figures of expected value for this kind of test
470 * to pass even with a typical test for floating point "approximate
471 * equality." That is clearly not required or desired. You really
472 * want to be able to provide 1128.93 along with a tolerance just like
473 * you provided 12 inches +- 0.005 inch above.
474 *
475 * This assertion is designed for real measurements by taking into
476 * account measurement tolerances. By doing so it also automatically
477 * compensates for floating point rounding errors. If you really want
478 * to check floating point equality down to the
479 * numeric_limits<double>::epsilon () range, consider using
480 * ns3::TestDoubleIsEqual().
481 *
482 * @note Mixing signed and unsigned types can lead to misleading
483 * results.
484 *
485 * The message is interpreted as a stream, for example:
486 *
487 * @code
488 * NS_TEST_EXPECT_MSG_EQ_TOL (snr, 1128.93, 0.005,
489 * "wrong snr (" << snr << ") in test");
490 * @endcode
491 *
492 * is legal.
493 *
494 * @param [in] actual Expression for the actual value found during the test.
495 * @param [in] limit Expression for the expected value of the test.
496 * @param [in] tol Tolerance of the test.
497 * @param [in] msg Message that is output if the test does not pass.
498 */
499#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
500 do \
501 { \
502 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
503 { \
504 ASSERT_ON_FAILURE; \
505 std::ostringstream msgStream; \
506 msgStream << msg; \
507 std::ostringstream actualStream; \
508 actualStream << (actual); \
509 std::ostringstream limitStream; \
510 limitStream << (limit) << " +- " << tol; \
511 std::ostringstream condStream; \
512 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
513 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
514 << #tol << " (tol)"; \
515 ReportTestFailure(condStream.str(), \
516 actualStream.str(), \
517 limitStream.str(), \
518 msgStream.str(), \
519 __FILE__, \
520 __LINE__); \
521 } \
522 } while (false)
523
524// ===========================================================================
525// Test for inequality
526// ===========================================================================
527
528/**
529 * @ingroup testing
530 *
531 * @brief Test that an actual and expected (limit) value are not equal
532 * and report and abort if not.
533 *
534 * Check to see if the expected (limit) value is not equal to the
535 * actual value found in a test case. If the two values are not equal
536 * nothing happens, but if the comparison fails, an error is reported
537 * in a consistent way and the execution of the current test case is
538 * aborted.
539 *
540 * The message is interpreted as a stream, for example:
541 *
542 * @code
543 * NS_TEST_ASSERT_MSG_NE (result, false,
544 * "cannot open file " << filename << " in test");
545 * @endcode
546 *
547 * is legal.
548 *
549 * @param [in] actual Expression for the actual value found during the test.
550 * @param [in] limit Expression for the value that actual is tested against.
551 * @param [in] msg Message that is output if the test does not pass.
552 */
553#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
554 do \
555 { \
556 if (!((actual) != (limit))) \
557 { \
558 ASSERT_ON_FAILURE; \
559 std::ostringstream msgStream; \
560 msgStream << msg; \
561 std::ostringstream actualStream; \
562 actualStream << (actual); \
563 std::ostringstream limitStream; \
564 limitStream << (limit); \
565 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
566 " (limit)", \
567 actualStream.str(), \
568 limitStream.str(), \
569 msgStream.str(), \
570 __FILE__, \
571 __LINE__); \
572 CONTINUE_ON_FAILURE; \
573 } \
574 } while (false)
575
576/**
577 * @ingroup testing
578 *
579 * @brief Test that an actual and expected (limit) value are not equal
580 * and report and abort if not.
581 *
582 * Check to see if the expected (limit) value is not equal to the
583 * actual value found in a test case. If the two values are equal
584 * nothing happens, but if the comparison fails, an error is reported
585 * in a consistent way and the execution of the current test case is
586 * aborted.
587 *
588 * The message is interpreted as a stream, for example:
589 *
590 * @code
591 * NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (result, false,
592 * "cannot open file " << filename << " in test");
593 * @endcode
594 *
595 * is legal.
596 *
597 * @param [in] actual Expression for the actual value found during the test.
598 * @param [in] limit Expression for the expected value of the test.
599 * @param [in] msg Message that is output if the test does not pass.
600 *
601 * This function returns a Boolean value.
602 *
603 */
604#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
605 do \
606 { \
607 if (!((actual) != (limit))) \
608 { \
609 ASSERT_ON_FAILURE; \
610 std::ostringstream msgStream; \
611 msgStream << msg; \
612 std::ostringstream actualStream; \
613 actualStream << (actual); \
614 std::ostringstream limitStream; \
615 limitStream << (limit); \
616 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
617 " (limit)", \
618 actualStream.str(), \
619 limitStream.str(), \
620 msgStream.str(), \
621 __FILE__, \
622 __LINE__); \
623 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
624 } \
625 } while (false)
626
627/**
628 * @ingroup testing
629 *
630 * @brief Test that an actual and expected (limit) value are not equal
631 * and report if not.
632 *
633 * Check to see if the expected (limit) value is not equal to the
634 * actual value found in a test case. If the two values are not equal
635 * nothing happens, but if the comparison fails, an error is reported
636 * in a consistent way. EXPECT* macros do not return if an error is
637 * detected.
638 *
639 * The message is interpreted as a stream, for example:
640 *
641 * @code
642 * NS_TEST_EXPECT_MSG_NE (result, false,
643 * "cannot open file " << filename << " in test");
644 * @endcode
645 *
646 * is legal.
647 *
648 * @param [in] actual Expression for the actual value found during the test.
649 * @param [in] limit Expression for the value that actual is tested against.
650 * @param [in] msg Message that is output if the test does not pass.
651 *
652 * @warning Do not use this macro if you are comparing floating point
653 * numbers (float or double). Use NS_TEST_EXPECT_MSG_FLNE instead.
654 */
655#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
656 do \
657 { \
658 if (!((actual) != (limit))) \
659 { \
660 ASSERT_ON_FAILURE; \
661 std::ostringstream msgStream; \
662 msgStream << msg; \
663 std::ostringstream actualStream; \
664 actualStream << (actual); \
665 std::ostringstream limitStream; \
666 limitStream << (limit); \
667 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
668 " (limit)", \
669 actualStream.str(), \
670 limitStream.str(), \
671 msgStream.str(), \
672 __FILE__, \
673 __LINE__); \
674 } \
675 } while (false)
676
677// ===========================================================================
678// Test for less than relation
679// ===========================================================================
680
681/**
682 * @ingroup testing
683 *
684 * @brief Test that an actual value is less than a limit and report
685 * and abort if not.
686 *
687 * Check to see if the actual value found in a test case is less than
688 * the limit value. If the actual value is lesser nothing happens,
689 * but if the check fails, an error is reported in a consistent way
690 * and the execution of the current test case is aborted.
691 *
692 * The message is interpreted as a stream.
693 *
694 * @param [in] actual Expression for the actual value found during the test.
695 * @param [in] limit Expression for the limit value of the test.
696 * @param [in] msg Message that is output if the test does not pass.
697 */
698#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
699 do \
700 { \
701 if (!((actual) < (limit))) \
702 { \
703 ASSERT_ON_FAILURE; \
704 std::ostringstream msgStream; \
705 msgStream << msg; \
706 std::ostringstream actualStream; \
707 actualStream << (actual); \
708 std::ostringstream limitStream; \
709 limitStream << (limit); \
710 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
711 " (limit)", \
712 actualStream.str(), \
713 limitStream.str(), \
714 msgStream.str(), \
715 __FILE__, \
716 __LINE__); \
717 CONTINUE_ON_FAILURE; \
718 } \
719 } while (false)
720
721/**
722 * @ingroup testing
723 *
724 * @brief Test that an actual value is less than or equal to a limit
725 * and report and abort if not.
726 *
727 * Check to see if the actual value found in a test case is less than
728 * or equal to the limit value. If the actual value is lesser or
729 * equal nothing happens, but if the check fails, an error is reported
730 * in a consistent way and the execution of the current test case is
731 * aborted.
732 *
733 * The message is interpreted as a stream.
734 *
735 * @param [in] actual Expression for the actual value found during the test.
736 * @param [in] limit Expression for the limit value of the test.
737 * @param [in] msg Message that is output if the test does not pass.
738 */
739#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
740 do \
741 { \
742 if (!((actual) <= (limit))) \
743 { \
744 ASSERT_ON_FAILURE; \
745 std::ostringstream msgStream; \
746 msgStream << msg; \
747 std::ostringstream actualStream; \
748 actualStream << (actual); \
749 std::ostringstream limitStream; \
750 limitStream << (limit); \
751 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
752 " (limit)", \
753 actualStream.str(), \
754 limitStream.str(), \
755 msgStream.str(), \
756 __FILE__, \
757 __LINE__); \
758 CONTINUE_ON_FAILURE; \
759 } \
760 } while (false)
761
762/**
763 * @ingroup testing
764 *
765 * @brief Test that an actual value is less than a limit and report if
766 * not.
767 *
768 * Check to see if the actual value found in a test case is less than
769 * the limit value. If the actual value is lesser nothing happens,
770 * but if the check fails, an error is reported in a consistent way.
771 * EXPECT* macros do not return if an error is detected.
772 *
773 * The message is interpreted as a stream.
774 *
775 * @param [in] actual Expression for the actual value found during the test.
776 * @param [in] limit Expression for the limit value of the test.
777 * @param [in] msg Message that is output if the test does not pass.
778 */
779#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
780 do \
781 { \
782 if (!((actual) < (limit))) \
783 { \
784 ASSERT_ON_FAILURE; \
785 std::ostringstream msgStream; \
786 msgStream << msg; \
787 std::ostringstream actualStream; \
788 actualStream << (actual); \
789 std::ostringstream limitStream; \
790 limitStream << (limit); \
791 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
792 " (limit)", \
793 actualStream.str(), \
794 limitStream.str(), \
795 msgStream.str(), \
796 __FILE__, \
797 __LINE__); \
798 } \
799 } while (false)
800
801/**
802 * @ingroup testing
803 *
804 * @brief Test that an actual value is less than or equal to a limit
805 * and report if not.
806 *
807 * Check to see if the actual value found in a test case is less than
808 * or equal to the limit value. If the actual value is lesser or
809 * equal nothing happens, but if the check fails, an error is reported
810 * in a consistent way. EXPECT* macros do not return if an error is
811 * detected.
812 *
813 * The message is interpreted as a stream.
814 *
815 * @param [in] actual Expression for the actual value found during the test.
816 * @param [in] limit Expression for the limit value of the test.
817 * @param [in] msg Message that is output if the test does not pass.
818 */
819#define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
820 do \
821 { \
822 if (!((actual) <= (limit))) \
823 { \
824 ASSERT_ON_FAILURE; \
825 std::ostringstream msgStream; \
826 msgStream << msg; \
827 std::ostringstream actualStream; \
828 actualStream << (actual); \
829 std::ostringstream limitStream; \
830 limitStream << (limit); \
831 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
832 " (limit)", \
833 actualStream.str(), \
834 limitStream.str(), \
835 msgStream.str(), \
836 __FILE__, \
837 __LINE__); \
838 } \
839 } while (false)
840
841// ===========================================================================
842// Test for greater than relation
843// ===========================================================================
844
845/**
846 * @ingroup testing
847 *
848 * @brief Test that an actual value is greater than a limit and report
849 * and abort if not.
850 *
851 * Check to see if the actual value found in a test case is greater
852 * than the limit value. If the actual value is greater nothing
853 * happens, but if the check fails, an error is reported in a
854 * consistent way and the execution of the current test case is
855 * aborted.
856 *
857 * The message is interpreted as a stream.
858 *
859 * @param [in] actual Expression for the actual value found during the test.
860 * @param [in] limit Expression for the limit value of the test.
861 * @param [in] msg Message that is output if the test does not pass.
862 */
863#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
864 do \
865 { \
866 if (!((actual) > (limit))) \
867 { \
868 ASSERT_ON_FAILURE; \
869 std::ostringstream msgStream; \
870 msgStream << msg; \
871 std::ostringstream actualStream; \
872 actualStream << (actual); \
873 std::ostringstream limitStream; \
874 limitStream << (limit); \
875 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
876 " (limit)", \
877 actualStream.str(), \
878 limitStream.str(), \
879 msgStream.str(), \
880 __FILE__, \
881 __LINE__); \
882 CONTINUE_ON_FAILURE; \
883 } \
884 } while (false)
885
886/**
887 * @ingroup testing
888 *
889 * @brief Test that an actual value is greater than or equal to a
890 * limit and report and abort if not.
891 *
892 * Check to see if the actual value found in a test case is greater
893 * than or equal to the limit value. If the actual value is greater
894 * nothing happens, but if the check fails, an error is reported in a
895 * consistent way and the execution of the current test case is
896 * aborted.
897 *
898 * The message is interpreted as a stream.
899 *
900 * @param [in] actual Expression for the actual value found during the test.
901 * @param [in] limit Expression for the limit value of the test.
902 * @param [in] msg Message that is output if the test does not pass.
903 */
904#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
905 do \
906 { \
907 if (!((actual) >= (limit))) \
908 { \
909 ASSERT_ON_FAILURE; \
910 std::ostringstream msgStream; \
911 msgStream << msg; \
912 std::ostringstream actualStream; \
913 actualStream << (actual); \
914 std::ostringstream limitStream; \
915 limitStream << (limit); \
916 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
917 " (limit)", \
918 actualStream.str(), \
919 limitStream.str(), \
920 msgStream.str(), \
921 __FILE__, \
922 __LINE__); \
923 CONTINUE_ON_FAILURE; \
924 } \
925 } while (false)
926
927/**
928 * @ingroup testing
929 *
930 * @brief Test that an actual value is greater than a limit and report
931 * if not.
932 *
933 * Check to see if the actual value found in a test case is greater
934 * than the limit value. If the actual value is greater nothing
935 * happens, but if the check fails, an error is reported in a
936 * consistent way. EXPECT* macros do not return if an error is
937 * detected.
938 *
939 * The message is interpreted as a stream.
940 *
941 * @param [in] actual Expression for the actual value found during the test.
942 * @param [in] limit Expression for the limit value of the test.
943 * @param [in] msg Message that is output if the test does not pass.
944 */
945#define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
946 do \
947 { \
948 if (!((actual) > (limit))) \
949 { \
950 ASSERT_ON_FAILURE; \
951 std::ostringstream msgStream; \
952 msgStream << msg; \
953 std::ostringstream actualStream; \
954 actualStream << (actual); \
955 std::ostringstream limitStream; \
956 limitStream << (limit); \
957 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
958 " (limit)", \
959 actualStream.str(), \
960 limitStream.str(), \
961 msgStream.str(), \
962 __FILE__, \
963 __LINE__); \
964 } \
965 } while (false)
966
967/**
968 * @ingroup testing
969 *
970 * @brief Test that an actual value is greater than or equal to limit
971 * and report if not.
972 *
973 * Check to see if the actual value found in a test case is greater
974 * than or equal to the limit value. If the actual value is greater
975 * nothing happens, but if the check fails, an error is reported in a
976 * consistent way. EXPECT* macros do not return if an error is
977 * detected.
978 *
979 * The message is interpreted as a stream.
980 *
981 * @param [in] actual Expression for the actual value found during the test.
982 * @param [in] limit Expression for the limit value of the test.
983 * @param [in] msg Message that is output if the test does not pass.
984 */
985#define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
986 do \
987 { \
988 if (!((actual) >= (limit))) \
989 { \
990 ASSERT_ON_FAILURE; \
991 std::ostringstream msgStream; \
992 msgStream << msg; \
993 std::ostringstream actualStream; \
994 actualStream << (actual); \
995 std::ostringstream limitStream; \
996 limitStream << (limit); \
997 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
998 " (limit)", \
999 actualStream.str(), \
1000 limitStream.str(), \
1001 msgStream.str(), \
1002 __FILE__, \
1003 __LINE__); \
1004 } \
1005 } while (false)
1006
1007/**
1008 * @ingroup testing
1009 * @brief Compare two double precision floating point numbers and
1010 * declare them equal if they are within some epsilon of each other.
1011 *
1012 * Approximate comparison of floating point numbers near equality is
1013 * trickier than one may expect and is well-discussed in the
1014 * literature. Basic strategies revolve around a suggestion by Knuth
1015 * to compare the floating point numbers as binary integers, supplying
1016 * a maximum difference between them . This max difference is
1017 * specified in Units in the Last Place (ulps) or a floating point
1018 * epsilon.
1019 *
1020 * This routine is based on the GNU Scientific Library function
1021 * gsl_fcmp.
1022 *
1023 * @param [in] a The first of double precision floating point
1024 * numbers to compare
1025 * @param [in] b The second of double precision floating point
1026 * numbers to compare
1027 * @param [in] epsilon The tolerance to use in the comparison.
1028 * @returns Returns \c true if the doubles are equal to a precision
1029 * defined by epsilon
1030 */
1031bool TestDoubleIsEqual(const double a,
1032 const double b,
1033 const double epsilon = std::numeric_limits<double>::epsilon());
1034
1035class TestRunnerImpl;
1036
1037/**
1038 * @ingroup testing
1039 *
1040 * @brief encapsulates test code
1041 *
1042 * To allow a new test to be run within the ns-3 test framework, users
1043 * need to create subclasses of this base class, override the DoRun
1044 * method, and use the NS_TEST_* macros within DoRun.
1045 *
1046 * @see sample-test-suite.cc
1047 */
1049{
1050 public:
1051 /** @brief How long the test takes to execute. */
1052 enum class Duration
1053 {
1054 QUICK = 1, //!< Fast test.
1055 EXTENSIVE = 2, //!< Medium length test.
1056 TAKES_FOREVER = 3 //!< Very long running test.
1057 };
1058
1059 /**
1060 * Destructor
1061 */
1062 virtual ~TestCase();
1063
1064 // Delete copy constructor and assignment operator to avoid misuse
1065 TestCase(const TestCase&) = delete;
1066 TestCase& operator=(const TestCase&) = delete;
1067
1068 /**
1069 * @return The name of this test
1070 */
1071 std::string GetName() const;
1072
1073 protected:
1074 /**
1075 * @brief Constructor.
1076 *
1077 * @param [in] name The name of the new TestCase created
1078 */
1079 TestCase(std::string name);
1080
1081 /**
1082 * @brief Add an individual child TestCase to this test suite.
1083 *
1084 * @param [in] testCase Pointer to the TestCase object to be added.
1085 * @param [in] duration Amount of time this test takes to execute
1086 * (defaults to QUICK).
1087 */
1088 void AddTestCase(TestCase* testCase, Duration duration = Duration::QUICK);
1089
1090 /**
1091 * @brief Set the data directory where reference trace files can be
1092 * found.
1093 *
1094 * @param [in] directory The directory where the test data is
1095 * located
1096 *
1097 * In general, this method is invoked as SetDataDir
1098 * (NS_TEST_SOURCEDIR); However, if a module contains a test
1099 * directory with subdirectories (e.g. src/mesh/test), and the test
1100 * data (e.g. pcap traces) is located in one of these
1101 * subdirectories, then the variable NS_TEST_SOURCEDIR may not work
1102 * and the user may want to explicitly pass in a directory string.
1103 *
1104 * Note that NS_TEST_SOURCEDIR is set in src/CMakeLists.txt for each module
1105 */
1106 void SetDataDir(std::string directory);
1107
1108 /**
1109 * @brief Check if any tests failed.
1110 *
1111 * @return \c true if any of the tests have failed, \c false otherwise.
1112 */
1113 bool IsStatusFailure() const;
1114 /**
1115 * @brief Check if all tests passed.
1116 *
1117 * @return \c true if the tests have succeeded, \c false otherwise.
1118 */
1119 bool IsStatusSuccess() const;
1120
1121 /**
1122 * @brief Get the parent of this TestCase.
1123 *
1124 * @return A pointer to the parent of this test.
1125 */
1126 TestCase* GetParent() const;
1127
1128 /**
1129 * @name Internal Interface
1130 * These methods are the interface used by test macros and should not
1131 * be used directly by normal test code.
1132 * @{
1133 */
1134 /**
1135 * @brief Log the failure of this TestCase.
1136 *
1137 * @param [in] cond The test condition.
1138 * @param [in] actual Actual value of the test.
1139 * @param [in] limit Expected value of the test.
1140 * @param [in] message Message indicating the type of failure.
1141 * @param [in] file The file where the test failed.
1142 * @param [in] line The line number in \pname{file} where the test failed.
1143 */
1144 void ReportTestFailure(std::string cond,
1145 std::string actual,
1146 std::string limit,
1147 std::string message,
1148 std::string file,
1149 int32_t line);
1150 /**
1151 * @brief Check if this run should assert on failure.
1152 *
1153 * @return \c true if we should assert on failure.
1154 */
1155 bool MustAssertOnFailure() const;
1156 /**
1157 * @brief Check if this run should continue on failure.
1158 *
1159 * @return \c true if we should continue on failure.
1160 */
1161 bool MustContinueOnFailure() const;
1162 /**
1163 * @brief Construct the full path to a file in the data directory.
1164 *
1165 * The data directory is configured by SetDataDirectory().
1166 *
1167 * @param [in] filename The bare (no path) file name
1168 * @return The full path to \pname{filename} in the data directory
1169 */
1170 std::string CreateDataDirFilename(std::string filename);
1171 /**
1172 * @brief Construct the full path to a file in a temporary directory.
1173 *
1174 * If the TestRunner is invoked with "--update-data", this will be
1175 * the data directory instead.
1176 *
1177 * @param [in] filename The bare (no path) file name
1178 * @return The full path to \pname{filename} in the temporary directory.
1179 */
1180 std::string CreateTempDirFilename(std::string filename);
1181 /**@}*/
1182
1183 private:
1184 /** Needs access to the TestCase data members. */
1185 friend class TestRunnerImpl;
1186
1187 /**
1188 * @brief Implementation to do any local setup required for this
1189 * TestCase.
1190 *
1191 * Subclasses should override this method to perform any costly
1192 * per-test setup before DoRun is invoked.
1193 */
1194 virtual void DoSetup();
1195
1196 /**
1197 * @brief Implementation to actually run this TestCase.
1198 *
1199 * Subclasses should override this method to conduct their tests.
1200 */
1201 virtual void DoRun() = 0;
1202
1203 /**
1204 * @brief Implementation to do any local setup required for this
1205 * TestCase.
1206 *
1207 * Subclasses should override this method to perform any costly
1208 * per-test teardown
1209 */
1210 virtual void DoTeardown();
1211
1212 // methods called by TestRunnerImpl
1213 /**
1214 * @brief Executes DoSetup(), DoRun(), and DoTeardown() for the TestCase
1215 *
1216 * Config::Reset() is called at both the beginning and end of this method
1217 * so that any changes to attribute default values (Config::SetDefault(...))
1218 * or global values (e.g., RngRun) that are made within the test case's
1219 * DoRun() method do not propagate beyond the scope of running the TestCase.
1220 *
1221 * @param [in] runner The test runner implementation.
1222 */
1223 void Run(TestRunnerImpl* runner);
1224 /** @copydoc IsStatusFailure() */
1225 bool IsFailed() const;
1226
1227 /**
1228 * @ingroup testingimpl
1229 * @brief Container for results from a TestCase.
1230 */
1231 struct Result;
1232
1233 TestCase* m_parent; //!< Pointer to my parent TestCase
1234 std::vector<TestCase*> m_children; //!< Vector of my children
1235 std::string m_dataDir; //!< My data directory
1236 TestRunnerImpl* m_runner; //!< Pointer to the TestRunner
1237 Result* m_result; //!< Results data
1238 std::string m_name; //!< TestCase name
1239 Duration m_duration; //!< TestCase duration
1240};
1241
1242/**
1243 * @ingroup testing
1244 *
1245 * @brief A suite of tests to run.
1246 *
1247 * @see sample-test-suite.cc
1248 */
1249class TestSuite : public TestCase
1250{
1251 public:
1252 /**
1253 * @enum Type
1254 * @brief Type of test.
1255 */
1256 enum class Type
1257 {
1258 ALL = 0, //!< Token to represent all tests.
1259 UNIT, //!< This test suite implements a Unit Test
1260 SYSTEM, //!< This test suite implements a System Test
1261 EXAMPLE, //!< This test suite implements an Example Test
1262 PERFORMANCE //!< This test suite implements a Performance Test
1263 };
1264
1265 /**
1266 * @brief Construct a new test suite.
1267 *
1268 * @param [in] name The name of the test suite.
1269 * @param [in] type The TestType of the test suite (defaults to UNIT test).
1270 */
1271 TestSuite(std::string name, Type type = Type::UNIT);
1272
1273 /**
1274 * @brief get the kind of test this test suite implements
1275 *
1276 * @returns The Type of the suite.
1277 */
1279
1280 private:
1281 // Inherited
1282 void DoRun() override;
1283
1284 TestSuite::Type m_type; //!< Type of this TestSuite
1285};
1286
1287/**
1288 * @ingroup testingimpl
1289 *
1290 * @brief A runner to execute tests.
1291 */
1293{
1294 public:
1295 /**
1296 * Run the requested suite of tests,
1297 * according to the given command line arguments.
1298 *
1299 * @param [in] argc The number of elements in \pname{argv}
1300 * @param [in] argv The vector of command line arguments
1301 * @returns Success status
1302 */
1303 static int Run(int argc, char* argv[]);
1304};
1305
1306/**
1307 * @ingroup testing
1308 *
1309 * @brief A simple way to store test vectors (for stimulus or from responses)
1310 */
1311template <typename T>
1313{
1314 public:
1315 /**
1316 * Constructor
1317 */
1319 /**
1320 * Virtual destructor
1321 */
1322 virtual ~TestVectors();
1323
1324 // Delete copy constructor and assignment operator to avoid misuse
1325 TestVectors(const TestVectors&) = delete;
1327
1328 /**
1329 * @brief Set the expected length of this vector.
1330 *
1331 * @param [in] reserve The number of entries to reserve
1332 */
1333 void Reserve(uint32_t reserve);
1334
1335 /**
1336 * @param [in] vector The test vector to add
1337 *
1338 * @returns The new test vector index
1339 */
1340 std::size_t Add(T vector);
1341
1342 /**
1343 * @brief Get the total number of test vectors.
1344 * @return The number of test vectors
1345 */
1346 std::size_t GetN() const;
1347 /**
1348 * @brief Get the i'th test vector
1349 * @param [in] i The requested vector index
1350 * @return The requested vector
1351 */
1352 T Get(std::size_t i) const;
1353
1354 /**
1355 * @return The underlying data structure begin iterator
1356 */
1357 typename std::vector<T>::iterator begin()
1358 {
1359 return m_vectors.begin();
1360 }
1361
1362 /**
1363 * @return The underlying data structure end iterator
1364 */
1365 typename std::vector<T>::iterator end()
1366 {
1367 return m_vectors.end();
1368 }
1369
1370 /**
1371 * @return The underlying data structure const begin iterator
1372 */
1373 typename std::vector<T>::const_iterator begin() const
1374 {
1375 return m_vectors.begin();
1376 }
1377
1378 /**
1379 * @return The underlying data structure const end iterator
1380 */
1381 typename std::vector<T>::const_iterator end() const
1382 {
1383 return m_vectors.end();
1384 }
1385
1386 private:
1387 typedef std::vector<T> TestVector; //!< Container type
1388 TestVector m_vectors; //!< The list of test vectors
1389};
1390
1391template <typename T>
1396
1397template <typename T>
1398void
1400{
1401 m_vectors.reserve(reserve);
1402}
1403
1404template <typename T>
1408
1409template <typename T>
1410std::size_t
1412{
1413 std::size_t index = m_vectors.size();
1414 m_vectors.push_back(vector);
1415 return index;
1416}
1417
1418template <typename T>
1419std::size_t
1421{
1422 return m_vectors.size();
1423}
1424
1425template <typename T>
1426T
1427TestVectors<T>::Get(std::size_t i) const
1428{
1429 NS_ABORT_MSG_UNLESS(m_vectors.size() > i, "TestVectors::Get(): Bad index");
1430 return m_vectors[i];
1431}
1432
1433/**
1434 * @brief Stream insertion operator.
1435 * @param [in] os The reference to the output stream.
1436 * @param [in] type The TestSuite::Type.
1437 * @return The reference to the output stream.
1438 */
1439std::ostream& operator<<(std::ostream& os, TestSuite::Type type);
1440
1441/**
1442 * @brief Stream insertion operator.
1443 * @param [in] os The reference to the output stream.
1444 * @param [in] duration The TestCase::Duration.
1445 * @return The reference to the output stream.
1446 */
1447std::ostream& operator<<(std::ostream& os, TestCase::Duration duration);
1448
1449} // namespace ns3
1450
1451#endif /* NS3_TEST_H */
std::string m_name
TestCase name.
Definition test.h:1238
bool MustContinueOnFailure() const
Check if this run should continue on failure.
Definition test.cc:406
bool IsStatusFailure() const
Check if any tests failed.
Definition test.cc:458
std::string m_dataDir
My data directory.
Definition test.h:1235
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
Definition test.cc:413
TestCase * m_parent
Pointer to my parent TestCase.
Definition test.h:1233
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
Result * m_result
Results data.
Definition test.h:1237
bool IsStatusSuccess() const
Check if all tests passed.
Definition test.cc:465
virtual void DoSetup()
Implementation to do any local setup required for this TestCase.
Definition test.cc:479
virtual ~TestCase()
Destructor.
Definition test.cc:278
Duration
How long the test takes to execute.
Definition test.h:1053
@ EXTENSIVE
Medium length test.
Definition test.h:1055
@ QUICK
Fast test.
Definition test.h:1054
@ TAKES_FOREVER
Very long running test.
Definition test.h:1056
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition test.cc:432
TestRunnerImpl * m_runner
Pointer to the TestRunner.
Definition test.h:1236
TestCase * GetParent() const
Get the parent of this TestCase.
Definition test.cc:374
bool MustAssertOnFailure() const
Check if this run should assert on failure.
Definition test.cc:399
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition test.cc:472
virtual void DoTeardown()
Implementation to do any local setup required for this TestCase.
Definition test.cc:485
void Run(TestRunnerImpl *runner)
Executes DoSetup(), DoRun(), and DoTeardown() for the TestCase.
Definition test.cc:340
TestCase(const TestCase &)=delete
virtual void DoRun()=0
Implementation to actually run this TestCase.
std::string GetName() const
Definition test.cc:367
friend class TestRunnerImpl
Needs access to the TestCase data members.
Definition test.h:1185
Duration m_duration
TestCase duration.
Definition test.h:1239
void ReportTestFailure(std::string cond, std::string actual, std::string limit, std::string message, std::string file, int32_t line)
Log the failure of this TestCase.
Definition test.cc:380
bool IsFailed() const
Check if any tests failed.
Definition test.cc:333
TestCase & operator=(const TestCase &)=delete
std::vector< TestCase * > m_children
Vector of my children.
Definition test.h:1234
A runner to execute tests.
Definition test.h:1293
static int Run(int argc, char *argv[])
Run the requested suite of tests, according to the given command line arguments.
Definition test.cc:1169
Type
Type of test.
Definition test.h:1257
@ PERFORMANCE
This test suite implements a Performance Test.
Definition test.h:1262
@ ALL
Token to represent all tests.
Definition test.h:1258
@ EXAMPLE
This test suite implements an Example Test.
Definition test.h:1261
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1259
@ SYSTEM
This test suite implements a System Test.
Definition test.h:1260
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:490
TestSuite::Type m_type
Type of this TestSuite.
Definition test.h:1284
void DoRun() override
Implementation to actually run this TestCase.
Definition test.cc:506
TestSuite::Type GetTestType()
get the kind of test this test suite implements
Definition test.cc:499
std::vector< T >::iterator begin()
Definition test.h:1357
std::vector< T > TestVector
Container type.
Definition test.h:1387
std::vector< T >::const_iterator begin() const
Definition test.h:1373
std::vector< T >::iterator end()
Definition test.h:1365
T Get(std::size_t i) const
Get the i'th test vector.
Definition test.h:1427
std::size_t GetN() const
Get the total number of test vectors.
Definition test.h:1420
TestVectors(const TestVectors &)=delete
TestVectors()
Constructor.
Definition test.h:1392
void Reserve(uint32_t reserve)
Set the expected length of this vector.
Definition test.h:1399
std::vector< T >::const_iterator end() const
Definition test.h:1381
std::size_t Add(T vector)
Definition test.h:1411
TestVector m_vectors
The list of test vectors.
Definition test.h:1388
virtual ~TestVectors()
Virtual destructor.
Definition test.h:1405
TestVectors & operator=(const TestVectors &)=delete
STL class.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition abort.h:133
bool TestDoubleIsEqual(const double x1, const double x2, const double epsilon)
Compare two double precision floating point numbers and declare them equal if they are within some ep...
Definition test.cc:36
Namespace for test files, TestCases and TestSuites.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
Container for results from a TestCase.
Definition test.cc:112
ns3::SystemWallClockMs declaration.