2025-01-10 21:33:48 +01:00
|
|
|
#include <QFile>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QUuid>
|
|
|
|
#include <QtCore/QStandardPaths>
|
2025-01-29 16:42:37 +01:00
|
|
|
#include <memory>
|
2025-01-10 21:33:48 +01:00
|
|
|
#include <quazip5/JlCompress.h>
|
|
|
|
|
2025-02-05 11:02:59 +01:00
|
|
|
//#include "passphraseprovider.h"
|
2025-01-10 21:33:48 +01:00
|
|
|
#include "utils.h"
|
|
|
|
|
2025-02-05 11:02:59 +01:00
|
|
|
TestsUtils::TestsUtils()
|
|
|
|
//m_passphrase_povider(std::unique_ptr<TesTPassphraseProvider>(new TesTPassphraseProvider()))
|
2025-01-29 16:42:37 +01:00
|
|
|
{}
|
|
|
|
|
2025-01-10 21:33:48 +01:00
|
|
|
|
2025-01-13 18:11:16 +01:00
|
|
|
QString TestsUtils::getTempPath()
|
|
|
|
{
|
2025-01-10 21:33:48 +01:00
|
|
|
// Get the system's temporary directory
|
2025-01-29 16:42:37 +01:00
|
|
|
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
2025-01-10 21:33:48 +01:00
|
|
|
|
|
|
|
// Generate a unique UUID
|
|
|
|
QString uuid = QUuid::createUuid().toString(QUuid::WithoutBraces);
|
|
|
|
|
|
|
|
// Create a new directory using the generated UUID
|
|
|
|
QString newTempDir = tempDir + "/" + uuid;
|
|
|
|
|
|
|
|
QDir dir;
|
2025-01-29 16:42:37 +01:00
|
|
|
dir.mkpath(newTempDir);
|
|
|
|
|
2025-01-30 16:25:29 +01:00
|
|
|
qDebug() << "[TestUtils] TempDir : " << newTempDir;
|
2025-01-29 16:42:37 +01:00
|
|
|
return newTempDir;
|
2025-01-10 21:33:48 +01:00
|
|
|
}
|
|
|
|
|
2025-01-30 16:25:29 +01:00
|
|
|
bool TestsUtils::fileExists(QUrl path)
|
|
|
|
{
|
|
|
|
QString p = path.toLocalFile();
|
|
|
|
auto ret = QFileInfo::exists(p) && QFileInfo(p).isFile();
|
|
|
|
qDebug() << "[TestUtils]" << p << "is existing file :" << ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestsUtils::copyFolder(QUrl sourceFolderUrl, QUrl destFolderUrl)
|
|
|
|
{
|
|
|
|
auto sourceFolder = sourceFolderUrl.toLocalFile();
|
|
|
|
auto destFolder = destFolderUrl.toLocalFile();
|
|
|
|
QDir sourceDir(sourceFolder);
|
|
|
|
if (!sourceDir.exists())
|
|
|
|
return;
|
|
|
|
QDir destDir(destFolder);
|
|
|
|
if (!destDir.exists()) {
|
|
|
|
destDir.mkdir(destFolder);
|
|
|
|
}
|
|
|
|
qDebug() << "[TestUtils]" << "Copy files from" << sourceFolder << "to" << destFolder;
|
|
|
|
QStringList files = sourceDir.entryList(QDir::Files);
|
|
|
|
for (int i = 0; i < files.count(); i++) {
|
|
|
|
QString srcName = sourceFolder + "/" + files[i];
|
|
|
|
QString destName = destFolder + "/" + files[i];
|
|
|
|
QFile::copy(srcName, destName);
|
|
|
|
qDebug() << "[TestUtils]" << "Copy file from" << srcName << "to" << destName;
|
|
|
|
}
|
|
|
|
files.clear();
|
|
|
|
files = sourceDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
|
|
|
for (int i = 0; i < files.count(); i++) {
|
|
|
|
QString srcName = sourceFolder + "/" + files[i];
|
|
|
|
QString destName = destFolder + "/" + files[i];
|
|
|
|
this->copyFolder(srcName, destName);
|
|
|
|
}
|
|
|
|
}
|
2025-01-10 21:33:48 +01:00
|
|
|
|
2025-02-05 11:02:59 +01:00
|
|
|
// QObject *TestsUtils::getTestPassphraseProvider()
|
|
|
|
// {
|
|
|
|
// return &TesTPassphraseProvider::instance();
|
|
|
|
// }
|
2025-01-29 16:42:37 +01:00
|
|
|
|
2025-01-10 21:33:48 +01:00
|
|
|
|