Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Verbruggen <erik@verbruggen.consulting>2022-10-26 19:22:42 +0300
committerErik Verbruggen <erik@verbruggen.consulting>2022-11-10 20:24:44 +0300
commitd9926fbf7817edb7d49ca97acd02a118a5b53812 (patch)
tree58c0367ea9c6b5fed10eea12a8cf894f60132724
parent726b247f72f9a4b53c7d9e31e605f59f7dbd9ad5 (diff)
Fix tests to run with winvfs/cfapiwork/fix-tests-with-winvfs
-rw-r--r--test/testsyncconflict.cpp24
-rw-r--r--test/testsyncengine.cpp76
-rw-r--r--test/testsyncmove.cpp11
-rw-r--r--test/testutils/syncenginetestutils.cpp10
4 files changed, 89 insertions, 32 deletions
diff --git a/test/testsyncconflict.cpp b/test/testsyncconflict.cpp
index 8f56f637d..7c41af1af 100644
--- a/test/testsyncconflict.cpp
+++ b/test/testsyncconflict.cpp
@@ -306,12 +306,19 @@ private slots:
fakeFolder.remoteModifier().insert(QStringLiteral("A/really-a-conflict")); // doesn't look like a conflict, but headers say it is
QVERIFY(fakeFolder.applyLocalModificationsAndSync());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
+
conflictRecord = fakeFolder.syncJournal().conflictRecord("A/really-a-conflict");
- QVERIFY(conflictRecord.isValid());
- QCOMPARE(conflictRecord.baseFileId, a2FileId);
- QCOMPARE(conflictRecord.baseModtime, 1234);
- QCOMPARE(conflictRecord.baseEtag, QByteArray("etag"));
- QCOMPARE(conflictRecord.initialBasePath, QByteArray("A/original"));
+
+ if (filesAreDehydrated) {
+ // A placeholder for the conflicting file is created, but no actual GET request is made, so there should be no conflict record
+ QVERIFY(!conflictRecord.isValid());
+ } else {
+ QVERIFY(conflictRecord.isValid());
+ QCOMPARE(conflictRecord.baseFileId, a2FileId);
+ QCOMPARE(conflictRecord.baseModtime, 1234);
+ QCOMPARE(conflictRecord.baseEtag, QByteArray("etag"));
+ QCOMPARE(conflictRecord.initialBasePath, QByteArray("A/original"));
+ }
}
// Check that conflict records are removed when the file is gone
@@ -649,6 +656,10 @@ private slots:
QFETCH_GLOBAL(Vfs::Mode, vfsMode);
QFETCH_GLOBAL(bool, filesAreDehydrated);
+ if (filesAreDehydrated) {
+ QSKIP("Known bug: https://github.com/owncloud/client/issues/10223");
+ }
+
FakeFolder fakeFolder(FileInfo::A12_B12_C12_S12(), vfsMode, filesAreDehydrated);
ItemCompletedSpy completeSpy(fakeFolder);
@@ -678,8 +689,9 @@ private slots:
const auto &conflicts = findConflicts(fakeFolder.currentLocalState());
QVERIFY(conflicts.size() == 1);
QVERIFY(conflicts[0].contains("A (conflicted copy"));
- for (const auto &conflict : conflicts)
+ for (const auto &conflict : conflicts) {
QDir(fakeFolder.localPath() + conflict).removeRecursively();
+ }
QVERIFY(fakeFolder.syncEngine().isAnotherSyncNeeded() == ImmediateFollowUp);
QVERIFY(fakeFolder.applyLocalModificationsAndSync());
diff --git a/test/testsyncengine.cpp b/test/testsyncengine.cpp
index 14aa89b19..f2ffdbee1 100644
--- a/test/testsyncengine.cpp
+++ b/test/testsyncengine.cpp
@@ -275,9 +275,12 @@ private slots:
QCOMPARE(finishedSpy.first().first().toBool(), false);
}
- /** Verify that an incompletely propagated directory doesn't have the server's
- * etag stored in the database yet. */
- void testDirEtagAfterIncompleteSync() {
+ /**
+ * Verify that an incompletely propagated directory doesn't have the server's
+ * etag stored in the database yet.
+ */
+ void testDirEtagAfterIncompleteSync()
+ {
QFETCH_GLOBAL(Vfs::Mode, vfsMode);
QFETCH_GLOBAL(bool, filesAreDehydrated);
@@ -286,12 +289,23 @@ private slots:
fakeFolder.serverErrorPaths().append(QStringLiteral("NewFolder/foo"));
fakeFolder.remoteModifier().mkdir(QStringLiteral("NewFolder"));
fakeFolder.remoteModifier().insert(QStringLiteral("NewFolder/foo"));
- QVERIFY(!fakeFolder.applyLocalModificationsAndSync());
+ bool syncSuccess = fakeFolder.applyLocalModificationsAndSync();
+ if (filesAreDehydrated) {
+ QVERIFY(syncSuccess);
+ } else {
+ QVERIFY(!syncSuccess);
+ }
SyncJournalFileRecord rec;
fakeFolder.syncJournal().getFileRecord(QByteArrayLiteral("NewFolder"), &rec);
QVERIFY(rec.isValid());
- QCOMPARE(rec._etag, QByteArrayLiteral("_invalid_"));
+ if (filesAreDehydrated) {
+ // No error, failure occurs only with a GET, so etag should be valid (i.e. NOT invalid):
+ QVERIFY(rec._etag != QByteArrayLiteral("_invalid_"));
+ } else {
+ // Download failed, check for invalid etag:
+ QCOMPARE(rec._etag, QByteArrayLiteral("_invalid_"));
+ }
QVERIFY(!rec._fileId.isEmpty());
}
@@ -299,6 +313,10 @@ private slots:
QFETCH_GLOBAL(Vfs::Mode, vfsMode);
QFETCH_GLOBAL(bool, filesAreDehydrated);
+ if (filesAreDehydrated) {
+ QSKIP("Nothing gets downloaded, so no error, so skip this test");
+ }
+
FakeFolder fakeFolder(FileInfo::A12_B12_C12_S12(), vfsMode, filesAreDehydrated);
ItemCompletedSpy completeSpy(fakeFolder);
fakeFolder.remoteModifier().mkdir(QStringLiteral("Y"));
@@ -338,41 +356,48 @@ private slots:
{
QTest::addColumn<bool>("sameMtime");
QTest::addColumn<QByteArray>("checksums");
-
- QTest::addColumn<int>("expectedGET");
+ QTest::addColumn<int>("expectedGEThydrated");
+ QTest::addColumn<int>("expectedGETdehydrated");
QTest::newRow("Same mtime, but no server checksum -> ignored in reconcile")
<< true << QByteArray()
- << 0;
+ << 0 // hydrated
+ << 1; // dehydrated
QTest::newRow("Same mtime, weak server checksum differ -> downloaded")
<< true << QByteArray("Adler32:bad")
- << 1;
+ << 1 // hydrated
+ << 1; // dehydrated;
QTest::newRow("Same mtime, matching weak checksum -> skipped")
<< true << QByteArray("Adler32:2a2010d")
- << 0;
+ << 0 // hydrated
+ << 1; // dehydrated;
QTest::newRow("Same mtime, strong server checksum differ -> downloaded")
<< true << QByteArray("SHA1:bad")
- << 1;
+ << 1 // hydrated
+ << 1; // dehydrated;
QTest::newRow("Same mtime, matching strong checksum -> skipped")
<< true << QByteArray("SHA1:56900fb1d337cf7237ff766276b9c1e8ce507427")
- << 0;
-
+ << 0 // hydrated
+ << 1; // dehydrated;
QTest::newRow("mtime changed, but no server checksum -> download")
<< false << QByteArray()
- << 1;
+ << 1 // hydrated
+ << 1; // dehydrated;
QTest::newRow("mtime changed, weak checksum match -> download anyway")
<< false << QByteArray("Adler32:2a2010d")
- << 1;
+ << 1 // hydrated
+ << 1; // dehydrated;
QTest::newRow("mtime changed, strong checksum match -> skip")
<< false << QByteArray("SHA1:56900fb1d337cf7237ff766276b9c1e8ce507427")
- << 0;
+ << 0 // hydrated
+ << 1; // dehydrated;
}
void testFakeConflict()
@@ -381,7 +406,10 @@ private slots:
QFETCH_GLOBAL(bool, filesAreDehydrated);
QFETCH(bool, sameMtime);
QFETCH(QByteArray, checksums);
- QFETCH(int, expectedGET);
+ QFETCH(int, expectedGEThydrated);
+ QFETCH(int, expectedGETdehydrated);
+
+ int expectedGET = filesAreDehydrated ? expectedGETdehydrated : expectedGEThydrated;
FakeFolder fakeFolder(FileInfo::A12_B12_C12_S12(), vfsMode, filesAreDehydrated);
OperationCounter counter(fakeFolder);
@@ -393,8 +421,11 @@ private slots:
auto mtime = QDateTime::currentDateTimeUtc().addDays(-4);
mtime.setMSecsSinceEpoch(mtime.toMSecsSinceEpoch() / 1000 * 1000);
- const auto a1size = fakeFolder.currentLocalState().find("A/a1")->contentSize;
+ const auto a1size = fakeFolder.currentRemoteState().find("A/a1")->contentSize;
+
+ // In the dehydrated case, executing this `setContents` will cause a hydration of the file, so there will always be 1 GET request.
fakeFolder.localModifier().setContents(QStringLiteral("A/a1"), a1size, 'C');
+
fakeFolder.localModifier().setModTime(QStringLiteral("A/a1"), mtime);
fakeFolder.remoteModifier().setContents(QStringLiteral("A/a1"), a1size, 'C');
if (!sameMtime) {
@@ -585,7 +616,14 @@ private slots:
// Bad OC-Checksum
checksumValue = "SHA1:bad";
fakeFolder.remoteModifier().create(QStringLiteral("A/a4"), 16, 'A');
- QVERIFY(!fakeFolder.applyLocalModificationsAndSync());
+ const bool syncSucceeded = fakeFolder.applyLocalModificationsAndSync();
+ if (filesAreDehydrated) {
+ // In the dehydrated case, files are never downloaded, so checksums are not computed. Only placeholders are created.
+ QVERIFY(syncSucceeded);
+ } else {
+ // Any case where files are actually downloaded (no vfs, local files are hydrated, etc), the checksum calculation should fail.
+ QVERIFY(!syncSucceeded);
+ }
// Good OC-Checksum
checksumValue = "SHA1:19b1928d58a2030d08023f3d7054516dbc186f20"; // printf 'A%.0s' {1..16} | sha1sum -
diff --git a/test/testsyncmove.cpp b/test/testsyncmove.cpp
index 47e888cdd..243d11bfa 100644
--- a/test/testsyncmove.cpp
+++ b/test/testsyncmove.cpp
@@ -226,13 +226,14 @@ private slots:
if (vfsMode == Vfs::Off) {
QCOMPARE(counter.nGET, 0); // b2m is detected as a *new* file, so we don't need to fetch the contents
QCOMPARE(counter.nMOVE, 0); // content differs, so not a move
+ QCOMPARE(counter.nPUT, 1); // upload b2m
+ QCOMPARE(counter.nDELETE, 1); // delete b2
} else {
- // with winvfs, we don't implement the CF_CALLBACK_TYPE_NOTIFY_RENAME callback, so:
- QCOMPARE(counter.nGET, 1); // callback to get the metadata/contents of b2m
- QCOMPARE(counter.nMOVE, 0); // no callback, contents differ, so not a move
+ QCOMPARE(counter.nGET, 1); // callback to get the (newly modified!) metadata/contents of b2m
+ QCOMPARE(counter.nMOVE, 1); // contents are the same, so it's a move
+ QCOMPARE(counter.nPUT, 0); // we detected a move, so no upload, and ...
+ QCOMPARE(counter.nDELETE, 0); // ... no delete
}
- QCOMPARE(counter.nPUT, 1); // upload b2m
- QCOMPARE(counter.nDELETE, 1); // delete b2
counter.reset();
// WinVFS handles this just fine.
diff --git a/test/testutils/syncenginetestutils.cpp b/test/testutils/syncenginetestutils.cpp
index c7e65ed82..ff8661ba3 100644
--- a/test/testutils/syncenginetestutils.cpp
+++ b/test/testutils/syncenginetestutils.cpp
@@ -1091,6 +1091,11 @@ void FakeFolder::fromDisk(QDir &dir, FileInfo &templateFi)
{
const auto infoList = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
for (const auto &diskChild : infoList) {
+ if (diskChild.isHidden() || diskChild.fileName().startsWith(QStringLiteral(".sync_"))) {
+ // Skip system files, sqlite db files, sync log, etc.
+ continue;
+ }
+
if (diskChild.isDir()) {
QDir subDir = dir;
subDir.cd(diskChild.fileName());
@@ -1112,9 +1117,10 @@ void FakeFolder::fromDisk(QDir &dir, FileInfo &templateFi)
auto content = f.read(1);
if (content.size() == 0) {
qWarning() << "Empty file at:" << diskChild.filePath();
- continue;
+ fi.contentChar = FileInfo::DefaultContentChar;
+ } else {
+ fi.contentChar = content.at(0);
}
- fi.contentChar = content.at(0);
fi.contentSize = fi.fileSize;
}