refactor tests begin

This commit is contained in:
Andrei Yankovich 2019-09-08 14:18:58 +03:00
parent a6c4ddadf9
commit 70896f70d3
3 changed files with 76 additions and 2 deletions

View File

@ -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
View 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
View 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