summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativexmllistmodel
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-03-30 07:30:01 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-03-30 07:30:01 (GMT)
commitc2bee860f72898c6d57ff9f117256059b3952479 (patch)
tree8f190bac91f9cbd11e6e52479a3effea132a3a20 /tests/auto/declarative/qdeclarativexmllistmodel
parentde306893b464ed0fa00f98488912fd6269713519 (diff)
parentc4f59859a589b76419e9133110eda850223f03dd (diff)
downloadQt-c2bee860f72898c6d57ff9f117256059b3952479.zip
Qt-c2bee860f72898c6d57ff9f117256059b3952479.tar.gz
Qt-c2bee860f72898c6d57ff9f117256059b3952479.tar.bz2
Merge remote branch 'origin/4.7' into qt-4.7-from-4.6
Conflicts: mkspecs/common/symbian/symbian.conf src/3rdparty/webkit/WebCore/WebCore.pro
Diffstat (limited to 'tests/auto/declarative/qdeclarativexmllistmodel')
-rw-r--r--tests/auto/declarative/qdeclarativexmllistmodel/data/model2.xml14
-rw-r--r--tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp120
2 files changed, 133 insertions, 1 deletions
diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/data/model2.xml b/tests/auto/declarative/qdeclarativexmllistmodel/data/model2.xml
new file mode 100644
index 0000000..dab2ec6
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativexmllistmodel/data/model2.xml
@@ -0,0 +1,14 @@
+<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>
+</Pets>
diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
index 81cc922..74da79e 100644
--- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
@@ -41,6 +41,8 @@
#include <qtest.h>
#include <QtTest/qsignalspy.h>
#include <QtCore/qtimer.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qtemporaryfile.h>
#ifdef QTEST_XMLPATTERNS
#include <QtDeclarative/qdeclarativeengine.h>
@@ -53,6 +55,7 @@ typedef QList<QVariantList> QDeclarativeXmlModelData;
Q_DECLARE_METATYPE(QList<QDeclarativeXmlListRange>)
Q_DECLARE_METATYPE(QDeclarativeXmlModelData)
+Q_DECLARE_METATYPE(QDeclarativeXmlListModel::Status)
class tst_qdeclarativexmllistmodel : public QObject
@@ -62,6 +65,10 @@ public:
tst_qdeclarativexmllistmodel() {}
private slots:
+ void initTestCase() {
+ qRegisterMetaType<QDeclarativeXmlListModel::Status>("QDeclarativeXmlListModel::Status");
+ }
+
void buildModel();
void missingFields();
void cdata();
@@ -69,6 +76,11 @@ private slots:
void roles();
void roleErrors();
void uniqueRoleNames();
+ void xml();
+ void xml_data();
+ void source();
+ void source_data();
+ void data();
void reload();
void useKeys();
void useKeys_data();
@@ -181,7 +193,6 @@ void tst_qdeclarativexmllistmodel::attributes()
QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
QVERIFY(model != 0);
QTRY_COMPARE(model->count(), 5);
-
QList<int> roles;
roles << Qt::UserRole;
QHash<int, QVariant> data = model->data(2, roles);
@@ -247,6 +258,113 @@ void tst_qdeclarativexmllistmodel::uniqueRoleNames()
delete model;
}
+
+void tst_qdeclarativexmllistmodel::xml()
+{
+ QFETCH(QString, xml);
+ QFETCH(int, count);
+
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QSignalSpy spy(model, SIGNAL(statusChanged(QDeclarativeXmlListModel::Status)));
+
+ QCOMPARE(model->progress(), qreal(0.0));
+ QCOMPARE(model->status(), QDeclarativeXmlListModel::Loading);
+ QTRY_COMPARE(spy.count(), 1); spy.clear();
+ QCOMPARE(model->status(), QDeclarativeXmlListModel::Ready);
+ QCOMPARE(model->progress(), qreal(1.0));
+ QCOMPARE(model->count(), 9);
+
+ // if xml is empty (i.e. clearing) it won't have any effect if a source is set
+ if (xml.isEmpty())
+ model->setSource(QUrl());
+ model->setXml(xml);
+ QCOMPARE(model->progress(), qreal(1.0)); // immediately goes to 1.0 if using setXml()
+ QTRY_COMPARE(spy.count(), 1); spy.clear();
+ QCOMPARE(model->status(), QDeclarativeXmlListModel::Loading);
+ QTRY_COMPARE(spy.count(), 1); spy.clear();
+ QCOMPARE(model->status(), QDeclarativeXmlListModel::Ready);
+ QCOMPARE(model->count(), count);
+
+ delete model;
+}
+
+void tst_qdeclarativexmllistmodel::xml_data()
+{
+ QTest::addColumn<QString>("xml");
+ QTest::addColumn<int>("count");
+
+ QTest::newRow("xml with no items") << "<Pets></Pets>" << 0;
+ QTest::newRow("empty xml") << "" << 0;
+ QTest::newRow("one item") << "<Pets><Pet><name>Hobbes</name><type>Tiger</type><age>7</age><size>Large</size></Pet></Pets>" << 1;
+}
+
+void tst_qdeclarativexmllistmodel::source()
+{
+ QFETCH(QUrl, source);
+ QFETCH(int, count);
+ QFETCH(QDeclarativeXmlListModel::Status, status);
+
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QSignalSpy spy(model, SIGNAL(statusChanged(QDeclarativeXmlListModel::Status)));
+
+ QCOMPARE(model->progress(), qreal(0.0));
+ QCOMPARE(model->status(), QDeclarativeXmlListModel::Loading);
+ QTRY_COMPARE(spy.count(), 1); spy.clear();
+ QCOMPARE(model->status(), QDeclarativeXmlListModel::Ready);
+ QCOMPARE(model->progress(), qreal(1.0));
+ QCOMPARE(model->count(), 9);
+
+ model->setSource(source);
+ QCOMPARE(model->progress(), qreal(0.0));
+ QTRY_COMPARE(spy.count(), 1); spy.clear();
+ QCOMPARE(model->status(), QDeclarativeXmlListModel::Loading);
+ QTRY_COMPARE(spy.count(), 1); spy.clear();
+ QCOMPARE(model->status(), status);
+ QCOMPARE(model->count(), count);
+ if (status == QDeclarativeXmlListModel::Ready)
+ QCOMPARE(model->progress(), qreal(1.0));
+
+ delete model;
+}
+
+void tst_qdeclarativexmllistmodel::source_data()
+{
+ QTest::addColumn<QUrl>("source");
+ QTest::addColumn<int>("count");
+ QTest::addColumn<QDeclarativeXmlListModel::Status>("status");
+
+ QTest::newRow("valid") << QUrl::fromLocalFile(SRCDIR "/data/model2.xml") << 2 << QDeclarativeXmlListModel::Ready;
+ QTest::newRow("invalid") << QUrl("http://blah.blah/blah.xml") << 0 << QDeclarativeXmlListModel::Error;
+
+ // empty file
+ QTemporaryFile *temp = new QTemporaryFile(this);
+ if (temp->open())
+ QTest::newRow("empty file") << QUrl::fromLocalFile(temp->fileName()) << 0 << QDeclarativeXmlListModel::Ready;
+ temp->close();
+}
+
+void tst_qdeclarativexmllistmodel::data()
+{
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+
+ QHash<int,QVariant> blank;
+ for (int i=0; i<model->roles().count(); i++)
+ blank.insert(model->roles()[i], QVariant());
+ for (int i=0; i<9; i++) {
+ QCOMPARE(model->data(i, model->roles()), blank);
+ for (int j=0; j<model->roles().count(); j++) {
+ QCOMPARE(model->data(i, j), QVariant());
+ }
+ }
+ QTRY_COMPARE(model->count(), 9);
+
+ delete model;
+}
+
void tst_qdeclarativexmllistmodel::reload()
{
// If no keys are used, the model should be rebuilt from scratch when