diff --git a/UnitTests/UnitTests.pro b/UnitTests/UnitTests.pro index a66615a..e240d2b 100644 --- a/UnitTests/UnitTests.pro +++ b/UnitTests/UnitTests.pro @@ -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 diff --git a/UnitTests/testutils.cpp b/UnitTests/testutils.cpp new file mode 100644 index 0000000..eceea24 --- /dev/null +++ b/UnitTests/testutils.cpp @@ -0,0 +1,51 @@ +#include "testutils.h" + +#include +#include + +TestUtils::TestUtils() +{ + +} + +QSet TestUtils::getTree(const QString &path) { + QFileInfo info(path); + + if (!info.exists()) { + return {}; + } + + auto result = QSet{}; + + 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 TestUtils::compareTree(const QSet &leftTree, const QSet &rightTree) { + QHash 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; +} + + diff --git a/UnitTests/testutils.h b/UnitTests/testutils.h new file mode 100644 index 0000000..cd6dade --- /dev/null +++ b/UnitTests/testutils.h @@ -0,0 +1,21 @@ +#ifndef TESTUTILS_H +#define TESTUTILS_H + +#include + +class TestUtils +{ +public: + TestUtils(); + QSet 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 compareTree(const QSet& leftTree, const QSet& rightTree); + +}; + +#endif // TESTUTILS_H