diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-31 17:24:40 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-31 17:24:40 +0200 |
commit | 4d89be0c8ed4a9b33d44f9782e93709be8fc8042 (patch) | |
tree | c2f06bc4ad8e6eaf53435536ec6ce448fdf80339 /tests/maildirresourcetest.cpp | |
parent | ed0faba01b26579e726f5a2d3cf5efb14140322c (diff) | |
download | sink-4d89be0c8ed4a9b33d44f9782e93709be8fc8042.tar.gz sink-4d89be0c8ed4a9b33d44f9782e93709be8fc8042.zip |
Got rid of the maildirresourcetest
Diffstat (limited to 'tests/maildirresourcetest.cpp')
-rw-r--r-- | tests/maildirresourcetest.cpp | 251 |
1 files changed, 0 insertions, 251 deletions
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp deleted file mode 100644 index 0a32000..0000000 --- a/tests/maildirresourcetest.cpp +++ /dev/null | |||
@@ -1,251 +0,0 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <QString> | ||
4 | #include <KMime/Message> | ||
5 | |||
6 | #include "maildirresource/maildirresource.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 | |||
17 | #define ASYNCCOMPARE(actual, expected) \ | ||
18 | do {\ | ||
19 | if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ | ||
20 | return KAsync::error<void>(1, "Comparison failed.");\ | ||
21 | } while (0) | ||
22 | |||
23 | #define ASYNCVERIFY(statement) \ | ||
24 | do {\ | ||
25 | if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ | ||
26 | return KAsync::error<void>(1, "Verify failed.");\ | ||
27 | } while (0) | ||
28 | |||
29 | using namespace Sink; | ||
30 | |||
31 | static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath) | ||
32 | { | ||
33 | QFileInfo srcFileInfo(srcFilePath); | ||
34 | if (srcFileInfo.isDir()) { | ||
35 | QDir targetDir(tgtFilePath); | ||
36 | targetDir.cdUp(); | ||
37 | if (!targetDir.mkdir(QFileInfo(srcFilePath).fileName())) { | ||
38 | qWarning() << "Failed to create directory " << tgtFilePath; | ||
39 | return false; | ||
40 | } | ||
41 | QDir sourceDir(srcFilePath); | ||
42 | QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System); | ||
43 | foreach (const QString &fileName, fileNames) { | ||
44 | const QString newSrcFilePath = srcFilePath + QLatin1Char('/') + fileName; | ||
45 | const QString newTgtFilePath = tgtFilePath + QLatin1Char('/') + fileName; | ||
46 | if (!copyRecursively(newSrcFilePath, newTgtFilePath)) | ||
47 | return false; | ||
48 | } | ||
49 | } else { | ||
50 | if (!QFile::copy(srcFilePath, tgtFilePath)) { | ||
51 | qWarning() << "Failed to copy file " << tgtFilePath; | ||
52 | return false; | ||
53 | } | ||
54 | } | ||
55 | return true; | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | * Test of complete system using the maildir resource. | ||
60 | * | ||
61 | * This test requires the maildir resource installed. | ||
62 | */ | ||
63 | class MaildirResourceTest : public QObject | ||
64 | { | ||
65 | Q_OBJECT | ||
66 | |||
67 | QTemporaryDir tempDir; | ||
68 | QString targetPath; | ||
69 | private slots: | ||
70 | void initTestCase() | ||
71 | { | ||
72 | targetPath = tempDir.path() + "/maildir1/"; | ||
73 | |||
74 | Sink::Test::initTest(); | ||
75 | Sink::Log::setDebugOutputLevel(Sink::Log::Trace); | ||
76 | MaildirResource::removeFromDisk("org.kde.maildir.instance1"); | ||
77 | Sink::ApplicationDomain::SinkResource resource; | ||
78 | resource.setProperty("identifier", "org.kde.maildir.instance1"); | ||
79 | resource.setProperty("type", "org.kde.maildir"); | ||
80 | resource.setProperty("path", targetPath); | ||
81 | Sink::Store::create(resource).exec().waitForFinished(); | ||
82 | } | ||
83 | |||
84 | void cleanup() | ||
85 | { | ||
86 | Sink::ResourceControl::shutdown(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished(); | ||
87 | MaildirResource::removeFromDisk("org.kde.maildir.instance1"); | ||
88 | QDir dir(targetPath); | ||
89 | dir.removeRecursively(); | ||
90 | } | ||
91 | |||
92 | void init() | ||
93 | { | ||
94 | qDebug(); | ||
95 | qDebug() << "-----------------------------------------"; | ||
96 | qDebug(); | ||
97 | copyRecursively(TESTDATAPATH "/maildir1", targetPath); | ||
98 | Sink::ResourceControl::start(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished(); | ||
99 | } | ||
100 | |||
101 | void testListFolders() | ||
102 | { | ||
103 | Sink::Query query; | ||
104 | query.resources << "org.kde.maildir.instance1"; | ||
105 | |||
106 | // Ensure all local data is processed | ||
107 | Sink::Store::synchronize(query).exec().waitForFinished(); | ||
108 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
109 | |||
110 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); | ||
111 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
112 | QCOMPARE(model->rowCount(QModelIndex()), 3); | ||
113 | } | ||
114 | |||
115 | void testListFolderTree() | ||
116 | { | ||
117 | Sink::Query query; | ||
118 | query.resources << "org.kde.maildir.instance1"; | ||
119 | query.parentProperty = "parent"; | ||
120 | |||
121 | // Ensure all local data is processed | ||
122 | Sink::Store::synchronize(query).exec().waitForFinished(); | ||
123 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
124 | |||
125 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); | ||
126 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
127 | QCOMPARE(model->rowCount(QModelIndex()), 1); | ||
128 | auto parentIndex = model->index(0, 0, QModelIndex()); | ||
129 | model->fetchMore(parentIndex); | ||
130 | QTRY_VERIFY(model->data(parentIndex, Sink::Store::ChildrenFetchedRole).toBool()); | ||
131 | QCOMPARE(model->rowCount(parentIndex), 2); | ||
132 | } | ||
133 | |||
134 | void testListMailsOfFolder() | ||
135 | { | ||
136 | using namespace Sink; | ||
137 | using namespace Sink::ApplicationDomain; | ||
138 | // Ensure all local data is processed | ||
139 | auto query = Query::ResourceFilter("org.kde.maildir.instance1"); | ||
140 | Store::synchronize(query).exec().waitForFinished(); | ||
141 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
142 | auto result = Store::fetchOne<Folder>(Query::ResourceFilter("org.kde.maildir.instance1") + Query::RequestedProperties(QByteArrayList() << "name")) | ||
143 | .then<QList<Mail::Ptr>, Folder>([](const Folder &folder) { | ||
144 | Trace() << "Found a folder" << folder.identifier(); | ||
145 | return Store::fetchAll<Mail>(Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" | ||
146 | << "subject")); | ||
147 | }) | ||
148 | .then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { QVERIFY(mails.size() >= 1); }) | ||
149 | .exec(); | ||
150 | result.waitForFinished(); | ||
151 | QVERIFY(!result.errorCode()); | ||
152 | } | ||
153 | |||
154 | void testMailContent() | ||
155 | { | ||
156 | Sink::Query query; | ||
157 | query.resources << "org.kde.maildir.instance1"; | ||
158 | query.requestedProperties << "folder" | ||
159 | << "subject" | ||
160 | << "mimeMessage" | ||
161 | << "date"; | ||
162 | |||
163 | // Ensure all local data is processed | ||
164 | Sink::Store::synchronize(query).exec().waitForFinished(); | ||
165 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
166 | |||
167 | auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); | ||
168 | QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
169 | QVERIFY(mailModel->rowCount(QModelIndex()) >= 1); | ||
170 | auto mail = mailModel->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>(); | ||
171 | QVERIFY(!mail->getProperty("subject").toString().isEmpty()); | ||
172 | QVERIFY(!mail->getProperty("mimeMessage").toString().isEmpty()); | ||
173 | QVERIFY(mail->getProperty("date").toDateTime().isValid()); | ||
174 | |||
175 | QFileInfo info(mail->getProperty("mimeMessage").toString()); | ||
176 | QVERIFY(info.exists()); | ||
177 | } | ||
178 | |||
179 | |||
180 | void testSyncFolderMove() | ||
181 | { | ||
182 | Sink::Query query; | ||
183 | query.resources << "org.kde.maildir.instance1"; | ||
184 | query.requestedProperties << "name"; | ||
185 | |||
186 | // Ensure all local data is processed | ||
187 | Sink::Store::synchronize(query).exec().waitForFinished(); | ||
188 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
189 | |||
190 | auto targetPath = tempDir.path() + "/maildir1/"; | ||
191 | QDir dir(targetPath); | ||
192 | QVERIFY(dir.rename("inbox", "newbox")); | ||
193 | |||
194 | // Ensure all local data is processed | ||
195 | Sink::Store::synchronize(query).exec().waitForFinished(); | ||
196 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
197 | |||
198 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); | ||
199 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
200 | QCOMPARE(model->rowCount(QModelIndex()), 4); | ||
201 | QCOMPARE(model->match(model->index(0, 0, QModelIndex()), Qt::DisplayRole, QStringLiteral("newbox"), 1).size(), 1); | ||
202 | } | ||
203 | |||
204 | void testReSyncMail() | ||
205 | { | ||
206 | Sink::Query query; | ||
207 | query.resources << "org.kde.maildir.instance1"; | ||
208 | query.requestedProperties << "folder" | ||
209 | << "subject"; | ||
210 | |||
211 | // Ensure all local data is processed | ||
212 | Sink::Store::synchronize(query).exec().waitForFinished(); | ||
213 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
214 | |||
215 | // Ensure all local data is processed | ||
216 | Sink::Store::synchronize(query).exec().waitForFinished(); | ||
217 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
218 | |||
219 | auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); | ||
220 | QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
221 | QCOMPARE(mailModel->rowCount(QModelIndex()), 3); | ||
222 | } | ||
223 | |||
224 | void testSyncMailRemoval() | ||
225 | { | ||
226 | Sink::Query query; | ||
227 | query.resources << "org.kde.maildir.instance1"; | ||
228 | query.requestedProperties << "folder" | ||
229 | << "subject"; | ||
230 | |||
231 | // Ensure all local data is processed | ||
232 | Sink::Store::synchronize(query).exec().waitForFinished(); | ||
233 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
234 | |||
235 | auto targetPath = tempDir.path() + "/maildir1/cur/1365777830.R28.localhost.localdomain:2,S"; | ||
236 | QFile file(targetPath); | ||
237 | QVERIFY(file.remove()); | ||
238 | |||
239 | // Ensure all local data is processed | ||
240 | Sink::Store::synchronize(query).exec().waitForFinished(); | ||
241 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
242 | |||
243 | auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); | ||
244 | QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
245 | QCOMPARE(mailModel->rowCount(QModelIndex()), 2); | ||
246 | } | ||
247 | |||
248 | }; | ||
249 | |||
250 | QTEST_MAIN(MaildirResourceTest) | ||
251 | #include "maildirresourcetest.moc" | ||