diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Globals.h | 62 |
1 files changed, 25 insertions, 37 deletions
diff --git a/src/Globals.h b/src/Globals.h index e37f6dc60..890394e2e 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -296,61 +296,49 @@ template class SizeChecker<UInt8, 1>; /** Faster than (int)floorf((float)x / (float)div) */ #define FAST_FLOOR_DIV(x, div) (((x) - (((x) < 0) ? ((div) - 1) : 0)) / (div)) -// Own version of assert() that writes failed assertions to the log for review +// Own version of ASSERT() that plays nicely with the testing framework #ifdef TEST_GLOBALS class cAssertFailure { - }; - - #ifdef _WIN32 - #if (defined(_MSC_VER) && defined(_DEBUG)) - #define DBG_BREAK _CrtDbgBreak() - #else - #define DBG_BREAK - #endif - #define REPORT_ERROR(FMT, ...) \ - { \ - AString msg = Printf(FMT, __VA_ARGS__); \ - puts(msg.c_str()); \ - fflush(stdout); \ - OutputDebugStringA(msg.c_str()); \ - DBG_BREAK; \ + AString mExpression; + AString mFileName; + int mLineNumber; + + public: + cAssertFailure(const AString & aExpression, const AString & aFileName, int aLineNumber): + mExpression(aExpression), + mFileName(aFileName), + mLineNumber(aLineNumber) + { } - #else - #define REPORT_ERROR(FMT, ...) \ - { \ - AString msg = Printf(FMT, __VA_ARGS__); \ - puts(msg.c_str()); \ - fflush(stdout); \ - } - #endif + + const AString & expression() const { return mExpression; } + const AString & fileName() const { return mFileName; } + int lineNumber() const { return mLineNumber; } + }; #ifdef _DEBUG - #define ASSERT(x) do { if (!(x)) { throw cAssertFailure();} } while (0) - #define testassert(x) do { if (!(x)) { REPORT_ERROR("Test failure: %s, file %s, line %d\n", #x, __FILE__, __LINE__); exit(1); } } while (0) - #define CheckAsserts(x) do { try {x} catch (cAssertFailure) { break; } REPORT_ERROR("Test failure: assert didn't fire for %s, file %s, line %d\n", #x, __FILE__, __LINE__); exit(1); } while (0) + #define ASSERT(x) do { if (!(x)) { throw cAssertFailure(#x, __FILE__, __LINE__);} } while (0) #else #define ASSERT(...) - #define testassert(...) - #define CheckAsserts(...) LOG("Assert checking is disabled in Release-mode executables (file %s, line %d)", __FILE__, __LINE__) #endif -#else + // Pretty much the same as ASSERT() but stays in Release builds + #define VERIFY(x) (!!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__), exit(1), 0)) + +#else // TEST_GLOBALS + #ifdef _DEBUG #define ASSERT(x) ( !!(x) || ( LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__), PrintStackTrace(), assert(0), 0)) #else #define ASSERT(x) #endif -#endif -// Pretty much the same as ASSERT() but stays in Release builds -#define VERIFY( x) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__), PrintStackTrace(), exit(1), 0)) + // Pretty much the same as ASSERT() but stays in Release builds + #define VERIFY(x) (!!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__), PrintStackTrace(), exit(1), 0)) -// Same as assert but in all Self test builds -#ifdef SELF_TEST - #define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0)) -#endif +#endif // else TEST_GLOBALS /** Use to mark code that should be impossible to reach. */ #define UNREACHABLE(x) do { FLOGERROR("Hit unreachable code: {0}, file {1}, line {2}", #x, __FILE__, __LINE__); PrintStackTrace(); std::terminate(); } while (false) |