From 5b548025ca353fa2f512356d0969b096b5b705e1 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 30 Apr 2009 16:44:40 +0200 Subject: Added simple autotests for QmlDom classes --- tests/auto/declarative/qmldom/qmldom.pro | 3 + tests/auto/declarative/qmldom/tst_qmldom.cpp | 90 ++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 tests/auto/declarative/qmldom/qmldom.pro create mode 100644 tests/auto/declarative/qmldom/tst_qmldom.cpp diff --git a/tests/auto/declarative/qmldom/qmldom.pro b/tests/auto/declarative/qmldom/qmldom.pro new file mode 100644 index 0000000..5294cb4 --- /dev/null +++ b/tests/auto/declarative/qmldom/qmldom.pro @@ -0,0 +1,3 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_qmldom.cpp diff --git a/tests/auto/declarative/qmldom/tst_qmldom.cpp b/tests/auto/declarative/qmldom/tst_qmldom.cpp new file mode 100644 index 0000000..7e7e067 --- /dev/null +++ b/tests/auto/declarative/qmldom/tst_qmldom.cpp @@ -0,0 +1,90 @@ +#include +#include +#include +#include + +#include + +class tst_qmldom : public QObject +{ + Q_OBJECT +public: + tst_qmldom() {} + +private slots: + void loadSimple(); + void loadProperties(); + void loadChildObject(); + +private: + QmlEngine engine; +}; + + +void tst_qmldom::loadSimple() +{ + QByteArray qml = "Item {}"; + //QByteArray qml = ""; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + QVERIFY(document.loadError().isEmpty()); + + QmlDomObject rootObject = document.rootObject(); + QVERIFY(rootObject.isValid()); + QVERIFY(!rootObject.isComponent()); + QVERIFY(!rootObject.isCustomType()); + QVERIFY(rootObject.objectType() == "Item"); +} + +void tst_qmldom::loadProperties() +{ + QByteArray qml = "Item { id : item; x : 300; visible : true }"; + //QByteArray qml = ""; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootObject = document.rootObject(); + QVERIFY(rootObject.isValid()); + QVERIFY(rootObject.objectId() == "item"); + QVERIFY(rootObject.properties().size() == 2); + + QmlDomProperty xProperty = rootObject.property("x"); + QVERIFY(xProperty.propertyName() == "x"); + QVERIFY(xProperty.value().isLiteral()); + QVERIFY(xProperty.value().toLiteral().literal() == "300"); + + QmlDomProperty visibleProperty = rootObject.property("visible"); + QVERIFY(visibleProperty.propertyName() == "visible"); + QVERIFY(visibleProperty.value().isLiteral()); + QVERIFY(visibleProperty.value().toLiteral().literal() == "true"); +} + +void tst_qmldom::loadChildObject() +{ + QByteArray qml = "Item { Item }"; + //QByteArray qml = " "; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootItem = document.rootObject(); + QVERIFY(rootItem.isValid()); + QVERIFY(rootItem.properties().size() == 1); + + QmlDomProperty listProperty = rootItem.properties().at(0); + QVERIFY(listProperty.isDefaultProperty()); + QVERIFY(listProperty.value().isList()); + + QmlDomList list = listProperty.value().toList(); + QVERIFY(list.values().size() == 1); + + QmlDomObject childItem = list.values().first().toObject(); + QVERIFY(childItem.isValid()); + QVERIFY(childItem.objectType() == "Item"); +} + +QTEST_MAIN(tst_qmldom) + +#include "tst_qmldom.moc" -- cgit v0.12