65 lines
2.0 KiB
C++
65 lines
2.0 KiB
C++
#include "testenv.h"
|
|||
|
|
|
||
|
|
#include "localization.h"
|
||
|
|
#include "zlibreference.h"
|
||
|
|
|
||
|
|
#include <QDir>
|
||
|
|
#include <QFileInfo>
|
||
|
|
#include <QProcessEnvironment>
|
||
|
|
|
||
|
|
class TestZlibReference : public QObject
|
||
|
|
{
|
||
|
|
Q_OBJECT
|
||
|
|
|
||
|
|
private slots:
|
||
|
|
void nonLinuxIsNoop()
|
||
|
|
{
|
||
|
|
#if defined(Q_OS_LINUX)
|
||
|
|
QSKIP("только для Windows и macOS");
|
||
|
|
#else
|
||
|
|
QVERIFY(!ZlibReference::systemIsZlibNg());
|
||
|
|
QVERIFY(ZlibReference::bundledPath().isEmpty());
|
||
|
|
QProcessEnvironment env;
|
||
|
|
env.insert(QStringLiteral("LD_PRELOAD"), QStringLiteral("/x.so"));
|
||
|
|
QString note = QStringLiteral("stale");
|
||
|
|
QVERIFY(ZlibReference::applyTo(env, ¬e));
|
||
|
|
QVERIFY(note.isEmpty());
|
||
|
|
QCOMPARE(env.value(QStringLiteral("LD_PRELOAD")), QStringLiteral("/x.so"));
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
void linuxPreloadFollowsSystemZlib()
|
||
|
|
{
|
||
|
|
#if !defined(Q_OS_LINUX)
|
||
|
|
QSKIP("только для Linux");
|
||
|
|
#else
|
||
|
|
QProcessEnvironment env;
|
||
|
|
env.insert(QStringLiteral("LD_PRELOAD"), QStringLiteral("/other.so"));
|
||
|
|
QString note;
|
||
|
|
const bool ok = ZlibReference::applyTo(env, ¬e);
|
||
|
|
|
||
|
|
if (!ZlibReference::systemIsZlibNg()) {
|
||
|
|
// Обычный zlib: окружение не трогаем.
|
||
|
|
QVERIFY(ok);
|
||
|
|
QVERIFY(note.isEmpty());
|
||
|
|
QCOMPARE(env.value(QStringLiteral("LD_PRELOAD")), QStringLiteral("/other.so"));
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const QString bundled = ZlibReference::bundledPath();
|
||
|
|
if (bundled.isEmpty()) {
|
||
|
|
QVERIFY(!ok);
|
||
|
|
QCOMPARE(note, Loc::text("zlib.warning.referenceMissing"));
|
||
|
|
QCOMPARE(env.value(QStringLiteral("LD_PRELOAD")), QStringLiteral("/other.so"));
|
||
|
|
} else {
|
||
|
|
QVERIFY(ok);
|
||
|
|
// Наш zlib первым, чужой LD_PRELOAD сохраняется.
|
||
|
|
QCOMPARE(env.value(QStringLiteral("LD_PRELOAD")), bundled + QStringLiteral(":/other.so"));
|
||
|
|
QVERIFY(QFileInfo(bundled).isFile());
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
BILAUNCHER_TEST_MAIN(TestZlibReference)
|
||
|
|
#include "tst_zlibreference.moc"
|