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