From 52f53caee5dec114756c54811ee1d4684371bf87 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 28 Jan 2015 14:49:34 +1100 Subject: [PATCH] debug: drop support for CHECK_HARD HARD vs SOFT assertions were never very well defined or supported. Currently they just imply a level of functionality that isn't present; it's better to remove them instead of expending the effort at this point. --- backtrace_execinfo.cpp | 2 +- debug.hpp | 27 +----------- except.cpp | 6 +-- float.cpp | 2 +- hash/ripemd.cpp | 2 +- image.cpp | 8 ++-- io.cpp | 10 ++--- json.cpp.rl | 38 ++++++++-------- maths/matrix.cpp | 12 +++--- maths/vector.cpp | 2 +- matrix.cpp | 2 +- net/socket.cpp | 22 +++++----- net/types.cpp | 4 +- noise/basis.cpp | 4 +- point.cpp | 6 +-- test/float.cpp | 4 +- test/ip.cpp | 2 +- test/json/types.cpp | 98 +++++++++++++++++++++--------------------- test/maths/maths.cpp | 16 +++---- test/maths/matrix.cpp | 20 ++++----- test/pool.cpp | 12 +++--- test/range.cpp | 40 ++++++++--------- test/region.cpp | 22 +++++----- test/ripemd.cpp | 4 +- test/version.cpp | 2 +- time.cpp | 4 +- tools/json-schema.cpp | 2 +- types/casts.hpp | 20 ++++----- vector.cpp | 6 +-- version.cpp.rl | 2 +- 30 files changed, 189 insertions(+), 212 deletions(-) diff --git a/backtrace_execinfo.cpp b/backtrace_execinfo.cpp index 59ad6d58..56b8b784 100644 --- a/backtrace_execinfo.cpp +++ b/backtrace_execinfo.cpp @@ -42,7 +42,7 @@ debug::backtrace::backtrace (void): while ((last = ::backtrace (&m_frames[0], m_frames.size ())) == size) m_frames.resize (size = m_frames.size () * 2); - CHECK_HARD (last > 0); + CHECK_GT (last, 0); m_frames.resize (last); } diff --git a/debug.hpp b/debug.hpp index e62afd9b..c78a9ad5 100644 --- a/debug.hpp +++ b/debug.hpp @@ -54,21 +54,6 @@ } while (0) -/////////////////////////////////////////////////////////////////////////////// -#define VERIFY_SOFT(C, COND) ({ \ - const auto __DEBUG_value = (C); \ - CHECK_SOFT(__DEBUG_value COND); \ - __DEBUG_value; \ -}) - - -#define VERIFY_HARD(C, COND) ({ \ - const auto __DEBUG_value = (C); \ - CHECK_HARD(__DEBUG_value COND); \ - __DEBUG_value; \ -}) - - /////////////////////////////////////////////////////////////////////////////// #define _CHECK_META(C, SUCCESS, FAILURE) do { \ const auto __DEBUG_value = (C); \ @@ -87,16 +72,8 @@ } while (0) -#if defined(ENABLE_DEBUGGING) - #define CHECK_HARD(C) _CHECK_META((C), { ; }, { panic (); }) - #define CHECK_SOFT(C) _CHECK_META((C), { ; }, { breakpoint (); }) - #define CHECK(C) CHECK_HARD(C) -#else - #define CHECK_HARD(C) { }; - #define CHECK_SOFT(C) { }; - #define CHECK(C) CHECK_SOFT(C) -#endif - +/////////////////////////////////////////////////////////////////////////////// +#define CHECK(C) do { DEBUG_ONLY(_CHECK_META((C), { ; }, { panic (); });); } while (0) /////////////////////////////////////////////////////////////////////////////// #define CHECK_EQ(A,B) do { \ diff --git a/except.cpp b/except.cpp index dd6a0d60..fce5fb32 100644 --- a/except.cpp +++ b/except.cpp @@ -34,7 +34,7 @@ errno_error::errno_error (int _errno): runtime_error (strerror (_errno)), id (_errno) { - CHECK_HARD (_errno != 0); + CHECK_NEQ (_errno, 0); } @@ -44,7 +44,7 @@ errno_error::errno_error (): runtime_error (strerror (errno)), id (errno) { - CHECK_HARD (errno != 0); + CHECK_NEQ (errno, 0); } @@ -69,7 +69,7 @@ errno_error::throw_code (void) void errno_error::throw_code (int code) { - CHECK_HARD (code != 0); + CHECK_NEQ (code, 0); throw errno_error (code); } diff --git a/float.cpp b/float.cpp index 88a699d0..e96c758c 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 (bits_type::has_floating); union { floating_t _floating; diff --git a/hash/ripemd.cpp b/hash/ripemd.cpp index a95d5799..0bdea9e3 100644 --- a/hash/ripemd.cpp +++ b/hash/ripemd.cpp @@ -43,7 +43,7 @@ RIPEMD::reset (void) { /////////////////////////////////////////////////////////////////////////////// void RIPEMD::update (const uint8_t *data, size_t len) { - CHECK_HARD (data); + CHECK (data); size_t cursor = 0; diff --git a/image.cpp b/image.cpp index 214806d8..8cb2994c 100644 --- a/image.cpp +++ b/image.cpp @@ -34,10 +34,10 @@ write_netpbm (const uint8_t *restrict pixels, size_t stride, const boost::filesystem::path &path, const char* MAGIC) { - CHECK_HARD (pixels); - CHECK_HARD (width > 0); - CHECK_HARD (stride >= width); - CHECK_HARD (height > 0); + CHECK (pixels); + CHECK_GT (width, 0); + CHECK_GE (stride, width); + CHECK_GT (height, 0); // Establish an output stream std::ofstream output (path.string ()); diff --git a/io.cpp b/io.cpp index 4b3ec022..6f9d7542 100644 --- a/io.cpp +++ b/io.cpp @@ -73,7 +73,7 @@ util::slurp (const boost::filesystem::path& path) { unique_ptr buffer (new char[size + 1]); buffer.get()[size] = '\0'; - CHECK_HARD (size >= 0); + CHECK_GE (size, 0); size_t remaining = (size_t)size; char *cursor = buffer.get(); @@ -81,8 +81,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_GT ( consumed, 0); + CHECK_LE ((size_t)consumed, remaining); remaining -= (size_t)consumed; cursor += consumed; @@ -95,8 +95,8 @@ util::slurp (const boost::filesystem::path& path) { template void util::write (const boost::filesystem::path &path, const T *data, size_t len) { - CHECK_SOFT (len > 0); - CHECK_HARD (data); + CHECK_GT (len, 0); + CHECK (data); fd_ref fd (path, ACCESS_WRITE); const char *cursor = reinterpret_cast (data); diff --git a/json.cpp.rl b/json.cpp.rl index 028f0c5f..56d9d84d 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 (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 (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 (!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 (!nodestack.empty ()); + CHECK (!nodestack.back ().value); throw parse_error ("unable to parse boolean"); } action new_number { - CHECK_HARD (!nodestack.empty ()); + CHECK (!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.start); + CHECK (back.stop); + CHECK_LE (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 (!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 (!nodestack.empty ()); + CHECK (nodestack.back ().root->is_object ()); + CHECK (nodestack.back ().value); + CHECK (!nodestack.back ().key); nodestack.back ().key = nodestack.back ().value; nodestack.back ().value = NULL; diff --git a/maths/matrix.cpp b/maths/matrix.cpp index 7af9e8b8..249fd2c9 100644 --- a/maths/matrix.cpp +++ b/maths/matrix.cpp @@ -44,7 +44,7 @@ matrix::matrix (size_t _rows, { if (size () != _data.size ()) throw std::runtime_error ("element and initializer size differs"); - CHECK_HARD (m_rows * m_columns == _data.size()); + CHECK_EQ (m_rows * m_columns, _data.size()); m_data.reset (new double[size ()]); std::copy (_data.begin (), _data.end (), m_data.get ()); @@ -98,14 +98,14 @@ matrix::sanity (void) const { const double * matrix::operator [] (unsigned int row) const { - CHECK_HARD (row < m_rows); + CHECK_LT (row, m_rows); return m_data.get () + row * m_columns; } double * matrix::operator [] (unsigned int row) { - CHECK_HARD (row < m_rows); + CHECK_LT (row, m_rows); return m_data.get () + row * m_columns; } @@ -483,7 +483,7 @@ matrix::identity (size_t diag) { matrix matrix::magic (size_t n) { - CHECK_HARD (n > 2); + CHECK_GT (n, 2); if (n % 2 == 1) return magic_odd (n); @@ -499,8 +499,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_GT (n, 2); + CHECK_EQ (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 a36a9717..cbd60130 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_EQ (size, 3); (void)size; return vector ({ A[1] * B[2] - A[2] * B[1], A[2] * B[0] - A[0] * B[2], diff --git a/matrix.cpp b/matrix.cpp index 1f453edc..dc1d5ec0 100644 --- a/matrix.cpp +++ b/matrix.cpp @@ -206,7 +206,7 @@ matrix::inverse_affine (void) const { template matrix& matrix::invert_affine (void) { - CHECK_HARD (is_affine ()); + CHECK (is_affine ()); // inv ([ M b ] == [ inv(M) -inv(M).b ] // [ 0 1 ]) [ 0 1 ] diff --git a/net/socket.cpp b/net/socket.cpp index 7e4cb076..3871127d 100644 --- a/net/socket.cpp +++ b/net/socket.cpp @@ -43,7 +43,7 @@ socket_domain::socket_domain (socket_t _fd): { #ifdef __WIN32 #else - CHECK_HARD (m_fd >= 0); + CHECK_GE (m_fd, 0); #endif } @@ -166,8 +166,8 @@ net::socket::socket (const socket_type &rhs): template void net::socket::send (const uint8_t *restrict data, size_t len) { - CHECK_HARD (data != NULL); - CHECK (len > 0); + CHECK (data != NULL); + CHECK_GT (len, 0); for (size_t sent = 0; sent < len; ) { ssize_t result = ::send (this->m_fd, static_cast(data + sent), len - sent, 0); @@ -183,8 +183,8 @@ net::socket::send (const uint8_t *restrict data, size_t len) { template size_t net::socket::recv (uint8_t *restrict data, size_t len) { - CHECK_HARD (data != NULL); - CHECK (len > 0); + CHECK (data != NULL); + CHECK_GT (len, 0); ssize_t received = ::recv (this->m_fd, data, len, 0); if (received < 0) @@ -263,8 +263,8 @@ void net::socket::send_addr (const address_type &addr, const uint8_t *restrict data, size_t len) { - CHECK_HARD (data != NULL); - CHECK (len > 0); + CHECK (data != NULL); + CHECK_GT (len, 0); typename address_type::sockaddr_type addr_in = addr.to_sockaddr (); @@ -272,7 +272,7 @@ net::socket::send_addr (const address_type &addr, if (sent < 0) net::error::throw_code (); - CHECK_HARD (sign_cast(sent) == len); + CHECK_EQ (sign_cast(sent), len); } @@ -280,14 +280,14 @@ template typename net::socket::address_type net::socket::recv_addr (uint8_t *restrict data, size_t len) { - CHECK_HARD (data != NULL); - CHECK (len > 0); + CHECK (data != NULL); + CHECK_GT (len, 0); typename address_type::sockaddr_type addr_in; socklen_t addr_len = sizeof (addr_in); ssize_t recvd = recvfrom (this->m_fd, data, len, 0, (sockaddr *)&addr_in, &addr_len); - CHECK_HARD (sizeof (addr_in) == addr_len); + CHECK_EQ (sizeof (addr_in), addr_len); if (recvd < 0) net::error::throw_code (); diff --git a/net/types.cpp b/net/types.cpp index 50199e28..0c6c986e 100644 --- a/net/types.cpp +++ b/net/types.cpp @@ -39,7 +39,7 @@ protocol net::string_to_protocol (const char *_name) { struct protoent *entry = getprotobyname (_name); // TODO: Throw an exception... - CHECK_HARD (entry); + CHECK (entry); return (protocol)entry->p_proto; } @@ -47,7 +47,7 @@ net::string_to_protocol (const char *_name) { std::string net::protocol_to_string (protocol _protocol) { struct protoent *entry = getprotobynumber ((int)_protocol); - CHECK_HARD (entry); + CHECK (entry); return entry->p_name; } diff --git a/noise/basis.cpp b/noise/basis.cpp index 05d5b007..d565dc1e 100644 --- a/noise/basis.cpp +++ b/noise/basis.cpp @@ -247,7 +247,7 @@ cellular::eval (double x, double y) const { } std::sort (std::begin (distances), std::end (distances)); - CHECK_SOFT (distances[0] >= 0); - CHECK_SOFT (bounds ().contains (distances[0])); + CHECK_GE (distances[0], 0); + CHECK (bounds ().contains (distances[0])); return distances[0]; } diff --git a/point.cpp b/point.cpp index f510a5ce..03f6a722 100644 --- a/point.cpp +++ b/point.cpp @@ -148,9 +148,9 @@ util::point::operator== (const util::point &rhs) const template void util::point::sanity (void) const { - CHECK_SOFT (std::all_of (begin (this->data), - end (this->data), - [] (double i) { return !std::isnan (i); })); + CHECK (std::all_of (begin (this->data), + end (this->data), + [] (double i) { return !std::isnan (i); })); } diff --git a/test/float.cpp b/test/float.cpp index 536a826f..f3d0c9aa 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 (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 (val == tests[i].floating); } } diff --git a/test/ip.cpp b/test/ip.cpp index 90cc9300..a85786cb 100644 --- a/test/ip.cpp +++ b/test/ip.cpp @@ -23,7 +23,7 @@ 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 (parsed == data[i].ip); } return EXIT_SUCCESS; diff --git a/test/json/types.cpp b/test/json/types.cpp index e02716aa..a6e6bcff 100644 --- a/test/json/types.cpp +++ b/test/json/types.cpp @@ -25,24 +25,24 @@ main (int, char**) { "}"; std::unique_ptr ptr = json::parse (TEST_STRING); - CHECK_HARD (ptr->is_object ()); + CHECK (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 ( ref["string"].is_string ()); + CHECK (!ref["string"].is_array ()); + CHECK (!ref["string"].is_boolean ()); + CHECK (!ref["string"].is_null ()); + CHECK (!ref["string"].is_number ()); + CHECK (!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 ( ref["integer"].is_number ()); + CHECK (!ref["integer"].is_array ()); + CHECK (!ref["integer"].is_boolean ()); + CHECK (!ref["integer"].is_null ()); + CHECK (!ref["integer"].is_object ()); + CHECK (!ref["integer"].is_string ()); CHECK ( exactly_equal ( (unsigned)ref["integer"].as_number ().native (), @@ -50,35 +50,35 @@ main (int, char**) { ) ); - 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 ( ref["null"].is_null ()); + CHECK (!ref["null"].is_array ()); + CHECK (!ref["null"].is_boolean ()); + CHECK (!ref["null"].is_number ()); + CHECK (!ref["null"].is_object ()); + CHECK (!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 ( ref["false"].is_boolean ()); + CHECK (!ref["false"].is_array ()); + CHECK (!ref["false"].is_null ()); + CHECK (!ref["false"].is_number ()); + CHECK (!ref["false"].is_object ()); + CHECK (!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 ( ref["true"].is_boolean ()); + CHECK (!ref["true"].is_array ()); + CHECK (!ref["true"].is_null ()); + CHECK (!ref["true"].is_number ()); + CHECK (!ref["true"].is_object ()); + CHECK (!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 ( ref["double"].is_number ()); + CHECK (!ref["double"].is_array ()); + CHECK (!ref["double"].is_boolean ()); + CHECK (!ref["double"].is_null ()); + CHECK (!ref["double"].is_object ()); + CHECK (!ref["double"].is_string ()); CHECK ( exactly_equal ( ref["double"].as_number ().native (), @@ -86,19 +86,19 @@ main (int, char**) { ) ); - 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 ( ref["object"].is_object ()); + CHECK (!ref["object"].is_array ()); + CHECK (!ref["object"].is_boolean ()); + CHECK (!ref["object"].is_null ()); + CHECK (!ref["object"].is_number ()); + CHECK (!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 ( ref["array"].is_array ()); + CHECK (!ref["array"].is_boolean ()); + CHECK (!ref["array"].is_null ()); + CHECK (!ref["array"].is_number ()); + CHECK (!ref["array"].is_object ()); + CHECK (!ref["array"].is_string ()); return EXIT_SUCCESS; } diff --git a/test/maths/maths.cpp b/test/maths/maths.cpp index eddf45e0..3df7a8b4 100644 --- a/test/maths/maths.cpp +++ b/test/maths/maths.cpp @@ -13,15 +13,15 @@ main (int, char **) { std::cerr.precision (15); std::cout.precision (15); - 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 (!almost_equal (-2.0, 0.0)); + CHECK (!almost_equal (-2.f, 0.f)); + CHECK ( 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 (), - numeric_limits::quiet_NaN ())); + CHECK ( almost_equal (numeric_limits::infinity (), + numeric_limits::infinity ())); + CHECK (!almost_equal (numeric_limits::infinity (), 0.0)); + CHECK (!almost_equal (numeric_limits::quiet_NaN (), + numeric_limits::quiet_NaN ())); CHECK_EQ (min (-2, 0, 2), -2); diff --git a/test/maths/matrix.cpp b/test/maths/matrix.cpp index 36a3d5ce..2c684bc4 100644 --- a/test/maths/matrix.cpp +++ b/test/maths/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 (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 (almost_equal (m[i][j], 1.0)); } else { - CHECK_HARD (almost_equal (m[i][j], 0.0)); + CHECK (almost_equal (m[i][j], 0.0)); } } @@ -102,9 +102,9 @@ main (int, char **) { 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 ( seq2x2.is_square ()); + CHECK ( magic3.is_square ()); + CHECK (! a4x2.is_square ()); CHECK_EQ (seq2x2.inverse (), matrix (2, 2, { -2.0, 1.0, 1.5, -0.5 })); @@ -124,10 +124,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 (homo3x3.is_homogeneous ()); + CHECK (!matrix::zeroes (3).is_homogeneous ()); + CHECK ( matrix::identity (3).is_homogeneous ()); + CHECK (invertible4.is_homogeneous ()); return EXIT_SUCCESS; } diff --git a/test/pool.cpp b/test/pool.cpp index 40e6584a..f9628536 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 (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 (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_EQ (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 (**i < uintpool.capacity ()); + CHECK (present[**i] != true); present[**i] = true; } // All must have been marked as present... - CHECK_HARD (find (present.begin (), present.end (), false) == present.end ()); + CHECK (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 275ec61e..643747e7 100644 --- a/test/range.cpp +++ b/test/range.cpp @@ -10,35 +10,35 @@ using namespace util; int main (int, char **) { // Check some simple cases close to the edges of a unit range. Tests float rounding. - 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 (std::numeric_limits::min ())); - CHECK_HARD (!range::UNIT.contains (-0.00001)); - CHECK_HARD (!range::UNIT.contains ( 1.00001)); + CHECK ( range::UNIT.contains ( 0.0)); + CHECK ( range::UNIT.contains ( 0.5)); + CHECK ( range::UNIT.contains ( 1.0)); + CHECK ( range::UNIT.contains (std::numeric_limits::min ())); + CHECK (!range::UNIT.contains (-0.00001)); + CHECK (!range::UNIT.contains ( 1.00001)); // Check edge cases of unit with integer values - 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 ( range::UNIT.contains (0)); + CHECK ( range::UNIT.contains (1)); + CHECK (!range::UNIT.contains (2)); + CHECK (!range::UNIT.contains (numeric_limits ::max ())); // Check the inclusivity of UNLIMITED with special floating values - 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 ( range::UNLIMITED.contains (0.0)); + CHECK ( range::UNLIMITED.contains (+numeric_limits::infinity ())); + CHECK ( range::UNLIMITED.contains (-numeric_limits::infinity ())); + CHECK (!range::UNLIMITED.contains ( numeric_limits::quiet_NaN ())); // Check the inclusivity of UNLIMITED with some large numbers - CHECK_HARD ( range::UNLIMITED.contains (numeric_limits::min())); - CHECK_HARD ( range::UNLIMITED.contains (numeric_limits::max())); + CHECK ( range::UNLIMITED.contains (numeric_limits::min())); + CHECK ( range::UNLIMITED.contains (numeric_limits::max())); // Check inclusivity of MAX - CHECK_HARD (!range::MAX.contains ( numeric_limits::infinity ())); - CHECK_HARD (!range::MAX.contains (-numeric_limits::infinity ())); + CHECK (!range::MAX.contains ( numeric_limits::infinity ())); + CHECK (!range::MAX.contains (-numeric_limits::infinity ())); - CHECK_HARD ( range::MAX.contains (numeric_limits::min())); - CHECK_HARD ( range::MAX.contains (numeric_limits::max())); + CHECK ( range::MAX.contains (numeric_limits::min())); + CHECK ( range::MAX.contains (numeric_limits::max())); // Check that expansion via NaN is a noop { diff --git a/test/region.cpp b/test/region.cpp index a20398d2..aefe5b30 100644 --- a/test/region.cpp +++ b/test/region.cpp @@ -12,25 +12,25 @@ 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.intersects (b)); + CHECK (!a.intersects (b)); } - CHECK_HARD (region::MAX.intersects (region::UNIT)); - CHECK_HARD (region< float>::MAX.intersects (region< float>::UNIT)); + CHECK (region::MAX.intersects (region::UNIT)); + CHECK (region< float>::MAX.intersects (region< float>::UNIT)); CHECK_EQ (region::UNIT.area (), 1.0); CHECK_EQ (region< float>::UNIT.area (), 1.0f); - CHECK_HARD (region (0, 0, 2, 2).includes (point<2,int>(1, 1))); - CHECK_HARD (region (0, 0, 2, 2).includes (point<2,int>(0, 0))); - CHECK_HARD (region (0, 0, 2, 2).includes (point<2,int>(2, 2))); + CHECK (region (0, 0, 2, 2).includes (point<2,int>(1, 1))); + CHECK (region (0, 0, 2, 2).includes (point<2,int>(0, 0))); + CHECK (region (0, 0, 2, 2).includes (point<2,int>(2, 2))); - CHECK_HARD ( region (0, 0, 2, 2).contains (point<2,int>(1, 1))); - CHECK_HARD (!region (0, 0, 2, 2).contains (point<2,int>(0, 0))); - CHECK_HARD (!region (0, 0, 2, 2).contains (point<2,int>(2, 2))); + CHECK ( region (0, 0, 2, 2).contains (point<2,int>(1, 1))); + CHECK (!region (0, 0, 2, 2).contains (point<2,int>(0, 0))); + CHECK (!region (0, 0, 2, 2).contains (point<2,int>(2, 2))); - //CHECK_HARD (region (0, 0, 10, 10).includes (point2d (0.4, 0.01))); - //CHECK_HARD (region (0, 0, 10, 10).contains (point2d (0.4, 0.01))); + //CHECK (region (0, 0, 10, 10).includes (point2d (0.4, 0.01))); + //CHECK (region (0, 0, 10, 10).contains (point2d (0.4, 0.01))); return 0; } diff --git a/test/ripemd.cpp b/test/ripemd.cpp index ecc69ee8..3fcd03d2 100644 --- a/test/ripemd.cpp +++ b/test/ripemd.cpp @@ -111,7 +111,7 @@ main(int, char**) { strlen (TESTS[i].input)); obj.finish (); - CHECK_HARD (obj.digest () == TESTS[i].output); + CHECK (obj.digest () == TESTS[i].output); } // Perform 'million-a' check @@ -130,7 +130,7 @@ main(int, char**) { 0x52, 0x78, 0x32, 0x43, 0xc1, 0x69, 0x7b, 0xdb, 0xe1, 0x6d, 0x37, 0xf9, 0x7f, 0x68, 0xf0, 0x83, 0x25, 0xdc, 0x15, 0x28 }; - CHECK_HARD (obj.digest () == MILLION); + CHECK (obj.digest () == MILLION); return EXIT_SUCCESS; } diff --git a/test/version.cpp b/test/version.cpp index df36c02c..eb2b4b38 100644 --- a/test/version.cpp +++ b/test/version.cpp @@ -44,7 +44,7 @@ main (int, char **) { 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_LE (i->parts.size (), 4); } return EXIT_SUCCESS; diff --git a/time.cpp b/time.cpp index 68539b7c..9b329c49 100644 --- a/time.cpp +++ b/time.cpp @@ -58,8 +58,8 @@ util::nanoseconds (void) { struct timespec t; clock_gettime (CLOCK_MONOTONIC, &t); - CHECK_SOFT (t.tv_sec > 0); - CHECK_SOFT (t.tv_nsec > 0); + CHECK_GT (t.tv_sec, 0); + CHECK_GT (t.tv_nsec, 0); return static_cast (t.tv_sec) * SECOND + static_cast (t.tv_nsec); } diff --git a/tools/json-schema.cpp b/tools/json-schema.cpp index d2408969..4980b988 100644 --- a/tools/json-schema.cpp +++ b/tools/json-schema.cpp @@ -382,7 +382,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 (node.is_array ()); typedef bool (*array_validator_t)(const json::array&, const json::node&); static const map VALIDATORS ({ diff --git a/types/casts.hpp b/types/casts.hpp index 24cef474..0b904622 100644 --- a/types/casts.hpp +++ b/types/casts.hpp @@ -34,7 +34,7 @@ namespace detail { std::is_unsigned::value && std::is_signed::value, V>::type v) { - CHECK_HARD (v >= 0); + CHECK_GE (v, 0); return static_cast (v); } @@ -45,7 +45,7 @@ namespace detail { std::is_signed::value && std::is_unsigned::value, V>::type v) { - CHECK_HARD (v < std::numeric_limits::max () / 2); + CHECK_LT (v, std::numeric_limits::max () / 2); return static_cast (v); } @@ -80,8 +80,8 @@ namespace detail { _trunc_cast (const typename std::enable_if::value == std::is_signed::value && std::is_integral::value, V>::type v) { - CHECK_HARD (v <= std::numeric_limits::max ()); - CHECK_HARD (v >= std::numeric_limits::lowest ()); + CHECK_LE (v, std::numeric_limits::max ()); + CHECK_GE (v, std::numeric_limits::lowest ()); return static_cast (v); } @@ -92,9 +92,9 @@ namespace detail { _trunc_cast (const typename std::enable_if::value == std::is_signed::value && std::is_floating_point::value, V>::type v) { - CHECK_HARD (v <= std::numeric_limits::max ()); - CHECK_HARD (v >= std::numeric_limits::lowest ()); - CHECK_HARD (exactly_equal (remainder (v, 1), 0.0)); + CHECK_LE (v, std::numeric_limits::max ()); + CHECK_GE (v, std::numeric_limits::lowest ()); + CHECK_EQ (remainder (v, 1), 0.0); return static_cast (v); } @@ -111,8 +111,8 @@ trunc_cast (V v) template T size_cast (const V v) { - CHECK_HARD (std::numeric_limits::lowest () <= v); - CHECK_HARD (std::numeric_limits::max () >= v); + CHECK_LE (std::numeric_limits::lowest (), v); + CHECK_GE (std::numeric_limits::max (), v); return static_cast (v); } @@ -122,7 +122,7 @@ size_cast (const V v) { template T* known_cast (V *v) { - CHECK_HARD (nullptr != dynamic_cast (v)); + CHECK (dynamic_cast (v)); return static_cast (v); } diff --git a/vector.cpp b/vector.cpp index 7398aea6..b85dcba6 100644 --- a/vector.cpp +++ b/vector.cpp @@ -346,9 +346,9 @@ util::vector::ZERO (T{0}); template void util::vector::sanity (void) const { - CHECK_SOFT (std::all_of (begin (this->data), - end (this->data), - [] (T i) { return !std::isnan (i); })); + CHECK (std::all_of (begin (this->data), + end (this->data), + [] (T i) { return !std::isnan (i); })); } diff --git a/version.cpp.rl b/version.cpp.rl index 5edd23a1..b70f2cf7 100644 --- a/version.cpp.rl +++ b/version.cpp.rl @@ -180,7 +180,7 @@ version::operator== (const version &rhs) const { std::ostream& operator <<(std::ostream& os, const util::version& rhs) { size_t elements = rhs.size; - CHECK_HARD (elements > 0); + CHECK_GT (elements, 0); os << rhs.major (); if (!--elements)