tst_QSignalSpy: check (thereby suppress) intended runtime warnings

Use QTest::ignoreMessage() to prevent the runtime warnings being
printed, cleaning up the test log, and to document that they're
intended.

Pick-to: 6.5
Change-Id: Ia0ba888cce83529217642be0e7e321d9406ba386
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit ce913bff5df668787dc904469fca09763acf0f27)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit a6fba6154514fa6e786a7e6b187c5b970f90a8d3)
This commit is contained in:
Marc Mutz 2024-03-18 07:44:07 +01:00 committed by Qt Cherry-pick Bot
parent daa5b56cd2
commit e49fa71718

View File

@ -464,27 +464,33 @@ void tst_QSignalSpy::spyOnMetaMethod()
Q_DECLARE_METATYPE(QMetaMethod); Q_DECLARE_METATYPE(QMetaMethod);
void tst_QSignalSpy::spyOnMetaMethod_invalid() void tst_QSignalSpy::spyOnMetaMethod_invalid()
{ {
QFETCH(const QByteArray, message);
QFETCH(QObject*, object); QFETCH(QObject*, object);
QFETCH(QMetaMethod, signal); QFETCH(QMetaMethod, signal);
QTest::ignoreMessage(QtWarningMsg, message.data());
QSignalSpy spy(object, signal); QSignalSpy spy(object, signal);
QVERIFY(!spy.isValid()); QVERIFY(!spy.isValid());
} }
void tst_QSignalSpy::spyOnMetaMethod_invalid_data() void tst_QSignalSpy::spyOnMetaMethod_invalid_data()
{ {
QTest::addColumn<QByteArray>("message");
QTest::addColumn<QObject*>("object"); QTest::addColumn<QObject*>("object");
QTest::addColumn<QMetaMethod>("signal"); QTest::addColumn<QMetaMethod>("signal");
QTest::addRow("Invalid object") QTest::addRow("Invalid object")
<< "QSignalSpy: Cannot spy on a null object"_ba
<< static_cast<QObject*>(nullptr) << static_cast<QObject*>(nullptr)
<< QMetaMethod(); << QMetaMethod();
QTest::addRow("Empty signal") QTest::addRow("Empty signal")
<< "QSignalSpy: Not a valid signal: ''"_ba
<< new QObject(this) << new QObject(this)
<< QMetaMethod(); << QMetaMethod();
QTest::addRow("Method is not a signal") QTest::addRow("Method is not a signal")
<< "QSignalSpy: Not a valid signal: 'deleteLater()'"_ba
<< new QObject(this) << new QObject(this)
<< QObject::staticMetaObject.method(QObject::staticMetaObject.indexOfMethod("deleteLater()")); << QObject::staticMetaObject.method(QObject::staticMetaObject.indexOfMethod("deleteLater()"));
} }