2019-01-26 15:34:39 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018-2019 QuasarApp.
|
|
|
|
* Distributed under the lgplv3 software license, see the accompanying
|
|
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
* of this license document, but changing it is not allowed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QtTest>
|
|
|
|
#include <quasarapp.h>
|
|
|
|
#include <deployutils.h>
|
|
|
|
#include <deploy.h>
|
|
|
|
#include <windependenciesscanner.h>
|
|
|
|
|
2019-01-26 22:27:36 +03:00
|
|
|
#include <QByteArray>
|
2019-01-26 15:34:39 +03:00
|
|
|
#include <QDir>
|
2019-01-26 22:27:36 +03:00
|
|
|
#include <thread>
|
2019-01-26 15:34:39 +03:00
|
|
|
// add necessary includes here
|
|
|
|
|
|
|
|
class deploytest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
deploytest();
|
2019-01-27 12:30:45 +03:00
|
|
|
/**
|
|
|
|
* @brief generateLib
|
|
|
|
* @param paath
|
|
|
|
* @return size of lib
|
|
|
|
*/
|
|
|
|
int generateLib(const QString& paath);
|
|
|
|
void deleteLib(const QString& paath);
|
|
|
|
|
2019-01-26 15:34:39 +03:00
|
|
|
~deploytest();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initTestCase();
|
|
|
|
void cleanupTestCase();
|
|
|
|
void testDeployUtils();
|
2019-01-26 22:27:36 +03:00
|
|
|
void testDeployTarget();
|
2019-01-27 15:37:19 +03:00
|
|
|
void testTranslations();
|
2019-01-26 22:27:36 +03:00
|
|
|
void testStrip();
|
2019-01-27 19:46:11 +03:00
|
|
|
void testDeploy();
|
2019-01-26 15:34:39 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
deploytest::deploytest(){}
|
|
|
|
|
2019-01-27 12:30:45 +03:00
|
|
|
int deploytest::generateLib(const QString &paath)
|
|
|
|
{
|
|
|
|
QDir dir;
|
2019-01-27 15:37:19 +03:00
|
|
|
dir.mkpath(QFileInfo(paath).absolutePath());
|
2019-01-27 12:30:45 +03:00
|
|
|
QFile testLib (paath);
|
|
|
|
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
if (testLib.open(QIODevice::ReadWrite| QIODevice::Truncate)) {
|
|
|
|
QFile resData(":/debugLib");
|
|
|
|
if (resData.open(QIODevice::ReadOnly)) {
|
|
|
|
QByteArray tempData = resData.readAll();
|
|
|
|
size = tempData.size();
|
|
|
|
testLib.write(tempData.data(), tempData.size());
|
|
|
|
resData.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
testLib.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void deploytest::deleteLib(const QString &paath)
|
|
|
|
{
|
|
|
|
QFileInfo info(paath);
|
|
|
|
if (info.isDir()) {
|
|
|
|
QFile::remove(info.absoluteFilePath());
|
|
|
|
} else {
|
|
|
|
QDir qt(info.absoluteFilePath());
|
|
|
|
qt.removeRecursively();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 15:34:39 +03:00
|
|
|
deploytest::~deploytest(){}
|
|
|
|
|
|
|
|
void deploytest::initTestCase() {
|
|
|
|
QDir qt;
|
|
|
|
qt.mkpath("./test/Qt/5.12/");
|
|
|
|
qt.mkpath("./test/extraPath/");
|
|
|
|
qt.mkpath("./test/extra/");
|
|
|
|
qt.mkpath("./test/warning/");
|
2019-01-26 17:39:19 +03:00
|
|
|
qt.mkpath("./test/bins/");
|
2019-01-26 15:34:39 +03:00
|
|
|
|
|
|
|
QFile f( "./test/Qt/5.12/generalLib.so");
|
|
|
|
if (f.open(QIODevice::WriteOnly| QIODevice::Truncate)) {
|
|
|
|
f.write("lib", 3);
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
f.setFileName("./test/extraPath/ExtraLib.so");
|
|
|
|
if (f.open(QIODevice::WriteOnly| QIODevice::Truncate)) {
|
|
|
|
f.write("lib", 3);
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
f.setFileName("./test/extra/ExtraLib.so");
|
|
|
|
if (f.open(QIODevice::WriteOnly| QIODevice::Truncate)) {
|
|
|
|
f.write("lib", 3);
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
f.setFileName("./test/warning/WarningLib.so");
|
|
|
|
if (f.open(QIODevice::WriteOnly| QIODevice::Truncate)) {
|
|
|
|
f.write("lib", 3);
|
|
|
|
f.close();
|
|
|
|
}
|
2019-01-26 17:39:19 +03:00
|
|
|
|
|
|
|
f.setFileName("./test/bins/execTarget.exe");
|
|
|
|
if (f.open(QIODevice::WriteOnly| QIODevice::Truncate)) {
|
|
|
|
f.write("exec", 3);
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
f.setFileName("./test/bins/execTarget");
|
|
|
|
if (f.open(QIODevice::WriteOnly| QIODevice::Truncate)) {
|
|
|
|
f.write("exec", 3);
|
|
|
|
f.close();
|
|
|
|
}
|
2019-01-26 15:34:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void deploytest::cleanupTestCase() {
|
|
|
|
QDir qt("./test");
|
|
|
|
qt.removeRecursively();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void deploytest::testDeployUtils() {
|
|
|
|
QString qtDir = "./test/Qt/5.12/";
|
|
|
|
QStringList extraPathes = QStringList() << QFileInfo("./test/extraPath/").absoluteFilePath();
|
|
|
|
|
|
|
|
DeployUtils::qtDir = QFileInfo(qtDir).absoluteFilePath();
|
|
|
|
DeployUtils::extraPaths = extraPathes;
|
|
|
|
|
|
|
|
// qt Dir
|
|
|
|
QVERIFY(DeployUtils::isQtLib("./test/Qt/5.12/myLib.so"));
|
|
|
|
QVERIFY(!DeployUtils::isQtLib("/myQtDur/Qt/5.11/myLib.so"));
|
|
|
|
QVERIFY(!DeployUtils::isQtLib("/mQtDur/Qt/5.12/myLib.so"));
|
|
|
|
QVERIFY(DeployUtils::isQtLib("./test/Qt/5.12/myLib/testlibs/mylib.so"));
|
|
|
|
|
|
|
|
// extra Dir
|
|
|
|
QVERIFY(!DeployUtils::isExtraLib("./test/Qt/5.12/myLib.so"));
|
|
|
|
QVERIFY(!DeployUtils::isExtraLib("/myQtDur/Qt/5.11/myLib.so"));
|
|
|
|
QVERIFY(!DeployUtils::isExtraLib("/mQtDur/Qt/5.12/myLib.so"));
|
|
|
|
QVERIFY(!DeployUtils::isExtraLib("./test/Qt/5.12/myLib/testlibs/mylib.so"));
|
|
|
|
|
|
|
|
QVERIFY(DeployUtils::isExtraLib("./test/extraPath/Qt/5.12/myLib.so"));
|
|
|
|
QVERIFY(DeployUtils::isExtraLib("./test/extraPath/Qt/5/myLib.so"));
|
|
|
|
QVERIFY(DeployUtils::isExtraLib("./test/extraPath/myLib.so"));
|
|
|
|
QVERIFY(DeployUtils::isExtraLib("./test/extraPath/Qt/5.12/myLib/testlibs/mylib.so"));
|
|
|
|
|
|
|
|
//getLibPriority
|
|
|
|
|
|
|
|
QVERIFY(DeployUtils::getLibPriority("./tst/Qt/5.12/generalLib.so") == 0);
|
|
|
|
QVERIFY(DeployUtils::getLibPriority("./test/Qt/5.12/generalLib.so") == 3);
|
|
|
|
QVERIFY(DeployUtils::getLibPriority("./test/extraPath/ExtraLib.so") == 2);
|
|
|
|
QVERIFY(DeployUtils::getLibPriority("./test/extra/ExtraLib.so") == 1);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-26 22:27:36 +03:00
|
|
|
void deploytest::testDeployTarget() {
|
2019-01-26 15:34:39 +03:00
|
|
|
|
2019-01-26 17:39:19 +03:00
|
|
|
Deploy *deploy = new Deploy();
|
|
|
|
QStringList targets;
|
|
|
|
targets << "./test/bins/execTarget.exe";
|
|
|
|
QVERIFY(deploy->setTargets(targets));
|
|
|
|
delete deploy;
|
|
|
|
targets.clear();
|
|
|
|
|
|
|
|
deploy = new Deploy();
|
|
|
|
targets << "./test/bins/execTarget";
|
|
|
|
QVERIFY(deploy->setTargets(targets));
|
|
|
|
delete deploy;
|
|
|
|
targets.clear();
|
|
|
|
|
|
|
|
deploy = new Deploy();
|
|
|
|
targets << "./test/bins/execTarget.exe" << "./test/bins/execTarget";
|
|
|
|
QVERIFY(deploy->setTargets(targets));
|
|
|
|
delete deploy;
|
|
|
|
targets.clear();
|
|
|
|
|
|
|
|
deploy = new Deploy();
|
|
|
|
targets << "./test/bns/execTarget.exe";
|
|
|
|
QVERIFY(!deploy->setTargets(targets));
|
|
|
|
delete deploy;
|
|
|
|
targets.clear();
|
|
|
|
|
|
|
|
deploy = new Deploy();
|
|
|
|
targets << "./test/bins/";
|
|
|
|
QVERIFY(deploy->setTargets(targets));
|
|
|
|
delete deploy;
|
|
|
|
targets.clear();
|
|
|
|
|
|
|
|
deploy = new Deploy();
|
|
|
|
targets << "./test/bins/" << "./test/warning/";
|
|
|
|
QVERIFY(deploy->setTargets(targets));
|
|
|
|
|
|
|
|
delete deploy;
|
|
|
|
targets.clear();
|
2019-01-26 22:27:36 +03:00
|
|
|
}
|
2019-01-26 17:39:19 +03:00
|
|
|
|
2019-01-26 22:27:36 +03:00
|
|
|
void deploytest::testStrip() {
|
2019-01-26 17:39:19 +03:00
|
|
|
|
2019-01-27 19:46:11 +03:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
Deploy *deploy = new Deploy();
|
|
|
|
QVERIFY(deploy->strip("./test/binTargetDir/debugLib.so"));
|
|
|
|
delete deploy;
|
|
|
|
#else
|
2019-01-27 12:30:45 +03:00
|
|
|
//for one lib
|
|
|
|
qint64 sizeBefor = generateLib("./test/binTargetDir/debugLib.so");
|
2019-01-26 22:27:36 +03:00
|
|
|
qint64 sizeAfter = 0;
|
|
|
|
|
|
|
|
Deploy *deploy = new Deploy();
|
2019-01-27 12:30:45 +03:00
|
|
|
QVERIFY(deploy->strip("./test/binTargetDir/debugLib.so"));
|
2019-01-26 22:27:36 +03:00
|
|
|
|
2019-01-27 12:30:45 +03:00
|
|
|
QFile testLib ("./test/binTargetDir/debugLib.so");
|
2019-01-26 22:27:36 +03:00
|
|
|
if (testLib.open(QIODevice::ReadOnly)) {
|
|
|
|
sizeAfter = testLib.size();
|
|
|
|
testLib.close();
|
|
|
|
}
|
2019-01-26 15:34:39 +03:00
|
|
|
|
2019-01-27 12:30:45 +03:00
|
|
|
deleteLib("./test/binTargetDir");
|
|
|
|
delete deploy;
|
2019-01-26 15:34:39 +03:00
|
|
|
|
2019-01-26 22:27:36 +03:00
|
|
|
QVERIFY(sizeBefor > sizeAfter);
|
2019-01-27 12:30:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
//for folder
|
|
|
|
QStringList libList = {
|
|
|
|
("./test/binTargetDir/debugLib1.so"),
|
|
|
|
("./test/binTargetDir/debugLib2.so.1.2"),
|
|
|
|
("./test/binTargetDir/debugLib3.so.1"),
|
|
|
|
("./test/binTargetDir/debugLib4.so.1.0.0"),
|
|
|
|
("./test/binTargetDir/debugLib.dll"),
|
|
|
|
("./test/binTargetDir/debugLib1.dll")
|
|
|
|
};
|
|
|
|
QList<qint64> sizeBeforList = {};
|
|
|
|
|
|
|
|
for (auto i: libList) {
|
|
|
|
sizeBeforList.push_back(generateLib(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<qint64> sizeAfterList;
|
|
|
|
|
|
|
|
deploy = new Deploy();
|
|
|
|
QVERIFY(deploy->strip("./test/binTargetDir"));
|
|
|
|
|
|
|
|
for(auto i: libList) {
|
|
|
|
QFile testLib (i);
|
|
|
|
if (testLib.open(QIODevice::ReadOnly)) {
|
|
|
|
sizeAfterList.push_back(testLib.size());
|
|
|
|
testLib.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteLib("./test/binTargetDir");
|
|
|
|
|
|
|
|
QVERIFY(sizeBeforList.size() == sizeAfterList.size());
|
|
|
|
|
|
|
|
for (int i = 0; i < sizeAfterList.size(); ++i) {
|
|
|
|
QVERIFY2(sizeBeforList[i] > sizeAfterList[i],
|
|
|
|
QString("index %0, lib: %1 size befor:%2, sizeAfter:%3").
|
|
|
|
arg(i).arg(libList[i]).arg(sizeBeforList[i]).arg(sizeAfterList[i]).
|
|
|
|
toLatin1());
|
|
|
|
}
|
2019-01-27 19:46:11 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void deploytest::testDeploy()
|
|
|
|
{
|
|
|
|
QuasarAppUtils::Params::parseParams(0, nullptr);
|
|
|
|
|
|
|
|
Deploy *deploy = new Deploy();
|
|
|
|
QVERIFY(!deploy->appDir.isEmpty());
|
|
|
|
delete deploy;
|
2019-01-26 15:34:39 +03:00
|
|
|
}
|
|
|
|
|
2019-01-27 15:37:19 +03:00
|
|
|
void deploytest::testTranslations() {
|
|
|
|
QStringList trList = {
|
|
|
|
("./test/QtDir/translations/qtbase_ru.qm"),
|
|
|
|
("./test/QtDir/translations/qtbase_en.qm"),
|
|
|
|
("./test/QtDir/translations/qtmultimedia_en.qm"),
|
|
|
|
("./test/QtDir/translations/qtmultimedia_ru.qm"),
|
|
|
|
("./test/QtDir/translations/qtdeclarative_en.qm"),
|
|
|
|
("./test/QtDir/translations/qtdeclarative_ru.qm"),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
QStringList res = {
|
|
|
|
("qtbase_ru.qm"),
|
|
|
|
("qtbase_en.qm"),
|
|
|
|
("qtmultimedia_en.qm"),
|
|
|
|
("qtmultimedia_ru.qm"),
|
|
|
|
};
|
|
|
|
|
|
|
|
QStringList libList = {
|
|
|
|
(QFileInfo("./test/target/Qt5Core.so").absoluteFilePath()),
|
|
|
|
(QFileInfo("./test/target/Qt5Nfc.so").absoluteFilePath()),
|
|
|
|
(QFileInfo("./test/target/Qt5MultimediaWidgets.dll").absoluteFilePath()),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
DeployUtils::qtDir = QFileInfo("./test/QtDir/").absoluteFilePath();
|
|
|
|
|
|
|
|
|
|
|
|
Deploy *deploy = new Deploy();
|
|
|
|
|
|
|
|
for (auto &&i: trList) {
|
|
|
|
generateLib(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &&i: libList) {
|
|
|
|
generateLib(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
deploy->translationDir = QFileInfo("./test/QtDir/translations/").absoluteFilePath();
|
|
|
|
deploy->targetDir = QFileInfo("./test/deploy/").absoluteFilePath();
|
|
|
|
|
|
|
|
auto trans = DeployUtils::extractTranslation(libList);
|
|
|
|
QVERIFY(trans.size() == 2);
|
|
|
|
QVERIFY(deploy->copyTranslations(trans));
|
|
|
|
|
|
|
|
QDir d("./test/deploy/translations") ;
|
|
|
|
QVERIFY(d.exists());
|
|
|
|
|
|
|
|
auto realList = d.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
|
|
|
|
QVERIFY(realList.size() == 4);
|
|
|
|
|
|
|
|
for(auto i: realList) {
|
|
|
|
|
|
|
|
QVERIFY(res.contains(i.fileName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteLib("./test/deploy");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-26 15:34:39 +03:00
|
|
|
QTEST_APPLESS_MAIN(deploytest)
|
|
|
|
|
|
|
|
#include "tst_deploytest.moc"
|