summaryrefslogtreecommitdiffstats
path: root/tests/querytest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/querytest.cpp')
-rw-r--r--tests/querytest.cpp161
1 files changed, 161 insertions, 0 deletions
diff --git a/tests/querytest.cpp b/tests/querytest.cpp
new file mode 100644
index 0000000..669bf58
--- /dev/null
+++ b/tests/querytest.cpp
@@ -0,0 +1,161 @@
1#include <QtTest>
2
3#include <QString>
4
5#include "dummyresource/resourcefactory.h"
6#include "clientapi.h"
7#include "commands.h"
8#include "resourceconfig.h"
9#include "log.h"
10#include "modelresult.h"
11
12/**
13 * Test of the query system using the dummy resource.
14 *
15 * This test requires the dummy resource installed.
16 */
17class QueryTest : public QObject
18{
19 Q_OBJECT
20private Q_SLOTS:
21 void initTestCase()
22 {
23 Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace);
24 auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy");
25 QVERIFY(factory);
26 DummyResource::removeFromDisk("org.kde.dummy.instance1");
27 ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy");
28 }
29
30 void cleanup()
31 {
32 Akonadi2::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished();
33 DummyResource::removeFromDisk("org.kde.dummy.instance1");
34 auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy");
35 QVERIFY(factory);
36 }
37
38 void init()
39 {
40 qDebug();
41 qDebug() << "-----------------------------------------";
42 qDebug();
43 }
44
45 void testSingle()
46 {
47 //Setup
48 {
49 Akonadi2::ApplicationDomain::Mail mail("org.kde.dummy.instance1");
50 Akonadi2::Store::create<Akonadi2::ApplicationDomain::Mail>(mail).exec().waitForFinished();
51 }
52
53 //Test
54 Akonadi2::Query query;
55 query.resources << "org.kde.dummy.instance1";
56 query.syncOnDemand = false;
57 query.processAll = false;
58 query.liveQuery = true;
59
60 //We fetch before the data is available and rely on the live query mechanism to deliver the actual data
61 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query);
62 model->fetchMore(QModelIndex());
63 QTRY_COMPARE(model->rowCount(), 1);
64 }
65
66 void testSingleWithDelay()
67 {
68 //Setup
69 {
70 Akonadi2::ApplicationDomain::Mail mail("org.kde.dummy.instance1");
71 Akonadi2::Store::create<Akonadi2::ApplicationDomain::Mail>(mail).exec().waitForFinished();
72 }
73
74 //Test
75 Akonadi2::Query query;
76 query.resources << "org.kde.dummy.instance1";
77 query.syncOnDemand = false;
78 query.processAll = true;
79 query.liveQuery = false;
80
81 //We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data
82 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query);
83
84 //Ensure all local data is processed
85 Akonadi2::Store::synchronize(query).exec().waitForFinished();
86
87 model->fetchMore(QModelIndex());
88 QVERIFY(model->rowCount() < 2);
89 QTRY_COMPARE(model->rowCount(), 1);
90 }
91
92 void testFolder()
93 {
94 //Setup
95 {
96 Akonadi2::ApplicationDomain::Folder folder("org.kde.dummy.instance1");
97 Akonadi2::Store::create<Akonadi2::ApplicationDomain::Folder>(folder).exec().waitForFinished();
98 }
99
100 //Test
101 Akonadi2::Query query;
102 query.resources << "org.kde.dummy.instance1";
103 query.syncOnDemand = false;
104 query.processAll = false;
105 query.liveQuery = true;
106
107 //We fetch before the data is available and rely on the live query mechanism to deliver the actual data
108 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query);
109 model->fetchMore(QModelIndex());
110 QTRY_COMPARE(model->rowCount(), 1);
111 auto folderEntity = model->index(0, 0).data(Akonadi2::Store::DomainObjectRole).value<Akonadi2::ApplicationDomain::Folder::Ptr>();
112 QVERIFY(!folderEntity->identifier().isEmpty());
113 }
114
115 void testFolderTree()
116 {
117 //Setup
118 {
119 Akonadi2::ApplicationDomain::Folder folder("org.kde.dummy.instance1");
120 Akonadi2::Store::create<Akonadi2::ApplicationDomain::Folder>(folder).exec().waitForFinished();
121
122 Akonadi2::Query query;
123 query.resources << "org.kde.dummy.instance1";
124 query.syncOnDemand = false;
125 query.processAll = true;
126
127 //Ensure all local data is processed
128 Akonadi2::Store::synchronize(query).exec().waitForFinished();
129
130 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query);
131 QTRY_COMPARE(model->rowCount(), 1);
132
133 auto folderEntity = model->index(0, 0).data(Akonadi2::Store::DomainObjectRole).value<Akonadi2::ApplicationDomain::Folder::Ptr>();
134 QVERIFY(!folderEntity->identifier().isEmpty());
135
136 Akonadi2::ApplicationDomain::Folder subfolder("org.kde.dummy.instance1");
137 subfolder.setProperty("parent", folderEntity->identifier());
138 Akonadi2::Store::create<Akonadi2::ApplicationDomain::Folder>(subfolder).exec().waitForFinished();
139 }
140
141 //Test
142 Akonadi2::Query query;
143 query.resources << "org.kde.dummy.instance1";
144 query.syncOnDemand = false;
145 query.processAll = true;
146 query.parentProperty = "parent";
147
148 //Ensure all local data is processed
149 Akonadi2::Store::synchronize(query).exec().waitForFinished();
150
151 //We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data
152 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query);
153 model->fetchMore(QModelIndex());
154 QTRY_COMPARE(model->rowCount(), 1);
155 model->fetchMore(model->index(0, 0));
156 QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1);
157 }
158};
159
160QTEST_MAIN(QueryTest)
161#include "querytest.moc"