aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2022-10-11 11:41:13 +0200
committerSami Shalayel <sami.shalayel@qt.io>2022-10-11 15:52:12 +0000
commit259ff52e64cd8725bfaa7330a33f8d36456e8b1a (patch)
tree910fb64469f29e473cb2699e81e9b4ef3361bdca /tests
parentcba96b3a97977f71931f311db9d5644d1d74d694 (diff)
qmltc: Remove broken alias optimization
Remove the recursive alias resolution mechanism. It tried to resolve aliases recursively but only knew the id's of the current component. This means that an alias pointing to a property defined in another component (e.g. a different qml file) was resolved using the id-to-scope map of the component containing the alias property. This leads to unresolved aliases at best and endless loops when the aliased property was itself an alias pointing to some property also existing in the original component (see QmltcTests/ComponentWithAlias{1..3}.qml for an example). Also added the reproducer in the qmltc tests. Fixes: QTBUG-107533 Fixes: QTBUG-107534 Change-Id: Idbf0cff3e45213bc7fbb4a98a9393c6754b00046 Pick-to: 6.4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt4
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias1.qml8
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias2.qml8
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias3.qml5
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/aliases.qml29
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.cpp32
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.h1
7 files changed, 86 insertions, 1 deletions
diff --git a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
index 7712dcf992..36e4d1413b 100644
--- a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
+++ b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
@@ -101,6 +101,7 @@ set(qml_sources
appendToQQmlListProperty.qml
inlineComponents.qml
repeaterCrash.qml
+ aliases.qml
# support types:
DefaultPropertySingleChild.qml
@@ -110,6 +111,9 @@ set(qml_sources
LocalWithOnCompleted.qml
LocallyImported_context.qml
# SingletonThing.qml
+ ComponentWithAlias1.qml
+ ComponentWithAlias2.qml
+ ComponentWithAlias3.qml
badFile.qml
)
diff --git a/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias1.qml b/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias1.qml
new file mode 100644
index 0000000000..210cf1e159
--- /dev/null
+++ b/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias1.qml
@@ -0,0 +1,8 @@
+import QtQuick
+
+Item {
+ property alias setMe: firstComponent.setMe
+ ComponentWithAlias2 {
+ id: firstComponent
+ }
+}
diff --git a/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias2.qml b/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias2.qml
new file mode 100644
index 0000000000..818f3a464e
--- /dev/null
+++ b/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias2.qml
@@ -0,0 +1,8 @@
+import QtQuick
+
+Item {
+ property alias setMe: firstComponent.setMe
+ ComponentWithAlias3 {
+ id: firstComponent
+ }
+}
diff --git a/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias3.qml b/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias3.qml
new file mode 100644
index 0000000000..87b917ad19
--- /dev/null
+++ b/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias3.qml
@@ -0,0 +1,5 @@
+import QtQuick
+
+Item {
+ property string setMe: "Set me!"
+}
diff --git a/tests/auto/qml/qmltc/QmltcTests/aliases.qml b/tests/auto/qml/qmltc/QmltcTests/aliases.qml
new file mode 100644
index 0000000000..9f13f7b17a
--- /dev/null
+++ b/tests/auto/qml/qmltc/QmltcTests/aliases.qml
@@ -0,0 +1,29 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+import QtQuick
+
+Item {
+ property alias aliasToAlias: subItem.aliasToAlias
+ Item {
+ id: subItem
+ property alias aliasToAlias: subsubItem.aliasToAlias
+
+ Item {
+ id: subsubItem
+ property alias aliasToAlias: subsubsubItem.value
+
+ Item {
+ id: subsubsubItem
+ property string value: "Hello World!"
+ }
+ }
+ }
+
+ property alias aliasToOtherFile: inOtherFile.setMe
+
+ ComponentWithAlias1 {
+ id: inOtherFile
+ }
+}
+
diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp
index 26265fcb46..2c5a164989 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.cpp
+++ b/tests/auto/qml/qmltc/tst_qmltc.cpp
@@ -76,7 +76,7 @@
#include "appendtoqqmllistproperty.h"
#include "inlinecomponents.h"
#include "repeatercrash.h"
-
+#include "aliases.h"
#include "testprivateproperty.h"
// Qt:
@@ -2930,4 +2930,34 @@ void tst_qmltc::inlineComponents()
}
}
+void tst_qmltc::aliases()
+{
+ QQmlEngine e;
+ PREPEND_NAMESPACE(aliases) fromQmltc(&e);
+
+ QQmlComponent component(&e);
+ component.loadUrl(QUrl("qrc:/qt/qml/QmltcTests/aliases.qml"));
+ QVERIFY(!component.isError());
+ QScopedPointer<QObject> fromComponent(component.create());
+ const QString testString = u"myTestString"_s;
+
+ QCOMPARE(fromQmltc.aliasToAlias(), u"Hello World!"_s);
+ QCOMPARE(fromComponent->property("aliasToAlias"), u"Hello World!"_s);
+
+ fromQmltc.setAliasToAlias(testString);
+ QVERIFY(fromComponent->setProperty("aliasToAlias", testString));
+
+ QCOMPARE(fromQmltc.aliasToAlias(), testString);
+ QCOMPARE(fromComponent->property("aliasToAlias"), testString);
+
+ QCOMPARE(fromQmltc.aliasToOtherFile(), u"Set me!"_s);
+ QCOMPARE(fromComponent->property("aliasToOtherFile"), u"Set me!"_s);
+
+ fromQmltc.setAliasToOtherFile(testString);
+ QVERIFY(fromComponent->setProperty("aliasToOtherFile", testString));
+
+ QCOMPARE(fromQmltc.aliasToOtherFile(), testString);
+ QCOMPARE(fromComponent->property("aliasToOtherFile"), testString);
+}
+
QTEST_MAIN(tst_qmltc)
diff --git a/tests/auto/qml/qmltc/tst_qmltc.h b/tests/auto/qml/qmltc/tst_qmltc.h
index 0eea63b0f2..eaa4bed27a 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.h
+++ b/tests/auto/qml/qmltc/tst_qmltc.h
@@ -88,4 +88,5 @@ private slots:
void generalizedGroupedProperty();
void appendToQQmlListProperty();
void inlineComponents();
+ void aliases();
};