qtcassert.h 996 B

1234567891011121314151617181920212223
  1. // Copyright (C) 2016 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
  3. #pragma once
  4. #include "utils_global.h"
  5. namespace Utils {
  6. QTCREATOR_UTILS_EXPORT void writeAssertLocation(const char *msg);
  7. QTCREATOR_UTILS_EXPORT void dumpBacktrace(int maxdepth);
  8. } // Utils
  9. #define QTC_ASSERT_STRINGIFY_HELPER(x) #x
  10. #define QTC_ASSERT_STRINGIFY(x) QTC_ASSERT_STRINGIFY_HELPER(x)
  11. #define QTC_ASSERT_STRING(cond) ::Utils::writeAssertLocation(\
  12. "\"" cond"\" in " __FILE__ ":" QTC_ASSERT_STRINGIFY(__LINE__))
  13. // The 'do {...} while (0)' idiom is not used for the main block here to be
  14. // able to use 'break' and 'continue' as 'actions'.
  15. #define QTC_ASSERT(cond, action) if (Q_LIKELY(cond)) {} else { QTC_ASSERT_STRING(#cond); action; } do {} while (0)
  16. #define QTC_CHECK(cond) if (Q_LIKELY(cond)) {} else { QTC_ASSERT_STRING(#cond); } do {} while (0)
  17. #define QTC_GUARD(cond) ((Q_LIKELY(cond)) ? true : (QTC_ASSERT_STRING(#cond), false))