diff options
Diffstat (limited to 'tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp')
-rw-r--r-- | tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index 4c69575ecc..6b1e4ce9ba 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -1,10 +1,14 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> +#include <QtTest/private/qcomparisontesthelper_p.h> + #include <QtCore/QCoreApplication> +#if QT_CONFIG(sortfilterproxymodel) #include <QtCore/QSortFilterProxyModel> +#endif #include <QtCore/QStringListModel> #include <QtGui/QStandardItemModel> @@ -56,6 +60,7 @@ private slots: void reset(); void complexChangesWithPersistent(); + void modelIndexComparisons(); void testMoveSameParentUp_data(); void testMoveSameParentUp(); @@ -77,9 +82,11 @@ private slots: void testMoveWithinOwnRange_data(); void testMoveWithinOwnRange(); +#if QT_CONFIG(sortfilterproxymodel) void testMoveThroughProxy(); void testReset(); +#endif void testDataChanged(); @@ -984,6 +991,27 @@ void tst_QAbstractItemModel::complexChangesWithPersistent() QVERIFY(e[i] == model.index(2, i-2 , QModelIndex())); } +void tst_QAbstractItemModel::modelIndexComparisons() +{ + QTestPrivate::testEqualityOperatorsCompile<QModelIndex>(); + QTestPrivate::testEqualityOperatorsCompile<QPersistentModelIndex>(); + QTestPrivate::testEqualityOperatorsCompile<QPersistentModelIndex, QModelIndex>(); + + QtTestModel model(3, 3); + + QModelIndex mi11 = model.index(1, 1); + QModelIndex mi22 = model.index(2, 2); + QPersistentModelIndex pmi11 = mi11; + QPersistentModelIndex pmi22 = mi22; + + QT_TEST_EQUALITY_OPS(mi11, mi11, true); + QT_TEST_EQUALITY_OPS(mi11, mi22, false); + QT_TEST_EQUALITY_OPS(pmi11, pmi11, true); + QT_TEST_EQUALITY_OPS(pmi11, pmi22, false); + QT_TEST_EQUALITY_OPS(pmi11, mi11, true); + QT_TEST_EQUALITY_OPS(pmi11, mi22, false); +} + void tst_QAbstractItemModel::testMoveSameParentDown_data() { QTest::addColumn<int>("startRow"); @@ -1215,6 +1243,7 @@ void tst_QAbstractItemModel::testMoveSameParentUp() } } +#if QT_CONFIG(sortfilterproxymodel) void tst_QAbstractItemModel::testMoveThroughProxy() { QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this); @@ -1233,6 +1262,7 @@ void tst_QAbstractItemModel::testMoveThroughProxy() moveCommand->setDestRow(0); moveCommand->doCommand(); } +#endif void tst_QAbstractItemModel::testMoveToGrandParent_data() { @@ -1780,6 +1810,7 @@ void tst_QAbstractItemModel::testMoveWithinOwnRange() QCOMPARE(afterSpy.size(), 0); } +#if QT_CONFIG(proxymodel) class ListenerObject : public QObject { Q_OBJECT @@ -1798,7 +1829,7 @@ private: QList<QPersistentModelIndex> m_persistentIndexes; QModelIndexList m_nonPersistentIndexes; }; - +#endif class ModelWithCustomRole : public QStringListModel { @@ -1812,6 +1843,7 @@ public: } }; +#if QT_CONFIG(proxymodel) ListenerObject::ListenerObject(QAbstractProxyModel *parent) : QObject(parent), m_model(parent) { @@ -1852,7 +1884,9 @@ void ListenerObject::slotReset() QVERIFY(!idx.isValid()); } } +#endif +#if QT_CONFIG(sortfilterproxymodel) void tst_QAbstractItemModel::testReset() { QSignalSpy beforeResetSpy(m_model, &DynamicTreeModel::modelAboutToBeReset); @@ -1907,6 +1941,7 @@ void tst_QAbstractItemModel::testReset() // After being reset the proxy must be queried again. QCOMPARE(nullProxy->roleNames().value(Qt::UserRole + 1), QByteArray()); } +#endif class CustomRoleModel : public QStringListModel { |