Changeset View
Changeset View
Standalone View
Standalone View
autotests/libs/tagtest.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 47 | private Q_SLOTS: | |||
---|---|---|---|---|---|
61 | void testRIDIsolation(); | 61 | void testRIDIsolation(); | ||
62 | void testFetchTagIdWithItem(); | 62 | void testFetchTagIdWithItem(); | ||
63 | void testFetchFullTagWithItem(); | 63 | void testFetchFullTagWithItem(); | ||
64 | void testModifyItemWithTagByGID(); | 64 | void testModifyItemWithTagByGID(); | ||
65 | void testModifyItemWithTagByRID(); | 65 | void testModifyItemWithTagByRID(); | ||
66 | void testMonitor(); | 66 | void testMonitor(); | ||
67 | void testTagAttributeConfusionBug(); | 67 | void testTagAttributeConfusionBug(); | ||
68 | void testFetchItemsByTag(); | 68 | void testFetchItemsByTag(); | ||
69 | void tagModifyJobShouldOnlySendModifiedAttributes(); | ||||
69 | }; | 70 | }; | ||
70 | 71 | | |||
71 | void TagTest::initTestCase() | 72 | void TagTest::initTestCase() | ||
72 | { | 73 | { | ||
73 | AkonadiTest::checkTestIsIsolated(); | 74 | AkonadiTest::checkTestIsIsolated(); | ||
74 | AkonadiTest::setAllResourcesOffline(); | 75 | AkonadiTest::setAllResourcesOffline(); | ||
75 | AttributeFactory::registerAttribute<TagAttribute>(); | 76 | AttributeFactory::registerAttribute<TagAttribute>(); | ||
76 | qRegisterMetaType<Akonadi::Tag>(); | 77 | qRegisterMetaType<Akonadi::Tag>(); | ||
▲ Show 20 Lines • Show All 270 Lines • ▼ Show 20 Line(s) | 344 | { | |||
347 | QVERIFY(createjob->tag().isValid()); | 348 | QVERIFY(createjob->tag().isValid()); | ||
348 | tag = createjob->tag(); | 349 | tag = createjob->tag(); | ||
349 | } | 350 | } | ||
350 | 351 | | |||
351 | //We can add an attribute | 352 | //We can add an attribute | ||
352 | { | 353 | { | ||
353 | Akonadi::TagAttribute *attr = tag.attribute<Akonadi::TagAttribute>(Tag::AddIfMissing); | 354 | Akonadi::TagAttribute *attr = tag.attribute<Akonadi::TagAttribute>(Tag::AddIfMissing); | ||
354 | attr->setDisplayName(QStringLiteral("display name")); | 355 | attr->setDisplayName(QStringLiteral("display name")); | ||
355 | tag.addAttribute(attr); | | |||
356 | tag.setParent(Tag(0)); | 356 | tag.setParent(Tag(0)); | ||
357 | tag.setType("mytype"); | 357 | tag.setType("mytype"); | ||
358 | TagModifyJob *modJob = new TagModifyJob(tag, this); | 358 | TagModifyJob *modJob = new TagModifyJob(tag, this); | ||
359 | AKVERIFYEXEC(modJob); | 359 | AKVERIFYEXEC(modJob); | ||
360 | 360 | | |||
361 | TagFetchJob *fetchJob = new TagFetchJob(this); | 361 | TagFetchJob *fetchJob = new TagFetchJob(this); | ||
362 | fetchJob->fetchScope().fetchAttribute<Akonadi::TagAttribute>(); | 362 | fetchJob->fetchScope().fetchAttribute<Akonadi::TagAttribute>(); | ||
363 | AKVERIFYEXEC(fetchJob); | 363 | AKVERIFYEXEC(fetchJob); | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | |||||
450 | void TagTest::testAttributes() | 450 | void TagTest::testAttributes() | ||
451 | { | 451 | { | ||
452 | Tag tag; | 452 | Tag tag; | ||
453 | { | 453 | { | ||
454 | tag.setGid("gid2"); | 454 | tag.setGid("gid2"); | ||
455 | TagAttribute *attr = tag.attribute<TagAttribute>(Tag::AddIfMissing); | 455 | TagAttribute *attr = tag.attribute<TagAttribute>(Tag::AddIfMissing); | ||
456 | attr->setDisplayName(QStringLiteral("name")); | 456 | attr->setDisplayName(QStringLiteral("name")); | ||
457 | attr->setInToolbar(true); | 457 | attr->setInToolbar(true); | ||
458 | tag.addAttribute(attr); | | |||
459 | TagCreateJob *createjob = new TagCreateJob(tag, this); | 458 | TagCreateJob *createjob = new TagCreateJob(tag, this); | ||
460 | AKVERIFYEXEC(createjob); | 459 | AKVERIFYEXEC(createjob); | ||
461 | QVERIFY(createjob->tag().isValid()); | 460 | QVERIFY(createjob->tag().isValid()); | ||
462 | tag = createjob->tag(); | 461 | tag = createjob->tag(); | ||
463 | 462 | | |||
464 | { | 463 | { | ||
465 | TagFetchJob *fetchJob = new TagFetchJob(createjob->tag(), this); | 464 | TagFetchJob *fetchJob = new TagFetchJob(createjob->tag(), this); | ||
466 | fetchJob->fetchScope().fetchAttribute<TagAttribute>(); | 465 | fetchJob->fetchScope().fetchAttribute<TagAttribute>(); | ||
▲ Show 20 Lines • Show All 418 Lines • ▼ Show 20 Line(s) | 860 | { | |||
885 | QCOMPARE(fetchJob->items().size(), 1); | 884 | QCOMPARE(fetchJob->items().size(), 1); | ||
886 | Item i = fetchJob->items().first(); | 885 | Item i = fetchJob->items().first(); | ||
887 | QCOMPARE(i, item1); | 886 | QCOMPARE(i, item1); | ||
888 | 887 | | |||
889 | TagDeleteJob *deleteJob = new TagDeleteJob(tag, this); | 888 | TagDeleteJob *deleteJob = new TagDeleteJob(tag, this); | ||
890 | AKVERIFYEXEC(deleteJob); | 889 | AKVERIFYEXEC(deleteJob); | ||
891 | } | 890 | } | ||
892 | 891 | | |||
892 | void TagTest::tagModifyJobShouldOnlySendModifiedAttributes() | ||||
893 | { | ||||
894 | // Given a tag with an attribute | ||||
895 | Tag tag(QStringLiteral("tagWithAttr")); | ||||
896 | auto *attr = new Akonadi::TagAttribute; | ||||
897 | attr->setDisplayName(QStringLiteral("display name")); | ||||
898 | tag.addAttribute(attr); | ||||
899 | { | ||||
900 | auto *createjob = new TagCreateJob(tag, this); | ||||
901 | AKVERIFYEXEC(createjob); | ||||
902 | tag = createjob->tag(); | ||||
903 | } | ||||
904 | | ||||
905 | // When one job modifies this attribute, and another one does an unrelated modify job | ||||
906 | Tag attrModTag(tag.id()); | ||||
907 | Akonadi::TagAttribute *modAttr = attrModTag.attribute<Akonadi::TagAttribute>(Tag::AddIfMissing); | ||||
908 | modAttr->setDisplayName(QStringLiteral("modified")); | ||||
909 | TagModifyJob *attrModJob = new TagModifyJob(attrModTag, this); | ||||
910 | AKVERIFYEXEC(attrModJob); | ||||
911 | | ||||
912 | tag.setType(Tag::GENERIC); | ||||
913 | // this job shouldn't send the old attribute again | ||||
914 | auto *modJob = new TagModifyJob(tag, this); | ||||
915 | AKVERIFYEXEC(modJob); | ||||
916 | | ||||
917 | // Then the tag should have both the modified attribute and the modified type | ||||
918 | { | ||||
919 | auto *fetchJob = new TagFetchJob(this); | ||||
920 | fetchJob->fetchScope().fetchAttribute<Akonadi::TagAttribute>(); | ||||
921 | AKVERIFYEXEC(fetchJob); | ||||
922 | QCOMPARE(fetchJob->tags().size(), 1); | ||||
923 | const Tag fetchedTag = fetchJob->tags().at(0); | ||||
924 | QVERIFY(fetchedTag.hasAttribute<Akonadi::TagAttribute>()); | ||||
925 | QCOMPARE(fetchedTag.attribute<Akonadi::TagAttribute>()->displayName(), QStringLiteral("modified")); | ||||
926 | QCOMPARE(fetchedTag.type(), Tag::GENERIC); | ||||
927 | } | ||||
928 | | ||||
929 | // And when adding a new attribute next to the old one | ||||
930 | auto *attr2 = AttributeFactory::createAttribute("SecondType"); | ||||
931 | tag.addAttribute(attr2); | ||||
932 | // this job shouldn't send the old attribute again | ||||
933 | auto *modJob2 = new TagModifyJob(tag, this); | ||||
934 | AKVERIFYEXEC(modJob2); | ||||
935 | | ||||
936 | // Then the tag should have the modified attribute and the second one | ||||
937 | { | ||||
938 | auto *fetchJob = new TagFetchJob(this); | ||||
939 | fetchJob->fetchScope().setFetchAllAttributes(true); | ||||
940 | AKVERIFYEXEC(fetchJob); | ||||
941 | QCOMPARE(fetchJob->tags().size(), 1); | ||||
942 | const Tag fetchedTag = fetchJob->tags().at(0); | ||||
943 | QVERIFY(fetchedTag.hasAttribute<Akonadi::TagAttribute>()); | ||||
944 | QCOMPARE(fetchedTag.attribute<Akonadi::TagAttribute>()->displayName(), QStringLiteral("modified")); | ||||
945 | QCOMPARE(fetchedTag.type(), Tag::GENERIC); | ||||
946 | QVERIFY(fetchedTag.attribute("SecondType")); | ||||
947 | } | ||||
948 | } | ||||
949 | | ||||
893 | #include "tagtest.moc" | 950 | #include "tagtest.moc" | ||
894 | 951 | | |||
895 | QTEST_AKONADIMAIN(TagTest) | 952 | QTEST_AKONADIMAIN(TagTest) |