aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-08-25 14:16:29 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-08-26 11:17:17 +0200
commitf0e5ff83a10a12cb38c3d6770e42f587d9392d51 (patch)
treedadb79aee98e63b0c02ed34c586b524106bad023
parent0d3f0b581c2272c70c14b1811a3d65a52276988c (diff)
tst_qqmlecmascript: Check that parent can defer child class properties
It is arguably a bad idea to defer properties which might get defined in child classes, but checking it in the engine would be expensive: We cannot simply check that the property exist, as we might want to defer attached properties. So for now, we add a test to document and verify the behavior. Change-Id: I264b136638c4ecddfa52b6687797cb981d9b531e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--tests/auto/qml/qqmlecmascript/data/deferredPropertiesChild.qml6
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.cpp1
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.h26
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp15
4 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/deferredPropertiesChild.qml b/tests/auto/qml/qqmlecmascript/data/deferredPropertiesChild.qml
new file mode 100644
index 0000000000..0a4d13f415
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/deferredPropertiesChild.qml
@@ -0,0 +1,6 @@
+import Qt.test 1.0
+
+DeferredByParentChild {
+ id: root
+ childValue: 10
+}
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp
index 4c5246c437..56cb03f6f4 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.cpp
+++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp
@@ -469,6 +469,7 @@ void registerTypes()
qmlRegisterSingletonType<TestTypeCppSingleton>("Test", 1, 0, "TestTypeCppSingleton", testTypeCppProvider);
qmlRegisterType<MyDeferredObject>("Qt.test", 1,0, "MyDeferredObject");
qmlRegisterType<DeferredChild>("Qt.test", 1,0, "DeferredChild");
+ qmlRegisterType<DeferredByParentChild>("Qt.test", 1,0, "DeferredByParentChild");
qmlRegisterType<MyVeryDeferredObject>("Qt.test", 1,0, "MyVeryDeferredObject");
qmlRegisterType<MyQmlContainer>("Qt.test", 1,0, "MyQmlContainer");
qmlRegisterExtendedType<MyBaseExtendedObject, BaseExtensionObject>("Qt.test", 1,0, "MyBaseExtendedObject");
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h
index fa13fa89d4..e6ef36fd1e 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.h
+++ b/tests/auto/qml/qqmlecmascript/testtypes.h
@@ -435,6 +435,32 @@ class DeferredChild : public NonDeferredBased
Q_CLASSINFO("DeferredPropertyNames", "baseValue")
};
+class ChildDeferringParent : public QObject
+{
+ Q_OBJECT
+ Q_CLASSINFO("DeferredPropertyNames", "childValue")
+};
+
+class DeferredByParentChild : public ChildDeferringParent
+{
+ Q_OBJECT
+ Q_PROPERTY(int childValue READ childValue WRITE setchildValue NOTIFY childValueChanged)
+signals:
+ void childValueChanged();
+public:
+ int childValue() const { return m_childValue; }
+
+ void setchildValue(int i) {
+ if (i == m_childValue)
+ return;
+ m_childValue = i;
+ emit childValueChanged();
+ }
+
+private:
+ int m_childValue = 0;
+};
+
class MyVeryDeferredObject : public QObject
{
Q_OBJECT
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index eb9fa14aa5..9b7286dc0e 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -101,6 +101,7 @@ private slots:
void dependenciesWithFunctions();
void deferredProperties();
void deferredPropertiesParent();
+ void deferredPropertiesByParent();
void deferredPropertiesErrors();
void deferredPropertiesInComponents();
void deferredPropertiesInDestruction();
@@ -1229,6 +1230,20 @@ void tst_qqmlecmascript::deferredPropertiesParent()
qmlExecuteDeferred(object);
QCOMPARE(object->baseValue(), 10);
}
+
+void tst_qqmlecmascript::deferredPropertiesByParent()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("deferredPropertiesChild.qml"));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ DeferredByParentChild *object = qobject_cast<DeferredByParentChild *>(obj.data());
+ QVERIFY(object != nullptr);
+ QCOMPARE(object->childValue(), 0);
+ qmlExecuteDeferred(object);
+ QCOMPARE(object->childValue(), 10);
+}
+
// Check errors on deferred properties are correctly emitted
void tst_qqmlecmascript::deferredPropertiesErrors()
{