From 9aa1cf3fb9bb380f6f069fc539b037bfd3d07030 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 19 Jan 2016 11:47:03 +0100 Subject: ExisteneceInspection --- common/inspection.h | 12 ++++++- examples/maildirresource/maildirresource.cpp | 6 ++++ tests/maildirresourcetest.cpp | 51 +++++++++++++++------------- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/common/inspection.h b/common/inspection.h index 45d599a..ecf5b3d 100644 --- a/common/inspection.h +++ b/common/inspection.h @@ -37,8 +37,18 @@ struct Inspection { return inspection; } + static Inspection ExistenceInspection(const Akonadi2::ApplicationDomain::Entity &entity, bool exists) + { + Inspection inspection; + inspection.resourceIdentifier = entity.resourceInstanceIdentifier(); + inspection.entityIdentifier = entity.identifier(); + inspection.expectedValue = exists; + return inspection; + } + enum Type { - PropertyInspectionType + PropertyInspectionType, + ExistenceInspectionType }; QByteArray resourceIdentifier; QByteArray entityIdentifier; diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 5d540be..9280bdc 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp @@ -312,6 +312,12 @@ KAsync::Job MaildirResource::inspect(int inspectionType, const QByteArray return KAsync::null(); } } + if (inspectionType == Akonadi2::Resources::Inspection::ExistenceInspectionType) { + const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); + if (QFileInfo(remoteId).exists() != expectedValue.toBool()) { + return KAsync::error(1, "Wrong file existence: " + remoteId); + } + } } return KAsync::null(); } diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp index 046c920..8952ff2 100644 --- a/tests/maildirresourcetest.cpp +++ b/tests/maildirresourcetest.cpp @@ -299,32 +299,37 @@ private Q_SLOTS: void testRemoveMail() { - Akonadi2::Query query; - query.resources << "org.kde.maildir.instance1"; - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - - Akonadi2::Query folderQuery; - folderQuery.resources << "org.kde.maildir.instance1"; - folderQuery.propertyFilter.insert("name", "maildir1"); - auto model = Akonadi2::Store::loadModel(folderQuery); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); - QCOMPARE(model->rowCount(QModelIndex()), 1); - auto folder = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + using namespace Akonadi2; + using namespace Akonadi2::ApplicationDomain; - Akonadi2::Query mailQuery; - mailQuery.resources << "org.kde.maildir.instance1"; - mailQuery.propertyFilter.insert("folder", folder->identifier()); - auto mailModel = Akonadi2::Store::loadModel(mailQuery); - QTRY_VERIFY(mailModel->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); - QCOMPARE(mailModel->rowCount(QModelIndex()), 1); - auto mail = mailModel->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + auto query = Query::ResourceFilter("org.kde.maildir.instance1"); + Store::synchronize(query).exec().waitForFinished(); + Store::flushMessageQueue(query.resources).exec().waitForFinished(); - Akonadi2::Store::remove(*mail).exec().waitForFinished(); - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + auto result = Store::fetchOne( + Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") + ) + .then, Folder>([query](const Folder &folder) { + return Store::fetchAll( + Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") + ) + .then, QList >([query](const QList &mails) { + //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE + if (mails.size() != 1) { + return KAsync::error(1, "Wrong number of mails."); + } + auto mail = mails.first(); - QTRY_COMPARE(QDir(tempDir.path() + "/maildir1/cur", QString(), QDir::NoSort, QDir::Files).count(), static_cast(0)); + auto inspectionCommand = Akonadi2::Resources::Inspection::ExistenceInspection(*mail, true); + return Store::remove(*mail) + .then(Store::flushMessageQueue(query.resources)) //The change needs to be replayed already + .then(Resources::inspect(inspectionCommand)); + }) + .then([](){}); + }) + .exec(); + result.waitForFinished(); + QVERIFY(!result.errorCode()); } void testMarkMailAsRead() -- cgit v1.2.3