summaryrefslogtreecommitdiffstats
path: root/tests/maildirresourcetest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/maildirresourcetest.cpp')
-rw-r--r--tests/maildirresourcetest.cpp205
1 files changed, 100 insertions, 105 deletions
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp
index d5f7f95..b5c1c3c 100644
--- a/tests/maildirresourcetest.cpp
+++ b/tests/maildirresourcetest.cpp
@@ -12,8 +12,7 @@
12#include "pipeline.h" 12#include "pipeline.h"
13#include "log.h" 13#include "log.h"
14 14
15static bool copyRecursively(const QString &srcFilePath, 15static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath)
16 const QString &tgtFilePath)
17{ 16{
18 QFileInfo srcFileInfo(srcFilePath); 17 QFileInfo srcFileInfo(srcFilePath);
19 if (srcFileInfo.isDir()) { 18 if (srcFileInfo.isDir()) {
@@ -26,10 +25,8 @@ static bool copyRecursively(const QString &srcFilePath,
26 QDir sourceDir(srcFilePath); 25 QDir sourceDir(srcFilePath);
27 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System); 26 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
28 foreach (const QString &fileName, fileNames) { 27 foreach (const QString &fileName, fileNames) {
29 const QString newSrcFilePath 28 const QString newSrcFilePath = srcFilePath + QLatin1Char('/') + fileName;
30 = srcFilePath + QLatin1Char('/') + fileName; 29 const QString newTgtFilePath = tgtFilePath + QLatin1Char('/') + fileName;
31 const QString newTgtFilePath
32 = tgtFilePath + QLatin1Char('/') + fileName;
33 if (!copyRecursively(newSrcFilePath, newTgtFilePath)) 30 if (!copyRecursively(newSrcFilePath, newTgtFilePath))
34 return false; 31 return false;
35 } 32 }
@@ -44,7 +41,7 @@ static bool copyRecursively(const QString &srcFilePath,
44 41
45/** 42/**
46 * Test of complete system using the maildir resource. 43 * Test of complete system using the maildir resource.
47 * 44 *
48 * This test requires the maildir resource installed. 45 * This test requires the maildir resource installed.
49 */ 46 */
50class MaildirResourceTest : public QObject 47class MaildirResourceTest : public QObject
@@ -89,7 +86,7 @@ private slots:
89 Sink::Query query; 86 Sink::Query query;
90 query.resources << "org.kde.maildir.instance1"; 87 query.resources << "org.kde.maildir.instance1";
91 88
92 //Ensure all local data is processed 89 // Ensure all local data is processed
93 Sink::Store::synchronize(query).exec().waitForFinished(); 90 Sink::Store::synchronize(query).exec().waitForFinished();
94 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 91 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
95 92
@@ -104,7 +101,7 @@ private slots:
104 query.resources << "org.kde.maildir.instance1"; 101 query.resources << "org.kde.maildir.instance1";
105 query.parentProperty = "parent"; 102 query.parentProperty = "parent";
106 103
107 //Ensure all local data is processed 104 // Ensure all local data is processed
108 Sink::Store::synchronize(query).exec().waitForFinished(); 105 Sink::Store::synchronize(query).exec().waitForFinished();
109 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 106 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
110 107
@@ -121,23 +118,18 @@ private slots:
121 { 118 {
122 using namespace Sink; 119 using namespace Sink;
123 using namespace Sink::ApplicationDomain; 120 using namespace Sink::ApplicationDomain;
124 //Ensure all local data is processed 121 // Ensure all local data is processed
125 auto query = Query::ResourceFilter("org.kde.maildir.instance1"); 122 auto query = Query::ResourceFilter("org.kde.maildir.instance1");
126 Store::synchronize(query).exec().waitForFinished(); 123 Store::synchronize(query).exec().waitForFinished();
127 ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 124 ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
128 auto result = Store::fetchOne<Folder>( 125 auto result = Store::fetchOne<Folder>(Query::ResourceFilter("org.kde.maildir.instance1") + Query::RequestedProperties(QByteArrayList() << "name"))
129 Query::ResourceFilter("org.kde.maildir.instance1") + Query::RequestedProperties(QByteArrayList() << "name") 126 .then<QList<Mail::Ptr>, Folder>([](const Folder &folder) {
130 ) 127 Trace() << "Found a folder" << folder.identifier();
131 .then<QList<Mail::Ptr>, Folder>([](const Folder &folder) { 128 return Store::fetchAll<Mail>(Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder"
132 Trace() << "Found a folder" << folder.identifier(); 129 << "subject"));
133 return Store::fetchAll<Mail>( 130 })
134 Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") 131 .then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { QVERIFY(mails.size() >= 1); })
135 ); 132 .exec();
136 })
137 .then<void, QList<Mail::Ptr> >([](const QList<Mail::Ptr> &mails) {
138 QVERIFY(mails.size() >= 1);
139 })
140 .exec();
141 result.waitForFinished(); 133 result.waitForFinished();
142 QVERIFY(!result.errorCode()); 134 QVERIFY(!result.errorCode());
143 } 135 }
@@ -146,9 +138,12 @@ private slots:
146 { 138 {
147 Sink::Query query; 139 Sink::Query query;
148 query.resources << "org.kde.maildir.instance1"; 140 query.resources << "org.kde.maildir.instance1";
149 query.requestedProperties << "folder" << "subject" << "mimeMessage" << "date"; 141 query.requestedProperties << "folder"
142 << "subject"
143 << "mimeMessage"
144 << "date";
150 145
151 //Ensure all local data is processed 146 // Ensure all local data is processed
152 Sink::Store::synchronize(query).exec().waitForFinished(); 147 Sink::Store::synchronize(query).exec().waitForFinished();
153 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 148 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
154 149
@@ -171,7 +166,7 @@ private slots:
171 query.resources << "org.kde.maildir.instance1"; 166 query.resources << "org.kde.maildir.instance1";
172 query.requestedProperties << "name"; 167 query.requestedProperties << "name";
173 168
174 //Ensure all local data is processed 169 // Ensure all local data is processed
175 Sink::Store::synchronize(query).exec().waitForFinished(); 170 Sink::Store::synchronize(query).exec().waitForFinished();
176 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 171 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
177 172
@@ -179,7 +174,7 @@ private slots:
179 QDir dir(targetPath); 174 QDir dir(targetPath);
180 QVERIFY(dir.rename("inbox", "newbox")); 175 QVERIFY(dir.rename("inbox", "newbox"));
181 176
182 //Ensure all local data is processed 177 // Ensure all local data is processed
183 Sink::Store::synchronize(query).exec().waitForFinished(); 178 Sink::Store::synchronize(query).exec().waitForFinished();
184 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 179 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
185 180
@@ -193,13 +188,14 @@ private slots:
193 { 188 {
194 Sink::Query query; 189 Sink::Query query;
195 query.resources << "org.kde.maildir.instance1"; 190 query.resources << "org.kde.maildir.instance1";
196 query.requestedProperties << "folder" << "subject"; 191 query.requestedProperties << "folder"
192 << "subject";
197 193
198 //Ensure all local data is processed 194 // Ensure all local data is processed
199 Sink::Store::synchronize(query).exec().waitForFinished(); 195 Sink::Store::synchronize(query).exec().waitForFinished();
200 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 196 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
201 197
202 //Ensure all local data is processed 198 // Ensure all local data is processed
203 Sink::Store::synchronize(query).exec().waitForFinished(); 199 Sink::Store::synchronize(query).exec().waitForFinished();
204 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 200 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
205 201
@@ -212,9 +208,10 @@ private slots:
212 { 208 {
213 Sink::Query query; 209 Sink::Query query;
214 query.resources << "org.kde.maildir.instance1"; 210 query.resources << "org.kde.maildir.instance1";
215 query.requestedProperties << "folder" << "subject"; 211 query.requestedProperties << "folder"
212 << "subject";
216 213
217 //Ensure all local data is processed 214 // Ensure all local data is processed
218 Sink::Store::synchronize(query).exec().waitForFinished(); 215 Sink::Store::synchronize(query).exec().waitForFinished();
219 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 216 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
220 217
@@ -222,7 +219,7 @@ private slots:
222 QFile file(targetPath); 219 QFile file(targetPath);
223 QVERIFY(file.remove()); 220 QVERIFY(file.remove());
224 221
225 //Ensure all local data is processed 222 // Ensure all local data is processed
226 Sink::Store::synchronize(query).exec().waitForFinished(); 223 Sink::Store::synchronize(query).exec().waitForFinished();
227 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 224 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
228 225
@@ -236,7 +233,7 @@ private slots:
236 Sink::Query query; 233 Sink::Query query;
237 query.resources << "org.kde.maildir.instance1"; 234 query.resources << "org.kde.maildir.instance1";
238 235
239 //Ensure all local data is processed 236 // Ensure all local data is processed
240 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 237 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
241 238
242 Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); 239 Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1");
@@ -244,7 +241,7 @@ private slots:
244 241
245 Sink::Store::create(folder).exec().waitForFinished(); 242 Sink::Store::create(folder).exec().waitForFinished();
246 243
247 //Ensure all local data is processed 244 // Ensure all local data is processed
248 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 245 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
249 246
250 auto targetPath = tempDir.path() + "/maildir1/testCreateFolder"; 247 auto targetPath = tempDir.path() + "/maildir1/testCreateFolder";
@@ -284,16 +281,16 @@ private slots:
284 Sink::Query query; 281 Sink::Query query;
285 query.resources << "org.kde.maildir.instance1"; 282 query.resources << "org.kde.maildir.instance1";
286 283
287 //Ensure all local data is processed 284 // Ensure all local data is processed
288 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 285 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
289 286
290 Sink::ApplicationDomain::Mail mail("org.kde.maildir.instance1"); 287 Sink::ApplicationDomain::Mail mail("org.kde.maildir.instance1");
291 mail.setProperty("name", "testCreateMail"); 288 mail.setProperty("name", "testCreateMail");
292 //FIXME instead of properties, ensure the mimeMessage property is used and the file is moved as expected 289 // FIXME instead of properties, ensure the mimeMessage property is used and the file is moved as expected
293 290
294 Sink::Store::create(mail).exec().waitForFinished(); 291 Sink::Store::create(mail).exec().waitForFinished();
295 292
296 //Ensure all local data is processed 293 // Ensure all local data is processed
297 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 294 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
298 295
299 auto targetPath = tempDir.path() + "/maildir1/new"; 296 auto targetPath = tempDir.path() + "/maildir1/new";
@@ -312,25 +309,23 @@ private slots:
312 ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 309 ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
313 310
314 auto result = Store::fetchOne<Folder>( 311 auto result = Store::fetchOne<Folder>(
315 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") 312 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name"))
316 ) 313 .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) {
317 .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) { 314 return Store::fetchAll<Mail>(Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder"
318 return Store::fetchAll<Mail>( 315 << "subject"))
319 Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") 316 .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([query](const QList<Mail::Ptr> &mails) {
320 ) 317 // Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE
321 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) { 318 if (mails.size() != 1) {
322 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE 319 return KAsync::error<void>(1, "Wrong number of mails.");
323 if (mails.size() != 1) { 320 }
324 return KAsync::error<void>(1, "Wrong number of mails."); 321 auto mail = mails.first();
325 } 322
326 auto mail = mails.first(); 323 return Store::remove(*mail)
327 324 .then(ResourceControl::flushReplayQueue(query.resources)) // The change needs to be replayed already
328 return Store::remove(*mail) 325 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::ExistenceInspection(*mail, false)));
329 .then(ResourceControl::flushReplayQueue(query.resources)) //The change needs to be replayed already 326 });
330 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::ExistenceInspection(*mail, false))); 327 })
331 }); 328 .exec();
332 })
333 .exec();
334 result.waitForFinished(); 329 result.waitForFinished();
335 QVERIFY(!result.errorCode()); 330 QVERIFY(!result.errorCode());
336 } 331 }
@@ -347,61 +342,61 @@ private slots:
347 Folder f; 342 Folder f;
348 343
349 auto result = Store::fetchOne<Folder>( 344 auto result = Store::fetchOne<Folder>(
350 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") 345 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name"))
351 ) 346 .then<void, KAsync::Job<void>, Folder>([query, &f](const Folder &folder) {
352 .then<void, KAsync::Job<void>, Folder>([query, &f](const Folder &folder) { 347 f = folder;
353 f = folder; 348 return Store::fetchAll<Mail>(Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", folder) +
354 return Store::fetchAll<Mail>( 349 Query::RequestedProperties(QByteArrayList() << "folder"
355 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") 350 << "subject"))
356 ) 351 .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([query](const QList<Mail::Ptr> &mails) {
357 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) { 352 // Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE
358 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE 353 if (mails.size() != 1) {
359 if (mails.size() != 1) { 354 return KAsync::error<void>(1, "Wrong number of mails.");
360 return KAsync::error<void>(1, "Wrong number of mails."); 355 }
361 } 356 auto mail = mails.first();
362 auto mail = mails.first(); 357 mail->setProperty("unread", true);
363 mail->setProperty("unread", true); 358 return Store::modify(*mail)
364 return Store::modify(*mail) 359 .then<void>(ResourceControl::flushReplayQueue(query.resources)) // The change needs to be replayed already
365 .then<void>(ResourceControl::flushReplayQueue(query.resources)) //The change needs to be replayed already 360 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::PropertyInspection(*mail, "unread", true)))
366 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::PropertyInspection(*mail, "unread", true))) 361 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::PropertyInspection(*mail, "subject", mail->getProperty("subject"))));
367 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::PropertyInspection(*mail, "subject", mail->getProperty("subject")))); 362 });
368 }); 363 })
369 }) 364 .exec();
370 .exec();
371 result.waitForFinished(); 365 result.waitForFinished();
372 QVERIFY(!result.errorCode()); 366 QVERIFY(!result.errorCode());
373 367
374 //Verify that we can still query for all relevant information 368 // Verify that we can still query for all relevant information
375 auto result2 = Store::fetchAll<Mail>( 369 auto result2 = Store::fetchAll<Mail>(
376 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", f) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject" << "mimeMessage" << "unread") 370 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", f) + Query::RequestedProperties(QByteArrayList() << "folder"
377 ) 371 << "subject"
378 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([](const QList<Mail::Ptr> &mails) { 372 << "mimeMessage"
379 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE 373 << "unread"))
380 if (mails.size() != 1) { 374 .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) {
381 qWarning() << "Wrong number of mails"; 375 // Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE
382 return KAsync::error<void>(1, "Wrong number of mails."); 376 if (mails.size() != 1) {
383 } 377 qWarning() << "Wrong number of mails";
384 auto mail = mails.first(); 378 return KAsync::error<void>(1, "Wrong number of mails.");
385 if (mail->getProperty("subject").toString().isEmpty()) { 379 }
386 qWarning() << "Wrong subject"; 380 auto mail = mails.first();
387 return KAsync::error<void>(1, "Wrong subject."); 381 if (mail->getProperty("subject").toString().isEmpty()) {
388 } 382 qWarning() << "Wrong subject";
389 if (mail->getProperty("unread").toBool() != true) { 383 return KAsync::error<void>(1, "Wrong subject.");
390 qWarning() << "Not unread"; 384 }
391 return KAsync::error<void>(1, "Not unread."); 385 if (mail->getProperty("unread").toBool() != true) {
392 } 386 qWarning() << "Not unread";
393 QFileInfo info(mail->getProperty("mimeMessage").toString()); 387 return KAsync::error<void>(1, "Not unread.");
394 if (!info.exists()) { 388 }
395 qWarning() << "Wrong subject"; 389 QFileInfo info(mail->getProperty("mimeMessage").toString());
396 return KAsync::error<void>(1, "Can't find mime message."); 390 if (!info.exists()) {
397 } 391 qWarning() << "Wrong subject";
398 return KAsync::null<void>(); 392 return KAsync::error<void>(1, "Can't find mime message.");
399 }) 393 }
400 .exec(); 394 return KAsync::null<void>();
395 })
396 .exec();
401 result2.waitForFinished(); 397 result2.waitForFinished();
402 QVERIFY(!result2.errorCode()); 398 QVERIFY(!result2.errorCode());
403 } 399 }
404
405}; 400};
406 401
407QTEST_MAIN(MaildirResourceTest) 402QTEST_MAIN(MaildirResourceTest)