66#define ASSERT_ON_FAILURE \
69 if (MustAssertOnFailure()) \
71 *(volatile int*)0 = 0; \
79#define CONTINUE_ON_FAILURE \
82 if (!MustContinueOnFailure()) \
92#define CONTINUE_ON_FAILURE_RETURNS_BOOL \
95 if (!MustContinueOnFailure()) \
97 return IsStatusFailure(); \
134#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
137 if (!((actual) == (limit))) \
140 std::ostringstream msgStream; \
142 std::ostringstream actualStream; \
143 actualStream << actual; \
144 std::ostringstream limitStream; \
145 limitStream << limit; \
146 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
148 actualStream.str(), \
153 CONTINUE_ON_FAILURE; \
189#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
192 if (!((actual) == (limit))) \
195 std::ostringstream msgStream; \
197 std::ostringstream actualStream; \
198 actualStream << actual; \
199 std::ostringstream limitStream; \
200 limitStream << limit; \
201 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
203 actualStream.str(), \
208 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
241#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
244 if (!((actual) == (limit))) \
247 std::ostringstream msgStream; \
249 std::ostringstream actualStream; \
250 actualStream << actual; \
251 std::ostringstream limitStream; \
252 limitStream << limit; \
253 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
255 actualStream.str(), \
327#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
330 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
333 std::ostringstream msgStream; \
335 std::ostringstream actualStream; \
336 actualStream << actual; \
337 std::ostringstream limitStream; \
338 limitStream << limit << " +- " << tol; \
339 std::ostringstream condStream; \
340 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
341 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
342 << #tol << " (tol)"; \
343 ReportTestFailure(condStream.str(), \
344 actualStream.str(), \
349 CONTINUE_ON_FAILURE; \
415#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
418 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
421 std::ostringstream msgStream; \
423 std::ostringstream actualStream; \
424 actualStream << actual; \
425 std::ostringstream limitStream; \
426 limitStream << limit << " +- " << tol; \
427 std::ostringstream condStream; \
428 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
429 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
430 << #tol << " (tol)"; \
431 ReportTestFailure(condStream.str(), \
432 actualStream.str(), \
437 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
500#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
503 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
506 std::ostringstream msgStream; \
508 std::ostringstream actualStream; \
509 actualStream << actual; \
510 std::ostringstream limitStream; \
511 limitStream << limit << " +- " << tol; \
512 std::ostringstream condStream; \
513 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
514 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
515 << #tol << " (tol)"; \
516 ReportTestFailure(condStream.str(), \
517 actualStream.str(), \
554#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
557 if (!((actual) != (limit))) \
560 std::ostringstream msgStream; \
562 std::ostringstream actualStream; \
563 actualStream << actual; \
564 std::ostringstream limitStream; \
565 limitStream << limit; \
566 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
568 actualStream.str(), \
573 CONTINUE_ON_FAILURE; \
605#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
608 if (!((actual) != (limit))) \
611 std::ostringstream msgStream; \
613 std::ostringstream actualStream; \
614 actualStream << actual; \
615 std::ostringstream limitStream; \
616 limitStream << limit; \
617 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
619 actualStream.str(), \
624 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
656#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
659 if (!((actual) != (limit))) \
662 std::ostringstream msgStream; \
664 std::ostringstream actualStream; \
665 actualStream << actual; \
666 std::ostringstream limitStream; \
667 limitStream << limit; \
668 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
670 actualStream.str(), \
699#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
702 if (!((actual) < (limit))) \
705 std::ostringstream msgStream; \
707 std::ostringstream actualStream; \
708 actualStream << actual; \
709 std::ostringstream limitStream; \
710 limitStream << limit; \
711 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
713 actualStream.str(), \
718 CONTINUE_ON_FAILURE; \
740#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
743 if (!((actual) <= (limit))) \
746 std::ostringstream msgStream; \
748 std::ostringstream actualStream; \
749 actualStream << actual; \
750 std::ostringstream limitStream; \
751 limitStream << limit; \
752 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
754 actualStream.str(), \
759 CONTINUE_ON_FAILURE; \
780#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
783 if (!((actual) < (limit))) \
786 std::ostringstream msgStream; \
788 std::ostringstream actualStream; \
789 actualStream << actual; \
790 std::ostringstream limitStream; \
791 limitStream << limit; \
792 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
794 actualStream.str(), \
820#define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
823 if (!((actual) <= (limit))) \
826 std::ostringstream msgStream; \
828 std::ostringstream actualStream; \
829 actualStream << actual; \
830 std::ostringstream limitStream; \
831 limitStream << limit; \
832 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
834 actualStream.str(), \
864#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
867 if (!((actual) > (limit))) \
870 std::ostringstream msgStream; \
872 std::ostringstream actualStream; \
873 actualStream << actual; \
874 std::ostringstream limitStream; \
875 limitStream << limit; \
876 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
878 actualStream.str(), \
883 CONTINUE_ON_FAILURE; \
905#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
908 if (!((actual) >= (limit))) \
911 std::ostringstream msgStream; \
913 std::ostringstream actualStream; \
914 actualStream << actual; \
915 std::ostringstream limitStream; \
916 limitStream << limit; \
917 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
919 actualStream.str(), \
924 CONTINUE_ON_FAILURE; \
946#define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
949 if (!((actual) > (limit))) \
952 std::ostringstream msgStream; \
954 std::ostringstream actualStream; \
955 actualStream << actual; \
956 std::ostringstream limitStream; \
957 limitStream << limit; \
958 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
960 actualStream.str(), \
986#define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
989 if (!((actual) >= (limit))) \
992 std::ostringstream msgStream; \
994 std::ostringstream actualStream; \
995 actualStream << actual; \
996 std::ostringstream limitStream; \
997 limitStream << limit; \
998 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
1000 actualStream.str(), \
1001 limitStream.str(), \
1034 const double epsilon = std::numeric_limits<double>::epsilon());
1036class TestRunnerImpl;
1164 std::
string message,
1289 static constexpr auto ALL =
Type::ALL;
1291 static constexpr auto UNIT =
Type::UNIT;
1293 static constexpr auto SYSTEM =
Type::SYSTEM;
1295 static constexpr auto EXAMPLE =
Type::EXAMPLE;
1297 static constexpr auto PERFORMANCE =
Type::PERFORMANCE;
1317 void DoRun() override;
1338 static int Run(
int argc,
char* argv[]);
1346template <
typename T>
1392 typename std::vector<T>::iterator
begin()
1394 return m_vectors.begin();
1400 typename std::vector<T>::iterator
end()
1402 return m_vectors.end();
1408 typename std::vector<T>::const_iterator
begin()
const
1410 return m_vectors.begin();
1416 typename std::vector<T>::const_iterator
end()
const
1418 return m_vectors.end();
1426template <
typename T>
1432template <
typename T>
1436 m_vectors.reserve(reserve);
1439template <
typename T>
1444template <
typename T>
1448 std::size_t index = m_vectors.size();
1449 m_vectors.push_back(vector);
1453template <
typename T>
1457 return m_vectors.size();
1460template <
typename T>
1465 return m_vectors[i];
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.
static constexpr auto QUICK
Deprecated test duration simple enums.
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.
Duration
How long the test takes to execute.
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.
static constexpr auto TAKES_FOREVER
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.
virtual void DoRun()=0
Implementation to actually run this TestCase.
std::string GetName() const
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.
static constexpr auto EXTENSIVE
bool IsFailed() const
Check if any tests failed.
std::vector< TestCase * > m_children
Vector of my children.
A runner to execute tests.
A simple way to store test vectors (for stimulus or from responses)
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
NS_DEPRECATED macro definition.
#define NS_DEPRECATED_3_42(msg)
Tag for things deprecated in version ns-3.42.
#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.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Container for results from a TestCase.
ns3::SystemWallClockMs declaration.