Skip to content

Commit 01544bf

Browse files
committed
Fix unit test
1 parent 28702c9 commit 01544bf

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

test/testfolderman.cpp

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "common/utility_win.h"
2424
#endif
2525

26+
27+
using namespace Qt::Literals::StringLiterals;
2628
using namespace OCC;
2729

2830

@@ -52,13 +54,24 @@ private Q_SLOTS:
5254
auto newAccountState = TestUtils::createDummyAccount();
5355
FolderMan *folderman = TestUtils::folderMan();
5456
QCOMPARE(folderman, FolderMan::instance());
57+
58+
const auto type = FolderMan::NewFolderType::SpacesFolder;
59+
const QUuid uuid = {};
60+
61+
if (Utility::isWindows()) { // drive-letter tests
62+
if (QFileInfo(QStringLiteral("c:/")).isWritable()) {
63+
// we expect success
64+
QCOMPARE(folderman->checkPathValidityForNewFolder(QStringLiteral("c:"), type, uuid), QString());
65+
QCOMPARE(folderman->checkPathValidityForNewFolder(QStringLiteral("c:/"), type, uuid), QString());
66+
QCOMPARE(folderman->checkPathValidityForNewFolder(QStringLiteral("c:/foo"), type, uuid), QString());
67+
}
68+
}
69+
5570
QVERIFY(folderman->addFolder(
5671
newAccountState.get(), TestUtils::createDummyFolderDefinition(newAccountState->account(), dirPath + QStringLiteral("/sub/OpenCloud1"))));
5772
QVERIFY(folderman->addFolder(
5873
newAccountState.get(), TestUtils::createDummyFolderDefinition(newAccountState->account(), dirPath + QStringLiteral("/OpenCloud2"))));
5974

60-
const auto type = FolderMan::NewFolderType::SpacesFolder;
61-
const QUuid uuid = {};
6275

6376
// those should be allowed
6477
// QString FolderMan::checkPathValidityForNewFolder(const QString& path, const QUrl &serverUrl, bool forNewDirectory)
@@ -118,19 +131,6 @@ private Q_SLOTS:
118131
}
119132
#endif
120133

121-
if (Utility::isWindows()) { // drive-letter tests
122-
if (!QFileInfo(QStringLiteral("v:/")).exists()) {
123-
QCOMPARE_NE(folderman->checkPathValidityForNewFolder(QStringLiteral("v:"), type, uuid), QString());
124-
QCOMPARE_NE(folderman->checkPathValidityForNewFolder(QStringLiteral("v:/"), type, uuid), QString());
125-
QCOMPARE_NE(folderman->checkPathValidityForNewFolder(QStringLiteral("v:/foo"), type, uuid), QString());
126-
}
127-
if (QFileInfo(QStringLiteral("c:/")).isWritable()) {
128-
QCOMPARE(folderman->checkPathValidityForNewFolder(QStringLiteral("c:"), type, uuid), QString());
129-
QCOMPARE(folderman->checkPathValidityForNewFolder(QStringLiteral("c:/"), type, uuid), QString());
130-
QCOMPARE(folderman->checkPathValidityForNewFolder(QStringLiteral("c:/foo"), type, uuid), QString());
131-
}
132-
}
133-
134134
// Invalid paths
135135
QCOMPARE_NE(folderman->checkPathValidityForNewFolder({}, type, uuid), QString());
136136

@@ -159,6 +159,26 @@ private Q_SLOTS:
159159
QVERIFY(QFileInfo::exists(dirPath + QStringLiteral("/db-check2/._sync_something.db")));
160160
QCOMPARE_NE(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/db-check2"), type, uuid), QString());
161161
}
162+
163+
164+
if (Utility::isWindows()) { // drive-letter tests
165+
const auto driveLetter = QFileInfo(dirPath).absoluteDir().absolutePath().at(0);
166+
const auto drive = u"%1:/"_s.arg(driveLetter);
167+
qDebug() << u"Checking drive:" << drive << u"writable:" << QFileInfo(drive).isWritable() << u"sync roots are in" << dirPath;
168+
if (QFileInfo(drive).isWritable()) {
169+
// fails as we already sync dirPath + QStringLiteral("/sub/OpenCloud1")
170+
171+
qDebug() << folderman->checkPathValidityForNewFolder(u"%1:"_s.arg(driveLetter), type, uuid);
172+
qDebug() << folderman->checkPathValidityForNewFolder(u"%1/:"_s.arg(driveLetter), type, uuid);
173+
// succeeds as the sub dir foo does not contain OpenCloud1
174+
qDebug() << folderman->checkPathValidityForNewFolder(u"%1:/foo"_s.arg(driveLetter), type, uuid);
175+
176+
QCOMPARE_NE(folderman->checkPathValidityForNewFolder(u"%1:"_s.arg(driveLetter), type, uuid), QString());
177+
QCOMPARE_NE(folderman->checkPathValidityForNewFolder(u"%1/:"_s.arg(driveLetter), type, uuid), QString());
178+
// succeeds as the sub dir foo does not contain OpenCloud1
179+
QCOMPARE(folderman->checkPathValidityForNewFolder(u"%1:/foo"_s.arg(driveLetter), type, uuid), QString());
180+
}
181+
}
162182
}
163183

164184
void testFindGoodPathForNewSyncFolder()

0 commit comments

Comments
 (0)