added tests for out dirs

This commit is contained in:
Andrei Yankovich 2019-08-26 08:46:53 +03:00
parent 9bedeece9e
commit 0f7e015c95
3 changed files with 42 additions and 5 deletions

View File

@ -58,10 +58,24 @@ void DistroStruct::setPluginsOutDir(const QString &value) {
}
QString DistroStruct::getRelativePath(QString path) const {
if (!path.size() || !(path[0] == "/" || path[0] == "\\"))
return "";
int count = path.count(QRegExp("[\\/]")) - 1;
path.replace('\\', '/');
int index = -1;
do {
path.replace("//", "/");
} while ((index = path.indexOf("//")) >= 0);
if (path.left(1) != '/') {
path.insert(0, '/');
}
if (path.right(1) != '/') {
path.insert(path.size(), '/');
}
int count = path.count('/') - 1;
for (int i = 0; i < count; ++i) {
path += "../";
}

View File

@ -41,6 +41,8 @@ public:
void setResOutDeir(const QString &value);
QString getPluginsOutDir(const QString& basePath = "/") const;
void setPluginsOutDir(const QString &value);
friend class deploytest;
};
#endif // DISTROSTRUCT_H

View File

@ -618,12 +618,33 @@ void deploytest::testDistroStruct() {
DistroStruct distro;
auto cases = QList<QPair<QString,QString>>{
{"", ""},
{"", "/"},
{"/", "/"},
{"/res","/res/../"},
{"/res/","/res/../"},
{"\\","\\"},
{"/res/type","/res/type/../../"},
{"/res/type/","/res/type/../../"},
{"res/type","/res/type/../../"},
{"res/type/","/res/type/../../"},
{"res//type/","/res/type/../../"},
{"res////type/","/res/type/../../"},
{"//res///type/////","/res/type/../../"},
{"\\", "/"},
{"\\res","/res/../"},
{"\\res\\","/res/../"},
{"\\res\\type","/res/type/../../"},
{"\\res\\type\\","/res/type/../../"},
{"res\\type","/res/type/../../"},
{"res\\type\\","/res/type/../../"},
{"res\\\\type\\","/res/type/../../"},
{"res\\\\\\\\type\\","/res/type/../../"},
{"\\\\res\\\\\\type\\\\\\\\\\","/res/type/../../"},
};
for (auto &i: cases) {
QVERIFY(distro.getRelativePath(i.first) == i.second);
}
}
void deploytest::mainTests() {