diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2010-05-24 10:02:57 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2010-05-24 10:46:57 (GMT) |
commit | 1079096a57112d9615812771adba18d2e9297320 (patch) | |
tree | 9c1fbdf2475e831fc9cce597586f37836589f60b /tests | |
parent | 4c975ee19b9671fbf76b546fc8ca2eff5bc69303 (diff) | |
download | Qt-1079096a57112d9615812771adba18d2e9297320.zip Qt-1079096a57112d9615812771adba18d2e9297320.tar.gz Qt-1079096a57112d9615812771adba18d2e9297320.tar.bz2 |
Added autotest for Component.createObject() without Qt.createComponent()
Also augmented the docs for both functions a little.
Task-number: QTBUG-10926
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qdeclarativecomponent/data/createObject.qml | 16 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp | 28 |
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativecomponent/data/createObject.qml b/tests/auto/declarative/qdeclarativecomponent/data/createObject.qml new file mode 100644 index 0000000..4ee1e75 --- /dev/null +++ b/tests/auto/declarative/qdeclarativecomponent/data/createObject.qml @@ -0,0 +1,16 @@ +import Qt 4.7 + +Item{ + id: root + property QtObject qobject : null + property QtObject declarativeitem : null + property QtObject graphicswidget: null + Component{id: a; QtObject{} } + Component{id: b; Item{} } + Component{id: c; QGraphicsWidget{} } + Component.onCompleted: { + root.qobject = a.createObject(root); + root.declarativeitem = b.createObject(root); + root.graphicswidget = c.createObject(root); + } +} diff --git a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp index c9e304c..faa1c21 100644 --- a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp +++ b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp @@ -39,7 +39,9 @@ ** ****************************************************************************/ #include <qtest.h> +#include <QDebug> +#include <QtGui/qgraphicsitem.h> #include <QtDeclarative/qdeclarativeengine.h> #include <QtDeclarative/qdeclarativecomponent.h> @@ -51,6 +53,7 @@ public: private slots: void loadEmptyUrl(); + void qmlCreateObject(); private: QDeclarativeEngine engine; @@ -70,6 +73,31 @@ void tst_qdeclarativecomponent::loadEmptyUrl() QCOMPARE(error.description(), QLatin1String("Invalid empty URL")); } +void tst_qdeclarativecomponent::qmlCreateObject() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/createObject.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QObject *testObject1 = object->property("qobject").value<QObject*>(); + QVERIFY(testObject1); + QVERIFY(testObject1->parent() == object); + + QObject *testObject2 = object->property("declarativeitem").value<QObject*>(); + QVERIFY(testObject2); + QVERIFY(testObject2->parent() == object); + QCOMPARE(testObject2->metaObject()->className(), "QDeclarativeItem"); + + //Note that QGraphicsObjects are not exposed to QML for instantiation, and so can't be used in a component directly + //Also this is actually the extended type QDeclarativeGraphicsWidget, but it still doesn't inherit QDeclarativeItem + QGraphicsObject *testObject3 = qobject_cast<QGraphicsObject*>(object->property("graphicswidget").value<QObject*>()); + QVERIFY(testObject3); + QVERIFY(testObject3->parent() == object); + QVERIFY(testObject3->parentItem() == qobject_cast<QGraphicsObject*>(object)); + QCOMPARE(testObject3->metaObject()->className(), "QDeclarativeGraphicsWidget"); +} + QTEST_MAIN(tst_qdeclarativecomponent) #include "tst_qdeclarativecomponent.moc" |