Alter testUnexpectedNonPlaceholder to better reflect the actual use case
authorDries Mys <dries.mys@my-dreams.be>
Sat, 22 Jul 2023 22:01:45 +0000 (00:01 +0200)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Wed, 26 Jul 2023 09:05:50 +0000 (11:05 +0200)
Signed-off-by: Dries Mys <dries.mys@my-dreams.be>
src/libsync/vfs/cfapi/cfapiwrapper.cpp
test/testsynccfapi.cpp

index 922e899d53d57cb2845df9e3613f73a7afacfdab..ac9e90b9ed6c3d4814afe928b5fd0b134bca9e23 100644 (file)
@@ -865,7 +865,7 @@ OCC::Result<OCC::Vfs::ConvertToPlaceholderResult, QString> OCC::CfApiWrapper::co
 
 OCC::Result<OCC::Vfs::ConvertToPlaceholderResult, QString> OCC::CfApiWrapper::revertPlaceholder(const QString &path)
 {
-    const qint64 result = CfRevertPlaceholder(handleForPath(path).get(), CF_REVERT_FLAG_NONE, nullptr);
+    const auto result = CfRevertPlaceholder(handleForPath(path).get(), CF_REVERT_FLAG_NONE, nullptr);
     if (result != S_OK) {
         qCWarning(lcCfApiWrapper) << "Couldn't revert placeholder for" << path << ":" << QString::fromWCharArray(_com_error(result).ErrorMessage());
         return {"Couldn't revert placeholder"};
index f3efd762454324eea665a876d943317ddabb7c80..cc1a023f5bcdf38b3dd14063fac05372d6624e2e 100644 (file)
@@ -120,7 +120,7 @@ private slots:
         QTest::newRow("skip local discovery") << false;
     }
 
-    void testUnexpectedNonPlaceholder()
+    void testReplaceFileByIdenticalFile()
     {
         FakeFolder fakeFolder{FileInfo{}};
         auto vfs = setupVfs(fakeFolder);
@@ -129,13 +129,16 @@ private slots:
         // Create a new local (non-placeholder) file
         fakeFolder.localModifier().insert("file0");
         fakeFolder.localModifier().insert("file1");
+        CopyFile(QString(fakeFolder.localPath() + "file1").toStdWString().data(), QString(fakeFolder.localPath() + "file2").toStdWString().data(), false);
         QVERIFY(!vfs->pinState("file0").isValid());
         QVERIFY(!vfs->pinState("file1").isValid());
+        QVERIFY(!vfs->pinState("file2").isValid());
 
         // Sync the files: files should be converted to placeholder files
         QVERIFY(fakeFolder.syncOnce());
         QVERIFY(vfs->pinState("file0").isValid());
         QVERIFY(vfs->pinState("file1").isValid());
+        QVERIFY(vfs->pinState("file2").isValid());
 
         // Sync again to ensure items are fully synced, otherwise test may succeed due to those pending changes.
         QVERIFY(fakeFolder.syncOnce());
@@ -143,15 +146,17 @@ private slots:
         QVERIFY(fakeFolder.syncOnce());
         QVERIFY(completeSpy.isEmpty());
 
-        // Convert to regular file (may occur when file is replaced by another one)
-        QVERIFY(cfapi::revertPlaceholder(fakeFolder.localPath() + "file1"));
+        // Replace file1 by identical file2: Windows will convert file1 to a regular (non-placeholder) file again.
+        CopyFile(QString(fakeFolder.localPath() + "file2").toStdWString().data(), QString(fakeFolder.localPath() + "file1").toStdWString().data(), false);
         QVERIFY(vfs->pinState("file0").isValid());
         QVERIFY(!vfs->pinState("file1").isValid());
+        QVERIFY(vfs->pinState("file2").isValid());
 
         // Sync again: file should be correctly converted to placeholders
         QVERIFY(fakeFolder.syncOnce());
         QVERIFY(vfs->pinState("file0").isValid());
         QVERIFY(vfs->pinState("file1").isValid());
+        QVERIFY(vfs->pinState("file2").isValid());
     }
 
     void testReplaceOnlineOnlyFile()