diff --git a/backtrace_execinfo.cpp b/backtrace_execinfo.cpp index 26f6124c..a94b6baa 100644 --- a/backtrace_execinfo.cpp +++ b/backtrace_execinfo.cpp @@ -17,7 +17,7 @@ debug::backtrace::backtrace (void): while ((final = ::backtrace (&m_frames[0], m_frames.size ())) == m_frames.size ()) m_frames.resize (m_frames.size () * 2); - check_hard (final > 0); + CHECK_HARD (final > 0); m_frames.resize ((unsigned)final); } diff --git a/debug.hpp b/debug.hpp index f307a1e8..60f4c99e 100644 --- a/debug.hpp +++ b/debug.hpp @@ -37,38 +37,38 @@ do { \ #define DEBUG_ONLY(X) #endif -#define trace { \ +#define TRACE { \ std::cerr << __FILE__ << ":" << __func__ << ":" << __LINE__ << std::endl; \ } -#define warn(MSG) do { \ +#define WARN(MSG) do { \ std::cerr << __FILE__ << ":" << __func__ << ":" __LINE__ << ", " << (MSG) << std::endl; \ } while (0) -#define warn_if(C, MSG) do { \ +#define WARN_IF(C, MSG) do { \ if (C) { \ std::cerr << __FILE__ << ":" << __func__ << ":" __LINE__ << ", " << (MSG) << std::endl; \ } \ } while (0) -#define verify_soft(C, COND) ({ \ +#define VERIFY_SOFT(C, COND) ({ \ const auto __DEBUG_value = (C); \ - check_soft(__DEBUG_value COND); \ + CHECK_SOFT(__DEBUG_value COND); \ __DEBUG_value; \ }) -#define verify_hard(C, COND) ({ \ +#define VERIFY_HARD(C, COND) ({ \ const auto __DEBUG_value = (C); \ - check_hard(__DEBUG_value COND); \ + CHECK_HARD(__DEBUG_value COND); \ __DEBUG_value; \ }) -#define _check_meta(C, SUCCESS, FAILURE) do { \ +#define _CHECK_META(C, SUCCESS, FAILURE) do { \ const auto __DEBUG_value = (C); \ if (unlikely (!__DEBUG_value)) { \ std::cerr << PACKAGE << ": " \ @@ -85,14 +85,14 @@ do { \ } while (0) -#define check_hard(C) _check_meta((C), { ; }, { panic (); }) -#define check_soft(C) _check_meta((C), { ; }, { breakpoint (); }) +#define CHECK_HARD(C) _CHECK_META((C), { ; }, { panic (); }) +#define CHECK_SOFT(C) _CHECK_META((C), { ; }, { breakpoint (); }) -#define check_eq(A,B) do { \ +#define CHECK_EQ(A,B) do { \ const auto __a = (A); \ const auto __b = (B); \ - _check_meta (almost_equal (__a, __b), \ + _CHECK_META (almost_equal (__a, __b), \ { ; }, \ { \ std::ostringstream os; \ @@ -105,10 +105,10 @@ do { \ } while (0) -#define check_neq(A,B) do { \ +#define CHECK_NEQ(A,B) do { \ const auto __a = (A); \ const auto __b = (B); \ - _check_meta (!almost_equal (__a, __b), \ + _CHECK_META (!almost_equal (__a, __b), \ { ; }, \ { \ std::ostringstream os; \ @@ -121,7 +121,7 @@ do { \ } while (0) -#define check_throws(E,C) do { \ +#define CHECK_THROWS(E,C) do { \ bool caught = false; \ \ try \ @@ -133,7 +133,7 @@ do { \ panic ("expected exception: " #E); \ } while (0) -#define check(C) check_hard(C) +#define CHECK(C) CHECK_HARD(C) class panic_error { diff --git a/except.cpp b/except.cpp index fa476089..d64da636 100644 --- a/except.cpp +++ b/except.cpp @@ -33,7 +33,7 @@ errno_error::errno_error (int _errno): runtime_error (strerror (_errno)), id (_errno) { - check_hard (_errno != 0); + CHECK_HARD (_errno != 0); } @@ -43,7 +43,7 @@ errno_error::errno_error (): runtime_error (strerror (errno)), id (errno) { - check_hard (errno != 0); + CHECK_HARD (errno != 0); } @@ -68,7 +68,7 @@ errno_error::throw_code (void) void errno_error::throw_code (int code) { - check_hard (code != 0); + CHECK_HARD (code != 0); throw errno_error (code); } @@ -78,7 +78,7 @@ win32_error::win32_error (DWORD _id): runtime_error ("Win32 error"), id (_id) { - check_soft (id != ERROR_SUCCESS); + CHECK_SOFT (id != ERROR_SUCCESS); } @@ -86,7 +86,7 @@ win32_error::win32_error (void): runtime_error ("Win32 error"), id (GetLastError ()) { - check_soft (id != ERROR_SUCCESS); + CHECK_SOFT (id != ERROR_SUCCESS); } @@ -103,7 +103,7 @@ win32_error::try_code (void) { void win32_error::throw_code (void) { const auto id = GetLastError (); - check (id != ERROR_SUCCESS); + CHECK (id != ERROR_SUCCESS); throw win32_error (id); } diff --git a/extent.cpp b/extent.cpp index 56a39ea1..db5cd43b 100644 --- a/extent.cpp +++ b/extent.cpp @@ -64,7 +64,7 @@ extent::operator ==(const extent& rhs) const { template void extent::sanity (void) const - { check (width >= 0 && height >= 0); } + { CHECK (width >= 0 && height >= 0); } namespace util { diff --git a/float.cpp b/float.cpp index 1682c439..666cc3e4 100644 --- a/float.cpp +++ b/float.cpp @@ -60,7 +60,7 @@ ieee_float::operator==(floating_t _floating) const { // TODO: This method really shouldn't be generated if there's no // representative native floating point type. But I'm sick of // C++'s template bullshit for tonight. - check_hard (bits_type::has_floating); + CHECK_HARD (bits_type::has_floating); union { floating_t _floating; diff --git a/io.cpp b/io.cpp index ab77b90b..ba12f133 100644 --- a/io.cpp +++ b/io.cpp @@ -52,7 +52,7 @@ util::slurp (const boost::filesystem::path& path) { unique_ptr buffer (new char[size + 1]); buffer.get()[size] = '\0'; - check_hard (size >= 0); + CHECK_HARD (size >= 0); size_t remaining = (size_t)size; char *cursor = buffer.get(); @@ -60,8 +60,8 @@ util::slurp (const boost::filesystem::path& path) { ssize_t consumed = read (fd, cursor, remaining); if (consumed == -1) throw errno_error(); - check_hard ( consumed > 0); - check_hard ((size_t)consumed <= remaining); + CHECK_HARD ( consumed > 0); + CHECK_HARD ((size_t)consumed <= remaining); remaining -= (size_t)consumed; cursor += consumed; @@ -92,7 +92,7 @@ fd_ref::fd_ref (const boost::filesystem::path &path): fd_ref::~fd_ref () { - check (fd >= 0); + CHECK (fd >= 0); close (fd); } @@ -150,7 +150,7 @@ scoped_cwd::~scoped_cwd () { void util::set_cwd (const boost::filesystem::path &path) { - check (path.string ().size () > 0); + CHECK (path.string ().size () > 0); if (chdir (path.string ().c_str ()) != 0) throw errno_error (); @@ -177,7 +177,7 @@ mapped_file::mapped_file (const boost::filesystem::path &_path): mapped_file::~mapped_file () { - check (m_data != NULL); + CHECK (m_data != NULL); munmap (m_data, m_size); } @@ -197,8 +197,8 @@ mapped_file::load_fd (void) { size_t mapped_file::size (void) const { - check (m_size > 0); - check (m_data != NULL); + CHECK (m_size > 0); + CHECK (m_data != NULL); return m_size; } @@ -206,8 +206,8 @@ mapped_file::size (void) const { const uint8_t* mapped_file::data (void) const { - check (m_size > 0); - check (m_data != NULL); + CHECK (m_size > 0); + CHECK (m_data != NULL); return m_data; } diff --git a/json.cpp.rl b/json.cpp.rl index 7c52bfd5..2ac50965 100644 --- a/json.cpp.rl +++ b/json.cpp.rl @@ -80,9 +80,9 @@ struct parse_context { action new_array { nodestack.push_back (parse_context(new json::array)); } action new_object_value { - check_hard (nodestack.back ().root->is_object ()); - check (nodestack.back ().key); - check (nodestack.back ().value); + CHECK_HARD (nodestack.back ().root->is_object ()); + CHECK (nodestack.back ().key); + CHECK (nodestack.back ().value); if (!nodestack.back ().key->is_string ()) throw parse_error ("object keys must be strings"); @@ -95,8 +95,8 @@ struct parse_context { } action new_array_value { - check_hard (nodestack.back ().root->is_array ()); - check (nodestack.back ().value); + CHECK_HARD (nodestack.back ().root->is_array ()); + CHECK (nodestack.back ().value); json::array *array = (json::array *)nodestack.back ().root; array->insert (unique_ptr (nodestack.back ().value)); @@ -104,8 +104,8 @@ struct parse_context { } action new_string { - check_hard (!nodestack.empty ()); - check (!nodestack.back ().value); + CHECK_HARD (!nodestack.empty ()); + CHECK (!nodestack.back ().value); std::string value (std::string (nodestack.back ().start, nodestack.back ().stop)); @@ -113,20 +113,20 @@ struct parse_context { } action new_boolean { - check_hard (!nodestack.empty ()); - check (!nodestack.back ().value); + CHECK_HARD (!nodestack.empty ()); + CHECK (!nodestack.back ().value); throw parse_error ("unable to parse boolean"); } action new_number { - check_hard (!nodestack.empty ()); + CHECK_HARD (!nodestack.empty ()); parse_context &back = nodestack.back (); - check (!back.value); - check_hard (back.start); - check_hard (back.stop); - check_hard (back.start <= back.stop); + CHECK (!back.value); + CHECK_HARD (back.start); + CHECK_HARD (back.stop); + CHECK_HARD (back.start <= back.stop); errno = 0; char *end; @@ -137,17 +137,17 @@ struct parse_context { } action new_null { - check_hard (!nodestack.empty ()); - check (!nodestack.back ().value); + CHECK_HARD (!nodestack.empty ()); + CHECK (!nodestack.back ().value); nodestack.back().value = new json::null (); } action new_object_key { - check_hard (!nodestack.empty ()); - check_hard (nodestack.back ().root->is_object ()); - check (nodestack.back ().value); - check (!nodestack.back ().key); + CHECK_HARD (!nodestack.empty ()); + CHECK_HARD (nodestack.back ().root->is_object ()); + CHECK (nodestack.back ().value); + CHECK (!nodestack.back ().key); nodestack.back ().key = nodestack.back ().value; nodestack.back ().value = NULL; @@ -292,7 +292,7 @@ json::parse (const char *start, throw parse_error ("unable to parse json"); //__root->print (cout) << endl; - check (*__root == *__root); + CHECK (*__root == *__root); return std::unique_ptr (__root); } diff --git a/json/schema.cpp b/json/schema.cpp index 7fdb1810..08a6513e 100644 --- a/json/schema.cpp +++ b/json/schema.cpp @@ -381,7 +381,7 @@ is_additional_items_valid (const json::array &, bool is_array_valid (const json::array &node, const json::object &schema) { - check_hard (node.is_array ()); + CHECK_HARD (node.is_array ()); typedef bool (*array_validator_t)(const json::array&, const json::node&); static const map VALIDATORS ({ @@ -441,7 +441,7 @@ is_properties_valid (const json::object &node, bool is_properties_valid (const json::object &node, const json::node &constraint) { - check (node.is_object ()); + CHECK (node.is_object ()); if (!constraint.is_object ()) throw json::schema_error ("properties needs an object"); diff --git a/lerp.cpp b/lerp.cpp index bd9e21fa..a8e89b56 100644 --- a/lerp.cpp +++ b/lerp.cpp @@ -33,14 +33,14 @@ lerp::sigmoid (double val) { double lerp::linear (double a, double b, double weight) { - check (weight >= 0 && weight <= 1.0); + CHECK (weight >= 0 && weight <= 1.0); return (1.0 - weight) * a + weight * b; } double lerp::cosine (double a, double b, double weight) { - check (weight >= 0 && weight <= 1.0); + CHECK (weight >= 0 && weight <= 1.0); double ft = weight * PI; double f = (1.0 - cos (ft)) * 0.5; diff --git a/log.cpp b/log.cpp index 0a12d9f2..c09679b2 100644 --- a/log.cpp +++ b/log.cpp @@ -37,7 +37,7 @@ using std::map; void check_level (level_t l) - { check (l >= 0 && l < NUM_LEVELS); } + { CHECK (l >= 0 && l < NUM_LEVELS); } const string& diff --git a/maths.cpp b/maths.cpp index 3c2aef59..8d91ea4b 100644 --- a/maths.cpp +++ b/maths.cpp @@ -84,7 +84,7 @@ almost_equal (const double &a, const double &b) template typename enable_if::value, T>::type round_up (T value, T align) { - check_hard (align > 1); + CHECK_HARD (align > 1); return (value + align - 1) / align; } diff --git a/maths/matrix.cpp b/maths/matrix.cpp index 709d3793..56ad1752 100644 --- a/maths/matrix.cpp +++ b/maths/matrix.cpp @@ -50,7 +50,7 @@ matrix::matrix (size_t _rows, throw std::runtime_error ("rows and columns must be positive"); if (size () != _data.size ()) throw std::runtime_error ("element and initializer size differs"); - check_hard (m_rows * m_columns == _data.size()); + CHECK_HARD (m_rows * m_columns == _data.size()); m_data = new double[size ()]; std::copy (_data.begin (), _data.end (), m_data); @@ -65,7 +65,7 @@ matrix::matrix (const std::initializer_list &rhs): double *row_cursor = m_data; for (auto i = rhs.begin (); i != rhs.end (); ++i) { - check (i->size () == m_columns); + CHECK (i->size () == m_columns); std::copy (i->data (), i->data () + i->size (), row_cursor); row_cursor += m_columns; @@ -95,22 +95,22 @@ matrix::~matrix() void matrix::sanity (void) const { - check (m_rows > 0); - check (m_columns > 0); - check (m_data != NULL); + CHECK (m_rows > 0); + CHECK (m_columns > 0); + CHECK (m_data != NULL); } const double * matrix::operator [] (unsigned int row) const { - check_hard (row < m_rows); + CHECK_HARD (row < m_rows); return m_data + row * m_columns; } double * matrix::operator [] (unsigned int row) { - check_hard (row < m_rows); + CHECK_HARD (row < m_rows); return m_data + row * m_columns; } @@ -303,8 +303,8 @@ matrix::determinant (void) const { double matrix::determinant2x2 (void) const { - check_eq (m_rows, 2); - check_eq (m_columns, 2); + CHECK_EQ (m_rows, 2); + CHECK_EQ (m_columns, 2); return (*this)[0][0] * (*this)[1][1] - (*this)[0][1] * (*this)[1][0]; @@ -320,8 +320,8 @@ matrix::determinant2x2 (void) const { // det (A) = a(ei - fg) + b(fg - di) + c(dh - eg) double matrix::determinant3x3 (void) const { - check_eq (m_rows, 3); - check_eq (m_columns, 3); + CHECK_EQ (m_rows, 3); + CHECK_EQ (m_columns, 3); return (*this)[0][0] * (*this)[1][1] * (*this)[2][2] + // aei (*this)[0][1] * (*this)[1][2] * (*this)[2][0] + // bfg @@ -335,8 +335,8 @@ matrix::determinant3x3 (void) const { // From libMathematics, http://www.geometrictools.com/ double matrix::determinant4x4 (void) const { - check_eq (m_rows, 4); - check_eq (m_columns, 4); + CHECK_EQ (m_rows, 4); + CHECK_EQ (m_columns, 4); double a0 = m_data[ 0] * m_data[ 5] - m_data[ 1] * m_data[ 4], a1 = m_data[ 0] * m_data[ 6] - m_data[ 2] * m_data[ 4], @@ -372,8 +372,8 @@ matrix::inverse (void) const { matrix matrix::inverse2x2 (void) const { - check (m_rows == 2); - check (m_columns == 2); + CHECK (m_rows == 2); + CHECK (m_columns == 2); double det = determinant2x2 (); if (almost_equal (det, 0.)) @@ -389,8 +389,8 @@ matrix::inverse2x2 (void) const { // matrix matrix::inverse3x3 (void) const { - check (m_rows == 3); - check (m_columns == 3); + CHECK (m_rows == 3); + CHECK (m_columns == 3); double det = determinant3x3(); if (almost_equal (det, 0.)) @@ -482,7 +482,7 @@ matrix::identity (size_t diag) { matrix matrix::magic (size_t n) { - check_hard (n > 2); + CHECK_HARD (n > 2); if (n % 2 == 1) return magic_odd (n); @@ -498,8 +498,8 @@ matrix::magic (size_t n) { // If filled then drop down one row instead. Wrap around indexing. matrix matrix::magic_odd (size_t n) { - check_hard (n > 2); - check_hard (n % 2 == 1); + CHECK_HARD (n > 2); + CHECK_HARD (n % 2 == 1); matrix val (zeroes (n)); for (unsigned int i = 1, x = n / 2, y = 0; i <= n * n; ++i) { diff --git a/maths/vector.cpp b/maths/vector.cpp index b9bb5164..ee266caa 100644 --- a/maths/vector.cpp +++ b/maths/vector.cpp @@ -73,7 +73,7 @@ double vector::dot (const double *restrict A, vector vector::cross (const double *restrict A, const double *restrict B, unsigned int size) { - check_hard (size == 3); + CHECK_HARD (size == 3); return vector ({ A[1] * B[2] - A[2] * B[1], A[2] * B[0] - A[0] * B[2], A[0] * B[1] - A[1] * B[0] }); diff --git a/matrix.cpp b/matrix.cpp index 05fbee2c..f8b57dc3 100644 --- a/matrix.cpp +++ b/matrix.cpp @@ -21,7 +21,7 @@ using namespace util; void matrix::scale (double x, double y, double z) { - check_hard (is_affine ()); + CHECK_HARD (is_affine ()); values[0][0] *= x; values[1][1] *= y; values[2][2] *= z; @@ -30,7 +30,7 @@ matrix::scale (double x, double y, double z) { void matrix::translate (double x, double y, double z) { - check_hard (is_affine ()); + CHECK_HARD (is_affine ()); values[0][3] += x; values[1][3] += y; values[2][3] += z; @@ -45,7 +45,7 @@ matrix::inverse (void) const { matrix& matrix::invert (void) { - check_hard (is_affine ()); + CHECK_HARD (is_affine ()); // inv ([ M b ] == [ inv(M) -inv(M).b ] // [ 0 1 ]) [ 0 1 @@ -64,7 +64,7 @@ matrix::invert (void) { double K = (values[0][0] * values[1][1] - values[0][1] * values[1][0]); double det = values[0][0] * A + values[0][1] * B + values[0][2] * C; - check_neq (det, 0.0); + CHECK_NEQ (det, 0.0); values[0][0] = A / det; values[0][1] = D / det; @@ -105,7 +105,7 @@ matrix::operator* (const matrix &rhs) const { util::point matrix::to_local (const util::point &p) const { - check_soft (is_affine ()); + CHECK_SOFT (is_affine ()); return { p.x * values[0][0] + p.y * values[0][1] + p.z * values[0][2] + values[0][3], p.x * values[1][0] + p.y * values[1][1] + p.z * values[1][2] + values[1][3], diff --git a/point.cpp b/point.cpp index 86ada6f5..d28441e7 100644 --- a/point.cpp +++ b/point.cpp @@ -89,9 +89,9 @@ point::operator- (const point &rhs) const { void point::sanity (void) const { - check_soft (!std::isnan (x)); - check_soft (!std::isnan (y)); - check_soft (!std::isnan (z)); + CHECK_SOFT (!std::isnan (x)); + CHECK_SOFT (!std::isnan (y)); + CHECK_SOFT (!std::isnan (z)); } diff --git a/pool.hpp b/pool.hpp index c43031b0..db21c438 100644 --- a/pool.hpp +++ b/pool.hpp @@ -52,13 +52,13 @@ template ~pool () { - check (m_next != NULL); + CHECK (m_next != NULL); unsigned int doomed_count = 0; for (node *cursor = m_next; cursor != NULL; cursor = cursor->_chain) ++doomed_count; - check_eq (doomed_count, m_capacity); + CHECK_EQ (doomed_count, m_capacity); operator delete (m_head); } diff --git a/range.cpp b/range.cpp index 7d57ecea..665dee91 100644 --- a/range.cpp +++ b/range.cpp @@ -57,7 +57,7 @@ range::contains (const range &r) const template void range::sanity (void) const - { check (min <= max); } + { CHECK (min <= max); } namespace util { @@ -66,7 +66,7 @@ namespace util { range::sanity (void) const { if (std::isnan (min) || std::isnan (max)) return; - check (min <= max); + CHECK (min <= max); } } diff --git a/region.cpp b/region.cpp index 9ae394b3..f03ea967 100644 --- a/region.cpp +++ b/region.cpp @@ -141,7 +141,7 @@ region::operator ==(const region& rhs) const template void region::sanity (void) const - { check (w >= 0 && h >= 0); } + { CHECK (w >= 0 && h >= 0); } namespace util { diff --git a/test/checksum.cpp b/test/checksum.cpp index dbb6315c..fd89dbcb 100644 --- a/test/checksum.cpp +++ b/test/checksum.cpp @@ -24,8 +24,8 @@ static const struct { int main (int, char**) { for (unsigned i = 0; i < elems (TESTS); ++i) { - check_eq (TESTS[i].adler, adler32 (TESTS[i].data, TESTS[i].size)); - check_eq (TESTS[i].bsd, bsdsum (TESTS[i].data, TESTS[i].size)); + CHECK_EQ (TESTS[i].adler, adler32 (TESTS[i].data, TESTS[i].size)); + CHECK_EQ (TESTS[i].bsd, bsdsum (TESTS[i].data, TESTS[i].size)); } return EXIT_SUCCESS; diff --git a/test/float.cpp b/test/float.cpp index 0a94ab3c..536a826f 100644 --- a/test/float.cpp +++ b/test/float.cpp @@ -34,7 +34,7 @@ test_double (void) { for (unsigned int i = 0; i < elems (tests); ++i) { ieee_double val; val.set_bits (tests[i].bits); - check_hard (val == tests[i].floating); + CHECK_HARD (val == tests[i].floating); } } @@ -63,7 +63,7 @@ test_single (void) { for (unsigned int i = 0; i < elems (tests); ++i) { ieee_single val; val.set_bits (tests[i].bits); - check_hard (val == tests[i].floating); + CHECK_HARD (val == tests[i].floating); } } diff --git a/test/hton.cpp b/test/hton.cpp index 34bb1476..46935167 100644 --- a/test/hton.cpp +++ b/test/hton.cpp @@ -16,11 +16,11 @@ main (int, char **) { uint16_t u16 = 0x1358; uint32_t u32 = 0x12345678; - check_eq (htons (u16), hton (u16)); - check_eq (htonl (u32), hton (u32)); + CHECK_EQ (htons (u16), hton (u16)); + CHECK_EQ (htonl (u32), hton (u32)); - check_eq (ntohs (u16), hton (u16)); - check_eq (ntohl (u32), hton (u32)); + CHECK_EQ (ntohs (u16), hton (u16)); + CHECK_EQ (ntohl (u32), hton (u32)); return EXIT_SUCCESS; } diff --git a/test/ip.cpp b/test/ip.cpp index df4390a7..38ecb498 100644 --- a/test/ip.cpp +++ b/test/ip.cpp @@ -24,12 +24,12 @@ main (int, char **) { for (unsigned int i = 0; i < elems (data); ++i) { ipv4::ip parsed (ipv4::ip::parse (data[i].str)); - check_hard (parsed == data[i].ip); + CHECK_HARD (parsed == data[i].ip); uint32_t mine = *(uint32_t*)(parsed.m_octets), theirs; - check_hard (inet_pton (AF_INET, data[i].str, &theirs) == 1); - check_hard (theirs == mine); + CHECK_HARD (inet_pton (AF_INET, data[i].str, &theirs) == 1); + CHECK_HARD (theirs == mine); } return EXIT_SUCCESS; diff --git a/test/json.cpp b/test/json.cpp index 5e62cbfd..77733619 100644 --- a/test/json.cpp +++ b/test/json.cpp @@ -24,70 +24,70 @@ main (int, char**) { "}"; std::unique_ptr ptr = json::parse (TEST_STRING); - check_hard (ptr->is_object ()); + CHECK_HARD (ptr->is_object ()); const json::node &ref = *ptr; - check_hard ( ref["string"].is_string ()); - check_hard (!ref["string"].is_array ()); - check_hard (!ref["string"].is_boolean ()); - check_hard (!ref["string"].is_null ()); - check_hard (!ref["string"].is_number ()); - check_hard (!ref["string"].is_object ()); + CHECK_HARD ( ref["string"].is_string ()); + CHECK_HARD (!ref["string"].is_array ()); + CHECK_HARD (!ref["string"].is_boolean ()); + CHECK_HARD (!ref["string"].is_null ()); + CHECK_HARD (!ref["string"].is_number ()); + CHECK_HARD (!ref["string"].is_object ()); check_eq ( ref["string"].as_string (), "brad"); - check_hard ( ref["integer"].is_number ()); - check_hard (!ref["integer"].is_array ()); - check_hard (!ref["integer"].is_boolean ()); - check_hard (!ref["integer"].is_null ()); - check_hard (!ref["integer"].is_object ()); - check_hard (!ref["integer"].is_string ()); + CHECK_HARD ( ref["integer"].is_number ()); + CHECK_HARD (!ref["integer"].is_array ()); + CHECK_HARD (!ref["integer"].is_boolean ()); + CHECK_HARD (!ref["integer"].is_null ()); + CHECK_HARD (!ref["integer"].is_object ()); + CHECK_HARD (!ref["integer"].is_string ()); check_eq ( ref["integer"].as_number (), 1u); - check_hard ( ref["null"].is_null ()); - check_hard (!ref["null"].is_array ()); - check_hard (!ref["null"].is_boolean ()); - check_hard (!ref["null"].is_number ()); - check_hard (!ref["null"].is_object ()); - check_hard (!ref["null"].is_string ()); + CHECK_HARD ( ref["null"].is_null ()); + CHECK_HARD (!ref["null"].is_array ()); + CHECK_HARD (!ref["null"].is_boolean ()); + CHECK_HARD (!ref["null"].is_number ()); + CHECK_HARD (!ref["null"].is_object ()); + CHECK_HARD (!ref["null"].is_string ()); - check_hard ( ref["false"].is_boolean ()); - check_hard (!ref["false"].is_array ()); - check_hard (!ref["false"].is_null ()); - check_hard (!ref["false"].is_number ()); - check_hard (!ref["false"].is_object ()); - check_hard (!ref["false"].is_string ()); + CHECK_HARD ( ref["false"].is_boolean ()); + CHECK_HARD (!ref["false"].is_array ()); + CHECK_HARD (!ref["false"].is_null ()); + CHECK_HARD (!ref["false"].is_number ()); + CHECK_HARD (!ref["false"].is_object ()); + CHECK_HARD (!ref["false"].is_string ()); check_eq ( ref["false"].as_boolean (), false); - check_hard ( ref["true"].is_boolean ()); - check_hard (!ref["true"].is_array ()); - check_hard (!ref["true"].is_null ()); - check_hard (!ref["true"].is_number ()); - check_hard (!ref["true"].is_object ()); - check_hard (!ref["true"].is_string ()); + CHECK_HARD ( ref["true"].is_boolean ()); + CHECK_HARD (!ref["true"].is_array ()); + CHECK_HARD (!ref["true"].is_null ()); + CHECK_HARD (!ref["true"].is_number ()); + CHECK_HARD (!ref["true"].is_object ()); + CHECK_HARD (!ref["true"].is_string ()); check_eq ( ref["true"].as_boolean (), true); - check_hard ( ref["double"].is_number ()); - check_hard (!ref["double"].is_array ()); - check_hard (!ref["double"].is_boolean ()); - check_hard (!ref["double"].is_null ()); - check_hard (!ref["double"].is_object ()); - check_hard (!ref["double"].is_string ()); + CHECK_HARD ( ref["double"].is_number ()); + CHECK_HARD (!ref["double"].is_array ()); + CHECK_HARD (!ref["double"].is_boolean ()); + CHECK_HARD (!ref["double"].is_null ()); + CHECK_HARD (!ref["double"].is_object ()); + CHECK_HARD (!ref["double"].is_string ()); check_eq ( ref["double"].as_number (), 3.14); - check_hard ( ref["object"].is_object ()); - check_hard (!ref["object"].is_array ()); - check_hard (!ref["object"].is_boolean ()); - check_hard (!ref["object"].is_null ()); - check_hard (!ref["object"].is_number ()); - check_hard (!ref["object"].is_string ()); + CHECK_HARD ( ref["object"].is_object ()); + CHECK_HARD (!ref["object"].is_array ()); + CHECK_HARD (!ref["object"].is_boolean ()); + CHECK_HARD (!ref["object"].is_null ()); + CHECK_HARD (!ref["object"].is_number ()); + CHECK_HARD (!ref["object"].is_string ()); - check_hard ( ref["array"].is_array ()); - check_hard (!ref["array"].is_boolean ()); - check_hard (!ref["array"].is_null ()); - check_hard (!ref["array"].is_number ()); - check_hard (!ref["array"].is_object ()); - check_hard (!ref["array"].is_string ()); + CHECK_HARD ( ref["array"].is_array ()); + CHECK_HARD (!ref["array"].is_boolean ()); + CHECK_HARD (!ref["array"].is_null ()); + CHECK_HARD (!ref["array"].is_number ()); + CHECK_HARD (!ref["array"].is_object ()); + CHECK_HARD (!ref["array"].is_string ()); return EXIT_SUCCESS; } diff --git a/test/maths.cpp b/test/maths.cpp index 1e9bafe8..a6f075a9 100644 --- a/test/maths.cpp +++ b/test/maths.cpp @@ -10,37 +10,37 @@ using std::numeric_limits; int main (int, char **) { - check_hard (!almost_equal (-2.0, 0.0)); - check_hard (!almost_equal (-2.f, 0.f)); - check_hard ( almost_equal ( 0.0, 0.0)); - //check_hard ( almost_equal ( 0.0, numeric_limits::min ())); - check_hard ( almost_equal (numeric_limits::infinity (), + CHECK_HARD (!almost_equal (-2.0, 0.0)); + CHECK_HARD (!almost_equal (-2.f, 0.f)); + CHECK_HARD ( almost_equal ( 0.0, 0.0)); + //CHECK_HARD ( almost_equal ( 0.0, numeric_limits::min ())); + CHECK_HARD ( almost_equal (numeric_limits::infinity (), numeric_limits::infinity ())); - check_hard (!almost_equal (numeric_limits::infinity (), 0.0)); - check_hard (!almost_equal (numeric_limits::quiet_NaN (), + CHECK_HARD (!almost_equal (numeric_limits::infinity (), 0.0)); + CHECK_HARD (!almost_equal (numeric_limits::quiet_NaN (), numeric_limits::quiet_NaN ())); - check_eq (min (-2, 0, 2), -2); - check_eq (max (-2, 0, 2), 2); + CHECK_EQ (min (-2, 0, 2), -2); + CHECK_EQ (max (-2, 0, 2), 2); - check_eq (pow2 (2), 4); - check_eq (pow2 (4), 16); + CHECK_EQ (pow2 (2), 4); + CHECK_EQ (pow2 (4), 16); - check_eq (rootsquare (2, 2), sqrt (8)); + CHECK_EQ (rootsquare (2, 2), sqrt (8)); double pos_zero = 1.0 / numeric_limits::infinity (); double neg_zero = -1.0 / numeric_limits::infinity (); - check_eq (sign (-1), -1); - check_eq (sign ( 1), 1); - check_eq (sign (pos_zero), 1); - check_eq (sign (neg_zero), -1); - check_eq (sign ( numeric_limits::infinity ()), 1); - check_eq (sign (-numeric_limits::infinity ()), -1); + CHECK_EQ (sign (-1), -1); + CHECK_EQ (sign ( 1), 1); + CHECK_EQ (sign (pos_zero), 1); + CHECK_EQ (sign (neg_zero), -1); + CHECK_EQ (sign ( numeric_limits::infinity ()), 1); + CHECK_EQ (sign (-numeric_limits::infinity ()), -1); - check_eq (to_degrees (PI), 180); - check_eq (to_radians (180), PI); + CHECK_EQ (to_degrees (PI), 180); + CHECK_EQ (to_radians (180), PI); return EXIT_SUCCESS; } diff --git a/test/matrix.cpp b/test/matrix.cpp index 56f9680d..0cfbfaee 100644 --- a/test/matrix.cpp +++ b/test/matrix.cpp @@ -33,7 +33,7 @@ test_zeroes (const matrix &m) { for (unsigned int i = 0; i < m.rows (); ++i) for (unsigned int j = 0; j < m.columns (); ++j) - check_hard (almost_equal (m[i][j], 0.0)); + CHECK_HARD (almost_equal (m[i][j], 0.0)); } @@ -44,9 +44,9 @@ test_identity (const matrix &m) { for (unsigned int i = 0; i < m.rows (); ++i) for (unsigned int j = 0; j < m.columns (); ++j) if (i == j) - check_hard (almost_equal (m[i][j], 1.0)); + CHECK_HARD (almost_equal (m[i][j], 1.0)); else - check_hard (almost_equal (m[i][j], 0.0)); + CHECK_HARD (almost_equal (m[i][j], 0.0)); } @@ -58,7 +58,7 @@ main (int, char **) { } for (unsigned int i = 3; i < 10; i += 2) - check (matrix::magic (i).is_magic ()); + CHECK (matrix::magic (i).is_magic ()); // Create a small matrix with unique element values for comparison tests. // This should be non-square so that row- vs. column-major problems can @@ -67,15 +67,15 @@ main (int, char **) { 2, 3, 4, 5, 6, 7 }); - check_eq (a4x2, a4x2); + CHECK_EQ (a4x2, a4x2); // Test that copy constructors work correctly. Keep this value around so // that we can check the following operators don't modify the original // value. - check_eq (a4x2, matrix(a4x2)); + CHECK_EQ (a4x2, matrix(a4x2)); // Check multiplication by identity results in the original value. - check_eq (a4x2, a4x2 * matrix::identity (a4x2.columns ())); + CHECK_EQ (a4x2, a4x2 * matrix::identity (a4x2.columns ())); matrix seq2x2(2, 2, { 1, 2, 3, 4 }); matrix magic3(3, 3, { 2, 7, 6, @@ -88,26 +88,26 @@ main (int, char **) { 4, 14, 15, 1 }); - check_eq (magic3[0][0], 2.0); - check_eq (magic3[0][1], 7.0); - check_eq (magic3[0][2], 6.0); - check_eq (magic3[1][0], 9.0); - check_eq (magic3[1][1], 5.0); - check_eq (magic3[1][2], 1.0); - check_eq (magic3[2][0], 4.0); - check_eq (magic3[2][1], 3.0); - check_eq (magic3[2][2], 8.0); + CHECK_EQ (magic3[0][0], 2.0); + CHECK_EQ (magic3[0][1], 7.0); + CHECK_EQ (magic3[0][2], 6.0); + CHECK_EQ (magic3[1][0], 9.0); + CHECK_EQ (magic3[1][1], 5.0); + CHECK_EQ (magic3[1][2], 1.0); + CHECK_EQ (magic3[2][0], 4.0); + CHECK_EQ (magic3[2][1], 3.0); + CHECK_EQ (magic3[2][2], 8.0); - check_eq (seq2x2.determinant (), -2.0); - check_eq (magic3.determinant (), -360.0); + CHECK_EQ (seq2x2.determinant (), -2.0); + CHECK_EQ (magic3.determinant (), -360.0); - check_hard ( seq2x2.is_square ()); - check_hard ( magic3.is_square ()); - check_hard (! a4x2.is_square ()); + CHECK_HARD ( seq2x2.is_square ()); + CHECK_HARD ( magic3.is_square ()); + CHECK_HARD (! a4x2.is_square ()); - check_eq (seq2x2.inverse (), matrix (2, 2, { -2.0, 1.0, + CHECK_EQ (seq2x2.inverse (), matrix (2, 2, { -2.0, 1.0, 1.5, -0.5 })); - check_eq (magic3.inverse (), matrix (3, 3, { -37.0, 38.0, 23.0, + CHECK_EQ (magic3.inverse (), matrix (3, 3, { -37.0, 38.0, 23.0, 68.0, 8.0, -52.0, - 7.0, -22.0, 53.0 }) /= 360.0); @@ -115,7 +115,7 @@ main (int, char **) { 9, 7, 6, 12, 5, 11, 10, 8, 0, 0, 0, 1 }); - check_eq (invertible4.inverse (), matrix (4, 4, { 4, 25, -21, -136, + CHECK_EQ (invertible4.inverse (), matrix (4, 4, { 4, 25, -21, -136, -60, -35, 111, -408, 64, 26, -98, 408, 0, 0, 0, 136 }) /= 136); @@ -123,10 +123,10 @@ main (int, char **) { const matrix homo3x3 (3, 3, { 1, 2, 0, 3, 4, 0, 0, 0, 1 }); - check_hard (homo3x3.is_homogeneous ()); - check_hard (!matrix::zeroes (3).is_homogeneous ()); - check_hard ( matrix::identity (3).is_homogeneous ()); - check_hard (invertible4.is_homogeneous ()); + CHECK_HARD (homo3x3.is_homogeneous ()); + CHECK_HARD (!matrix::zeroes (3).is_homogeneous ()); + CHECK_HARD ( matrix::identity (3).is_homogeneous ()); + CHECK_HARD (invertible4.is_homogeneous ()); return EXIT_SUCCESS; } diff --git a/test/pool.cpp b/test/pool.cpp index e6d3e7f7..40e6584a 100644 --- a/test/pool.cpp +++ b/test/pool.cpp @@ -25,7 +25,7 @@ check_unique_ptr (void) { // Take all pointers out, checking they are unique, then replace for destruction. for (unsigned int i = 0; i < uintpool.capacity (); ++i) { bool success = uintset.insert (uintpool.acquire ()).second; - check_hard (success); + CHECK_HARD (success); } for (auto i = uintset.begin (); i != uintset.end (); ++i) @@ -35,7 +35,7 @@ check_unique_ptr (void) { // Do the above one more time to ensure that releasing works right for (unsigned int i = 0; i < uintpool.capacity (); ++i) { bool success = uintset.insert (uintpool.acquire ()).second; - check_hard (success); + CHECK_HARD (success); } for (auto i = uintset.begin (); i != uintset.end (); ++i) @@ -57,19 +57,19 @@ check_keep_value (void) { uintvector.push_back(item); } - check (uintvector.size () == uintpool.capacity ()); + CHECK (uintvector.size () == uintpool.capacity ()); // Ensure they're all still present vector present(uintpool.capacity (), false); for (auto i = uintvector.begin (); i != uintvector.end (); ++i) { - check_hard (**i < uintpool.capacity ()); - check_hard (present[**i] != true); + CHECK_HARD (**i < uintpool.capacity ()); + CHECK_HARD (present[**i] != true); present[**i] = true; } // All must have been marked as present... - check_hard (find (present.begin (), present.end (), false) == present.end ()); + CHECK_HARD (find (present.begin (), present.end (), false) == present.end ()); // Release all back into the pool for destruction for (auto i = uintvector.begin (); i != uintvector.end (); ++i) diff --git a/test/range.cpp b/test/range.cpp index 00cef73b..bfa764f3 100644 --- a/test/range.cpp +++ b/test/range.cpp @@ -9,24 +9,24 @@ using namespace util; int main (int, char **) { - check_hard ( range::UNIT.contains ( 0.0)); - check_hard ( range::UNIT.contains ( 0.5)); - check_hard ( range::UNIT.contains ( 1.0)); - check_hard (!range::UNIT.contains (-0.00001)); - check_hard (!range::UNIT.contains ( 1.00001)); + CHECK_HARD ( range::UNIT.contains ( 0.0)); + CHECK_HARD ( range::UNIT.contains ( 0.5)); + CHECK_HARD ( range::UNIT.contains ( 1.0)); + CHECK_HARD (!range::UNIT.contains (-0.00001)); + CHECK_HARD (!range::UNIT.contains ( 1.00001)); - check_hard ( range::UNIT.contains (0)); - check_hard ( range::UNIT.contains (1)); - check_hard (!range::UNIT.contains (2)); - check_hard (!range::UNIT.contains (numeric_limits ::max ())); + CHECK_HARD ( range::UNIT.contains (0)); + CHECK_HARD ( range::UNIT.contains (1)); + CHECK_HARD (!range::UNIT.contains (2)); + CHECK_HARD (!range::UNIT.contains (numeric_limits ::max ())); - check_hard ( range::UNLIMITED.contains (0.0)); - check_hard ( range::UNLIMITED.contains (+numeric_limits::infinity ())); - check_hard ( range::UNLIMITED.contains (-numeric_limits::infinity ())); - check_hard (!range::UNLIMITED.contains ( numeric_limits::quiet_NaN ())); + CHECK_HARD ( range::UNLIMITED.contains (0.0)); + CHECK_HARD ( range::UNLIMITED.contains (+numeric_limits::infinity ())); + CHECK_HARD ( range::UNLIMITED.contains (-numeric_limits::infinity ())); + CHECK_HARD (!range::UNLIMITED.contains ( numeric_limits::quiet_NaN ())); - check_hard ( range::UNLIMITED.contains (numeric_limits::min())); - check_hard ( range::UNLIMITED.contains (numeric_limits::max())); + CHECK_HARD ( range::UNLIMITED.contains (numeric_limits::min())); + CHECK_HARD ( range::UNLIMITED.contains (numeric_limits::max())); return EXIT_SUCCESS; } diff --git a/test/region.cpp b/test/region.cpp index 408a6e07..25d0e861 100644 --- a/test/region.cpp +++ b/test/region.cpp @@ -8,7 +8,7 @@ main (int, char **) { region a (32.7, -6.09703, 0.8, 2); region b (33.5, -4.5, 0.5, 0.5); - check_hard (!a.overlaps (b)); + CHECK_HARD (!a.overlaps (b)); } return 0; diff --git a/test/signal.cpp b/test/signal.cpp index 1244e10c..cabc8512 100644 --- a/test/signal.cpp +++ b/test/signal.cpp @@ -23,7 +23,7 @@ test_single (void) { void_signal.connect (increment_uint); void_signal (val); - check_eq (val, 1); + CHECK_EQ (val, 1); } @@ -36,7 +36,7 @@ test_double (void) { void_signal.connect (increment_uint); void_signal (val); - check_eq (val, 2); + CHECK_EQ (val, 2); } diff --git a/test/version.cpp b/test/version.cpp index 4987f2e9..bd6dd3ac 100644 --- a/test/version.cpp +++ b/test/version.cpp @@ -38,12 +38,12 @@ main (int, char **) { for (auto i = tests.begin (); i != tests.end (); ++i) { version v (i->str); - if (i->parts.size () > 0) check (v.major () == i->parts[0]); - if (i->parts.size () > 1) check (v.minor () == i->parts[1]); - if (i->parts.size () > 2) check (v.point () == i->parts[2]); - if (i->parts.size () > 3) check (v.build () == i->parts[3]); + if (i->parts.size () > 0) CHECK (v.major () == i->parts[0]); + if (i->parts.size () > 1) CHECK (v.minor () == i->parts[1]); + if (i->parts.size () > 2) CHECK (v.point () == i->parts[2]); + if (i->parts.size () > 3) CHECK (v.build () == i->parts[3]); - check_hard (i->parts.size () <= 4); + CHECK_HARD (i->parts.size () <= 4); } return EXIT_SUCCESS; diff --git a/time.cpp b/time.cpp index 83e7e7a8..190cd68e 100644 --- a/time.cpp +++ b/time.cpp @@ -55,8 +55,8 @@ util::nanoseconds (void) { struct timespec t; clock_gettime (CLOCK_REALTIME, &t); - check_soft (t.tv_sec > 0); - check_soft (t.tv_nsec > 0); + CHECK_SOFT (t.tv_sec > 0); + CHECK_SOFT (t.tv_nsec > 0); return static_cast (t.tv_sec) * 1000000000ULL + static_cast (t.tv_nsec); } diff --git a/types.hpp b/types.hpp index 9fbe9ceb..4089a32d 100644 --- a/types.hpp +++ b/types.hpp @@ -86,7 +86,7 @@ namespace detail { std::is_unsigned::value && std::is_signed::value, V>::type v) { - check_hard (v >= 0); + CHECK_HARD (v >= 0); return static_cast (v); } @@ -97,7 +97,7 @@ namespace detail { std::is_signed::value && std::is_unsigned::value, V>::type v) { - check_hard (v < std::numeric_limits::max () / 2); + CHECK_HARD (v < std::numeric_limits::max () / 2); return static_cast (v); } } @@ -124,7 +124,7 @@ namespace detail { T _trunc_cast (const typename enable_if::value == std::is_signed::value, V>::type v) { - check_hard (v <= std::numeric_limits::max ()); + CHECK_HARD (v <= std::numeric_limits::max ()); checK_hard (v >= std::numeric_limits::min ()); return static_cast (v); diff --git a/vector.cpp b/vector.cpp index d79e273c..014b8f8f 100644 --- a/vector.cpp +++ b/vector.cpp @@ -194,9 +194,9 @@ vector::is_zero (void) const { void vector::sanity (void) const { - check_soft (!std::isnan (x)); - check_soft (!std::isnan (y)); - check_soft (!std::isnan (z)); + CHECK_SOFT (!std::isnan (x)); + CHECK_SOFT (!std::isnan (y)); + CHECK_SOFT (!std::isnan (z)); } diff --git a/version.cpp.rl b/version.cpp.rl index ee8fbafd..9819a1af 100644 --- a/version.cpp.rl +++ b/version.cpp.rl @@ -72,7 +72,7 @@ check_release (version::release_t r) { void version::sanity (void) const { check_release (m_release); - check (!m_values.empty ()); + CHECK (!m_values.empty ()); }