mirror of
https://github.com/QuasarApp/CQtDeployer.git
synced 2025-04-29 11:14:33 +00:00
refactor tests begin
This commit is contained in:
parent
a6c4ddadf9
commit
70896f70d3
@ -30,11 +30,13 @@ TEMPLATE = app
|
||||
|
||||
SOURCES += tst_deploytest.cpp \
|
||||
libcreator.cpp \
|
||||
qmlcreator.cpp
|
||||
qmlcreator.cpp \
|
||||
testutils.cpp
|
||||
|
||||
RESOURCES += \
|
||||
res.qrc
|
||||
|
||||
HEADERS += \
|
||||
libcreator.h \
|
||||
qmlcreator.h
|
||||
qmlcreator.h \
|
||||
testutils.h
|
||||
|
51
UnitTests/testutils.cpp
Normal file
51
UnitTests/testutils.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "testutils.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
TestUtils::TestUtils()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QSet<QString> TestUtils::getTree(const QString &path) {
|
||||
QFileInfo info(path);
|
||||
|
||||
if (!info.exists()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto result = QSet<QString>{};
|
||||
|
||||
if (!info.isDir()) {
|
||||
result.insert(info.absoluteFilePath());
|
||||
return result;
|
||||
}
|
||||
|
||||
QDir dir(info.absoluteFilePath());
|
||||
auto list = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
|
||||
for (auto &i: list) {
|
||||
result.unite(getTree(i.absoluteFilePath()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
21
UnitTests/testutils.h
Normal file
21
UnitTests/testutils.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef TESTUTILS_H
|
||||
#define TESTUTILS_H
|
||||
|
||||
#include <QSet>
|
||||
|
||||
class TestUtils
|
||||
{
|
||||
public:
|
||||
TestUtils();
|
||||
QSet<QString> getTree( const QString& path);
|
||||
/**
|
||||
* @brief compareTree - compare 2 tree
|
||||
* @param leftTree
|
||||
* @param rightTree
|
||||
* @return hash with pathes and indexes( 1 - missing left and -1 - missing right)
|
||||
*/
|
||||
QHash<QString, int> compareTree(const QSet<QString>& leftTree, const QSet<QString>& rightTree);
|
||||
|
||||
};
|
||||
|
||||
#endif // TESTUTILS_H
|
Loading…
x
Reference in New Issue
Block a user