From 7ed3ecd282516296bbc7e4a2a24d1e3266bd8601 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 25 May 2016 10:21:36 +0200 Subject: Maildir folder inspection --- examples/maildirresource/maildirresource.cpp | 12 +++++++ tests/maildirresourcetest.cpp | 48 ---------------------------- tests/mailtest.cpp | 3 ++ 3 files changed, 15 insertions(+), 48 deletions(-) diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 6dc9990..e1e4d95 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp @@ -531,7 +531,11 @@ KAsync::Job MaildirResource::inspect(int inspectionType, const QByteArray } if (domainType == ENTITY_TYPE_FOLDER) { const auto remoteId = resolveLocalId(ENTITY_TYPE_FOLDER, entityId, synchronizationTransaction); + auto mainDatabase = Sink::Storage::mainDatabase(transaction, ENTITY_TYPE_FOLDER); + auto bufferAdaptor = getLatest(mainDatabase, entityId, *mMailAdaptorFactory); + Q_ASSERT(bufferAdaptor); + const Sink::ApplicationDomain::Folder folder(mResourceInstanceIdentifier, entityId, 0, bufferAdaptor); if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) { if (!QDir(remoteId).exists()) { return KAsync::error(1, "The directory is not existing: " + remoteId); @@ -551,6 +555,14 @@ KAsync::Job MaildirResource::inspect(int inspectionType, const QByteArray if (list.size() != expectedCount) { return KAsync::error(1, QString("Wrong number of files; found %1 instead of %2.").arg(list.size()).arg(expectedCount)); } + if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { + if (!remoteId.endsWith(folder.getName().toUtf8())) { + return KAsync::error(1, "Wrong folder name: " + remoteId); + } + if (QDir(remoteId).exists() != expectedValue.toBool()) { + return KAsync::error(1, "Wrong folder existence: " + remoteId); + } + } } } return KAsync::null(); diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp index 46d2a28..0a32000 100644 --- a/tests/maildirresourcetest.cpp +++ b/tests/maildirresourcetest.cpp @@ -245,54 +245,6 @@ private slots: QCOMPARE(mailModel->rowCount(QModelIndex()), 2); } - void testCreateFolder() - { - Sink::Query query; - query.resources << "org.kde.maildir.instance1"; - - // Ensure all local data is processed - Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - - Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); - folder.setProperty("name", "testCreateFolder"); - - Sink::Store::create(folder).exec().waitForFinished(); - - // Ensure all local data is processed - Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - - auto targetPath = tempDir.path() + "/maildir1/testCreateFolder"; - QFileInfo file(targetPath); - QTRY_VERIFY(file.exists()); - QVERIFY(file.isDir()); - } - - void testRemoveFolder() - { - Sink::Query query; - query.resources << "org.kde.maildir.instance1"; - - auto targetPath = tempDir.path() + "/maildir1/testCreateFolder"; - - Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); - folder.setProperty("name", "testCreateFolder"); - Sink::Store::create(folder).exec().waitForFinished(); - Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - QTRY_VERIFY(QFileInfo(targetPath).exists()); - - Sink::Query folderQuery; - folderQuery.resources << "org.kde.maildir.instance1"; - folderQuery += Sink::Query::PropertyFilter("name", "testCreateFolder"); - auto model = Sink::Store::loadModel(folderQuery); - QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); - QCOMPARE(model->rowCount(QModelIndex()), 1); - auto createdFolder = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); - - Sink::Store::remove(*createdFolder).exec().waitForFinished(); - Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - QTRY_VERIFY(!QFileInfo(targetPath).exists()); - } - }; QTEST_MAIN(MaildirResourceTest) diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp index e47c3eb..532896b 100644 --- a/tests/mailtest.cpp +++ b/tests/mailtest.cpp @@ -95,6 +95,7 @@ void MailTest::testCreateModifyDeleteFolder() }); VERIFYEXEC(job); } + VERIFYEXEC(ResourceControl::inspect(ResourceControl::Inspection::ExistenceInspection(folder, true))); QString name2 = "name2"; QByteArray icon2 = "icon2"; @@ -118,6 +119,7 @@ void MailTest::testCreateModifyDeleteFolder() }); VERIFYEXEC(job); } + VERIFYEXEC(ResourceControl::inspect(ResourceControl::Inspection::ExistenceInspection(folder, true))); VERIFYEXEC(Store::remove(folder)); VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); @@ -128,6 +130,7 @@ void MailTest::testCreateModifyDeleteFolder() }); VERIFYEXEC(job); } + VERIFYEXEC(ResourceControl::inspect(ResourceControl::Inspection::ExistenceInspection(folder, false))); } void MailTest::testCreateModifyDeleteMail() -- cgit v1.2.3