Changeset View
Changeset View
Standalone View
Standalone View
tests/units/testlib/akonadifakedatatest.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/akonadifakedata.h" | 24 | #include "testlib/akonadifakedata.h" | ||
25 | #include "akonadi/akonadimonitorinterface.h" | 25 | #include "akonadi/akonadimonitorinterface.h" | ||
26 | #include "akonadi/akonadiserializer.h" | ||||
26 | 27 | | |||
27 | #include <testlib/qtest_zanshin.h> | 28 | #include <testlib/qtest_zanshin.h> | ||
28 | 29 | | |||
30 | #include <akonadiserializer.h> | ||||
31 | | ||||
29 | namespace QTest { | 32 | namespace QTest { | ||
30 | 33 | | |||
31 | template<typename T> | 34 | template<typename T> | ||
32 | inline bool zCompareHelper(bool isOk, | 35 | inline bool zCompareHelper(bool isOk, | ||
33 | const T &left, const T &right, | 36 | const T &left, const T &right, | ||
34 | const char *actual, const char *expected, | 37 | const char *actual, const char *expected, | ||
35 | const char *file, int line) | 38 | const char *file, int line) | ||
36 | { | 39 | { | ||
37 | return compare_helper(isOk, isOk ? "COMPARE()" : "Compared values are not the same", | 40 | return compare_helper(isOk, isOk ? "COMPARE()" : "Compared values are not the same", | ||
38 | toString<T>(left), toString<T>(right), | 41 | toString<T>(left), toString<T>(right), | ||
39 | actual, expected, | 42 | actual, expected, | ||
40 | file, line); | 43 | file, line); | ||
41 | } | 44 | } | ||
42 | 45 | | |||
43 | // More aggressive compare to make sure we just don't get collections with ids out | 46 | // More aggressive compare to make sure we just don't get collections with ids out | ||
44 | template <> | 47 | template <> | ||
45 | inline bool qCompare(const Akonadi::Collection &left, const Akonadi::Collection &right, | 48 | inline bool qCompare(const Akonadi::Collection &left, const Akonadi::Collection &right, | ||
46 | const char *actual, const char *expected, | 49 | const char *actual, const char *expected, | ||
47 | const char *file, int line) | 50 | const char *file, int line) | ||
48 | { | 51 | { | ||
49 | return zCompareHelper((left == right) && (left.displayName() == right.displayName()), | 52 | return zCompareHelper((left == right) && (left.displayName() == right.displayName()), | ||
50 | left, right, actual, expected, file, line); | 53 | left, right, actual, expected, file, line); | ||
51 | } | 54 | } | ||
52 | 55 | | |||
53 | // More aggressive compare to make sure we just don't get tags with ids out | | |||
54 | template <> | | |||
55 | inline bool qCompare(const Akonadi::Tag &left, const Akonadi::Tag &right, | | |||
56 | const char *actual, const char *expected, | | |||
57 | const char *file, int line) | | |||
58 | { | | |||
59 | return zCompareHelper((left == right) && (left.name() == right.name()), | | |||
60 | left, right, actual, expected, file, line); | | |||
61 | } | | |||
62 | | ||||
63 | // More aggressive compare to make sure we just don't get items with ids out | 56 | // More aggressive compare to make sure we just don't get items with ids out | ||
64 | template <> | 57 | template <> | ||
65 | inline bool qCompare(const Akonadi::Item &left, const Akonadi::Item &right, | 58 | inline bool qCompare(const Akonadi::Item &left, const Akonadi::Item &right, | ||
66 | const char *actual, const char *expected, | 59 | const char *actual, const char *expected, | ||
67 | const char *file, int line) | 60 | const char *file, int line) | ||
68 | { | 61 | { | ||
69 | return zCompareHelper((left == right) && (left.payloadData() == right.payloadData()), | 62 | return zCompareHelper((left == right) && (left.payloadData() == right.payloadData()), | ||
70 | left, right, actual, expected, file, line); | 63 | left, right, actual, expected, file, line); | ||
71 | } | 64 | } | ||
72 | 65 | | |||
73 | } | 66 | } | ||
74 | 67 | | |||
75 | class AkonadiFakeDataTest : public QObject | 68 | class AkonadiFakeDataTest : public QObject | ||
76 | { | 69 | { | ||
77 | Q_OBJECT | 70 | Q_OBJECT | ||
78 | public: | 71 | public: | ||
79 | explicit AkonadiFakeDataTest(QObject *parent = nullptr) | 72 | explicit AkonadiFakeDataTest(QObject *parent = nullptr) | ||
80 | : QObject(parent) | 73 | : QObject(parent) | ||
81 | { | 74 | { | ||
82 | qRegisterMetaType<Akonadi::Collection>(); | 75 | qRegisterMetaType<Akonadi::Collection>(); | ||
83 | qRegisterMetaType<Akonadi::Tag>(); | | |||
84 | qRegisterMetaType<Akonadi::Item>(); | 76 | qRegisterMetaType<Akonadi::Item>(); | ||
ervin: Remove the line instread of registering the type twice | |||||
dfaure: search/replace side effect ;)
Fixed. | |||||
85 | } | 77 | } | ||
86 | 78 | | |||
87 | private slots: | 79 | private slots: | ||
88 | void shouldBeInitiallyEmpty() | 80 | void shouldBeInitiallyEmpty() | ||
89 | { | 81 | { | ||
90 | // GIVEN | 82 | // GIVEN | ||
91 | auto data = Testlib::AkonadiFakeData(); | 83 | auto data = Testlib::AkonadiFakeData(); | ||
92 | 84 | | |||
93 | // THEN | 85 | // THEN | ||
94 | QVERIFY(data.collections().isEmpty()); | 86 | QVERIFY(data.collections().isEmpty()); | ||
95 | QVERIFY(data.tags().isEmpty()); | 87 | QVERIFY(data.contexts().isEmpty()); | ||
96 | QVERIFY(data.items().isEmpty()); | 88 | QVERIFY(data.items().isEmpty()); | ||
97 | } | 89 | } | ||
98 | 90 | | |||
99 | void shouldCreateCollections() | 91 | void shouldCreateCollections() | ||
100 | { | 92 | { | ||
101 | // GIVEN | 93 | // GIVEN | ||
102 | auto data = Testlib::AkonadiFakeData(); | 94 | auto data = Testlib::AkonadiFakeData(); | ||
103 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | 95 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | ||
Show All 39 Lines | 119 | { | |||
143 | // THEN | 135 | // THEN | ||
144 | QCOMPARE(data.collections().size(), 1); | 136 | QCOMPARE(data.collections().size(), 1); | ||
145 | QCOMPARE(data.collection(c1.id()), c2); | 137 | QCOMPARE(data.collection(c1.id()), c2); | ||
146 | 138 | | |||
147 | QCOMPARE(spy.size(), 1); | 139 | QCOMPARE(spy.size(), 1); | ||
148 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Collection>(), c2); | 140 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Collection>(), c2); | ||
149 | } | 141 | } | ||
150 | 142 | | |||
151 | void shouldNotLooseParentCollectionOnModifyCollection() | 143 | void shouldNotLoseParentCollectionOnModifyCollection() | ||
152 | { | 144 | { | ||
153 | // GIVEN | 145 | // GIVEN | ||
154 | auto data = Testlib::AkonadiFakeData(); | 146 | auto data = Testlib::AkonadiFakeData(); | ||
155 | 147 | | |||
156 | auto root = Akonadi::Collection(42); | 148 | auto root = Akonadi::Collection(42); | ||
157 | root.setName(QStringLiteral("root")); | 149 | root.setName(QStringLiteral("root")); | ||
158 | data.createCollection(root); | 150 | data.createCollection(root); | ||
159 | 151 | | |||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | |||||
222 | } | 214 | } | ||
223 | 215 | | |||
224 | void shouldRemoveCollections() | 216 | void shouldRemoveCollections() | ||
225 | { | 217 | { | ||
226 | // GIVEN | 218 | // GIVEN | ||
227 | auto data = Testlib::AkonadiFakeData(); | 219 | auto data = Testlib::AkonadiFakeData(); | ||
228 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | 220 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | ||
229 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::collectionRemoved); | 221 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::collectionRemoved); | ||
222 | Akonadi::Serializer serializer; | ||||
230 | 223 | | |||
231 | auto c1 = Akonadi::Collection(42); | 224 | auto c1 = Akonadi::Collection(42); | ||
232 | c1.setName(QStringLiteral("42")); | 225 | c1.setName(QStringLiteral("42")); | ||
233 | data.createCollection(c1); | 226 | data.createCollection(c1); | ||
234 | 227 | | |||
235 | auto c2 = Akonadi::Collection(43); | 228 | auto c2 = Akonadi::Collection(43); | ||
236 | c2.setName(QStringLiteral("43")); | 229 | c2.setName(QStringLiteral("43")); | ||
237 | c2.setParentCollection(Akonadi::Collection(42)); | 230 | c2.setParentCollection(Akonadi::Collection(42)); | ||
238 | data.createCollection(c2); | 231 | data.createCollection(c2); | ||
239 | 232 | | |||
240 | auto c3 = Akonadi::Collection(44); | 233 | auto c3 = Akonadi::Collection(44); | ||
241 | c3.setName(QStringLiteral("44")); | 234 | c3.setName(QStringLiteral("44")); | ||
242 | c3.setParentCollection(Akonadi::Collection(43)); | 235 | c3.setParentCollection(Akonadi::Collection(43)); | ||
243 | data.createCollection(c3); | 236 | data.createCollection(c3); | ||
244 | 237 | | |||
245 | auto i1 = Akonadi::Item(42); | 238 | auto task1 = Domain::Task::Ptr::create(); | ||
246 | i1.setPayloadFromData("42"); | 239 | auto i1 = serializer.createItemFromTask(task1); | ||
240 | i1.setId(42); | ||||
247 | i1.setParentCollection(Akonadi::Collection(43)); | 241 | i1.setParentCollection(Akonadi::Collection(43)); | ||
248 | data.createItem(i1); | 242 | data.createItem(i1); | ||
249 | 243 | | |||
250 | auto i2 = Akonadi::Item(43); | 244 | auto task2 = Domain::Task::Ptr::create(); | ||
251 | i2.setPayloadFromData("43"); | 245 | auto i2 = serializer.createItemFromTask(task2); | ||
246 | i2.setId(43); | ||||
252 | i2.setParentCollection(Akonadi::Collection(44)); | 247 | i2.setParentCollection(Akonadi::Collection(44)); | ||
253 | data.createItem(i2); | 248 | data.createItem(i2); | ||
254 | 249 | | |||
255 | // WHEN | 250 | // WHEN | ||
256 | data.removeCollection(c2); | 251 | data.removeCollection(c2); | ||
257 | 252 | | |||
258 | // THEN | 253 | // THEN | ||
259 | QCOMPARE(data.collections().size(), 1); | 254 | QCOMPARE(data.collections().size(), 1); | ||
Show All 14 Lines | |||||
274 | QVERIFY(data.childItems(c2.id()).isEmpty()); | 269 | QVERIFY(data.childItems(c2.id()).isEmpty()); | ||
275 | QVERIFY(data.childItems(c3.id()).isEmpty()); | 270 | QVERIFY(data.childItems(c3.id()).isEmpty()); | ||
276 | 271 | | |||
277 | QCOMPARE(spy.size(), 2); | 272 | QCOMPARE(spy.size(), 2); | ||
278 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Collection>(), c3); | 273 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Collection>(), c3); | ||
279 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Collection>(), c2); | 274 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Collection>(), c2); | ||
280 | } | 275 | } | ||
281 | 276 | | |||
282 | void shouldCreateTags() | 277 | void shouldCreateContexts() | ||
283 | { | 278 | { | ||
284 | // GIVEN | 279 | // GIVEN | ||
285 | auto data = Testlib::AkonadiFakeData(); | 280 | auto data = Testlib::AkonadiFakeData(); | ||
286 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | 281 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | ||
287 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::tagAdded); | 282 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::itemAdded); | ||
283 | Akonadi::Serializer serializer; | ||||
284 | | ||||
285 | auto context1 = Domain::Context::Ptr::create(); | ||||
286 | context1->setName(QStringLiteral("42")); | ||||
287 | context1->setProperty("todoUid", "ctx-42"); | ||||
288 | auto t1 = serializer.createItemFromContext(context1); | ||||
288 | 289 | | |||
289 | auto t1 = Akonadi::Tag(42); | 290 | auto context2 = Domain::Context::Ptr::create(); | ||
290 | t1.setName(QStringLiteral("42")); | 291 | context2->setName(QStringLiteral("43")); | ||
291 | auto t2 = Akonadi::Tag(43); | 292 | context2->setProperty("todoUid", "ctx-43"); | ||
292 | t2.setName(QStringLiteral("43")); | 293 | auto t2 = serializer.createItemFromContext(context2); | ||
293 | 294 | | |||
294 | // WHEN | 295 | // WHEN | ||
295 | data.createTag(t1); | 296 | data.createContext(t1); | ||
296 | data.createTag(t2); | 297 | data.createContext(t2); | ||
297 | 298 | | |||
298 | // THEN | 299 | // THEN | ||
299 | QCOMPARE(data.tags().size(), 2); | 300 | QCOMPARE(data.contexts().size(), 2); | ||
300 | QVERIFY(data.tags().contains(t1)); | 301 | QVERIFY(data.contexts().contains(t1)); | ||
301 | QVERIFY(data.tags().contains(t2)); | 302 | QVERIFY(data.contexts().contains(t2)); | ||
302 | QCOMPARE(data.tag(t1.id()), t1); | 303 | QCOMPARE(data.contextItem("ctx-42"), t1); | ||
303 | QCOMPARE(data.tag(t2.id()), t2); | 304 | QCOMPARE(data.contextItem("ctx-43"), t2); | ||
304 | 305 | | |||
305 | QCOMPARE(spy.size(), 2); | 306 | QCOMPARE(spy.size(), 2); | ||
306 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Tag>(), t1); | 307 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Item>(), t1); | ||
307 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Tag>(), t2); | 308 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Item>(), t2); | ||
308 | } | 309 | } | ||
309 | 310 | | |||
310 | void shouldModifyTags() | 311 | void shouldModifyContexts() | ||
311 | { | 312 | { | ||
312 | // GIVEN | 313 | // GIVEN | ||
313 | auto data = Testlib::AkonadiFakeData(); | 314 | auto data = Testlib::AkonadiFakeData(); | ||
314 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | 315 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | ||
315 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::tagChanged); | 316 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::itemChanged); | ||
317 | Akonadi::Serializer serializer; | ||||
316 | 318 | | |||
317 | auto t1 = Akonadi::Tag(42); | 319 | auto context1 = Domain::Context::Ptr::create(); | ||
318 | t1.setName(QStringLiteral("42")); | 320 | context1->setName(QStringLiteral("42")); | ||
319 | data.createTag(t1); | 321 | context1->setProperty("todoUid", "ctx-42"); | ||
322 | auto t1 = serializer.createItemFromContext(context1); | ||||
323 | data.createContext(t1); | ||||
320 | 324 | | |||
321 | auto t2 = Akonadi::Tag(t1.id()); | 325 | auto context2 = Domain::Context::Ptr::create(); | ||
322 | t2.setName(QStringLiteral("42-bis")); | 326 | context2->setName(QStringLiteral("42-bis")); | ||
327 | context2->setProperty("todoUid", "ctx-42"); | ||||
328 | auto t2 = serializer.createItemFromContext(context2); | ||||
323 | 329 | | |||
324 | // WHEN | 330 | // WHEN | ||
325 | data.modifyTag(t2); | 331 | data.modifyContext(t2); | ||
326 | 332 | | |||
327 | // THEN | 333 | // THEN | ||
328 | QCOMPARE(data.tags().size(), 1); | 334 | QCOMPARE(data.contexts().size(), 1); | ||
329 | QCOMPARE(data.tag(t1.id()), t2); | 335 | QCOMPARE(data.contextItem("ctx-42"), t2); | ||
330 | 336 | | |||
331 | QCOMPARE(spy.size(), 1); | 337 | QCOMPARE(spy.size(), 1); | ||
332 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Tag>(), t2); | 338 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Item>(), t2); | ||
333 | } | 339 | } | ||
334 | 340 | | |||
335 | void shouldRemoveTags() | 341 | void shouldRemoveContexts() | ||
336 | { | 342 | { | ||
337 | // GIVEN | 343 | // GIVEN | ||
338 | auto data = Testlib::AkonadiFakeData(); | 344 | auto data = Testlib::AkonadiFakeData(); | ||
339 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | 345 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | ||
340 | QSignalSpy tagSpy(monitor.data(), &Akonadi::MonitorInterface::tagRemoved); | 346 | QSignalSpy contextSpy(monitor.data(), &Akonadi::MonitorInterface::itemRemoved); | ||
341 | QSignalSpy itemSpy(monitor.data(), &Akonadi::MonitorInterface::itemChanged); | 347 | QSignalSpy itemSpy(monitor.data(), &Akonadi::MonitorInterface::itemChanged); | ||
348 | Akonadi::Serializer serializer; | ||||
342 | 349 | | |||
343 | auto c1 = Akonadi::Collection(42); | 350 | auto c1 = Akonadi::Collection(42); | ||
344 | data.createCollection(c1); | 351 | data.createCollection(c1); | ||
345 | 352 | | |||
346 | auto t1 = Akonadi::Tag(42); | 353 | auto context1 = Domain::Context::Ptr::create(); | ||
347 | t1.setName(QStringLiteral("42")); | 354 | context1->setName(QStringLiteral("1")); | ||
348 | data.createTag(t1); | 355 | context1->setProperty("todoUid", "ctx-1"); | ||
349 | 356 | auto t1 = serializer.createItemFromContext(context1); | |||
350 | auto t2 = Akonadi::Tag(43); | 357 | data.createContext(t1); | ||
351 | t2.setName(QStringLiteral("43")); | | |||
352 | data.createTag(t2); | | |||
353 | 358 | | |||
354 | auto i1 = Akonadi::Item(42); | 359 | auto context2 = Domain::Context::Ptr::create(); | ||
355 | i1.setPayloadFromData("42"); | 360 | context2->setName(QStringLiteral("2")); | ||
361 | context2->setProperty("todoUid", "ctx-2"); | ||||
362 | auto t2 = serializer.createItemFromContext(context2); | ||||
363 | data.createContext(t2); | ||||
364 | | ||||
365 | auto task1 = Domain::Task::Ptr::create(); | ||||
366 | auto i1 = serializer.createItemFromTask(task1); | ||||
356 | i1.setParentCollection(c1); | 367 | i1.setParentCollection(c1); | ||
357 | i1.setTag(Akonadi::Tag(t1.id())); | 368 | i1.setId(42); | ||
369 | serializer.addContextToTask(context1, i1); | ||||
358 | data.createItem(i1); | 370 | data.createItem(i1); | ||
371 | QVERIFY(serializer.isContextChild(context1, i1)); | ||||
359 | 372 | | |||
360 | auto i2 = Akonadi::Item(43); | 373 | auto task2 = Domain::Task::Ptr::create(); | ||
361 | i2.setPayloadFromData("43"); | 374 | auto i2 = serializer.createItemFromTask(task2); | ||
362 | i2.setParentCollection(c1); | 375 | i2.setParentCollection(c1); | ||
363 | i2.setTag(Akonadi::Tag(t2.id())); | 376 | i2.setId(43); | ||
377 | serializer.addContextToTask(context2, i2); | ||||
364 | data.createItem(i2); | 378 | data.createItem(i2); | ||
379 | QVERIFY(serializer.isContextChild(context2, i2)); | ||||
365 | 380 | | |||
366 | const auto itemSet = QSet<Akonadi::Item>() << i1 << i2; | 381 | const auto itemSet = QSet<Akonadi::Item>() << i1 << i2; | ||
367 | 382 | | |||
368 | // WHEN | 383 | // WHEN | ||
369 | data.removeTag(t2); | 384 | data.removeContext(t2); | ||
370 | 385 | | |||
371 | // THEN | 386 | // THEN | ||
372 | QCOMPARE(data.tags().size(), 1); | 387 | QCOMPARE(data.contexts().size(), 1); | ||
373 | QCOMPARE(data.tags().at(0), t1); | 388 | QCOMPARE(data.contexts().at(0), t1); | ||
374 | 389 | | |||
375 | QVERIFY(!data.tag(t2.id()).isValid()); | 390 | QVERIFY(!data.contextItem("ctx-2").isValid()); | ||
376 | 391 | | |||
377 | QCOMPARE(data.tagItems(t1.id()).size(), 1); | 392 | QCOMPARE(data.contextItems("ctx-1").size(), 1); | ||
378 | QCOMPARE(data.tagItems(t1.id()).at(0), i1); | 393 | QCOMPARE(data.contextItems("ctx-1").at(0), i1); | ||
379 | QVERIFY(data.tagItems(t2.id()).isEmpty()); | 394 | QVERIFY(data.contextItems("ctx-2").isEmpty()); | ||
380 | 395 | | |||
381 | QCOMPARE(data.items().toList().toSet(), itemSet); | 396 | QCOMPARE(data.items().toList().toSet(), itemSet); | ||
382 | 397 | | |||
383 | QVERIFY(data.item(i1.id()).isValid()); | 398 | QVERIFY(data.item(i1.id()).isValid()); | ||
384 | QVERIFY(data.item(i2.id()).isValid()); | 399 | const auto item2 = data.item(i2.id()); | ||
385 | QVERIFY(!data.item(i2.id()).tags().contains(t2)); | 400 | QVERIFY(item2.isValid()); | ||
401 | QVERIFY(!serializer.isContextChild(context2, item2)); | ||||
386 | 402 | | |||
387 | QCOMPARE(tagSpy.size(), 1); | 403 | QCOMPARE(contextSpy.size(), 1); | ||
388 | QCOMPARE(tagSpy.takeFirst().at(0).value<Akonadi::Tag>(), t2); | 404 | QCOMPARE(contextSpy.takeFirst().at(0).value<Akonadi::Item>(), t2); | ||
389 | 405 | | |||
390 | QCOMPARE(itemSpy.size(), 1); | 406 | QCOMPARE(itemSpy.size(), 1); | ||
391 | QCOMPARE(itemSpy.first().at(0).value<Akonadi::Item>(), i2); | 407 | const auto emittedItem2 = itemSpy.first().at(0).value<Akonadi::Item>(); | ||
392 | QVERIFY(!itemSpy.first().at(0).value<Akonadi::Item>().tags().contains(t2)); | 408 | QCOMPARE(emittedItem2, i2); | ||
409 | QVERIFY(!serializer.isContextChild(context2, emittedItem2)); | ||||
393 | } | 410 | } | ||
394 | 411 | | |||
395 | void shouldCreateItems() | 412 | void shouldCreateItems() | ||
396 | { | 413 | { | ||
397 | // GIVEN | 414 | // GIVEN | ||
398 | auto data = Testlib::AkonadiFakeData(); | 415 | auto data = Testlib::AkonadiFakeData(); | ||
399 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | 416 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | ||
400 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::itemAdded); | 417 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::itemAdded); | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 440 | { | |||
448 | QCOMPARE(data.item(i1.id()), i2); | 465 | QCOMPARE(data.item(i1.id()), i2); | ||
449 | 466 | | |||
450 | QCOMPARE(spy.size(), 1); | 467 | QCOMPARE(spy.size(), 1); | ||
451 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Item>(), i2); | 468 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Item>(), i2); | ||
452 | 469 | | |||
453 | QCOMPARE(moveSpy.size(), 0); | 470 | QCOMPARE(moveSpy.size(), 0); | ||
454 | } | 471 | } | ||
455 | 472 | | |||
456 | void shouldNotLooseParentCollectionOnModifyItem() | 473 | void shouldNotLoseParentCollectionOnModifyItem() | ||
457 | { | 474 | { | ||
458 | // GIVEN | 475 | // GIVEN | ||
459 | auto data = Testlib::AkonadiFakeData(); | 476 | auto data = Testlib::AkonadiFakeData(); | ||
460 | 477 | | |||
461 | auto c1 = Akonadi::Collection(42); | 478 | auto c1 = Akonadi::Collection(42); | ||
462 | c1.setName(QStringLiteral("42")); | 479 | c1.setName(QStringLiteral("42")); | ||
463 | data.createCollection(c1); | 480 | data.createCollection(c1); | ||
464 | 481 | | |||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 520 | { | |||
532 | QCOMPARE(spy.size(), 1); | 549 | QCOMPARE(spy.size(), 1); | ||
533 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Item>(), i1); | 550 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Item>(), i1); | ||
534 | } | 551 | } | ||
535 | 552 | | |||
536 | void shouldListTagItems() | 553 | void shouldListTagItems() | ||
537 | { | 554 | { | ||
538 | // GIVEN | 555 | // GIVEN | ||
539 | auto data = Testlib::AkonadiFakeData(); | 556 | auto data = Testlib::AkonadiFakeData(); | ||
540 | auto t1 = Akonadi::Tag(42); | 557 | Akonadi::Serializer serializer; | ||
541 | t1.setName(QStringLiteral("42")); | | |||
542 | data.createTag(t1); | | |||
543 | 558 | | |||
544 | auto i1 = Akonadi::Item(42); | 559 | auto context1 = Domain::Context::Ptr::create(); | ||
545 | i1.setPayloadFromData("42"); | 560 | context1->setName(QStringLiteral("42")); | ||
546 | i1.setTag(Akonadi::Tag(42)); | 561 | context1->setProperty("todoUid", "ctx-42"); | ||
562 | auto t1 = serializer.createItemFromContext(context1); | ||||
563 | data.createContext(t1); | ||||
564 | | ||||
565 | auto task1 = Domain::Task::Ptr::create(); | ||||
566 | auto i1 = serializer.createItemFromTask(task1); | ||||
567 | i1.setId(1); | ||||
568 | serializer.addContextToTask(context1, i1); | ||||
547 | 569 | | |||
548 | // WHEN | 570 | // WHEN | ||
549 | data.createItem(i1); | 571 | data.createItem(i1); | ||
550 | 572 | | |||
551 | // THEN | 573 | // THEN | ||
552 | QCOMPARE(data.tagItems(t1.id()).size(), 1); | 574 | QCOMPARE(data.contextItems("ctx-42").size(), 1); | ||
553 | QCOMPARE(data.tagItems(t1.id()).at(0), i1); | 575 | QCOMPARE(data.contextItems("ctx-42").at(0), i1); | ||
554 | } | 576 | } | ||
555 | 577 | | |||
556 | void shouldRetagItemsOnModify() | 578 | void shouldRetagItemsOnModify() | ||
557 | { | 579 | { | ||
558 | // GIVEN | 580 | // GIVEN | ||
559 | auto data = Testlib::AkonadiFakeData(); | 581 | auto data = Testlib::AkonadiFakeData(); | ||
560 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | 582 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | ||
561 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::itemChanged); | 583 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::itemChanged); | ||
584 | Akonadi::Serializer serializer; | ||||
562 | 585 | | |||
563 | auto t1 = Akonadi::Tag(42); | 586 | auto context1 = Domain::Context::Ptr::create(); | ||
564 | t1.setName(QStringLiteral("42")); | 587 | context1->setName(QStringLiteral("42")); | ||
565 | data.createTag(t1); | 588 | context1->setProperty("todoUid", "ctx-42"); | ||
566 | 589 | auto t1 = serializer.createItemFromContext(context1); | |||
567 | auto t2 = Akonadi::Tag(43); | 590 | data.createContext(t1); | ||
568 | t2.setName(QStringLiteral("43")); | 591 | | ||
569 | data.createTag(t2); | 592 | auto context2 = Domain::Context::Ptr::create(); | ||
570 | 593 | context2->setName(QStringLiteral("43")); | |||
571 | auto i1 = Akonadi::Item(42); | 594 | context2->setProperty("todoUid", "ctx-43"); | ||
572 | i1.setPayloadFromData("42"); | 595 | auto t2 = serializer.createItemFromContext(context2); | ||
573 | i1.setTag(Akonadi::Tag(42)); | 596 | data.createContext(t2); | ||
597 | | ||||
598 | auto task1 = Domain::Task::Ptr::create(); | ||||
599 | auto i1 = serializer.createItemFromTask(task1); | ||||
600 | i1.setId(1); | ||||
601 | serializer.addContextToTask(context1, i1); | ||||
574 | data.createItem(i1); | 602 | data.createItem(i1); | ||
575 | 603 | | |||
576 | // WHEN | 604 | // WHEN | ||
577 | i1.setPayloadFromData("42-bis"); | 605 | auto i2 = serializer.createItemFromTask(task1); | ||
578 | i1.clearTag(Akonadi::Tag(42)); | 606 | i2.setId(1); | ||
579 | i1.setTag(Akonadi::Tag(43)); | 607 | serializer.addContextToTask(context2, i2); | ||
580 | data.modifyItem(i1); | 608 | data.modifyItem(i2); | ||
581 | 609 | | |||
582 | // THEN | 610 | // THEN | ||
583 | QVERIFY(data.tagItems(t1.id()).isEmpty()); | 611 | QVERIFY(data.contextItems("ctx-42").isEmpty()); | ||
584 | QCOMPARE(data.tagItems(t2.id()).size(), 1); | 612 | QCOMPARE(data.contextItems("ctx-43").size(), 1); | ||
585 | QCOMPARE(data.tagItems(t2.id()).at(0), i1); | 613 | QCOMPARE(data.contextItems("ctx-43").at(0), i2); | ||
586 | 614 | | |||
587 | QCOMPARE(spy.size(), 1); | 615 | QCOMPARE(spy.size(), 1); | ||
588 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Item>(), i1); | 616 | QCOMPARE(spy.takeFirst().at(0).value<Akonadi::Item>(), i2); | ||
589 | } | 617 | } | ||
590 | 618 | | |||
591 | void shouldRemoveItems() | 619 | void shouldRemoveItems() | ||
592 | { | 620 | { | ||
593 | // GIVEN | 621 | // GIVEN | ||
594 | auto data = Testlib::AkonadiFakeData(); | 622 | auto data = Testlib::AkonadiFakeData(); | ||
595 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | 623 | QScopedPointer<Akonadi::MonitorInterface> monitor(data.createMonitor()); | ||
596 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::itemRemoved); | 624 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::itemRemoved); | ||
Show All 26 Lines |
Remove the line instread of registering the type twice