74 #define ASSERT_ON_FAILURE \
76 if (MustAssertOnFailure ()) \
78 *(volatile int *)0 = 0; \
86 #define CONTINUE_ON_FAILURE \
88 if (!MustContinueOnFailure ()) \
98 #define CONTINUE_ON_FAILURE_RETURNS_BOOL \
100 if (!MustContinueOnFailure ()) \
102 return IsStatusFailure (); \
141 #define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
143 if (!((actual) == (limit))) \
146 std::ostringstream msgStream; \
148 std::ostringstream actualStream; \
149 actualStream << actual; \
150 std::ostringstream limitStream; \
151 limitStream << limit; \
152 ReportTestFailure (std::string (#actual) + " (actual) == " + \
153 std::string (#limit) + " (limit)", \
154 actualStream.str (), limitStream.str (), \
155 msgStream.str (), __FILE__, __LINE__); \
156 CONTINUE_ON_FAILURE; \
192 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
194 if (!((actual) == (limit))) \
197 std::ostringstream msgStream; \
199 std::ostringstream actualStream; \
200 actualStream << actual; \
201 std::ostringstream limitStream; \
202 limitStream << limit; \
203 ReportTestFailure (std::string (#actual) + " (actual) == " + \
204 std::string (#limit) + " (limit)", \
205 actualStream.str (), limitStream.str (), \
206 msgStream.str (), __FILE__, __LINE__); \
207 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
240 #define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
242 if (!((actual) == (limit))) \
245 std::ostringstream msgStream; \
247 std::ostringstream actualStream; \
248 actualStream << actual; \
249 std::ostringstream limitStream; \
250 limitStream << limit; \
251 ReportTestFailure (std::string (#actual) + " (actual) == " + \
252 std::string (#limit) + " (limit)", \
253 actualStream.str (), limitStream.str (), \
254 msgStream.str (), __FILE__, __LINE__); \
323 #define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
325 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
328 std::ostringstream msgStream; \
330 std::ostringstream actualStream; \
331 actualStream << actual; \
332 std::ostringstream limitStream; \
333 limitStream << limit << " +- " << tol; \
334 std::ostringstream condStream; \
335 condStream << #actual << " (actual) < " << #limit \
336 << " (limit) + " << #tol << " (tol) && " \
337 << #actual << " (actual) > " << #limit \
338 << " (limit) - " << #tol << " (tol)"; \
339 ReportTestFailure (condStream.str (), actualStream.str (), \
340 limitStream.str (), msgStream.str (), \
341 __FILE__, __LINE__); \
342 CONTINUE_ON_FAILURE; \
408 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
410 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
413 std::ostringstream msgStream; \
415 std::ostringstream actualStream; \
416 actualStream << actual; \
417 std::ostringstream limitStream; \
418 limitStream << limit << " +- " << tol; \
419 std::ostringstream condStream; \
420 condStream << #actual << " (actual) < " << #limit \
421 << " (limit) + " << #tol << " (tol) && " \
422 << #actual << " (actual) > " << #limit \
423 << " (limit) - " << #tol << " (tol)"; \
424 ReportTestFailure (condStream.str (), actualStream.str (), \
425 limitStream.str (), msgStream.str (), \
426 __FILE__, __LINE__); \
427 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
491 #define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
493 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
496 std::ostringstream msgStream; \
498 std::ostringstream actualStream; \
499 actualStream << actual; \
500 std::ostringstream limitStream; \
501 limitStream << limit << " +- " << tol; \
502 std::ostringstream condStream; \
503 condStream << #actual << " (actual) < " << #limit \
504 << " (limit) + " << #tol << " (tol) && " \
505 << #actual << " (actual) > " << #limit \
506 << " (limit) - " << #tol << " (tol)"; \
507 ReportTestFailure (condStream.str (), actualStream.str (), \
508 limitStream.str (), msgStream.str (), \
509 __FILE__, __LINE__); \
542 #define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
544 if (!((actual) != (limit))) \
547 std::ostringstream msgStream; \
549 std::ostringstream actualStream; \
550 actualStream << actual; \
551 std::ostringstream limitStream; \
552 limitStream << limit; \
553 ReportTestFailure (std::string (#actual) + " (actual) != " + \
554 std::string (#limit) + " (limit)", \
555 actualStream.str (), limitStream.str (), \
556 msgStream.str (), __FILE__, __LINE__); \
557 CONTINUE_ON_FAILURE; \
589 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
591 if (!((actual) != (limit))) \
594 std::ostringstream msgStream; \
596 std::ostringstream actualStream; \
597 actualStream << actual; \
598 std::ostringstream limitStream; \
599 limitStream << limit; \
600 ReportTestFailure (std::string (#actual) + " (actual) != " + \
601 std::string (#limit) + " (limit)", \
602 actualStream.str (), limitStream.str (), \
603 msgStream.str (), __FILE__, __LINE__); \
604 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
636 #define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
638 if (!((actual) != (limit))) \
641 std::ostringstream msgStream; \
643 std::ostringstream actualStream; \
644 actualStream << actual; \
645 std::ostringstream limitStream; \
646 limitStream << limit; \
647 ReportTestFailure (std::string (#actual) + " (actual) != " + \
648 std::string (#limit) + " (limit)", \
649 actualStream.str (), limitStream.str (), \
650 msgStream.str (), __FILE__, __LINE__); \
675 #define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
677 if (!((actual) < (limit))) \
680 std::ostringstream msgStream; \
682 std::ostringstream actualStream; \
683 actualStream << actual; \
684 std::ostringstream limitStream; \
685 limitStream << limit; \
686 ReportTestFailure (std::string (#actual) + " (actual) < " + \
687 std::string (#limit) + " (limit)", \
688 actualStream.str (), limitStream.str (), \
689 msgStream.str (), __FILE__, __LINE__); \
690 CONTINUE_ON_FAILURE; \
712 #define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
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; \
748 #define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
750 if (!((actual) < (limit))) \
753 std::ostringstream msgStream; \
755 std::ostringstream actualStream; \
756 actualStream << actual; \
757 std::ostringstream limitStream; \
758 limitStream << limit; \
759 ReportTestFailure (std::string (#actual) + " (actual) < " + \
760 std::string (#limit) + " (limit)", \
761 actualStream.str (), limitStream.str (), \
762 msgStream.str (), __FILE__, __LINE__); \
785 #define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
787 if (!((actual) <= (limit))) \
790 std::ostringstream msgStream; \
792 std::ostringstream actualStream; \
793 actualStream << actual; \
794 std::ostringstream limitStream; \
795 limitStream << limit; \
796 ReportTestFailure (std::string (#actual) + " (actual) < " + \
797 std::string (#limit) + " (limit)", \
798 actualStream.str (), limitStream.str (), \
799 msgStream.str (), __FILE__, __LINE__); \
825 #define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
827 if (!((actual) > (limit))) \
830 std::ostringstream msgStream; \
832 std::ostringstream actualStream; \
833 actualStream << actual; \
834 std::ostringstream limitStream; \
835 limitStream << limit; \
836 ReportTestFailure (std::string (#actual) + " (actual) > " + \
837 std::string (#limit) + " (limit)", \
838 actualStream.str (), limitStream.str (), \
839 msgStream.str (), __FILE__, __LINE__); \
840 CONTINUE_ON_FAILURE; \
862 #define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
864 if (!((actual) >= (limit))) \
867 std::ostringstream msgStream; \
869 std::ostringstream actualStream; \
870 actualStream << actual; \
871 std::ostringstream limitStream; \
872 limitStream << limit; \
873 ReportTestFailure (std::string (#actual) + " (actual) > " + \
874 std::string (#limit) + " (limit)", \
875 actualStream.str (), limitStream.str (), \
876 msgStream.str (), __FILE__, __LINE__); \
877 CONTINUE_ON_FAILURE; \
899 #define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
901 if (!((actual) > (limit))) \
904 std::ostringstream msgStream; \
906 std::ostringstream actualStream; \
907 actualStream << actual; \
908 std::ostringstream limitStream; \
909 limitStream << limit; \
910 ReportTestFailure (std::string (#actual) + " (actual) > " + \
911 std::string (#limit) + " (limit)", \
912 actualStream.str (), limitStream.str (), \
913 msgStream.str (), __FILE__, __LINE__); \
935 #define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
937 if (!((actual) >= (limit))) \
940 std::ostringstream msgStream; \
942 std::ostringstream actualStream; \
943 actualStream << actual; \
944 std::ostringstream limitStream; \
945 limitStream << limit; \
946 ReportTestFailure (std::string (#actual) + " (actual) > " + \
947 std::string (#limit) + " (limit)", \
948 actualStream.str (), limitStream.str (), \
949 msgStream.str (), __FILE__, __LINE__); \
980 class TestRunnerImpl;
1016 std::string
GetName (
void)
const;
1090 std::string limit, std::string message,
1091 std::string
file, int32_t line);
1220 virtual void DoRun (
void);
1241 static int Run (
int argc,
char *argv[]);
1249 template <
typename T>
1297 template <
typename T>
1302 template <
typename T>
1306 m_vectors.reserve (reserve);
1309 template <
typename T>
1313 template <
typename T>
1317 std::size_t index = m_vectors.size ();
1318 m_vectors.push_back (vector);
1322 template <
typename T>
1326 return m_vectors.size ();
1329 template <
typename T>
1334 return m_vectors[i];
std::string m_name
TestCase name.
bool IsStatusSuccess(void) const
Check if all tests passed.
TestDuration
How long the test takes to execute.
@ EXTENSIVE
Medium length test.
@ TAKES_FOREVER
Very long running test.
enum TestDuration m_duration
TestCase duration.
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.
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
TestCase * m_parent
Pointer to my parent TestCase.
std::vector< TestCase * > m_children
Vector of my children.
virtual ~TestCase()
Destructor.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
bool MustAssertOnFailure(void) const
Check if this run should assert on failure.
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 TestCsse.
virtual void DoRun(void)=0
Implementation to actually run this TestCase.
bool IsFailed(void) const
Check if any tests failed.
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
void Run(TestRunnerImpl *runner)
Actually run this TestCase.
TestCase(const TestCase &)=delete
TestCase & operator=(const TestCase &)=delete
bool MustContinueOnFailure(void) const
Check if this run should continue on failure.
bool IsStatusFailure(void) const
Check if any tests failed.
struct Result * m_result
Results data.
std::string GetName(void) 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.
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.
virtual void DoRun(void)
Implementation to actually run this TestCase.
TestSuite::Type GetTestType(void)
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(void) 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.