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 | |
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')
-rw-r--r-- | tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp | 26 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 70 | ||||
-rw-r--r-- | tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 25 | ||||
-rw-r--r-- | tests/auto/qml/qqmlinstruction/qqmlinstruction.pro | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmlinstruction/tst_qqmlinstruction.cpp | 18 | ||||
-rw-r--r-- | tests/auto/qml/qqmlpropertymap/qqmlpropertymap.pro | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp | 17 | ||||
-rw-r--r-- | tests/auto/qml/v4/tst_v4.cpp | 40 |
8 files changed, 54 insertions, 146 deletions
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index d3aba444af..748d4d71e8 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -226,20 +226,13 @@ void tst_qqmlcomponent::qmlCreateObjectWithProperties() delete testBindingThisObj; } -static QStringList warnings; -static void msgHandler(QtMsgType, const QMessageLogContext &, const QString &warning) -{ - warnings << warning; -} - void tst_qqmlcomponent::qmlCreateParentReference() { QQmlEngine engine; QCOMPARE(engine.outputWarningsToStandardError(), true); - warnings.clear(); - QtMessageHandler old = qInstallMessageHandler(msgHandler); + QQmlTestMessageHandler messageHandler; QQmlComponent component(&engine, testFileUrl("createParentReference.qml")); QVERIFY2(component.errorString().isEmpty(), component.errorString().toUtf8()); @@ -249,12 +242,10 @@ void tst_qqmlcomponent::qmlCreateParentReference() QVERIFY(QMetaObject::invokeMethod(object, "createChild")); delete object; - qInstallMessageHandler(old); - engine.setOutputWarningsToStandardError(false); QCOMPARE(engine.outputWarningsToStandardError(), false); - QCOMPARE(warnings.count(), 0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); } void tst_qqmlcomponent::async() @@ -398,13 +389,14 @@ void tst_qqmlcomponent::onDestructionCount() // Warning should not be emitted any further QCOMPARE(engine.outputWarningsToStandardError(), true); - warnings.clear(); - QtMessageHandler old = qInstallMessageHandler(msgHandler); - - QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QCoreApplication::processEvents(); + QStringList warnings; + { + QQmlTestMessageHandler messageHandler; - qInstallMessageHandler(old); + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QCoreApplication::processEvents(); + warnings = messageHandler.messages(); + } engine.setOutputWarningsToStandardError(false); QCOMPARE(engine.outputWarningsToStandardError(), false); diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index bca76a7bc9..9ecb3b6e1d 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -1923,27 +1923,18 @@ void tst_qqmlecmascript::compileInvalidBinding() delete object; } -static int transientErrorsMsgCount = 0; -static void transientErrorsMsgHandler(QtMsgType, const QMessageLogContext &, const QString &) -{ - ++transientErrorsMsgCount; -} - // Check that transient binding errors are not displayed void tst_qqmlecmascript::transientErrors() { { QQmlComponent component(&engine, testFileUrl("transientErrors.qml")); - transientErrorsMsgCount = 0; - QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); + QQmlTestMessageHandler messageHandler; QObject *object = component.create(); QVERIFY(object != 0); - qInstallMessageHandler(old); - - QCOMPARE(transientErrorsMsgCount, 0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); delete object; } @@ -1952,15 +1943,12 @@ void tst_qqmlecmascript::transientErrors() { QQmlComponent component(&engine, testFileUrl("transientErrors.2.qml")); - transientErrorsMsgCount = 0; - QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); + QQmlTestMessageHandler messageHandler; QObject *object = component.create(); QVERIFY(object != 0); - qInstallMessageHandler(old); - - QCOMPARE(transientErrorsMsgCount, 0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); delete object; } @@ -1973,13 +1961,11 @@ void tst_qqmlecmascript::shutdownErrors() QObject *object = component.create(); QVERIFY(object != 0); - transientErrorsMsgCount = 0; - QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); + QQmlTestMessageHandler messageHandler; delete object; - qInstallMessageHandler(old); - QCOMPARE(transientErrorsMsgCount, 0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); } void tst_qqmlecmascript::compositePropertyType() @@ -5794,14 +5780,11 @@ void tst_qqmlecmascript::qtbug_9792() delete context; - transientErrorsMsgCount = 0; - QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); + QQmlTestMessageHandler messageHandler; object->basicSignal(); - - qInstallMessageHandler(old); - QCOMPARE(transientErrorsMsgCount, 0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); delete object; } @@ -5835,14 +5818,11 @@ void tst_qqmlecmascript::noSpuriousWarningsAtShutdown() QObject *o = component.create(); - transientErrorsMsgCount = 0; - QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); + QQmlTestMessageHandler messageHandler; delete o; - qInstallMessageHandler(old); - - QCOMPARE(transientErrorsMsgCount, 0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); } @@ -5851,14 +5831,11 @@ void tst_qqmlecmascript::noSpuriousWarningsAtShutdown() QObject *o = component.create(); - transientErrorsMsgCount = 0; - QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); + QQmlTestMessageHandler messageHandler; delete o; - qInstallMessageHandler(old); - - QCOMPARE(transientErrorsMsgCount, 0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); } } @@ -6672,22 +6649,15 @@ void tst_qqmlecmascript::doubleEvaluate() delete object; } -static QStringList messages; -static void captureMsgHandler(QtMsgType, const QMessageLogContext &, const QString &msg) -{ - messages.append(msg); -} - void tst_qqmlecmascript::nonNotifyable() { QV4Compiler::enableV4(false); QQmlComponent component(&engine, testFileUrl("nonNotifyable.qml")); QV4Compiler::enableV4(true); - QtMessageHandler old = qInstallMessageHandler(captureMsgHandler); - messages.clear(); + QQmlTestMessageHandler messageHandler; + QObject *object = component.create(); - qInstallMessageHandler(old); QVERIFY(object != 0); @@ -6698,9 +6668,9 @@ void tst_qqmlecmascript::nonNotifyable() QLatin1String(object->metaObject()->className()) + QLatin1String("::value"); - QCOMPARE(messages.length(), 2); - QCOMPARE(messages.at(0), expected1); - QCOMPARE(messages.at(1), expected2); + QCOMPARE(messageHandler.messages().length(), 2); + QCOMPARE(messageHandler.messages().at(0), expected1); + QCOMPARE(messageHandler.messages().at(1), expected2); delete object; } @@ -7125,16 +7095,14 @@ void tst_qqmlecmascript::bindingSuppression() EventProcessor processor; engine.rootContext()->setContextProperty("pendingEvents", &processor); - transientErrorsMsgCount = 0; - QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); + QQmlTestMessageHandler messageHandler; QQmlComponent c(&engine, testFileUrl("bindingSuppression.qml")); QObject *obj = c.create(); QVERIFY(obj != 0); delete obj; - qInstallMessageHandler(old); - QCOMPARE(transientErrorsMsgCount, 0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); } void tst_qqmlecmascript::signalEmitted() 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() diff --git a/tests/auto/qml/qqmlinstruction/qqmlinstruction.pro b/tests/auto/qml/qqmlinstruction/qqmlinstruction.pro index 1eb4a203a3..73f29ab973 100644 --- a/tests/auto/qml/qqmlinstruction/qqmlinstruction.pro +++ b/tests/auto/qml/qqmlinstruction/qqmlinstruction.pro @@ -5,5 +5,7 @@ macx:CONFIG -= app_bundle CONFIG += parallel_test +include (../../shared/util.pri) + QT += core-private gui-private v8-private qml-private testlib DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/qml/qqmlinstruction/tst_qqmlinstruction.cpp b/tests/auto/qml/qqmlinstruction/tst_qqmlinstruction.cpp index 591d4722e2..e25c38d9cc 100644 --- a/tests/auto/qml/qqmlinstruction/tst_qqmlinstruction.cpp +++ b/tests/auto/qml/qqmlinstruction/tst_qqmlinstruction.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include <qtest.h> +#include "../../shared/util.h" #include <private/qqmlcompiler_p.h> #include <QVector3D> @@ -65,12 +66,6 @@ private slots: void time(); }; -static QStringList messages; -static void msgHandler(QtMsgType, const QMessageLogContext &, const QString &msg) -{ - messages << msg; -} - void tst_qqmlinstruction::dump() { QQmlEngine engine; @@ -564,15 +559,14 @@ void tst_qqmlinstruction::dump() << "57\t\tSTORE_VAR_BOOL\t\t83\ttrue" << "-------------------------------------------------------------------------------"; - messages = QStringList(); - QtMessageHandler old = qInstallMessageHandler(msgHandler); + QQmlTestMessageHandler messageHandler; data->dumpInstructions(); - qInstallMessageHandler(old); - QCOMPARE(messages.count(), expect.count()); - for (int ii = 0; ii < messages.count(); ++ii) { - QCOMPARE(messages.at(ii), expect.at(ii)); + const int messageCount = messageHandler.messages().count(); + QCOMPARE(messageCount, expect.count()); + for (int ii = 0; ii < messageCount; ++ii) { + QCOMPARE(messageHandler.messages().at(ii), expect.at(ii)); } data->release(); diff --git a/tests/auto/qml/qqmlpropertymap/qqmlpropertymap.pro b/tests/auto/qml/qqmlpropertymap/qqmlpropertymap.pro index bf22afa20c..81212bb064 100644 --- a/tests/auto/qml/qqmlpropertymap/qqmlpropertymap.pro +++ b/tests/auto/qml/qqmlpropertymap/qqmlpropertymap.pro @@ -4,6 +4,8 @@ macx:CONFIG -= app_bundle SOURCES += tst_qqmlpropertymap.cpp +include (../../shared/util.pri) + CONFIG += parallel_test QT += core-private gui-private qml-private quick-private testlib diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp index 99179f533b..af2a032a30 100644 --- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp +++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ #include <qtest.h> +#include "../../shared/util.h" #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcontext.h> #include <QtQml/qqmlpropertymap.h> @@ -294,19 +295,9 @@ public slots: void testSlot() {} }; -namespace -{ - QStringList messages; - void msgHandler(QtMsgType, const QMessageLogContext &, const QString &msg) - { - messages << msg; - } -} - void tst_QQmlPropertyMap::metaObjectAccessibility() { - messages.clear(); - QtMessageHandler old = qInstallMessageHandler(msgHandler); + QQmlTestMessageHandler messageHandler; QQmlEngine engine; @@ -318,9 +309,7 @@ void tst_QQmlPropertyMap::metaObjectAccessibility() QCOMPARE(map.metaObject()->className(), "MyEnhancedPropertyMap"); - qInstallMessageHandler(old); - - QCOMPARE(messages.count(), 0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); } QTEST_MAIN(tst_QQmlPropertyMap) diff --git a/tests/auto/qml/v4/tst_v4.cpp b/tests/auto/qml/v4/tst_v4.cpp index f5e66a1d83..0644b363dd 100644 --- a/tests/auto/qml/v4/tst_v4.cpp +++ b/tests/auto/qml/v4/tst_v4.cpp @@ -104,16 +104,6 @@ void tst_v4::initTestCase() registerTypes(); } -static int v4ErrorCount; -static QList<QString> v4ErrorMessages; -static void v4ErrorsMsgHandler(QtMsgType, const QMessageLogContext &, const QString &message) -{ - v4ErrorMessages.append(message); - - if (message.contains("QV4")) - ++v4ErrorCount; -} - void tst_v4::qtscript() { QFETCH(QString, file); @@ -121,21 +111,14 @@ void tst_v4::qtscript() QQmlComponent component(&engine, testFileUrl(file)); - v4ErrorCount = 0; - v4ErrorMessages.clear(); - QtMessageHandler old = qInstallMessageHandler(v4ErrorsMsgHandler); + QQmlTestMessageHandler messageHandler; QObject *o = component.create(); delete o; - qInstallMessageHandler(old); - - if (v4ErrorCount) { - foreach (const QString &msg, v4ErrorMessages) - qDebug() << msg; - } QEXPECT_FAIL("jsvalueHandling", "QTBUG-26951 - QJSValue has a different representation of NULL to QV8Engine", Continue); - QCOMPARE(v4ErrorCount, 0); + const int v4ErrorCount = messageHandler.messages().filter(QLatin1String("QV4")).size(); + QVERIFY2(v4ErrorCount == 0, qPrintable(messageHandler.messageString())); QV4Compiler::enableBindingsTest(false); } @@ -959,12 +942,6 @@ void tst_v4::subscriptions() } } -static QStringList messages; -static void msgHandler(QtMsgType, const QMessageLogContext &, const QString &msg) -{ - messages << msg; -} - static QByteArray getAddress(int address) { return QByteArray::number(address); @@ -1108,8 +1085,7 @@ void tst_v4::debuggingDumpInstructions() expectedPreAddress << "\t\tInitString\t\tString_DataIndex(0) -> String_Slot(0)"; QStringList expected; - messages = QStringList(); - QtMessageHandler old = qInstallMessageHandler(msgHandler); + QQmlTestMessageHandler messageHandler; QQmlJS::Bytecode bc; #define DUMP_INSTR_IN_UNIT_TEST(I, FMT) { QQmlJS::V4InstrData<QQmlJS::V4Instr::I> i; memset(&i, 0, sizeof(i)); bc.append(i); } @@ -1130,15 +1106,15 @@ void tst_v4::debuggingDumpInstructions() bc.dump(start, end); // ensure that the output was expected. - qInstallMessageHandler(old); - QCOMPARE(messages.count(), expected.count()); - for (int ii = 0; ii < messages.count(); ++ii) { + const int messageCount = messageHandler.messages().count(); + QCOMPARE(messageCount, expected.count()); + for (int ii = 0; ii < messageCount; ++ii) { // Calculating the destination address of a null jump/branch instruction is tricky // so instead we simply don't compare that part of those instructions. QRegExp ignoreAddress("\\bAddress\\((\\w*)\\)"); ignoreAddress.setMinimal(true); QString expectOut = expected.at(ii); expectOut.replace(ignoreAddress, ""); - QString actualOut = messages.at(ii); actualOut.replace(ignoreAddress, ""); + QString actualOut = messageHandler.messages().at(ii); actualOut.replace(ignoreAddress, ""); QCOMPARE(actualOut, expectOut); } } |