summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp')
-rw-r--r--tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp71
1 files changed, 61 insertions, 10 deletions
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
index ddeb9da649..c48b79b260 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();
@@ -414,7 +421,7 @@ void tst_QAbstractItemModel::itemFlags()
void tst_QAbstractItemModel::match()
{
- QtTestModel model(4, 1);
+ QtTestModel model(5, 1);
QModelIndex start = model.index(0, 0, QModelIndex());
QVERIFY(start.isValid());
QModelIndexList res = model.match(start, Qt::DisplayRole, QVariant("1"), 3);
@@ -427,19 +434,20 @@ void tst_QAbstractItemModel::match()
model.setData(model.index(1, 0, QModelIndex()), "cat", Qt::DisplayRole);
model.setData(model.index(2, 0, QModelIndex()), "dog", Qt::DisplayRole);
model.setData(model.index(3, 0, QModelIndex()), "boar", Qt::DisplayRole);
+ model.setData(model.index(4, 0, QModelIndex()), "bo/a/r", Qt::DisplayRole); // QTBUG-104585
res = model.match(start, Qt::DisplayRole, QVariant("dog"), -1, Qt::MatchExactly);
QCOMPARE(res.size(), 1);
res = model.match(start, Qt::DisplayRole, QVariant("a"), -1, Qt::MatchContains);
- QCOMPARE(res.size(), 3);
+ QCOMPARE(res.size(), 4);
res = model.match(start, Qt::DisplayRole, QVariant("b"), -1, Qt::MatchStartsWith);
- QCOMPARE(res.size(), 2);
+ QCOMPARE(res.size(), 3);
res = model.match(start, Qt::DisplayRole, QVariant("t"), -1, Qt::MatchEndsWith);
QCOMPARE(res.size(), 2);
res = model.match(start, Qt::DisplayRole, QVariant("*a*"), -1, Qt::MatchWildcard);
- QCOMPARE(res.size(), 3);
+ QCOMPARE(res.size(), 4);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1, Qt::MatchRegularExpression);
- QCOMPARE(res.size(), 2);
+ QCOMPARE(res.size(), 3);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1, Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
QCOMPARE(res.size(), 0);
res = model.match(start, Qt::DisplayRole, QVariant("BOAR"), -1, Qt::MatchFixedString);
@@ -450,7 +458,7 @@ void tst_QAbstractItemModel::match()
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1,
Qt::MatchRegularExpression);
- QCOMPARE(res.size(), 2);
+ QCOMPARE(res.size(), 3);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1,
Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
QCOMPARE(res.size(), 0);
@@ -464,7 +472,7 @@ void tst_QAbstractItemModel::match()
QRegularExpression::CaseInsensitiveOption)),
-1,
Qt::MatchRegularExpression);
- QCOMPARE(res.size(), 2);
+ QCOMPARE(res.size(), 3);
// Ensure that the case sensitivity is properly ignored when passing a
// QRegularExpression object.
@@ -474,7 +482,7 @@ void tst_QAbstractItemModel::match()
QRegularExpression::CaseInsensitiveOption)),
-1,
Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
- QCOMPARE(res.size(), 2);
+ QCOMPARE(res.size(), 3);
}
typedef QPair<int, int> Position;
@@ -983,6 +991,42 @@ void tst_QAbstractItemModel::complexChangesWithPersistent()
QVERIFY(e[i] == model.index(2, i-2 , QModelIndex()));
}
+void tst_QAbstractItemModel::modelIndexComparisons()
+{
+ QTestPrivate::testAllComparisonOperatorsCompile<QModelIndex>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QPersistentModelIndex>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QPersistentModelIndex, QModelIndex>();
+
+ QtTestModel model(3, 3);
+
+ QModelIndex mi11 = model.index(1, 1);
+ QModelIndex mi22 = model.index(2, 2);
+ QPersistentModelIndex pmi11 = mi11;
+ QPersistentModelIndex pmi22 = mi22;
+ QPersistentModelIndex pmiU;
+
+ QT_TEST_EQUALITY_OPS(mi11, mi11, true);
+ QT_TEST_EQUALITY_OPS(mi11, mi22, false);
+ QT_TEST_ALL_COMPARISON_OPS(mi11, mi11, Qt::strong_ordering::equal);
+ QT_TEST_ALL_COMPARISON_OPS(mi11, mi22, Qt::strong_ordering::less);
+ QT_TEST_ALL_COMPARISON_OPS(mi22, mi11, Qt::strong_ordering::greater);
+ 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);
+
+ QT_TEST_ALL_COMPARISON_OPS(pmi11, pmi11, Qt::strong_ordering::equal);
+ QT_TEST_ALL_COMPARISON_OPS(pmi11, pmi22, Qt::strong_ordering::less);
+ // Disengaged QPMIs are sorted randomly (based on address of their Private)
+ // So all we can check here is QPMIs with d == nullptr, which should reliably
+ // come before any others.
+ QT_TEST_ALL_COMPARISON_OPS(pmiU, pmiU, Qt::strong_ordering::equal);
+ QT_TEST_ALL_COMPARISON_OPS(pmi11, pmiU, Qt::strong_ordering::greater);
+ QT_TEST_ALL_COMPARISON_OPS(pmi11, mi11, Qt::strong_ordering::equal);
+ QT_TEST_ALL_COMPARISON_OPS(pmi11, mi22, Qt::strong_ordering::less);
+ QT_TEST_ALL_COMPARISON_OPS(pmiU, mi11, Qt::strong_ordering::less);
+}
+
void tst_QAbstractItemModel::testMoveSameParentDown_data()
{
QTest::addColumn<int>("startRow");
@@ -1214,6 +1258,7 @@ void tst_QAbstractItemModel::testMoveSameParentUp()
}
}
+#if QT_CONFIG(sortfilterproxymodel)
void tst_QAbstractItemModel::testMoveThroughProxy()
{
QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this);
@@ -1232,6 +1277,7 @@ void tst_QAbstractItemModel::testMoveThroughProxy()
moveCommand->setDestRow(0);
moveCommand->doCommand();
}
+#endif
void tst_QAbstractItemModel::testMoveToGrandParent_data()
{
@@ -1779,6 +1825,7 @@ void tst_QAbstractItemModel::testMoveWithinOwnRange()
QCOMPARE(afterSpy.size(), 0);
}
+#if QT_CONFIG(proxymodel)
class ListenerObject : public QObject
{
Q_OBJECT
@@ -1797,7 +1844,7 @@ private:
QList<QPersistentModelIndex> m_persistentIndexes;
QModelIndexList m_nonPersistentIndexes;
};
-
+#endif
class ModelWithCustomRole : public QStringListModel
{
@@ -1811,6 +1858,7 @@ public:
}
};
+#if QT_CONFIG(proxymodel)
ListenerObject::ListenerObject(QAbstractProxyModel *parent)
: QObject(parent), m_model(parent)
{
@@ -1851,7 +1899,9 @@ void ListenerObject::slotReset()
QVERIFY(!idx.isValid());
}
}
+#endif
+#if QT_CONFIG(sortfilterproxymodel)
void tst_QAbstractItemModel::testReset()
{
QSignalSpy beforeResetSpy(m_model, &DynamicTreeModel::modelAboutToBeReset);
@@ -1906,6 +1956,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
{