65#define ASSERT_ON_FAILURE \
68 if (MustAssertOnFailure()) \
70 *(volatile int*)0 = 0; \
78#define CONTINUE_ON_FAILURE \
81 if (!MustContinueOnFailure()) \
91#define CONTINUE_ON_FAILURE_RETURNS_BOOL \
94 if (!MustContinueOnFailure()) \
96 return IsStatusFailure(); \
133#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
136 if (!((actual) == (limit))) \
139 std::ostringstream msgStream; \
141 std::ostringstream actualStream; \
142 actualStream << (actual); \
143 std::ostringstream limitStream; \
144 limitStream << (limit); \
145 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
147 actualStream.str(), \
152 CONTINUE_ON_FAILURE; \
188#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
191 if (!((actual) == (limit))) \
194 std::ostringstream msgStream; \
196 std::ostringstream actualStream; \
197 actualStream << (actual); \
198 std::ostringstream limitStream; \
199 limitStream << (limit); \
200 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
202 actualStream.str(), \
207 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
240#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
243 if (!((actual) == (limit))) \
246 std::ostringstream msgStream; \
248 std::ostringstream actualStream; \
249 actualStream << (actual); \
250 std::ostringstream limitStream; \
251 limitStream << (limit); \
252 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
254 actualStream.str(), \
326#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
329 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
332 std::ostringstream msgStream; \
334 std::ostringstream actualStream; \
335 actualStream << (actual); \
336 std::ostringstream limitStream; \
337 limitStream << (limit) << " +- " << tol; \
338 std::ostringstream condStream; \
339 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
340 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
341 << #tol << " (tol)"; \
342 ReportTestFailure(condStream.str(), \
343 actualStream.str(), \
348 CONTINUE_ON_FAILURE; \
414#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
417 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
420 std::ostringstream msgStream; \
422 std::ostringstream actualStream; \
423 actualStream << (actual); \
424 std::ostringstream limitStream; \
425 limitStream << (limit) << " +- " << tol; \
426 std::ostringstream condStream; \
427 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
428 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
429 << #tol << " (tol)"; \
430 ReportTestFailure(condStream.str(), \
431 actualStream.str(), \
436 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
499#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
502 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
505 std::ostringstream msgStream; \
507 std::ostringstream actualStream; \
508 actualStream << (actual); \
509 std::ostringstream limitStream; \
510 limitStream << (limit) << " +- " << tol; \
511 std::ostringstream condStream; \
512 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
513 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
514 << #tol << " (tol)"; \
515 ReportTestFailure(condStream.str(), \
516 actualStream.str(), \
553#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
556 if (!((actual) != (limit))) \
559 std::ostringstream msgStream; \
561 std::ostringstream actualStream; \
562 actualStream << (actual); \
563 std::ostringstream limitStream; \
564 limitStream << (limit); \
565 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
567 actualStream.str(), \
572 CONTINUE_ON_FAILURE; \
604#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
607 if (!((actual) != (limit))) \
610 std::ostringstream msgStream; \
612 std::ostringstream actualStream; \
613 actualStream << (actual); \
614 std::ostringstream limitStream; \
615 limitStream << (limit); \
616 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
618 actualStream.str(), \
623 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
655#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
658 if (!((actual) != (limit))) \
661 std::ostringstream msgStream; \
663 std::ostringstream actualStream; \
664 actualStream << (actual); \
665 std::ostringstream limitStream; \
666 limitStream << (limit); \
667 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
669 actualStream.str(), \
698#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
701 if (!((actual) < (limit))) \
704 std::ostringstream msgStream; \
706 std::ostringstream actualStream; \
707 actualStream << (actual); \
708 std::ostringstream limitStream; \
709 limitStream << (limit); \
710 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
712 actualStream.str(), \
717 CONTINUE_ON_FAILURE; \
739#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
742 if (!((actual) <= (limit))) \
745 std::ostringstream msgStream; \
747 std::ostringstream actualStream; \
748 actualStream << (actual); \
749 std::ostringstream limitStream; \
750 limitStream << (limit); \
751 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
753 actualStream.str(), \
758 CONTINUE_ON_FAILURE; \
779#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
782 if (!((actual) < (limit))) \
785 std::ostringstream msgStream; \
787 std::ostringstream actualStream; \
788 actualStream << (actual); \
789 std::ostringstream limitStream; \
790 limitStream << (limit); \
791 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
793 actualStream.str(), \
819#define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
822 if (!((actual) <= (limit))) \
825 std::ostringstream msgStream; \
827 std::ostringstream actualStream; \
828 actualStream << (actual); \
829 std::ostringstream limitStream; \
830 limitStream << (limit); \
831 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
833 actualStream.str(), \
863#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
866 if (!((actual) > (limit))) \
869 std::ostringstream msgStream; \
871 std::ostringstream actualStream; \
872 actualStream << (actual); \
873 std::ostringstream limitStream; \
874 limitStream << (limit); \
875 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
877 actualStream.str(), \
882 CONTINUE_ON_FAILURE; \
904#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
907 if (!((actual) >= (limit))) \
910 std::ostringstream msgStream; \
912 std::ostringstream actualStream; \
913 actualStream << (actual); \
914 std::ostringstream limitStream; \
915 limitStream << (limit); \
916 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
918 actualStream.str(), \
923 CONTINUE_ON_FAILURE; \
945#define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
948 if (!((actual) > (limit))) \
951 std::ostringstream msgStream; \
953 std::ostringstream actualStream; \
954 actualStream << (actual); \
955 std::ostringstream limitStream; \
956 limitStream << (limit); \
957 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
959 actualStream.str(), \
985#define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
988 if (!((actual) >= (limit))) \
991 std::ostringstream msgStream; \
993 std::ostringstream actualStream; \
994 actualStream << (actual); \
995 std::ostringstream limitStream; \
996 limitStream << (limit); \
997 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
999 actualStream.str(), \
1000 limitStream.str(), \
1033 const double epsilon = std::numeric_limits<double>::epsilon());
1035class TestRunnerImpl;
1147 std::string message,
1282 void DoRun()
override;
1303 static int Run(
int argc,
char* argv[]);
1311template <
typename T>
1357 typename std::vector<T>::iterator
begin()
1365 typename std::vector<T>::iterator
end()
1373 typename std::vector<T>::const_iterator
begin()
const
1381 typename std::vector<T>::const_iterator
end()
const
1391template <
typename T>
1397template <
typename T>
1404template <
typename T>
1409template <
typename T>
1418template <
typename T>
1425template <
typename T>
std::string m_name
TestCase name.
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.
TestCase * m_parent
Pointer to my parent TestCase.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
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.
Duration
How long the test takes to execute.
@ EXTENSIVE
Medium length test.
@ TAKES_FOREVER
Very long running test.
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.
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)
Executes DoSetup(), DoRun(), and DoTeardown() for the TestCase.
TestCase(const TestCase &)=delete
virtual void DoRun()=0
Implementation to actually run this TestCase.
std::string GetName() const
friend class TestRunnerImpl
Needs access to the TestCase data members.
Duration m_duration
TestCase duration.
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.
TestCase & operator=(const TestCase &)=delete
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.
@ PERFORMANCE
This test suite implements a Performance Test.
@ ALL
Token to represent all tests.
@ EXAMPLE
This test suite implements an Example Test.
@ UNIT
This test suite implements a Unit Test.
@ SYSTEM
This test suite implements a System Test.
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
TestSuite::Type m_type
Type of this TestSuite.
void DoRun() override
Implementation to actually run this TestCase.
TestSuite::Type GetTestType()
get the kind of test this test suite implements
std::vector< T >::iterator begin()
std::vector< T > TestVector
Container type.
std::vector< T >::const_iterator begin() const
std::vector< T >::iterator end()
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::vector< T >::const_iterator end() const
std::size_t Add(T vector)
TestVector m_vectors
The list of test vectors.
virtual ~TestVectors()
Virtual destructor.
TestVectors & operator=(const TestVectors &)=delete
#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...
Namespace for test files, TestCases and TestSuites.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Container for results from a TestCase.
ns3::SystemWallClockMs declaration.