diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-10-07 13:16:47 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-12 01:31:11 +0200 |
commit | 3422d4adda7480a44a063ab86447c2fe2792fe02 (patch) | |
tree | 21cd120a33e7a9df586f45896d50b5688fdbc782 /tests/auto/declarative/qdeclarativecomponent | |
parent | 6fcaca378b84ada546dc62d72a53a71d0da86ef9 (diff) |
Component.incubateObject() autotest
Change-Id: I37f76d5b273ae4f032c4de5ac8fcbff4204b78fe
Reviewed-on: http://codereview.qt-project.org/6200
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Sanity-Review: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qdeclarativecomponent')
-rw-r--r-- | tests/auto/declarative/qdeclarativecomponent/data/incubateObject.qml | 36 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp | 35 |
2 files changed, 70 insertions, 1 deletions
diff --git a/tests/auto/declarative/qdeclarativecomponent/data/incubateObject.qml b/tests/auto/declarative/qdeclarativecomponent/data/incubateObject.qml new file mode 100644 index 0000000000..c11319db30 --- /dev/null +++ b/tests/auto/declarative/qdeclarativecomponent/data/incubateObject.qml @@ -0,0 +1,36 @@ +import QtQuick 2.0 + +Item{ + id: root + + property bool test1: false + property bool test2: false + + property var i + + Component{ + id: component + Item { + property int dummy: 13 + property int dummy2: 26 + } + } + + Component.onCompleted: { + i = component.incubateObject(null, { dummy2: 19 }); + + if (i.status != Component.Loading) return; + if (i.object != null) return; + + i.onStatusChanged = function(status) { + if (status != Component.Ready) return; + if (i.object == null) return; + if (i.object.dummy != 13) return; + if (i.object.dummy2 != 19) return; + test2 = true; + } + + test1 = true; + } +} + diff --git a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp index fe947fd201..89148812c5 100644 --- a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp +++ b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp @@ -45,22 +45,42 @@ #include <QtDeclarative/qdeclarativecomponent.h> #include <QtDeclarative/qsgitem.h> #include <QtDeclarative/qdeclarativeproperty.h> +#include <QtDeclarative/qdeclarativeincubator.h> #include <qcolor.h> +#include "../../../shared/util.h" + +#ifdef Q_OS_SYMBIAN +// In Symbian OS test data is located in applications private dir +#define SRCDIR "." +#endif + +class MyIC : public QObject, public QDeclarativeIncubationController +{ + Q_OBJECT +public: + MyIC() { startTimer(5); } +protected: + virtual void timerEvent(QTimerEvent*) { + incubateFor(5); + } +}; class tst_qdeclarativecomponent : public QObject { Q_OBJECT public: - tst_qdeclarativecomponent() { } + tst_qdeclarativecomponent() { engine.setIncubationController(&ic); } private slots: void null(); void loadEmptyUrl(); void qmlCreateObject(); void qmlCreateObjectWithProperties(); + void qmlIncubateObject(); private: QDeclarativeEngine engine; + MyIC ic; }; void tst_qdeclarativecomponent::null() @@ -91,6 +111,19 @@ void tst_qdeclarativecomponent::loadEmptyUrl() QCOMPARE(error.description(), QLatin1String("Invalid empty URL")); } +void tst_qdeclarativecomponent::qmlIncubateObject() +{ + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/incubateObject.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + QCOMPARE(object->property("test1").toBool(), true); + QCOMPARE(object->property("test2").toBool(), false); + + QTRY_VERIFY(object->property("test2").toBool() == true); + + delete object; +} + void tst_qdeclarativecomponent::qmlCreateObject() { QDeclarativeEngine engine; |