CQtDeployer/tests/units/overwritetest.cpp

72 lines
2.0 KiB
C++

//#
//# Copyright (C) 2020-2022 QuasarApp.
//# Distributed under the GPLv3 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 "overwritetest.h"
#include <configparser.h>
#include <dependenciesscanner.h>
#include <filemanager.h>
#include <packing.h>
#include <pluginsparser.h>
void OverwiriteTest::test() {
TestUtils utils;
#ifdef Q_OS_UNIX
QFile f("./" + DISTRO_DIR + "/bin/TestOnlyC");
auto comapareTree = utils.createTree(
{"./" + DISTRO_DIR + "/bin/TestOnlyC",
"./" + DISTRO_DIR + "/bin/qt.conf",
"./" + DISTRO_DIR + "/TestOnlyC.sh"});
QString bin = TestBinDir + "TestOnlyC";
#else
QFile f("./" + DISTRO_DIR + "/TestOnlyC.exe");
auto comapareTree = utils.createTree(
{"./" + DISTRO_DIR + "/TestOnlyC.exe",
"./" + DISTRO_DIR + "/TestOnlyC.bat",
"./" + DISTRO_DIR + "/qt.conf"});
QString bin = TestBinDir + "TestOnlyC.exe";
#endif
runTestParams({"-bin", bin, "force-clear", "noOverwrite"}, &comapareTree);
QVERIFY(f.open(QIODevice::ReadOnly));
auto hashBefor = QCryptographicHash::hash(f.readAll(), QCryptographicHash::Md5);
f.close();
QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Append));
f.write(QByteArray(10, '1'));
f.close();
QVERIFY(f.open(QIODevice::ReadOnly));
auto hashAfter = QCryptographicHash::hash(f.readAll(), QCryptographicHash::Md5);
f.close();
QVERIFY(hashAfter != hashBefor);
runTestParams({"-bin", bin, "noOverwrite"}, &comapareTree);
QVERIFY(f.open(QIODevice::ReadOnly));
hashAfter = QCryptographicHash::hash(f.readAll(), QCryptographicHash::Md5);
f.close();
QVERIFY(hashAfter != hashBefor);
runTestParams({"-bin", bin}, &comapareTree);
QVERIFY(f.open(QIODevice::ReadOnly));
hashAfter = QCryptographicHash::hash(f.readAll(), QCryptographicHash::Md5);
f.close();
QVERIFY(hashAfter == hashBefor);
}