aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Shalayel <[email protected]>2025-05-06 08:51:34 +0200
committerSami Shalayel <[email protected]>2025-05-31 07:02:18 +0200
commit455f3169e348e39aeea3c24f6a53103a816d7d20 (patch)
tree0e45b5e0042e82e7a67dbfae6f91a02e21af4815
parenta39d417a67c0ff2596026dd94f39f0db34a13186 (diff)
make tst_generate_qmlls_ini a data testHEADdev
Massage the test to become a data test, so that it can be more easily extended and changed. Change-Id: I7eca260b9ba4b73fd4d474ed18ebd0bed46afb5a Reviewed-by: Fabian Kosmale <[email protected]>
-rw-r--r--tests/auto/cmake/test_generate_qmlls_ini/main.cpp154
1 files changed, 72 insertions, 82 deletions
diff --git a/tests/auto/cmake/test_generate_qmlls_ini/main.cpp b/tests/auto/cmake/test_generate_qmlls_ini/main.cpp
index 1582c3da02..614273ba21 100644
--- a/tests/auto/cmake/test_generate_qmlls_ini/main.cpp
+++ b/tests/auto/cmake/test_generate_qmlls_ini/main.cpp
@@ -13,6 +13,7 @@ class tst_generate_qmlls_ini : public QObject
{
Q_OBJECT
private slots:
+ void qmllsIniAreCorrect_data();
void qmllsIniAreCorrect();
};
@@ -25,66 +26,58 @@ using namespace Qt::StringLiterals;
# define BUILD_DIRECTORY u"invalid_build_directory"_s
#endif
-void tst_generate_qmlls_ini::qmllsIniAreCorrect()
+static QString contentOf(const QString &fileName)
+{
+ auto file = QFile(fileName);
+ [&file] {
+ QVERIFY(file.exists());
+ QVERIFY(file.open(QFile::ReadOnly | QFile::Text));
+ }();
+ return QString::fromUtf8(file.readAll());
+}
+
+void tst_generate_qmlls_ini::qmllsIniAreCorrect_data()
{
- const QString qmllsIniName = u".qmlls.ini"_s;
+ QTest::addColumn<QString>("folder");
+ QTest::addColumn<QStringList>("expectedBuildDirs");
+ QTest::addColumn<QString>("expectedNoCMakeCalls");
+ QTest::addColumn<QString>("expectedDocDir");
+ QTest::addColumn<QStringList>("expectedImportPaths");
+
QDir source(SOURCE_DIRECTORY);
QDir build(BUILD_DIRECTORY);
- if (!source.exists())
+ if (!source.exists()) {
QSKIP(u"Cannot find source directory '%1', skipping test..."_s.arg(SOURCE_DIRECTORY)
.toLatin1());
-
- const QString qmllsIniTemplate = uR"([General]
-buildDir="%1"
-no-cmake-calls=%2
-docDir=%3
-importPaths="%4"
-)"_s;
+ }
const QString &docPath = QLibraryInfo::path(QLibraryInfo::DocumentationPath);
- const QString defaultImportPath = QLibraryInfo::path(QLibraryInfo::QmlImportsPath);
- {
- auto file = QFile(source.absoluteFilePath(qmllsIniName));
- QVERIFY(file.exists());
- QVERIFY(file.open(QFile::ReadOnly | QFile::Text));
- const auto fileContent = QString::fromUtf8(file.readAll());
- auto secondFolder = QDir(build.absolutePath().append(u"/qml/hello/subfolders"_s));
- QVERIFY(secondFolder.exists());
- QCOMPARE(fileContent,
- qmllsIniTemplate.arg(build.absolutePath()
- .append(QDir::listSeparator())
- .append(secondFolder.absolutePath()),
- "false"_L1, docPath, defaultImportPath));
- }
+ const QStringList defaultImportPaths{ QLibraryInfo::path(QLibraryInfo::QmlImportsPath) };
+ const QString noCMakeCalls = "false"_L1;
+
+ QTest::addRow("subfolders") << source.absolutePath()
+ << QStringList{ build.absolutePath(),
+ QDir(build.absolutePath().append(
+ "/qml/hello/subfolders"_L1))
+ .absolutePath() }
+ << noCMakeCalls << docPath << defaultImportPaths;
{
QDir sourceSubfolder = source;
QVERIFY(sourceSubfolder.cd(u"SomeSubfolder"_s));
- QDir buildSubfolder(build.absolutePath().append(u"/SomeSubfolder/qml/Some/Sub/Folder"_s));
- {
- auto file = QFile(sourceSubfolder.absoluteFilePath(qmllsIniName));
- QVERIFY(file.exists());
- QVERIFY(file.open(QFile::ReadOnly | QFile::Text));
- const auto fileContent = QString::fromUtf8(file.readAll());
- QCOMPARE(fileContent,
- qmllsIniTemplate.arg(buildSubfolder.absolutePath(), "false"_L1, docPath,
- defaultImportPath));
- }
+ QTest::addRow("subfolders2")
+ << sourceSubfolder.absolutePath()
+ << QStringList{ build.absoluteFilePath(u"SomeSubfolder/qml/Some/Sub/Folder"_s) }
+ << noCMakeCalls << docPath << defaultImportPaths;
}
{
QDir dottedUriSubfolder = source;
QVERIFY(dottedUriSubfolder.cd(u"Dotted"_s));
QVERIFY(dottedUriSubfolder.cd(u"Uri"_s));
- {
- auto file = QFile(dottedUriSubfolder.absoluteFilePath(qmllsIniName));
- QVERIFY(file.exists());
- QVERIFY(file.open(QFile::ReadOnly | QFile::Text));
- const auto fileContent = QString::fromUtf8(file.readAll());
- QCOMPARE(fileContent,
- qmllsIniTemplate.arg(build.absolutePath(), "false"_L1, docPath,
- defaultImportPath));
- }
+ QTest::addRow("dotted-uri")
+ << dottedUriSubfolder.absolutePath() << QStringList{ build.absolutePath() }
+ << noCMakeCalls << docPath << defaultImportPaths;
}
{
QDir dottedUriSubfolder = source;
@@ -92,61 +85,58 @@ importPaths="%4"
QVERIFY(dottedUriSubfolder.cd(u"Uri"_s));
QVERIFY(dottedUriSubfolder.cd(u"Hello"_s));
QVERIFY(dottedUriSubfolder.cd(u"World"_s));
- {
- auto file = QFile(dottedUriSubfolder.absoluteFilePath(qmllsIniName));
- QVERIFY(file.exists());
- QVERIFY(file.open(QFile::ReadOnly | QFile::Text));
- const auto fileContent = QString::fromUtf8(file.readAll());
- QCOMPARE(fileContent,
- qmllsIniTemplate.arg(build.absolutePath(), "false"_L1, docPath,
- defaultImportPath));
- }
+
+ QTest::addRow("dotted-uri2")
+ << dottedUriSubfolder.absolutePath() << QStringList{ build.absolutePath() }
+ << noCMakeCalls << docPath << defaultImportPaths;
}
{
QDir dottedUriSubfolder = source;
QVERIFY(dottedUriSubfolder.cd(u"ModuleWithDependency"_s));
QVERIFY(dottedUriSubfolder.cd(u"MyModule"_s));
- {
- auto file = QFile(dottedUriSubfolder.absoluteFilePath(qmllsIniName));
- QVERIFY(file.exists());
- QVERIFY(file.open(QFile::ReadOnly | QFile::Text));
- const auto fileContent = QString::fromUtf8(file.readAll());
- QCOMPARE(fileContent,
- qmllsIniTemplate.arg(build.absoluteFilePath(u"ModuleWithDependency"_s),
- "false"_L1, docPath,
- build.absoluteFilePath(u"Dependency"_s)
- + QDir::listSeparator() + defaultImportPath));
- }
+ QTest::addRow("module-with-dependency")
+ << dottedUriSubfolder.absolutePath() << QStringList{ build.absoluteFilePath(u"ModuleWithDependency"_s), }
+ << noCMakeCalls << docPath << QStringList { build.absoluteFilePath(u"Dependency"_s) } + defaultImportPaths;
}
{
QDir quotesInPath = source;
QVERIFY(quotesInPath.cd(u"quotesInPath"_s));
- {
- auto file = QFile(quotesInPath.absoluteFilePath(qmllsIniName));
- QVERIFY(file.exists());
- QVERIFY(file.open(QFile::ReadOnly | QFile::Text));
- const auto fileContent = QString::fromUtf8(file.readAll());
- QCOMPARE(fileContent,
- qmllsIniTemplate.arg(build.absolutePath(), "false"_L1, docPath,
- uR"(\"hello\"\"world\")"_s + QDir::listSeparator()
- + defaultImportPath));
- }
+ QTest::addRow("quotes-in-path")
+ << quotesInPath.absolutePath() << QStringList{ build.absolutePath(), }
+ << noCMakeCalls << docPath << QStringList {R"(\"hello\"\"world\")"_L1 } + defaultImportPaths;
}
{
QDir withoutCMakeBuilds = source;
QVERIFY(withoutCMakeBuilds.cd(u"WithoutCMakeBuilds"_s));
- {
- auto file = QFile(withoutCMakeBuilds.absoluteFilePath(qmllsIniName));
- QVERIFY(file.exists());
- QVERIFY(file.open(QFile::ReadOnly | QFile::Text));
- const auto fileContent = QString::fromUtf8(file.readAll());
- QCOMPARE(fileContent,
- qmllsIniTemplate.arg(build.absolutePath(), "true"_L1, docPath,
- defaultImportPath));
- }
+ QTest::addRow("without-cmake-calls")
+ << withoutCMakeBuilds.absolutePath() << QStringList{ build.absolutePath(), }
+ << u"true"_s << docPath << defaultImportPaths;
}
}
+void tst_generate_qmlls_ini::qmllsIniAreCorrect()
+{
+ QFETCH(QString, folder);
+ QFETCH(QStringList, expectedBuildDirs);
+ QFETCH(QString, expectedNoCMakeCalls);
+ QFETCH(QString, expectedDocDir);
+ QFETCH(QStringList, expectedImportPaths);
+
+ static constexpr QLatin1String qmllsIniName = ".qmlls.ini"_L1;
+ static constexpr QLatin1String qmllsIniTemplate = R"([General]
+buildDir="%1"
+no-cmake-calls=%2
+docDir=%3
+importPaths="%4"
+)"_L1;
+
+ const QString iniContent = contentOf(QString(folder).append("/"_L1).append(qmllsIniName));
+ QCOMPARE(iniContent,
+ qmllsIniTemplate.arg(expectedBuildDirs.join(QDir::listSeparator()),
+ expectedNoCMakeCalls, expectedDocDir,
+ expectedImportPaths.join(QDir::listSeparator())));
+}
+
QTEST_MAIN(tst_generate_qmlls_ini)
#include "main.moc"