16#if !defined(_CRT_SECURE_NO_WARNINGS)
17#define _CRT_SECURE_NO_WARNINGS
41#error Macro CHECK is already defined
47 if (!UnitTest::Check(value)) \
48 UnitTest::ReportFailure (__FILE__, __LINE__, "Check failed: " #value);\
51 UnitTest::ReportFailure (__FILE__, __LINE__, \
52 "Unhandled exception in CHECK(" #value ")"); \
63#error Macro CHECK_EX is already defined
65#define CHECK_EX(value, ...) \
69 if (!UnitTest::Check(value)){ \
70 char message[UnitTest::MAX_MESSAGE_SIZE]; \
71 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
72 UnitTest::ReportFailure (__FILE__, __LINE__, message); \
76 UnitTest::ReportFailure (__FILE__, __LINE__, \
77 "Unhandled exception in CHECK_EX(" #value ")"); \
88#error Macro CHECK_EQUAL is already defined
91#define CHECK_EQUAL(expected, actual) \
96 if (!UnitTest::CheckEqual((expected), (actual), str__)) \
97 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
100 UnitTest::ReportFailure (__FILE__, __LINE__, \
101 "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
112#error Macro CHECK_NAN is already defined
115#define CHECK_NAN(value) \
119 if (!UnitTest::CheckNaN(value)) \
120 UnitTest::ReportFailure (__FILE__, __LINE__, "Check failed: " #value " is not NaN");\
123 UnitTest::ReportFailure (__FILE__, __LINE__, \
124 "Unhandled exception in CHECK_NAN(" #value ")"); \
136#error Macro CHECK_EQUAL_EX is already defined
138#define CHECK_EQUAL_EX(expected, actual, ...) \
143 if (!UnitTest::CheckEqual((expected), (actual), str__)) \
145 char message[UnitTest::MAX_MESSAGE_SIZE]; \
146 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
149 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
153 UnitTest::ReportFailure (__FILE__, __LINE__, \
154 "Unhandled exception in CHECK_EQUAL_EX(" #expected ", " #actual ")"); \
167#error Macro CHECK_CLOSE is already defined
169#define CHECK_CLOSE(expected, actual,...) \
174 if (!UnitTest::CheckClose ((expected), (actual), (__VA_ARGS__+0), str__)) \
175 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
177 catch (UnitTest::tolerance_not_set&) \
179 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
182 UnitTest::ReportFailure (__FILE__, __LINE__, \
183 "Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
196#error Macro CHECK_CLOSE_EX is already defined
198#define CHECK_CLOSE_EX(expected, actual, tolerance, ...) \
203 if (!UnitTest::CheckClose ((expected), (actual), (tolerance), str__)) \
205 char message[UnitTest::MAX_MESSAGE_SIZE]; \
206 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
209 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
212 catch (UnitTest::tolerance_not_set&) \
214 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
217 UnitTest::ReportFailure (__FILE__, __LINE__, \
218 "Unhandled exception in CHECK_CLOSE_EX(" #expected ", " #actual ")"); \
228#ifdef CHECK_ARRAY_EQUAL
229#error Macro CHECK_ARRAY_EQUAL is already defined
232#define CHECK_ARRAY_EQUAL(expected, actual, count) \
237 if (!UnitTest::CheckArrayEqual ((expected), (actual), (count), str__)) \
238 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
241 UnitTest::ReportFailure (__FILE__, __LINE__, \
242 "Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \
253#ifdef CHECK_ARRAY_CLOSE
254#error Macro CHECK_ARRAY_CLOSE is already defined
257#define CHECK_ARRAY_CLOSE(expected, actual, count, ...) \
262 if (!UnitTest::CheckArrayClose ((expected), (actual), (count), (__VA_ARGS__+0), str__)) \
263 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
265 catch (UnitTest::tolerance_not_set&) \
267 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
270 UnitTest::ReportFailure (__FILE__, __LINE__, \
271 "Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
282#ifdef CHECK_ARRAY2D_EQUAL
283#error Macro CHECK_ARRAY2D_EQUAL is already defined
286#define CHECK_ARRAY2D_EQUAL(expected, actual, rows, columns) \
291 if (!UnitTest::CheckArray2DEqual ((expected), (actual), (rows), (columns), str__)) \
292 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
295 UnitTest::ReportFailure (__FILE__, __LINE__, \
296 "Unhandled exception in CHECK_ARRAY2D_EQUAL(" #expected ", " #actual ")"); \
308#ifdef CHECK_ARRAY2D_CLOSE
309#error Macro CHECK_ARRAY2D_CLOSE is already defined
312#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, ...) \
317 if (!UnitTest::CheckArray2DClose (expected, actual, rows, columns, (__VA_ARGS__+0), str__)) \
318 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
320 catch (UnitTest::tolerance_not_set&) \
322 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
325 UnitTest::ReportFailure (__FILE__, __LINE__, \
326 "Unhandled exception in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"); \
339#error Macro CHECK_THROW is already defined
341#define CHECK_THROW(expr, except) \
344 bool caught_ = false; \
346 catch (const except& ) { caught_ = true; } \
348 UnitTest::ReportFailure (__FILE__, __LINE__, \
349 "Unexpected exception in CHECK_THROW"); \
352 UnitTest::ReportFailure (__FILE__, __LINE__, \
353 "Expected exception: \"" #except "\", not thrown"); \
365#error Macro CHECK_THROW_EX is already defined
367#define CHECK_THROW_EX(expr, except, ...) \
370 bool caught_ = false; \
372 catch (const except& ) { caught_ = true; } \
374 UnitTest::ReportFailure (__FILE__, __LINE__, \
375 "Unexpected exception in CHECK_THROW_EX"); \
378 std::string str__{"Expected exception: \"" #except "\", not thrown"}; \
379 char message[UnitTest::MAX_MESSAGE_SIZE]; \
380 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
383 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
395#ifdef CHECK_THROW_EQUAL
396#error Macro CHECK_THROW_EQUAL is already defined
398#define CHECK_THROW_EQUAL(expression, value, except) \
401 bool caught_ = false; \
402 try { expression; } \
403 catch (const except& actual) { \
406 if (!UnitTest::CheckEqual(value, actual, str__)) \
407 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
410 UnitTest::ReportFailure (__FILE__, __LINE__, \
411 "Unexpected exception in CHECK_THROW_EQUAL"); \
414 UnitTest::ReportFailure (__FILE__, __LINE__, \
415 "Expected exception: \"" #except "\", not thrown"); \
427#ifdef CHECK_THROW_EQUAL_EX
428#error Macro CHECK_THROW_EQUAL_EX is already defined
430#define CHECK_THROW_EQUAL_EX(expression, value, except, ...) \
433 bool caught_ = false; \
434 try { expression; } \
435 catch (const except& actual) { \
438 if (!UnitTest::CheckEqual(value, actual, str__)) \
440 char message[UnitTest::MAX_MESSAGE_SIZE]; \
441 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
444 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
448 UnitTest::ReportFailure (__FILE__, __LINE__, \
449 "Unexpected exception in CHECK_THROW_EQUAL"); \
453 std::string str__{ "Expected exception: \"" #except "\", not thrown" }; \
454 char message[UnitTest::MAX_MESSAGE_SIZE]; \
455 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
458 UnitTest::ReportFailure (__FILE__, __LINE__, \
459 "Expected exception: \"" #except "\", not thrown"); \
469#ifdef CHECK_FILE_EQUAL
470#error Macro CHECK_FILE_EQUAL is already defined
472#define CHECK_FILE_EQUAL(expected, actual) \
477 if (!UnitTest::CheckFileEqual((expected), (actual), str__)) \
478 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
481 UnitTest::ReportFailure (__FILE__, __LINE__, \
482 "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
493#error Macro FAILURE is already defined
495#define FAILURE(...) \
498 char message[UnitTest::MAX_MESSAGE_SIZE]; \
499 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
500 UnitTest::ReportFailure (__FILE__, __LINE__, message); \
507#if _MSVC_LANG < 201703L
509extern double default_tolerance;
512inline double default_tolerance = 0;
524template <
typename Value>
536template <
typename Value>
539 return std::isnan(value);
551template <
typename expected_T,
typename actual_T>
552bool CheckEqual (
const expected_T& expected,
const actual_T& actual, std::string& msg)
554 if (!(expected == actual))
556 std::stringstream stream;
557 stream <<
"Expected " << expected <<
" but was " << actual;
566template <
typename expected_T,
typename actual_T>
567bool CheckEqual (
const expected_T* expected,
const actual_T* actual, std::string& msg)
569 if (!(*expected == *actual))
571 std::stringstream stream;
572 stream <<
"Expected " << *expected <<
" but was " << *actual;
593template <
typename expected_T,
typename actual_T>
595bool CheckEqual (
const std::vector<expected_T>& expected,
const std::vector<actual_T>& actual, std::string& msg)
597 if (expected != actual)
599 std::stringstream stream;
600 stream <<
"Expected [ ";
601 for (
auto& p : expected)
604 stream <<
"] but was [ ";
605 for (
auto& p : actual)
628template <
typename expected_T,
typename actual_T,
size_t N>
630bool CheckEqual (
const std::array<expected_T,N>& expected,
const std::array<actual_T,N>& actual, std::string& msg)
632 if (expected != actual)
634 std::stringstream stream;
635 stream <<
"Expected [ ";
636 for (
size_t i = 0; i < N; ++i)
637 stream << expected[i] <<
" ";
639 stream <<
"] but was [ ";
640 for (
size_t i = 0; i < N; ++i)
641 stream << actual[i] <<
" ";
663template <
typename expected_T,
typename actual_T>
665bool CheckEqual (
const std::list<expected_T>& expected,
const std::list<actual_T>& actual, std::string& msg)
667 if (expected != actual)
669 std::stringstream stream;
670 stream <<
"Expected ( ";
671 for (
auto const& x : expected)
674 stream <<
") but was ( ";
675 for (
auto const& x : actual)
689#if __WCHAR_MAX__ > 0x10000
691std::string to_utf8 (
const std::wstring& ws)
694 auto in = ws.cbegin ();
695 while (in != ws.end ())
697 unsigned int c = (
unsigned int)*in++;
699 out.push_back ((
char)c);
702 out.push_back (0xC0 | (c >> 6));
703 out.push_back (0x80 | (c & 0x3f));
707 out.push_back (0xE0 | (c >> 12));
708 out.push_back (0x80 | ((c >> 6) & 0x3f));
709 out.push_back (0x80 | (c & 0x3f));
713 out.push_back (0xF0 | (c >> 18));
714 out.push_back (0x80 | ((c >> 12) & 0x3f));
715 out.push_back (0x80 | ((c >> 6) & 0x3f));
716 out.push_back (0x80 | (c & 0x3f));
726 auto in = ws.cbegin ();
727 while (in != ws.end ())
729 unsigned int c1 = (
unsigned int)*in++;
730 if (c1 < 0xD800 || c1 > 0xe000)
733 out.push_back ((
char)c1);
736 out.push_back (
char(0xC0 | (c1 >> 6)));
737 out.push_back (
char(0x80 | (c1 & 0x3f)));
741 out.push_back (
char(0xE0 | (c1 >> 12)));
742 out.push_back (
char(0x80 | ((c1 >> 6) & 0x3f)));
743 out.push_back (
char(0x80 | (c1 & 0x3f)));
746 else if (in != ws.end ())
748 unsigned int c2 = (
unsigned int)*in++;
749 if (c1 > 0xdbff || c2 < 0xdc00)
755 unsigned int c = ((c1 << 10) | c2) + 0x10000;
757 out.push_back (
char(0xF0 | (c >> 18)));
758 out.push_back (
char(0x80 | ((c >> 12) & 0x3f)));
759 out.push_back (
char(0x80 | ((c >> 6) & 0x3f)));
760 out.push_back (
char(0x80 | (c & 0x3f)));
779bool CheckEqual (
const std::wstring expected,
const std::wstring actual,
782 if (expected != actual)
784 std::stringstream stream;
785 auto u8exp =
to_utf8 (expected);
787 stream <<
"Expected \'" << u8exp <<
"\' but was \'" << u8act <<
"\'";
807bool CheckEqual (
const wchar_t *expected,
const wchar_t *actual,
810 if (wcscmp (expected, actual))
812 std::stringstream stream;
813 std::string u8exp =
to_utf8 (expected);
814 std::string u8act =
to_utf8 (actual);
815 stream <<
"Expected \'" << u8exp <<
"\' but was \'" << u8act <<
"\'";
826bool CheckEqual (
wchar_t *expected,
wchar_t *actual, std::string &msg)
828 return CheckEqual (
const_cast<const wchar_t *
> (expected),
const_cast<const wchar_t *
> (actual), msg);
832bool CheckEqual (
const wchar_t *expected,
wchar_t *actual, std::string &msg)
834 return CheckEqual (expected,
const_cast<const wchar_t *
> (actual), msg);
838bool CheckEqual (
wchar_t *expected,
const wchar_t *actual, std::string &msg)
840 return CheckEqual (
const_cast<const wchar_t *
> (expected), actual, msg);
850bool CheckEqual (
const char* expected,
const char* actual, std::string& msg)
852 if (strcmp (expected, actual))
854 std::stringstream stream;
855 stream <<
"Expected \'" << expected <<
"\' but was \'" << actual <<
"\'";
863bool CheckEqual (
char* expected,
char* actual, std::string& msg)
865 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
869bool CheckEqual (
const char* expected,
char* actual, std::string& msg)
871 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
875bool CheckEqual (
char* expected,
const char* actual, std::string& msg)
877 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
881#if _MSVC_LANG > 201703L
887bool CheckEqual (
const char8_t* expected,
const std::string& actual, std::string& msg)
889 return CheckEqual ((
const char*)expected, actual, msg);
893bool CheckEqual (
const std::string& expected,
const char8_t* actual, std::string& msg)
895 return CheckEqual (expected, (
const char*)actual, msg);
899bool CheckEqual (
const char8_t* expected,
const char8_t* actual, std::string& msg)
901 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) <<
"\'";
936template <
typename expected_T,
typename actual_T>
937bool isClose (
const expected_T& expected,
const actual_T& actual,
double tolerance)
945 return fabs ((
double)(actual - expected)) <= tolerance;
958template <
typename expected_T,
typename actual_T>
959bool CheckClose (
const expected_T& expected,
const actual_T& actual,
double tolerance,
962 if (!
isClose(actual, expected, tolerance))
965 int prec = (int)(1 - log10 (fail_tol));
966 std::stringstream stream;
967 stream.precision (prec);
968 stream.setf (std::ios::fixed);
969 stream <<
"Expected " << expected <<
" +/- " << fail_tol <<
" but was " << actual;
986template <
typename expected_T,
typename actual_T>
987bool Equal1D (
const expected_T& expected,
const actual_T& actual,
size_t count)
989 for (
size_t i = 0; i < count; ++i)
990 if (expected[i] != actual[i])
1004template <
typename expected_T,
typename actual_T>
1006 size_t count, std::string& msg)
1008 if (!
Equal1D (expected, actual, count))
1010 std::stringstream stream;
1011 stream <<
"Expected [ ";
1012 for (
size_t i = 0; i < count; ++i)
1013 stream << expected[i] <<
" ";
1015 stream <<
"] but was [ ";
1016 for (
size_t i = 0; i < count; ++i)
1017 stream << actual[i] <<
" ";
1020 msg = stream.str ();
1039template <
typename expected_T,
typename actual_T>
1040bool isClose1D (
const expected_T& expected,
const actual_T& actual,
size_t count,
double tolerance)
1042 for (
size_t i = 0; i < count; ++i)
1044 if (!
isClose(expected[i], actual[i], tolerance))
1063template <
typename expected_T,
typename actual_T>
1065 double tolerance, std::string& msg)
1067 if (!
isClose1D (expected, actual, count, tolerance))
1070 int prec = (int)(1 - log10 (fail_tol));
1072 std::stringstream stream;
1073 stream.precision (prec);
1074 stream.setf (std::ios::fixed);
1075 stream <<
"Expected [ ";
1076 for (
size_t i = 0; i < count; ++i)
1077 stream << expected[i] <<
" ";
1079 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1080 for (
size_t i = 0; i < count; ++i)
1081 stream << actual[i] <<
" ";
1083 msg = stream.str ();
1102 if (!(expected == actual)) {
1103 std::stringstream stream;
1104 stream <<
"Expected " << expected <<
" but was " << actual;
1122template <
typename expected_T,
typename actual_T>
1123bool CheckClose (
const std::vector<expected_T>& expected,
const std::vector<actual_T>& actual,
double tolerance,
1126 if (expected.size () != actual.size ()
1127 || !
isClose1D (&expected[0], &actual[0], expected.size(), tolerance))
1130 int prec = (int)(1 - log10 (fail_tol));
1131 std::stringstream stream;
1132 stream.precision (prec);
1133 stream.setf (std::ios::fixed);
1134 stream <<
"Expected [ ";
1135 for (
auto& p : expected)
1138 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1139 for (
auto& p : actual)
1142 msg = stream.str ();
1158template <
typename expected_T,
typename actual_T,
size_t N>
1159bool CheckClose (
const std::array<expected_T, N>& expected,
const std::array<actual_T, N>& actual,
double tolerance,
1162 if (!
isClose1D (&expected[0], &actual[0], N, tolerance))
1165 int prec = (int)(1 - log10 (fail_tol));
1166 std::stringstream stream;
1167 stream.precision (prec);
1168 stream.setf (std::ios::fixed);
1169 stream <<
"Expected [ ";
1170 for (
auto& p : expected)
1173 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1174 for (
auto& p : actual)
1177 msg = stream.str ();
1192template <
typename expected_T,
typename actual_T>
1193bool Equal2D (
const expected_T& expected,
const actual_T& actual,
size_t rows,
size_t columns)
1195 for (
size_t i = 0; i < rows; ++i)
1196 if (!
Equal1D (expected[i], actual[i], columns))
1211template <
typename expected_T,
typename actual_T>
1213 size_t rows,
size_t columns, std::string& msg)
1215 if (!
Equal2D (expected, actual, rows, columns))
1217 std::stringstream stream;
1219 stream <<
"Expected [\n";
1220 for (i = 0; i < rows; ++i)
1223 for (j = 0; j < columns; ++j)
1224 stream << expected[i][j] <<
" ";
1228 stream <<
"] but was [\n";
1229 for (i = 0; i < rows; ++i)
1232 for (j = 0; j < columns; ++j)
1233 stream << actual[i][j] <<
" ";
1237 msg = stream.str ();
1253template <
typename expected_T,
typename actual_T>
1254bool isClose2D (
const expected_T& expected,
const actual_T& actual,
size_t rows,
size_t columns,
1257 for (
size_t i = 0; i < rows; ++i)
1258 if (!
isClose1D (expected[i], actual[i], columns, tolerance))
1275template <
typename expected_T,
typename actual_T>
1277 size_t rows,
size_t columns,
double tolerance, std::string& msg)
1279 if (!
isClose2D (expected, actual, rows, columns, tolerance))
1282 int prec = (int)(1 - log10 (fail_tol));
1283 std::stringstream stream;
1284 stream.precision (prec);
1285 stream.setf (std::ios::fixed);
1286 stream <<
"Expected [\n";
1288 for (i = 0; i < rows; ++i)
1291 for (j = 0; j < columns; ++j)
1292 stream << expected[i][j] <<
" ";
1296 stream <<
"] +/- " << fail_tol <<
" but was [\n";
1297 for (i = 0; i < rows; ++i)
1300 for (j = 0; j < columns; ++j)
1301 stream << actual[i][j] <<
" ";
1305 msg = stream.str ();
1323bool CheckFileEqual (
const std::string& ref,
const std::string& actual, std::string& message)
1325 struct stat st1, st2;
1326 std::ostringstream buf;
1328 stat (ref.c_str(), &st1);
1329 stat (actual.c_str(), &st2);
1330 if (st1.st_size != st2.st_size)
1332 buf <<
"Size is different (" << st1.st_size <<
" vs " << st2.st_size
1333 <<
") while comparing " << ref <<
" and " << actual;
1334 message = buf.str();
1339 f1 = fopen (ref.c_str(),
"r");
1340 f2 = fopen (actual.c_str(),
"r");
1343 if (f1) fclose (f1);
1344 if (f2) fclose (f2);
1345 buf <<
"Failed to open files while comparing "
1346 << ref <<
" and " << actual;
1347 message = buf.str();
1353 char ln1[1024], ln2[1024];
1357 if (fgets (ln1,
sizeof (ln1), f1)
1358 && fgets (ln2,
sizeof (ln2), f2))
1359 ok = !strcmp (ln1, ln2);
1369 for (off = 0, p1 = ln1, p2 = ln2;
1370 *p1 && *p2 && *p1 == *p2;
1373 buf <<
"Difference at line " << ln <<
" position " << off
1374 <<
" while comparing " << ref <<
" and " << actual;
1375 message = buf.str();
1390#define EXPECT_TRUE(x) CHECK (x)
1391#define EXPECT_FALSE(x) CHECK (!(x))
1392#define EXPECT_EQ(A, B) CHECK_EQUAL (B, A)
1393#define EXPECT_NE(A, B) \
1397 std::string str__; \
1398 if (UnitTest::CheckEqual ((A), (B), str__)) \
1399 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
1402 UnitTest::ReportFailure (__FILE__, __LINE__, \
1403 "Unhandled exception in CHECK_EQUAL(" #A ", " #B ")"); \
1407#define EXPECT_GE(A, B) CHECK ((A) >= (B))
1408#define EXPECT_GT(A, B) CHECK ((A) > (B))
1409#define EXPECT_LE(A, B) CHECK ((A) <= (B))
1410#define EXPECT_LT(A, B) CHECK ((A) < (B))
1412#define EXPECT_NEAR(A, B, tol) CHECK_CLOSE(B, A, tol)
1413#define EXPECT_THROW(expr, except) CHECK_THROW(expr, except)
1415#define ASSERT_TRUE(expr) ABORT (!(expr))
1416#define ASSERT_FALSE(expr) ABORT (expr)
1417#define ASSERT_EQ(e1, e2) \
1420 std::string str__; \
1421 if (!UnitTest::CheckEqual((e1), (e2), str__)) \
1422 throw UnitTest::test_abort (__FILE__, __LINE__, str__.c_str()); \
1425#define ASSERT_NE(e1, e2) \
1428 std::string str__; \
1429 if (UnitTest::CheckEqual ((e1), (e2), str__)) \
1431 std::stringstream stream__; \
1432 stream__ << (e1) << " and " << (e2) << " should be different"; \
1433 throw UnitTest::test_abort (__FILE__, __LINE__, stream__.str ().c_str ());\
1437#define ASSERT_GE(e1, e2) ABORT ((e1) < (e2))
1438#define ASSERT_GT(e1, e2) ABORT ((e1) <= (e2))
1439#define ASSERT_LE(e1, e2) ABORT ((e1) > (e2))
1440#define ASSERT_LT(e1, e2) ABORT ((e1) >= (e2))
bool CheckNaN(Value const value)
Definition checks.h:537
double default_tolerance
Default tolerance for CLOSE... macros.
std::string to_utf8(const std::wstring &ws)
Internal function for conversion from UTF-16 to UTF-8.
Definition checks.h:723
bool CheckArray2DClose(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, double tolerance, std::string &msg)
Definition checks.h:1276
bool CheckClose(const expected_T &expected, const actual_T &actual, double tolerance, std::string &msg)
Definition checks.h:959
bool Check(Value const value)
Definition checks.h:525
bool isClose1D(const expected_T &expected, const actual_T &actual, size_t count, double tolerance)
Definition checks.h:1040
bool CheckArrayClose(const expected_T &expected, const actual_T &actual, size_t count, double tolerance, std::string &msg)
Definition checks.h:1064
bool CheckArrayEqual(const expected_T &expected, const actual_T &actual, size_t count, std::string &msg)
Definition checks.h:1005
bool CheckArray2DEqual(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, std::string &msg)
Definition checks.h:1212
bool CheckEqual(const expected_T &expected, const actual_T &actual, std::string &msg)
Definition checks.h:552
bool Equal1D(const expected_T &expected, const actual_T &actual, size_t count)
Definition checks.h:987
bool isClose2D(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, double tolerance)
Definition checks.h:1254
bool CheckFileEqual(const std::string &ref, const std::string &actual, std::string &message)
Definition checks.h:1323
bool Equal2D(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns)
Definition checks.h:1193
bool isClose(const expected_T &expected, const actual_T &actual, double tolerance)
Definition checks.h:937