diff options
| author | Sami Shalayel <sami.shalayel@qt.io> | 2025-06-05 10:51:46 +0200 |
|---|---|---|
| committer | Sami Shalayel <sami.shalayel@qt.io> | 2025-06-06 13:04:40 +0200 |
| commit | c9713681e8d0ee7b7a69d38c5972ee73e8ee4b78 (patch) | |
| tree | 24324285d457bdea2b780b3faa0c8d73ff63125b /tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp | |
| parent | f2e8a9b49f2c1bd8d1dc6bc424d6148173f9a142 (diff) | |
qmlcachegen: fix crash on unresolved type with required property
qmlcachegen can't resolve all types when importing QtQuick.Controls, so
scopes from QtQuick.Controls might be unresolved.
Check the scope before creating a fix suggesion when checking the
required properties, and add a test that tests a file with required
properties on an unresolved base type "Tumbler".
This also fixes the crashes from QTBUG-137196 and QTBUG-136998 it seems.
Pick-to: 6.10 6.9 6.8 6.5
Fixes: QTBUG-137411
Fixes: QTBUG-137196
Fixes: QTBUG-136998
Change-Id: Ibf461b54abf84ba13bff8c4833940c7359cf2d8e
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp')
| -rw-r--r-- | tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp index 653556a213..21e76a4ab5 100644 --- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp +++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp @@ -74,6 +74,9 @@ private slots: void aotstatsGeneration_data(); void aotstatsGeneration(); void aotstatsFormatRevisionMissmatch(); + + void crash_data(); + void crash(); }; // A wrapper around QQmlComponent to ensure the temporary reference counts @@ -122,6 +125,36 @@ static bool generateCache(const QString &qmlFileName, QByteArray *capturedStderr return proc.exitCode() == 0; } +static bool generateCpp(const QString &qmlFileName, QByteArray *capturedStderr = nullptr) +{ +#if defined(QTEST_CROSS_COMPILED) + QTest::qFail("You cannot call qmlcachegen on the target.", __FILE__, __LINE__); + return false; +#endif + QProcess proc; + if (capturedStderr == nullptr) + proc.setProcessChannelMode(QProcess::ForwardedChannels); + proc.setProgram(QLibraryInfo::path(QLibraryInfo::LibraryExecutablesPath) + + QLatin1String("/qmlcachegen")); + QTemporaryDir outputDir; + const QString outputFile = outputDir.filePath("output.cpp"_L1); + proc.setArguments(QStringList{ "--resource-path"_L1, "qrc:/qt/qml/Crashes/testFile.qml"_L1, + "-o"_L1, outputFile, qmlFileName }); + proc.start(); + if (!proc.waitForFinished()) + return false; + + if (capturedStderr) + *capturedStderr = proc.readAllStandardError(); + + if (!QFile::exists(outputFile)) + return false; + + if (proc.exitStatus() != QProcess::NormalExit) + return false; + return proc.exitCode() == 0; +} + tst_qmlcachegen::tst_qmlcachegen() : QQmlDataTest(QT_QMLTEST_DATADIR) { @@ -1049,6 +1082,27 @@ void tst_qmlcachegen::aotstatsFormatRevisionMissmatch() QVERIFY(!QQmlJS::AotStats::fromJsonDocument(document).has_value()); } +void tst_qmlcachegen::crash_data() +{ + QTest::addColumn<QString>("fileName"); + + QTest::addRow("buggyFixSuggestion") << u"buggyFixSuggestion.qml"_s; +} + +void tst_qmlcachegen::crash() +{ +#if defined(QTEST_CROSS_COMPILED) + QSKIP("Cannot call qmlcachegen on cross-compiled target."); +#endif + + QFETCH(QString, fileName); + const QString filePath = testFile("crashes/" + fileName); + + QFile file(filePath); + QVERIFY(file.exists()); + QVERIFY(generateCpp(filePath)); +} + const QQmlScriptString &ScriptStringProps::undef() const { return m_undef; |
