36#error Macro CHECK is already defined
42 if (!UnitTest::Check(value)) \
43 UnitTest::ReportFailure (__FILE__, __LINE__, "Check failed: " #value);\
46 UnitTest::ReportFailure (__FILE__, __LINE__, \
47 "Unhandled exception in CHECK(" #value ")"); \
58#error Macro CHECK_EX is already defined
60#define CHECK_EX(value, ...) \
64 if (!UnitTest::Check(value)){ \
65 char message[UnitTest::MAX_MESSAGE_SIZE]; \
66 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
67 UnitTest::ReportFailure (__FILE__, __LINE__, message); \
71 UnitTest::ReportFailure (__FILE__, __LINE__, \
72 "Unhandled exception in CHECK_EX(" #value ")"); \
83#error Macro CHECK_EQUAL is already defined
86#define CHECK_EQUAL(expected, actual) \
91 if (!UnitTest::CheckEqual((expected), (actual), str__)) \
92 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
95 UnitTest::ReportFailure (__FILE__, __LINE__, \
96 "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
107#error Macro CHECK_NAN is already defined
110#define CHECK_NAN(value) \
114 if (!UnitTest::CheckNaN(value)) \
115 UnitTest::ReportFailure (__FILE__, __LINE__, "Check failed: " #value " is not NaN");\
118 UnitTest::ReportFailure (__FILE__, __LINE__, \
119 "Unhandled exception in CHECK_NAN(" #value ")"); \
131#error Macro CHECK_EQUAL_EX is already defined
133#define CHECK_EQUAL_EX(expected, actual, ...) \
138 if (!UnitTest::CheckEqual((expected), (actual), str__)) \
140 char message[UnitTest::MAX_MESSAGE_SIZE]; \
141 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
144 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
148 UnitTest::ReportFailure (__FILE__, __LINE__, \
149 "Unhandled exception in CHECK_EQUAL_EX(" #expected ", " #actual ")"); \
162#error Macro CHECK_CLOSE is already defined
164#define CHECK_CLOSE(expected, actual,...) \
169 if (!UnitTest::CheckClose ((expected), (actual), (__VA_ARGS__+0), str__)) \
170 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
172 catch (UnitTest::tolerance_not_set&) \
174 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
177 UnitTest::ReportFailure (__FILE__, __LINE__, \
178 "Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
191#error Macro CHECK_CLOSE_EX is already defined
193#define CHECK_CLOSE_EX(expected, actual, tolerance, ...) \
198 if (!UnitTest::CheckClose ((expected), (actual), (tolerance), str__)) \
200 char message[UnitTest::MAX_MESSAGE_SIZE]; \
201 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
204 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
207 catch (UnitTest::tolerance_not_set&) \
209 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
212 UnitTest::ReportFailure (__FILE__, __LINE__, \
213 "Unhandled exception in CHECK_CLOSE_EX(" #expected ", " #actual ")"); \
223#ifdef CHECK_ARRAY_EQUAL
224#error Macro CHECK_ARRAY_EQUAL is already defined
227#define CHECK_ARRAY_EQUAL(expected, actual, count) \
232 if (!UnitTest::CheckArrayEqual ((expected), (actual), (count), str__)) \
233 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
236 UnitTest::ReportFailure (__FILE__, __LINE__, \
237 "Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \
248#ifdef CHECK_ARRAY_CLOSE
249#error Macro CHECK_ARRAY_CLOSE is already defined
252#define CHECK_ARRAY_CLOSE(expected, actual, count, ...) \
257 if (!UnitTest::CheckArrayClose ((expected), (actual), (count), (__VA_ARGS__+0), str__)) \
258 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
260 catch (UnitTest::tolerance_not_set&) \
262 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
265 UnitTest::ReportFailure (__FILE__, __LINE__, \
266 "Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
277#ifdef CHECK_ARRAY2D_EQUAL
278#error Macro CHECK_ARRAY2D_EQUAL is already defined
281#define CHECK_ARRAY2D_EQUAL(expected, actual, rows, columns) \
286 if (!UnitTest::CheckArray2DEqual ((expected), (actual), (rows), (columns), str__)) \
287 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
290 UnitTest::ReportFailure (__FILE__, __LINE__, \
291 "Unhandled exception in CHECK_ARRAY2D_EQUAL(" #expected ", " #actual ")"); \
303#ifdef CHECK_ARRAY2D_CLOSE
304#error Macro CHECK_ARRAY2D_CLOSE is already defined
307#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, ...) \
312 if (!UnitTest::CheckArray2DClose (expected, actual, rows, columns, (__VA_ARGS__+0), str__)) \
313 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
315 catch (UnitTest::tolerance_not_set&) \
317 throw UnitTest::test_abort (__FILE__, __LINE__, "UnitTest::default_tolerance not set"); \
320 UnitTest::ReportFailure (__FILE__, __LINE__, \
321 "Unhandled exception in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"); \
334#error Macro CHECK_THROW is already defined
336#define CHECK_THROW(expr, except) \
339 bool caught_ = false; \
341 catch (const except& ) { caught_ = true; } \
343 UnitTest::ReportFailure (__FILE__, __LINE__, \
344 "Unexpected exception in CHECK_THROW"); \
347 UnitTest::ReportFailure (__FILE__, __LINE__, \
348 "Expected exception: \"" #except "\", not thrown"); \
360#error Macro CHECK_THROW_EX is already defined
362#define CHECK_THROW_EX(expr, except, ...) \
365 bool caught_ = false; \
367 catch (const except& ) { caught_ = true; } \
369 UnitTest::ReportFailure (__FILE__, __LINE__, \
370 "Unexpected exception in CHECK_THROW_EX"); \
373 std::string str__{"Expected exception: \"" #except "\", not thrown"}; \
374 char message[UnitTest::MAX_MESSAGE_SIZE]; \
375 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
378 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
390#ifdef CHECK_THROW_EQUAL
391#error Macro CHECK_THROW_EQUAL is already defined
393#define CHECK_THROW_EQUAL(expression, value, except) \
396 bool caught_ = false; \
397 try { expression; } \
398 catch (const except& actual) { \
401 if (!UnitTest::CheckEqual(value, actual, str__)) \
402 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
405 UnitTest::ReportFailure (__FILE__, __LINE__, \
406 "Unexpected exception in CHECK_THROW_EQUAL"); \
409 UnitTest::ReportFailure (__FILE__, __LINE__, \
410 "Expected exception: \"" #except "\", not thrown"); \
422#ifdef CHECK_THROW_EQUAL_EX
423#error Macro CHECK_THROW_EQUAL_EX is already defined
425#define CHECK_THROW_EQUAL_EX(expression, value, except, ...) \
428 bool caught_ = false; \
429 try { expression; } \
430 catch (const except& actual) { \
433 if (!UnitTest::CheckEqual(value, actual, str__)) \
435 char message[UnitTest::MAX_MESSAGE_SIZE]; \
436 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
439 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
443 UnitTest::ReportFailure (__FILE__, __LINE__, \
444 "Unexpected exception in CHECK_THROW_EQUAL"); \
448 std::string str__{ "Expected exception: \"" #except "\", not thrown" }; \
449 char message[UnitTest::MAX_MESSAGE_SIZE]; \
450 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
453 UnitTest::ReportFailure (__FILE__, __LINE__, \
454 "Expected exception: \"" #except "\", not thrown"); \
464#ifdef CHECK_FILE_EQUAL
465#error Macro CHECK_FILE_EQUAL is already defined
467#define CHECK_FILE_EQUAL(expected, actual) \
472 if (!UnitTest::CheckFileEqual((expected), (actual), str__)) \
473 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
476 UnitTest::ReportFailure (__FILE__, __LINE__, \
477 "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
488#error Macro FAILURE is already defined
490#define FAILURE(...) \
493 char message[UnitTest::MAX_MESSAGE_SIZE]; \
494 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
495 UnitTest::ReportFailure (__FILE__, __LINE__, message); \
502#if UTPP_CPP_LANG < 201703L
504extern double default_tolerance;
507inline double default_tolerance = 0;
519template <
typename Value>
531template <
typename Value>
534 return std::isnan(value);
546template <
typename expected_T,
typename actual_T>
547bool CheckEqual (
const expected_T& expected,
const actual_T& actual, std::string& msg)
549 if (!(expected == actual))
551 std::stringstream stream;
552 stream <<
"Expected " << expected <<
" but was " << actual;
561template <
typename expected_T,
typename actual_T>
562bool CheckEqual (
const expected_T* expected,
const actual_T* actual, std::string& msg)
564 if (!(*expected == *actual))
566 std::stringstream stream;
567 stream <<
"Expected " << *expected <<
" but was " << *actual;
588template <
typename expected_T,
typename actual_T>
590bool CheckEqual (
const std::vector<expected_T>& expected,
const std::vector<actual_T>& actual, std::string& msg)
592 if (expected != actual)
594 std::stringstream stream;
595 stream <<
"Expected [ ";
596 for (
auto& p : expected)
599 stream <<
"] but was [ ";
600 for (
auto& p : actual)
623template <
typename expected_T,
typename actual_T,
size_t N>
625bool CheckEqual (
const std::array<expected_T,N>& expected,
const std::array<actual_T,N>& actual, std::string& msg)
627 if (expected != actual)
629 std::stringstream stream;
630 stream <<
"Expected [ ";
631 for (
size_t i = 0; i < N; ++i)
632 stream << expected[i] <<
" ";
634 stream <<
"] but was [ ";
635 for (
size_t i = 0; i < N; ++i)
636 stream << actual[i] <<
" ";
658template <
typename expected_T,
typename actual_T>
660bool CheckEqual (
const std::list<expected_T>& expected,
const std::list<actual_T>& actual, std::string& msg)
662 if (expected != actual)
664 std::stringstream stream;
665 stream <<
"Expected ( ";
666 for (
auto const& x : expected)
669 stream <<
") but was ( ";
670 for (
auto const& x : actual)
684#if __WCHAR_MAX__ > 0x10000
686std::string to_utf8 (
const std::wstring& ws)
689 auto in = ws.cbegin ();
690 while (in != ws.end ())
692 unsigned int c = (
unsigned int)*in++;
694 out.push_back ((
char)c);
697 out.push_back (0xC0 | (c >> 6));
698 out.push_back (0x80 | (c & 0x3f));
702 out.push_back (0xE0 | (c >> 12));
703 out.push_back (0x80 | ((c >> 6) & 0x3f));
704 out.push_back (0x80 | (c & 0x3f));
708 out.push_back (0xF0 | (c >> 18));
709 out.push_back (0x80 | ((c >> 12) & 0x3f));
710 out.push_back (0x80 | ((c >> 6) & 0x3f));
711 out.push_back (0x80 | (c & 0x3f));
721 auto in = ws.cbegin ();
722 while (in != ws.end ())
724 unsigned int c1 = (
unsigned int)*in++;
725 if (c1 < 0xD800 || c1 > 0xe000)
728 out.push_back ((
char)c1);
731 out.push_back (
char(0xC0 | (c1 >> 6)));
732 out.push_back (
char(0x80 | (c1 & 0x3f)));
736 out.push_back (
char(0xE0 | (c1 >> 12)));
737 out.push_back (
char(0x80 | ((c1 >> 6) & 0x3f)));
738 out.push_back (
char(0x80 | (c1 & 0x3f)));
741 else if (in != ws.end ())
743 unsigned int c2 = (
unsigned int)*in++;
744 if (c1 > 0xdbff || c2 < 0xdc00)
750 unsigned int c = ((c1 << 10) | c2) + 0x10000;
752 out.push_back (
char(0xF0 | (c >> 18)));
753 out.push_back (
char(0x80 | ((c >> 12) & 0x3f)));
754 out.push_back (
char(0x80 | ((c >> 6) & 0x3f)));
755 out.push_back (
char(0x80 | (c & 0x3f)));
774bool CheckEqual (
const std::wstring expected,
const std::wstring actual,
777 if (expected != actual)
779 std::stringstream stream;
780 auto u8exp =
to_utf8 (expected);
782 stream <<
"Expected \'" << u8exp <<
"\' but was \'" << u8act <<
"\'";
802bool CheckEqual (
const wchar_t *expected,
const wchar_t *actual,
805 if (wcscmp (expected, actual))
807 std::stringstream stream;
808 std::string u8exp =
to_utf8 (expected);
809 std::string u8act =
to_utf8 (actual);
810 stream <<
"Expected \'" << u8exp <<
"\' but was \'" << u8act <<
"\'";
820bool CheckEqual(
const wchar_t* expected,
const std::wstring actual,
823 return CheckEqual(std::wstring(expected), actual, msg);
827bool CheckEqual(
const std::wstring expected,
const wchar_t* actual,
830 return CheckEqual(expected, std::wstring(actual), msg);
837 return CheckEqual(expected, std::wstring(actual), msg);
841bool CheckEqual (
wchar_t *expected,
wchar_t *actual, std::string &msg)
843 return CheckEqual (
const_cast<const wchar_t *
> (expected),
const_cast<const wchar_t *
> (actual), msg);
847bool CheckEqual (
const wchar_t *expected,
wchar_t *actual, std::string &msg)
849 return CheckEqual (expected,
const_cast<const wchar_t *
> (actual), msg);
853bool CheckEqual (
wchar_t *expected,
const wchar_t *actual, std::string &msg)
855 return CheckEqual (
const_cast<const wchar_t *
> (expected), actual, msg);
865bool CheckEqual (
const char* expected,
const char* actual, std::string& msg)
867 if (strcmp (expected, actual))
869 std::stringstream stream;
870 stream <<
"Expected \'" << expected <<
"\' but was \'" << actual <<
"\'";
878bool CheckEqual (
char* expected,
char* actual, std::string& msg)
880 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
884bool CheckEqual (
const char* expected,
char* actual, std::string& msg)
886 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
890bool CheckEqual (
char* expected,
const char* actual, std::string& msg)
892 return CheckEqual (
const_cast<const char *
>(expected),
const_cast<const char*
>(actual), msg);
896#if UTPP_CPP_LANG > 201703L
897#if defined(__cpp_char8_t)
903bool CheckEqual (
const char8_t* expected,
const std::string& actual, std::string& msg)
905 return CheckEqual ((
const char*)expected, actual, msg);
909bool CheckEqual (
const std::string& expected,
const char8_t* actual, std::string& msg)
911 return CheckEqual (expected, (
const char*)actual, msg);
915bool CheckEqual (
const char8_t* expected,
const char8_t* actual, std::string& msg)
917 return CheckEqual ((
const char*)expected, (
const char*)actual, msg);
926bool CheckEqual (
char32_t expected,
char32_t actual, std::string& msg)
928 if (expected != actual)
930 std::stringstream stream;
931 stream << std::hex <<
"Expected (char32_t)U\'\\x" <<
static_cast<uint32_t
>(expected)
932 <<
"\' but was (char32_t)U\'\\x" <<
static_cast<uint32_t
>(actual) <<
"\'";
955template <
typename expected_T,
typename actual_T>
956bool isClose (
const expected_T& expected,
const actual_T& actual,
double tolerance)
964 return fabs ((
double)(actual - expected)) <= tolerance;
977template <
typename expected_T,
typename actual_T>
978bool CheckClose (
const expected_T& expected,
const actual_T& actual,
double tolerance,
981 if (!
isClose(actual, expected, tolerance))
984 int prec = (int)(1 - log10 (fail_tol));
985 std::stringstream stream;
986 stream.precision (prec);
987 stream.setf (std::ios::fixed);
988 stream <<
"Expected " << expected <<
" +/- " << fail_tol <<
" but was " << actual;
1005template <
typename expected_T,
typename actual_T>
1006bool Equal1D (
const expected_T& expected,
const actual_T& actual,
size_t count)
1008 for (
size_t i = 0; i < count; ++i)
1009 if (expected[i] != actual[i])
1023template <
typename expected_T,
typename actual_T>
1025 size_t count, std::string& msg)
1027 if (!
Equal1D (expected, actual, count))
1029 std::stringstream stream;
1030 stream <<
"Expected [ ";
1031 for (
size_t i = 0; i < count; ++i)
1032 stream << expected[i] <<
" ";
1034 stream <<
"] but was [ ";
1035 for (
size_t i = 0; i < count; ++i)
1036 stream << actual[i] <<
" ";
1039 msg = stream.str ();
1058template <
typename expected_T,
typename actual_T>
1059bool isClose1D (
const expected_T& expected,
const actual_T& actual,
size_t count,
double tolerance)
1061 for (
size_t i = 0; i < count; ++i)
1063 if (!
isClose(expected[i], actual[i], tolerance))
1082template <
typename expected_T,
typename actual_T>
1084 double tolerance, std::string& msg)
1086 if (!
isClose1D (expected, actual, count, tolerance))
1089 int prec = (int)(1 - log10 (fail_tol));
1091 std::stringstream stream;
1092 stream.precision (prec);
1093 stream.setf (std::ios::fixed);
1094 stream <<
"Expected [ ";
1095 for (
size_t i = 0; i < count; ++i)
1096 stream << expected[i] <<
" ";
1098 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1099 for (
size_t i = 0; i < count; ++i)
1100 stream << actual[i] <<
" ";
1102 msg = stream.str ();
1121 if (!(expected == actual)) {
1122 std::stringstream stream;
1123 stream <<
"Expected " << expected <<
" but was " << actual;
1141template <
typename expected_T,
typename actual_T>
1142bool CheckClose (
const std::vector<expected_T>& expected,
const std::vector<actual_T>& actual,
double tolerance,
1145 if (expected.size () != actual.size ()
1146 || !
isClose1D (&expected[0], &actual[0], expected.size(), tolerance))
1149 int prec = (int)(1 - log10 (fail_tol));
1150 std::stringstream stream;
1151 stream.precision (prec);
1152 stream.setf (std::ios::fixed);
1153 stream <<
"Expected [ ";
1154 for (
auto& p : expected)
1157 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1158 for (
auto& p : actual)
1161 msg = stream.str ();
1177template <
typename expected_T,
typename actual_T,
size_t N>
1178bool CheckClose (
const std::array<expected_T, N>& expected,
const std::array<actual_T, N>& actual,
double tolerance,
1181 if (!
isClose1D (&expected[0], &actual[0], N, tolerance))
1184 int prec = (int)(1 - log10 (fail_tol));
1185 std::stringstream stream;
1186 stream.precision (prec);
1187 stream.setf (std::ios::fixed);
1188 stream <<
"Expected [ ";
1189 for (
auto& p : expected)
1192 stream <<
"] +/- " << fail_tol <<
" but was [ ";
1193 for (
auto& p : actual)
1196 msg = stream.str ();
1211template <
typename expected_T,
typename actual_T>
1212bool Equal2D (
const expected_T& expected,
const actual_T& actual,
size_t rows,
size_t columns)
1214 for (
size_t i = 0; i < rows; ++i)
1215 if (!
Equal1D (expected[i], actual[i], columns))
1230template <
typename expected_T,
typename actual_T>
1232 size_t rows,
size_t columns, std::string& msg)
1234 if (!
Equal2D (expected, actual, rows, columns))
1236 std::stringstream stream;
1238 stream <<
"Expected [\n";
1239 for (i = 0; i < rows; ++i)
1242 for (j = 0; j < columns; ++j)
1243 stream << expected[i][j] <<
" ";
1247 stream <<
"] but was [\n";
1248 for (i = 0; i < rows; ++i)
1251 for (j = 0; j < columns; ++j)
1252 stream << actual[i][j] <<
" ";
1256 msg = stream.str ();
1272template <
typename expected_T,
typename actual_T>
1273bool isClose2D (
const expected_T& expected,
const actual_T& actual,
size_t rows,
size_t columns,
1276 for (
size_t i = 0; i < rows; ++i)
1277 if (!
isClose1D (expected[i], actual[i], columns, tolerance))
1294template <
typename expected_T,
typename actual_T>
1296 size_t rows,
size_t columns,
double tolerance, std::string& msg)
1298 if (!
isClose2D (expected, actual, rows, columns, tolerance))
1301 int prec = (int)(1 - log10 (fail_tol));
1302 std::stringstream stream;
1303 stream.precision (prec);
1304 stream.setf (std::ios::fixed);
1305 stream <<
"Expected [\n";
1307 for (i = 0; i < rows; ++i)
1310 for (j = 0; j < columns; ++j)
1311 stream << expected[i][j] <<
" ";
1315 stream <<
"] +/- " << fail_tol <<
" but was [\n";
1316 for (i = 0; i < rows; ++i)
1319 for (j = 0; j < columns; ++j)
1320 stream << actual[i][j] <<
" ";
1324 msg = stream.str ();
1342bool CheckFileEqual (
const std::string& ref,
const std::string& actual, std::string& message)
1344 struct stat st1, st2;
1345 std::ostringstream buf;
1347 stat (ref.c_str(), &st1);
1348 stat (actual.c_str(), &st2);
1349 if (st1.st_size != st2.st_size)
1351 buf <<
"Size is different (" << st1.st_size <<
" vs " << st2.st_size
1352 <<
") while comparing " << ref <<
" and " << actual;
1353 message = buf.str();
1358 f1 = fopen (ref.c_str(),
"r");
1359 f2 = fopen (actual.c_str(),
"r");
1362 if (f1) fclose (f1);
1363 if (f2) fclose (f2);
1364 buf <<
"Failed to open files while comparing "
1365 << ref <<
" and " << actual;
1366 message = buf.str();
1372 char ln1[1024], ln2[1024];
1376 if (fgets (ln1,
sizeof (ln1), f1)
1377 && fgets (ln2,
sizeof (ln2), f2))
1378 ok = !strcmp (ln1, ln2);
1388 for (off = 0, p1 = ln1, p2 = ln2;
1389 *p1 && *p2 && *p1 == *p2;
1392 buf <<
"Difference at line " << ln <<
" position " << off
1393 <<
" while comparing " << ref <<
" and " << actual;
1394 message = buf.str();
1409#define EXPECT_TRUE(x) CHECK (x)
1410#define EXPECT_FALSE(x) CHECK (!(x))
1411#define EXPECT_EQ(A, B) CHECK_EQUAL (B, A)
1412#define EXPECT_NE(A, B) \
1416 std::string str__; \
1417 if (UnitTest::CheckEqual ((A), (B), str__)) \
1418 UnitTest::ReportFailure (__FILE__, __LINE__, str__); \
1421 UnitTest::ReportFailure (__FILE__, __LINE__, \
1422 "Unhandled exception in CHECK_EQUAL(" #A ", " #B ")"); \
1426#define EXPECT_GE(A, B) CHECK ((A) >= (B))
1427#define EXPECT_GT(A, B) CHECK ((A) > (B))
1428#define EXPECT_LE(A, B) CHECK ((A) <= (B))
1429#define EXPECT_LT(A, B) CHECK ((A) < (B))
1431#define EXPECT_NEAR(A, B, tol) CHECK_CLOSE(B, A, tol)
1432#define EXPECT_THROW(expr, except) CHECK_THROW(expr, except)
1434#define ASSERT_TRUE(expr) ABORT (!(expr))
1435#define ASSERT_FALSE(expr) ABORT (expr)
1436#define ASSERT_EQ(e1, e2) \
1439 std::string str__; \
1440 if (!UnitTest::CheckEqual((e1), (e2), str__)) \
1441 throw UnitTest::test_abort (__FILE__, __LINE__, str__.c_str()); \
1444#define ASSERT_NE(e1, e2) \
1447 std::string str__; \
1448 if (UnitTest::CheckEqual ((e1), (e2), str__)) \
1450 std::stringstream stream__; \
1451 stream__ << (e1) << " and " << (e2) << " should be different"; \
1452 throw UnitTest::test_abort (__FILE__, __LINE__, stream__.str ().c_str ());\
1456#define ASSERT_GE(e1, e2) ABORT ((e1) < (e2))
1457#define ASSERT_GT(e1, e2) ABORT ((e1) <= (e2))
1458#define ASSERT_LE(e1, e2) ABORT ((e1) > (e2))
1459#define ASSERT_LT(e1, e2) ABORT ((e1) >= (e2))
bool CheckNaN(Value const value)
Definition checks.h:532
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:718
bool CheckArray2DClose(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, double tolerance, std::string &msg)
Definition checks.h:1295
bool CheckClose(const expected_T &expected, const actual_T &actual, double tolerance, std::string &msg)
Definition checks.h:978
bool Check(Value const value)
Definition checks.h:520
bool isClose1D(const expected_T &expected, const actual_T &actual, size_t count, double tolerance)
Definition checks.h:1059
bool CheckArrayClose(const expected_T &expected, const actual_T &actual, size_t count, double tolerance, std::string &msg)
Definition checks.h:1083
bool CheckArrayEqual(const expected_T &expected, const actual_T &actual, size_t count, std::string &msg)
Definition checks.h:1024
bool CheckArray2DEqual(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, std::string &msg)
Definition checks.h:1231
bool CheckEqual(const expected_T &expected, const actual_T &actual, std::string &msg)
Definition checks.h:547
bool Equal1D(const expected_T &expected, const actual_T &actual, size_t count)
Definition checks.h:1006
bool isClose2D(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns, double tolerance)
Definition checks.h:1273
bool CheckFileEqual(const std::string &ref, const std::string &actual, std::string &message)
Definition checks.h:1342
bool Equal2D(const expected_T &expected, const actual_T &actual, size_t rows, size_t columns)
Definition checks.h:1212
bool isClose(const expected_T &expected, const actual_T &actual, double tolerance)
Definition checks.h:956