From 16fe846058aa0a89577660d18bdc0aceda7fecfd Mon Sep 17 00:00:00 2001 From: Derick Hawcroft Date: Mon, 15 Jun 2009 11:16:59 +1000 Subject: Adds unit test for task: 180617 Tests to see if QSqlQueryModel inserts extra empty gridlines into a view for a specific SQL query statement that should return no data. --- tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp | 45 +++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp b/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp index 88b5770..051764e 100644 --- a/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp +++ b/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp @@ -94,6 +94,9 @@ private slots: void setQueryWithNoRowsInResultSet_data() { generic_data(); } void setQueryWithNoRowsInResultSet(); + void task_180617(); + void task_180617_data() { generic_data(); } + private: void generic_data(const QString &engine=QString()); void dropTestTables(QSqlDatabase db); @@ -496,7 +499,7 @@ void tst_QSqlQueryModel::withSortFilterProxyModel() QSignalSpy modelRowsInsertedSpy(&model, SIGNAL(rowsInserted(const QModelIndex &, int, int))); model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test3"), db)); view.scrollToBottom(); - + QTestEventLoop::instance().enterLoop(1); QCOMPARE(proxy.rowCount(), 511); @@ -530,12 +533,12 @@ void tst_QSqlQueryModel::setQuerySignalEmission() QSignalSpy modelRowsRemovedSpy(&model, SIGNAL(rowsRemoved(const QModelIndex &, int, int))); // First select, the model was empty and no rows had to be removed! - model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test"), db)); + model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test"), db)); QCOMPARE(modelRowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(modelRowsRemovedSpy.count(), 0); // Second select, the model wasn't empty and two rows had to be removed! - model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test"), db)); + model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test"), db)); QCOMPARE(modelRowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(modelRowsAboutToBeRemovedSpy.value(0).value(1).toInt(), 0); QCOMPARE(modelRowsAboutToBeRemovedSpy.value(0).value(2).toInt(), 1); @@ -559,10 +562,44 @@ 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") + " where 0 = 1")); - model.setQuery(query); + model.setQuery(query); QCOMPARE(modelRowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(modelRowsInsertedSpy.count(), 0); } +// For task 180617 +// According to the task, several specific duplicate SQL queries would cause +// multiple empty grid lines to be visible in the view +void tst_QSqlQueryModel::task_180617() +{ + QFETCH(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + QTableView view; + QCOMPARE(view.columnAt(0), -1); + QCOMPARE(view.rowAt(0), -1); + + QSqlQueryModel model; + model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db ); + view.setModel(&model); + + bool error = false; + // Usually a syntax error + if (model.lastError().isValid()) // usually a syntax error + error = true; + + QCOMPARE(view.columnAt(0), (error)?-1:0 ); + QCOMPARE(view.rowAt(0), -1); + + model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db ); + model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db ); + model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db ); + model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db ); + + QCOMPARE(view.columnAt(0), (error)?-1:0 ); + QCOMPARE(view.rowAt(0), -1); +} + QTEST_MAIN(tst_QSqlQueryModel) #include "tst_qsqlquerymodel.moc" -- cgit v0.12