2013-01-24 14:25:26 +01:00
|
|
|
/* ============================================================
|
2018-01-24 17:15:26 +01:00
|
|
|
* Falkon - Qt web browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
2013-01-24 14:25:26 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "qztoolstest.h"
|
|
|
|
#include "qztools.h"
|
|
|
|
|
2015-10-09 12:26:13 +02:00
|
|
|
#include <QDir>
|
2013-01-24 14:25:26 +01:00
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
2015-10-09 12:26:13 +02:00
|
|
|
void QzToolsTest::initTestCase()
|
|
|
|
{
|
2018-01-24 17:15:26 +01:00
|
|
|
m_tmpPath = QDir::tempPath() + QL1S("/falkon-test/qztoolstest");
|
2015-10-09 12:26:13 +02:00
|
|
|
QDir().mkpath(m_tmpPath);
|
|
|
|
|
|
|
|
QVERIFY(QDir(m_tmpPath).exists());
|
|
|
|
}
|
|
|
|
|
|
|
|
void QzToolsTest::cleanupTestCase()
|
|
|
|
{
|
|
|
|
QDir().rmpath(m_tmpPath);
|
|
|
|
|
|
|
|
QVERIFY(!QDir(m_tmpPath).exists());
|
|
|
|
}
|
|
|
|
|
2013-01-24 14:25:26 +01:00
|
|
|
void QzToolsTest::samePartOfStrings_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("string1");
|
|
|
|
QTest::addColumn<QString>("string2");
|
|
|
|
QTest::addColumn<QString>("result");
|
|
|
|
|
|
|
|
// Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
|
|
QTest::newRow("General") << "Lorem ipsum dolor" << "Lorem ipsum dolor Test_1" << "Lorem ipsum dolor";
|
|
|
|
QTest::newRow("OneChar") << "L" << "LTest_1" << "L";
|
|
|
|
QTest::newRow("EmptyReturn") << "Lorem ipsum dolor" << "orem ipsum dolor Test_1" << "";
|
|
|
|
QTest::newRow("EmptyString1") << "" << "orem ipsum dolor Test_1" << "";
|
|
|
|
QTest::newRow("EmptyString2") << "Lorem ipsum dolor" << "" << "";
|
|
|
|
QTest::newRow("EmptyBoth") << "" << "" << "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void QzToolsTest::samePartOfStrings()
|
|
|
|
{
|
|
|
|
QFETCH(QString, string1);
|
|
|
|
QFETCH(QString, string2);
|
|
|
|
QFETCH(QString, result);
|
|
|
|
|
|
|
|
QCOMPARE(QzTools::samePartOfStrings(string1, string2), result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QzToolsTest::getFileNameFromUrl_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QUrl>("url");
|
|
|
|
QTest::addColumn<QString>("result");
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
QTest::newRow("Basic") << QUrl(QSL("http://www.google.com/filename.html")) << QSL("filename.html");
|
|
|
|
QTest::newRow("OnlyHost") << QUrl(QSL("http://www.google.com/")) << QSL("www.google.com");
|
|
|
|
QTest::newRow("OnlyHostWithoutSlash") << QUrl(QSL("http://www.google.com")) << QSL("www.google.com");
|
|
|
|
QTest::newRow("EndingDirectory") << QUrl(QSL("http://www.google.com/filename/")) << QSL("filename");
|
|
|
|
QTest::newRow("EmptyUrl") << QUrl(QSL("")) << QSL("");
|
|
|
|
QTest::newRow("OnlyScheme") << QUrl(QSL("http:")) << QSL("");
|
|
|
|
QTest::newRow("FileSchemeUrl") << QUrl(QSL("file:///usr/share/test/file.tx")) << QSL("file.tx");
|
|
|
|
QTest::newRow("FileSchemeUrlDirectory") << QUrl(QSL("file:///usr/share/test/")) << QSL("test");
|
|
|
|
QTest::newRow("FileSchemeUrlRoot") << QUrl(QSL("file:///")) << QSL("");
|
2013-01-24 14:25:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QzToolsTest::getFileNameFromUrl()
|
|
|
|
{
|
|
|
|
QFETCH(QUrl, url);
|
|
|
|
QFETCH(QString, result);
|
|
|
|
|
|
|
|
QCOMPARE(QzTools::getFileNameFromUrl(url), result);
|
|
|
|
}
|
2013-02-15 10:47:34 +01:00
|
|
|
|
|
|
|
void QzToolsTest::splitCommandArguments_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("command");
|
|
|
|
QTest::addColumn<QStringList>("result");
|
|
|
|
|
|
|
|
QTest::newRow("Basic") << "/usr/bin/foo -o foo.out"
|
2023-11-20 23:35:11 +01:00
|
|
|
<< (QStringList() << QSL("/usr/bin/foo") << QSL("-o") << QSL("foo.out"));
|
2013-02-15 10:47:34 +01:00
|
|
|
QTest::newRow("Empty") << QString()
|
|
|
|
<< QStringList();
|
2023-11-20 23:35:11 +01:00
|
|
|
QTest::newRow("OnlySpaces") << QSL(" ")
|
2013-02-15 10:47:34 +01:00
|
|
|
<< QStringList();
|
2023-11-20 23:35:11 +01:00
|
|
|
QTest::newRow("OnlyQuotes") << QSL(R"("" "")")
|
2013-02-15 10:47:34 +01:00
|
|
|
<< QStringList();
|
2023-11-20 23:35:11 +01:00
|
|
|
QTest::newRow("EmptyQuotesAndSpace") << QSL(R"("" "" " ")")
|
|
|
|
<< QStringList(QSL(" "));
|
2013-02-15 10:47:34 +01:00
|
|
|
QTest::newRow("MultipleSpaces") << " /usr/foo -o foo.out "
|
2023-11-20 23:35:11 +01:00
|
|
|
<< (QStringList() << QSL("/usr/foo") << QSL("-o") << QSL("foo.out"));
|
2022-06-19 09:24:25 +02:00
|
|
|
QTest::newRow("Quotes") << R"("/usr/foo" "-o" "foo.out")"
|
2023-11-20 23:35:11 +01:00
|
|
|
<< (QStringList() << QSL("/usr/foo") << QSL("-o") << QSL("foo.out"));
|
2013-02-15 10:47:34 +01:00
|
|
|
QTest::newRow("SingleQuotes") << "'/usr/foo' '-o' 'foo.out'"
|
2023-11-20 23:35:11 +01:00
|
|
|
<< (QStringList() << QSL("/usr/foo") << QSL("-o") << QSL("foo.out"));
|
2013-02-15 10:47:34 +01:00
|
|
|
QTest::newRow("SingleAndDoubleQuotes") << " '/usr/foo' \"-o\" 'foo.out' "
|
2023-11-20 23:35:11 +01:00
|
|
|
<< (QStringList() << QSL("/usr/foo") << QSL("-o") << QSL("foo.out"));
|
2013-02-15 10:47:34 +01:00
|
|
|
QTest::newRow("SingleInDoubleQuotes") << "/usr/foo \"-o 'ds' \" 'foo.out' "
|
2023-11-20 23:35:11 +01:00
|
|
|
<< (QStringList() << QSL("/usr/foo") << QSL("-o 'ds' ") << QSL("foo.out"));
|
2013-02-15 10:47:34 +01:00
|
|
|
QTest::newRow("DoubleInSingleQuotes") << "/usr/foo -o 'foo\" d \".out' "
|
2023-11-20 23:35:11 +01:00
|
|
|
<< (QStringList() << QSL("/usr/foo") << QSL("-o") << QSL("foo\" d \".out"));
|
|
|
|
QTest::newRow("SpacesWithQuotes") << QSL(R"( " " " " )")
|
|
|
|
<< (QStringList() << QSL(" ") << QSL(" "));
|
2013-02-15 10:47:34 +01:00
|
|
|
QTest::newRow("QuotesAndSpaces") << "/usr/foo -o \"foo - out\""
|
2023-11-20 23:35:11 +01:00
|
|
|
<< (QStringList() << QSL("/usr/foo") << QSL("-o") << QSL("foo - out"));
|
2013-02-15 10:47:34 +01:00
|
|
|
QTest::newRow("EqualAndQuotes") << "/usr/foo -o=\"foo - out\""
|
2023-11-20 23:35:11 +01:00
|
|
|
<< (QStringList() << QSL("/usr/foo") << QSL("-o=foo - out"));
|
2013-02-15 10:47:34 +01:00
|
|
|
QTest::newRow("EqualWithSpaces") << "/usr/foo -o = \"foo - out\""
|
2023-11-20 23:35:11 +01:00
|
|
|
<< (QStringList() << QSL("/usr/foo") << QSL("-o") << QSL("=") << QSL("foo - out"));
|
2013-02-15 10:47:34 +01:00
|
|
|
QTest::newRow("MultipleSpacesAndQuotes") << " /usr/foo -o=\" foo.out \" "
|
2023-11-20 23:35:11 +01:00
|
|
|
<< (QStringList() << QSL("/usr/foo") << QSL("-o= foo.out "));
|
2013-02-15 10:47:34 +01:00
|
|
|
// Unmatched quotes should be treated as an error
|
|
|
|
QTest::newRow("UnmatchedQuote") << "/usr/bin/foo -o \"bar"
|
|
|
|
<< QStringList();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QzToolsTest::splitCommandArguments()
|
|
|
|
{
|
|
|
|
QFETCH(QString, command);
|
|
|
|
QFETCH(QStringList, result);
|
|
|
|
|
|
|
|
QCOMPARE(QzTools::splitCommandArguments(command), result);
|
|
|
|
}
|
2015-10-09 12:26:13 +02:00
|
|
|
|
2016-12-20 14:19:58 +01:00
|
|
|
void QzToolsTest::escapeSqlGlobString_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("input");
|
|
|
|
QTest::addColumn<QString>("result");
|
|
|
|
|
|
|
|
QTest::newRow("NothingToEscape") << "http://test" << "http://test";
|
|
|
|
QTest::newRow("Escape *") << "http://test*/heh" << "http://test[*]/heh";
|
|
|
|
QTest::newRow("Escape **") << "http://test**/he*h" << "http://test[*][*]/he[*]h";
|
|
|
|
QTest::newRow("Escape ?") << "http://test?/heh" << "http://test[?]/heh";
|
|
|
|
QTest::newRow("Escape ??") << "http://t??est?/heh" << "http://t[?][?]est[?]/heh";
|
|
|
|
QTest::newRow("Escape [") << "http://[test/heh" << "http://[[]test/heh";
|
|
|
|
QTest::newRow("Escape [[") << "http://[[te[st/heh" << "http://[[][[]te[[]st/heh";
|
|
|
|
QTest::newRow("Escape ]") << "http://]test/heh" << "http://[]]test/heh";
|
|
|
|
QTest::newRow("Escape ]]") << "http://]]te]st/heh" << "http://[]][]]te[]]st/heh";
|
|
|
|
QTest::newRow("Escape []") << "http://[]test/heh" << "http://[[][]]test/heh";
|
|
|
|
QTest::newRow("Escape [][[]][]") << "http://t[][[]][]est/heh" << "http://t[[][]][[][[][]][]][[][]]est/heh";
|
|
|
|
QTest::newRow("Escape [?]][[*]") << "http://t[?]][[*]est/heh" << "http://t[[][?][]][]][[][[][*][]]est/heh";
|
|
|
|
}
|
|
|
|
|
|
|
|
void QzToolsTest::escapeSqlGlobString()
|
|
|
|
{
|
|
|
|
QFETCH(QString, input);
|
|
|
|
QFETCH(QString, result);
|
|
|
|
|
|
|
|
QCOMPARE(QzTools::escapeSqlGlobString(input), result);
|
|
|
|
}
|
|
|
|
|
2015-10-09 12:26:13 +02:00
|
|
|
class TempFile
|
|
|
|
{
|
|
|
|
QString name;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit TempFile(const QString &name)
|
|
|
|
: name(name)
|
|
|
|
{
|
|
|
|
QFile file(name);
|
|
|
|
file.open(QFile::WriteOnly);
|
2018-01-24 17:15:26 +01:00
|
|
|
file.write(QByteArrayLiteral("falkon-test"));
|
2015-10-09 12:26:13 +02:00
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
~TempFile()
|
|
|
|
{
|
|
|
|
QFile::remove(name);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void QzToolsTest::ensureUniqueFilename()
|
|
|
|
{
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out")), createPath("test.out"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test")), createPath("test"));
|
|
|
|
|
|
|
|
// default appendFormat = (%1)
|
|
|
|
{
|
|
|
|
TempFile f1(createPath("test.out"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out")), createPath("test(1).out"));
|
|
|
|
TempFile f2(createPath("test(1).out"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out")), createPath("test(2).out"));
|
|
|
|
TempFile f3(createPath("test(2).out"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out")), createPath("test(3).out"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
TempFile f1(createPath("test"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test")), createPath("test(1)"));
|
|
|
|
TempFile f2(createPath("test(1)"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test")), createPath("test(2)"));
|
|
|
|
TempFile f3(createPath("test(2)"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test")), createPath("test(3)"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
TempFile f1(createPath("test(1)"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test")), createPath("test"));
|
|
|
|
TempFile f2(createPath("test"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test")), createPath("test(2)"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// appendFormat = %1
|
|
|
|
{
|
|
|
|
QString appendFormat = QSL("%1");
|
|
|
|
|
|
|
|
TempFile f1(createPath("test.out"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out"), appendFormat), createPath("test1.out"));
|
|
|
|
TempFile f2(createPath("test1.out"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out"), appendFormat), createPath("test2.out"));
|
|
|
|
TempFile f3(createPath("test2.out"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out"), appendFormat), createPath("test3.out"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QString appendFormat = QSL("%1");
|
|
|
|
|
|
|
|
TempFile f1(createPath("test"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test1"));
|
|
|
|
TempFile f2(createPath("test1"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test2"));
|
|
|
|
TempFile f3(createPath("test2"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test3"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QString appendFormat = QSL("%1");
|
|
|
|
|
|
|
|
TempFile f1(createPath("test1"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test"));
|
|
|
|
TempFile f2(createPath("test"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test2"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// appendFormat = .%1
|
|
|
|
{
|
|
|
|
QString appendFormat = QSL(".%1");
|
|
|
|
|
|
|
|
TempFile f1(createPath("test.out"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out"), appendFormat), createPath("test.1.out"));
|
|
|
|
TempFile f2(createPath("test.1.out"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out"), appendFormat), createPath("test.2.out"));
|
|
|
|
TempFile f3(createPath("test.2.out"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out"), appendFormat), createPath("test.3.out"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QString appendFormat = QSL(".%1");
|
|
|
|
|
|
|
|
TempFile f1(createPath("test"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test.1"));
|
|
|
|
TempFile f2(createPath("test.1"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test.2"));
|
|
|
|
TempFile f3(createPath("test.2"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test.3"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QString appendFormat = QSL(".%1");
|
|
|
|
|
|
|
|
TempFile f1(createPath("test.1"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test"));
|
|
|
|
TempFile f2(createPath("test"));
|
|
|
|
QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test.2"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-31 15:08:06 +02:00
|
|
|
static void createTestDirectoryStructure(const QString &path)
|
|
|
|
{
|
|
|
|
QDir().mkdir(path);
|
|
|
|
QDir dir(path);
|
2023-11-20 23:35:11 +01:00
|
|
|
dir.mkdir(QSL("dir1"));
|
|
|
|
dir.mkdir(QSL("dir2"));
|
|
|
|
dir.mkdir(QSL("dir3"));
|
|
|
|
dir.cd(QSL("dir1"));
|
|
|
|
dir.mkdir(QSL("dir1_1"));
|
|
|
|
dir.mkdir(QSL("dir1_2"));
|
|
|
|
dir.mkdir(QSL("dir1_3"));
|
2018-03-31 15:08:06 +02:00
|
|
|
dir.cdUp();
|
2023-11-20 23:35:11 +01:00
|
|
|
dir.cd(QSL("dir3"));
|
|
|
|
dir.mkdir(QSL("dir3_1"));
|
|
|
|
QFile file(path + QSL("/dir1/dir1_2/file1.txt"));
|
2018-03-31 15:08:06 +02:00
|
|
|
file.open(QFile::WriteOnly);
|
|
|
|
file.write("test");
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QzToolsTest::copyRecursivelyTest()
|
|
|
|
{
|
|
|
|
const QString testDir = createPath("copyRecursivelyTest");
|
|
|
|
createTestDirectoryStructure(testDir);
|
|
|
|
|
2024-06-15 12:35:20 +02:00
|
|
|
QVERIFY(!QFileInfo::exists(testDir + QSL("-copy")));
|
2018-03-31 15:08:06 +02:00
|
|
|
|
2018-10-21 17:14:27 +02:00
|
|
|
// Copy to non-existent target
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(QzTools::copyRecursively(testDir, testDir + QSL("-copy")), true);
|
|
|
|
|
|
|
|
QCOMPARE(QFileInfo(testDir + QSL("-copy")).isDir(), true);
|
|
|
|
QCOMPARE(QFileInfo(testDir + QSL("-copy/dir1")).isDir(), true);
|
|
|
|
QCOMPARE(QFileInfo(testDir + QSL("-copy/dir2")).isDir(), true);
|
|
|
|
QCOMPARE(QFileInfo(testDir + QSL("-copy/dir3")).isDir(), true);
|
|
|
|
QCOMPARE(QFileInfo(testDir + QSL("-copy/dir1/dir1_1")).isDir(), true);
|
|
|
|
QCOMPARE(QFileInfo(testDir + QSL("-copy/dir1/dir1_2")).isDir(), true);
|
|
|
|
QCOMPARE(QFileInfo(testDir + QSL("-copy/dir1/dir1_3")).isDir(), true);
|
|
|
|
QCOMPARE(QFileInfo(testDir + QSL("-copy/dir3/dir3_1")).isDir(), true);
|
|
|
|
QCOMPARE(QFileInfo(testDir + QSL("-copy/dir1/dir1_2/file1.txt")).isFile(), true);
|
|
|
|
|
|
|
|
QFile file(testDir + QSL("-copy/dir1/dir1_2/file1.txt"));
|
2018-03-31 15:08:06 +02:00
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
QCOMPARE(file.readAll(), QByteArray("test"));
|
2018-04-26 11:20:05 +02:00
|
|
|
file.close();
|
2018-03-31 15:08:06 +02:00
|
|
|
|
|
|
|
// Copy to target that already exists
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(QzTools::copyRecursively(testDir, testDir + QSL("-copy")), false);
|
2018-03-31 15:08:06 +02:00
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
QCOMPARE(QzTools::removeRecursively(testDir), true);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(QzTools::removeRecursively(testDir + QSL("-copy")), true);
|
2018-03-31 15:08:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QzToolsTest::removeRecursivelyTest()
|
|
|
|
{
|
|
|
|
const QString testDir = createPath("removeRecursivelyTest");
|
|
|
|
createTestDirectoryStructure(testDir);
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(QzTools::copyRecursively(testDir, testDir + QSL("-copy")), true);
|
|
|
|
QCOMPARE(QzTools::removeRecursively(testDir + QSL("-copy")), true);
|
2024-06-15 12:35:20 +02:00
|
|
|
QCOMPARE(QFileInfo::exists(testDir + QSL("-copy")), false);
|
2018-03-31 15:08:06 +02:00
|
|
|
|
2018-10-21 17:14:27 +02:00
|
|
|
// Remove non-existent path returns success
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(QzTools::removeRecursively(testDir + QSL("-copy")), true);
|
2018-03-31 15:08:06 +02:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(QzTools::copyRecursively(testDir, testDir + QSL("-copy2")), true);
|
2018-03-31 15:08:06 +02:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
QFile dir(testDir + QSL("-copy2"));
|
2018-03-31 15:08:06 +02:00
|
|
|
dir.setPermissions(dir.permissions() & ~(QFile::WriteOwner | QFile::WriteUser | QFile::WriteGroup | QFile::WriteOther));
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(QzTools::removeRecursively(testDir + QSL("-copy2")), false);
|
2018-03-31 15:08:06 +02:00
|
|
|
|
|
|
|
dir.setPermissions(dir.permissions() | QFile::WriteOwner);
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(QzTools::removeRecursively(testDir + QSL("-copy2")), true);
|
2018-03-31 15:08:06 +02:00
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
QCOMPARE(QzTools::removeRecursively(testDir), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QzToolsTest::dontFollowSymlinksTest()
|
|
|
|
{
|
|
|
|
const QString testDir = createPath("removeRecursivelyTest");
|
|
|
|
createTestDirectoryStructure(testDir);
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
QDir().mkpath(testDir + QSL("/subdir"));
|
|
|
|
QFile::link(testDir, testDir + QSL("/subdir/link"));
|
2018-03-31 15:08:06 +02:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
QVERIFY(QzTools::removeRecursively(testDir + QSL("/subdir")));
|
2018-03-31 15:08:06 +02:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
QVERIFY(!QFile::exists(testDir + QSL("/subdir")));
|
2018-03-31 15:08:06 +02:00
|
|
|
QVERIFY(QFile::exists(testDir));
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
QDir().mkpath(testDir + QSL("/subdir/normalfolder"));
|
|
|
|
QFile::link(QSL(".."), testDir + QSL("/subdir/link"));
|
2018-03-31 15:08:06 +02:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
QVERIFY(QzTools::copyRecursively(testDir + QSL("/subdir"), testDir + QSL("/subdir2")));
|
2018-03-31 15:08:06 +02:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(QFile::exists(testDir + QSL("/subdir2/link")), true);
|
|
|
|
QCOMPARE(QFile::exists(testDir + QSL("/subdir2/normalfolder")), true);
|
2018-03-31 15:08:06 +02:00
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
QCOMPARE(QzTools::removeRecursively(testDir), true);
|
|
|
|
}
|
|
|
|
|
2015-10-09 12:26:13 +02:00
|
|
|
QString QzToolsTest::createPath(const char *file) const
|
|
|
|
{
|
2023-11-20 23:35:11 +01:00
|
|
|
return m_tmpPath + QL1S("/") + QString::fromUtf8(file);
|
2015-10-09 12:26:13 +02:00
|
|
|
}
|
2018-01-24 16:38:25 +01:00
|
|
|
|
2018-02-07 18:00:44 +01:00
|
|
|
QTEST_GUILESS_MAIN(QzToolsTest)
|