diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2023-11-02 16:27:01 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-11-09 19:12:37 +0100 |
| commit | ae3905531320a6603f3fe7065628853dac303cdb (patch) | |
| tree | db13ba4f3b43362f254883e215387a4496e3793b /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
| parent | 674dc3f73d9d730e87483b86aa9d55186c57cd52 (diff) | |
QmlCompiler: Allow comparison of optional types
The only extra case we have to consider is the construction of an
optional type from a QObject-derived since that is stored in a QVariant
rather than a QObject*. Everything else we can compare is already
covered by the generic QJSPrimitiveValue comparison since
QJSPrimitiveValue can store undefined.
Fixes: QTBUG-117799
Change-Id: Iac89f28497c34d217af156d363b8beeda76174ef
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index fedcd477a0..3f0e2a4569 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -165,6 +165,7 @@ private slots: void objectToString(); void objectWithStringListMethod(); void onAssignment(); + void optionalComparison(); void outOfBoundsArray(); void overriddenProperty(); void ownPropertiesNonShadowable(); @@ -3365,6 +3366,27 @@ void tst_QmlCppCodegen::onAssignment() QCOMPARE(object->property("scale").toDouble(), 1.0); } +void tst_QmlCppCodegen::optionalComparison() +{ + QQmlEngine engine; + QQmlComponent component(&engine, QUrl(u"qrc:/qt/qml/TestTypes/optionalComparison.qml"_s)); + QVERIFY2(!component.isError(), component.errorString().toUtf8()); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + + QCOMPARE(object->property("found").toInt(), 1); + QCOMPARE(object->property("foundStrict").toInt(), 1); + QCOMPARE(object->property("foundNot").toInt(), 2); + QCOMPARE(object->property("foundStrictNot").toInt(), 2); + + // this === this, null === null (x4), undefined === undefined + QCOMPARE(object->property("undefinedEqualsUndefined").toInt(), 6); + + QCOMPARE(object->property("optionalNull").toBool(), true); + object->setObjectName("foo"_L1); + QCOMPARE(object->property("optionalNull").toBool(), false); +} + void tst_QmlCppCodegen::outOfBoundsArray() { QQmlEngine engine; |
