Changeset View
Changeset View
Standalone View
Standalone View
agents/unifiedmailboxagent/autotests/unifiedmailboxmanagertest.cpp
Show All 14 Lines | 1 | /* | |||
---|---|---|---|---|---|
15 | along with this program; see the file COPYING. If not, write to | 15 | along with this program; see the file COPYING. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "../unifiedmailboxmanager.h" | 20 | #include "../unifiedmailboxmanager.h" | ||
21 | #include "../unifiedmailbox.h" | 21 | #include "../unifiedmailbox.h" | ||
22 | #include "../common.h" | 22 | #include "../common.h" | ||
23 | #include "../utils.h" | | |||
24 | 23 | | |||
25 | #include <KSharedConfig> | 24 | #include <KSharedConfig> | ||
26 | #include <KConfigGroup> | 25 | #include <KConfigGroup> | ||
27 | 26 | | |||
28 | #include <AkonadiCore/SpecialCollectionAttribute> | 27 | #include <AkonadiCore/SpecialCollectionAttribute> | ||
29 | #include <AkonadiCore/CollectionFetchJob> | 28 | #include <AkonadiCore/CollectionFetchJob> | ||
30 | #include <AkonadiCore/CollectionFetchScope> | 29 | #include <AkonadiCore/CollectionFetchScope> | ||
31 | #include <AkonadiCore/CollectionCreateJob> | 30 | #include <AkonadiCore/CollectionCreateJob> | ||
Show All 21 Lines | 48 | #define AKVERIFY_RET(statement, ret) \ | |||
53 | } while (false) | 52 | } while (false) | ||
54 | 53 | | |||
55 | #define AKCOMPARE_RET(actual, expected, ret) \ | 54 | #define AKCOMPARE_RET(actual, expected, ret) \ | ||
56 | do { \ | 55 | do { \ | ||
57 | if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)) { \ | 56 | if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)) { \ | ||
58 | return ret;} \ | 57 | return ret;} \ | ||
59 | } while (false) | 58 | } while (false) | ||
60 | 59 | | |||
61 | stdx::optional<Akonadi::Collection> collectionForId(qint64 id) | 60 | Akonadi::Collection collectionForId(qint64 id) | ||
62 | { | 61 | { | ||
63 | auto fetch = new Akonadi::CollectionFetchJob(Akonadi::Collection(id), Akonadi::CollectionFetchJob::Base); | 62 | auto fetch = new Akonadi::CollectionFetchJob(Akonadi::Collection(id), Akonadi::CollectionFetchJob::Base); | ||
64 | fetch->fetchScope().fetchAttribute<Akonadi::SpecialCollectionAttribute>(); | 63 | fetch->fetchScope().fetchAttribute<Akonadi::SpecialCollectionAttribute>(); | ||
65 | AKVERIFY_RET(fetch->exec(), stdx::nullopt); | 64 | AKVERIFY_RET(fetch->exec(), {}); | ||
66 | const auto cols = fetch->collections(); | 65 | const auto cols = fetch->collections(); | ||
67 | AKCOMPARE_RET(cols.count(), 1, stdx::nullopt); | 66 | AKCOMPARE_RET(cols.count(), 1, {}); | ||
68 | AKVERIFY_RET(cols.first().isValid(), stdx::nullopt); | | |||
69 | return cols.first(); | 67 | return cols.first(); | ||
70 | } | 68 | } | ||
71 | 69 | | |||
72 | stdx::optional<Akonadi::Collection> collectionForRid(const QString &rid) | 70 | Akonadi::Collection collectionForRid(const QString &rid) | ||
73 | { | 71 | { | ||
74 | auto fetch = new Akonadi::CollectionFetchJob(Akonadi::Collection::root(), Akonadi::CollectionFetchJob::Recursive); | 72 | auto fetch = new Akonadi::CollectionFetchJob(Akonadi::Collection::root(), Akonadi::CollectionFetchJob::Recursive); | ||
75 | fetch->fetchScope().fetchAttribute<Akonadi::SpecialCollectionAttribute>(); | 73 | fetch->fetchScope().fetchAttribute<Akonadi::SpecialCollectionAttribute>(); | ||
76 | fetch->fetchScope().setAncestorRetrieval(Akonadi::CollectionFetchScope::All); | 74 | fetch->fetchScope().setAncestorRetrieval(Akonadi::CollectionFetchScope::All); | ||
77 | AKVERIFY_RET(fetch->exec(), stdx::nullopt); | 75 | AKVERIFY_RET(fetch->exec(), {}); | ||
78 | const auto cols = fetch->collections(); | 76 | const auto cols = fetch->collections(); | ||
79 | auto colIt = std::find_if(cols.cbegin(), cols.cend(), [&rid](const Akonadi::Collection &col) { | 77 | auto colIt = std::find_if(cols.cbegin(), cols.cend(), [&rid](const Akonadi::Collection &col) { | ||
80 | return col.remoteId() == rid; | 78 | return col.remoteId() == rid; | ||
81 | }); | 79 | }); | ||
82 | AKVERIFY_RET(colIt != cols.cend(), stdx::nullopt); | 80 | AKVERIFY_RET(colIt != cols.cend(), {}); | ||
83 | return *colIt; | 81 | return *colIt; | ||
84 | } | 82 | } | ||
85 | 83 | | |||
84 | // A kingdom and a horse for std::optional! | ||||
86 | std::unique_ptr<UnifiedMailbox> createUnifiedMailbox(const QString &id, const QString &name, const QStringList &sourceRids) | 85 | std::unique_ptr<UnifiedMailbox> createUnifiedMailbox(const QString &id, const QString &name, const QStringList &sourceRids) | ||
87 | { | 86 | { | ||
88 | auto mailbox = std::make_unique<UnifiedMailbox>(); | 87 | auto mailbox = std::make_unique<UnifiedMailbox>(); | ||
89 | mailbox->setId(id); | 88 | mailbox->setId(id); | ||
90 | mailbox->setName(name); | 89 | mailbox->setName(name); | ||
91 | mailbox->setIcon(QStringLiteral("dummy-icon")); | 90 | mailbox->setIcon(QStringLiteral("dummy-icon")); | ||
92 | for (const auto &srcRid : sourceRids) { | 91 | for (const auto &srcRid : sourceRids) { | ||
93 | const auto srcCol = collectionForRid(srcRid); | 92 | const auto srcCol = collectionForRid(srcRid); | ||
94 | AKVERIFY_RET(srcCol, {}); | 93 | AKVERIFY_RET(srcCol.isValid(), {}); | ||
95 | mailbox->addSourceCollection(srcCol->id()); | 94 | mailbox->addSourceCollection(srcCol.id()); | ||
96 | } | 95 | } | ||
97 | return mailbox; | 96 | return mailbox; | ||
98 | } | 97 | } | ||
99 | 98 | | |||
100 | class EntityDeleter | 99 | class EntityDeleter | ||
101 | { | 100 | { | ||
102 | public: | 101 | public: | ||
103 | ~EntityDeleter() | 102 | ~EntityDeleter() | ||
Show All 22 Lines | 123 | { | |||
126 | return *this; | 125 | return *this; | ||
127 | } | 126 | } | ||
128 | 127 | | |||
129 | private: | 128 | private: | ||
130 | Akonadi::Collection::List cols; | 129 | Akonadi::Collection::List cols; | ||
131 | Akonadi::Item::List items; | 130 | Akonadi::Item::List items; | ||
132 | }; | 131 | }; | ||
133 | 132 | | |||
134 | stdx::optional<Akonadi::Collection> createCollection(const QString &name, const Akonadi::Collection &parent, EntityDeleter &deleter) | 133 | Akonadi::Collection createCollection(const QString &name, const Akonadi::Collection &parent, EntityDeleter &deleter) | ||
135 | { | 134 | { | ||
136 | Akonadi::Collection col; | 135 | Akonadi::Collection col; | ||
137 | col.setName(name); | 136 | col.setName(name); | ||
138 | col.setParentCollection(parent); | 137 | col.setParentCollection(parent); | ||
139 | col.setVirtual(true); | 138 | col.setVirtual(true); | ||
140 | auto createCol = new Akonadi::CollectionCreateJob(col); | 139 | auto createCol = new Akonadi::CollectionCreateJob(col); | ||
141 | AKVERIFY_RET(createCol->exec(), stdx::nullopt); | 140 | AKVERIFY_RET(createCol->exec(), {}); | ||
142 | col = createCol->collection(); | 141 | col = createCol->collection(); | ||
143 | if (col.isValid()) { | 142 | if (col.isValid()) { | ||
144 | deleter << col; | 143 | deleter << col; | ||
145 | return col; | | |||
146 | } | 144 | } | ||
147 | return stdx::nullopt; | 145 | return col; | ||
148 | } | 146 | } | ||
149 | } // namespace | 147 | } // namespace | ||
150 | 148 | | |||
151 | class UnifiedMailboxManagerTest : public QObject | 149 | class UnifiedMailboxManagerTest : public QObject | ||
152 | { | 150 | { | ||
153 | Q_OBJECT | 151 | Q_OBJECT | ||
154 | 152 | | |||
155 | private Q_SLOTS: | 153 | private Q_SLOTS: | ||
Show All 29 Lines | 179 | const auto verifyBox = [&manager, &success](const QString &id, int numSources) { | |||
185 | return e.second->id() == id; | 183 | return e.second->id() == id; | ||
186 | }); | 184 | }); | ||
187 | QVERIFY(boxIt != manager.end()); | 185 | QVERIFY(boxIt != manager.end()); | ||
188 | const auto &box = boxIt->second; | 186 | const auto &box = boxIt->second; | ||
189 | const auto sourceCollections = box->sourceCollections(); | 187 | const auto sourceCollections = box->sourceCollections(); | ||
190 | QCOMPARE(sourceCollections.size(), numSources); | 188 | QCOMPARE(sourceCollections.size(), numSources); | ||
191 | for (auto source : sourceCollections) { | 189 | for (auto source : sourceCollections) { | ||
192 | auto col = collectionForId(source); | 190 | auto col = collectionForId(source); | ||
193 | QVERIFY(col); | 191 | QVERIFY(col.isValid()); | ||
194 | QVERIFY(col->hasAttribute<Akonadi::SpecialCollectionAttribute>()); | 192 | QVERIFY(col.hasAttribute<Akonadi::SpecialCollectionAttribute>()); | ||
195 | QCOMPARE(col->attribute<Akonadi::SpecialCollectionAttribute>()->collectionType(), id.toLatin1()); | 193 | QCOMPARE(col.attribute<Akonadi::SpecialCollectionAttribute>()->collectionType(), id.toLatin1()); | ||
196 | } | 194 | } | ||
197 | success = true; | 195 | success = true; | ||
198 | }; | 196 | }; | ||
199 | verifyBox(Common::InboxBoxId, 2); | 197 | verifyBox(Common::InboxBoxId, 2); | ||
200 | QVERIFY(success); | 198 | QVERIFY(success); | ||
201 | verifyBox(Common::SentBoxId, 2); | 199 | verifyBox(Common::SentBoxId, 2); | ||
202 | QVERIFY(success); | 200 | QVERIFY(success); | ||
203 | verifyBox(Common::DraftsBoxId, 1); | 201 | verifyBox(Common::DraftsBoxId, 1); | ||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | 302 | const auto inbox = createUnifiedMailbox(Common::InboxBoxId, QStringLiteral("Inbox"), | |||
305 | { QStringLiteral("res1_inbox"), QStringLiteral("res2_inbox") }); | 303 | { QStringLiteral("res1_inbox"), QStringLiteral("res2_inbox") }); | ||
306 | auto boxGroup = boxesGroup.group(inbox->id()); | 304 | auto boxGroup = boxesGroup.group(inbox->id()); | ||
307 | inbox->save(boxGroup); | 305 | inbox->save(boxGroup); | ||
308 | const auto sentBox = createUnifiedMailbox(Common::SentBoxId, QStringLiteral("Sent"), | 306 | const auto sentBox = createUnifiedMailbox(Common::SentBoxId, QStringLiteral("Sent"), | ||
309 | { QStringLiteral("res1_sent"), QStringLiteral("res2_sent") }); | 307 | { QStringLiteral("res1_sent"), QStringLiteral("res2_sent") }); | ||
310 | boxGroup = boxesGroup.group(sentBox->id()); | 308 | boxGroup = boxesGroup.group(sentBox->id()); | ||
311 | sentBox->save(boxGroup); | 309 | sentBox->save(boxGroup); | ||
312 | 310 | | |||
313 | const auto parentCol = collectionForRid(Common::AgentIdentifier); | 311 | const Akonadi::Collection parentCol = collectionForRid(Common::AgentIdentifier); | ||
314 | QVERIFY(parentCol); | 312 | QVERIFY(parentCol.isValid()); | ||
315 | 313 | | |||
316 | const auto inboxBoxCol = createCollection(Common::InboxBoxId, parentCol.value(), deleter); | 314 | const auto inboxBoxCol = createCollection(Common::InboxBoxId, parentCol, deleter); | ||
317 | QVERIFY(inboxBoxCol); | 315 | QVERIFY(inboxBoxCol.isValid()); | ||
318 | 316 | | |||
319 | const auto sentBoxCol = createCollection(Common::SentBoxId, parentCol.value(), deleter); | 317 | const auto sentBoxCol = createCollection(Common::SentBoxId, parentCol, deleter); | ||
320 | QVERIFY(sentBoxCol); | 318 | QVERIFY(sentBoxCol.isValid()); | ||
321 | 319 | | |||
322 | // Load from config | 320 | // Load from config | ||
323 | bool loadingDone = false; | 321 | bool loadingDone = false; | ||
324 | manager.loadBoxes([&loadingDone]() { | 322 | manager.loadBoxes([&loadingDone]() { | ||
325 | loadingDone = true; | 323 | loadingDone = true; | ||
326 | }); | 324 | }); | ||
327 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | 325 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | ||
328 | 326 | | |||
329 | // Now the boxes should be loaded and we should be able to access them | 327 | // Now the boxes should be loaded and we should be able to access them | ||
330 | // by IDs of collections that represent them. The collections should also | 328 | // by IDs of collections that represent them. The collections should also | ||
331 | // be set for each box. | 329 | // be set for each box. | ||
332 | auto box = manager.unifiedMailboxFromCollection(inboxBoxCol.value()); | 330 | auto box = manager.unifiedMailboxFromCollection(inboxBoxCol); | ||
333 | QVERIFY(box != nullptr); | 331 | QVERIFY(box != nullptr); | ||
334 | QCOMPARE(box->collectionId().value(), inboxBoxCol->id()); | 332 | QCOMPARE(box->collectionId(), inboxBoxCol.id()); | ||
335 | 333 | | |||
336 | box = manager.unifiedMailboxFromCollection(sentBoxCol.value()); | 334 | box = manager.unifiedMailboxFromCollection(sentBoxCol); | ||
337 | QVERIFY(box != nullptr); | 335 | QVERIFY(box != nullptr); | ||
338 | QCOMPARE(box->collectionId().value(), sentBoxCol->id()); | 336 | QCOMPARE(box->collectionId(), sentBoxCol.id()); | ||
339 | } | 337 | } | ||
340 | 338 | | |||
341 | void testItemAddedToSourceCollection() | 339 | void testItemAddedToSourceCollection() | ||
342 | { | 340 | { | ||
343 | // Setup | 341 | // Setup | ||
344 | auto kcfg = KSharedConfig::openConfig(QString::fromUtf8(QTest::currentTestFunction())); | 342 | auto kcfg = KSharedConfig::openConfig(QString::fromUtf8(QTest::currentTestFunction())); | ||
345 | UnifiedMailboxManager manager(kcfg); | 343 | UnifiedMailboxManager manager(kcfg); | ||
346 | EntityDeleter deleter; | 344 | EntityDeleter deleter; | ||
347 | 345 | | |||
348 | const auto parentCol = collectionForRid(Common::AgentIdentifier); | 346 | const auto parentCol = collectionForRid(Common::AgentIdentifier); | ||
349 | QVERIFY(parentCol); | 347 | QVERIFY(parentCol.isValid()); | ||
350 | 348 | | |||
351 | const auto inboxBoxCol = createCollection(Common::InboxBoxId, parentCol.value(), deleter); | 349 | const auto inboxBoxCol = createCollection(Common::InboxBoxId, parentCol, deleter); | ||
352 | QVERIFY(inboxBoxCol); | 350 | QVERIFY(inboxBoxCol.isValid()); | ||
353 | 351 | | |||
354 | // Load boxes - config is empty so this will create the default Boxes and | 352 | // Load boxes - config is empty so this will create the default Boxes and | ||
355 | // assign the Inboxes from Knuts to it | 353 | // assign the Inboxes from Knuts to it | ||
356 | bool loadingDone = true; | 354 | bool loadingDone = true; | ||
357 | manager.loadBoxes([&loadingDone]() { | 355 | manager.loadBoxes([&loadingDone]() { | ||
358 | loadingDone = true; | 356 | loadingDone = true; | ||
359 | }); | 357 | }); | ||
360 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | 358 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | ||
361 | 359 | | |||
362 | // Now discover collections for the created boxes | 360 | // Now discover collections for the created boxes | ||
363 | loadingDone = false; | 361 | loadingDone = false; | ||
364 | manager.discoverBoxCollections([&loadingDone]() { | 362 | manager.discoverBoxCollections([&loadingDone]() { | ||
365 | loadingDone = true; | 363 | loadingDone = true; | ||
366 | }); | 364 | }); | ||
367 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | 365 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | ||
368 | 366 | | |||
369 | // Get one of the source collections for Inbox | 367 | // Get one of the source collections for Inbox | ||
370 | const auto inboxSourceCol = collectionForRid(QStringLiteral("res1_inbox")); | 368 | const auto inboxSourceCol = collectionForRid(QStringLiteral("res1_inbox")); | ||
371 | QVERIFY(inboxSourceCol); | 369 | QVERIFY(inboxSourceCol.isValid()); | ||
372 | 370 | | |||
373 | // Setup up a monitor to to be notified when an item gets linked into | 371 | // Setup up a monitor to to be notified when an item gets linked into | ||
374 | // the unified mailbox collection | 372 | // the unified mailbox collection | ||
375 | Akonadi::Monitor monitor; | 373 | Akonadi::Monitor monitor; | ||
376 | monitor.setCollectionMonitored(inboxBoxCol.value()); | 374 | monitor.setCollectionMonitored(inboxBoxCol); | ||
377 | QSignalSpy itemLinkedSignalSpy(&monitor, &Akonadi::Monitor::itemsLinked); | 375 | QSignalSpy itemLinkedSignalSpy(&monitor, &Akonadi::Monitor::itemsLinked); | ||
378 | QVERIFY(QSignalSpy(&monitor, &Akonadi::Monitor::monitorReady).wait()); | 376 | QVERIFY(QSignalSpy(&monitor, &Akonadi::Monitor::monitorReady).wait()); | ||
379 | 377 | | |||
380 | // Add a new Item into the source collection | 378 | // Add a new Item into the source collection | ||
381 | Akonadi::Item item; | 379 | Akonadi::Item item; | ||
382 | item.setMimeType(QStringLiteral("application/octet-stream")); | 380 | item.setMimeType(QStringLiteral("application/octet-stream")); | ||
383 | item.setParentCollection(inboxSourceCol.value()); | 381 | item.setParentCollection(inboxSourceCol); | ||
384 | item.setPayload(QByteArray{"Hello world!"}); | 382 | item.setPayload(QByteArray{"Hello world!"}); | ||
385 | auto createItem = new Akonadi::ItemCreateJob(item, inboxSourceCol.value(), this); | 383 | auto createItem = new Akonadi::ItemCreateJob(item, inboxSourceCol, this); | ||
386 | AKVERIFYEXEC(createItem); | 384 | AKVERIFYEXEC(createItem); | ||
387 | item = createItem->item(); | 385 | item = createItem->item(); | ||
388 | deleter << item; | 386 | deleter << item; | ||
389 | 387 | | |||
390 | // Then wait for ItemLinked notification as the Manager has linked the new Item | 388 | // Then wait for ItemLinked notification as the Manager has linked the new Item | ||
391 | // to the dest collection | 389 | // to the dest collection | ||
392 | QTRY_COMPARE(itemLinkedSignalSpy.size(), 1); | 390 | QTRY_COMPARE(itemLinkedSignalSpy.size(), 1); | ||
393 | const auto linkedItems = itemLinkedSignalSpy.at(0).at(0).value<Akonadi::Item::List>(); | 391 | const auto linkedItems = itemLinkedSignalSpy.at(0).at(0).value<Akonadi::Item::List>(); | ||
394 | QCOMPARE(linkedItems.size(), 1); | 392 | QCOMPARE(linkedItems.size(), 1); | ||
395 | QCOMPARE(linkedItems.at(0), item); | 393 | QCOMPARE(linkedItems.at(0), item); | ||
396 | const auto linkedCol = itemLinkedSignalSpy.at(0).at(1).value<Akonadi::Collection>(); | 394 | const auto linkedCol = itemLinkedSignalSpy.at(0).at(1).value<Akonadi::Collection>(); | ||
397 | QCOMPARE(linkedCol, inboxBoxCol.value()); | 395 | QCOMPARE(linkedCol, inboxBoxCol); | ||
398 | } | 396 | } | ||
399 | 397 | | |||
400 | void testItemMovedFromSourceCollection() | 398 | void testItemMovedFromSourceCollection() | ||
401 | { | 399 | { | ||
402 | // Setup | 400 | // Setup | ||
403 | auto kcfg = KSharedConfig::openConfig(QString::fromUtf8(QTest::currentTestFunction())); | 401 | auto kcfg = KSharedConfig::openConfig(QString::fromUtf8(QTest::currentTestFunction())); | ||
404 | UnifiedMailboxManager manager(kcfg); | 402 | UnifiedMailboxManager manager(kcfg); | ||
405 | EntityDeleter deleter; | 403 | EntityDeleter deleter; | ||
406 | 404 | | |||
407 | const auto parentCol = collectionForRid(Common::AgentIdentifier); | 405 | const auto parentCol = collectionForRid(Common::AgentIdentifier); | ||
408 | QVERIFY(parentCol); | 406 | QVERIFY(parentCol.isValid()); | ||
409 | 407 | | |||
410 | const auto inboxBoxCol = createCollection(Common::InboxBoxId, parentCol.value(), deleter); | 408 | const auto inboxBoxCol = createCollection(Common::InboxBoxId, parentCol, deleter); | ||
411 | QVERIFY(inboxBoxCol); | 409 | QVERIFY(inboxBoxCol.isValid()); | ||
412 | 410 | | |||
413 | // Load boxes - config is empty so this will create the default Boxes and | 411 | // Load boxes - config is empty so this will create the default Boxes and | ||
414 | // assign the Inboxes from Knuts to it | 412 | // assign the Inboxes from Knuts to it | ||
415 | bool loadingDone = true; | 413 | bool loadingDone = true; | ||
416 | manager.loadBoxes([&loadingDone]() { | 414 | manager.loadBoxes([&loadingDone]() { | ||
417 | loadingDone = true; | 415 | loadingDone = true; | ||
418 | }); | 416 | }); | ||
419 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | 417 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | ||
420 | 418 | | |||
421 | // Now discover collections for the created boxes | 419 | // Now discover collections for the created boxes | ||
422 | loadingDone = false; | 420 | loadingDone = false; | ||
423 | manager.discoverBoxCollections([&loadingDone]() { | 421 | manager.discoverBoxCollections([&loadingDone]() { | ||
424 | loadingDone = true; | 422 | loadingDone = true; | ||
425 | }); | 423 | }); | ||
426 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | 424 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | ||
427 | 425 | | |||
428 | // Get one of the source collections for Inbox | 426 | // Get one of the source collections for Inbox | ||
429 | const auto inboxSourceCol = collectionForRid(QStringLiteral("res1_inbox")); | 427 | const auto inboxSourceCol = collectionForRid(QStringLiteral("res1_inbox")); | ||
430 | QVERIFY(inboxSourceCol); | 428 | QVERIFY(inboxSourceCol.isValid()); | ||
431 | 429 | | |||
432 | // Setup up a monitor to to be notified when an item gets linked into | 430 | // Setup up a monitor to to be notified when an item gets linked into | ||
433 | // the unified mailbox collection | 431 | // the unified mailbox collection | ||
434 | Akonadi::Monitor monitor; | 432 | Akonadi::Monitor monitor; | ||
435 | monitor.setCollectionMonitored(inboxBoxCol.value()); | 433 | monitor.setCollectionMonitored(inboxBoxCol); | ||
436 | QSignalSpy itemLinkedSignalSpy(&monitor, &Akonadi::Monitor::itemsLinked); | 434 | QSignalSpy itemLinkedSignalSpy(&monitor, &Akonadi::Monitor::itemsLinked); | ||
437 | QSignalSpy itemUnlinkedSignalSpy(&monitor, &Akonadi::Monitor::itemsUnlinked); | 435 | QSignalSpy itemUnlinkedSignalSpy(&monitor, &Akonadi::Monitor::itemsUnlinked); | ||
438 | QVERIFY(QSignalSpy(&monitor, &Akonadi::Monitor::monitorReady).wait()); | 436 | QVERIFY(QSignalSpy(&monitor, &Akonadi::Monitor::monitorReady).wait()); | ||
439 | 437 | | |||
440 | // Add a new Item into the source collection | 438 | // Add a new Item into the source collection | ||
441 | Akonadi::Item item; | 439 | Akonadi::Item item; | ||
442 | item.setMimeType(QStringLiteral("application/octet-stream")); | 440 | item.setMimeType(QStringLiteral("application/octet-stream")); | ||
443 | item.setParentCollection(inboxSourceCol.value()); | 441 | item.setParentCollection(inboxSourceCol); | ||
444 | item.setPayload(QByteArray{"Hello world!"}); | 442 | item.setPayload(QByteArray{"Hello world!"}); | ||
445 | auto createItem = new Akonadi::ItemCreateJob(item, inboxSourceCol.value(), this); | 443 | auto createItem = new Akonadi::ItemCreateJob(item, inboxSourceCol, this); | ||
446 | AKVERIFYEXEC(createItem); | 444 | AKVERIFYEXEC(createItem); | ||
447 | item = createItem->item(); | 445 | item = createItem->item(); | ||
448 | deleter << item; | 446 | deleter << item; | ||
449 | 447 | | |||
450 | // Waity for the item to be linked | 448 | // Waity for the item to be linked | ||
451 | QTRY_COMPARE(itemLinkedSignalSpy.size(), 1); | 449 | QTRY_COMPARE(itemLinkedSignalSpy.size(), 1); | ||
452 | 450 | | |||
453 | const auto destinationCol = collectionForRid(QStringLiteral("res1_foo")); | 451 | const auto destinationCol = collectionForRid(QStringLiteral("res1_foo")); | ||
454 | QVERIFY(destinationCol); | 452 | QVERIFY(destinationCol.isValid()); | ||
455 | 453 | | |||
456 | // Now move the Item to an unmonitored collection | 454 | // Now move the Item to an unmonitored collection | ||
457 | auto move = new Akonadi::ItemMoveJob(item, destinationCol.value(), this); | 455 | auto move = new Akonadi::ItemMoveJob(item, destinationCol, this); | ||
458 | AKVERIFYEXEC(move); | 456 | AKVERIFYEXEC(move); | ||
459 | 457 | | |||
460 | QTRY_COMPARE(itemUnlinkedSignalSpy.size(), 1); | 458 | QTRY_COMPARE(itemUnlinkedSignalSpy.size(), 1); | ||
461 | const auto unlinkedItems = itemUnlinkedSignalSpy.at(0).at(0).value<Akonadi::Item::List>(); | 459 | const auto unlinkedItems = itemUnlinkedSignalSpy.at(0).at(0).value<Akonadi::Item::List>(); | ||
462 | QCOMPARE(unlinkedItems.size(), 1); | 460 | QCOMPARE(unlinkedItems.size(), 1); | ||
463 | QCOMPARE(unlinkedItems.first(), item); | 461 | QCOMPARE(unlinkedItems.first(), item); | ||
464 | const auto unlinkedCol = itemUnlinkedSignalSpy.at(0).at(1).value<Akonadi::Collection>(); | 462 | const auto unlinkedCol = itemUnlinkedSignalSpy.at(0).at(1).value<Akonadi::Collection>(); | ||
465 | QCOMPARE(unlinkedCol, inboxBoxCol.value()); | 463 | QCOMPARE(unlinkedCol, inboxBoxCol); | ||
466 | } | 464 | } | ||
467 | 465 | | |||
468 | void testItemMovedBetweenSourceCollections() | 466 | void testItemMovedBetweenSourceCollections() | ||
469 | { | 467 | { | ||
470 | // Setup | 468 | // Setup | ||
471 | auto kcfg = KSharedConfig::openConfig(QString::fromUtf8(QTest::currentTestFunction())); | 469 | auto kcfg = KSharedConfig::openConfig(QString::fromUtf8(QTest::currentTestFunction())); | ||
472 | UnifiedMailboxManager manager(kcfg); | 470 | UnifiedMailboxManager manager(kcfg); | ||
473 | EntityDeleter deleter; | 471 | EntityDeleter deleter; | ||
474 | 472 | | |||
475 | const auto parentCol = collectionForRid(Common::AgentIdentifier); | 473 | const auto parentCol = collectionForRid(Common::AgentIdentifier); | ||
476 | QVERIFY(parentCol); | 474 | QVERIFY(parentCol.isValid()); | ||
477 | 475 | | |||
478 | const auto inboxBoxCol = createCollection(Common::InboxBoxId, parentCol.value(), deleter); | 476 | const auto inboxBoxCol = createCollection(Common::InboxBoxId, parentCol, deleter); | ||
479 | QVERIFY(inboxBoxCol); | 477 | QVERIFY(inboxBoxCol.isValid()); | ||
480 | 478 | | |||
481 | const auto draftsBoxCol = createCollection(Common::DraftsBoxId, parentCol.value(), deleter); | 479 | const auto draftsBoxCol = createCollection(Common::DraftsBoxId, parentCol, deleter); | ||
482 | QVERIFY(draftsBoxCol); | 480 | QVERIFY(draftsBoxCol.isValid()); | ||
483 | 481 | | |||
484 | // Load boxes - config is empty so this will create the default Boxes and | 482 | // Load boxes - config is empty so this will create the default Boxes and | ||
485 | // assign the Inboxes from Knuts to it | 483 | // assign the Inboxes from Knuts to it | ||
486 | bool loadingDone = true; | 484 | bool loadingDone = true; | ||
487 | manager.loadBoxes([&loadingDone]() { | 485 | manager.loadBoxes([&loadingDone]() { | ||
488 | loadingDone = true; | 486 | loadingDone = true; | ||
489 | }); | 487 | }); | ||
490 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | 488 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | ||
491 | 489 | | |||
492 | // Now discover collections for the created boxes | 490 | // Now discover collections for the created boxes | ||
493 | loadingDone = false; | 491 | loadingDone = false; | ||
494 | manager.discoverBoxCollections([&loadingDone]() { | 492 | manager.discoverBoxCollections([&loadingDone]() { | ||
495 | loadingDone = true; | 493 | loadingDone = true; | ||
496 | }); | 494 | }); | ||
497 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | 495 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | ||
498 | 496 | | |||
499 | // Get one of the source collections for Inbox and Drafts | 497 | // Get one of the source collections for Inbox and Drafts | ||
500 | const auto inboxSourceCol = collectionForRid(QStringLiteral("res1_inbox")); | 498 | const auto inboxSourceCol = collectionForRid(QStringLiteral("res1_inbox")); | ||
501 | QVERIFY(inboxSourceCol); | 499 | QVERIFY(inboxSourceCol.isValid()); | ||
502 | const auto draftsSourceCol = collectionForRid(QStringLiteral("res1_drafts")); | 500 | const auto draftsSourceCol = collectionForRid(QStringLiteral("res1_drafts")); | ||
503 | QVERIFY(draftsSourceCol); | 501 | QVERIFY(draftsSourceCol.isValid()); | ||
504 | 502 | | |||
505 | // Setup up a monitor to to be notified when an item gets linked into | 503 | // Setup up a monitor to to be notified when an item gets linked into | ||
506 | // the unified mailbox collection | 504 | // the unified mailbox collection | ||
507 | Akonadi::Monitor monitor; | 505 | Akonadi::Monitor monitor; | ||
508 | monitor.setCollectionMonitored(inboxBoxCol.value()); | 506 | monitor.setCollectionMonitored(inboxBoxCol); | ||
509 | monitor.setCollectionMonitored(draftsBoxCol.value()); | 507 | monitor.setCollectionMonitored(draftsBoxCol); | ||
510 | QSignalSpy itemLinkedSignalSpy(&monitor, &Akonadi::Monitor::itemsLinked); | 508 | QSignalSpy itemLinkedSignalSpy(&monitor, &Akonadi::Monitor::itemsLinked); | ||
511 | QSignalSpy itemUnlinkedSignalSpy(&monitor, &Akonadi::Monitor::itemsUnlinked); | 509 | QSignalSpy itemUnlinkedSignalSpy(&monitor, &Akonadi::Monitor::itemsUnlinked); | ||
512 | QVERIFY(QSignalSpy(&monitor, &Akonadi::Monitor::monitorReady).wait()); | 510 | QVERIFY(QSignalSpy(&monitor, &Akonadi::Monitor::monitorReady).wait()); | ||
513 | 511 | | |||
514 | // Add a new Item into the source Inbox collection | 512 | // Add a new Item into the source Inbox collection | ||
515 | Akonadi::Item item; | 513 | Akonadi::Item item; | ||
516 | item.setMimeType(QStringLiteral("application/octet-stream")); | 514 | item.setMimeType(QStringLiteral("application/octet-stream")); | ||
517 | item.setParentCollection(inboxSourceCol.value()); | 515 | item.setParentCollection(inboxSourceCol); | ||
518 | item.setPayload(QByteArray{"Hello world!"}); | 516 | item.setPayload(QByteArray{"Hello world!"}); | ||
519 | auto createItem = new Akonadi::ItemCreateJob(item, inboxSourceCol.value(), this); | 517 | auto createItem = new Akonadi::ItemCreateJob(item, inboxSourceCol, this); | ||
520 | AKVERIFYEXEC(createItem); | 518 | AKVERIFYEXEC(createItem); | ||
521 | item = createItem->item(); | 519 | item = createItem->item(); | ||
522 | deleter << item; | 520 | deleter << item; | ||
523 | 521 | | |||
524 | // Waity for the item to be linked | 522 | // Waity for the item to be linked | ||
525 | QTRY_COMPARE(itemLinkedSignalSpy.size(), 1); | 523 | QTRY_COMPARE(itemLinkedSignalSpy.size(), 1); | ||
526 | itemLinkedSignalSpy.clear(); | 524 | itemLinkedSignalSpy.clear(); | ||
527 | 525 | | |||
528 | // Now move the Item to another Unified mailbox's source collection | 526 | // Now move the Item to another Unified mailbox's source collection | ||
529 | auto move = new Akonadi::ItemMoveJob(item, draftsSourceCol.value(), this); | 527 | auto move = new Akonadi::ItemMoveJob(item, draftsSourceCol, this); | ||
530 | AKVERIFYEXEC(move); | 528 | AKVERIFYEXEC(move); | ||
531 | 529 | | |||
532 | QTRY_COMPARE(itemUnlinkedSignalSpy.size(), 1); | 530 | QTRY_COMPARE(itemUnlinkedSignalSpy.size(), 1); | ||
533 | const auto unlinkedItems = itemUnlinkedSignalSpy.at(0).at(0).value<Akonadi::Item::List>(); | 531 | const auto unlinkedItems = itemUnlinkedSignalSpy.at(0).at(0).value<Akonadi::Item::List>(); | ||
534 | QCOMPARE(unlinkedItems.size(), 1); | 532 | QCOMPARE(unlinkedItems.size(), 1); | ||
535 | QCOMPARE(unlinkedItems.first(), item); | 533 | QCOMPARE(unlinkedItems.first(), item); | ||
536 | const auto unlinkedCol = itemUnlinkedSignalSpy.at(0).at(1).value<Akonadi::Collection>(); | 534 | const auto unlinkedCol = itemUnlinkedSignalSpy.at(0).at(1).value<Akonadi::Collection>(); | ||
537 | QCOMPARE(unlinkedCol, inboxBoxCol.value()); | 535 | QCOMPARE(unlinkedCol, inboxBoxCol); | ||
538 | 536 | | |||
539 | QTRY_COMPARE(itemLinkedSignalSpy.size(), 1); | 537 | QTRY_COMPARE(itemLinkedSignalSpy.size(), 1); | ||
540 | const auto linkedItems = itemLinkedSignalSpy.at(0).at(0).value<Akonadi::Item::List>(); | 538 | const auto linkedItems = itemLinkedSignalSpy.at(0).at(0).value<Akonadi::Item::List>(); | ||
541 | QCOMPARE(linkedItems.size(), 1); | 539 | QCOMPARE(linkedItems.size(), 1); | ||
542 | QCOMPARE(linkedItems.first(), item); | 540 | QCOMPARE(linkedItems.first(), item); | ||
543 | const auto linkedCol = itemLinkedSignalSpy.at(0).at(1).value<Akonadi::Collection>(); | 541 | const auto linkedCol = itemLinkedSignalSpy.at(0).at(1).value<Akonadi::Collection>(); | ||
544 | QCOMPARE(linkedCol, draftsBoxCol.value()); | 542 | QCOMPARE(linkedCol, draftsBoxCol); | ||
545 | } | 543 | } | ||
546 | 544 | | |||
547 | void testSourceCollectionRemoved() | 545 | void testSourceCollectionRemoved() | ||
548 | { | 546 | { | ||
549 | // Setup | 547 | // Setup | ||
550 | auto kcfg = KSharedConfig::openConfig(QString::fromUtf8(QTest::currentTestFunction())); | 548 | auto kcfg = KSharedConfig::openConfig(QString::fromUtf8(QTest::currentTestFunction())); | ||
551 | UnifiedMailboxManager manager(kcfg); | 549 | UnifiedMailboxManager manager(kcfg); | ||
552 | auto &changeRecorder = manager.changeRecorder(); | 550 | auto &changeRecorder = manager.changeRecorder(); | ||
553 | QSignalSpy crRemovedSpy(&changeRecorder, &Akonadi::Monitor::collectionRemoved); | 551 | QSignalSpy crRemovedSpy(&changeRecorder, &Akonadi::Monitor::collectionRemoved); | ||
554 | EntityDeleter deleter; | 552 | EntityDeleter deleter; | ||
555 | 553 | | |||
556 | const auto parentCol = collectionForRid(Common::AgentIdentifier); | 554 | const auto parentCol = collectionForRid(Common::AgentIdentifier); | ||
557 | QVERIFY(parentCol); | 555 | QVERIFY(parentCol.isValid()); | ||
558 | 556 | | |||
559 | const auto inboxBoxCol = createCollection(Common::InboxBoxId, parentCol.value(), deleter); | 557 | const auto inboxBoxCol = createCollection(Common::InboxBoxId, parentCol, deleter); | ||
560 | QVERIFY(inboxBoxCol); | 558 | QVERIFY(inboxBoxCol.isValid()); | ||
561 | 559 | | |||
562 | // Load boxes - config is empty so this will create the default Boxes and | 560 | // Load boxes - config is empty so this will create the default Boxes and | ||
563 | // assign the Inboxes from Knuts to it | 561 | // assign the Inboxes from Knuts to it | ||
564 | bool loadingDone = true; | 562 | bool loadingDone = true; | ||
565 | manager.loadBoxes([&loadingDone]() { | 563 | manager.loadBoxes([&loadingDone]() { | ||
566 | loadingDone = true; | 564 | loadingDone = true; | ||
567 | }); | 565 | }); | ||
568 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | 566 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | ||
569 | 567 | | |||
570 | // Now discover collections for the created boxes | 568 | // Now discover collections for the created boxes | ||
571 | loadingDone = false; | 569 | loadingDone = false; | ||
572 | manager.discoverBoxCollections([&loadingDone]() { | 570 | manager.discoverBoxCollections([&loadingDone]() { | ||
573 | loadingDone = true; | 571 | loadingDone = true; | ||
574 | }); | 572 | }); | ||
575 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | 573 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | ||
576 | 574 | | |||
577 | auto inboxSourceCol = collectionForRid(QStringLiteral("res1_inbox")); | 575 | auto inboxSourceCol = collectionForRid(QStringLiteral("res1_inbox")); | ||
578 | QVERIFY(inboxSourceCol); | 576 | QVERIFY(inboxSourceCol.isValid()); | ||
579 | auto delJob = new Akonadi::CollectionDeleteJob(inboxSourceCol.value(), this); | 577 | auto delJob = new Akonadi::CollectionDeleteJob(inboxSourceCol, this); | ||
580 | AKVERIFYEXEC(delJob); | 578 | AKVERIFYEXEC(delJob); | ||
581 | 579 | | |||
582 | // Wait for the change recorder to be notified | 580 | // Wait for the change recorder to be notified | ||
583 | QVERIFY(crRemovedSpy.wait()); | 581 | QVERIFY(crRemovedSpy.wait()); | ||
584 | crRemovedSpy.clear(); | 582 | crRemovedSpy.clear(); | ||
585 | // and then wait a little bit more to give the Manager time to process the event | 583 | // and then wait a little bit more to give the Manager time to process the event | ||
586 | QTest::qWait(0); | 584 | QTest::qWait(0); | ||
587 | 585 | | |||
588 | auto inboxBox = manager.unifiedMailboxFromCollection(inboxBoxCol.value()); | 586 | auto inboxBox = manager.unifiedMailboxFromCollection(inboxBoxCol); | ||
589 | QVERIFY(inboxBox); | 587 | QVERIFY(inboxBox); | ||
590 | QVERIFY(!inboxBox->sourceCollections().contains(inboxSourceCol->id())); | 588 | QVERIFY(!inboxBox->sourceCollections().contains(inboxSourceCol.id())); | ||
591 | QVERIFY(!changeRecorder.collectionsMonitored().contains(inboxSourceCol.value())); | 589 | QVERIFY(!changeRecorder.collectionsMonitored().contains(inboxSourceCol)); | ||
592 | QVERIFY(!manager.unifiedMailboxForSource(inboxSourceCol->id())); | 590 | QVERIFY(!manager.unifiedMailboxForSource(inboxSourceCol.id())); | ||
593 | 591 | | |||
594 | // Lets removed the other source collection now, that should remove the unified box completely | 592 | // Lets removed the other source collection now, that should remove the unified box completely | ||
595 | inboxSourceCol = collectionForRid(QStringLiteral("res2_inbox")); | 593 | inboxSourceCol = collectionForRid(QStringLiteral("res2_inbox")); | ||
596 | QVERIFY(inboxSourceCol); | 594 | QVERIFY(inboxSourceCol.isValid()); | ||
597 | delJob = new Akonadi::CollectionDeleteJob(inboxSourceCol.value(), this); | 595 | delJob = new Akonadi::CollectionDeleteJob(inboxSourceCol, this); | ||
598 | AKVERIFYEXEC(delJob); | 596 | AKVERIFYEXEC(delJob); | ||
599 | 597 | | |||
600 | // Wait for the change recorder once again | 598 | // Wait for the change recorder once again | ||
601 | QVERIFY(crRemovedSpy.wait()); | 599 | QVERIFY(crRemovedSpy.wait()); | ||
602 | QTest::qWait(0); | 600 | QTest::qWait(0); | ||
603 | 601 | | |||
604 | QVERIFY(!manager.unifiedMailboxFromCollection(inboxBoxCol.value())); | 602 | QVERIFY(!manager.unifiedMailboxFromCollection(inboxBoxCol)); | ||
605 | QVERIFY(!changeRecorder.collectionsMonitored().contains(inboxSourceCol.value())); | 603 | QVERIFY(!changeRecorder.collectionsMonitored().contains(inboxSourceCol)); | ||
606 | QVERIFY(!manager.unifiedMailboxForSource(inboxSourceCol->id())); | 604 | QVERIFY(!manager.unifiedMailboxForSource(inboxSourceCol.id())); | ||
607 | } | 605 | } | ||
608 | 606 | | |||
609 | void testSpecialSourceCollectionCreated() | 607 | void testSpecialSourceCollectionCreated() | ||
610 | { | 608 | { | ||
611 | // TODO: this does not work yet: we only monitor collections that we are | 609 | // TODO: this does not work yet: we only monitor collections that we are | ||
612 | // interested in, we don't monitor other collections | 610 | // interested in, we don't monitor other collections | ||
613 | } | 611 | } | ||
614 | 612 | | |||
615 | void testSpecialSourceCollectionDemoted() | 613 | void testSpecialSourceCollectionDemoted() | ||
616 | { | 614 | { | ||
617 | // Setup | 615 | // Setup | ||
618 | auto kcfg = KSharedConfig::openConfig(QString::fromUtf8(QTest::currentTestFunction())); | 616 | auto kcfg = KSharedConfig::openConfig(QString::fromUtf8(QTest::currentTestFunction())); | ||
619 | UnifiedMailboxManager manager(kcfg); | 617 | UnifiedMailboxManager manager(kcfg); | ||
620 | auto &changeRecorder = manager.changeRecorder(); | 618 | auto &changeRecorder = manager.changeRecorder(); | ||
621 | QSignalSpy crChangedSpy(&changeRecorder, qOverload<const Akonadi::Collection &, const QSet<QByteArray> &>(&Akonadi::Monitor::collectionChanged)); | 619 | QSignalSpy crChangedSpy(&changeRecorder, qOverload<const Akonadi::Collection &, const QSet<QByteArray> &>(&Akonadi::Monitor::collectionChanged)); | ||
622 | EntityDeleter deleter; | 620 | EntityDeleter deleter; | ||
623 | 621 | | |||
624 | const auto parentCol = collectionForRid(Common::AgentIdentifier); | 622 | const auto parentCol = collectionForRid(Common::AgentIdentifier); | ||
625 | QVERIFY(parentCol); | 623 | QVERIFY(parentCol.isValid()); | ||
626 | 624 | | |||
627 | const auto sentBoxCol = createCollection(Common::SentBoxId, parentCol.value(), deleter); | 625 | const auto sentBoxCol = createCollection(Common::SentBoxId, parentCol, deleter); | ||
628 | QVERIFY(sentBoxCol); | 626 | QVERIFY(sentBoxCol.isValid()); | ||
629 | 627 | | |||
630 | // Load boxes - config is empty so this will create the default Boxes and | 628 | // Load boxes - config is empty so this will create the default Boxes and | ||
631 | // assign the Inboxes from Knuts to it | 629 | // assign the Inboxes from Knuts to it | ||
632 | bool loadingDone = true; | 630 | bool loadingDone = true; | ||
633 | manager.loadBoxes([&loadingDone]() { | 631 | manager.loadBoxes([&loadingDone]() { | ||
634 | loadingDone = true; | 632 | loadingDone = true; | ||
635 | }); | 633 | }); | ||
636 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | 634 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | ||
637 | 635 | | |||
638 | // Now discover collections for the created boxes | 636 | // Now discover collections for the created boxes | ||
639 | loadingDone = false; | 637 | loadingDone = false; | ||
640 | manager.discoverBoxCollections([&loadingDone]() { | 638 | manager.discoverBoxCollections([&loadingDone]() { | ||
641 | loadingDone = true; | 639 | loadingDone = true; | ||
642 | }); | 640 | }); | ||
643 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | 641 | QTRY_VERIFY_WITH_TIMEOUT(loadingDone, milliseconds(10s).count()); | ||
644 | 642 | | |||
645 | auto sentSourceCol = collectionForRid(QStringLiteral("res1_sent")); | 643 | auto sentSourceCol = collectionForRid(QStringLiteral("res1_sent")); | ||
646 | QVERIFY(sentSourceCol); | 644 | QVERIFY(sentSourceCol.isValid()); | ||
647 | sentSourceCol->removeAttribute<Akonadi::SpecialCollectionAttribute>(); | 645 | sentSourceCol.removeAttribute<Akonadi::SpecialCollectionAttribute>(); | ||
648 | auto modify = new Akonadi::CollectionModifyJob(sentSourceCol.value(), this); | 646 | auto modify = new Akonadi::CollectionModifyJob(sentSourceCol, this); | ||
649 | AKVERIFYEXEC(modify); | 647 | AKVERIFYEXEC(modify); | ||
650 | 648 | | |||
651 | // Wait for the change recorder to be notified | 649 | // Wait for the change recorder to be notified | ||
652 | QVERIFY(crChangedSpy.wait()); | 650 | QVERIFY(crChangedSpy.wait()); | ||
653 | crChangedSpy.clear(); | 651 | crChangedSpy.clear(); | ||
654 | // and then wait a little bit more to give the Manager time to process the event | 652 | // and then wait a little bit more to give the Manager time to process the event | ||
655 | QTest::qWait(0); | 653 | QTest::qWait(0); | ||
656 | 654 | | |||
657 | auto sourceBox = manager.unifiedMailboxFromCollection(sentBoxCol.value()); | 655 | auto sourceBox = manager.unifiedMailboxFromCollection(sentBoxCol); | ||
658 | QVERIFY(sourceBox); | 656 | QVERIFY(sourceBox); | ||
659 | QVERIFY(!sourceBox->sourceCollections().contains(sentSourceCol->id())); | 657 | QVERIFY(!sourceBox->sourceCollections().contains(sentSourceCol.id())); | ||
660 | QVERIFY(!changeRecorder.collectionsMonitored().contains(sentSourceCol.value())); | 658 | QVERIFY(!changeRecorder.collectionsMonitored().contains(sentSourceCol)); | ||
661 | QVERIFY(!manager.unifiedMailboxForSource(sentSourceCol->id())); | 659 | QVERIFY(!manager.unifiedMailboxForSource(sentSourceCol.id())); | ||
662 | 660 | | |||
663 | // Lets demote the other source collection now, that should remove the unified box completely | 661 | // Lets demote the other source collection now, that should remove the unified box completely | ||
664 | sentSourceCol = collectionForRid(QStringLiteral("res2_sent")); | 662 | sentSourceCol = collectionForRid(QStringLiteral("res2_sent")); | ||
665 | QVERIFY(sentSourceCol); | 663 | QVERIFY(sentSourceCol.isValid()); | ||
666 | sentSourceCol->attribute<Akonadi::SpecialCollectionAttribute>()->setCollectionType("drafts"); | 664 | sentSourceCol.attribute<Akonadi::SpecialCollectionAttribute>()->setCollectionType("drafts"); | ||
667 | modify = new Akonadi::CollectionModifyJob(sentSourceCol.value(), this); | 665 | modify = new Akonadi::CollectionModifyJob(sentSourceCol, this); | ||
668 | AKVERIFYEXEC(modify); | 666 | AKVERIFYEXEC(modify); | ||
669 | 667 | | |||
670 | // Wait for the change recorder once again | 668 | // Wait for the change recorder once again | ||
671 | QVERIFY(crChangedSpy.wait()); | 669 | QVERIFY(crChangedSpy.wait()); | ||
672 | QTest::qWait(0); | 670 | QTest::qWait(0); | ||
673 | 671 | | |||
674 | // There's no more Sent unified box | 672 | // There's no more Sent unified box | ||
675 | QVERIFY(!manager.unifiedMailboxFromCollection(sentBoxCol.value())); | 673 | QVERIFY(!manager.unifiedMailboxFromCollection(sentBoxCol)); | ||
676 | 674 | | |||
677 | // The collection is still monitored: it belongs to the Drafts special box now! | 675 | // The collection is still monitored: it belongs to the Drafts special box now! | ||
678 | QVERIFY(changeRecorder.collectionsMonitored().contains(sentSourceCol.value())); | 676 | QVERIFY(changeRecorder.collectionsMonitored().contains(sentSourceCol)); | ||
679 | QVERIFY(manager.unifiedMailboxForSource(sentSourceCol->id())); | 677 | QVERIFY(manager.unifiedMailboxForSource(sentSourceCol.id())); | ||
680 | } | 678 | } | ||
681 | }; | 679 | }; | ||
682 | 680 | | |||
683 | QTEST_AKONADIMAIN(UnifiedMailboxManagerTest) | 681 | QTEST_AKONADIMAIN(UnifiedMailboxManagerTest) | ||
684 | 682 | | |||
685 | #include "unifiedmailboxmanagertest.moc" | 683 | #include "unifiedmailboxmanagertest.moc" |