diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2024-06-24 09:08:47 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-06-28 18:16:48 +0200 |
| commit | 3d3ff946e3986e2ab2c28416b70b76b7988ab1da (patch) | |
| tree | a5d33984d10062b28de82e15027e00d7bc281f48 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
| parent | 681a8fd952d95d79e2023e70fa37581e56c89a8e (diff) | |
QmlCompiler: Don't generate invalid code for unstorable lists
When printing a sequence type through one of the console methods, we
have to consider the adjusted type, not only the one we intended to
read.
Amends commit 7894f271ab3714102e14744914de6d0549b9a7d8.
Pick-to: 6.8
Task-number: QTBUG-126398
Change-Id: I4606ed2006a547bdf93ec136ebbfab10b706b917
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 53cc068e8c..21d649a690 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -7,6 +7,7 @@ #include <data/enumProperty.h> #include <data/enumproblems.h> #include <data/getOptionalLookup.h> +#include <data/listprovider.h> #include <data/objectwithmethod.h> #include <data/resettable.h> #include <data/weathermoduleurl.h> @@ -148,6 +149,7 @@ private slots: void jsImport(); void jsMathObject(); void jsmoduleImport(); + void jsonArrayToStringList(); void lengthAccessArraySequenceCompat(); void letAndConst(); void listAsArgument(); @@ -2892,6 +2894,29 @@ void tst_QmlCppCodegen::jsmoduleImport() QVERIFY(result.toBool()); } +void tst_QmlCppCodegen::jsonArrayToStringList() +{ + QQmlEngine engine; + QQmlComponent component(&engine, QUrl(u"qrc:/qt/qml/TestTypes/jsonArrayToStringList.qml"_s)); + QVERIFY2(!component.isError(), component.errorString().toUtf8()); + QTest::ignoreMessage(QtDebugMsg, "json [1,aa,2,null,null]"); + + // TODO: Enable when fixed. We cannot QEXPECT_FAIL on ignoreMessage + // QTest::ignoreMessage(QtDebugMsg, "strings [1,aa,2,null,null]"); + // QTest::ignoreMessage(QtDebugMsg, "strings2 [1,aa,2,null,null]"); + + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + + QListProvider *provider = qobject_cast<QListProvider *>(object.data()); + QCOMPARE(provider->json(), QJsonDocument::fromJson("[1,\"aa\",2,null,null]").array()); + QEXPECT_FAIL("", "assignment to string list is broken", Continue); + QCOMPARE(provider->strings(), (QStringList { u"1"_s, u"aa"_s, u"2"_s, u"null"_s, u"null"_s })); + QEXPECT_FAIL("", "assignment to string list is broken", Continue); + QCOMPARE(provider->property("strings2").toStringList(), + (QStringList { u"1"_s, u"aa"_s, u"2"_s, u"null"_s, u"null"_s })); +} + void tst_QmlCppCodegen::lengthAccessArraySequenceCompat() { QQmlEngine engine; |
