diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-09-20 17:18:21 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-09-20 17:18:21 +0200 |
commit | ebc5c48c03b6145e604da7c313b35321d0a71142 (patch) | |
tree | 1cee00a9fa4faa4995c0a50f01703ac5672c8797 /tests/mailthreadtest.cpp | |
parent | 4a14a6fade947aa830d3f21598a4a6ba7316b933 (diff) | |
download | sink-ebc5c48c03b6145e604da7c313b35321d0a71142.tar.gz sink-ebc5c48c03b6145e604da7c313b35321d0a71142.zip |
A first draft of the threading algorithm.
Diffstat (limited to 'tests/mailthreadtest.cpp')
-rw-r--r-- | tests/mailthreadtest.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/mailthreadtest.cpp b/tests/mailthreadtest.cpp new file mode 100644 index 0000000..1bbe713 --- /dev/null +++ b/tests/mailthreadtest.cpp | |||
@@ -0,0 +1,94 @@ | |||
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 "mailthreadtest.h" | ||
20 | |||
21 | #include <QtTest> | ||
22 | |||
23 | #include <QString> | ||
24 | #include <KMime/Message> | ||
25 | |||
26 | #include "store.h" | ||
27 | #include "resourcecontrol.h" | ||
28 | #include "log.h" | ||
29 | #include "test.h" | ||
30 | |||
31 | using namespace Sink; | ||
32 | using namespace Sink::ApplicationDomain; | ||
33 | |||
34 | SINK_DEBUG_AREA("mailthreadtest") | ||
35 | |||
36 | //TODO extract resource test | ||
37 | // | ||
38 | void MailThreadTest::initTestCase() | ||
39 | { | ||
40 | Test::initTest(); | ||
41 | QVERIFY(isBackendAvailable()); | ||
42 | resetTestEnvironment(); | ||
43 | auto resource = createResource(); | ||
44 | QVERIFY(!resource.identifier().isEmpty()); | ||
45 | |||
46 | VERIFYEXEC(Store::create(resource)); | ||
47 | |||
48 | mResourceInstanceIdentifier = resource.identifier(); | ||
49 | mCapabilities = resource.getProperty("capabilities").value<QByteArrayList>(); | ||
50 | } | ||
51 | |||
52 | void MailThreadTest::cleanup() | ||
53 | { | ||
54 | //TODO the shutdown job fails if the resource is already shut down | ||
55 | // VERIFYEXEC(ResourceControl::shutdown(mResourceInstanceIdentifier)); | ||
56 | ResourceControl::shutdown(mResourceInstanceIdentifier).exec().waitForFinished(); | ||
57 | removeResourceFromDisk(mResourceInstanceIdentifier); | ||
58 | } | ||
59 | |||
60 | void MailThreadTest::init() | ||
61 | { | ||
62 | VERIFYEXEC(ResourceControl::start(mResourceInstanceIdentifier)); | ||
63 | } | ||
64 | |||
65 | |||
66 | void MailThreadTest::testListThreadLeader() | ||
67 | { | ||
68 | Sink::Query query; | ||
69 | query.resources << mResourceInstanceIdentifier; | ||
70 | query.request<Mail::Subject>().request<Mail::MimeMessage>().request<Mail::Folder>().request<Mail::Date>(); | ||
71 | query.threadLeaderOnly = true; | ||
72 | query.sort<Mail::Date>(); | ||
73 | |||
74 | // Ensure all local data is processed | ||
75 | VERIFYEXEC(Store::synchronize(query)); | ||
76 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
77 | |||
78 | auto job = Store::fetchAll<Mail>(query).syncThen<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | ||
79 | QCOMPARE(mails.size(), 1); | ||
80 | QVERIFY(mails.first()->getSubject().startsWith(QString("ThreadLeader"))); | ||
81 | const auto data = mails.first()->getMimeMessage(); | ||
82 | QVERIFY(!data.isEmpty()); | ||
83 | |||
84 | KMime::Message m; | ||
85 | m.setContent(data); | ||
86 | m.parse(); | ||
87 | QCOMPARE(mails.first()->getSubject(), m.subject(true)->asUnicodeString()); | ||
88 | QVERIFY(!mails.first()->getFolder().isEmpty()); | ||
89 | QVERIFY(mails.first()->getDate().isValid()); | ||
90 | }); | ||
91 | VERIFYEXEC(job); | ||
92 | } | ||
93 | |||
94 | #include "mailthreadtest.moc" | ||