diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2012-12-18 11:41:06 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-20 21:38:38 +0100 |
commit | 5fd1c5fbaf13195fed16ca171f4eac81be125e2b (patch) | |
tree | ec6a445f2f0367f7a5298274950750ad56e23c68 /tests/auto/qml/qqmlengine | |
parent | 920b949e5185258baabfb3f738b660b3c0f002e3 (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/qml/qqmlengine')
-rw-r--r-- | tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index 128294bbcb..2a78831ba1 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -417,12 +417,6 @@ void tst_qqmlengine::failedCompilation_data() QTest::newRow("Invalid content") << "failedCompilation.1.qml"; } -static QStringList warnings; -static void msgHandler(QtMsgType, const QMessageLogContext &, const QString &warning) -{ - warnings << warning; -} - void tst_qqmlengine::outputWarningsToStandardError() { QQmlEngine engine; @@ -434,35 +428,26 @@ void tst_qqmlengine::outputWarningsToStandardError() QVERIFY(c.isReady() == true); - warnings.clear(); - QtMessageHandler old = qInstallMessageHandler(msgHandler); + QQmlTestMessageHandler messageHandler; QObject *o = c.create(); - qInstallMessageHandler(old); - QVERIFY(o != 0); delete o; - QCOMPARE(warnings.count(), 1); - QCOMPARE(warnings.at(0), QLatin1String("<Unknown File>: Unable to assign [undefined] to int")); - warnings.clear(); - + QCOMPARE(messageHandler.messages().count(), 1); + QCOMPARE(messageHandler.messages().at(0), QLatin1String("<Unknown File>: Unable to assign [undefined] to int")); + messageHandler.clear(); engine.setOutputWarningsToStandardError(false); QCOMPARE(engine.outputWarningsToStandardError(), false); - - old = qInstallMessageHandler(msgHandler); - o = c.create(); - qInstallMessageHandler(old); - QVERIFY(o != 0); delete o; - QCOMPARE(warnings.count(), 0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); } void tst_qqmlengine::objectOwnership() |