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.
This commit is contained in:
parent
c185ea7226
commit
52f53caee5
@ -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);
|
||||
}
|
||||
|
||||
|
27
debug.hpp
27
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 { \
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ ieee_float<E, S>::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<TOTAL_BITS>::has_floating);
|
||||
CHECK (bits_type<TOTAL_BITS>::has_floating);
|
||||
|
||||
union {
|
||||
floating_t _floating;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 ());
|
||||
|
10
io.cpp
10
io.cpp
@ -73,7 +73,7 @@ util::slurp (const boost::filesystem::path& path) {
|
||||
unique_ptr <char []> 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 <typename T>
|
||||
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<const char*> (data);
|
||||
|
38
json.cpp.rl
38
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<json::node> (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;
|
||||
|
@ -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) {
|
||||
|
@ -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],
|
||||
|
@ -206,7 +206,7 @@ matrix<T>::inverse_affine (void) const {
|
||||
template <typename T>
|
||||
matrix<T>&
|
||||
matrix<T>::invert_affine (void) {
|
||||
CHECK_HARD (is_affine ());
|
||||
CHECK (is_affine ());
|
||||
|
||||
// inv ([ M b ] == [ inv(M) -inv(M).b ]
|
||||
// [ 0 1 ]) [ 0 1 ]
|
||||
|
@ -43,7 +43,7 @@ socket_domain<D>::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<D, type::STREAM>::socket (const socket_type &rhs):
|
||||
template <domain D>
|
||||
void
|
||||
net::socket<D, type::STREAM>::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<const void *>(data + sent), len - sent, 0);
|
||||
@ -183,8 +183,8 @@ net::socket<D, type::STREAM>::send (const uint8_t *restrict data, size_t len) {
|
||||
template <domain D>
|
||||
size_t
|
||||
net::socket<D, type::STREAM>::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<D, type::DGRAM>::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<D, type::DGRAM>::send_addr (const address_type &addr,
|
||||
if (sent < 0)
|
||||
net::error::throw_code ();
|
||||
|
||||
CHECK_HARD (sign_cast<size_t>(sent) == len);
|
||||
CHECK_EQ (sign_cast<size_t>(sent), len);
|
||||
}
|
||||
|
||||
|
||||
@ -280,14 +280,14 @@ template <domain D>
|
||||
typename net::socket<D, type::DGRAM>::address_type
|
||||
net::socket<D, type::DGRAM>::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 ();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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];
|
||||
}
|
||||
|
@ -148,9 +148,9 @@ util::point<S,T>::operator== (const util::point<S,T> &rhs) const
|
||||
template <size_t S, typename T>
|
||||
void
|
||||
util::point<S,T>::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); }));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -25,24 +25,24 @@ main (int, char**) {
|
||||
"}";
|
||||
|
||||
std::unique_ptr<json::node> 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;
|
||||
}
|
||||
|
@ -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<double>::min ()));
|
||||
CHECK_HARD ( almost_equal (numeric_limits<double>::infinity (),
|
||||
numeric_limits<double>::infinity ()));
|
||||
CHECK_HARD (!almost_equal (numeric_limits<double>::infinity (), 0.0));
|
||||
CHECK_HARD (!almost_equal (numeric_limits<double>::quiet_NaN (),
|
||||
numeric_limits<double>::quiet_NaN ()));
|
||||
CHECK ( almost_equal (numeric_limits<double>::infinity (),
|
||||
numeric_limits<double>::infinity ()));
|
||||
CHECK (!almost_equal (numeric_limits<double>::infinity (), 0.0));
|
||||
CHECK (!almost_equal (numeric_limits<double>::quiet_NaN (),
|
||||
numeric_limits<double>::quiet_NaN ()));
|
||||
|
||||
|
||||
CHECK_EQ (min (-2, 0, 2), -2);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<bool> 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)
|
||||
|
@ -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<double>::UNIT.contains ( 0.0));
|
||||
CHECK_HARD ( range<double>::UNIT.contains ( 0.5));
|
||||
CHECK_HARD ( range<double>::UNIT.contains ( 1.0));
|
||||
CHECK_HARD ( range<double>::UNIT.contains (std::numeric_limits<double>::min ()));
|
||||
CHECK_HARD (!range<double>::UNIT.contains (-0.00001));
|
||||
CHECK_HARD (!range<double>::UNIT.contains ( 1.00001));
|
||||
CHECK ( range<double>::UNIT.contains ( 0.0));
|
||||
CHECK ( range<double>::UNIT.contains ( 0.5));
|
||||
CHECK ( range<double>::UNIT.contains ( 1.0));
|
||||
CHECK ( range<double>::UNIT.contains (std::numeric_limits<double>::min ()));
|
||||
CHECK (!range<double>::UNIT.contains (-0.00001));
|
||||
CHECK (!range<double>::UNIT.contains ( 1.00001));
|
||||
|
||||
// Check edge cases of unit with integer values
|
||||
CHECK_HARD ( range<uint16_t>::UNIT.contains (0));
|
||||
CHECK_HARD ( range<uint16_t>::UNIT.contains (1));
|
||||
CHECK_HARD (!range<uint16_t>::UNIT.contains (2));
|
||||
CHECK_HARD (!range<uint16_t>::UNIT.contains (numeric_limits <uint16_t>::max ()));
|
||||
CHECK ( range<uint16_t>::UNIT.contains (0));
|
||||
CHECK ( range<uint16_t>::UNIT.contains (1));
|
||||
CHECK (!range<uint16_t>::UNIT.contains (2));
|
||||
CHECK (!range<uint16_t>::UNIT.contains (numeric_limits <uint16_t>::max ()));
|
||||
|
||||
// Check the inclusivity of UNLIMITED with special floating values
|
||||
CHECK_HARD ( range<double>::UNLIMITED.contains (0.0));
|
||||
CHECK_HARD ( range<double>::UNLIMITED.contains (+numeric_limits<double>::infinity ()));
|
||||
CHECK_HARD ( range<double>::UNLIMITED.contains (-numeric_limits<double>::infinity ()));
|
||||
CHECK_HARD (!range<double>::UNLIMITED.contains ( numeric_limits<double>::quiet_NaN ()));
|
||||
CHECK ( range<double>::UNLIMITED.contains (0.0));
|
||||
CHECK ( range<double>::UNLIMITED.contains (+numeric_limits<double>::infinity ()));
|
||||
CHECK ( range<double>::UNLIMITED.contains (-numeric_limits<double>::infinity ()));
|
||||
CHECK (!range<double>::UNLIMITED.contains ( numeric_limits<double>::quiet_NaN ()));
|
||||
|
||||
// Check the inclusivity of UNLIMITED with some large numbers
|
||||
CHECK_HARD ( range<uint16_t>::UNLIMITED.contains (numeric_limits<uint16_t>::min()));
|
||||
CHECK_HARD ( range<uint16_t>::UNLIMITED.contains (numeric_limits<uint16_t>::max()));
|
||||
CHECK ( range<uint16_t>::UNLIMITED.contains (numeric_limits<uint16_t>::min()));
|
||||
CHECK ( range<uint16_t>::UNLIMITED.contains (numeric_limits<uint16_t>::max()));
|
||||
|
||||
// Check inclusivity of MAX
|
||||
CHECK_HARD (!range<double>::MAX.contains ( numeric_limits<double>::infinity ()));
|
||||
CHECK_HARD (!range<double>::MAX.contains (-numeric_limits<double>::infinity ()));
|
||||
CHECK (!range<double>::MAX.contains ( numeric_limits<double>::infinity ()));
|
||||
CHECK (!range<double>::MAX.contains (-numeric_limits<double>::infinity ()));
|
||||
|
||||
CHECK_HARD ( range<uint16_t>::MAX.contains (numeric_limits<uint16_t>::min()));
|
||||
CHECK_HARD ( range<uint16_t>::MAX.contains (numeric_limits<uint16_t>::max()));
|
||||
CHECK ( range<uint16_t>::MAX.contains (numeric_limits<uint16_t>::min()));
|
||||
CHECK ( range<uint16_t>::MAX.contains (numeric_limits<uint16_t>::max()));
|
||||
|
||||
// Check that expansion via NaN is a noop
|
||||
{
|
||||
|
@ -12,25 +12,25 @@ main (int, char **) {
|
||||
region<double> a (32.7, -6.09703, 0.8, 2);
|
||||
region<double> b (33.5, -4.5, 0.5, 0.5);
|
||||
|
||||
CHECK_HARD (!a.intersects (b));
|
||||
CHECK (!a.intersects (b));
|
||||
}
|
||||
|
||||
CHECK_HARD (region<double>::MAX.intersects (region<double>::UNIT));
|
||||
CHECK_HARD (region< float>::MAX.intersects (region< float>::UNIT));
|
||||
CHECK (region<double>::MAX.intersects (region<double>::UNIT));
|
||||
CHECK (region< float>::MAX.intersects (region< float>::UNIT));
|
||||
|
||||
CHECK_EQ (region<double>::UNIT.area (), 1.0);
|
||||
CHECK_EQ (region< float>::UNIT.area (), 1.0f);
|
||||
|
||||
CHECK_HARD (region<int> (0, 0, 2, 2).includes (point<2,int>(1, 1)));
|
||||
CHECK_HARD (region<int> (0, 0, 2, 2).includes (point<2,int>(0, 0)));
|
||||
CHECK_HARD (region<int> (0, 0, 2, 2).includes (point<2,int>(2, 2)));
|
||||
CHECK (region<int> (0, 0, 2, 2).includes (point<2,int>(1, 1)));
|
||||
CHECK (region<int> (0, 0, 2, 2).includes (point<2,int>(0, 0)));
|
||||
CHECK (region<int> (0, 0, 2, 2).includes (point<2,int>(2, 2)));
|
||||
|
||||
CHECK_HARD ( region<int> (0, 0, 2, 2).contains (point<2,int>(1, 1)));
|
||||
CHECK_HARD (!region<int> (0, 0, 2, 2).contains (point<2,int>(0, 0)));
|
||||
CHECK_HARD (!region<int> (0, 0, 2, 2).contains (point<2,int>(2, 2)));
|
||||
CHECK ( region<int> (0, 0, 2, 2).contains (point<2,int>(1, 1)));
|
||||
CHECK (!region<int> (0, 0, 2, 2).contains (point<2,int>(0, 0)));
|
||||
CHECK (!region<int> (0, 0, 2, 2).contains (point<2,int>(2, 2)));
|
||||
|
||||
//CHECK_HARD (region<intmax_t> (0, 0, 10, 10).includes (point2d (0.4, 0.01)));
|
||||
//CHECK_HARD (region<intmax_t> (0, 0, 10, 10).contains (point2d (0.4, 0.01)));
|
||||
//CHECK (region<intmax_t> (0, 0, 10, 10).includes (point2d (0.4, 0.01)));
|
||||
//CHECK (region<intmax_t> (0, 0, 10, 10).contains (point2d (0.4, 0.01)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
4
time.cpp
4
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<uint64_t> (t.tv_sec) * SECOND + static_cast<uint64_t> (t.tv_nsec);
|
||||
}
|
||||
|
@ -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<string, array_validator_t> VALIDATORS ({
|
||||
|
@ -34,7 +34,7 @@ namespace detail {
|
||||
std::is_unsigned<T>::value &&
|
||||
std::is_signed<V>::value, V>::type v)
|
||||
{
|
||||
CHECK_HARD (v >= 0);
|
||||
CHECK_GE (v, 0);
|
||||
return static_cast<T> (v);
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ namespace detail {
|
||||
std::is_signed<T>::value &&
|
||||
std::is_unsigned<V>::value, V>::type v)
|
||||
{
|
||||
CHECK_HARD (v < std::numeric_limits<V>::max () / 2);
|
||||
CHECK_LT (v, std::numeric_limits<V>::max () / 2);
|
||||
return static_cast<T> (v);
|
||||
}
|
||||
|
||||
@ -80,8 +80,8 @@ namespace detail {
|
||||
_trunc_cast (const typename std::enable_if<sizeof (T) < sizeof (V) &&
|
||||
std::is_signed<T>::value == std::is_signed<V>::value &&
|
||||
std::is_integral<T>::value, V>::type v) {
|
||||
CHECK_HARD (v <= std::numeric_limits<T>::max ());
|
||||
CHECK_HARD (v >= std::numeric_limits<T>::lowest ());
|
||||
CHECK_LE (v, std::numeric_limits<T>::max ());
|
||||
CHECK_GE (v, std::numeric_limits<T>::lowest ());
|
||||
|
||||
return static_cast<T> (v);
|
||||
}
|
||||
@ -92,9 +92,9 @@ namespace detail {
|
||||
_trunc_cast (const typename std::enable_if<sizeof (T) < sizeof (V) &&
|
||||
std::is_signed<T>::value == std::is_signed<V>::value &&
|
||||
std::is_floating_point<T>::value, V>::type v) {
|
||||
CHECK_HARD (v <= std::numeric_limits<T>::max ());
|
||||
CHECK_HARD (v >= std::numeric_limits<T>::lowest ());
|
||||
CHECK_HARD (exactly_equal (remainder (v, 1), 0.0));
|
||||
CHECK_LE (v, std::numeric_limits<T>::max ());
|
||||
CHECK_GE (v, std::numeric_limits<T>::lowest ());
|
||||
CHECK_EQ (remainder (v, 1), 0.0);
|
||||
|
||||
return static_cast<T> (v);
|
||||
}
|
||||
@ -111,8 +111,8 @@ trunc_cast (V v)
|
||||
template <typename T, typename V>
|
||||
T
|
||||
size_cast (const V v) {
|
||||
CHECK_HARD (std::numeric_limits<T>::lowest () <= v);
|
||||
CHECK_HARD (std::numeric_limits<T>::max () >= v);
|
||||
CHECK_LE (std::numeric_limits<T>::lowest (), v);
|
||||
CHECK_GE (std::numeric_limits<T>::max (), v);
|
||||
|
||||
return static_cast<T> (v);
|
||||
}
|
||||
@ -122,7 +122,7 @@ size_cast (const V v) {
|
||||
template <typename T, typename V>
|
||||
T*
|
||||
known_cast (V *v) {
|
||||
CHECK_HARD (nullptr != dynamic_cast<T*> (v));
|
||||
CHECK (dynamic_cast<T*> (v));
|
||||
return static_cast<T*> (v);
|
||||
}
|
||||
|
||||
|
@ -346,9 +346,9 @@ util::vector<S,T>::ZERO (T{0});
|
||||
template <size_t S, typename T>
|
||||
void
|
||||
util::vector<S,T>::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); }));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user