diff options
author | Ivan Komissarov <abbapoh@gmail.com> | 2021-05-22 14:45:25 +0200 |
---|---|---|
committer | Ivan Komissarov <ABBAPOH@gmail.com> | 2021-09-23 11:32:23 +0000 |
commit | e87dd50dd5a74d0ddc8f9753a67a0a2500947e5f (patch) | |
tree | cd3085b0a6f5e8ec08b14ff166210e632e6b2a32 /tests | |
parent | 91e0274d265a8ce7070c3d039700341b8d31cf5c (diff) | |
download | qbs-e87dd50dd5a74d0ddc8f9753a67a0a2500947e5f.tar.gz |
Long live qbs-pkgconfig!
This patchset introduce a static library for parsing .pc files. Code is
based on the original pkg-config source code https://
gitlab.freedesktop.org/pkg-config/pkg-config and is written in pure C++
(except for the places where we need access to filesystem as
std::filesystem is not available for all platforms - in that case, Qt
classes are used)
Parsing .pc files manually allows to have more control over dependencies
between modules, e.g. to generate a standalone module per one .pc file
and merge properties using Qbs itself, not via pkg-config.
Library is almost feature-complete and all tests copied from pkg-config
pass. Some functionality is omitted (e.g. prefix variables (what is
this?) or validating dependencies since Qbs does this as well)
Bechmark shows that parsing ~100 files takes about 10-15ms. Running
pkg-config on the same set of files takes ~4 seconds:
RESULT : TestPkgConfig::benchSystem():
14 msecs per iteration (total: 57, iterations: 4)
Fixes: QBS-1615
Change-Id: I5bfdfa588aa04d9d69fd738dd2beea14174c0242
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests')
25 files changed, 519 insertions, 1 deletions
diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index 6f6097787..8b1a124aa 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -5,5 +5,6 @@ add_subdirectory(blackbox) if(WITH_UNIT_TESTS) add_subdirectory(buildgraph) add_subdirectory(language) + add_subdirectory(pkgconfig) add_subdirectory(tools) endif() diff --git a/tests/auto/auto.qbs b/tests/auto/auto.qbs index 2f0aef37c..a4c4beedd 100644 --- a/tests/auto/auto.qbs +++ b/tests/auto/auto.qbs @@ -15,6 +15,7 @@ Project { "buildgraph/buildgraph.qbs", "cmdlineparser/cmdlineparser.qbs", "language/language.qbs", + "pkgconfig/pkgconfig.qbs", "tools/tools.qbs", ] } diff --git a/tests/auto/pkgconfig/CMakeLists.txt b/tests/auto/pkgconfig/CMakeLists.txt new file mode 100644 index 000000000..4d60491ba --- /dev/null +++ b/tests/auto/pkgconfig/CMakeLists.txt @@ -0,0 +1,8 @@ +add_qbs_test(pkgconfig + SOURCES + tst_pkgconfig.cpp + tst_pkgconfig.h + DEPENDS + qbspkgconfig + qbsscriptengine + ) diff --git a/tests/auto/pkgconfig/pkgconfig.qbs b/tests/auto/pkgconfig/pkgconfig.qbs new file mode 100644 index 000000000..d42a5233b --- /dev/null +++ b/tests/auto/pkgconfig/pkgconfig.qbs @@ -0,0 +1,19 @@ +import qbs +import qbs.Utilities + +QbsUnittest { + Depends { name: "qbspkgconfig" } + condition: qbsbuildconfig.enableUnitTests + testName: "pkgconfig" + files: ["../shared.h", "tst_pkgconfig.h", "tst_pkgconfig.cpp"] + cpp.defines: base.concat([ + "SRCDIR=" + Utilities.cStringQuote(path), + ]) + + Group { + name: "testdata" + prefix: "testdata/" + files: ["**/*"] + fileTags: [] + } +} diff --git a/tests/auto/pkgconfig/testdata/non-l-required.json b/tests/auto/pkgconfig/testdata/non-l-required.json new file mode 100644 index 000000000..d2dd90f06 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/non-l-required.json @@ -0,0 +1,12 @@ +{ + "Name": "Non-l flags required test package", + "Description": "Test package for checking order of non-L Libs & Cflags", + "Version": "1.0.0", + "Libs": [ + {"Type": "StaticLibraryName", "Value": "/non-l-required.a"}, + {"Type": "LinkerFlag", "Value": "-pthread"} + ], + "Cflags": [ + {"Type": "IncludePath", "Value": "/non-l-required/include"} + ] +} diff --git a/tests/auto/pkgconfig/testdata/non-l-required.pc b/tests/auto/pkgconfig/testdata/non-l-required.pc new file mode 100644 index 000000000..7e398e2e1 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/non-l-required.pc @@ -0,0 +1,5 @@ +Name: Non-l flags required test package +Description: Test package for checking order of non-L Libs & Cflags +Version: 1.0.0 +Libs: /non-l-required.a -pthread +Cflags: -I/non-l-required/include diff --git a/tests/auto/pkgconfig/testdata/requires-test.json b/tests/auto/pkgconfig/testdata/requires-test.json new file mode 100644 index 000000000..32acf4b91 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/requires-test.json @@ -0,0 +1,18 @@ +{ + "Name": "Requires test package", + "Description": "Dummy pkgconfig test package for testing Requires/Requires.private", + "Version": "1.0.0", + "Libs": [ + {"Type": "LibraryPath", "Value": "/requires-test/lib"}, + {"Type": "LibraryName", "Value": "requires-test"} + ], + "Cflags": [ + {"Type": "IncludePath", "Value": "/requires-test/include"} + ], + "Requires": [ + {"Comparison": "GreaterThanEqual", "Name": "public-dep", "Version": "1"} + ], + "RequiresPrivate": [ + {"Comparison": "GreaterThanEqual", "Name": "private-dep", "Version": "1"} + ] +} diff --git a/tests/auto/pkgconfig/testdata/requires-test.pc b/tests/auto/pkgconfig/testdata/requires-test.pc new file mode 100644 index 000000000..e483db2db --- /dev/null +++ b/tests/auto/pkgconfig/testdata/requires-test.pc @@ -0,0 +1,8 @@ +Name: Requires test package +Description: Dummy pkgconfig test package for testing Requires/Requires.private +Version: 1.0.0 +Requires: public-dep >= 1 +Requires.private: private-dep >= 1 +Libs: -L/requires-test/lib -lrequires-test +Cflags: -I/requires-test/include + diff --git a/tests/auto/pkgconfig/testdata/simple.json b/tests/auto/pkgconfig/testdata/simple.json new file mode 100644 index 000000000..d58556e74 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/simple.json @@ -0,0 +1,20 @@ +{ + "Name": "Simple test", + "Description": "Dummy pkgconfig test package for testing pkgconfig", + "Version": "1.0.0", + "Vars": { + "prefix": "/usr", + "exec_prefix": "/usr", + "libdir": "/usr/lib", + "includedir": "/usr/include" + }, + "Libs": [ + {"Type": "LibraryName", "Value": "simple"} + ], + "LibsPrivate": [ + {"Type": "LibraryName", "Value": "m"} + ], + "Cflags": [ + {"Type": "IncludePath", "Value": "/usr/include"} + ] +} diff --git a/tests/auto/pkgconfig/testdata/simple.pc b/tests/auto/pkgconfig/testdata/simple.pc new file mode 100644 index 000000000..2daa0350f --- /dev/null +++ b/tests/auto/pkgconfig/testdata/simple.pc @@ -0,0 +1,12 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: Simple test +Description: Dummy pkgconfig test package for testing pkgconfig +Version: 1.0.0 +Requires: +Libs: -lsimple +Libs.private: -lm +Cflags: -I${includedir} diff --git a/tests/auto/pkgconfig/testdata/special-flags.json b/tests/auto/pkgconfig/testdata/special-flags.json new file mode 100644 index 000000000..1949820a6 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/special-flags.json @@ -0,0 +1,30 @@ +{ + "Name": "Special flags test", + "Description": "Dummy pkgconfig test package for testing pkgconfig", + "Version": "1.0.0", + "Vars": { + "prefix": "/usr", + "exec_prefix": "/usr", + "libdir": "/usr/lib", + "includedir": "/usr/include" + }, + "Libs": [ + {"Type": "LibraryPath", "Value": "/foo"}, + {"Type": "Framework", "Value": "Foo"}, + {"Type": "LibraryName", "Value": "simple"}, + {"Type": "LibraryPath", "Value": "/bar"}, + {"Type": "Framework", "Value": "Bar"}, + {"Type": "LinkerFlag", "Value": "-Wl,-framework"}, + {"Type": "LinkerFlag", "Value": "-Wl,Baz"} + ], + "Cflags": [ + {"Type": "IncludePath", "Value": "/foo"}, + {"Type": "CompilerFlag", "Value": "-g"}, + {"Type": "SystemIncludePath", "Value": "/system1"}, + {"Type": "DirAfterIncludePath", "Value": "/after1"}, + {"Type": "CompilerFlag", "Value": "-ffoo"}, + {"Type": "IncludePath", "Value": "/bar"}, + {"Type": "DirAfterIncludePath", "Value": "/after2"}, + {"Type": "SystemIncludePath", "Value": "/system2"} + ] +} diff --git a/tests/auto/pkgconfig/testdata/special-flags.pc b/tests/auto/pkgconfig/testdata/special-flags.pc new file mode 100644 index 000000000..0bdaeb1b0 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/special-flags.pc @@ -0,0 +1,11 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: Special flags test +Description: Dummy pkgconfig test package for testing pkgconfig +Version: 1.0.0 +Requires: +Libs: -L/foo -framework Foo -lsimple -L/bar -framework Bar -Wl,-framework -Wl,Baz +Cflags: -I/foo -g -isystem /system1 -idirafter /after1 -ffoo -I/bar -idirafter /after2 -isystem /system2 diff --git a/tests/auto/pkgconfig/testdata/sysroot.json b/tests/auto/pkgconfig/testdata/sysroot.json new file mode 100644 index 000000000..7e8b3f6bb --- /dev/null +++ b/tests/auto/pkgconfig/testdata/sysroot.json @@ -0,0 +1,21 @@ +{ + "Name": "Test for sysroot", + "Description": "Test package for testing sysroot", + "Version": "1.0.0", + "Vars": { + "prefix": "/opt", + "exec_prefix": "/opt", + "libdir": "/opt/lib", + "includedir": "/opt/include", + "sysroot": "/newroot" + }, + "Libs": [ + {"Type": "LibraryPath", "Value": "/newroot/opt/lib"}, + {"Type": "LibraryName", "Value": "system"} + ], + "Cflags": [ + {"Type": "IncludePath", "Value": "/newroot/opt/include"}, + {"Type": "DirAfterIncludePath", "Value": "/newroot/opt/include/after"}, + {"Type": "SystemIncludePath", "Value": "/newroot/opt/include/system"} + ] +} diff --git a/tests/auto/pkgconfig/testdata/sysroot.pc b/tests/auto/pkgconfig/testdata/sysroot.pc new file mode 100644 index 000000000..d2f78987f --- /dev/null +++ b/tests/auto/pkgconfig/testdata/sysroot.pc @@ -0,0 +1,12 @@ +prefix=/opt +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include +sysroot=${pc_sysrootdir} + +Name: Test for sysroot +Description: Test package for testing sysroot +Version: 1.0.0 +Requires: +Libs: -L${libdir} -lsystem +Cflags: -I${includedir} -idirafter ${includedir}/after -isystem ${includedir}/system diff --git a/tests/auto/pkgconfig/testdata/system.json b/tests/auto/pkgconfig/testdata/system.json new file mode 100644 index 000000000..89007e7ec --- /dev/null +++ b/tests/auto/pkgconfig/testdata/system.json @@ -0,0 +1,17 @@ +{ + "Name": "System library", + "Description": "Test package", + "Version": "1.0.0", + "Vars": { + "prefix": "/usr", + "exec_prefix": "/usr", + "libdir": "/usr/lib", + "includedir": "/usr/include" + }, + "Libs": [ + {"Type": "LibraryName", "Value": "system"} + ], + "Cflags": [ + {"Type": "IncludePath", "Value": "/usr/include"} + ] +} diff --git a/tests/auto/pkgconfig/testdata/system.pc b/tests/auto/pkgconfig/testdata/system.pc new file mode 100644 index 000000000..2cef2ed9b --- /dev/null +++ b/tests/auto/pkgconfig/testdata/system.pc @@ -0,0 +1,10 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: System library +Description: Test package +Version: 1.0.0 +Libs: -L${libdir} -lsystem +Cflags: -I${includedir} diff --git a/tests/auto/pkgconfig/testdata/tilde.json b/tests/auto/pkgconfig/testdata/tilde.json new file mode 100644 index 000000000..01ea5d050 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/tilde.json @@ -0,0 +1,11 @@ +{ + "Name": "tilde", + "Description": "tilde test module", + "Version": "1.0", + "Libs": [ + {"Type": "LibraryPath", "Value": "~"} + ], + "Cflags": [ + {"Type": "IncludePath", "Value": "~"} + ] +} diff --git a/tests/auto/pkgconfig/testdata/tilde.pc b/tests/auto/pkgconfig/testdata/tilde.pc new file mode 100644 index 000000000..c3babc120 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/tilde.pc @@ -0,0 +1,5 @@ +Name: tilde +Description: tilde test module +Version: 1.0 +Libs: -L~ +Cflags: -I~ diff --git a/tests/auto/pkgconfig/testdata/variables.json b/tests/auto/pkgconfig/testdata/variables.json new file mode 100644 index 000000000..7565b6804 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/variables.json @@ -0,0 +1,17 @@ +{ + "Name": "Complex variables", + "Description": "Test complex variable output", + "Version": "1.0", + "Vars": { + "prefix": "/local", + "exec_prefix": "/local", + "libdir": "/local/lib", + "includedir": "\"/local/include\"", + "cppflags": "-I\"/local/include\"/foo -DFOO=\\\"/bar\\\"" + }, + "Cflags": [ + {"Type": "IncludePath", "Value": "/local/include"}, + {"Type": "IncludePath", "Value": "/local/include/foo"}, + {"Type": "Define", "Value": "FOO=\"/bar\""} + ] +} diff --git a/tests/auto/pkgconfig/testdata/variables.pc b/tests/auto/pkgconfig/testdata/variables.pc new file mode 100644 index 000000000..b27ab78e1 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/variables.pc @@ -0,0 +1,11 @@ +prefix=/local +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir="${prefix}/include" +cppflags=-I${includedir}/foo \ + -DFOO=\"/bar\" + +Name: Complex variables +Description: Test complex variable output +Version: 1.0 +Cflags: -I${includedir} ${cppflags} diff --git a/tests/auto/pkgconfig/testdata/whitespace.json b/tests/auto/pkgconfig/testdata/whitespace.json new file mode 100644 index 000000000..dcfa3ece3 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/whitespace.json @@ -0,0 +1,24 @@ +{ + "Name": "Whitespace test", + "Description": "Dummy pkgconfig test package for testing pkgconfig", + "Version": "1.0.0", + "Vars": { + "prefix": "/usr", + "exec_prefix": "/usr", + "libdir": "\"/usr/white space/lib\"", + "includedir": "\"/usr/white space/include\"" + }, + "Libs": [ + {"Type": "LibraryPath", "Value": "/usr/white space/lib"}, + {"Type": "LibraryName", "Value": "foo bar"}, + {"Type": "LibraryName", "Value": "bar baz"}, + {"Type": "LinkerFlag", "Value": "-r:foo"} + ], + "Cflags": [ + {"Type": "IncludePath", "Value": "/usr/white space/include"}, + {"Type": "IncludePath", "Value": "$(top_builddir)"}, + {"Type": "IncludePath", "Value": "include dir"}, + {"Type": "IncludePath", "Value": "other include dir"}, + {"Type": "Define", "Value": "lala=misc"} + ] +} diff --git a/tests/auto/pkgconfig/testdata/whitespace.pc b/tests/auto/pkgconfig/testdata/whitespace.pc new file mode 100644 index 000000000..693bbc4d0 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/whitespace.pc @@ -0,0 +1,11 @@ +prefix=/usr +exec_prefix=${prefix} +libdir="${exec_prefix}/white space/lib" +includedir="${prefix}/white space/include" + +Name: Whitespace test +Description: Dummy pkgconfig test package for testing pkgconfig +Version: 1.0.0 +Requires: +Libs: -L${libdir} -lfoo\ bar "-lbar baz" -r:foo +Cflags: -I${includedir} -I$(top_builddir) -Iinclude\ dir "-Iother include dir" -Dlala=misc diff --git a/tests/auto/pkgconfig/tst_pkgconfig.cpp b/tests/auto/pkgconfig/tst_pkgconfig.cpp new file mode 100644 index 000000000..b05dd4923 --- /dev/null +++ b/tests/auto/pkgconfig/tst_pkgconfig.cpp @@ -0,0 +1,181 @@ +/**************************************************************************** +** +** Copyright (C) 2021 Ivan Komissarov (abbapoh@gmail.com) +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qbs. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "tst_pkgconfig.h" + +#include "../shared.h" + +#include <tools/fileinfo.h> +#include <tools/hostosinfo.h> +#include <pkgconfig.h> +#include <jsextensions/pkgconfigjs.h> + +#include <QJsonArray> +#include <QJsonDocument> + +using HostOsInfo = qbs::Internal::HostOsInfo; +using PcPackage = qbs::PcPackage; +using PkgConfig = qbs::PkgConfig; +using Options = qbs::PkgConfig::Options; + +TestPkgConfig::TestPkgConfig() + : m_sourceDataDir(testDataSourceDir(SRCDIR "/testdata")) + , m_workingDataDir(testWorkDir(QStringLiteral("pkgconfig"))) +{ +} + +void TestPkgConfig::initTestCase() +{ + QString errorMessage; + qbs::Internal::removeDirectoryWithContents(m_workingDataDir, &errorMessage); + QVERIFY2(qbs::Internal::copyFileRecursion(m_sourceDataDir, + m_workingDataDir, false, true, &errorMessage), + qPrintable(errorMessage)); +} + +void TestPkgConfig::pkgConfig() +{ + QFETCH(QString, fileName); + QFETCH(QVariantMap, optionsMap); + + Options options = qbs::Internal::PkgConfigJs::convertOptions(QProcessEnvironment::systemEnvironment(), optionsMap); + options.searchPaths.push_back(m_workingDataDir.toStdString()); + + PkgConfig pkgConfig(std::move(options)); + + QFile jsonFile(m_workingDataDir + "/" + fileName + ".json"); + QVERIFY(jsonFile.open(QIODevice::ReadOnly)); + QJsonParseError error{}; + const auto json = QJsonDocument::fromJson(jsonFile.readAll(), &error).toVariant().toMap(); + QCOMPARE(error.error, QJsonParseError::NoError); + + const auto &package = pkgConfig.getPackage(fileName.toStdString()); + QCOMPARE(QString::fromStdString(package.baseFileName), fileName); + QCOMPARE(QString::fromStdString(package.name), json.value("Name").toString()); + QCOMPARE(QString::fromStdString(package.description), json.value("Description").toString()); + QCOMPARE(QString::fromStdString(package.version), json.value("Version").toString()); + + auto vars = json["Vars"].toMap(); + vars["pcfiledir"] = QFileInfo(m_workingDataDir).absoluteFilePath(); + + for (const auto &[key, value]: package.vars) { + QCOMPARE(QString::fromStdString(value), + vars.value(QString::fromStdString(key)).toString()); + } + + const auto jsonLibs = json.value("Libs").toJsonArray().toVariantList(); + QCOMPARE(package.libs.size(), size_t(jsonLibs.size())); + for (size_t i = 0; i < package.libs.size(); ++i) { + const auto &item = package.libs[i]; + const auto jsonItem = jsonLibs.at(i).toMap(); + + QCOMPARE(item.type, + *PcPackage::Flag::typeFromString(jsonItem.value("Type").toString().toStdString())); + QCOMPARE(QString::fromStdString(item.value), jsonItem.value("Value").toString()); + } + + const auto jsonLibsPrivate = json.value("LibsPrivate").toJsonArray().toVariantList(); + QCOMPARE(package.libsPrivate.size(), size_t(jsonLibsPrivate.size())); + for (size_t i = 0; i < package.libsPrivate.size(); ++i) { + const auto &item = package.libsPrivate[i]; + const auto jsonItem = jsonLibsPrivate.at(i).toMap(); + + QCOMPARE(item.type, + *PcPackage::Flag::typeFromString(jsonItem.value("Type").toString().toStdString())); + QCOMPARE(QString::fromStdString(item.value), jsonItem.value("Value").toString()); + } + + const auto jsonCFlags = json.value("Cflags").toJsonArray().toVariantList(); + QCOMPARE(package.cflags.size(), size_t(jsonCFlags.size())); + for (size_t i = 0; i < package.cflags.size(); ++i) { + const auto &item = package.cflags[i]; + const auto jsonItem = jsonCFlags.at(i).toMap(); + + QCOMPARE(item.type, + *PcPackage::Flag::typeFromString(jsonItem.value("Type").toString().toStdString())); + QCOMPARE(QString::fromStdString(item.value), jsonItem.value("Value").toString()); + } + + for (const auto &item: package.requiresPublic) + qInfo() << "requires" << item.name.c_str() << item.version.c_str(); + + const auto jsonRequires = json.value("Requires").toJsonArray().toVariantList(); + QCOMPARE(package.requiresPublic.size(), size_t(jsonRequires.size())); + for (size_t i = 0; i < package.requiresPublic.size(); ++i) { + const auto &item = package.requiresPublic[i]; + const auto jsonItem = jsonRequires.at(i).toMap(); + + QCOMPARE(item.comparison, + *PcPackage::RequiredVersion::comparisonFromString( + jsonItem.value("Comparison").toString().toStdString())); + QCOMPARE(QString::fromStdString(item.name), jsonItem.value("Name").toString()); + QCOMPARE(QString::fromStdString(item.version), jsonItem.value("Version").toString()); + } + + const auto jsonRequiresPrivate = json.value("RequiresPrivate").toJsonArray().toVariantList(); + QCOMPARE(package.requiresPrivate.size(), size_t(jsonRequiresPrivate.size())); + for (size_t i = 0; i < package.requiresPrivate.size(); ++i) { + const auto &item = package.requiresPrivate[i]; + const auto jsonItem = jsonRequiresPrivate.at(i).toMap(); + + QCOMPARE(item.comparison, + *PcPackage::RequiredVersion::comparisonFromString( + jsonItem.value("Comparison").toString().toStdString())); + QCOMPARE(QString::fromStdString(item.name), jsonItem.value("Name").toString()); + QCOMPARE(QString::fromStdString(item.version), jsonItem.value("Version").toString()); + } +} + +void TestPkgConfig::pkgConfig_data() +{ + QTest::addColumn<QString>("fileName"); + QTest::addColumn<QVariantMap>("optionsMap"); + + QTest::newRow("non-l-required") << QStringLiteral("non-l-required") << QVariantMap(); + QTest::newRow("simple") << QStringLiteral("simple") << QVariantMap(); + QTest::newRow("requires-test") << QStringLiteral("requires-test") << QVariantMap(); + QTest::newRow("special-flags") << QStringLiteral("special-flags") << QVariantMap(); + QTest::newRow("system") << QStringLiteral("system") << QVariantMap(); + QTest::newRow("sysroot") + << QStringLiteral("sysroot") << QVariantMap({{"sysroot", "/newroot"}}); + QTest::newRow("tilde") << QStringLiteral("tilde") << QVariantMap(); + QTest::newRow("variables") << QStringLiteral("variables") << QVariantMap(); + QTest::newRow("whitespace") << QStringLiteral("whitespace") << QVariantMap(); +} + +void TestPkgConfig::benchSystem() +{ + if (HostOsInfo::hostOs() == HostOsInfo::HostOsWindows) + QSKIP("Not available on Windows"); + QBENCHMARK { + PkgConfig pkgConfig; + QVERIFY(!pkgConfig.packages().empty()); + } +} + +QTEST_MAIN(TestPkgConfig) diff --git a/tests/auto/pkgconfig/tst_pkgconfig.h b/tests/auto/pkgconfig/tst_pkgconfig.h new file mode 100644 index 000000000..687411862 --- /dev/null +++ b/tests/auto/pkgconfig/tst_pkgconfig.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2021 Ivan Komissarov (abbapoh@gmail.com) +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qbs. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBS_TST_API_H +#define QBS_TST_API_H + +#include <QtCore/qobject.h> +#include <QtCore/qvariant.h> + +class TestPkgConfig : public QObject +{ + Q_OBJECT + +public: + TestPkgConfig(); + +private slots: + void initTestCase(); + void pkgConfig(); + void pkgConfig_data(); + void benchSystem(); + +private: + const QString m_sourceDataDir; + const QString m_workingDataDir; +}; + +#endif // Include guard. diff --git a/tests/auto/shared.h b/tests/auto/shared.h index e97fa9166..94c22b47e 100644 --- a/tests/auto/shared.h +++ b/tests/auto/shared.h @@ -332,7 +332,7 @@ inline QString testWorkDir(const QString &testName) if (!dir.endsWith(QLatin1Char('/'))) dir += QLatin1Char('/'); } - return dir + testName + "/testWorkDir"; + return QDir::cleanPath(dir + testName + "/testWorkDir"); } inline bool copyDllExportHeader(const QString &srcDataDir, const QString &targetDataDir) |