From 5175d186a404214fc0e972ba697a46881aa504dc Mon Sep 17 00:00:00 2001 From: allexzander Date: Thu, 4 Aug 2022 17:51:26 +0300 Subject: [PATCH] Do not ignore return values for SyncJournalDB in unit tests. Signed-off-by: allexzander --- test/syncenginetestutils.cpp | 2 +- test/testasyncop.cpp | 2 +- test/testblacklist.cpp | 2 +- test/testcfapishellextensionsipc.cpp | 2 +- test/testlocaldiscovery.cpp | 2 +- test/testsynccfapi.cpp | 23 +++++++++++------------ test/testsyncconflict.cpp | 2 +- test/testsyncengine.cpp | 9 ++++----- test/testsyncjournaldb.cpp | 19 +++++++++---------- test/testsyncvirtualfiles.cpp | 26 +++++++++++++------------- test/testsyncxattr.cpp | 23 +++++++++++------------ test/testuploadreset.cpp | 6 +++--- 12 files changed, 57 insertions(+), 61 deletions(-) diff --git a/test/syncenginetestutils.cpp b/test/syncenginetestutils.cpp index f3af23d43..70b87bb5a 100644 --- a/test/syncenginetestutils.cpp +++ b/test/syncenginetestutils.cpp @@ -1198,7 +1198,7 @@ static FileInfo &findOrCreateDirs(FileInfo &base, PathComponents components) FileInfo FakeFolder::dbState() const { FileInfo result; - _journalDb->getFilesBelowPath("", [&](const OCC::SyncJournalFileRecord &record) { + [[maybe_unused]] const auto journalDbResult =_journalDb->getFilesBelowPath("", [&](const OCC::SyncJournalFileRecord &record) { auto components = PathComponents(record.path()); auto &parentDir = findOrCreateDirs(result, components.parentDirComponents()); auto name = components.fileName(); diff --git a/test/testasyncop.cpp b/test/testasyncop.cpp index 22b5c57f9..2f05bd193 100644 --- a/test/testasyncop.cpp +++ b/test/testasyncop.cpp @@ -177,7 +177,7 @@ private slots: return waitAndChain(waitForeverCallback)(tc, request); }))); - fakeFolder.syncJournal().wipeErrorBlacklist(); + QVERIFY(fakeFolder.syncJournal().wipeErrorBlacklist() != -1); // This second sync will redo the files that had errors // But the waiting folder will not complete before it is aborted. diff --git a/test/testblacklist.cpp b/test/testblacklist.cpp index d71326560..f236947ec 100644 --- a/test/testblacklist.cpp +++ b/test/testblacklist.cpp @@ -14,7 +14,7 @@ using namespace OCC; SyncJournalFileRecord journalRecord(FakeFolder &folder, const QByteArray &path) { SyncJournalFileRecord rec; - folder.syncJournal().getFileRecord(path, &rec); + [[maybe_unused]] const auto result = folder.syncJournal().getFileRecord(path, &rec); return rec; } diff --git a/test/testcfapishellextensionsipc.cpp b/test/testcfapishellextensionsipc.cpp index 6f1e5ba68..d9fe3cc0d 100644 --- a/test/testcfapishellextensionsipc.cpp +++ b/test/testcfapishellextensionsipc.cpp @@ -150,7 +150,7 @@ private slots: QVERIFY(realFolder); for (const auto &dummyImageName : dummmyImageNames) { if (fakeFolder.syncJournal().getFileRecord(dummyImageName, &record)) { - realFolder->journalDb()->setFileRecord(record); + QVERIFY(realFolder->journalDb()->setFileRecord(record)); } } diff --git a/test/testlocaldiscovery.cpp b/test/testlocaldiscovery.cpp index 5cffb73eb..bc066aefc 100644 --- a/test/testlocaldiscovery.cpp +++ b/test/testlocaldiscovery.cpp @@ -153,7 +153,7 @@ private slots: QVERIFY(!trackerContains("A/spurious")); // removed due to full discovery fakeFolder.serverErrorPaths().clear(); - fakeFolder.syncJournal().wipeErrorBlacklist(); + QVERIFY(fakeFolder.syncJournal().wipeErrorBlacklist() != -1); tracker.addTouchedPath("A/newspurious"); // will be removed due to successful sync fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem, tracker.localDiscoveryPaths()); diff --git a/test/testsynccfapi.cpp b/test/testsynccfapi.cpp index 8d41fa029..43f021116 100644 --- a/test/testsynccfapi.cpp +++ b/test/testsynccfapi.cpp @@ -67,7 +67,7 @@ bool itemInstruction(const ItemCompletedSpy &spy, const QString &path, const Syn SyncJournalFileRecord dbRecord(FakeFolder &folder, const QString &path) { SyncJournalFileRecord record; - folder.syncJournal().getFileRecord(path, &record); + [[maybe_unused]] const auto result = folder.syncJournal().getFileRecord(path, &record); return record; } @@ -75,11 +75,11 @@ void triggerDownload(FakeFolder &folder, const QByteArray &path) { auto &journal = folder.syncJournal(); SyncJournalFileRecord record; - journal.getFileRecord(path, &record); - if (!record.isValid()) + if (!journal.getFileRecord(path, &record) || !record.isValid()) { return; + } record._type = ItemTypeVirtualFileDownload; - journal.setFileRecord(record); + QVERIFY(journal.setFileRecord(record)); journal.schedulePathForRemoteDiscovery(record._path); } @@ -87,11 +87,11 @@ void markForDehydration(FakeFolder &folder, const QByteArray &path) { auto &journal = folder.syncJournal(); SyncJournalFileRecord record; - journal.getFileRecord(path, &record); - if (!record.isValid()) + if (!journal.getFileRecord(path, &record) || !record.isValid()) { return; + } record._type = ItemTypeVirtualFileDehydration; - journal.setFileRecord(record); + QVERIFY(journal.setFileRecord(record)); journal.schedulePathForRemoteDiscovery(record._path); } @@ -237,8 +237,8 @@ private slots: QCOMPARE(QFileInfo(fakeFolder.localPath() + "A/a3").size(), 33); cleanup(); - fakeFolder.syncEngine().journal()->deleteFileRecord("A/a2"); - fakeFolder.syncEngine().journal()->deleteFileRecord("A/a3"); + QVERIFY(fakeFolder.syncEngine().journal()->deleteFileRecord("A/a2")); + QVERIFY(fakeFolder.syncEngine().journal()->deleteFileRecord("A/a3")); fakeFolder.remoteModifier().remove("A/a3"); fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::FilesystemOnly); QVERIFY(fakeFolder.syncOnce()); @@ -456,7 +456,7 @@ private slots: auto cleanup = [&]() { completeSpy.clear(); - fakeFolder.syncJournal().wipeErrorBlacklist(); + QVERIFY(fakeFolder.syncJournal().wipeErrorBlacklist() != -1); }; cleanup(); @@ -735,8 +735,7 @@ private slots: }; auto hasDehydratedDbEntries = [&](const QString &path) { SyncJournalFileRecord rec; - fakeFolder.syncJournal().getFileRecord(path, &rec); - return rec.isValid() && rec._type == ItemTypeVirtualFile; + return fakeFolder.syncJournal().getFileRecord(path, &rec) && rec.isValid() && rec._type == ItemTypeVirtualFile; }; QVERIFY(isDehydrated("A/a1")); diff --git a/test/testsyncconflict.cpp b/test/testsyncconflict.cpp index 7017b976d..d43549304 100644 --- a/test/testsyncconflict.cpp +++ b/test/testsyncconflict.cpp @@ -57,7 +57,7 @@ bool expectAndWipeConflict(FileModifier &local, FileInfo state, const QString pa SyncJournalFileRecord dbRecord(FakeFolder &folder, const QString &path) { SyncJournalFileRecord record; - folder.syncJournal().getFileRecord(path, &record); + [[maybe_unused]] const auto result = folder.syncJournal().getFileRecord(path, &record); return record; } diff --git a/test/testsyncengine.cpp b/test/testsyncengine.cpp index 5131bbbc2..7a562bca5 100644 --- a/test/testsyncengine.cpp +++ b/test/testsyncengine.cpp @@ -211,7 +211,7 @@ private slots: auto getDbChecksum = [&](QString path) { SyncJournalFileRecord record; - fakeFolder.syncJournal().getFileRecord(path, &record); + [[maybe_unused]] const auto result = fakeFolder.syncJournal().getFileRecord(path, &record); return record._checksumHeader; }; @@ -275,7 +275,7 @@ private slots: fakeFolder.syncEngine().journal()->schedulePathForRemoteDiscovery(QByteArrayLiteral("parentFolder/subFolderA/")); auto getEtag = [&](const QByteArray &file) { SyncJournalFileRecord rec; - fakeFolder.syncJournal().getFileRecord(file, &rec); + [[maybe_unused]] const auto result = fakeFolder.syncJournal().getFileRecord(file, &rec); return rec._etag; }; QVERIFY(getEtag("parentFolder") == "_invalid_"); @@ -336,8 +336,7 @@ private slots: QVERIFY(!fakeFolder.syncOnce()); SyncJournalFileRecord rec; - fakeFolder.syncJournal().getFileRecord(QByteArrayLiteral("NewFolder"), &rec); - QVERIFY(rec.isValid()); + QVERIFY(fakeFolder.syncJournal().getFileRecord(QByteArrayLiteral("NewFolder"), &rec) && rec.isValid()); QCOMPARE(rec._etag, QByteArrayLiteral("_invalid_")); QVERIFY(!rec._fileId.isEmpty()); } @@ -454,7 +453,7 @@ private slots: // check that mtime in journal and filesystem agree QString a1path = fakeFolder.localPath() + "A/a1"; SyncJournalFileRecord a1record; - fakeFolder.syncJournal().getFileRecord(QByteArray("A/a1"), &a1record); + QVERIFY(fakeFolder.syncJournal().getFileRecord(QByteArray("A/a1"), &a1record)); QCOMPARE(a1record._modtime, (qint64)FileSystem::getModTime(a1path)); // Extra sync reads from db, no difference diff --git a/test/testsyncjournaldb.cpp b/test/testsyncjournaldb.cpp index 44cd26257..c0a1b8a7e 100644 --- a/test/testsyncjournaldb.cpp +++ b/test/testsyncjournaldb.cpp @@ -68,7 +68,7 @@ private slots: // Update checksum record._checksumHeader = "Adler32:newchecksum"; - _db.updateFileRecordChecksum("foo", "newchecksum", "Adler32"); + QVERIFY(_db.updateFileRecordChecksum("foo", "newchecksum", "Adler32")); QVERIFY(_db.getFileRecord(QByteArrayLiteral("foo"), &storedRecord)); QVERIFY(storedRecord == record); @@ -81,7 +81,7 @@ private slots: record._fileId = "efg"; record._remotePerm = RemotePermissions::fromDbValue("NV"); record._fileSize = 289055; - _db.setFileRecord(record); + QVERIFY(_db.setFileRecord(record)); QVERIFY(_db.getFileRecord(QByteArrayLiteral("foo"), &storedRecord)); QVERIFY(storedRecord == record); @@ -213,11 +213,11 @@ private slots: record._type = type; record._etag = initialEtag; record._remotePerm = RemotePermissions::fromDbValue("RW"); - _db.setFileRecord(record); + QVERIFY(_db.setFileRecord(record)); }; auto getEtag = [&](const QByteArray &path) { SyncJournalFileRecord record; - _db.getFileRecord(path, &record); + [[maybe_unused]] const auto result = _db.getFileRecord(path, &record); return record._etag; }; @@ -275,7 +275,7 @@ private slots: SyncJournalFileRecord record; record._path = path; record._remotePerm = RemotePermissions::fromDbValue("RW"); - _db.setFileRecord(record); + QVERIFY(_db.setFileRecord(record)); }; QByteArrayList elements; @@ -296,8 +296,7 @@ private slots: bool ok = true; for (const auto& elem : elements) { SyncJournalFileRecord record; - _db.getFileRecord(elem, &record); - if (!record.isValid()) { + if (!_db.getFileRecord(elem, &record) || !record.isValid()) { qWarning() << "Missing record: " << elem; ok = false; } @@ -305,17 +304,17 @@ private slots: return ok; }; - _db.deleteFileRecord("moo", true); + QVERIFY(_db.deleteFileRecord("moo", true)); elements.removeAll("moo"); elements.removeAll("moo/file"); QVERIFY(checkElements()); - _db.deleteFileRecord("fo_", true); + QVERIFY(_db.deleteFileRecord("fo_", true)); elements.removeAll("fo_"); elements.removeAll("fo_/file"); QVERIFY(checkElements()); - _db.deleteFileRecord("foo%bar", true); + QVERIFY(_db.deleteFileRecord("foo%bar", true)); elements.removeAll("foo%bar"); QVERIFY(checkElements()); } diff --git a/test/testsyncvirtualfiles.cpp b/test/testsyncvirtualfiles.cpp index 425305b65..ada90495e 100644 --- a/test/testsyncvirtualfiles.cpp +++ b/test/testsyncvirtualfiles.cpp @@ -24,7 +24,7 @@ bool itemInstruction(const ItemCompletedSpy &spy, const QString &path, const Syn SyncJournalFileRecord dbRecord(FakeFolder &folder, const QString &path) { SyncJournalFileRecord record; - folder.syncJournal().getFileRecord(path, &record); + [[maybe_unused]] const auto result = folder.syncJournal().getFileRecord(path, &record); return record; } @@ -32,11 +32,11 @@ void triggerDownload(FakeFolder &folder, const QByteArray &path) { auto &journal = folder.syncJournal(); SyncJournalFileRecord record; - journal.getFileRecord(path + DVSUFFIX, &record); - if (!record.isValid()) + if (!journal.getFileRecord(path + DVSUFFIX, &record) || !record.isValid()) { return; + } record._type = ItemTypeVirtualFileDownload; - journal.setFileRecord(record); + QVERIFY(journal.setFileRecord(record)); journal.schedulePathForRemoteDiscovery(record._path); } @@ -44,11 +44,11 @@ void markForDehydration(FakeFolder &folder, const QByteArray &path) { auto &journal = folder.syncJournal(); SyncJournalFileRecord record; - journal.getFileRecord(path, &record); - if (!record.isValid()) + if (!journal.getFileRecord(path, &record) || !record.isValid()) { return; + } record._type = ItemTypeVirtualFileDehydration; - journal.setFileRecord(record); + QVERIFY(journal.setFileRecord(record)); journal.schedulePathForRemoteDiscovery(record._path); } @@ -186,8 +186,8 @@ private slots: QVERIFY(fakeFolder.currentLocalState().find("A/a3" DVSUFFIX)); cleanup(); - fakeFolder.syncEngine().journal()->deleteFileRecord("A/a2" DVSUFFIX); - fakeFolder.syncEngine().journal()->deleteFileRecord("A/a3" DVSUFFIX); + QVERIFY(fakeFolder.syncEngine().journal()->deleteFileRecord("A/a2" DVSUFFIX)); + QVERIFY(fakeFolder.syncEngine().journal()->deleteFileRecord("A/a3" DVSUFFIX)); fakeFolder.remoteModifier().remove("A/a3"); fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::FilesystemOnly); QVERIFY(fakeFolder.syncOnce()); @@ -431,7 +431,7 @@ private slots: auto cleanup = [&]() { completeSpy.clear(); - fakeFolder.syncJournal().wipeErrorBlacklist(); + QVERIFY(fakeFolder.syncJournal().wipeErrorBlacklist() != -1); }; cleanup(); @@ -964,9 +964,9 @@ private slots: }; auto hasDehydratedDbEntries = [&](const QString &path) { SyncJournalFileRecord normal, suffix; - fakeFolder.syncJournal().getFileRecord(path, &normal); - fakeFolder.syncJournal().getFileRecord(path + DVSUFFIX, &suffix); - return !normal.isValid() && suffix.isValid() && suffix._type == ItemTypeVirtualFile; + return (!fakeFolder.syncJournal().getFileRecord(path, &normal) || !normal.isValid()) + && fakeFolder.syncJournal().getFileRecord(path + DVSUFFIX, &suffix) && suffix.isValid() + && suffix._type == ItemTypeVirtualFile; }; QVERIFY(isDehydrated("A/a1")); diff --git a/test/testsyncxattr.cpp b/test/testsyncxattr.cpp index 896d1171e..091393057 100644 --- a/test/testsyncxattr.cpp +++ b/test/testsyncxattr.cpp @@ -45,7 +45,7 @@ bool itemInstruction(const ItemCompletedSpy &spy, const QString &path, const Syn SyncJournalFileRecord dbRecord(FakeFolder &folder, const QString &path) { SyncJournalFileRecord record; - folder.syncJournal().getFileRecord(path, &record); + [[maybe_unused]] const auto result = folder.syncJournal().getFileRecord(path, &record); return record; } @@ -53,11 +53,11 @@ void triggerDownload(FakeFolder &folder, const QByteArray &path) { auto &journal = folder.syncJournal(); SyncJournalFileRecord record; - journal.getFileRecord(path, &record); - if (!record.isValid()) + if (!journal.getFileRecord(path, &record) || !record.isValid()) { return; + } record._type = ItemTypeVirtualFileDownload; - journal.setFileRecord(record); + QVERIFY(journal.setFileRecord(record)); journal.schedulePathForRemoteDiscovery(record._path); } @@ -65,11 +65,11 @@ void markForDehydration(FakeFolder &folder, const QByteArray &path) { auto &journal = folder.syncJournal(); SyncJournalFileRecord record; - journal.getFileRecord(path, &record); - if (!record.isValid()) + if (!journal.getFileRecord(path, &record) || !record.isValid()) { return; + } record._type = ItemTypeVirtualFileDehydration; - journal.setFileRecord(record); + QVERIFY(journal.setFileRecord(record)); journal.schedulePathForRemoteDiscovery(record._path); } @@ -217,8 +217,8 @@ private slots: QCOMPARE(dbRecord(fakeFolder, "A/a3")._fileSize, 33); cleanup(); - fakeFolder.syncEngine().journal()->deleteFileRecord("A/a2"); - fakeFolder.syncEngine().journal()->deleteFileRecord("A/a3"); + QVERIFY(fakeFolder.syncEngine().journal()->deleteFileRecord("A/a2")); + QVERIFY(fakeFolder.syncEngine().journal()->deleteFileRecord("A/a3")); fakeFolder.remoteModifier().remove("A/a3"); fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::FilesystemOnly); QVERIFY(fakeFolder.syncOnce()); @@ -436,7 +436,7 @@ private slots: auto cleanup = [&]() { completeSpy.clear(); - fakeFolder.syncJournal().wipeErrorBlacklist(); + QVERIFY(fakeFolder.syncJournal().wipeErrorBlacklist() != -1); }; cleanup(); @@ -708,8 +708,7 @@ private slots: }; auto hasDehydratedDbEntries = [&](const QString &path) { SyncJournalFileRecord rec; - fakeFolder.syncJournal().getFileRecord(path, &rec); - return rec.isValid() && rec._type == ItemTypeVirtualFile; + return fakeFolder.syncJournal().getFileRecord(path, &rec) && rec.isValid() && rec._type == ItemTypeVirtualFile; }; QVERIFY(isDehydrated("A/a1")); diff --git a/test/testuploadreset.cpp b/test/testuploadreset.cpp index cc7d4c5ae..4eb55c88a 100644 --- a/test/testuploadreset.cpp +++ b/test/testuploadreset.cpp @@ -48,21 +48,21 @@ private slots: QCOMPARE(uploadInfo._errorCount, 1); QCOMPARE(uploadInfo._transferid, 1U); - fakeFolder.syncEngine().journal()->wipeErrorBlacklist(); + QVERIFY(fakeFolder.syncEngine().journal()->wipeErrorBlacklist()); QVERIFY(!fakeFolder.syncOnce()); uploadInfo = fakeFolder.syncEngine().journal()->getUploadInfo("A/a0"); QCOMPARE(uploadInfo._errorCount, 2); QCOMPARE(uploadInfo._transferid, 1U); - fakeFolder.syncEngine().journal()->wipeErrorBlacklist(); + QVERIFY(fakeFolder.syncEngine().journal()->wipeErrorBlacklist()); QVERIFY(!fakeFolder.syncOnce()); uploadInfo = fakeFolder.syncEngine().journal()->getUploadInfo("A/a0"); QCOMPARE(uploadInfo._errorCount, 3); QCOMPARE(uploadInfo._transferid, 1U); - fakeFolder.syncEngine().journal()->wipeErrorBlacklist(); + QVERIFY(fakeFolder.syncEngine().journal()->wipeErrorBlacklist()); QVERIFY(!fakeFolder.syncOnce()); uploadInfo = fakeFolder.syncEngine().journal()->getUploadInfo("A/a0");