diff options
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 2 | ||||
-rw-r--r-- | examples/maildirresource/CMakeLists.txt | 2 | ||||
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 8 | ||||
-rw-r--r-- | examples/maildirresource/tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | examples/maildirresource/tests/data/maildir1/test/cur/1365777830.R28.localhost.localdomain:2,S | 72 | ||||
-rw-r--r-- | examples/maildirresource/tests/maildirmailsynctest.cpp | 132 | ||||
-rw-r--r-- | tests/mailsynctest.cpp | 141 | ||||
-rw-r--r-- | tests/mailsynctest.h | 20 |
8 files changed, 343 insertions, 36 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 7d8ab48..1e111ec 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -267,7 +267,7 @@ namespace ImapResource { | |||
267 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); | 267 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); |
268 | resource.setProperty("type", "org.kde.imap"); | 268 | resource.setProperty("type", "org.kde.imap"); |
269 | resource.setProperty("account", account); | 269 | resource.setProperty("account", account); |
270 | resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << "storage")); | 270 | resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << "storage" << "folder.hierarchy")); |
271 | return resource; | 271 | return resource; |
272 | } | 272 | } |
273 | } | 273 | } |
diff --git a/examples/maildirresource/CMakeLists.txt b/examples/maildirresource/CMakeLists.txt index 3a1430c..e4d113c 100644 --- a/examples/maildirresource/CMakeLists.txt +++ b/examples/maildirresource/CMakeLists.txt | |||
@@ -11,5 +11,7 @@ target_link_libraries(${PROJECT_NAME} sink maildir KF5::Mime) | |||
11 | 11 | ||
12 | install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${SINK_RESOURCE_PLUGINS_PATH}) | 12 | install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${SINK_RESOURCE_PLUGINS_PATH}) |
13 | 13 | ||
14 | add_definitions(-DTESTDATAPATH="${CMAKE_CURRENT_SOURCE_DIR}/tests/data") | ||
15 | |||
14 | add_subdirectory(libmaildir) | 16 | add_subdirectory(libmaildir) |
15 | add_subdirectory(tests) | 17 | add_subdirectory(tests) |
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index ca20fa3..268f506 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -373,7 +373,11 @@ public: | |||
373 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE | 373 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE |
374 | { | 374 | { |
375 | Log() << " Synchronizing"; | 375 | Log() << " Synchronizing"; |
376 | return KAsync::start<void>([this]() { | 376 | return KAsync::start<void, KAsync::Job<void> >([this]() { |
377 | KPIM::Maildir maildir(mMaildirPath, true); | ||
378 | if (!maildir.isValid(false)) { | ||
379 | return KAsync::error<void>(1, "Maildir path doesn't point to a valid maildir: " + mMaildirPath); | ||
380 | } | ||
377 | synchronizeFolders(); | 381 | synchronizeFolders(); |
378 | //The next sync needs the folders available | 382 | //The next sync needs the folders available |
379 | commit(); | 383 | commit(); |
@@ -385,6 +389,7 @@ public: | |||
385 | commitSync(); | 389 | commitSync(); |
386 | } | 390 | } |
387 | Log() << "Done Synchronizing"; | 391 | Log() << "Done Synchronizing"; |
392 | return KAsync::null<void>(); | ||
388 | }); | 393 | }); |
389 | } | 394 | } |
390 | 395 | ||
@@ -410,7 +415,6 @@ public: | |||
410 | }); | 415 | }); |
411 | } else if (operation == Sink::Operation_Removal) { | 416 | } else if (operation == Sink::Operation_Removal) { |
412 | Trace() << "Removing a mail: " << oldRemoteId; | 417 | Trace() << "Removing a mail: " << oldRemoteId; |
413 | // QFile::remove(oldRemoteId); | ||
414 | return KAsync::null<QByteArray>(); | 418 | return KAsync::null<QByteArray>(); |
415 | } else if (operation == Sink::Operation_Modification) { | 419 | } else if (operation == Sink::Operation_Modification) { |
416 | Trace() << "Modifying a mail: " << oldRemoteId; | 420 | Trace() << "Modifying a mail: " << oldRemoteId; |
diff --git a/examples/maildirresource/tests/CMakeLists.txt b/examples/maildirresource/tests/CMakeLists.txt index ffe9286..d6f0fe7 100644 --- a/examples/maildirresource/tests/CMakeLists.txt +++ b/examples/maildirresource/tests/CMakeLists.txt | |||
@@ -7,5 +7,7 @@ include(SinkTest) | |||
7 | 7 | ||
8 | auto_tests ( | 8 | auto_tests ( |
9 | maildirmailtest | 9 | maildirmailtest |
10 | maildirmailsynctest | ||
10 | ) | 11 | ) |
11 | target_link_libraries(maildirmailtest sink_resource_maildir) | 12 | target_link_libraries(maildirmailtest sink_resource_maildir) |
13 | target_link_libraries(maildirmailsynctest sink_resource_maildir) | ||
diff --git a/examples/maildirresource/tests/data/maildir1/test/cur/1365777830.R28.localhost.localdomain:2,S b/examples/maildirresource/tests/data/maildir1/test/cur/1365777830.R28.localhost.localdomain:2,S new file mode 100644 index 0000000..91231b5 --- /dev/null +++ b/examples/maildirresource/tests/data/maildir1/test/cur/1365777830.R28.localhost.localdomain:2,S | |||
@@ -0,0 +1,72 @@ | |||
1 | Return-Path: <nepomuk-bounces@kde.org> | ||
2 | Received: from compute4.internal (compute4.nyi.mail.srv.osa [10.202.2.44]) | ||
3 | by slots3a1p1 (Cyrus git2.5+0-git-fastmail-8998) with LMTPA; | ||
4 | Mon, 11 Mar 2013 14:28:42 -0400 | ||
5 | X-Sieve: CMU Sieve 2.4 | ||
6 | X-Spam-score: 0.0 | ||
7 | X-Spam-hits: BAYES_00 -1.9, RCVD_IN_DNSWL_MED -2.3, RP_MATCHES_RCVD -0.704, | ||
8 | LANGUAGES unknown, BAYES_USED global, SA_VERSION 3.3.1 | ||
9 | X-Spam-source: IP='46.4.96.248', Host='postbox.kde.org', Country='unk', FromHeader='org', | ||
10 | MailFrom='org' | ||
11 | X-Spam-charsets: plain='us-ascii' | ||
12 | X-Resolved-to: chrigi_1@fastmail.fm | ||
13 | X-Delivered-to: chrigi_1@fastmail.fm | ||
14 | X-Mail-from: nepomuk-bounces@kde.org | ||
15 | Received: from mx4.nyi.mail.srv.osa ([10.202.2.203]) | ||
16 | by compute4.internal (LMTPProxy); Mon, 11 Mar 2013 14:28:42 -0400 | ||
17 | Received: from postbox.kde.org (postbox.kde.org [46.4.96.248]) | ||
18 | by mx4.messagingengine.com (Postfix) with ESMTP id 1C9D2440F88 | ||
19 | for <chrigi_1@fastmail.fm>; Mon, 11 Mar 2013 14:28:42 -0400 (EDT) | ||
20 | Received: from postbox.kde.org (localhost [IPv6:::1]) | ||
21 | by postbox.kde.org (Postfix) with ESMTP id 00FFEB3732B; | ||
22 | Mon, 11 Mar 2013 18:28:40 +0000 (UTC) | ||
23 | DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=kde.org; s=default; | ||
24 | t=1363026520; bh=cOdvyBAJJ8ho64q0H7rxkl+cB2y6TiyVOX0fO3yZ64U=; | ||
25 | h=Date:From:To:Message-ID:In-Reply-To:References:MIME-Version: | ||
26 | Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help: | ||
27 | List-Subscribe:Content-Type:Content-Transfer-Encoding:Sender; b=dv | ||
28 | dJAFu+6JCuNun5WIuP4ysfKpLh0DeuhEEfy2cQavUGMICJ27k7tI73x6gN37V5Q/evJ | ||
29 | NDFna3/IhNBsAQeLiXs28HKxzcVhbnq5jdFR6fbyo6k1fOKt5vTT1GTDZ+3zIGPD1CU | ||
30 | ioDBGxPb/Ds6gee90tjadOj6o+Oc+2ZSq94= | ||
31 | X-Original-To: nepomuk@kde.org | ||
32 | X-Remote-Delivered-To: nepomuk@localhost.kde.org | ||
33 | Received: from build.kde.org (build.kde.org [IPv6:2a01:4f8:160:9363::5]) | ||
34 | by postbox.kde.org (Postfix) with ESMTP id 4491CB3732B | ||
35 | for <nepomuk@kde.org>; Mon, 11 Mar 2013 18:28:27 +0000 (UTC) | ||
36 | Received: from localhost ([127.0.0.1]) by build.kde.org with esmtp (Exim 4.72) | ||
37 | (envelope-from <null@kde.org>) id 1UF7SV-0000gs-11 | ||
38 | for nepomuk@kde.org; Mon, 11 Mar 2013 18:28:27 +0000 | ||
39 | Date: Mon, 11 Mar 2013 18:28:27 +0000 (UTC) | ||
40 | From: KDE CI System <null@kde.org> | ||
41 | To: nepomuk@kde.org | ||
42 | Message-ID: <1977027405.27.1363026507008.JavaMail.jenkins@build> | ||
43 | In-Reply-To: <880663748.26.1363026023717.JavaMail.jenkins@build> | ||
44 | References: <880663748.26.1363026023717.JavaMail.jenkins@build> | ||
45 | MIME-Version: 1.0 | ||
46 | X-Jenkins-Job: nepomuk-core_stable | ||
47 | X-Jenkins-Result: UNSTABLE | ||
48 | X-Scanned-By: MIMEDefang 2.71 on 46.4.96.248 | ||
49 | Subject: [Nepomuk] Jenkins build is still unstable: nepomuk-core_stable #158 | ||
50 | X-BeenThere: nepomuk@kde.org | ||
51 | X-Mailman-Version: 2.1.14 | ||
52 | Precedence: list | ||
53 | List-Id: The Semantic KDE <nepomuk.kde.org> | ||
54 | List-Unsubscribe: <https://mail.kde.org/mailman/options/nepomuk>, | ||
55 | <mailto:nepomuk-request@kde.org?subject=unsubscribe> | ||
56 | List-Archive: <http://mail.kde.org/pipermail/nepomuk> | ||
57 | List-Post: <mailto:nepomuk@kde.org> | ||
58 | List-Help: <mailto:nepomuk-request@kde.org?subject=help> | ||
59 | List-Subscribe: <https://mail.kde.org/mailman/listinfo/nepomuk>, | ||
60 | <mailto:nepomuk-request@kde.org?subject=subscribe> | ||
61 | Content-Type: text/plain; charset="us-ascii" | ||
62 | Content-Transfer-Encoding: 7bit | ||
63 | Errors-To: nepomuk-bounces@kde.org | ||
64 | Sender: nepomuk-bounces@kde.org | ||
65 | X-Truedomain: NotChecked | ||
66 | |||
67 | See <http://build.kde.org/job/nepomuk-core_stable/changes> | ||
68 | |||
69 | _______________________________________________ | ||
70 | Nepomuk mailing list | ||
71 | Nepomuk@kde.org | ||
72 | https://mail.kde.org/mailman/listinfo/nepomuk | ||
diff --git a/examples/maildirresource/tests/maildirmailsynctest.cpp b/examples/maildirresource/tests/maildirmailsynctest.cpp new file mode 100644 index 0000000..444fb42 --- /dev/null +++ b/examples/maildirresource/tests/maildirmailsynctest.cpp | |||
@@ -0,0 +1,132 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | #include <QtTest> | ||
20 | |||
21 | #include <tests/mailsynctest.h> | ||
22 | #include "../maildirresource.h" | ||
23 | #include "../libmaildir/maildir.h" | ||
24 | |||
25 | #include "common/test.h" | ||
26 | #include "common/domain/applicationdomaintype.h" | ||
27 | |||
28 | using namespace Sink; | ||
29 | using namespace Sink::ApplicationDomain; | ||
30 | |||
31 | static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath) | ||
32 | { | ||
33 | QFileInfo srcFileInfo(srcFilePath); | ||
34 | if (srcFileInfo.isDir()) { | ||
35 | QDir targetDir(tgtFilePath); | ||
36 | targetDir.cdUp(); | ||
37 | if (!targetDir.mkdir(QFileInfo(srcFilePath).fileName())) { | ||
38 | qWarning() << "Failed to create directory " << tgtFilePath; | ||
39 | return false; | ||
40 | } | ||
41 | QDir sourceDir(srcFilePath); | ||
42 | QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System); | ||
43 | foreach (const QString &fileName, fileNames) { | ||
44 | const QString newSrcFilePath = srcFilePath + QLatin1Char('/') + fileName; | ||
45 | const QString newTgtFilePath = tgtFilePath + QLatin1Char('/') + fileName; | ||
46 | if (!copyRecursively(newSrcFilePath, newTgtFilePath)) | ||
47 | return false; | ||
48 | } | ||
49 | } else { | ||
50 | if (!QFile::copy(srcFilePath, tgtFilePath)) { | ||
51 | qWarning() << "Failed to copy file " << tgtFilePath; | ||
52 | return false; | ||
53 | } | ||
54 | } | ||
55 | return true; | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | * Test of complete system using the maildir resource. | ||
60 | * | ||
61 | * This test requires the maildir resource installed. | ||
62 | */ | ||
63 | class MaildirMailSyncTest : public Sink::MailSyncTest | ||
64 | { | ||
65 | Q_OBJECT | ||
66 | |||
67 | QTemporaryDir tempDir; | ||
68 | QString targetPath; | ||
69 | |||
70 | protected: | ||
71 | void resetTestEnvironment() Q_DECL_OVERRIDE | ||
72 | { | ||
73 | targetPath = tempDir.path() + "/maildir1/"; | ||
74 | QDir dir(targetPath); | ||
75 | dir.removeRecursively(); | ||
76 | copyRecursively(TESTDATAPATH "/maildir1", targetPath); | ||
77 | } | ||
78 | |||
79 | Sink::ApplicationDomain::SinkResource createResource() Q_DECL_OVERRIDE | ||
80 | { | ||
81 | auto resource = ApplicationDomain::MaildirResource::create("account1"); | ||
82 | resource.setProperty("path", targetPath); | ||
83 | return resource; | ||
84 | } | ||
85 | |||
86 | Sink::ApplicationDomain::SinkResource createFaultyResource() Q_DECL_OVERRIDE | ||
87 | { | ||
88 | auto resource = ApplicationDomain::MaildirResource::create("account1"); | ||
89 | resource.setProperty("path", ""); | ||
90 | return resource; | ||
91 | } | ||
92 | |||
93 | void removeResourceFromDisk(const QByteArray &identifier) Q_DECL_OVERRIDE | ||
94 | { | ||
95 | ::MaildirResource::removeFromDisk(identifier); | ||
96 | } | ||
97 | |||
98 | void createFolder(const QStringList &folderPath) Q_DECL_OVERRIDE | ||
99 | { | ||
100 | auto rootPath = tempDir.path() + "/maildir1/"; | ||
101 | KPIM::Maildir maildir(rootPath + folderPath.join('/'), false); | ||
102 | maildir.create(); | ||
103 | } | ||
104 | |||
105 | void removeFolder(const QStringList &folderPath) Q_DECL_OVERRIDE | ||
106 | { | ||
107 | auto rootPath = tempDir.path() + "/maildir1/"; | ||
108 | KPIM::Maildir maildir(rootPath + folderPath.join('/'), false); | ||
109 | maildir.remove(); | ||
110 | QDir dir(rootPath + folderPath.join('/')); | ||
111 | dir.removeRecursively(); | ||
112 | // QVERIFY(maildir.removeSubFolder(name)); | ||
113 | } | ||
114 | |||
115 | QByteArray createMessage(const QStringList &folderPath, const QByteArray &message) Q_DECL_OVERRIDE | ||
116 | { | ||
117 | auto rootPath = tempDir.path() + "/maildir1/"; | ||
118 | KPIM::Maildir maildir(rootPath + folderPath.join('/')); | ||
119 | return maildir.addEntry(message).toUtf8(); | ||
120 | } | ||
121 | |||
122 | void removeMessage(const QStringList &folderPath, const QByteArray &messageIdentifier) Q_DECL_OVERRIDE | ||
123 | { | ||
124 | auto rootPath = tempDir.path() + "/maildir1/"; | ||
125 | KPIM::Maildir maildir(rootPath + folderPath.join('/')); | ||
126 | maildir.removeEntry(messageIdentifier); | ||
127 | } | ||
128 | }; | ||
129 | |||
130 | QTEST_MAIN(MaildirMailSyncTest) | ||
131 | |||
132 | #include "maildirmailsynctest.moc" | ||
diff --git a/tests/mailsynctest.cpp b/tests/mailsynctest.cpp index b86fbae..2fc8568 100644 --- a/tests/mailsynctest.cpp +++ b/tests/mailsynctest.cpp | |||
@@ -47,6 +47,7 @@ void MailSyncTest::initTestCase() | |||
47 | 47 | ||
48 | void MailSyncTest::cleanup() | 48 | void MailSyncTest::cleanup() |
49 | { | 49 | { |
50 | //TODO the shutdown job fails if the resource is already shut down | ||
50 | // VERIFYEXEC(ResourceControl::shutdown(mResourceInstanceIdentifier)); | 51 | // VERIFYEXEC(ResourceControl::shutdown(mResourceInstanceIdentifier)); |
51 | ResourceControl::shutdown(mResourceInstanceIdentifier).exec().waitForFinished(); | 52 | ResourceControl::shutdown(mResourceInstanceIdentifier).exec().waitForFinished(); |
52 | removeResourceFromDisk(mResourceInstanceIdentifier); | 53 | removeResourceFromDisk(mResourceInstanceIdentifier); |
@@ -62,6 +63,21 @@ void MailSyncTest::init() | |||
62 | 63 | ||
63 | void MailSyncTest::testListFolders() | 64 | void MailSyncTest::testListFolders() |
64 | { | 65 | { |
66 | int baseCount = 0; | ||
67 | //First figure out how many folders we have by default | ||
68 | { | ||
69 | auto job = Store::fetchAll<Folder>(Query()) | ||
70 | .then<void, QList<Folder::Ptr>>([&](const QList<Folder::Ptr> &folders) { | ||
71 | QStringList names; | ||
72 | for (const auto &folder : folders) { | ||
73 | names << folder->getName(); | ||
74 | } | ||
75 | Trace() << "base folder: " << names; | ||
76 | baseCount = folders.size(); | ||
77 | }); | ||
78 | VERIFYEXEC(job); | ||
79 | } | ||
80 | |||
65 | Sink::Query query; | 81 | Sink::Query query; |
66 | query.resources << mResourceInstanceIdentifier; | 82 | query.resources << mResourceInstanceIdentifier; |
67 | query.request<Folder::Name>(); | 83 | query.request<Folder::Name>(); |
@@ -70,20 +86,78 @@ void MailSyncTest::testListFolders() | |||
70 | VERIFYEXEC(Store::synchronize(query)); | 86 | VERIFYEXEC(Store::synchronize(query)); |
71 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 87 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
72 | 88 | ||
73 | auto job = Store::fetchAll<Folder>(query).then<void, QList<Folder::Ptr>>([](const QList<Folder::Ptr> &folders) { | 89 | auto job = Store::fetchAll<Folder>(query).then<void, QList<Folder::Ptr>>([=](const QList<Folder::Ptr> &folders) { |
74 | QCOMPARE(folders.size(), 2); | ||
75 | QStringList names; | 90 | QStringList names; |
76 | for (const auto &folder : folders) { | 91 | for (const auto &folder : folders) { |
77 | names << folder->getName(); | 92 | names << folder->getName(); |
78 | } | 93 | } |
94 | //Workaround for maildir | ||
95 | if (names.contains("maildir1")) { | ||
96 | names.removeAll("maildir1"); | ||
97 | } | ||
98 | if (mCapabilities.contains("drafts")) { | ||
99 | QVERIFY(names.contains("drafts")); | ||
100 | names.removeAll("drafts"); | ||
101 | } | ||
102 | QCOMPARE(names.size(), 2); | ||
79 | QVERIFY(names.contains("INBOX")); | 103 | QVERIFY(names.contains("INBOX")); |
80 | QVERIFY(names.contains("test")); | 104 | QVERIFY(names.contains("test")); |
81 | }); | 105 | }); |
82 | VERIFYEXEC(job); | 106 | VERIFYEXEC(job); |
83 | } | 107 | } |
84 | 108 | ||
109 | void MailSyncTest::testListNewFolder() | ||
110 | { | ||
111 | Sink::Query query; | ||
112 | query.resources << mResourceInstanceIdentifier; | ||
113 | query.request<Folder::Name>(); | ||
114 | |||
115 | createFolder(QStringList() << "test2"); | ||
116 | |||
117 | // Ensure all local data is processed | ||
118 | VERIFYEXEC(Store::synchronize(query)); | ||
119 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
120 | |||
121 | auto job = Store::fetchAll<Folder>(query).then<void, QList<Folder::Ptr>>([](const QList<Folder::Ptr> &folders) { | ||
122 | QStringList names; | ||
123 | for (const auto &folder : folders) { | ||
124 | names << folder->getName(); | ||
125 | } | ||
126 | QVERIFY(names.contains("test2")); | ||
127 | }); | ||
128 | VERIFYEXEC(job); | ||
129 | } | ||
130 | |||
131 | void MailSyncTest::testListRemovedFolder() | ||
132 | { | ||
133 | Sink::Query query; | ||
134 | query.resources << mResourceInstanceIdentifier; | ||
135 | query.request<Folder::Name>(); | ||
136 | |||
137 | VERIFYEXEC(Store::synchronize(query)); | ||
138 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
139 | |||
140 | removeFolder(QStringList() << "test2"); | ||
141 | |||
142 | // Ensure all local data is processed | ||
143 | VERIFYEXEC(Store::synchronize(query)); | ||
144 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
145 | |||
146 | auto job = Store::fetchAll<Folder>(query).then<void, QList<Folder::Ptr>>([](const QList<Folder::Ptr> &folders) { | ||
147 | QStringList names; | ||
148 | for (const auto &folder : folders) { | ||
149 | names << folder->getName(); | ||
150 | } | ||
151 | QVERIFY(!names.contains("test2")); | ||
152 | }); | ||
153 | VERIFYEXEC(job); | ||
154 | } | ||
155 | |||
85 | void MailSyncTest::testListFolderHierarchy() | 156 | void MailSyncTest::testListFolderHierarchy() |
86 | { | 157 | { |
158 | if (!mCapabilities.contains("folder.hierarchy")) { | ||
159 | QSKIP("Missing capability folder.hierarchy"); | ||
160 | } | ||
87 | Sink::Query query; | 161 | Sink::Query query; |
88 | query.resources << mResourceInstanceIdentifier; | 162 | query.resources << mResourceInstanceIdentifier; |
89 | query.request<Folder::Name>().request<Folder::Parent>(); | 163 | query.request<Folder::Name>().request<Folder::Parent>(); |
@@ -94,19 +168,35 @@ void MailSyncTest::testListFolderHierarchy() | |||
94 | VERIFYEXEC(Store::synchronize(query)); | 168 | VERIFYEXEC(Store::synchronize(query)); |
95 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 169 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
96 | 170 | ||
97 | auto job = Store::fetchAll<Folder>(query).then<void, QList<Folder::Ptr>>([](const QList<Folder::Ptr> &folders) { | 171 | auto job = Store::fetchAll<Folder>(query).then<void, QList<Folder::Ptr>>([=](const QList<Folder::Ptr> &folders) { |
98 | QCOMPARE(folders.size(), 3); | ||
99 | QHash<QString, Folder::Ptr> map; | 172 | QHash<QString, Folder::Ptr> map; |
100 | for (const auto &folder : folders) { | 173 | for (const auto &folder : folders) { |
101 | map.insert(folder->getName(), folder); | 174 | map.insert(folder->getName(), folder); |
102 | } | 175 | } |
176 | QStringList names; | ||
177 | for (const auto &folder : folders) { | ||
178 | names << folder->getName(); | ||
179 | } | ||
180 | |||
181 | //Workaround for maildir | ||
182 | if (names.contains("maildir1")) { | ||
183 | names.removeAll("maildir1"); | ||
184 | } | ||
185 | if (mCapabilities.contains("drafts")) { | ||
186 | QVERIFY(names.contains("drafts")); | ||
187 | names.removeAll("drafts"); | ||
188 | } | ||
189 | QCOMPARE(names.size(), 3); | ||
103 | QCOMPARE(map.value("sub")->getParent(), map.value("test")->identifier()); | 190 | QCOMPARE(map.value("sub")->getParent(), map.value("test")->identifier()); |
104 | }); | 191 | }); |
105 | VERIFYEXEC(job); | 192 | VERIFYEXEC(job); |
106 | } | 193 | } |
107 | 194 | ||
108 | void MailSyncTest::testListNewFolders() | 195 | void MailSyncTest::testListNewSubFolder() |
109 | { | 196 | { |
197 | if (!mCapabilities.contains("folder.hierarchy")) { | ||
198 | QSKIP("Missing capability folder.hierarchy"); | ||
199 | } | ||
110 | Sink::Query query; | 200 | Sink::Query query; |
111 | query.resources << mResourceInstanceIdentifier; | 201 | query.resources << mResourceInstanceIdentifier; |
112 | query.request<Folder::Name>(); | 202 | query.request<Folder::Name>(); |
@@ -127,8 +217,11 @@ void MailSyncTest::testListNewFolders() | |||
127 | VERIFYEXEC(job); | 217 | VERIFYEXEC(job); |
128 | } | 218 | } |
129 | 219 | ||
130 | void MailSyncTest::testListRemovedFolders() | 220 | void MailSyncTest::testListRemovedSubFolder() |
131 | { | 221 | { |
222 | if (!mCapabilities.contains("folder.hierarchy")) { | ||
223 | QSKIP("Missing capability folder.hierarchy"); | ||
224 | } | ||
132 | Sink::Query query; | 225 | Sink::Query query; |
133 | query.resources << mResourceInstanceIdentifier; | 226 | query.resources << mResourceInstanceIdentifier; |
134 | query.request<Folder::Name>(); | 227 | query.request<Folder::Name>(); |
@@ -176,7 +269,7 @@ void MailSyncTest::testListMails() | |||
176 | VERIFYEXEC(job); | 269 | VERIFYEXEC(job); |
177 | } | 270 | } |
178 | 271 | ||
179 | void MailSyncTest::testFetchNewMessages() | 272 | void MailSyncTest::testFetchNewRemovedMessages() |
180 | { | 273 | { |
181 | Sink::Query query; | 274 | Sink::Query query; |
182 | query.resources << mResourceInstanceIdentifier; | 275 | query.resources << mResourceInstanceIdentifier; |
@@ -189,36 +282,30 @@ void MailSyncTest::testFetchNewMessages() | |||
189 | auto msg = KMime::Message::Ptr::create(); | 282 | auto msg = KMime::Message::Ptr::create(); |
190 | msg->subject(true)->fromUnicodeString("Foobar", "utf8"); | 283 | msg->subject(true)->fromUnicodeString("Foobar", "utf8"); |
191 | msg->assemble(); | 284 | msg->assemble(); |
192 | createMessage(QStringList() << "test", msg->encodedContent(true)); | 285 | auto messageIdentifier = createMessage(QStringList() << "test", msg->encodedContent(true)); |
193 | 286 | ||
194 | Store::synchronize(query).exec().waitForFinished(); | 287 | Store::synchronize(query).exec().waitForFinished(); |
195 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 288 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
196 | 289 | ||
197 | auto job = Store::fetchAll<Mail>(query).then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | 290 | { |
198 | QCOMPARE(mails.size(), 2); | 291 | auto job = Store::fetchAll<Mail>(query).then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { |
199 | }); | 292 | QCOMPARE(mails.size(), 2); |
200 | VERIFYEXEC(job); | 293 | }); |
201 | } | 294 | VERIFYEXEC(job); |
295 | } | ||
202 | 296 | ||
203 | void MailSyncTest::testFetchRemovedMessages() | ||
204 | { | ||
205 | Sink::Query query; | ||
206 | query.resources << mResourceInstanceIdentifier; | ||
207 | query.request<Mail::Subject>().request<Mail::MimeMessage>(); | ||
208 | 297 | ||
209 | // Ensure all local data is processed | 298 | removeMessage(QStringList() << "test", messageIdentifier); |
210 | VERIFYEXEC(Store::synchronize(query)); | ||
211 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
212 | |||
213 | removeMessage(QStringList() << "test", "2:*"); | ||
214 | 299 | ||
215 | Store::synchronize(query).exec().waitForFinished(); | 300 | Store::synchronize(query).exec().waitForFinished(); |
216 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 301 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
217 | 302 | ||
218 | auto job = Store::fetchAll<Mail>(query).then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | 303 | { |
219 | QCOMPARE(mails.size(), 1); | 304 | auto job = Store::fetchAll<Mail>(query).then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { |
220 | }); | 305 | QCOMPARE(mails.size(), 1); |
221 | VERIFYEXEC(job); | 306 | }); |
307 | VERIFYEXEC(job); | ||
308 | } | ||
222 | } | 309 | } |
223 | 310 | ||
224 | //TODO test flag sync | 311 | //TODO test flag sync |
diff --git a/tests/mailsynctest.h b/tests/mailsynctest.h index f9ee7be..b0fda7c 100644 --- a/tests/mailsynctest.h +++ b/tests/mailsynctest.h | |||
@@ -45,6 +45,13 @@ do {\ | |||
45 | 45 | ||
46 | namespace Sink { | 46 | namespace Sink { |
47 | 47 | ||
48 | /** | ||
49 | * Tests if the resource can synchronize (read-only) emails. | ||
50 | * | ||
51 | * The default testenvironment is: | ||
52 | * * INBOX | ||
53 | * * INBOX.test | ||
54 | */ | ||
48 | class MailSyncTest : public QObject | 55 | class MailSyncTest : public QObject |
49 | { | 56 | { |
50 | Q_OBJECT | 57 | Q_OBJECT |
@@ -59,8 +66,8 @@ protected: | |||
59 | virtual void removeResourceFromDisk(const QByteArray &mResourceInstanceIdentifier) = 0; | 66 | virtual void removeResourceFromDisk(const QByteArray &mResourceInstanceIdentifier) = 0; |
60 | virtual void createFolder(const QStringList &folderPath) = 0; | 67 | virtual void createFolder(const QStringList &folderPath) = 0; |
61 | virtual void removeFolder(const QStringList &folderPath) = 0; | 68 | virtual void removeFolder(const QStringList &folderPath) = 0; |
62 | virtual void createMessage(const QStringList &folderPath, const QByteArray &message) = 0; | 69 | virtual QByteArray createMessage(const QStringList &folderPath, const QByteArray &message) = 0; |
63 | virtual void removeMessage(const QStringList &folderPath, const QByteArray &message) = 0; | 70 | virtual void removeMessage(const QStringList &folderPath, const QByteArray &messageIdentifier) = 0; |
64 | 71 | ||
65 | private slots: | 72 | private slots: |
66 | void initTestCase(); | 73 | void initTestCase(); |
@@ -68,13 +75,14 @@ private slots: | |||
68 | void cleanup(); | 75 | void cleanup(); |
69 | 76 | ||
70 | void testListFolders(); | 77 | void testListFolders(); |
78 | void testListNewFolder(); | ||
79 | void testListRemovedFolder(); | ||
71 | void testListFolderHierarchy(); | 80 | void testListFolderHierarchy(); |
72 | void testListNewFolders(); | 81 | void testListNewSubFolder(); |
73 | void testListRemovedFolders(); | 82 | void testListRemovedSubFolder(); |
74 | 83 | ||
75 | void testListMails(); | 84 | void testListMails(); |
76 | void testFetchNewMessages(); | 85 | void testFetchNewRemovedMessages(); |
77 | void testFetchRemovedMessages(); | ||
78 | 86 | ||
79 | void testFailingSync(); | 87 | void testFailingSync(); |
80 | }; | 88 | }; |