diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2021-12-17 12:57:01 +0100 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2021-12-24 12:17:49 +0000 |
commit | 5aec2bedcb9538140ead12e340caee84f606cb96 (patch) | |
tree | d8b7d1842f97c8e7fdd83c862c012666d06da72e /tests | |
parent | 28f59cea3139a2c810ba4c5e98c5d2142ac7b879 (diff) |
QQmlJSImportVisitor: Fix property change handler detection logic
We can have weird cases like `onXChanged: {}` with x's NOTIFY named
xNotReallyChanged and those should still function correctly; bindable
properties without notify can also use property change handlers
Picking to 6.3 as this is pretty much a bug + qmltc needs this as well
to support the weird cases (as otherwise it'll just fail in the visitor)
Change-Id: Ib9a1ce8b7d76133a89bcf0dab16f25659ce69c2b
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
(cherry picked from commit 72efa7f9814e0593156cfde3ce7201d481173d1a)
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
8 files changed, 130 insertions, 0 deletions
diff --git a/tests/auto/qml/qmllint/data/PropertyChangeHandlers/propertychangehandlers.qmltypes b/tests/auto/qml/qmllint/data/PropertyChangeHandlers/propertychangehandlers.qmltypes new file mode 100644 index 0000000000..d16b97dc6c --- /dev/null +++ b/tests/auto/qml/qmllint/data/PropertyChangeHandlers/propertychangehandlers.qmltypes @@ -0,0 +1,65 @@ +import QtQuick.tooling 1.2 +Module { + Component { + file: "typewithproperties.h" + name: "TypeWithProperties" + accessSemantics: "reference" + prototype: "QObject" + exports: ["QmltcTests/TypeWithProperties 1.0"] + exportMetaObjectRevisions: [256] + Property { + name: "a" + type: "double" + bindable: "bindableA" + read: "a" + write: "setA" + index: 0 + } + Property { + name: "b" + type: "QString" + read: "b" + write: "setB" + notify: "bChanged" + index: 1 + } + Property { + name: "c" + type: "QVariant" + read: "c" + write: "setC" + notify: "cWeirdSignal" + index: 2 + } + Property { + name: "d" + type: "QVariant" + bindable: "bindableD" + read: "d" + write: "setD" + notify: "dSignal" + index: 3 + } + Property { + name: "e" + type: "QString" + bindable: "bindableE" + read: "e" + write: "setE" + notify: "eChanged" + index: 3 + } + Signal { name: "bChanged" } + Signal { + name: "cWeirdSignal" + Parameter { type: "QVariant" } + } + Signal { + name: "dSignal" + Parameter { type: "QVariant" } + Parameter { type: "QString" } + } + Signal { name: "eChanged" } + Method { name: "wannabeSignal" } + } +} diff --git a/tests/auto/qml/qmllint/data/PropertyChangeHandlers/qmldir b/tests/auto/qml/qmllint/data/PropertyChangeHandlers/qmldir new file mode 100644 index 0000000000..6adb690e9c --- /dev/null +++ b/tests/auto/qml/qmllint/data/PropertyChangeHandlers/qmldir @@ -0,0 +1,3 @@ +module PropertyChangeHandlers +typeinfo propertychangehandlers.qmltypes +import QtQml diff --git a/tests/auto/qml/qmllint/data/badCppPropertyChangeHandlers1.qml b/tests/auto/qml/qmllint/data/badCppPropertyChangeHandlers1.qml new file mode 100644 index 0000000000..a2d1c14aaa --- /dev/null +++ b/tests/auto/qml/qmllint/data/badCppPropertyChangeHandlers1.qml @@ -0,0 +1,4 @@ +import PropertyChangeHandlers 1.0 +TypeWithProperties { + onAChanged: function(value) { console.log("error!", value); } +} diff --git a/tests/auto/qml/qmllint/data/badCppPropertyChangeHandlers2.qml b/tests/auto/qml/qmllint/data/badCppPropertyChangeHandlers2.qml new file mode 100644 index 0000000000..8e6ed938b0 --- /dev/null +++ b/tests/auto/qml/qmllint/data/badCppPropertyChangeHandlers2.qml @@ -0,0 +1,4 @@ +import PropertyChangeHandlers 1.0 +TypeWithProperties { + onBChanged: function(value) { console.log("error!", value); } +} diff --git a/tests/auto/qml/qmllint/data/badCppPropertyChangeHandlers3.qml b/tests/auto/qml/qmllint/data/badCppPropertyChangeHandlers3.qml new file mode 100644 index 0000000000..58b56128d2 --- /dev/null +++ b/tests/auto/qml/qmllint/data/badCppPropertyChangeHandlers3.qml @@ -0,0 +1,4 @@ +import PropertyChangeHandlers 1.0 +TypeWithProperties { + onXChanged: { console.log("error!"); } +} diff --git a/tests/auto/qml/qmllint/data/badCppPropertyChangeHandlers4.qml b/tests/auto/qml/qmllint/data/badCppPropertyChangeHandlers4.qml new file mode 100644 index 0000000000..6526a46a8c --- /dev/null +++ b/tests/auto/qml/qmllint/data/badCppPropertyChangeHandlers4.qml @@ -0,0 +1,4 @@ +import PropertyChangeHandlers 1.0 +TypeWithProperties { + onWannabeSignal: { console.log("error!"); } +} diff --git a/tests/auto/qml/qmllint/data/goodCppPropertyChangeHandlers.qml b/tests/auto/qml/qmllint/data/goodCppPropertyChangeHandlers.qml new file mode 100644 index 0000000000..1ec2284c7d --- /dev/null +++ b/tests/auto/qml/qmllint/data/goodCppPropertyChangeHandlers.qml @@ -0,0 +1,26 @@ +import PropertyChangeHandlers 1.0 +import QtQuick +Item { + TypeWithProperties { + onAChanged: { console.log("OK"); } + onBChanged: { console.log("OK"); } + onCChanged: { console.log("OK"); } + onDChanged: { console.log("OK"); } + onEChanged: { console.log("OK"); } + } + + TypeWithProperties { + onCWeirdSignal: { console.log("OK"); } + onDSignal: { console.log("OK"); } + } + + TypeWithProperties { + onCWeirdSignal: function(value) { console.log("OK?", value); } + onDSignal: function(value, str) { console.log("OK?", value, str); } + } + + TypeWithProperties { + onCChanged: function(value) { console.log("OK?", value); } + onDChanged: function(value, str) { console.log("OK?", value, str); } + } +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 14bdc7dfbd..9c574cd252 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -790,6 +790,24 @@ void TestQmllint::dirtyQmlCode_data() << QStringLiteral("Property \"objectName\" not found on type \"Foozle\"") << QStringLiteral("Unqualified access") << QString() << false; + QTest::newRow("cppPropertyChangeHandlers-wrong-parameters-size-bindable") + << QStringLiteral("badCppPropertyChangeHandlers1.qml") + << QStringLiteral("Signal handler for \"onAChanged\" has more formal parameters than " + "the signal it handles") + << QString() << QString() << false; + QTest::newRow("cppPropertyChangeHandlers-wrong-parameters-size-notify") + << QStringLiteral("badCppPropertyChangeHandlers2.qml") + << QStringLiteral("Signal handler for \"onBChanged\" has more formal parameters than " + "the signal it handles") + << QString() << QString() << false; + QTest::newRow("cppPropertyChangeHandlers-no-property") + << QStringLiteral("badCppPropertyChangeHandlers3.qml") + << QStringLiteral("no matching signal found for handler \"onXChanged\"") << QString() + << QString() << false; + QTest::newRow("cppPropertyChangeHandlers-not-a-signal") + << QStringLiteral("badCppPropertyChangeHandlers4.qml") + << QStringLiteral("no matching signal found for handler \"onWannabeSignal\"") + << QString() << QString() << false; } void TestQmllint::dirtyQmlCode() @@ -947,6 +965,8 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("declared property of JS object") << QStringLiteral("bareQt.qml"); QTest::newRow("ID overrides property") << QStringLiteral("accessibleId.qml"); QTest::newRow("matchByName") << QStringLiteral("matchByName.qml"); + QTest::newRow("cppPropertyChangeHandlers") + << QStringLiteral("goodCppPropertyChangeHandlers.qml"); } void TestQmllint::cleanQmlCode() |