From 5decbd0b214d7222e22bb8602fb04cc231c0e94f Mon Sep 17 00:00:00 2001 From: Camila Date: Tue, 26 Oct 2021 22:37:43 +0200 Subject: [PATCH] Expand ExcludedFiles tests. Signed-off-by: Camila --- test/testexcludedfiles.cpp | 72 +++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/test/testexcludedfiles.cpp b/test/testexcludedfiles.cpp index 7dc8b19f0..c044f5e59 100644 --- a/test/testexcludedfiles.cpp +++ b/test/testexcludedfiles.cpp @@ -700,7 +700,77 @@ private slots: QVERIFY(excludes.versionDirectiveKeepNextLine(test.first) == test.second); } } - + + void testAddExcludeFilePath_addSameFilePath_listSizeDoesNotIncrease() + { + excludedFiles.reset(new ExcludedFiles()); + const auto filePath = QString("exclude/.sync-exclude.lst"); + + excludedFiles->addExcludeFilePath(filePath); + excludedFiles->addExcludeFilePath(filePath); + + QCOMPARE(excludedFiles->_excludeFiles.size(), 1); + } + + void testAddExcludeFilePath_addDifferentFilePaths_listSizeIncrease() + { + excludedFiles.reset(new ExcludedFiles()); + + const auto filePath1 = QString("exclude1/.sync-exclude.lst"); + const auto filePath2 = QString("exclude2/.sync-exclude.lst"); + + excludedFiles->addExcludeFilePath(filePath1); + excludedFiles->addExcludeFilePath(filePath2); + + QCOMPARE(excludedFiles->_excludeFiles.size(), 2); + } + + void testAddExcludeFilePath_addDefaultExcludeFile_returnCorrectMap() + { + const QString basePath("syncFolder/"); + const QString folder1("syncFolder/folder1/"); + const QString folder2(folder1 + "folder2/"); + excludedFiles.reset(new ExcludedFiles(basePath)); + + const QString defaultExcludeList("desktop-client/config-folder/sync-exclude.lst"); + const QString folder1ExcludeList(folder1 + ".sync-exclude.lst"); + const QString folder2ExcludeList(folder2 + ".sync-exclude.lst"); + + excludedFiles->addExcludeFilePath(defaultExcludeList); + excludedFiles->addExcludeFilePath(folder1ExcludeList); + excludedFiles->addExcludeFilePath(folder2ExcludeList); + + QCOMPARE(excludedFiles->_excludeFiles.size(), 3); + QCOMPARE(excludedFiles->_excludeFiles[basePath].first(), defaultExcludeList); + QCOMPARE(excludedFiles->_excludeFiles[folder1].first(), folder1ExcludeList); + QCOMPARE(excludedFiles->_excludeFiles[folder2].first(), folder2ExcludeList); + } + + void testReloadExcludeFiles_fileDoesNotExist_returnFalse() { + excludedFiles.reset(new ExcludedFiles()); + const QString nonExistingFile("directory/.sync-exclude.lst"); + excludedFiles->addExcludeFilePath(nonExistingFile); + QCOMPARE(excludedFiles->reloadExcludeFiles(), false); + QCOMPARE(excludedFiles->_allExcludes.size(), 0); + } + + void testReloadExcludeFiles_fileExists_returnTrue() + { + const auto tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation); + excludedFiles.reset(new ExcludedFiles(tempDir + "/")); + + const auto subTempDir = QStringLiteral("exclude"); + QVERIFY(QDir(tempDir).mkpath(subTempDir)); + + const auto existingFilePath = QString(tempDir + '/' + subTempDir + "/.sync-exclude.lst"); + QFile excludeList(existingFilePath); + QVERIFY(excludeList.open(QFile::WriteOnly)); + excludeList.close(); + + excludedFiles->addExcludeFilePath(existingFilePath); + QCOMPARE(excludedFiles->reloadExcludeFiles(), true); + QCOMPARE(excludedFiles->_allExcludes.size(), 1); + } }; QTEST_APPLESS_MAIN(TestExcludedFiles) -- 2.30.2