aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorIvan Komissarov <abbapoh@gmail.com>2020-01-11 13:54:10 +0100
committerIvan Komissarov <ABBAPOH@gmail.com>2020-01-15 11:32:29 +0000
commitc347107e5c17703a74c44fa29200846d8cc1a50e (patch)
tree97e11dc6716aef796204752e618482aae3cc8944 /tests
parent7c31d4d375cff51b1f1318a05c7ded11c263448d (diff)
Add overrideInfoPlist test
This test checks that properties can be overridden in a .qbs file Task-number: QBS-1447 Change-Id: Ib39c7c11f26357bb4074eb9ba7cb2730f25c9441 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/blackbox/testdata-apple/overrideInfoPlist/Override-Info.plist10
-rw-r--r--tests/auto/blackbox/testdata-apple/overrideInfoPlist/main.c1
-rw-r--r--tests/auto/blackbox/testdata-apple/overrideInfoPlist/overrideInfoPlist.qbs16
-rw-r--r--tests/auto/blackbox/tst_blackboxapple.cpp110
-rw-r--r--tests/auto/blackbox/tst_blackboxapple.h1
5 files changed, 112 insertions, 26 deletions
diff --git a/tests/auto/blackbox/testdata-apple/overrideInfoPlist/Override-Info.plist b/tests/auto/blackbox/testdata-apple/overrideInfoPlist/Override-Info.plist
new file mode 100644
index 000000000..f2621e983
--- /dev/null
+++ b/tests/auto/blackbox/testdata-apple/overrideInfoPlist/Override-Info.plist
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>DefaultValue</key>
+ <string>The default value</string>
+ <key>OverriddenValue</key>
+ <string>The default value</string>
+</dict>
+</plist>
diff --git a/tests/auto/blackbox/testdata-apple/overrideInfoPlist/main.c b/tests/auto/blackbox/testdata-apple/overrideInfoPlist/main.c
new file mode 100644
index 000000000..76e819701
--- /dev/null
+++ b/tests/auto/blackbox/testdata-apple/overrideInfoPlist/main.c
@@ -0,0 +1 @@
+int main() { return 0; }
diff --git a/tests/auto/blackbox/testdata-apple/overrideInfoPlist/overrideInfoPlist.qbs b/tests/auto/blackbox/testdata-apple/overrideInfoPlist/overrideInfoPlist.qbs
new file mode 100644
index 000000000..e70584ed8
--- /dev/null
+++ b/tests/auto/blackbox/testdata-apple/overrideInfoPlist/overrideInfoPlist.qbs
@@ -0,0 +1,16 @@
+CppApplication {
+ Depends { name: "bundle" }
+ cpp.minimumMacosVersion: "10.7"
+ files: ["main.c", "Override-Info.plist"]
+
+ Properties {
+ condition: qbs.targetOS.contains("darwin")
+ bundle.isBundle: true
+ bundle.identifierPrefix: "com.test"
+
+ bundle.infoPlist: ({
+ "CFBundleName": "My Bundle",
+ "OverriddenValue": "The overridden value",
+ })
+ }
+}
diff --git a/tests/auto/blackbox/tst_blackboxapple.cpp b/tests/auto/blackbox/tst_blackboxapple.cpp
index 96cd70b58..819193b4b 100644
--- a/tests/auto/blackbox/tst_blackboxapple.cpp
+++ b/tests/auto/blackbox/tst_blackboxapple.cpp
@@ -60,6 +60,54 @@ static QString getEmbeddedBinaryPlist(const QString &file)
return QString::fromUtf8(p.readAllStandardOutput()).trimmed();
}
+static QVariantMap readInfoPlistFile(const QString &infoPlistPath)
+{
+ if (!QFile::exists(infoPlistPath)) {
+ qWarning() << infoPlistPath << "doesn't exist";
+ return {};
+ }
+
+ QProcess plutil;
+ plutil.start("plutil", {
+ QStringLiteral("-convert"),
+ QStringLiteral("json"),
+ infoPlistPath
+ });
+ if (!plutil.waitForStarted()) {
+ qWarning() << plutil.errorString();
+ return {};
+ }
+ if (!plutil.waitForFinished()) {
+ qWarning() << plutil.errorString();
+ return {};
+ }
+ if (plutil.exitCode() != 0) {
+ qWarning() << plutil.readAllStandardError().constData();
+ return {};
+ }
+
+ QFile infoPlist(infoPlistPath);
+ if (!infoPlist.open(QIODevice::ReadOnly)) {
+ qWarning() << infoPlist.errorString();
+ return {};
+ }
+ QJsonParseError error;
+ const auto json = QJsonDocument::fromJson(infoPlist.readAll(), &error);
+ if (error.error != QJsonParseError::NoError) {
+ qWarning() << error.errorString();
+ return {};
+ }
+ return json.object().toVariantMap();
+}
+
+static QString getInfoPlistPath(const QString &bundlePath)
+{
+ QFileInfo contents(bundlePath + "/Contents");
+ if (contents.exists() && contents.isDir())
+ return contents.filePath() + "/Info.plist"; // macOS bundle
+ return bundlePath + "/Info.plist";
+}
+
TestBlackboxApple::TestBlackboxApple()
: TestBlackboxBase (SRCDIR "/testdata-apple", "blackbox-apple")
{
@@ -719,37 +767,22 @@ void TestBlackboxApple::infoPlist()
params.arguments = QStringList() << "-f" << "infoplist.qbs";
QCOMPARE(runQbs(params), 0);
- auto infoplistPath = relativeProductBuildDir("infoplist")
- + "/infoplist.app/Contents/Info.plist";
- if (!QFile::exists(infoplistPath))
- infoplistPath = relativeProductBuildDir("infoplist") + "/infoplist.app/Info.plist";
- QVERIFY(QFile::exists(infoplistPath));
- QProcess plutil;
- plutil.start("plutil", {
- QStringLiteral("-convert"),
- QStringLiteral("json"),
- infoplistPath
- });
- QVERIFY2(plutil.waitForStarted(), qPrintable(plutil.errorString()));
- QVERIFY2(plutil.waitForFinished(), qPrintable(plutil.errorString()));
- QVERIFY2(plutil.exitCode() == 0, qPrintable(plutil.readAllStandardError().constData()));
+ const auto infoPlistPath = getInfoPlistPath(
+ relativeProductBuildDir("infoplist") + "/infoplist.app");
+ QVERIFY(QFile::exists(infoPlistPath));
+ const auto content = readInfoPlistFile(infoPlistPath);
+ QVERIFY(!content.isEmpty());
- QFile infoplist(infoplistPath);
- QVERIFY(infoplist.open(QIODevice::ReadOnly));
- QJsonParseError error;
- const auto json = QJsonDocument::fromJson(infoplist.readAll(), &error);
- QCOMPARE(error.error, QJsonParseError::NoError);
- QVERIFY(json.isObject());
// common values
- QCOMPARE(json.object().value(QStringLiteral("CFBundleIdentifier")),
+ QCOMPARE(content.value(QStringLiteral("CFBundleIdentifier")),
QStringLiteral("org.example.infoplist"));
- QCOMPARE(json.object().value(QStringLiteral("CFBundleName")), QStringLiteral("infoplist"));
- QCOMPARE(json.object().value(QStringLiteral("CFBundleExecutable")),
+ QCOMPARE(content.value(QStringLiteral("CFBundleName")), QStringLiteral("infoplist"));
+ QCOMPARE(content.value(QStringLiteral("CFBundleExecutable")),
QStringLiteral("infoplist"));
- if (!json.object().contains(QStringLiteral("SDKROOT"))) { // macOS-specific values
- QCOMPARE(json.object().value("LSMinimumSystemVersion"), QStringLiteral("10.7"));
- QVERIFY(json.object().contains("NSPrincipalClass"));
+ if (!content.contains(QStringLiteral("SDKROOT"))) { // macOS-specific values
+ QCOMPARE(content.value("LSMinimumSystemVersion"), QStringLiteral("10.7"));
+ QVERIFY(content.contains("NSPrincipalClass"));
}
}
@@ -760,6 +793,31 @@ void TestBlackboxApple::objcArc()
QCOMPARE(runQbs(), 0);
}
+void TestBlackboxApple::overrideInfoPlist()
+{
+ QDir::setCurrent(testDataDir + "/overrideInfoPlist");
+
+ QCOMPARE(runQbs(), 0);
+
+ const auto infoPlistPath = getInfoPlistPath(
+ relativeProductBuildDir("overrideInfoPlist") + "/overrideInfoPlist.app");
+ QVERIFY(QFile::exists(infoPlistPath));
+ const auto content = readInfoPlistFile(infoPlistPath);
+ QVERIFY(!content.isEmpty());
+
+ // test we do not override custom values by default
+ QCOMPARE(content.value(QStringLiteral("DefaultValue")),
+ QStringLiteral("The default value"));
+ // test we can override custom values
+ QCOMPARE(content.value(QStringLiteral("OverriddenValue")),
+ QStringLiteral("The overridden value"));
+ // test we do not override special values set by Qbs by default
+ QCOMPARE(content.value(QStringLiteral("CFBundleExecutable")),
+ QStringLiteral("overrideInfoPlist"));
+ // test we can override special values set by Qbs
+ QCOMPARE(content.value(QStringLiteral("CFBundleName")), QStringLiteral("My Bundle"));
+}
+
void TestBlackboxApple::xcode()
{
QProcess xcodeSelect;
diff --git a/tests/auto/blackbox/tst_blackboxapple.h b/tests/auto/blackbox/tst_blackboxapple.h
index 76711ddf5..be2e5c5b5 100644
--- a/tests/auto/blackbox/tst_blackboxapple.h
+++ b/tests/auto/blackbox/tst_blackboxapple.h
@@ -63,6 +63,7 @@ private slots:
void iconsetApp();
void infoPlist();
void objcArc();
+ void overrideInfoPlist();
void xcode();
private: