diff options
Diffstat (limited to 'tests/mailtest.cpp')
-rw-r--r-- | tests/mailtest.cpp | 103 |
1 files changed, 91 insertions, 12 deletions
diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp index 2fcad93..4e36517 100644 --- a/tests/mailtest.cpp +++ b/tests/mailtest.cpp | |||
@@ -242,11 +242,14 @@ void MailTest::testMoveMail() | |||
242 | 242 | ||
243 | VERIFYEXEC(Store::create(mail)); | 243 | VERIFYEXEC(Store::create(mail)); |
244 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); | 244 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); |
245 | |||
246 | Mail modifiedMail; | ||
245 | { | 247 | { |
246 | auto job = Store::fetchAll<Mail>(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name << Mail::MimeMessage::name)) | 248 | auto job = Store::fetchAll<Mail>(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name << Mail::MimeMessage::name)) |
247 | .then<void, QList<Mail::Ptr>>([=](const QList<Mail::Ptr> &mails) { | 249 | .then<void, QList<Mail::Ptr>>([=, &modifiedMail](const QList<Mail::Ptr> &mails) { |
248 | QCOMPARE(mails.size(), 1); | 250 | QCOMPARE(mails.size(), 1); |
249 | auto mail = *mails.first(); | 251 | auto mail = *mails.first(); |
252 | modifiedMail = mail; | ||
250 | QCOMPARE(mail.getFolder(), folder.identifier()); | 253 | QCOMPARE(mail.getFolder(), folder.identifier()); |
251 | Warning() << "path: " << mail.getMimeMessagePath(); | 254 | Warning() << "path: " << mail.getMimeMessagePath(); |
252 | QVERIFY(QFile(mail.getMimeMessagePath()).exists()); | 255 | QVERIFY(QFile(mail.getMimeMessagePath()).exists()); |
@@ -256,9 +259,9 @@ void MailTest::testMoveMail() | |||
256 | 259 | ||
257 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::CacheIntegrityInspection(folder))); | 260 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::CacheIntegrityInspection(folder))); |
258 | 261 | ||
259 | mail.setFolder(folder1); | 262 | modifiedMail.setFolder(folder1); |
260 | 263 | ||
261 | VERIFYEXEC(Store::modify(mail)); | 264 | VERIFYEXEC(Store::modify(modifiedMail)); |
262 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); | 265 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); |
263 | { | 266 | { |
264 | auto job = Store::fetchAll<Mail>(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name << Mail::MimeMessage::name)) | 267 | auto job = Store::fetchAll<Mail>(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name << Mail::MimeMessage::name)) |
@@ -349,17 +352,93 @@ void MailTest::testCreateDraft() | |||
349 | VERIFYEXEC(job); | 352 | VERIFYEXEC(job); |
350 | 353 | ||
351 | //Ensure we can also query by folder | 354 | //Ensure we can also query by folder |
352 | auto job2 = Store::fetchAll<ApplicationDomain::Mail>(Query::PropertyFilter("folder", folderIdentifier)) | 355 | { |
353 | .then<void, QList<ApplicationDomain::Mail::Ptr> >([&](const QList<ApplicationDomain::Mail::Ptr> &mails) { | 356 | auto job = Store::fetchAll<ApplicationDomain::Mail>(Query::PropertyFilter("folder", folderIdentifier)) |
354 | bool found = false; | 357 | .then<void, QList<ApplicationDomain::Mail::Ptr> >([&](const QList<ApplicationDomain::Mail::Ptr> &mails) { |
355 | for (const auto m : mails) { | 358 | bool found = false; |
356 | if (m->identifier() == mail.identifier()) { | 359 | for (const auto m : mails) { |
357 | found = true; | 360 | if (m->identifier() == mail.identifier()) { |
361 | found = true; | ||
362 | } | ||
358 | } | 363 | } |
359 | } | 364 | QVERIFY(found); |
360 | QVERIFY(found); | 365 | }); |
366 | VERIFYEXEC(job); | ||
367 | } | ||
368 | |||
369 | //Ensure the folder is also existing | ||
370 | { | ||
371 | ApplicationDomain::Folder folder; | ||
372 | auto job = Store::fetchAll<ApplicationDomain::Folder>(Query::IdentityFilter(folderIdentifier)) | ||
373 | .then<void, QList<ApplicationDomain::Folder::Ptr> >([&](const QList<ApplicationDomain::Folder::Ptr> &folders) { | ||
374 | QCOMPARE(folders.size(), 1); | ||
375 | folder = *folders.first(); | ||
376 | }); | ||
377 | VERIFYEXEC(job); | ||
378 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::ExistenceInspection(folder, true))); | ||
379 | } | ||
380 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, true))); | ||
381 | } | ||
382 | |||
383 | void MailTest::testModifyMailToDraft() | ||
384 | { | ||
385 | if (!mCapabilities.contains(ResourceCapabilities::Mail::drafts)) { | ||
386 | QSKIP("Resource doesn't have the drafts capability"); | ||
387 | } | ||
388 | |||
389 | auto folder = Folder::create(mResourceInstanceIdentifier); | ||
390 | folder.setName("sdljldskjf"); | ||
391 | VERIFYEXEC(Store::create(folder)); | ||
392 | |||
393 | auto message = KMime::Message::Ptr::create(); | ||
394 | message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8"); | ||
395 | message->assemble(); | ||
396 | |||
397 | auto mail = ApplicationDomain::Mail::create(mResourceInstanceIdentifier); | ||
398 | mail.setMimeMessage(message->encodedContent()); | ||
399 | mail.setDraft(false); | ||
400 | mail.setFolder(folder); | ||
401 | |||
402 | VERIFYEXEC(Store::create(mail)); | ||
403 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); | ||
404 | |||
405 | ApplicationDomain::Mail modifiedMail; | ||
406 | { | ||
407 | auto job = Store::fetchOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail.identifier()) + Query::RequestedProperties(QByteArrayList() << Mail::MimeMessage::name << Mail::Folder::name)) | ||
408 | .then<void, ApplicationDomain::Mail>([&](const ApplicationDomain::Mail &mail) { | ||
409 | modifiedMail = mail; | ||
410 | }); | ||
411 | VERIFYEXEC(job); | ||
412 | } | ||
413 | modifiedMail.setDraft(true); | ||
414 | VERIFYEXEC(Store::modify(modifiedMail)); | ||
415 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); | ||
416 | VERIFYEXEC(ResourceControl::flushReplayQueue(QByteArrayList() << mResourceInstanceIdentifier)); | ||
417 | |||
418 | QByteArray folderIdentifier; | ||
419 | auto job = Store::fetchOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail.identifier()) + Query::RequestedProperties(QByteArrayList() << Mail::MimeMessage::name << Mail::Folder::name)) | ||
420 | .then<void, ApplicationDomain::Mail>([&](const ApplicationDomain::Mail &mail) { | ||
421 | folderIdentifier = mail.getProperty("folder").toByteArray(); | ||
422 | QVERIFY(!folderIdentifier.isEmpty()); | ||
361 | }); | 423 | }); |
362 | VERIFYEXEC(job2); | 424 | VERIFYEXEC(job); |
425 | |||
426 | //Ensure the folder is also existing | ||
427 | { | ||
428 | ApplicationDomain::Folder folder; | ||
429 | Query query; | ||
430 | query.ids << folderIdentifier; | ||
431 | query.request<Folder::SpecialPurpose>(); | ||
432 | auto job = Store::fetchAll<ApplicationDomain::Folder>(Query::IdentityFilter(folderIdentifier)) | ||
433 | .then<void, QList<ApplicationDomain::Folder::Ptr> >([&](const QList<ApplicationDomain::Folder::Ptr> &folders) { | ||
434 | QCOMPARE(folders.size(), 1); | ||
435 | folder = *folders.first(); | ||
436 | QVERIFY(folder.getSpecialPurpose().contains("drafts")); | ||
437 | }); | ||
438 | VERIFYEXEC(job); | ||
439 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::ExistenceInspection(folder, true))); | ||
440 | } | ||
441 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, true))); | ||
363 | } | 442 | } |
364 | 443 | ||
365 | #include "mailtest.moc" | 444 | #include "mailtest.moc" |