|
23 | 23 | #include "common/utility_win.h" |
24 | 24 | #endif |
25 | 25 |
|
| 26 | + |
| 27 | +using namespace Qt::Literals::StringLiterals; |
26 | 28 | using namespace OCC; |
27 | 29 |
|
28 | 30 |
|
@@ -52,13 +54,24 @@ private Q_SLOTS: |
52 | 54 | auto newAccountState = TestUtils::createDummyAccount(); |
53 | 55 | FolderMan *folderman = TestUtils::folderMan(); |
54 | 56 | 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 | + |
55 | 70 | QVERIFY(folderman->addFolder( |
56 | 71 | newAccountState.get(), TestUtils::createDummyFolderDefinition(newAccountState->account(), dirPath + QStringLiteral("/sub/OpenCloud1")))); |
57 | 72 | QVERIFY(folderman->addFolder( |
58 | 73 | newAccountState.get(), TestUtils::createDummyFolderDefinition(newAccountState->account(), dirPath + QStringLiteral("/OpenCloud2")))); |
59 | 74 |
|
60 | | - const auto type = FolderMan::NewFolderType::SpacesFolder; |
61 | | - const QUuid uuid = {}; |
62 | 75 |
|
63 | 76 | // those should be allowed |
64 | 77 | // QString FolderMan::checkPathValidityForNewFolder(const QString& path, const QUrl &serverUrl, bool forNewDirectory) |
@@ -118,19 +131,6 @@ private Q_SLOTS: |
118 | 131 | } |
119 | 132 | #endif |
120 | 133 |
|
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 | | - |
134 | 134 | // Invalid paths |
135 | 135 | QCOMPARE_NE(folderman->checkPathValidityForNewFolder({}, type, uuid), QString()); |
136 | 136 |
|
@@ -159,6 +159,26 @@ private Q_SLOTS: |
159 | 159 | QVERIFY(QFileInfo::exists(dirPath + QStringLiteral("/db-check2/._sync_something.db"))); |
160 | 160 | QCOMPARE_NE(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/db-check2"), type, uuid), QString()); |
161 | 161 | } |
| 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 | + } |
162 | 182 | } |
163 | 183 |
|
164 | 184 | void testFindGoodPathForNewSyncFolder() |
|
0 commit comments