aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlcomponent
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlcomponent')
-rw-r--r--tests/auto/qml/qqmlcomponent/lifecyclewatcher.h25
-rw-r--r--tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp50
2 files changed, 66 insertions, 9 deletions
diff --git a/tests/auto/qml/qqmlcomponent/lifecyclewatcher.h b/tests/auto/qml/qqmlcomponent/lifecyclewatcher.h
index 738fd86942..3d3bdfd562 100644
--- a/tests/auto/qml/qqmlcomponent/lifecyclewatcher.h
+++ b/tests/auto/qml/qqmlcomponent/lifecyclewatcher.h
@@ -15,10 +15,29 @@ class LifeCycleWatcher : public QObject, public QQmlParserStatus, public QQmlFin
QML_ELEMENT
Q_INTERFACES(QQmlParserStatus)
Q_INTERFACES(QQmlFinalizerHook)
+ Q_PROPERTY(QString text MEMBER text)
public:
- void classBegin() override {states.push_back(1); }
- void componentComplete() override {states.push_back(2);};
- void componentFinalized() override { states.push_back(3); }
+ void classBegin() override
+ {
+ states.push_back(1);
+ observedTexts.push_back(text);
+ }
+
+ void componentComplete() override
+ {
+ states.push_back(2);
+ observedTexts.push_back(text);
+ }
+
+ void componentFinalized() override
+ {
+ states.push_back(3);
+ observedTexts.push_back(text);
+ }
+
+ QString text;
QList<int> states;
+ QStringList observedTexts;
};
+
#endif
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
index 1ccf7a6f23..59703d5c36 100644
--- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
+++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
@@ -1361,8 +1361,7 @@ void tst_qqmlcomponent::loadFromModule()
void tst_qqmlcomponent::loadFromModuleLifecycle()
{
QQmlEngine engine;
- QList<int> loadFromModuleOrder;
- QList<int> plainLoadOrder;
+ const QString text = "text"_L1;
const QList<int> expected {1, 2, 3};
{
QQmlComponent component(&engine);
@@ -1371,19 +1370,58 @@ void tst_qqmlcomponent::loadFromModuleLifecycle()
std::unique_ptr<QObject> root{ component.create() };
LifeCycleWatcher *watcher = qobject_cast<LifeCycleWatcher *>(root.get());
QVERIFY(watcher);
- loadFromModuleOrder = watcher->states;
- QCOMPARE(loadFromModuleOrder, expected);
+ QCOMPARE(watcher->states, expected);
+ QCOMPARE(watcher->observedTexts, QStringList(3));
+
+ const QString loaded = "load from module"_L1;
+ root.reset(component.createWithInitialProperties(QVariantMap{{text, loaded}}));
+ watcher = qobject_cast<LifeCycleWatcher *>(root.get());
+ QVERIFY(watcher);
+ QCOMPARE(watcher->states, expected);
+ QCOMPARE(watcher->observedTexts, QStringList({QString(), loaded, loaded}));
}
+
{
QQmlComponent component(&engine);
component.setData("import test; LifeCycleWatcher {}", {});
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+
std::unique_ptr<QObject> root{ component.create() };
LifeCycleWatcher *watcher = qobject_cast<LifeCycleWatcher *>(root.get());
QVERIFY(watcher);
- plainLoadOrder = watcher->states;
+ QCOMPARE(watcher->states, expected);
+ QCOMPARE(watcher->observedTexts, QStringList(3));
+
+ const QString loaded = "load from data"_L1;
+ root.reset(component.createWithInitialProperties(QVariantMap{{text, loaded}}));
+ watcher = qobject_cast<LifeCycleWatcher *>(root.get());
+ QVERIFY(watcher);
+ QCOMPARE(watcher->states, expected);
+ QCOMPARE(watcher->observedTexts, QStringList({QString(), loaded, loaded}));
}
- QCOMPARE(loadFromModuleOrder, plainLoadOrder);
+
+ {
+ QQmlComponent component(&engine);
+ const QString compiled = "inline"_L1;
+ component.setData("import test; LifeCycleWatcher { text: 'inline' }", {});
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+
+ std::unique_ptr<QObject> root{ component.create() };
+ LifeCycleWatcher *watcher = qobject_cast<LifeCycleWatcher *>(root.get());
+ QVERIFY(watcher);
+ QCOMPARE(watcher->states, expected);
+ QCOMPARE(watcher->observedTexts, QStringList({QString(), compiled, compiled}));
+
+ const QString loaded = "overridden"_L1;
+ std::unique_ptr<QObject> withProperties(
+ component.createWithInitialProperties(QVariantMap{{text, loaded}}));
+ watcher = qobject_cast<LifeCycleWatcher *>(withProperties.get());
+ QVERIFY(watcher);
+ QCOMPARE(watcher->states, expected);
+ QCOMPARE(watcher->observedTexts, QStringList({QString(), loaded, loaded}));
+ }
+
+
}
struct CallVerifyingIncubtor : QQmlIncubator