summaryrefslogtreecommitdiff
path: root/src/libs/utils/qtcassert.h
diff options
context:
space:
mode:
authorhjk <qtc-committer@nokia.com>2012-04-17 08:01:25 +0200
committerhjk <qthjk@ovi.com>2012-04-17 09:53:44 +0200
commit5b0bf616401624e28ba1c0e94e474c2da2e6350a (patch)
tree661e3e7490e2f8b718c77f03f37bccb806ed7b18 /src/libs/utils/qtcassert.h
parent37e38530905b31607d07bea1ca65618d95c8f380 (diff)
downloadqt-creator-5b0bf616401624e28ba1c0e94e474c2da2e6350a.tar.gz
qtcassert: move actual printing to separate function and enforce style
This also allows simple setting of breakpoints on failed asserts. Change-Id: I6dd84cbfaf659d57e39f3447386cebc0221b2b84 Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
Diffstat (limited to 'src/libs/utils/qtcassert.h')
-rw-r--r--src/libs/utils/qtcassert.h19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/libs/utils/qtcassert.h b/src/libs/utils/qtcassert.h
index 11a0df20b3..d533cac0e1 100644
--- a/src/libs/utils/qtcassert.h
+++ b/src/libs/utils/qtcassert.h
@@ -33,19 +33,20 @@
#ifndef QTC_ASSERT_H
#define QTC_ASSERT_H
-#include <QDebug>
+#include "utils_global.h"
-#define QTC_ASSERT_STRINGIFY_INTERNAL(x) #x
-#define QTC_ASSERT_STRINGIFY(x) QTC_ASSERT_STRINGIFY_INTERNAL(x)
+namespace Utils { QTCREATOR_UTILS_EXPORT void writeAssertLocation(const char *msg); }
-// we do not use the 'do {...} while (0)' idiom here to be able to use
-// 'break' and 'continue' as 'actions'.
+#define QTC_ASSERT_STRINGIFY_HELPER(x) #x
+#define QTC_ASSERT_STRINGIFY(x) QTC_ASSERT_STRINGIFY_HELPER(x)
+#define QTC_ASSERT_STRING(cond) ::Utils::writeAssertLocation(\
+ "\"" cond"\" in file " __FILE__ ", line " QTC_ASSERT_STRINGIFY(__LINE__))
-#define QTC_ASSERT(cond, action) \
- if(cond){}else{qDebug()<<"SOFT ASSERT: \""#cond"\" in file " __FILE__ ", line " QTC_ASSERT_STRINGIFY(__LINE__);action;}
+// The 'do {...} while (0)' idiom is not used for the main block here to be
+// able to use 'break' and 'continue' as 'actions'.
-#define QTC_CHECK(cond) \
- if(cond){}else{qDebug()<<"SOFT ASSERT: \""#cond"\" in file " __FILE__ ", line " QTC_ASSERT_STRINGIFY(__LINE__);}
+#define QTC_ASSERT(cond, action) if (cond) {} else { QTC_ASSERT_STRING(#cond); action; } do {} while (0)
+#define QTC_CHECK(cond) if (cond) {} else { QTC_ASSERT_STRING(#cond); } do {} while (0)
#endif // QTC_ASSERT_H