75 #define ASSERT_ON_FAILURE \
77 if (MustAssertOnFailure ()) \
79 *(volatile int *)0 = 0; \
87 #define CONTINUE_ON_FAILURE \
89 if (!MustContinueOnFailure ()) \
99 #define CONTINUE_ON_FAILURE_RETURNS_BOOL \
101 if (!MustContinueOnFailure ()) \
103 return IsStatusFailure (); \
118 #define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
120 if (!((actual) == (limit))) \
123 std::ostringstream msgStream; \
125 std::ostringstream actualStream; \
126 actualStream << actual; \
127 std::ostringstream limitStream; \
128 limitStream << limit; \
129 ReportTestFailure (std::string (#actual) + " (actual) == " + \
130 std::string (#limit) + " (limit)", \
131 actualStream.str (), limitStream.str (), \
132 msgStream.str (), file, line); \
133 CONTINUE_ON_FAILURE; \
166 #define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
167 NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
174 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
176 if (!((actual) == (limit))) \
179 std::ostringstream msgStream; \
181 std::ostringstream actualStream; \
182 actualStream << actual; \
183 std::ostringstream limitStream; \
184 limitStream << limit; \
185 ReportTestFailure (std::string (#actual) + " (actual) == " + \
186 std::string (#limit) + " (limit)", \
187 actualStream.str (), limitStream.str (), \
188 msgStream.str (), file, line); \
189 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
225 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
226 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
236 #define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
238 if (!((actual) == (limit))) \
241 std::ostringstream msgStream; \
243 std::ostringstream actualStream; \
244 actualStream << actual; \
245 std::ostringstream limitStream; \
246 limitStream << limit; \
247 ReportTestFailure (std::string (#actual) + " (actual) == " + \
248 std::string (#limit) + " (limit)", \
249 actualStream.str (), limitStream.str (), \
250 msgStream.str (), file, line); \
283 #define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
284 NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
296 #define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
298 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
301 std::ostringstream msgStream; \
303 std::ostringstream actualStream; \
304 actualStream << actual; \
305 std::ostringstream limitStream; \
306 limitStream << limit << " +- " << tol; \
307 std::ostringstream condStream; \
308 condStream << #actual << " (actual) < " << #limit \
309 << " (limit) + " << #tol << " (tol) && " \
310 << #actual << " (actual) > " << #limit \
311 << " (limit) - " << #tol << " (tol)"; \
312 ReportTestFailure (condStream.str (), actualStream.str (), \
313 limitStream.str (), msgStream.str (), \
315 CONTINUE_ON_FAILURE; \
378 #define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
379 NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
386 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line) \
388 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
391 std::ostringstream msgStream; \
393 std::ostringstream actualStream; \
394 actualStream << actual; \
395 std::ostringstream limitStream; \
396 limitStream << limit << " +- " << tol; \
397 std::ostringstream condStream; \
398 condStream << #actual << " (actual) < " << #limit \
399 << " (limit) + " << #tol << " (tol) && " \
400 << #actual << " (actual) > " << #limit \
401 << " (limit) - " << #tol << " (tol)"; \
402 ReportTestFailure (condStream.str (), actualStream.str (), \
403 limitStream.str (), msgStream.str (), \
405 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
471 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
472 NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
482 #define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
484 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
487 std::ostringstream msgStream; \
489 std::ostringstream actualStream; \
490 actualStream << actual; \
491 std::ostringstream limitStream; \
492 limitStream << limit << " +- " << tol; \
493 std::ostringstream condStream; \
494 condStream << #actual << " (actual) < " << #limit \
495 << " (limit) + " << #tol << " (tol) && " \
496 << #actual << " (actual) > " << #limit \
497 << " (limit) - " << #tol << " (tol)"; \
498 ReportTestFailure (condStream.str (), actualStream.str (), \
499 limitStream.str (), msgStream.str (), \
563 #define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
564 NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
575 #define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
577 if (!((actual) != (limit))) \
580 std::ostringstream msgStream; \
582 std::ostringstream actualStream; \
583 actualStream << actual; \
584 std::ostringstream limitStream; \
585 limitStream << limit; \
586 ReportTestFailure (std::string (#actual) + " (actual) != " + \
587 std::string (#limit) + " (limit)", \
588 actualStream.str (), limitStream.str (), \
589 msgStream.str (), file, line); \
590 CONTINUE_ON_FAILURE; \
622 #define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
623 NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
630 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
632 if (!((actual) != (limit))) \
635 std::ostringstream msgStream; \
637 std::ostringstream actualStream; \
638 actualStream << actual; \
639 std::ostringstream limitStream; \
640 limitStream << limit; \
641 ReportTestFailure (std::string (#actual) + " (actual) != " + \
642 std::string (#limit) + " (limit)", \
643 actualStream.str (), limitStream.str (), \
644 msgStream.str (), file, line); \
645 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
680 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
681 NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
691 #define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
693 if (!((actual) != (limit))) \
696 std::ostringstream msgStream; \
698 std::ostringstream actualStream; \
699 actualStream << actual; \
700 std::ostringstream limitStream; \
701 limitStream << limit; \
702 ReportTestFailure (std::string (#actual) + " (actual) != " + \
703 std::string (#limit) + " (limit)", \
704 actualStream.str (), limitStream.str (), \
705 msgStream.str (), file, line); \
737 #define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
738 NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
749 #define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
751 if (!((actual) < (limit))) \
754 std::ostringstream msgStream; \
756 std::ostringstream actualStream; \
757 actualStream << actual; \
758 std::ostringstream limitStream; \
759 limitStream << limit; \
760 ReportTestFailure (std::string (#actual) + " (actual) < " + \
761 std::string (#limit) + " (limit)", \
762 actualStream.str (), limitStream.str (), \
763 msgStream.str (), file, line); \
764 CONTINUE_ON_FAILURE; \
773 #define NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
775 if (!((actual) <= (limit))) \
778 std::ostringstream msgStream; \
780 std::ostringstream actualStream; \
781 actualStream << actual; \
782 std::ostringstream limitStream; \
783 limitStream << limit; \
784 ReportTestFailure (std::string (#actual) + " (actual) < " + \
785 std::string (#limit) + " (limit)", \
786 actualStream.str (), limitStream.str (), \
787 msgStream.str (), file, line); \
788 CONTINUE_ON_FAILURE; \
809 #define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
810 NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
830 #define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
831 NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
840 #define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
842 if (!((actual) < (limit))) \
845 std::ostringstream msgStream; \
847 std::ostringstream actualStream; \
848 actualStream << actual; \
849 std::ostringstream limitStream; \
850 limitStream << limit; \
851 ReportTestFailure (std::string (#actual) + " (actual) < " + \
852 std::string (#limit) + " (limit)", \
853 actualStream.str (), limitStream.str (), \
854 msgStream.str (), file, line); \
866 #define NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
868 if (!((actual) <= (limit))) \
871 std::ostringstream msgStream; \
873 std::ostringstream actualStream; \
874 actualStream << actual; \
875 std::ostringstream limitStream; \
876 limitStream << limit; \
877 ReportTestFailure (std::string (#actual) + " (actual) < " + \
878 std::string (#limit) + " (limit)", \
879 actualStream.str (), limitStream.str (), \
880 msgStream.str (), file, line); \
901 #define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
902 NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
922 #define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
923 NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
934 #define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
936 if (!((actual) > (limit))) \
939 std::ostringstream msgStream; \
941 std::ostringstream actualStream; \
942 actualStream << actual; \
943 std::ostringstream limitStream; \
944 limitStream << limit; \
945 ReportTestFailure (std::string (#actual) + " (actual) > " + \
946 std::string (#limit) + " (limit)", \
947 actualStream.str (), limitStream.str (), \
948 msgStream.str (), file, line); \
949 CONTINUE_ON_FAILURE; \
958 #define NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
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) > " + \
970 std::string (#limit) + " (limit)", \
971 actualStream.str (), limitStream.str (), \
972 msgStream.str (), file, line); \
973 CONTINUE_ON_FAILURE; \
995 #define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
996 NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1016 #define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
1017 NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1026 #define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
1028 if (!((actual) > (limit))) \
1030 ASSERT_ON_FAILURE; \
1031 std::ostringstream msgStream; \
1033 std::ostringstream actualStream; \
1034 actualStream << actual; \
1035 std::ostringstream limitStream; \
1036 limitStream << limit; \
1037 ReportTestFailure (std::string (#actual) + " (actual) > " + \
1038 std::string (#limit) + " (limit)", \
1039 actualStream.str (), limitStream.str (), \
1040 msgStream.str (), file, line); \
1052 #define NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
1054 if (!((actual) >= (limit))) \
1056 ASSERT_ON_FAILURE; \
1057 std::ostringstream msgStream; \
1059 std::ostringstream actualStream; \
1060 actualStream << actual; \
1061 std::ostringstream limitStream; \
1062 limitStream << limit; \
1063 ReportTestFailure (std::string (#actual) + " (actual) > " + \
1064 std::string (#limit) + " (limit)", \
1065 actualStream.str (), limitStream.str (), \
1066 msgStream.str (), file, line); \
1088 #define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
1089 NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1109 #define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
1110 NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1140 class TestRunnerImpl;
1172 std::string
GetName (
void)
const;
1246 std::string limit, std::string message,
1247 std::string
file, int32_t line);
1376 virtual void DoRun (
void);
1397 static int Run (
int argc,
char *argv[]);
1405 template <
typename T>
1449 template <
typename T>
1454 template <
typename T>
1458 m_vectors.reserve (reserve);
1461 template <
typename T>
1465 template <
typename T>
1469 std::size_t index = m_vectors.size ();
1470 m_vectors.push_back (vector);
1474 template <
typename T>
1478 return m_vectors.size ();
1481 template <
typename T>
1486 return m_vectors[i];
A base class for (non-Singleton) objects which shouldn't be copied.
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.
TestCase(std::string name)
Constructor.
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.
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.
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()
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.
ns3::NonCopyable declaration.
Container for results from a TestCase.
ns3::SystemWallClockMs declaration.