diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2016-09-08 11:48:17 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2016-09-30 09:14:02 +0000 |
commit | 8e58146a14e158252b503be08003a9b1fc2d9640 (patch) | |
tree | 93bd1752e37a4423b1f6a36e5be12d9d249636e6 /tests/auto/blackbox | |
parent | 96b501d80e539a832ef9f2bef4f34162eb8ad3e2 (diff) |
Cpp Module: Add soVersion property
People must be able to set the version part of their shared library's
soname. So far, we hardcode it to the major part of the product version,
but that's not always right.
[ChangeLog] Introduced cpp.soVersion.
Change-Id: Ie06d5b88d0b3ee62f5924d58407e2a88e9e6f90d
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'tests/auto/blackbox')
-rw-r--r-- | tests/auto/blackbox/testdata/soversion/lib.cpp | 1 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/soversion/soversion.qbs | 9 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.cpp | 59 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.h | 2 |
4 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/blackbox/testdata/soversion/lib.cpp b/tests/auto/blackbox/testdata/soversion/lib.cpp new file mode 100644 index 000000000..8101b05dc --- /dev/null +++ b/tests/auto/blackbox/testdata/soversion/lib.cpp @@ -0,0 +1 @@ +void f() { } diff --git a/tests/auto/blackbox/testdata/soversion/soversion.qbs b/tests/auto/blackbox/testdata/soversion/soversion.qbs new file mode 100644 index 000000000..d024c25b9 --- /dev/null +++ b/tests/auto/blackbox/testdata/soversion/soversion.qbs @@ -0,0 +1,9 @@ +import qbs + +DynamicLibrary { + name: "mylib" + property bool useVersion + version: useVersion ? "1.2.3" : undefined + Depends { name: "cpp" } + files: ["lib.cpp"] +} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 088588193..b1ad35771 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -1618,6 +1618,65 @@ void TestBlackbox::ruleWithNoInputs() QVERIFY2(m_qbsStdout.contains("creating output"), m_qbsStdout.constData()); } + +static QString soName(const QString &readElfPath, const QString &libFilePath) +{ + QProcess readElf; + readElf.start(readElfPath, QStringList() << "-a" << libFilePath); + if (!readElf.waitForStarted() || !readElf.waitForFinished() || readElf.exitCode() != 0) { + qDebug() << readElf.errorString() << readElf.readAllStandardError(); + return QString(); + } + const QByteArray output = readElf.readAllStandardOutput(); + const QByteArray magicString = "Library soname: ["; + const int magicStringIndex = output.indexOf(magicString); + if (magicStringIndex == -1) + return QString(); + const int endIndex = output.indexOf(']', magicStringIndex); + if (endIndex == -1) + return QString(); + const int nameIndex = magicStringIndex + magicString.count(); + const QByteArray theName = output.mid(nameIndex, endIndex - nameIndex); + return QString::fromLatin1(theName); +} + +void TestBlackbox::soVersion() +{ + const QString readElfPath = findExecutable(QStringList("readelf")); + if (readElfPath.isEmpty()) + QSKIP("No readelf found"); + QDir::setCurrent(testDataDir + "/soversion"); + + QFETCH(QString, soVersion); + QFETCH(bool, useVersion); + QFETCH(QString, expectedSoName); + + QbsRunParameters params; + params.arguments << ("mylib.useVersion:" + QString((useVersion ? "true" : "false"))); + if (!soVersion.isNull()) + params.arguments << ("cpp.soVersion:" + soVersion); + const QString libFilePath = relativeProductBuildDir("mylib") + "/libmylib.so" + + (useVersion ? ".1.2.3" : QString()); + QCOMPARE(runQbs(params), 0); + QVERIFY2(regularFileExists(libFilePath), qPrintable(libFilePath)); + QCOMPARE(soName(readElfPath, libFilePath), expectedSoName); +} + +void TestBlackbox::soVersion_data() +{ + QTest::addColumn<QString>("soVersion"); + QTest::addColumn<bool>("useVersion"); + QTest::addColumn<QString>("expectedSoName"); + + QTest::newRow("default") << QString() << true << QString("libmylib.so.1"); + QTest::newRow("explicit soVersion") << QString("1.2") << true << QString("libmylib.so.1.2"); + QTest::newRow("empty soVersion") << QString("") << true << QString("libmylib.so.1.2.3"); + QTest::newRow("no version, explicit soVersion") << QString("5") << false + << QString("libmylib.so.5"); + QTest::newRow("no version, default soVersion") << QString() << false << QString("libmylib.so"); + QTest::newRow("no version, empty soVersion") << QString("") << false << QString("libmylib.so"); +} + void TestBlackbox::overrideProjectProperties() { QDir::setCurrent(testDataDir + "/overrideProjectProperties"); diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index 7a0852f63..cde842552 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -155,6 +155,8 @@ private slots: void ruleConditions(); void ruleCycle(); void ruleWithNoInputs(); + void soVersion(); + void soVersion_data(); void subProfileChangeTracking(); void successiveChanges(); void symlinkRemoval(); |