diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-07-29 16:19:21 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-08-04 14:24:47 +0200 |
commit | d1a6e6884bfe8db7070a5ba21d59aa1b86eeecb6 (patch) | |
tree | 9938f04bc940dcd69109ff0283f2b9c274e488a5 /tests | |
parent | 25a0ca5e1163fe8de0efdc78f1a9f2a4724f41c9 (diff) |
QmlCompiler: Allow any conversion possible via QJSPrimitiveValue
All of those are legal in ECMAScript, and so we need to support them in
script bindings. As we have stricter rules for literal bindings, add an
extra method there to check for what QQmlPropertyValidator does.
Fixes: QTBUG-105252
Task-number: QTBUG-105188
Change-Id: I0621b2c3aa196414f669873e93670557284a8bca
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit b184d026484572915c3ff34224dfc371a4e6a3cc)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/notNotString.qml | 7 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 13 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/templateStringSubstitution.qml (renamed from tests/auto/qml/qmllint/data/badTemplateStringSubstitution.qml) | 0 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 38 |
5 files changed, 34 insertions, 25 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt index d5711293b0..f3e608a6ae 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -114,6 +114,7 @@ set(qml_files nonNotifyable.qml noscope.qml notEqualsInt.qml + notNotString.qml nullAccess.qml objectInVar.qml outOfBounds.qml diff --git a/tests/auto/qml/qmlcppcodegen/data/notNotString.qml b/tests/auto/qml/qmlcppcodegen/data/notNotString.qml new file mode 100644 index 0000000000..d46c2cddc9 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/notNotString.qml @@ -0,0 +1,7 @@ +pragma Strict +import QML + +QtObject { + id: self + property bool notNotString: !!self.objectName +} diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 2d8c1b00c7..186758518e 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -131,6 +131,7 @@ private slots: void enumLookup(); void stringToByteArray(); void listPropertyAsModel(); + void notNotString(); }; void tst_QmlCppCodegen::simpleBinding() @@ -2402,6 +2403,18 @@ void tst_QmlCppCodegen::listPropertyAsModel() QCOMPARE(children.count(), 5); } +void tst_QmlCppCodegen::notNotString() +{ + QQmlEngine engine; + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/notNotString.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + + QCOMPARE(o->property("notNotString").value<bool>(), false); + o->setObjectName(u"a"_s); + QCOMPARE(o->property("notNotString").value<bool>(), true); +} + void tst_QmlCppCodegen::runInterpreted() { #ifdef Q_OS_ANDROID diff --git a/tests/auto/qml/qmllint/data/badTemplateStringSubstitution.qml b/tests/auto/qml/qmllint/data/templateStringSubstitution.qml index 64d6e0158d..64d6e0158d 100644 --- a/tests/auto/qml/qmllint/data/badTemplateStringSubstitution.qml +++ b/tests/auto/qml/qmllint/data/templateStringSubstitution.qml diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index e57541162f..e0e690ed99 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -562,24 +562,20 @@ void TestQmllint::dirtyQmlCode_data() QTest::newRow("bad template literal (simple)") << QStringLiteral("badTemplateStringSimple.qml") << Result { { Message { - QStringLiteral("Cannot assign binding of type string to int") } } }; - QTest::newRow("bad template literal (substitution)") - << QStringLiteral("badTemplateStringSubstitution.qml") - << Result { { Message { - QStringLiteral("Cannot assign binding of type QString to int") } } }; + QStringLiteral("Cannot assign literal of type string to int") } } }; QTest::newRow("bad constant number to string") << QStringLiteral("numberToStringProperty.qml") << Result { { Message { QStringLiteral( - "Cannot assign a numeric constant to a string property") } } }; + "Cannot assign literal of type double to QString") } } }; QTest::newRow("bad unary minus to string") << QStringLiteral("unaryMinusToStringProperty.qml") << Result { { Message { QStringLiteral( - "Cannot assign a numeric constant to a string property") } } }; + "Cannot assign literal of type double to QString") } } }; QTest::newRow("bad tranlsation binding (qsTr)") << QStringLiteral("bad_qsTr.qml") << Result {}; QTest::newRow("bad string binding (QT_TR_NOOP)") << QStringLiteral("bad_QT_TR_NOOP.qml") << Result { { Message { - QStringLiteral("Cannot assign binding of type string to int") } } }; + QStringLiteral("Cannot assign literal of type string to int") } } }; QTest::newRow("BadScriptBindingOnGroup") << QStringLiteral("badScriptBinding.group.qml") << Result { { Message { @@ -679,7 +675,7 @@ void TestQmllint::dirtyQmlCode_data() QTest::newRow("badAttachedPropertyTypeString") << QStringLiteral("badAttachedPropertyTypeString.qml") << Result { { Message { - QStringLiteral("Cannot assign binding of type string to int") } } }; + QStringLiteral("Cannot assign literal of type string to int") } } }; QTest::newRow("badAttachedPropertyTypeQtObject") << QStringLiteral("badAttachedPropertyTypeQtObject.qml") << Result { { Message { QStringLiteral( @@ -789,18 +785,10 @@ expression: \${expr} \${expr} \\\${expr} \\\${expr}`)", QTest::newRow("WithStatement") << QStringLiteral("WithStatement.qml") << Result { { Message { QStringLiteral( "with statements are strongly discouraged") } } }; - QTest::newRow("BindingTypeMismatch") - << QStringLiteral("bindingTypeMismatch.qml") - << Result { { Message { - QStringLiteral("Cannot assign binding of type QString to int") } } }; - QTest::newRow("BindingTypeMismatchFunction") - << QStringLiteral("bindingTypeMismatchFunction.qml") - << Result { { Message { - QStringLiteral("Cannot assign binding of type QString to int") } } }; QTest::newRow("BadLiteralBinding") << QStringLiteral("badLiteralBinding.qml") << Result { { Message { - QStringLiteral("Cannot assign binding of type string to int") } } }; + QStringLiteral("Cannot assign literal of type string to int") } } }; QTest::newRow("BadLiteralBindingDate") << QStringLiteral("badLiteralBindingDate.qml") << Result { { Message { @@ -939,11 +927,7 @@ expression: \${expr} \${expr} \\\${expr} \\\${expr}`)", { Message { QStringLiteral("Ready") } } } }; QTest::newRow("nullBinding") << QStringLiteral("nullBinding.qml") << Result{ { Message{ QStringLiteral( - "Cannot assign binding of type null to double") } } }; - QTest::newRow("nullBindingFunction") - << QStringLiteral("nullBindingFunction.qml") - << Result{ { Message{ - QStringLiteral("Cannot assign binding of type null to double") } } }; + "Cannot assign literal of type null to double") } } }; QTest::newRow("missingRequiredAlias") << QStringLiteral("missingRequiredAlias.qml") << Result { { Message { @@ -1157,6 +1141,10 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("prefixedAttachedProperty") << QStringLiteral("prefixedAttachedProperty.qml"); QTest::newRow("stringToByteArray") << QStringLiteral("stringToByteArray.qml"); QTest::newRow("jsLibrary") << QStringLiteral("jsLibrary.qml"); + QTest::newRow("nullBindingFunction") << QStringLiteral("nullBindingFunction.qml"); + QTest::newRow("BindingTypeMismatchFunction") << QStringLiteral("bindingTypeMismatchFunction.qml"); + QTest::newRow("BindingTypeMismatch") << QStringLiteral("bindingTypeMismatch.qml"); + QTest::newRow("template literal (substitution)") << QStringLiteral("templateStringSubstitution.qml"); } void TestQmllint::cleanQmlCode() @@ -1691,9 +1679,9 @@ void TestQmllint::quickPlugin() u"Cannot specify top, bottom, and verticalCenter anchors at the same time."_s }, Message{ u"Baseline anchor cannot be used in conjunction with top, bottom, or verticalCenter anchors."_s }, - Message { u"Cannot assign binding of type null to QQuickAnchorLine"_s, 5, + Message { u"Cannot assign literal of type null to QQuickAnchorLine"_s, 5, 35 }, - Message { u"Cannot assign binding of type null to QQuickAnchorLine"_s, 6, + Message { u"Cannot assign literal of type null to QQuickAnchorLine"_s, 6, 33 } } }); runTest("pluginQuick_anchorsUndefined.qml", Result::clean()); runTest("pluginQuick_layoutChildren.qml", |