2019-09-23 18:37:17 +03:00
|
|
|
/*
|
2019-12-08 13:57:20 +03:00
|
|
|
* Copyright (C) 2018-2020 QuasarApp.
|
2019-09-23 18:37:17 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2019-09-08 14:18:58 +03:00
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
|
|
TestUtils::TestUtils()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-23 14:26:45 +03:00
|
|
|
QSet<QString> TestUtils::getTree(const QString &path, int limit, int depch) {
|
2019-09-08 14:18:58 +03:00
|
|
|
QFileInfo info(path);
|
|
|
|
|
2019-09-23 14:26:45 +03:00
|
|
|
if (limit > 0 && depch >= limit) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-09-08 14:18:58 +03:00
|
|
|
if (!info.exists()) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto result = QSet<QString>{};
|
|
|
|
|
|
|
|
if (!info.isDir()) {
|
2019-09-13 18:21:53 +03:00
|
|
|
result.insert(getFilePath(info.absoluteFilePath()));
|
2019-09-08 14:18:58 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDir dir(info.absoluteFilePath());
|
|
|
|
auto list = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
|
2020-01-12 16:43:03 +03:00
|
|
|
for (const auto &i: list) {
|
2019-09-23 14:26:45 +03:00
|
|
|
result.unite(getTree(i.absoluteFilePath(), limit, depch + 1));
|
2019-09-08 14:18:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-09-13 18:21:53 +03:00
|
|
|
QString TestUtils::getFilePath(const QString& i) {
|
|
|
|
auto file = QFileInfo(i).absoluteFilePath();
|
|
|
|
auto delimiter = file.lastIndexOf("/");
|
|
|
|
auto shared = file.indexOf(".so.", Qt::CaseInsensitive);
|
|
|
|
|
|
|
|
if (shared > delimiter) {
|
|
|
|
file = file.left(shared);
|
|
|
|
file.push_back(".so");
|
|
|
|
}
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2019-09-11 13:09:09 +03:00
|
|
|
QSet<QString> TestUtils::createTree(const QStringList &tree) {
|
|
|
|
QSet<QString> res;
|
2020-01-12 16:43:03 +03:00
|
|
|
for (const auto &i : tree) {
|
2019-09-13 18:21:53 +03:00
|
|
|
res.insert(getFilePath(i));
|
2019-09-11 13:09:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-09-08 14:18:58 +03:00
|
|
|
QHash<QString, int> TestUtils::compareTree(const QSet<QString> &leftTree, const QSet<QString> &rightTree) {
|
|
|
|
QHash<QString, int> result;
|
|
|
|
|
|
|
|
auto valuel = leftTree - rightTree;
|
|
|
|
auto valuer = rightTree - leftTree;
|
|
|
|
|
|
|
|
for(auto &i :valuel) {
|
|
|
|
result.insert(i, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(auto &i :valuer) {
|
|
|
|
result.insert(i, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|