Skip to content

Commit

Permalink
add new automated tests to investigate the bug
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Jun 14, 2024
1 parent 36c4b9a commit 8f7aa24
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/testsynccfapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class TestSyncCfApi : public QObject
Q_OBJECT

private slots:
void initTestCase()
{
Logger::instance()->setLogFlush(true);
Logger::instance()->setLogDebug(true);
}

void testVirtualFileLifecycle_data()
{
QTest::addColumn<bool>("doLocalDiscovery");
Expand Down Expand Up @@ -1384,6 +1390,62 @@ private slots:
QVERIFY(fakeFolder.syncOnce());
QVERIFY(itemInstruction(completeSpy, "A", CSYNC_INSTRUCTION_NONE));
}

void testRemoteTypeChangeExistingLocalMustGetRemoved()
{
FakeFolder fakeFolder{FileInfo{}};
setupVfs(fakeFolder);

// test file change to directory on remote
fakeFolder.remoteModifier().mkdir("a");
fakeFolder.remoteModifier().insert("a/TESTFILE");
QVERIFY(fakeFolder.syncOnce());

fakeFolder.remoteModifier().remove("a/TESTFILE");
fakeFolder.remoteModifier().mkdir("a/TESTFILE");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());


// test directory change to file on remote
fakeFolder.remoteModifier().mkdir("a/TESTDIR");
QVERIFY(fakeFolder.syncOnce());

fakeFolder.remoteModifier().remove("a/TESTDIR");
fakeFolder.remoteModifier().insert("a/TESTDIR");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}

void testRecursiveRename()
{
FakeFolder fakeFolder{FileInfo{}};

// test file change to directory on remote
fakeFolder.remoteModifier().mkdir("folder1");
fakeFolder.remoteModifier().mkdir("folder1/folder1.1");
fakeFolder.remoteModifier().insert("folder1/folder1.1/TESTFILE1.1.1");
fakeFolder.remoteModifier().mkdir("folder1/folder1.2");
fakeFolder.remoteModifier().mkdir("folder1/folder1.2/folder1.2.1");
fakeFolder.remoteModifier().insert("folder1/folder1.2/folder1.2.1/TESTFILE1.2.1.1");
fakeFolder.remoteModifier().insert("folder1/folder1.2/folder1.2.1/TESTFILE1.2.1.2");
fakeFolder.remoteModifier().insert("folder1/folder1.2/folder1.2.1/TESTFILE1.2.1.3");
fakeFolder.remoteModifier().mkdir("folder1/folder1.2/folder1.2.2");
fakeFolder.remoteModifier().mkdir("folder1/folder1.2/folder1.2.2/test");
fakeFolder.remoteModifier().mkdir("folder1/folder1.2/folder1.2.2/test/folder1.2.2.1");
fakeFolder.remoteModifier().insert("folder1/folder1.2/folder1.2.2/test/folder1.2.2.1/TESTFILE1.2.2.1.1");
fakeFolder.remoteModifier().insert("folder1/folder1.2/folder1.2.2/test/folder1.2.2.1/TESTFILE1.2.2.1.2");
fakeFolder.remoteModifier().insert("folder1/folder1.2/folder1.2.2/test/folder1.2.2.1/TESTFILE1.2.2.1.3");
QVERIFY(fakeFolder.syncOnce());

fakeFolder.remoteModifier().rename("folder1/folder1.2/folder1.2.2/test/folder1.2.2.1", "folder1/folder1.2/folder1.2.2/folder1.2.2.1");
fakeFolder.remoteModifier().remove("folder1/folder1.2/folder1.2.2/test");
fakeFolder.remoteModifier().rename("folder1/folder1.2/folder1.2.2", "folder1/folder1.2/new name folder1.2.2");
fakeFolder.remoteModifier().rename("folder1/new name folder1.2", "folder1/new name folder1.2");
fakeFolder.remoteModifier().rename("folder1", "new name folder");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}
};

QTEST_GUILESS_MAIN(TestSyncCfApi)
Expand Down
54 changes: 54 additions & 0 deletions test/testsyncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,60 @@ private slots:
QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/abcdęfg.txt"));
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}

void testRemoteTypeChangeExistingLocalMustGetRemoved()
{
FakeFolder fakeFolder{FileInfo{}};

// test file change to directory on remote
fakeFolder.remoteModifier().mkdir("a");
fakeFolder.remoteModifier().insert("a/TESTFILE");
QVERIFY(fakeFolder.syncOnce());

fakeFolder.remoteModifier().remove("a/TESTFILE");
fakeFolder.remoteModifier().mkdir("a/TESTFILE");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

// test directory change to file on remote
fakeFolder.remoteModifier().mkdir("a/TESTDIR");
QVERIFY(fakeFolder.syncOnce());

fakeFolder.remoteModifier().remove("a/TESTDIR");
fakeFolder.remoteModifier().insert("a/TESTDIR");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}

void testRecursiveRename()
{
FakeFolder fakeFolder{FileInfo{}};

// test file change to directory on remote
fakeFolder.remoteModifier().mkdir("folder1");
fakeFolder.remoteModifier().mkdir("folder1/folder1.1");
fakeFolder.remoteModifier().insert("folder1/folder1.1/TESTFILE1.1.1");
fakeFolder.remoteModifier().mkdir("folder1/folder1.2");
fakeFolder.remoteModifier().mkdir("folder1/folder1.2/folder1.2.1");
fakeFolder.remoteModifier().insert("folder1/folder1.2/folder1.2.1/TESTFILE1.2.1.1");
fakeFolder.remoteModifier().insert("folder1/folder1.2/folder1.2.1/TESTFILE1.2.1.2");
fakeFolder.remoteModifier().insert("folder1/folder1.2/folder1.2.1/TESTFILE1.2.1.3");
fakeFolder.remoteModifier().mkdir("folder1/folder1.2/folder1.2.2");
fakeFolder.remoteModifier().mkdir("folder1/folder1.2/folder1.2.2/test");
fakeFolder.remoteModifier().mkdir("folder1/folder1.2/folder1.2.2/test/folder1.2.2.1");
fakeFolder.remoteModifier().insert("folder1/folder1.2/folder1.2.2/test/folder1.2.2.1/TESTFILE1.2.2.1.1");
fakeFolder.remoteModifier().insert("folder1/folder1.2/folder1.2.2/test/folder1.2.2.1/TESTFILE1.2.2.1.2");
fakeFolder.remoteModifier().insert("folder1/folder1.2/folder1.2.2/test/folder1.2.2.1/TESTFILE1.2.2.1.3");
QVERIFY(fakeFolder.syncOnce());

fakeFolder.remoteModifier().rename("folder1/folder1.2/folder1.2.2/test/folder1.2.2.1", "folder1/folder1.2/folder1.2.2/folder1.2.2.1");
fakeFolder.remoteModifier().remove("folder1/folder1.2/folder1.2.2/test");
fakeFolder.remoteModifier().rename("folder1/folder1.2/folder1.2.2", "folder1/folder1.2/new name folder1.2.2");
fakeFolder.remoteModifier().rename("folder1/new name folder1.2", "folder1/new name folder1.2");
fakeFolder.remoteModifier().rename("folder1", "new name folder");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}
};

QTEST_GUILESS_MAIN(TestSyncEngine)
Expand Down

0 comments on commit 8f7aa24

Please sign in to comment.