31 #include "system-wall-clock-ms.h"
32 #include "deprecated.h"
44 #define ASSERT_ON_FAILURE \
46 if (MustAssertOnFailure ()) \
48 *(volatile int *)0 = 0; \
52 #define CONTINUE_ON_FAILURE \
54 if (!MustContinueOnFailure ()) \
60 #define CONTINUE_ON_FAILURE_RETURNS_BOOL \
62 if (!MustContinueOnFailure ()) \
64 return IsStatusFailure (); \
77 #define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
79 if (!((actual) == (limit))) \
82 std::ostringstream msgStream; \
84 std::ostringstream actualStream; \
85 actualStream << actual; \
86 std::ostringstream limitStream; \
87 limitStream << limit; \
88 ReportTestFailure (std::string (#actual) + " (actual) == " + \
89 std::string (#limit) + " (limit)", \
90 actualStream.str (), limitStream.str (), \
91 msgStream.str (), file, line); \
92 CONTINUE_ON_FAILURE; \
122 #define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
123 NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
128 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
130 if (!((actual) == (limit))) \
133 std::ostringstream msgStream; \
135 std::ostringstream actualStream; \
136 actualStream << actual; \
137 std::ostringstream limitStream; \
138 limitStream << limit; \
139 ReportTestFailure (std::string (#actual) + " (actual) == " + \
140 std::string (#limit) + " (limit)", \
141 actualStream.str (), limitStream.str (), \
142 msgStream.str (), file, line); \
143 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
176 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
177 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
185 #define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
187 if (!((actual) == (limit))) \
190 std::ostringstream msgStream; \
192 std::ostringstream actualStream; \
193 actualStream << actual; \
194 std::ostringstream limitStream; \
195 limitStream << limit; \
196 ReportTestFailure (std::string (#actual) + " (actual) == " + \
197 std::string (#limit) + " (limit)", \
198 actualStream.str (), limitStream.str (), \
199 msgStream.str (), file, line); \
229 #define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
230 NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
240 #define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
242 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
245 std::ostringstream msgStream; \
247 std::ostringstream actualStream; \
248 actualStream << actual; \
249 std::ostringstream limitStream; \
250 limitStream << limit << " +- " << tol; \
251 std::ostringstream condStream; \
252 condStream << #actual << " (actual) < " << #limit \
253 << " (limit) + " << #tol << " (tol) && " \
254 << #actual << " (actual) > " << #limit \
255 << " (limit) - " << #tol << " (tol)"; \
256 ReportTestFailure (condStream.str (), actualStream.str (), \
257 limitStream.str (), msgStream.str (), \
259 CONTINUE_ON_FAILURE; \
311 #define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
312 NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
317 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line) \
319 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
322 std::ostringstream msgStream; \
324 std::ostringstream actualStream; \
325 actualStream << actual; \
326 std::ostringstream limitStream; \
327 limitStream << limit << " +- " << tol; \
328 std::ostringstream condStream; \
329 condStream << #actual << " (actual) < " << #limit \
330 << " (limit) + " << #tol << " (tol) && " \
331 << #actual << " (actual) > " << #limit \
332 << " (limit) - " << #tol << " (tol)"; \
333 ReportTestFailure (condStream.str (), actualStream.str (), \
334 limitStream.str (), msgStream.str (), \
336 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
391 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
392 NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
400 #define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
402 if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
405 std::ostringstream msgStream; \
407 std::ostringstream actualStream; \
408 actualStream << actual; \
409 std::ostringstream limitStream; \
410 limitStream << limit << " +- " << tol; \
411 std::ostringstream condStream; \
412 condStream << #actual << " (actual) < " << #limit \
413 << " (limit) + " << #tol << " (tol) && " \
414 << #actual << " (actual) > " << #limit \
415 << " (limit) - " << #tol << " (tol)"; \
416 ReportTestFailure (condStream.str (), actualStream.str (), \
417 limitStream.str (), msgStream.str (), \
470 #define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
471 NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
480 #define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
482 if (!((actual) != (limit))) \
485 std::ostringstream msgStream; \
487 std::ostringstream actualStream; \
488 actualStream << actual; \
489 std::ostringstream limitStream; \
490 limitStream << limit; \
491 ReportTestFailure (std::string (#actual) + " (actual) != " + \
492 std::string (#limit) + " (limit)", \
493 actualStream.str (), limitStream.str (), \
494 msgStream.str (), file, line); \
495 CONTINUE_ON_FAILURE; \
524 #define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
525 NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
530 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
532 if (!((actual) != (limit))) \
535 std::ostringstream msgStream; \
537 std::ostringstream actualStream; \
538 actualStream << actual; \
539 std::ostringstream limitStream; \
540 limitStream << limit; \
541 ReportTestFailure (std::string (#actual) + " (actual) != " + \
542 std::string (#limit) + " (limit)", \
543 actualStream.str (), limitStream.str (), \
544 msgStream.str (), file, line); \
545 CONTINUE_ON_FAILURE_RETURNS_BOOL; \
577 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
578 NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
586 #define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
588 if (!((actual) != (limit))) \
591 std::ostringstream msgStream; \
593 std::ostringstream actualStream; \
594 actualStream << actual; \
595 std::ostringstream limitStream; \
596 limitStream << limit; \
597 ReportTestFailure (std::string (#actual) + " (actual) != " + \
598 std::string (#limit) + " (limit)", \
599 actualStream.str (), limitStream.str (), \
600 msgStream.str (), file, line); \
629 #define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
630 NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
639 #define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
641 if (!((actual) < (limit))) \
644 std::ostringstream msgStream; \
646 std::ostringstream actualStream; \
647 actualStream << actual; \
648 std::ostringstream limitStream; \
649 limitStream << limit; \
650 ReportTestFailure (std::string (#actual) + " (actual) < " + \
651 std::string (#limit) + " (limit)", \
652 actualStream.str (), limitStream.str (), \
653 msgStream.str (), file, line); \
654 CONTINUE_ON_FAILURE; \
673 #define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
674 NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
682 #define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
684 if (!((actual) < (limit))) \
687 std::ostringstream msgStream; \
689 std::ostringstream actualStream; \
690 actualStream << actual; \
691 std::ostringstream limitStream; \
692 limitStream << limit; \
693 ReportTestFailure (std::string (#actual) + " (actual) < " + \
694 std::string (#limit) + " (limit)", \
695 actualStream.str (), limitStream.str (), \
696 msgStream.str (), file, line); \
714 #define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
715 NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
724 #define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
726 if (!((actual) > (limit))) \
729 std::ostringstream msgStream; \
731 std::ostringstream actualStream; \
732 actualStream << actual; \
733 std::ostringstream limitStream; \
734 limitStream << limit; \
735 ReportTestFailure (std::string (#actual) + " (actual) > " + \
736 std::string (#limit) + " (limit)", \
737 actualStream.str (), limitStream.str (), \
738 msgStream.str (), file, line); \
739 CONTINUE_ON_FAILURE; \
758 #define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
759 NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
767 #define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
769 if (!((actual) > (limit))) \
772 std::ostringstream msgStream; \
774 std::ostringstream actualStream; \
775 actualStream << actual; \
776 std::ostringstream limitStream; \
777 limitStream << limit; \
778 ReportTestFailure (std::string (#actual) + " (actual) > " + \
779 std::string (#limit) + " (limit)", \
780 actualStream.str (), limitStream.str (), \
781 msgStream.str (), file, line); \
799 #define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
800 NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
823 const double epsilon = std::numeric_limits<double>::epsilon ());
825 class TestRunnerImpl;
903 std::
string GetName (
void) const;
907 void ReportTestFailure (std::
string cond, std::
string actual,
908 std::
string limit, std::
string message,
909 std::
string file, int32_t line);
910 bool MustAssertOnFailure (
void) const;
911 bool MustContinueOnFailure (
void) const;
912 std::
string CreateDataDirFilename (std::
string filename);
913 std::
string CreateTempDirFilename (std::
string filename);
930 virtual
void DoRun (
void) = 0;
944 void Run (TestRunnerImpl *runner);
945 bool IsFailed (
void) const;
952 std::
string m_dataDir;
953 TestRunnerImpl *m_runner;
954 struct Result *m_result;
984 TestSuite (std::string name, Type type = UNIT);
994 virtual void DoRun (
void);
1006 static int Run (
int argc,
char *argv[]);
1012 template <
typename T>
1019 void Reserve (uint32_t reserve);
1021 uint32_t Add (T vector);
1023 uint32_t GetN (
void)
const;
1024 T Get (uint32_t i)
const;
1031 typedef std::vector<T> TestVector;
1032 TestVector m_vectors;
1035 template <
typename T>
1041 template <
typename T>
1043 TestVectors<T>::Reserve (uint32_t reserve)
1045 m_vectors.reserve (reserve);
1048 template <
typename T>
1049 TestVectors<T>::~TestVectors ()
1053 template <
typename T>
1055 TestVectors<T>::Add (T vector)
1057 uint32_t index = m_vectors.size ();
1058 m_vectors.push_back (vector);
1062 template <
typename T>
1064 TestVectors<T>::GetN (
void)
const
1066 return m_vectors.size ();
1069 template <
typename T>
1071 TestVectors<T>::Get (uint32_t i)
const
1074 return m_vectors[i];
virtual void DoSetup(void)
Implementation to do any local setup required for this test case.
virtual void DoTeardown(void)
Implementation to do any local setup required for this test case.
A runner to execute tests.
#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)
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...
TestCase(std::string name)
bool GetErrorStatus(void) const NS_DEPRECATED
TestDuration
How long the test takes to execute.
virtual void DoRun(void)=0
Implementation to actually run this test case.
bool IsStatusFailure(void) const
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
bool IsStatusSuccess(void) const
void SetDataDir(std::string directory)
std::string GetName(void) const