diff options
Diffstat (limited to 'examples/imapresource/tests')
-rw-r--r-- | examples/imapresource/tests/CMakeLists.txt | 21 | ||||
-rw-r--r-- | examples/imapresource/tests/imapresourcetest.cpp | 162 | ||||
-rw-r--r-- | examples/imapresource/tests/resetmailbox.sh | 10 |
3 files changed, 193 insertions, 0 deletions
diff --git a/examples/imapresource/tests/CMakeLists.txt b/examples/imapresource/tests/CMakeLists.txt new file mode 100644 index 0000000..cdd5fcb --- /dev/null +++ b/examples/imapresource/tests/CMakeLists.txt | |||
@@ -0,0 +1,21 @@ | |||
1 | set(CMAKE_AUTOMOC ON) | ||
2 | include_directories( | ||
3 | ${CMAKE_CURRENT_BINARY_DIR} | ||
4 | ) | ||
5 | |||
6 | macro(auto_tests) | ||
7 | foreach(_testname ${ARGN}) | ||
8 | add_executable(${_testname} ${_testname}.cpp) | ||
9 | # generate_flatbuffers(${_testname} calendar) | ||
10 | add_test(${_testname} ${_testname}) | ||
11 | qt5_use_modules(${_testname} Core Test Concurrent) | ||
12 | target_link_libraries(${_testname} sink libhawd) | ||
13 | endforeach(_testname) | ||
14 | endmacro(auto_tests) | ||
15 | |||
16 | auto_tests ( | ||
17 | imapresourcetest | ||
18 | ) | ||
19 | target_link_libraries(imapresourcetest sink_resource_imap) | ||
20 | |||
21 | install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resetmailbox.sh DESTINATION bin PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ) | ||
diff --git a/examples/imapresource/tests/imapresourcetest.cpp b/examples/imapresource/tests/imapresourcetest.cpp new file mode 100644 index 0000000..27d7d6d --- /dev/null +++ b/examples/imapresource/tests/imapresourcetest.cpp | |||
@@ -0,0 +1,162 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <QString> | ||
4 | #include <KMime/Message> | ||
5 | |||
6 | // #include "imapresource/imapresource.h" | ||
7 | #include "store.h" | ||
8 | #include "resourcecontrol.h" | ||
9 | #include "commands.h" | ||
10 | #include "entitybuffer.h" | ||
11 | #include "resourceconfig.h" | ||
12 | #include "modelresult.h" | ||
13 | #include "pipeline.h" | ||
14 | #include "log.h" | ||
15 | #include "test.h" | ||
16 | #include "../imapresource.h" | ||
17 | #include "../imapserverproxy.h" | ||
18 | |||
19 | #define ASYNCCOMPARE(actual, expected) \ | ||
20 | do {\ | ||
21 | if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ | ||
22 | return KAsync::error<void>(1, "Comparison failed.");\ | ||
23 | } while (0) | ||
24 | |||
25 | #define ASYNCVERIFY(statement) \ | ||
26 | do {\ | ||
27 | if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ | ||
28 | return KAsync::error<void>(1, "Verify failed.");\ | ||
29 | } while (0) | ||
30 | |||
31 | #define VERIFYEXEC(statement) \ | ||
32 | do {\ | ||
33 | auto result = statement.exec(); \ | ||
34 | result.waitForFinished(); \ | ||
35 | if (!QTest::qVerify(!result.errorCode(), #statement, "", __FILE__, __LINE__))\ | ||
36 | return;\ | ||
37 | } while (0) | ||
38 | |||
39 | using namespace Sink; | ||
40 | using namespace Sink::ApplicationDomain; | ||
41 | |||
42 | /** | ||
43 | * Test of complete system using the imap resource. | ||
44 | * | ||
45 | * This test requires the imap resource installed. | ||
46 | */ | ||
47 | class ImapResourceTest : public QObject | ||
48 | { | ||
49 | Q_OBJECT | ||
50 | |||
51 | QTemporaryDir tempDir; | ||
52 | QString targetPath; | ||
53 | private slots: | ||
54 | void initTestCase() | ||
55 | { | ||
56 | |||
57 | //FIXME initTest only works for the current process, | ||
58 | //we also have to start resources in test-mode | ||
59 | // Sink::Test::initTest(); | ||
60 | Sink::Log::setDebugOutputLevel(Sink::Log::Trace); | ||
61 | ::ImapResource::removeFromDisk("org.kde.imap.instance1"); | ||
62 | system("resetmailbox.sh"); | ||
63 | // auto resource = ApplicationDomain::ImapResource::create("account1"); | ||
64 | Sink::ApplicationDomain::SinkResource resource; | ||
65 | resource.setProperty("identifier", "org.kde.imap.instance1"); | ||
66 | resource.setProperty("type", "org.kde.imap"); | ||
67 | resource.setProperty("server", "localhost"); | ||
68 | resource.setProperty("port", 993); | ||
69 | Sink::Store::create(resource).exec().waitForFinished(); | ||
70 | } | ||
71 | |||
72 | void cleanup() | ||
73 | { | ||
74 | Sink::ResourceControl::shutdown(QByteArray("org.kde.imap.instance1")).exec().waitForFinished(); | ||
75 | ::ImapResource::removeFromDisk("org.kde.imap.instance1"); | ||
76 | } | ||
77 | |||
78 | void init() | ||
79 | { | ||
80 | qDebug(); | ||
81 | qDebug() << "-----------------------------------------"; | ||
82 | qDebug(); | ||
83 | Sink::ResourceControl::start(QByteArray("org.kde.imap.instance1")).exec().waitForFinished(); | ||
84 | } | ||
85 | |||
86 | void testListFolders() | ||
87 | { | ||
88 | Sink::Query query; | ||
89 | query.resources << "org.kde.imap.instance1"; | ||
90 | query.request<Folder::Name>(); | ||
91 | |||
92 | // Ensure all local data is processed | ||
93 | VERIFYEXEC(Store::synchronize(query)); | ||
94 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
95 | |||
96 | auto job = Store::fetchAll<Folder>(query).then<void, QList<Folder::Ptr>>([](const QList<Folder::Ptr> &folders) { | ||
97 | QCOMPARE(folders.size(), 2); | ||
98 | QStringList names; | ||
99 | for (const auto &folder : folders) { | ||
100 | names << folder->getName(); | ||
101 | } | ||
102 | QVERIFY(names.contains("INBOX")); | ||
103 | QVERIFY(names.contains("INBOX.test")); | ||
104 | }); | ||
105 | VERIFYEXEC(job); | ||
106 | } | ||
107 | |||
108 | void testListMails() | ||
109 | { | ||
110 | Sink::Query query; | ||
111 | query.resources << "org.kde.imap.instance1"; | ||
112 | query.request<Mail::Subject>().request<Mail::MimeMessage>(); | ||
113 | |||
114 | // Ensure all local data is processed | ||
115 | VERIFYEXEC(Store::synchronize(query)); | ||
116 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
117 | |||
118 | auto job = Store::fetchAll<Mail>(query).then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | ||
119 | QCOMPARE(mails.size(), 1); | ||
120 | QVERIFY(mails.first()->getSubject().startsWith(QString("[Nepomuk] Jenkins build is still unstable"))); | ||
121 | const auto data = mails.first()->getMimeMessage(); | ||
122 | QVERIFY(!data.isEmpty()); | ||
123 | |||
124 | KMime::Message m; | ||
125 | m.setContent(data); | ||
126 | m.parse(); | ||
127 | QCOMPARE(mails.first()->getSubject(), m.subject(true)->asUnicodeString()); | ||
128 | }); | ||
129 | VERIFYEXEC(job); | ||
130 | } | ||
131 | |||
132 | void testFetchNewMessages() | ||
133 | { | ||
134 | Sink::Query query; | ||
135 | query.resources << "org.kde.imap.instance1"; | ||
136 | query.request<Mail::Subject>().request<Mail::MimeMessage>(); | ||
137 | |||
138 | // Ensure all local data is processed | ||
139 | VERIFYEXEC(Store::synchronize(query)); | ||
140 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
141 | |||
142 | ImapServerProxy imap("localhost", 993); | ||
143 | imap.login("doe", "doe").exec().waitForFinished(); | ||
144 | |||
145 | auto msg = KMime::Message::Ptr::create(); | ||
146 | msg->subject(true)->fromUnicodeString("Foobar", "utf8"); | ||
147 | msg->assemble(); | ||
148 | |||
149 | VERIFYEXEC(imap.append("INBOX.test", msg->encodedContent(true))); | ||
150 | |||
151 | Store::synchronize(query).exec().waitForFinished(); | ||
152 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
153 | |||
154 | auto job = Store::fetchAll<Mail>(query).then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | ||
155 | QCOMPARE(mails.size(), 2); | ||
156 | }); | ||
157 | VERIFYEXEC(job); | ||
158 | } | ||
159 | }; | ||
160 | |||
161 | QTEST_MAIN(ImapResourceTest) | ||
162 | #include "imapresourcetest.moc" | ||
diff --git a/examples/imapresource/tests/resetmailbox.sh b/examples/imapresource/tests/resetmailbox.sh new file mode 100644 index 0000000..966115a --- /dev/null +++ b/examples/imapresource/tests/resetmailbox.sh | |||
@@ -0,0 +1,10 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | sudo echo "dm user.doe.test" | cyradm --auth PLAIN -u cyrus -w admin localhost | ||
4 | sudo echo "cm user.doe.test" | cyradm --auth PLAIN -u cyrus -w admin localhost | ||
5 | sudo echo "sam user.doe cyrus c" | cyradm --auth PLAIN -u cyrus -w admin localhost | ||
6 | sudo echo "sam user.doe.test cyrus c" | cyradm --auth PLAIN -u cyrus -w admin localhost | ||
7 | # sudo rm -R /var/spool/imap/d/user/doe/* | ||
8 | sudo cp /work/source/Sink/tests/data/maildir1/cur/1365777830.R28.localhost.localdomain\:2\,S /var/spool/imap/d/user/doe/test/1. | ||
9 | sudo chown cyrus:mail /var/spool/imap/d/user/doe/test/1. | ||
10 | sudo /usr/lib/cyrus-imapd/reconstruct "user.doe.test" | ||