summaryrefslogtreecommitdiffstats
path: root/tests/maildirresourcetest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/maildirresourcetest.cpp')
-rw-r--r--tests/maildirresourcetest.cpp84
1 files changed, 81 insertions, 3 deletions
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp
index b91aef2..372ca5d 100644
--- a/tests/maildirresourcetest.cpp
+++ b/tests/maildirresourcetest.cpp
@@ -12,6 +12,7 @@
12#include "modelresult.h" 12#include "modelresult.h"
13#include "pipeline.h" 13#include "pipeline.h"
14#include "log.h" 14#include "log.h"
15#include "test.h"
15 16
16#define ASYNCCOMPARE(actual, expected) \ 17#define ASYNCCOMPARE(actual, expected) \
17do {\ 18do {\
@@ -25,6 +26,8 @@ do {\
25 return KAsync::error<void>(1, "Verify failed.");\ 26 return KAsync::error<void>(1, "Verify failed.");\
26} while (0) 27} while (0)
27 28
29using namespace Sink;
30
28static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath) 31static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath)
29{ 32{
30 QFileInfo srcFileInfo(srcFilePath); 33 QFileInfo srcFileInfo(srcFilePath);
@@ -105,7 +108,7 @@ private slots:
105 108
106 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 109 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
107 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 110 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
108 QCOMPARE(model->rowCount(QModelIndex()), 2); 111 QCOMPARE(model->rowCount(QModelIndex()), 3);
109 } 112 }
110 113
111 void testListFolderTree() 114 void testListFolderTree()
@@ -124,7 +127,7 @@ private slots:
124 auto parentIndex = model->index(0, 0, QModelIndex()); 127 auto parentIndex = model->index(0, 0, QModelIndex());
125 model->fetchMore(parentIndex); 128 model->fetchMore(parentIndex);
126 QTRY_VERIFY(model->data(parentIndex, Sink::Store::ChildrenFetchedRole).toBool()); 129 QTRY_VERIFY(model->data(parentIndex, Sink::Store::ChildrenFetchedRole).toBool());
127 QCOMPARE(model->rowCount(parentIndex), 1); 130 QCOMPARE(model->rowCount(parentIndex), 2);
128 } 131 }
129 132
130 void testListMailsOfFolder() 133 void testListMailsOfFolder()
@@ -193,7 +196,7 @@ private slots:
193 196
194 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 197 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
195 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 198 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
196 QCOMPARE(model->rowCount(QModelIndex()), 2); 199 QCOMPARE(model->rowCount(QModelIndex()), 3);
197 QCOMPARE(model->match(model->index(0, 0, QModelIndex()), Qt::DisplayRole, QStringLiteral("newbox"), 1).size(), 1); 200 QCOMPARE(model->match(model->index(0, 0, QModelIndex()), Qt::DisplayRole, QStringLiteral("newbox"), 1).size(), 1);
198 } 201 }
199 202
@@ -321,6 +324,48 @@ private slots:
321 QCOMPARE(m.subject(true)->asUnicodeString(), QString::fromLatin1("Foobar")); 324 QCOMPARE(m.subject(true)->asUnicodeString(), QString::fromLatin1("Foobar"));
322 } 325 }
323 326
327 void testCreateMailInFolder()
328 {
329 auto query = Sink::Query::ResourceFilter("org.kde.maildir.instance1");
330
331 // Ensure all local data is processed
332 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
333
334 auto folder = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Folder>("org.kde.maildir.instance1");
335 folder.setProperty("name", "newfolder");
336
337 Sink::Store::create(folder).exec().waitForFinished();
338
339 auto message = KMime::Message::Ptr::create();
340 message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8");
341 message->assemble();
342
343 auto mail = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Mail>("org.kde.maildir.instance1");
344 mail.setBlobProperty("mimeMessage", message->encodedContent());
345 mail.setProperty("folder", folder);
346
347 Sink::Store::create(mail).exec().waitForFinished();
348 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
349
350 auto future = Sink::Store::fetchOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail.identifier()) + Query::RequestedProperties(QByteArrayList() << "mimeMessage" << "folder"))
351 .then<void, ApplicationDomain::Mail>([folder](const ApplicationDomain::Mail &mail) {
352 QCOMPARE(mail.getProperty("folder").toByteArray(), folder.identifier());
353 }).exec();
354 future.waitForFinished();
355 if (future.errorCode()) {
356 qWarning() << future.errorCode() << future.errorMessage();
357 }
358 QVERIFY(!future.errorCode());
359 auto future2 = ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, false)).exec();
360 future2.waitForFinished();
361 QVERIFY(!future2.errorCode());
362
363 auto targetPath = tempDir.path() + "/maildir1/newfolder/new";
364 QDir dir(targetPath);
365 dir.setFilter(QDir::Files);
366 QTRY_COMPARE(dir.count(), static_cast<unsigned int>(1));
367 }
368
324 void testRemoveMail() 369 void testRemoveMail()
325 { 370 {
326 using namespace Sink; 371 using namespace Sink;
@@ -399,6 +444,39 @@ private slots:
399 result2.waitForFinished(); 444 result2.waitForFinished();
400 QVERIFY(!result2.errorCode()); 445 QVERIFY(!result2.errorCode());
401 } 446 }
447
448 void testCreateDraft()
449 {
450 Sink::Query query;
451 query.resources << "org.kde.maildir.instance1";
452
453 Sink::Store::synchronize(query).exec().waitForFinished();
454 // Ensure all local data is processed
455 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
456
457 auto message = KMime::Message::Ptr::create();
458 message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8");
459 message->assemble();
460
461 auto mail = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Mail>("org.kde.maildir.instance1");
462 mail.setBlobProperty("mimeMessage", message->encodedContent());
463 mail.setProperty("draft", true);
464
465 Sink::Store::create(mail).exec().waitForFinished();
466
467 // Ensure all local data is processed
468 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
469
470 auto future = Sink::Store::fetchOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail.identifier()) + Query::RequestedProperties(QByteArrayList() << "mimeMessage" << "folder"))
471 .then<void, ApplicationDomain::Mail>([](const ApplicationDomain::Mail &mail) {
472 QVERIFY(!mail.getProperty("folder").toByteArray().isEmpty());
473 }).exec();
474 future.waitForFinished();
475 if (future.errorCode()) {
476 qWarning() << future.errorCode() << future.errorMessage();
477 }
478 QVERIFY(!future.errorCode());
479 }
402}; 480};
403 481
404QTEST_MAIN(MaildirResourceTest) 482QTEST_MAIN(MaildirResourceTest)