diff options
Diffstat (limited to 'examples/imapresource/tests')
-rw-r--r-- | examples/imapresource/tests/imapresourcetest.cpp | 30 | ||||
-rw-r--r-- | examples/imapresource/tests/imapserverproxytest.cpp | 50 |
2 files changed, 78 insertions, 2 deletions
diff --git a/examples/imapresource/tests/imapresourcetest.cpp b/examples/imapresource/tests/imapresourcetest.cpp index 8ce32c2..30bb953 100644 --- a/examples/imapresource/tests/imapresourcetest.cpp +++ b/examples/imapresource/tests/imapresourcetest.cpp | |||
@@ -65,6 +65,8 @@ private slots: | |||
65 | resource.setProperty("identifier", "org.kde.imap.instance1"); | 65 | resource.setProperty("identifier", "org.kde.imap.instance1"); |
66 | resource.setProperty("type", "org.kde.imap"); | 66 | resource.setProperty("type", "org.kde.imap"); |
67 | resource.setProperty("server", "localhost"); | 67 | resource.setProperty("server", "localhost"); |
68 | resource.setProperty("user", "doe"); | ||
69 | resource.setProperty("password", "doe"); | ||
68 | resource.setProperty("port", 993); | 70 | resource.setProperty("port", 993); |
69 | Sink::Store::create(resource).exec().waitForFinished(); | 71 | Sink::Store::create(resource).exec().waitForFinished(); |
70 | } | 72 | } |
@@ -164,8 +166,8 @@ private slots: | |||
164 | VERIFYEXEC(Store::synchronize(query)); | 166 | VERIFYEXEC(Store::synchronize(query)); |
165 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | 167 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); |
166 | 168 | ||
167 | ImapServerProxy imap("localhost", 993); | 169 | Imap::ImapServerProxy imap("localhost", 993); |
168 | imap.login("doe", "doe").exec().waitForFinished(); | 170 | VERIFYEXEC(imap.login("doe", "doe")); |
169 | 171 | ||
170 | auto msg = KMime::Message::Ptr::create(); | 172 | auto msg = KMime::Message::Ptr::create(); |
171 | msg->subject(true)->fromUnicodeString("Foobar", "utf8"); | 173 | msg->subject(true)->fromUnicodeString("Foobar", "utf8"); |
@@ -182,6 +184,30 @@ private slots: | |||
182 | VERIFYEXEC(job); | 184 | VERIFYEXEC(job); |
183 | } | 185 | } |
184 | 186 | ||
187 | void testFetchRemovedMessages() | ||
188 | { | ||
189 | Sink::Query query; | ||
190 | query.resources << "org.kde.imap.instance1"; | ||
191 | query.request<Mail::Subject>().request<Mail::MimeMessage>(); | ||
192 | |||
193 | // Ensure all local data is processed | ||
194 | VERIFYEXEC(Store::synchronize(query)); | ||
195 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
196 | |||
197 | Imap::ImapServerProxy imap("localhost", 993); | ||
198 | VERIFYEXEC(imap.login("doe", "doe")); | ||
199 | |||
200 | VERIFYEXEC(imap.remove("INBOX.test", "2:*")); | ||
201 | |||
202 | Store::synchronize(query).exec().waitForFinished(); | ||
203 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
204 | |||
205 | auto job = Store::fetchAll<Mail>(query).then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | ||
206 | QCOMPARE(mails.size(), 1); | ||
207 | }); | ||
208 | VERIFYEXEC(job); | ||
209 | } | ||
210 | |||
185 | void testFailingSync() | 211 | void testFailingSync() |
186 | { | 212 | { |
187 | auto resource = ApplicationDomain::ImapResource::create("account1"); | 213 | auto resource = ApplicationDomain::ImapResource::create("account1"); |
diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp index 139597a..b30cc33 100644 --- a/examples/imapresource/tests/imapserverproxytest.cpp +++ b/examples/imapresource/tests/imapserverproxytest.cpp | |||
@@ -79,6 +79,7 @@ private slots: | |||
79 | void testFetchFolders() | 79 | void testFetchFolders() |
80 | { | 80 | { |
81 | ImapServerProxy imap("localhost", 993); | 81 | ImapServerProxy imap("localhost", 993); |
82 | VERIFYEXEC(imap.login("doe", "doe")); | ||
82 | auto future = imap.fetchFolders([](const QVector<Folder> &){}); | 83 | auto future = imap.fetchFolders([](const QVector<Folder> &){}); |
83 | future.waitForFinished(); | 84 | future.waitForFinished(); |
84 | QVERIFY(!future.errorCode()); | 85 | QVERIFY(!future.errorCode()); |
@@ -93,6 +94,55 @@ private slots: | |||
93 | QVERIFY(future2.errorCode()); | 94 | QVERIFY(future2.errorCode()); |
94 | } | 95 | } |
95 | 96 | ||
97 | void testFetchMail() | ||
98 | { | ||
99 | ImapServerProxy imap("localhost", 993); | ||
100 | VERIFYEXEC(imap.login("doe", "doe")); | ||
101 | |||
102 | KIMAP::FetchJob::FetchScope scope; | ||
103 | scope.mode = KIMAP::FetchJob::FetchScope::Headers; | ||
104 | int count = 0; | ||
105 | auto job = imap.select("INBOX.test").then<void>(imap.fetch(KIMAP::ImapSet::fromImapSequenceSet("1:*"), scope, | ||
106 | [&count](const QString &mailbox, | ||
107 | const QMap<qint64,qint64> &uids, | ||
108 | const QMap<qint64,qint64> &sizes, | ||
109 | const QMap<qint64,KIMAP::MessageAttribute> &attrs, | ||
110 | const QMap<qint64,KIMAP::MessageFlags> &flags, | ||
111 | const QMap<qint64,KIMAP::MessagePtr> &messages) { | ||
112 | Trace() << "Received " << uids.size() << " messages from " << mailbox; | ||
113 | Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); | ||
114 | count += uids.size(); | ||
115 | })); | ||
116 | |||
117 | VERIFYEXEC(job); | ||
118 | QCOMPARE(count, 1); | ||
119 | } | ||
120 | |||
121 | void testRemoveMail() | ||
122 | { | ||
123 | ImapServerProxy imap("localhost", 993); | ||
124 | VERIFYEXEC(imap.login("doe", "doe")); | ||
125 | VERIFYEXEC(imap.remove("INBOX.test", "1:*")); | ||
126 | |||
127 | KIMAP::FetchJob::FetchScope scope; | ||
128 | scope.mode = KIMAP::FetchJob::FetchScope::Headers; | ||
129 | int count = 0; | ||
130 | auto job = imap.select("INBOX.test").then<void>(imap.fetch(KIMAP::ImapSet::fromImapSequenceSet("1:*"), scope, | ||
131 | [&count](const QString &mailbox, | ||
132 | const QMap<qint64,qint64> &uids, | ||
133 | const QMap<qint64,qint64> &sizes, | ||
134 | const QMap<qint64,KIMAP::MessageAttribute> &attrs, | ||
135 | const QMap<qint64,KIMAP::MessageFlags> &flags, | ||
136 | const QMap<qint64,KIMAP::MessagePtr> &messages) { | ||
137 | Trace() << "Received " << uids.size() << " messages from " << mailbox; | ||
138 | Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); | ||
139 | count += uids.size(); | ||
140 | })); | ||
141 | |||
142 | VERIFYEXEC(job); | ||
143 | QCOMPARE(count, 0); | ||
144 | } | ||
145 | |||
96 | }; | 146 | }; |
97 | 147 | ||
98 | QTEST_MAIN(ImapServerProxyTest) | 148 | QTEST_MAIN(ImapServerProxyTest) |