aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/shared/util.h
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2012-12-18 11:41:06 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-20 21:38:38 +0100
commit5fd1c5fbaf13195fed16ca171f4eac81be125e2b (patch)
treeec6a445f2f0367f7a5298274950750ad56e23c68 /tests/auto/shared/util.h
parent920b949e5185258baabfb3f738b660b3c0f002e3 (diff)
Quick tests: Introduce QQmlMessageHandler.
Add QQmlMessageHandler class that can be used to record messages into a QStringList. It also makes sure that the old message handler is reinstalled if the test fails. Task-number: QTBUG-28611 Change-Id: I0fff7bc11e188cf47178d9573e5f2eead693bc10 Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Diffstat (limited to 'tests/auto/shared/util.h')
-rw-r--r--tests/auto/shared/util.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/shared/util.h b/tests/auto/shared/util.h
index 4a5c9176c6..eff54b30d9 100644
--- a/tests/auto/shared/util.h
+++ b/tests/auto/shared/util.h
@@ -45,6 +45,7 @@
#include <QtCore/QDir>
#include <QtCore/QUrl>
#include <QtCore/QCoreApplication>
+#include <QtCore/QStringList>
#include <QtTest/QTest>
QT_FORWARD_DECLARE_CLASS(QQmlComponent)
@@ -87,4 +88,24 @@ private:
QString m_directory;
};
+class QQmlTestMessageHandler
+{
+ Q_DISABLE_COPY(QQmlTestMessageHandler)
+public:
+ QQmlTestMessageHandler();
+ ~QQmlTestMessageHandler();
+
+ const QStringList &messages() const { return m_messages; }
+ const QString messageString() const { return m_messages.join(QLatin1Char('\n')); }
+
+ void clear() { m_messages.clear(); }
+
+private:
+ static void messageHandler(QtMsgType, const QMessageLogContext &, const QString &message);
+
+ static QQmlTestMessageHandler *m_instance;
+ QStringList m_messages;
+ QtMessageHandler m_oldHandler;
+};
+
#endif // QQMLTESTUTILS_H