49 #define ASSERT_ON_FAILURE \
51 if (MustAssertOnFailure ()) \
53 *(volatile int *)0 = 0; \
62 #define CONTINUE_ON_FAILURE \
64 if (!MustContinueOnFailure ()) \
75 #define CONTINUE_ON_FAILURE_RETURNS_BOOL \
77 if (!MustContinueOnFailure ()) \
79 return IsStatusFailure (); \
92 #define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
94 if (!((actual) == (limit))) \
97 std::ostringstream msgStream; \
99 std::ostringstream actualStream; \
100 actualStream << actual; \
101 std::ostringstream limitStream; \
102 limitStream << limit; \
103 ReportTestFailure (std::string (#actual) + " (actual) == " + \
104 std::string (#limit) + " (limit)", \
105 actualStream.str (), limitStream.str (), \
106 msgStream.str (), file, line); \
107 CONTINUE_ON_FAILURE; \
137 #define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
138 NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
143 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
145 if (!((actual) == (limit))) \
148 std::ostringstream msgStream; \
150 std::ostringstream actualStream; \
151 actualStream << actual; \
152 std::ostringstream limitStream; \
153 limitStream << limit; \
154 ReportTestFailure (std::string (#actual) + " (actual) == " + \
155 std::string (#limit) + " (limit)", \
156 actualStream.str (), limitStream.str (), \
157 msgStream.str (), file, line); \
158 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
191 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
192 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
200 #define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
202 if (!((actual) == (limit))) \
205 std::ostringstream msgStream; \
207 std::ostringstream actualStream; \
208 actualStream << actual; \
209 std::ostringstream limitStream; \
210 limitStream << limit; \
211 ReportTestFailure (std::string (#actual) + " (actual) == " + \
212 std::string (#limit) + " (limit)", \
213 actualStream.str (), limitStream.str (), \
214 msgStream.str (), file, line); \
244 #define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
245 NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
255 #define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
257 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
260 std::ostringstream msgStream; \
262 std::ostringstream actualStream; \
263 actualStream << actual; \
264 std::ostringstream limitStream; \
265 limitStream << limit << " +- " << tol; \
266 std::ostringstream condStream; \
267 condStream << #actual << " (actual) < " << #limit \
268 << " (limit) + " << #tol << " (tol) && " \
269 << #actual << " (actual) > " << #limit \
270 << " (limit) - " << #tol << " (tol)"; \
271 ReportTestFailure (condStream.str (), actualStream.str (), \
272 limitStream.str (), msgStream.str (), \
274 CONTINUE_ON_FAILURE; \
326 #define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
327 NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
332 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line) \
334 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
337 std::ostringstream msgStream; \
339 std::ostringstream actualStream; \
340 actualStream << actual; \
341 std::ostringstream limitStream; \
342 limitStream << limit << " +- " << tol; \
343 std::ostringstream condStream; \
344 condStream << #actual << " (actual) < " << #limit \
345 << " (limit) + " << #tol << " (tol) && " \
346 << #actual << " (actual) > " << #limit \
347 << " (limit) - " << #tol << " (tol)"; \
348 ReportTestFailure (condStream.str (), actualStream.str (), \
349 limitStream.str (), msgStream.str (), \
351 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
406 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
407 NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
415 #define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
417 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
420 std::ostringstream msgStream; \
422 std::ostringstream actualStream; \
423 actualStream << actual; \
424 std::ostringstream limitStream; \
425 limitStream << limit << " +- " << tol; \
426 std::ostringstream condStream; \
427 condStream << #actual << " (actual) < " << #limit \
428 << " (limit) + " << #tol << " (tol) && " \
429 << #actual << " (actual) > " << #limit \
430 << " (limit) - " << #tol << " (tol)"; \
431 ReportTestFailure (condStream.str (), actualStream.str (), \
432 limitStream.str (), msgStream.str (), \
485 #define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
486 NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
495 #define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
497 if (!((actual) != (limit))) \
500 std::ostringstream msgStream; \
502 std::ostringstream actualStream; \
503 actualStream << actual; \
504 std::ostringstream limitStream; \
505 limitStream << limit; \
506 ReportTestFailure (std::string (#actual) + " (actual) != " + \
507 std::string (#limit) + " (limit)", \
508 actualStream.str (), limitStream.str (), \
509 msgStream.str (), file, line); \
510 CONTINUE_ON_FAILURE; \
539 #define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
540 NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
545 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
547 if (!((actual) != (limit))) \
550 std::ostringstream msgStream; \
552 std::ostringstream actualStream; \
553 actualStream << actual; \
554 std::ostringstream limitStream; \
555 limitStream << limit; \
556 ReportTestFailure (std::string (#actual) + " (actual) != " + \
557 std::string (#limit) + " (limit)", \
558 actualStream.str (), limitStream.str (), \
559 msgStream.str (), file, line); \
560 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
592 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
593 NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
601 #define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
603 if (!((actual) != (limit))) \
606 std::ostringstream msgStream; \
608 std::ostringstream actualStream; \
609 actualStream << actual; \
610 std::ostringstream limitStream; \
611 limitStream << limit; \
612 ReportTestFailure (std::string (#actual) + " (actual) != " + \
613 std::string (#limit) + " (limit)", \
614 actualStream.str (), limitStream.str (), \
615 msgStream.str (), file, line); \
644 #define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
645 NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
654 #define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
656 if (!((actual) < (limit))) \
659 std::ostringstream msgStream; \
661 std::ostringstream actualStream; \
662 actualStream << actual; \
663 std::ostringstream limitStream; \
664 limitStream << limit; \
665 ReportTestFailure (std::string (#actual) + " (actual) < " + \
666 std::string (#limit) + " (limit)", \
667 actualStream.str (), limitStream.str (), \
668 msgStream.str (), file, line); \
669 CONTINUE_ON_FAILURE; \
688 #define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
689 NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
697 #define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
699 if (!((actual) < (limit))) \
702 std::ostringstream msgStream; \
704 std::ostringstream actualStream; \
705 actualStream << actual; \
706 std::ostringstream limitStream; \
707 limitStream << limit; \
708 ReportTestFailure (std::string (#actual) + " (actual) < " + \
709 std::string (#limit) + " (limit)", \
710 actualStream.str (), limitStream.str (), \
711 msgStream.str (), file, line); \
729 #define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
730 NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
739 #define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
741 if (!((actual) > (limit))) \
744 std::ostringstream msgStream; \
746 std::ostringstream actualStream; \
747 actualStream << actual; \
748 std::ostringstream limitStream; \
749 limitStream << limit; \
750 ReportTestFailure (std::string (#actual) + " (actual) > " + \
751 std::string (#limit) + " (limit)", \
752 actualStream.str (), limitStream.str (), \
753 msgStream.str (), file, line); \
754 CONTINUE_ON_FAILURE; \
773 #define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
774 NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
782 #define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
784 if (!((actual) > (limit))) \
787 std::ostringstream msgStream; \
789 std::ostringstream actualStream; \
790 actualStream << actual; \
791 std::ostringstream limitStream; \
792 limitStream << limit; \
793 ReportTestFailure (std::string (#actual) + " (actual) > " + \
794 std::string (#limit) + " (limit)", \
795 actualStream.str (), limitStream.str (), \
796 msgStream.str (), file, line); \
814 #define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
815 NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
838 const double epsilon = std::numeric_limits<double>::epsilon ());
840 class TestRunnerImpl;
922 std::
string GetName (
void) const;
933 std::
string limit, std::
string message,
934 std::
string file, int32_t line);
977 virtual
void DoRun (
void) = 0;
1003 void Run (TestRunnerImpl *runner);
1047 TestSuite (std::string name, Type type = UNIT);
1057 virtual void DoRun (
void);
1076 static int Run (
int argc,
char *argv[]);
1082 template <
typename T>
1098 void Reserve (uint32_t reserve);
1104 uint32_t Add (T vector);
1109 uint32_t GetN (
void)
const;
1115 T Get (uint32_t i)
const;
1135 template <
typename T>
1141 template <
typename T>
1145 m_vectors.reserve (reserve);
1148 template <
typename T>
1153 template <
typename T>
1157 uint32_t index = m_vectors.size ();
1158 m_vectors.push_back (vector);
1162 template <
typename T>
1166 return m_vectors.size ();
1169 template <
typename T>
1174 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.
virtual ~TestVectors()
Virtual desctructor.
A runner to execute tests.
void Reserve(uint32_t reserve)
bool IsFailed(void) const
std::vector< T > TestVector
Container type.
enum TestDuration m_duration
TestCase duration.
uint32_t GetN(void) const
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
A simple way to store test vectors (for stimulus or from responses)
TestVectors()
Constructor.
TestCase * m_parent
Pointer to my parent TestCase.
TestRunnerImpl * m_runner
Pointer to the TestRunner.
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
TestCase(std::string name)
bool GetErrorStatus(void) const NS_DEPRECATED
TestDuration
How long the test takes to execute.
virtual ~TestCase()
Destructor.
std::string CreateDataDirFilename(std::string filename)
virtual void DoRun(void)=0
Implementation to actually run this TestCase.
struct Result * m_result
Results data.
bool IsStatusFailure(void) const
void ReportTestFailure(std::string cond, std::string actual, std::string limit, std::string message, std::string file, int32_t line)
void Run(TestRunnerImpl *runner)
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
bool IsStatusSuccess(void) const
std::string CreateTempDirFilename(std::string filename)
bool operator==(const EventId &a, const EventId &b)
void SetDataDir(std::string directory)
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.
std::string m_name
TestCase name.
TestCase & operator=(TestCase &tc)
std::string m_dataDir
My data directory.
bool MustContinueOnFailure(void) const