From 69b4b690cc26b697675264298623d9974cc76796 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 15:03:02 +1000 Subject: More XmlListModel tests. --- .../declarative/qmlxmllistmodel/data/model.qml | 2 +- .../declarative/qmlxmllistmodel/data/model.xml | 42 +++++----- .../declarative/qmlxmllistmodel/data/recipes.qml | 10 +++ .../declarative/qmlxmllistmodel/data/recipes.xml | 90 ++++++++++++++++++++++ .../qmlxmllistmodel/tst_qmlxmllistmodel.cpp | 51 ++++++++++++ 5 files changed, 172 insertions(+), 23 deletions(-) create mode 100644 tests/auto/declarative/qmlxmllistmodel/data/recipes.qml create mode 100644 tests/auto/declarative/qmlxmllistmodel/data/recipes.xml 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 @@ - - + + Polly Parrot 12 Small - - + + Penny Turtle 4 Small - - + + Warren Rabbit 2 Small - - + + Spot Dog 9 Medium - - + + Whiskers Cat 2 Medium - - + + Joey Kangaroo 1 - Medium - - + + Kimba Bunny 65 Large - - + + Rover Dog - 5 Large - - + + Tiny Elephant 15 Large - - + + 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 @@ + + + content/pics/pancakes.jpg + +
    +
  • 1 cup (150g) self-raising flour +
  • 1 tbs caster sugar +
  • 3/4 cup (185ml) milk +
  • 1 egg +
+ + ]]>
+ +
    +
  1. Sift flour and sugar together into a bowl. Add a pinch of salt. +
  2. Beat milk and egg together, then add to dry ingredients. Beat until smooth. +
  3. Pour mixture into a pan on medium heat and cook until bubbles appear on the surface. +
  4. Turn over and cook other side until golden. +
+ + ]]>
+
+ + content/pics/fruit-salad.jpg + + + + + content/pics/vegetable-soup.jpg + +
    +
  • 1 onion +
  • 1 turnip +
  • 1 potato +
  • 1 carrot +
  • 1 head of celery +
  • 1 1/2 litres of water +
+ + ]]>
+ +
    +
  1. Chop vegetables. +
  2. Boil in water until vegetables soften. +
  3. Season with salt and pepper to taste. +
+ + ]]>
+
+ + content/pics/hamburger.jpg + +
    +
  • 500g minced beef +
  • Seasoning +
  • lettuce, tomato, onion, cheese +
  • 1 hamburger bun for each burger +
+ + ]]>
+ +
    +
  1. Mix the beef, together with seasoning, in a food processor. +
  2. Shape the beef into burgers. +
  3. Grill the burgers for about 5 mins on each side (until cooked through) +
  4. Serve each burger on a bun with ketchup, cheese, lettuce, tomato and onion. +
+ + ]]>
+
+ + content/pics/lemonade.jpg + +
    +
  • 1 cup Lemon Juice +
  • 1 cup Sugar +
  • 6 Cups of Water (2 cups warm water, 4 cups cold water) +
+ + ]]>
+ +
    +
  1. Pour 2 cups of warm water into a pitcher and stir in sugar until it dissolves. +
  2. Pour in lemon juice, stir again, and add 4 cups of cold water. +
  3. Chill or serve over ice cubes. +
+ + ]]>
+
+
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(component.create()); + QVERIFY(listModel != 0); + QTRY_COMPARE(listModel->count(), 9); + + QList roles; + roles << Qt::UserRole << Qt::UserRole + 1 << Qt::UserRole + 2 << Qt::UserRole + 3 << Qt::UserRole + 4; + QHash 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(component.create()); + QVERIFY(listModel != 0); + QTRY_COMPARE(listModel->count(), 5); + + QList roles; + roles << Qt::UserRole + 2; + QHash data = listModel->data(2, roles); + QVERIFY(data.count() == 1); + QVERIFY(data.value(Qt::UserRole+2).toString().startsWith(QLatin1String(""))); +} + +void tst_qmlxmllistmodel::attributes() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/recipes.qml")); + QmlXmlListModel *listModel = qobject_cast(component.create()); + QVERIFY(listModel != 0); + QTRY_COMPARE(listModel->count(), 5); + + QList roles; + roles << Qt::UserRole; + QHash 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" -- cgit v0.12