70 #define ASSERT_ON_FAILURE \
72 if (MustAssertOnFailure ()) \
74 *(volatile int *)0 = 0; \
82 #define CONTINUE_ON_FAILURE \
84 if (!MustContinueOnFailure ()) \
94 #define CONTINUE_ON_FAILURE_RETURNS_BOOL \
96 if (!MustContinueOnFailure ()) \
98 return IsStatusFailure (); \
113 #define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
115 if (!((actual) == (limit))) \
118 std::ostringstream msgStream; \
120 std::ostringstream actualStream; \
121 actualStream << actual; \
122 std::ostringstream limitStream; \
123 limitStream << limit; \
124 ReportTestFailure (std::string (#actual) + " (actual) == " + \
125 std::string (#limit) + " (limit)", \
126 actualStream.str (), limitStream.str (), \
127 msgStream.str (), file, line); \
128 CONTINUE_ON_FAILURE; \
161 #define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
162 NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
169 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
171 if (!((actual) == (limit))) \
174 std::ostringstream msgStream; \
176 std::ostringstream actualStream; \
177 actualStream << actual; \
178 std::ostringstream limitStream; \
179 limitStream << limit; \
180 ReportTestFailure (std::string (#actual) + " (actual) == " + \
181 std::string (#limit) + " (limit)", \
182 actualStream.str (), limitStream.str (), \
183 msgStream.str (), file, line); \
184 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
220 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
221 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
231 #define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
233 if (!((actual) == (limit))) \
236 std::ostringstream msgStream; \
238 std::ostringstream actualStream; \
239 actualStream << actual; \
240 std::ostringstream limitStream; \
241 limitStream << limit; \
242 ReportTestFailure (std::string (#actual) + " (actual) == " + \
243 std::string (#limit) + " (limit)", \
244 actualStream.str (), limitStream.str (), \
245 msgStream.str (), file, line); \
278 #define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
279 NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
291 #define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
293 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
296 std::ostringstream msgStream; \
298 std::ostringstream actualStream; \
299 actualStream << actual; \
300 std::ostringstream limitStream; \
301 limitStream << limit << " +- " << tol; \
302 std::ostringstream condStream; \
303 condStream << #actual << " (actual) < " << #limit \
304 << " (limit) + " << #tol << " (tol) && " \
305 << #actual << " (actual) > " << #limit \
306 << " (limit) - " << #tol << " (tol)"; \
307 ReportTestFailure (condStream.str (), actualStream.str (), \
308 limitStream.str (), msgStream.str (), \
310 CONTINUE_ON_FAILURE; \
373 #define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
374 NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
381 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line) \
383 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
386 std::ostringstream msgStream; \
388 std::ostringstream actualStream; \
389 actualStream << actual; \
390 std::ostringstream limitStream; \
391 limitStream << limit << " +- " << tol; \
392 std::ostringstream condStream; \
393 condStream << #actual << " (actual) < " << #limit \
394 << " (limit) + " << #tol << " (tol) && " \
395 << #actual << " (actual) > " << #limit \
396 << " (limit) - " << #tol << " (tol)"; \
397 ReportTestFailure (condStream.str (), actualStream.str (), \
398 limitStream.str (), msgStream.str (), \
400 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
466 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
467 NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
477 #define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
479 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
482 std::ostringstream msgStream; \
484 std::ostringstream actualStream; \
485 actualStream << actual; \
486 std::ostringstream limitStream; \
487 limitStream << limit << " +- " << tol; \
488 std::ostringstream condStream; \
489 condStream << #actual << " (actual) < " << #limit \
490 << " (limit) + " << #tol << " (tol) && " \
491 << #actual << " (actual) > " << #limit \
492 << " (limit) - " << #tol << " (tol)"; \
493 ReportTestFailure (condStream.str (), actualStream.str (), \
494 limitStream.str (), msgStream.str (), \
558 #define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
559 NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
570 #define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
572 if (!((actual) != (limit))) \
575 std::ostringstream msgStream; \
577 std::ostringstream actualStream; \
578 actualStream << actual; \
579 std::ostringstream limitStream; \
580 limitStream << limit; \
581 ReportTestFailure (std::string (#actual) + " (actual) != " + \
582 std::string (#limit) + " (limit)", \
583 actualStream.str (), limitStream.str (), \
584 msgStream.str (), file, line); \
585 CONTINUE_ON_FAILURE; \
617 #define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
618 NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
625 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
627 if (!((actual) != (limit))) \
630 std::ostringstream msgStream; \
632 std::ostringstream actualStream; \
633 actualStream << actual; \
634 std::ostringstream limitStream; \
635 limitStream << limit; \
636 ReportTestFailure (std::string (#actual) + " (actual) != " + \
637 std::string (#limit) + " (limit)", \
638 actualStream.str (), limitStream.str (), \
639 msgStream.str (), file, line); \
640 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
675 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
676 NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
686 #define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
688 if (!((actual) != (limit))) \
691 std::ostringstream msgStream; \
693 std::ostringstream actualStream; \
694 actualStream << actual; \
695 std::ostringstream limitStream; \
696 limitStream << limit; \
697 ReportTestFailure (std::string (#actual) + " (actual) != " + \
698 std::string (#limit) + " (limit)", \
699 actualStream.str (), limitStream.str (), \
700 msgStream.str (), file, line); \
732 #define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
733 NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
744 #define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
746 if (!((actual) < (limit))) \
749 std::ostringstream msgStream; \
751 std::ostringstream actualStream; \
752 actualStream << actual; \
753 std::ostringstream limitStream; \
754 limitStream << limit; \
755 ReportTestFailure (std::string (#actual) + " (actual) < " + \
756 std::string (#limit) + " (limit)", \
757 actualStream.str (), limitStream.str (), \
758 msgStream.str (), file, line); \
759 CONTINUE_ON_FAILURE; \
768 #define NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
770 if (!((actual) <= (limit))) \
773 std::ostringstream msgStream; \
775 std::ostringstream actualStream; \
776 actualStream << actual; \
777 std::ostringstream limitStream; \
778 limitStream << limit; \
779 ReportTestFailure (std::string (#actual) + " (actual) < " + \
780 std::string (#limit) + " (limit)", \
781 actualStream.str (), limitStream.str (), \
782 msgStream.str (), file, line); \
783 CONTINUE_ON_FAILURE; \
804 #define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
805 NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
825 #define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
826 NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
835 #define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
837 if (!((actual) < (limit))) \
840 std::ostringstream msgStream; \
842 std::ostringstream actualStream; \
843 actualStream << actual; \
844 std::ostringstream limitStream; \
845 limitStream << limit; \
846 ReportTestFailure (std::string (#actual) + " (actual) < " + \
847 std::string (#limit) + " (limit)", \
848 actualStream.str (), limitStream.str (), \
849 msgStream.str (), file, line); \
861 #define NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
863 if (!((actual) <= (limit))) \
866 std::ostringstream msgStream; \
868 std::ostringstream actualStream; \
869 actualStream << actual; \
870 std::ostringstream limitStream; \
871 limitStream << limit; \
872 ReportTestFailure (std::string (#actual) + " (actual) < " + \
873 std::string (#limit) + " (limit)", \
874 actualStream.str (), limitStream.str (), \
875 msgStream.str (), file, line); \
896 #define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
897 NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
917 #define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
918 NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
929 #define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
931 if (!((actual) > (limit))) \
934 std::ostringstream msgStream; \
936 std::ostringstream actualStream; \
937 actualStream << actual; \
938 std::ostringstream limitStream; \
939 limitStream << limit; \
940 ReportTestFailure (std::string (#actual) + " (actual) > " + \
941 std::string (#limit) + " (limit)", \
942 actualStream.str (), limitStream.str (), \
943 msgStream.str (), file, line); \
944 CONTINUE_ON_FAILURE; \
953 #define NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
955 if (!((actual) >= (limit))) \
958 std::ostringstream msgStream; \
960 std::ostringstream actualStream; \
961 actualStream << actual; \
962 std::ostringstream limitStream; \
963 limitStream << limit; \
964 ReportTestFailure (std::string (#actual) + " (actual) > " + \
965 std::string (#limit) + " (limit)", \
966 actualStream.str (), limitStream.str (), \
967 msgStream.str (), file, line); \
968 CONTINUE_ON_FAILURE; \
990 #define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
991 NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1011 #define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
1012 NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1021 #define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
1023 if (!((actual) > (limit))) \
1025 ASSERT_ON_FAILURE; \
1026 std::ostringstream msgStream; \
1028 std::ostringstream actualStream; \
1029 actualStream << actual; \
1030 std::ostringstream limitStream; \
1031 limitStream << limit; \
1032 ReportTestFailure (std::string (#actual) + " (actual) > " + \
1033 std::string (#limit) + " (limit)", \
1034 actualStream.str (), limitStream.str (), \
1035 msgStream.str (), file, line); \
1047 #define NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
1049 if (!((actual) >= (limit))) \
1051 ASSERT_ON_FAILURE; \
1052 std::ostringstream msgStream; \
1054 std::ostringstream actualStream; \
1055 actualStream << actual; \
1056 std::ostringstream limitStream; \
1057 limitStream << limit; \
1058 ReportTestFailure (std::string (#actual) + " (actual) > " + \
1059 std::string (#limit) + " (limit)", \
1060 actualStream.str (), limitStream.str (), \
1061 msgStream.str (), file, line); \
1083 #define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
1084 NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1104 #define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
1105 NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1136 class TestRunnerImpl;
1165 std::string
GetName (
void)
const;
1238 std::string limit, std::string message,
1239 std::string file, int32_t line);
1290 virtual void DoRun (
void) = 0;
1366 virtual void DoRun (
void);
1387 static int Run (
int argc,
char *argv[]);
1395 template <
typename T>
1413 void Reserve (uint32_t reserve);
1420 uint32_t
Add (T vector);
1426 uint32_t
GetN (
void)
const;
1432 T
Get (uint32_t i)
const;
1439 template <
typename T>
1445 template <
typename T>
1449 m_vectors.reserve (reserve);
1452 template <
typename T>
1457 template <
typename T>
1461 uint32_t index = m_vectors.size ();
1462 m_vectors.push_back (vector);
1466 template <
typename T>
1470 return m_vectors.size ();
1473 template <
typename T>
1478 return m_vectors[i];
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
This test suite implements a System Test.
T Get(uint32_t i) const
Get the i'th test vector.
A base class for (non-Singleton) objects which shouldn't be copied.
virtual ~TestVectors()
Virtual desctructor.
A runner to execute tests.
void Reserve(uint32_t reserve)
Set the expected length of this vector.
Container for results from a TestCase.
bool IsFailed(void) const
Check if any tests failed.
std::vector< T > TestVector
Container type.
enum TestDuration m_duration
TestCase duration.
ns3::NonCopyable class declaration and implementation.
uint32_t GetN(void) const
Get the total number of test vectors.
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
A simple way to store test vectors (for stimulus or from responses)
virtual void DoRun(void)
Implementation to actually run this TestCase.
TestVectors()
Constructor.
TestCase * m_parent
Pointer to my parent TestCase.
TestRunnerImpl * m_runner
Pointer to the TestRunner.
System-independent wall clock class ns3::SystemWallClockMs declaration.
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
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...
TestSuite::Type m_type
Type of this TestSuite.
bool MustAssertOnFailure(void) const
Check if this run should assert on failure.
This test suite implements a Performance Test.
TestCase(std::string name)
Constructor.
This test suite implements a Build Verification Test.
TestDuration
How long the test takes to execute.
virtual ~TestCase()
Destructor.
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
virtual void DoRun(void)=0
Implementation to actually run this TestCase.
struct Result * m_result
Results data.
bool IsStatusFailure(void) const
Check if any tests failed.
TestCase * GetParent() const
Get the parent of this TestCsse.
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.
void Run(TestRunnerImpl *runner)
Actually run this TestCase.
bool IsStatusSuccess(void) const
Check if all tests passed.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
TestVector m_vectors
The list of test vectors.
std::vector< TestCase * > m_children
Vector of my children.
This test suite implements an Example Test.
std::string GetName(void) const
This test suite implements a Unit Test.
TestSuite::Type GetTestType(void)
get the kind of test this test suite implements
static int Run(int argc, char *argv[])
Run the requested suite of tests, according to the given command line arguments.
std::string m_name
TestCase name.
std::string m_dataDir
My data directory.
bool MustContinueOnFailure(void) const
Check if this run should continue on failure.