diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/mailthreadtest.cpp | 78 | ||||
-rw-r--r-- | tests/mailthreadtest.h | 1 |
2 files changed, 79 insertions, 0 deletions
diff --git a/tests/mailthreadtest.cpp b/tests/mailthreadtest.cpp index 8c325d8..d2962e5 100644 --- a/tests/mailthreadtest.cpp +++ b/tests/mailthreadtest.cpp | |||
@@ -29,6 +29,8 @@ | |||
29 | #include "log.h" | 29 | #include "log.h" |
30 | #include "test.h" | 30 | #include "test.h" |
31 | #include "standardqueries.h" | 31 | #include "standardqueries.h" |
32 | #include "index.h" | ||
33 | #include "definitions.h" | ||
32 | 34 | ||
33 | using namespace Sink; | 35 | using namespace Sink; |
34 | using namespace Sink::ApplicationDomain; | 36 | using namespace Sink::ApplicationDomain; |
@@ -249,3 +251,79 @@ void MailThreadTest::testRealWorldThread() | |||
249 | QCOMPARE(mails.size(), 8); | 251 | QCOMPARE(mails.size(), 8); |
250 | } | 252 | } |
251 | } | 253 | } |
254 | |||
255 | //Avoid accidentally merging or changing threads | ||
256 | void MailThreadTest::testNoParentsWithModifications() | ||
257 | { | ||
258 | auto folder = Folder::create(mResourceInstanceIdentifier); | ||
259 | folder.setName("folder2"); | ||
260 | VERIFYEXEC(Store::create(folder)); | ||
261 | |||
262 | auto createMail = [&] (const QString &subject) { | ||
263 | auto message1 = KMime::Message::Ptr::create(); | ||
264 | message1->subject(true)->fromUnicodeString(subject, "utf8"); | ||
265 | message1->messageID(true)->fromUnicodeString("<" + subject + "@foobar.com" + ">", "utf8"); | ||
266 | message1->date(true)->setDateTime(QDateTime::currentDateTimeUtc()); | ||
267 | message1->assemble(); | ||
268 | |||
269 | auto mail = Mail::create(mResourceInstanceIdentifier); | ||
270 | mail.setMimeMessage(message1->encodedContent(true)); | ||
271 | mail.setFolder(folder); | ||
272 | return mail; | ||
273 | }; | ||
274 | |||
275 | auto mail1 = createMail("1"); | ||
276 | VERIFYEXEC(Store::create(mail1)); | ||
277 | auto mail2 = createMail("2"); | ||
278 | VERIFYEXEC(Store::create(mail2)); | ||
279 | VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); | ||
280 | |||
281 | auto query = Sink::StandardQueries::threadLeaders(folder); | ||
282 | query.resourceFilter(mResourceInstanceIdentifier); | ||
283 | query.request<Mail::Subject>().request<Mail::MimeMessage>().request<Mail::Folder>().request<Mail::Date>().request<Mail::ThreadId>(); | ||
284 | |||
285 | QSet<QByteArray> threadIds; | ||
286 | { | ||
287 | auto mails = Store::read<Mail>(query); | ||
288 | QCOMPARE(mails.size(), 2); | ||
289 | for (const auto &m : mails) { | ||
290 | threadIds << m.getProperty(Mail::ThreadId::name).toByteArray(); | ||
291 | } | ||
292 | } | ||
293 | |||
294 | auto readIndex = [&] (const QString &indexName, const QByteArray &lookupKey) { | ||
295 | Index index(Sink::storageLocation(), mResourceInstanceIdentifier, indexName, Sink::Storage::DataStore::ReadOnly); | ||
296 | QByteArrayList keys; | ||
297 | index.lookup(lookupKey, | ||
298 | [&](const QByteArray &value) { keys << QByteArray{value.constData(), value.size()}; }, | ||
299 | [=](const Index::Error &error) { SinkWarning() << "Lookup error in secondary index: " << error.message; }, | ||
300 | false); | ||
301 | return keys; | ||
302 | }; | ||
303 | QCOMPARE(readIndex("mail.index.messageIdthreadId", "1@foobar.com").size(), 1); | ||
304 | QCOMPARE(readIndex("mail.index.messageIdthreadId", "2@foobar.com").size(), 1); | ||
305 | |||
306 | //We try to modify both mails on purpose | ||
307 | auto checkMail = [&] (Mail mail1) { | ||
308 | Mail modification = mail1; | ||
309 | modification.setChangedProperties({}); | ||
310 | modification.setImportant(true); | ||
311 | VERIFYEXEC(Store::modify(modification)); | ||
312 | VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); | ||
313 | |||
314 | QCOMPARE(readIndex("mail.index.messageIdthreadId", "1@foobar.com").size(), 1); | ||
315 | QCOMPARE(readIndex("mail.index.messageIdthreadId", "2@foobar.com").size(), 1); | ||
316 | |||
317 | { | ||
318 | auto mails = Store::read<Mail>(query); | ||
319 | QCOMPARE(mails.size(), 2); | ||
320 | QSet<QByteArray> newThreadIds; | ||
321 | for (const auto &m : mails) { | ||
322 | newThreadIds << m.getProperty(Mail::ThreadId::name).toByteArray(); | ||
323 | } | ||
324 | QCOMPARE(threadIds, newThreadIds); | ||
325 | } | ||
326 | }; | ||
327 | checkMail(mail1); | ||
328 | checkMail(mail2); | ||
329 | } | ||
diff --git a/tests/mailthreadtest.h b/tests/mailthreadtest.h index 6b64d4e..9ae1b4c 100644 --- a/tests/mailthreadtest.h +++ b/tests/mailthreadtest.h | |||
@@ -54,6 +54,7 @@ private slots: | |||
54 | void testListThreadLeader(); | 54 | void testListThreadLeader(); |
55 | void testIndexInMixedOrder(); | 55 | void testIndexInMixedOrder(); |
56 | void testRealWorldThread(); | 56 | void testRealWorldThread(); |
57 | void testNoParentsWithModifications(); | ||
57 | }; | 58 | }; |
58 | 59 | ||
59 | } | 60 | } |