diff options
Diffstat (limited to 'examples/maildirresource/tests/maildirthreadtest.cpp')
-rw-r--r-- | examples/maildirresource/tests/maildirthreadtest.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/examples/maildirresource/tests/maildirthreadtest.cpp b/examples/maildirresource/tests/maildirthreadtest.cpp new file mode 100644 index 0000000..a74869c --- /dev/null +++ b/examples/maildirresource/tests/maildirthreadtest.cpp | |||
@@ -0,0 +1,90 @@ | |||
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/mailthreadtest.h> | ||
22 | #include "../maildirresource.h" | ||
23 | #include "../libmaildir/maildir.h" | ||
24 | |||
25 | #include "common/test.h" | ||
26 | #include "common/domain/applicationdomaintype.h" | ||
27 | |||
28 | #include "utils.h"; | ||
29 | |||
30 | using namespace Sink; | ||
31 | using namespace Sink::ApplicationDomain; | ||
32 | |||
33 | /** | ||
34 | * Test of complete system using the maildir resource. | ||
35 | * | ||
36 | * This test requires the maildir resource installed. | ||
37 | */ | ||
38 | class MaildirThreadTest : public Sink::MailThreadTest | ||
39 | { | ||
40 | Q_OBJECT | ||
41 | |||
42 | QTemporaryDir tempDir; | ||
43 | QString targetPath; | ||
44 | |||
45 | protected: | ||
46 | void resetTestEnvironment() Q_DECL_OVERRIDE | ||
47 | { | ||
48 | targetPath = tempDir.path() + "/maildir2/"; | ||
49 | QDir dir(targetPath); | ||
50 | dir.removeRecursively(); | ||
51 | copyRecursively(TESTDATAPATH "/maildir2", targetPath); | ||
52 | } | ||
53 | |||
54 | Sink::ApplicationDomain::SinkResource createResource() Q_DECL_OVERRIDE | ||
55 | { | ||
56 | auto resource = ApplicationDomain::MaildirResource::create("account1"); | ||
57 | resource.setProperty("path", targetPath); | ||
58 | return resource; | ||
59 | } | ||
60 | |||
61 | Sink::ApplicationDomain::SinkResource createFaultyResource() Q_DECL_OVERRIDE | ||
62 | { | ||
63 | auto resource = ApplicationDomain::MaildirResource::create("account1"); | ||
64 | resource.setProperty("path", ""); | ||
65 | return resource; | ||
66 | } | ||
67 | |||
68 | void removeResourceFromDisk(const QByteArray &identifier) Q_DECL_OVERRIDE | ||
69 | { | ||
70 | ::MaildirResource::removeFromDisk(identifier); | ||
71 | } | ||
72 | |||
73 | QByteArray createMessage(const QStringList &folderPath, const QByteArray &message) Q_DECL_OVERRIDE | ||
74 | { | ||
75 | auto rootPath = tempDir.path() + "/maildir2/"; | ||
76 | KPIM::Maildir maildir(rootPath + folderPath.join('/')); | ||
77 | return maildir.addEntry(message).toUtf8(); | ||
78 | } | ||
79 | |||
80 | void removeMessage(const QStringList &folderPath, const QByteArray &messageIdentifier) Q_DECL_OVERRIDE | ||
81 | { | ||
82 | auto rootPath = tempDir.path() + "/maildir2/"; | ||
83 | KPIM::Maildir maildir(rootPath + folderPath.join('/')); | ||
84 | maildir.removeEntry(messageIdentifier); | ||
85 | } | ||
86 | }; | ||
87 | |||
88 | QTEST_MAIN(MaildirThreadTest) | ||
89 | |||
90 | #include "maildirthreadtest.moc" | ||