summaryrefslogtreecommitdiffstats
path: root/tests/maildirsyncbenchmark.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/maildirsyncbenchmark.cpp')
-rw-r--r--tests/maildirsyncbenchmark.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/maildirsyncbenchmark.cpp b/tests/maildirsyncbenchmark.cpp
new file mode 100644
index 0000000..4f23524
--- /dev/null
+++ b/tests/maildirsyncbenchmark.cpp
@@ -0,0 +1,110 @@
1#include <QtTest>
2#include <QString>
3#include <iostream>
4
5#include "hawd/dataset.h"
6#include "hawd/formatter.h"
7
8#include "maildirresource/maildirresource.h"
9#include "store.h"
10#include "resourcecontrol.h"
11#include "commands.h"
12#include "entitybuffer.h"
13#include "resourceconfig.h"
14#include "modelresult.h"
15#include "pipeline.h"
16#include "log.h"
17
18
19static bool copyRecursively(const QString &srcFilePath,
20 const QString &tgtFilePath)
21{
22 QFileInfo srcFileInfo(srcFilePath);
23 if (srcFileInfo.isDir()) {
24 QDir targetDir(tgtFilePath);
25 targetDir.cdUp();
26 if (!targetDir.mkdir(QFileInfo(srcFilePath).fileName())) {
27 qWarning() << "Failed to create directory " << tgtFilePath;
28 return false;
29 }
30 QDir sourceDir(srcFilePath);
31 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
32 foreach (const QString &fileName, fileNames) {
33 const QString newSrcFilePath
34 = srcFilePath + QLatin1Char('/') + fileName;
35 const QString newTgtFilePath
36 = tgtFilePath + QLatin1Char('/') + fileName;
37 if (!copyRecursively(newSrcFilePath, newTgtFilePath))
38 return false;
39 }
40 } else {
41 if (!QFile::copy(srcFilePath, tgtFilePath)) {
42 qWarning() << "Failed to copy file " << srcFilePath << tgtFilePath;
43 return false;
44 }
45 }
46 return true;
47}
48
49/**
50 * Test of complete system using the maildir resource.
51 *
52 * This test requires the maildir resource installed.
53 */
54class MaildirSyncBenchmark : public QObject
55{
56 Q_OBJECT
57
58 QTemporaryDir tempDir;
59 QString targetPath;
60 HAWD::State mHawdState;
61
62private Q_SLOTS:
63 void initTestCase()
64 {
65 targetPath = tempDir.path() + "/maildir1";
66
67 Sink::Log::setDebugOutputLevel(Sink::Log::Log);
68 MaildirResource::removeFromDisk("org.kde.maildir.test1");
69 Sink::ApplicationDomain::SinkResource resource;
70 resource.setProperty("identifier", "org.kde.maildir.test1");
71 resource.setProperty("type", "org.kde.maildir");
72 resource.setProperty("path", targetPath);
73 Sink::Store::create(resource).exec().waitForFinished();
74 }
75
76 void cleanup()
77 {
78 MaildirResource::removeFromDisk("org.kde.maildir.test1");
79 QDir dir(targetPath);
80 dir.removeRecursively();
81 }
82
83 void init()
84 {
85 copyRecursively(TESTDATAPATH "/maildir1", targetPath);
86 }
87
88 void testbench()
89 {
90 auto pipeline = QSharedPointer<Sink::Pipeline>::create("org.kde.maildir.test1");
91 MaildirResource resource("org.kde.maildir.test1", pipeline);
92 QTime time;
93 time.start();
94 resource.Sink::GenericResource::synchronizeWithSource().exec().waitForFinished();
95 std::cout << "Sync took " << time.elapsed() << std::endl;
96 resource.processAllMessages().exec().waitForFinished();
97 const auto allProcessedTime = time.elapsed();
98 std::cout << "All done " << allProcessedTime << std::endl;
99
100 // HAWD::Dataset dataset("maildir_sync", mHawdState);
101 // HAWD::Dataset::Row row = dataset.row();
102 // row.setValue("totalTime", allProcessedTime);
103 // dataset.insertRow(row);
104 // HAWD::Formatter::print(dataset);
105
106 }
107};
108
109QTEST_MAIN(MaildirSyncBenchmark)
110#include "maildirsyncbenchmark.moc"