File: benchlargesync.cpp

package info (click to toggle)
nextcloud-desktop 4.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,404 kB
  • sloc: cpp: 118,401; objc: 752; python: 606; sh: 395; ansic: 391; ruby: 174; makefile: 44; javascript: 32; xml: 6
file content (52 lines) | stat: -rw-r--r-- 1,761 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2017 ownCloud GmbH
 * SPDX-License-Identifier: CC0-1.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 "syncenginetestutils.h"
#include <syncengine.h>

using namespace OCC;

int numDirs = 0;
int numFiles = 0;

template<int filesPerDir, int dirPerDir, int maxDepth>
void addBunchOfFiles(int depth, const QString &path, FileModifier &fi) {
    for (int fileNum = 1; fileNum <= filesPerDir; ++fileNum) {
        QString name = QStringLiteral("file") + QString::number(fileNum);
        fi.insert(path.isEmpty() ? name : path + "/" + name);
        numFiles++;
    }
    if (depth >= maxDepth)
        return;
    for (int dirNum = 1; dirNum <= dirPerDir; ++dirNum) {
        QString name = QStringLiteral("dir") + QString::number(dirNum);
        QString subPath = path.isEmpty() ? name : path + "/" + name;
        fi.mkdir(subPath);
        numDirs++;
        addBunchOfFiles<filesPerDir, dirPerDir, maxDepth>(depth + 1, subPath, fi);
    }
}

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
    addBunchOfFiles<10, 8, 4>(0, "", fakeFolder.localModifier());

    qDebug() << "NUMFILES" << numFiles;
    qDebug() << "NUMDIRS" << numDirs;
    QElapsedTimer timer;
    timer.start();
    bool result1 = fakeFolder.syncOnce();
    qDebug() << "FIRST SYNC: " << result1 << timer.restart();
    bool result2 = fakeFolder.syncOnce();
    qDebug() << "SECOND SYNC: " << result2 << timer.restart();
    return (result1 && result2) ? 0 : -1;
}