diff --git a/test/testutility.cpp b/test/testutility.cpp index 89b54f5d607fe..7c39b0e7fbfe6 100644 --- a/test/testutility.cpp +++ b/test/testutility.cpp @@ -291,6 +291,54 @@ private slots: QVERIFY(!isPathWindowsDrivePartitionRoot("c:\\")); #endif } + + void testFullRemotePathToRemoteSyncRootRelative() + { + QVector> remoteFullPathsForRoot = { + {"2020", {"2020"}}, + {"/2021/", {"2021"}}, + {"/2022/file.docx", {"2022/file.docx"}} + }; + // test against root remote path - result must stay unchanged, leading and trailing slashes must get removed + for (const auto &remoteFullPathForRoot : remoteFullPathsForRoot) { + const auto fullRemotePathOriginal = remoteFullPathForRoot.first; + const auto fullRemotePathExpected = remoteFullPathForRoot.second; + const auto fullRepotePathResult = OCC::Utility::fullRemotePathToRemoteSyncRootRelative(fullRemotePathOriginal, "/"); + QCOMPARE(fullRepotePathResult, fullRemotePathExpected); + } + + QString remotePathNonRoot = "/Documents/reports"; + QVector> remoteFullPathsForNonRoot = { + {remotePathNonRoot + "/" + "2020", {"2020"}}, + {remotePathNonRoot + "/" + "2021/", {"2021"}}, + {remotePathNonRoot + "/" + "2022/file.docx", {"2022/file.docx"}} + }; + + // test against non-root remote path - must always return a proper path as in local db + for (const auto &remoteFullPathForNonRoot : remoteFullPathsForNonRoot) { + const auto fullRemotePathOriginal = remoteFullPathForNonRoot.first; + const auto fullRemotePathExpected = remoteFullPathForNonRoot.second; + const auto fullRepotePathResult = OCC::Utility::fullRemotePathToRemoteSyncRootRelative(fullRemotePathOriginal, remotePathNonRoot); + QCOMPARE(fullRepotePathResult, fullRemotePathExpected); + } + + // test against non-root remote path with trailing slash - must work the same + QString remotePathNonRootWithTrailingSlash = "/Documents/reports/"; + for (const auto &remoteFullPathForNonRoot : remoteFullPathsForNonRoot) { + const auto fullRemotePathOriginal = remoteFullPathForNonRoot.first; + const auto fullRemotePathExpected = remoteFullPathForNonRoot.second; + const auto fullRepotePathResult = OCC::Utility::fullRemotePathToRemoteSyncRootRelative(fullRemotePathOriginal, remotePathNonRootWithTrailingSlash); + QCOMPARE(fullRepotePathResult, fullRemotePathExpected); + } + + // test against unrelated remote path - result must stay unchanged + QString remotePathUnrelated = "/Documents1/reports"; + for (const auto &remoteFullPathForNonRoot : remoteFullPathsForNonRoot) { + const auto fullRemotePathOriginal = remoteFullPathForNonRoot.first; + const auto fullRepotePathResult = OCC::Utility::fullRemotePathToRemoteSyncRootRelative(fullRemotePathOriginal, remotePathUnrelated); + QCOMPARE(fullRepotePathResult, fullRemotePathOriginal); + } + } }; QTEST_GUILESS_MAIN(TestUtility)