Commit a9b75538 authored by Laurent Montel's avatar Laurent Montel 😁

Start to create autotest for customidentifier

parent 19884acb
......@@ -11,4 +11,25 @@ add_executable(testroundtrip ${testroundtrip_srcs})
add_test(NAME kcontacts-testroundtrip COMMAND testroundtrip)
target_link_libraries(testroundtrip KF5Contacts Qt5::Test)
ecm_add_tests(birthdaytest.cpp addresseetest.cpp impptest.cpp emailtest.cpp addresstest.cpp geotest.cpp keytest.cpp phonenumbertest.cpp picturetest.cpp secrecytest.cpp soundtest.cpp timezonetest.cpp contactgrouptest.cpp vcarddragtest.cpp langtest.cpp gendertest.cpp calendarurltest.cpp ldifconvertertest.cpp relatedtest.cpp resourcelocatorurltest.cpp NAME_PREFIX "kcontacts-" LINK_LIBRARIES KF5Contacts Qt5::Test KF5::ConfigCore Qt5::Gui)
ecm_add_tests(birthdaytest.cpp
addresseetest.cpp
impptest.cpp
emailtest.cpp
addresstest.cpp
geotest.cpp
keytest.cpp
phonenumbertest.cpp
picturetest.cpp
secrecytest.cpp
soundtest.cpp
timezonetest.cpp
contactgrouptest.cpp
vcarddragtest.cpp
langtest.cpp gendertest.cpp
calendarurltest.cpp
ldifconvertertest.cpp
relatedtest.cpp
resourcelocatorurltest.cpp
customidentifiertest.cpp
NAME_PREFIX "kcontacts-" LINK_LIBRARIES KF5Contacts Qt5::Test KF5::ConfigCore Qt5::Gui)
/*
This file is part of the KContacts framework.
Copyright (c) 2015-2016 Laurent Montel <montel@kde.org>
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 <QTest>
#include "vcardtool.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"
"UID:testuid\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::v4_0);
expected = QByteArray("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"
"X-KADDRESSBOOK-X-ANNIVERSARY:19960415\r\n"
"X-KADDRESSBOOK-X-SpousesName:foo\r\n"
"END:VCARD\r\n\r\n");
QCOMPARE(ba, expected);
}
QTEST_MAIN(CustomIdentifierTest)
/*
This file is part of the KContacts framework.
Copyright (c) 2015-2016 Laurent Montel <montel@kde.org>
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.
*/
#ifndef CUSTOMIDENTIFIERTEST_H
#define CUSTOMIDENTIFIERTEST_H
#include <QObject>
class CustomIdentifierTest : public QObject
{
Q_OBJECT
public:
explicit CustomIdentifierTest(QObject *parent = Q_NULLPTR);
~CustomIdentifierTest();
private Q_SLOTS:
void shouldExportVcard4();
void shouldHaveEmptyCustoms();
void shouldExportVcard3();
};
#endif // CUSTOMIDENTIFIERTEST_H
......@@ -605,6 +605,12 @@ QByteArray VCardTool::createVCards(const Addressee::List &list,
dt.setTime(QTime());
card.addLine(VCardLine(QStringLiteral("ANNIVERSARY"), createDateTime(dt, version)));
}
} else if (identifier.toLower() == QLatin1String("x-kaddressbook-x-spousesname") && version == VCard::v4_0) {
if (!value.isEmpty()) {
VCardLine line( QStringLiteral("RELATED"));
line.addParameter(QStringLiteral("TYPE"), QStringLiteral("spouse"));
card.addLine(line);
}
} else {
VCardLine line(identifier, value);
if (version == VCard::v2_1 && needsEncoding(value)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment