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 <<
"\'";
820bool CheckEqual (
wchar_t *expected,
wchar_t *actual, std::string &msg)
822 return CheckEqual (
const_cast<const wchar_t *
> (expected),
const_cast<const wchar_t *
> (actual), msg);
826bool CheckEqual (
const wchar_t *expected,
wchar_t *actual, std::string &msg)
828 return CheckEqual (expected,
const_cast<const wchar_t *
> (actual), msg);
832bool CheckEqual (
wchar_t *expected,
const wchar_t *actual, std::string &msg)
834 return CheckEqual (
const_cast<const wchar_t *
> (expected), actual, msg);
844bool CheckEqual (
const char* expected,
const char* actual, std::string& msg)
846 if (strcmp (expected, actual))
848 std::stringstream stream;
849 stream <<
"Expected \'" << expected <<
"\' but was \'" << actual <<
"\'";
857bool CheckEqual (
char* expected,
char* actual, std::string& msg)
859 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
863bool CheckEqual (
const char* expected,
char* actual, std::string& msg)
865 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
869bool CheckEqual (
char* expected,
const char* actual, std::string& msg)
871 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
875#if _MSVC_LANG > 201703L
876#if defined(__cpp_char8_t)
882bool CheckEqual (
const char8_t* expected,
const std::string& actual, std::string& msg)
884 return CheckEqual ((
const char*)expected, actual, msg);
888bool CheckEqual (
const std::string& expected,
const char8_t* actual, std::string& msg)
890 return CheckEqual (expected, (
const char*)actual, msg);
894bool CheckEqual (
const char8_t* expected,
const char8_t* actual, std::string& msg)
896 return CheckEqual ((
const char*)expected, (
const char*)actual, msg);
905bool CheckEqual (
char32_t expected,
char32_t actual, std::string& msg)
907 if (expected != actual)
909 std::stringstream stream;
910 stream << std::hex <<
"Expected (char32_t)U\'\\x" <<
static_cast<uint32_t
>(expected)
911 <<
"\' but was (char32_t)U\'\\x" <<
static_cast<uint32_t
>(actual) <<
"\'";
934template <
typename expected_T,
typename actual_T>
935bool isClose (
const expected_T& expected,
const actual_T& actual,
double tolerance)
943 return fabs ((
double)(actual - expected)) <= tolerance;
956template <
typename expected_T,
typename actual_T>
957bool CheckClose (
const expected_T& expected,
const actual_T& actual,
double tolerance,
960 if (!
isClose(actual, expected, tolerance))
963 int prec = (int)(1 - log10 (fail_tol));
964 std::stringstream stream;
965 stream.precision (prec);
966 stream.setf (std::ios::fixed);
967 stream <<
"Expected " << expected <<
" +/- " << fail_tol <<
" but was " << actual;
984template <
typename expected_T,
typename actual_T>
985bool Equal1D (
const expected_T& expected,
const actual_T& actual,
size_t count)
987 for (
size_t i = 0; i < count; ++i)
988 if (expected[i] != actual[i])
1002template <
typename expected_T,
typename actual_T>
1004 size_t count, std::string& msg)
1006 if (!
Equal1D (expected, actual, count))
1008 std::stringstream stream;
1009 stream <<
"Expected [ ";
1010 for (
size_t i = 0; i < count; ++i)
1011 stream << expected[i] <<
" ";
1013 stream <<
"] but was [ ";
1014 for (
size_t i = 0; i < count; ++i)
1015 stream << actual[i] <<
" ";
1018 msg = stream.str ();
1037template <
typename expected_T,
typename actual_T>
1038bool isClose1D (
const expected_T& expected,
const actual_T& actual,
size_t count,
double tolerance)
1040 for (
size_t i = 0; i < count; ++i)
1042 if (!
isClose(expected[i], actual[i], tolerance))
1061template <
typename expected_T,
typename actual_T>
1063 double tolerance, std::string& msg)
1065 if (!
isClose1D (expected, actual, count, tolerance))
1068 int prec = (int)(1 - log10 (fail_tol));
1070 std::stringstream stream;
1071 stream.precision (prec);
1072 stream.setf (std::ios::fixed);
1073 stream <<
"Expected [ ";
1074 for (
size_t i = 0; i < count; ++i)
1075 stream << expected[i] <<
" ";
1077 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1078 for (
size_t i = 0; i < count; ++i)
1079 stream << actual[i] <<
" ";
1081 msg = stream.str ();
1100 if (!(expected == actual)) {
1101 std::stringstream stream;
1102 stream <<
"Expected " << expected <<
" but was " << actual;
1120template <
typename expected_T,
typename actual_T>
1121bool CheckClose (
const std::vector<expected_T>& expected,
const std::vector<actual_T>& actual,
double tolerance,
1124 if (expected.size () != actual.size ()
1125 || !
isClose1D (&expected[0], &actual[0], expected.size(), tolerance))
1128 int prec = (int)(1 - log10 (fail_tol));
1129 std::stringstream stream;
1130 stream.precision (prec);
1131 stream.setf (std::ios::fixed);
1132 stream <<
"Expected [ ";
1133 for (
auto& p : expected)
1136 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1137 for (
auto& p : actual)
1140 msg = stream.str ();
1156template <
typename expected_T,
typename actual_T,
size_t N>
1157bool CheckClose (
const std::array<expected_T, N>& expected,
const std::array<actual_T, N>& actual,
double tolerance,
1160 if (!
isClose1D (&expected[0], &actual[0], N, tolerance))
1163 int prec = (int)(1 - log10 (fail_tol));
1164 std::stringstream stream;
1165 stream.precision (prec);
1166 stream.setf (std::ios::fixed);
1167 stream <<
"Expected [ ";
1168 for (
auto& p : expected)
1171 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1172 for (
auto& p : actual)
1175 msg = stream.str ();
1190template <
typename expected_T,
typename actual_T>
1191bool Equal2D (
const expected_T& expected,
const actual_T& actual,
size_t rows,
size_t columns)
1193 for (
size_t i = 0; i < rows; ++i)
1194 if (!
Equal1D (expected[i], actual[i], columns))
1209template <
typename expected_T,
typename actual_T>
1211 size_t rows,
size_t columns, std::string& msg)
1213 if (!
Equal2D (expected, actual, rows, columns))
1215 std::stringstream stream;
1217 stream <<
"Expected [\n";
1218 for (i = 0; i < rows; ++i)
1221 for (j = 0; j < columns; ++j)
1222 stream << expected[i][j] <<
" ";
1226 stream <<
"] but was [\n";
1227 for (i = 0; i < rows; ++i)
1230 for (j = 0; j < columns; ++j)
1231 stream << actual[i][j] <<
" ";
1235 msg = stream.str ();
1251template <
typename expected_T,
typename actual_T>
1252bool isClose2D (
const expected_T& expected,
const actual_T& actual,
size_t rows,
size_t columns,
1255 for (
size_t i = 0; i < rows; ++i)
1256 if (!
isClose1D (expected[i], actual[i], columns, tolerance))
1273template <
typename expected_T,
typename actual_T>
1275 size_t rows,
size_t columns,
double tolerance, std::string& msg)
1277 if (!
isClose2D (expected, actual, rows, columns, tolerance))
1280 int prec = (int)(1 - log10 (fail_tol));
1281 std::stringstream stream;
1282 stream.precision (prec);
1283 stream.setf (std::ios::fixed);
1284 stream <<
"Expected [\n";
1286 for (i = 0; i < rows; ++i)
1289 for (j = 0; j < columns; ++j)
1290 stream << expected[i][j] <<
" ";
1294 stream <<
"] +/- " << fail_tol <<
" but was [\n";
1295 for (i = 0; i < rows; ++i)
1298 for (j = 0; j < columns; ++j)
1299 stream << actual[i][j] <<
" ";
1303 msg = stream.str ();
1321bool CheckFileEqual (
const std::string& ref,
const std::string& actual, std::string& message)
1323 struct stat st1, st2;
1324 std::ostringstream buf;
1326 stat (ref.c_str(), &st1);
1327 stat (actual.c_str(), &st2);
1328 if (st1.st_size != st2.st_size)
1330 buf <<
"Size is different (" << st1.st_size <<
" vs " << st2.st_size
1331 <<
") while comparing " << ref <<
" and " << actual;
1332 message = buf.str();
1337 f1 = fopen (ref.c_str(),
"r");
1338 f2 = fopen (actual.c_str(),
"r");
1341 if (f1) fclose (f1);
1342 if (f2) fclose (f2);
1343 buf <<
"Failed to open files while comparing "
1344 << ref <<
" and " << actual;
1345 message = buf.str();
1351 char ln1[1024], ln2[1024];
1355 if (fgets (ln1,
sizeof (ln1), f1)
1356 && fgets (ln2,
sizeof (ln2), f2))
1357 ok = !strcmp (ln1, ln2);
1367 for (off = 0, p1 = ln1, p2 = ln2;
1368 *p1 && *p2 && *p1 == *p2;
1371 buf <<
"Difference at line " << ln <<
" position " << off
1372 <<
" while comparing " << ref <<
" and " << actual;
1373 message = buf.str();
1388#define EXPECT_TRUE(x) CHECK (x)
1389#define EXPECT_FALSE(x) CHECK (!(x))
1390#define EXPECT_EQ(A, B) CHECK_EQUAL (B, A)
1391#define EXPECT_NE(A, B) \
1395 std::string str__; \
1396 if (UnitTest::CheckEqual ((A), (B), str__)) \
1397 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
1400 UnitTest::ReportFailure (__FILE__, __LINE__, \
1401 "Unhandled exception in CHECK_EQUAL(" #A ", " #B ")"); \
1405#define EXPECT_GE(A, B) CHECK ((A) >= (B))
1406#define EXPECT_GT(A, B) CHECK ((A) > (B))
1407#define EXPECT_LE(A, B) CHECK ((A) <= (B))
1408#define EXPECT_LT(A, B) CHECK ((A) < (B))
1410#define EXPECT_NEAR(A, B, tol) CHECK_CLOSE(B, A, tol)
1411#define EXPECT_THROW(expr, except) CHECK_THROW(expr, except)
1413#define ASSERT_TRUE(expr) ABORT (!(expr))
1414#define ASSERT_FALSE(expr) ABORT (expr)
1415#define ASSERT_EQ(e1, e2) \
1418 std::string str__; \
1419 if (!UnitTest::CheckEqual((e1), (e2), str__)) \
1420 throw UnitTest::test_abort (__FILE__, __LINE__, str__.c_str()); \
1423#define ASSERT_NE(e1, e2) \
1426 std::string str__; \
1427 if (UnitTest::CheckEqual ((e1), (e2), str__)) \
1429 std::stringstream stream__; \
1430 stream__ << (e1) << " and " << (e2) << " should be different"; \
1431 throw UnitTest::test_abort (__FILE__, __LINE__, stream__.str ().c_str ());\
1435#define ASSERT_GE(e1, e2) ABORT ((e1) < (e2))
1436#define ASSERT_GT(e1, e2) ABORT ((e1) <= (e2))
1437#define ASSERT_LE(e1, e2) ABORT ((e1) > (e2))
1438#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:1274
bool CheckClose(const expected_T &expected, const actual_T &actual, double tolerance, std::string &msg)
Definition checks.h:957
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:1038
bool CheckArrayClose(const expected_T &expected, const actual_T &actual, size_t count, double tolerance, std::string &msg)
Definition checks.h:1062
bool CheckArrayEqual(const expected_T &expected, const actual_T &actual, size_t count, std::string &msg)
Definition checks.h:1003
bool CheckArray2DEqual(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, std::string &msg)
Definition checks.h:1210
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:985
bool isClose2D(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, double tolerance)
Definition checks.h:1252
bool CheckFileEqual(const std::string &ref, const std::string &actual, std::string &message)
Definition checks.h:1321
bool Equal2D(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns)
Definition checks.h:1191
bool isClose(const expected_T &expected, const actual_T &actual, double tolerance)
Definition checks.h:935