68 #define ASSERT_ON_FAILURE \
70 if (MustAssertOnFailure ()) \
72 *(volatile int *)0 = 0; \
80 #define CONTINUE_ON_FAILURE \
82 if (!MustContinueOnFailure ()) \
92 #define CONTINUE_ON_FAILURE_RETURNS_BOOL \
94 if (!MustContinueOnFailure ()) \
96 return IsStatusFailure (); \
111 #define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
113 if (!((actual) == (limit))) \
116 std::ostringstream msgStream; \
118 std::ostringstream actualStream; \
119 actualStream << actual; \
120 std::ostringstream limitStream; \
121 limitStream << limit; \
122 ReportTestFailure (std::string (#actual) + " (actual) == " + \
123 std::string (#limit) + " (limit)", \
124 actualStream.str (), limitStream.str (), \
125 msgStream.str (), file, line); \
126 CONTINUE_ON_FAILURE; \
158 #define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
159 NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
166 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
168 if (!((actual) == (limit))) \
171 std::ostringstream msgStream; \
173 std::ostringstream actualStream; \
174 actualStream << actual; \
175 std::ostringstream limitStream; \
176 limitStream << limit; \
177 ReportTestFailure (std::string (#actual) + " (actual) == " + \
178 std::string (#limit) + " (limit)", \
179 actualStream.str (), limitStream.str (), \
180 msgStream.str (), file, line); \
181 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
216 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
217 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
227 #define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
229 if (!((actual) == (limit))) \
232 std::ostringstream msgStream; \
234 std::ostringstream actualStream; \
235 actualStream << actual; \
236 std::ostringstream limitStream; \
237 limitStream << limit; \
238 ReportTestFailure (std::string (#actual) + " (actual) == " + \
239 std::string (#limit) + " (limit)", \
240 actualStream.str (), limitStream.str (), \
241 msgStream.str (), file, line); \
273 #define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
274 NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
286 #define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
288 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
291 std::ostringstream msgStream; \
293 std::ostringstream actualStream; \
294 actualStream << actual; \
295 std::ostringstream limitStream; \
296 limitStream << limit << " +- " << tol; \
297 std::ostringstream condStream; \
298 condStream << #actual << " (actual) < " << #limit \
299 << " (limit) + " << #tol << " (tol) && " \
300 << #actual << " (actual) > " << #limit \
301 << " (limit) - " << #tol << " (tol)"; \
302 ReportTestFailure (condStream.str (), actualStream.str (), \
303 limitStream.str (), msgStream.str (), \
305 CONTINUE_ON_FAILURE; \
362 #define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
363 NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
370 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line) \
372 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
375 std::ostringstream msgStream; \
377 std::ostringstream actualStream; \
378 actualStream << actual; \
379 std::ostringstream limitStream; \
380 limitStream << limit << " +- " << tol; \
381 std::ostringstream condStream; \
382 condStream << #actual << " (actual) < " << #limit \
383 << " (limit) + " << #tol << " (tol) && " \
384 << #actual << " (actual) > " << #limit \
385 << " (limit) - " << #tol << " (tol)"; \
386 ReportTestFailure (condStream.str (), actualStream.str (), \
387 limitStream.str (), msgStream.str (), \
389 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
449 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
450 NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
460 #define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
462 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
465 std::ostringstream msgStream; \
467 std::ostringstream actualStream; \
468 actualStream << actual; \
469 std::ostringstream limitStream; \
470 limitStream << limit << " +- " << tol; \
471 std::ostringstream condStream; \
472 condStream << #actual << " (actual) < " << #limit \
473 << " (limit) + " << #tol << " (tol) && " \
474 << #actual << " (actual) > " << #limit \
475 << " (limit) - " << #tol << " (tol)"; \
476 ReportTestFailure (condStream.str (), actualStream.str (), \
477 limitStream.str (), msgStream.str (), \
535 #define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
536 NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
547 #define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
549 if (!((actual) != (limit))) \
552 std::ostringstream msgStream; \
554 std::ostringstream actualStream; \
555 actualStream << actual; \
556 std::ostringstream limitStream; \
557 limitStream << limit; \
558 ReportTestFailure (std::string (#actual) + " (actual) != " + \
559 std::string (#limit) + " (limit)", \
560 actualStream.str (), limitStream.str (), \
561 msgStream.str (), file, line); \
562 CONTINUE_ON_FAILURE; \
593 #define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
594 NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
601 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
603 if (!((actual) != (limit))) \
606 std::ostringstream msgStream; \
608 std::ostringstream actualStream; \
609 actualStream << actual; \
610 std::ostringstream limitStream; \
611 limitStream << limit; \
612 ReportTestFailure (std::string (#actual) + " (actual) != " + \
613 std::string (#limit) + " (limit)", \
614 actualStream.str (), limitStream.str (), \
615 msgStream.str (), file, line); \
616 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
650 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
651 NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
661 #define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
663 if (!((actual) != (limit))) \
666 std::ostringstream msgStream; \
668 std::ostringstream actualStream; \
669 actualStream << actual; \
670 std::ostringstream limitStream; \
671 limitStream << limit; \
672 ReportTestFailure (std::string (#actual) + " (actual) != " + \
673 std::string (#limit) + " (limit)", \
674 actualStream.str (), limitStream.str (), \
675 msgStream.str (), file, line); \
706 #define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
707 NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
718 #define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
720 if (!((actual) < (limit))) \
723 std::ostringstream msgStream; \
725 std::ostringstream actualStream; \
726 actualStream << actual; \
727 std::ostringstream limitStream; \
728 limitStream << limit; \
729 ReportTestFailure (std::string (#actual) + " (actual) < " + \
730 std::string (#limit) + " (limit)", \
731 actualStream.str (), limitStream.str (), \
732 msgStream.str (), file, line); \
733 CONTINUE_ON_FAILURE; \
742 #define NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
744 if (!((actual) <= (limit))) \
747 std::ostringstream msgStream; \
749 std::ostringstream actualStream; \
750 actualStream << actual; \
751 std::ostringstream limitStream; \
752 limitStream << limit; \
753 ReportTestFailure (std::string (#actual) + " (actual) < " + \
754 std::string (#limit) + " (limit)", \
755 actualStream.str (), limitStream.str (), \
756 msgStream.str (), file, line); \
757 CONTINUE_ON_FAILURE; \
778 #define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
779 NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
798 #define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
799 NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
808 #define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
810 if (!((actual) < (limit))) \
813 std::ostringstream msgStream; \
815 std::ostringstream actualStream; \
816 actualStream << actual; \
817 std::ostringstream limitStream; \
818 limitStream << limit; \
819 ReportTestFailure (std::string (#actual) + " (actual) < " + \
820 std::string (#limit) + " (limit)", \
821 actualStream.str (), limitStream.str (), \
822 msgStream.str (), file, line); \
834 #define NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
836 if (!((actual) <= (limit))) \
839 std::ostringstream msgStream; \
841 std::ostringstream actualStream; \
842 actualStream << actual; \
843 std::ostringstream limitStream; \
844 limitStream << limit; \
845 ReportTestFailure (std::string (#actual) + " (actual) < " + \
846 std::string (#limit) + " (limit)", \
847 actualStream.str (), limitStream.str (), \
848 msgStream.str (), file, line); \
868 #define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
869 NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
888 #define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
889 NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
900 #define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
902 if (!((actual) > (limit))) \
905 std::ostringstream msgStream; \
907 std::ostringstream actualStream; \
908 actualStream << actual; \
909 std::ostringstream limitStream; \
910 limitStream << limit; \
911 ReportTestFailure (std::string (#actual) + " (actual) > " + \
912 std::string (#limit) + " (limit)", \
913 actualStream.str (), limitStream.str (), \
914 msgStream.str (), file, line); \
915 CONTINUE_ON_FAILURE; \
924 #define NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
926 if (!((actual) >= (limit))) \
929 std::ostringstream msgStream; \
931 std::ostringstream actualStream; \
932 actualStream << actual; \
933 std::ostringstream limitStream; \
934 limitStream << limit; \
935 ReportTestFailure (std::string (#actual) + " (actual) > " + \
936 std::string (#limit) + " (limit)", \
937 actualStream.str (), limitStream.str (), \
938 msgStream.str (), file, line); \
939 CONTINUE_ON_FAILURE; \
960 #define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
961 NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
980 #define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
981 NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
990 #define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
992 if (!((actual) > (limit))) \
995 std::ostringstream msgStream; \
997 std::ostringstream actualStream; \
998 actualStream << actual; \
999 std::ostringstream limitStream; \
1000 limitStream << limit; \
1001 ReportTestFailure (std::string (#actual) + " (actual) > " + \
1002 std::string (#limit) + " (limit)", \
1003 actualStream.str (), limitStream.str (), \
1004 msgStream.str (), file, line); \
1016 #define NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
1018 if (!((actual) >= (limit))) \
1020 ASSERT_ON_FAILURE; \
1021 std::ostringstream msgStream; \
1023 std::ostringstream actualStream; \
1024 actualStream << actual; \
1025 std::ostringstream limitStream; \
1026 limitStream << limit; \
1027 ReportTestFailure (std::string (#actual) + " (actual) > " + \
1028 std::string (#limit) + " (limit)", \
1029 actualStream.str (), limitStream.str (), \
1030 msgStream.str (), file, line); \
1050 #define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
1051 NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1070 #define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
1071 NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1097 class TestRunnerImpl;
1129 std::string
GetName (
void)
const;
1190 std::string limit, std::string message,
1191 std::string file, int32_t line);
1229 virtual void DoRun (
void) = 0;
1308 virtual void DoRun (
void);
1329 static int Run (
int argc,
char *argv[]);
1337 template <
typename T>
1353 void Reserve (uint32_t reserve);
1359 uint32_t
Add (T vector);
1364 uint32_t
GetN (
void)
const;
1370 T
Get (uint32_t i)
const;
1390 template <
typename T>
1396 template <
typename T>
1400 m_vectors.reserve (reserve);
1403 template <
typename T>
1408 template <
typename T>
1412 uint32_t index = m_vectors.size ();
1413 m_vectors.push_back (vector);
1417 template <
typename T>
1421 return m_vectors.size ();
1424 template <
typename T>
1429 return m_vectors[i];
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
TestVectors & operator=(const TestVectors &tv)
Assignment, private to prevent copying.
T Get(uint32_t i) const
Get the i'th test vector.
virtual ~TestVectors()
Virtual desctructor.
A runner to execute tests.
void Reserve(uint32_t reserve)
bool IsFailed(void) const
std::vector< T > TestVector
Container type.
enum TestDuration m_duration
TestCase duration.
This test suite implements a Unit Test.
uint32_t GetN(void) const
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
TestDuration
How long the test takes to execute.
This test suite implements an Example Test.
A simple way to store test vectors (for stimulus or from responses)
virtual void DoRun(void)
Implementation to actually run this TestCase.
TestVectors()
Constructor.
TestCase * m_parent
Pointer to my parent TestCase.
TestRunnerImpl * m_runner
Pointer to the TestRunner.
System-independent wall clock class ns3::SystemWallClockMs declaration.
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
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...
TestSuite::Type m_type
Type of this TestSuite.
bool MustAssertOnFailure(void) const
TestCase(std::string name)
virtual ~TestCase()
Destructor.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string CreateDataDirFilename(std::string filename)
This test suite implements a Performance Test.
virtual void DoRun(void)=0
Implementation to actually run this TestCase.
struct Result * m_result
Results data.
bool IsStatusFailure(void) const
TestCase * GetParent() const
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.
bool operator==(const TestVectors &tv) const
Comparison (unimplemented?)
void Run(TestRunnerImpl *runner)
Actually run this TestCase.
bool IsStatusSuccess(void) const
This test suite implements a System Test.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
std::string CreateTempDirFilename(std::string filename)
This test suite implements a Build Verification Test.
void SetDataDir(std::string directory)
TestVector m_vectors
The list of test vectors.
std::vector< TestCase * > m_children
Vector of my children.
std::string GetName(void) const
TestSuite::Type GetTestType(void)
get the kind of test this test suite implements
static int Run(int argc, char *argv[])
Run the requested suite of tests.
std::string m_name
TestCase name.
TestCase & operator=(TestCase &tc)
Private, to block copying.
std::string m_dataDir
My data directory.
bool MustContinueOnFailure(void) const