summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativexmllistmodel
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-05-20 06:42:06 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-05-21 00:11:34 (GMT)
commit30b490476bad5d486332093fc672856a8dd6a195 (patch)
treed33650d24441fd2dc4d91076fca6821aedcb9d83 /tests/auto/declarative/qdeclarativexmllistmodel
parent0a2ef85bc7c560f38f5ba591968ce49969893a1c (diff)
downloadQt-30b490476bad5d486332093fc672856a8dd6a195.zip
Qt-30b490476bad5d486332093fc672856a8dd6a195.tar.gz
Qt-30b490476bad5d486332093fc672856a8dd6a195.tar.bz2
Add XmlListModel::get()
Task-number: QTBUG-10761
Diffstat (limited to 'tests/auto/declarative/qdeclarativexmllistmodel')
-rw-r--r--tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
index 7769979..e1dd6f4 100644
--- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
@@ -81,6 +81,7 @@ private slots:
void source();
void source_data();
void data();
+ void get();
void reload();
void useKeys();
void useKeys_data();
@@ -388,6 +389,46 @@ void tst_qdeclarativexmllistmodel::data()
delete model;
}
+void tst_qdeclarativexmllistmodel::get()
+{
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+ QVERIFY(model->get(0).isUndefined());
+
+ QTRY_COMPARE(model->count(), 9);
+ QVERIFY(model->get(-1).isUndefined());
+
+ QScriptValue sv = model->get(0);
+ QCOMPARE(sv.property("name").toString(), QLatin1String("Polly"));
+ QCOMPARE(sv.property("type").toString(), QLatin1String("Parrot"));
+ QCOMPARE(sv.property("age").toNumber(), qsreal(12));
+ QCOMPARE(sv.property("size").toString(), QLatin1String("Small"));
+
+ sv = model->get(1);
+ QCOMPARE(sv.property("name").toString(), QLatin1String("Penny"));
+ QCOMPARE(sv.property("type").toString(), QLatin1String("Turtle"));
+ QCOMPARE(sv.property("age").toNumber(), qsreal(4));
+ QCOMPARE(sv.property("size").toString(), QLatin1String("Small"));
+
+ sv = model->get(7);
+ QCOMPARE(sv.property("name").toString(), QLatin1String("Rover"));
+ QCOMPARE(sv.property("type").toString(), QLatin1String("Dog"));
+ QCOMPARE(sv.property("age").toNumber(), qsreal(0));
+ QCOMPARE(sv.property("size").toString(), QLatin1String("Large"));
+
+ sv = model->get(8);
+ QCOMPARE(sv.property("name").toString(), QLatin1String("Tiny"));
+ QCOMPARE(sv.property("type").toString(), QLatin1String("Elephant"));
+ QCOMPARE(sv.property("age").toNumber(), qsreal(15));
+ QCOMPARE(sv.property("size").toString(), QLatin1String("Large"));
+
+ sv = model->get(9);
+ QVERIFY(sv.isUndefined());
+
+ delete model;
+}
+
void tst_qdeclarativexmllistmodel::reload()
{
// If no keys are used, the model should be rebuilt from scratch when