diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-15 11:45:34 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-15 11:45:34 +0100 |
commit | 97fa1912a004c144ffb1392a6bfd0469e6047e3f (patch) | |
tree | 4c8fe4fedbf0aac3e098553f425bb44d796a4ac3 | |
parent | 78284e0963d93e3e0f85e2165013412580a3b8c1 (diff) | |
download | sink-97fa1912a004c144ffb1392a6bfd0469e6047e3f.tar.gz sink-97fa1912a004c144ffb1392a6bfd0469e6047e3f.zip |
Test markMailAsRead with all the new KAsync::Job stuff
-rw-r--r-- | tests/maildirresourcetest.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp index 3e07d93..c649536 100644 --- a/tests/maildirresourcetest.cpp +++ b/tests/maildirresourcetest.cpp | |||
@@ -327,6 +327,49 @@ private Q_SLOTS: | |||
327 | QTRY_COMPARE(QDir(tempDir.path() + "/maildir1/cur", QString(), QDir::NoSort, QDir::Files).count(), static_cast<unsigned int>(0)); | 327 | QTRY_COMPARE(QDir(tempDir.path() + "/maildir1/cur", QString(), QDir::NoSort, QDir::Files).count(), static_cast<unsigned int>(0)); |
328 | } | 328 | } |
329 | 329 | ||
330 | void testMarkMailAsRead() | ||
331 | { | ||
332 | using namespace Akonadi2; | ||
333 | using namespace Akonadi2::ApplicationDomain; | ||
334 | |||
335 | auto query = Query::ResourceFilter("org.kde.maildir.instance1"); | ||
336 | Akonadi2::Store::synchronize(query).exec().waitForFinished(); | ||
337 | Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
338 | |||
339 | auto result = Store::fetchOne<Folder>( | ||
340 | Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") | ||
341 | ) | ||
342 | .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) { | ||
343 | return Store::fetchAll<Mail>( | ||
344 | Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") | ||
345 | ) | ||
346 | .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([](const QList<Mail::Ptr> &mails) -> KAsync::Job<void> { | ||
347 | //Can't use QCOMPARE because it tries to return | ||
348 | if (mails.size() != 1) { | ||
349 | return KAsync::error<void>(1, "Wrong number of mails."); | ||
350 | } | ||
351 | auto mail = mails.first(); | ||
352 | mail->setProperty("unread", true); | ||
353 | return Akonadi2::Store::modify(*mail); | ||
354 | }) | ||
355 | .then<void>(Akonadi2::Store::flushMessageQueue(query.resources)) | ||
356 | .then<void, KAsync::Job<void> >([folder]() -> KAsync::Job<void> { | ||
357 | return Store::fetchAll<Mail>( | ||
358 | Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject" << "unread") | ||
359 | ) | ||
360 | .then<void, QList<Mail::Ptr> >([](const QList<Mail::Ptr> &mails) { | ||
361 | QCOMPARE(mails.size(), 1); | ||
362 | auto mail = mails.first(); | ||
363 | QCOMPARE(mail->getProperty("unread").toBool(), true); | ||
364 | }) | ||
365 | .then<void>([](){}); | ||
366 | }); | ||
367 | }) | ||
368 | .exec(); | ||
369 | result.waitForFinished(); | ||
370 | QVERIFY(!result.errorCode()); | ||
371 | } | ||
372 | |||
330 | }; | 373 | }; |
331 | 374 | ||
332 | QTEST_MAIN(MaildirResourceTest) | 375 | QTEST_MAIN(MaildirResourceTest) |