tst_QAbstractProxyModel: port to QTEST_THROW_ON_FAIL

Dogfooding the new QtTest 6.8 feature.

This not only helps with the sourceModelBinding() test with its manual
currentTestFailed() calls, but also the old verifySubSetOf() helper
function that's there from Qt 4 times.

Use Ye Olde Scope Guard Trick™ to replace the qDebug() messages
recording where failures occurred.

Change-Id: I4d1460bde5315dfcc3b261b6e09c7293bbd9ff89
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 32fc8b936d1d036ba5b70ec1cac7681e1c9359c8)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-01-26 14:24:58 +01:00 committed by Qt Cherry-pick Bot
parent a9ebd2d64e
commit 7e021ab891
3 changed files with 27 additions and 12 deletions

View File

@ -5,7 +5,9 @@ add_subdirectory(qstringlistmodel)
if(TARGET Qt::Gui)
add_subdirectory(qabstractitemmodel)
if(QT_FEATURE_proxymodel)
if (NOT WASM) # QTBUG-121822
add_subdirectory(qabstractproxymodel)
endif()
add_subdirectory(qconcatenatetablesproxymodel)
add_subdirectory(qidentityproxymodel)
add_subdirectory(qsortfilterproxymodel_recursive)

View File

@ -14,6 +14,10 @@ endif()
qt_internal_add_test(tst_qabstractproxymodel
SOURCES
tst_qabstractproxymodel.cpp
NO_BATCH # QTBUG-121815
DEFINES
QTEST_THROW_ON_FAIL
QTEST_THROW_ON_SKIP
LIBRARIES
Qt::Gui
Qt::TestPrivate

View File

@ -3,10 +3,17 @@
#include <QTest>
#include <QtTest/private/qpropertytesthelper_p.h>
#ifndef QTEST_THROW_ON_FAIL
# error This test requires QTEST_THROW_ON_FAIL being active.
#endif
#include <qabstractproxymodel.h>
#include <QItemSelection>
#include <qstandarditemmodel.h>
#include <QtCore/qscopeguard.h>
class tst_QAbstractProxyModel : public QObject
{
Q_OBJECT
@ -610,28 +617,30 @@ void tst_QAbstractProxyModel::sourceModelBinding()
SubQAbstractProxyModel proxy;
QStandardItemModel model1;
QStandardItemModel model2;
const char *lhs;
const char *rhs;
auto printOnFailure = qScopeGuard([&] {
qDebug("Failed %s - %s test", lhs, rhs);
});
lhs = "model";
rhs = "model";
QTestPrivate::testReadWritePropertyBasics<SubQAbstractProxyModel, QAbstractItemModel *>(
proxy, &model1, &model2, "sourceModel");
if (QTest::currentTestFailed()) {
qDebug("Failed model - model test");
return;
}
proxy.setSourceModel(&model2);
lhs = "model";
rhs = "nullptr";
QTestPrivate::testReadWritePropertyBasics<SubQAbstractProxyModel, QAbstractItemModel *>(
proxy, &model1, nullptr, "sourceModel");
if (QTest::currentTestFailed()) {
qDebug("Failed model - nullptr test");
return;
}
proxy.setSourceModel(&model1);
lhs = "nullptr";
rhs = "model";
QTestPrivate::testReadWritePropertyBasics<SubQAbstractProxyModel, QAbstractItemModel *>(
proxy, nullptr, &model2, "sourceModel");
if (QTest::currentTestFailed()) {
qDebug("Failed nullptr - model test");
return;
}
printOnFailure.dismiss();
}
QTEST_MAIN(tst_QAbstractProxyModel)