diff --git a/autotests/addresstest.cpp b/autotests/addresstest.cpp index 7c25fba5..dd55c07e 100644 --- a/autotests/addresstest.cpp +++ b/autotests/addresstest.cpp @@ -1,452 +1,452 @@ /* This file is part of the KContacts framework. Copyright (c) 2007 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "addresstest.h" #include "addresseelist.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include "kcontacts/address.h" #include #include #include #include #include QTEST_MAIN(AddressTest) #ifndef Q_OS_WIN void initLocale() { qputenv("LC_ALL", "it_CH.utf-8"); } Q_CONSTRUCTOR_FUNCTION(initLocale) #endif void AddressTest::initTestCase() { } void AddressTest::emptyTest() { KContacts::Address address; QVERIFY(address.isEmpty()); } void AddressTest::storeTest() { KContacts::Address address; address.setId(QStringLiteral("My Id")); address.setType(KContacts::Address::Home); address.setPostOfficeBox(QStringLiteral("1234")); address.setExtended(QStringLiteral("My Extended Label")); address.setStreet(QStringLiteral("My Street")); address.setLocality(QStringLiteral("My Locality")); address.setRegion(QStringLiteral("My Region")); address.setPostalCode(QStringLiteral("My PostalCode")); address.setCountry(QStringLiteral("My Country")); address.setLabel(QStringLiteral("My Label")); QCOMPARE(address.id(), QStringLiteral("My Id")); QCOMPARE(address.type(), KContacts::Address::Home); QCOMPARE(address.postOfficeBox(), QStringLiteral("1234")); QCOMPARE(address.extended(), QStringLiteral("My Extended Label")); QCOMPARE(address.street(), QStringLiteral("My Street")); QCOMPARE(address.locality(), QStringLiteral("My Locality")); QCOMPARE(address.region(), QStringLiteral("My Region")); QCOMPARE(address.postalCode(), QStringLiteral("My PostalCode")); QCOMPARE(address.country(), QStringLiteral("My Country")); QCOMPARE(address.label(), QStringLiteral("My Label")); QVERIFY(!address.geo().isValid()); } void AddressTest::equalsTest() { KContacts::Address address1, address2; address1.setId(QStringLiteral("My Id")); address1.setType(KContacts::Address::Home); address1.setPostOfficeBox(QStringLiteral("1234")); address1.setExtended(QStringLiteral("My Extended Label")); address1.setStreet(QStringLiteral("My Street")); address1.setLocality(QStringLiteral("My Locality")); address1.setRegion(QStringLiteral("My Region")); address1.setPostalCode(QStringLiteral("My Postalcode")); address1.setCountry(QStringLiteral("My country")); address1.setLabel(QStringLiteral("My Label")); address2.setId(QStringLiteral("My Id")); address2.setType(KContacts::Address::Home); address2.setPostOfficeBox(QStringLiteral("1234")); address2.setExtended(QStringLiteral("My Extended Label")); address2.setStreet(QStringLiteral("My Street")); address2.setLocality(QStringLiteral("My Locality")); address2.setRegion(QStringLiteral("My Region")); address2.setPostalCode(QStringLiteral("My Postalcode")); address2.setCountry(QStringLiteral("My country")); address2.setLabel(QStringLiteral("My Label")); QVERIFY(address1 == address2); } void AddressTest::differsTest() { KContacts::Address address1(KContacts::Address::Home); KContacts::Address address2(KContacts::Address::Work); QVERIFY(address1 != address2); } void AddressTest::assignmentTest() { KContacts::Address address1, address2; address1.setId(QStringLiteral("My Id")); address1.setType(KContacts::Address::Home); address1.setPostOfficeBox(QStringLiteral("1234")); address1.setExtended(QStringLiteral("My Extended Label")); address1.setStreet(QStringLiteral("My Street")); address1.setLocality(QStringLiteral("My Locality")); address1.setRegion(QStringLiteral("My Region")); address1.setPostalCode(QStringLiteral("My Postalcode")); address1.setCountry(QStringLiteral("My country")); address1.setLabel(QStringLiteral("My Label")); address2 = address1; QVERIFY(address1 == address2); } void AddressTest::serializeTest() { KContacts::Address address1, address2; address1.setType(KContacts::Address::Work); address1.setPostOfficeBox(QStringLiteral("1234")); address1.setExtended(QStringLiteral("My Extended Label")); address1.setStreet(QStringLiteral("My Street")); address1.setLocality(QStringLiteral("My Locality")); address1.setRegion(QStringLiteral("My Region")); address1.setPostalCode(QStringLiteral("My Postalcode")); address1.setCountry(QStringLiteral("My country")); address1.setLabel(QStringLiteral("My Label")); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << address1; QDataStream t(&data, QIODevice::ReadOnly); t >> address2; QVERIFY(address1 == address2); } void AddressTest::formatTest() { { KContacts::Address address; address.setStreet(QStringLiteral("Lummerlandstr. 1")); address.setPostalCode(QStringLiteral("12345")); address.setLocality(QStringLiteral("Lummerstadt")); address.setCountry(QStringLiteral("Germany")); const QString result(QStringLiteral("Jim Knopf\nLummerlandstr. 1\n" "12345 Lummerstadt\n\nGERMANY")); QCOMPARE(address.formattedAddress(QStringLiteral("Jim Knopf")), result); } { KContacts::Address address; address.setStreet(QStringLiteral("457 Foobar Ave")); address.setPostalCode(QStringLiteral("1A2B3C")); address.setLocality(QStringLiteral("Nervousbreaktown")); address.setRegion(QStringLiteral("DC")); address.setCountry(QStringLiteral("United States of America")); const QString result( QStringLiteral("Huck Finn\n457 Foobar Ave\nNervousbreaktown," " DC 1A2B3C\n\nUNITED STATES OF AMERICA")); QCOMPARE(address.formattedAddress(QStringLiteral("Huck Finn")), result); } { KContacts::Address address; address.setStreet(QStringLiteral("Lummerlandstr. 1")); address.setPostalCode(QStringLiteral("12345")); address.setLocality(QStringLiteral("Lummerstadt")); address.setCountry(QStringLiteral("Deutschland")); const QString result(QStringLiteral("Jim Knopf\nLummerlandstr. 1\n" "12345 Lummerstadt\n\nDEUTSCHLAND")); QCOMPARE(address.formattedAddress(QStringLiteral("Jim Knopf")), result); } { KContacts::Address address; address.setStreet(QStringLiteral("Lummerlandstr. 1")); address.setPostalCode(QStringLiteral("12345")); address.setLocality(QStringLiteral("Lummerstadt")); address.setCountry(QString()); const QString result(QStringLiteral("Jim Knopf\nLummerlandstr. 1\n12345 Lummerstadt")); QCOMPARE(address.formattedAddress(QStringLiteral("Jim Knopf")), result); } { KContacts::Address address; address.setStreet(QStringLiteral("Haus Randa")); address.setPostalCode(QStringLiteral("1234")); address.setLocality(QStringLiteral("Randa")); address.setPostOfficeBox(QStringLiteral("5678")); address.setCountry(QStringLiteral("Schweiz")); // we want the Italian variant of the Swiss format for it_CH const QString result(QStringLiteral("Dr. Konqui\nCasella postale 5678\nHaus Randa\n1234 Randa\n\nSCHWEIZ")); QCOMPARE(address.formattedAddress(QStringLiteral("Dr. Konqui")), result); } } void AddressTest::shouldExportVcard3() { KContacts::Address address; address.setId(QStringLiteral("My Id")); address.setType(KContacts::Address::Home); address.setPostOfficeBox(QStringLiteral("1234")); address.setExtended(QStringLiteral("My Extended Label")); address.setStreet(QStringLiteral("My Street")); address.setLocality(QStringLiteral("My Locality")); address.setRegion(QStringLiteral("My Region")); address.setPostalCode(QStringLiteral("My Postalcode")); address.setCountry(QStringLiteral("My country")); address.setLabel(QStringLiteral("My Label")); KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); addr.insertAddress(address); 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" "ADR;TYPE=home:1234;My Extended Label;My Street;My Locality;My Region;My Pos\r\n" " talcode;My country\r\n" "EMAIL:foo@kde.org\r\n" "LABEL;TYPE=home:My Label\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void AddressTest::shouldParseAddressVCard3() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "ADR;TYPE=home:1234;My Extended Label;My Street;My Locality;My Region;My Pos\r\n" " talcode;My country\r\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "LABEL;TYPE=home:My Label\r\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).addresses().count(), 1); KContacts::Address address = lst.at(0).addresses().at(0); QCOMPARE(address.type(), KContacts::Address::Home); QCOMPARE(address.postOfficeBox(), QStringLiteral("1234")); QCOMPARE(address.extended(), QStringLiteral("My Extended Label")); QCOMPARE(address.region(), QStringLiteral("My Region")); QCOMPARE(address.street(), QStringLiteral("My Street")); QCOMPARE(address.country(), QStringLiteral("My country")); QCOMPARE(address.postalCode(), QStringLiteral("My Postalcode")); QCOMPARE(address.label(), QStringLiteral("My Label")); } void AddressTest::shouldParseAddressVCard4() { QByteArray vcarddata("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "ADR;LABEL=\"My Label\";TYPE=home:1234;My Extended Label;My Street;My Locality\r\n" " ;My Region;My Postalcode;My country\r\nEMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).addresses().count(), 1); KContacts::Address address = lst.at(0).addresses().at(0); QCOMPARE(address.type(), KContacts::Address::Home); QCOMPARE(address.postOfficeBox(), QStringLiteral("1234")); QCOMPARE(address.extended(), QStringLiteral("My Extended Label")); QCOMPARE(address.region(), QStringLiteral("My Region")); QCOMPARE(address.street(), QStringLiteral("My Street")); QCOMPARE(address.country(), QStringLiteral("My country")); QCOMPARE(address.postalCode(), QStringLiteral("My Postalcode")); QCOMPARE(address.label(), QStringLiteral("My Label")); } void AddressTest::shouldParseAddressVCard4WithGeoPosition() { QByteArray vcarddata("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "ADR;GEO=\"geo:22.500000,45.099998\";LABEL=\"My Label\";TYPE=home:1234;My Extend\r\n" " ed Label;My Street;My Locality;My Region;My Postalcode;My country\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).addresses().count(), 1); KContacts::Address address = lst.at(0).addresses().at(0); QCOMPARE(address.type(), KContacts::Address::Home); QCOMPARE(address.postOfficeBox(), QStringLiteral("1234")); QCOMPARE(address.extended(), QStringLiteral("My Extended Label")); QCOMPARE(address.region(), QStringLiteral("My Region")); QCOMPARE(address.street(), QStringLiteral("My Street")); QCOMPARE(address.country(), QStringLiteral("My country")); QCOMPARE(address.postalCode(), QStringLiteral("My Postalcode")); QCOMPARE(address.label(), QStringLiteral("My Label")); KContacts::Geo geo = address.geo(); QVERIFY(geo.isValid()); QCOMPARE(geo.latitude(), 22.5f); QCOMPARE(geo.longitude(), 45.1f); } void AddressTest::shouldExportVCard4WithGeoPosition() { KContacts::Address address; address.setId(QStringLiteral("My Id")); address.setType(KContacts::Address::Home); address.setPostOfficeBox(QStringLiteral("1234")); address.setExtended(QStringLiteral("My Extended Label")); address.setStreet(QStringLiteral("My Street")); address.setLocality(QStringLiteral("My Locality")); address.setRegion(QStringLiteral("My Region")); address.setPostalCode(QStringLiteral("My Postalcode")); address.setCountry(QStringLiteral("My country")); address.setLabel(QStringLiteral("My Label")); KContacts::Geo geo; geo.setLatitude(22.5f); geo.setLongitude(45.1f); address.setGeo(geo); KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); addr.insertAddress(address); 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" "ADR;GEO=\"geo:22.500000,45.099998\";LABEL=\"My Label\";TYPE=home:1234;My Extend\r\n" " ed Label;My Street;My Locality;My Region;My Postalcode;My country\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void AddressTest::shouldExportVcard4() { KContacts::Address address; address.setId(QStringLiteral("My Id")); address.setType(KContacts::Address::Home); address.setPostOfficeBox(QStringLiteral("1234")); address.setExtended(QStringLiteral("My Extended Label")); address.setStreet(QStringLiteral("My Street")); address.setLocality(QStringLiteral("My Locality")); address.setRegion(QStringLiteral("My Region")); address.setPostalCode(QStringLiteral("My Postalcode")); address.setCountry(QStringLiteral("My country")); address.setLabel(QStringLiteral("My Label")); KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); addr.insertAddress(address); 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" "ADR;LABEL=\"My Label\";TYPE=home:1234;My Extended Label;My Street;My Locality\r\n" " ;My Region;My Postalcode;My country\r\nEMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void AddressTest::countryToISOTest() { using namespace KContacts; QCOMPARE(Address::countryToISO(QStringLiteral("France")), QLatin1String("fr")); QCOMPARE(Address::countryToISO(QStringLiteral("Frankreich")), QLatin1String("fr")); QCOMPARE(Address::countryToISO(QStringLiteral("Germany")), QLatin1String("de")); QCOMPARE(Address::countryToISO(QStringLiteral("Österreich")), QLatin1String("at")); QCOMPARE(Address::countryToISO(QStringLiteral("Disneyland")), QString()); QCOMPARE(Address::countryToISO(QStringLiteral("Østrig")), QLatin1String("at")); QCOMPARE(Address::countryToISO(QStringLiteral("Den Demokratiske Republik Congo (DRC)")), QLatin1String("cd")); QCOMPARE(Address::countryToISO(QStringLiteral("Congo-Kinshasa")), QLatin1String("cd")); QCOMPARE(Address::countryToISO(QStringLiteral("South Sudan")), QLatin1String("ss")); QCOMPARE(Address::countryToISO(QStringLiteral("United States")), QLatin1String("us")); QCOMPARE(Address::countryToISO(QStringLiteral("United States Of America")), QLatin1String("us")); QCOMPARE(Address::countryToISO(QStringLiteral("United")), QString()); } void AddressTest::isoToCountryTest() { qunsetenv("LC_ALL"); qputenv("LANGUAGE", "en"); using namespace KContacts; QCOMPARE(Address::ISOtoCountry(QStringLiteral("FR")), QLatin1String("France")); QCOMPARE(Address::ISOtoCountry(QStringLiteral("de")), QLatin1String("Germany")); // invalid QCOMPARE(Address::ISOtoCountry(QStringLiteral("EU")), QLatin1String("EU")); QCOMPARE(Address::ISOtoCountry(QStringLiteral("zz")), QLatin1String("zz")); QCOMPARE(Address::ISOtoCountry(QStringLiteral("0")), QLatin1String("0")); } diff --git a/autotests/birthdaytest.cpp b/autotests/birthdaytest.cpp index 5596888f..d53944ee 100644 --- a/autotests/birthdaytest.cpp +++ b/autotests/birthdaytest.cpp @@ -1,231 +1,231 @@ /* This file is part of kcontacts. Copyright (C) 2016-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "birthdaytest.h" #include -#include +#include #include "addressee.h" #include "vcard.h" BirthDayTest::BirthDayTest(QObject *parent) : QObject(parent) { } BirthDayTest::~BirthDayTest() { } void BirthDayTest::shouldParseBirthDay() { QByteArray vcarddata("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "BDAY:19760505T120505\r\n" "EMAIL:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QDateTime dt(QDate(1976, 5, 5), QTime(12, 5, 5)); QCOMPARE(lst.at(0).birthday(), dt); QCOMPARE(lst.at(0).birthdayHasTime(), true); } void BirthDayTest::shouldParseBirthDayWithoutTime() { QByteArray vcarddata("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "BDAY:19760505\r\n" "EMAIL:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QDateTime dt(QDate(1976, 5, 5)); QCOMPARE(lst.at(0).birthday(), dt); QCOMPARE(lst.at(0).birthdayHasTime(), false); } void BirthDayTest::shouldParseBirthDayWithoutTimeAndYear() { QByteArray vcarddata("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "BDAY:--0505\r\n" "EMAIL:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QDateTime dt(QDate(-1, 5, 5)); QCOMPARE(lst.at(0).birthday(), dt); QCOMPARE(lst.at(0).birthdayHasTime(), false); } void BirthDayTest::shouldExportVcard4() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); 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:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void BirthDayTest::shouldExportVcard4WithoutTime() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); addr.setUid(QStringLiteral("testuid")); const QDate d(1976, 5, 5); addr.setBirthday(d); 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:19760505\r\n" "EMAIL:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void BirthDayTest::shouldExportVcard4WithoutTimeAndWithoutYear() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); 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::v4_0); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "BDAY:--0505\r\n" "EMAIL:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void BirthDayTest::shouldExportVcard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); 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::v3_0); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "BDAY:1976-05-05T12:05:05\r\n" "EMAIL:foo@kde.org\r\n" "EMAIL:bla@kde.org\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("foo@kde.org") << QStringLiteral("bla@kde.org")); 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:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void BirthDayTest::shouldExportVcard3WithoutTime() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); addr.setUid(QStringLiteral("testuid")); const QDate d(1976, 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:1976-05-05\r\n" "EMAIL:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(BirthDayTest) diff --git a/autotests/calendarurltest.cpp b/autotests/calendarurltest.cpp index 3f66febf..71edae63 100644 --- a/autotests/calendarurltest.cpp +++ b/autotests/calendarurltest.cpp @@ -1,304 +1,304 @@ /* This file is part of the KContacts framework. Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "calendarurltest.h" #include "calendarurl.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include using namespace KContacts; Q_DECLARE_METATYPE(KContacts::CalendarUrl::CalendarType) CalendarUrlTest::CalendarUrlTest(QObject *parent) : QObject(parent) { } CalendarUrlTest::~CalendarUrlTest() { } void CalendarUrlTest::shouldHaveDefaultValue() { CalendarUrl calendarUrl(CalendarUrl::FBUrl); QVERIFY(!calendarUrl.isValid()); QVERIFY(calendarUrl.url().isEmpty()); QVERIFY(calendarUrl.parameters().isEmpty()); } void CalendarUrlTest::shouldAssignValue() { QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); CalendarUrl calendarUrl(CalendarUrl::FBUrl); calendarUrl.setParameters(params); QVERIFY(!calendarUrl.isValid()); QCOMPARE(calendarUrl.type(), CalendarUrl::FBUrl); QVERIFY(calendarUrl.url().isEmpty()); QVERIFY(!calendarUrl.parameters().isEmpty()); QCOMPARE(calendarUrl.parameters(), params); } void CalendarUrlTest::shouldAssignExternal() { CalendarUrl calendarUrl(CalendarUrl::FBUrl); const CalendarUrl::CalendarType type = CalendarUrl::CALUri; calendarUrl.setType(type); QVERIFY(calendarUrl.url().isEmpty()); QCOMPARE(calendarUrl.type(), type); } void CalendarUrlTest::shouldSerialized() { for (int i = 0; i < CalendarUrl::EndCalendarType; ++i) { CalendarUrl calendarUrl; CalendarUrl result; CalendarUrl::CalendarType type = static_cast(i); calendarUrl.setType(type); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); calendarUrl.setParameters(params); calendarUrl.setUrl(QUrl(QStringLiteral("mailto:foo@kde.org"))); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << calendarUrl; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(calendarUrl == result); } } void CalendarUrlTest::shouldEqualCalendarUrl() { for (int i = 0; i < CalendarUrl::EndCalendarType; ++i) { CalendarUrl calendarUrl; CalendarUrl result; CalendarUrl::CalendarType type = static_cast(i); calendarUrl.setType(type); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); calendarUrl.setUrl(QUrl(QStringLiteral("mailto:foo@kde.org"))); calendarUrl.setParameters(params); result = calendarUrl; QVERIFY(calendarUrl == result); } } void CalendarUrlTest::shouldParseCalendarUrl() { for (int i = CalendarUrl::Unknown + 1; i < CalendarUrl::EndCalendarType; ++i) { CalendarUrl::CalendarType type = static_cast(i); QByteArray baType; switch (type) { case CalendarUrl::Unknown: case CalendarUrl::EndCalendarType: break; case CalendarUrl::FBUrl: baType = QByteArray("FBURL"); break; case CalendarUrl::CALUri: baType = QByteArray("CALURI"); break; case CalendarUrl::CALADRUri: baType = QByteArray("CALADRURI"); break; } QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n"); vcarddata += baType; vcarddata += QByteArray( ";PREF=1:https://sherlockholmes.com/calendar/sherlockholmes\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).calendarUrlList().count(), 1); const CalendarUrl calurl = lst.at(0).calendarUrlList().at(0); QCOMPARE(calurl.type(), type); QCOMPARE(calurl.url(), QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes"))); QVERIFY(!calurl.parameters().isEmpty()); } } void CalendarUrlTest::shouldGenerateVCard_data() { QTest::addColumn("type"); QTest::addColumn("value"); for (int i = CalendarUrl::Unknown + 1; i < CalendarUrl::EndCalendarType; ++i) { KContacts::CalendarUrl::CalendarType type = static_cast(i); QByteArray baType; switch (type) { case CalendarUrl::Unknown: case CalendarUrl::EndCalendarType: break; case CalendarUrl::FBUrl: baType = QByteArray("FBURL"); break; case CalendarUrl::CALUri: baType = QByteArray("CALURI"); break; case CalendarUrl::CALADRUri: baType = QByteArray("CALADRURI"); break; } QTest::newRow(baType.constData()) << type << baType; } } void CalendarUrlTest::shouldGenerateVCard() { QFETCH(KContacts::CalendarUrl::CalendarType, type); QFETCH(QByteArray, value); KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); 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:foo@kde.org\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:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); } QCOMPARE(ba, expected); } void CalendarUrlTest::shouldGenerateVCardWithParameter() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); CalendarUrl url; url.setType(CalendarUrl::CALUri); url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes"))); QMap 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:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void CalendarUrlTest::shouldNotGeneratedAttributeForVcard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); CalendarUrl url; url.setType(CalendarUrl::CALUri); url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes"))); QMap 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::v3_0); QByteArray expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void CalendarUrlTest::shouldGenerateMultiCalendarUrl() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); CalendarUrl url; url.setType(CalendarUrl::CALUri); url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes"))); QMap params; params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); url.setParameters(params); addr.insertCalendarUrl(url); url.setType(CalendarUrl::FBUrl); url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes2"))); params.clear(); params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); 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:foo@kde.org\r\n" "FBURL;FOO1=bla1,blo1:https://sherlockholmes.com/calendar/sherlockholmes2\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(CalendarUrlTest) diff --git a/autotests/clientpidmaptest.cpp b/autotests/clientpidmaptest.cpp index 15b0678f..2abea44f 100644 --- a/autotests/clientpidmaptest.cpp +++ b/autotests/clientpidmaptest.cpp @@ -1,240 +1,240 @@ /* This file is part of the KContacts framework. Copyright (C) 2016-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "clientpidmaptest.h" #include "clientpidmap.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include ClientPidMapTest::ClientPidMapTest(QObject *parent) : QObject(parent) { } ClientPidMapTest::~ClientPidMapTest() { } void ClientPidMapTest::shouldHaveDefaultValue() { KContacts::ClientPidMap role; QVERIFY(!role.isValid()); QVERIFY(role.clientPidMap().isEmpty()); QVERIFY(role.parameters().isEmpty()); } void ClientPidMapTest::shouldAssignValue() { const QString lang(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::ClientPidMap role(lang); role.setParameters(params); QVERIFY(role.isValid()); QVERIFY(!role.clientPidMap().isEmpty()); QCOMPARE(role.clientPidMap(), lang); QVERIFY(!role.parameters().isEmpty()); QCOMPARE(role.parameters(), params); } void ClientPidMapTest::shouldAssignExternal() { KContacts::ClientPidMap role; const QString lang(QStringLiteral("fr")); role.setClientPidMap(lang); QVERIFY(role.isValid()); QCOMPARE(role.clientPidMap(), lang); } void ClientPidMapTest::shouldSerialized() { KContacts::ClientPidMap role; KContacts::ClientPidMap result; const QString lang(QStringLiteral("fr")); role.setClientPidMap(lang); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); role.setParameters(params); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << role; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(role == result); } void ClientPidMapTest::shouldEqualClientPidMap() { KContacts::ClientPidMap role; KContacts::ClientPidMap result; const QString lang(QStringLiteral("fr")); role.setClientPidMap(lang); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); role.setParameters(params); result = role; QVERIFY(role == result); } void ClientPidMapTest::shouldParseClientPidMap() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "CLIENTPIDMAP:boo\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).clientPidMapList().count(), 1); QCOMPARE(lst.at(0).clientPidMapList().at(0).clientPidMap(), QStringLiteral("boo")); } void ClientPidMapTest::shouldParseWithoutClientPidMap() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).clientPidMapList().count(), 0); } void ClientPidMapTest::shouldCreateVCard() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::ClientPidMap::List lstClientPidMap; KContacts::ClientPidMap clientpidmap(QStringLiteral("fr")); lstClientPidMap << clientpidmap; addr.setClientPidMapList(lstClientPidMap); 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" "CLIENTPIDMAP:fr\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void ClientPidMapTest::shouldCreateVCardWithTwoClientPidMap() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::ClientPidMap::List lstClientPidMap; KContacts::ClientPidMap clientpidmap(QStringLiteral("fr")); KContacts::ClientPidMap clientpidmap2(QStringLiteral("fr2")); lstClientPidMap << clientpidmap << clientpidmap2; addr.setClientPidMapList(lstClientPidMap); 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" "CLIENTPIDMAP:fr\r\n" "CLIENTPIDMAP:fr2\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void ClientPidMapTest::shouldCreateVCardWithParameters() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::ClientPidMap::List lstClientPidMap; KContacts::ClientPidMap clientpidmap(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); clientpidmap.setParameters(params); lstClientPidMap << clientpidmap; addr.setClientPidMapList(lstClientPidMap); 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" "CLIENTPIDMAP;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void ClientPidMapTest::shouldGenerateClientPidMapForVCard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::ClientPidMap::List lstClientPidMap; KContacts::ClientPidMap clientpidmap(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); clientpidmap.setParameters(params); lstClientPidMap << clientpidmap; addr.setClientPidMapList(lstClientPidMap); 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:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(ClientPidMapTest) diff --git a/autotests/customidentifiertest.cpp b/autotests/customidentifiertest.cpp index 8ca9b820..f5eae5eb 100644 --- a/autotests/customidentifiertest.cpp +++ b/autotests/customidentifiertest.cpp @@ -1,121 +1,121 @@ /* This file is part of the KContacts framework. Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "customidentifiertest.h" #include -#include "vcardtool.h" +#include "vcardtool_p.h" #include "addressee.h" CustomIdentifierTest::CustomIdentifierTest(QObject *parent) : QObject(parent) { } CustomIdentifierTest::~CustomIdentifierTest() { } void CustomIdentifierTest::shouldHaveEmptyCustoms() { KContacts::Addressee addresseeWithMail; addresseeWithMail.insertEmail(QStringLiteral("foo@bar.org")); QVERIFY(!addresseeWithMail.isEmpty()); QVERIFY(addresseeWithMail.customs().isEmpty()); } void CustomIdentifierTest::shouldExportVcard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); addr.setUid(QStringLiteral("testuid")); addr.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-SpousesName"), QStringLiteral("foo")); lst << addr; KContacts::VCardTool vcard; QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "EMAIL:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "X-KADDRESSBOOK-X-SpousesName:foo\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); addr.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-ANNIVERSARY"), QStringLiteral("19960415")); lst.clear(); lst << addr; ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "EMAIL:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "X-KADDRESSBOOK-X-ANNIVERSARY:19960415\r\n" "X-KADDRESSBOOK-X-SpousesName:foo\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void CustomIdentifierTest::shouldExportVcard4() { //TODO don't work to export custom! KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); addr.setUid(QStringLiteral("testuid")); addr.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-SpousesName"), QStringLiteral("foo")); lst << addr; KContacts::VCardTool vcard; QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "RELATED;TYPE=spouse;VALUE=foo:;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); QDate dt(12, 9, 3); addr.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-ANNIVERSARY"), dt.toString(Qt::ISODate)); lst.clear(); lst << addr; ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "ANNIVERSARY:00120903\r\n" "EMAIL:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "RELATED;TYPE=spouse;VALUE=foo:;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(CustomIdentifierTest) diff --git a/autotests/datetimetest.cpp b/autotests/datetimetest.cpp index 176d7f2b..a2372672 100644 --- a/autotests/datetimetest.cpp +++ b/autotests/datetimetest.cpp @@ -1,174 +1,174 @@ /* This file is part of kcontacts. Copyright (c) 2016 Benjamin Löwe This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "datetimetest.h" #include -#include +#include DateTimeTest::DateTimeTest(QObject *parent) : QObject(parent) { } DateTimeTest::~DateTimeTest() { } void DateTimeTest::shouldParseDateTime() { using namespace KContacts; QDateTime expected, dt; bool timeIsValid; dt = VCardTool::parseDateTime(QStringLiteral("2016-01-20T12:33:30+0200")); expected = QDateTime(QDate(2016, 1, 20), QTime(12, 33, 30), Qt::OffsetFromUTC, 2 * 3600); QCOMPARE(dt, expected); QVERIFY(dt.isValid()); dt = VCardTool::parseDateTime(QStringLiteral("2016-01-20T12:33:30+02")); QCOMPARE(dt, expected); QVERIFY(dt.isValid()); dt = VCardTool::parseDateTime(QStringLiteral("20160120T123330+0200")); QCOMPARE(dt, expected); QVERIFY(dt.isValid()); dt = VCardTool::parseDateTime(QStringLiteral("2016-01-20T12:33Z")); expected = QDateTime(QDate(2016, 1, 20), QTime(12, 33, 0), Qt::UTC); QCOMPARE(dt, expected); QVERIFY(dt.isValid()); dt = VCardTool::parseDateTime(QStringLiteral("2016-01-20T12:33-0300")); expected = QDateTime(QDate(2016, 1, 20), QTime(12, 33, 0), Qt::OffsetFromUTC, -3 * 3600); QCOMPARE(dt, expected); QVERIFY(dt.isValid()); dt = VCardTool::parseDateTime(QStringLiteral("2016-01-20T12:33"), &timeIsValid); expected = QDateTime(QDate(2016, 1, 20), QTime(12, 33, 0), Qt::LocalTime); QCOMPARE(dt, expected); QVERIFY(timeIsValid); QVERIFY(dt.isValid()); dt = VCardTool::parseDateTime(QStringLiteral("2016-01-20"), &timeIsValid); expected = QDateTime(QDate(2016, 1, 20), QTime(), Qt::LocalTime); QCOMPARE(dt, expected); QVERIFY(dt.isValid()); QVERIFY(!timeIsValid); QCOMPARE(dt.time(), QTime(0, 0)); dt = VCardTool::parseDateTime(QStringLiteral("T1233Z"), &timeIsValid); QVERIFY(!dt.isValid()); QVERIFY(timeIsValid); QCOMPARE(dt.time(), QTime(12, 33)); dt = VCardTool::parseDateTime(QStringLiteral("--0120")); expected = QDateTime(QDate(-1, 1, 20)); QCOMPARE(dt, expected); QVERIFY(dt.isValid()); dt = VCardTool::parseDateTime(QStringLiteral("--01-20")); expected = QDateTime(QDate(-1, 1, 20)); QCOMPARE(dt, expected); QVERIFY(dt.isValid()); } void DateTimeTest::shouldCreateDateTime() { using namespace KContacts; QDateTime dt; QString str, expected; dt = QDateTime(QDate(2016, 1, 20), QTime(12, 33, 30), Qt::UTC); str = VCardTool::createDateTime(dt, VCard::v4_0); expected = QStringLiteral("20160120T123330Z"); QCOMPARE(str, expected); dt = QDateTime(QDate(2016, 1, 20), QTime(), Qt::UTC); str = VCardTool::createDateTime(dt, VCard::v4_0); expected = QStringLiteral("20160120T000000Z"); QCOMPARE(str, expected); dt = QDateTime(QDate(2016, 1, 20), QTime(12, 33, 30), Qt::LocalTime); str = VCardTool::createDateTime(dt, VCard::v4_0); expected = QStringLiteral("20160120T123330"); QCOMPARE(str, expected); dt = QDateTime(QDate(2016, 1, 20), QTime(12, 33, 30), Qt::OffsetFromUTC, -2 * 3600); str = VCardTool::createDateTime(dt, VCard::v4_0); expected = QStringLiteral("20160120T123330-0200"); QCOMPARE(str, expected); dt = QDateTime(QDate(2016, 1, 20), QTime(12, 33, 30), Qt::OffsetFromUTC, +2.5 * 3600); str = VCardTool::createDateTime(dt, VCard::v4_0); expected = QStringLiteral("20160120T123330+0230"); QCOMPARE(str, expected); dt = QDateTime(QDate(2016, 1, 20), QTime(12, 33, 30), Qt::OffsetFromUTC, -2 * 3600); str = VCardTool::createDateTime(dt, VCard::v3_0); expected = QStringLiteral("2016-01-20T12:33:30-02:00"); QCOMPARE(str, expected); dt = QDateTime(QDate(), QTime(12, 33, 30), Qt::OffsetFromUTC, -2 * 3600); str = VCardTool::createDateTime(dt, VCard::v3_0); expected = QString(); QCOMPARE(str, expected); dt = QDateTime(QDate(2016, 1, 20), QTime(12, 33, 30)); str = VCardTool::createDateTime(dt, VCard::v3_0, false); expected = QStringLiteral("2016-01-20"); QCOMPARE(str, expected); dt = QDateTime(QDate(2016, 1, 20), QTime(12, 33, 30)); str = VCardTool::createDateTime(dt, VCard::v4_0, false); expected = QStringLiteral("20160120"); QCOMPARE(str, expected); } void DateTimeTest::shouldCreateDate() { using namespace KContacts; QDate d; QString str, expected; d = QDate(2016, 1, 20); str = VCardTool::createDate(d, VCard::v3_0); expected = QStringLiteral("2016-01-20"); QCOMPARE(str, expected); d = QDate(2016, 1, 20); str = VCardTool::createDate(d, VCard::v4_0); expected = QStringLiteral("20160120"); QCOMPARE(str, expected); d = QDate(-1, 1, 20); str = VCardTool::createDate(d, VCard::v3_0); expected = QStringLiteral("--01-20"); QCOMPARE(str, expected); d = QDate(-1, 1, 20); str = VCardTool::createDate(d, VCard::v4_0); expected = QStringLiteral("--0120"); QCOMPARE(str, expected); } QTEST_MAIN(DateTimeTest) diff --git a/autotests/emailtest.cpp b/autotests/emailtest.cpp index 50d25c7d..acf51286 100644 --- a/autotests/emailtest.cpp +++ b/autotests/emailtest.cpp @@ -1,185 +1,185 @@ /* This file is part of the KContacts framework. Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "emailtest.h" #include "email.h" #include -#include "vcardtool.h" +#include "vcardtool_p.h" EmailTest::EmailTest(QObject *parent) : QObject(parent) { } EmailTest::~EmailTest() { } void EmailTest::shouldHaveDefaultValue() { KContacts::Email email; QVERIFY(!email.isValid()); QVERIFY(email.mail().isEmpty()); QVERIFY(email.parameters().isEmpty()); } void EmailTest::shouldAssignValue() { const QString mail(QStringLiteral("foo@kde.org")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::Email email(mail); email.setParameters(params); QVERIFY(email.isValid()); QVERIFY(!email.mail().isEmpty()); QCOMPARE(email.mail(), mail); QVERIFY(!email.parameters().isEmpty()); QCOMPARE(email.parameters(), params); } void EmailTest::shouldAssignExternal() { KContacts::Email email; const QString mail(QStringLiteral("foo@kde.org")); email.setEmail(mail); QVERIFY(email.isValid()); QVERIFY(!email.mail().isEmpty()); QCOMPARE(email.mail(), mail); } void EmailTest::shouldSerialized() { KContacts::Email email; KContacts::Email result; const QString mail(QStringLiteral("foo@kde.org")); email.setEmail(mail); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); email.setParameters(params); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << email; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(email == result); } void EmailTest::shouldEqualEmail() { KContacts::Email email; KContacts::Email result; const QString mail(QStringLiteral("foo@kde.org")); email.setEmail(mail); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); email.setParameters(params); result = email; QVERIFY(email == result); } void EmailTest::shouldParseEmailVCard() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "EMAIL;TYPE=HOME,PREF;X-EVOLUTION-UI-SLOT=2:foo@foo.com\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QVERIFY(!lst.at(0).emailList().isEmpty()); QCOMPARE(lst.at(0).emailList().count(), 1); KContacts::Email email = lst.at(0).emailList().at(0); QCOMPARE(email.mail(), QStringLiteral("foo@foo.com")); QCOMPARE(email.parameters().count(), 2); } void EmailTest::shouldParseEmailVCardWithMultiEmails() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "EMAIL;TYPE=HOME,PREF;X-EVOLUTION-UI-SLOT=2:foo@foo.com\n" "EMAIL;TYPE=HOME,PREF;X-EVOLUTION-UI-SLOT=2:bla@bla.com\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QVERIFY(!lst.at(0).emailList().isEmpty()); QCOMPARE(lst.at(0).emailList().count(), 2); KContacts::Email email = lst.at(0).emailList().at(0); QCOMPARE(email.mail(), QStringLiteral("bla@bla.com")); email = lst.at(0).emailList().at(1); QCOMPARE(email.mail(), QStringLiteral("foo@foo.com")); QCOMPARE(email.parameters().count(), 2); } void EmailTest::shouldParseEmailVCardWithoutEmail() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QVERIFY(lst.at(0).emailList().isEmpty()); } void EmailTest::shouldExportVcard() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); addr.setUid(QStringLiteral("testuid")); 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" "EMAIL:foo@kde.org\r\n" "EMAIL:bla@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(EmailTest) diff --git a/autotests/fieldgrouptest.cpp b/autotests/fieldgrouptest.cpp index 30425304..e3d08fce 100644 --- a/autotests/fieldgrouptest.cpp +++ b/autotests/fieldgrouptest.cpp @@ -1,263 +1,263 @@ /* This file is part of the KContacts framework. Copyright (C) 2016-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "fieldgrouptest.h" #include "fieldgroup.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include FieldGroupTest::FieldGroupTest(QObject *parent) : QObject(parent) { } FieldGroupTest::~FieldGroupTest() { } void FieldGroupTest::shouldHaveDefaultValue() { KContacts::FieldGroup fieldgroup; QVERIFY(!fieldgroup.isValid()); QVERIFY(fieldgroup.fieldGroupName().isEmpty()); QVERIFY(fieldgroup.parameters().isEmpty()); QVERIFY(fieldgroup.value().isEmpty()); } void FieldGroupTest::shouldAssignValue() { const QString fielgroundname(QStringLiteral("fr")); const QString value(QStringLiteral("bla")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::FieldGroup fieldGroup(fielgroundname); fieldGroup.setParameters(params); fieldGroup.setValue(value); QVERIFY(fieldGroup.isValid()); QVERIFY(!fieldGroup.fieldGroupName().isEmpty()); QCOMPARE(fieldGroup.fieldGroupName(), fielgroundname); QVERIFY(!fieldGroup.parameters().isEmpty()); QCOMPARE(fieldGroup.parameters(), params); QCOMPARE(fieldGroup.value(), value); } void FieldGroupTest::shouldAssignExternal() { KContacts::FieldGroup fieldgroup; const QString fieldgroundname(QStringLiteral("fr")); const QString value(QStringLiteral("bla")); fieldgroup.setValue(value); fieldgroup.setFieldGroupName(fieldgroundname); QVERIFY(fieldgroup.isValid()); QCOMPARE(fieldgroup.fieldGroupName(), fieldgroundname); QCOMPARE(fieldgroup.value(), value); } void FieldGroupTest::shouldSerialized() { KContacts::FieldGroup fieldGroup; KContacts::FieldGroup result; const QString lang(QStringLiteral("fr")); fieldGroup.setFieldGroupName(lang); const QString value(QStringLiteral("bla")); fieldGroup.setValue(value); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); fieldGroup.setParameters(params); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << fieldGroup; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(fieldGroup == result); } void FieldGroupTest::shouldEqualFieldGroup() { KContacts::FieldGroup fieldGroup; KContacts::FieldGroup result; const QString lang(QStringLiteral("fr")); const QString value(QStringLiteral("bla")); fieldGroup.setValue(value); fieldGroup.setFieldGroupName(lang); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); fieldGroup.setParameters(params); result = fieldGroup; QVERIFY(fieldGroup == result); } void FieldGroupTest::shouldParseFieldGroup() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "fr.foo:bla\n" "fr2.foo:bla\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).fieldGroupList().count(), 2); } void FieldGroupTest::shouldParseWithoutFieldGroup() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).fieldGroupList().count(), 0); } void FieldGroupTest::shouldCreateVCard() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::FieldGroup::List lstFieldGroup; KContacts::FieldGroup fieldGroup(QStringLiteral("fr")); const QString value(QStringLiteral("bla")); fieldGroup.setValue(value); lstFieldGroup << fieldGroup; addr.setFieldGroupList(lstFieldGroup); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "fr:bla\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void FieldGroupTest::shouldCreateVCardWithTwoLang() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::FieldGroup::List lstFieldGroup; KContacts::FieldGroup fieldGroup1(QStringLiteral("fr")); const QString value(QStringLiteral("bla")); fieldGroup1.setValue(value); KContacts::FieldGroup fieldGroup2(QStringLiteral("fr2")); fieldGroup2.setValue(value); lstFieldGroup << fieldGroup1 << fieldGroup2; addr.setFieldGroupList(lstFieldGroup); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "fr:bla\r\n" "fr2:bla\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void FieldGroupTest::shouldCreateVCardWithParameters() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); const QString value(QStringLiteral("bla")); KContacts::FieldGroup::List lstFieldGroup; KContacts::FieldGroup fieldGroup(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); fieldGroup.setParameters(params); fieldGroup.setValue(value); lstFieldGroup << fieldGroup; addr.setFieldGroupList(lstFieldGroup); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "fr;FOO1=bla1,blo1;FOO2=bla2,blo2:bla\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void FieldGroupTest::shouldNotGenerateFieldGroupForVCard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::FieldGroup::List lstFieldGroup; KContacts::FieldGroup fieldGroup(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); fieldGroup.setParameters(params); const QString value(QStringLiteral("bla")); fieldGroup.setValue(value); lstFieldGroup << fieldGroup; addr.setFieldGroupList(lstFieldGroup); 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:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "fr;FOO1=bla1,blo1;FOO2=bla2,blo2:bla\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(FieldGroupTest) diff --git a/autotests/gendertest.cpp b/autotests/gendertest.cpp index d298e1e6..ba593644 100644 --- a/autotests/gendertest.cpp +++ b/autotests/gendertest.cpp @@ -1,256 +1,256 @@ /* This file is part of the KContacts framework. Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "gendertest.h" #include "gender.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include GenderTest::GenderTest(QObject *parent) : QObject(parent) { } GenderTest::~GenderTest() { } void GenderTest::shouldHaveDefaultValue() { KContacts::Gender gender; QVERIFY(!gender.isValid()); QVERIFY(gender.gender().isEmpty()); QVERIFY(gender.comment().isEmpty()); } void GenderTest::shouldAssignValue() { const QString genderStr(QStringLiteral("F")); KContacts::Gender gender(genderStr); const QString commentStr(QStringLiteral("foo")); gender.setComment(commentStr); QVERIFY(gender.isValid()); QVERIFY(!gender.gender().isEmpty()); QCOMPARE(gender.gender(), genderStr); QVERIFY(!gender.comment().isEmpty()); QCOMPARE(gender.comment(), commentStr); } void GenderTest::shouldAssignExternal() { KContacts::Gender gender; const QString genderStr(QStringLiteral("H")); gender.setGender(genderStr); QVERIFY(gender.isValid()); QVERIFY(!gender.gender().isEmpty()); QCOMPARE(gender.gender(), genderStr); } void GenderTest::shouldSerialized() { KContacts::Gender gender; KContacts::Gender result; const QString genderStr(QStringLiteral("H")); gender.setGender(genderStr); gender.setComment(QStringLiteral("foo")); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << gender; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(gender == result); } void GenderTest::shouldEqualGender() { KContacts::Gender gender; KContacts::Gender result; const QString genderStr(QStringLiteral("H")); gender.setGender(genderStr); gender.setComment(QStringLiteral("foo")); result = gender; QVERIFY(gender == result); } void GenderTest::shouldParseGender_data() { QTest::addColumn("vcarddata"); QTest::addColumn("genre"); QTest::addColumn("comment"); QTest::addColumn("hasGender"); QByteArray str("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); QTest::newRow("nogender") << str << QString() << QString() << false; str = QByteArray("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "GENDER:H\n" "END:VCARD\n"); QTest::newRow("hasgenderbutnocomment") << str << QStringLiteral("H") << QString() << true; str = QByteArray("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "GENDER:;foo\n" "END:VCARD\n"); QTest::newRow("hasgenderbutnotypebutcomment") << str << QString() << QStringLiteral("foo") << true; str = QByteArray("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "GENDER:H;foo\n" "END:VCARD\n"); QTest::newRow("hasgendertypeandcomment") << str << QStringLiteral("H") << QStringLiteral("foo") << true; } void GenderTest::shouldParseGender() { QFETCH(QByteArray, vcarddata); QFETCH(QString, genre); QFETCH(QString, comment); QFETCH(bool, hasGender); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).gender().isValid(), hasGender); QCOMPARE(lst.at(0).gender().comment(), comment); QCOMPARE(lst.at(0).gender().gender(), genre); } QByteArray GenderTest::createCard(const QByteArray &gender) { QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n"); if (!gender.isEmpty()) { expected += gender + "\r\n"; } expected += QByteArray( "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); return expected; } void GenderTest::shouldExportEmptyGender() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); 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::shouldExportOnlyGenderWithoutCommentGender() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Gender gender; gender.setGender(QStringLiteral("H")); addr.setGender(gender); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected = createCard(QByteArray("GENDER:H")); QCOMPARE(ba, expected); } void GenderTest::shouldExportOnlyGenderWithCommentGender() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Gender gender; gender.setGender(QStringLiteral("H")); 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:H;comment")); QCOMPARE(ba, expected); } void GenderTest::shouldExportOnlyGenderWithoutTypeCommentGender() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); 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("foo@kde.org")); 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:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(GenderTest) diff --git a/autotests/geotest.cpp b/autotests/geotest.cpp index ab0e8343..ec7ab380 100644 --- a/autotests/geotest.cpp +++ b/autotests/geotest.cpp @@ -1,205 +1,205 @@ /* This file is part of the KContacts framework. Copyright (c) 2007 KDE-PIM team This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "geotest.h" #include "kcontacts/geo.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include QTEST_MAIN(GeoTest) void GeoTest::constructor() { KContacts::Geo geo(1.2f, 3.4f); QVERIFY((float)geo.latitude() == (float)1.2); QVERIFY((float)geo.longitude() == (float)3.4); } void GeoTest::isValid() { KContacts::Geo geo; QVERIFY(!geo.isValid()); geo.setLatitude(23); QVERIFY(!geo.isValid()); geo.setLongitude(45); QVERIFY(geo.isValid()); geo.clear(); QVERIFY(!geo.isValid()); QVERIFY(geo == KContacts::Geo()); } void GeoTest::setData() { KContacts::Geo geo; geo.setLatitude(22.5f); geo.setLongitude(45.1f); QVERIFY((float)geo.latitude() == (float)22.5); QVERIFY((float)geo.longitude() == (float)45.1); } void GeoTest::equals() { KContacts::Geo geo1(22.5f, 33.7f); KContacts::Geo geo2(22.5f, 33.7f); QVERIFY(geo1 == geo2); } void GeoTest::differs() { KContacts::Geo geo1(22.5f, 33.7f); KContacts::Geo geo2(22.5f, 33.6f); QVERIFY(geo1 != geo2); } void GeoTest::serialization() { KContacts::Geo geo1(22.5f, 33.7f); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << geo1; KContacts::Geo geo2; QDataStream t(&data, QIODevice::ReadOnly); t >> geo2; QVERIFY(geo1 == geo2); } void GeoTest::shouldParseGeoVCard3() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "GEO:22.5;180.0\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QVERIFY(lst.at(0).geo().isValid()); KContacts::Geo geo = lst.at(0).geo(); QCOMPARE(geo.latitude(), 22.5); QCOMPARE(geo.longitude(), 180.0); } void GeoTest::shouldParseGeoVCard4() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:4.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "GEO:geo:22.5,180.0\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QVERIFY(lst.at(0).geo().isValid()); KContacts::Geo geo = lst.at(0).geo(); QCOMPARE(geo.latitude(), 22.5); QCOMPARE(geo.longitude(), 180.0); } void GeoTest::shouldGenerateVCard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Geo geo; geo.setLongitude(180.0); geo.setLatitude(22.5); addr.setGeo(geo); 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:foo@kde.org\r\n" "GEO:22.500000;180.000000\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void GeoTest::shouldGenerateVCard4() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Geo geo; geo.setLongitude(180.0); geo.setLatitude(22.5); addr.setGeo(geo); 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" "EMAIL:foo@kde.org\r\n" "GEO:geo:22.500000,180.000000\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void GeoTest::shouldGenerateWithoutGeo() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } diff --git a/autotests/importexportvcardtest.cpp b/autotests/importexportvcardtest.cpp index 8590a2c5..22b1be23 100644 --- a/autotests/importexportvcardtest.cpp +++ b/autotests/importexportvcardtest.cpp @@ -1,224 +1,224 @@ /* This file is part of the KContacts framework. Copyright (C) 2016-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "importexportvcardtest.h" #include -#include "vcardtool.h" +#include "vcardtool_p.h" #include ImportExportVCardTest::ImportExportVCardTest(QObject *parent) : QObject(parent) { } ImportExportVCardTest::~ImportExportVCardTest() { } static void compareBuffers(const QByteArray &outputData, const QByteArray &expected) { if (outputData != expected) { qDebug() << " outputData " << outputData; qDebug() << " expected " << expected; } const QList outputLines = outputData.split('\n'); const QList outputRefLines = expected.split('\n'); for (int i = 0; i < qMin(outputLines.count(), outputRefLines.count()); ++i) { const QByteArray actual = outputLines.at(i); const QByteArray expect = outputRefLines.at(i); if (actual != expect) { qCritical() << "Mismatch at output line" << (i + 1); QCOMPARE(actual, expect); QCOMPARE(actual.count(), expect.count()); } } QCOMPARE(outputLines.count(), outputRefLines.count()); QCOMPARE(outputData.size(), expected.size()); } void ImportExportVCardTest::shouldExportFullTestVcard4() { QByteArray vcarddata("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "FN:Sherlock Holmes\r\n" "TEL;VALUE=uri;PREF=1;TYPE=\"voice,home\":tel:+44-555-555-5555;ext=5555\r\n" "TEL;VALUE=uri;TYPE=\"voice,cell,text\":tel:+44-555-555-6666\r\n" "TEL;VALUE=uri;TYPE=\"voice,work\":tel:+44-555-555-7777\r\n" "N:Holmes;Sherlock;;Mr;;\r\n" "KIND:individual\r\n" "NICKNAME:Shirley\r\n" "PHOTO:\r\n" "BDAY:19531015T231000Z\r\n" "ANNIVERSARY:19960415\r\n" "GENDER:M\r\n" "ADR;GEO=\"geo:51.5237,0.1585\";LABEL=\"Mr Sherlock Holmes, 221B Baker Street, London NW1, England, United Kingdom\":;;221B Baker Street;London;;NW1;United Kingdom\r\n" "EMAIL;TYPE=home:sherlock.holmes@gmail.com\r\n" "EMAIL;PREF=1;TYPE=work:detective@sherlockholmes.com\r\n" "IMPP;PREF=1:xmpp:detective@sherlockholmes.com\r\n" "LANG;TYPE=work;PREF=1:en\r\n" "LANG;TYPE=work;PREF=2:fr\r\n" "TZ:London/Europe\r\n" "GEO:geo:51.5237,0.1585\r\n" "TITLE;ALTID=1;LANGUAGE=fr:Patron\r\n" "TITLE;ALTID=2;LANGUAGE=en:Boss\r\n" "ROLE:Detective\r\n" "UID:urn:uuid:b8767877-b4a1-4c70-9acc-505d3819e519\r\n" "CATEGORIES:FICTION,LITERATURE\r\n" "PRODID:-//KADDRESSBOOK//NONSGML Version 1//EN\r\n" "REV:20140722T222710Z\r\n" "URL;TYPE=home:https://sherlockholmes.com\r\n" "KEY;MEDIATYPE=application/pgp-keys:https://sherlockholmes.com/sherlock-holmes.pub.asc\r\n" "CALURI;PREF=1:https://sherlockholmes.com/calendar/sherlockholmes\r\n" "FBURL;PREF=1:https://sherlockholmes.com/busy/detective\r\n" "CALADRURI;PREF=1:mailto:detective@sherlockholmes.com\r\n" "END:VCARD\r\n\r\n"); QByteArray vcardexpected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "ADR;GEO=\"geo:51.523701,0.158500\";LABEL=\"Mr Sherlock Holmes, 221B Baker Stre\r\n" " et, London NW1, England, United Kingdom\";TYPE:;;221B Baker Street;London;;\r\n" " NW1;United Kingdom\r\n" "ANNIVERSARY:19960415\r\n" "BDAY:19531015T231000Z\r\n" "CALADRURI;PREF=1:mailto:detective@sherlockholmes.com\r\n" "CALURI;PREF=1:https://sherlockholmes.com/calendar/sherlockholmes\r\n" "EMAIL;TYPE=home:sherlock.holmes@gmail.com\r\n" "EMAIL;PREF=1;TYPE=work:detective@sherlockholmes.com\r\n" "FBURL;PREF=1:https://sherlockholmes.com/busy/detective\r\n" "FN:Sherlock Holmes\r\n" "GENDER:M\r\n" "GEO:geo:51.523701,0.158500\r\n" "IMPP;X-SERVICE-TYPE=xmpp;PREF=1:detective@sherlockholmes.com\r\n" "KEY;MEDIATYPE=application/pgp-keys:https://sherlockholmes.com/sherlock-holm\r\n" " es.pub.asc\r\nKIND:individual\r\n" "LANG;PREF=1;TYPE=work:en\r\n" "LANG;PREF=2;TYPE=work:fr\r\n" "N:Holmes;Sherlock;;Mr;\r\n" "NICKNAME:Shirley\r\n" "PRODID:-//KADDRESSBOOK//NONSGML Version 1//EN\r\n" "REV:20140722T222710Z\r\n" "ROLE:Detective\r\n" "TEL;TYPE=\"home,voice\";PREF=1;VALUE=uri:tel:+44-555-555-5555;ext=5555\r\n" "TEL;TYPE=\"cell,voice\";VALUE=uri:tel:+44-555-555-6666\r\n" "TEL;TYPE=\"voice,work\";VALUE=uri:tel:+44-555-555-7777\r\n" "TITLE;ALTID=1;LANGUAGE=fr:Patron\r\n" "TITLE;ALTID=2;LANGUAGE=en:Boss\r\n" "TZ:+00:00\r\n" "UID:urn:uuid:b8767877-b4a1-4c70-9acc-505d3819e519\r\n" "URL;TYPE=home:https://sherlockholmes.com\r\n" "END:VCARD\r\n\r\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); const QByteArray result = vcard.exportVCards(lst, KContacts::VCard::v4_0); compareBuffers(result, vcardexpected); } void ImportExportVCardTest::shouldExportMiscElementVcard4() { QByteArray vcarddata("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "UID:urn:uuid:4fbe8971-0bc3-424c-9c26-36c3e1eff6b1\r\n" "FN;PID=1.1:J. Doe\r\n" "N:Doe;J.;;;\r\n" "EMAIL;PID=1.1:jdoe@example.com\r\n" "EMAIL;PID=2.1:boss@example.com\r\n" "TEL;PID=1.1;VALUE=uri:tel:+1-555-555-5555\r\n" "TEL;PID=2.1;VALUE=uri:tel:+1-666-666-6666\r\n" "CLIENTPIDMAP:1;urn:uuid:53e374d9-337e-4727-8803-a1e9c14e0556\r\n" "END:VCARD\r\n\r\n"); QByteArray vcardexpected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "CLIENTPIDMAP:1;urn:uuid:53e374d9-337e-4727-8803-a1e9c14e0556\r\n" "EMAIL;PID=1.1:jdoe@example.com\r\n" "EMAIL;PID=2.1:boss@example.com\r\n" "FN:J. Doe\r\n" "N:Doe;J.;;;\r\n" "TEL;PID=1.1;VALUE=uri:tel:+1-555-555-5555\r\n" "TEL;PID=2.1;VALUE=uri:tel:+1-666-666-6666\r\n" "UID:urn:uuid:4fbe8971-0bc3-424c-9c26-36c3e1eff6b1\r\n" "END:VCARD\r\n\r\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); const QByteArray result = vcard.exportVCards(lst, KContacts::VCard::v4_0); compareBuffers(result, vcardexpected); } void ImportExportVCardTest::shouldExportMemberElementVcard4() { QByteArray vcarddata("BEGIN:VCARD" "VERSION:4.0\r\n" "KIND:group\r\n" "FN:Funky distribution list\r\n" "MEMBER:mailto:subscriber1@example.com\r\n" "MEMBER:xmpp:subscriber2@example.com\r\n" "MEMBER:sip:subscriber3@example.com\r\n" "MEMBER:tel:+1-418-555-5555\r\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\r\n" "END:VCARD\r\n"); QByteArray vcardexpected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "FN:Funky distribution list\r\n" "KIND:group\r\n" "MEMBER:mailto:subscriber1@example.com\r\n" "MEMBER:xmpp:subscriber2@example.com\r\n" "MEMBER:sip:subscriber3@example.com\r\n" "MEMBER:tel:+1-418-555-5555\r\n" "N:;;;;\r\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\r\n" "END:VCARD\r\n\r\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); const QByteArray result = vcard.exportVCards(lst, KContacts::VCard::v4_0); compareBuffers(result, vcardexpected); } void ImportExportVCardTest::shouldExportMissingNewlineVcard4() { QByteArray vcarddata("BEGIN:VCARD" "VERSION:4.0\r\n" "KIND:group\r\n" "FN:Funky distribution list\r\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\r\n" "END:VCARD"); QByteArray vcardexpected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "FN:Funky distribution list\r\n" "KIND:group\r\n" "N:;;;;\r\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\r\n" "END:VCARD\r\n\r\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); const QByteArray result = vcard.exportVCards(lst, KContacts::VCard::v4_0); compareBuffers(result, vcardexpected); } // TODO please make this data driven before copy/pasting more methods here... QTEST_MAIN(ImportExportVCardTest) diff --git a/autotests/impptest.cpp b/autotests/impptest.cpp index 30dae276..572aa87a 100644 --- a/autotests/impptest.cpp +++ b/autotests/impptest.cpp @@ -1,323 +1,323 @@ /* This file is part of libkabc. Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "impptest.h" #include "impp.h" #include -#include "vcardtool.h" +#include "vcardtool_p.h" Q_DECLARE_METATYPE(KContacts::Impp::ImppType) ImppTest::ImppTest(QObject *parent) : QObject(parent) { } ImppTest::~ImppTest() { } void ImppTest::shouldHaveDefaultValue() { KContacts::Impp impp; QVERIFY(!impp.isValid()); QVERIFY(impp.address().isEmpty()); QCOMPARE(impp.type(), KContacts::Impp::Unknown); QVERIFY(impp.parameters().isEmpty()); } void ImppTest::shouldAssignValue() { const QString address(QStringLiteral("address")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::Impp impp; impp.setParameters(params); impp.setType(KContacts::Impp::Icq); impp.setAddress(address); QVERIFY(impp.isValid()); QVERIFY(!impp.address().isEmpty()); QCOMPARE(impp.address(), address); QCOMPARE(impp.type(), KContacts::Impp::Icq); QVERIFY(!impp.parameters().isEmpty()); QCOMPARE(impp.parameters(), params); } void ImppTest::shouldSerialized() { const QString address(QStringLiteral("address")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::Impp impp; impp.setParameters(params); impp.setType(KContacts::Impp::Icq); impp.setAddress(address); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << impp; KContacts::Impp result; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(impp == result); } void ImppTest::shouldEqualImpp() { const QString address(QStringLiteral("address")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::Impp impp; impp.setParameters(params); impp.setType(KContacts::Impp::Icq); impp.setAddress(address); KContacts::Impp result(impp); QVERIFY(impp == result); } void ImppTest::shouldParseWithoutImpp() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "LANG:fr" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).imppList().count(), 0); } void ImppTest::shouldParseImpp() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "IMPP;X-SERVICE-TYPE=skype:skype:xxxxxxxx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).imppList().count(), 1); KContacts::Impp impp = lst.at(0).imppList().at(0); QCOMPARE(impp.address(), QStringLiteral("skype:xxxxxxxx")); QCOMPARE(impp.type(), KContacts::Impp::Skype); } void ImppTest::shouldParseImppVcard4() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:4.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "IMPP:skype:xxxxxxxx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).imppList().count(), 1); KContacts::Impp impp = lst.at(0).imppList().at(0); QCOMPARE(impp.address(), QStringLiteral("xxxxxxxx")); QCOMPARE(impp.type(), KContacts::Impp::Skype); } QByteArray createCard(KContacts::Impp::ImppType type) { QByteArray expected("BEGIN:VCARD\n" "VERSION:3.0\n" "EMAIL:foo@kde.org\n"); if (type != KContacts::Impp::Unknown) { const QByteArray baType = KContacts::Impp::typeToString(type).toLatin1(); expected += "IMPP;X-SERVICE-TYPE=" + baType + ":" + baType + ":address\n"; } expected += QByteArray( "N:;;;;\n" "UID:testuid\n" "END:VCARD\n\n"); return expected; } void ImppTest::shouldParseServiceType_data() { QTest::addColumn("type"); QTest::addColumn("hasImpp"); QTest::newRow("withoutimpp") << KContacts::Impp::Unknown << false; QTest::newRow("skype") << KContacts::Impp::Skype << true; for (int i = KContacts::Impp::Unknown + 1; i < KContacts::Impp::EndList; ++i) { KContacts::Impp::ImppType type = static_cast(i); QTest::newRow(KContacts::Impp::typeToString(type).toLatin1().constData()) << type << true; } } void ImppTest::shouldParseServiceType() { QFETCH(KContacts::Impp::ImppType, type); QFETCH(bool, hasImpp); QByteArray vcarddata = createCard(type); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(!lst.at(0).imppList().isEmpty(), hasImpp); if (hasImpp) { KContacts::Impp impp = lst.at(0).imppList().at(0); QCOMPARE(impp.address(), QStringLiteral("%1:address").arg(KContacts::Impp::typeToString(type))); QCOMPARE(impp.type(), type); } } QByteArray expectedVcard(KContacts::Impp::ImppType type) { QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n"); if (type != KContacts::Impp::Unknown) { const QByteArray baType = KContacts::Impp::typeToString(type).toLatin1(); expected += "IMPP;X-SERVICE-TYPE=" + baType + ":address\r\n"; } expected += ("N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); return expected; } void ImppTest::shouldExportEmptyType() { QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QCOMPARE(ba, expected); } void ImppTest::shouldExportType_data() { QTest::addColumn("type"); for (int i = KContacts::Impp::Unknown + 1; i < KContacts::Impp::EndList; ++i) { KContacts::Impp::ImppType type = static_cast(i); QTest::newRow(KContacts::Impp::typeToString(type).toLatin1().constData()) << type; } } void ImppTest::shouldExportType() { QFETCH(KContacts::Impp::ImppType, type); QByteArray expected = expectedVcard(type); KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Impp impp; impp.setAddress(QStringLiteral("address")); impp.setType(type); addr.insertImpp(impp); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QCOMPARE(ba, expected); } void ImppTest::shouldExportWithParameters() { QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" "IMPP;FOO1=bla1,blo1;FOO2=bla2,blo2;X-SERVICE-TYPE=skype:address\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::Impp impp; impp.setAddress(QStringLiteral("address")); impp.setType(KContacts::Impp::Skype); impp.setParameters(params); addr.insertImpp(impp); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QCOMPARE(ba, expected); } void ImppTest::shouldShouldNotExportTwiceServiceType() { QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" "IMPP;FOO1=bla1,blo1;FOO2=bla2,blo2;X-SERVICE-TYPE=skype:address\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); params.insert(QStringLiteral("X-SERVICE-TYPE"), QStringList() << QStringLiteral("aim")); KContacts::Impp impp; impp.setAddress(QStringLiteral("address")); impp.setType(KContacts::Impp::Skype); impp.setParameters(params); addr.insertImpp(impp); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QCOMPARE(ba, expected); } QTEST_MAIN(ImppTest) diff --git a/autotests/keytest.cpp b/autotests/keytest.cpp index 1dc70264..40189c15 100644 --- a/autotests/keytest.cpp +++ b/autotests/keytest.cpp @@ -1,186 +1,186 @@ /* This file is part of the KContacts framework. Copyright (c) 2007 Tobias Koenig Copyright (C) 2016-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "keytest.h" #include "kcontacts/key.h" #include -#include "vcardtool.h" +#include "vcardtool_p.h" QTEST_MAIN(KeyTest) void KeyTest::storeTest() { KContacts::Key key; key.setId(QStringLiteral("My Id")); key.setType(KContacts::Key::Custom); key.setCustomTypeString(QStringLiteral("GnuPG")); key.setTextData(QStringLiteral("That's my super secret key")); QVERIFY(key.id() == QStringLiteral("My Id")); QVERIFY(key.type() == KContacts::Key::Custom); QVERIFY(key.customTypeString() == QStringLiteral("GnuPG")); QVERIFY(key.textData() == QStringLiteral("That's my super secret key")); QVERIFY(key.isBinary() == false); } void KeyTest::equalsTest() { KContacts::Key key1, key2; key1.setId(QStringLiteral("My Id")); key1.setType(KContacts::Key::Custom); key1.setCustomTypeString(QStringLiteral("GnuPG")); key1.setTextData(QStringLiteral("That's my super secret key")); key2.setId(QStringLiteral("My Id")); key2.setType(KContacts::Key::Custom); key2.setCustomTypeString(QStringLiteral("GnuPG")); key2.setTextData(QStringLiteral("That's my super secret key")); QVERIFY(key1 == key2); } void KeyTest::differsTest() { KContacts::Key key1(QStringLiteral("TextKey"), KContacts::Key::PGP); KContacts::Key key2(QStringLiteral("TextKey"), KContacts::Key::Custom); QVERIFY(key1 != key2); } void KeyTest::assignmentTest() { KContacts::Key key1, key2; key1.setId(QStringLiteral("My Id")); key1.setType(KContacts::Key::Custom); key1.setCustomTypeString(QStringLiteral("GnuPG")); key1.setTextData(QStringLiteral("That's my super secret key")); key2 = key1; QVERIFY(key1 == key2); } void KeyTest::serializeTest() { KContacts::Key key1, key2; key1.setId(QStringLiteral("My Id")); key1.setType(KContacts::Key::Custom); key1.setCustomTypeString(QStringLiteral("GnuPG")); key1.setTextData(QStringLiteral("That's my super secret key")); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << key1; QDataStream t(&data, QIODevice::ReadOnly); t >> key2; QVERIFY(key1 == key2); } void KeyTest::shouldExportVCard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Key key1(QStringLiteral("https://foo.org/sherlock-holmes.pub.asc"), KContacts::Key::PGP); addr.setKeys(KContacts::Key::List{key1}); 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:foo@kde.org\r\n" "KEY;TYPE=PGP:https://foo.org/sherlock-holmes.pub.asc\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void KeyTest::shouldExportVCard4() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Key key1(QStringLiteral("https://foo.org/sherlock-holmes.pub.asc"), KContacts::Key::PGP); addr.setKeys(KContacts::Key::List{key1}); 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" "EMAIL:foo@kde.org\r\n" "KEY;MEDIATYPE=application/pgp-keys:https://foo.org/sherlock-holmes.pub.asc\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void KeyTest::shouldParseVcard3() { QByteArray vcarddata("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "EMAIL:foo@kde.org\r\n" "KEY;TYPE=PGP:https://foo.org/sherlock-holmes.pub.asc\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QVERIFY(!lst.at(0).keys().isEmpty()); QCOMPARE(lst.at(0).keys().count(), 1); KContacts::Key key = lst.at(0).keys().at(0); QCOMPARE(key.type(), KContacts::Key::PGP); QCOMPARE(key.textData(), QStringLiteral("https://foo.org/sherlock-holmes.pub.asc")); } void KeyTest::shouldParseVcard4() { QByteArray vcarddata("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" "KEY;MEDIATYPE=application/pgp-keys:https://foo.org/sherlock-holmes.pub.asc\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QVERIFY(!lst.at(0).keys().isEmpty()); QCOMPARE(lst.at(0).keys().count(), 1); KContacts::Key key = lst.at(0).keys().at(0); QCOMPARE(key.type(), KContacts::Key::PGP); QCOMPARE(key.textData(), QStringLiteral("https://foo.org/sherlock-holmes.pub.asc")); } diff --git a/autotests/langtest.cpp b/autotests/langtest.cpp index 2dafd040..6e75fee2 100644 --- a/autotests/langtest.cpp +++ b/autotests/langtest.cpp @@ -1,240 +1,240 @@ /* This file is part of the KContacts framework. Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "langtest.h" #include "lang.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include LangTest::LangTest(QObject *parent) : QObject(parent) { } LangTest::~LangTest() { } void LangTest::shouldHaveDefaultValue() { KContacts::Lang language; QVERIFY(!language.isValid()); QVERIFY(language.language().isEmpty()); QVERIFY(language.parameters().isEmpty()); } void LangTest::shouldAssignValue() { const QString lang(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::Lang language(lang); language.setParameters(params); QVERIFY(language.isValid()); QVERIFY(!language.language().isEmpty()); QCOMPARE(language.language(), lang); QVERIFY(!language.parameters().isEmpty()); QCOMPARE(language.parameters(), params); } void LangTest::shouldAssignExternal() { KContacts::Lang language; const QString lang(QStringLiteral("fr")); language.setLanguage(lang); QVERIFY(language.isValid()); QCOMPARE(language.language(), lang); } void LangTest::shouldSerialized() { KContacts::Lang language; KContacts::Lang result; const QString lang(QStringLiteral("fr")); language.setLanguage(lang); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); language.setParameters(params); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << language; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(language == result); } void LangTest::shouldEqualLanguage() { KContacts::Lang language; KContacts::Lang result; const QString lang(QStringLiteral("fr")); language.setLanguage(lang); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); language.setParameters(params); result = language; QVERIFY(language == result); } void LangTest::shouldParseLanguage() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "LANG:fr\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).langs().count(), 1); QCOMPARE(lst.at(0).langs().at(0).language(), QStringLiteral("fr")); } void LangTest::shouldParseWithoutLanguage() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).langs().count(), 0); } void LangTest::shouldCreateVCard() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Lang::List lstLang; KContacts::Lang lang(QStringLiteral("fr")); lstLang << lang; addr.setLangs(lstLang); 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" "EMAIL:foo@kde.org\r\n" "LANG:fr\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void LangTest::shouldCreateVCardWithTwoLang() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Lang::List lstLang; KContacts::Lang lang(QStringLiteral("fr")); KContacts::Lang lang2(QStringLiteral("fr2")); lstLang << lang << lang2; addr.setLangs(lstLang); 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" "EMAIL:foo@kde.org\r\n" "LANG:fr\r\n" "LANG:fr2\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void LangTest::shouldCreateVCardWithParameters() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Lang::List lstLang; KContacts::Lang lang(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); lang.setParameters(params); lstLang << lang; addr.setLangs(lstLang); 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" "EMAIL:foo@kde.org\r\n" "LANG;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void LangTest::shouldNotGenerateLangForVCard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Lang::List lstLang; KContacts::Lang lang(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); lang.setParameters(params); lstLang << lang; addr.setLangs(lstLang); 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:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(LangTest) diff --git a/autotests/nicknametest.cpp b/autotests/nicknametest.cpp index ab227c34..3a30519c 100644 --- a/autotests/nicknametest.cpp +++ b/autotests/nicknametest.cpp @@ -1,243 +1,243 @@ /* This file is part of the KContacts framework. Copyright (C) 2016-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "nicknametest.h" #include "nickname.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include NickNameTest::NickNameTest(QObject *parent) : QObject(parent) { } NickNameTest::~NickNameTest() { } void NickNameTest::shouldHaveDefaultValue() { KContacts::NickName nickname; QVERIFY(!nickname.isValid()); QVERIFY(nickname.nickname().isEmpty()); QVERIFY(nickname.parameters().isEmpty()); } void NickNameTest::shouldAssignValue() { const QString lang(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::NickName nickname(lang); nickname.setParameters(params); QVERIFY(nickname.isValid()); QVERIFY(!nickname.nickname().isEmpty()); QCOMPARE(nickname.nickname(), lang); QVERIFY(!nickname.parameters().isEmpty()); QCOMPARE(nickname.parameters(), params); } void NickNameTest::shouldAssignExternal() { KContacts::NickName nickname; const QString lang(QStringLiteral("fr")); nickname.setNickName(lang); QVERIFY(nickname.isValid()); QCOMPARE(nickname.nickname(), lang); } void NickNameTest::shouldSerialized() { KContacts::NickName nickname; KContacts::NickName result; const QString lang(QStringLiteral("fr")); nickname.setNickName(lang); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); nickname.setParameters(params); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << nickname; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(nickname == result); } void NickNameTest::shouldEqualNickName() { KContacts::NickName nickname; KContacts::NickName result; const QString lang(QStringLiteral("fr")); nickname.setNickName(lang); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); nickname.setParameters(params); result = nickname; QVERIFY(nickname == result); } void NickNameTest::shouldParseNickName() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "NickName:boo\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).extraNickNameList().count(), 1); QCOMPARE(lst.at(0).extraNickNameList().at(0).nickname(), QStringLiteral("boo")); QCOMPARE(lst.at(0).nickName(), QStringLiteral("boo")); } void NickNameTest::shouldParseWithoutNickName() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).extraNickNameList().count(), 0); QCOMPARE(lst.at(0).nickName(), QString()); } void NickNameTest::shouldCreateVCard() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::NickName::List lstNickName; KContacts::NickName title(QStringLiteral("blo")); lstNickName << title; addr.setExtraNickNameList(lstNickName); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "NICKNAME:blo\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void NickNameTest::shouldCreateVCardWithTwoNickName() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::NickName::List lstNickName; KContacts::NickName title(QStringLiteral("fr")); KContacts::NickName title2(QStringLiteral("fr2")); lstNickName << title << title2; addr.setExtraNickNameList(lstNickName); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "NICKNAME:fr\r\n" "NICKNAME:fr2\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void NickNameTest::shouldCreateVCardWithParameters() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::NickName::List lstNickName; KContacts::NickName title(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); title.setParameters(params); lstNickName << title; addr.setExtraNickNameList(lstNickName); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "NICKNAME;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void NickNameTest::shouldGenerateNickNameForVCard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::NickName::List lstNickName; KContacts::NickName title(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); title.setParameters(params); lstNickName << title; addr.setExtraNickNameList(lstNickName); 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:foo@kde.org\r\n" "N:;;;;\r\n" "NICKNAME;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(NickNameTest) diff --git a/autotests/orgtest.cpp b/autotests/orgtest.cpp index 38d0ddf4..572d25b7 100644 --- a/autotests/orgtest.cpp +++ b/autotests/orgtest.cpp @@ -1,286 +1,286 @@ /* This file is part of the KContacts framework. Copyright (C) 2016-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "orgtest.h" #include "org.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include OrgTest::OrgTest(QObject *parent) : QObject(parent) { } OrgTest::~OrgTest() { } void OrgTest::shouldHaveDefaultValue() { KContacts::Org org; QVERIFY(!org.isValid()); QVERIFY(org.organization().isEmpty()); QVERIFY(org.parameters().isEmpty()); } void OrgTest::shouldAssignValue() { const QString organization(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::Org org(organization); org.setParameters(params); QVERIFY(org.isValid()); QVERIFY(!org.organization().isEmpty()); QCOMPARE(org.organization(), organization); QVERIFY(!org.parameters().isEmpty()); QCOMPARE(org.parameters(), params); } void OrgTest::shouldAssignExternal() { KContacts::Org org; const QString organization(QStringLiteral("fr")); org.setOrganization(organization); QVERIFY(org.isValid()); QCOMPARE(org.organization(), organization); } void OrgTest::shouldSerialized() { KContacts::Org org; KContacts::Org result; const QString organization(QStringLiteral("fr")); org.setOrganization(organization); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); org.setParameters(params); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << org; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(org == result); } void OrgTest::shouldEqualOrg() { KContacts::Org org; KContacts::Org result; const QString organization(QStringLiteral("fr")); org.setOrganization(organization); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); org.setParameters(params); result = org; QVERIFY(org == result); } void OrgTest::shouldParseOrg() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "Org:boo\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).extraOrganizationList().count(), 1); QCOMPARE(lst.at(0).organization(), QStringLiteral("boo")); QCOMPARE(lst.at(0).extraOrganizationList().at(0).organization(), QStringLiteral("boo")); } void OrgTest::shouldParseVcardWithTwoOrg() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "Org:boo\n" "Org:bla\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).extraOrganizationList().count(), 2); QCOMPARE(lst.at(0).extraOrganizationList().at(0).organization(), QStringLiteral("boo")); QCOMPARE(lst.at(0).extraOrganizationList().at(1).organization(), QStringLiteral("bla")); } void OrgTest::shouldCreateVCardWithSemiColon() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Org::List lstOrg; KContacts::Org org(QStringLiteral("fr;bla")); lstOrg << org; addr.setExtraOrganizationList(lstOrg); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "ORG:fr\\\\;bla\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void OrgTest::shouldParseWithoutOrg() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).extraOrganizationList().count(), 0); } void OrgTest::shouldCreateVCard() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Org::List lstOrg; KContacts::Org org(QStringLiteral("fr")); lstOrg << org; addr.setExtraOrganizationList(lstOrg); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "ORG:fr\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void OrgTest::shouldCreateVCardWithTwoOrg() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Org::List lstOrg; KContacts::Org org(QStringLiteral("fr")); KContacts::Org org2(QStringLiteral("fr2")); lstOrg << org << org2; addr.setExtraOrganizationList(lstOrg); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "ORG:fr\r\n" "ORG:fr2\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void OrgTest::shouldCreateVCardWithParameters() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Org::List lstOrg; KContacts::Org org(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); org.setParameters(params); lstOrg << org; addr.setExtraOrganizationList(lstOrg); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "ORG;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void OrgTest::shouldGenerateOrgForVCard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Org::List lstOrg; KContacts::Org org(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); org.setParameters(params); lstOrg << org; addr.setExtraOrganizationList(lstOrg); 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:foo@kde.org\r\n" "N:;;;;\r\n" "ORG;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(OrgTest) diff --git a/autotests/phonenumbertest.cpp b/autotests/phonenumbertest.cpp index 5c27eeea..2eff40e3 100644 --- a/autotests/phonenumbertest.cpp +++ b/autotests/phonenumbertest.cpp @@ -1,328 +1,328 @@ /* This file is part of the KContacts framework. Copyright (c) 2007 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "phonenumbertest.h" #include "kcontacts/phonenumber.h" #include #include #include -#include +#include QTEST_MAIN(PhoneNumberTest) #ifndef Q_OS_WIN void initLocale() { qputenv("LC_ALL", "en_US.utf-8"); } Q_CONSTRUCTOR_FUNCTION(initLocale) #endif void PhoneNumberTest::emptyTest() { KContacts::PhoneNumber number; QVERIFY(number.isEmpty()); } void PhoneNumberTest::storeTest() { KContacts::PhoneNumber number; number.setId(QStringLiteral("My Id")); number.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number.setNumber(QStringLiteral("2734826345")); QVERIFY(number.id() == QLatin1String("My Id")); QVERIFY(number.type() == (KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell)); QVERIFY(number.number() == QLatin1String("2734826345")); } void PhoneNumberTest::equalsTest() { KContacts::PhoneNumber number1, number2; number1.setId(QStringLiteral("My Id")); number1.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number1.setNumber(QStringLiteral("2734826345")); number2.setId(QStringLiteral("My Id")); number2.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number2.setNumber(QStringLiteral("2734826345")); QVERIFY(number1 == number2); } void PhoneNumberTest::differsTest() { KContacts::PhoneNumber number1(QStringLiteral("123"), KContacts::PhoneNumber::Home); KContacts::PhoneNumber number2(QStringLiteral("123"), KContacts::PhoneNumber::Work); QVERIFY(number1 != number2); } void PhoneNumberTest::assignmentTest() { KContacts::PhoneNumber number1, number2; number1.setId(QStringLiteral("My Id")); number1.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number1.setNumber(QStringLiteral("2734826345")); number1 = number2; QVERIFY(number1 == number2); } void PhoneNumberTest::serializeTest() { KContacts::PhoneNumber number1, number2; number1.setId(QStringLiteral("My Id")); number1.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number1.setNumber(QStringLiteral("2734826345")); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << number1; QDataStream t(&data, QIODevice::ReadOnly); t >> number2; QVERIFY(number1 == number2); } void PhoneNumberTest::labelTest() { QMap labels; const KContacts::PhoneNumber::TypeList types = KContacts::PhoneNumber::typeList(); // check all types standalone for (KContacts::PhoneNumber::Type type : types) { const KContacts::PhoneNumber phone(QStringLiteral("1"), type); QCOMPARE(phone.type(), type); // Pref is special cased if (type != KContacts::PhoneNumber::Pref) { QCOMPARE(phone.typeLabel(), KContacts::PhoneNumber::typeFlagLabel((KContacts::PhoneNumber::TypeFlag)(int)type)); labels.insert(type, phone.typeLabel()); } else { labels.insert(type, KContacts::PhoneNumber::typeFlagLabel((KContacts::PhoneNumber::TypeFlag)(int)type)); } QCOMPARE(KContacts::PhoneNumber::typeLabel(type), phone.typeLabel()); } // combine all with Pref for (KContacts::PhoneNumber::Type type : qAsConst(types)) { KContacts::PhoneNumber::Type combinedType = type | KContacts::PhoneNumber::Pref; const KContacts::PhoneNumber phone(QLatin1String("1"), combinedType); QCOMPARE(phone.type(), combinedType); QCOMPARE(KContacts::PhoneNumber::typeLabel(combinedType), phone.typeLabel()); if (type < KContacts::PhoneNumber::Pref) { const QString expectedCombinedString = QStringLiteral("%1/%2").arg(labels[type]).arg(labels[KContacts::PhoneNumber::Pref]); QCOMPARE(phone.typeLabel(), expectedCombinedString); } else if (type > KContacts::PhoneNumber::Pref) { const QString expectedCombinedString = QStringLiteral("%1/%2").arg(labels[KContacts::PhoneNumber::Pref]).arg(labels[type]); QCOMPARE(phone.typeLabel(), expectedCombinedString); } } // combine all with Fax for (KContacts::PhoneNumber::Type type : qAsConst(types)) { KContacts::PhoneNumber::Type combinedType = type | KContacts::PhoneNumber::Fax; const KContacts::PhoneNumber phone(QLatin1String("1"), combinedType); QCOMPARE(phone.type(), combinedType); QCOMPARE(KContacts::PhoneNumber::typeLabel(combinedType), phone.typeLabel()); if (type == KContacts::PhoneNumber::Home || type == KContacts::PhoneNumber::Work) { // special cased } else if (type < KContacts::PhoneNumber::Fax) { const QString expectedCombinedString = QStringLiteral("%1/%2").arg(labels[type]).arg(labels[KContacts::PhoneNumber::Fax]); QCOMPARE(phone.typeLabel(), expectedCombinedString); } else if (type > KContacts::PhoneNumber::Fax) { const QString expectedCombinedString = QStringLiteral("%1/%2").arg(labels[KContacts::PhoneNumber::Fax]).arg(labels[type]); QCOMPARE(phone.typeLabel(), expectedCombinedString); } } // special cases QCOMPARE(KContacts::PhoneNumber::typeLabel(KContacts::PhoneNumber::Pref), QLatin1String("Preferred Number")); QCOMPARE(KContacts::PhoneNumber::typeLabel(KContacts::PhoneNumber::Home |KContacts::PhoneNumber::Fax), QLatin1String("Home Fax")); QCOMPARE(KContacts::PhoneNumber::typeLabel(KContacts::PhoneNumber::Work |KContacts::PhoneNumber::Fax), QLatin1String("Work Fax")); QCOMPARE(KContacts::PhoneNumber::typeLabel(KContacts::PhoneNumber::Home |KContacts::PhoneNumber::Fax |KContacts::PhoneNumber::Pref), QLatin1String("Home Fax/Preferred")); QCOMPARE(KContacts::PhoneNumber::typeLabel(KContacts::PhoneNumber::Work |KContacts::PhoneNumber::Fax |KContacts::PhoneNumber::Pref), QLatin1String("Work Fax/Preferred")); } void PhoneNumberTest::shouldParseVCard21() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:2.1\n" "EMAIL:foo@kde.org\n" "N:;;;;\n" "TEL;CELL;WORK:+1-919-676-9564\n" "UID:testuid\n" "END:VCARD\n" "\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); KContacts::Addressee addr = lst.at(0); QCOMPARE(addr.phoneNumbers().count(), 1); KContacts::PhoneNumber number1 = addr.phoneNumbers().at(0); //QCOMPARE(number1.number(), QString()); } void PhoneNumberTest::shouldExportVCard21() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::PhoneNumber number1; number1.setId(QStringLiteral("My Id")); number1.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number1.setNumber(QStringLiteral("+1-919-676-9564")); addr.setPhoneNumbers(KContacts::PhoneNumber::List() << number1); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v2_1); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:2.1\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "TEL;CELL;WORK:+1-919-676-9564\r\n" "UID:testuid\r\n" "END:VCARD\r\n" "\r\n"); QCOMPARE(ba, expected); } void PhoneNumberTest::shouldExportVCard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::PhoneNumber number1; number1.setId(QStringLiteral("My Id")); number1.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number1.setNumber(QStringLiteral("+1-919-676-9564")); addr.setPhoneNumbers(KContacts::PhoneNumber::List() << number1); 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:foo@kde.org\r\n" "N:;;;;\r\n" "TEL;TYPE=CELL,WORK:+1-919-676-9564\r\n" "UID:testuid\r\n" "END:VCARD\r\n" "\r\n"); QCOMPARE(ba, expected); } void PhoneNumberTest::shouldExportVCard4() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::PhoneNumber number1; number1.setId(QStringLiteral("My Id")); number1.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number1.setNumber(QStringLiteral("+1-919-676-9564")); addr.setPhoneNumbers(KContacts::PhoneNumber::List() << number1); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "TEL;TYPE=\"cell,work\":+1-919-676-9564\r\n" "UID:testuid\r\n" "END:VCARD\r\n" "\r\n"); QCOMPARE(ba, expected); } void PhoneNumberTest::shouldParseVcard3() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "TEL;VALUE=uri;PREF=1;TYPE=\"voice,home\":tel:+44-555-555-5555;ext=5555\r\n" "TEL;VALUE=uri;TYPE=\"voice,cell,text\":tel:+44-555-555-6666\r\n" "TEL;VALUE=uri;TYPE=\"voice,work\":tel:+44-555-555-7777\r\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "LANG:fr\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); KContacts::Addressee addr = lst.at(0); QCOMPARE(addr.phoneNumbers().count(), 3); } void PhoneNumberTest::shouldParseVcard4() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:4.0\n" "N:LastName;FirstName;;;\n" "TEL;VALUE=uri;PREF=1;TYPE=\"voice,home\":tel:+44-555-555-5555;ext=5555\r\n" "TEL;VALUE=uri;TYPE=\"voice,cell,text\":tel:+44-555-555-6666\r\n" "TEL;VALUE=uri;TYPE=\"voice,work\":tel:+44-555-555-7777\r\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "LANG:fr\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); KContacts::Addressee addr = lst.at(0); QCOMPARE(addr.phoneNumbers().count(), 3); } diff --git a/autotests/relatedtest.cpp b/autotests/relatedtest.cpp index fea9c1e1..fcb3ff19 100644 --- a/autotests/relatedtest.cpp +++ b/autotests/relatedtest.cpp @@ -1,262 +1,262 @@ /* This file is part of the KContacts framework. Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "relatedtest.h" #include "related.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include RelatedTest::RelatedTest(QObject *parent) : QObject(parent) { } RelatedTest::~RelatedTest() { } void RelatedTest::shouldHaveDefaultValue() { KContacts::Related related; QVERIFY(!related.isValid()); QVERIFY(related.related().isEmpty()); QVERIFY(related.parameters().isEmpty()); } void RelatedTest::shouldAssignValue() { const QString relatedTo(QStringLiteral("friend")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::Related related(relatedTo); related.setParameters(params); QVERIFY(related.isValid()); QVERIFY(!related.related().isEmpty()); QCOMPARE(related.related(), relatedTo); QVERIFY(!related.parameters().isEmpty()); QCOMPARE(related.parameters(), params); } void RelatedTest::shouldAssignExternal() { KContacts::Related related; const QString relatedTo(QStringLiteral("friend")); related.setRelated(relatedTo); QVERIFY(related.isValid()); QCOMPARE(related.related(), relatedTo); } void RelatedTest::shouldSerialized() { KContacts::Related related; KContacts::Related result; const QString relatedTo(QStringLiteral("friend")); related.setRelated(relatedTo); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); related.setParameters(params); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << related; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(related == result); } void RelatedTest::shouldEqualRelated() { KContacts::Related related; KContacts::Related result; const QString relatedTo(QStringLiteral("friend")); related.setRelated(relatedTo); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); related.setParameters(params); result = related; QVERIFY(related == result); } void RelatedTest::shouldParseRelated() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:4.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "RELATED:friend\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).relationShips().count(), 1); const KContacts::Related related = lst.at(0).relationShips().at(0); QCOMPARE(related.related(), QStringLiteral("friend")); } void RelatedTest::shouldParseRelatedWithArgument() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:4.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "RELATED;FOO1=bla1,blo1;FOO2=bla2,blo2:friend\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).relationShips().count(), 1); const KContacts::Related related = lst.at(0).relationShips().at(0); QCOMPARE(related.related(), QStringLiteral("friend")); QCOMPARE(related.parameters().count(), 2); } void RelatedTest::shouldParseWithoutRelated() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).relationShips().count(), 0); } void RelatedTest::shouldCreateVCard4() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Related::List lstRelated; KContacts::Related related(QStringLiteral("friend")); lstRelated << related; addr.setRelationShips(lstRelated); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "RELATED:friend\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void RelatedTest::shouldCreateVCardWithTwoRelated() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Related::List lstRelated; KContacts::Related related(QStringLiteral("friend")); KContacts::Related related2(QStringLiteral("kde")); lstRelated << related << related2; addr.setRelationShips(lstRelated); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "RELATED:friend\r\n" "RELATED:kde\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void RelatedTest::shouldCreateVCardWithParameters() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Related::List lstRelated; KContacts::Related related(QStringLiteral("friend")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); related.setParameters(params); lstRelated << related; addr.setRelationShips(lstRelated); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "RELATED;FOO1=bla1,blo1;FOO2=bla2,blo2:friend\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void RelatedTest::shouldNotExportInVcard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Related::List lstRelated; KContacts::Related related(QStringLiteral("friend")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); related.setParameters(params); lstRelated << related; addr.setRelationShips(lstRelated); 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:foo@kde.org\r\n" "N:;;;;\r\n" "RELATED;FOO1=bla1,blo1;FOO2=bla2,blo2:friend\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(RelatedTest) diff --git a/autotests/resourcelocatorurltest.cpp b/autotests/resourcelocatorurltest.cpp index ff8b7013..587dd71f 100644 --- a/autotests/resourcelocatorurltest.cpp +++ b/autotests/resourcelocatorurltest.cpp @@ -1,225 +1,225 @@ /* This file is part of the KContacts framework. Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "resourcelocatorurltest.h" #include "resourcelocatorurl.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include using namespace KContacts; ResourceLocatorUrlTest::ResourceLocatorUrlTest(QObject *parent) : QObject(parent) { } ResourceLocatorUrlTest::~ResourceLocatorUrlTest() { } void ResourceLocatorUrlTest::shouldHaveDefaultValue() { ResourceLocatorUrl ResourceLocatorUrl; QVERIFY(!ResourceLocatorUrl.isValid()); QVERIFY(ResourceLocatorUrl.url().isEmpty()); QVERIFY(ResourceLocatorUrl.parameters().isEmpty()); } void ResourceLocatorUrlTest::shouldAssignValue() { QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); ResourceLocatorUrl ResourceLocatorUrl; ResourceLocatorUrl.setParameters(params); QVERIFY(!ResourceLocatorUrl.isValid()); QVERIFY(ResourceLocatorUrl.url().isEmpty()); QVERIFY(!ResourceLocatorUrl.parameters().isEmpty()); QCOMPARE(ResourceLocatorUrl.parameters(), params); } void ResourceLocatorUrlTest::shouldAssignExternal() { ResourceLocatorUrl resourcelocatorurl; QUrl url = QUrl(QStringLiteral("https://www.kde.org")); resourcelocatorurl.setUrl(url); QVERIFY(!resourcelocatorurl.url().isEmpty()); QCOMPARE(resourcelocatorurl.url(), url); } void ResourceLocatorUrlTest::shouldSerialized() { ResourceLocatorUrl resourcelocatorurl; ResourceLocatorUrl result; QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); resourcelocatorurl.setParameters(params); resourcelocatorurl.setUrl(QUrl(QStringLiteral("mailto:foo@kde.org"))); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << resourcelocatorurl; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(resourcelocatorurl == result); } void ResourceLocatorUrlTest::shouldEqualResourceLocatorUrl() { ResourceLocatorUrl resourcelocatorurl; ResourceLocatorUrl result; QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); resourcelocatorurl.setUrl(QUrl(QStringLiteral("mailto:foo@kde.org"))); resourcelocatorurl.setParameters(params); result = resourcelocatorurl; QVERIFY(resourcelocatorurl == result); } void ResourceLocatorUrlTest::shouldParseResourceLocatorUrl() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "URL;PREF=1:https://firsturl\n" "URL;PREF=1:https://sherlockholmes.com/calendar/sherlockholmes\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).extraUrlList().count(), 2); const ResourceLocatorUrl calurl = lst.at(0).extraUrlList().at(0); QCOMPARE(calurl.url(), QUrl(QStringLiteral("https://firsturl"))); QVERIFY(!calurl.parameters().isEmpty()); } void ResourceLocatorUrlTest::shouldGenerateVCard4() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::ResourceLocatorUrl webpage; webpage.setUrl(QUrl(QStringLiteral("https://www.kde.org"))); addr.setUrl(webpage); ResourceLocatorUrl url; url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes"))); addr.insertExtraUrl(url); url.setUrl(QUrl(QStringLiteral("https://foo.kde.org"))); addr.insertExtraUrl(url); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected; expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "URL:https://www.kde.org\r\n" "URL:https://sherlockholmes.com/calendar/sherlockholmes\r\n" "URL:https://foo.kde.org\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void ResourceLocatorUrlTest::shouldGenerateVCardWithParameter() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::ResourceLocatorUrl webpage; webpage.setUrl(QUrl(QStringLiteral("https://www.kde.org"))); addr.setUrl(webpage); ResourceLocatorUrl url; url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes"))); QMap params; params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); url.setParameters(params); addr.insertExtraUrl(url); url.setUrl(QUrl(QStringLiteral("https://foo.kde.org"))); QMap params2; url.setParameters(params2); addr.insertExtraUrl(url); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected; expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "URL:https://www.kde.org\r\n" "URL;FOO2=bla2,blo2:https://sherlockholmes.com/calendar/sherlockholmes\r\n" "URL:https://foo.kde.org\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void ResourceLocatorUrlTest::shouldGenerateVCard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::ResourceLocatorUrl webpage; webpage.setUrl(QUrl(QStringLiteral("https://www.kde.org"))); addr.setUrl(webpage); ResourceLocatorUrl url; url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes"))); QMap params; params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); url.setParameters(params); addr.insertExtraUrl(url); url.setUrl(QUrl(QStringLiteral("https://foo.kde.org"))); QMap params2; url.setParameters(params2); addr.insertExtraUrl(url); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); QByteArray expected; expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "URL:https://www.kde.org\r\n" "URL;FOO2=bla2,blo2:https://sherlockholmes.com/calendar/sherlockholmes\r\n" "URL:https://foo.kde.org\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(ResourceLocatorUrlTest) diff --git a/autotests/roletest.cpp b/autotests/roletest.cpp index 4a1d26f9..51af4a4c 100644 --- a/autotests/roletest.cpp +++ b/autotests/roletest.cpp @@ -1,243 +1,243 @@ /* This file is part of the KContacts framework. Copyright (C) 2016-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "roletest.h" #include "role.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include RoleTest::RoleTest(QObject *parent) : QObject(parent) { } RoleTest::~RoleTest() { } void RoleTest::shouldHaveDefaultValue() { KContacts::Role role; QVERIFY(!role.isValid()); QVERIFY(role.role().isEmpty()); QVERIFY(role.parameters().isEmpty()); } void RoleTest::shouldAssignValue() { const QString lang(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::Role role(lang); role.setParameters(params); QVERIFY(role.isValid()); QVERIFY(!role.role().isEmpty()); QCOMPARE(role.role(), lang); QVERIFY(!role.parameters().isEmpty()); QCOMPARE(role.parameters(), params); } void RoleTest::shouldAssignExternal() { KContacts::Role role; const QString lang(QStringLiteral("fr")); role.setRole(lang); QVERIFY(role.isValid()); QCOMPARE(role.role(), lang); } void RoleTest::shouldSerialized() { KContacts::Role role; KContacts::Role result; const QString lang(QStringLiteral("fr")); role.setRole(lang); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); role.setParameters(params); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << role; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(role == result); } void RoleTest::shouldEqualRole() { KContacts::Role role; KContacts::Role result; const QString lang(QStringLiteral("fr")); role.setRole(lang); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); role.setParameters(params); result = role; QVERIFY(role == result); } void RoleTest::shouldParseRole() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "Role:boo\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).extraRoleList().count(), 1); QCOMPARE(lst.at(0).role(), QStringLiteral("boo")); QCOMPARE(lst.at(0).extraRoleList().at(0).role(), QStringLiteral("boo")); } void RoleTest::shouldParseWithoutRole() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).extraRoleList().count(), 0); QCOMPARE(lst.at(0).role(), QString()); } void RoleTest::shouldCreateVCard() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Role::List lstRole; KContacts::Role role(QStringLiteral("fr")); lstRole << role; addr.setExtraRoleList(lstRole); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "ROLE:fr\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void RoleTest::shouldCreateVCardWithTwoRole() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Role::List lstRole; KContacts::Role role(QStringLiteral("fr")); KContacts::Role role2(QStringLiteral("fr2")); lstRole << role << role2; addr.setExtraRoleList(lstRole); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "ROLE:fr\r\n" "ROLE:fr2\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void RoleTest::shouldCreateVCardWithParameters() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Role::List lstRole; KContacts::Role role(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); role.setParameters(params); lstRole << role; addr.setExtraRoleList(lstRole); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "ROLE;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void RoleTest::shouldGenerateRoleForVCard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Role::List lstRole; KContacts::Role role(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); role.setParameters(params); lstRole << role; addr.setExtraRoleList(lstRole); 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:foo@kde.org\r\n" "N:;;;;\r\n" "ROLE;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(RoleTest) diff --git a/autotests/secrecytest.cpp b/autotests/secrecytest.cpp index 0ca03b48..be054ffc 100644 --- a/autotests/secrecytest.cpp +++ b/autotests/secrecytest.cpp @@ -1,86 +1,86 @@ /* This file is part of the KContacts framework. Copyright (c) 2007 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "secrecytest.h" #include "kcontacts/secrecy.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include QTEST_MAIN(SecrecyTest) void SecrecyTest::emptyTest() { KContacts::Secrecy secrecy; QVERIFY(secrecy.type() == KContacts::Secrecy::Invalid); } void SecrecyTest::storeTest() { KContacts::Secrecy secrecy; secrecy.setType(KContacts::Secrecy::Private); QVERIFY(secrecy.type() == KContacts::Secrecy::Private); } void SecrecyTest::equalsTest() { KContacts::Secrecy secrecy1, secrecy2; secrecy1.setType(KContacts::Secrecy::Confidential); secrecy2.setType(KContacts::Secrecy::Confidential); QVERIFY(secrecy1 == secrecy2); } void SecrecyTest::differsTest() { KContacts::Secrecy secrecy1(KContacts::Secrecy::Private); KContacts::Secrecy secrecy2(KContacts::Secrecy::Confidential); QVERIFY(secrecy1 != secrecy2); } void SecrecyTest::assignmentTest() { KContacts::Secrecy secrecy1, secrecy2; secrecy1.setType(KContacts::Secrecy::Confidential); secrecy1 = secrecy2; QVERIFY(secrecy1 == secrecy2); } void SecrecyTest::serializeTest() { KContacts::Secrecy secrecy1, secrecy2; secrecy1.setType(KContacts::Secrecy::Confidential); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << secrecy1; QDataStream t(&data, QIODevice::ReadOnly); t >> secrecy2; QVERIFY(secrecy1 == secrecy2); } diff --git a/autotests/soundtest.cpp b/autotests/soundtest.cpp index 2dbe0183..41fb06bb 100644 --- a/autotests/soundtest.cpp +++ b/autotests/soundtest.cpp @@ -1,262 +1,262 @@ /* This file is part of the KContacts framework. Copyright (c) 2007 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "soundtest.h" #include "kcontacts/sound.h" #include "addressee.h" #include -#include "vcardtool.h" +#include "vcardtool_p.h" QTEST_MAIN(SoundTest) static QByteArray testData() { static QByteArray data; if (data.isNull()) { for (int i = 0; i < 20; ++i) { data.append(char(i)); } } return data; } void SoundTest::emptyTest() { KContacts::Sound sound; QVERIFY(sound.isEmpty()); } void SoundTest::storeTestIntern() { KContacts::Sound sound; sound.setData(testData()); QVERIFY(sound.isIntern() == true); QVERIFY(sound.data() == testData()); } void SoundTest::storeTestExtern() { KContacts::Sound sound; sound.setUrl(QLatin1String("http://myhomepage.com/sound.wav")); QVERIFY(sound.isIntern() == false); QVERIFY(sound.url() == QLatin1String("http://myhomepage.com/sound.wav")); } void SoundTest::equalsTestIntern() { KContacts::Sound sound1, sound2; sound1.setData(testData()); sound2.setData(testData()); QVERIFY(sound1 == sound2); } void SoundTest::equalsTestExtern() { KContacts::Sound sound1, sound2; sound1.setUrl(QStringLiteral("http://myhomepage.com/sound.wav")); sound2.setUrl(QStringLiteral("http://myhomepage.com/sound.wav")); QVERIFY(sound1 == sound2); } void SoundTest::differsTest() { KContacts::Sound sound1, sound2; sound1.setUrl(QStringLiteral("http://myhomepage.com/sound.wav")); sound2.setData(testData()); QVERIFY(sound1 != sound2); } void SoundTest::assignmentTestIntern() { KContacts::Sound sound1, sound2; sound1.setData(testData()); sound2 = sound1; QVERIFY(sound1 == sound2); } void SoundTest::assignmentTestExtern() { KContacts::Sound sound1, sound2; sound1.setUrl(QStringLiteral("http://myhomepage.com/sound.wav")); sound2 = sound1; QVERIFY(sound1 == sound2); } void SoundTest::serializeTest() { KContacts::Sound sound1, sound2; sound1.setUrl(QStringLiteral("http://myhomepage.com/sound.wav")); sound1.setData(testData()); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << sound1; QDataStream t(&data, QIODevice::ReadOnly); t >> sound2; QVERIFY(sound1 == sound2); } void SoundTest::shouldParseSource() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "SOUND;VALUE=URI:http://myhomepage.com/sound.wav\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QVERIFY(!lst.at(0).sound().isEmpty()); KContacts::Sound sound = lst.at(0).sound(); QVERIFY(!sound.isIntern()); QCOMPARE(sound.url(), QStringLiteral("http://myhomepage.com/sound.wav")); } void SoundTest::shouldGenerateVCard4WithData() { KContacts::Addressee::List lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Sound sound1; sound1.setUrl(QStringLiteral("http://myhomepage.com/sound.wav")); sound1.setData(testData()); addr.setSound(sound1); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected; expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "SOUND;ENCODING=b:AAECAwQFBgcICQoLDA0ODxAREhM=\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void SoundTest::shouldGenerateVCard4WithUrl() { KContacts::Addressee::List lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Sound sound1; sound1.setUrl(QStringLiteral("http://myhomepage.com/sound.wav")); addr.setSound(sound1); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected; expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "SOUND;VALUE=URI:http://myhomepage.com/sound.wav\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void SoundTest::shouldGenerateVCard3WithData() { KContacts::Addressee::List lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Sound sound1; sound1.setUrl(QStringLiteral("http://myhomepage.com/sound.wav")); sound1.setData(testData()); addr.setSound(sound1); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); QByteArray expected; expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "SOUND;ENCODING=b:AAECAwQFBgcICQoLDA0ODxAREhM=\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void SoundTest::shouldGenerateVCard3WithUrl() { KContacts::Addressee::List lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Sound sound1; sound1.setUrl(QStringLiteral("http://myhomepage.com/sound.wav")); addr.setSound(sound1); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); QByteArray expected; expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "SOUND;VALUE=URI:http://myhomepage.com/sound.wav\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } diff --git a/autotests/timezonetest.cpp b/autotests/timezonetest.cpp index 5fb046c0..e26d60e9 100644 --- a/autotests/timezonetest.cpp +++ b/autotests/timezonetest.cpp @@ -1,137 +1,137 @@ /* This file is part of the KContacts framework. Copyright (c) 2007 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "timezonetest.h" #include "kcontacts/timezone.h" #include -#include "vcardtool.h" +#include "vcardtool_p.h" QTEST_MAIN(TimeZoneTest) void TimeZoneTest::emptyTest() { KContacts::TimeZone timezone; QVERIFY(timezone.isValid() == false); } void TimeZoneTest::storeTest() { KContacts::TimeZone timezone; timezone.setOffset(2); QVERIFY(timezone.offset() == 2); } void TimeZoneTest::equalsTest() { KContacts::TimeZone timezone1, timezone2; timezone1.setOffset(2); timezone2.setOffset(2); QVERIFY(timezone1 == timezone2); } void TimeZoneTest::differsTest() { KContacts::TimeZone timezone1(2); KContacts::TimeZone timezone2(3); QVERIFY(timezone1 != timezone2); QVERIFY(timezone1 != KContacts::TimeZone()); } void TimeZoneTest::assignmentTest() { KContacts::TimeZone timezone1, timezone2; timezone1.setOffset(2); timezone1 = timezone2; QVERIFY(timezone1 == timezone2); } void TimeZoneTest::serializeTest() { KContacts::TimeZone timezone1, timezone2; timezone1.setOffset(2); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << timezone1; QDataStream t(&data, QIODevice::ReadOnly); t >> timezone2; QVERIFY(timezone1 == timezone2); } void TimeZoneTest::shouldGenerateVCard3() { KContacts::Addressee::List lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::TimeZone timezone; timezone.setOffset(2); addr.setTimeZone(timezone); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); QByteArray expected; expected = QByteArray("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "TZ:+00:02\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void TimeZoneTest::shouldGenerateVCard4() { //TODO fixme. KContacts::Addressee::List lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::TimeZone timezone; timezone.setOffset(2); addr.setTimeZone(timezone); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); const QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "TZ:+00:02\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } diff --git a/autotests/titletest.cpp b/autotests/titletest.cpp index 365b85bf..9cf3b7b7 100644 --- a/autotests/titletest.cpp +++ b/autotests/titletest.cpp @@ -1,264 +1,264 @@ /* This file is part of the KContacts framework. Copyright (C) 2016-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "titletest.h" #include "title.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include TitleTest::TitleTest(QObject *parent) : QObject(parent) { } TitleTest::~TitleTest() { } void TitleTest::shouldHaveDefaultValue() { KContacts::Title title; QVERIFY(!title.isValid()); QVERIFY(title.title().isEmpty()); QVERIFY(title.parameters().isEmpty()); } void TitleTest::shouldAssignValue() { const QString lang(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); KContacts::Title title(lang); title.setParameters(params); QVERIFY(title.isValid()); QVERIFY(!title.title().isEmpty()); QCOMPARE(title.title(), lang); QVERIFY(!title.parameters().isEmpty()); QCOMPARE(title.parameters(), params); } void TitleTest::shouldAssignExternal() { KContacts::Title title; const QString lang(QStringLiteral("fr")); title.setTitle(lang); QVERIFY(title.isValid()); QCOMPARE(title.title(), lang); } void TitleTest::shouldSerialized() { KContacts::Title title; KContacts::Title result; const QString lang(QStringLiteral("fr")); title.setTitle(lang); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); title.setParameters(params); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << title; QDataStream t(&data, QIODevice::ReadOnly); t >> result; QVERIFY(title == result); } void TitleTest::shouldEqualTitle() { KContacts::Title title; KContacts::Title result; const QString lang(QStringLiteral("fr")); title.setTitle(lang); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); title.setParameters(params); result = title; QVERIFY(title == result); } void TitleTest::shouldParseTwoTitles() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "Title:boo\n" "Title:bla\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).extraTitleList().count(), 2); QCOMPARE(lst.at(0).title(), QStringLiteral("boo")); QCOMPARE(lst.at(0).extraTitleList().at(0).title(), QStringLiteral("boo")); QCOMPARE(lst.at(0).extraTitleList().at(1).title(), QStringLiteral("bla")); } void TitleTest::shouldParseTitle() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "Title:boo\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).extraTitleList().count(), 1); QCOMPARE(lst.at(0).title(), QStringLiteral("boo")); QCOMPARE(lst.at(0).extraTitleList().at(0).title(), QStringLiteral("boo")); } void TitleTest::shouldParseWithoutTitle() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); QCOMPARE(lst.at(0).extraTitleList().count(), 0); QCOMPARE(lst.at(0).title(), QString()); } void TitleTest::shouldCreateVCard() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Title::List lstTitle; KContacts::Title title(QStringLiteral("fr")); lstTitle << title; addr.setExtraTitleList(lstTitle); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "TITLE:fr\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void TitleTest::shouldCreateVCardWithTwoTitle() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Title::List lstTitle; KContacts::Title title(QStringLiteral("fr")); KContacts::Title title2(QStringLiteral("fr2")); lstTitle << title << title2; addr.setExtraTitleList(lstTitle); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "TITLE:fr\r\n" "TITLE:fr2\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void TitleTest::shouldCreateVCardWithParameters() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Title::List lstTitle; KContacts::Title title(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); title.setParameters(params); lstTitle << title; addr.setExtraTitleList(lstTitle); 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" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "TITLE;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } void TitleTest::shouldGenerateTitleForVCard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Title::List lstTitle; KContacts::Title title(QStringLiteral("fr")); QMap params; params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1")); params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2")); title.setParameters(params); lstTitle << title; addr.setExtraTitleList(lstTitle); 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:foo@kde.org\r\n" "N:;;;;\r\n" "TITLE;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } QTEST_MAIN(TitleTest) diff --git a/autotests/vcardtool_benchmark.cpp b/autotests/vcardtool_benchmark.cpp index cf9da391..ee87f789 100644 --- a/autotests/vcardtool_benchmark.cpp +++ b/autotests/vcardtool_benchmark.cpp @@ -1,78 +1,78 @@ /* This file is part of the KContacts framework. Copyright (c) 2016 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "vcardtool_benchmark.h" #include "title.h" -#include "vcardtool.h" +#include "vcardtool_p.h" #include PerformanceTest::PerformanceTest(QObject *parent) : QObject(parent) { } PerformanceTest::~PerformanceTest() { } void PerformanceTest::testParserPerformance() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "Title:boo\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); QBENCHMARK { KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); } } void PerformanceTest::testExportPerformance() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::Title::List lstTitle; KContacts::Title title(QStringLiteral("fr")); lstTitle << title; addr.setExtraTitleList(lstTitle); lst << addr; QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "TITLE:fr\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); QBENCHMARK { KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QCOMPARE(ba, expected); } } QTEST_GUILESS_MAIN(PerformanceTest) diff --git a/src/converter/vcardconverter.cpp b/src/converter/vcardconverter.cpp index 8ad95543..b8628997 100644 --- a/src/converter/vcardconverter.cpp +++ b/src/converter/vcardconverter.cpp @@ -1,148 +1,148 @@ /* This file is part of the KContacts framework. Copyright (c) 2002 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "vcardconverter.h" -#include "vcardtool.h" +#include "vcardtool_p.h" using namespace KContacts; VCardConverter::VCardConverter() : d(nullptr) { } VCardConverter::~VCardConverter() { } QByteArray VCardConverter::exportVCard(const Addressee &addr, Version version) const { Addressee::List list; list.append(addr); return exportVCards(list, version); } QByteArray VCardConverter::exportVCards(const Addressee::List &list, Version version) const { VCardTool tool; QByteArray returnValue; switch (version) { case v2_1: returnValue = tool.exportVCards(list, VCard::v2_1); break; case v3_0: returnValue = tool.exportVCards(list, VCard::v3_0); break; case v4_0: returnValue = tool.exportVCards(list, VCard::v4_0); break; } return returnValue; } QByteArray VCardConverter::createVCard(const Addressee &addr, Version version) const { Addressee::List list; list.append(addr); return createVCards(list, version); } QByteArray VCardConverter::createVCards(const Addressee::List &list, Version version) const { VCardTool tool; QByteArray returnValue; switch (version) { case v2_1: returnValue = tool.createVCards(list, VCard::v2_1); break; case v3_0: returnValue = tool.createVCards(list, VCard::v3_0); break; case v4_0: returnValue = tool.createVCards(list, VCard::v4_0); break; } return returnValue; } Addressee VCardConverter::parseVCard(const QByteArray &vcard) const { Addressee::List list = parseVCards(vcard); return list.isEmpty() ? Addressee() : list[ 0 ]; } Addressee::List VCardConverter::parseVCards(const QByteArray &vcard) const { VCardTool tool; return tool.parseVCards(vcard); } /* Helper functions */ QString KContacts::dateToVCardString(const QDateTime &dateTime) { return dateTime.toString(QStringLiteral("yyyyMMddThhmmssZ")); } QString KContacts::dateToVCardString(QDate date) { return date.toString(QStringLiteral("yyyyMMdd")); } QDateTime KContacts::VCardStringToDate(const QString &dateString) { QDate date; QTime time; QString d(dateString); d = d.remove(QLatin1Char('-')).remove(QLatin1Char(':')); if (d.length() >= 8) { date = QDate(d.midRef(0, 4).toUInt(), d.midRef(4, 2).toUInt(), d.midRef(6, 2).toUInt()); } if (d.length() > 9 && d[ 8 ].toUpper() == QLatin1Char('T')) { time = QTime(d.midRef(9, 2).toUInt(), d.midRef(11, 2).toUInt(), d.midRef(13, 2).toUInt()); } return QDateTime(date, time); } void KContacts::adaptIMAttributes(QByteArray &data) { data.replace("X-messaging/aim-All", ("X-AIM")); data.replace("X-messaging/icq-All", ("X-ICQ")); data.replace("X-messaging/xmpp-All", ("X-JABBER")); data.replace("X-messaging/msn-All", ("X-MSN")); data.replace("X-messaging/yahoo-All", ("X-YAHOO")); data.replace("X-messaging/gadu-All", ("X-GADUGADU")); data.replace("X-messaging/skype-All", ("X-SKYPE")); data.replace("X-messaging/groupwise-All", ("X-GROUPWISE")); data.replace("X-messaging/sms-All", ("X-SMS")); data.replace("X-messaging/meanwhile-All", ("X-MEANWHILE")); data.replace("X-messaging/irc-All", ("X-IRC")); data.replace("X-messaging/googletalk-All", ("X-GTALK")); } diff --git a/src/vcardtool.cpp b/src/vcardtool.cpp index 6a109dcd..bbf33530 100644 --- a/src/vcardtool.cpp +++ b/src/vcardtool.cpp @@ -1,1617 +1,1617 @@ /* This file is part of the KContacts framework. Copyright (c) 2003 Tobias Koenig Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "vcardtool.h" +#include "vcardtool_p.h" #include "key.h" #include "picture.h" #include "secrecy.h" #include "sound.h" #include "lang.h" #include "gender.h" #include "related.h" #include "fieldgroup.h" #include "kcontacts_debug.h" #include #include #include #include using namespace KContacts; static bool needsEncoding(const QString &value) { int length = value.length(); for (int i = 0; i < length; ++i) { char c = value.at(i).toLatin1(); if ((c < 33 || c > 126) && c != ' ' && c != '=') { return true; } } return false; } static const struct { const char *addressType; Address::TypeFlag flag; } s_addressTypes[] = { { "dom", Address::Dom }, { "home", Address::Home }, { "intl", Address::Intl }, { "parcel", Address::Parcel }, { "postal", Address::Postal }, { "pref", Address::Pref }, { "work", Address::Work }, }; static const unsigned int s_numAddressTypes = sizeof s_addressTypes / sizeof *s_addressTypes; static Address::TypeFlag stringToAddressType(const QString &str) { for (unsigned int i = 0; i < s_numAddressTypes; ++i) { if (str == QLatin1String(s_addressTypes[i].addressType)) { return s_addressTypes[i].flag; } } return {}; } static const struct { const char *phoneType; PhoneNumber::TypeFlag flag; } s_phoneTypes[] = { { "BBS", PhoneNumber::Bbs }, { "CAR", PhoneNumber::Car }, { "CELL", PhoneNumber::Cell }, { "FAX", PhoneNumber::Fax }, { "HOME", PhoneNumber::Home }, { "ISDN", PhoneNumber::Isdn }, { "MODEM", PhoneNumber::Modem }, { "MSG", PhoneNumber::Msg }, { "PAGER", PhoneNumber::Pager }, { "PCS", PhoneNumber::Pcs }, { "PREF", PhoneNumber::Pref }, { "VIDEO", PhoneNumber::Video }, { "VOICE", PhoneNumber::Voice }, { "WORK", PhoneNumber::Work }, }; static const unsigned int s_numPhoneTypes = sizeof s_phoneTypes / sizeof *s_phoneTypes; static PhoneNumber::TypeFlag stringToPhoneType(const QString &str) { for (unsigned int i = 0; i < s_numPhoneTypes; ++i) { if (str == QLatin1String(s_phoneTypes[i].phoneType)) { return s_phoneTypes[i].flag; } } return {}; } VCardTool::VCardTool() { } VCardTool::~VCardTool() { } QByteArray VCardTool::exportVCards(const Addressee::List &list, VCard::Version version) const { return createVCards(list, version, true /*export vcard*/); } QByteArray VCardTool::createVCards(const Addressee::List &list, VCard::Version version) const { return createVCards(list, version, false /*don't export*/); } void VCardTool::addParameters(VCardLine &line, const QMap ¶ms) const { QMapIterator i(params); while (i.hasNext()) { i.next(); line.addParameter(i.key(), i.value().join(QLatin1Char(','))); } } void VCardTool::addParameter(VCardLine &line, VCard::Version version, const QString &key, const QStringList &valueStringList) const { if (version == VCard::v2_1) { for (const QString &valueStr : valueStringList) { line.addParameter(valueStr, QString()); } } else if (version == VCard::v3_0) { line.addParameter(key, valueStringList.join(QLatin1Char(','))); } else { if (valueStringList.count() < 2) { line.addParameter(key, valueStringList.join(QLatin1Char(','))); } else { line.addParameter(key, QLatin1Char('"') + valueStringList.join(QLatin1Char(',')) + QLatin1Char('"')); } } } QByteArray VCardTool::createVCards(const Addressee::List &list, VCard::Version version, bool exportVcard) const { VCard::List vCardList; Addressee::List::ConstIterator addrIt; Addressee::List::ConstIterator listEnd(list.constEnd()); for (addrIt = list.constBegin(); addrIt != listEnd; ++addrIt) { VCard card; QStringList::ConstIterator strIt; // VERSION if (version == VCard::v2_1) { card.addLine(VCardLine(QStringLiteral("VERSION"), QStringLiteral("2.1"))); } else if (version == VCard::v3_0) { card.addLine(VCardLine(QStringLiteral("VERSION"), QStringLiteral("3.0"))); } else if (version == VCard::v4_0) { card.addLine(VCardLine(QStringLiteral("VERSION"), QStringLiteral("4.0"))); } // ADR + LABEL const Address::List addresses = (*addrIt).addresses(); Address::List::ConstIterator end(addresses.end()); for (Address::List::ConstIterator it = addresses.begin(); it != end; ++it) { QStringList address; const bool isEmpty = ((*it).postOfficeBox().isEmpty() && (*it).extended().isEmpty() && (*it).street().isEmpty() && (*it).locality().isEmpty() && (*it).region().isEmpty() && (*it).postalCode().isEmpty() && (*it).country().isEmpty()); address.append((*it).postOfficeBox().replace(QLatin1Char(';'), QStringLiteral("\\;"))); address.append((*it).extended().replace(QLatin1Char(';'), QStringLiteral("\\;"))); address.append((*it).street().replace(QLatin1Char(';'), QStringLiteral("\\;"))); address.append((*it).locality().replace(QLatin1Char(';'), QStringLiteral("\\;"))); address.append((*it).region().replace(QLatin1Char(';'), QStringLiteral("\\;"))); address.append((*it).postalCode().replace(QLatin1Char(';'), QStringLiteral("\\;"))); address.append((*it).country().replace(QLatin1Char(';'), QStringLiteral("\\;"))); const QString addressJoined(address.join(QLatin1Char(';'))); VCardLine adrLine(QStringLiteral("ADR"), addressJoined); if (version == VCard::v2_1 && needsEncoding(addressJoined)) { adrLine.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8")); adrLine.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE")); } const bool hasLabel = !(*it).label().isEmpty(); QStringList addreLineType; QStringList labelLineType; for (unsigned int i = 0; i < s_numAddressTypes; ++i) { if (s_addressTypes[i].flag & (*it).type()) { const QString str = QString::fromLatin1(s_addressTypes[i].addressType); addreLineType << str; if (hasLabel) { labelLineType << str; } } } if (hasLabel) { if (version == VCard::v4_0) { if (!(*it).label().isEmpty()) { adrLine.addParameter(QStringLiteral("LABEL"), QStringLiteral("\"%1\"").arg((*it).label())); } } else { VCardLine labelLine(QStringLiteral("LABEL"), (*it).label()); if (version == VCard::v2_1 && needsEncoding((*it).label())) { labelLine.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8")); labelLine.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE")); } addParameter(labelLine, version, QStringLiteral("TYPE"), labelLineType); card.addLine(labelLine); } } if (version == VCard::v4_0) { Geo geo = (*it).geo(); if (geo.isValid()) { QString str; str.sprintf("\"geo:%.6f,%.6f\"", geo.latitude(), geo.longitude()); adrLine.addParameter(QStringLiteral("GEO"), str); } } if (!isEmpty) { addParameter(adrLine, version, QStringLiteral("TYPE"), addreLineType); card.addLine(adrLine); } } // BDAY const bool withTime = (*addrIt).birthdayHasTime(); const QString birthdayString = createDateTime((*addrIt).birthday(), version, withTime); card.addLine(VCardLine(QStringLiteral("BDAY"), birthdayString)); //Laurent: 31 Jan 2015. Not necessary to export it. When Categories were changes as AkonadiTag nobody thought that it was break categorie support... //=> not necessary to export just tag... // CATEGORIES only > 2.1 if (!exportVcard) { if (version != VCard::v2_1) { QStringList categories = (*addrIt).categories(); QStringList::Iterator catIt; QStringList::Iterator catEnd(categories.end()); for (catIt = categories.begin(); catIt != catEnd; ++catIt) { (*catIt).replace(QLatin1Char(','), QStringLiteral("\\,")); } VCardLine catLine(QStringLiteral("CATEGORIES"), categories.join(QLatin1Char(','))); card.addLine(catLine); } } // MEMBER (only in 4.0) if (version == VCard::v4_0) { // The KIND property must be set to "group" in order to use this property. if ((*addrIt).kind().toLower() == QLatin1String("group")) { const QStringList lst = (*addrIt).members(); for (const QString &member : lst) { VCardLine line(QStringLiteral("MEMBER"), member); card.addLine(line); } } } // SOURCE const QVector lstUrl = (*addrIt).sourcesUrlList(); for (const QUrl &url : lstUrl) { VCardLine line = VCardLine(QStringLiteral("SOURCE"), url.url()); card.addLine(line); } const Related::List relatedList = (*addrIt).relationShips(); Related::List::ConstIterator relatedIt; Related::List::ConstIterator relatedEnd(relatedList.end()); for (relatedIt = relatedList.begin(); relatedIt != relatedEnd; ++relatedIt) { VCardLine line(QStringLiteral("RELATED"), (*relatedIt).related()); addParameters(line, (*relatedIt).parameters()); card.addLine(line); } // CLASS only for version == 3.0 if (version == VCard::v3_0) { card.addLine(createSecrecy((*addrIt).secrecy())); } // LANG only for version == 4.0 if (version == VCard::v4_0) { const Lang::List langList = (*addrIt).langs(); Lang::List::ConstIterator langIt; Lang::List::ConstIterator langEnd(langList.end()); for (langIt = langList.begin(); langIt != langEnd; ++langIt) { VCardLine line(QStringLiteral("LANG"), (*langIt).language()); addParameters(line, (*langIt).parameters()); card.addLine(line); } } // CLIENTPIDMAP if (version == VCard::v4_0) { const ClientPidMap::List clientpidmapList = (*addrIt).clientPidMapList(); ClientPidMap::List::ConstIterator clientPidMapIt; ClientPidMap::List::ConstIterator clientPidMapEnd(clientpidmapList.end()); for (clientPidMapIt = clientpidmapList.begin(); clientPidMapIt != clientPidMapEnd; ++clientPidMapIt) { VCardLine line(QStringLiteral("CLIENTPIDMAP"), (*clientPidMapIt).clientPidMap()); addParameters(line, (*clientPidMapIt).parameters()); card.addLine(line); } } // EMAIL const Email::List emailList = (*addrIt).emailList(); Email::List::ConstIterator emailIt; Email::List::ConstIterator emailEnd(emailList.end()); for (emailIt = emailList.begin(); emailIt != emailEnd; ++emailIt) { VCardLine line(QStringLiteral("EMAIL"), (*emailIt).mail()); QMapIterator i((*emailIt).parameters()); while (i.hasNext()) { i.next(); if (version == VCard::v2_1) { if (i.key().toLower() == QLatin1String("type")) { QStringList valueStringList = i.value(); bool hasPreferred = false; const int removeItems = valueStringList.removeAll(QStringLiteral("PREF")); if (removeItems > 0) { hasPreferred = true; } if (!valueStringList.isEmpty()) { addParameter(line, version, i.key(), valueStringList); } if (hasPreferred) { line.addParameter(QStringLiteral("PREF"), QString()); } } else { line.addParameter(i.key(), i.value().join(QLatin1Char(','))); } } else { line.addParameter(i.key(), i.value().join(QLatin1Char(','))); } } card.addLine(line); } // FN required for only version > 2.1 VCardLine fnLine(QStringLiteral("FN"), (*addrIt).formattedName()); if (version == VCard::v2_1 && needsEncoding((*addrIt).formattedName())) { fnLine.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8")); fnLine.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE")); } card.addLine(fnLine); // GEO const Geo geo = (*addrIt).geo(); if (geo.isValid()) { QString str; if (version == VCard::v4_0) { str.sprintf("geo:%.6f,%.6f", geo.latitude(), geo.longitude()); } else { str.sprintf("%.6f;%.6f", geo.latitude(), geo.longitude()); } card.addLine(VCardLine(QStringLiteral("GEO"), str)); } // KEY const Key::List keys = (*addrIt).keys(); Key::List::ConstIterator keyIt; Key::List::ConstIterator keyEnd(keys.end()); for (keyIt = keys.begin(); keyIt != keyEnd; ++keyIt) { card.addLine(createKey(*keyIt, version)); } // LOGO card.addLine(createPicture(QStringLiteral("LOGO"), (*addrIt).logo(), version)); const QVector lstLogo = (*addrIt).extraLogoList(); for (const Picture &logo : lstLogo) { card.addLine(createPicture(QStringLiteral("LOGO"), logo, version)); } // MAILER only for version < 4.0 if (version != VCard::v4_0) { VCardLine mailerLine(QStringLiteral("MAILER"), (*addrIt).mailer()); if (version == VCard::v2_1 && needsEncoding((*addrIt).mailer())) { mailerLine.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8")); mailerLine.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE")); } card.addLine(mailerLine); } // N required for only version < 4.0 QStringList name; name.append((*addrIt).familyName().replace(QLatin1Char(';'), QStringLiteral("\\;"))); name.append((*addrIt).givenName().replace(QLatin1Char(';'), QStringLiteral("\\;"))); name.append((*addrIt).additionalName().replace(QLatin1Char(';'), QStringLiteral("\\;"))); name.append((*addrIt).prefix().replace(QLatin1Char(';'), QStringLiteral("\\;"))); name.append((*addrIt).suffix().replace(QLatin1Char(';'), QStringLiteral("\\;"))); VCardLine nLine(QStringLiteral("N"), name.join(QLatin1Char(';'))); if (version == VCard::v2_1 && needsEncoding(name.join(QLatin1Char(';')))) { nLine.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8")); nLine.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE")); } if (version == VCard::v4_0 && !(*addrIt).sortString().isEmpty()) { nLine.addParameter(QStringLiteral("SORT-AS"), (*addrIt).sortString()); } card.addLine(nLine); // NAME only for version < 4.0 if (version != VCard::v4_0) { VCardLine nameLine(QStringLiteral("NAME"), (*addrIt).name()); if (version == VCard::v2_1 && needsEncoding((*addrIt).name())) { nameLine.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8")); nameLine.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE")); } card.addLine(nameLine); } // NICKNAME only for version > 2.1 if (version != VCard::v2_1) { const QVector lstNickName = (*addrIt).extraNickNameList(); for (const NickName &nickName : lstNickName) { VCardLine nickNameLine(QStringLiteral("NICKNAME"), nickName.nickname()); addParameters(nickNameLine, nickName.parameters()); card.addLine(nickNameLine); } } // NOTE VCardLine noteLine(QStringLiteral("NOTE"), (*addrIt).note()); if (version == VCard::v2_1 && needsEncoding((*addrIt).note())) { noteLine.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8")); noteLine.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE")); } card.addLine(noteLine); // ORG const QVector lstOrg = (*addrIt).extraOrganizationList(); for (const Org &org : lstOrg) { QStringList organization; organization.append(org.organization().replace(QLatin1Char(';'), QStringLiteral("\\;"))); if (!(*addrIt).department().isEmpty()) { organization.append((*addrIt).department().replace(QLatin1Char(';'), QStringLiteral("\\;"))); } const QString orgStr = organization.join(QLatin1Char(';')); VCardLine orgLine(QStringLiteral("ORG"), orgStr); if (version == VCard::v2_1 && needsEncoding(orgStr)) { orgLine.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8")); orgLine.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE")); } addParameters(orgLine, org.parameters()); card.addLine(orgLine); } // PHOTO card.addLine(createPicture(QStringLiteral("PHOTO"), (*addrIt).photo(), version)); const QVector lstExtraPhoto = (*addrIt).extraPhotoList(); for (const Picture &photo : lstExtraPhoto) { card.addLine(createPicture(QStringLiteral("PHOTO"), photo, version)); } // PROID only for version > 2.1 if (version != VCard::v2_1) { card.addLine(VCardLine(QStringLiteral("PRODID"), (*addrIt).productId())); } // REV card.addLine(VCardLine(QStringLiteral("REV"), createDateTime((*addrIt).revision(), version))); // ROLE const QVector lstExtraRole = (*addrIt).extraRoleList(); for (const Role &role : lstExtraRole) { VCardLine roleLine(QStringLiteral("ROLE"), role.role()); if (version == VCard::v2_1 && needsEncoding(role.role())) { roleLine.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8")); roleLine.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE")); } addParameters(roleLine, role.parameters()); card.addLine(roleLine); } // SORT-STRING if (version == VCard::v3_0) { card.addLine(VCardLine(QStringLiteral("SORT-STRING"), (*addrIt).sortString())); } // SOUND card.addLine(createSound((*addrIt).sound(), version)); const QVector lstSound = (*addrIt).extraSoundList(); for (const Sound &sound : lstSound) { card.addLine(createSound(sound, version)); } // TEL const PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers(); PhoneNumber::List::ConstIterator phoneIt; PhoneNumber::List::ConstIterator phoneEnd(phoneNumbers.end()); for (phoneIt = phoneNumbers.begin(); phoneIt != phoneEnd; ++phoneIt) { VCardLine line(QStringLiteral("TEL"), (*phoneIt).number()); QMapIterator i((*phoneIt).parameters()); while (i.hasNext()) { i.next(); if (i.key().toUpper() != QLatin1String("TYPE")) { line.addParameter(i.key(), i.value().join(QLatin1Char(','))); } } QStringList lst; for (unsigned int i = 0; i < s_numPhoneTypes; ++i) { if (s_phoneTypes[i].flag & (*phoneIt).type()) { const QString str = QString::fromLatin1(s_phoneTypes[i].phoneType); if (version == VCard::v4_0) { lst << str.toLower(); } else { lst << str; } } } if (!lst.isEmpty()) { addParameter(line, version, QStringLiteral("TYPE"), lst); } card.addLine(line); } // TITLE const QVector lstTitle = (*addrIt).extraTitleList(); for (const Title &title : lstTitle) { VCardLine titleLine(QStringLiteral("TITLE"), title.title()); if (version == VCard::v2_1 && needsEncoding(title.title())) { titleLine.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8")); titleLine.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE")); } addParameters(titleLine, title.parameters()); card.addLine(titleLine); } // TZ // TODO Add vcard4.0 support const TimeZone timeZone = (*addrIt).timeZone(); if (timeZone.isValid()) { QString str; int neg = 1; if (timeZone.offset() < 0) { neg = -1; } str.sprintf("%c%02d:%02d", (timeZone.offset() >= 0 ? '+' : '-'), (timeZone.offset() / 60) * neg, (timeZone.offset() % 60) * neg); card.addLine(VCardLine(QStringLiteral("TZ"), str)); } // UID card.addLine(VCardLine(QStringLiteral("UID"), (*addrIt).uid())); // URL const QVector<ResourceLocatorUrl> lstExtraUrl = (*addrIt).extraUrlList(); for (const ResourceLocatorUrl &url : lstExtraUrl) { VCardLine line(QStringLiteral("URL"), url.url()); addParameters(line, url.parameters()); card.addLine(line); } if (version == VCard::v4_0) { // GENDER const Gender gender = (*addrIt).gender(); if (gender.isValid()) { QString genderStr; if (!gender.gender().isEmpty()) { genderStr = gender.gender(); } if (!gender.comment().isEmpty()) { genderStr += QLatin1Char(';') + gender.comment(); } VCardLine line(QStringLiteral("GENDER"), genderStr); card.addLine(line); } // KIND if (!(*addrIt).kind().isEmpty()) { VCardLine line(QStringLiteral("KIND"), (*addrIt).kind()); card.addLine(line); } } // From vcard4. if (version == VCard::v4_0) { const QVector<CalendarUrl> lstCalendarUrl = (*addrIt).calendarUrlList(); for (const CalendarUrl &url : lstCalendarUrl) { if (url.isValid()) { QString type; switch (url.type()) { case CalendarUrl::Unknown: case CalendarUrl::EndCalendarType: break; case CalendarUrl::FBUrl: type = QStringLiteral("FBURL"); break; case CalendarUrl::CALUri: type = QStringLiteral("CALURI"); break; case CalendarUrl::CALADRUri: type = QStringLiteral("CALADRURI"); break; } if (!type.isEmpty()) { VCardLine line(type, url.url().toDisplayString()); addParameters(line, url.parameters()); card.addLine(line); } } } } //FieldGroup const QVector<FieldGroup> lstGroup = (*addrIt).fieldGroupList(); for (const FieldGroup &group : lstGroup) { VCardLine line(group.fieldGroupName(), group.value()); addParameters(line, group.parameters()); card.addLine(line); } // IMPP (supported in vcard 3 too) const QVector<Impp> lstImpp = (*addrIt).imppList(); for (const Impp &impp : lstImpp) { VCardLine line(QStringLiteral("IMPP"), impp.address()); line.addParameter(QStringLiteral("X-SERVICE-TYPE"), Impp::typeToString(impp.type())); QMapIterator<QString, QStringList> i(impp.parameters()); while (i.hasNext()) { i.next(); if (i.key().toLower() != QStringLiteral("x-service-type")) { line.addParameter(i.key(), i.value().join(QLatin1Char(','))); } } card.addLine(line); } // X- const QStringList customs = (*addrIt).customs(); for (strIt = customs.begin(); strIt != customs.end(); ++strIt) { QString identifier = QLatin1String("X-") +(*strIt).left((*strIt).indexOf(QLatin1Char(':'))); const QString value = (*strIt).mid((*strIt).indexOf(QLatin1Char(':')) + 1); if (value.isEmpty()) { continue; } //Convert to standard identifier if (exportVcard) { if (identifier == QLatin1String("X-messaging/aim-All")) { identifier = QStringLiteral("X-AIM"); } else if (identifier == QLatin1String("X-messaging/icq-All")) { identifier = QStringLiteral("X-ICQ"); } else if (identifier == QLatin1String("X-messaging/xmpp-All")) { identifier = QStringLiteral("X-JABBER"); } else if (identifier == QLatin1String("X-messaging/msn-All")) { identifier = QStringLiteral("X-MSN"); } else if (identifier == QLatin1String("X-messaging/yahoo-All")) { identifier = QStringLiteral("X-YAHOO"); } else if (identifier == QLatin1String("X-messaging/gadu-All")) { identifier = QStringLiteral("X-GADUGADU"); } else if (identifier == QLatin1String("X-messaging/skype-All")) { identifier = QStringLiteral("X-SKYPE"); } else if (identifier == QLatin1String("X-messaging/groupwise-All")) { identifier = QStringLiteral("X-GROUPWISE"); } else if (identifier == QLatin1String("X-messaging/sms-All")) { identifier = QStringLiteral("X-SMS"); } else if (identifier == QLatin1String("X-messaging/meanwhile-All")) { identifier = QStringLiteral("X-MEANWHILE"); } else if (identifier == QLatin1String("X-messaging/irc-All")) { identifier = QStringLiteral("X-IRC"); //Not defined by rfc but need for fixing #300869 } else if (identifier == QLatin1String("X-messaging/googletalk-All")) { //Not defined by rfc but need for fixing #300869 identifier = QStringLiteral("X-GTALK"); } else if (identifier == QLatin1String("X-messaging/twitter-All")) { identifier = QStringLiteral("X-TWITTER"); } } if (identifier.toLower() == QLatin1String("x-kaddressbook-x-anniversary") && version == VCard::v4_0) { // ANNIVERSARY if (!value.isEmpty()) { const QDate date = QDate::fromString(value, Qt::ISODate); QDateTime dt = QDateTime(date); dt.setTime(QTime()); VCardLine line(QStringLiteral("ANNIVERSARY"), createDateTime(dt, version, false)); card.addLine(line); } } else if (identifier.toLower() == QLatin1String("x-kaddressbook-x-spousesname") && version == VCard::v4_0) { if (!value.isEmpty()) { VCardLine line(QStringLiteral("RELATED"), QStringLiteral(";")); line.addParameter(QStringLiteral("TYPE"), QStringLiteral("spouse")); line.addParameter(QStringLiteral("VALUE"), value); card.addLine(line); } } else { VCardLine line(identifier, value); if (version == VCard::v2_1 && needsEncoding(value)) { line.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8")); line.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE")); } card.addLine(line); } } vCardList.append(card); } return VCardParser::createVCards(vCardList); } Addressee::List VCardTool::parseVCards(const QByteArray &vcard) const { static const QLatin1Char semicolonSep(';'); static const QLatin1Char commaSep(','); QString identifier; QString group; Addressee::List addrList; const VCard::List vCardList = VCardParser::parseVCards(vcard); VCard::List::ConstIterator cardIt; VCard::List::ConstIterator listEnd(vCardList.end()); for (cardIt = vCardList.begin(); cardIt != listEnd; ++cardIt) { Addressee addr; const QStringList idents = (*cardIt).identifiers(); QStringList::ConstIterator identIt; QStringList::ConstIterator identEnd(idents.end()); for (identIt = idents.begin(); identIt != identEnd; ++identIt) { const VCardLine::List lines = (*cardIt).lines((*identIt)); VCardLine::List::ConstIterator lineIt; // iterate over the lines for (lineIt = lines.begin(); lineIt != lines.end(); ++lineIt) { identifier = (*lineIt).identifier().toLower(); group = (*lineIt).group(); if (!group.isEmpty()) { KContacts::FieldGroup groupField(group + QLatin1Char('.') + (*lineIt).identifier()); groupField.setParameters((*lineIt).parameterMap()); groupField.setValue((*lineIt).value().toString()); addr.insertFieldGroup(groupField); } // ADR else if (identifier == QLatin1String("adr")) { Address address; const QStringList addrParts = splitString(semicolonSep, (*lineIt).value().toString()); const int addrPartsCount(addrParts.count()); if (addrPartsCount > 0) { address.setPostOfficeBox(addrParts.at(0)); } if (addrPartsCount > 1) { address.setExtended(addrParts.at(1)); } if (addrPartsCount > 2) { address.setStreet(addrParts.at(2)); } if (addrPartsCount > 3) { address.setLocality(addrParts.at(3)); } if (addrPartsCount > 4) { address.setRegion(addrParts.at(4)); } if (addrPartsCount > 5) { address.setPostalCode(addrParts.at(5)); } if (addrPartsCount > 6) { address.setCountry(addrParts.at(6)); } Address::Type type; const QStringList types = (*lineIt).parameters(QStringLiteral("type")); QStringList::ConstIterator end(types.end()); for (QStringList::ConstIterator it = types.begin(); it != end; ++it) { type |= stringToAddressType((*it).toLower()); } address.setType(type); QString label = (*lineIt).parameter(QStringLiteral("label")); if (!label.isEmpty()) { if (label.length() > 1) { if (label.at(0) == QLatin1Char('"') && label.at(label.length() - 1) == QLatin1Char('"')) { label = label.mid(1, label.length() - 2); } } address.setLabel(label); } QString geoStr = (*lineIt).parameter(QStringLiteral("geo")); if (!geoStr.isEmpty()) { geoStr.remove(QLatin1Char('\"')); geoStr.remove(QStringLiteral("geo:")); if (geoStr.contains(QLatin1Char(','))) { QStringList arguments = geoStr.split(QLatin1Char(',')); KContacts::Geo geo; geo.setLatitude(arguments.at(0).toDouble()); geo.setLongitude(arguments.at(1).toDouble()); address.setGeo(geo); } } addr.insertAddress(address); } // ANNIVERSARY else if (identifier == QLatin1String("anniversary")) { const QString t = (*lineIt).value().toString(); const QDateTime dt(parseDateTime(t)); addr.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Anniversary"), dt.date().toString(Qt::ISODate)); } // BDAY else if (identifier == QLatin1String("bday")) { bool withTime; const QDateTime bday = parseDateTime((*lineIt).value().toString(), &withTime); addr.setBirthday(bday, withTime); } // CATEGORIES else if (identifier == QLatin1String("categories")) { const QStringList categories = splitString(commaSep, (*lineIt).value().toString()); addr.setCategories(categories); } // FBURL else if (identifier == QLatin1String("fburl")) { CalendarUrl calurl; calurl.setType(CalendarUrl::FBUrl); const QUrl url = QUrl((*lineIt).value().toString()); calurl.setUrl(url); calurl.setParameters((*lineIt).parameterMap()); addr.insertCalendarUrl(calurl); } // CALADRURI else if (identifier == QLatin1String("caladruri")) { CalendarUrl calurl; calurl.setType(CalendarUrl::CALADRUri); const QUrl url = QUrl((*lineIt).value().toString()); calurl.setUrl(url); calurl.setParameters((*lineIt).parameterMap()); addr.insertCalendarUrl(calurl); } // CALURI else if (identifier == QLatin1String("caluri")) { CalendarUrl calurl; calurl.setType(CalendarUrl::CALUri); const QUrl url = QUrl((*lineIt).value().toString()); calurl.setUrl(url); calurl.setParameters((*lineIt).parameterMap()); addr.insertCalendarUrl(calurl); } //IMPP else if (identifier == QLatin1String("impp")) { QString imppStr = (*lineIt).value().toString(); Impp impp; impp.setParameters((*lineIt).parameterMap()); if (!(*lineIt).parameter(QStringLiteral("x-service-type")).isEmpty()) { impp.setAddress(imppStr); const QString serviceType = (*lineIt).parameter(QStringLiteral("x-service-type")).toLower(); imppService(serviceType, impp); } else { const int pos = imppStr.indexOf(QLatin1Char(':')); if (pos != -1) { const QString serviceType = imppStr.left(pos); const QString address = imppStr.right(imppStr.length() - pos - 1); impp.setAddress(address); imppService(serviceType, impp); } } addr.insertImpp(impp); } // CLASS else if (identifier == QLatin1String("class")) { addr.setSecrecy(parseSecrecy(*lineIt)); } // GENDER else if (identifier == QLatin1String("gender")) { QString genderStr = (*lineIt).value().toString(); if (!genderStr.isEmpty()) { Gender gender; if (genderStr.at(0) != QLatin1Char(';')) { gender.setGender(genderStr.at(0)); if (genderStr.length() > 2 && (genderStr.at(1) == QLatin1Char(';'))) { gender.setComment(genderStr.right(genderStr.length() - 2)); } } else { gender.setComment(genderStr.right(genderStr.length() - 1)); } addr.setGender(gender); } } // LANG else if (identifier == QLatin1String("lang")) { Lang lang; lang.setLanguage((*lineIt).value().toString()); lang.setParameters((*lineIt).parameterMap()); addr.insertLang(lang); } // EMAIL else if (identifier == QLatin1String("email")) { const QStringList types = (*lineIt).parameters(QStringLiteral("type")); addr.insertEmail((*lineIt).value().toString(), types.contains(QLatin1String("PREF")), (*lineIt).parameterMap()); } // KIND else if (identifier == QLatin1String("kind")) { addr.setKind((*lineIt).value().toString()); } // FN else if (identifier == QLatin1String("fn")) { addr.setFormattedName((*lineIt).value().toString()); } // GEO else if (identifier == QLatin1String("geo")) { Geo geo; QString lineStr = (*lineIt).value().toString(); if (lineStr.startsWith(QLatin1String("geo:"))) { //VCard 4.0 lineStr.remove(QStringLiteral("geo:")); const QStringList geoParts = lineStr.split(QLatin1Char(','), QString::KeepEmptyParts); if (geoParts.size() >= 2) { geo.setLatitude(geoParts.at(0).toFloat()); geo.setLongitude(geoParts.at(1).toFloat()); addr.setGeo(geo); } } else { const QStringList geoParts = lineStr.split(QLatin1Char(';'), QString::KeepEmptyParts); if (geoParts.size() >= 2) { geo.setLatitude(geoParts.at(0).toFloat()); geo.setLongitude(geoParts.at(1).toFloat()); addr.setGeo(geo); } } } // KEY else if (identifier == QLatin1String("key")) { addr.insertKey(parseKey(*lineIt)); } // LABEL else if (identifier == QLatin1String("label")) { Address::Type type; const QStringList types = (*lineIt).parameters(QStringLiteral("type")); QStringList::ConstIterator end(types.end()); for (QStringList::ConstIterator it = types.begin(); it != end; ++it) { type |= stringToAddressType((*it).toLower()); } bool available = false; KContacts::Address::List addressList = addr.addresses(); for (KContacts::Address::List::Iterator it = addressList.begin(); it != addressList.end(); ++it) { if ((*it).type() == type) { (*it).setLabel((*lineIt).value().toString()); addr.insertAddress(*it); available = true; break; } } if (!available) { // a standalone LABEL tag KContacts::Address address(type); address.setLabel((*lineIt).value().toString()); addr.insertAddress(address); } } // LOGO else if (identifier == QLatin1String("logo")) { Picture picture = parsePicture(*lineIt); if (addr.logo().isEmpty()) { addr.setLogo(picture); } else { addr.insertExtraLogo(picture); } } // MAILER else if (identifier == QLatin1String("mailer")) { addr.setMailer((*lineIt).value().toString()); } // N else if (identifier == QLatin1String("n")) { const QStringList nameParts = splitString(semicolonSep, (*lineIt).value().toString()); const int numberOfParts(nameParts.count()); if (numberOfParts > 0) { addr.setFamilyName(nameParts.at(0)); } if (numberOfParts > 1) { addr.setGivenName(nameParts.at(1)); } if (numberOfParts > 2) { addr.setAdditionalName(nameParts.at(2)); } if (numberOfParts > 3) { addr.setPrefix(nameParts.at(3)); } if (numberOfParts > 4) { addr.setSuffix(nameParts.at(4)); } if (!(*lineIt).parameter(QStringLiteral("sort-as")).isEmpty()) { addr.setSortString((*lineIt).parameter(QStringLiteral("sort-as"))); } } // NAME else if (identifier == QLatin1String("name")) { addr.setName((*lineIt).value().toString()); } // NICKNAME else if (identifier == QLatin1String("nickname")) { NickName nickName((*lineIt).value().toString()); nickName.setParameters((*lineIt).parameterMap()); addr.insertExtraNickName(nickName); } // NOTE else if (identifier == QLatin1String("note")) { addr.setNote((*lineIt).value().toString()); } // ORGANIZATION else if (identifier == QLatin1String("org")) { const QStringList orgParts = splitString(semicolonSep, (*lineIt).value().toString()); const int orgPartsCount(orgParts.count()); if (orgPartsCount > 0) { Org organization(orgParts.at(0)); organization.setParameters((*lineIt).parameterMap()); addr.insertExtraOrganization(organization); } if (orgPartsCount > 1) { addr.setDepartment(orgParts.at(1)); } if (!(*lineIt).parameter(QStringLiteral("sort-as")).isEmpty()) { addr.setSortString((*lineIt).parameter(QStringLiteral("sort-as"))); } } // PHOTO else if (identifier == QLatin1String("photo")) { Picture picture = parsePicture(*lineIt); if (addr.photo().isEmpty()) { addr.setPhoto(picture); } else { addr.insertExtraPhoto(picture); } } // PROID else if (identifier == QLatin1String("prodid")) { addr.setProductId((*lineIt).value().toString()); } // REV else if (identifier == QLatin1String("rev")) { addr.setRevision(parseDateTime((*lineIt).value().toString())); } // ROLE else if (identifier == QLatin1String("role")) { Role role((*lineIt).value().toString()); role.setParameters((*lineIt).parameterMap()); addr.insertExtraRole(role); } // SORT-STRING else if (identifier == QLatin1String("sort-string")) { addr.setSortString((*lineIt).value().toString()); } // SOUND else if (identifier == QLatin1String("sound")) { Sound sound = parseSound(*lineIt); if (addr.sound().isEmpty()) { addr.setSound(sound); } else { addr.insertExtraSound(sound); } } // TEL else if (identifier == QLatin1String("tel")) { PhoneNumber phone; phone.setNumber((*lineIt).value().toString()); PhoneNumber::Type type; bool foundType = false; const QStringList types = (*lineIt).parameters(QStringLiteral("type")); QStringList::ConstIterator typeEnd(types.constEnd()); for (QStringList::ConstIterator it = types.constBegin(); it != typeEnd; ++it) { type |= stringToPhoneType((*it).toUpper()); foundType = true; } phone.setType(foundType ? type : PhoneNumber::Undefined); phone.setParameters((*lineIt).parameterMap()); addr.insertPhoneNumber(phone); } // TITLE else if (identifier == QLatin1String("title")) { Title title((*lineIt).value().toString()); title.setParameters((*lineIt).parameterMap()); addr.insertExtraTitle(title); } // TZ else if (identifier == QLatin1String("tz")) { //TODO add vcard4 support TimeZone tz; const QString date = (*lineIt).value().toString(); if (!date.isEmpty()) { int hours = date.midRef(1, 2).toInt(); int minutes = date.midRef(4, 2).toInt(); int offset = (hours * 60) + minutes; offset = offset * (date[ 0 ] == QLatin1Char('+') ? 1 : -1); tz.setOffset(offset); addr.setTimeZone(tz); } } // UID else if (identifier == QLatin1String("uid")) { addr.setUid((*lineIt).value().toString()); } // URL else if (identifier == QLatin1String("url")) { const QUrl url = QUrl((*lineIt).value().toString()); ResourceLocatorUrl resourceLocatorUrl; resourceLocatorUrl.setUrl(url); resourceLocatorUrl.setParameters((*lineIt).parameterMap()); addr.insertExtraUrl(resourceLocatorUrl); } // SOURCE else if (identifier == QLatin1String("source")) { const QUrl url = QUrl((*lineIt).value().toString()); addr.insertSourceUrl(url); } // MEMBER (vcard 4.0) else if (identifier == QLatin1String("member")) { addr.insertMember((*lineIt).value().toString()); } // RELATED (vcard 4.0) else if (identifier == QLatin1String("related")) { Related related; related.setRelated((*lineIt).value().toString()); related.setParameters((*lineIt).parameterMap()); addr.insertRelationShip(related); } // CLIENTPIDMAP (vcard 4.0) else if (identifier == QLatin1String("clientpidmap")) { ClientPidMap clientpidmap; clientpidmap.setClientPidMap((*lineIt).value().toString()); clientpidmap.setParameters((*lineIt).parameterMap()); addr.insertClientPidMap(clientpidmap); } // X- //TODO import X-GENDER else if (identifier.startsWith(QLatin1String("x-"))) { QString ident = (*lineIt).identifier(); //X-Evolution if (identifier == QLatin1String("x-evolution-spouse") || identifier == QLatin1String("x-spouse")) { ident = QStringLiteral("X-KADDRESSBOOK-X-SpousesName"); } else if (identifier == QLatin1String("x-evolution-blog-url")) { ident = QStringLiteral("X-KADDRESSBOOK-BlogFeed"); } else if (identifier == QLatin1String("x-evolution-assistant") || identifier == QLatin1String("x-assistant")) { ident = QStringLiteral("X-KADDRESSBOOK-X-AssistantsName"); } else if (identifier == QLatin1String("x-evolution-anniversary") || identifier == QLatin1String("x-anniversary")) { ident = QStringLiteral("X-KADDRESSBOOK-X-Anniversary"); } else if (identifier == QLatin1String("x-evolution-manager") || identifier == QLatin1String("x-manager")) { ident = QStringLiteral("X-KADDRESSBOOK-X-ManagersName"); } else if (identifier == QLatin1String("x-aim")) { ident = QStringLiteral("X-messaging/aim-All"); } else if (identifier == QLatin1String("x-icq")) { ident = QStringLiteral("X-messaging/icq-All"); } else if (identifier == QLatin1String("x-jabber")) { ident = QStringLiteral("X-messaging/xmpp-All"); } else if (identifier == QLatin1String("x-jabber")) { ident = QStringLiteral("X-messaging/xmpp-All"); } else if (identifier == QLatin1String("x-msn")) { ident = QStringLiteral("X-messaging/msn-All"); } else if (identifier == QLatin1String("x-yahoo")) { ident = QStringLiteral("X-messaging/yahoo-All"); } else if (identifier == QLatin1String("x-gadugadu")) { ident = QStringLiteral("X-messaging/gadu-All"); } else if (identifier == QLatin1String("x-skype")) { ident = QStringLiteral("X-messaging/skype-All"); } else if (identifier == QLatin1String("x-groupwise")) { ident = QStringLiteral("X-messaging/groupwise-All"); } else if (identifier == QLatin1String("x-sms")) { ident = QStringLiteral("X-messaging/sms-All"); } else if (identifier == QLatin1String("x-meanwhile")) { ident = QStringLiteral("X-messaging/meanwhile-All"); } else if (identifier == QLatin1String("x-irc")) { ident = QStringLiteral("X-messaging/irc-All"); } else if (identifier == QLatin1String("x-gtalk")) { ident = QStringLiteral("X-messaging/googletalk-All"); } else if (identifier == QLatin1String("x-twitter")) { ident = QStringLiteral("X-messaging/twitter-All"); } const QString key = ident.mid(2); const int dash = key.indexOf(QLatin1Char('-')); addr.insertCustom(key.left(dash), key.mid(dash + 1), (*lineIt).value().toString()); } } } addrList.append(addr); } return addrList; } QDateTime VCardTool::parseDateTime(const QString &str, bool *timeValid) { const int posT = str.indexOf(QLatin1Char('T')); QString dateString = posT >= 0 ? str.left(posT) : str; const bool noYear = dateString.startsWith(QLatin1String("--")); dateString = dateString.remove(QLatin1Char('-')); QDate date; if (noYear) { date = QDate::fromString(dateString, QStringLiteral("MMdd")); date = date.addYears(-1900); } else { date = QDate::fromString(dateString, QStringLiteral("yyyyMMdd")); } QTime time; Qt::TimeSpec spec = Qt::LocalTime; int offsetSecs = 0; if (posT >= 0) { QString timeString = str.mid(posT + 1); timeString = timeString.remove(QLatin1Char(':')); const int zPos = timeString.indexOf(QLatin1Char('Z')); const int plusPos = timeString.indexOf(QLatin1Char('+')); const int minusPos = timeString.indexOf(QLatin1Char('-')); const int tzPos = qMax(qMax(zPos, plusPos), minusPos); const QString hhmmssString = tzPos >= 0 ? timeString.left(tzPos) : timeString; switch (hhmmssString.size()) { case 2: time = QTime::fromString(hhmmssString, QStringLiteral("hh")); break; case 4: time = QTime::fromString(hhmmssString, QStringLiteral("hhmm")); break; case 6: time = QTime::fromString(hhmmssString, QStringLiteral("hhmmss")); break; } if (tzPos >= 0) { if (zPos >= 0) { spec = Qt::UTC; } else { spec = Qt::OffsetFromUTC; QTime offsetTime; const QString offsetString = timeString.mid(tzPos + 1); switch (offsetString.size()) { case 2: offsetTime = QTime::fromString(offsetString, QStringLiteral("hh")); break; case 4: offsetTime = QTime::fromString(offsetString, QStringLiteral("hhmm")); break; } offsetSecs = offsetTime.hour() * 3600 + offsetTime.minute() * 60; } if (minusPos >= 0) { offsetSecs *= -1; } } } if (timeValid) { *timeValid = time.isValid(); } return QDateTime(date, time, spec, offsetSecs); } QString VCardTool::createDateTime(const QDateTime &dateTime, VCard::Version version, bool withTime) { if (!dateTime.date().isValid()) { return QString(); } QString str = createDate(dateTime.date(), version); if (!withTime) { return str; } str += createTime(dateTime.time(), version); if (dateTime.timeSpec() == Qt::UTC) { str += QLatin1Char('Z'); } else if (dateTime.timeSpec() == Qt::OffsetFromUTC) { const int offsetSecs = dateTime.offsetFromUtc(); if (offsetSecs >= 0) { str += QLatin1Char('+'); } else { str += QLatin1Char('-'); } QTime offsetTime = QTime(0, 0).addSecs(abs(offsetSecs)); if (version == VCard::v4_0) { str += offsetTime.toString(QStringLiteral("HHmm")); } else { str += offsetTime.toString(QStringLiteral("HH:mm")); } } return str; } QString VCardTool::createDate(const QDate &date, VCard::Version version) { QString format; if (date.year() > 0) { format = QStringLiteral("yyyyMMdd"); } else { format = QStringLiteral("--MMdd"); } if (version != VCard::v4_0) { format = format.replace(QStringLiteral("yyyy"), QStringLiteral("yyyy-")); format = format.replace(QStringLiteral("MM"), QStringLiteral("MM-")); } return date.toString(format); } QString VCardTool::createTime(const QTime &time, VCard::Version version) { QString format; if (version == VCard::v4_0) { format = QStringLiteral("HHmmss"); } else { format = QStringLiteral("HH:mm:ss"); } return QLatin1Char('T') + time.toString(format); } Picture VCardTool::parsePicture(const VCardLine &line) const { Picture pic; const QStringList params = line.parameterList(); QString type; if (params.contains(QLatin1String("type"))) { type = line.parameter(QStringLiteral("type")); } if (params.contains(QLatin1String("encoding"))) { pic.setRawData(line.value().toByteArray(), type); } else if (params.contains(QLatin1String("value"))) { if (line.parameter(QStringLiteral("value")).toLower() == QLatin1String("uri")) { pic.setUrl(line.value().toString()); } } return pic; } VCardLine VCardTool::createPicture(const QString &identifier, const Picture &pic, VCard::Version version) const { VCardLine line(identifier); if (pic.isEmpty()) { return line; } if (pic.isIntern()) { line.setValue(pic.rawData()); if (version == VCard::v2_1) { line.addParameter(QStringLiteral("ENCODING"), QStringLiteral("BASE64")); line.addParameter(pic.type(), QString()); } else { /*if (version == VCard::v3_0) */ line.addParameter(QStringLiteral("encoding"), QStringLiteral("b")); line.addParameter(QStringLiteral("type"), pic.type()); #if 0 } else { //version 4.0 line.addParameter(QStringLiteral("data") + QStringLiteral(":image/") + pic.type(), QStringLiteral("base64")); #endif } } else { line.setValue(pic.url()); line.addParameter(QStringLiteral("value"), QStringLiteral("URI")); } return line; } Sound VCardTool::parseSound(const VCardLine &line) const { Sound snd; const QStringList params = line.parameterList(); if (params.contains(QLatin1String("encoding"))) { snd.setData(line.value().toByteArray()); } else if (params.contains(QLatin1String("value"))) { if (line.parameter(QStringLiteral("value")).toLower() == QLatin1String("uri")) { snd.setUrl(line.value().toString()); } } /* TODO: support sound types if ( params.contains( "type" ) ) snd.setType( line.parameter( "type" ) ); */ return snd; } VCardLine VCardTool::createSound(const Sound &snd, VCard::Version version) const { Q_UNUSED(version); VCardLine line(QStringLiteral("SOUND")); if (snd.isIntern()) { if (!snd.data().isEmpty()) { line.setValue(snd.data()); if (version == VCard::v2_1) { line.addParameter(QStringLiteral("ENCODING"), QStringLiteral("BASE64")); } else { line.addParameter(QStringLiteral("encoding"), QStringLiteral("b")); } // TODO: need to store sound type!!! } } else if (!snd.url().isEmpty()) { line.setValue(snd.url()); line.addParameter(QStringLiteral("value"), QStringLiteral("URI")); } return line; } Key VCardTool::parseKey(const VCardLine &line) const { Key key; const QStringList params = line.parameterList(); if (params.contains(QLatin1String("encoding"))) { key.setBinaryData(line.value().toByteArray()); } else { key.setTextData(line.value().toString()); } if (params.contains(QLatin1String("type"))) { if (line.parameter(QStringLiteral("type")).toLower() == QLatin1String("x509")) { key.setType(Key::X509); } else if (line.parameter(QStringLiteral("type")).toLower() == QLatin1String("pgp")) { key.setType(Key::PGP); } else { key.setType(Key::Custom); key.setCustomTypeString(line.parameter(QStringLiteral("type"))); } } else if (params.contains(QLatin1String("mediatype"))) { const QString param = line.parameter(QStringLiteral("mediatype")).toLower(); if (param == QLatin1String("application/x-x509-ca-cert")) { key.setType(Key::X509); } else if (param == QLatin1String("application/pgp-keys")) { key.setType(Key::PGP); } else { key.setType(Key::Custom); key.setCustomTypeString(line.parameter(QStringLiteral("type"))); } } return key; } VCardLine VCardTool::createKey(const Key &key, VCard::Version version) const { VCardLine line(QStringLiteral("KEY")); if (key.isBinary()) { if (!key.binaryData().isEmpty()) { line.setValue(key.binaryData()); if (version == VCard::v2_1) { line.addParameter(QStringLiteral("ENCODING"), QStringLiteral("BASE64")); } else { line.addParameter(QStringLiteral("encoding"), QStringLiteral("b")); } } } else if (!key.textData().isEmpty()) { line.setValue(key.textData()); } if (version == VCard::v4_0) { if (key.type() == Key::X509) { line.addParameter(QStringLiteral("MEDIATYPE"), QStringLiteral("application/x-x509-ca-cert")); } else if (key.type() == Key::PGP) { line.addParameter(QStringLiteral("MEDIATYPE"), QStringLiteral("application/pgp-keys")); } else if (key.type() == Key::Custom) { line.addParameter(QStringLiteral("MEDIATYPE"), key.customTypeString()); } } else { if (key.type() == Key::X509) { line.addParameter(QStringLiteral("type"), QStringLiteral("X509")); } else if (key.type() == Key::PGP) { line.addParameter(QStringLiteral("type"), QStringLiteral("PGP")); } else if (key.type() == Key::Custom) { line.addParameter(QStringLiteral("type"), key.customTypeString()); } } return line; } Secrecy VCardTool::parseSecrecy(const VCardLine &line) const { Secrecy secrecy; const QString value = line.value().toString().toLower(); if (value == QLatin1String("public")) { secrecy.setType(Secrecy::Public); } else if (value == QLatin1String("private")) { secrecy.setType(Secrecy::Private); } else if (value == QLatin1String("confidential")) { secrecy.setType(Secrecy::Confidential); } return secrecy; } VCardLine VCardTool::createSecrecy(const Secrecy &secrecy) const { VCardLine line(QStringLiteral("CLASS")); int type = secrecy.type(); if (type == Secrecy::Public) { line.setValue(QStringLiteral("PUBLIC")); } else if (type == Secrecy::Private) { line.setValue(QStringLiteral("PRIVATE")); } else if (type == Secrecy::Confidential) { line.setValue(QStringLiteral("CONFIDENTIAL")); } return line; } QStringList VCardTool::splitString(QChar sep, const QString &str) const { QStringList list; QString value(str); int start = 0; int pos = value.indexOf(sep, start); while (pos != -1) { if (pos == 0 || value[ pos - 1 ] != QLatin1Char('\\')) { if (pos > start && pos <= value.length()) { list << value.mid(start, pos - start); } else { list << QString(); } start = pos + 1; pos = value.indexOf(sep, start); } else { value.replace(pos - 1, 2, sep); pos = value.indexOf(sep, pos); } } int l = value.length() - 1; const QString mid = value.mid(start, l - start + 1); if (!mid.isEmpty()) { list << mid; } else { list << QString(); } return list; } void VCardTool::imppService(const QString &serviceType, KContacts::Impp &impp) const { if (serviceType == QLatin1String("facebook")) { impp.setType(KContacts::Impp::Facebook); } else if (serviceType == QLatin1String("jabber")) { impp.setType(KContacts::Impp::Jabber); } else if (serviceType == QLatin1String("sip")) { impp.setType(KContacts::Impp::Sip); } else if (serviceType == QLatin1String("aim")) { impp.setType(KContacts::Impp::Aim); } else if (serviceType == QLatin1String("msn")) { impp.setType(KContacts::Impp::Msn); } else if (serviceType == QLatin1String("twitter")) { impp.setType(KContacts::Impp::Twitter); } else if (serviceType == QLatin1String("googletalk")) { impp.setType(KContacts::Impp::GoogleTalk); } else if (serviceType == QLatin1String("xmpp")) { impp.setType(KContacts::Impp::Xmpp); } else if (serviceType == QLatin1String("icq")) { impp.setType(KContacts::Impp::Icq); } else if (serviceType == QLatin1String("yahoo")) { impp.setType(KContacts::Impp::Yahoo); } else if (serviceType == QLatin1String("qq")) { impp.setType(KContacts::Impp::Qq); } else if (serviceType == QLatin1String("gadugadu")) { impp.setType(KContacts::Impp::GaduGadu); } else if (serviceType == QLatin1String("owncloud-handle")) { impp.setType(KContacts::Impp::Ownclound); } else if (serviceType == QLatin1String("skype")) { impp.setType(KContacts::Impp::Skype); } else { qCDebug(KCONTACTS_LOG) << "unknown service type " << serviceType; } } diff --git a/src/vcardtool.h b/src/vcardtool_p.h similarity index 100% rename from src/vcardtool.h rename to src/vcardtool_p.h