From: Kai Koehne Date: Wed, 12 Sep 2012 08:42:25 +0000 (+0200) Subject: Autotests: Use qInstallMessageHandler X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1dd4790aeef17f056840bfea6c438075adbaaa03;p=profile%2Fivi%2Fqtbase.git Autotests: Use qInstallMessageHandler qInstallMsgHandler got deprecated in Qt 5. Change-Id: Ib36983e66b3a8090b99f14e3fd4e210602a3f018 Reviewed-by: Qt Doc Bot Reviewed-by: Thiago Macieira --- diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 6e1b9f8..091ada1 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -3236,9 +3236,8 @@ struct MessageHandlerType : public MessageHandler MessageHandlerType(const int typeId) : MessageHandler(typeId, handler) {} - static void handler(QtMsgType, const char *txt) + static void handler(QtMsgType, const QMessageLogContext &, const QString &msg) { - QString msg = QString::fromLatin1(txt); // Format itself is not important, but basic data as a type name should be included in the output ok = msg.startsWith("QVariant::"); QVERIFY2(ok, (QString::fromLatin1("Message is not started correctly: '") + msg + '\'').toLatin1().constData()); diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 3d0ec9f..14e83ad 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -2410,7 +2410,7 @@ public: static bool success; -void porterDuff_warningChecker(QtMsgType type, const char *msg) +void porterDuff_warningChecker(QtMsgType type, const QMessageLogContext &, const QString &msg) { if (type == QtWarningMsg && msg == QLatin1String("QPainter::setCompositionMode: PorterDuff modes not supported on device")) success = false; @@ -2418,7 +2418,7 @@ void porterDuff_warningChecker(QtMsgType type, const char *msg) void tst_QPainter::porterDuff_warning() { - QtMsgHandler old = qInstallMsgHandler(porterDuff_warningChecker); + QtMessageHandler old = qInstallMessageHandler(porterDuff_warningChecker); DummyPaintEngine dummy; QPainter p(&dummy); @@ -2434,7 +2434,7 @@ void tst_QPainter::porterDuff_warning() p.setCompositionMode(QPainter::CompositionMode_DestinationOver); QVERIFY(!success); - QVERIFY(qInstallMsgHandler(old) == porterDuff_warningChecker); + QVERIFY(qInstallMessageHandler(old) == porterDuff_warningChecker); } class quint24 diff --git a/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp b/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp index 126b41e..d779ac7 100644 --- a/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp +++ b/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp @@ -79,8 +79,8 @@ private slots: void linkedList(); private: - static QtMsgHandler testMessageHandler; - static void safeMessageHandler(QtMsgType, const char *); + static QtMessageHandler testMessageHandler; + static void safeMessageHandler(QtMsgType, const QMessageLogContext&, const QString&); #endif }; @@ -275,15 +275,16 @@ public: } }; -QtMsgHandler tst_ExceptionSafety_Objects::testMessageHandler; +QtMessageHandler tst_ExceptionSafety_Objects::testMessageHandler; -void tst_ExceptionSafety_Objects::safeMessageHandler(QtMsgType type, const char *msg) +void tst_ExceptionSafety_Objects::safeMessageHandler(QtMsgType type, const QMessageLogContext &ctxt, + const QString &msg) { // this temporarily suspends OOM testing while handling a message int currentIndex = mallocFailIndex; AllocFailer allocFailer(0); allocFailer.deactivate(); - (*testMessageHandler)(type, msg); + (*testMessageHandler)(type, ctxt, msg); allocFailer.reactivateAt(currentIndex); } @@ -307,7 +308,7 @@ void tst_ExceptionSafety_Objects::initTestCase() // set handlers for bad exception cases, you might want to step in and breakpoint the default handlers too defaultTerminate = std::set_terminate(&debugTerminate); defaultUnexpected = std::set_unexpected(&debugUnexpected); - testMessageHandler = qInstallMsgHandler(safeMessageHandler); + testMessageHandler = qInstallMessageHandler(safeMessageHandler); QVERIFY(AllocFailer::initialize()); @@ -342,7 +343,7 @@ void tst_ExceptionSafety_Objects::initTestCase() void tst_ExceptionSafety_Objects::cleanupTestCase() { - qInstallMsgHandler(testMessageHandler); + qInstallMessageHandler(testMessageHandler); } void tst_ExceptionSafety_Objects::objects() diff --git a/tests/auto/other/qvariant_common/tst_qvariant_common.h b/tests/auto/other/qvariant_common/tst_qvariant_common.h index 63d236d..0e1b453 100644 --- a/tests/auto/other/qvariant_common/tst_qvariant_common.h +++ b/tests/auto/other/qvariant_common/tst_qvariant_common.h @@ -47,22 +47,21 @@ struct MessageHandlerInvalidType { MessageHandlerInvalidType() - : oldMsgHandler(qInstallMsgHandler(handler)) + : oldMsgHandler(qInstallMessageHandler(handler)) { ok = false; } ~MessageHandlerInvalidType() { - qInstallMsgHandler(oldMsgHandler); + qInstallMessageHandler(oldMsgHandler); } - QtMsgHandler oldMsgHandler; + QtMessageHandler oldMsgHandler; - static void handler(QtMsgType type, const char *txt) + static void handler(QtMsgType type, const QMessageLogContext & /*ctxt*/, const QString &msg) { Q_UNUSED(type); - QString msg = QString::fromLatin1(txt); // uint(-1) can be platform dependent so we check only beginning of the message. ok = msg.startsWith("Trying to construct an instance of an invalid type, type id:"); QVERIFY2(ok, (QString::fromLatin1("Message is not started correctly: '") + msg + '\'').toLatin1().constData()); @@ -74,15 +73,15 @@ bool MessageHandlerInvalidType::ok; class MessageHandler { public: - MessageHandler(const int typeId, QtMsgHandler msgHandler = handler) - : oldMsgHandler(qInstallMsgHandler(msgHandler)) + MessageHandler(const int typeId, QtMessageHandler msgHandler = handler) + : oldMsgHandler(qInstallMessageHandler(msgHandler)) { currentId = typeId; } ~MessageHandler() { - qInstallMsgHandler(oldMsgHandler); + qInstallMessageHandler(oldMsgHandler); } bool testPassed() const @@ -90,9 +89,8 @@ public: return ok; } protected: - static void handler(QtMsgType, const char *txt) + static void handler(QtMsgType, const QMessageLogContext &, const QString &msg) { - QString msg = QString::fromLatin1(txt); // Format itself is not important, but basic data as a type name should be included in the output ok = msg.startsWith("QVariant("); QVERIFY2(ok, (QString::fromLatin1("Message is not started correctly: '") + msg + '\'').toLatin1().constData()); @@ -114,7 +112,7 @@ protected: } - QtMsgHandler oldMsgHandler; + QtMessageHandler oldMsgHandler; static int currentId; static bool ok; }; @@ -224,4 +222,4 @@ int MessageHandler::currentId; QCOMPARE(val.canConvert(QVariant::ULongLong), ULongLongCast); -#endif \ No newline at end of file +#endif