1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
#include <QtTest>
#include <QString>
#include "maildirresource/maildirresource.h"
#include "clientapi.h"
#include "commands.h"
#include "entitybuffer.h"
#include "resourceconfig.h"
#include "modelresult.h"
#include "pipeline.h"
#include "log.h"
static bool copyRecursively(const QString &srcFilePath,
const QString &tgtFilePath)
{
QFileInfo srcFileInfo(srcFilePath);
if (srcFileInfo.isDir()) {
QDir targetDir(tgtFilePath);
targetDir.cdUp();
if (!targetDir.mkdir(QFileInfo(srcFilePath).fileName())) {
qWarning() << "Failed to create directory " << tgtFilePath;
return false;
}
QDir sourceDir(srcFilePath);
QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
foreach (const QString &fileName, fileNames) {
const QString newSrcFilePath
= srcFilePath + QLatin1Char('/') + fileName;
const QString newTgtFilePath
= tgtFilePath + QLatin1Char('/') + fileName;
if (!copyRecursively(newSrcFilePath, newTgtFilePath))
return false;
}
} else {
if (!QFile::copy(srcFilePath, tgtFilePath)) {
qWarning() << "Failed to copy file " << tgtFilePath;
return false;
}
}
return true;
}
/**
* Test of complete system using the maildir resource.
*
* This test requires the maildir resource installed.
*/
class MaildirResourceTest : public QObject
{
Q_OBJECT
QTemporaryDir tempDir;
private Q_SLOTS:
void initTestCase()
{
QVERIFY(tempDir.isValid());
auto targetPath = tempDir.path() + QDir::separator() + "maildir1/";
copyRecursively(TESTDATAPATH "/maildir1", targetPath);
Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace);
auto factory = Akonadi2::ResourceFactory::load("org.kde.maildir");
QVERIFY(factory);
MaildirResource::removeFromDisk("org.kde.maildir.instance1");
Akonadi2::ApplicationDomain::AkonadiResource resource;
resource.setProperty("identifier", "org.kde.maildir.instance1");
resource.setProperty("type", "org.kde.maildir");
resource.setProperty("path", targetPath);
Akonadi2::Store::create(resource).exec().waitForFinished();
}
void cleanup()
{
Akonadi2::Store::shutdown(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished();
MaildirResource::removeFromDisk("org.kde.maildir.instance1");
}
void init()
{
qDebug();
qDebug() << "-----------------------------------------";
qDebug();
}
void testListFolders()
{
Akonadi2::Query query;
query.resources << "org.kde.maildir.instance1";
query.syncOnDemand = true;
query.processAll = true;
//Ensure all local data is processed
Akonadi2::Store::synchronize(query).exec().waitForFinished();
auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query);
QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
QVERIFY(model->rowCount(QModelIndex()) > 1);
}
void testListFolderTree()
{
Akonadi2::Query query;
query.resources << "org.kde.maildir.instance1";
query.syncOnDemand = true;
query.processAll = true;
query.parentProperty = "parent";
//Ensure all local data is processed
Akonadi2::Store::synchronize(query).exec().waitForFinished();
auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query);
QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
QCOMPARE(model->rowCount(QModelIndex()), 1);
auto parentIndex = model->index(0, 0, QModelIndex());
model->fetchMore(parentIndex);
QTRY_VERIFY(model->data(parentIndex, Akonadi2::Store::ChildrenFetchedRole).toBool());
QCOMPARE(model->rowCount(parentIndex), 1);
}
void testListMailsOfFolder()
{
{
Akonadi2::Query query;
query.resources << "org.kde.maildir.instance1";
query.syncOnDemand = true;
query.processAll = true;
//Ensure all local data is processed
Akonadi2::Store::synchronize(query).exec().waitForFinished();
}
QByteArray folderIdentifier;
{
Akonadi2::Query query;
query.resources << "org.kde.maildir.instance1";
query.requestedProperties << "folder" << "name";
auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query);
QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
QVERIFY(model->rowCount(QModelIndex()) > 1);
folderIdentifier = model->index(1, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value<Akonadi2::ApplicationDomain::Folder::Ptr>()->identifier();
}
Akonadi2::Query query;
query.resources << "org.kde.maildir.instance1";
query.requestedProperties << "folder" << "summary";
query.propertyFilter.insert("folder", folderIdentifier);
auto mailModel = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query);
QTRY_VERIFY(mailModel->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
QVERIFY(mailModel->rowCount(QModelIndex()) >= 1);
}
void testSyncFolderMove()
{
Akonadi2::Query query;
query.resources << "org.kde.maildir.instance1";
query.syncOnDemand = true;
query.processAll = true;
query.requestedProperties << "name";
//Ensure all local data is processed
Akonadi2::Store::synchronize(query).exec().waitForFinished();
auto targetPath = tempDir.path() + QDir::separator() + "maildir1/";
QDir dir(targetPath);
QVERIFY(dir.rename("inbox", "newbox"));
//Ensure all local data is processed
Akonadi2::Store::synchronize(query).exec().waitForFinished();
auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query);
QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
QCOMPARE(model->rowCount(QModelIndex()), 2);
QCOMPARE(model->match(model->index(0, 0, QModelIndex()), Qt::DisplayRole, QStringLiteral("newbox"), 1).size(), 1);
}
};
QTEST_MAIN(MaildirResourceTest)
#include "maildirresourcetest.moc"
|