From 3746eedeab134a228a318c3962718f52e1dfffeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Wed, 9 Jul 2014 17:42:08 +0200 Subject: Update QVariant tests Remove old message handler hack as we have a new and better api to ignore warning messages. Change-Id: Id967b2672fe3e3638db9977500118a19c2afb730 Reviewed-by: Friedemann Kleint --- .../auto/corelib/kernel/qvariant/tst_qvariant.cpp | 6 ++--- .../kernel/qguivariant/test/tst_qguivariant.cpp | 6 ++--- .../other/qvariant_common/tst_qvariant_common.h | 27 ---------------------- .../kernel/qwidgetsvariant/tst_qwidgetsvariant.cpp | 6 ++--- 4 files changed, 6 insertions(+), 39 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index aef79e0c2f..660d0f804e 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -318,18 +318,16 @@ void tst_QVariant::constructor_invalid() QFETCH(uint, typeId); { - MessageHandlerInvalidType msg; + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:")); QVariant variant(static_cast(typeId)); QVERIFY(!variant.isValid()); QVERIFY(variant.userType() == QMetaType::UnknownType); - QVERIFY(msg.ok); } { - MessageHandlerInvalidType msg; + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:")); QVariant variant(typeId, /* copy */ 0); QVERIFY(!variant.isValid()); QVERIFY(variant.userType() == QMetaType::UnknownType); - QVERIFY(msg.ok); } } diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp index 431db86330..dc139cfa94 100644 --- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp +++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp @@ -145,18 +145,16 @@ void tst_QGuiVariant::constructor_invalid() QFETCH(uint, typeId); { - MessageHandlerInvalidType msg; + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:")); QVariant variant(static_cast(typeId)); QVERIFY(!variant.isValid()); QVERIFY(variant.userType() == QMetaType::UnknownType); - QVERIFY(msg.ok); } { - MessageHandlerInvalidType msg; + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:")); QVariant variant(typeId, /* copy */ 0); QVERIFY(!variant.isValid()); QVERIFY(variant.userType() == QMetaType::UnknownType); - QVERIFY(msg.ok); } } diff --git a/tests/auto/other/qvariant_common/tst_qvariant_common.h b/tests/auto/other/qvariant_common/tst_qvariant_common.h index 7a34d7b0c2..89c8bc777a 100644 --- a/tests/auto/other/qvariant_common/tst_qvariant_common.h +++ b/tests/auto/other/qvariant_common/tst_qvariant_common.h @@ -44,33 +44,6 @@ #include -struct MessageHandlerInvalidType -{ - MessageHandlerInvalidType() - : oldMsgHandler(qInstallMessageHandler(handler)) - { - ok = false; - } - - ~MessageHandlerInvalidType() - { - qInstallMessageHandler(oldMsgHandler); - } - - QtMessageHandler oldMsgHandler; - - static void handler(QtMsgType type, const QMessageLogContext & /*ctxt*/, const QString &msg) - { - Q_UNUSED(type); - // 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()); - } - static bool ok; -}; -bool MessageHandlerInvalidType::ok; - - class MessageHandler { public: MessageHandler(const int typeId, QtMessageHandler msgHandler = handler) diff --git a/tests/auto/widgets/kernel/qwidgetsvariant/tst_qwidgetsvariant.cpp b/tests/auto/widgets/kernel/qwidgetsvariant/tst_qwidgetsvariant.cpp index 286b887521..6264151c08 100644 --- a/tests/auto/widgets/kernel/qwidgetsvariant/tst_qwidgetsvariant.cpp +++ b/tests/auto/widgets/kernel/qwidgetsvariant/tst_qwidgetsvariant.cpp @@ -89,18 +89,16 @@ void tst_QWidgetsVariant::constructor_invalid() QFETCH(uint, typeId); { - MessageHandlerInvalidType msg; + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:")); QVariant variant(static_cast(typeId)); QVERIFY(!variant.isValid()); QVERIFY(variant.userType() == QMetaType::UnknownType); - QVERIFY(msg.ok); } { - MessageHandlerInvalidType msg; + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:")); QVariant variant(typeId, /* copy */ 0); QVERIFY(!variant.isValid()); QVERIFY(variant.userType() == QMetaType::UnknownType); - QVERIFY(msg.ok); } } -- cgit v1.2.3