62 #define ASSERT_ON_FAILURE \
64 if (MustAssertOnFailure ()) \
66 *(volatile int *)0 = 0; \
74 #define CONTINUE_ON_FAILURE \
76 if (!MustContinueOnFailure ()) \
86 #define CONTINUE_ON_FAILURE_RETURNS_BOOL \
88 if (!MustContinueOnFailure ()) \
90 return IsStatusFailure (); \
105 #define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
107 if (!((actual) == (limit))) \
110 std::ostringstream msgStream; \
112 std::ostringstream actualStream; \
113 actualStream << actual; \
114 std::ostringstream limitStream; \
115 limitStream << limit; \
116 ReportTestFailure (std::string (#actual) + " (actual) == " + \
117 std::string (#limit) + " (limit)", \
118 actualStream.str (), limitStream.str (), \
119 msgStream.str (), file, line); \
120 CONTINUE_ON_FAILURE; \
152 #define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
153 NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
160 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
162 if (!((actual) == (limit))) \
165 std::ostringstream msgStream; \
167 std::ostringstream actualStream; \
168 actualStream << actual; \
169 std::ostringstream limitStream; \
170 limitStream << limit; \
171 ReportTestFailure (std::string (#actual) + " (actual) == " + \
172 std::string (#limit) + " (limit)", \
173 actualStream.str (), limitStream.str (), \
174 msgStream.str (), file, line); \
175 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
210 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
211 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
221 #define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
223 if (!((actual) == (limit))) \
226 std::ostringstream msgStream; \
228 std::ostringstream actualStream; \
229 actualStream << actual; \
230 std::ostringstream limitStream; \
231 limitStream << limit; \
232 ReportTestFailure (std::string (#actual) + " (actual) == " + \
233 std::string (#limit) + " (limit)", \
234 actualStream.str (), limitStream.str (), \
235 msgStream.str (), file, line); \
267 #define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
268 NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
280 #define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
282 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
285 std::ostringstream msgStream; \
287 std::ostringstream actualStream; \
288 actualStream << actual; \
289 std::ostringstream limitStream; \
290 limitStream << limit << " +- " << tol; \
291 std::ostringstream condStream; \
292 condStream << #actual << " (actual) < " << #limit \
293 << " (limit) + " << #tol << " (tol) && " \
294 << #actual << " (actual) > " << #limit \
295 << " (limit) - " << #tol << " (tol)"; \
296 ReportTestFailure (condStream.str (), actualStream.str (), \
297 limitStream.str (), msgStream.str (), \
299 CONTINUE_ON_FAILURE; \
356 #define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
357 NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
364 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line) \
366 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
369 std::ostringstream msgStream; \
371 std::ostringstream actualStream; \
372 actualStream << actual; \
373 std::ostringstream limitStream; \
374 limitStream << limit << " +- " << tol; \
375 std::ostringstream condStream; \
376 condStream << #actual << " (actual) < " << #limit \
377 << " (limit) + " << #tol << " (tol) && " \
378 << #actual << " (actual) > " << #limit \
379 << " (limit) - " << #tol << " (tol)"; \
380 ReportTestFailure (condStream.str (), actualStream.str (), \
381 limitStream.str (), msgStream.str (), \
383 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
443 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
444 NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
454 #define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
456 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
459 std::ostringstream msgStream; \
461 std::ostringstream actualStream; \
462 actualStream << actual; \
463 std::ostringstream limitStream; \
464 limitStream << limit << " +- " << tol; \
465 std::ostringstream condStream; \
466 condStream << #actual << " (actual) < " << #limit \
467 << " (limit) + " << #tol << " (tol) && " \
468 << #actual << " (actual) > " << #limit \
469 << " (limit) - " << #tol << " (tol)"; \
470 ReportTestFailure (condStream.str (), actualStream.str (), \
471 limitStream.str (), msgStream.str (), \
529 #define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
530 NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
541 #define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
543 if (!((actual) != (limit))) \
546 std::ostringstream msgStream; \
548 std::ostringstream actualStream; \
549 actualStream << actual; \
550 std::ostringstream limitStream; \
551 limitStream << limit; \
552 ReportTestFailure (std::string (#actual) + " (actual) != " + \
553 std::string (#limit) + " (limit)", \
554 actualStream.str (), limitStream.str (), \
555 msgStream.str (), file, line); \
556 CONTINUE_ON_FAILURE; \
587 #define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
588 NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
595 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
597 if (!((actual) != (limit))) \
600 std::ostringstream msgStream; \
602 std::ostringstream actualStream; \
603 actualStream << actual; \
604 std::ostringstream limitStream; \
605 limitStream << limit; \
606 ReportTestFailure (std::string (#actual) + " (actual) != " + \
607 std::string (#limit) + " (limit)", \
608 actualStream.str (), limitStream.str (), \
609 msgStream.str (), file, line); \
610 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
644 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
645 NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
655 #define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
657 if (!((actual) != (limit))) \
660 std::ostringstream msgStream; \
662 std::ostringstream actualStream; \
663 actualStream << actual; \
664 std::ostringstream limitStream; \
665 limitStream << limit; \
666 ReportTestFailure (std::string (#actual) + " (actual) != " + \
667 std::string (#limit) + " (limit)", \
668 actualStream.str (), limitStream.str (), \
669 msgStream.str (), file, line); \
700 #define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
701 NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
712 #define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
714 if (!((actual) < (limit))) \
717 std::ostringstream msgStream; \
719 std::ostringstream actualStream; \
720 actualStream << actual; \
721 std::ostringstream limitStream; \
722 limitStream << limit; \
723 ReportTestFailure (std::string (#actual) + " (actual) < " + \
724 std::string (#limit) + " (limit)", \
725 actualStream.str (), limitStream.str (), \
726 msgStream.str (), file, line); \
727 CONTINUE_ON_FAILURE; \
736 #define NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
738 if (!((actual) <= (limit))) \
741 std::ostringstream msgStream; \
743 std::ostringstream actualStream; \
744 actualStream << actual; \
745 std::ostringstream limitStream; \
746 limitStream << limit; \
747 ReportTestFailure (std::string (#actual) + " (actual) < " + \
748 std::string (#limit) + " (limit)", \
749 actualStream.str (), limitStream.str (), \
750 msgStream.str (), file, line); \
751 CONTINUE_ON_FAILURE; \
772 #define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
773 NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
792 #define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
793 NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
802 #define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
804 if (!((actual) < (limit))) \
807 std::ostringstream msgStream; \
809 std::ostringstream actualStream; \
810 actualStream << actual; \
811 std::ostringstream limitStream; \
812 limitStream << limit; \
813 ReportTestFailure (std::string (#actual) + " (actual) < " + \
814 std::string (#limit) + " (limit)", \
815 actualStream.str (), limitStream.str (), \
816 msgStream.str (), file, line); \
828 #define NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
830 if (!((actual) <= (limit))) \
833 std::ostringstream msgStream; \
835 std::ostringstream actualStream; \
836 actualStream << actual; \
837 std::ostringstream limitStream; \
838 limitStream << limit; \
839 ReportTestFailure (std::string (#actual) + " (actual) < " + \
840 std::string (#limit) + " (limit)", \
841 actualStream.str (), limitStream.str (), \
842 msgStream.str (), file, line); \
862 #define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
863 NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
882 #define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
883 NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
894 #define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
896 if (!((actual) > (limit))) \
899 std::ostringstream msgStream; \
901 std::ostringstream actualStream; \
902 actualStream << actual; \
903 std::ostringstream limitStream; \
904 limitStream << limit; \
905 ReportTestFailure (std::string (#actual) + " (actual) > " + \
906 std::string (#limit) + " (limit)", \
907 actualStream.str (), limitStream.str (), \
908 msgStream.str (), file, line); \
909 CONTINUE_ON_FAILURE; \
918 #define NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
920 if (!((actual) >= (limit))) \
923 std::ostringstream msgStream; \
925 std::ostringstream actualStream; \
926 actualStream << actual; \
927 std::ostringstream limitStream; \
928 limitStream << limit; \
929 ReportTestFailure (std::string (#actual) + " (actual) > " + \
930 std::string (#limit) + " (limit)", \
931 actualStream.str (), limitStream.str (), \
932 msgStream.str (), file, line); \
933 CONTINUE_ON_FAILURE; \
954 #define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
955 NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
974 #define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
975 NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
984 #define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
986 if (!((actual) > (limit))) \
989 std::ostringstream msgStream; \
991 std::ostringstream actualStream; \
992 actualStream << actual; \
993 std::ostringstream limitStream; \
994 limitStream << limit; \
995 ReportTestFailure (std::string (#actual) + " (actual) > " + \
996 std::string (#limit) + " (limit)", \
997 actualStream.str (), limitStream.str (), \
998 msgStream.str (), file, line); \
1010 #define NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
1012 if (!((actual) >= (limit))) \
1014 ASSERT_ON_FAILURE; \
1015 std::ostringstream msgStream; \
1017 std::ostringstream actualStream; \
1018 actualStream << actual; \
1019 std::ostringstream limitStream; \
1020 limitStream << limit; \
1021 ReportTestFailure (std::string (#actual) + " (actual) > " + \
1022 std::string (#limit) + " (limit)", \
1023 actualStream.str (), limitStream.str (), \
1024 msgStream.str (), file, line); \
1044 #define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
1045 NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1064 #define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
1065 NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1089 const double epsilon = std::numeric_limits<double>::epsilon ());
1091 class TestRunnerImpl;
1123 std::string
GetName (
void)
const;
1184 std::string limit, std::string message,
1185 std::string file, int32_t line);
1223 virtual void DoRun (
void) = 0;
1302 virtual void DoRun (
void);
1323 static int Run (
int argc,
char *argv[]);
1331 template <
typename T>
1347 void Reserve (uint32_t reserve);
1353 uint32_t
Add (T vector);
1358 uint32_t
GetN (
void)
const;
1364 T
Get (uint32_t i)
const;
1384 template <
typename T>
1390 template <
typename T>
1394 m_vectors.reserve (reserve);
1397 template <
typename T>
1402 template <
typename T>
1406 uint32_t index = m_vectors.size ();
1407 m_vectors.push_back (vector);
1411 template <
typename T>
1415 return m_vectors.size ();
1418 template <
typename T>
1423 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