diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/mailthreadtest.cpp | 94 | ||||
-rw-r--r-- | tests/mailthreadtest.h | 57 |
3 files changed, 152 insertions, 1 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 294cce2..f8fe3b3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
@@ -12,7 +12,7 @@ add_definitions(-DTESTDATAPATH="${CMAKE_CURRENT_SOURCE_DIR}/data") | |||
12 | 12 | ||
13 | find_package(KF5 COMPONENTS REQUIRED Mime) | 13 | find_package(KF5 COMPONENTS REQUIRED Mime) |
14 | 14 | ||
15 | add_library(sink_test SHARED testimplementations.cpp getrssusage.cpp mailtest.cpp mailsynctest.cpp) | 15 | add_library(sink_test SHARED testimplementations.cpp getrssusage.cpp mailtest.cpp mailsynctest.cpp mailthreadtest.cpp) |
16 | qt5_use_modules(sink_test Core Test Concurrent) | 16 | qt5_use_modules(sink_test Core Test Concurrent) |
17 | target_link_libraries(sink_test sink libhawd KF5::Mime) | 17 | target_link_libraries(sink_test sink libhawd KF5::Mime) |
18 | 18 | ||
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" | ||
diff --git a/tests/mailthreadtest.h b/tests/mailthreadtest.h new file mode 100644 index 0000000..d6b9c24 --- /dev/null +++ b/tests/mailthreadtest.h | |||
@@ -0,0 +1,57 @@ | |||
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 | #pragma once | ||
20 | |||
21 | #include <QObject> | ||
22 | #include <QByteArray> | ||
23 | |||
24 | #include <applicationdomaintype.h> | ||
25 | #include "testutils.h" | ||
26 | |||
27 | namespace Sink { | ||
28 | |||
29 | /** | ||
30 | * Tests if the resource can thread emails. | ||
31 | */ | ||
32 | class MailThreadTest : public QObject | ||
33 | { | ||
34 | Q_OBJECT | ||
35 | |||
36 | protected: | ||
37 | QByteArray mResourceInstanceIdentifier; | ||
38 | QByteArrayList mCapabilities; | ||
39 | |||
40 | virtual bool isBackendAvailable() { return true; } | ||
41 | virtual void resetTestEnvironment() = 0; | ||
42 | virtual Sink::ApplicationDomain::SinkResource createResource() = 0; | ||
43 | virtual Sink::ApplicationDomain::SinkResource createFaultyResource() = 0; | ||
44 | virtual void removeResourceFromDisk(const QByteArray &mResourceInstanceIdentifier) = 0; | ||
45 | virtual QByteArray createMessage(const QStringList &folderPath, const QByteArray &message) = 0; | ||
46 | virtual void removeMessage(const QStringList &folderPath, const QByteArray &messageIdentifier) = 0; | ||
47 | |||
48 | private slots: | ||
49 | void initTestCase(); | ||
50 | void init(); | ||
51 | void cleanup(); | ||
52 | |||
53 | void testListThreadLeader(); | ||
54 | }; | ||
55 | |||
56 | } | ||
57 | |||