diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-25 10:21:36 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-25 10:21:36 +0200 |
commit | 7ed3ecd282516296bbc7e4a2a24d1e3266bd8601 (patch) | |
tree | f7c41bcf967a7daafeb70b5421f166db58ebbc3b | |
parent | 76892330fbf737cbdb09dc7bc4099418fc4cd1cc (diff) | |
download | sink-7ed3ecd282516296bbc7e4a2a24d1e3266bd8601.tar.gz sink-7ed3ecd282516296bbc7e4a2a24d1e3266bd8601.zip |
Maildir folder inspection
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 12 | ||||
-rw-r--r-- | tests/maildirresourcetest.cpp | 48 | ||||
-rw-r--r-- | 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<void> MaildirResource::inspect(int inspectionType, const QByteArray | |||
531 | } | 531 | } |
532 | if (domainType == ENTITY_TYPE_FOLDER) { | 532 | if (domainType == ENTITY_TYPE_FOLDER) { |
533 | const auto remoteId = resolveLocalId(ENTITY_TYPE_FOLDER, entityId, synchronizationTransaction); | 533 | const auto remoteId = resolveLocalId(ENTITY_TYPE_FOLDER, entityId, synchronizationTransaction); |
534 | auto mainDatabase = Sink::Storage::mainDatabase(transaction, ENTITY_TYPE_FOLDER); | ||
535 | auto bufferAdaptor = getLatest(mainDatabase, entityId, *mMailAdaptorFactory); | ||
536 | Q_ASSERT(bufferAdaptor); | ||
534 | 537 | ||
538 | const Sink::ApplicationDomain::Folder folder(mResourceInstanceIdentifier, entityId, 0, bufferAdaptor); | ||
535 | if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) { | 539 | if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) { |
536 | if (!QDir(remoteId).exists()) { | 540 | if (!QDir(remoteId).exists()) { |
537 | return KAsync::error<void>(1, "The directory is not existing: " + remoteId); | 541 | return KAsync::error<void>(1, "The directory is not existing: " + remoteId); |
@@ -551,6 +555,14 @@ KAsync::Job<void> MaildirResource::inspect(int inspectionType, const QByteArray | |||
551 | if (list.size() != expectedCount) { | 555 | if (list.size() != expectedCount) { |
552 | return KAsync::error<void>(1, QString("Wrong number of files; found %1 instead of %2.").arg(list.size()).arg(expectedCount)); | 556 | return KAsync::error<void>(1, QString("Wrong number of files; found %1 instead of %2.").arg(list.size()).arg(expectedCount)); |
553 | } | 557 | } |
558 | if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { | ||
559 | if (!remoteId.endsWith(folder.getName().toUtf8())) { | ||
560 | return KAsync::error<void>(1, "Wrong folder name: " + remoteId); | ||
561 | } | ||
562 | if (QDir(remoteId).exists() != expectedValue.toBool()) { | ||
563 | return KAsync::error<void>(1, "Wrong folder existence: " + remoteId); | ||
564 | } | ||
565 | } | ||
554 | } | 566 | } |
555 | } | 567 | } |
556 | return KAsync::null<void>(); | 568 | return KAsync::null<void>(); |
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: | |||
245 | QCOMPARE(mailModel->rowCount(QModelIndex()), 2); | 245 | QCOMPARE(mailModel->rowCount(QModelIndex()), 2); |
246 | } | 246 | } |
247 | 247 | ||
248 | void testCreateFolder() | ||
249 | { | ||
250 | Sink::Query query; | ||
251 | query.resources << "org.kde.maildir.instance1"; | ||
252 | |||
253 | // Ensure all local data is processed | ||
254 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
255 | |||
256 | Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); | ||
257 | folder.setProperty("name", "testCreateFolder"); | ||
258 | |||
259 | Sink::Store::create(folder).exec().waitForFinished(); | ||
260 | |||
261 | // Ensure all local data is processed | ||
262 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
263 | |||
264 | auto targetPath = tempDir.path() + "/maildir1/testCreateFolder"; | ||
265 | QFileInfo file(targetPath); | ||
266 | QTRY_VERIFY(file.exists()); | ||
267 | QVERIFY(file.isDir()); | ||
268 | } | ||
269 | |||
270 | void testRemoveFolder() | ||
271 | { | ||
272 | Sink::Query query; | ||
273 | query.resources << "org.kde.maildir.instance1"; | ||
274 | |||
275 | auto targetPath = tempDir.path() + "/maildir1/testCreateFolder"; | ||
276 | |||
277 | Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); | ||
278 | folder.setProperty("name", "testCreateFolder"); | ||
279 | Sink::Store::create(folder).exec().waitForFinished(); | ||
280 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
281 | QTRY_VERIFY(QFileInfo(targetPath).exists()); | ||
282 | |||
283 | Sink::Query folderQuery; | ||
284 | folderQuery.resources << "org.kde.maildir.instance1"; | ||
285 | folderQuery += Sink::Query::PropertyFilter("name", "testCreateFolder"); | ||
286 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(folderQuery); | ||
287 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
288 | QCOMPARE(model->rowCount(QModelIndex()), 1); | ||
289 | auto createdFolder = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Folder::Ptr>(); | ||
290 | |||
291 | Sink::Store::remove(*createdFolder).exec().waitForFinished(); | ||
292 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
293 | QTRY_VERIFY(!QFileInfo(targetPath).exists()); | ||
294 | } | ||
295 | |||
296 | }; | 248 | }; |
297 | 249 | ||
298 | QTEST_MAIN(MaildirResourceTest) | 250 | 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() | |||
95 | }); | 95 | }); |
96 | VERIFYEXEC(job); | 96 | VERIFYEXEC(job); |
97 | } | 97 | } |
98 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::ExistenceInspection(folder, true))); | ||
98 | 99 | ||
99 | QString name2 = "name2"; | 100 | QString name2 = "name2"; |
100 | QByteArray icon2 = "icon2"; | 101 | QByteArray icon2 = "icon2"; |
@@ -118,6 +119,7 @@ void MailTest::testCreateModifyDeleteFolder() | |||
118 | }); | 119 | }); |
119 | VERIFYEXEC(job); | 120 | VERIFYEXEC(job); |
120 | } | 121 | } |
122 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::ExistenceInspection(folder, true))); | ||
121 | 123 | ||
122 | VERIFYEXEC(Store::remove(folder)); | 124 | VERIFYEXEC(Store::remove(folder)); |
123 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); | 125 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); |
@@ -128,6 +130,7 @@ void MailTest::testCreateModifyDeleteFolder() | |||
128 | }); | 130 | }); |
129 | VERIFYEXEC(job); | 131 | VERIFYEXEC(job); |
130 | } | 132 | } |
133 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::ExistenceInspection(folder, false))); | ||
131 | } | 134 | } |
132 | 135 | ||
133 | void MailTest::testCreateModifyDeleteMail() | 136 | void MailTest::testCreateModifyDeleteMail() |