Changeset View
Changeset View
Standalone View
Standalone View
tests/testlib/akonadistoragetestbase.cpp
Show First 20 Lines • Show All 458 Lines • ▼ Show 20 Line(s) | 423 | { | |||
---|---|---|---|---|---|
459 | 459 | | |||
460 | auto parent = notifiedItem.parentCollection(); | 460 | auto parent = notifiedItem.parentCollection(); | ||
461 | while (parent != Akonadi::Collection::root()) { | 461 | while (parent != Akonadi::Collection::root()) { | ||
462 | QVERIFY(parent.isValid()); | 462 | QVERIFY(parent.isValid()); | ||
463 | parent = parent.parentCollection(); | 463 | parent = parent.parentCollection(); | ||
464 | } | 464 | } | ||
465 | } | 465 | } | ||
466 | 466 | | |||
467 | void AkonadiStorageTestBase::shouldNotifyItemTagAdded() | | |||
468 | { | | |||
469 | // GIVEN | | |||
470 | | ||||
471 | // A spied monitor | | |||
472 | auto monitor = createMonitor(); | | |||
473 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::itemChanged); | | |||
474 | MonitorSpy monitorSpy(monitor.data()); | | |||
475 | | ||||
476 | // An existing item (if we trust the test data)... | | |||
477 | Akonadi::Item item = fetchItemByRID(QStringLiteral("{1d33862f-f274-4c67-ab6c-362d56521ff5}"), calendar2()); | | |||
478 | QVERIFY(item.isValid()); | | |||
479 | item.setMimeType(QStringLiteral("application/x-vnd.akonadi.calendar.todo")); | | |||
480 | | ||||
481 | // An existing tag (if we trust the test data) | | |||
482 | Akonadi::Tag tag(5); | | |||
483 | | ||||
484 | // WHEN | | |||
485 | item.setTag(tag); | | |||
486 | auto storage = createStorage(); | | |||
487 | auto job = storage->updateItem(item); | | |||
488 | AKVERIFYEXEC(job); | | |||
489 | monitorSpy.waitForStableState(); | | |||
490 | QTRY_VERIFY(!spy.isEmpty()); | | |||
491 | | ||||
492 | // THEN | | |||
493 | QCOMPARE(spy.size(), 1); | | |||
494 | auto notifiedItem = spy.takeFirst().at(0).value<Akonadi::Item>(); | | |||
495 | QCOMPARE(notifiedItem.id(), item.id()); | | |||
496 | QVERIFY(notifiedItem.hasPayload<KCalCore::Todo::Ptr>()); | | |||
497 | | ||||
498 | Akonadi::Tag::List notifiedTags = notifiedItem.tags(); | | |||
499 | | ||||
500 | QVERIFY(notifiedTags.contains(tag)); | | |||
501 | foreach (const auto &tag, notifiedTags) { | | |||
502 | QVERIFY(tag.isValid()); | | |||
503 | QVERIFY(!tag.name().isEmpty()); | | |||
504 | QVERIFY(!tag.type().isEmpty()); | | |||
505 | } | | |||
506 | | ||||
507 | auto parent = notifiedItem.parentCollection(); | | |||
508 | while (parent != Akonadi::Collection::root()) { | | |||
509 | QVERIFY(parent.isValid()); | | |||
510 | parent = parent.parentCollection(); | | |||
511 | } | | |||
512 | } | | |||
513 | | ||||
514 | void AkonadiStorageTestBase::shouldNotifyItemTagRemoved() // aka dissociate | | |||
515 | { | | |||
516 | // GIVEN | | |||
517 | auto storage = createStorage(); | | |||
518 | Akonadi::Tag tag = fetchTagByGID(QStringLiteral("philosophy-tag")); | | |||
519 | const QString expectedRemoteIds = {QStringLiteral("{7824df00-2fd6-47a4-8319-52659dc82006}")}; | | |||
520 | auto job = storage->fetchTagItems(tag); | | |||
521 | AKVERIFYEXEC(job->kjob()); | | |||
522 | | ||||
523 | auto item = job->items().at(0); | | |||
524 | QCOMPARE(item.remoteId(), expectedRemoteIds); | | |||
525 | | ||||
526 | QVERIFY(item.loadedPayloadParts().contains(Akonadi::Item::FullPayload)); | | |||
527 | QVERIFY(!item.attributes().isEmpty()); | | |||
528 | QVERIFY(item.modificationTime().isValid()); | | |||
529 | QVERIFY(!item.flags().isEmpty()); | | |||
530 | QVERIFY(!item.tags().isEmpty()); | | |||
531 | | ||||
532 | // A spied monitor | | |||
533 | auto monitor = createMonitor(); | | |||
534 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::itemChanged); | | |||
535 | MonitorSpy monitorSpy(monitor.data()); | | |||
536 | | ||||
537 | // WHEN | | |||
538 | item.clearTag(tag); | | |||
539 | auto jobUpdate = storage->updateItem(item); | | |||
540 | AKVERIFYEXEC(jobUpdate); | | |||
541 | monitorSpy.waitForStableState(); | | |||
542 | QTRY_VERIFY(!spy.isEmpty()); | | |||
543 | | ||||
544 | // THEN | | |||
545 | QCOMPARE(spy.size(), 1); | | |||
546 | auto notifiedItem = spy.takeFirst().at(0).value<Akonadi::Item>(); | | |||
547 | QCOMPARE(notifiedItem.id(), item.id()); | | |||
548 | QVERIFY(!notifiedItem.tags().contains(tag)); | | |||
549 | } | | |||
550 | | ||||
551 | void AkonadiStorageTestBase::shouldNotifyTagAdded() | | |||
552 | { | | |||
553 | // GIVEN | | |||
554 | | ||||
555 | // A spied monitor | | |||
556 | auto monitor = createMonitor(); | | |||
557 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::tagAdded); | | |||
558 | MonitorSpy monitorSpy(monitor.data()); | | |||
559 | | ||||
560 | // A tag | | |||
561 | Akonadi::Tag tag; | | |||
562 | tag.setGid("gid"); | | |||
563 | tag.setName(QStringLiteral("name")); | | |||
564 | tag.setType("type"); | | |||
565 | | ||||
566 | // WHEN | | |||
567 | auto storage = createStorage(); | | |||
568 | auto job = storage->createTag(tag); | | |||
569 | AKVERIFYEXEC(job); | | |||
570 | monitorSpy.waitForStableState(); | | |||
571 | QTRY_VERIFY(!spy.isEmpty()); | | |||
572 | | ||||
573 | // THEN | | |||
574 | QCOMPARE(spy.size(), 1); | | |||
575 | auto notifiedTag = spy.takeFirst().at(0).value<Akonadi::Tag>(); | | |||
576 | QCOMPARE(notifiedTag.gid(), tag.gid()); | | |||
577 | QCOMPARE(notifiedTag.name(), tag.name()); | | |||
578 | QCOMPARE(notifiedTag.type(), tag.type()); | | |||
579 | } | | |||
580 | | ||||
581 | void AkonadiStorageTestBase::shouldNotifyTagRemoved() | | |||
582 | { | | |||
583 | // GIVEN | | |||
584 | | ||||
585 | // An existing tag (if we trust the test data) connected to an existing item tagged to it | | |||
586 | auto storage = createStorage(); | | |||
587 | Akonadi::Tag tag = fetchTagByGID(QStringLiteral("delete-me")); | | |||
588 | // NOTE : this item was linked to the delete-me tag during test time | | |||
589 | const QString expectedRemoteIds = {QStringLiteral("{1d33862f-f274-4c67-ab6c-362d56521ff5}")}; | | |||
590 | auto job = storage->fetchTagItems(tag); | | |||
591 | AKVERIFYEXEC(job->kjob()); | | |||
592 | | ||||
593 | QCOMPARE(job->items().size(), 1); | | |||
594 | auto itemTagged = job->items().at(0); | | |||
595 | QCOMPARE(itemTagged.remoteId(), expectedRemoteIds); | | |||
596 | | ||||
597 | // A spied monitor | | |||
598 | auto monitor = createMonitor(); | | |||
599 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::tagRemoved); | | |||
600 | QSignalSpy spyItemChanged(monitor.data(), &Akonadi::MonitorInterface::itemChanged); | | |||
601 | MonitorSpy monitorSpy(monitor.data()); | | |||
602 | | ||||
603 | // WHEN | | |||
604 | auto jobDelete = storage->removeTag(tag); | | |||
605 | AKVERIFYEXEC(jobDelete); | | |||
606 | monitorSpy.waitForStableState(); | | |||
607 | QTRY_VERIFY(!spy.isEmpty()); | | |||
608 | QTRY_VERIFY(!spyItemChanged.isEmpty()); | | |||
609 | | ||||
610 | // THEN | | |||
611 | QCOMPARE(spy.size(), 1); | | |||
612 | auto notifiedTag = spy.takeFirst().at(0).value<Akonadi::Tag>(); | | |||
613 | QCOMPARE(notifiedTag.id(), tag.id()); | | |||
614 | | ||||
615 | QCOMPARE(spyItemChanged.size(), 1); | | |||
616 | auto notifiedItem = spyItemChanged.takeFirst().at(0).value<Akonadi::Item>(); | | |||
617 | QCOMPARE(notifiedItem.id(), itemTagged.id()); | | |||
618 | } | | |||
619 | | ||||
620 | void AkonadiStorageTestBase::shouldNotifyTagChanged() | | |||
621 | { | | |||
622 | // GIVEN | | |||
623 | | ||||
624 | // A spied monitor | | |||
625 | auto monitor = createMonitor(); | | |||
626 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::tagChanged); | | |||
627 | MonitorSpy monitorSpy(monitor.data()); | | |||
628 | | ||||
629 | // An existing tag (if we trust the test data) | | |||
630 | Akonadi::Tag tag(6); | | |||
631 | tag.setName(QStringLiteral("Oh it changed!")); | | |||
632 | | ||||
633 | // WHEN | | |||
634 | auto storage = createStorage(); | | |||
635 | auto job = storage->updateTag(tag); | | |||
636 | AKVERIFYEXEC(job); | | |||
637 | monitorSpy.waitForStableState(); | | |||
638 | QTRY_VERIFY(!spy.isEmpty()); | | |||
639 | | ||||
640 | // THEN | | |||
641 | QCOMPARE(spy.size(), 1); | | |||
642 | auto notifiedTag = spy.takeFirst().at(0).value<Akonadi::Tag>(); | | |||
643 | QCOMPARE(notifiedTag.id(), tag.id()); | | |||
644 | QCOMPARE(notifiedTag.name(), tag.name()); | | |||
645 | } | | |||
646 | | ||||
647 | void AkonadiStorageTestBase::shouldReadDefaultCollectionFromSettings() | 467 | void AkonadiStorageTestBase::shouldReadDefaultCollectionFromSettings() | ||
648 | { | 468 | { | ||
649 | // GIVEN | 469 | // GIVEN | ||
650 | 470 | | |||
651 | // A storage implementation | 471 | // A storage implementation | ||
652 | auto storage = createStorage(); | 472 | auto storage = createStorage(); | ||
653 | 473 | | |||
654 | // WHEN | 474 | // WHEN | ||
▲ Show 20 Lines • Show All 257 Lines • ▼ Show 20 Line(s) | 708 | { | |||
912 | // THEN | 732 | // THEN | ||
913 | QCOMPARE(spy.size(), 2); | 733 | QCOMPARE(spy.size(), 2); | ||
914 | auto notifiedItem = spy.takeFirst().at(0).value<Akonadi::Item>(); | 734 | auto notifiedItem = spy.takeFirst().at(0).value<Akonadi::Item>(); | ||
915 | QCOMPARE(notifiedItem.id(), item.id()); | 735 | QCOMPARE(notifiedItem.id(), item.id()); | ||
916 | notifiedItem = spy.takeFirst().at(0).value<Akonadi::Item>(); | 736 | notifiedItem = spy.takeFirst().at(0).value<Akonadi::Item>(); | ||
917 | QCOMPARE(notifiedItem.id(), item2.id()); | 737 | QCOMPARE(notifiedItem.id(), item2.id()); | ||
918 | } | 738 | } | ||
919 | 739 | | |||
920 | void AkonadiStorageTestBase::shouldCreateTag() | | |||
921 | { | | |||
922 | // GIVEN | | |||
923 | | ||||
924 | // A storage implementation | | |||
925 | auto storage = createStorage(); | | |||
926 | | ||||
927 | // A spied monitor | | |||
928 | auto monitor = createMonitor(); | | |||
929 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::tagAdded); | | |||
930 | MonitorSpy monitorSpy(monitor.data()); | | |||
931 | | ||||
932 | // A tag | | |||
933 | Akonadi::Tag tag; | | |||
934 | QString name = QStringLiteral("Tag42"); | | |||
935 | const QByteArray type = QByteArray("Zanshin-Context"); | | |||
936 | const QByteArray gid = QByteArray(name.toLatin1()); | | |||
937 | tag.setName(name); | | |||
938 | tag.setType(QByteArray("Zanshin-Context")); | | |||
939 | tag.setGid(gid); | | |||
940 | | ||||
941 | // WHEN | | |||
942 | auto job = storage->createTag(tag); | | |||
943 | AKVERIFYEXEC(job); | | |||
944 | monitorSpy.waitForStableState(); | | |||
945 | QTRY_VERIFY(!spy.isEmpty()); | | |||
946 | | ||||
947 | // THEN | | |||
948 | QCOMPARE(spy.size(), 1); | | |||
949 | auto notifiedTag = spy.takeFirst().at(0).value<Akonadi::Tag>(); | | |||
950 | QCOMPARE(notifiedTag.name(), name); | | |||
951 | QCOMPARE(notifiedTag.type(), type); | | |||
952 | QCOMPARE(notifiedTag.gid(), gid); | | |||
953 | } | | |||
954 | | ||||
955 | void AkonadiStorageTestBase::shouldRemoveTag() | | |||
956 | { | | |||
957 | | ||||
958 | // GIVEN | | |||
959 | auto storage = createStorage(); | | |||
960 | | ||||
961 | // A spied monitor | | |||
962 | auto monitor = createMonitor(); | | |||
963 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::tagRemoved); | | |||
964 | MonitorSpy monitorSpy(monitor.data()); | | |||
965 | | ||||
966 | // An existing tag | | |||
967 | Akonadi::Tag tag = fetchTagByGID(QStringLiteral("errands-context")); | | |||
968 | | ||||
969 | // WHEN | | |||
970 | auto job = storage->removeTag(tag); | | |||
971 | AKVERIFYEXEC(job); | | |||
972 | monitorSpy.waitForStableState(); | | |||
973 | QTRY_VERIFY(!spy.isEmpty()); | | |||
974 | | ||||
975 | // THEN | | |||
976 | QCOMPARE(spy.size(), 1); | | |||
977 | auto notifiedTag = spy.takeFirst().at(0).value<Akonadi::Tag>(); | | |||
978 | QCOMPARE(notifiedTag.id(), tag.id()); | | |||
979 | } | | |||
980 | | ||||
981 | void AkonadiStorageTestBase::shouldUpdateTag() | | |||
982 | { | | |||
983 | // GIVEN | | |||
984 | auto storage = createStorage(); | | |||
985 | | ||||
986 | // A spied monitor | | |||
987 | auto monitor = createMonitor(); | | |||
988 | QSignalSpy spy(monitor.data(), &Akonadi::MonitorInterface::tagChanged); | | |||
989 | MonitorSpy monitorSpy(monitor.data()); | | |||
990 | | ||||
991 | // An existing tag | | |||
992 | Akonadi::Tag tag = fetchTagByGID(QStringLiteral("change-me")); | | |||
993 | | ||||
994 | // WHEN | | |||
995 | auto job = storage->updateTag(tag); | | |||
996 | AKVERIFYEXEC(job); | | |||
997 | monitorSpy.waitForStableState(); | | |||
998 | QTRY_VERIFY(!spy.isEmpty()); | | |||
999 | | ||||
1000 | // THEN | | |||
1001 | QCOMPARE(spy.size(), 1); | | |||
1002 | auto notifiedTag = spy.takeFirst().at(0).value<Akonadi::Tag>(); | | |||
1003 | QCOMPARE(notifiedTag.id(), tag.id()); | | |||
1004 | } | | |||
1005 | | ||||
1006 | void AkonadiStorageTestBase::shouldUpdateCollection() | 740 | void AkonadiStorageTestBase::shouldUpdateCollection() | ||
1007 | { | 741 | { | ||
1008 | // GIVEN | 742 | // GIVEN | ||
1009 | 743 | | |||
1010 | // A storage implementation | 744 | // A storage implementation | ||
1011 | auto storage = createStorage(); | 745 | auto storage = createStorage(); | ||
1012 | 746 | | |||
1013 | // An existing collection | 747 | // An existing collection | ||
▲ Show 20 Lines • Show All 168 Lines • Show Last 20 Lines |