38#error Macro CHECK is already defined
44 if (!UnitTest::Check(value)) \
45 UnitTest::ReportFailure (__FILE__, __LINE__, "Check failed: " #value);\
48 UnitTest::ReportFailure (__FILE__, __LINE__, \
49 "Unhandled exception in CHECK(" #value ")"); \
62#error Macro CHECK_EX is already defined
64#define CHECK_EX(value, ...) \
68 if (!UnitTest::Check(value)){ \
69 char message[UnitTest::MAX_MESSAGE_SIZE]; \
70 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
71 UnitTest::ReportFailure (__FILE__, __LINE__, message); \
75 UnitTest::ReportFailure (__FILE__, __LINE__, \
76 "Unhandled exception in CHECK_EX(" #value ")"); \
89#error Macro CHECK_EQUAL is already defined
92#define CHECK_EQUAL(expected, actual) \
97 if (!UnitTest::CheckEqual((expected), (actual), str__)) \
98 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
101 UnitTest::ReportFailure (__FILE__, __LINE__, \
102 "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
114#error Macro CHECK_NAN is already defined
117#define CHECK_NAN(value) \
121 if (!UnitTest::CheckNaN(value)) \
122 UnitTest::ReportFailure (__FILE__, __LINE__, "Check failed: " #value " is not NaN");\
125 UnitTest::ReportFailure (__FILE__, __LINE__, \
126 "Unhandled exception in CHECK_NAN(" #value ")"); \
141#error Macro CHECK_EQUAL_EX is already defined
143#define CHECK_EQUAL_EX(expected, actual, ...) \
148 if (!UnitTest::CheckEqual((expected), (actual), str__)) \
150 char message[UnitTest::MAX_MESSAGE_SIZE]; \
151 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
154 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
158 UnitTest::ReportFailure (__FILE__, __LINE__, \
159 "Unhandled exception in CHECK_EQUAL_EX(" #expected ", " #actual ")"); \
178#error Macro CHECK_CLOSE is already defined
180#define CHECK_CLOSE(expected, actual,...) \
185 if (!UnitTest::CheckClose ((expected), (actual), (__VA_ARGS__+0), str__)) \
186 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
188 catch (UnitTest::tolerance_not_set&) \
190 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
193 UnitTest::ReportFailure (__FILE__, __LINE__, \
194 "Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
212#error Macro CHECK_CLOSE_EX is already defined
214#define CHECK_CLOSE_EX(expected, actual, tolerance, ...) \
219 if (!UnitTest::CheckClose ((expected), (actual), (tolerance), str__)) \
221 char message[UnitTest::MAX_MESSAGE_SIZE]; \
222 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
225 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
228 catch (UnitTest::tolerance_not_set&) \
230 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
233 UnitTest::ReportFailure (__FILE__, __LINE__, \
234 "Unhandled exception in CHECK_CLOSE_EX(" #expected ", " #actual ")"); \
247#ifdef CHECK_ARRAY_EQUAL
248#error Macro CHECK_ARRAY_EQUAL is already defined
251#define CHECK_ARRAY_EQUAL(expected, actual, count) \
256 if (!UnitTest::CheckArrayEqual ((expected), (actual), (count), str__)) \
257 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
260 UnitTest::ReportFailure (__FILE__, __LINE__, \
261 "Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \
279#ifdef CHECK_ARRAY_CLOSE
280#error Macro CHECK_ARRAY_CLOSE is already defined
283#define CHECK_ARRAY_CLOSE(expected, actual, count, ...) \
288 if (!UnitTest::CheckArrayClose ((expected), (actual), (count), (__VA_ARGS__+0), str__)) \
289 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
291 catch (UnitTest::tolerance_not_set&) \
293 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
296 UnitTest::ReportFailure (__FILE__, __LINE__, \
297 "Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
312#ifdef CHECK_ARRAY2D_EQUAL
313#error Macro CHECK_ARRAY2D_EQUAL is already defined
316#define CHECK_ARRAY2D_EQUAL(expected, actual, rows, columns) \
321 if (!UnitTest::CheckArray2DEqual ((expected), (actual), (rows), (columns), str__)) \
322 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
325 UnitTest::ReportFailure (__FILE__, __LINE__, \
326 "Unhandled exception in CHECK_ARRAY2D_EQUAL(" #expected ", " #actual ")"); \
346#ifdef CHECK_ARRAY2D_CLOSE
347#error Macro CHECK_ARRAY2D_CLOSE is already defined
350#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, ...) \
355 if (!UnitTest::CheckArray2DClose (expected, actual, rows, columns, (__VA_ARGS__+0), str__)) \
356 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
358 catch (UnitTest::tolerance_not_set&) \
360 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
363 UnitTest::ReportFailure (__FILE__, __LINE__, \
364 "Unhandled exception in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"); \
377#error Macro CHECK_THROW is already defined
379#define CHECK_THROW(expr, except) \
382 bool caught_ = false; \
384 catch (const except& ) { caught_ = true; } \
386 UnitTest::ReportFailure (__FILE__, __LINE__, \
387 "Unexpected exception in CHECK_THROW"); \
390 UnitTest::ReportFailure (__FILE__, __LINE__, \
391 "Expected exception: \"" #except "\", not thrown"); \
405#error Macro CHECK_THROW_EX is already defined
407#define CHECK_THROW_EX(expr, except, ...) \
410 bool caught_ = false; \
412 catch (const except& ) { caught_ = true; } \
414 UnitTest::ReportFailure (__FILE__, __LINE__, \
415 "Unexpected exception in CHECK_THROW_EX"); \
418 std::string str__{"Expected exception: \"" #except "\", not thrown"}; \
419 char message[UnitTest::MAX_MESSAGE_SIZE]; \
420 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
423 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
438#ifdef CHECK_THROW_EQUAL
439#error Macro CHECK_THROW_EQUAL is already defined
441#define CHECK_THROW_EQUAL(expr, value, except) \
444 bool caught_ = false; \
446 catch (const except& actual) { \
449 if (!UnitTest::CheckEqual(value, actual, str__)) \
450 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
453 UnitTest::ReportFailure (__FILE__, __LINE__, \
454 "Unexpected exception in CHECK_THROW_EQUAL"); \
457 UnitTest::ReportFailure (__FILE__, __LINE__, \
458 "Expected exception: \"" #except "\", not thrown"); \
473#ifdef CHECK_THROW_EQUAL_EX
474#error Macro CHECK_THROW_EQUAL_EX is already defined
476#define CHECK_THROW_EQUAL_EX(expr, value, except, ...) \
479 bool caught_ = false; \
481 catch (const except& actual) { \
484 if (!UnitTest::CheckEqual(value, actual, str__)) \
486 char message[UnitTest::MAX_MESSAGE_SIZE]; \
487 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
490 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
494 UnitTest::ReportFailure (__FILE__, __LINE__, \
495 "Unexpected exception in CHECK_THROW_EQUAL"); \
499 std::string str__{ "Expected exception: \"" #except "\", not thrown" }; \
500 char message[UnitTest::MAX_MESSAGE_SIZE]; \
501 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
504 UnitTest::ReportFailure (__FILE__, __LINE__, \
505 "Expected exception: \"" #except "\", not thrown"); \
517#ifdef CHECK_FILE_EQUAL
518#error Macro CHECK_FILE_EQUAL is already defined
520#define CHECK_FILE_EQUAL(expected, actual) \
525 if (!UnitTest::CheckFileEqual((expected), (actual), str__)) \
526 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
529 UnitTest::ReportFailure (__FILE__, __LINE__, \
530 "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
542#error Macro FAILURE is already defined
544#define FAILURE(...) \
547 char message[UnitTest::MAX_MESSAGE_SIZE]; \
548 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
549 UnitTest::ReportFailure (__FILE__, __LINE__, message); \
563#if UTPP_CPP_LANG < 201703L
564extern double default_tolerance;
566inline double default_tolerance = 0;
578template <
typename Value>
590template <
typename Value>
593 return std::isnan(value);
605template <
typename expected_T,
typename actual_T>
606bool CheckEqual (
const expected_T& expected,
const actual_T& actual, std::string& msg)
608 if (!(expected == actual))
610 std::stringstream stream;
611 stream <<
"Expected " << expected <<
" but was " << actual;
620template <
typename expected_T,
typename actual_T>
621bool CheckEqual (
const expected_T* expected,
const actual_T* actual, std::string& msg)
623 if (!(*expected == *actual))
625 std::stringstream stream;
626 stream <<
"Expected " << *expected <<
" but was " << *actual;
647template <
typename expected_T,
typename actual_T>
649bool CheckEqual (
const std::vector<expected_T>& expected,
const std::vector<actual_T>& actual, std::string& msg)
651 if (expected != actual)
653 std::stringstream stream;
654 stream <<
"Expected [ ";
655 for (
auto& p : expected)
658 stream <<
"] but was [ ";
659 for (
auto& p : actual)
682template <
typename expected_T,
typename actual_T,
size_t N>
684bool CheckEqual (
const std::array<expected_T,N>& expected,
const std::array<actual_T,N>& actual, std::string& msg)
686 if (expected != actual)
688 std::stringstream stream;
689 stream <<
"Expected [ ";
690 for (
size_t i = 0; i < N; ++i)
691 stream << expected[i] <<
" ";
693 stream <<
"] but was [ ";
694 for (
size_t i = 0; i < N; ++i)
695 stream << actual[i] <<
" ";
717template <
typename expected_T,
typename actual_T>
719bool CheckEqual (
const std::list<expected_T>& expected,
const std::list<actual_T>& actual, std::string& msg)
721 if (expected != actual)
723 std::stringstream stream;
724 stream <<
"Expected ( ";
725 for (
auto const& x : expected)
728 stream <<
") but was ( ";
729 for (
auto const& x : actual)
745#if __WCHAR_MAX__ > 0x10000
747std::string to_utf8 (
const std::wstring& ws)
750 auto in = ws.cbegin ();
751 while (in != ws.end ())
753 unsigned int c = (
unsigned int)*in++;
755 out.push_back ((
char)c);
758 out.push_back (0xC0 | (c >> 6));
759 out.push_back (0x80 | (c & 0x3f));
763 out.push_back (0xE0 | (c >> 12));
764 out.push_back (0x80 | ((c >> 6) & 0x3f));
765 out.push_back (0x80 | (c & 0x3f));
769 out.push_back (0xF0 | (c >> 18));
770 out.push_back (0x80 | ((c >> 12) & 0x3f));
771 out.push_back (0x80 | ((c >> 6) & 0x3f));
772 out.push_back (0x80 | (c & 0x3f));
782 auto in = ws.cbegin ();
783 while (in != ws.end ())
785 unsigned int c1 = (
unsigned int)*in++;
786 if (c1 < 0xD800 || c1 > 0xe000)
789 out.push_back ((
char)c1);
792 out.push_back (
char(0xC0 | (c1 >> 6)));
793 out.push_back (
char(0x80 | (c1 & 0x3f)));
797 out.push_back (
char(0xE0 | (c1 >> 12)));
798 out.push_back (
char(0x80 | ((c1 >> 6) & 0x3f)));
799 out.push_back (
char(0x80 | (c1 & 0x3f)));
802 else if (in != ws.end ())
804 unsigned int c2 = (
unsigned int)*in++;
805 if (c1 > 0xdbff || c2 < 0xdc00)
811 unsigned int c = ((c1 << 10) | c2) + 0x10000;
813 out.push_back (
char(0xF0 | (c >> 18)));
814 out.push_back (
char(0x80 | ((c >> 12) & 0x3f)));
815 out.push_back (
char(0x80 | ((c >> 6) & 0x3f)));
816 out.push_back (
char(0x80 | (c & 0x3f)));
835bool CheckEqual (
const std::wstring expected,
const std::wstring actual,
838 if (expected != actual)
840 std::stringstream stream;
841 auto u8exp =
to_utf8 (expected);
843 stream <<
"Expected \'" << u8exp <<
"\' but was \'" << u8act <<
"\'";
863bool CheckEqual (
const wchar_t *expected,
const wchar_t *actual,
866 if (wcscmp (expected, actual))
868 std::stringstream stream;
869 std::string u8exp =
to_utf8 (expected);
870 std::string u8act =
to_utf8 (actual);
871 stream <<
"Expected \'" << u8exp <<
"\' but was \'" << u8act <<
"\'";
881bool CheckEqual(
const wchar_t* expected,
const std::wstring actual,
884 return CheckEqual(std::wstring(expected), actual, msg);
888bool CheckEqual(
const std::wstring expected,
const wchar_t* actual,
891 return CheckEqual(expected, std::wstring(actual), msg);
898 return CheckEqual(expected, std::wstring(actual), msg);
902bool CheckEqual (
wchar_t *expected,
wchar_t *actual, std::string &msg)
904 return CheckEqual (
const_cast<const wchar_t *
> (expected),
const_cast<const wchar_t *
> (actual), msg);
908bool CheckEqual (
const wchar_t *expected,
wchar_t *actual, std::string &msg)
910 return CheckEqual (expected,
const_cast<const wchar_t *
> (actual), msg);
914bool CheckEqual (
wchar_t *expected,
const wchar_t *actual, std::string &msg)
916 return CheckEqual (
const_cast<const wchar_t *
> (expected), actual, msg);
930bool CheckEqual (
const char* expected,
const char* actual, std::string& msg)
932 if (strcmp (expected, actual))
934 std::stringstream stream;
935 stream <<
"Expected \'" << expected <<
"\' but was \'" << actual <<
"\'";
943bool CheckEqual (
char* expected,
char* actual, std::string& msg)
945 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
949bool CheckEqual (
const char* expected,
char* actual, std::string& msg)
951 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
955bool CheckEqual (
char* expected,
const char* actual, std::string& msg)
957 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
961#if UTPP_CPP_LANG > 201703L
962#if defined(__cpp_char8_t)
968bool CheckEqual (
const char8_t* expected,
const std::string& actual, std::string& msg)
970 return CheckEqual ((
const char*)expected, actual, msg);
974bool CheckEqual (
const std::string& expected,
const char8_t* actual, std::string& msg)
976 return CheckEqual (expected, (
const char*)actual, msg);
980bool CheckEqual (
const char8_t* expected,
const char8_t* actual, std::string& msg)
982 return CheckEqual ((
const char*)expected, (
const char*)actual, msg);
991bool CheckEqual (
char32_t expected,
char32_t actual, std::string& msg)
993 if (expected != actual)
995 std::stringstream stream;
996 stream << std::hex <<
"Expected (char32_t)U\'\\x" <<
static_cast<uint32_t
>(expected)
997 <<
"\' but was (char32_t)U\'\\x" <<
static_cast<uint32_t
>(actual) <<
"\'";
1020template <
typename expected_T,
typename actual_T>
1021bool isClose (
const expected_T& expected,
const actual_T& actual,
double tolerance)
1029 return fabs ((
double)(actual - expected)) <= tolerance;
1042template <
typename expected_T,
typename actual_T>
1043bool CheckClose (
const expected_T& expected,
const actual_T& actual,
double tolerance,
1046 if (!
isClose(actual, expected, tolerance))
1049 int prec = (int)(1 - log10 (fail_tol));
1050 std::stringstream stream;
1051 stream.precision (prec);
1052 stream.setf (std::ios::fixed);
1053 stream <<
"Expected " << expected <<
" +/- " << fail_tol <<
" but was " << actual;
1054 msg = stream.str ();
1070template <
typename expected_T,
typename actual_T>
1071bool Equal1D (
const expected_T& expected,
const actual_T& actual,
size_t count)
1073 for (
size_t i = 0; i < count; ++i)
1074 if (expected[i] != actual[i])
1088template <
typename expected_T,
typename actual_T>
1090 size_t count, std::string& msg)
1092 if (!
Equal1D (expected, actual, count))
1094 std::stringstream stream;
1095 stream <<
"Expected [ ";
1096 for (
size_t i = 0; i < count; ++i)
1097 stream << expected[i] <<
" ";
1099 stream <<
"] but was [ ";
1100 for (
size_t i = 0; i < count; ++i)
1101 stream << actual[i] <<
" ";
1104 msg = stream.str ();
1123template <
typename expected_T,
typename actual_T>
1124bool isClose1D (
const expected_T& expected,
const actual_T& actual,
size_t count,
double tolerance)
1126 for (
size_t i = 0; i < count; ++i)
1128 if (!
isClose(expected[i], actual[i], tolerance))
1147template <
typename expected_T,
typename actual_T>
1149 double tolerance, std::string& msg)
1151 if (!
isClose1D (expected, actual, count, tolerance))
1154 int prec = (int)(1 - log10 (fail_tol));
1156 std::stringstream stream;
1157 stream.precision (prec);
1158 stream.setf (std::ios::fixed);
1159 stream <<
"Expected [ ";
1160 for (
size_t i = 0; i < count; ++i)
1161 stream << expected[i] <<
" ";
1163 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1164 for (
size_t i = 0; i < count; ++i)
1165 stream << actual[i] <<
" ";
1167 msg = stream.str ();
1186 if (!(expected == actual)) {
1187 std::stringstream stream;
1188 stream <<
"Expected " << expected <<
" but was " << actual;
1206template <
typename expected_T,
typename actual_T>
1207bool CheckClose (
const std::vector<expected_T>& expected,
const std::vector<actual_T>& actual,
double tolerance,
1210 if (expected.size () != actual.size ()
1211 || !
isClose1D (&expected[0], &actual[0], expected.size(), tolerance))
1214 int prec = (int)(1 - log10 (fail_tol));
1215 std::stringstream stream;
1216 stream.precision (prec);
1217 stream.setf (std::ios::fixed);
1218 stream <<
"Expected [ ";
1219 for (
auto& p : expected)
1222 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1223 for (
auto& p : actual)
1226 msg = stream.str ();
1242template <
typename expected_T,
typename actual_T,
size_t N>
1243bool CheckClose (
const std::array<expected_T, N>& expected,
const std::array<actual_T, N>& actual,
double tolerance,
1246 if (!
isClose1D (&expected[0], &actual[0], N, tolerance))
1249 int prec = (int)(1 - log10 (fail_tol));
1250 std::stringstream stream;
1251 stream.precision (prec);
1252 stream.setf (std::ios::fixed);
1253 stream <<
"Expected [ ";
1254 for (
auto& p : expected)
1257 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1258 for (
auto& p : actual)
1261 msg = stream.str ();
1276template <
typename expected_T,
typename actual_T>
1277bool Equal2D (
const expected_T& expected,
const actual_T& actual,
size_t rows,
size_t columns)
1279 for (
size_t i = 0; i < rows; ++i)
1280 if (!
Equal1D (expected[i], actual[i], columns))
1295template <
typename expected_T,
typename actual_T>
1297 size_t rows,
size_t columns, std::string& msg)
1299 if (!
Equal2D (expected, actual, rows, columns))
1301 std::stringstream stream;
1303 stream <<
"Expected [\n";
1304 for (i = 0; i < rows; ++i)
1307 for (j = 0; j < columns; ++j)
1308 stream << expected[i][j] <<
" ";
1312 stream <<
"] but was [\n";
1313 for (i = 0; i < rows; ++i)
1316 for (j = 0; j < columns; ++j)
1317 stream << actual[i][j] <<
" ";
1321 msg = stream.str ();
1337template <
typename expected_T,
typename actual_T>
1338bool isClose2D (
const expected_T& expected,
const actual_T& actual,
size_t rows,
size_t columns,
1341 for (
size_t i = 0; i < rows; ++i)
1342 if (!
isClose1D (expected[i], actual[i], columns, tolerance))
1359template <
typename expected_T,
typename actual_T>
1361 size_t rows,
size_t columns,
double tolerance, std::string& msg)
1363 if (!
isClose2D (expected, actual, rows, columns, tolerance))
1366 int prec = (int)(1 - log10 (fail_tol));
1367 std::stringstream stream;
1368 stream.precision (prec);
1369 stream.setf (std::ios::fixed);
1370 stream <<
"Expected [\n";
1372 for (i = 0; i < rows; ++i)
1375 for (j = 0; j < columns; ++j)
1376 stream << expected[i][j] <<
" ";
1380 stream <<
"] +/- " << fail_tol <<
" but was [\n";
1381 for (i = 0; i < rows; ++i)
1384 for (j = 0; j < columns; ++j)
1385 stream << actual[i][j] <<
" ";
1389 msg = stream.str ();
1407bool CheckFileEqual (
const std::string& ref,
const std::string& actual, std::string& message)
1409 struct stat st1, st2;
1410 std::ostringstream buf;
1412 stat (ref.c_str(), &st1);
1413 stat (actual.c_str(), &st2);
1414 if (st1.st_size != st2.st_size)
1416 buf <<
"Size is different (" << st1.st_size <<
" vs " << st2.st_size
1417 <<
") while comparing " << ref <<
" and " << actual;
1418 message = buf.str();
1423 f1 = fopen (ref.c_str(),
"r");
1424 f2 = fopen (actual.c_str(),
"r");
1427 if (f1) fclose (f1);
1428 if (f2) fclose (f2);
1429 buf <<
"Failed to open files while comparing "
1430 << ref <<
" and " << actual;
1431 message = buf.str();
1437 char ln1[1024], ln2[1024];
1441 if (fgets (ln1,
sizeof (ln1), f1)
1442 && fgets (ln2,
sizeof (ln2), f2))
1443 ok = !strcmp (ln1, ln2);
1453 for (off = 0, p1 = ln1, p2 = ln2;
1454 *p1 && *p2 && *p1 == *p2;
1457 buf <<
"Difference at line " << ln <<
" position " << off
1458 <<
" while comparing " << ref <<
" and " << actual;
1459 message = buf.str();
1475#define EXPECT_TRUE(x) CHECK (x)
1481#define EXPECT_FALSE(x) CHECK (!(x))
1487#define EXPECT_EQ(A, B) CHECK_EQUAL (B, A)
1492#define EXPECT_NE(A, B) \
1496 std::string str__; \
1497 if (UnitTest::CheckEqual ((A), (B), str__)) \
1498 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
1501 UnitTest::ReportFailure (__FILE__, __LINE__, \
1502 "Unhandled exception in EXPECT_NE(" #A ", " #B ")"); \
1509#define EXPECT_GE(A, B) CHECK ((A) >= (B))
1514#define EXPECT_GT(A, B) CHECK ((A) > (B))
1519#define EXPECT_LE(A, B) CHECK ((A) <= (B))
1524#define EXPECT_LT(A, B) CHECK ((A) < (B))
1529#define EXPECT_NEAR(A, B, tol) CHECK_CLOSE(B, A, tol)
1534#define EXPECT_THROW(expr, except) CHECK_THROW(expr, except)
1539#define ASSERT_TRUE(expr) ABORT (!(expr))
1544#define ASSERT_FALSE(expr) ABORT (expr)
1549#define ASSERT_EQ(e1, e2) \
1552 std::string str__; \
1553 if (!UnitTest::CheckEqual((e1), (e2), str__)) \
1555 std::stringstream stream__; \
1556 stream__ << (e1) << " and " << (e2) << " should be equal"; \
1557 throw UnitTest::test_abort (__FILE__, __LINE__, str__.c_str()); \
1564#define ASSERT_NE(e1, e2) \
1567 std::string str__; \
1568 if (UnitTest::CheckEqual ((e1), (e2), str__)) \
1570 std::stringstream stream__; \
1571 stream__ << (e1) << " and " << (e2) << " should be different"; \
1572 throw UnitTest::test_abort (__FILE__, __LINE__, stream__.str ().c_str ());\
1579#define ASSERT_GE(e1, e2) ABORT ((e1) < (e2))
1584#define ASSERT_GT(e1, e2) ABORT ((e1) <= (e2))
1589#define ASSERT_LE(e1, e2) ABORT ((e1) > (e2))
1594#define ASSERT_LT(e1, e2) ABORT ((e1) >= (e2))
bool CheckNaN(Value const value)
Definition checks.h:591
std::string to_utf8(const std::wstring &ws)
Definition checks.h:779
bool CheckArray2DClose(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, double tolerance, std::string &msg)
Definition checks.h:1360
bool CheckClose(const expected_T &expected, const actual_T &actual, double tolerance, std::string &msg)
Definition checks.h:1043
bool Check(Value const value)
Definition checks.h:579
bool isClose1D(const expected_T &expected, const actual_T &actual, size_t count, double tolerance)
Definition checks.h:1124
bool CheckArrayClose(const expected_T &expected, const actual_T &actual, size_t count, double tolerance, std::string &msg)
Definition checks.h:1148
bool CheckArrayEqual(const expected_T &expected, const actual_T &actual, size_t count, std::string &msg)
Definition checks.h:1089
bool CheckArray2DEqual(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, std::string &msg)
Definition checks.h:1296
bool CheckEqual(const expected_T &expected, const actual_T &actual, std::string &msg)
Definition checks.h:606
bool Equal1D(const expected_T &expected, const actual_T &actual, size_t count)
Definition checks.h:1071
bool isClose2D(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, double tolerance)
Definition checks.h:1338
bool CheckFileEqual(const std::string &ref, const std::string &actual, std::string &message)
Definition checks.h:1407
bool Equal2D(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns)
Definition checks.h:1277
bool isClose(const expected_T &expected, const actual_T &actual, double tolerance)
Definition checks.h:1021