Exemplo n.º 1
0
void ImportExportVCardTest::shouldExportMemberElementVcard4()
{
    QByteArray vcarddata("BEGIN:VCARD"
                         "VERSION:4.0\r\n"
                         "KIND:group\r\n"
                         "FN:Funky distribution list\r\n"
                         "MEMBER:mailto:[email protected]\r\n"
                         "MEMBER:xmpp:[email protected]\r\n"
                         "MEMBER:sip:[email protected]\r\n"
                         "MEMBER:tel:+1-418-555-5555\r\n"
                         "UID:[email protected]\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:[email protected]\r\n"
                             "MEMBER:xmpp:[email protected]\r\n"
                             "MEMBER:sip:[email protected]\r\n"
                             "MEMBER:tel:+1-418-555-5555\r\n"
                             "N:;;;;\r\n"
                             "UID:[email protected]\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);
    //qDebug() << " result " << result;
    QCOMPARE(result, vcardexpected);
}
Exemplo n.º 2
0
void CalendarUrlTest::shouldGenerateVCardWithParameter()
{
    KContacts::AddresseeList lst;
    KContacts::Addressee addr;
    addr.setEmails(QStringList() << QStringLiteral("*****@*****.**"));
    addr.setUid(QStringLiteral("testuid"));
    CalendarUrl url;
    url.setType(CalendarUrl::CALUri);
    url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes")));
    QMap<QString, QStringList> params;
    params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2"));
    url.setParameters(params);
    addr.insertCalendarUrl(url);
    lst << addr;
    KContacts::VCardTool vcard;
    const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0);
    QByteArray expected = QByteArray("BEGIN:VCARD\r\n"
                                     "VERSION:4.0\r\n"
                                     "CALURI;FOO2=bla2,blo2:https://sherlockholmes.com/calendar/sherlockholmes\r\n"
                                     "EMAIL:[email protected]\r\n"
                                     "N:;;;;\r\n"
                                     "UID:testuid\r\n"
                                     "END:VCARD\r\n\r\n");
    QCOMPARE(ba, expected);
}
Exemplo n.º 3
0
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:[email protected]\r\n"
                         "EMAIL;PID=2.1:[email protected]\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:[email protected]\r\n"
                             "EMAIL;PID=2.1:[email protected]\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);
    //qDebug() << " result " << result;
    QCOMPARE(result, vcardexpected);

}
Exemplo n.º 4
0
void GenderTest::shouldExportEmptyGender()
{
    KContacts::AddresseeList lst;
    KContacts::Addressee addr;
    addr.setEmails(QStringList() << QStringLiteral("*****@*****.**"));
    addr.setUid(QStringLiteral("testuid"));
    lst << addr;
    KContacts::VCardTool vcard;
    const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0);
    QByteArray expected = createCard(QByteArray());
    QCOMPARE(ba, expected);
}
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
void GenderTest::shouldExportOnlyGenderWithoutTypeCommentGender()
{
    KContacts::AddresseeList lst;
    KContacts::Addressee addr;
    addr.setEmails(QStringList() << QStringLiteral("*****@*****.**"));
    addr.setUid(QStringLiteral("testuid"));
    KContacts::Gender gender;
    gender.setComment(QStringLiteral("comment"));
    addr.setGender(gender);
    lst << addr;
    KContacts::VCardTool vcard;
    const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0);
    QByteArray expected = createCard(QByteArray("GENDER:;comment"));
    QCOMPARE(ba, expected);
}
Exemplo n.º 7
0
void BirthDayTest::shouldParseBirthDayWithoutTimeAndYear()
{
    QByteArray vcarddata("BEGIN:VCARD\r\n"
                         "VERSION:4.0\r\n"
                         "BDAY:--0505\r\n"
                         "EMAIL:[email protected]\r\n"
                         "EMAIL:[email protected]\r\n"
                         "N:;;;;\r\n"
                         "UID:testuid\r\n"
                         "END:VCARD\r\n\r\n");

    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);
}
Exemplo n.º 8
0
void CalendarUrlTest::shouldParseCalendarUrl()
{
    for (int i = CalendarUrl::Unknown + 1; i < CalendarUrl::EndCalendarType; ++i) {
        CalendarUrl::CalendarType type = static_cast<CalendarUrl::CalendarType>(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:[email protected]\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());
    }
}
Exemplo n.º 9
0
void GenderTest::shouldNotExportInVcard3()
{
    KContacts::AddresseeList lst;
    KContacts::Addressee addr;
    addr.setEmails(QStringList() << QStringLiteral("*****@*****.**"));
    addr.setUid(QStringLiteral("testuid"));
    KContacts::Gender gender;
    gender.setComment(QStringLiteral("comment"));
    addr.setGender(gender);
    lst << addr;
    KContacts::VCardTool vcard;
    const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0);
    QByteArray expected("BEGIN:VCARD\r\n"
                        "VERSION:3.0\r\n"
                        "EMAIL:[email protected]\r\n"
                        "N:;;;;\r\n"
                        "UID:testuid\r\n"
                        "END:VCARD\r\n\r\n");
    QCOMPARE(ba, expected);
}
Exemplo n.º 10
0
void BirthDayTest::shouldExportVcard4()
{
    KContacts::AddresseeList lst;
    KContacts::Addressee addr;
    addr.setEmails(QStringList() << QStringLiteral("*****@*****.**") << QStringLiteral("*****@*****.**"));
    addr.setUid(QStringLiteral("testuid"));
    const QDateTime dt(QDate(1976, 5, 5), QTime(12, 5, 5));
    addr.setBirthday(dt);
    lst << addr;
    KContacts::VCardTool vcard;
    const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0);
    QByteArray expected("BEGIN:VCARD\r\n"
                        "VERSION:4.0\r\n"
                        "BDAY:19760505T120505\r\n"
                        "EMAIL:[email protected]\r\n"
                        "EMAIL:[email protected]\r\n"
                        "N:;;;;\r\n"
                        "UID:testuid\r\n"
                        "END:VCARD\r\n\r\n");

    QCOMPARE(ba, expected);
}
Exemplo n.º 11
0
void BirthDayTest::shouldExportVcard3WithoutTimeAndWithoutYear()
{
    KContacts::AddresseeList lst;
    KContacts::Addressee addr;
    addr.setEmails(QStringList() << QStringLiteral("*****@*****.**") << QStringLiteral("*****@*****.**"));
    addr.setUid(QStringLiteral("testuid"));
    const QDate d(-1, 5, 5);
    addr.setBirthday(d);
    lst << addr;
    KContacts::VCardTool vcard;
    const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0);
    QByteArray expected("BEGIN:VCARD\r\n"
                        "VERSION:3.0\r\n"
                        "BDAY:--05-05\r\n"
                        "EMAIL:[email protected]\r\n"
                        "EMAIL:[email protected]\r\n"
                        "N:;;;;\r\n"
                        "UID:testuid\r\n"
                        "END:VCARD\r\n\r\n");

    QCOMPARE(ba, expected);
}
Exemplo n.º 12
0
void CalendarUrlTest::shouldGenerateVCard()
{
    QFETCH(KContacts::CalendarUrl::CalendarType, type);
    QFETCH(QByteArray, value);

    KContacts::AddresseeList lst;
    KContacts::Addressee addr;
    addr.setEmails(QStringList() << QStringLiteral("*****@*****.**"));
    addr.setUid(QStringLiteral("testuid"));
    CalendarUrl url;
    url.setType(type);
    url.setUrl(QUrl(QStringLiteral("https://sherlockholmes.com/calendar/sherlockholmes")));
    addr.insertCalendarUrl(url);
    lst << addr;
    KContacts::VCardTool vcard;
    const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0);
    QByteArray expected;
    // Different order
    if (type == KContacts::CalendarUrl::FBUrl) {
        expected = QByteArray("BEGIN:VCARD\r\n"
                              "VERSION:4.0\r\n"
                              "EMAIL:[email protected]\r\n");
        expected += value + QByteArray(":https://sherlockholmes.com/calendar/sherlockholmes\r\n"
                                       "N:;;;;\r\n"
                                       "UID:testuid\r\n"
                                       "END:VCARD\r\n\r\n");
    } else {
        expected = QByteArray("BEGIN:VCARD\r\n"
                              "VERSION:4.0\r\n");
        expected += value + QByteArray(":https://sherlockholmes.com/calendar/sherlockholmes\r\n"
                                       "EMAIL:[email protected]\r\n"
                                       "N:;;;;\r\n"
                                       "UID:testuid\r\n"
                                       "END:VCARD\r\n\r\n");
    }

    QCOMPARE(ba, expected);
}
Exemplo n.º 13
0
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:[email protected]\r\n"
                         "EMAIL;PREF=1;TYPE=work:[email protected]\r\n"
                         "IMPP;PREF=1:xmpp:[email protected]\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:[email protected]\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\";TYPE:;;221B Bak\r\n"
                             " er Street;London;;NW1;United Kingdom\r\n"
                             "ANNIVERSARY:19960415\r\n"
                             "BDAY:19531015T231000Z\r\n"
                             "CALADRURI;PREF=1:mailto:[email protected]\r\n"
                             "CALURI;PREF=1:https://sherlockholmes.com/calendar/sherlockholmes\r\n"
                             "EMAIL;TYPE=home:[email protected]\r\n"
                             "EMAIL;PREF=1;TYPE=work:[email protected]\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:[email protected]\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;PREF=1;VALUE=uri: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);
    //qDebug() << " result " << result;
    QCOMPARE(result, vcardexpected);
}