diff options
author | Christian Kamm <mail@ckamm.de> | 2017-06-28 12:15:22 +0300 |
---|---|---|
committer | Markus Goetz <markus@woboq.com> | 2017-07-03 13:54:24 +0300 |
commit | 851a3128e4cd80024430e50904859276a1b662d1 (patch) | |
tree | 2cf2bf8c1a3d7c20a1ccca0078c26478e0145bf6 /test/testsyncengine.cpp | |
parent | bdb8a4a0cb6959bbc7e5e483f82bf295ea3c163f (diff) |
SyncEngine: Add unittest for SyncFileItem properties #5855
Checks instruction, direction, size, modtime for three common cases.
Diffstat (limited to 'test/testsyncengine.cpp')
-rw-r--r-- | test/testsyncengine.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/test/testsyncengine.cpp b/test/testsyncengine.cpp index 1f48931da..1a9ac42d1 100644 --- a/test/testsyncengine.cpp +++ b/test/testsyncengine.cpp @@ -385,6 +385,81 @@ private slots: QVERIFY(fakeFolder.syncOnce()); QCOMPARE(nGET, 1); } + + /** + * Checks whether SyncFileItems have the expected properties before start + * of propagation. + */ + void testSyncFileItemProperties() + { + FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() }; + + auto initialMtime = fakeFolder.currentLocalState().find("A/a1")->lastModified; + auto changedMtime = QDateTime::currentDateTime().addDays(-4); + auto changedMtime2 = QDateTime::currentDateTime().addDays(-3); + + // Base mtime with no ms content (filesystem is seconds only) + initialMtime.setMSecsSinceEpoch(initialMtime.toMSecsSinceEpoch() / 1000 * 1000); + changedMtime.setMSecsSinceEpoch(changedMtime.toMSecsSinceEpoch() / 1000 * 1000); + changedMtime2.setMSecsSinceEpoch(changedMtime2.toMSecsSinceEpoch() / 1000 * 1000); + + // upload a + fakeFolder.localModifier().appendByte("A/a1"); + fakeFolder.localModifier().setModTime("A/a1", changedMtime); + // download b + fakeFolder.remoteModifier().appendByte("B/b1"); + fakeFolder.remoteModifier().setModTime("B/b1", changedMtime); + // conflict c + fakeFolder.localModifier().appendByte("C/c1"); + fakeFolder.localModifier().appendByte("C/c1"); + fakeFolder.localModifier().setModTime("C/c1", changedMtime); + fakeFolder.remoteModifier().appendByte("C/c1"); + fakeFolder.remoteModifier().setModTime("C/c1", changedMtime2); + + connect(&fakeFolder.syncEngine(), &SyncEngine::aboutToPropagate, [&](SyncFileItemVector &items) { + SyncFileItemPtr a1, b1, c1; + for (auto &item : items) { + if (item->_file == "A/a1") + a1 = item; + if (item->_file == "B/b1") + b1 = item; + if (item->_file == "C/c1") + c1 = item; + } + + // a1: should have local size and modtime + QVERIFY(a1); + QCOMPARE(a1->_instruction, CSYNC_INSTRUCTION_SYNC); + QCOMPARE(a1->_direction, SyncFileItem::Up); + + // NOTE: This is currently a bug! #5855 + //QCOMPARE(a1->_size, quint64(5)); + + QCOMPARE(Utility::qDateTimeFromTime_t(a1->_modtime), changedMtime); + QCOMPARE(a1->log._other_size, quint64(4)); + QCOMPARE(Utility::qDateTimeFromTime_t(a1->log._other_modtime), initialMtime); + + // b2: should have remote size and modtime + QVERIFY(b1); + QCOMPARE(b1->_instruction, CSYNC_INSTRUCTION_SYNC); + QCOMPARE(b1->_direction, SyncFileItem::Down); + QCOMPARE(b1->_size, quint64(17)); + QCOMPARE(Utility::qDateTimeFromTime_t(b1->_modtime), changedMtime); + QCOMPARE(b1->log._other_size, quint64(16)); + QCOMPARE(Utility::qDateTimeFromTime_t(b1->log._other_modtime), initialMtime); + + // c1: conflicts are downloads, so remote size and modtime + QVERIFY(c1); + QCOMPARE(c1->_instruction, CSYNC_INSTRUCTION_CONFLICT); + QCOMPARE(c1->_direction, SyncFileItem::None); + QCOMPARE(c1->_size, quint64(25)); + QCOMPARE(Utility::qDateTimeFromTime_t(c1->_modtime), changedMtime2); + QCOMPARE(c1->log._other_size, quint64(26)); + QCOMPARE(Utility::qDateTimeFromTime_t(c1->log._other_modtime), changedMtime); + }); + + QVERIFY(fakeFolder.syncOnce()); + } }; QTEST_GUILESS_MAIN(TestSyncEngine) |