summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qmlxmllistmodel
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qmlxmllistmodel')
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/data/model.qml10
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/data/model.xml54
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/data/model2.qml11
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/data/recipes.qml10
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/data/recipes.xml90
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/data/roleErrors.qml10
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/data/unique.qml8
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro7
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp195
9 files changed, 395 insertions, 0 deletions
diff --git a/tests/auto/declarative/qmlxmllistmodel/data/model.qml b/tests/auto/declarative/qmlxmllistmodel/data/model.qml
new file mode 100644
index 0000000..2cbb027
--- /dev/null
+++ b/tests/auto/declarative/qmlxmllistmodel/data/model.qml
@@ -0,0 +1,10 @@
+import Qt 4.6
+
+XmlListModel {
+ source: "model.xml"
+ query: "/Pets/Pet"
+ XmlRole { name: "name"; query: "name/string()" }
+ XmlRole { name: "type"; query: "type/string()" }
+ XmlRole { name: "age"; query: "age/number()" }
+ XmlRole { name: "size"; query: "size/string()" }
+}
diff --git a/tests/auto/declarative/qmlxmllistmodel/data/model.xml b/tests/auto/declarative/qmlxmllistmodel/data/model.xml
new file mode 100644
index 0000000..40cd6d0
--- /dev/null
+++ b/tests/auto/declarative/qmlxmllistmodel/data/model.xml
@@ -0,0 +1,54 @@
+<Pets>
+ <Pet>
+ <name>Polly</name>
+ <type>Parrot</type>
+ <age>12</age>
+ <size>Small</size>
+ </Pet>
+ <Pet>
+ <name>Penny</name>
+ <type>Turtle</type>
+ <age>4</age>
+ <size>Small</size>
+ </Pet>
+ <Pet>
+ <name>Warren</name>
+ <type>Rabbit</type>
+ <age>2</age>
+ <size>Small</size>
+ </Pet>
+ <Pet>
+ <name>Spot</name>
+ <type>Dog</type>
+ <age>9</age>
+ <size>Medium</size>
+ </Pet>
+ <Pet>
+ <name>Whiskers</name>
+ <type>Cat</type>
+ <age>2</age>
+ <size>Medium</size>
+ </Pet>
+ <Pet>
+ <name>Joey</name>
+ <type>Kangaroo</type>
+ <age>1</age>
+ </Pet>
+ <Pet>
+ <name>Kimba</name>
+ <type>Bunny</type>
+ <age>65</age>
+ <size>Large</size>
+ </Pet>
+ <Pet>
+ <name>Rover</name>
+ <type>Dog</type>
+ <size>Large</size>
+ </Pet>
+ <Pet>
+ <name>Tiny</name>
+ <type>Elephant</type>
+ <age>15</age>
+ <size>Large</size>
+ </Pet>
+</Pets>
diff --git a/tests/auto/declarative/qmlxmllistmodel/data/model2.qml b/tests/auto/declarative/qmlxmllistmodel/data/model2.qml
new file mode 100644
index 0000000..140e0ad
--- /dev/null
+++ b/tests/auto/declarative/qmlxmllistmodel/data/model2.qml
@@ -0,0 +1,11 @@
+import Qt 4.6
+
+XmlListModel {
+ source: "model.xml"
+ query: "/Pets/Pet"
+ XmlRole { name: "name"; query: "name/string()" }
+ XmlRole { name: "type"; query: "type/string()" }
+ XmlRole { name: "age"; query: "age/number()" }
+ XmlRole { name: "size"; query: "size/string()" }
+ XmlRole { name: "tricks"; query: "tricks/string()" }
+}
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/data/roleErrors.qml b/tests/auto/declarative/qmlxmllistmodel/data/roleErrors.qml
new file mode 100644
index 0000000..26c533f
--- /dev/null
+++ b/tests/auto/declarative/qmlxmllistmodel/data/roleErrors.qml
@@ -0,0 +1,10 @@
+import Qt 4.6
+
+XmlListModel {
+ source: "model.xml"
+ query: "/Pets/Pet"
+ XmlRole { name: "name"; query: "/name/string()" } //starts with '/'
+ XmlRole { name: "type"; query: "type" } //no type
+ XmlRole { name: "age"; query: "age/" } //ends with '/'
+ XmlRole { name: "size"; query: "size/number()" } //wrong type
+}
diff --git a/tests/auto/declarative/qmlxmllistmodel/data/unique.qml b/tests/auto/declarative/qmlxmllistmodel/data/unique.qml
new file mode 100644
index 0000000..ed0f293
--- /dev/null
+++ b/tests/auto/declarative/qmlxmllistmodel/data/unique.qml
@@ -0,0 +1,8 @@
+import Qt 4.6
+
+XmlListModel {
+ source: "model.xml"
+ query: "/Pets/Pet"
+ XmlRole { name: "name"; query: "name/string()" }
+ XmlRole { name: "name"; query: "type/string()" }
+}
diff --git a/tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro b/tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro
new file mode 100644
index 0000000..462723e
--- /dev/null
+++ b/tests/auto/declarative/qmlxmllistmodel/qmlxmllistmodel.pro
@@ -0,0 +1,7 @@
+load(qttest_p4)
+contains(QT_CONFIG,declarative): QT += declarative gui
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qmlxmllistmodel.cpp
+
+DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp
new file mode 100644
index 0000000..af4bcda
--- /dev/null
+++ b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp
@@ -0,0 +1,195 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qtest.h>
+#include <QtDeclarative/qmlengine.h>
+#include <QtDeclarative/qmlcomponent.h>
+#include <private/qmlxmllistmodel_p.h>
+#include "../../../shared/util.h"
+
+class tst_qmlxmllistmodel : public QObject
+
+{
+ Q_OBJECT
+public:
+ tst_qmlxmllistmodel() {}
+
+private slots:
+ void buildModel();
+ void missingFields();
+ void cdata();
+ void attributes();
+ void roles();
+ void roleErrors();
+ void uniqueRoleNames();
+
+private:
+ QmlEngine engine;
+};
+
+void tst_qmlxmllistmodel::buildModel()
+{
+ QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/model.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;
+ QHash<int, QVariant> data = listModel->data(3, roles);
+ QVERIFY(data.count() == 4);
+ QCOMPARE(data.value(Qt::UserRole).toString(), QLatin1String("Spot"));
+ QCOMPARE(data.value(Qt::UserRole+1).toString(), QLatin1String("Dog"));
+ QCOMPARE(data.value(Qt::UserRole+2).toInt(), 9);
+ QCOMPARE(data.value(Qt::UserRole+3).toString(), QLatin1String("Medium"));
+
+ delete listModel;
+}
+
+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(""));
+
+ delete listModel;
+}
+
+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>")));
+
+ delete listModel;
+}
+
+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"));
+
+ delete listModel;
+}
+
+void tst_qmlxmllistmodel::roles()
+{
+ QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/model.qml"));
+ QmlXmlListModel *listModel = qobject_cast<QmlXmlListModel*>(component.create());
+ QVERIFY(listModel != 0);
+ QTRY_COMPARE(listModel->count(), 9);
+
+ QList<int> roles = listModel->roles();
+ QCOMPARE(roles.count(), 4);
+ QCOMPARE(listModel->toString(roles.at(0)), QLatin1String("name"));
+ QCOMPARE(listModel->toString(roles.at(1)), QLatin1String("type"));
+ QCOMPARE(listModel->toString(roles.at(2)), QLatin1String("age"));
+ QCOMPARE(listModel->toString(roles.at(3)), QLatin1String("size"));
+
+ delete listModel;
+}
+
+void tst_qmlxmllistmodel::roleErrors()
+{
+ QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/roleErrors.qml"));
+ QTest::ignoreMessage(QtWarningMsg, "QML XmlRole (file://" SRCDIR "/data/roleErrors.qml:6:5) An XmlRole query must not start with '/'");
+ //### make sure we receive all expected warning messages.
+ 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;
+ QHash<int, QVariant> data = listModel->data(3, roles);
+ QVERIFY(data.count() == 4);
+
+ //### should any of these return valid values?
+ QCOMPARE(data.value(Qt::UserRole), QVariant());
+ QCOMPARE(data.value(Qt::UserRole+1), QVariant());
+ QCOMPARE(data.value(Qt::UserRole+2), QVariant());
+ QCOMPARE(data.value(Qt::UserRole+3), QVariant());
+
+ delete listModel;
+}
+
+void tst_qmlxmllistmodel::uniqueRoleNames()
+{
+ QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/unique.qml"));
+ QTest::ignoreMessage(QtWarningMsg, "QML XmlRole (file://" SRCDIR "/data/unique.qml:7:5) \"name\" duplicates a previous role name and will be disabled.");
+ QmlXmlListModel *listModel = qobject_cast<QmlXmlListModel*>(component.create());
+ QVERIFY(listModel != 0);
+ QTRY_COMPARE(listModel->count(), 9);
+
+ QList<int> roles = listModel->roles();
+ QCOMPARE(roles.count(), 1);
+
+ delete listModel;
+}
+
+QTEST_MAIN(tst_qmlxmllistmodel)
+
+#include "tst_qmlxmllistmodel.moc"