44 #define NDEBUG_PRECONDITIONS 45 #define NDEBUG_POSTCONDITIONS 46 #define NDEBUG_INVARIANTS 49 #ifdef DEBUG_ONLY_PRECONDITIONS 50 #ifdef NDEBUG_PRECONDITIONS 51 #undef NDEBUG_PRECONDITIONS 56 #ifndef NDEBUG_POSTCONDITIONS 57 #define NDEBUG_POSTCONDITIONS 59 #ifndef NDEBUG_INVARIANTS 60 #define NDEBUG_INVARIANTS 66 #define check(condition, message) 68 #ifdef EXCEPTION_POLICY 69 #define check(condition, message) \ 71 throw string_concat(NULL, 0, (char*)"Assertion fail", message[0] ? (char*)": " : (char*)"", message, (char*)", assertion: \"", #condition, (char*)"\", function: \"", __FUNCTION__, (char*)"\":", int2str(__LINE__), (char*)", file: \"", __FILE__, (char*)"\"\n", NULL) 72 #else // EXIT_POLICY (default) 81 #define check(condition, message) \ 84 fprintf (stderr, "Assertion fail%s%s, assertion: \"%s\", function: \"%s\":%d, file: \"%s\"\n", \ 85 message[0] ? ": " : "", message, #condition, __FUNCTION__, __LINE__ , __FILE__); \ 94 #ifdef NDEBUG_PRECONDITIONS 95 #define require(condition, message) 97 #ifdef EXCEPTION_POLICY 98 #define require(condition, message) \ 100 throw string_concat(NULL, 0, (char*)"Precondition fail", message[0] ? (char*)": " : (char*)"", message, (char*)", assertion: \"", #condition, (char*)"\", function: \"", __FUNCTION__, (char*)"\":", int2str(__LINE__), (char*)", file: \"", __FILE__, (char*)"\"\n", NULL) 101 #else // EXIT_POLICY (default) 110 #define require(condition, message) \ 113 fprintf (stderr, "Precondition fail%s%s, assertion: \"%s\", function: \"%s\":%d, file: \"%s\"\n", \ 114 message[0] ? ": " : "", message, #condition, __FUNCTION__, __LINE__ , __FILE__); \ 123 #ifdef NDEBUG_POSTCONDITIONS 124 #define ensure(condition, message) 126 #ifdef EXCEPTION_POLICY 127 #define ensure(condition, message) \ 129 throw string_concat(NULL, 0, (char*)"Postcondition fail", message[0] ? (char*)": " : (char*)"", message, (char*)", assertion: \"", #condition, (char*)"\", function: \"", __FUNCTION__, (char*)"\":", int2str(__LINE__), (char*)", file: \"", __FILE__, (char*)"\"\n", NULL) 130 #else // EXIT_POLICY (default) 139 #define ensure(condition, message) \ 142 fprintf (stderr, "Postcondition fail%s%s, assertion: \"%s\", function: \"%s\":%d, file: \"%s\"\n", \ 143 message[0] ? ": " : "", message, #condition, __FUNCTION__, __LINE__ , __FILE__); \ 152 #ifdef NDEBUG_INVARIANTS 153 #define invariant(condition, message) 155 #ifdef EXCEPTION_POLICY 156 #define invariant(condition, message) \ 158 throw string_concat(NULL, 0, (char*)"Invariant fail", message[0] ? (char*)": " : (char*)"", message, (char*)", assertion: \"", #condition, (char*)"\", function: \"", __FUNCTION__, (char*)"\":", int2str(__LINE__), (char*)", file: \"", __FILE__, (char*)"\"\n", NULL) 159 #else // EXIT_POLICY (default) 168 #define invariant(condition, message) \ 171 fprintf (stderr, "Invariant fail%s%s, assertion: \"%s\", function: \"%s\":%d, file: \"%s\"\n", \ 172 message[0] ? ": " : "", message, #condition, __FUNCTION__, __LINE__ , __FILE__); \ Useful common functions and macros.