diff options
author | Tapani Mikola <tapani.mikola@nokia.com> | 2012-06-11 14:39:11 +0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-11 15:24:35 +0200 |
commit | 9ff47024513a024ecfc34540e1670d8d80c0f48d (patch) | |
tree | 82e25f69347a234c78265fa87192e8f1efa28031 /tests | |
parent | b80efec0b680d925efc30174b6721c0db0d8c741 (diff) |
Fix a crash in query model
Query model (and list model that uses it) was crashing, if
query was changed while the model had pending queries.
Change-Id: Ibaa5c72696d201200ba4e5c53d17594625df3b97
Reviewed-by: Jamey Hicks <jamey.hicks@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp | 64 | ||||
-rw-r--r-- | tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.h | 2 |
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp b/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp index fe2f8296..e591caaf 100644 --- a/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp +++ b/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp @@ -1609,6 +1609,66 @@ void TestJsonDbCachingListModel::useDataToGetUuidAndIndexValue() delete queryModel; } +void TestJsonDbCachingListModel::changeQueryWhileQuerying() +{ + resetWaitFlags(); + + createIndex("anotherNumber2", "number"); + + for (int i=0; i < 1000; i++) { + QVariantMap item; + item.insert("_type", __FUNCTION__); + item.insert("anotherNumber2", i); + int id = i%2 ? create(item, "com.nokia.shared.1") : create(item, "com.nokia.shared.2"); + waitForResponse1(id); + } + + QJsonDbQueryModel *queryModel = new QJsonDbQueryModel(QJsonDbConnection::defaultConnection(), this); + queryModel->setSortOrder(QString("[/anotherNumber2]")); + queryModel->setQuery(QString("[?_type=\"%1\"]").arg(__FUNCTION__)); + queryModel->setCacheSize(100); + queryModel->setPartitionNames(QStringList() << "com.nokia.shared.1" << "com.nokia.shared.2"); + queryModel->setQueryRoleNames(QStringList() << "_type" << "_uuid" << "_indexValue" << "anotherNumber2"); + connectListModel(queryModel); + + queryModel->populate(); + + mWaitingForQueryingState = true; + waitForExitOrTimeout(); + QCOMPARE(mWaitingForQueryingState, false); + + queryModel->setQuery(QString("[?_type=\"foo\"]")); + + mWaitingForReset = true; + waitForExitOrTimeout(); + QCOMPARE(mWaitingForReset, false); + + QCOMPARE(queryModel->rowCount(), 0); + + queryModel->setQuery(QString("[?_type=\"%1\"]").arg(__FUNCTION__)); + + mWaitingForReset = true; + waitForExitOrTimeout(); + QCOMPARE(mWaitingForReset, false); + + QCOMPARE(queryModel->rowCount(), 1000); + + // Make a query that does not hit cache + // Should put the model into querying state and send the requests + (void)queryModel->data (980, 3); + + // Reset the model by changing the query + queryModel->setQuery(QString("[?_type=\"foo\"]")); + + mWaitingForReset = true; + waitForExitOrTimeout(); + QCOMPARE(mWaitingForReset, false); + + QCOMPARE(queryModel->rowCount(), 0); + + delete queryModel; +} + QStringList TestJsonDbCachingListModel::getOrderValues(QAbstractListModel *listModel) { QStringList vals; @@ -1680,6 +1740,9 @@ void TestJsonDbCachingListModel::stateChanged() if (model->property("state").toInt() == 2 && mWaitingForStateChanged) { mWaitingForStateChanged = false; eventLoop1.exit(0); + } else if (model->property("state").toInt() == 1 && mWaitingForQueryingState) { + mWaitingForQueryingState = false; + eventLoop1.exit(0); } } @@ -1773,6 +1836,7 @@ void TestJsonDbCachingListModel::resetWaitFlags() mWaitingForReset = false; mWaitingForChanged = false; mWaitingForRemoved = false; + mWaitingForQueryingState = false; } void TestJsonDbCachingListModel::waitForItemChanged(bool waitForRemove) diff --git a/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.h b/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.h index f0e39a10..7a854c21 100644 --- a/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.h +++ b/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.h @@ -103,6 +103,7 @@ private slots: void roleNames(); void getItemNotInCache(); void useDataToGetUuidAndIndexValue(); + void changeQueryWhileQuerying(); public: void timeout(); private: @@ -134,6 +135,7 @@ private: int mItemsUpdated; int mItemsRemoved; bool mWaitingForStateChanged; + bool mWaitingForQueryingState; bool mWaitingForRowsInserted; bool mWaitingForReset; bool mWaitingForChanged; |