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