From 764c14140f4354325dfd736159f377977be98832 Mon Sep 17 00:00:00 2001 From: alex-z Date: Fri, 12 Jan 2024 19:57:14 +0100 Subject: [PATCH] Fix unit tests for file lock feature. Signed-off-by: alex-z --- src/libsync/lockfilejobs.cpp | 2 +- src/libsync/syncfileitem.h | 2 +- test/testlockfile.cpp | 42 ++++++++++++++++++++++++------------ 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/libsync/lockfilejobs.cpp b/src/libsync/lockfilejobs.cpp index 972bffa39a202..d1d0f98b9b9a4 100644 --- a/src/libsync/lockfilejobs.cpp +++ b/src/libsync/lockfilejobs.cpp @@ -183,7 +183,7 @@ SyncJournalFileRecord LockFileJob::handleReply() if (_journal->getFileRecord(relativePathInDb, &record) && record.isValid()) { setFileRecordLocked(record); if ((_lockStatus == SyncFileItem::LockStatus::LockedItem) - && (_userId != account()->davUser())) { + && (_lockOwnerType == SyncFileItem::LockOwnerType::AppLock || _userId != account()->davUser())) { FileSystem::setFileReadOnly(_localSyncPath + relativePathInDb, true); } const auto result = _journal->setFileRecord(record); diff --git a/src/libsync/syncfileitem.h b/src/libsync/syncfileitem.h index a7dbcbd340f4e..c0d880be6097f 100644 --- a/src/libsync/syncfileitem.h +++ b/src/libsync/syncfileitem.h @@ -117,7 +117,7 @@ class OWNCLOUDSYNC_EXPORT SyncFileItem enum class LockOwnerType : int{ UserLock = 0, AppLock = 1, - TokenLock = 3, + TokenLock = 2, }; Q_ENUM(LockOwnerType) diff --git a/test/testlockfile.cpp b/test/testlockfile.cpp index 7271a56e46abb..174f9c656abea 100644 --- a/test/testlockfile.cpp +++ b/test/testlockfile.cpp @@ -40,7 +40,8 @@ private slots: QStringLiteral("/"), fakeFolder.localPath(), &fakeFolder.syncJournal(), - OCC::SyncFileItem::LockStatus::LockedItem); + OCC::SyncFileItem::LockStatus::LockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QVERIFY(lockFileSuccessSpy.wait()); QCOMPARE(lockFileErrorSpy.count(), 0); @@ -85,7 +86,8 @@ private slots: QStringLiteral("/"), fakeFolder.localPath(), &fakeFolder.syncJournal(), - OCC::SyncFileItem::LockStatus::LockedItem); + OCC::SyncFileItem::LockStatus::LockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QVERIFY(lockFileErrorSpy.wait()); QCOMPARE(lockFileSuccessSpy.count(), 0); @@ -109,7 +111,8 @@ private slots: QStringLiteral("/"), fakeFolder.localPath(), &fakeFolder.syncJournal(), - OCC::SyncFileItem::LockStatus::LockedItem); + OCC::SyncFileItem::LockStatus::LockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QVERIFY(lockFileSuccessSpy.wait()); QCOMPARE(lockFileErrorSpy.count(), 0); @@ -136,7 +139,8 @@ private slots: QStringLiteral("/"), fakeFolder.localPath(), &fakeFolder.syncJournal(), - OCC::SyncFileItem::LockStatus::LockedItem); + OCC::SyncFileItem::LockStatus::LockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QVERIFY(lockFileSuccessSpy.wait()); QCOMPARE(lockFileErrorSpy.count(), 0); @@ -160,7 +164,8 @@ private slots: QStringLiteral("/") + testFileName, QStringLiteral("/"), fakeFolder.localPath(), - OCC::SyncFileItem::LockStatus::LockedItem); + OCC::SyncFileItem::LockStatus::LockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QSignalSpy jobSuccess(job, &OCC::LockFileJob::finishedWithoutError); QSignalSpy jobFailure(job, &OCC::LockFileJob::finishedWithError); @@ -198,7 +203,8 @@ private slots: QStringLiteral("/") + testFileName, QStringLiteral("/"), fakeFolder.localPath(), - OCC::SyncFileItem::LockStatus::LockedItem); + OCC::SyncFileItem::LockStatus::LockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QSignalSpy lockFileJobSuccess(lockFileJob, &OCC::LockFileJob::finishedWithoutError); QSignalSpy lockFileJobFailure(lockFileJob, &OCC::LockFileJob::finishedWithError); @@ -215,7 +221,8 @@ private slots: QStringLiteral("/") + testFileName, QStringLiteral("/"), fakeFolder.localPath(), - OCC::SyncFileItem::LockStatus::UnlockedItem); + OCC::SyncFileItem::LockStatus::UnlockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QSignalSpy unlockFileJobSuccess(unlockFileJob, &OCC::LockFileJob::finishedWithoutError); QSignalSpy unlockFileJobFailure(unlockFileJob, &OCC::LockFileJob::finishedWithError); @@ -274,7 +281,8 @@ private slots: QStringLiteral("/") + testFileName, QStringLiteral("/"), fakeFolder.localPath(), - OCC::SyncFileItem::LockStatus::LockedItem); + OCC::SyncFileItem::LockStatus::LockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QSignalSpy jobSuccess(job, &OCC::LockFileJob::finishedWithoutError); QSignalSpy jobFailure(job, &OCC::LockFileJob::finishedWithError); @@ -327,7 +335,8 @@ private slots: QStringLiteral("/") + testFileName, QStringLiteral("/"), fakeFolder.localPath(), - OCC::SyncFileItem::LockStatus::LockedItem); + OCC::SyncFileItem::LockStatus::LockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QSignalSpy jobSuccess(job, &OCC::LockFileJob::finishedWithoutError); QSignalSpy jobFailure(job, &OCC::LockFileJob::finishedWithError); @@ -380,7 +389,8 @@ private slots: QStringLiteral("/") + testFileName, QStringLiteral("/"), fakeFolder.localPath(), - OCC::SyncFileItem::LockStatus::UnlockedItem); + OCC::SyncFileItem::LockStatus::UnlockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QSignalSpy jobSuccess(job, &OCC::LockFileJob::finishedWithoutError); QSignalSpy jobFailure(job, &OCC::LockFileJob::finishedWithError); @@ -431,7 +441,8 @@ private slots: QStringLiteral("/") + testFileName, QStringLiteral("/"), fakeFolder.localPath(), - OCC::SyncFileItem::LockStatus::UnlockedItem); + OCC::SyncFileItem::LockStatus::UnlockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QSignalSpy jobSuccess(job, &OCC::LockFileJob::finishedWithoutError); QSignalSpy jobFailure(job, &OCC::LockFileJob::finishedWithError); @@ -469,7 +480,8 @@ private slots: QStringLiteral("/") + testFileName, QStringLiteral("/"), fakeFolder.localPath(), - OCC::SyncFileItem::LockStatus::LockedItem); + OCC::SyncFileItem::LockStatus::LockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QSignalSpy lockFileJobSuccess(lockFileJob, &OCC::LockFileJob::finishedWithoutError); QSignalSpy lockFileJobFailure(lockFileJob, &OCC::LockFileJob::finishedWithError); @@ -486,7 +498,8 @@ private slots: QStringLiteral("/") + testFileName, QStringLiteral("/"), fakeFolder.localPath(), - OCC::SyncFileItem::LockStatus::UnlockedItem); + OCC::SyncFileItem::LockStatus::UnlockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QSignalSpy unlockFileJobSuccess(unlockFileJob, &OCC::LockFileJob::finishedWithoutError); QSignalSpy unlockFileJobFailure(unlockFileJob, &OCC::LockFileJob::finishedWithError); @@ -539,7 +552,8 @@ private slots: QStringLiteral("/") + testFileName, QStringLiteral("/"), fakeFolder.localPath(), - OCC::SyncFileItem::LockStatus::UnlockedItem); + OCC::SyncFileItem::LockStatus::UnlockedItem, + OCC::SyncFileItem::LockOwnerType::UserLock); QSignalSpy jobSuccess(job, &OCC::LockFileJob::finishedWithoutError); QSignalSpy jobFailure(job, &OCC::LockFileJob::finishedWithError);