diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-24 09:20:02 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-24 09:20:02 +0200 |
commit | 6434a87199b3259e9002570332beaa8caf5d2213 (patch) | |
tree | 87c5fe877e350b067b37961b9af2058693be8665 /tests/mailtest.cpp | |
parent | f47270cea65545f946ff301014cb09bd5ff40261 (diff) | |
download | sink-6434a87199b3259e9002570332beaa8caf5d2213.tar.gz sink-6434a87199b3259e9002570332beaa8caf5d2213.zip |
A generic mailtest that can be applied to all resources that support
mails.
Diffstat (limited to 'tests/mailtest.cpp')
-rw-r--r-- | tests/mailtest.cpp | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp new file mode 100644 index 0000000..79a077c --- /dev/null +++ b/tests/mailtest.cpp | |||
@@ -0,0 +1,183 @@ | |||
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 "mailtest.h" | ||
20 | |||
21 | #include <QtTest> | ||
22 | |||
23 | #include <QString> | ||
24 | #include <KMime/Message> | ||
25 | |||
26 | #include "store.h" | ||
27 | #include "resourcecontrol.h" | ||
28 | #include "log.h" | ||
29 | #include "test.h" | ||
30 | |||
31 | using namespace Sink; | ||
32 | using namespace Sink::ApplicationDomain; | ||
33 | |||
34 | void MailTest::initTestCase() | ||
35 | { | ||
36 | Test::initTest(); | ||
37 | Log::setDebugOutputLevel(Sink::Log::Trace); | ||
38 | resetTestEnvironment(); | ||
39 | auto resource = createResource(); | ||
40 | QVERIFY(!resource.identifier().isEmpty()); | ||
41 | |||
42 | VERIFYEXEC(Store::create(resource)); | ||
43 | |||
44 | mResourceInstanceIdentifier = resource.identifier(); | ||
45 | } | ||
46 | |||
47 | void MailTest::cleanup() | ||
48 | { | ||
49 | VERIFYEXEC(ResourceControl::shutdown(mResourceInstanceIdentifier)); | ||
50 | removeResourceFromDisk(mResourceInstanceIdentifier); | ||
51 | } | ||
52 | |||
53 | void MailTest::init() | ||
54 | { | ||
55 | qDebug(); | ||
56 | qDebug() << "-----------------------------------------"; | ||
57 | qDebug(); | ||
58 | VERIFYEXEC(ResourceControl::start(mResourceInstanceIdentifier)); | ||
59 | } | ||
60 | |||
61 | void MailTest::testCreateModifyDeleteFolder() | ||
62 | { | ||
63 | QString name = "name"; | ||
64 | QByteArray icon = "icon"; | ||
65 | |||
66 | auto folder = Folder::create(mResourceInstanceIdentifier); | ||
67 | folder.setName(name); | ||
68 | folder.setIcon(icon); | ||
69 | |||
70 | VERIFYEXEC(Store::create(folder)); | ||
71 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); | ||
72 | { | ||
73 | auto job = Store::fetchAll<Folder>(Query::RequestedProperties(QByteArrayList() << Folder::Name::name << Folder::Icon::name)) | ||
74 | .then<void, QList<Folder::Ptr>>([=](const QList<Folder::Ptr> &folders) { | ||
75 | QCOMPARE(folders.size(), 1); | ||
76 | auto folder = *folders.first(); | ||
77 | QCOMPARE(folder.getName(), name); | ||
78 | QCOMPARE(folder.getIcon(), icon); | ||
79 | }); | ||
80 | VERIFYEXEC(job); | ||
81 | } | ||
82 | |||
83 | QString name2 = "name2"; | ||
84 | QByteArray icon2 = "icon2"; | ||
85 | folder.setName(name2); | ||
86 | folder.setIcon(icon2); | ||
87 | |||
88 | VERIFYEXEC(Store::modify(folder)); | ||
89 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); | ||
90 | { | ||
91 | auto job = Store::fetchAll<Folder>(Query::RequestedProperties(QByteArrayList() << Folder::Name::name << Folder::Icon::name)) | ||
92 | .then<void, QList<Folder::Ptr>>([=](const QList<Folder::Ptr> &folders) { | ||
93 | QCOMPARE(folders.size(), 1); | ||
94 | auto folder = *folders.first(); | ||
95 | QCOMPARE(folder.getName(), name2); | ||
96 | QCOMPARE(folder.getIcon(), icon2); | ||
97 | }); | ||
98 | VERIFYEXEC(job); | ||
99 | } | ||
100 | |||
101 | VERIFYEXEC(Store::remove(folder)); | ||
102 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); | ||
103 | { | ||
104 | auto job = Store::fetchAll<Folder>(Query::RequestedProperties(QByteArrayList() << Folder::Name::name << Folder::Icon::name)) | ||
105 | .then<void, QList<Folder::Ptr>>([=](const QList<Folder::Ptr> &folders) { | ||
106 | QCOMPARE(folders.size(), 0); | ||
107 | }); | ||
108 | VERIFYEXEC(job); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | void MailTest::testCreateModifyDeleteMail() | ||
113 | { | ||
114 | |||
115 | const auto subject = QString::fromLatin1("Foobar"); | ||
116 | |||
117 | Query query; | ||
118 | query.resources << mResourceInstanceIdentifier; | ||
119 | query.request<Mail::Folder>().request<Mail::Subject>(); | ||
120 | |||
121 | auto folder = Folder::create(mResourceInstanceIdentifier); | ||
122 | folder.setName("folder"); | ||
123 | VERIFYEXEC(Store::create(folder)); | ||
124 | |||
125 | auto message = KMime::Message::Ptr::create(); | ||
126 | message->subject(true)->fromUnicodeString(subject, "utf8"); | ||
127 | message->assemble(); | ||
128 | |||
129 | auto mail = Mail::create(mResourceInstanceIdentifier); | ||
130 | mail.setMimeMessage(message->encodedContent()); | ||
131 | mail.setFolder(folder); | ||
132 | |||
133 | VERIFYEXEC(Store::create(mail)); | ||
134 | VERIFYEXEC(ResourceControl::flushMessageQueue(query.resources)); | ||
135 | { | ||
136 | auto job = Store::fetchAll<Mail>(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name)) | ||
137 | .then<void, QList<Mail::Ptr>>([=](const QList<Mail::Ptr> &mails) { | ||
138 | QCOMPARE(mails.size(), 1); | ||
139 | auto mail = *mails.first(); | ||
140 | // QCOMPARE(mail.getSubject(), subject); | ||
141 | QCOMPARE(mail.getFolder(), folder.identifier()); | ||
142 | // TODO test access to mime message | ||
143 | |||
144 | // return Store::remove(*mail) | ||
145 | // .then(ResourceControl::flushReplayQueue(query.resources)) // The change needs to be replayed already | ||
146 | // .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::ExistenceInspection(*mail, false))); | ||
147 | }); | ||
148 | VERIFYEXEC(job); | ||
149 | } | ||
150 | |||
151 | const auto subject2 = QString::fromLatin1("Foobar2"); | ||
152 | auto message2 = KMime::Message::Ptr::create(); | ||
153 | message2->subject(true)->fromUnicodeString(subject2, "utf8"); | ||
154 | message2->assemble(); | ||
155 | mail.setMimeMessage(message2->encodedContent()); | ||
156 | |||
157 | VERIFYEXEC(Store::modify(mail)); | ||
158 | VERIFYEXEC(ResourceControl::flushMessageQueue(query.resources)); | ||
159 | { | ||
160 | auto job = Store::fetchAll<Mail>(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name)) | ||
161 | .then<void, QList<Mail::Ptr>>([=](const QList<Mail::Ptr> &mails) { | ||
162 | QCOMPARE(mails.size(), 1); | ||
163 | auto mail = *mails.first(); | ||
164 | QCOMPARE(mail.getFolder(), folder.identifier()); | ||
165 | // QCOMPARE(mail.getSubject(), subject); | ||
166 | // TODO test access to modified mime message | ||
167 | |||
168 | }); | ||
169 | VERIFYEXEC(job); | ||
170 | } | ||
171 | |||
172 | VERIFYEXEC(Store::remove(mail)); | ||
173 | VERIFYEXEC(ResourceControl::flushMessageQueue(query.resources)); | ||
174 | { | ||
175 | auto job = Store::fetchAll<Mail>(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name)) | ||
176 | .then<void, QList<Mail::Ptr>>([=](const QList<Mail::Ptr> &mails) { | ||
177 | QCOMPARE(mails.size(), 0); | ||
178 | }); | ||
179 | VERIFYEXEC(job); | ||
180 | } | ||
181 | } | ||
182 | |||
183 | #include "mailtest.moc" | ||