summaryrefslogtreecommitdiffstats
path: root/examples/maildirresource/tests/maildirmailsynctest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-31 15:11:54 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-31 15:11:54 +0200
commit2061ba0cf16b6a0a3313f861f79b90cf2905efce (patch)
treec0e28aa0ff2271140bb58d6a0f1b51c9fc28a103 /examples/maildirresource/tests/maildirmailsynctest.cpp
parent4798de83c9f198bfc0a802a987c9002968fb6c2c (diff)
downloadsink-2061ba0cf16b6a0a3313f861f79b90cf2905efce.tar.gz
sink-2061ba0cf16b6a0a3313f861f79b90cf2905efce.zip
The maildir resource passes the maildirmailsync test
Diffstat (limited to 'examples/maildirresource/tests/maildirmailsynctest.cpp')
-rw-r--r--examples/maildirresource/tests/maildirmailsynctest.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/examples/maildirresource/tests/maildirmailsynctest.cpp b/examples/maildirresource/tests/maildirmailsynctest.cpp
new file mode 100644
index 0000000..444fb42
--- /dev/null
+++ b/examples/maildirresource/tests/maildirmailsynctest.cpp
@@ -0,0 +1,132 @@
1/*
2 * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19#include <QtTest>
20
21#include <tests/mailsynctest.h>
22#include "../maildirresource.h"
23#include "../libmaildir/maildir.h"
24
25#include "common/test.h"
26#include "common/domain/applicationdomaintype.h"
27
28using namespace Sink;
29using namespace Sink::ApplicationDomain;
30
31static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath)
32{
33 QFileInfo srcFileInfo(srcFilePath);
34 if (srcFileInfo.isDir()) {
35 QDir targetDir(tgtFilePath);
36 targetDir.cdUp();
37 if (!targetDir.mkdir(QFileInfo(srcFilePath).fileName())) {
38 qWarning() << "Failed to create directory " << tgtFilePath;
39 return false;
40 }
41 QDir sourceDir(srcFilePath);
42 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
43 foreach (const QString &fileName, fileNames) {
44 const QString newSrcFilePath = srcFilePath + QLatin1Char('/') + fileName;
45 const QString newTgtFilePath = tgtFilePath + QLatin1Char('/') + fileName;
46 if (!copyRecursively(newSrcFilePath, newTgtFilePath))
47 return false;
48 }
49 } else {
50 if (!QFile::copy(srcFilePath, tgtFilePath)) {
51 qWarning() << "Failed to copy file " << tgtFilePath;
52 return false;
53 }
54 }
55 return true;
56}
57
58/**
59 * Test of complete system using the maildir resource.
60 *
61 * This test requires the maildir resource installed.
62 */
63class MaildirMailSyncTest : public Sink::MailSyncTest
64{
65 Q_OBJECT
66
67 QTemporaryDir tempDir;
68 QString targetPath;
69
70protected:
71 void resetTestEnvironment() Q_DECL_OVERRIDE
72 {
73 targetPath = tempDir.path() + "/maildir1/";
74 QDir dir(targetPath);
75 dir.removeRecursively();
76 copyRecursively(TESTDATAPATH "/maildir1", targetPath);
77 }
78
79 Sink::ApplicationDomain::SinkResource createResource() Q_DECL_OVERRIDE
80 {
81 auto resource = ApplicationDomain::MaildirResource::create("account1");
82 resource.setProperty("path", targetPath);
83 return resource;
84 }
85
86 Sink::ApplicationDomain::SinkResource createFaultyResource() Q_DECL_OVERRIDE
87 {
88 auto resource = ApplicationDomain::MaildirResource::create("account1");
89 resource.setProperty("path", "");
90 return resource;
91 }
92
93 void removeResourceFromDisk(const QByteArray &identifier) Q_DECL_OVERRIDE
94 {
95 ::MaildirResource::removeFromDisk(identifier);
96 }
97
98 void createFolder(const QStringList &folderPath) Q_DECL_OVERRIDE
99 {
100 auto rootPath = tempDir.path() + "/maildir1/";
101 KPIM::Maildir maildir(rootPath + folderPath.join('/'), false);
102 maildir.create();
103 }
104
105 void removeFolder(const QStringList &folderPath) Q_DECL_OVERRIDE
106 {
107 auto rootPath = tempDir.path() + "/maildir1/";
108 KPIM::Maildir maildir(rootPath + folderPath.join('/'), false);
109 maildir.remove();
110 QDir dir(rootPath + folderPath.join('/'));
111 dir.removeRecursively();
112 // QVERIFY(maildir.removeSubFolder(name));
113 }
114
115 QByteArray createMessage(const QStringList &folderPath, const QByteArray &message) Q_DECL_OVERRIDE
116 {
117 auto rootPath = tempDir.path() + "/maildir1/";
118 KPIM::Maildir maildir(rootPath + folderPath.join('/'));
119 return maildir.addEntry(message).toUtf8();
120 }
121
122 void removeMessage(const QStringList &folderPath, const QByteArray &messageIdentifier) Q_DECL_OVERRIDE
123 {
124 auto rootPath = tempDir.path() + "/maildir1/";
125 KPIM::Maildir maildir(rootPath + folderPath.join('/'));
126 maildir.removeEntry(messageIdentifier);
127 }
128};
129
130QTEST_MAIN(MaildirMailSyncTest)
131
132#include "maildirmailsynctest.moc"