diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-11-04 05:03:02 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-11-04 05:06:34 (GMT) |
commit | 69b4b690cc26b697675264298623d9974cc76796 (patch) | |
tree | 5fc36cb79696dfab685f780adbd07a39d465e1ec /tests/auto/declarative | |
parent | 63d3766ca2a7f3380d4a67e34497f2f70c42b5f2 (diff) | |
download | Qt-69b4b690cc26b697675264298623d9974cc76796.zip Qt-69b4b690cc26b697675264298623d9974cc76796.tar.gz Qt-69b4b690cc26b697675264298623d9974cc76796.tar.bz2 |
More XmlListModel tests.
Diffstat (limited to 'tests/auto/declarative')
5 files changed, 172 insertions, 23 deletions
diff --git a/tests/auto/declarative/qmlxmllistmodel/data/model.qml b/tests/auto/declarative/qmlxmllistmodel/data/model.qml index 199a447..2cbb027 100644 --- a/tests/auto/declarative/qmlxmllistmodel/data/model.qml +++ b/tests/auto/declarative/qmlxmllistmodel/data/model.qml @@ -2,7 +2,7 @@ import Qt 4.6 XmlListModel { source: "model.xml" - query: "/ListModel/ListElement" + query: "/Pets/Pet" XmlRole { name: "name"; query: "name/string()" } XmlRole { name: "type"; query: "type/string()" } XmlRole { name: "age"; query: "age/number()" } diff --git a/tests/auto/declarative/qmlxmllistmodel/data/model.xml b/tests/auto/declarative/qmlxmllistmodel/data/model.xml index f1fe742..40cd6d0 100644 --- a/tests/auto/declarative/qmlxmllistmodel/data/model.xml +++ b/tests/auto/declarative/qmlxmllistmodel/data/model.xml @@ -1,56 +1,54 @@ -<ListModel> - <ListElement> +<Pets> + <Pet> <name>Polly</name> <type>Parrot</type> <age>12</age> <size>Small</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Penny</name> <type>Turtle</type> <age>4</age> <size>Small</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Warren</name> <type>Rabbit</type> <age>2</age> <size>Small</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Spot</name> <type>Dog</type> <age>9</age> <size>Medium</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Whiskers</name> <type>Cat</type> <age>2</age> <size>Medium</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Joey</name> <type>Kangaroo</type> <age>1</age> - <size>Medium</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Kimba</name> <type>Bunny</type> <age>65</age> <size>Large</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Rover</name> <type>Dog</type> - <age>5</age> <size>Large</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Tiny</name> <type>Elephant</type> <age>15</age> <size>Large</size> - </ListElement> -</ListModel> + </Pet> +</Pets> diff --git a/tests/auto/declarative/qmlxmllistmodel/data/recipes.qml b/tests/auto/declarative/qmlxmllistmodel/data/recipes.qml new file mode 100644 index 0000000..13dea91 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/data/recipes.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +XmlListModel { + source: "recipes.xml" + query: "/recipes/recipe" + XmlRole { name: "title"; query: "@title/string()" } + XmlRole { name: "picture"; query: "picture/string()" } + XmlRole { name: "ingredients"; query: "ingredients/string()" } + XmlRole { name: "preparation"; query: "method/string()" } +} diff --git a/tests/auto/declarative/qmlxmllistmodel/data/recipes.xml b/tests/auto/declarative/qmlxmllistmodel/data/recipes.xml new file mode 100644 index 0000000..d71de60 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/data/recipes.xml @@ -0,0 +1,90 @@ +<recipes> + <recipe title="Pancakes"> + <picture>content/pics/pancakes.jpg</picture> + <ingredients><![CDATA[<html> + <ul> + <li> 1 cup (150g) self-raising flour + <li> 1 tbs caster sugar + <li> 3/4 cup (185ml) milk + <li> 1 egg + </ul> + </html> + ]]></ingredients> + <method><![CDATA[<html> + <ol> + <li> Sift flour and sugar together into a bowl. Add a pinch of salt. + <li> Beat milk and egg together, then add to dry ingredients. Beat until smooth. + <li> Pour mixture into a pan on medium heat and cook until bubbles appear on the surface. + <li> Turn over and cook other side until golden. + </ol> + </html> + ]]></method> + </recipe> + <recipe title="Fruit Salad"> + <picture>content/pics/fruit-salad.jpg</picture> + <ingredients><![CDATA[* Seasonal Fruit]]></ingredients> + <method><![CDATA[* Chop fruit and place in a bowl.]]></method> + </recipe> + <recipe title="Vegetable Soup"> + <picture>content/pics/vegetable-soup.jpg</picture> + <ingredients><![CDATA[<html> + <ul> + <li> 1 onion + <li> 1 turnip + <li> 1 potato + <li> 1 carrot + <li> 1 head of celery + <li> 1 1/2 litres of water + </ul> + </html> + ]]></ingredients> + <method><![CDATA[<html> + <ol> + <li> Chop vegetables. + <li> Boil in water until vegetables soften. + <li> Season with salt and pepper to taste. + </ol> + </html> + ]]></method> + </recipe> + <recipe title="Hamburger"> + <picture>content/pics/hamburger.jpg</picture> + <ingredients><![CDATA[<html> + <ul> + <li> 500g minced beef + <li> Seasoning + <li> lettuce, tomato, onion, cheese + <li> 1 hamburger bun for each burger + </ul> + </html> + ]]></ingredients> + <method><![CDATA[<html> + <ol> + <li> Mix the beef, together with seasoning, in a food processor. + <li> Shape the beef into burgers. + <li> Grill the burgers for about 5 mins on each side (until cooked through) + <li> Serve each burger on a bun with ketchup, cheese, lettuce, tomato and onion. + </ol> + </html> + ]]></method> + </recipe> + <recipe title="Lemonade"> + <picture>content/pics/lemonade.jpg</picture> + <ingredients><![CDATA[<html> + <ul> + <li> 1 cup Lemon Juice + <li> 1 cup Sugar + <li> 6 Cups of Water (2 cups warm water, 4 cups cold water) + </ul> + </html> + ]]></ingredients> + <method><![CDATA[<html> + <ol> + <li> Pour 2 cups of warm water into a pitcher and stir in sugar until it dissolves. + <li> Pour in lemon juice, stir again, and add 4 cups of cold water. + <li> Chill or serve over ice cubes. + </ol> + </html> + ]]></method> + </recipe> +</recipes> diff --git a/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp index 0fc9006..4898686 100644 --- a/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp +++ b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp @@ -53,6 +53,9 @@ public: private slots: void buildModel(); + void missingFields(); + void cdata(); + void attributes(); private: QmlEngine engine; @@ -75,6 +78,54 @@ void tst_qmlxmllistmodel::buildModel() QCOMPARE(data.value(Qt::UserRole+3).toString(), QLatin1String("Medium")); } +void tst_qmlxmllistmodel::missingFields() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/model2.qml")); + QmlXmlListModel *listModel = qobject_cast<QmlXmlListModel*>(component.create()); + QVERIFY(listModel != 0); + QTRY_COMPARE(listModel->count(), 9); + + QList<int> roles; + roles << Qt::UserRole << Qt::UserRole + 1 << Qt::UserRole + 2 << Qt::UserRole + 3 << Qt::UserRole + 4; + QHash<int, QVariant> data = listModel->data(5, roles); + QVERIFY(data.count() == 5); + QCOMPARE(data.value(Qt::UserRole+3).toString(), QLatin1String("")); + QCOMPARE(data.value(Qt::UserRole+4).toString(), QLatin1String("")); + + data = listModel->data(7, roles); + QVERIFY(data.count() == 5); + QCOMPARE(data.value(Qt::UserRole+2).toString(), QLatin1String("")); +} + +void tst_qmlxmllistmodel::cdata() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/recipes.qml")); + QmlXmlListModel *listModel = qobject_cast<QmlXmlListModel*>(component.create()); + QVERIFY(listModel != 0); + QTRY_COMPARE(listModel->count(), 5); + + QList<int> roles; + roles << Qt::UserRole + 2; + QHash<int, QVariant> data = listModel->data(2, roles); + QVERIFY(data.count() == 1); + QVERIFY(data.value(Qt::UserRole+2).toString().startsWith(QLatin1String("<html>"))); +} + +void tst_qmlxmllistmodel::attributes() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/recipes.qml")); + QmlXmlListModel *listModel = qobject_cast<QmlXmlListModel*>(component.create()); + QVERIFY(listModel != 0); + QTRY_COMPARE(listModel->count(), 5); + + QList<int> roles; + roles << Qt::UserRole; + QHash<int, QVariant> data = listModel->data(2, roles); + QVERIFY(data.count() == 1); + QCOMPARE(data.value(Qt::UserRole).toString(), QLatin1String("Vegetable Soup")); +} + + QTEST_MAIN(tst_qmlxmllistmodel) #include "tst_qmlxmllistmodel.moc" |