Skip to content

Commit 511900b

Browse files
committed
chore: add test for fileId check via sync journal
Signed-off-by: Jyrki Gadinger <[email protected]>
1 parent 9d3ed8f commit 511900b

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

test/testsyncjournaldb.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "logger.h"
1818

1919
using namespace OCC;
20+
using namespace Qt::StringLiterals;
2021

2122
class TestSyncJournalDB : public QObject
2223
{
@@ -509,6 +510,73 @@ private slots:
509510
QCOMPARE(list->size(), 0);
510511
}
511512

513+
void testHasFileIds()
514+
{
515+
QList<qint64> allFileIds = {};
516+
const auto makeEntry = [this, &allFileIds](const qint64 &fileId) -> void {
517+
SyncJournalFileRecord record;
518+
record._fileId = u"%1oc123xyz987e"_s.arg(fileId, 8, 10, '0'_L1).toLocal8Bit();
519+
record._modtime = QDateTime::currentSecsSinceEpoch();
520+
record._path = u"item%1"_s.arg(fileId).toLocal8Bit();
521+
record._type = ItemTypeFile;
522+
record._etag = "etag"_ba;
523+
QVERIFY(_db.setFileRecord(record));
524+
525+
allFileIds.append(fileId);
526+
};
527+
528+
// generate some test data: -9, 0..32, int32_max..(int32_max + 32), (int64_max - 32)..int64_max
529+
makeEntry(-9);
530+
531+
for (qint64 fileId = 0; fileId <= 32; fileId++) {
532+
makeEntry(fileId);
533+
}
534+
535+
constexpr qint64 maxInt32 = std::numeric_limits<qint32>::max();
536+
for (qint64 fileId = maxInt32; fileId <= maxInt32 + 32; fileId++) {
537+
makeEntry(fileId);
538+
}
539+
540+
constexpr qint64 maxInt64 = std::numeric_limits<qint64>::max();
541+
for (qint64 fileId = maxInt64 - 32; fileId < maxInt64; fileId++) {
542+
makeEntry(fileId);
543+
}
544+
makeEntry(maxInt64); // have an entry for the maximum int64 value
545+
546+
// these exist:
547+
QVERIFY(_db.hasFileIds({4}));
548+
QVERIFY(_db.hasFileIds({-9}));
549+
QVERIFY(_db.hasFileIds({8, 25, 31}));
550+
QVERIFY(_db.hasFileIds({maxInt32 + 4, maxInt64 - 17}));
551+
QVERIFY(_db.hasFileIds({maxInt64 - 17}));
552+
QVERIFY(_db.hasFileIds({maxInt64}));
553+
554+
// these don't:
555+
QVERIFY(!_db.hasFileIds({-8}));
556+
QVERIFY(!_db.hasFileIds({-16}));
557+
QVERIFY(!_db.hasFileIds({-(maxInt32 + 4)}));
558+
QVERIFY(!_db.hasFileIds({maxInt64 - 33}));
559+
QVERIFY(!_db.hasFileIds({maxInt32 + 33}));
560+
QVERIFY(!_db.hasFileIds({std::numeric_limits<qint32>::min()}));
561+
QVERIFY(!_db.hasFileIds({std::numeric_limits<qint64>::min()}));
562+
563+
// as fileids are padded with zeroes, ensure that there is no accidental base-8 conversion done
564+
// 0o37 (octal) == 31 (decimal) --> 37(dec) does not exist, but 31(dec) does.
565+
QVERIFY(_db.hasFileIds({037})); // octal
566+
QVERIFY(!_db.hasFileIds({37})); // decimal
567+
568+
QVERIFY(!_db.hasFileIds({33})); // 33 does not exist...
569+
QVERIFY(_db.hasFileIds({33, 25})); // ...but 25 does
570+
571+
// nothing doesn't exist
572+
QVERIFY(!_db.hasFileIds({}));
573+
574+
// checking for a large amount of file ids should also work just fine, and be reasonably fast.
575+
QBENCHMARK {
576+
QVERIFY(_db.hasFileIds(allFileIds));
577+
}
578+
}
579+
512580
private:
513581
SyncJournalDb _db;
514582
};

0 commit comments

Comments
 (0)