diff options
author | Matthieu Gallien <matthieu.gallien@nextcloud.com> | 2022-10-07 19:21:41 +0300 |
---|---|---|
committer | Matthieu Gallien <matthieu_gallien@yahoo.fr> | 2022-10-11 17:01:58 +0300 |
commit | a378c4d80a296cf54a27a0fc4b2b92b46b971830 (patch) | |
tree | 0f7756456576cbb3d78d059b0a8b55b9977b473d | |
parent | d371855e56ce4bed449f4f998567a15d069a56a7 (diff) |
add extra tests for lock files to better capture desired behavior
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
-rw-r--r-- | test/testlockfile.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/testlockfile.cpp b/test/testlockfile.cpp index 16f246fcf..d0dcc2ae5 100644 --- a/test/testlockfile.cpp +++ b/test/testlockfile.cpp @@ -570,6 +570,67 @@ private slots: QVERIFY(fakeFolder.syncJournal().getFileRecord(QStringLiteral("A/a1"), &fileRecordUnlocked)); QVERIFY(fileRecordUnlocked._lockstate._locked); } + + void testSyncLockedFiles() + { + FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() }; + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + int nGET = 0, nPUT = 0; + QObject parent; + fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData) -> QNetworkReply * { + Q_UNUSED(outgoingData) + Q_UNUSED(request) + + if (op == QNetworkAccessManager::PutOperation) { + ++nPUT; + } else if (op == QNetworkAccessManager::GetOperation) { + ++nGET; + } + + return nullptr; + }); + + ItemCompletedSpy completeSpy(fakeFolder); + + completeSpy.clear(); + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(nGET, 0); + QCOMPARE(nPUT, 0); + + QCOMPARE(completeSpy.findItem(QStringLiteral("A/a1"))->_locked, OCC::SyncFileItem::LockStatus::UnlockedItem); + OCC::SyncJournalFileRecord fileRecordBefore; + QVERIFY(fakeFolder.syncJournal().getFileRecord(QStringLiteral("A/a1"), &fileRecordBefore)); + QVERIFY(!fileRecordBefore._lockstate._locked); + + fakeFolder.remoteModifier().modifyLockState(QStringLiteral("A/a1"), FileModifier::LockState::FileLocked, 1, QStringLiteral("Nextcloud Office"), {}, QStringLiteral("richdocuments"), QDateTime::currentDateTime().toSecsSinceEpoch(), 1226); + fakeFolder.remoteModifier().setModTimeKeepEtag(QStringLiteral("A/a1"), QDateTime::currentDateTime()); + fakeFolder.remoteModifier().appendByte(QStringLiteral("A/a1")); + + completeSpy.clear(); + QVERIFY(fakeFolder.syncOnce()); + + QCOMPARE(nGET, 1); + QCOMPARE(nPUT, 0); + + QCOMPARE(completeSpy.findItem(QStringLiteral("A/a1"))->_locked, OCC::SyncFileItem::LockStatus::LockedItem); + OCC::SyncJournalFileRecord fileRecordLocked; + QVERIFY(fakeFolder.syncJournal().getFileRecord(QStringLiteral("A/a1"), &fileRecordLocked)); + QVERIFY(fileRecordLocked._lockstate._locked); + + completeSpy.clear(); + QVERIFY(fakeFolder.syncOnce()); + + QCOMPARE(nGET, 1); + QCOMPARE(nPUT, 0); + + OCC::SyncJournalFileRecord fileRecordAfter; + QVERIFY(fakeFolder.syncJournal().getFileRecord(QStringLiteral("A/a1"), &fileRecordAfter)); + QVERIFY(fileRecordAfter._lockstate._locked); + + auto expectedState = fakeFolder.currentLocalState(); + QCOMPARE(fakeFolder.currentRemoteState(), expectedState); + } }; QTEST_GUILESS_MAIN(TestLockFile) |