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 <Friedemann.Kleint@digia.com>
This commit is contained in:
parent
776ddcab2c
commit
3746eedeab
@ -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<QVariant::Type>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<QVariant::Type>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,33 +44,6 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
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)
|
||||
|
@ -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<QVariant::Type>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user