summaryrefslogtreecommitdiffstats
path: root/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp')
-rw-r--r--tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp91
1 files changed, 33 insertions, 58 deletions
diff --git a/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp b/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
index ac94961a84..a669c72a1e 100644
--- a/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
+++ b/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** 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>
@@ -87,9 +62,9 @@ private slots:
void task_QTBUG_4963_setHeaderDataWithProxyModel();
private:
- void generic_data(const QString &engine=QString());
- void dropTestTables(QSqlDatabase db);
- void createTestTables(QSqlDatabase db);
+ void generic_data(const QString &engine = QString());
+ void dropTestTables(const QSqlDatabase &db);
+ void createTestTables(const QSqlDatabase &db);
void populateTestTables(QSqlDatabase db);
tst_Databases dbs;
};
@@ -98,8 +73,8 @@ private:
class DBTestModel: public QSqlQueryModel
{
public:
- DBTestModel(QObject *parent = nullptr): QSqlQueryModel(parent) {}
- QModelIndex indexInQuery(const QModelIndex &item) const { return QSqlQueryModel::indexInQuery(item); }
+ using QSqlQueryModel::QSqlQueryModel;
+ using QSqlQueryModel::indexInQuery;
};
tst_QSqlQueryModel::tst_QSqlQueryModel()
@@ -113,8 +88,8 @@ tst_QSqlQueryModel::~tst_QSqlQueryModel()
void tst_QSqlQueryModel::initTestCase()
{
QVERIFY(dbs.open());
- for (QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it) {
- QSqlDatabase db = QSqlDatabase::database((*it));
+ for (const auto &dbName : std::as_const(dbs.dbNames)) {
+ QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
dropTestTables(db); //in case of leftovers
createTestTables(db);
@@ -124,15 +99,15 @@ void tst_QSqlQueryModel::initTestCase()
void tst_QSqlQueryModel::cleanupTestCase()
{
- for (QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it) {
- QSqlDatabase db = QSqlDatabase::database((*it));
+ for (const auto &dbName : std::as_const(dbs.dbNames)) {
+ QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
dropTestTables(db);
}
dbs.close();
}
-void tst_QSqlQueryModel::dropTestTables(QSqlDatabase db)
+void tst_QSqlQueryModel::dropTestTables(const QSqlDatabase &db)
{
QStringList tableNames;
tableNames << qTableName("test", __FILE__, db)
@@ -142,7 +117,7 @@ void tst_QSqlQueryModel::dropTestTables(QSqlDatabase db)
tst_Databases::safeDropTables(db, tableNames);
}
-void tst_QSqlQueryModel::createTestTables(QSqlDatabase db)
+void tst_QSqlQueryModel::createTestTables(const QSqlDatabase &db)
{
dropTestTables(db);
QSqlQuery q(db);
@@ -227,7 +202,7 @@ void tst_QSqlQueryModel::removeColumn()
QCOMPARE(model.columnCount(), 3);
QVERIFY(model.removeColumn(0));
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QVERIFY(*(QModelIndex *)spy.at(0).at(0).constData() == QModelIndex());
QCOMPARE(spy.at(0).at(1).toInt(), 0);
QCOMPARE(spy.at(0).at(2).toInt(), 0);
@@ -257,7 +232,7 @@ void tst_QSqlQueryModel::removeColumn()
QVERIFY(model.removeColumn(2));
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
QVERIFY(*(QModelIndex *)spy.at(1).at(0).constData() == QModelIndex());
QCOMPARE(spy.at(1).at(1).toInt(), 2);
QCOMPARE(spy.at(1).at(2).toInt(), 2);
@@ -270,7 +245,7 @@ void tst_QSqlQueryModel::removeColumn()
QVERIFY(model.removeColumn(1));
- QCOMPARE(spy.count(), 3);
+ QCOMPARE(spy.size(), 3);
QVERIFY(*(QModelIndex *)spy.at(2).at(0).constData() == QModelIndex());
QCOMPARE(spy.at(2).at(1).toInt(), 1);
QCOMPARE(spy.at(2).at(2).toInt(), 1);
@@ -284,7 +259,7 @@ void tst_QSqlQueryModel::removeColumn()
QVERIFY(model.removeColumn(0));
- QCOMPARE(spy.count(), 4);
+ QCOMPARE(spy.size(), 4);
QVERIFY(*(QModelIndex *)spy.at(3).at(0).constData() == QModelIndex());
QCOMPARE(spy.at(3).at(1).toInt(), 0);
QCOMPARE(spy.at(3).at(2).toInt(), 0);
@@ -326,7 +301,7 @@ void tst_QSqlQueryModel::insertColumn()
QVERIFY(model.insertColumn(1));
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QVERIFY(*(QModelIndex *)spy.at(0).at(0).constData() == QModelIndex());
QCOMPARE(spy.at(0).at(1).toInt(), 1);
QCOMPARE(spy.at(0).at(2).toInt(), 1);
@@ -355,7 +330,7 @@ void tst_QSqlQueryModel::insertColumn()
QVERIFY(model.insertColumn(0));
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
QVERIFY(*(QModelIndex *)spy.at(1).at(0).constData() == QModelIndex());
QCOMPARE(spy.at(1).at(1).toInt(), 0);
QCOMPARE(spy.at(1).at(2).toInt(), 0);
@@ -370,7 +345,7 @@ void tst_QSqlQueryModel::insertColumn()
QVERIFY(!model.insertColumn(6));
QVERIFY(model.insertColumn(5));
- QCOMPARE(spy.count(), 3);
+ QCOMPARE(spy.size(), 3);
QVERIFY(*(QModelIndex *)spy.at(2).at(0).constData() == QModelIndex());
QCOMPARE(spy.at(2).at(1).toInt(), 5);
QCOMPARE(spy.at(2).at(2).toInt(), 5);
@@ -449,7 +424,7 @@ void tst_QSqlQueryModel::setHeaderData()
QSignalSpy spy(&model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)));
QVERIFY(model.setHeaderData(2, Qt::Horizontal, "bar"));
QCOMPARE(model.headerData(2, Qt::Horizontal).toString(), QString("bar"));
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QCOMPARE(qvariant_cast<Qt::Orientation>(spy.value(0).value(0)), Qt::Horizontal);
QCOMPARE(spy.value(0).value(1).toInt(), 2);
QCOMPARE(spy.value(0).value(2).toInt(), 2);
@@ -477,8 +452,8 @@ void tst_QSqlQueryModel::fetchMore()
model.setQuery(QSqlQuery("select * from " + qTableName("many", __FILE__, db), db));
int rowCount = model.rowCount();
- QCOMPARE(modelAboutToBeResetSpy.count(), 1);
- QCOMPARE(modelResetSpy.count(), 1);
+ QCOMPARE(modelAboutToBeResetSpy.size(), 1);
+ QCOMPARE(modelResetSpy.size(), 1);
// If the driver doesn't return the query size fetchMore() causes the
// model to grow and new signals are emitted
@@ -524,11 +499,11 @@ void tst_QSqlQueryModel::withSortFilterProxyModel()
QCOMPARE(proxy.rowCount(), 511);
// setQuery() resets the model accompanied by begin and end signals
- QCOMPARE(modelAboutToBeResetSpy.count(), 1);
- QCOMPARE(modelResetSpy.count(), 1);
+ QCOMPARE(modelAboutToBeResetSpy.size(), 1);
+ QCOMPARE(modelResetSpy.size(), 1);
// The call to scrollToBottom() forces the model to fetch additional rows.
- QCOMPARE(modelRowsInsertedSpy.count(), 1);
+ QCOMPARE(modelRowsInsertedSpy.size(), 1);
QCOMPARE(modelRowsInsertedSpy.value(0).value(1).toInt(), 256);
QCOMPARE(modelRowsInsertedSpy.value(0).value(2).toInt(), 510);
}
@@ -548,14 +523,14 @@ void tst_QSqlQueryModel::setQuerySignalEmission()
// First select, the model was empty and no rows had to be removed, but model resets anyway.
model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test", __FILE__, db), db));
- QCOMPARE(modelAboutToBeResetSpy.count(), 1);
- QCOMPARE(modelResetSpy.count(), 1);
+ QCOMPARE(modelAboutToBeResetSpy.size(), 1);
+ QCOMPARE(modelResetSpy.size(), 1);
// Second select, the model wasn't empty and two rows had to be removed!
// setQuery() resets the model accompanied by begin and end signals
model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test", __FILE__, db), db));
- QCOMPARE(modelAboutToBeResetSpy.count(), 2);
- QCOMPARE(modelResetSpy.count(), 2);
+ QCOMPARE(modelAboutToBeResetSpy.size(), 2);
+ QCOMPARE(modelResetSpy.size(), 2);
}
// For task 170783: When the query's result set is empty no rows should be inserted,
@@ -573,9 +548,9 @@ void tst_QSqlQueryModel::setQueryWithNoRowsInResultSet()
// The query's result set will be empty so no signals should be emitted!
QSqlQuery query(db);
QVERIFY_SQL(query, exec("SELECT * FROM " + qTableName("test", __FILE__, db) + " where 0 = 1"));
- model.setQuery(query);
- QCOMPARE(modelRowsAboutToBeInsertedSpy.count(), 0);
- QCOMPARE(modelRowsInsertedSpy.count(), 0);
+ model.setQuery(std::move(query));
+ QCOMPARE(modelRowsAboutToBeInsertedSpy.size(), 0);
+ QCOMPARE(modelRowsInsertedSpy.size(), 0);
}
class NestedResetsTest: public QSqlQueryModel