summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@digia.com>2013-11-07 16:04:42 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-18 16:27:57 +0100
commitea61e04a41f22638aef36f0aa0b51a8121a47f1d (patch)
tree633cd7d3e80872751e076da9ce7a641eaba7662b /tests
parent380cfc951baa3c0405bd32cdefdd3300619d2c32 (diff)
downloadqtenginio-ea61e04a41f22638aef36f0aa0b51a8121a47f1d.tar.gz
Fix EnginioModel::setData
The code was not checking for rows indexes smaller then 0. Change-Id: I39d4fad06809977e3cec0f7b7dc85f3814c0dcfa Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/enginiomodel/tst_enginiomodel.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/enginiomodel/tst_enginiomodel.cpp b/tests/auto/enginiomodel/tst_enginiomodel.cpp
index cfb96ad..5e9aa49 100644
--- a/tests/auto/enginiomodel/tst_enginiomodel.cpp
+++ b/tests/auto/enginiomodel/tst_enginiomodel.cpp
@@ -96,6 +96,7 @@ private slots:
void appendAndChangeQueryBeforeItIsFinished();
void deleteModelDurringRequests();
void updatingRoles();
+ void setData();
private:
template<class T>
void externallyRemovedImpl();
@@ -1426,5 +1427,64 @@ void tst_EnginioModel::updatingRoles()
QCOMPARE(model.roleNames()[CustomModel::InvalidRole], QByteArray("objectType"));
}
+void tst_EnginioModel::setData()
+{
+ QString propertyName = "title";
+ QString objectType = "objects." + EnginioTests::CUSTOM_OBJECT1;
+ QJsonObject query;
+ query.insert("objectType", objectType);
+
+ EnginioClient client;
+ client.setBackendId(_backendId);
+ client.setServiceUrl(EnginioTests::TESTAPP_URL);
+
+ struct Model: public EnginioModel {
+ enum Roles {
+ TitleRole = EnginioModel::LastRole
+ };
+
+ virtual QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE
+ {
+ QHash<int, QByteArray> roles = EnginioModel::roleNames();
+ roles.insert(TitleRole, "title");
+ return roles;
+ }
+ } model;
+
+ model.disableNotifications();
+ model.setQuery(query);
+
+ { // init the model
+ QSignalSpy spy(&model, SIGNAL(modelReset()));
+ model.setEnginio(&client);
+
+ QTRY_VERIFY(spy.count() > 0);
+ }
+
+ if (model.rowCount() < 1) {
+ QJsonObject o;
+ o.insert(propertyName, QString::fromLatin1("o"));
+ o.insert("objectType", objectType);
+ model.append(o);
+ }
+
+ // try to get data through an invalid index
+ QCOMPARE(model.data(model.index(-1)), QVariant());
+ QCOMPARE(model.data(model.index(-1, 1)), QVariant());
+ QCOMPARE(model.data(model.index(model.rowCount() + 3)), QVariant());
+ QCOMPARE(model.data(model.index(model.rowCount())), QVariant());
+
+ QTRY_VERIFY(model.rowCount() > 0);
+
+ // try to set data through an invalid index
+ QVERIFY(!model.setData(model.index(model.rowCount()), QVariant()));
+ QVERIFY(!model.setData(model.index(model.rowCount() + 3), QVariant()));
+ QVERIFY(!model.setData(model.index(-1), QVariant()));
+ QVERIFY(!model.setData(model.index(-1, 1), QVariant()));
+
+ // make a correct setData call
+ QVERIFY(model.setData(model.index(0), QString::fromLatin1("1111"), Model::TitleRole));
+}
+
QTEST_MAIN(tst_EnginioModel)
#include "tst_enginiomodel.moc"