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
path: root/test
diff options
context:
space:
mode:
authorHannah von Reth <hannah.vonreth@owncloud.com>2020-07-14 15:19:22 +0300
committerHannah von Reth <vonreth@kde.org>2020-07-15 15:05:57 +0300
commitbcf9f3199d77fa28dc9ad76206449f1c5afaba69 (patch)
tree8aa054c6e05d0fd5aa5d7a2a80594421e18ccc7f /test
parentcbcaeb9c1a6445f641c80fa43384f474f941c48b (diff)
Remove dead code
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt1
-rw-r--r--test/syncenginetestutils.h122
-rw-r--r--test/testzsync.cpp371
3 files changed, 5 insertions, 489 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 993a23f08..f0d2bfe7d 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -22,7 +22,6 @@ owncloud_add_test(SyncConflict "syncenginetestutils.h")
owncloud_add_test(SyncFileStatusTracker "syncenginetestutils.h")
owncloud_add_test(Download "syncenginetestutils.h")
owncloud_add_test(ChunkingNg "syncenginetestutils.h")
-owncloud_add_test(Zsync "syncenginetestutils.h")
owncloud_add_test(AsyncOp "syncenginetestutils.h")
owncloud_add_test(UploadReset "syncenginetestutils.h")
owncloud_add_test(AllFilesDeleted "syncenginetestutils.h")
diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h
index 858660c95..724dbf830 100644
--- a/test/syncenginetestutils.h
+++ b/test/syncenginetestutils.h
@@ -406,7 +406,6 @@ public:
: fileInfo.isShared ? QStringLiteral("SRDNVCKW") : QStringLiteral("RDNVCKW"));
xml.writeTextElement(ocUri, QStringLiteral("id"), fileInfo.fileId);
xml.writeTextElement(ocUri, QStringLiteral("checksums"), fileInfo.checksums);
- xml.writeTextElement(ocUri, QStringLiteral("zsync"), QStringLiteral("true"));
buffer.write(fileInfo.extraDavProperties);
xml.writeEndElement(); // prop
xml.writeTextElement(davUri, QStringLiteral("status"), "HTTP/1.1 200 OK");
@@ -764,15 +763,10 @@ public:
static FileInfo *perform(FileInfo &uploadsFileInfo, FileInfo &remoteRootFileInfo, const QNetworkRequest &request)
{
QString source = getFilePathFromUrl(request.url());
- bool zsync = false;
Q_ASSERT(!source.isEmpty());
- Q_ASSERT(source.endsWith("/.file") || source.endsWith("/.file.zsync"));
- if (source.endsWith("/.file"))
- source = source.left(source.length() - qstrlen("/.file"));
- if (source.endsWith("/.file.zsync")) {
- source = source.left(source.length() - qstrlen("/.file.zsync"));
- zsync = true;
- }
+ Q_ASSERT(source.endsWith("/.file"));
+ source = source.left(source.length() - qstrlen("/.file"));
+
auto sourceFolder = uploadsFileInfo.find(source);
Q_ASSERT(sourceFolder);
Q_ASSERT(sourceFolder->isDir);
@@ -784,34 +778,21 @@ public:
QString fileName = getFilePathFromUrl(QUrl::fromEncoded(request.rawHeader("Destination")));
Q_ASSERT(!fileName.isEmpty());
- // Ignore .zsync metadata
- if (sourceFolder->children.contains(".zsync"))
- sourceFolder->children.remove(".zsync");
-
// Compute the size and content from the chunks if possible
for (auto chunkName : sourceFolder->children.keys()) {
auto &x = sourceFolder->children[chunkName];
- if (!zsync && chunkName.toLongLong() != prev)
+ if (chunkName.toLongLong() != prev)
break;
Q_ASSERT(!x.isDir);
Q_ASSERT(x.size > 0); // There should not be empty chunks
size += x.size;
- Q_ASSERT(!payload || payload == x.contentChar || !"For zsync all chunks must start with the same character");
+ Q_ASSERT(!payload || payload == x.contentChar);
payload = x.contentChar;
++count;
prev = chunkName.toLongLong() + x.size;
}
Q_ASSERT(sourceFolder->children.count() == count); // There should not be holes or extra files
- // For zsync, get the size from the header, and allow no-chunk uploads (shrinking files)
- if (zsync) {
- size = request.rawHeader("OC-Total-File-Length").toLongLong();
- if (count == 0) {
- if (auto info = remoteRootFileInfo.find(fileName))
- payload = info->contentChar;
- }
- }
-
// NOTE: This does not actually assemble the file data from the chunks!
FileInfo *fileInfo = remoteRootFileInfo.find(fileName);
if (fileInfo) {
@@ -864,99 +845,6 @@ public:
qint64 readData(char *, qint64) override { return 0; }
};
-class FakeChunkZsyncMoveReply : public QNetworkReply
-{
- Q_OBJECT
- FileInfo *fileInfo;
-
-public:
- FakeChunkZsyncMoveReply(FileInfo &uploadsFileInfo, FileInfo &remoteRootFileInfo,
- QNetworkAccessManager::Operation op, const QNetworkRequest &request,
- quint64 delayMs, QVector<quint64> &mods, QObject *parent)
- : QNetworkReply{ parent }
- {
- setRequest(request);
- setUrl(request.url());
- setOperation(op);
- open(QIODevice::ReadOnly);
-
- Q_ASSERT(!mods.isEmpty());
-
- QString source = getFilePathFromUrl(request.url());
- Q_ASSERT(!source.isEmpty());
- Q_ASSERT(source.endsWith("/.file.zsync"));
- source = source.left(source.length() - qstrlen("/.file.zsync"));
- auto sourceFolder = uploadsFileInfo.find(source);
- Q_ASSERT(sourceFolder);
- Q_ASSERT(sourceFolder->isDir);
- int count = 0;
-
- // Ignore .zsync metadata
- if (sourceFolder->children.contains(".zsync"))
- sourceFolder->children.remove(".zsync");
-
- for (auto chunkName : sourceFolder->children.keys()) {
- auto &x = sourceFolder->children[chunkName];
- Q_ASSERT(!x.isDir);
- Q_ASSERT(x.size > 0); // There should not be empty chunks
- quint64 start = quint64(chunkName.toLongLong());
- auto it = mods.begin();
- while (it != mods.end()) {
- if (*it >= start && *it < start + x.size) {
- ++count;
- mods.erase(it);
- } else
- ++it;
- }
- }
-
- Q_ASSERT(count > 0); // There should be at least one chunk
- Q_ASSERT(mods.isEmpty()); // All files should match a modification
-
- QString fileName = getFilePathFromUrl(QUrl::fromEncoded(request.rawHeader("Destination")));
- Q_ASSERT(!fileName.isEmpty());
-
- fileInfo = remoteRootFileInfo.find(fileName);
- Q_ASSERT(fileInfo);
- if (!fileInfo) {
- abort();
- return;
- }
-
- QVERIFY(request.hasRawHeader("If")); // The client should put this header
- if (request.rawHeader("If") != QByteArray("<" + request.rawHeader("Destination") + "> ([\"" + fileInfo->etag.toLatin1() + "\"])")) {
- QMetaObject::invokeMethod(this, "respondPreconditionFailed", Qt::QueuedConnection);
- return;
- }
-
- fileInfo->lastModified = OCC::Utility::qDateTimeFromTime_t(request.rawHeader("X-OC-Mtime").toLongLong());
- remoteRootFileInfo.find(fileName, /*invalidate_etags=*/true);
-
- QTimer::singleShot(delayMs, this, &FakeChunkZsyncMoveReply::respond);
- }
-
- Q_INVOKABLE void respond()
- {
- setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 201);
- setRawHeader("OC-ETag", fileInfo->etag.toLatin1());
- setRawHeader("ETag", fileInfo->etag.toLatin1());
- setRawHeader("OC-FileId", fileInfo->fileId);
- emit metaDataChanged();
- emit finished();
- }
-
- Q_INVOKABLE void respondPreconditionFailed()
- {
- setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 412);
- setError(InternalServerError, "Precondition Failed");
- emit metaDataChanged();
- emit finished();
- }
-
- void abort() override {}
- qint64 readData(char *, qint64) override { return 0; }
-};
-
class FakePayloadReply : public QNetworkReply
{
Q_OBJECT
diff --git a/test/testzsync.cpp b/test/testzsync.cpp
deleted file mode 100644
index 4aa2dbaed..000000000
--- a/test/testzsync.cpp
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * This software is in the public domain, furnished "as is", without technical
- * support, and with no warranty, express or implied, as to its usefulness for
- * any purpose.
- *
- */
-
-#include <QtTest>
-#include "syncenginetestutils.h"
-#include <syncengine.h>
-#include <propagatecommonzsync.h>
-
-using namespace OCC;
-
-QStringList findConflicts(const FileInfo &dir)
-{
- QStringList conflicts;
- for (const auto &item : dir.children) {
- if (item.name.contains("conflict")) {
- conflicts.append(item.path());
- }
- }
- return conflicts;
-}
-
-static quint64 blockstart_from_offset(quint64 offset)
-{
- return offset & ~quint64(ZSYNC_BLOCKSIZE - 1);
-}
-
-class TestZsync : public QObject
-{
- Q_OBJECT
-
-private slots:
-
- void testFileDownloadSimple()
- {
- FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
- fakeFolder.syncEngine().account()->setCapabilities({ { "dav", QVariantMap{ { "chunking", "1.0" }, { "zsync", "1.0" } } } });
-
- SyncOptions opt;
- opt._deltaSyncEnabled = true;
- opt._deltaSyncMinFileSize = 0;
- // Reduce the chunk size, allowing us to work with smaller data
- int chunkSize = 2 * 1000 * 1001;
- opt._minChunkSize = opt._maxChunkSize = opt._initialChunkSize = chunkSize;
- fakeFolder.syncEngine().setSyncOptions(opt);
-
- const int size = 100 * 1000 * 1000;
- QMap<QString, QByteArray> metadata;
-
- // Preparation, create files and upload them, capturing metadata
- // (because letting the client compute the metadata is easiest)
-
- fakeFolder.localModifier().insert("A/a0", size);
- fakeFolder.localModifier().appendByte("A/a0", 'X');
- qsrand(QDateTime::currentDateTime().toTime_t());
- const int nModifications = 10;
- for (int i = 0; i < nModifications; i++) {
- quint64 offset = qrand() % size;
- fakeFolder.localModifier().modifyByte("A/a0", offset, 'Y');
- }
-
- // Keep hold of original file contents for a0
- QFile f(fakeFolder.localPath() + "/A/a0");
- f.open(QIODevice::ReadOnly);
- QByteArray data = f.readAll();
- f.close();
-
- fakeFolder.localModifier().insert("A/threeBlocks", 3 * ZSYNC_BLOCKSIZE);
- fakeFolder.localModifier().insert("A/threeBlocksPlusOne", 3 * ZSYNC_BLOCKSIZE + 1);
- fakeFolder.localModifier().insert("A/threeBlocksMinusOne", 3 * ZSYNC_BLOCKSIZE - 1);
-
- // Capture the zsync metadata during upload for later use
- // This fills metadata by filename
- auto transactionId = [] (const QUrl &url) {
- auto components = url.path().split("/");
- return components[components.size() - 2];
- };
- fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *data) -> QNetworkReply * {
- if (op == QNetworkAccessManager::PutOperation && request.url().toString().endsWith(".zsync")) {
- metadata[transactionId(request.url())] = data->readAll();
- return new FakePutReply{ fakeFolder.uploadState(), op, request, metadata[transactionId(request.url())], this };
- }
- if (request.attribute(QNetworkRequest::CustomVerbAttribute) == "MOVE") {
- metadata[request.rawHeader("Destination").split('/').last()] = metadata[transactionId(request.url())];
- }
- return nullptr;
- });
- QVERIFY(fakeFolder.syncOnce());
- QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- QVERIFY(metadata["a0"].startsWith("zsync: "));
- QVERIFY(metadata["threeBlocks"].startsWith("zsync: "));
- QVERIFY(metadata["threeBlocksPlusOne"].startsWith("zsync: "));
- QVERIFY(metadata["threeBlocksMinusOne"].startsWith("zsync: "));
-
-
- // Test 1: create a conflict by changing the local file and touching the remote
- // and verify zsync saves bandwidth on download
-
- // The new local file is like the original,
- // but without the modifications and the appendByte
- fakeFolder.localModifier().remove("A/a0");
- fakeFolder.localModifier().insert("A/a0", size);
- auto currentMtime = QDateTime::currentDateTimeUtc();
- fakeFolder.remoteModifier().setModTime("A/a0", currentMtime);
- quint64 transferedData = 0;
- fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * {
- QUrlQuery query(request.url());
- if (op == QNetworkAccessManager::GetOperation) {
- if (query.hasQueryItem("zsync")) {
- return new FakeGetWithDataReply{ fakeFolder.remoteModifier(), metadata["a0"], op, request, this };
- }
-
- auto reply = new FakeGetWithDataReply{ fakeFolder.remoteModifier(), data, op, request, this };
- transferedData += reply->payload.size();
- return reply;
- }
-
- return nullptr;
- });
- QVERIFY(fakeFolder.syncOnce());
-
- // We didn't transfer the whole file
- // (plus one because of the new trailing byte)
- QVERIFY(transferedData <= (nModifications + 1) * ZSYNC_BLOCKSIZE);
-
- // Verify that the newly propagated file was assembled to have the expected data
- f.open(QIODevice::ReadOnly);
- QVERIFY(data == f.readAll());
- f.close();
-
- // Check the conflict creation
- auto conflicts = findConflicts(fakeFolder.currentLocalState().children["A"]);
- QCOMPARE(conflicts.size(), 1);
- for (auto c : conflicts) {
- fakeFolder.localModifier().remove(c);
- }
- QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
-
-
- // Test 2: The remote file has grown, not on a zsync block boundary
-
- // Setup the local state
- fakeFolder.remoteModifier().insert("A/growthSameBlock", 3 * ZSYNC_BLOCKSIZE - 1);
- fakeFolder.remoteModifier().insert("A/growthNewBlock", 3 * ZSYNC_BLOCKSIZE);
- fakeFolder.remoteModifier().insert("A/shrinkSameBlock", 3 * ZSYNC_BLOCKSIZE);
- fakeFolder.remoteModifier().insert("A/shrinkFewerBlock", 3 * ZSYNC_BLOCKSIZE + 1);
- QVERIFY(fakeFolder.syncOnce());
-
- // Grow/shrink files on the remote side
- fakeFolder.remoteModifier().remove("A/growthSameBlock");
- fakeFolder.remoteModifier().remove("A/growthNewBlock");
- fakeFolder.remoteModifier().remove("A/shrinkSameBlock");
- fakeFolder.remoteModifier().remove("A/shrinkFewerBlock");
- fakeFolder.remoteModifier().insert("A/growthSameBlock", 3 * ZSYNC_BLOCKSIZE);
- fakeFolder.remoteModifier().insert("A/growthNewBlock", 3 * ZSYNC_BLOCKSIZE + 1);
- fakeFolder.remoteModifier().insert("A/shrinkSameBlock", 3 * ZSYNC_BLOCKSIZE - 1);
- fakeFolder.remoteModifier().insert("A/shrinkFewerBlock", 3 * ZSYNC_BLOCKSIZE);
-
- // inject appropriate zsync metadata and actual data replies
- QMap<QString, QByteArray> downloads;
- fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * {
- QUrlQuery query(request.url());
- if (op == QNetworkAccessManager::GetOperation) {
- auto filename = request.url().path().split("/").last();
- if (query.hasQueryItem("zsync")) {
- QByteArray meta;
- if (filename == "growthSameBlock") {
- meta = metadata["threeBlocks"];
- } else if (filename == "growthNewBlock") {
- meta = metadata["threeBlocksPlusOne"];
- } else if (filename == "shrinkSameBlock") {
- meta = metadata["threeBlocksMinusOne"];
- } else if (filename == "shrinkFewerBlock") {
- meta = metadata["threeBlocks"];
- } else {
- Q_ASSERT(false);
- }
- return new FakeGetWithDataReply{ fakeFolder.remoteModifier(), meta, op, request, this };
- } else {
- downloads[filename] = request.rawHeader("Range");
- QByteArray fakeData(3 * ZSYNC_BLOCKSIZE + 1, fakeFolder.remoteModifier().find("A/growthNewBlock")->contentChar);
- return new FakeGetWithDataReply{ fakeFolder.remoteModifier(), fakeData, op, request, this };
- }
- }
- return nullptr;
- });
- QVERIFY(fakeFolder.syncOnce());
- QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
-
- // growthSameBlock: no download needed, first block can become third block
- QVERIFY(!downloads.contains("growthSameBlock"));
- // growthNewBlock: downloading one byte
- QCOMPARE(downloads["growthNewBlock"].data(), "bytes=3145728-3145728");
- // shrinkSameBlock: downloading N-1 bytes
- QCOMPARE(downloads["shrinkSameBlock"].data(), "bytes=2097152-3145726");
- // shrinkFewerBlock: no download needed
- QVERIFY(!downloads.contains("shrinkFewerBlock"));
- }
-
- void testFileUploadSimple()
- {
- FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
- fakeFolder.syncEngine().account()->setCapabilities({ { "dav", QVariantMap{ { "chunking", "1.0" }, { "zsync", "1.0" } } } });
-
- SyncOptions opt;
- opt._deltaSyncEnabled = true;
- opt._deltaSyncMinFileSize = 0;
- fakeFolder.syncEngine().setSyncOptions(opt);
-
- const int size = 100 * 1000 * 1000;
- QByteArray metadata;
-
- // Test 1: NEW file upload with zsync metadata
- fakeFolder.localModifier().insert("A/a0", size);
- fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *data) -> QNetworkReply * {
- if (op == QNetworkAccessManager::PutOperation && request.url().toString().endsWith(".zsync")) {
- metadata = data->readAll();
- return new FakePutReply{ fakeFolder.uploadState(), op, request, metadata, this };
- }
-
- return nullptr;
- });
- QVERIFY(fakeFolder.syncOnce());
- QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- QVERIFY(metadata.startsWith("zsync: "));
-
- // Test 2: Modify local contents and ensure that modified chunks are sent
- QVector<quint64> mods;
- qsrand(QDateTime::currentDateTime().toTime_t());
- fakeFolder.localModifier().appendByte("A/a0", 'X');
- mods.append(blockstart_from_offset(size + 1));
- for (int i = 0; i < 10; i++) {
- quint64 offset = qrand() % size;
- fakeFolder.localModifier().modifyByte("A/a0", offset, 'Y');
- mods.append(blockstart_from_offset(offset));
- }
- fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * {
- QUrlQuery query(request.url());
- if (op == QNetworkAccessManager::GetOperation && query.hasQueryItem("zsync")) {
- return new FakeGetWithDataReply{ fakeFolder.remoteModifier(), metadata, op, request, this };
- }
-
- if (request.attribute(QNetworkRequest::CustomVerbAttribute) == QLatin1String("MOVE")) {
- return new FakeChunkZsyncMoveReply{ fakeFolder.uploadState(), fakeFolder.remoteModifier(), op, request, 0, mods, this };
- }
-
- return nullptr;
- });
- QVERIFY(fakeFolder.syncOnce());
- fakeFolder.remoteModifier().appendByte("A/a0", 'X');
- QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- }
-
- void testFileUploadGrowShrink()
- {
- FakeFolder fakeFolder{ FileInfo() };
- fakeFolder.syncEngine().account()->setCapabilities({ { "dav", QVariantMap{ { "chunking", "1.0" }, { "zsync", "1.0" } } } });
-
- SyncOptions opt;
- opt._deltaSyncEnabled = true;
- opt._deltaSyncMinFileSize = 0;
- int chunkSize = 2 * 1000 * 1000;
- opt._minChunkSize = opt._maxChunkSize = opt._initialChunkSize = chunkSize; // don't dynamically size chunks
- fakeFolder.syncEngine().setSyncOptions(opt);
-
- const int zsyncBlockSize = 1024 * 1024;
-
- QByteArray metadata;
- QList<QPair<int, int>> putChunks;
- fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *data) -> QNetworkReply * {
- // Handle .zsync file storage and retrieval - note that preparing a PUT already updates the
- // zsync file data before the upload is finalized with a MOVE here.
- QUrlQuery query(request.url());
- if (request.url().toString().endsWith(".zsync") && op == QNetworkAccessManager::PutOperation) {
- metadata = data->readAll();
- return new FakePutReply{ fakeFolder.uploadState(), op, request, metadata, this };
- }
- if (op == QNetworkAccessManager::GetOperation && query.hasQueryItem("zsync")) {
- return new FakeGetWithDataReply{ fakeFolder.remoteModifier(), metadata, op, request, this };
- }
- // Grab chunk offset and size
- if (op == QNetworkAccessManager::PutOperation) {
- auto payload = data->readAll();
- putChunks.append({ request.rawHeader("OC-Chunk-Offset").toInt(), payload.size() });
- return new FakePutReply{ fakeFolder.uploadState(), op, request, payload, this };
- }
- return nullptr;
- });
-
- // Note: The remote side doesn't actually store the file contents
-
- // Test 1: NEW file upload with zsync metadata
- auto totalSize = 2 * zsyncBlockSize + 5;
- fakeFolder.localModifier().insert("a0", totalSize);
- QVERIFY(fakeFolder.syncOnce());
- QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- QVERIFY(putChunks.size() == 2);
- QVERIFY(putChunks[0] == qMakePair(0, 2000000));
- QVERIFY(putChunks[1] == qMakePair(2000000, totalSize - 2000000));
-
- // Test 2: Appending data to the file
- putChunks.clear();
- totalSize += 1;
- fakeFolder.localModifier().appendByte("a0", 'Q');
- QVERIFY(fakeFolder.syncOnce());
- QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- QVERIFY(putChunks.size() == 1);
- QVERIFY(putChunks[0] == qMakePair(2 * zsyncBlockSize, 6));
-
- // Test 3: reduce the file size
- putChunks.clear();
- totalSize -= 10;
- fakeFolder.localModifier().remove("a0");
- fakeFolder.localModifier().insert("a0", totalSize);
- QVERIFY(fakeFolder.syncOnce());
- QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- QVERIFY(putChunks.size() == 1);
- QVERIFY(putChunks[0] == qMakePair(zsyncBlockSize, totalSize - zsyncBlockSize)); // technically unnecessary
-
- // Test 4: add a large amount, such that the zsync block gets chunked
- putChunks.clear();
- totalSize += int(1.5 * chunkSize);
- fakeFolder.localModifier().remove("a0");
- fakeFolder.localModifier().insert("a0", totalSize);
- QVERIFY(fakeFolder.syncOnce());
- QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- QVERIFY(putChunks.size() == 3);
- // The first block stays, the rest is re-uploaded, total upload size is roughly 1MiB + 1.5 * 2MB = slightly more than 4MB
- QVERIFY(putChunks[0] == qMakePair(zsyncBlockSize, chunkSize));
- QVERIFY(putChunks[1] == qMakePair(zsyncBlockSize + chunkSize, chunkSize));
- QVERIFY(putChunks[2] == qMakePair(zsyncBlockSize + 2 * chunkSize, totalSize - (zsyncBlockSize + 2 * chunkSize)));
-
- // Test 5: append and change an early block at the same time
- putChunks.clear();
- totalSize += 1;
- fakeFolder.localModifier().appendByte("a0", 'Q');
- fakeFolder.localModifier().modifyByte("a0", 5, 'Q');
- QVERIFY(fakeFolder.syncOnce());
- QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- QVERIFY(putChunks.size() == 2);
- QVERIFY(putChunks[0] == qMakePair(0, zsyncBlockSize));
- QVERIFY(putChunks[1] == qMakePair(4 * zsyncBlockSize, totalSize - 4 * zsyncBlockSize));
-
- // Test 6: Shrink to an aligned size
- putChunks.clear();
- totalSize = 2 * zsyncBlockSize;
- fakeFolder.localModifier().remove("a0");
- fakeFolder.localModifier().insert("a0", totalSize);
- fakeFolder.localModifier().modifyByte("a0", 5, 'Q'); // same data as before
- QVERIFY(fakeFolder.syncOnce());
- QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- QVERIFY(putChunks.size() == 0);
-
- // Test 7: Grow to an aligned size
- putChunks.clear();
- totalSize = 3 * zsyncBlockSize;
- fakeFolder.localModifier().remove("a0");
- fakeFolder.localModifier().insert("a0", totalSize);
- fakeFolder.localModifier().modifyByte("a0", 5, 'Q'); // same data as before
- QVERIFY(fakeFolder.syncOnce());
- QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- QVERIFY(putChunks.size() == 1);
- QVERIFY(putChunks[0] == qMakePair(2 * zsyncBlockSize, zsyncBlockSize));
- }
-};
-
-QTEST_GUILESS_MAIN(TestZsync)
-#include "testzsync.moc"