76 #define ASSERT_ON_FAILURE \
79 if (MustAssertOnFailure()) \
81 *(volatile int*)0 = 0; \
89 #define CONTINUE_ON_FAILURE \
92 if (!MustContinueOnFailure()) \
102 #define CONTINUE_ON_FAILURE_RETURNS_BOOL \
105 if (!MustContinueOnFailure()) \
107 return IsStatusFailure(); \
144 #define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
147 if (!((actual) == (limit))) \
150 std::ostringstream msgStream; \
152 std::ostringstream actualStream; \
153 actualStream << actual; \
154 std::ostringstream limitStream; \
155 limitStream << limit; \
156 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
158 actualStream.str(), \
163 CONTINUE_ON_FAILURE; \
199 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
202 if (!((actual) == (limit))) \
205 std::ostringstream msgStream; \
207 std::ostringstream actualStream; \
208 actualStream << actual; \
209 std::ostringstream limitStream; \
210 limitStream << limit; \
211 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
213 actualStream.str(), \
218 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
251 #define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
254 if (!((actual) == (limit))) \
257 std::ostringstream msgStream; \
259 std::ostringstream actualStream; \
260 actualStream << actual; \
261 std::ostringstream limitStream; \
262 limitStream << limit; \
263 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
265 actualStream.str(), \
337 #define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
340 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
343 std::ostringstream msgStream; \
345 std::ostringstream actualStream; \
346 actualStream << actual; \
347 std::ostringstream limitStream; \
348 limitStream << limit << " +- " << tol; \
349 std::ostringstream condStream; \
350 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
351 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
352 << #tol << " (tol)"; \
353 ReportTestFailure(condStream.str(), \
354 actualStream.str(), \
359 CONTINUE_ON_FAILURE; \
425 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
428 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
431 std::ostringstream msgStream; \
433 std::ostringstream actualStream; \
434 actualStream << actual; \
435 std::ostringstream limitStream; \
436 limitStream << limit << " +- " << tol; \
437 std::ostringstream condStream; \
438 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
439 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
440 << #tol << " (tol)"; \
441 ReportTestFailure(condStream.str(), \
442 actualStream.str(), \
447 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
510 #define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
513 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
516 std::ostringstream msgStream; \
518 std::ostringstream actualStream; \
519 actualStream << actual; \
520 std::ostringstream limitStream; \
521 limitStream << limit << " +- " << tol; \
522 std::ostringstream condStream; \
523 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
524 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
525 << #tol << " (tol)"; \
526 ReportTestFailure(condStream.str(), \
527 actualStream.str(), \
564 #define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
567 if (!((actual) != (limit))) \
570 std::ostringstream msgStream; \
572 std::ostringstream actualStream; \
573 actualStream << actual; \
574 std::ostringstream limitStream; \
575 limitStream << limit; \
576 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
578 actualStream.str(), \
583 CONTINUE_ON_FAILURE; \
615 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
618 if (!((actual) != (limit))) \
621 std::ostringstream msgStream; \
623 std::ostringstream actualStream; \
624 actualStream << actual; \
625 std::ostringstream limitStream; \
626 limitStream << limit; \
627 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
629 actualStream.str(), \
634 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
666 #define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
669 if (!((actual) != (limit))) \
672 std::ostringstream msgStream; \
674 std::ostringstream actualStream; \
675 actualStream << actual; \
676 std::ostringstream limitStream; \
677 limitStream << limit; \
678 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
680 actualStream.str(), \
709 #define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
712 if (!((actual) < (limit))) \
715 std::ostringstream msgStream; \
717 std::ostringstream actualStream; \
718 actualStream << actual; \
719 std::ostringstream limitStream; \
720 limitStream << limit; \
721 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
723 actualStream.str(), \
728 CONTINUE_ON_FAILURE; \
750 #define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
753 if (!((actual) <= (limit))) \
756 std::ostringstream msgStream; \
758 std::ostringstream actualStream; \
759 actualStream << actual; \
760 std::ostringstream limitStream; \
761 limitStream << limit; \
762 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
764 actualStream.str(), \
769 CONTINUE_ON_FAILURE; \
790 #define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
793 if (!((actual) < (limit))) \
796 std::ostringstream msgStream; \
798 std::ostringstream actualStream; \
799 actualStream << actual; \
800 std::ostringstream limitStream; \
801 limitStream << limit; \
802 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
804 actualStream.str(), \
830 #define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
833 if (!((actual) <= (limit))) \
836 std::ostringstream msgStream; \
838 std::ostringstream actualStream; \
839 actualStream << actual; \
840 std::ostringstream limitStream; \
841 limitStream << limit; \
842 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
844 actualStream.str(), \
874 #define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
877 if (!((actual) > (limit))) \
880 std::ostringstream msgStream; \
882 std::ostringstream actualStream; \
883 actualStream << actual; \
884 std::ostringstream limitStream; \
885 limitStream << limit; \
886 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
888 actualStream.str(), \
893 CONTINUE_ON_FAILURE; \
915 #define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
918 if (!((actual) >= (limit))) \
921 std::ostringstream msgStream; \
923 std::ostringstream actualStream; \
924 actualStream << actual; \
925 std::ostringstream limitStream; \
926 limitStream << limit; \
927 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
929 actualStream.str(), \
934 CONTINUE_ON_FAILURE; \
956 #define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
959 if (!((actual) > (limit))) \
962 std::ostringstream msgStream; \
964 std::ostringstream actualStream; \
965 actualStream << actual; \
966 std::ostringstream limitStream; \
967 limitStream << limit; \
968 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
970 actualStream.str(), \
996 #define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
999 if (!((actual) >= (limit))) \
1001 ASSERT_ON_FAILURE; \
1002 std::ostringstream msgStream; \
1004 std::ostringstream actualStream; \
1005 actualStream << actual; \
1006 std::ostringstream limitStream; \
1007 limitStream << limit; \
1008 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
1010 actualStream.str(), \
1011 limitStream.str(), \
1046 class TestRunnerImpl;
1158 std::string message,
1288 void DoRun()
override;
1309 static int Run(
int argc,
char* argv[]);
1317 template <
typename T>
1365 template <
typename T>
1371 template <
typename T>
1375 m_vectors.reserve(reserve);
1378 template <
typename T>
1383 template <
typename T>
1387 std::size_t index = m_vectors.size();
1388 m_vectors.push_back(vector);
1392 template <
typename T>
1396 return m_vectors.size();
1399 template <
typename T>
1404 return m_vectors[i];
std::string m_name
TestCase name.
TestDuration
How long the test takes to execute.
@ EXTENSIVE
Medium length test.
@ TAKES_FOREVER
Very long running test.
bool MustContinueOnFailure() const
Check if this run should continue on failure.
bool IsStatusFailure() const
Check if any tests failed.
std::string m_dataDir
My data directory.
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
TestCase * m_parent
Pointer to my parent TestCase.
Result * m_result
Results data.
bool IsStatusSuccess() const
Check if all tests passed.
virtual void DoSetup()
Implementation to do any local setup required for this TestCase.
virtual ~TestCase()
Destructor.
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
TestRunnerImpl * m_runner
Pointer to the TestRunner.
TestCase * GetParent() const
Get the parent of this TestCase.
TestDuration m_duration
TestCase duration.
bool MustAssertOnFailure() const
Check if this run should assert on failure.
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
virtual void DoTeardown()
Implementation to do any local setup required for this TestCase.
void Run(TestRunnerImpl *runner)
Actually run this TestCase.
TestCase(const TestCase &)=delete
virtual void DoRun()=0
Implementation to actually run this TestCase.
TestCase & operator=(const TestCase &)=delete
std::string GetName() 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 IsFailed() const
Check if any tests failed.
std::vector< TestCase * > m_children
Vector of my children.
A runner to execute tests.
static int Run(int argc, char *argv[])
Run the requested suite of tests, according to the given command line arguments.
@ EXAMPLE
This test suite implements an Example Test.
@ PERFORMANCE
This test suite implements a Performance Test.
@ UNIT
This test suite implements a Unit Test.
@ SYSTEM
This test suite implements a System Test.
TestSuite::Type m_type
Type of this TestSuite.
TestSuite(std::string name, Type type=UNIT)
Construct a new test suite.
void DoRun() override
Implementation to actually run this TestCase.
TestSuite::Type GetTestType()
get the kind of test this test suite implements
A simple way to store test vectors (for stimulus or from responses)
std::vector< T > TestVector
Container type.
TestVectors & operator=(const TestVectors &)=delete
T Get(std::size_t i) const
Get the i'th test vector.
std::size_t GetN() const
Get the total number of test vectors.
TestVectors(const TestVectors &)=delete
TestVectors()
Constructor.
void Reserve(uint32_t reserve)
Set the expected length of this vector.
std::size_t Add(T vector)
TestVector m_vectors
The list of test vectors.
virtual ~TestVectors()
Virtual destructor.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
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...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Container for results from a TestCase.
ns3::SystemWallClockMs declaration.