Skip to content

Commit

Permalink
add automated tests for complex move scenario
Browse files Browse the repository at this point in the history
we rename the top folder and we rename a not direct child that is also
moved to another folder below the original renamed top folder

so
a/b/c
a/b/d/file

will be
e/b/c/f/file

with
a -> e
d-> f

Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Sep 11, 2024
1 parent ebe6880 commit cc46374
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions test/testsyncmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,98 @@ private slots:
QCOMPARE(counter.nMOVE, 2);
QCOMPARE(counter.nMKCOL, 0);
}

void testMultipleRenameFromServer()
{
FakeFolder fakeFolder{{}};

fakeFolder.remoteModifier().mkdir("root");
fakeFolder.remoteModifier().mkdir("root/stable");
fakeFolder.remoteModifier().mkdir("root/stable/folder to move");
fakeFolder.remoteModifier().insert("root/stable/folder to move/index.txt");
fakeFolder.remoteModifier().mkdir("root/stable/move");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

fakeFolder.remoteModifier().rename("root", "root test");
fakeFolder.remoteModifier().rename("root test/stable/folder to move", "root test/stable/folder");
fakeFolder.remoteModifier().rename("root test/stable/folder", "root test/stable/move/folder");
OperationCounter counter;
fakeFolder.setServerOverride(counter.functor());

connect(&fakeFolder.syncEngine(), &SyncEngine::aboutToPropagate, [&](SyncFileItemVector &items) {
SyncFileItemPtr root, stable, folder, file, move;
for (auto &item : items) {
qDebug() << item->_file;
if (item->_file == "root") {
root = item;
} else if (item->_file == "root test/stable") {
stable = item;
} else if (item->_file == "root test/stable/move") {
move = item;
} else if (item->_file == "root/stable/folder to move") {
folder = item;
} else if (item->_file == "root test/stable/move/folder/index.txt") {
file = item;
}
}

QVERIFY(root);
QCOMPARE(root->_instruction, CSYNC_INSTRUCTION_RENAME);
QCOMPARE(root->_direction, SyncFileItem::Down);

QVERIFY(stable);
QCOMPARE(stable->_instruction, CSYNC_INSTRUCTION_RENAME);
QCOMPARE(stable->_direction, SyncFileItem::Down);

QVERIFY(move);
QCOMPARE(move->_instruction, CSYNC_INSTRUCTION_RENAME);
QCOMPARE(move->_direction, SyncFileItem::Down);

QVERIFY(folder);
QCOMPARE(folder->_instruction, CSYNC_INSTRUCTION_RENAME);
QCOMPARE(folder->_direction, SyncFileItem::Down);

QVERIFY(file);
QCOMPARE(file->_instruction, CSYNC_INSTRUCTION_RENAME);
QCOMPARE(file->_direction, SyncFileItem::Down);
});

QVERIFY(fakeFolder.syncOnce());
QCOMPARE(counter.nDELETE, 0);
QCOMPARE(counter.nGET, 0);
QCOMPARE(counter.nPUT, 0);
QCOMPARE(counter.nMOVE, 0);
QCOMPARE(counter.nMKCOL, 0);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}

void testMultipleRenameFromLocal()
{
FakeFolder fakeFolder{{}};

fakeFolder.remoteModifier().mkdir("root");
fakeFolder.remoteModifier().mkdir("root/stable");
fakeFolder.remoteModifier().mkdir("root/stable/folder to move");
fakeFolder.remoteModifier().insert("root/stable/folder to move/index.txt");
fakeFolder.remoteModifier().mkdir("root/stable/move");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

fakeFolder.localModifier().rename("root", "root test");
fakeFolder.localModifier().rename("root test/stable/folder to move", "root test/stable/folder");
fakeFolder.localModifier().rename("root test/stable/folder", "root test/stable/move/folder");
OperationCounter counter;
fakeFolder.setServerOverride(counter.functor());

QVERIFY(fakeFolder.syncOnce());
QCOMPARE(counter.nDELETE, 0);
QCOMPARE(counter.nGET, 0);
QCOMPARE(counter.nPUT, 0);
QCOMPARE(counter.nMOVE, 2);
QCOMPARE(counter.nMKCOL, 0);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}
};

QTEST_GUILESS_MAIN(TestSyncMove)
Expand Down

0 comments on commit cc46374

Please sign in to comment.