From 7744e638441fe93ee28bab80c2339e12a8f318d4 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 8 May 2016 14:03:44 +0200 Subject: Updated maildirresource test. --- tests/maildirresourcetest.cpp | 84 +++++++++++++++++++++++++++++++++++++++++-- 1 file 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 @@ #include "modelresult.h" #include "pipeline.h" #include "log.h" +#include "test.h" #define ASYNCCOMPARE(actual, expected) \ do {\ @@ -25,6 +26,8 @@ do {\ return KAsync::error(1, "Verify failed.");\ } while (0) +using namespace Sink; + static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath) { QFileInfo srcFileInfo(srcFilePath); @@ -105,7 +108,7 @@ private slots: auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); - QCOMPARE(model->rowCount(QModelIndex()), 2); + QCOMPARE(model->rowCount(QModelIndex()), 3); } void testListFolderTree() @@ -124,7 +127,7 @@ private slots: auto parentIndex = model->index(0, 0, QModelIndex()); model->fetchMore(parentIndex); QTRY_VERIFY(model->data(parentIndex, Sink::Store::ChildrenFetchedRole).toBool()); - QCOMPARE(model->rowCount(parentIndex), 1); + QCOMPARE(model->rowCount(parentIndex), 2); } void testListMailsOfFolder() @@ -193,7 +196,7 @@ private slots: auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); - QCOMPARE(model->rowCount(QModelIndex()), 2); + QCOMPARE(model->rowCount(QModelIndex()), 3); QCOMPARE(model->match(model->index(0, 0, QModelIndex()), Qt::DisplayRole, QStringLiteral("newbox"), 1).size(), 1); } @@ -321,6 +324,48 @@ private slots: QCOMPARE(m.subject(true)->asUnicodeString(), QString::fromLatin1("Foobar")); } + void testCreateMailInFolder() + { + auto query = Sink::Query::ResourceFilter("org.kde.maildir.instance1"); + + // Ensure all local data is processed + Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); + + auto folder = Sink::ApplicationDomain::ApplicationDomainType::createEntity("org.kde.maildir.instance1"); + folder.setProperty("name", "newfolder"); + + Sink::Store::create(folder).exec().waitForFinished(); + + auto message = KMime::Message::Ptr::create(); + message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8"); + message->assemble(); + + auto mail = Sink::ApplicationDomain::ApplicationDomainType::createEntity("org.kde.maildir.instance1"); + mail.setBlobProperty("mimeMessage", message->encodedContent()); + mail.setProperty("folder", folder); + + Sink::Store::create(mail).exec().waitForFinished(); + Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); + + auto future = Sink::Store::fetchOne(Query::IdentityFilter(mail.identifier()) + Query::RequestedProperties(QByteArrayList() << "mimeMessage" << "folder")) + .then([folder](const ApplicationDomain::Mail &mail) { + QCOMPARE(mail.getProperty("folder").toByteArray(), folder.identifier()); + }).exec(); + future.waitForFinished(); + if (future.errorCode()) { + qWarning() << future.errorCode() << future.errorMessage(); + } + QVERIFY(!future.errorCode()); + auto future2 = ResourceControl::inspect(ResourceControl::Inspection::ExistenceInspection(mail, false)).exec(); + future2.waitForFinished(); + QVERIFY(!future2.errorCode()); + + auto targetPath = tempDir.path() + "/maildir1/newfolder/new"; + QDir dir(targetPath); + dir.setFilter(QDir::Files); + QTRY_COMPARE(dir.count(), static_cast(1)); + } + void testRemoveMail() { using namespace Sink; @@ -399,6 +444,39 @@ private slots: result2.waitForFinished(); QVERIFY(!result2.errorCode()); } + + void testCreateDraft() + { + Sink::Query query; + query.resources << "org.kde.maildir.instance1"; + + Sink::Store::synchronize(query).exec().waitForFinished(); + // Ensure all local data is processed + Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); + + auto message = KMime::Message::Ptr::create(); + message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8"); + message->assemble(); + + auto mail = Sink::ApplicationDomain::ApplicationDomainType::createEntity("org.kde.maildir.instance1"); + mail.setBlobProperty("mimeMessage", message->encodedContent()); + mail.setProperty("draft", true); + + Sink::Store::create(mail).exec().waitForFinished(); + + // Ensure all local data is processed + Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); + + auto future = Sink::Store::fetchOne(Query::IdentityFilter(mail.identifier()) + Query::RequestedProperties(QByteArrayList() << "mimeMessage" << "folder")) + .then([](const ApplicationDomain::Mail &mail) { + QVERIFY(!mail.getProperty("folder").toByteArray().isEmpty()); + }).exec(); + future.waitForFinished(); + if (future.errorCode()) { + qWarning() << future.errorCode() << future.errorMessage(); + } + QVERIFY(!future.errorCode()); + } }; QTEST_MAIN(MaildirResourceTest) -- cgit v1.2.3