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 /**
1061 * Deprecated test duration simple enums.
1062 *
1063 * Use the `TestCase::Duration` enum class symbols instead.
1064 * @{
1065 */
1066 NS_DEPRECATED_3_42("Use Duration::QUICK instead")
1067 static constexpr auto QUICK = Duration::QUICK;
1068 NS_DEPRECATED_3_42("Use Duration::EXTENSIVE instead")
1069 static constexpr auto EXTENSIVE = Duration::EXTENSIVE;
1071 static constexpr auto TAKES_FOREVER = Duration::TAKES_FOREVER;
1072
1073 using TestDuration NS_DEPRECATED_3_42("Use Duration instead") = Duration;
1074 /**@}*/
1075
1076 /**
1077 * Destructor
1078 */
1079 virtual ~TestCase();
1080
1081 // Delete copy constructor and assignment operator to avoid misuse
1083 TestCase& operator=(const TestCase&) = delete;
1084
1085 /**
1086 * \return The name of this test
1087 */
1088 std::string GetName() const;
1089
1090 protected:
1091 /**
1092 * \brief Constructor.
1093 *
1094 * \param [in] name The name of the new TestCase created
1095 */
1096 TestCase(std::string name);
1097
1098 /**
1099 * \brief Add an individual child TestCase to this test suite.
1100 *
1101 * \param [in] testCase Pointer to the TestCase object to be added.
1102 * \param [in] duration Amount of time this test takes to execute
1103 * (defaults to QUICK).
1104 */
1105 void AddTestCase(TestCase* testCase, Duration duration = Duration::QUICK);
1106
1107 /**
1108 * \brief Set the data directory where reference trace files can be
1109 * found.
1110 *
1111 * \param [in] directory The directory where the test data is
1112 * located
1113 *
1114 * In general, this method is invoked as SetDataDir
1115 * (NS_TEST_SOURCEDIR); However, if a module contains a test
1116 * directory with subdirectories (e.g. src/mesh/test), and the test
1117 * data (e.g. pcap traces) is located in one of these
1118 * subdirectories, then the variable NS_TEST_SOURCEDIR may not work
1119 * and the user may want to explicitly pass in a directory string.
1120 *
1121 * Note that NS_TEST_SOURCEDIR is set in src/CMakeLists.txt for each module
1122 */
1123 void SetDataDir(std::string directory);
1124
1125 /**
1126 * \brief Check if any tests failed.
1127 *
1128 * \return \c true if any of the tests have failed, \c false otherwise.
1129 */
1130 bool IsStatusFailure() const;
1131 /**
1132 * \brief Check if all tests passed.
1133 *
1134 * \return \c true if the tests have succeeded, \c false otherwise.
1135 */
1136 bool IsStatusSuccess() const;
1137
1138 /**
1139 * \brief Get the parent of this TestCase.
1140 *
1141 * \return A pointer to the parent of this test.
1142 */
1143 TestCase* GetParent() const;
1144
1145 /**
1146 * \name Internal Interface
1147 * These methods are the interface used by test macros and should not
1148 * be used directly by normal test code.
1149 * @{
1150 */
1151 /**
1152 * \brief Log the failure of this TestCase.
1153 *
1154 * \param [in] cond The test condition.
1155 * \param [in] actual Actual value of the test.
1156 * \param [in] limit Expected value of the test.
1157 * \param [in] message Message indicating the type of failure.
1158 * \param [in] file The file where the test failed.
1159 * \param [in] line The line number in \pname{file} where the test failed.
1160 */
1161 void ReportTestFailure(std::string cond,
1162 std::string actual,
1163 std::string limit,
1164 std::string message,
1165 std::string file,
1166 int32_t line);
1167 /**
1168 * \brief Check if this run should assert on failure.
1169 *
1170 * \return \c true if we should assert on failure.
1171 */
1172 bool MustAssertOnFailure() const;
1173 /**
1174 * \brief Check if this run should continue on failure.
1175 *
1176 * \return \c true if we should continue on failure.
1177 */
1178 bool MustContinueOnFailure() const;
1179 /**
1180 * \brief Construct the full path to a file in the data directory.
1181 *
1182 * The data directory is configured by SetDataDirectory().
1183 *
1184 * \param [in] filename The bare (no path) file name
1185 * \return The full path to \pname{filename} in the data directory
1186 */
1187 std::string CreateDataDirFilename(std::string filename);
1188 /**
1189 * \brief Construct the full path to a file in a temporary directory.
1190 *
1191 * If the TestRunner is invoked with "--update-data", this will be
1192 * the data directory instead.
1193 *
1194 * \param [in] filename The bare (no path) file name
1195 * \return The full path to \pname{filename} in the temporary directory.
1196 */
1197 std::string CreateTempDirFilename(std::string filename);
1198 /**@}*/
1199
1200 private:
1201 /** Needs access to the TestCase data members. */
1202 friend class TestRunnerImpl;
1203
1204 /**
1205 * \brief Implementation to do any local setup required for this
1206 * TestCase.
1207 *
1208 * Subclasses should override this method to perform any costly
1209 * per-test setup before DoRun is invoked.
1210 */
1211 virtual void DoSetup();
1212
1213 /**
1214 * \brief Implementation to actually run this TestCase.
1215 *
1216 * Subclasses should override this method to conduct their tests.
1217 */
1218 virtual void DoRun() = 0;
1219
1220 /**
1221 * \brief Implementation to do any local setup required for this
1222 * TestCase.
1223 *
1224 * Subclasses should override this method to perform any costly
1225 * per-test teardown
1226 */
1227 virtual void DoTeardown();
1228
1229 // methods called by TestRunnerImpl
1230 /**
1231 * \brief Executes DoSetup(), DoRun(), and DoTeardown() for the TestCase
1232 *
1233 * Config::Reset() is called at both the beginning and end of this method
1234 * so that any changes to attribute default values (Config::SetDefault(...))
1235 * or global values (e.g., RngRun) that are made within the test case's
1236 * DoRun() method do not propagate beyond the scope of running the TestCase.
1237 *
1238 * \param [in] runner The test runner implementation.
1239 */
1240 void Run(TestRunnerImpl* runner);
1241 /** \copydoc IsStatusFailure() */
1242 bool IsFailed() const;
1243
1244 /**
1245 * \ingroup testingimpl
1246 * \brief Container for results from a TestCase.
1247 */
1248 struct Result;
1249
1250 TestCase* m_parent; //!< Pointer to my parent TestCase
1251 std::vector<TestCase*> m_children; //!< Vector of my children
1252 std::string m_dataDir; //!< My data directory
1253 TestRunnerImpl* m_runner; //!< Pointer to the TestRunner
1254 Result* m_result; //!< Results data
1255 std::string m_name; //!< TestCase name
1256 Duration m_duration; //!< TestCase duration
1257};
1258
1259/**
1260 * \ingroup testing
1261 *
1262 * \brief A suite of tests to run.
1263 *
1264 * \see sample-test-suite.cc
1265 */
1266class TestSuite : public TestCase
1267{
1268 public:
1269 /**
1270 * \enum Type
1271 * \brief Type of test.
1272 */
1273 enum class Type
1274 {
1275 ALL = 0, //!< Token to represent all tests.
1276 UNIT, //!< This test suite implements a Unit Test
1277 SYSTEM, //!< This test suite implements a System Test
1278 EXAMPLE, //!< This test suite implements an Example Test
1279 PERFORMANCE //!< This test suite implements a Performance Test
1280 };
1281
1282 /**
1283 * Deprecated test type simple enums.
1284 *
1285 * Use the `TestSuite::Type` enum class symbols instead.
1286 * @{
1287 */
1288 NS_DEPRECATED_3_42("Use Type::ALL instead")
1289 static constexpr auto ALL = Type::ALL;
1290 NS_DEPRECATED_3_42("Use Type::UNIT instead")
1291 static constexpr auto UNIT = Type::UNIT;
1292 NS_DEPRECATED_3_42("Use Type::SYSTEM instead")
1293 static constexpr auto SYSTEM = Type::SYSTEM;
1294 NS_DEPRECATED_3_42("Use Type::EXAMPLE instead")
1295 static constexpr auto EXAMPLE = Type::EXAMPLE;
1296 NS_DEPRECATED_3_42("Use Type::PERFORMANCE instead")
1297 static constexpr auto PERFORMANCE = Type::PERFORMANCE;
1298 /**@}*/
1299
1300 /**
1301 * \brief Construct a new test suite.
1302 *
1303 * \param [in] name The name of the test suite.
1304 * \param [in] type The TestType of the test suite (defaults to UNIT test).
1305 */
1306 TestSuite(std::string name, Type type = Type::UNIT);
1307
1308 /**
1309 * \brief get the kind of test this test suite implements
1310 *
1311 * \returns The Type of the suite.
1312 */
1313 TestSuite::Type GetTestType();
1314
1315 private:
1316 // Inherited
1317 void DoRun() override;
1318
1319 TestSuite::Type m_type; //!< Type of this TestSuite
1320};
1321
1322/**
1323 * \ingroup testingimpl
1324 *
1325 * \brief A runner to execute tests.
1326 */
1328{
1329 public:
1330 /**
1331 * Run the requested suite of tests,
1332 * according to the given command line arguments.
1333 *
1334 * \param [in] argc The number of elements in \pname{argv}
1335 * \param [in] argv The vector of command line arguments
1336 * \returns Success status
1337 */
1338 static int Run(int argc, char* argv[]);
1339};
1340
1341/**
1342 * \ingroup testing
1343 *
1344 * \brief A simple way to store test vectors (for stimulus or from responses)
1345 */
1346template <typename T>
1348{
1349 public:
1350 /**
1351 * Constructor
1352 */
1354 /**
1355 * Virtual destructor
1356 */
1357 virtual ~TestVectors();
1358
1359 // Delete copy constructor and assignment operator to avoid misuse
1360 TestVectors(const TestVectors&) = delete;
1362
1363 /**
1364 * \brief Set the expected length of this vector.
1365 *
1366 * \param [in] reserve The number of entries to reserve
1367 */
1368 void Reserve(uint32_t reserve);
1369
1370 /**
1371 * \param [in] vector The test vector to add
1372 *
1373 * \returns The new test vector index
1374 */
1375 std::size_t Add(T vector);
1376
1377 /**
1378 * \brief Get the total number of test vectors.
1379 * \return The number of test vectors
1380 */
1381 std::size_t GetN() const;
1382 /**
1383 * \brief Get the i'th test vector
1384 * \param [in] i The requested vector index
1385 * \return The requested vector
1386 */
1387 T Get(std::size_t i) const;
1388
1389 /**
1390 * \return The underlying data structure begin iterator
1391 */
1392 typename std::vector<T>::iterator begin()
1393 {
1394 return m_vectors.begin();
1395 }
1396
1397 /**
1398 * \return The underlying data structure end iterator
1399 */
1400 typename std::vector<T>::iterator end()
1401 {
1402 return m_vectors.end();
1403 }
1404
1405 /**
1406 * \return The underlying data structure const begin iterator
1407 */
1408 typename std::vector<T>::const_iterator begin() const
1409 {
1410 return m_vectors.begin();
1411 }
1412
1413 /**
1414 * \return The underlying data structure const end iterator
1415 */
1416 typename std::vector<T>::const_iterator end() const
1417 {
1418 return m_vectors.end();
1419 }
1420
1421 private:
1422 typedef std::vector<T> TestVector; //!< Container type
1423 TestVector m_vectors; //!< The list of test vectors
1424};
1425
1426template <typename T>
1428 : m_vectors()
1429{
1430}
1431
1432template <typename T>
1433void
1435{
1436 m_vectors.reserve(reserve);
1437}
1438
1439template <typename T>
1443
1444template <typename T>
1445std::size_t
1447{
1448 std::size_t index = m_vectors.size();
1449 m_vectors.push_back(vector);
1450 return index;
1451}
1452
1453template <typename T>
1454std::size_t
1456{
1457 return m_vectors.size();
1458}
1459
1460template <typename T>
1461T
1462TestVectors<T>::Get(std::size_t i) const
1463{
1464 NS_ABORT_MSG_UNLESS(m_vectors.size() > i, "TestVectors::Get(): Bad index");
1465 return m_vectors[i];
1466}
1467
1468/**
1469 * @brief Stream insertion operator.
1470 * @param [in] os The reference to the output stream.
1471 * @param [in] type The TestSuite::Type.
1472 * @return The reference to the output stream.
1473 */
1474std::ostream& operator<<(std::ostream& os, TestSuite::Type type);
1475
1476/**
1477 * @brief Stream insertion operator.
1478 * @param [in] os The reference to the output stream.
1479 * @param [in] duration The TestCase::Duration.
1480 * @return The reference to the output stream.
1481 */
1482std::ostream& operator<<(std::ostream& os, TestCase::Duration duration);
1483
1484} // namespace ns3
1485
1486#endif /* NS3_TEST_H */
encapsulates test code
Definition test.h:1050
std::string m_name
TestCase name.
Definition test.h:1255
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:1252
static constexpr auto QUICK
Deprecated test duration simple enums.
Definition test.h:1067
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:1250
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:1254
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
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:432
TestRunnerImpl * m_runner
Pointer to the TestRunner.
Definition test.h:1253
TestCase * GetParent() const
Get the parent of this TestCase.
Definition test.cc:374
static constexpr auto TAKES_FOREVER
Definition test.h:1071
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
virtual void DoRun()=0
Implementation to actually run this TestCase.
std::string GetName() const
Definition test.cc:367
Duration m_duration
TestCase duration.
Definition test.h:1256
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
static constexpr auto EXTENSIVE
Definition test.h:1069
bool IsFailed() const
Check if any tests failed.
Definition test.cc:333
std::vector< TestCase * > m_children
Vector of my children.
Definition test.h:1251
A runner to execute tests.
Definition test.h:1328
Container for all tests.
Definition test.cc:130
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
A simple way to store test vectors (for stimulus or from responses)
Definition test.h:1348
std::vector< T >::iterator begin()
Definition test.h:1392
std::vector< T > TestVector
Container type.
Definition test.h:1422
std::vector< T >::const_iterator begin() const
Definition test.h:1408
std::vector< T >::iterator end()
Definition test.h:1400
T Get(std::size_t i) const
Get the i'th test vector.
Definition test.h:1462
std::size_t GetN() const
Get the total number of test vectors.
Definition test.h:1455
TestVectors(const TestVectors &)=delete
TestVectors()
Constructor.
Definition test.h:1427
void Reserve(uint32_t reserve)
Set the expected length of this vector.
Definition test.h:1434
std::vector< T >::const_iterator end() const
Definition test.h:1416
std::size_t Add(T vector)
Definition test.h:1446
TestVector m_vectors
The list of test vectors.
Definition test.h:1423
virtual ~TestVectors()
Virtual destructor.
Definition test.h:1440
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:36
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:112
ns3::SystemWallClockMs declaration.