55 #define ASSERT_ON_FAILURE \
57 if (MustAssertOnFailure ()) \
59 *(volatile int *)0 = 0; \
68 #define CONTINUE_ON_FAILURE \
70 if (!MustContinueOnFailure ()) \
81 #define CONTINUE_ON_FAILURE_RETURNS_BOOL \
83 if (!MustContinueOnFailure ()) \
85 return IsStatusFailure (); \
101 #define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
103 if (!((actual) == (limit))) \
106 std::ostringstream msgStream; \
108 std::ostringstream actualStream; \
109 actualStream << actual; \
110 std::ostringstream limitStream; \
111 limitStream << limit; \
112 ReportTestFailure (std::string (#actual) + " (actual) == " + \
113 std::string (#limit) + " (limit)", \
114 actualStream.str (), limitStream.str (), \
115 msgStream.str (), file, line); \
116 CONTINUE_ON_FAILURE; \
148 #define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
149 NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
157 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
159 if (!((actual) == (limit))) \
162 std::ostringstream msgStream; \
164 std::ostringstream actualStream; \
165 actualStream << actual; \
166 std::ostringstream limitStream; \
167 limitStream << limit; \
168 ReportTestFailure (std::string (#actual) + " (actual) == " + \
169 std::string (#limit) + " (limit)", \
170 actualStream.str (), limitStream.str (), \
171 msgStream.str (), file, line); \
172 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
207 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
208 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
219 #define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
221 if (!((actual) == (limit))) \
224 std::ostringstream msgStream; \
226 std::ostringstream actualStream; \
227 actualStream << actual; \
228 std::ostringstream limitStream; \
229 limitStream << limit; \
230 ReportTestFailure (std::string (#actual) + " (actual) == " + \
231 std::string (#limit) + " (limit)", \
232 actualStream.str (), limitStream.str (), \
233 msgStream.str (), file, line); \
265 #define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
266 NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
279 #define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
281 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
284 std::ostringstream msgStream; \
286 std::ostringstream actualStream; \
287 actualStream << actual; \
288 std::ostringstream limitStream; \
289 limitStream << limit << " +- " << tol; \
290 std::ostringstream condStream; \
291 condStream << #actual << " (actual) < " << #limit \
292 << " (limit) + " << #tol << " (tol) && " \
293 << #actual << " (actual) > " << #limit \
294 << " (limit) - " << #tol << " (tol)"; \
295 ReportTestFailure (condStream.str (), actualStream.str (), \
296 limitStream.str (), msgStream.str (), \
298 CONTINUE_ON_FAILURE; \
355 #define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
356 NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
364 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line) \
366 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
369 std::ostringstream msgStream; \
371 std::ostringstream actualStream; \
372 actualStream << actual; \
373 std::ostringstream limitStream; \
374 limitStream << limit << " +- " << tol; \
375 std::ostringstream condStream; \
376 condStream << #actual << " (actual) < " << #limit \
377 << " (limit) + " << #tol << " (tol) && " \
378 << #actual << " (actual) > " << #limit \
379 << " (limit) - " << #tol << " (tol)"; \
380 ReportTestFailure (condStream.str (), actualStream.str (), \
381 limitStream.str (), msgStream.str (), \
383 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
443 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
444 NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
455 #define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
457 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
460 std::ostringstream msgStream; \
462 std::ostringstream actualStream; \
463 actualStream << actual; \
464 std::ostringstream limitStream; \
465 limitStream << limit << " +- " << tol; \
466 std::ostringstream condStream; \
467 condStream << #actual << " (actual) < " << #limit \
468 << " (limit) + " << #tol << " (tol) && " \
469 << #actual << " (actual) > " << #limit \
470 << " (limit) - " << #tol << " (tol)"; \
471 ReportTestFailure (condStream.str (), actualStream.str (), \
472 limitStream.str (), msgStream.str (), \
530 #define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
531 NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
543 #define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
545 if (!((actual) != (limit))) \
548 std::ostringstream msgStream; \
550 std::ostringstream actualStream; \
551 actualStream << actual; \
552 std::ostringstream limitStream; \
553 limitStream << limit; \
554 ReportTestFailure (std::string (#actual) + " (actual) != " + \
555 std::string (#limit) + " (limit)", \
556 actualStream.str (), limitStream.str (), \
557 msgStream.str (), file, line); \
558 CONTINUE_ON_FAILURE; \
589 #define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
590 NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
598 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
600 if (!((actual) != (limit))) \
603 std::ostringstream msgStream; \
605 std::ostringstream actualStream; \
606 actualStream << actual; \
607 std::ostringstream limitStream; \
608 limitStream << limit; \
609 ReportTestFailure (std::string (#actual) + " (actual) != " + \
610 std::string (#limit) + " (limit)", \
611 actualStream.str (), limitStream.str (), \
612 msgStream.str (), file, line); \
613 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
647 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
648 NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
659 #define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
661 if (!((actual) != (limit))) \
664 std::ostringstream msgStream; \
666 std::ostringstream actualStream; \
667 actualStream << actual; \
668 std::ostringstream limitStream; \
669 limitStream << limit; \
670 ReportTestFailure (std::string (#actual) + " (actual) != " + \
671 std::string (#limit) + " (limit)", \
672 actualStream.str (), limitStream.str (), \
673 msgStream.str (), file, line); \
704 #define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
705 NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
717 #define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
719 if (!((actual) < (limit))) \
722 std::ostringstream msgStream; \
724 std::ostringstream actualStream; \
725 actualStream << actual; \
726 std::ostringstream limitStream; \
727 limitStream << limit; \
728 ReportTestFailure (std::string (#actual) + " (actual) < " + \
729 std::string (#limit) + " (limit)", \
730 actualStream.str (), limitStream.str (), \
731 msgStream.str (), file, line); \
732 CONTINUE_ON_FAILURE; \
742 #define NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
744 if (!((actual) <= (limit))) \
747 std::ostringstream msgStream; \
749 std::ostringstream actualStream; \
750 actualStream << actual; \
751 std::ostringstream limitStream; \
752 limitStream << limit; \
753 ReportTestFailure (std::string (#actual) + " (actual) < " + \
754 std::string (#limit) + " (limit)", \
755 actualStream.str (), limitStream.str (), \
756 msgStream.str (), file, line); \
757 CONTINUE_ON_FAILURE; \
778 #define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
779 NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
798 #define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
799 NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
809 #define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
811 if (!((actual) < (limit))) \
814 std::ostringstream msgStream; \
816 std::ostringstream actualStream; \
817 actualStream << actual; \
818 std::ostringstream limitStream; \
819 limitStream << limit; \
820 ReportTestFailure (std::string (#actual) + " (actual) < " + \
821 std::string (#limit) + " (limit)", \
822 actualStream.str (), limitStream.str (), \
823 msgStream.str (), file, line); \
836 #define NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
838 if (!((actual) <= (limit))) \
841 std::ostringstream msgStream; \
843 std::ostringstream actualStream; \
844 actualStream << actual; \
845 std::ostringstream limitStream; \
846 limitStream << limit; \
847 ReportTestFailure (std::string (#actual) + " (actual) < " + \
848 std::string (#limit) + " (limit)", \
849 actualStream.str (), limitStream.str (), \
850 msgStream.str (), file, line); \
870 #define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
871 NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
890 #define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
891 NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
903 #define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
905 if (!((actual) > (limit))) \
908 std::ostringstream msgStream; \
910 std::ostringstream actualStream; \
911 actualStream << actual; \
912 std::ostringstream limitStream; \
913 limitStream << limit; \
914 ReportTestFailure (std::string (#actual) + " (actual) > " + \
915 std::string (#limit) + " (limit)", \
916 actualStream.str (), limitStream.str (), \
917 msgStream.str (), file, line); \
918 CONTINUE_ON_FAILURE; \
928 #define NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
930 if (!((actual) >= (limit))) \
933 std::ostringstream msgStream; \
935 std::ostringstream actualStream; \
936 actualStream << actual; \
937 std::ostringstream limitStream; \
938 limitStream << limit; \
939 ReportTestFailure (std::string (#actual) + " (actual) > " + \
940 std::string (#limit) + " (limit)", \
941 actualStream.str (), limitStream.str (), \
942 msgStream.str (), file, line); \
943 CONTINUE_ON_FAILURE; \
964 #define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
965 NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
984 #define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
985 NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
995 #define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
997 if (!((actual) > (limit))) \
1000 std::ostringstream msgStream; \
1002 std::ostringstream actualStream; \
1003 actualStream << actual; \
1004 std::ostringstream limitStream; \
1005 limitStream << limit; \
1006 ReportTestFailure (std::string (#actual) + " (actual) > " + \
1007 std::string (#limit) + " (limit)", \
1008 actualStream.str (), limitStream.str (), \
1009 msgStream.str (), file, line); \
1022 #define NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
1024 if (!((actual) >= (limit))) \
1026 ASSERT_ON_FAILURE; \
1027 std::ostringstream msgStream; \
1029 std::ostringstream actualStream; \
1030 actualStream << actual; \
1031 std::ostringstream limitStream; \
1032 limitStream << limit; \
1033 ReportTestFailure (std::string (#actual) + " (actual) > " + \
1034 std::string (#limit) + " (limit)", \
1035 actualStream.str (), limitStream.str (), \
1036 msgStream.str (), file, line); \
1056 #define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
1057 NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1076 #define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
1077 NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1100 const double epsilon = std::numeric_limits<double>::epsilon ());
1102 class TestRunnerImpl;
1134 std::string
GetName (
void)
const;
1203 std::
string limit, std::
string message,
1204 std::
string file, int32_t line);
1242 virtual
void DoRun (
void) = 0;
1266 void Run (TestRunnerImpl *runner);
1311 TestSuite (std::string name, Type type = UNIT);
1321 virtual void DoRun (
void);
1342 static int Run (
int argc,
char *argv[]);
1350 template <
typename T>
1366 void Reserve (uint32_t reserve);
1372 uint32_t Add (T vector);
1377 uint32_t GetN (
void)
const;
1383 T Get (uint32_t i)
const;
1403 template <
typename T>
1409 template <
typename T>
1413 m_vectors.reserve (reserve);
1416 template <
typename T>
1421 template <
typename T>
1425 uint32_t index = m_vectors.size ();
1426 m_vectors.push_back (vector);
1430 template <
typename T>
1434 return m_vectors.size ();
1437 template <
typename T>
1442 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
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
TestCase * GetParent() 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.
void Run(TestRunnerImpl *runner)
Actually run this TestCase.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
bool IsStatusSuccess(void) const
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
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)
Private, to block copying.
std::string m_dataDir
My data directory.
bool MustContinueOnFailure(void) const