diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-10-18 13:34:20 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-20 13:25:31 +0200 |
commit | 84af8c0ca510366a3017c1af83abc1cd18009198 (patch) | |
tree | 72a8571c8150f9d383eb7de03fc04fa9de9ab4f9 /tests | |
parent | 0db8440681ed0d1ea9baeda21dd71bb2e331bea2 (diff) |
Behave correctly when AsynchronousIfNested is nested
When AIN is nested within a synchronous AIN, it should behave
synchronously.
Change-Id: Ib3f8281667118d7787967f25e27797f67e581006
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
4 files changed, 86 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.3.qml b/tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.3.qml new file mode 100644 index 0000000000..7e5ee7cf5c --- /dev/null +++ b/tests/auto/declarative/qdeclarativeincubator/data/asynchronousIfNested.3.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +CallbackRegistering { + value: 19 +} diff --git a/tests/auto/declarative/qdeclarativeincubator/testtypes.cpp b/tests/auto/declarative/qdeclarativeincubator/testtypes.cpp index 3ff15a71af..99d2cb1005 100644 --- a/tests/auto/declarative/qdeclarativeincubator/testtypes.cpp +++ b/tests/auto/declarative/qdeclarativeincubator/testtypes.cpp @@ -82,8 +82,28 @@ void CompletionRegisteringType::clearMe() m_me = 0; } +CallbackRegisteringType::callback CallbackRegisteringType::m_callback = 0; +void *CallbackRegisteringType::m_data = 0; +CallbackRegisteringType::CallbackRegisteringType() +: m_v(0) +{ +} + +void CallbackRegisteringType::clearCallback() +{ + m_callback = 0; + m_data = 0; +} + +void CallbackRegisteringType::registerCallback(callback c, void *d) +{ + m_callback = c; + m_data = d; +} + void registerTypes() { qmlRegisterType<SelfRegisteringType>("Qt.test", 1,0, "SelfRegistering"); qmlRegisterType<CompletionRegisteringType>("Qt.test", 1,0, "CompletionRegistering"); + qmlRegisterType<CallbackRegisteringType>("Qt.test", 1,0, "CallbackRegistering"); } diff --git a/tests/auto/declarative/qdeclarativeincubator/testtypes.h b/tests/auto/declarative/qdeclarativeincubator/testtypes.h index 85ee4a6a9b..6e732548b2 100644 --- a/tests/auto/declarative/qdeclarativeincubator/testtypes.h +++ b/tests/auto/declarative/qdeclarativeincubator/testtypes.h @@ -63,6 +63,27 @@ private: int m_v; }; +class CallbackRegisteringType : public QObject +{ +Q_OBJECT +Q_PROPERTY(int value READ value WRITE setValue) +public: + CallbackRegisteringType(); + + int value() const { return m_v; } + void setValue(int v) { if (m_callback) m_callback(this, m_data); m_v = v; } + + typedef void (*callback)(CallbackRegisteringType *, void *); + static void clearCallback(); + static void registerCallback(callback, void *); + +private: + static callback m_callback; + static void *m_data; + + int m_v; +}; + class CompletionRegisteringType : public QObject, public QDeclarativeParserStatus { Q_OBJECT diff --git a/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp b/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp index 672387ece2..358254854e 100644 --- a/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp +++ b/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp @@ -614,6 +614,46 @@ void tst_qdeclarativeincubator::asynchronousIfNested() delete nested.object(); delete incubator.object(); } + + // AsynchronousIfNested within a synchronous AsynchronousIfNested behaves synchronously + { + SelfRegisteringType::clearMe(); + + QDeclarativeComponent component(&engine, TEST_FILE("asynchronousIfNested.3.qml")); + QVERIFY(component.isReady()); + + struct CallbackData { + CallbackData(QDeclarativeEngine *e) : engine(e), pass(false) {} + QDeclarativeEngine *engine; + bool pass; + static void callback(CallbackRegisteringType *o, void *data) { + CallbackData *d = (CallbackData *)data; + + QDeclarativeComponent c(d->engine, TEST_FILE("asynchronousIfNested.1.qml")); + if (!c.isReady()) return; + + QDeclarativeIncubator incubator(QDeclarativeIncubator::AsynchronousIfNested); + c.create(incubator, 0, qmlContext(o)); + + if (!incubator.isReady()) return; + + if (incubator.object()->property("a").toInt() != 10) return; + + d->pass = true; + } + }; + + CallbackData cd(&engine); + CallbackRegisteringType::registerCallback(&CallbackData::callback, &cd); + + QDeclarativeIncubator incubator(QDeclarativeIncubator::AsynchronousIfNested); + component.create(incubator); + + QVERIFY(incubator.isReady()); + QCOMPARE(cd.pass, true); + + delete incubator.object(); + } } void tst_qdeclarativeincubator::nestedComponent() |