summaryrefslogtreecommitdiffstats
path: root/tests/maildirresourcetest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/maildirresourcetest.cpp')
-rw-r--r--tests/maildirresourcetest.cpp89
1 files changed, 87 insertions, 2 deletions
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp
index c65cdf0..bef94ba 100644
--- a/tests/maildirresourcetest.cpp
+++ b/tests/maildirresourcetest.cpp
@@ -11,6 +11,32 @@
11#include "pipeline.h" 11#include "pipeline.h"
12#include "log.h" 12#include "log.h"
13 13
14static bool copyRecursively(const QString &srcFilePath,
15 const QString &tgtFilePath)
16{
17 QFileInfo srcFileInfo(srcFilePath);
18 if (srcFileInfo.isDir()) {
19 QDir targetDir(tgtFilePath);
20 targetDir.cdUp();
21 if (!targetDir.mkdir(QFileInfo(tgtFilePath).fileName()))
22 return false;
23 QDir sourceDir(srcFilePath);
24 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
25 foreach (const QString &fileName, fileNames) {
26 const QString newSrcFilePath
27 = srcFilePath + QLatin1Char('/') + fileName;
28 const QString newTgtFilePath
29 = tgtFilePath + QLatin1Char('/') + fileName;
30 if (!copyRecursively(newSrcFilePath, newTgtFilePath))
31 return false;
32 }
33 } else {
34 if (!QFile::copy(srcFilePath, tgtFilePath))
35 return false;
36 }
37 return true;
38}
39
14/** 40/**
15 * Test of complete system using the maildir resource. 41 * Test of complete system using the maildir resource.
16 * 42 *
@@ -22,6 +48,12 @@ class MaildirResourceTest : public QObject
22private Q_SLOTS: 48private Q_SLOTS:
23 void initTestCase() 49 void initTestCase()
24 { 50 {
51 auto targetPath = QDir::tempPath() + QDir::separator() + "maildirresourcetest" + QDir::separator() + "maildir1";
52 QDir dir(targetPath);
53 dir.removeRecursively();
54
55 copyRecursively(TESTDATAPATH "/maildir1", targetPath);
56
25 Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); 57 Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace);
26 auto factory = Akonadi2::ResourceFactory::load("org.kde.maildir"); 58 auto factory = Akonadi2::ResourceFactory::load("org.kde.maildir");
27 QVERIFY(factory); 59 QVERIFY(factory);
@@ -29,7 +61,7 @@ private Q_SLOTS:
29 Akonadi2::ApplicationDomain::AkonadiResource resource; 61 Akonadi2::ApplicationDomain::AkonadiResource resource;
30 resource.setProperty("identifier", "org.kde.maildir.instance1"); 62 resource.setProperty("identifier", "org.kde.maildir.instance1");
31 resource.setProperty("type", "org.kde.maildir"); 63 resource.setProperty("type", "org.kde.maildir");
32 resource.setProperty("path", "/work/build/local-mail"); 64 resource.setProperty("path", targetPath);
33 Akonadi2::Store::create(resource).exec().waitForFinished(); 65 Akonadi2::Store::create(resource).exec().waitForFinished();
34 } 66 }
35 67
@@ -57,7 +89,60 @@ private Q_SLOTS:
57 Akonadi2::Store::synchronize(query).exec().waitForFinished(); 89 Akonadi2::Store::synchronize(query).exec().waitForFinished();
58 90
59 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); 91 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query);
60 QTRY_VERIFY(model->rowCount(QModelIndex()) > 1); 92 QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
93 QVERIFY(model->rowCount(QModelIndex()) > 1);
94 }
95
96 void testListFolderTree()
97 {
98 Akonadi2::Query query;
99 query.resources << "org.kde.maildir.instance1";
100 query.syncOnDemand = true;
101 query.processAll = true;
102 query.parentProperty = "parent";
103
104 //Ensure all local data is processed
105 Akonadi2::Store::synchronize(query).exec().waitForFinished();
106
107 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query);
108 QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
109 QCOMPARE(model->rowCount(QModelIndex()), 1);
110 auto parentIndex = model->index(0, 0, QModelIndex());
111 model->fetchMore(parentIndex);
112 QTRY_VERIFY(model->data(parentIndex, Akonadi2::Store::ChildrenFetchedRole).toBool());
113 QCOMPARE(model->rowCount(parentIndex), 1);
114 }
115
116 void testListMailsOfFolder()
117 {
118 {
119 Akonadi2::Query query;
120 query.resources << "org.kde.maildir.instance1";
121 query.syncOnDemand = true;
122 query.processAll = true;
123
124 //Ensure all local data is processed
125 Akonadi2::Store::synchronize(query).exec().waitForFinished();
126 }
127 QByteArray folderIdentifier;
128 {
129 Akonadi2::Query query;
130 query.resources << "org.kde.maildir.instance1";
131 query.requestedProperties << "folder" << "name";
132
133 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query);
134 QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
135 QVERIFY(model->rowCount(QModelIndex()) > 1);
136 folderIdentifier = model->index(1, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value<Akonadi2::ApplicationDomain::Folder::Ptr>()->identifier();
137 }
138
139 Akonadi2::Query query;
140 query.resources << "org.kde.maildir.instance1";
141 query.requestedProperties << "folder" << "summary";
142 query.propertyFilter.insert("folder", folderIdentifier);
143 auto mailModel = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query);
144 QTRY_VERIFY(mailModel->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
145 QVERIFY(mailModel->rowCount(QModelIndex()) >= 1);
61 } 146 }
62 147
63}; 148};