Warning, file /frameworks/kcontacts/autotests/clientpidmaptest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of the KContacts framework. 0003 SPDX-FileCopyrightText: 2016-2019 Laurent Montel <montel@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "clientpidmaptest.h" 0009 #include "clientpidmap.h" 0010 #include "parametermap_p.h" 0011 #include "vcardtool_p.h" 0012 #include <QTest> 0013 0014 ClientPidMapTest::ClientPidMapTest(QObject *parent) 0015 : QObject(parent) 0016 { 0017 } 0018 0019 ClientPidMapTest::~ClientPidMapTest() 0020 { 0021 } 0022 0023 void ClientPidMapTest::shouldHaveDefaultValue() 0024 { 0025 KContacts::ClientPidMap role; 0026 QVERIFY(!role.isValid()); 0027 QVERIFY(role.clientPidMap().isEmpty()); 0028 QVERIFY(role.params().empty()); 0029 } 0030 0031 void ClientPidMapTest::shouldAssignValue() 0032 { 0033 const QString lang(QStringLiteral("fr")); 0034 KContacts::ParameterMap params; 0035 params.push_back({QStringLiteral("Foo1"), {QStringLiteral("bla1"), QStringLiteral("blo1")}}); 0036 params.push_back({QStringLiteral("Foo2"), {QStringLiteral("bla2"), QStringLiteral("blo2")}}); 0037 KContacts::ClientPidMap role(lang); 0038 role.setParams(params); 0039 QVERIFY(role.isValid()); 0040 QVERIFY(!role.clientPidMap().isEmpty()); 0041 QCOMPARE(role.clientPidMap(), lang); 0042 QVERIFY(!role.params().empty()); 0043 QCOMPARE(role.params(), params); 0044 } 0045 0046 void ClientPidMapTest::shouldAssignExternal() 0047 { 0048 KContacts::ClientPidMap role; 0049 const QString lang(QStringLiteral("fr")); 0050 role.setClientPidMap(lang); 0051 QVERIFY(role.isValid()); 0052 QCOMPARE(role.clientPidMap(), lang); 0053 } 0054 0055 void ClientPidMapTest::shouldSerialized() 0056 { 0057 KContacts::ClientPidMap role; 0058 KContacts::ClientPidMap result; 0059 const QString lang(QStringLiteral("fr")); 0060 role.setClientPidMap(lang); 0061 KContacts::ParameterMap params; 0062 params.push_back({QStringLiteral("Foo1"), {QStringLiteral("bla1"), QStringLiteral("blo1")}}); 0063 params.push_back({QStringLiteral("Foo2"), {QStringLiteral("bla2"), QStringLiteral("blo2")}}); 0064 role.setParams(params); 0065 0066 QByteArray data; 0067 QDataStream s(&data, QIODevice::WriteOnly); 0068 s << role; 0069 0070 QDataStream t(&data, QIODevice::ReadOnly); 0071 t >> result; 0072 0073 QVERIFY(role == result); 0074 } 0075 0076 void ClientPidMapTest::shouldEqualClientPidMap() 0077 { 0078 KContacts::ClientPidMap role; 0079 KContacts::ClientPidMap result; 0080 const QString lang(QStringLiteral("fr")); 0081 role.setClientPidMap(lang); 0082 KContacts::ParameterMap params; 0083 params.push_back({QStringLiteral("Foo1"), {QStringLiteral("bla1"), QStringLiteral("blo1")}}); 0084 params.push_back({QStringLiteral("Foo2"), {QStringLiteral("bla2"), QStringLiteral("blo2")}}); 0085 role.setParams(params); 0086 0087 result = role; 0088 QVERIFY(role == result); 0089 } 0090 0091 void ClientPidMapTest::shouldParseClientPidMap() 0092 { 0093 QByteArray vcarddata( 0094 "BEGIN:VCARD\n" 0095 "VERSION:3.0\n" 0096 "CLIENTPIDMAP:boo\n" 0097 "N:LastName;FirstName;;;\n" 0098 "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" 0099 "REV:2015-03-14T09:24:45+00:00\n" 0100 "FN:FirstName LastName\n" 0101 "END:VCARD\n"); 0102 0103 KContacts::VCardTool vcard; 0104 const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); 0105 QCOMPARE(lst.count(), 1); 0106 QCOMPARE(lst.at(0).clientPidMapList().count(), 1); 0107 QCOMPARE(lst.at(0).clientPidMapList().at(0).clientPidMap(), QStringLiteral("boo")); 0108 } 0109 0110 void ClientPidMapTest::shouldParseWithoutClientPidMap() 0111 { 0112 QByteArray vcarddata( 0113 "BEGIN:VCARD\n" 0114 "VERSION:3.0\n" 0115 "N:LastName;FirstName;;;\n" 0116 "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" 0117 "REV:2015-03-14T09:24:45+00:00\n" 0118 "FN:FirstName LastName\n" 0119 "END:VCARD\n"); 0120 0121 KContacts::VCardTool vcard; 0122 const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); 0123 QCOMPARE(lst.count(), 1); 0124 QCOMPARE(lst.at(0).clientPidMapList().count(), 0); 0125 } 0126 0127 void ClientPidMapTest::shouldCreateVCard() 0128 { 0129 KContacts::AddresseeList lst; 0130 KContacts::Addressee addr; 0131 addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); 0132 addr.setUid(QStringLiteral("testuid")); 0133 KContacts::ClientPidMap::List lstClientPidMap; 0134 KContacts::ClientPidMap clientpidmap(QStringLiteral("fr")); 0135 lstClientPidMap << clientpidmap; 0136 addr.setClientPidMapList(lstClientPidMap); 0137 lst << addr; 0138 KContacts::VCardTool vcard; 0139 const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); 0140 QByteArray expected( 0141 "BEGIN:VCARD\r\n" 0142 "VERSION:4.0\r\n" 0143 "CLIENTPIDMAP:fr\r\n" 0144 "EMAIL:foo@kde.org\r\n" 0145 "N:;;;;\r\n" 0146 "UID:testuid\r\n" 0147 "END:VCARD\r\n\r\n"); 0148 0149 QCOMPARE(ba, expected); 0150 } 0151 0152 void ClientPidMapTest::shouldCreateVCardWithTwoClientPidMap() 0153 { 0154 KContacts::AddresseeList lst; 0155 KContacts::Addressee addr; 0156 addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); 0157 addr.setUid(QStringLiteral("testuid")); 0158 KContacts::ClientPidMap::List lstClientPidMap; 0159 KContacts::ClientPidMap clientpidmap(QStringLiteral("fr")); 0160 KContacts::ClientPidMap clientpidmap2(QStringLiteral("fr2")); 0161 lstClientPidMap << clientpidmap << clientpidmap2; 0162 addr.setClientPidMapList(lstClientPidMap); 0163 lst << addr; 0164 KContacts::VCardTool vcard; 0165 const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); 0166 QByteArray expected( 0167 "BEGIN:VCARD\r\n" 0168 "VERSION:4.0\r\n" 0169 "CLIENTPIDMAP:fr\r\n" 0170 "CLIENTPIDMAP:fr2\r\n" 0171 "EMAIL:foo@kde.org\r\n" 0172 "N:;;;;\r\n" 0173 "UID:testuid\r\n" 0174 "END:VCARD\r\n\r\n"); 0175 0176 QCOMPARE(ba, expected); 0177 } 0178 0179 void ClientPidMapTest::shouldCreateVCardWithParameters() 0180 { 0181 KContacts::AddresseeList lst; 0182 KContacts::Addressee addr; 0183 addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); 0184 addr.setUid(QStringLiteral("testuid")); 0185 KContacts::ClientPidMap::List lstClientPidMap; 0186 KContacts::ClientPidMap clientpidmap(QStringLiteral("fr")); 0187 KContacts::ParameterMap params; 0188 params.push_back({QStringLiteral("Foo1"), {QStringLiteral("bla1"), QStringLiteral("blo1")}}); 0189 params.push_back({QStringLiteral("Foo2"), {QStringLiteral("bla2"), QStringLiteral("blo2")}}); 0190 clientpidmap.setParams(params); 0191 lstClientPidMap << clientpidmap; 0192 addr.setClientPidMapList(lstClientPidMap); 0193 lst << addr; 0194 KContacts::VCardTool vcard; 0195 const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); 0196 QByteArray expected( 0197 "BEGIN:VCARD\r\n" 0198 "VERSION:4.0\r\n" 0199 "CLIENTPIDMAP;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n" 0200 "EMAIL:foo@kde.org\r\n" 0201 "N:;;;;\r\n" 0202 "UID:testuid\r\n" 0203 "END:VCARD\r\n\r\n"); 0204 QCOMPARE(ba, expected); 0205 } 0206 0207 void ClientPidMapTest::shouldGenerateClientPidMapForVCard3() 0208 { 0209 KContacts::AddresseeList lst; 0210 KContacts::Addressee addr; 0211 addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); 0212 addr.setUid(QStringLiteral("testuid")); 0213 KContacts::ClientPidMap::List lstClientPidMap; 0214 KContacts::ClientPidMap clientpidmap(QStringLiteral("fr")); 0215 KContacts::ParameterMap params; 0216 params.push_back({QStringLiteral("Foo1"), {QStringLiteral("bla1"), QStringLiteral("blo1")}}); 0217 params.push_back({QStringLiteral("Foo2"), {QStringLiteral("bla2"), QStringLiteral("blo2")}}); 0218 clientpidmap.setParams(params); 0219 lstClientPidMap << clientpidmap; 0220 addr.setClientPidMapList(lstClientPidMap); 0221 lst << addr; 0222 KContacts::VCardTool vcard; 0223 const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); 0224 QByteArray expected( 0225 "BEGIN:VCARD\r\n" 0226 "VERSION:3.0\r\n" 0227 "EMAIL:foo@kde.org\r\n" 0228 "N:;;;;\r\n" 0229 "UID:testuid\r\n" 0230 "END:VCARD\r\n\r\n"); 0231 QCOMPARE(ba, expected); 0232 } 0233 0234 QTEST_MAIN(ClientPidMapTest)