diff options
-rw-r--r-- | common/inspection.h | 12 | ||||
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 6 | ||||
-rw-r--r-- | 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 { | |||
37 | return inspection; | 37 | return inspection; |
38 | } | 38 | } |
39 | 39 | ||
40 | static Inspection ExistenceInspection(const Akonadi2::ApplicationDomain::Entity &entity, bool exists) | ||
41 | { | ||
42 | Inspection inspection; | ||
43 | inspection.resourceIdentifier = entity.resourceInstanceIdentifier(); | ||
44 | inspection.entityIdentifier = entity.identifier(); | ||
45 | inspection.expectedValue = exists; | ||
46 | return inspection; | ||
47 | } | ||
48 | |||
40 | enum Type { | 49 | enum Type { |
41 | PropertyInspectionType | 50 | PropertyInspectionType, |
51 | ExistenceInspectionType | ||
42 | }; | 52 | }; |
43 | QByteArray resourceIdentifier; | 53 | QByteArray resourceIdentifier; |
44 | QByteArray entityIdentifier; | 54 | 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<void> MaildirResource::inspect(int inspectionType, const QByteArray | |||
312 | return KAsync::null<void>(); | 312 | return KAsync::null<void>(); |
313 | } | 313 | } |
314 | } | 314 | } |
315 | if (inspectionType == Akonadi2::Resources::Inspection::ExistenceInspectionType) { | ||
316 | const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); | ||
317 | if (QFileInfo(remoteId).exists() != expectedValue.toBool()) { | ||
318 | return KAsync::error<void>(1, "Wrong file existence: " + remoteId); | ||
319 | } | ||
320 | } | ||
315 | } | 321 | } |
316 | return KAsync::null<void>(); | 322 | return KAsync::null<void>(); |
317 | } | 323 | } |
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: | |||
299 | 299 | ||
300 | void testRemoveMail() | 300 | void testRemoveMail() |
301 | { | 301 | { |
302 | Akonadi2::Query query; | 302 | using namespace Akonadi2; |
303 | query.resources << "org.kde.maildir.instance1"; | 303 | using namespace Akonadi2::ApplicationDomain; |
304 | Akonadi2::Store::synchronize(query).exec().waitForFinished(); | ||
305 | Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
306 | |||
307 | Akonadi2::Query folderQuery; | ||
308 | folderQuery.resources << "org.kde.maildir.instance1"; | ||
309 | folderQuery.propertyFilter.insert("name", "maildir1"); | ||
310 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(folderQuery); | ||
311 | QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); | ||
312 | QCOMPARE(model->rowCount(QModelIndex()), 1); | ||
313 | auto folder = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value<Akonadi2::ApplicationDomain::Folder::Ptr>(); | ||
314 | 304 | ||
315 | Akonadi2::Query mailQuery; | 305 | auto query = Query::ResourceFilter("org.kde.maildir.instance1"); |
316 | mailQuery.resources << "org.kde.maildir.instance1"; | 306 | Store::synchronize(query).exec().waitForFinished(); |
317 | mailQuery.propertyFilter.insert("folder", folder->identifier()); | 307 | Store::flushMessageQueue(query.resources).exec().waitForFinished(); |
318 | auto mailModel = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(mailQuery); | ||
319 | QTRY_VERIFY(mailModel->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); | ||
320 | QCOMPARE(mailModel->rowCount(QModelIndex()), 1); | ||
321 | auto mail = mailModel->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value<Akonadi2::ApplicationDomain::Mail::Ptr>(); | ||
322 | 308 | ||
323 | Akonadi2::Store::remove(*mail).exec().waitForFinished(); | 309 | auto result = Store::fetchOne<Folder>( |
324 | Akonadi2::Store::synchronize(query).exec().waitForFinished(); | 310 | Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") |
325 | Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); | 311 | ) |
312 | .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) { | ||
313 | return Store::fetchAll<Mail>( | ||
314 | Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") | ||
315 | ) | ||
316 | .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) { | ||
317 | //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE | ||
318 | if (mails.size() != 1) { | ||
319 | return KAsync::error<void>(1, "Wrong number of mails."); | ||
320 | } | ||
321 | auto mail = mails.first(); | ||
326 | 322 | ||
327 | QTRY_COMPARE(QDir(tempDir.path() + "/maildir1/cur", QString(), QDir::NoSort, QDir::Files).count(), static_cast<unsigned int>(0)); | 323 | auto inspectionCommand = Akonadi2::Resources::Inspection::ExistenceInspection(*mail, true); |
324 | return Store::remove(*mail) | ||
325 | .then(Store::flushMessageQueue(query.resources)) //The change needs to be replayed already | ||
326 | .then(Resources::inspect<Mail>(inspectionCommand)); | ||
327 | }) | ||
328 | .then<void>([](){}); | ||
329 | }) | ||
330 | .exec(); | ||
331 | result.waitForFinished(); | ||
332 | QVERIFY(!result.errorCode()); | ||
328 | } | 333 | } |
329 | 334 | ||
330 | void testMarkMailAsRead() | 335 | void testMarkMailAsRead() |