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; \
753 #define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
754 NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
764 #define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
766 if (!((actual) < (limit))) \
769 std::ostringstream msgStream; \
771 std::ostringstream actualStream; \
772 actualStream << actual; \
773 std::ostringstream limitStream; \
774 limitStream << limit; \
775 ReportTestFailure (std::string (#actual) + " (actual) < " + \
776 std::string (#limit) + " (limit)", \
777 actualStream.str (), limitStream.str (), \
778 msgStream.str (), file, line); \
798 #define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
799 NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
811 #define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
813 if (!((actual) > (limit))) \
816 std::ostringstream msgStream; \
818 std::ostringstream actualStream; \
819 actualStream << actual; \
820 std::ostringstream limitStream; \
821 limitStream << limit; \
822 ReportTestFailure (std::string (#actual) + " (actual) > " + \
823 std::string (#limit) + " (limit)", \
824 actualStream.str (), limitStream.str (), \
825 msgStream.str (), file, line); \
826 CONTINUE_ON_FAILURE; \
847 #define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
848 NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
858 #define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
860 if (!((actual) > (limit))) \
863 std::ostringstream msgStream; \
865 std::ostringstream actualStream; \
866 actualStream << actual; \
867 std::ostringstream limitStream; \
868 limitStream << limit; \
869 ReportTestFailure (std::string (#actual) + " (actual) > " + \
870 std::string (#limit) + " (limit)", \
871 actualStream.str (), limitStream.str (), \
872 msgStream.str (), file, line); \
892 #define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
893 NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
916 const double epsilon = std::numeric_limits<double>::epsilon ());
918 class TestRunnerImpl;
950 std::string
GetName (
void)
const;
1019 std::
string limit, std::
string message,
1020 std::
string file, int32_t line);
1058 virtual
void DoRun (
void) = 0;
1082 void Run (TestRunnerImpl *runner);
1127 TestSuite (std::string name, Type type = UNIT);
1137 virtual void DoRun (
void);
1158 static int Run (
int argc,
char *argv[]);
1166 template <
typename T>
1182 void Reserve (uint32_t reserve);
1188 uint32_t Add (T vector);
1193 uint32_t GetN (
void)
const;
1199 T Get (uint32_t i)
const;
1219 template <
typename T>
1225 template <
typename T>
1229 m_vectors.reserve (reserve);
1232 template <
typename T>
1237 template <
typename T>
1241 uint32_t index = m_vectors.size ();
1242 m_vectors.push_back (vector);
1246 template <
typename T>
1250 return m_vectors.size ();
1253 template <
typename T>
1258 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