summaryrefslogtreecommitdiffstats
path: root/tests/auto/sql/models
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/sql/models')
-rw-r--r--tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp56
-rw-r--r--tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp52
2 files changed, 34 insertions, 74 deletions
diff --git a/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp b/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
index 33793c013d..1c1319630e 100644
--- a/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
+++ b/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
@@ -478,22 +478,23 @@ void tst_QSqlQueryModel::fetchMore()
CHECK_DATABASE(db);
QSqlQueryModel model;
- QSignalSpy spy(&model, SIGNAL(rowsInserted(QModelIndex, int, int)));
+ QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset()));
+ QSignalSpy modelResetSpy(&model, SIGNAL(modelReset()));
model.setQuery(QSqlQuery("select * from " + qTableName("many", __FILE__), db));
int rowCount = model.rowCount();
- QCOMPARE(spy.value(0).value(1).toInt(), 0);
- QCOMPARE(spy.value(0).value(2).toInt(), rowCount - 1);
+ QCOMPARE(modelAboutToBeResetSpy.count(), 1);
+ QCOMPARE(modelResetSpy.count(), 1);
// If the driver doesn't return the query size fetchMore() causes the
// model to grow and new signals are emitted
+ QSignalSpy rowsInsertedSpy(&model, SIGNAL(rowsInserted(QModelIndex, int, int)));
if (!db.driver()->hasFeature(QSqlDriver::QuerySize)) {
- spy.clear();
model.fetchMore();
int newRowCount = model.rowCount();
- QCOMPARE(spy.value(0).value(1).toInt(), rowCount);
- QCOMPARE(spy.value(0).value(2).toInt(), newRowCount - 1);
+ QCOMPARE(rowsInsertedSpy.value(0).value(1).toInt(), rowCount);
+ QCOMPARE(rowsInsertedSpy.value(0).value(2).toInt(), newRowCount - 1);
}
}
@@ -519,7 +520,8 @@ void tst_QSqlQueryModel::withSortFilterProxyModel()
QTableView view;
view.setModel(&proxy);
- QSignalSpy modelRowsRemovedSpy(&model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)));
+ QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset()));
+ QSignalSpy modelResetSpy(&model, SIGNAL(modelReset()));
QSignalSpy modelRowsInsertedSpy(&model, SIGNAL(rowsInserted(const QModelIndex &, int, int)));
model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test3", __FILE__), db));
view.scrollToBottom();
@@ -528,19 +530,14 @@ void tst_QSqlQueryModel::withSortFilterProxyModel()
QCOMPARE(proxy.rowCount(), 511);
- // The second call to setQuery() clears the model by removing it's rows.
- // Only 256 rows because that is what was cached.
- QCOMPARE(modelRowsRemovedSpy.count(), 1);
- QCOMPARE(modelRowsRemovedSpy.value(0).value(1).toInt(), 0);
- QCOMPARE(modelRowsRemovedSpy.value(0).value(2).toInt(), 255);
-
- // The call to scrollToBottom() forces the model to fetch all rows,
- // which will be done in two steps.
- QCOMPARE(modelRowsInsertedSpy.count(), 2);
- QCOMPARE(modelRowsInsertedSpy.value(0).value(1).toInt(), 0);
- QCOMPARE(modelRowsInsertedSpy.value(0).value(2).toInt(), 255);
- QCOMPARE(modelRowsInsertedSpy.value(1).value(1).toInt(), 256);
- QCOMPARE(modelRowsInsertedSpy.value(1).value(2).toInt(), 510);
+ // setQuery() resets the model accompanied by begin and end signals
+ QCOMPARE(modelAboutToBeResetSpy.count(), 1);
+ QCOMPARE(modelResetSpy.count(), 1);
+
+ // The call to scrollToBottom() forces the model to fetch additional rows.
+ QCOMPARE(modelRowsInsertedSpy.count(), 1);
+ QCOMPARE(modelRowsInsertedSpy.value(0).value(1).toInt(), 256);
+ QCOMPARE(modelRowsInsertedSpy.value(0).value(2).toInt(), 510);
}
// For task 155402: When the model is already empty when setQuery() is called
@@ -553,22 +550,19 @@ void tst_QSqlQueryModel::setQuerySignalEmission()
CHECK_DATABASE(db);
QSqlQueryModel model;
- QSignalSpy modelRowsAboutToBeRemovedSpy(&model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)));
- QSignalSpy modelRowsRemovedSpy(&model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)));
+ QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset()));
+ QSignalSpy modelResetSpy(&model, SIGNAL(modelReset()));
- // First select, the model was empty and no rows had to be removed!
+ // 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));
- QCOMPARE(modelRowsAboutToBeRemovedSpy.count(), 0);
- QCOMPARE(modelRowsRemovedSpy.count(), 0);
+ QCOMPARE(modelAboutToBeResetSpy.count(), 1);
+ QCOMPARE(modelResetSpy.count(), 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));
- QCOMPARE(modelRowsAboutToBeRemovedSpy.count(), 1);
- QCOMPARE(modelRowsAboutToBeRemovedSpy.value(0).value(1).toInt(), 0);
- QCOMPARE(modelRowsAboutToBeRemovedSpy.value(0).value(2).toInt(), 1);
- QCOMPARE(modelRowsRemovedSpy.count(), 1);
- QCOMPARE(modelRowsRemovedSpy.value(0).value(1).toInt(), 0);
- QCOMPARE(modelRowsRemovedSpy.value(0).value(2).toInt(), 1);
+ QCOMPARE(modelAboutToBeResetSpy.count(), 2);
+ QCOMPARE(modelResetSpy.count(), 2);
}
// For task 170783: When the query's result set is empty no rows should be inserted,
diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
index 2cea8b3546..89085df6c9 100644
--- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
+++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
@@ -1338,39 +1338,13 @@ void tst_QSqlTableModel::setFilter()
QCOMPARE(model.rowCount(), 1);
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1);
- QSignalSpy rowsRemovedSpy(&model, SIGNAL(rowsRemoved(QModelIndex,int,int)));
- QSignalSpy rowsAboutToBeRemovedSpy(&model,
- SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)));
- QSignalSpy rowsInsertedSpy(&model, SIGNAL(rowsInserted(QModelIndex,int,int)));
- QSignalSpy rowsAboutToBeInsertedSpy(&model,
- SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)));
+ QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset()));
+ QSignalSpy modelResetSpy(&model, SIGNAL(modelReset()));
model.setFilter("id = 2");
// check the signals
- QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1);
- QCOMPARE(rowsRemovedSpy.count(), 1);
- QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1);
- QCOMPARE(rowsInsertedSpy.count(), 1);
- QList<QVariant> args = rowsAboutToBeRemovedSpy.takeFirst();
- QCOMPARE(args.count(), 3);
- QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), QModelIndex());
- QCOMPARE(args.at(1).toInt(), 0);
- QCOMPARE(args.at(2).toInt(), 0);
- args = rowsRemovedSpy.takeFirst();
- QCOMPARE(args.count(), 3);
- QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), QModelIndex());
- QCOMPARE(args.at(1).toInt(), 0);
- QCOMPARE(args.at(2).toInt(), 0);
- args = rowsInsertedSpy.takeFirst();
- QCOMPARE(args.count(), 3);
- QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), QModelIndex());
- QCOMPARE(args.at(1).toInt(), 0);
- QCOMPARE(args.at(2).toInt(), 0);
- args = rowsAboutToBeInsertedSpy.takeFirst();
- QCOMPARE(args.count(), 3);
- QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), QModelIndex());
- QCOMPARE(args.at(1).toInt(), 0);
- QCOMPARE(args.at(2).toInt(), 0);
+ QCOMPARE(modelAboutToBeResetSpy.count(), 1);
+ QCOMPARE(modelResetSpy.count(), 1);
QCOMPARE(model.rowCount(), 1);
QCOMPARE(model.data(model.index(0, 0)).toInt(), 2);
@@ -1500,7 +1474,8 @@ void tst_QSqlTableModel::insertRecordsInLoop()
record.setValue(1, "Testman");
record.setValue(2, 1);
- QSignalSpy spyRowsRemoved(&model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)));
+ QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset()));
+ QSignalSpy modelResetSpy(&model, SIGNAL(modelReset()));
QSignalSpy spyRowsInserted(&model, SIGNAL(rowsInserted(const QModelIndex &, int, int)));
for (int i = 0; i < 10; i++) {
QVERIFY(model.insertRecord(model.rowCount(), record));
@@ -1509,18 +1484,9 @@ void tst_QSqlTableModel::insertRecordsInLoop()
}
model.submitAll(); // submitAll() calls select() which clears and repopulates the table
- int firstRowIndex = 0, lastRowIndex = 12;
- QCOMPARE(spyRowsRemoved.count(), 11);
- // QSqlTableModel emits 10 signals for its 10 inserted rows
- QCOMPARE(spyRowsRemoved.at(0).at(1).toInt(), lastRowIndex);
- QCOMPARE(spyRowsRemoved.at(9).at(1).toInt(), firstRowIndex + 3);
- // QSqlQueryModel emits 1 signal for its 3 rows
- QCOMPARE(spyRowsRemoved.at(10).at(1).toInt(), firstRowIndex);
- QCOMPARE(spyRowsRemoved.at(10).at(2).toInt(), firstRowIndex + 2);
-
- QCOMPARE(spyRowsInserted.at(10).at(1).toInt(), firstRowIndex);
- QCOMPARE(spyRowsInserted.at(10).at(2).toInt(), lastRowIndex);
- QCOMPARE(spyRowsInserted.count(), 11);
+ // model emits reset signals
+ QCOMPARE(modelAboutToBeResetSpy.count(), 1);
+ QCOMPARE(modelResetSpy.count(), 1);
QCOMPARE(model.rowCount(), 13);
QCOMPARE(model.columnCount(), 3);