Changeset View
Changeset View
Standalone View
Standalone View
tests/units/akonadi/akonadicontextqueriestest.cpp
Show All 17 Lines | 1 | /* This file is part of Zanshin | |||
---|---|---|---|---|---|
18 | You should have received a copy of the GNU General Public License | 18 | You should have received a copy of the GNU General Public License | ||
19 | along with this program; if not, write to the Free Software | 19 | along with this program; if not, write to the Free Software | ||
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
21 | USA. | 21 | USA. | ||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | #include <testlib/qtest_zanshin.h> | 24 | #include <testlib/qtest_zanshin.h> | ||
25 | 25 | | |||
26 | #include "akonadi/akonadicachingstorage.h" | ||||
26 | #include "akonadi/akonadicontextqueries.h" | 27 | #include "akonadi/akonadicontextqueries.h" | ||
27 | #include "akonadi/akonadiserializer.h" | 28 | #include "akonadi/akonadiserializer.h" | ||
28 | 29 | | |||
29 | #include "testlib/akonadifakedata.h" | 30 | #include "testlib/akonadifakedata.h" | ||
30 | #include "testlib/gencollection.h" | 31 | #include "testlib/gencollection.h" | ||
31 | #include "testlib/gentodo.h" | 32 | #include "testlib/gentodo.h" | ||
32 | #include "testlib/gentag.h" | 33 | #include "testlib/gentag.h" | ||
33 | #include "testlib/testhelpers.h" | 34 | #include "testlib/testhelpers.h" | ||
34 | 35 | | |||
35 | using namespace Testlib; | 36 | using namespace Testlib; | ||
36 | 37 | | |||
37 | class AkonadiContextQueriesTest : public QObject | 38 | class AkonadiContextQueriesTest : public QObject | ||
38 | { | 39 | { | ||
39 | Q_OBJECT | 40 | Q_OBJECT | ||
41 | private: | ||||
42 | Akonadi::StorageInterface::Ptr createCachingStorage(AkonadiFakeData &data, const Akonadi::Cache::Ptr &cache) | ||||
43 | { | ||||
44 | auto storage = Akonadi::StorageInterface::Ptr(data.createStorage()); | ||||
45 | return Akonadi::StorageInterface::Ptr(new Akonadi::CachingStorage(cache, storage)); | ||||
46 | } | ||||
40 | 47 | | |||
41 | private slots: | 48 | private slots: | ||
42 | void shouldDealWithEmptyTagList() | 49 | void shouldDealWithEmptyTagList() | ||
43 | { | 50 | { | ||
44 | // GIVEN | 51 | // GIVEN | ||
45 | AkonadiFakeData data; | 52 | AkonadiFakeData data; | ||
46 | 53 | | |||
47 | // WHEN | 54 | // WHEN | ||
48 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 55 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | ||
49 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | 56 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
50 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 57 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||
58 | Akonadi::Cache::Ptr())); | ||||
51 | auto result = queries->findAll(); | 59 | auto result = queries->findAll(); | ||
52 | 60 | | |||
53 | // THEN | 61 | // THEN | ||
54 | QVERIFY(result->data().isEmpty()); | 62 | QVERIFY(result->data().isEmpty()); | ||
55 | TestHelpers::waitForEmptyJobQueue(); | 63 | TestHelpers::waitForEmptyJobQueue(); | ||
56 | QVERIFY(result->data().isEmpty()); | 64 | QVERIFY(result->data().isEmpty()); | ||
57 | QCOMPARE(result->data().size(), 0); | 65 | QCOMPARE(result->data().size(), 0); | ||
58 | } | 66 | } | ||
59 | 67 | | |||
60 | void shouldLookInAllReportedForAllContexts() | 68 | void shouldLookInAllReportedForAllContexts() | ||
61 | { | 69 | { | ||
62 | // GIVEN | 70 | // GIVEN | ||
63 | AkonadiFakeData data; | 71 | AkonadiFakeData data; | ||
64 | 72 | | |||
65 | // Two context tags | 73 | // Two context tags | ||
66 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | 74 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | ||
67 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43")).asContext()); | 75 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43")).asContext()); | ||
68 | 76 | | |||
69 | // WHEN | 77 | // WHEN | ||
70 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 78 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | ||
71 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | 79 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
72 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 80 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||
81 | Akonadi::Cache::Ptr())); | ||||
73 | auto result = queries->findAll(); | 82 | auto result = queries->findAll(); | ||
74 | result->data(); | 83 | result->data(); | ||
75 | result = queries->findAll(); // Should not cause any problem or wrong data | 84 | result = queries->findAll(); // Should not cause any problem or wrong data | ||
76 | 85 | | |||
77 | // THEN | 86 | // THEN | ||
78 | QVERIFY(result->data().isEmpty()); | 87 | QVERIFY(result->data().isEmpty()); | ||
79 | TestHelpers::waitForEmptyJobQueue(); | 88 | TestHelpers::waitForEmptyJobQueue(); | ||
80 | 89 | | |||
Show All 9 Lines | 96 | { | |||
90 | 99 | | |||
91 | // One context tag and one plain tag | 100 | // One context tag and one plain tag | ||
92 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | 101 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | ||
93 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43")).asPlain()); | 102 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43")).asPlain()); | ||
94 | 103 | | |||
95 | // WHEN | 104 | // WHEN | ||
96 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 105 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | ||
97 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | 106 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
98 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 107 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||
108 | Akonadi::Cache::Ptr())); | ||||
99 | auto result = queries->findAll(); | 109 | auto result = queries->findAll(); | ||
100 | result->data(); | 110 | result->data(); | ||
101 | result = queries->findAll(); // Should not cause any problem or wrong data | 111 | result = queries->findAll(); // Should not cause any problem or wrong data | ||
102 | 112 | | |||
103 | // THEN | 113 | // THEN | ||
104 | QVERIFY(result->data().isEmpty()); | 114 | QVERIFY(result->data().isEmpty()); | ||
105 | TestHelpers::waitForEmptyJobQueue(); | 115 | TestHelpers::waitForEmptyJobQueue(); | ||
106 | 116 | | |||
107 | QCOMPARE(result->data().size(), 1); | 117 | QCOMPARE(result->data().size(), 1); | ||
108 | QCOMPARE(result->data().at(0)->name(), QStringLiteral("42")); | 118 | QCOMPARE(result->data().at(0)->name(), QStringLiteral("42")); | ||
109 | } | 119 | } | ||
110 | 120 | | |||
111 | void shouldReactToTagAdded() | 121 | void shouldReactToTagAdded() | ||
112 | { | 122 | { | ||
113 | // GIVEN | 123 | // GIVEN | ||
114 | AkonadiFakeData data; | 124 | AkonadiFakeData data; | ||
115 | 125 | | |||
116 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 126 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | ||
117 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | 127 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
118 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 128 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||
129 | Akonadi::Cache::Ptr())); | ||||
119 | auto result = queries->findAll(); | 130 | auto result = queries->findAll(); | ||
120 | TestHelpers::waitForEmptyJobQueue(); | 131 | TestHelpers::waitForEmptyJobQueue(); | ||
121 | QVERIFY(result->data().isEmpty()); | 132 | QVERIFY(result->data().isEmpty()); | ||
122 | 133 | | |||
123 | // WHEN | 134 | // WHEN | ||
124 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | 135 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | ||
125 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43")).asContext()); | 136 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43")).asContext()); | ||
126 | 137 | | |||
Show All 9 Lines | 145 | { | |||
136 | AkonadiFakeData data; | 147 | AkonadiFakeData data; | ||
137 | 148 | | |||
138 | // Two context tags | 149 | // Two context tags | ||
139 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | 150 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | ||
140 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43")).asContext()); | 151 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43")).asContext()); | ||
141 | 152 | | |||
142 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 153 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | ||
143 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | 154 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
144 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 155 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||
156 | Akonadi::Cache::Ptr())); | ||||
145 | auto result = queries->findAll(); | 157 | auto result = queries->findAll(); | ||
146 | QVERIFY(result->data().isEmpty()); | 158 | QVERIFY(result->data().isEmpty()); | ||
147 | TestHelpers::waitForEmptyJobQueue(); | 159 | TestHelpers::waitForEmptyJobQueue(); | ||
148 | QCOMPARE(result->data().size(), 2); | 160 | QCOMPARE(result->data().size(), 2); | ||
149 | 161 | | |||
150 | // WHEN | 162 | // WHEN | ||
151 | data.removeTag(Akonadi::Tag(43)); | 163 | data.removeTag(Akonadi::Tag(43)); | ||
152 | 164 | | |||
153 | // THEN | 165 | // THEN | ||
154 | QCOMPARE(result->data().size(), 1); | 166 | QCOMPARE(result->data().size(), 1); | ||
155 | QCOMPARE(result->data().at(0)->name(), QStringLiteral("42")); | 167 | QCOMPARE(result->data().at(0)->name(), QStringLiteral("42")); | ||
156 | } | 168 | } | ||
157 | 169 | | |||
158 | void shouldReactToTagChanges() | 170 | void shouldReactToTagChanges() | ||
159 | { | 171 | { | ||
160 | // GIVEN | 172 | // GIVEN | ||
161 | AkonadiFakeData data; | 173 | AkonadiFakeData data; | ||
162 | 174 | | |||
163 | // Two context tags | 175 | // Two context tags | ||
164 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | 176 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | ||
165 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43")).asContext()); | 177 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43")).asContext()); | ||
166 | 178 | | |||
167 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 179 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | ||
168 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | 180 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
169 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 181 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||
182 | Akonadi::Cache::Ptr())); | ||||
170 | auto result = queries->findAll(); | 183 | auto result = queries->findAll(); | ||
171 | QVERIFY(result->data().isEmpty()); | 184 | QVERIFY(result->data().isEmpty()); | ||
172 | TestHelpers::waitForEmptyJobQueue(); | 185 | TestHelpers::waitForEmptyJobQueue(); | ||
173 | QCOMPARE(result->data().size(), 2); | 186 | QCOMPARE(result->data().size(), 2); | ||
174 | 187 | | |||
175 | // WHEN | 188 | // WHEN | ||
176 | data.modifyTag(GenTag(data.tag(43)).withName(QStringLiteral("43bis"))); | 189 | data.modifyTag(GenTag(data.tag(43)).withName(QStringLiteral("43bis"))); | ||
177 | 190 | | |||
Show All 16 Lines | 198 | { | |||
194 | 207 | | |||
195 | // Three tasks in the collection, two related to context, one not | 208 | // Three tasks in the collection, two related to context, one not | ||
196 | data.createItem(GenTodo().withParent(42).withId(42).withTitle(QStringLiteral("42")).withTags({42})); | 209 | data.createItem(GenTodo().withParent(42).withId(42).withTitle(QStringLiteral("42")).withTags({42})); | ||
197 | data.createItem(GenTodo().withParent(42).withId(43).withTitle(QStringLiteral("43"))); | 210 | data.createItem(GenTodo().withParent(42).withId(43).withTitle(QStringLiteral("43"))); | ||
198 | data.createItem(GenTodo().withParent(42).withId(44).withTitle(QStringLiteral("44")).withTags({42})); | 211 | data.createItem(GenTodo().withParent(42).withId(44).withTitle(QStringLiteral("44")).withTags({42})); | ||
199 | 212 | | |||
200 | // WHEN | 213 | // WHEN | ||
201 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | 214 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | ||
202 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 215 | auto cache = Akonadi::Cache::Ptr::create(serializer, Akonadi::MonitorInterface::Ptr(data.createMonitor())); | ||
216 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(createCachingStorage(data, cache), | ||||
203 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | 217 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
204 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 218 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||
219 | cache)); | ||||
205 | 220 | | |||
206 | auto context = serializer->createContextFromTag(data.tag(42)); | 221 | auto context = serializer->createContextFromTag(data.tag(42)); | ||
207 | auto result = queries->findTopLevelTasks(context); | 222 | auto result = queries->findTopLevelTasks(context); | ||
208 | result->data(); | 223 | result->data(); | ||
209 | result = queries->findTopLevelTasks(context); // Should not cause any problem or wrong data | 224 | result = queries->findTopLevelTasks(context); // Should not cause any problem or wrong data | ||
210 | 225 | | |||
211 | // THEN | 226 | // THEN | ||
212 | QVERIFY(result->data().isEmpty()); | 227 | QVERIFY(result->data().isEmpty()); | ||
Show All 19 Lines | 244 | { | |||
232 | 247 | | |||
233 | // One top level collection | 248 | // One top level collection | ||
234 | data.createCollection(GenCollection().withId(42).withRootAsParent().withTaskContent()); | 249 | data.createCollection(GenCollection().withId(42).withRootAsParent().withTaskContent()); | ||
235 | 250 | | |||
236 | // One context tag | 251 | // One context tag | ||
237 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | 252 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | ||
238 | 253 | | |||
239 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | 254 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | ||
240 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 255 | auto cache = Akonadi::Cache::Ptr::create(serializer, Akonadi::MonitorInterface::Ptr(data.createMonitor())); | ||
256 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(createCachingStorage(data, cache), | ||||
241 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | 257 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
242 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 258 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||
259 | cache)); | ||||
243 | 260 | | |||
244 | auto context = serializer->createContextFromTag(data.tag(42)); | 261 | auto context = serializer->createContextFromTag(data.tag(42)); | ||
245 | auto result = queries->findTopLevelTasks(context); | 262 | auto result = queries->findTopLevelTasks(context); | ||
246 | TestHelpers::waitForEmptyJobQueue(); | 263 | TestHelpers::waitForEmptyJobQueue(); | ||
247 | QVERIFY(result->data().isEmpty()); | 264 | QVERIFY(result->data().isEmpty()); | ||
248 | 265 | | |||
249 | // WHEN | 266 | // WHEN | ||
250 | data.createItem(GenTodo().withParent(42).withId(42).withTitle(QStringLiteral("42")).withTags({42})); | 267 | data.createItem(GenTodo().withParent(42).withId(42).withTitle(QStringLiteral("42")).withTags({42})); | ||
Show All 13 Lines | 275 | { | |||
264 | 281 | | |||
265 | // One context tag | 282 | // One context tag | ||
266 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | 283 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | ||
267 | 284 | | |||
268 | // One task related to the context | 285 | // One task related to the context | ||
269 | data.createItem(GenTodo().withParent(42).withId(42).withTitle(QStringLiteral("42")).withTags({42})); | 286 | data.createItem(GenTodo().withParent(42).withId(42).withTitle(QStringLiteral("42")).withTags({42})); | ||
270 | 287 | | |||
271 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | 288 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | ||
272 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 289 | auto cache = Akonadi::Cache::Ptr::create(serializer, Akonadi::MonitorInterface::Ptr(data.createMonitor())); | ||
290 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(createCachingStorage(data, cache), | ||||
273 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | 291 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
274 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 292 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||
293 | cache)); | ||||
275 | 294 | | |||
276 | auto context = serializer->createContextFromTag(data.tag(42)); | 295 | auto context = serializer->createContextFromTag(data.tag(42)); | ||
277 | auto result = queries->findTopLevelTasks(context); | 296 | auto result = queries->findTopLevelTasks(context); | ||
278 | 297 | | |||
279 | bool replaceHandlerCalled = false; | 298 | bool replaceHandlerCalled = false; | ||
280 | result->addPostReplaceHandler([&replaceHandlerCalled](const Domain::Task::Ptr &, int) { | 299 | result->addPostReplaceHandler([&replaceHandlerCalled](const Domain::Task::Ptr &, int) { | ||
281 | replaceHandlerCalled = true; | 300 | replaceHandlerCalled = true; | ||
282 | }); | 301 | }); | ||
Show All 20 Lines | 316 | { | |||
303 | 322 | | |||
304 | // One context tag | 323 | // One context tag | ||
305 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | 324 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | ||
306 | 325 | | |||
307 | // One task not related to the context | 326 | // One task not related to the context | ||
308 | data.createItem(GenTodo().withParent(42).withId(42).withTitle(QStringLiteral("42"))); | 327 | data.createItem(GenTodo().withParent(42).withId(42).withTitle(QStringLiteral("42"))); | ||
309 | 328 | | |||
310 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | 329 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | ||
311 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 330 | auto cache = Akonadi::Cache::Ptr::create(serializer, Akonadi::MonitorInterface::Ptr(data.createMonitor())); | ||
331 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(createCachingStorage(data, cache), | ||||
312 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | 332 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
313 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 333 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||
334 | cache)); | ||||
314 | 335 | | |||
315 | auto context = serializer->createContextFromTag(data.tag(42)); | 336 | auto context = serializer->createContextFromTag(data.tag(42)); | ||
316 | auto result = queries->findTopLevelTasks(context); | 337 | auto result = queries->findTopLevelTasks(context); | ||
317 | TestHelpers::waitForEmptyJobQueue(); | 338 | TestHelpers::waitForEmptyJobQueue(); | ||
318 | QVERIFY(result->data().isEmpty()); | 339 | QVERIFY(result->data().isEmpty()); | ||
319 | 340 | | |||
320 | // WHEN | 341 | // WHEN | ||
321 | data.modifyItem(GenTodo(data.item(42)).withTags({42})); | 342 | data.modifyItem(GenTodo(data.item(42)).withTags({42})); | ||
Show All 13 Lines | 350 | { | |||
335 | 356 | | |||
336 | // One context tag | 357 | // One context tag | ||
337 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | 358 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | ||
338 | 359 | | |||
339 | // One task related to the context | 360 | // One task related to the context | ||
340 | data.createItem(GenTodo().withParent(42).withId(42).withTitle(QStringLiteral("42")).withTags({42})); | 361 | data.createItem(GenTodo().withParent(42).withId(42).withTitle(QStringLiteral("42")).withTags({42})); | ||
341 | 362 | | |||
342 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | 363 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | ||
343 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 364 | auto cache = Akonadi::Cache::Ptr::create(serializer, Akonadi::MonitorInterface::Ptr(data.createMonitor())); | ||
365 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(createCachingStorage(data, cache), | ||||
344 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | 366 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
345 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 367 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||
368 | cache)); | ||||
346 | 369 | | |||
347 | auto context = serializer->createContextFromTag(data.tag(42)); | 370 | auto context = serializer->createContextFromTag(data.tag(42)); | ||
348 | auto result = queries->findTopLevelTasks(context); | 371 | auto result = queries->findTopLevelTasks(context); | ||
349 | TestHelpers::waitForEmptyJobQueue(); | 372 | TestHelpers::waitForEmptyJobQueue(); | ||
350 | QCOMPARE(result->data().size(), 1); | 373 | QCOMPARE(result->data().size(), 1); | ||
351 | 374 | | |||
352 | // WHEN | 375 | // WHEN | ||
353 | data.modifyItem(GenTodo(data.item(42)).withTags({})); | 376 | data.modifyItem(GenTodo(data.item(42)).withTags({})); | ||
Show All 13 Lines | 383 | { | |||
367 | // Two context tags | 390 | // Two context tags | ||
368 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | 391 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42")).asContext()); | ||
369 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43")).asContext()); | 392 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43")).asContext()); | ||
370 | 393 | | |||
371 | // One task related to the first context | 394 | // One task related to the first context | ||
372 | data.createItem(GenTodo().withParent(42).withId(42).withTitle(QStringLiteral("42")).withTags({42})); | 395 | data.createItem(GenTodo().withParent(42).withId(42).withTitle(QStringLiteral("42")).withTags({42})); | ||
373 | 396 | | |||
374 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | 397 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | ||
375 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 398 | auto cache = Akonadi::Cache::Ptr::create(serializer, Akonadi::MonitorInterface::Ptr(data.createMonitor())); | ||
399 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(createCachingStorage(data, cache), | ||||
376 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | 400 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
377 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 401 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||
402 | cache)); | ||||
378 | 403 | | |||
379 | auto context1 = serializer->createContextFromTag(data.tag(42)); | 404 | auto context1 = serializer->createContextFromTag(data.tag(42)); | ||
380 | auto result1 = queries->findTopLevelTasks(context1); | 405 | auto result1 = queries->findTopLevelTasks(context1); | ||
381 | auto context2 = serializer->createContextFromTag(data.tag(43)); | 406 | auto context2 = serializer->createContextFromTag(data.tag(43)); | ||
382 | auto result2 = queries->findTopLevelTasks(context2); | 407 | auto result2 = queries->findTopLevelTasks(context2); | ||
383 | TestHelpers::waitForEmptyJobQueue(); | 408 | TestHelpers::waitForEmptyJobQueue(); | ||
384 | QCOMPARE(result1->data().size(), 1); | 409 | QCOMPARE(result1->data().size(), 1); | ||
385 | QCOMPARE(result1->data().at(0)->title(), QStringLiteral("42")); | 410 | QCOMPARE(result1->data().at(0)->title(), QStringLiteral("42")); | ||
Show All 19 Lines | 423 | { | |||
405 | // One top level collection | 430 | // One top level collection | ||
406 | data.createCollection(GenCollection().withId(42).withRootAsParent().withTaskContent()); | 431 | data.createCollection(GenCollection().withId(42).withRootAsParent().withTaskContent()); | ||
407 | 432 | | |||
408 | // A task related to the context | 433 | // A task related to the context | ||
409 | data.createItem(GenTodo().withId(42).withParent(42).withTitle(QStringLiteral("42")).withTags({42})); | 434 | data.createItem(GenTodo().withId(42).withParent(42).withTitle(QStringLiteral("42")).withTags({42})); | ||
410 | 435 | | |||
411 | 436 | | |||
412 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | 437 | auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); | ||
413 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(Akonadi::StorageInterface::Ptr(data.createStorage()), | 438 | auto cache = Akonadi::Cache::Ptr::create(serializer, Akonadi::MonitorInterface::Ptr(data.createMonitor())); | ||
414 | serializer, | 439 | QScopedPointer<Domain::ContextQueries> queries(new Akonadi::ContextQueries(createCachingStorage(data, cache), | ||
415 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 440 | Akonadi::Serializer::Ptr(new Akonadi::Serializer), | ||
441 | Akonadi::MonitorInterface::Ptr(data.createMonitor()), | ||||
442 | cache)); | ||||
416 | 443 | | |||
417 | auto context = serializer->createContextFromTag(data.tag(42)); | 444 | auto context = serializer->createContextFromTag(data.tag(42)); | ||
418 | auto result = queries->findTopLevelTasks(context); | 445 | auto result = queries->findTopLevelTasks(context); | ||
419 | 446 | | |||
420 | bool removeHandlerCalled = false; | 447 | bool removeHandlerCalled = false; | ||
421 | result->addPostRemoveHandler([&removeHandlerCalled](const Domain::Artifact::Ptr &, int) { | 448 | result->addPostRemoveHandler([&removeHandlerCalled](const Domain::Artifact::Ptr &, int) { | ||
422 | removeHandlerCalled = true; | 449 | removeHandlerCalled = true; | ||
423 | }); | 450 | }); | ||
Show All 17 Lines |