|
17 | 17 | #include "logger.h" |
18 | 18 |
|
19 | 19 | using namespace OCC; |
| 20 | +using namespace Qt::StringLiterals; |
20 | 21 |
|
21 | 22 | class TestSyncJournalDB : public QObject |
22 | 23 | { |
@@ -509,6 +510,73 @@ private slots: |
509 | 510 | QCOMPARE(list->size(), 0); |
510 | 511 | } |
511 | 512 |
|
| 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 | + |
512 | 580 | private: |
513 | 581 | SyncJournalDb _db; |
514 | 582 | }; |
|
0 commit comments