35#error Macro CHECK is already defined
41 if (!UnitTest::Check(value)) \
42 UnitTest::ReportFailure (__FILE__, __LINE__, "Check failed: " #value);\
45 UnitTest::ReportFailure (__FILE__, __LINE__, \
46 "Unhandled exception in CHECK(" #value ")"); \
57#error Macro CHECK_EX is already defined
59#define CHECK_EX(value, ...) \
63 if (!UnitTest::Check(value)){ \
64 char message[UnitTest::MAX_MESSAGE_SIZE]; \
65 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
66 UnitTest::ReportFailure (__FILE__, __LINE__, message); \
70 UnitTest::ReportFailure (__FILE__, __LINE__, \
71 "Unhandled exception in CHECK_EX(" #value ")"); \
82#error Macro CHECK_EQUAL is already defined
85#define CHECK_EQUAL(expected, actual) \
90 if (!UnitTest::CheckEqual((expected), (actual), str__)) \
91 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
94 UnitTest::ReportFailure (__FILE__, __LINE__, \
95 "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
106#error Macro CHECK_NAN is already defined
109#define CHECK_NAN(value) \
113 if (!UnitTest::CheckNaN(value)) \
114 UnitTest::ReportFailure (__FILE__, __LINE__, "Check failed: " #value " is not NaN");\
117 UnitTest::ReportFailure (__FILE__, __LINE__, \
118 "Unhandled exception in CHECK_NAN(" #value ")"); \
130#error Macro CHECK_EQUAL_EX is already defined
132#define CHECK_EQUAL_EX(expected, actual, ...) \
137 if (!UnitTest::CheckEqual((expected), (actual), str__)) \
139 char message[UnitTest::MAX_MESSAGE_SIZE]; \
140 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
143 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
147 UnitTest::ReportFailure (__FILE__, __LINE__, \
148 "Unhandled exception in CHECK_EQUAL_EX(" #expected ", " #actual ")"); \
161#error Macro CHECK_CLOSE is already defined
163#define CHECK_CLOSE(expected, actual,...) \
168 if (!UnitTest::CheckClose ((expected), (actual), (__VA_ARGS__+0), str__)) \
169 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
171 catch (UnitTest::tolerance_not_set&) \
173 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
176 UnitTest::ReportFailure (__FILE__, __LINE__, \
177 "Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
190#error Macro CHECK_CLOSE_EX is already defined
192#define CHECK_CLOSE_EX(expected, actual, tolerance, ...) \
197 if (!UnitTest::CheckClose ((expected), (actual), (tolerance), str__)) \
199 char message[UnitTest::MAX_MESSAGE_SIZE]; \
200 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
203 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
206 catch (UnitTest::tolerance_not_set&) \
208 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
211 UnitTest::ReportFailure (__FILE__, __LINE__, \
212 "Unhandled exception in CHECK_CLOSE_EX(" #expected ", " #actual ")"); \
222#ifdef CHECK_ARRAY_EQUAL
223#error Macro CHECK_ARRAY_EQUAL is already defined
226#define CHECK_ARRAY_EQUAL(expected, actual, count) \
231 if (!UnitTest::CheckArrayEqual ((expected), (actual), (count), str__)) \
232 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
235 UnitTest::ReportFailure (__FILE__, __LINE__, \
236 "Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \
247#ifdef CHECK_ARRAY_CLOSE
248#error Macro CHECK_ARRAY_CLOSE is already defined
251#define CHECK_ARRAY_CLOSE(expected, actual, count, ...) \
256 if (!UnitTest::CheckArrayClose ((expected), (actual), (count), (__VA_ARGS__+0), str__)) \
257 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
259 catch (UnitTest::tolerance_not_set&) \
261 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
264 UnitTest::ReportFailure (__FILE__, __LINE__, \
265 "Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
276#ifdef CHECK_ARRAY2D_EQUAL
277#error Macro CHECK_ARRAY2D_EQUAL is already defined
280#define CHECK_ARRAY2D_EQUAL(expected, actual, rows, columns) \
285 if (!UnitTest::CheckArray2DEqual ((expected), (actual), (rows), (columns), str__)) \
286 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
289 UnitTest::ReportFailure (__FILE__, __LINE__, \
290 "Unhandled exception in CHECK_ARRAY2D_EQUAL(" #expected ", " #actual ")"); \
302#ifdef CHECK_ARRAY2D_CLOSE
303#error Macro CHECK_ARRAY2D_CLOSE is already defined
306#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, ...) \
311 if (!UnitTest::CheckArray2DClose (expected, actual, rows, columns, (__VA_ARGS__+0), str__)) \
312 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
314 catch (UnitTest::tolerance_not_set&) \
316 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
319 UnitTest::ReportFailure (__FILE__, __LINE__, \
320 "Unhandled exception in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"); \
333#error Macro CHECK_THROW is already defined
335#define CHECK_THROW(expr, except) \
338 bool caught_ = false; \
340 catch (const except& ) { caught_ = true; } \
342 UnitTest::ReportFailure (__FILE__, __LINE__, \
343 "Unexpected exception in CHECK_THROW"); \
346 UnitTest::ReportFailure (__FILE__, __LINE__, \
347 "Expected exception: \"" #except "\", not thrown"); \
359#error Macro CHECK_THROW_EX is already defined
361#define CHECK_THROW_EX(expr, except, ...) \
364 bool caught_ = false; \
366 catch (const except& ) { caught_ = true; } \
368 UnitTest::ReportFailure (__FILE__, __LINE__, \
369 "Unexpected exception in CHECK_THROW_EX"); \
372 std::string str__{"Expected exception: \"" #except "\", not thrown"}; \
373 char message[UnitTest::MAX_MESSAGE_SIZE]; \
374 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
377 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
389#ifdef CHECK_THROW_EQUAL
390#error Macro CHECK_THROW_EQUAL is already defined
392#define CHECK_THROW_EQUAL(expression, value, except) \
395 bool caught_ = false; \
396 try { expression; } \
397 catch (const except& actual) { \
400 if (!UnitTest::CheckEqual(value, actual, str__)) \
401 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
404 UnitTest::ReportFailure (__FILE__, __LINE__, \
405 "Unexpected exception in CHECK_THROW_EQUAL"); \
408 UnitTest::ReportFailure (__FILE__, __LINE__, \
409 "Expected exception: \"" #except "\", not thrown"); \
421#ifdef CHECK_THROW_EQUAL_EX
422#error Macro CHECK_THROW_EQUAL_EX is already defined
424#define CHECK_THROW_EQUAL_EX(expression, value, except, ...) \
427 bool caught_ = false; \
428 try { expression; } \
429 catch (const except& actual) { \
432 if (!UnitTest::CheckEqual(value, actual, str__)) \
434 char message[UnitTest::MAX_MESSAGE_SIZE]; \
435 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
438 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
442 UnitTest::ReportFailure (__FILE__, __LINE__, \
443 "Unexpected exception in CHECK_THROW_EQUAL"); \
447 std::string str__{ "Expected exception: \"" #except "\", not thrown" }; \
448 char message[UnitTest::MAX_MESSAGE_SIZE]; \
449 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
452 UnitTest::ReportFailure (__FILE__, __LINE__, \
453 "Expected exception: \"" #except "\", not thrown"); \
463#ifdef CHECK_FILE_EQUAL
464#error Macro CHECK_FILE_EQUAL is already defined
466#define CHECK_FILE_EQUAL(expected, actual) \
471 if (!UnitTest::CheckFileEqual((expected), (actual), str__)) \
472 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
475 UnitTest::ReportFailure (__FILE__, __LINE__, \
476 "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
487#error Macro FAILURE is already defined
489#define FAILURE(...) \
492 char message[UnitTest::MAX_MESSAGE_SIZE]; \
493 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
494 UnitTest::ReportFailure (__FILE__, __LINE__, message); \
501#if _MSVC_LANG < 201703L
503extern double default_tolerance;
506inline double default_tolerance = 0;
518template <
typename Value>
530template <
typename Value>
533 return std::isnan(value);
545template <
typename expected_T,
typename actual_T>
546bool CheckEqual (
const expected_T& expected,
const actual_T& actual, std::string& msg)
548 if (!(expected == actual))
550 std::stringstream stream;
551 stream <<
"Expected " << expected <<
" but was " << actual;
560template <
typename expected_T,
typename actual_T>
561bool CheckEqual (
const expected_T* expected,
const actual_T* actual, std::string& msg)
563 if (!(*expected == *actual))
565 std::stringstream stream;
566 stream <<
"Expected " << *expected <<
" but was " << *actual;
587template <
typename expected_T,
typename actual_T>
589bool CheckEqual (
const std::vector<expected_T>& expected,
const std::vector<actual_T>& actual, std::string& msg)
591 if (expected != actual)
593 std::stringstream stream;
594 stream <<
"Expected [ ";
595 for (
auto& p : expected)
598 stream <<
"] but was [ ";
599 for (
auto& p : actual)
622template <
typename expected_T,
typename actual_T,
size_t N>
624bool CheckEqual (
const std::array<expected_T,N>& expected,
const std::array<actual_T,N>& actual, std::string& msg)
626 if (expected != actual)
628 std::stringstream stream;
629 stream <<
"Expected [ ";
630 for (
size_t i = 0; i < N; ++i)
631 stream << expected[i] <<
" ";
633 stream <<
"] but was [ ";
634 for (
size_t i = 0; i < N; ++i)
635 stream << actual[i] <<
" ";
657template <
typename expected_T,
typename actual_T>
659bool CheckEqual (
const std::list<expected_T>& expected,
const std::list<actual_T>& actual, std::string& msg)
661 if (expected != actual)
663 std::stringstream stream;
664 stream <<
"Expected ( ";
665 for (
auto const& x : expected)
668 stream <<
") but was ( ";
669 for (
auto const& x : actual)
683#if __WCHAR_MAX__ > 0x10000
685std::string to_utf8 (
const std::wstring& ws)
688 auto in = ws.cbegin ();
689 while (in != ws.end ())
691 unsigned int c = (
unsigned int)*in++;
693 out.push_back ((
char)c);
696 out.push_back (0xC0 | (c >> 6));
697 out.push_back (0x80 | (c & 0x3f));
701 out.push_back (0xE0 | (c >> 12));
702 out.push_back (0x80 | ((c >> 6) & 0x3f));
703 out.push_back (0x80 | (c & 0x3f));
707 out.push_back (0xF0 | (c >> 18));
708 out.push_back (0x80 | ((c >> 12) & 0x3f));
709 out.push_back (0x80 | ((c >> 6) & 0x3f));
710 out.push_back (0x80 | (c & 0x3f));
720 auto in = ws.cbegin ();
721 while (in != ws.end ())
723 unsigned int c1 = (
unsigned int)*in++;
724 if (c1 < 0xD800 || c1 > 0xe000)
727 out.push_back ((
char)c1);
730 out.push_back (
char(0xC0 | (c1 >> 6)));
731 out.push_back (
char(0x80 | (c1 & 0x3f)));
735 out.push_back (
char(0xE0 | (c1 >> 12)));
736 out.push_back (
char(0x80 | ((c1 >> 6) & 0x3f)));
737 out.push_back (
char(0x80 | (c1 & 0x3f)));
740 else if (in != ws.end ())
742 unsigned int c2 = (
unsigned int)*in++;
743 if (c1 > 0xdbff || c2 < 0xdc00)
749 unsigned int c = ((c1 << 10) | c2) + 0x10000;
751 out.push_back (
char(0xF0 | (c >> 18)));
752 out.push_back (
char(0x80 | ((c >> 12) & 0x3f)));
753 out.push_back (
char(0x80 | ((c >> 6) & 0x3f)));
754 out.push_back (
char(0x80 | (c & 0x3f)));
773bool CheckEqual (
const std::wstring expected,
const std::wstring actual,
776 if (expected != actual)
778 std::stringstream stream;
779 auto u8exp =
to_utf8 (expected);
781 stream <<
"Expected \'" << u8exp <<
"\' but was \'" << u8act <<
"\'";
801bool CheckEqual (
const wchar_t *expected,
const wchar_t *actual,
804 if (wcscmp (expected, actual))
806 std::stringstream stream;
807 std::string u8exp =
to_utf8 (expected);
808 std::string u8act =
to_utf8 (actual);
809 stream <<
"Expected \'" << u8exp <<
"\' but was \'" << u8act <<
"\'";
819bool CheckEqual(
const wchar_t* expected,
const std::wstring actual,
822 return CheckEqual(std::wstring(expected), actual, msg);
826bool CheckEqual(
const std::wstring expected,
const wchar_t* actual,
829 return CheckEqual(expected, std::wstring(actual), msg);
836 return CheckEqual(expected, std::wstring(actual), msg);
840bool CheckEqual (
wchar_t *expected,
wchar_t *actual, std::string &msg)
842 return CheckEqual (
const_cast<const wchar_t *
> (expected),
const_cast<const wchar_t *
> (actual), msg);
846bool CheckEqual (
const wchar_t *expected,
wchar_t *actual, std::string &msg)
848 return CheckEqual (expected,
const_cast<const wchar_t *
> (actual), msg);
852bool CheckEqual (
wchar_t *expected,
const wchar_t *actual, std::string &msg)
854 return CheckEqual (
const_cast<const wchar_t *
> (expected), actual, msg);
864bool CheckEqual (
const char* expected,
const char* actual, std::string& msg)
866 if (strcmp (expected, actual))
868 std::stringstream stream;
869 stream <<
"Expected \'" << expected <<
"\' but was \'" << actual <<
"\'";
877bool CheckEqual (
char* expected,
char* actual, std::string& msg)
879 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
883bool CheckEqual (
const char* expected,
char* actual, std::string& msg)
885 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
889bool CheckEqual (
char* expected,
const char* actual, std::string& msg)
891 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
895#if _MSVC_LANG > 201703L
896#if defined(__cpp_char8_t)
902bool CheckEqual (
const char8_t* expected,
const std::string& actual, std::string& msg)
904 return CheckEqual ((
const char*)expected, actual, msg);
908bool CheckEqual (
const std::string& expected,
const char8_t* actual, std::string& msg)
910 return CheckEqual (expected, (
const char*)actual, msg);
914bool CheckEqual (
const char8_t* expected,
const char8_t* actual, std::string& msg)
916 return CheckEqual ((
const char*)expected, (
const char*)actual, msg);
925bool CheckEqual (
char32_t expected,
char32_t actual, std::string& msg)
927 if (expected != actual)
929 std::stringstream stream;
930 stream << std::hex <<
"Expected (char32_t)U\'\\x" <<
static_cast<uint32_t
>(expected)
931 <<
"\' but was (char32_t)U\'\\x" <<
static_cast<uint32_t
>(actual) <<
"\'";
954template <
typename expected_T,
typename actual_T>
955bool isClose (
const expected_T& expected,
const actual_T& actual,
double tolerance)
963 return fabs ((
double)(actual - expected)) <= tolerance;
976template <
typename expected_T,
typename actual_T>
977bool CheckClose (
const expected_T& expected,
const actual_T& actual,
double tolerance,
980 if (!
isClose(actual, expected, tolerance))
983 int prec = (int)(1 - log10 (fail_tol));
984 std::stringstream stream;
985 stream.precision (prec);
986 stream.setf (std::ios::fixed);
987 stream <<
"Expected " << expected <<
" +/- " << fail_tol <<
" but was " << actual;
1004template <
typename expected_T,
typename actual_T>
1005bool Equal1D (
const expected_T& expected,
const actual_T& actual,
size_t count)
1007 for (
size_t i = 0; i < count; ++i)
1008 if (expected[i] != actual[i])
1022template <
typename expected_T,
typename actual_T>
1024 size_t count, std::string& msg)
1026 if (!
Equal1D (expected, actual, count))
1028 std::stringstream stream;
1029 stream <<
"Expected [ ";
1030 for (
size_t i = 0; i < count; ++i)
1031 stream << expected[i] <<
" ";
1033 stream <<
"] but was [ ";
1034 for (
size_t i = 0; i < count; ++i)
1035 stream << actual[i] <<
" ";
1038 msg = stream.str ();
1057template <
typename expected_T,
typename actual_T>
1058bool isClose1D (
const expected_T& expected,
const actual_T& actual,
size_t count,
double tolerance)
1060 for (
size_t i = 0; i < count; ++i)
1062 if (!
isClose(expected[i], actual[i], tolerance))
1081template <
typename expected_T,
typename actual_T>
1083 double tolerance, std::string& msg)
1085 if (!
isClose1D (expected, actual, count, tolerance))
1088 int prec = (int)(1 - log10 (fail_tol));
1090 std::stringstream stream;
1091 stream.precision (prec);
1092 stream.setf (std::ios::fixed);
1093 stream <<
"Expected [ ";
1094 for (
size_t i = 0; i < count; ++i)
1095 stream << expected[i] <<
" ";
1097 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1098 for (
size_t i = 0; i < count; ++i)
1099 stream << actual[i] <<
" ";
1101 msg = stream.str ();
1120 if (!(expected == actual)) {
1121 std::stringstream stream;
1122 stream <<
"Expected " << expected <<
" but was " << actual;
1140template <
typename expected_T,
typename actual_T>
1141bool CheckClose (
const std::vector<expected_T>& expected,
const std::vector<actual_T>& actual,
double tolerance,
1144 if (expected.size () != actual.size ()
1145 || !
isClose1D (&expected[0], &actual[0], expected.size(), tolerance))
1148 int prec = (int)(1 - log10 (fail_tol));
1149 std::stringstream stream;
1150 stream.precision (prec);
1151 stream.setf (std::ios::fixed);
1152 stream <<
"Expected [ ";
1153 for (
auto& p : expected)
1156 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1157 for (
auto& p : actual)
1160 msg = stream.str ();
1176template <
typename expected_T,
typename actual_T,
size_t N>
1177bool CheckClose (
const std::array<expected_T, N>& expected,
const std::array<actual_T, N>& actual,
double tolerance,
1180 if (!
isClose1D (&expected[0], &actual[0], N, tolerance))
1183 int prec = (int)(1 - log10 (fail_tol));
1184 std::stringstream stream;
1185 stream.precision (prec);
1186 stream.setf (std::ios::fixed);
1187 stream <<
"Expected [ ";
1188 for (
auto& p : expected)
1191 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1192 for (
auto& p : actual)
1195 msg = stream.str ();
1210template <
typename expected_T,
typename actual_T>
1211bool Equal2D (
const expected_T& expected,
const actual_T& actual,
size_t rows,
size_t columns)
1213 for (
size_t i = 0; i < rows; ++i)
1214 if (!
Equal1D (expected[i], actual[i], columns))
1229template <
typename expected_T,
typename actual_T>
1231 size_t rows,
size_t columns, std::string& msg)
1233 if (!
Equal2D (expected, actual, rows, columns))
1235 std::stringstream stream;
1237 stream <<
"Expected [\n";
1238 for (i = 0; i < rows; ++i)
1241 for (j = 0; j < columns; ++j)
1242 stream << expected[i][j] <<
" ";
1246 stream <<
"] but was [\n";
1247 for (i = 0; i < rows; ++i)
1250 for (j = 0; j < columns; ++j)
1251 stream << actual[i][j] <<
" ";
1255 msg = stream.str ();
1271template <
typename expected_T,
typename actual_T>
1272bool isClose2D (
const expected_T& expected,
const actual_T& actual,
size_t rows,
size_t columns,
1275 for (
size_t i = 0; i < rows; ++i)
1276 if (!
isClose1D (expected[i], actual[i], columns, tolerance))
1293template <
typename expected_T,
typename actual_T>
1295 size_t rows,
size_t columns,
double tolerance, std::string& msg)
1297 if (!
isClose2D (expected, actual, rows, columns, tolerance))
1300 int prec = (int)(1 - log10 (fail_tol));
1301 std::stringstream stream;
1302 stream.precision (prec);
1303 stream.setf (std::ios::fixed);
1304 stream <<
"Expected [\n";
1306 for (i = 0; i < rows; ++i)
1309 for (j = 0; j < columns; ++j)
1310 stream << expected[i][j] <<
" ";
1314 stream <<
"] +/- " << fail_tol <<
" but was [\n";
1315 for (i = 0; i < rows; ++i)
1318 for (j = 0; j < columns; ++j)
1319 stream << actual[i][j] <<
" ";
1323 msg = stream.str ();
1341bool CheckFileEqual (
const std::string& ref,
const std::string& actual, std::string& message)
1343 struct stat st1, st2;
1344 std::ostringstream buf;
1346 stat (ref.c_str(), &st1);
1347 stat (actual.c_str(), &st2);
1348 if (st1.st_size != st2.st_size)
1350 buf <<
"Size is different (" << st1.st_size <<
" vs " << st2.st_size
1351 <<
") while comparing " << ref <<
" and " << actual;
1352 message = buf.str();
1357 f1 = fopen (ref.c_str(),
"r");
1358 f2 = fopen (actual.c_str(),
"r");
1361 if (f1) fclose (f1);
1362 if (f2) fclose (f2);
1363 buf <<
"Failed to open files while comparing "
1364 << ref <<
" and " << actual;
1365 message = buf.str();
1371 char ln1[1024], ln2[1024];
1375 if (fgets (ln1,
sizeof (ln1), f1)
1376 && fgets (ln2,
sizeof (ln2), f2))
1377 ok = !strcmp (ln1, ln2);
1387 for (off = 0, p1 = ln1, p2 = ln2;
1388 *p1 && *p2 && *p1 == *p2;
1391 buf <<
"Difference at line " << ln <<
" position " << off
1392 <<
" while comparing " << ref <<
" and " << actual;
1393 message = buf.str();
1408#define EXPECT_TRUE(x) CHECK (x)
1409#define EXPECT_FALSE(x) CHECK (!(x))
1410#define EXPECT_EQ(A, B) CHECK_EQUAL (B, A)
1411#define EXPECT_NE(A, B) \
1415 std::string str__; \
1416 if (UnitTest::CheckEqual ((A), (B), str__)) \
1417 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
1420 UnitTest::ReportFailure (__FILE__, __LINE__, \
1421 "Unhandled exception in CHECK_EQUAL(" #A ", " #B ")"); \
1425#define EXPECT_GE(A, B) CHECK ((A) >= (B))
1426#define EXPECT_GT(A, B) CHECK ((A) > (B))
1427#define EXPECT_LE(A, B) CHECK ((A) <= (B))
1428#define EXPECT_LT(A, B) CHECK ((A) < (B))
1430#define EXPECT_NEAR(A, B, tol) CHECK_CLOSE(B, A, tol)
1431#define EXPECT_THROW(expr, except) CHECK_THROW(expr, except)
1433#define ASSERT_TRUE(expr) ABORT (!(expr))
1434#define ASSERT_FALSE(expr) ABORT (expr)
1435#define ASSERT_EQ(e1, e2) \
1438 std::string str__; \
1439 if (!UnitTest::CheckEqual((e1), (e2), str__)) \
1440 throw UnitTest::test_abort (__FILE__, __LINE__, str__.c_str()); \
1443#define ASSERT_NE(e1, e2) \
1446 std::string str__; \
1447 if (UnitTest::CheckEqual ((e1), (e2), str__)) \
1449 std::stringstream stream__; \
1450 stream__ << (e1) << " and " << (e2) << " should be different"; \
1451 throw UnitTest::test_abort (__FILE__, __LINE__, stream__.str ().c_str ());\
1455#define ASSERT_GE(e1, e2) ABORT ((e1) < (e2))
1456#define ASSERT_GT(e1, e2) ABORT ((e1) <= (e2))
1457#define ASSERT_LE(e1, e2) ABORT ((e1) > (e2))
1458#define ASSERT_LT(e1, e2) ABORT ((e1) >= (e2))
bool CheckNaN(Value const value)
Definition checks.h:531
double default_tolerance
Default tolerance for CLOSE... macros.
std::string to_utf8(const std::wstring &ws)
Internal function for conversion from wstring to UTF-8.
Definition checks.h:717
bool CheckArray2DClose(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, double tolerance, std::string &msg)
Definition checks.h:1294
bool CheckClose(const expected_T &expected, const actual_T &actual, double tolerance, std::string &msg)
Definition checks.h:977
bool Check(Value const value)
Definition checks.h:519
bool isClose1D(const expected_T &expected, const actual_T &actual, size_t count, double tolerance)
Definition checks.h:1058
bool CheckArrayClose(const expected_T &expected, const actual_T &actual, size_t count, double tolerance, std::string &msg)
Definition checks.h:1082
bool CheckArrayEqual(const expected_T &expected, const actual_T &actual, size_t count, std::string &msg)
Definition checks.h:1023
bool CheckArray2DEqual(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, std::string &msg)
Definition checks.h:1230
bool CheckEqual(const expected_T &expected, const actual_T &actual, std::string &msg)
Definition checks.h:546
bool Equal1D(const expected_T &expected, const actual_T &actual, size_t count)
Definition checks.h:1005
bool isClose2D(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, double tolerance)
Definition checks.h:1272
bool CheckFileEqual(const std::string &ref, const std::string &actual, std::string &message)
Definition checks.h:1341
bool Equal2D(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns)
Definition checks.h:1211
bool isClose(const expected_T &expected, const actual_T &actual, double tolerance)
Definition checks.h:955