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.cpp136
1 files changed, 68 insertions, 68 deletions
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
index 5719d9e046..36eb9320a4 100644
--- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
@@ -1,33 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
+#include <QtTest/private/qcomparisontesthelper_p.h>
+
#include <QtCore/QCoreApplication>
#include <QtCore/QSortFilterProxyModel>
#include <QtCore/QStringListModel>
@@ -81,6 +58,7 @@ private slots:
void reset();
void complexChangesWithPersistent();
+ void modelIndexComparisons();
void testMoveSameParentUp_data();
void testMoveSameParentUp();
@@ -181,8 +159,8 @@ QtTestModel::QtTestModel(const QList<QList<QString> > tbl, QObject *parent)
: QAbstractItemModel(parent), wrongIndex(false)
{
table = tbl;
- rCount = tbl.count();
- cCount = tbl.at(0).count();
+ rCount = tbl.size();
+ cCount = tbl.at(0).size();
}
QModelIndex QtTestModel::index(int row, int column, const QModelIndex &parent) const
@@ -216,7 +194,7 @@ bool QtTestModel::insertRows(int row, int count, const QModelIndex &parent)
QAbstractItemModel::beginInsertRows(parent, row, row + count - 1);
int cc = columnCount(parent);
table.insert(row, count, QList<QString>(cc));
- rCount = table.count();
+ rCount = table.size();
QAbstractItemModel::endInsertRows();
return true;
}
@@ -227,7 +205,7 @@ bool QtTestModel::insertColumns(int column, int count, const QModelIndex &parent
int rc = rowCount(parent);
for (int i = 0; i < rc; ++i)
table[i].insert(column, 1, "");
- cCount = table.at(0).count();
+ cCount = table.at(0).size();
QAbstractItemModel::endInsertColumns();
return true;
}
@@ -243,7 +221,7 @@ bool QtTestModel::removeRows( int row, int count, const QModelIndex & parent)
for (int r = row+count-1; r >= row; --r)
table.remove(r);
- rCount = table.count();
+ rCount = table.size();
QAbstractItemModel::endRemoveRows();
return true;
@@ -257,7 +235,7 @@ bool QtTestModel::removeColumns(int column, int count, const QModelIndex & paren
for (int r = 0; r < rCount; ++r)
table[r].remove(c);
- cCount = table.at(0).count();
+ cCount = table.at(0).size();
QAbstractItemModel::endRemoveColumns();
return true;
@@ -285,7 +263,7 @@ bool QtTestModel::moveRows(const QModelIndex &sourceParent, int src, int cnt,
}
}
- rCount = table.count();
+ rCount = table.size();
QAbstractItemModel::endMoveRows();
return true;
@@ -315,7 +293,7 @@ bool QtTestModel::moveColumns(const QModelIndex &sourceParent, int src, int cnt,
}
}
- cCount = table.at(0).count();
+ cCount = table.at(0).size();
QAbstractItemModel::endMoveColumns();
return true;
@@ -439,11 +417,11 @@ 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);
- QCOMPARE(res.count(), 1);
+ QCOMPARE(res.size(), 1);
QModelIndex idx = model.index(1, 0, QModelIndex());
bool areEqual = (idx == res.first());
QVERIFY(areEqual);
@@ -452,44 +430,45 @@ 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.count(), 1);
+ QCOMPARE(res.size(), 1);
res = model.match(start, Qt::DisplayRole, QVariant("a"), -1, Qt::MatchContains);
- QCOMPARE(res.count(), 3);
+ QCOMPARE(res.size(), 4);
res = model.match(start, Qt::DisplayRole, QVariant("b"), -1, Qt::MatchStartsWith);
- QCOMPARE(res.count(), 2);
+ QCOMPARE(res.size(), 3);
res = model.match(start, Qt::DisplayRole, QVariant("t"), -1, Qt::MatchEndsWith);
- QCOMPARE(res.count(), 2);
+ QCOMPARE(res.size(), 2);
res = model.match(start, Qt::DisplayRole, QVariant("*a*"), -1, Qt::MatchWildcard);
- QCOMPARE(res.count(), 3);
+ QCOMPARE(res.size(), 4);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1, Qt::MatchRegularExpression);
- QCOMPARE(res.count(), 2);
+ QCOMPARE(res.size(), 3);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1, Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
- QCOMPARE(res.count(), 0);
+ QCOMPARE(res.size(), 0);
res = model.match(start, Qt::DisplayRole, QVariant("BOAR"), -1, Qt::MatchFixedString);
- QCOMPARE(res.count(), 1);
+ QCOMPARE(res.size(), 1);
res = model.match(start, Qt::DisplayRole, QVariant("bat"), -1,
Qt::MatchFixedString | Qt::MatchCaseSensitive);
- QCOMPARE(res.count(), 1);
+ QCOMPARE(res.size(), 1);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1,
Qt::MatchRegularExpression);
- QCOMPARE(res.count(), 2);
+ QCOMPARE(res.size(), 3);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1,
Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
- QCOMPARE(res.count(), 0);
+ QCOMPARE(res.size(), 0);
res = model.match(start, Qt::DisplayRole, QVariant(QRegularExpression(".*O.*")),
-1, Qt::MatchRegularExpression);
- QCOMPARE(res.count(), 0);
+ QCOMPARE(res.size(), 0);
res = model.match(start,
Qt::DisplayRole,
QVariant(QRegularExpression(".*O.*",
QRegularExpression::CaseInsensitiveOption)),
-1,
Qt::MatchRegularExpression);
- QCOMPARE(res.count(), 2);
+ QCOMPARE(res.size(), 3);
// Ensure that the case sensitivity is properly ignored when passing a
// QRegularExpression object.
@@ -499,7 +478,7 @@ void tst_QAbstractItemModel::match()
QRegularExpression::CaseInsensitiveOption)),
-1,
Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
- QCOMPARE(res.count(), 2);
+ QCOMPARE(res.size(), 3);
}
typedef QPair<int, int> Position;
@@ -782,7 +761,7 @@ void tst_QAbstractItemModel::dropMimeData()
// get the mimeData from the "selected" indexes
QModelIndexList selectedIndexes;
- for (int i = 0; i < selection.count(); ++i)
+ for (int i = 0; i < selection.size(); ++i)
selectedIndexes << src.index(selection.at(i).first, selection.at(i).second, QModelIndex());
QMimeData *md = src.mimeData(selectedIndexes);
// do the drop
@@ -853,8 +832,8 @@ void tst_QAbstractItemModel::removeRows()
QVERIFY(rowsRemovedSpy.isValid());
QCOMPARE(model.removeRows(6, 4), true);
- QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1);
- QCOMPARE(rowsRemovedSpy.count(), 1);
+ QCOMPARE(rowsAboutToBeRemovedSpy.size(), 1);
+ QCOMPARE(rowsRemovedSpy.size(), 1);
}
void tst_QAbstractItemModel::removeColumns()
@@ -868,8 +847,8 @@ void tst_QAbstractItemModel::removeColumns()
QVERIFY(columnsRemovedSpy.isValid());
QCOMPARE(model.removeColumns(6, 4), true);
- QCOMPARE(columnsAboutToBeRemovedSpy.count(), 1);
- QCOMPARE(columnsRemovedSpy.count(), 1);
+ QCOMPARE(columnsAboutToBeRemovedSpy.size(), 1);
+ QCOMPARE(columnsRemovedSpy.size(), 1);
}
void tst_QAbstractItemModel::insertRows()
@@ -883,8 +862,8 @@ void tst_QAbstractItemModel::insertRows()
QVERIFY(rowsInsertedSpy.isValid());
QCOMPARE(model.insertRows(6, 4), true);
- QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1);
- QCOMPARE(rowsInsertedSpy.count(), 1);
+ QCOMPARE(rowsAboutToBeInsertedSpy.size(), 1);
+ QCOMPARE(rowsInsertedSpy.size(), 1);
}
void tst_QAbstractItemModel::insertColumns()
@@ -898,8 +877,8 @@ void tst_QAbstractItemModel::insertColumns()
QVERIFY(columnsInsertedSpy.isValid());
QCOMPARE(model.insertColumns(6, 4), true);
- QCOMPARE(columnsAboutToBeInsertedSpy.count(), 1);
- QCOMPARE(columnsInsertedSpy.count(), 1);
+ QCOMPARE(columnsAboutToBeInsertedSpy.size(), 1);
+ QCOMPARE(columnsInsertedSpy.size(), 1);
}
void tst_QAbstractItemModel::moveRows()
@@ -913,8 +892,8 @@ void tst_QAbstractItemModel::moveRows()
QVERIFY(rowsMovedSpy.isValid());
QCOMPARE(model.moveRows(QModelIndex(), 6, 4, QModelIndex(), 1), true);
- QCOMPARE(rowsAboutToBeMovedSpy.count(), 1);
- QCOMPARE(rowsMovedSpy.count(), 1);
+ QCOMPARE(rowsAboutToBeMovedSpy.size(), 1);
+ QCOMPARE(rowsMovedSpy.size(), 1);
}
void tst_QAbstractItemModel::moveColumns()
@@ -928,12 +907,12 @@ void tst_QAbstractItemModel::moveColumns()
QVERIFY(columnsMovedSpy.isValid());
QCOMPARE(model.moveColumns(QModelIndex(), 6, 4, QModelIndex(), 1), true);
- QCOMPARE(columnsAboutToBeMovedSpy.count(), 1);
- QCOMPARE(columnsMovedSpy.count(), 1);
+ QCOMPARE(columnsAboutToBeMovedSpy.size(), 1);
+ QCOMPARE(columnsMovedSpy.size(), 1);
QCOMPARE(model.moveColumn(QModelIndex(), 4, QModelIndex(), 1), true);
- QCOMPARE(columnsAboutToBeMovedSpy.count(), 2);
- QCOMPARE(columnsMovedSpy.count(), 2);
+ QCOMPARE(columnsAboutToBeMovedSpy.size(), 2);
+ QCOMPARE(columnsMovedSpy.size(), 2);
}
void tst_QAbstractItemModel::reset()
@@ -943,7 +922,7 @@ void tst_QAbstractItemModel::reset()
QSignalSpy resetSpy(&model, &QtTestModel::modelReset);
QVERIFY(resetSpy.isValid());
model.reset();
- QCOMPARE(resetSpy.count(), 1);
+ QCOMPARE(resetSpy.size(), 1);
}
void tst_QAbstractItemModel::complexChangesWithPersistent()
@@ -1008,6 +987,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");
@@ -1872,7 +1872,7 @@ void ListenerObject::slotAboutToBeReset()
void ListenerObject::slotReset()
{
- for (const auto &idx : qAsConst(m_persistentIndexes)) {
+ for (const auto &idx : std::as_const(m_persistentIndexes)) {
QVERIFY(!idx.isValid());
}
}