diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-11-04 04:15:20 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-11-04 04:15:20 (GMT) |
commit | 99fe55b3b4c031f1288f9e1c16455ca08663059c (patch) | |
tree | 153955a9a0abe246fac637a6e7710438b8a41c65 /tests/auto | |
parent | 630d3b9ba9da12331c72406c311ca26f88c6061a (diff) | |
download | Qt-99fe55b3b4c031f1288f9e1c16455ca08663059c.zip Qt-99fe55b3b4c031f1288f9e1c16455ca08663059c.tar.gz Qt-99fe55b3b4c031f1288f9e1c16455ca08663059c.tar.bz2 |
Start on QmlXmlListModel autotest.
Diffstat (limited to 'tests/auto')
5 files changed, 154 insertions, 0 deletions
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 7e3bf1e..f09d6cf 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -28,6 +28,7 @@ SUBDIRS += anchors \ qmlmetatype \ qmlpropertymap \ qmltimer \ + qmlxmllistmodel \ repeater \ sql \ states \ diff --git a/tests/auto/declarative/qmlxmllistmodel/data/model.qml b/tests/auto/declarative/qmlxmllistmodel/data/model.qml new file mode 100644 index 0000000..199a447 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/data/model.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +XmlListModel { + source: "model.xml" + query: "/ListModel/ListElement" + 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..f1fe742 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/data/model.xml @@ -0,0 +1,56 @@ +<ListModel> + <ListElement> + <name>Polly</name> + <type>Parrot</type> + <age>12</age> + <size>Small</size> + </ListElement> + <ListElement> + <name>Penny</name> + <type>Turtle</type> + <age>4</age> + <size>Small</size> + </ListElement> + <ListElement> + <name>Warren</name> + <type>Rabbit</type> + <age>2</age> + <size>Small</size> + </ListElement> + <ListElement> + <name>Spot</name> + <type>Dog</type> + <age>9</age> + <size>Medium</size> + </ListElement> + <ListElement> + <name>Whiskers</name> + <type>Cat</type> + <age>2</age> + <size>Medium</size> + </ListElement> + <ListElement> + <name>Joey</name> + <type>Kangaroo</type> + <age>1</age> + <size>Medium</size> + </ListElement> + <ListElement> + <name>Kimba</name> + <type>Bunny</type> + <age>65</age> + <size>Large</size> + </ListElement> + <ListElement> + <name>Rover</name> + <type>Dog</type> + <age>5</age> + <size>Large</size> + </ListElement> + <ListElement> + <name>Tiny</name> + <type>Elephant</type> + <age>15</age> + <size>Large</size> + </ListElement> +</ListModel> 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..0fc9006 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** 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(); + +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")); +} + +QTEST_MAIN(tst_qmlxmllistmodel) + +#include "tst_qmlxmllistmodel.moc" |