From 625bb0520708879ef5d281ab0c62fc7ad5415441 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 6 Oct 2011 14:14:40 +1000 Subject: Allow incubators to be driven recursively Change-Id: If8ce239372c3cf3166b666329ba812b25ee54669 Reviewed-on: http://codereview.qt-project.org/6102 Reviewed-by: Aaron Kennedy --- .../tst_qdeclarativeincubator.cpp | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp') diff --git a/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp b/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp index f870ffb5cd..52ddf81602 100644 --- a/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp +++ b/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp @@ -78,6 +78,7 @@ private slots: void forceCompletion(); void setInitialState(); void clearDuringCompletion(); + void recursiveClear(); private: QDeclarativeIncubationController controller; @@ -422,10 +423,56 @@ void tst_qdeclarativeincubator::clearDuringCompletion() QPointer srt = SelfRegisteringType::me(); incubator.clear(); + QCoreApplication::processEvents(QEventLoop::DeferredDeletion); QVERIFY(incubator.isNull()); QVERIFY(srt.isNull()); } +class Switcher : public QObject +{ + Q_OBJECT +public: + Switcher(QDeclarativeEngine *e) : QObject(), engine(e) { } + + struct MyIncubator : public QDeclarativeIncubator + { + MyIncubator(QDeclarativeIncubator::IncubationMode mode, QObject *s) + : QDeclarativeIncubator(mode), switcher(s) {} + + virtual void setInitialState(QObject *o) { + if (o->objectName() == "switchMe") + connect(o, SIGNAL(switchMe()), switcher, SLOT(switchIt())); + } + + QObject *switcher; + }; + + void start() + { + incubator = new MyIncubator(QDeclarativeIncubator::Synchronous, this); + component = new QDeclarativeComponent(engine, TEST_FILE("recursiveClear.1.qml")); + component->create(*incubator); + } + + QDeclarativeEngine *engine; + MyIncubator *incubator; + QDeclarativeComponent *component; + +public slots: + void switchIt() { + component->deleteLater(); + incubator->clear(); + component = new QDeclarativeComponent(engine, TEST_FILE("recursiveClear.2.qml")); + component->create(*incubator); + } +}; + +void tst_qdeclarativeincubator::recursiveClear() +{ + Switcher switcher(&engine); + switcher.start(); +} + QTEST_MAIN(tst_qdeclarativeincubator) #include "tst_qdeclarativeincubator.moc" -- cgit v1.2.3