From 189bc67a0a9a500fbc76dd51d9eec63469ecffa3 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jul 2023 22:29:49 +0800 Subject: [PATCH] Fix chunk numbering in chunking tests Signed-off-by: Claudio Cambra --- test/testchunkingng.cpp | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/test/testchunkingng.cpp b/test/testchunkingng.cpp index 6b9930f3b..fbd8d93bb 100644 --- a/test/testchunkingng.cpp +++ b/test/testchunkingng.cpp @@ -21,12 +21,11 @@ static void partialUpload(FakeFolder &fakeFolder, const QString &name, qint64 si fakeFolder.localModifier().insert(name, size); // Abort when the upload is at 1/3 qint64 sizeWhenAbort = -1; - auto con = QObject::connect(&fakeFolder.syncEngine(), &SyncEngine::transmissionProgress, - [&](const ProgressInfo &progress) { - if (progress.completedSize() > (progress.totalSize() /3 )) { - sizeWhenAbort = progress.completedSize(); - fakeFolder.syncEngine().abort(); - } + const auto con = QObject::connect(&fakeFolder.syncEngine(), &SyncEngine::transmissionProgress, [&](const ProgressInfo &progress) { + if (progress.completedSize() > (progress.totalSize() / 3)) { + sizeWhenAbort = progress.completedSize(); + fakeFolder.syncEngine().abort(); + } }); QVERIFY(!fakeFolder.syncOnce()); // there should have been an error @@ -182,8 +181,10 @@ private slots: QVERIFY(uploadedSize > 5 * 1000 * 1000); // at least 5 MB // Add a chunk that makes the file completely uploaded - fakeFolder.uploadState().children.first().insert( - QString::number(chunkMap.size()).rightJustified(16, '0'), size - uploadedSize); + const auto testChunkNameNum = chunkMap.count() + 1; // Chunk nums start at 1 with Chunk V2, so size() == last num, add 1 + const auto testChunkName = QString("%1").arg(testChunkNameNum, 5, 10, QChar('0')); + const auto testChunkSize = size - uploadedSize; + fakeFolder.uploadState().children.first().insert(testChunkName, testChunkSize); bool sawPut = false; bool sawDelete = false; @@ -216,19 +217,27 @@ private slots: void testResume4() { FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()}; fakeFolder.syncEngine().account()->setCapabilities({ { "dav", QVariantMap{ {"chunking", "1.0"} } } }); - const int size = 30 * 1000 * 1000; // 30 MB - setChunkSize(fakeFolder.syncEngine(), 1 * 1000 * 1000); + + constexpr auto size = 30 * 1000 * 1000; // 30 MB + constexpr auto chunkSize = 5 * 1000 * 1000; // 5 MB + setChunkSize(fakeFolder.syncEngine(), chunkSize); partialUpload(fakeFolder, "A/a0", size); QCOMPARE(fakeFolder.uploadState().children.count(), 1); - auto chunkingId = fakeFolder.uploadState().children.first().name; + + const auto chunkingId = fakeFolder.uploadState().children.first().name; const auto &chunkMap = fakeFolder.uploadState().children.first().children; - qint64 uploadedSize = std::accumulate(chunkMap.begin(), chunkMap.end(), 0LL, [](qint64 s, const FileInfo &f) { return s + f.size; }); + + const auto uploadedSize = std::accumulate(chunkMap.begin(), chunkMap.end(), 0LL, [](qint64 s, const FileInfo &f) { + return s + f.size; + }); QVERIFY(uploadedSize > 5 * 1000 * 1000); // at least 5 MB // Add a chunk that makes the file more than completely uploaded - fakeFolder.uploadState().children.first().insert( - QString::number(chunkMap.size()).rightJustified(16, '0'), size - uploadedSize + 100); + const auto testChunkNameNum = chunkMap.count() + 1; // Chunk nums start at 1 with Chunk V2, so size() == last num, add 1 + const auto testChunkName = QString("%1").arg(testChunkNameNum, 5, 10, QChar('0')); + const auto testChunkSize = size - uploadedSize + 100; + fakeFolder.uploadState().children.first().insert(testChunkName, testChunkSize); QVERIFY(fakeFolder.syncOnce()); -- 2.30.2