77#define ASSERT_ON_FAILURE \
80 if (MustAssertOnFailure()) \
82 *(volatile int*)0 = 0; \
90#define CONTINUE_ON_FAILURE \
93 if (!MustContinueOnFailure()) \
103#define CONTINUE_ON_FAILURE_RETURNS_BOOL \
106 if (!MustContinueOnFailure()) \
108 return IsStatusFailure(); \
145#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
148 if (!((actual) == (limit))) \
151 std::ostringstream msgStream; \
153 std::ostringstream actualStream; \
154 actualStream << actual; \
155 std::ostringstream limitStream; \
156 limitStream << limit; \
157 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
159 actualStream.str(), \
164 CONTINUE_ON_FAILURE; \
200#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
203 if (!((actual) == (limit))) \
206 std::ostringstream msgStream; \
208 std::ostringstream actualStream; \
209 actualStream << actual; \
210 std::ostringstream limitStream; \
211 limitStream << limit; \
212 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
214 actualStream.str(), \
219 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
252#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
255 if (!((actual) == (limit))) \
258 std::ostringstream msgStream; \
260 std::ostringstream actualStream; \
261 actualStream << actual; \
262 std::ostringstream limitStream; \
263 limitStream << limit; \
264 ReportTestFailure(std::string(#actual) + " (actual) == " + std::string(#limit) + \
266 actualStream.str(), \
338#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
341 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
344 std::ostringstream msgStream; \
346 std::ostringstream actualStream; \
347 actualStream << actual; \
348 std::ostringstream limitStream; \
349 limitStream << limit << " +- " << tol; \
350 std::ostringstream condStream; \
351 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
352 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
353 << #tol << " (tol)"; \
354 ReportTestFailure(condStream.str(), \
355 actualStream.str(), \
360 CONTINUE_ON_FAILURE; \
426#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
429 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
432 std::ostringstream msgStream; \
434 std::ostringstream actualStream; \
435 actualStream << actual; \
436 std::ostringstream limitStream; \
437 limitStream << limit << " +- " << tol; \
438 std::ostringstream condStream; \
439 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
440 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
441 << #tol << " (tol)"; \
442 ReportTestFailure(condStream.str(), \
443 actualStream.str(), \
448 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
511#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
514 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
517 std::ostringstream msgStream; \
519 std::ostringstream actualStream; \
520 actualStream << actual; \
521 std::ostringstream limitStream; \
522 limitStream << limit << " +- " << tol; \
523 std::ostringstream condStream; \
524 condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol \
525 << " (tol) && " << #actual << " (actual) > " << #limit << " (limit) - " \
526 << #tol << " (tol)"; \
527 ReportTestFailure(condStream.str(), \
528 actualStream.str(), \
565#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
568 if (!((actual) != (limit))) \
571 std::ostringstream msgStream; \
573 std::ostringstream actualStream; \
574 actualStream << actual; \
575 std::ostringstream limitStream; \
576 limitStream << limit; \
577 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
579 actualStream.str(), \
584 CONTINUE_ON_FAILURE; \
616#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
619 if (!((actual) != (limit))) \
622 std::ostringstream msgStream; \
624 std::ostringstream actualStream; \
625 actualStream << actual; \
626 std::ostringstream limitStream; \
627 limitStream << limit; \
628 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
630 actualStream.str(), \
635 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
667#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
670 if (!((actual) != (limit))) \
673 std::ostringstream msgStream; \
675 std::ostringstream actualStream; \
676 actualStream << actual; \
677 std::ostringstream limitStream; \
678 limitStream << limit; \
679 ReportTestFailure(std::string(#actual) + " (actual) != " + std::string(#limit) + \
681 actualStream.str(), \
710#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
713 if (!((actual) < (limit))) \
716 std::ostringstream msgStream; \
718 std::ostringstream actualStream; \
719 actualStream << actual; \
720 std::ostringstream limitStream; \
721 limitStream << limit; \
722 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
724 actualStream.str(), \
729 CONTINUE_ON_FAILURE; \
751#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
754 if (!((actual) <= (limit))) \
757 std::ostringstream msgStream; \
759 std::ostringstream actualStream; \
760 actualStream << actual; \
761 std::ostringstream limitStream; \
762 limitStream << limit; \
763 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
765 actualStream.str(), \
770 CONTINUE_ON_FAILURE; \
791#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
794 if (!((actual) < (limit))) \
797 std::ostringstream msgStream; \
799 std::ostringstream actualStream; \
800 actualStream << actual; \
801 std::ostringstream limitStream; \
802 limitStream << limit; \
803 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
805 actualStream.str(), \
831#define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
834 if (!((actual) <= (limit))) \
837 std::ostringstream msgStream; \
839 std::ostringstream actualStream; \
840 actualStream << actual; \
841 std::ostringstream limitStream; \
842 limitStream << limit; \
843 ReportTestFailure(std::string(#actual) + " (actual) < " + std::string(#limit) + \
845 actualStream.str(), \
875#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
878 if (!((actual) > (limit))) \
881 std::ostringstream msgStream; \
883 std::ostringstream actualStream; \
884 actualStream << actual; \
885 std::ostringstream limitStream; \
886 limitStream << limit; \
887 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
889 actualStream.str(), \
894 CONTINUE_ON_FAILURE; \
916#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
919 if (!((actual) >= (limit))) \
922 std::ostringstream msgStream; \
924 std::ostringstream actualStream; \
925 actualStream << actual; \
926 std::ostringstream limitStream; \
927 limitStream << limit; \
928 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
930 actualStream.str(), \
935 CONTINUE_ON_FAILURE; \
957#define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
960 if (!((actual) > (limit))) \
963 std::ostringstream msgStream; \
965 std::ostringstream actualStream; \
966 actualStream << actual; \
967 std::ostringstream limitStream; \
968 limitStream << limit; \
969 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
971 actualStream.str(), \
997#define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
1000 if (!((actual) >= (limit))) \
1002 ASSERT_ON_FAILURE; \
1003 std::ostringstream msgStream; \
1005 std::ostringstream actualStream; \
1006 actualStream << actual; \
1007 std::ostringstream limitStream; \
1008 limitStream << limit; \
1009 ReportTestFailure(std::string(#actual) + " (actual) > " + std::string(#limit) + \
1011 actualStream.str(), \
1012 limitStream.str(), \
1045 const double epsilon = std::numeric_limits<double>::epsilon());
1047class TestRunnerImpl;
1170 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;
1316 void DoRun() override;
1337 static int Run(
int argc,
char* argv[]);
1345template <
typename T>
1391 typename std::vector<T>::iterator
begin()
1393 return m_vectors.begin();
1399 typename std::vector<T>::iterator
end()
1401 return m_vectors.end();
1407 typename std::vector<T>::const_iterator
begin()
const
1409 return m_vectors.begin();
1415 typename std::vector<T>::const_iterator
end()
const
1417 return m_vectors.end();
1425template <
typename T>
1431template <
typename T>
1435 m_vectors.reserve(reserve);
1438template <
typename T>
1443template <
typename T>
1447 std::size_t index = m_vectors.size();
1448 m_vectors.push_back(vector);
1452template <
typename T>
1456 return m_vectors.size();
1459template <
typename T>
1464 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
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.