diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2009-04-30 14:44:40 (GMT) |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2009-04-30 14:45:48 (GMT) |
commit | 5b548025ca353fa2f512356d0969b096b5b705e1 (patch) | |
tree | 8cdd4e6eb8ef8e6813cd6e5b33aafcf884d5c4c7 | |
parent | 6091b55ef4da3459ca3dd9d92e41fc223cf06aaf (diff) | |
download | Qt-5b548025ca353fa2f512356d0969b096b5b705e1.zip Qt-5b548025ca353fa2f512356d0969b096b5b705e1.tar.gz Qt-5b548025ca353fa2f512356d0969b096b5b705e1.tar.bz2 |
Added simple autotests for QmlDom classes
-rw-r--r-- | tests/auto/declarative/qmldom/qmldom.pro | 3 | ||||
-rw-r--r-- | tests/auto/declarative/qmldom/tst_qmldom.cpp | 90 |
2 files changed, 93 insertions, 0 deletions
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 <qtest.h> +#include <QtDeclarative/qmlengine.h> +#include <QtDeclarative/qmlcomponent.h> +#include <QtDeclarative/qmldom.h> + +#include <QtCore/QDebug> + +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 = "<Item/>"; + + 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 = "<Item id='item' x='300' visible='true'/>"; + + 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 = "<Item> <Item/> </Item>"; + + 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" |