diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2024-04-03 17:55:45 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-04-05 20:38:07 +0200 |
commit | b91a26ae3b7b2ab68128f41db6ed4ccf7366dfc4 (patch) | |
tree | 172c9daaef074f9a875fb9aca8cc5ff938ccf0e4 /tests/auto | |
parent | 4b5f091c499b5aad66a8b39fcdab8f80d986a1f8 (diff) |
QtQml: Resolve generalized group properties during alias resolution
This way we can know the scope in which to search for the IDs.
Pick-to: 6.7 6.5
Fixes: QTBUG-123865
Change-Id: I1dff9bdc69e3edaa80d85c757e3bb2b24e174cd0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto')
3 files changed, 151 insertions, 0 deletions
diff --git a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp index c1df8ec467..810fdecafd 100644 --- a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp +++ b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp @@ -42,6 +42,7 @@ private slots: void cacheModuleScripts(); void reuseStaticMappings(); void invalidateSaveLoadCache(); + void duplicateIdsInInlineComponents(); void inlineComponentDoesNotCauseConstantInvalidation_data(); void inlineComponentDoesNotCauseConstantInvalidation(); @@ -1186,6 +1187,77 @@ void tst_qmldiskcache::invalidateSaveLoadCache() QVERIFY(unit->unitData() != oldUnit->unitData()); } +void tst_qmldiskcache::duplicateIdsInInlineComponents() +{ + // Exercise the case of loading strange generalized group properties from .qmlc. + + QQmlEngine engine; + + TestCompiler testCompiler(&engine); + QVERIFY(testCompiler.tempDir.isValid()); + + const QByteArray contents = QByteArrayLiteral(R"( + import QtQml + QtObject { + component First : QtObject { + property QtObject aa: QtObject { + id: a + } + property Binding bb: Binding { + a.objectName: "test1" + } + } + + component Second : QtObject { + property QtObject aa: QtObject { + id: a + } + property Binding bb: Binding { + a.objectName: "test2" + } + + property Component cc: QtObject { + property QtObject aa: QtObject { + id: a + } + property Binding bb: Binding { + a.objectName: "test3" + } + } + } + + property First first: First {} + property Second second: Second {} + property QtObject third: second.cc.createObject(); + + objectName: first.aa.objectName + second.aa.objectName + third.aa.objectName; + } + )"); + + { + testCompiler.clearCache(); + QVERIFY2(testCompiler.compile(contents), qPrintable(testCompiler.lastErrorString)); + QVERIFY2(testCompiler.verify(), qPrintable(testCompiler.lastErrorString)); + } + + { + CleanlyLoadingComponent component(&engine, testCompiler.testFilePath); + + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + QCOMPARE(obj->objectName(), "test1test2test3"); + } + + engine.clearComponentCache(); + + { + CleanlyLoadingComponent component(&engine, testCompiler.testFilePath); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + QCOMPARE(obj->objectName(), "test1test2test3"); + } +} + void tst_qmldiskcache::inlineComponentDoesNotCauseConstantInvalidation_data() { QTest::addColumn<QByteArray>("code"); diff --git a/tests/auto/qml/qqmlpropertycache/data/duplicateIdsAndGeneralizedGroupProperties.qml b/tests/auto/qml/qqmlpropertycache/data/duplicateIdsAndGeneralizedGroupProperties.qml new file mode 100644 index 0000000000..2dd2cd8e21 --- /dev/null +++ b/tests/auto/qml/qqmlpropertycache/data/duplicateIdsAndGeneralizedGroupProperties.qml @@ -0,0 +1,64 @@ +import QtQuick 2.15 + +Item { + component First : Item { + Item { + id: a + } + + states: [ + State { + name: "test1" + + PropertyChanges { + a.enabled: false + } + } + ] + } + + component Second : Item { + QtObject { + id: a + property bool enabled: true + } + + states: [ + State { + name: "test2" + + PropertyChanges { + a.enabled: false + } + } + ] + + property Component cc: Item { + Item { id: a } + + states: [ + State { + name: "test3" + + PropertyChanges { + a.enabled: false + } + } + ] + } + } + + First { id: first } + Second { id: second } + property Item third: second.cc.createObject(); + + Component.onCompleted: { + console.log(1, first.data[0].enabled, second.data[0].enabled, third.data[0].enabled); + first.state = "test1"; + console.log(2, first.data[0].enabled, second.data[0].enabled, third.data[0].enabled); + second.state = "test2"; + console.log(3, first.data[0].enabled, second.data[0].enabled, third.data[0].enabled); + third.state = "test3"; + console.log(4, first.data[0].enabled, second.data[0].enabled, third.data[0].enabled); + } +} diff --git a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp index 2d7a7b954c..6af2a3e371 100644 --- a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp +++ b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp @@ -36,6 +36,7 @@ private slots: void restrictRegistrationVersion(); void rejectOverriddenFinal(); void overriddenSignals(); + void duplicateIdsAndGeneralizedGroupProperties(); private: QQmlEngine engine; @@ -774,4 +775,18 @@ void tst_qqmlpropertycache::overriddenSignals() // Should be an error, but we can't enforce it yet. } +void tst_qqmlpropertycache::duplicateIdsAndGeneralizedGroupProperties() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("duplicateIdsAndGeneralizedGroupProperties.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + + QTest::ignoreMessage(QtDebugMsg, "1 true true true"); + QTest::ignoreMessage(QtDebugMsg, "2 false true true"); + QTest::ignoreMessage(QtDebugMsg, "3 false false true"); + QTest::ignoreMessage(QtDebugMsg, "4 false false false"); + + QScopedPointer<QObject> o(c.create()); +} + QTEST_MAIN(tst_qqmlpropertycache) |