From: Kai Koehne Date: Thu, 13 Sep 2012 12:35:42 +0000 (+0200) Subject: Autotests: Use qInstallMessageHandler X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=08444bab1bf25e20837ea47b647a5b1216caa05c;p=konrad%2Fqtdeclarative.git Autotests: Use qInstallMessageHandler qInstallMsgHandler got deprecated in Qt 5. Change-Id: Icb6423c7d9f7e507ba36376b0af5ad183379c494 Reviewed-by: Martin Jones --- diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index 3a3952d..01cec58 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -227,9 +227,9 @@ void tst_qqmlcomponent::qmlCreateObjectWithProperties() } static QStringList warnings; -static void msgHandler(QtMsgType, const char *warning) +static void msgHandler(QtMsgType, const QMessageLogContext &, const QString &warning) { - warnings << QString::fromUtf8(warning); + warnings << warning; } void tst_qqmlcomponent::qmlCreateParentReference() @@ -239,7 +239,7 @@ void tst_qqmlcomponent::qmlCreateParentReference() QCOMPARE(engine.outputWarningsToStandardError(), true); warnings.clear(); - QtMsgHandler old = qInstallMsgHandler(msgHandler); + QtMessageHandler old = qInstallMessageHandler(msgHandler); QQmlComponent component(&engine, testFileUrl("createParentReference.qml")); QVERIFY2(component.errorString().isEmpty(), component.errorString().toUtf8()); @@ -249,7 +249,7 @@ void tst_qqmlcomponent::qmlCreateParentReference() QVERIFY(QMetaObject::invokeMethod(object, "createChild")); delete object; - qInstallMsgHandler(old); + qInstallMessageHandler(old); engine.setOutputWarningsToStandardError(false); QCOMPARE(engine.outputWarningsToStandardError(), false); @@ -399,12 +399,12 @@ void tst_qqmlcomponent::onDestructionCount() QCOMPARE(engine.outputWarningsToStandardError(), true); warnings.clear(); - QtMsgHandler old = qInstallMsgHandler(msgHandler); + QtMessageHandler old = qInstallMessageHandler(msgHandler); QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QCoreApplication::processEvents(); - qInstallMsgHandler(old); + qInstallMessageHandler(old); 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 97fe099..bf7e7cd 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -1922,7 +1922,7 @@ void tst_qqmlecmascript::compileInvalidBinding() } static int transientErrorsMsgCount = 0; -static void transientErrorsMsgHandler(QtMsgType, const char *) +static void transientErrorsMsgHandler(QtMsgType, const QMessageLogContext &, const QString &) { ++transientErrorsMsgCount; } @@ -1934,12 +1934,12 @@ void tst_qqmlecmascript::transientErrors() QQmlComponent component(&engine, testFileUrl("transientErrors.qml")); transientErrorsMsgCount = 0; - QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler); + QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); QObject *object = component.create(); QVERIFY(object != 0); - qInstallMsgHandler(old); + qInstallMessageHandler(old); QCOMPARE(transientErrorsMsgCount, 0); @@ -1951,12 +1951,12 @@ void tst_qqmlecmascript::transientErrors() QQmlComponent component(&engine, testFileUrl("transientErrors.2.qml")); transientErrorsMsgCount = 0; - QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler); + QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); QObject *object = component.create(); QVERIFY(object != 0); - qInstallMsgHandler(old); + qInstallMessageHandler(old); QCOMPARE(transientErrorsMsgCount, 0); @@ -1972,11 +1972,11 @@ void tst_qqmlecmascript::shutdownErrors() QVERIFY(object != 0); transientErrorsMsgCount = 0; - QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler); + QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); delete object; - qInstallMsgHandler(old); + qInstallMessageHandler(old); QCOMPARE(transientErrorsMsgCount, 0); } @@ -5754,11 +5754,11 @@ void tst_qqmlecmascript::qtbug_9792() delete context; transientErrorsMsgCount = 0; - QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler); + QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); object->basicSignal(); - qInstallMsgHandler(old); + qInstallMessageHandler(old); QCOMPARE(transientErrorsMsgCount, 0); @@ -5795,11 +5795,11 @@ void tst_qqmlecmascript::noSpuriousWarningsAtShutdown() QObject *o = component.create(); transientErrorsMsgCount = 0; - QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler); + QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); delete o; - qInstallMsgHandler(old); + qInstallMessageHandler(old); QCOMPARE(transientErrorsMsgCount, 0); } @@ -5811,11 +5811,11 @@ void tst_qqmlecmascript::noSpuriousWarningsAtShutdown() QObject *o = component.create(); transientErrorsMsgCount = 0; - QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler); + QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); delete o; - qInstallMsgHandler(old); + qInstallMessageHandler(old); QCOMPARE(transientErrorsMsgCount, 0); } @@ -6625,9 +6625,9 @@ void tst_qqmlecmascript::doubleEvaluate() } static QStringList messages; -static void captureMsgHandler(QtMsgType, const char *msg) +static void captureMsgHandler(QtMsgType, const QMessageLogContext &, const QString &msg) { - messages.append(QLatin1String(msg)); + messages.append(msg); } void tst_qqmlecmascript::nonNotifyable() @@ -6636,10 +6636,10 @@ void tst_qqmlecmascript::nonNotifyable() QQmlComponent component(&engine, testFileUrl("nonNotifyable.qml")); QV4Compiler::enableV4(true); - QtMsgHandler old = qInstallMsgHandler(captureMsgHandler); + QtMessageHandler old = qInstallMessageHandler(captureMsgHandler); messages.clear(); QObject *object = component.create(); - qInstallMsgHandler(old); + qInstallMessageHandler(old); QVERIFY(object != 0); @@ -7078,14 +7078,14 @@ void tst_qqmlecmascript::bindingSuppression() engine.rootContext()->setContextProperty("pendingEvents", &processor); transientErrorsMsgCount = 0; - QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler); + QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler); QQmlComponent c(&engine, testFileUrl("bindingSuppression.qml")); QObject *obj = c.create(); QVERIFY(obj != 0); delete obj; - qInstallMsgHandler(old); + qInstallMessageHandler(old); QCOMPARE(transientErrorsMsgCount, 0); } diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index c9d3e27..3b565bc 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -418,9 +418,9 @@ void tst_qqmlengine::failedCompilation_data() } static QStringList warnings; -static void msgHandler(QtMsgType, const char *warning) +static void msgHandler(QtMsgType, const QMessageLogContext &, const QString &warning) { - warnings << QString::fromUtf8(warning); + warnings << warning; } void tst_qqmlengine::outputWarningsToStandardError() @@ -435,11 +435,11 @@ void tst_qqmlengine::outputWarningsToStandardError() QVERIFY(c.isReady() == true); warnings.clear(); - QtMsgHandler old = qInstallMsgHandler(msgHandler); + QtMessageHandler old = qInstallMessageHandler(msgHandler); QObject *o = c.create(); - qInstallMsgHandler(old); + qInstallMessageHandler(old); QVERIFY(o != 0); delete o; @@ -453,11 +453,11 @@ void tst_qqmlengine::outputWarningsToStandardError() QCOMPARE(engine.outputWarningsToStandardError(), false); - old = qInstallMsgHandler(msgHandler); + old = qInstallMessageHandler(msgHandler); o = c.create(); - qInstallMsgHandler(old); + qInstallMessageHandler(old); QVERIFY(o != 0); delete o; diff --git a/tests/auto/qml/qqmlinstruction/tst_qqmlinstruction.cpp b/tests/auto/qml/qqmlinstruction/tst_qqmlinstruction.cpp index 77de47d..feac36e 100644 --- a/tests/auto/qml/qqmlinstruction/tst_qqmlinstruction.cpp +++ b/tests/auto/qml/qqmlinstruction/tst_qqmlinstruction.cpp @@ -66,9 +66,9 @@ private slots: }; static QStringList messages; -static void msgHandler(QtMsgType, const char *msg) +static void msgHandler(QtMsgType, const QMessageLogContext &, const QString &msg) { - messages << QLatin1String(msg); + messages << msg; } void tst_qqmlinstruction::dump() @@ -565,10 +565,10 @@ void tst_qqmlinstruction::dump() << "-------------------------------------------------------------------------------"; messages = QStringList(); - QtMsgHandler old = qInstallMsgHandler(msgHandler); + QtMessageHandler old = qInstallMessageHandler(msgHandler); data->dumpInstructions(); - qInstallMsgHandler(old); + qInstallMessageHandler(old); QCOMPARE(messages.count(), expect.count()); for (int ii = 0; ii < messages.count(); ++ii) { diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp index eb3c000..a48cee7 100644 --- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp +++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp @@ -297,16 +297,16 @@ public slots: namespace { QStringList messages; - void msgHandler(QtMsgType, const char *msg) + void msgHandler(QtMsgType, const QMessageLogContext &, const QString &msg) { - messages << QLatin1String(msg); + messages << msg; } } void tst_QQmlPropertyMap::metaObjectAccessibility() { messages.clear(); - QtMsgHandler old = qInstallMsgHandler(msgHandler); + QtMessageHandler old = qInstallMessageHandler(msgHandler); QQmlEngine engine; @@ -318,7 +318,7 @@ void tst_QQmlPropertyMap::metaObjectAccessibility() QCOMPARE(map.metaObject()->className(), "MyEnhancedPropertyMap"); - qInstallMsgHandler(old); + qInstallMessageHandler(old); QCOMPARE(messages.count(), 0); } diff --git a/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp b/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp index 2eadc46..ae2e030 100644 --- a/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp +++ b/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp @@ -242,24 +242,24 @@ void tst_QQuickWorkerScript::script_included() } static QString qquickworkerscript_lastWarning; -static void qquickworkerscript_warningsHandler(QtMsgType type, const char *msg) +static void qquickworkerscript_warningsHandler(QtMsgType type, const QMessageLogContext &, const QString &msg) { if (type == QtWarningMsg) - qquickworkerscript_lastWarning = QString::fromUtf8(msg); + qquickworkerscript_lastWarning = msg; } void tst_QQuickWorkerScript::scriptError_onLoad() { QQmlComponent component(&m_engine, testFileUrl("worker_error_onLoad.qml")); - QtMsgHandler previousMsgHandler = qInstallMsgHandler(qquickworkerscript_warningsHandler); + QtMessageHandler previousMsgHandler = qInstallMessageHandler(qquickworkerscript_warningsHandler); QQuickWorkerScript *worker = qobject_cast(component.create()); QVERIFY(worker != 0); QTRY_COMPARE(qquickworkerscript_lastWarning, testFileUrl("script_error_onLoad.js").toString() + QLatin1String(":3: SyntaxError: Unexpected identifier")); - qInstallMsgHandler(previousMsgHandler); + qInstallMessageHandler(previousMsgHandler); qApp->processEvents(); delete worker; } @@ -270,14 +270,14 @@ void tst_QQuickWorkerScript::scriptError_onCall() QQuickWorkerScript *worker = qobject_cast(component.create()); QVERIFY(worker != 0); - QtMsgHandler previousMsgHandler = qInstallMsgHandler(qquickworkerscript_warningsHandler); + QtMessageHandler previousMsgHandler = qInstallMessageHandler(qquickworkerscript_warningsHandler); QVariant value; QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value))); QTRY_COMPARE(qquickworkerscript_lastWarning, testFileUrl("script_error_onCall.js").toString() + QLatin1String(":4: ReferenceError: getData is not defined")); - qInstallMsgHandler(previousMsgHandler); + qInstallMessageHandler(previousMsgHandler); qApp->processEvents(); delete worker; } diff --git a/tests/auto/qml/v4/tst_v4.cpp b/tests/auto/qml/v4/tst_v4.cpp index c09a020..782477a 100644 --- a/tests/auto/qml/v4/tst_v4.cpp +++ b/tests/auto/qml/v4/tst_v4.cpp @@ -105,13 +105,12 @@ void tst_v4::initTestCase() } static int v4ErrorCount; -static QList v4ErrorMessages; -static void v4ErrorsMsgHandler(QtMsgType, const char *message) +static QList v4ErrorMessages; +static void v4ErrorsMsgHandler(QtMsgType, const QMessageLogContext &, const QString &message) { - QByteArray m(message); - v4ErrorMessages.append(m); + v4ErrorMessages.append(message); - if (m.contains("QV4")) + if (message.contains("QV4")) ++v4ErrorCount; } @@ -124,15 +123,15 @@ void tst_v4::qtscript() v4ErrorCount = 0; v4ErrorMessages.clear(); - QtMsgHandler old = qInstallMsgHandler(v4ErrorsMsgHandler); + QtMessageHandler old = qInstallMessageHandler(v4ErrorsMsgHandler); QObject *o = component.create(); delete o; - qInstallMsgHandler(old); + qInstallMessageHandler(old); if (v4ErrorCount) { - foreach (const QByteArray &msg, v4ErrorMessages) + foreach (const QString &msg, v4ErrorMessages) qDebug() << msg; } QEXPECT_FAIL("jsvalueHandling", "QTBUG-26951 - QJSValue has a different representation of NULL to QV8Engine", Continue); @@ -961,9 +960,9 @@ void tst_v4::subscriptions() } static QStringList messages; -static void msgHandler(QtMsgType, const char *msg) +static void msgHandler(QtMsgType, const QMessageLogContext &, const QString &msg) { - messages << QLatin1String(msg); + messages << msg; } static QByteArray getAddress(int address) @@ -1110,7 +1109,7 @@ void tst_v4::debuggingDumpInstructions() QStringList expected; messages = QStringList(); - QtMsgHandler old = qInstallMsgHandler(msgHandler); + QtMessageHandler old = qInstallMessageHandler(msgHandler); QQmlJS::Bytecode bc; #define DUMP_INSTR_IN_UNIT_TEST(I, FMT) { QQmlJS::V4InstrData i; memset(&i, 0, sizeof(i)); bc.append(i); } @@ -1131,7 +1130,7 @@ void tst_v4::debuggingDumpInstructions() bc.dump(start, end); // ensure that the output was expected. - qInstallMsgHandler(old); + qInstallMessageHandler(old); QCOMPARE(messages.count(), expected.count()); for (int ii = 0; ii < messages.count(); ++ii) { // Calculating the destination address of a null jump/branch instruction is tricky diff --git a/tests/auto/quick/examples/tst_examples.cpp b/tests/auto/quick/examples/tst_examples.cpp index f9994a7..b9ebb15 100644 --- a/tests/auto/quick/examples/tst_examples.cpp +++ b/tests/auto/quick/examples/tst_examples.cpp @@ -50,11 +50,11 @@ #include #include -static QtMsgHandler testlibMsgHandler = 0; -void msgHandlerFilter(QtMsgType type, const char *msg) +static QtMessageHandler testlibMsgHandler = 0; +void msgHandlerFilter(QtMsgType type, const QMessageLogContext &ctxt, const QString &msg) { if (type == QtCriticalMsg || type == QtFatalMsg) - (*testlibMsgHandler)(type, msg); + (*testlibMsgHandler)(type, ctxt, msg); } class tst_examples : public QObject @@ -129,13 +129,13 @@ tst_examples::~tst_examples() void tst_examples::init() { if (!qstrcmp(QTest::currentTestFunction(), "sgsnippets")) - testlibMsgHandler = qInstallMsgHandler(msgHandlerFilter); + testlibMsgHandler = qInstallMessageHandler(msgHandlerFilter); } void tst_examples::cleanup() { if (!qstrcmp(QTest::currentTestFunction(), "sgsnippets")) - qInstallMsgHandler(testlibMsgHandler); + qInstallMessageHandler(testlibMsgHandler); } /* diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index a8f92cb..49ea9d0 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -662,9 +662,9 @@ void tst_qquickimage::sourceSize_QTBUG_16389() } static int numberOfWarnings = 0; -static void checkWarnings(QtMsgType, const char *msg) +static void checkWarnings(QtMsgType, const QMessageLogContext &, const QString &msg) { - if (!QString(msg).contains("QGLContext::makeCurrent(): Failed.")) + if (!msg.contains("QGLContext::makeCurrent(): Failed.")) numberOfWarnings++; } @@ -679,11 +679,11 @@ void tst_qquickimage::nullPixmapPaint() QTRY_VERIFY(image != 0); image->setSource(SERVER_ADDR + QString("/no-such-file.png")); - QtMsgHandler previousMsgHandler = qInstallMsgHandler(checkWarnings); + QtMessageHandler previousMsgHandler = qInstallMessageHandler(checkWarnings); // used to print "QTransform::translate with NaN called" QPixmap pm = QPixmap::fromImage(window->grabWindow()); - qInstallMsgHandler(previousMsgHandler); + qInstallMessageHandler(previousMsgHandler); QVERIFY(numberOfWarnings == 0); delete image; diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index c2bcd54..7c166c5 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -259,7 +259,7 @@ private: } #endif - static void errorMsgHandler(QtMsgType, const char *) + static void errorMsgHandler(QtMsgType, const QMessageLogContext &, const QString &) { ++m_errorCount; } @@ -6784,7 +6784,7 @@ void tst_QQuickListView::parentBinding() QQuickView *window = createView(); m_errorCount = 0; - QtMsgHandler old = qInstallMsgHandler(errorMsgHandler); + QtMessageHandler old = qInstallMessageHandler(errorMsgHandler); window->setSource(testFileUrl("parentBinding.qml")); window->show(); @@ -6805,7 +6805,7 @@ void tst_QQuickListView::parentBinding() // there should be no transient binding error QVERIFY(!m_errorCount); - qInstallMsgHandler(old); + qInstallMessageHandler(old); delete window; } diff --git a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp index 32ec41b..247c0d5 100644 --- a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp +++ b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp @@ -1724,7 +1724,7 @@ void tst_qquickpositioners::test_flow_implicit_resize() QString warningMessage; -void interceptWarnings(QtMsgType type, const char *msg) +void interceptWarnings(QtMsgType type, const QMessageLogContext &, const QString &msg) { Q_UNUSED( type ); warningMessage = msg; @@ -1732,7 +1732,7 @@ void interceptWarnings(QtMsgType type, const char *msg) void tst_qquickpositioners::test_conflictinganchors() { - QtMsgHandler oldMsgHandler = qInstallMsgHandler(interceptWarnings); + QtMessageHandler oldMsgHandler = qInstallMessageHandler(interceptWarnings); QQmlEngine engine; QQmlComponent component(&engine); @@ -1826,7 +1826,7 @@ void tst_qquickpositioners::test_conflictinganchors() item = qobject_cast(component.create()); QVERIFY(item); QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow. Flow will not function.")); - qInstallMsgHandler(oldMsgHandler); + qInstallMessageHandler(oldMsgHandler); delete item; } diff --git a/tests/auto/quick/qquickview/tst_qquickview.cpp b/tests/auto/quick/qquickview/tst_qquickview.cpp index 977b867..aea3950 100644 --- a/tests/auto/quick/qquickview/tst_qquickview.cpp +++ b/tests/auto/quick/qquickview/tst_qquickview.cpp @@ -187,7 +187,7 @@ void tst_QQuickView::resizemodeitem() delete view; } -static void silentErrorsMsgHandler(QtMsgType, const char *) +static void silentErrorsMsgHandler(QtMsgType, const QMessageLogContext &, const QString &) { } @@ -195,9 +195,9 @@ void tst_QQuickView::errors() { QQuickView *view = new QQuickView; QVERIFY(view); - QtMsgHandler old = qInstallMsgHandler(silentErrorsMsgHandler); + QtMessageHandler old = qInstallMessageHandler(silentErrorsMsgHandler); view->setSource(testFileUrl("error1.qml")); - qInstallMsgHandler(old); + qInstallMessageHandler(old); QVERIFY(view->status() == QQuickView::Error); QVERIFY(view->errors().count() == 1); delete view;