void CalendarUrlTest::shouldGenerateVCardWithParameter() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); CalendarUrl url; url.setType(CalendarUrl::CALUri); url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes"))); QMap<QString, QStringList> params; params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); url.setParameters(params); addr.insertCalendarUrl(url); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "CALURI;FOO2=bla2,blo2:https://sherlockholmes.com/calendar/sherlockholmes\r\n" "EMAIL:[email protected]\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); }
void AddresseeTest::fullEmailTest() { KContacts::Addressee a; QStringList emails; emails << QStringLiteral("*****@*****.**"); a.setEmails(emails); a.setFormattedName(QStringLiteral("firstname \"nickname\" lastname")); QCOMPARE(a.fullEmail(), QStringLiteral("\"firstname \\\"nickname\\\" lastname\" <*****@*****.**>")); }
void GenderTest::shouldExportEmptyGender() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected = createCard(QByteArray()); QCOMPARE(ba, expected); }
void GenderTest::shouldExportOnlyGenderWithoutTypeCommentGender() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); KContacts::Gender gender; gender.setComment(QStringLiteral("comment")); addr.setGender(gender); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected = createCard(QByteArray("GENDER:;comment")); QCOMPARE(ba, expected); }
void GenderTest::shouldNotExportInVcard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); KContacts::Gender gender; gender.setComment(QStringLiteral("comment")); addr.setGender(gender); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "EMAIL:[email protected]\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); }
void AddEmailToExistingContactJob::start() { if (mItem.hasPayload<KContacts::Addressee>()) { KContacts::Addressee address = mItem.payload<KContacts::Addressee>(); QStringList emails = address.emails(); if (emails.contains(mEmail)) { Q_EMIT emitResult(); } else { emails.append(mEmail); address.setEmails(emails); mItem.setPayload<KContacts::Addressee>(address); Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mItem); connect(job, &Akonadi::ItemModifyJob::result, this, &AddEmailToExistingContactJob::slotAddEmailDone); } } else { qCDebug(KMAIL_LOG) << " not a KContacts::Addressee item "; //TODO add error Q_EMIT emitResult(); } }
void BirthDayTest::shouldExportVcard4() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**") << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); const QDateTime dt(QDate(1976, 5, 5), QTime(12, 5, 5)); addr.setBirthday(dt); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "BDAY:19760505T120505\r\n" "EMAIL:[email protected]\r\n" "EMAIL:[email protected]\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); }
void BirthDayTest::shouldExportVcard3WithoutTimeAndWithoutYear() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**") << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); const QDate d(-1, 5, 5); addr.setBirthday(d); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "BDAY:--05-05\r\n" "EMAIL:[email protected]\r\n" "EMAIL:[email protected]\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); }
void CalendarUrlTest::shouldGenerateVCard() { QFETCH(KContacts::CalendarUrl::CalendarType, type); QFETCH(QByteArray, value); KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("*****@*****.**")); addr.setUid(QStringLiteral("testuid")); CalendarUrl url; url.setType(type); url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes"))); addr.insertCalendarUrl(url); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected; // Different order if (type == KContacts::CalendarUrl::FBUrl) { expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:[email protected]\r\n"); expected += value + QByteArray(":https://sherlockholmes.com/calendar/sherlockholmes\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); } else { expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:4.0\r\n"); expected += value + QByteArray(":https://sherlockholmes.com/calendar/sherlockholmes\r\n" "EMAIL:[email protected]\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); } QCOMPARE(ba, expected); }
void AddresseeTest::storeTest() { KContacts::Addressee addressee; KContacts::Picture logo(QStringLiteral("http://scottlandyard.info/pics/logo.png")); KContacts::Picture photo(QStringLiteral("http://scottlandyard.info/~sinclair/photo.png")); KContacts::Sound sound(QStringLiteral("http://scottlandyard.info/~sinclair/sound.wav")); QStringList emails; emails << QStringLiteral("*****@*****.**") << QStringLiteral("*****@*****.**"); KContacts::Key::List keys; keys << KContacts::Key(QStringLiteral("SecretKey")); QStringList categories; categories << QStringLiteral("Helper") << QStringLiteral("Friend"); QStringList customs; customs << QStringLiteral("X-Danger: high"); KContacts::Gender gender(QStringLiteral("H")); addressee.setGender(gender); KContacts::Lang lang(QLatin1String("lang")); addressee.setLangs(KContacts::Lang::List() << lang); addressee.setUid(QStringLiteral("My uid")); addressee.setName(QStringLiteral("John Sinclair")); addressee.setFormattedName(QStringLiteral("Sinclair, John")); addressee.setFamilyName(QStringLiteral("Sinclair")); addressee.setGivenName(QStringLiteral("John")); addressee.setAdditionalName(QStringLiteral("Bob")); addressee.setPrefix(QStringLiteral("Sir")); addressee.setSuffix(QStringLiteral("II")); addressee.setNickName(QStringLiteral("ghosthunter")); addressee.setBirthday(QDate(1982, 7, 19)); addressee.setMailer(QStringLiteral("mutt")); addressee.setTimeZone(KContacts::TimeZone(2)); addressee.setGeo(KContacts::Geo(42, 23)); addressee.setTitle(QStringLiteral("Ghost Hunter")); addressee.setRole(QStringLiteral("Leader")); addressee.setOrganization(QStringLiteral("Scottland Yard")); addressee.setNote(QStringLiteral("Don't cross black deads way...")); addressee.setProductId(QStringLiteral("ProductId45")); addressee.setRevision(QDateTime(QDate(1982, 9, 15))); addressee.setSortString(QStringLiteral("Name")); KContacts::ResourceLocatorUrl url; url.setUrl(QUrl(QStringLiteral("www.scottlandyard.info"))); addressee.setUrl(url); addressee.setSecrecy(KContacts::Secrecy(KContacts::Secrecy::Public)); addressee.setLogo(logo); addressee.setPhoto(photo); addressee.setSound(sound); addressee.setEmails(emails); addressee.setKeys(keys); addressee.setCategories(categories); addressee.setCustoms(customs); addressee.setKind(QStringLiteral("foo")); addressee.setChanged(false); KContacts::Impp imp; imp.setType(KContacts::Impp::GaduGadu); imp.setAddress(QStringLiteral("*****@*****.**")); KContacts::Impp::List listImp; listImp << imp; addressee.setImppList(listImp); QVERIFY(addressee.imppList() == listImp); QVERIFY(addressee.langs() == (KContacts::Lang::List() << lang)); QVERIFY(addressee.gender() == gender); QVERIFY(addressee.uid() == QStringLiteral("My uid")); QVERIFY(addressee.name() == QStringLiteral("John Sinclair")); QVERIFY(addressee.formattedName() == QStringLiteral("Sinclair, John")); QVERIFY(addressee.familyName() == QStringLiteral("Sinclair")); QVERIFY(addressee.givenName() == QStringLiteral("John")); QVERIFY(addressee.additionalName() == QStringLiteral("Bob")); QVERIFY(addressee.prefix() == QStringLiteral("Sir")); QVERIFY(addressee.suffix() == QStringLiteral("II")); QVERIFY(addressee.nickName() == QStringLiteral("ghosthunter")); QVERIFY(addressee.birthday().date() == QDate(1982, 7, 19)); QVERIFY(addressee.birthday().time() == QTime(0, 0)); QVERIFY(!addressee.birthdayHasTime()); QVERIFY(addressee.mailer() == QStringLiteral("mutt")); QVERIFY(addressee.timeZone() == KContacts::TimeZone(2)); QVERIFY(addressee.geo() == KContacts::Geo(42, 23)); QVERIFY(addressee.title() == QStringLiteral("Ghost Hunter")); QVERIFY(addressee.role() == QStringLiteral("Leader")); QVERIFY(addressee.organization() == QStringLiteral("Scottland Yard")); QVERIFY(addressee.note() == QStringLiteral("Don't cross black deads way...")); QVERIFY(addressee.productId() == QStringLiteral("ProductId45")); QVERIFY(addressee.revision() == QDateTime(QDate(1982, 9, 15))); QVERIFY(addressee.sortString() == QStringLiteral("Name")); QVERIFY(addressee.url() == url); QVERIFY(addressee.secrecy() == KContacts::Secrecy(KContacts::Secrecy::Public)); QVERIFY(addressee.logo() == logo); QVERIFY(addressee.photo() == photo); QVERIFY(addressee.sound() == sound); QVERIFY(addressee.emails() == emails); QVERIFY(addressee.keys() == keys); QVERIFY(addressee.categories() == categories); QVERIFY(addressee.customs() == customs); QVERIFY(addressee.changed() == false); QCOMPARE(addressee.kind(), QStringLiteral("foo")); }