4
1
mirror of https://github.com/QuasarApp/CQtDeployer.git synced 2025-05-04 13:39:34 +00:00

added new tests for absalute pathes

This commit is contained in:
Andrei Yankovich 2019-10-16 18:07:36 +03:00
parent 4fc34e7827
commit 9e5bb1507a
4 changed files with 118 additions and 16 deletions

@ -130,8 +130,15 @@ void ConfigParser::readKey(const QString& key, const QJsonObject& obj,
if (!val.isEmpty()) {
if (PathUtils::isPath(val)) {
list.push_back(
QFileInfo(confFileDir + '/' + val).absoluteFilePath());
QString path;
if (PathUtils::isAbsalutPath(val)) {
path = QFileInfo(val).absoluteFilePath();
} else {
path = QFileInfo(confFileDir + '/' + val).absoluteFilePath();
}
list.push_back(path);
} else {
list.push_back(val);
@ -146,7 +153,12 @@ void ConfigParser::readKey(const QString& key, const QJsonObject& obj,
if (!val.isEmpty()) {
if (PathUtils::isPath(val)) {
val = QFileInfo(confFileDir + '/' + val).absoluteFilePath();
if (PathUtils::isAbsalutPath(val)) {
val = QFileInfo(val).absoluteFilePath();
} else {
val = QFileInfo(confFileDir + '/' + val).absoluteFilePath();
}
}
QuasarAppUtils::Params::setArg(key, val);

@ -35,6 +35,12 @@ QString PathUtils::toFullPath(QString path) {
QString PathUtils::getRelativeLink(QString from, QString to) {
auto mainDrive = getDrive(from);
if (mainDrive != getDrive(to) && !mainDrive.isNull()) {
return to;
}
bool isFile = QFileInfo(to).isFile();
from = toFullPath(from);
to = toFullPath(to);
@ -63,6 +69,25 @@ bool PathUtils::isPath(const QString &path) {
return path.contains('/') || path.contains('\\') || path == ".";
}
QChar PathUtils::getDrive(QString path) {
path = stripPath(path);
if (path.size() > 1 && path[1] == ':') {
return path[0];
}
return 0;
}
bool PathUtils::isAbsalutPath(const QString &path) {
if (getDrive(path).isNull()) {
return path.size() && (path.at(0) == "/" || path.at(0) == "\\");
}
return true;
}
QString PathUtils::getReleativePath(QString path) {
path = toFullPath(path);
@ -81,19 +106,13 @@ QString PathUtils::getReleativePath(QString path) {
}
QString PathUtils::stripPath(QString path) {
path.replace('\\', '/');
int index = -1;
do {
path.replace("//", "/");
} while ((index = path.indexOf("//")) >= 0);
path = toFullPath(path);
if (path.left(1) == '/') {
path = path.right(path.size() - 1);
path.remove(0, 1);
}
if (path.right(1) == '/') {
path = path.left(path.size() - 1);
return path.remove(path.size() - 1, 1);
}
return path;

@ -19,11 +19,56 @@ class DEPLOYSHARED_EXPORT PathUtils
{
public:
PathUtils();
/**
* @brief toFullPath remove all dublicate separators and insert separators into begin and end
* @param path
* @return return full path
*/
static QString toFullPath(QString path);
/**
* @brief getReleativePath
* @param path
* @return return releative path from "path" to root dir
*/
static QString getReleativePath(QString path);
static QString stripPath(QString path) ;
/**
* @brief stripPath remove all dublicate separators and remove separators from begin and end
* @param path
* @return return strip patth
*/
static QString stripPath(QString path);
/**
* @brief getRelativeLink return releative path
* @param from
* @param to
* @return releative path
*/
static QString getRelativeLink(QString from, QString to);
/**
* @brief isPath
* @param path
* @return return true if imput value is path
*/
static bool isPath(const QString &path);
/**
* @brief getDrive
* @param path
* @return char of drive in windows systems
*/
static QChar getDrive(QString path);
/**
* @brief isAbsalutPath
* @param path
* @return return true if path is absolute
*/
static bool isAbsalutPath(const QString &path);
};
#endif // PATHUTILS_H

@ -581,11 +581,26 @@ void deploytest::testRelativeLink() {
{"/media/etc/usr", "/media/etc", "./../"},
{"/media/etc", "/media/etc/usr", "./usr/"},
{"C:/", "C:/", "./"},
{"C:\\", "C:/", "./"},
{"C:/", "C:\\", "./"},
{"C:/media", "C:/etc", "./../etc/"},
{"C:/media//\\", "C:/etc///", "./../etc/"},
{"C:/media/etc/usr", "C:/media/etc", "./../"},
{"C:/media\\etc", "C:/media/etc/usr", "./usr/"},
{"C:/media/etc", "D:/media/etc/usr", "D:/media/etc/usr"},
};
for (auto &i: cases) {
QVERIFY(PathUtils::getRelativeLink(i[0], i[1]) == i[2]);
}
for (int i = 1; i < cases.size() - 1; i++) {
QVERIFY(PathUtils::isAbsalutPath(cases[i][0]));
QVERIFY(!PathUtils::isAbsalutPath(cases[i][2]));
}
}
void deploytest::testSetTargetDir() {
@ -845,11 +860,11 @@ void deploytest::testConfFile() {
#ifdef Q_OS_UNIX
runTestParams({"-bin", TestBinDir + "TestOnlyC," + TestBinDir + "QtWidgetsProject," + TestBinDir + "TestQMLWidgets",
"clear" ,
"clear",
"-confFile", TestBinDir + "/TestConf.json"}, &comapareTree);
#else
runTestParams({"-bin", TestBinDir + "TestOnlyC.exe," + TestBinDir + "QtWidgetsProject.exe," + TestBinDir + "TestQMLWidgets.exe",
"clear" ,
"clear" , "-libDir", "L:/never/absalut/path"
"-confFile", TestBinDir + "/TestConf.json"}, &comapareTree);
#endif
@ -870,9 +885,14 @@ void deploytest::testConfFile() {
QVERIFY(data.contains("./TestOnlyC"));
QVERIFY(data.contains("./QtWidgetsProject"));
QVERIFY(data.contains("./TestQMLWidgets"));
// QVERIFY(data.contains("\"libDir\": \"/never/absalut/path/\""));
QVERIFY(data.contains("\"clear\": true"));
QVERIFY(confFile.open(QIODevice::ReadOnly | QIODevice::Append));
confFile.write(QString("\"libDir\": \"/never/absalut/path/\"").toLatin1());
confFile.close();
runTestParams({"-confFile", TestBinDir + "/TestConf.json"}, &comapareTree);
#else
QVERIFY(!doc.isNull());
@ -881,6 +901,7 @@ void deploytest::testConfFile() {
QVERIFY(data.contains("./TestOnlyC.exe"));
QVERIFY(data.contains("./QtWidgetsProject.exe"));
QVERIFY(data.contains("./TestQMLWidgets.exe"));
QVERIFY(data.contains("\"libDir\": \"L:/never/absalut/path/\""));
QVERIFY(data.contains("\"clear\": true"));
@ -890,7 +911,12 @@ void deploytest::testConfFile() {
QVERIFY(QuasarAppUtils::Params::isEndable("clear"));
QVERIFY(QuasarAppUtils::Params::isEndable("bin"));
QVERIFY(QuasarAppUtils::Params::isEndable("libDir"));
#ifdef Q_OS_UNIX
QVERIFY(QuasarAppUtils::Params::getStrArg("libDir") == "/never/absalut/path/");
#else
QVERIFY(QuasarAppUtils::Params::getStrArg("libDir") == "L:/never/absalut/path/");
#endif
QFile::remove(TestBinDir + "/TestConf.json");