summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMark Brand <mabrand@mabrand.nl>2012-02-10 00:47:33 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-15 02:36:21 +0100
commit555aa4439b3a4a2c5fd12b6ac155b87fe69e749f (patch)
treec6f73e6b6efe42038d940b3252d92dc212e967b0 /tests/auto
parent76418628f14ff555242d7819e6cbcc6191c44360 (diff)
QSqlTableModel::commitAll(): replace row removal hack
The purpose of the hack was to fool QSqlQueryModel into signaling the removal of extra rows via rowsRemoved(). The extra rows are the inserted rows generated by QSqlTableModel. While it is important to signal the removal of all the rows before requerying after committing changes, there is a cleaner way. The table model should remove its rows before the query model removes its rows. Iterating backwards avoids having to decrement row numbers above ones being removed. Expected test results have been adjusted for these changes. Change-Id: I0e8aa81f5e7b8fea5922f5ffd1cfb4a932313a10 Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
index c0bdfae8b7..270de8292b 100644
--- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
+++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
@@ -1199,9 +1199,13 @@ void tst_QSqlTableModel::insertRecordsInLoop()
model.submitAll(); // submitAll() calls select() which clears and repopulates the table
int firstRowIndex = 0, lastRowIndex = 12;
- QCOMPARE(spyRowsRemoved.count(), 1);
- QCOMPARE(spyRowsRemoved.at(0).at(1).toInt(), firstRowIndex);
- QCOMPARE(spyRowsRemoved.at(0).at(2).toInt(), lastRowIndex);
+ 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);