mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-25 06:25:56 +03:00
Tests: introduce ItemCompletedSpy to avoid a bit of code duplication
This commit is contained in:
parent
adbd3d869b
commit
390af4d41b
8 changed files with 98 additions and 153 deletions
|
@ -1181,6 +1181,21 @@ inline const FileInfo *findConflict(FileInfo &dir, const QString &filename)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
struct ItemCompletedSpy : QSignalSpy {
|
||||
explicit ItemCompletedSpy(FakeFolder &folder)
|
||||
: QSignalSpy(&folder.syncEngine(), &OCC::SyncEngine::itemCompleted)
|
||||
{}
|
||||
|
||||
OCC::SyncFileItemPtr findItem(const QString &path) const
|
||||
{
|
||||
for (const QList<QVariant> &args : *this) {
|
||||
auto item = args[0].value<OCC::SyncFileItemPtr>();
|
||||
if (item->destination() == path)
|
||||
return item;
|
||||
}
|
||||
return OCC::SyncFileItemPtr::create();
|
||||
}
|
||||
};
|
||||
|
||||
// QTest::toString overloads
|
||||
namespace OCC {
|
||||
|
|
|
@ -11,16 +11,6 @@
|
|||
|
||||
using namespace OCC;
|
||||
|
||||
SyncFileItemPtr findItem(const QSignalSpy &spy, const QString &path)
|
||||
{
|
||||
for (const QList<QVariant> &args : spy) {
|
||||
auto item = args[0].value<SyncFileItemPtr>();
|
||||
if (item->destination() == path)
|
||||
return item;
|
||||
}
|
||||
return SyncFileItemPtr(new SyncFileItem);
|
||||
}
|
||||
|
||||
SyncJournalFileRecord journalRecord(FakeFolder &folder, const QByteArray &path)
|
||||
{
|
||||
SyncJournalFileRecord rec;
|
||||
|
@ -46,7 +36,7 @@ private slots:
|
|||
|
||||
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
|
||||
auto &modifier = remote ? fakeFolder.remoteModifier() : fakeFolder.localModifier();
|
||||
|
||||
|
@ -73,7 +63,7 @@ private slots:
|
|||
fakeFolder.serverErrorPaths().append("A/new", 500); // will be blacklisted
|
||||
QVERIFY(!fakeFolder.syncOnce());
|
||||
{
|
||||
auto it = findItem(completeSpy, "A/new");
|
||||
auto it = completeSpy.findItem("A/new");
|
||||
QVERIFY(it);
|
||||
QCOMPARE(it->_status, SyncFileItem::NormalError); // initial error visible
|
||||
QCOMPARE(it->_instruction, CSYNC_INSTRUCTION_NEW);
|
||||
|
@ -94,7 +84,7 @@ private slots:
|
|||
// Ignored during the second run - but soft errors are also errors
|
||||
QVERIFY(!fakeFolder.syncOnce());
|
||||
{
|
||||
auto it = findItem(completeSpy, "A/new");
|
||||
auto it = completeSpy.findItem("A/new");
|
||||
QVERIFY(it);
|
||||
QCOMPARE(it->_status, SyncFileItem::BlacklistedError);
|
||||
QCOMPARE(it->_instruction, CSYNC_INSTRUCTION_IGNORE); // no retry happened!
|
||||
|
@ -121,7 +111,7 @@ private slots:
|
|||
}
|
||||
QVERIFY(!fakeFolder.syncOnce());
|
||||
{
|
||||
auto it = findItem(completeSpy, "A/new");
|
||||
auto it = completeSpy.findItem("A/new");
|
||||
QVERIFY(it);
|
||||
QCOMPARE(it->_status, SyncFileItem::BlacklistedError); // blacklisted as it's just a retry
|
||||
QCOMPARE(it->_instruction, CSYNC_INSTRUCTION_NEW); // retry!
|
||||
|
@ -143,7 +133,7 @@ private slots:
|
|||
modifier.appendByte("A/new");
|
||||
QVERIFY(!fakeFolder.syncOnce());
|
||||
{
|
||||
auto it = findItem(completeSpy, "A/new");
|
||||
auto it = completeSpy.findItem("A/new");
|
||||
QVERIFY(it);
|
||||
QCOMPARE(it->_status, SyncFileItem::BlacklistedError);
|
||||
QCOMPARE(it->_instruction, CSYNC_INSTRUCTION_NEW); // retry!
|
||||
|
@ -171,7 +161,7 @@ private slots:
|
|||
}
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
{
|
||||
auto it = findItem(completeSpy, "A/new");
|
||||
auto it = completeSpy.findItem("A/new");
|
||||
QVERIFY(it);
|
||||
QCOMPARE(it->_status, SyncFileItem::Success);
|
||||
QCOMPARE(it->_instruction, CSYNC_INSTRUCTION_NEW);
|
||||
|
|
|
@ -41,16 +41,6 @@ static void assertCsyncJournalOk(SyncJournalDb &journal)
|
|||
#endif
|
||||
}
|
||||
|
||||
SyncFileItemPtr findItem(const QSignalSpy &spy, const QString &path)
|
||||
{
|
||||
for (const QList<QVariant> &args : spy) {
|
||||
auto item = args[0].value<SyncFileItemPtr>();
|
||||
if (item->destination() == path)
|
||||
return item;
|
||||
}
|
||||
return SyncFileItemPtr(new SyncFileItem);
|
||||
}
|
||||
|
||||
SyncFileItemPtr findDiscoveryItem(const SyncFileItemVector &spy, const QString &path)
|
||||
{
|
||||
for (const auto &item : spy) {
|
||||
|
@ -60,9 +50,9 @@ SyncFileItemPtr findDiscoveryItem(const SyncFileItemVector &spy, const QString &
|
|||
return SyncFileItemPtr(new SyncFileItem);
|
||||
}
|
||||
|
||||
bool itemInstruction(const QSignalSpy &spy, const QString &path, const csync_instructions_e instr)
|
||||
bool itemInstruction(const ItemCompletedSpy &spy, const QString &path, const csync_instructions_e instr)
|
||||
{
|
||||
auto item = findItem(spy, path);
|
||||
auto item = spy.findItem(path);
|
||||
return item->_instruction == instr;
|
||||
}
|
||||
|
||||
|
@ -418,7 +408,7 @@ private slots:
|
|||
// also hook into discovery!!
|
||||
SyncFileItemVector discovery;
|
||||
connect(&fakeFolder.syncEngine(), &SyncEngine::aboutToPropagate, this, [&discovery](auto v) { discovery = v; });
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
QVERIFY(!fakeFolder.syncOnce());
|
||||
|
||||
// if renaming doesn't work, just delete+create
|
||||
|
|
|
@ -12,16 +12,6 @@
|
|||
|
||||
using namespace OCC;
|
||||
|
||||
SyncFileItemPtr findItem(const QSignalSpy &spy, const QString &path)
|
||||
{
|
||||
for (const QList<QVariant> &args : spy) {
|
||||
auto item = args[0].value<SyncFileItemPtr>();
|
||||
if (item->destination() == path)
|
||||
return item;
|
||||
}
|
||||
return SyncFileItemPtr(new SyncFileItem);
|
||||
}
|
||||
|
||||
struct FakeBrokenXmlPropfindReply : FakePropfindReply {
|
||||
FakeBrokenXmlPropfindReply(FileInfo &remoteRootFileInfo, QNetworkAccessManager::Operation op,
|
||||
const QNetworkRequest &request, QObject *parent)
|
||||
|
@ -120,7 +110,7 @@ private slots:
|
|||
// So the test that test timeout finishes fast
|
||||
QScopedValueRollback<int> setHttpTimeout(AbstractNetworkJob::httpTimeout, errorKind == Timeout ? 1 : 10000);
|
||||
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
QSignalSpy errorSpy(&fakeFolder.syncEngine(), &SyncEngine::syncError);
|
||||
QCOMPARE(fakeFolder.syncOnce(), syncSucceeds);
|
||||
|
||||
|
@ -131,13 +121,13 @@ private slots:
|
|||
QCOMPARE(errorSpy.size(), 1);
|
||||
QCOMPARE(errorSpy[0][0].toString(), QString(fatalErrorPrefix + expectedErrorString));
|
||||
} else {
|
||||
QCOMPARE(findItem(completeSpy, "B")->_instruction, CSYNC_INSTRUCTION_IGNORE);
|
||||
QVERIFY(findItem(completeSpy, "B")->_errorString.contains(expectedErrorString));
|
||||
QCOMPARE(completeSpy.findItem("B")->_instruction, CSYNC_INSTRUCTION_IGNORE);
|
||||
QVERIFY(completeSpy.findItem("B")->_errorString.contains(expectedErrorString));
|
||||
|
||||
// The other folder should have been sync'ed as the sync just ignored the faulty dir
|
||||
QCOMPARE(fakeFolder.currentRemoteState().children["A"], fakeFolder.currentLocalState().children["A"]);
|
||||
QCOMPARE(fakeFolder.currentRemoteState().children["C"], fakeFolder.currentLocalState().children["C"]);
|
||||
QCOMPARE(findItem(completeSpy, "A/z1")->_instruction, CSYNC_INSTRUCTION_NEW);
|
||||
QCOMPARE(completeSpy.findItem("A/z1")->_instruction, CSYNC_INSTRUCTION_NEW);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -169,17 +159,17 @@ private slots:
|
|||
return nullptr;
|
||||
});
|
||||
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
QVERIFY(!fakeFolder.syncOnce());
|
||||
|
||||
QCOMPARE(findItem(completeSpy, "good")->_instruction, CSYNC_INSTRUCTION_NEW);
|
||||
QCOMPARE(findItem(completeSpy, "noetag")->_instruction, CSYNC_INSTRUCTION_ERROR);
|
||||
QCOMPARE(findItem(completeSpy, "nofileid")->_instruction, CSYNC_INSTRUCTION_ERROR);
|
||||
QCOMPARE(findItem(completeSpy, "nopermissions")->_instruction, CSYNC_INSTRUCTION_NEW);
|
||||
QCOMPARE(findItem(completeSpy, "nopermissions/A")->_instruction, CSYNC_INSTRUCTION_ERROR);
|
||||
QVERIFY(findItem(completeSpy, "noetag")->_errorString.contains("etag"));
|
||||
QVERIFY(findItem(completeSpy, "nofileid")->_errorString.contains("file id"));
|
||||
QVERIFY(findItem(completeSpy, "nopermissions/A")->_errorString.contains("permissions"));
|
||||
QCOMPARE(completeSpy.findItem("good")->_instruction, CSYNC_INSTRUCTION_NEW);
|
||||
QCOMPARE(completeSpy.findItem("noetag")->_instruction, CSYNC_INSTRUCTION_ERROR);
|
||||
QCOMPARE(completeSpy.findItem("nofileid")->_instruction, CSYNC_INSTRUCTION_ERROR);
|
||||
QCOMPARE(completeSpy.findItem("nopermissions")->_instruction, CSYNC_INSTRUCTION_NEW);
|
||||
QCOMPARE(completeSpy.findItem("nopermissions/A")->_instruction, CSYNC_INSTRUCTION_ERROR);
|
||||
QVERIFY(completeSpy.findItem("noetag")->_errorString.contains("etag"));
|
||||
QVERIFY(completeSpy.findItem("nofileid")->_errorString.contains("file id"));
|
||||
QVERIFY(completeSpy.findItem("nopermissions/A")->_errorString.contains("permissions"));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -11,29 +11,19 @@
|
|||
|
||||
using namespace OCC;
|
||||
|
||||
SyncFileItemPtr findItem(const QSignalSpy &spy, const QString &path)
|
||||
bool itemSuccessful(const ItemCompletedSpy &spy, const QString &path, const csync_instructions_e instr)
|
||||
{
|
||||
for (const QList<QVariant> &args : spy) {
|
||||
auto item = args[0].value<SyncFileItemPtr>();
|
||||
if (item->destination() == path)
|
||||
return item;
|
||||
}
|
||||
return SyncFileItemPtr(new SyncFileItem);
|
||||
}
|
||||
|
||||
bool itemSuccessful(const QSignalSpy &spy, const QString &path, const csync_instructions_e instr)
|
||||
{
|
||||
auto item = findItem(spy, path);
|
||||
auto item = spy.findItem(path);
|
||||
return item->_status == SyncFileItem::Success && item->_instruction == instr;
|
||||
}
|
||||
|
||||
bool itemConflict(const QSignalSpy &spy, const QString &path)
|
||||
bool itemConflict(const ItemCompletedSpy &spy, const QString &path)
|
||||
{
|
||||
auto item = findItem(spy, path);
|
||||
auto item = spy.findItem(path);
|
||||
return item->_status == SyncFileItem::Conflict && item->_instruction == CSYNC_INSTRUCTION_CONFLICT;
|
||||
}
|
||||
|
||||
bool itemSuccessfulMove(const QSignalSpy &spy, const QString &path)
|
||||
bool itemSuccessfulMove(const ItemCompletedSpy &spy, const QString &path)
|
||||
{
|
||||
return itemSuccessful(spy, path, CSYNC_INSTRUCTION_RENAME);
|
||||
}
|
||||
|
@ -410,7 +400,7 @@ private slots:
|
|||
{
|
||||
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
|
||||
fakeFolder.syncEngine().account()->setCapabilities({ { "uploadConflictFiles", true } });
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
|
||||
auto cleanup = [&]() {
|
||||
completeSpy.clear();
|
||||
|
@ -488,7 +478,7 @@ private slots:
|
|||
{
|
||||
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
|
||||
fakeFolder.syncEngine().account()->setCapabilities({ { "uploadConflictFiles", true } });
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
|
||||
// 1) a NEW/NEW conflict
|
||||
fakeFolder.remoteModifier().mkdir("Z");
|
||||
|
@ -539,7 +529,7 @@ private slots:
|
|||
void testTypeConflictWithMove()
|
||||
{
|
||||
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
|
||||
// the remote becomes a file, but a file inside the dir has moved away!
|
||||
fakeFolder.remoteModifier().remove("A");
|
||||
|
@ -572,7 +562,7 @@ private slots:
|
|||
void testTypeChange()
|
||||
{
|
||||
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
|
||||
// dir becomes file
|
||||
fakeFolder.remoteModifier().remove("A");
|
||||
|
|
|
@ -11,33 +11,23 @@
|
|||
|
||||
using namespace OCC;
|
||||
|
||||
SyncFileItemPtr findItem(const QSignalSpy &spy, const QString &path)
|
||||
bool itemDidComplete(const ItemCompletedSpy &spy, const QString &path)
|
||||
{
|
||||
for (const QList<QVariant> &args : spy) {
|
||||
auto item = args[0].value<SyncFileItemPtr>();
|
||||
if (item->destination() == path)
|
||||
return item;
|
||||
}
|
||||
return SyncFileItemPtr(new SyncFileItem);
|
||||
}
|
||||
|
||||
bool itemDidComplete(const QSignalSpy &spy, const QString &path)
|
||||
{
|
||||
if (auto item = findItem(spy, path)) {
|
||||
if (auto item = spy.findItem(path)) {
|
||||
return item->_instruction != CSYNC_INSTRUCTION_NONE && item->_instruction != CSYNC_INSTRUCTION_UPDATE_METADATA;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool itemInstruction(const QSignalSpy &spy, const QString &path, const csync_instructions_e instr)
|
||||
bool itemInstruction(const ItemCompletedSpy &spy, const QString &path, const csync_instructions_e instr)
|
||||
{
|
||||
auto item = findItem(spy, path);
|
||||
auto item = spy.findItem(path);
|
||||
return item->_instruction == instr;
|
||||
}
|
||||
|
||||
bool itemDidCompleteSuccessfully(const QSignalSpy &spy, const QString &path)
|
||||
bool itemDidCompleteSuccessfully(const ItemCompletedSpy &spy, const QString &path)
|
||||
{
|
||||
if (auto item = findItem(spy, path)) {
|
||||
if (auto item = spy.findItem(path)) {
|
||||
return item->_status == SyncFileItem::Success;
|
||||
}
|
||||
return false;
|
||||
|
@ -50,7 +40,7 @@ class TestSyncEngine : public QObject
|
|||
private slots:
|
||||
void testFileDownload() {
|
||||
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
fakeFolder.remoteModifier().insert("A/a0");
|
||||
fakeFolder.syncOnce();
|
||||
QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/a0"));
|
||||
|
@ -59,7 +49,7 @@ private slots:
|
|||
|
||||
void testFileUpload() {
|
||||
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
fakeFolder.localModifier().insert("A/a0");
|
||||
fakeFolder.syncOnce();
|
||||
QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/a0"));
|
||||
|
@ -68,7 +58,7 @@ private slots:
|
|||
|
||||
void testDirDownload() {
|
||||
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
fakeFolder.remoteModifier().mkdir("Y");
|
||||
fakeFolder.remoteModifier().mkdir("Z");
|
||||
fakeFolder.remoteModifier().insert("Z/d0");
|
||||
|
@ -81,7 +71,7 @@ private slots:
|
|||
|
||||
void testDirUpload() {
|
||||
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
fakeFolder.localModifier().mkdir("Y");
|
||||
fakeFolder.localModifier().mkdir("Z");
|
||||
fakeFolder.localModifier().insert("Z/d0");
|
||||
|
@ -94,7 +84,7 @@ private slots:
|
|||
|
||||
void testLocalDelete() {
|
||||
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
fakeFolder.remoteModifier().remove("A/a1");
|
||||
fakeFolder.syncOnce();
|
||||
QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/a1"));
|
||||
|
@ -103,7 +93,7 @@ private slots:
|
|||
|
||||
void testRemoteDelete() {
|
||||
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
fakeFolder.localModifier().remove("A/a1");
|
||||
fakeFolder.syncOnce();
|
||||
QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/a1"));
|
||||
|
@ -133,7 +123,7 @@ private slots:
|
|||
QCOMPARE(getDbChecksum("a3.eml"), referenceChecksum);
|
||||
QCOMPARE(getDbChecksum("b3.txt"), referenceChecksum);
|
||||
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
// Touch the file without changing the content, shouldn't upload
|
||||
fakeFolder.localModifier().setContents("a1.eml", 'A');
|
||||
// Change the content/size
|
||||
|
@ -255,7 +245,7 @@ private slots:
|
|||
|
||||
void testDirDownloadWithError() {
|
||||
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
fakeFolder.remoteModifier().mkdir("Y");
|
||||
fakeFolder.remoteModifier().mkdir("Y/Z");
|
||||
fakeFolder.remoteModifier().insert("Y/Z/d0");
|
||||
|
|
|
@ -35,29 +35,19 @@ struct OperationCounter {
|
|||
}
|
||||
};
|
||||
|
||||
SyncFileItemPtr findItem(const QSignalSpy &spy, const QString &path)
|
||||
bool itemSuccessful(const ItemCompletedSpy &spy, const QString &path, const csync_instructions_e instr)
|
||||
{
|
||||
for (const QList<QVariant> &args : spy) {
|
||||
auto item = args[0].value<SyncFileItemPtr>();
|
||||
if (item->destination() == path)
|
||||
return item;
|
||||
}
|
||||
return SyncFileItemPtr(new SyncFileItem);
|
||||
}
|
||||
|
||||
bool itemSuccessful(const QSignalSpy &spy, const QString &path, const csync_instructions_e instr)
|
||||
{
|
||||
auto item = findItem(spy, path);
|
||||
auto item = spy.findItem(path);
|
||||
return item->_status == SyncFileItem::Success && item->_instruction == instr;
|
||||
}
|
||||
|
||||
bool itemConflict(const QSignalSpy &spy, const QString &path)
|
||||
bool itemConflict(const ItemCompletedSpy &spy, const QString &path)
|
||||
{
|
||||
auto item = findItem(spy, path);
|
||||
auto item = spy.findItem(path);
|
||||
return item->_status == SyncFileItem::Conflict && item->_instruction == CSYNC_INSTRUCTION_CONFLICT;
|
||||
}
|
||||
|
||||
bool itemSuccessfulMove(const QSignalSpy &spy, const QString &path)
|
||||
bool itemSuccessfulMove(const ItemCompletedSpy &spy, const QString &path)
|
||||
{
|
||||
return itemSuccessful(spy, path, CSYNC_INSTRUCTION_RENAME);
|
||||
}
|
||||
|
@ -167,7 +157,7 @@ private slots:
|
|||
QCOMPARE(fakeFolder.currentLocalState(), remoteState);
|
||||
|
||||
expectedServerState = fakeFolder.currentRemoteState();
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
fakeFolder.syncOnce(); // This sync should do nothing
|
||||
QCOMPARE(completeSpy.count(), 0);
|
||||
|
||||
|
@ -347,7 +337,7 @@ private slots:
|
|||
counter.reset();
|
||||
local.rename("A/a1", "A/a1m");
|
||||
remote.rename("B/b1", "B/b1m");
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
QCOMPARE(counter.nGET, 0);
|
||||
|
@ -356,10 +346,10 @@ private slots:
|
|||
QCOMPARE(counter.nDELETE, 0);
|
||||
QVERIFY(itemSuccessfulMove(completeSpy, "A/a1m"));
|
||||
QVERIFY(itemSuccessfulMove(completeSpy, "B/b1m"));
|
||||
QCOMPARE(findItem(completeSpy, "A/a1m")->_file, QStringLiteral("A/a1"));
|
||||
QCOMPARE(findItem(completeSpy, "A/a1m")->_renameTarget, QStringLiteral("A/a1m"));
|
||||
QCOMPARE(findItem(completeSpy, "B/b1m")->_file, QStringLiteral("B/b1"));
|
||||
QCOMPARE(findItem(completeSpy, "B/b1m")->_renameTarget, QStringLiteral("B/b1m"));
|
||||
QCOMPARE(completeSpy.findItem("A/a1m")->_file, QStringLiteral("A/a1"));
|
||||
QCOMPARE(completeSpy.findItem("A/a1m")->_renameTarget, QStringLiteral("A/a1m"));
|
||||
QCOMPARE(completeSpy.findItem("B/b1m")->_file, QStringLiteral("B/b1"));
|
||||
QCOMPARE(completeSpy.findItem("B/b1m")->_renameTarget, QStringLiteral("B/b1m"));
|
||||
}
|
||||
|
||||
// Touch+Move on same side
|
||||
|
@ -409,7 +399,7 @@ private slots:
|
|||
remote.appendByte("B/b1m");
|
||||
remote.insert("B/b1mt");
|
||||
local.rename("B/b1m", "B/b1mt");
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
QVERIFY(expectAndWipeConflict(local, fakeFolder.currentLocalState(), "A/a1mt"));
|
||||
QVERIFY(expectAndWipeConflict(local, fakeFolder.currentLocalState(), "B/b1mt"));
|
||||
|
@ -432,7 +422,7 @@ private slots:
|
|||
remote.rename("A/a1mt", "A/a1N");
|
||||
remote.insert("B/b1N", 13);
|
||||
local.rename("B/b1mt", "B/b1N");
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
QVERIFY(expectAndWipeConflict(local, fakeFolder.currentLocalState(), "A/a1N"));
|
||||
QVERIFY(expectAndWipeConflict(local, fakeFolder.currentLocalState(), "B/b1N"));
|
||||
|
@ -479,7 +469,7 @@ private slots:
|
|||
counter.reset();
|
||||
local.rename("A", "AM");
|
||||
remote.rename("B", "BM");
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
QCOMPARE(printDbData(fakeFolder.dbState()), printDbData(fakeFolder.currentRemoteState()));
|
||||
|
@ -489,10 +479,10 @@ private slots:
|
|||
QCOMPARE(counter.nDELETE, 0);
|
||||
QVERIFY(itemSuccessfulMove(completeSpy, "AM"));
|
||||
QVERIFY(itemSuccessfulMove(completeSpy, "BM"));
|
||||
QCOMPARE(findItem(completeSpy, "AM")->_file, QStringLiteral("A"));
|
||||
QCOMPARE(findItem(completeSpy, "AM")->_renameTarget, QStringLiteral("AM"));
|
||||
QCOMPARE(findItem(completeSpy, "BM")->_file, QStringLiteral("B"));
|
||||
QCOMPARE(findItem(completeSpy, "BM")->_renameTarget, QStringLiteral("BM"));
|
||||
QCOMPARE(completeSpy.findItem("AM")->_file, QStringLiteral("A"));
|
||||
QCOMPARE(completeSpy.findItem("AM")->_renameTarget, QStringLiteral("AM"));
|
||||
QCOMPARE(completeSpy.findItem("BM")->_file, QStringLiteral("B"));
|
||||
QCOMPARE(completeSpy.findItem("BM")->_renameTarget, QStringLiteral("BM"));
|
||||
}
|
||||
|
||||
// Folder move with contents touched on the same side
|
||||
|
@ -507,7 +497,7 @@ private slots:
|
|||
local.rename("AM", "A2");
|
||||
remote.setContents("BM/b2m", 'C');
|
||||
remote.rename("BM", "B2");
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
QCOMPARE(printDbData(fakeFolder.dbState()), printDbData(fakeFolder.currentRemoteState()));
|
||||
|
@ -630,7 +620,7 @@ private slots:
|
|||
remote.appendByte("B/b1");
|
||||
local.rename("B/b1", "B/b1mq");
|
||||
local.mkdir("B/b1");
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
// BUG: This doesn't behave right
|
||||
//QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
|
|
|
@ -15,19 +15,9 @@ using namespace OCC;
|
|||
|
||||
#define DVSUFFIX APPLICATION_DOTVIRTUALFILE_SUFFIX
|
||||
|
||||
SyncFileItemPtr findItem(const QSignalSpy &spy, const QString &path)
|
||||
bool itemInstruction(const ItemCompletedSpy &spy, const QString &path, const csync_instructions_e instr)
|
||||
{
|
||||
for (const QList<QVariant> &args : spy) {
|
||||
auto item = args[0].value<SyncFileItemPtr>();
|
||||
if (item->destination() == path)
|
||||
return item;
|
||||
}
|
||||
return SyncFileItemPtr(new SyncFileItem);
|
||||
}
|
||||
|
||||
bool itemInstruction(const QSignalSpy &spy, const QString &path, const csync_instructions_e instr)
|
||||
{
|
||||
auto item = findItem(spy, path);
|
||||
auto item = spy.findItem(path);
|
||||
return item->_instruction == instr;
|
||||
}
|
||||
|
||||
|
@ -94,7 +84,7 @@ private slots:
|
|||
FakeFolder fakeFolder{ FileInfo() };
|
||||
setupVfs(fakeFolder);
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
|
||||
auto cleanup = [&]() {
|
||||
completeSpy.clear();
|
||||
|
@ -215,7 +205,7 @@ private slots:
|
|||
FakeFolder fakeFolder{ FileInfo() };
|
||||
setupVfs(fakeFolder);
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
|
||||
auto cleanup = [&]() {
|
||||
completeSpy.clear();
|
||||
|
@ -286,7 +276,7 @@ private slots:
|
|||
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
|
||||
setupVfs(fakeFolder);
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
|
||||
auto cleanup = [&]() {
|
||||
completeSpy.clear();
|
||||
|
@ -322,7 +312,7 @@ private slots:
|
|||
FakeFolder fakeFolder{ FileInfo() };
|
||||
setupVfs(fakeFolder);
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
|
||||
auto cleanup = [&]() {
|
||||
completeSpy.clear();
|
||||
|
@ -384,10 +374,10 @@ private slots:
|
|||
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
QVERIFY(itemInstruction(completeSpy, "A/a1", CSYNC_INSTRUCTION_SYNC));
|
||||
QCOMPARE(findItem(completeSpy, "A/a1")->_type, ItemTypeVirtualFileDownload);
|
||||
QCOMPARE(completeSpy.findItem("A/a1")->_type, ItemTypeVirtualFileDownload);
|
||||
QVERIFY(itemInstruction(completeSpy, "A/a1" DVSUFFIX, CSYNC_INSTRUCTION_NONE));
|
||||
QVERIFY(itemInstruction(completeSpy, "A/a2", CSYNC_INSTRUCTION_SYNC));
|
||||
QCOMPARE(findItem(completeSpy, "A/a2")->_type, ItemTypeVirtualFileDownload);
|
||||
QCOMPARE(completeSpy.findItem("A/a2")->_type, ItemTypeVirtualFileDownload);
|
||||
QVERIFY(itemInstruction(completeSpy, "A/a2" DVSUFFIX, CSYNC_INSTRUCTION_NONE));
|
||||
QVERIFY(itemInstruction(completeSpy, "A/a3" DVSUFFIX, CSYNC_INSTRUCTION_REMOVE));
|
||||
QVERIFY(itemInstruction(completeSpy, "A/a4m", CSYNC_INSTRUCTION_NEW));
|
||||
|
@ -437,7 +427,7 @@ private slots:
|
|||
FakeFolder fakeFolder{ FileInfo() };
|
||||
setupVfs(fakeFolder);
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
|
||||
auto cleanup = [&]() {
|
||||
completeSpy.clear();
|
||||
|
@ -595,7 +585,7 @@ private slots:
|
|||
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
|
||||
setupVfs(fakeFolder);
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
|
||||
auto cleanup = [&]() {
|
||||
completeSpy.clear();
|
||||
|
@ -635,7 +625,7 @@ private slots:
|
|||
FakeFolder fakeFolder{ FileInfo() };
|
||||
setupVfs(fakeFolder);
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
|
||||
auto cleanup = [&]() {
|
||||
completeSpy.clear();
|
||||
|
@ -690,7 +680,7 @@ private slots:
|
|||
{
|
||||
FakeFolder fakeFolder{ FileInfo() };
|
||||
setupVfs(fakeFolder);
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
auto cleanup = [&]() {
|
||||
completeSpy.clear();
|
||||
};
|
||||
|
@ -781,7 +771,7 @@ private slots:
|
|||
QVERIFY(fakeFolder.syncOnce());
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
auto cleanup = [&]() {
|
||||
completeSpy.clear();
|
||||
};
|
||||
|
@ -832,13 +822,13 @@ private slots:
|
|||
QVERIFY(isDehydrated("A/a1"));
|
||||
QVERIFY(hasDehydratedDbEntries("A/a1"));
|
||||
QVERIFY(itemInstruction(completeSpy, "A/a1" DVSUFFIX, CSYNC_INSTRUCTION_SYNC));
|
||||
QCOMPARE(findItem(completeSpy, "A/a1" DVSUFFIX)->_type, ItemTypeVirtualFileDehydration);
|
||||
QCOMPARE(findItem(completeSpy, "A/a1" DVSUFFIX)->_file, QStringLiteral("A/a1"));
|
||||
QCOMPARE(findItem(completeSpy, "A/a1" DVSUFFIX)->_renameTarget, QStringLiteral("A/a1" DVSUFFIX));
|
||||
QCOMPARE(completeSpy.findItem("A/a1" DVSUFFIX)->_type, ItemTypeVirtualFileDehydration);
|
||||
QCOMPARE(completeSpy.findItem("A/a1" DVSUFFIX)->_file, QStringLiteral("A/a1"));
|
||||
QCOMPARE(completeSpy.findItem("A/a1" DVSUFFIX)->_renameTarget, QStringLiteral("A/a1" DVSUFFIX));
|
||||
QVERIFY(isDehydrated("A/a2"));
|
||||
QVERIFY(hasDehydratedDbEntries("A/a2"));
|
||||
QVERIFY(itemInstruction(completeSpy, "A/a2" DVSUFFIX, CSYNC_INSTRUCTION_SYNC));
|
||||
QCOMPARE(findItem(completeSpy, "A/a2" DVSUFFIX)->_type, ItemTypeVirtualFileDehydration);
|
||||
QCOMPARE(completeSpy.findItem("A/a2" DVSUFFIX)->_type, ItemTypeVirtualFileDehydration);
|
||||
|
||||
QVERIFY(!fakeFolder.currentLocalState().find("B/b1"));
|
||||
QVERIFY(!fakeFolder.currentRemoteState().find("B/b1"));
|
||||
|
@ -992,7 +982,7 @@ private slots:
|
|||
{
|
||||
FakeFolder fakeFolder{ FileInfo() };
|
||||
|
||||
QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
auto cleanup = [&]() {
|
||||
completeSpy.clear();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue