diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-10-18 14:56:25 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-20 13:26:17 +0200 |
commit | 2d4f2b3e758df0e9bafaa9b3adea7f4d5c19ae2b (patch) | |
tree | 6a35fda5fa8f0a1ec02cc319bd42a9fa9fd56b6e /tests/auto/declarative/qdeclarativeincubator | |
parent | 3fe0716f608da26332625b98e724aad73f687993 (diff) |
Allow QDeclarativeIncubator to be deleted within statusChanged() callback
Change-Id: I17621870b67d8a975545adc27ddaf9695e6a9428
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qdeclarativeincubator')
-rw-r--r-- | tests/auto/declarative/qdeclarativeincubator/data/selfDelete.qml | 5 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp | 75 |
2 files changed, 80 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/selfDelete.qml b/tests/auto/declarative/qdeclarativeincubator/data/selfDelete.qml new file mode 100644 index 0000000000..c3952074f1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeincubator/data/selfDelete.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +QtObject { + property int dummy: 12 +} diff --git a/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp b/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp index e3648f70fe..00c226e6a5 100644 --- a/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp +++ b/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp @@ -51,6 +51,7 @@ #include <QDeclarativeComponent> #include <QDeclarativeIncubator> #include "../shared/util.h" +#include "../../../shared/util.h" inline QUrl TEST_FILE(const QString &filename) { @@ -83,6 +84,7 @@ private slots: void asynchronousIfNested(); void nestedComponent(); void chainedAsynchronousIfNested(); + void selfDelete(); private: QDeclarativeIncubationController controller; @@ -772,6 +774,79 @@ void tst_qdeclarativeincubator::chainedAsynchronousIfNested() QVERIFY(incubator2.isReady()); } +void tst_qdeclarativeincubator::selfDelete() +{ + struct MyIncubator : public QDeclarativeIncubator { + MyIncubator(bool *done, Status status, IncubationMode mode) + : QDeclarativeIncubator(mode), done(done), status(status) {} + + protected: + virtual void statusChanged(Status s) { + if (s == status) { + *done = true; + if (s == Ready) delete object(); + delete this; + } + } + + private: + bool *done; + Status status; + }; + + { + QDeclarativeComponent component(&engine, TEST_FILE("selfDelete.qml")); + +#define DELETE_TEST(status, mode) { \ + bool done = false; \ + component.create(*(new MyIncubator(&done, status, mode))); \ + bool True = true; \ + controller.incubateWhile(&True); \ + QVERIFY(done == true); \ + } + + DELETE_TEST(QDeclarativeIncubator::Loading, QDeclarativeIncubator::Synchronous); + DELETE_TEST(QDeclarativeIncubator::Ready, QDeclarativeIncubator::Synchronous); + DELETE_TEST(QDeclarativeIncubator::Loading, QDeclarativeIncubator::Asynchronous); + DELETE_TEST(QDeclarativeIncubator::Ready, QDeclarativeIncubator::Asynchronous); + +#undef DELETE_TEST + } + + // Delete within error status + { + SelfRegisteringType::clearMe(); + + QDeclarativeComponent component(&engine, TEST_FILE("objectDeleted.qml")); + QVERIFY(component.isReady()); + + bool done = false; + MyIncubator *incubator = new MyIncubator(&done, QDeclarativeIncubator::Error, + QDeclarativeIncubator::Asynchronous); + component.create(*incubator); + + QCOMPARE(incubator->QDeclarativeIncubator::status(), QDeclarativeIncubator::Loading); + QVERIFY(SelfRegisteringType::me() == 0); + + while (SelfRegisteringType::me() == 0 && incubator->isLoading()) { + bool b = false; + controller.incubateWhile(&b); + } + + QVERIFY(SelfRegisteringType::me() != 0); + QVERIFY(incubator->isLoading()); + + delete SelfRegisteringType::me(); + + { + bool b = true; + controller.incubateWhile(&b); + } + + QVERIFY(done); + } +} + QTEST_MAIN(tst_qdeclarativeincubator) #include "tst_qdeclarativeincubator.moc" |