From: Hannah von Reth Date: Fri, 20 Mar 2020 10:17:48 +0000 (+0100) Subject: Test: Add test for vfs failed move crash X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~122 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7644be576fb79981e2cf7fc2b27788769309a576;p=nextcloud-desktop.git Test: Add test for vfs failed move crash --- diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index 0774f2a97..14c30fc8a 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -281,6 +281,10 @@ public: && children == other.children; } + bool operator!=(const FileInfo &other) const { + return !operator==(other); + } + QString path() const { return (parentPath.isEmpty() ? QString() : (parentPath + '/')) + name; } diff --git a/test/testsyncmove.cpp b/test/testsyncmove.cpp index 7925e3beb..540d313ed 100644 --- a/test/testsyncmove.cpp +++ b/test/testsyncmove.cpp @@ -857,6 +857,63 @@ private slots: QVERIFY(fakeFolder.syncOnce()); QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); } + + void testMovedWithError_data() + { + QTest::addColumn("vfsMode"); + + QTest::newRow("Vfs::Off") << Vfs::Off; + QTest::newRow("Vfs::WithSuffix") << Vfs::WithSuffix; +#ifdef Q_OS_WIN32 + QTest::newRow("Vfs::WindowsCfApi") << Vfs::WindowsCfApi; +#endif + } + + void testMovedWithError() + { + QFETCH(Vfs::Mode, vfsMode); + const auto getName = [vfsMode] (const QString &s) + { + if (vfsMode == Vfs::WithSuffix) + { + return QStringLiteral("%1" APPLICATION_DOTVIRTUALFILE_SUFFIX).arg(s); + } + return s; + }; + const QByteArray testPath = "folder/folderA/file.txt"; + FakeFolder fakeFolder{ FileInfo{ QString(), { FileInfo{ QStringLiteral("folder"), { FileInfo{ QStringLiteral("folderA"), { { QStringLiteral("file.txt"), 400 } } }, QStringLiteral("folderB") } } } } }; + + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + if (vfsMode != Vfs::Off) + { + auto vfs = QSharedPointer(createVfsFromPlugin(Vfs::WithSuffix).release()); + QVERIFY(vfs); + fakeFolder.switchToVfs(vfs); + fakeFolder.syncJournal().internalPinStates().setForPath("", PinState::OnlineOnly); + + // make files virtual + fakeFolder.syncOnce(); + } + + fakeFolder.serverErrorPaths().append(testPath, 403); + fakeFolder.localModifier().rename(getName(testPath), getName("folder/folderB/file.txt")); + + // sync1 file gets detected as error, instruction is still NEW_FILE + fakeFolder.syncOnce(); + + // sync2 file is in error state, checkErrorBlacklisting sets instruction to IGNORED + fakeFolder.syncOnce(); + + if (vfsMode != Vfs::Off) + { + fakeFolder.syncJournal().internalPinStates().setForPath("", PinState::AlwaysLocal); + fakeFolder.syncOnce(); + } + // the sync must have failed as we have a file in the error state + QVERIFY(fakeFolder.currentLocalState() != fakeFolder.currentRemoteState()); + } + }; QTEST_GUILESS_MAIN(TestSyncMove)