File indexing completed on 2024-11-24 04:43:03
0001 /* 0002 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "mergecontactstest.h" 0008 #include "../job/mergecontacts.h" 0009 #include <QTest> 0010 0011 using namespace KABMergeContacts; 0012 using namespace KContacts; 0013 MergeContactsTest::MergeContactsTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void MergeContactsTest::shouldReturnDefaultAddressWhenNoListItem() 0019 { 0020 MergeContacts contacts; 0021 KContacts::Addressee result = contacts.mergedContact(); 0022 QCOMPARE(result.isEmpty(), true); 0023 } 0024 0025 void MergeContactsTest::shouldReturnDefaultAddressWhenOneItem() 0026 { 0027 Akonadi::Item::List lst; 0028 Akonadi::Item item; 0029 KContacts::Addressee address; 0030 address.setName(QStringLiteral("foo1")); 0031 item.setPayload<KContacts::Addressee>(address); 0032 lst << item; 0033 0034 MergeContacts contacts(lst); 0035 KContacts::Addressee result = contacts.mergedContact(); 0036 QCOMPARE(result.isEmpty(), true); 0037 } 0038 0039 void MergeContactsTest::noNeedManualSelectionCheckWhenEmptyList() 0040 { 0041 MergeContacts contacts; 0042 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0043 QCOMPARE(result, MergeContacts::None); 0044 } 0045 0046 void MergeContactsTest::noNeedManualSelectionCheckWhenOneItem() 0047 { 0048 Akonadi::Item::List lst; 0049 KContacts::Addressee address; 0050 Akonadi::Item item; 0051 address.setName(QStringLiteral("foo1")); 0052 item.setPayload<KContacts::Addressee>(address); 0053 lst << item; 0054 MergeContacts contacts(lst); 0055 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0056 QCOMPARE(result, MergeContacts::None); 0057 } 0058 0059 void MergeContactsTest::checkNeedManualSelectionWithName_data() 0060 { 0061 QTest::addColumn<QString>("nameItemA"); 0062 QTest::addColumn<QString>("nameItemB"); 0063 QTest::addColumn<QString>("nameItemC"); 0064 QTest::addColumn<bool>("needManualCheck"); 0065 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0066 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0067 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0068 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0069 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0070 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0071 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0072 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0073 } 0074 0075 void MergeContactsTest::checkNeedManualSelectionWithName() 0076 { 0077 QFETCH(QString, nameItemA); 0078 QFETCH(QString, nameItemB); 0079 QFETCH(QString, nameItemC); 0080 QFETCH(bool, needManualCheck); 0081 0082 Akonadi::Item::List lst; 0083 Addressee addressA; 0084 Akonadi::Item itemA; 0085 addressA.setName(nameItemA); 0086 itemA.setPayload<Addressee>(addressA); 0087 lst << itemA; 0088 0089 Addressee addressB; 0090 Akonadi::Item itemB; 0091 addressB.setName(nameItemB); 0092 itemB.setPayload<Addressee>(addressB); 0093 lst << itemB; 0094 0095 Addressee addressC; 0096 Akonadi::Item itemC; 0097 addressC.setName(nameItemC); 0098 itemC.setPayload<Addressee>(addressC); 0099 lst << itemC; 0100 0101 MergeContacts contacts(lst); 0102 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0103 const bool bResult = (result == MergeContacts::Name); 0104 QCOMPARE(bResult, needManualCheck); 0105 } 0106 0107 void MergeContactsTest::checkNeedManualSelectionWithNickName_data() 0108 { 0109 QTest::addColumn<QString>("nameItemA"); 0110 QTest::addColumn<QString>("nameItemB"); 0111 QTest::addColumn<QString>("nameItemC"); 0112 QTest::addColumn<bool>("needManualCheck"); 0113 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0114 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0115 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0116 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0117 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0118 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0119 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0120 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0121 } 0122 0123 void MergeContactsTest::checkNeedManualSelectionWithNickName() 0124 { 0125 QFETCH(QString, nameItemA); 0126 QFETCH(QString, nameItemB); 0127 QFETCH(QString, nameItemC); 0128 QFETCH(bool, needManualCheck); 0129 0130 Akonadi::Item::List lst; 0131 Addressee addressA; 0132 Akonadi::Item itemA; 0133 addressA.setNickName(nameItemA); 0134 itemA.setPayload<Addressee>(addressA); 0135 lst << itemA; 0136 0137 Addressee addressB; 0138 Akonadi::Item itemB; 0139 addressB.setNickName(nameItemB); 0140 itemB.setPayload<Addressee>(addressB); 0141 lst << itemB; 0142 0143 Addressee addressC; 0144 Akonadi::Item itemC; 0145 addressC.setNickName(nameItemC); 0146 itemC.setPayload<Addressee>(addressC); 0147 lst << itemC; 0148 0149 MergeContacts contacts(lst); 0150 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0151 const bool bResult = (result == MergeContacts::NickName); 0152 QCOMPARE(bResult, needManualCheck); 0153 } 0154 0155 void MergeContactsTest::checkNeedManualSelectionWithOrganization_data() 0156 { 0157 QTest::addColumn<QString>("nameItemA"); 0158 QTest::addColumn<QString>("nameItemB"); 0159 QTest::addColumn<QString>("nameItemC"); 0160 QTest::addColumn<bool>("needManualCheck"); 0161 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0162 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0163 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0164 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0165 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0166 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0167 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0168 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0169 } 0170 0171 void MergeContactsTest::checkNeedManualSelectionWithOrganization() 0172 { 0173 QFETCH(QString, nameItemA); 0174 QFETCH(QString, nameItemB); 0175 QFETCH(QString, nameItemC); 0176 QFETCH(bool, needManualCheck); 0177 0178 Akonadi::Item::List lst; 0179 Addressee addressA; 0180 Akonadi::Item itemA; 0181 addressA.setOrganization(nameItemA); 0182 itemA.setPayload<Addressee>(addressA); 0183 lst << itemA; 0184 0185 Addressee addressB; 0186 Akonadi::Item itemB; 0187 addressB.setOrganization(nameItemB); 0188 itemB.setPayload<Addressee>(addressB); 0189 lst << itemB; 0190 0191 Addressee addressC; 0192 Akonadi::Item itemC; 0193 addressC.setOrganization(nameItemC); 0194 itemC.setPayload<Addressee>(addressC); 0195 lst << itemC; 0196 0197 MergeContacts contacts(lst); 0198 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0199 const bool bResult = (result == MergeContacts::Organization); 0200 QCOMPARE(bResult, needManualCheck); 0201 } 0202 0203 void MergeContactsTest::checkNeedManualSelectionWithTitle_data() 0204 { 0205 QTest::addColumn<QString>("nameItemA"); 0206 QTest::addColumn<QString>("nameItemB"); 0207 QTest::addColumn<QString>("nameItemC"); 0208 QTest::addColumn<bool>("needManualCheck"); 0209 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0210 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0211 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0212 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0213 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0214 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0215 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0216 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0217 } 0218 0219 void MergeContactsTest::checkNeedManualSelectionWithTitle() 0220 { 0221 QFETCH(QString, nameItemA); 0222 QFETCH(QString, nameItemB); 0223 QFETCH(QString, nameItemC); 0224 QFETCH(bool, needManualCheck); 0225 0226 Akonadi::Item::List lst; 0227 Addressee addressA; 0228 Akonadi::Item itemA; 0229 addressA.setTitle(nameItemA); 0230 itemA.setPayload<Addressee>(addressA); 0231 lst << itemA; 0232 0233 Addressee addressB; 0234 Akonadi::Item itemB; 0235 addressB.setTitle(nameItemB); 0236 itemB.setPayload<Addressee>(addressB); 0237 lst << itemB; 0238 0239 Addressee addressC; 0240 Akonadi::Item itemC; 0241 addressC.setTitle(nameItemC); 0242 itemC.setPayload<Addressee>(addressC); 0243 lst << itemC; 0244 0245 MergeContacts contacts(lst); 0246 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0247 const bool bResult = (result == MergeContacts::Title); 0248 QCOMPARE(bResult, needManualCheck); 0249 } 0250 0251 void MergeContactsTest::checkNeedManualSelectionWithFamilyName_data() 0252 { 0253 QTest::addColumn<QString>("nameItemA"); 0254 QTest::addColumn<QString>("nameItemB"); 0255 QTest::addColumn<QString>("nameItemC"); 0256 QTest::addColumn<bool>("needManualCheck"); 0257 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0258 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0259 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0260 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0261 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0262 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0263 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0264 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0265 } 0266 0267 void MergeContactsTest::checkNeedManualSelectionWithFamilyName() 0268 { 0269 QFETCH(QString, nameItemA); 0270 QFETCH(QString, nameItemB); 0271 QFETCH(QString, nameItemC); 0272 QFETCH(bool, needManualCheck); 0273 0274 Akonadi::Item::List lst; 0275 Addressee addressA; 0276 Akonadi::Item itemA; 0277 addressA.setFamilyName(nameItemA); 0278 itemA.setPayload<Addressee>(addressA); 0279 lst << itemA; 0280 0281 Addressee addressB; 0282 Akonadi::Item itemB; 0283 addressB.setFamilyName(nameItemB); 0284 itemB.setPayload<Addressee>(addressB); 0285 lst << itemB; 0286 0287 Addressee addressC; 0288 Akonadi::Item itemC; 0289 addressC.setFamilyName(nameItemC); 0290 itemC.setPayload<Addressee>(addressC); 0291 lst << itemC; 0292 0293 MergeContacts contacts(lst); 0294 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0295 const bool bResult = (result == MergeContacts::FamilyName); 0296 QCOMPARE(bResult, needManualCheck); 0297 } 0298 0299 void MergeContactsTest::checkNeedManualSelectionWithDepartement_data() 0300 { 0301 QTest::addColumn<QString>("nameItemA"); 0302 QTest::addColumn<QString>("nameItemB"); 0303 QTest::addColumn<QString>("nameItemC"); 0304 QTest::addColumn<bool>("needManualCheck"); 0305 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0306 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0307 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0308 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0309 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0310 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0311 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0312 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0313 } 0314 0315 void MergeContactsTest::checkNeedManualSelectionWithDepartement() 0316 { 0317 QFETCH(QString, nameItemA); 0318 QFETCH(QString, nameItemB); 0319 QFETCH(QString, nameItemC); 0320 QFETCH(bool, needManualCheck); 0321 0322 Akonadi::Item::List lst; 0323 Addressee addressA; 0324 Akonadi::Item itemA; 0325 addressA.setDepartment(nameItemA); 0326 itemA.setPayload<Addressee>(addressA); 0327 lst << itemA; 0328 0329 Addressee addressB; 0330 Akonadi::Item itemB; 0331 addressB.setDepartment(nameItemB); 0332 itemB.setPayload<Addressee>(addressB); 0333 lst << itemB; 0334 0335 Addressee addressC; 0336 Akonadi::Item itemC; 0337 addressC.setDepartment(nameItemC); 0338 itemC.setPayload<Addressee>(addressC); 0339 lst << itemC; 0340 0341 MergeContacts contacts(lst); 0342 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0343 const bool bResult = (result == MergeContacts::Departement); 0344 QCOMPARE(bResult, needManualCheck); 0345 } 0346 0347 void MergeContactsTest::checkNeedManualSelectionWithProfession_data() 0348 { 0349 QTest::addColumn<QString>("nameItemA"); 0350 QTest::addColumn<QString>("nameItemB"); 0351 QTest::addColumn<QString>("nameItemC"); 0352 QTest::addColumn<bool>("needManualCheck"); 0353 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0354 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0355 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0356 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0357 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0358 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0359 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0360 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0361 } 0362 0363 void MergeContactsTest::checkNeedManualSelectionWithProfession() 0364 { 0365 QFETCH(QString, nameItemA); 0366 QFETCH(QString, nameItemB); 0367 QFETCH(QString, nameItemC); 0368 QFETCH(bool, needManualCheck); 0369 0370 Akonadi::Item::List lst; 0371 Addressee addressA; 0372 Akonadi::Item itemA; 0373 addressA.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Profession"), nameItemA); 0374 itemA.setPayload<KContacts::Addressee>(addressA); 0375 lst << itemA; 0376 0377 Addressee addressB; 0378 Akonadi::Item itemB; 0379 addressB.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Profession"), nameItemB); 0380 itemB.setPayload<KContacts::Addressee>(addressB); 0381 lst << itemB; 0382 0383 Addressee addressC; 0384 Akonadi::Item itemC; 0385 addressC.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Profession"), nameItemC); 0386 itemC.setPayload<KContacts::Addressee>(addressC); 0387 lst << itemC; 0388 0389 MergeContacts contacts(lst); 0390 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0391 const bool bResult = (result == MergeContacts::Profession); 0392 QCOMPARE(bResult, needManualCheck); 0393 } 0394 0395 void MergeContactsTest::checkNeedManualSelectionWithOffice_data() 0396 { 0397 QTest::addColumn<QString>("nameItemA"); 0398 QTest::addColumn<QString>("nameItemB"); 0399 QTest::addColumn<QString>("nameItemC"); 0400 QTest::addColumn<bool>("needManualCheck"); 0401 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0402 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0403 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0404 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0405 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0406 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0407 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0408 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0409 } 0410 0411 void MergeContactsTest::checkNeedManualSelectionWithOffice() 0412 { 0413 QFETCH(QString, nameItemA); 0414 QFETCH(QString, nameItemB); 0415 QFETCH(QString, nameItemC); 0416 QFETCH(bool, needManualCheck); 0417 0418 Akonadi::Item::List lst; 0419 Addressee addressA; 0420 Akonadi::Item itemA; 0421 addressA.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Office"), nameItemA); 0422 itemA.setPayload<KContacts::Addressee>(addressA); 0423 lst << itemA; 0424 0425 Addressee addressB; 0426 Akonadi::Item itemB; 0427 addressB.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Office"), nameItemB); 0428 itemB.setPayload<KContacts::Addressee>(addressB); 0429 lst << itemB; 0430 0431 Addressee addressC; 0432 Akonadi::Item itemC; 0433 addressC.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Office"), nameItemC); 0434 itemC.setPayload<KContacts::Addressee>(addressC); 0435 lst << itemC; 0436 0437 MergeContacts contacts(lst); 0438 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0439 const bool bResult = (result == MergeContacts::Office); 0440 QCOMPARE(bResult, needManualCheck); 0441 } 0442 0443 void MergeContactsTest::checkNeedManualSelectionWithManagerName_data() 0444 { 0445 QTest::addColumn<QString>("nameItemA"); 0446 QTest::addColumn<QString>("nameItemB"); 0447 QTest::addColumn<QString>("nameItemC"); 0448 QTest::addColumn<bool>("needManualCheck"); 0449 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0450 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0451 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0452 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0453 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0454 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0455 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0456 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0457 } 0458 0459 void MergeContactsTest::checkNeedManualSelectionWithManagerName() 0460 { 0461 QFETCH(QString, nameItemA); 0462 QFETCH(QString, nameItemB); 0463 QFETCH(QString, nameItemC); 0464 QFETCH(bool, needManualCheck); 0465 0466 Akonadi::Item::List lst; 0467 Addressee addressA; 0468 Akonadi::Item itemA; 0469 addressA.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-ManagersName"), nameItemA); 0470 itemA.setPayload<KContacts::Addressee>(addressA); 0471 lst << itemA; 0472 0473 Addressee addressB; 0474 Akonadi::Item itemB; 0475 addressB.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-ManagersName"), nameItemB); 0476 itemB.setPayload<KContacts::Addressee>(addressB); 0477 lst << itemB; 0478 0479 Addressee addressC; 0480 Akonadi::Item itemC; 0481 addressC.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-ManagersName"), nameItemC); 0482 itemC.setPayload<KContacts::Addressee>(addressC); 0483 lst << itemC; 0484 0485 MergeContacts contacts(lst); 0486 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0487 const bool bResult = (result == MergeContacts::ManagerName); 0488 QCOMPARE(bResult, needManualCheck); 0489 } 0490 0491 void MergeContactsTest::checkNeedManualSelectionWithAssistantName_data() 0492 { 0493 QTest::addColumn<QString>("nameItemA"); 0494 QTest::addColumn<QString>("nameItemB"); 0495 QTest::addColumn<QString>("nameItemC"); 0496 QTest::addColumn<bool>("needManualCheck"); 0497 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0498 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0499 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0500 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0501 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0502 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0503 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0504 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0505 } 0506 0507 void MergeContactsTest::checkNeedManualSelectionWithAssistantName() 0508 { 0509 QFETCH(QString, nameItemA); 0510 QFETCH(QString, nameItemB); 0511 QFETCH(QString, nameItemC); 0512 QFETCH(bool, needManualCheck); 0513 0514 Akonadi::Item::List lst; 0515 Addressee addressA; 0516 Akonadi::Item itemA; 0517 addressA.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-AssistantsName"), nameItemA); 0518 itemA.setPayload<KContacts::Addressee>(addressA); 0519 lst << itemA; 0520 0521 Addressee addressB; 0522 Akonadi::Item itemB; 0523 addressB.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-AssistantsName"), nameItemB); 0524 itemB.setPayload<KContacts::Addressee>(addressB); 0525 lst << itemB; 0526 0527 Addressee addressC; 0528 Akonadi::Item itemC; 0529 addressC.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-AssistantsName"), nameItemC); 0530 itemC.setPayload<KContacts::Addressee>(addressC); 0531 lst << itemC; 0532 0533 MergeContacts contacts(lst); 0534 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0535 const bool bResult = (result == MergeContacts::Assistant); 0536 QCOMPARE(bResult, needManualCheck); 0537 } 0538 0539 void MergeContactsTest::checkNeedManualSelectionWithAnniversary_data() 0540 { 0541 QTest::addColumn<QString>("nameItemA"); 0542 QTest::addColumn<QString>("nameItemB"); 0543 QTest::addColumn<QString>("nameItemC"); 0544 QTest::addColumn<bool>("needManualCheck"); 0545 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0546 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0547 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0548 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0549 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0550 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0551 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0552 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0553 } 0554 0555 void MergeContactsTest::checkNeedManualSelectionWithAnniversary() 0556 { 0557 QFETCH(QString, nameItemA); 0558 QFETCH(QString, nameItemB); 0559 QFETCH(QString, nameItemC); 0560 QFETCH(bool, needManualCheck); 0561 0562 Akonadi::Item::List lst; 0563 Addressee addressA; 0564 Akonadi::Item itemA; 0565 addressA.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Anniversary"), nameItemA); 0566 itemA.setPayload<KContacts::Addressee>(addressA); 0567 lst << itemA; 0568 0569 Addressee addressB; 0570 Akonadi::Item itemB; 0571 addressB.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Anniversary"), nameItemB); 0572 itemB.setPayload<KContacts::Addressee>(addressB); 0573 lst << itemB; 0574 0575 Addressee addressC; 0576 Akonadi::Item itemC; 0577 addressC.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Anniversary"), nameItemC); 0578 itemC.setPayload<KContacts::Addressee>(addressC); 0579 lst << itemC; 0580 0581 MergeContacts contacts(lst); 0582 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0583 const bool bResult = (result == MergeContacts::Anniversary); 0584 QCOMPARE(bResult, needManualCheck); 0585 } 0586 0587 void MergeContactsTest::shouldMergeTitle_data() 0588 { 0589 QTest::addColumn<QString>("nameItemA"); 0590 QTest::addColumn<QString>("nameItemB"); 0591 QTest::addColumn<QString>("nameItemC"); 0592 QTest::addColumn<bool>("isEmpty"); 0593 QTest::addColumn<QString>("result"); 0594 QTest::newRow("empty") << QString() << QString() << QString() << false << QString(); 0595 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false << QStringLiteral("foo"); 0596 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false << QStringLiteral("foo"); 0597 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false << QStringLiteral("foo"); 0598 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false << QStringLiteral("foo"); 0599 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false << QStringLiteral("foo"); 0600 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << false << QStringLiteral("foo"); 0601 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << false << QStringLiteral("foo1"); 0602 } 0603 0604 void MergeContactsTest::shouldMergeTitle() 0605 { 0606 QFETCH(QString, nameItemA); 0607 QFETCH(QString, nameItemB); 0608 QFETCH(QString, nameItemC); 0609 QFETCH(bool, isEmpty); 0610 QFETCH(QString, result); 0611 0612 Akonadi::Item::List lst; 0613 Addressee addressA; 0614 addressA.setTitle(nameItemA); 0615 Akonadi::Item itemA; 0616 itemA.setPayload<Addressee>(addressA); 0617 lst << itemA; 0618 0619 Addressee addressB; 0620 Akonadi::Item itemB; 0621 addressB.setTitle(nameItemB); 0622 itemB.setPayload<Addressee>(addressB); 0623 lst << itemB; 0624 0625 Addressee addressC; 0626 Akonadi::Item itemC; 0627 addressC.setTitle(nameItemC); 0628 itemC.setPayload<Addressee>(addressC); 0629 lst << itemC; 0630 0631 MergeContacts contacts(lst); 0632 KContacts::Addressee resultAddr = contacts.mergedContact(); 0633 QCOMPARE(resultAddr.isEmpty(), isEmpty); 0634 QCOMPARE(resultAddr.title(), result); 0635 } 0636 0637 void MergeContactsTest::shouldMergeDepartement_data() 0638 { 0639 QTest::addColumn<QString>("nameItemA"); 0640 QTest::addColumn<QString>("nameItemB"); 0641 QTest::addColumn<QString>("nameItemC"); 0642 QTest::addColumn<bool>("isEmpty"); 0643 QTest::addColumn<QString>("result"); 0644 QTest::newRow("empty") << QString() << QString() << QString() << false << QString(); 0645 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false << QStringLiteral("foo"); 0646 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false << QStringLiteral("foo"); 0647 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false << QStringLiteral("foo"); 0648 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false << QStringLiteral("foo"); 0649 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false << QStringLiteral("foo"); 0650 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << false << QStringLiteral("foo"); 0651 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << false << QStringLiteral("foo1"); 0652 } 0653 0654 void MergeContactsTest::shouldMergeDepartement() 0655 { 0656 QFETCH(QString, nameItemA); 0657 QFETCH(QString, nameItemB); 0658 QFETCH(QString, nameItemC); 0659 QFETCH(bool, isEmpty); 0660 QFETCH(QString, result); 0661 0662 Akonadi::Item::List lst; 0663 Addressee addressA; 0664 addressA.setDepartment(nameItemA); 0665 Akonadi::Item itemA; 0666 itemA.setPayload<Addressee>(addressA); 0667 lst << itemA; 0668 0669 Addressee addressB; 0670 Akonadi::Item itemB; 0671 addressB.setDepartment(nameItemB); 0672 itemB.setPayload<Addressee>(addressB); 0673 lst << itemB; 0674 0675 Addressee addressC; 0676 Akonadi::Item itemC; 0677 addressC.setDepartment(nameItemC); 0678 itemC.setPayload<Addressee>(addressC); 0679 lst << itemC; 0680 0681 MergeContacts contacts(lst); 0682 KContacts::Addressee resultAddr = contacts.mergedContact(); 0683 QCOMPARE(resultAddr.isEmpty(), isEmpty); 0684 QCOMPARE(resultAddr.department(), result); 0685 } 0686 0687 void MergeContactsTest::checkNeedManualSelectionWithPartnersName_data() 0688 { 0689 QTest::addColumn<QString>("nameItemA"); 0690 QTest::addColumn<QString>("nameItemB"); 0691 QTest::addColumn<QString>("nameItemC"); 0692 QTest::addColumn<bool>("needManualCheck"); 0693 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0694 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0695 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0696 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0697 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0698 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0699 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0700 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0701 } 0702 0703 void MergeContactsTest::checkNeedManualSelectionWithPartnersName() 0704 { 0705 QFETCH(QString, nameItemA); 0706 QFETCH(QString, nameItemB); 0707 QFETCH(QString, nameItemC); 0708 QFETCH(bool, needManualCheck); 0709 0710 Akonadi::Item::List lst; 0711 Addressee addressA; 0712 Akonadi::Item itemA; 0713 addressA.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-SpousesName"), nameItemA); 0714 itemA.setPayload<KContacts::Addressee>(addressA); 0715 lst << itemA; 0716 0717 Addressee addressB; 0718 Akonadi::Item itemB; 0719 addressB.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-SpousesName"), nameItemB); 0720 itemB.setPayload<KContacts::Addressee>(addressB); 0721 lst << itemB; 0722 0723 Addressee addressC; 0724 Akonadi::Item itemC; 0725 addressC.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-SpousesName"), nameItemC); 0726 itemC.setPayload<KContacts::Addressee>(addressC); 0727 lst << itemC; 0728 0729 MergeContacts contacts(lst); 0730 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0731 const bool bResult = (result == MergeContacts::PartnerName); 0732 QCOMPARE(bResult, needManualCheck); 0733 } 0734 0735 void MergeContactsTest::checkNeedManualSelectionWithBlog_data() 0736 { 0737 QTest::addColumn<QString>("nameItemA"); 0738 QTest::addColumn<QString>("nameItemB"); 0739 QTest::addColumn<QString>("nameItemC"); 0740 QTest::addColumn<bool>("needManualCheck"); 0741 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 0742 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false; 0743 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false; 0744 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false; 0745 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false; 0746 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false; 0747 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0748 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << true; 0749 } 0750 0751 void MergeContactsTest::checkNeedManualSelectionWithBlog() 0752 { 0753 QFETCH(QString, nameItemA); 0754 QFETCH(QString, nameItemB); 0755 QFETCH(QString, nameItemC); 0756 QFETCH(bool, needManualCheck); 0757 0758 Akonadi::Item::List lst; 0759 Addressee addressA; 0760 Akonadi::Item itemA; 0761 addressA.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("BlogFeed"), nameItemA); 0762 itemA.setPayload<KContacts::Addressee>(addressA); 0763 lst << itemA; 0764 0765 Addressee addressB; 0766 Akonadi::Item itemB; 0767 addressB.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("BlogFeed"), nameItemB); 0768 itemB.setPayload<KContacts::Addressee>(addressB); 0769 lst << itemB; 0770 0771 Addressee addressC; 0772 Akonadi::Item itemC; 0773 addressC.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("BlogFeed"), nameItemC); 0774 itemC.setPayload<KContacts::Addressee>(addressC); 0775 lst << itemC; 0776 0777 MergeContacts contacts(lst); 0778 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0779 const bool bResult = (result == MergeContacts::Blog); 0780 QCOMPARE(bResult, needManualCheck); 0781 } 0782 0783 void MergeContactsTest::checkNeedManualSelectionWithHomePage_data() 0784 { 0785 QTest::addColumn<QUrl>("nameItemA"); 0786 QTest::addColumn<QUrl>("nameItemB"); 0787 QTest::addColumn<QUrl>("nameItemC"); 0788 QTest::addColumn<bool>("needManualCheck"); 0789 QTest::newRow("noConflict") << QUrl() << QUrl() << QUrl() << false; 0790 QTest::newRow("noWithOneNameConflict") << QUrl() << QUrl() << QUrl(QStringLiteral("http://www.kde.org")) << false; 0791 QTest::newRow("noWithOneNameConflict1") << QUrl() << QUrl(QStringLiteral("http://www.kde.org")) << QUrl() << false; 0792 QTest::newRow("noWithOneNameConflict2") << QUrl(QStringLiteral("http://www.kde.org")) << QUrl() << QUrl() << false; 0793 QTest::newRow("noConflictWithSameName") << QUrl(QStringLiteral("http://www.kde.org")) << QUrl(QStringLiteral("http://www.kde.org")) << QUrl() << false; 0794 QTest::newRow("noConflictWithSameName2") << QUrl(QStringLiteral("http://www.kde.org")) << QUrl(QStringLiteral("http://www.kde.org")) 0795 << QUrl(QStringLiteral("http://www.kde.org")) << false; 0796 QTest::newRow("conflictUrl") << QUrl(QStringLiteral("http://www.kde.org")) << QUrl(QStringLiteral("http://www.kde.org1")) 0797 << QUrl(QStringLiteral("http://www.kde.org")) << true; 0798 QTest::newRow("conflict1") << QUrl() << QUrl(QStringLiteral("http://www.kde.org1")) << QUrl(QStringLiteral("http://www.kde.org")) << true; 0799 } 0800 0801 void MergeContactsTest::checkNeedManualSelectionWithHomePage() 0802 { 0803 QFETCH(QUrl, nameItemA); 0804 QFETCH(QUrl, nameItemB); 0805 QFETCH(QUrl, nameItemC); 0806 QFETCH(bool, needManualCheck); 0807 0808 Akonadi::Item::List lst; 0809 Addressee addressA; 0810 Akonadi::Item itemA; 0811 KContacts::ResourceLocatorUrl url; 0812 url.setUrl(nameItemA); 0813 addressA.setUrl(url); 0814 itemA.setPayload<Addressee>(addressA); 0815 lst << itemA; 0816 0817 Addressee addressB; 0818 Akonadi::Item itemB; 0819 url.setUrl(nameItemB); 0820 addressB.setUrl(url); 0821 itemB.setPayload<Addressee>(addressB); 0822 lst << itemB; 0823 0824 Addressee addressC; 0825 Akonadi::Item itemC; 0826 url.setUrl(nameItemC); 0827 addressC.setUrl(url); 0828 itemC.setPayload<Addressee>(addressC); 0829 lst << itemC; 0830 0831 MergeContacts contacts(lst); 0832 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 0833 const bool bResult = (result == MergeContacts::HomePage); 0834 QCOMPARE(bResult, needManualCheck); 0835 } 0836 0837 void MergeContactsTest::shouldMergeNotes_data() 0838 { 0839 QTest::addColumn<QString>("noteItemA"); 0840 QTest::addColumn<QString>("noteItemB"); 0841 QTest::addColumn<QString>("noteItemC"); 0842 QTest::addColumn<QString>("note"); 0843 QTest::newRow("noNotes") << QString() << QString() << QString() << QString(); 0844 QTest::newRow("oneNotes") << QStringLiteral("one") << QString() << QString() << QStringLiteral("one"); 0845 QTest::newRow("twoNotes") << QString() << QStringLiteral("one") << QStringLiteral("one") << QStringLiteral("one\none"); 0846 QTest::newRow("threeNotes") << QStringLiteral("one") << QStringLiteral("one") << QStringLiteral("one") << QStringLiteral("one\none\none"); 0847 } 0848 0849 void MergeContactsTest::shouldMergeNotes() 0850 { 0851 QFETCH(QString, noteItemA); 0852 QFETCH(QString, noteItemB); 0853 QFETCH(QString, noteItemC); 0854 QFETCH(QString, note); 0855 0856 Akonadi::Item::List lst; 0857 Addressee addressA; 0858 Akonadi::Item itemA; 0859 addressA.setName(QStringLiteral("foo1")); 0860 addressA.setNote(noteItemA); 0861 itemA.setPayload<Addressee>(addressA); 0862 lst << itemA; 0863 0864 Addressee addressB; 0865 Akonadi::Item itemB; 0866 addressB.setName(QStringLiteral("foo1")); 0867 addressB.setNote(noteItemB); 0868 itemB.setPayload<Addressee>(addressB); 0869 lst << itemB; 0870 0871 Addressee addressC; 0872 Akonadi::Item itemC; 0873 addressC.setName(QStringLiteral("foo1")); 0874 addressC.setNote(noteItemC); 0875 itemC.setPayload<Addressee>(addressC); 0876 lst << itemC; 0877 0878 MergeContacts contacts(lst); 0879 0880 const Addressee result = contacts.mergedContact(); 0881 QCOMPARE(result.note(), note); 0882 } 0883 0884 void MergeContactsTest::shouldMergeEmails_data() 0885 { 0886 QTest::addColumn<QStringList>("emailsItemA"); 0887 QTest::addColumn<QStringList>("emailsItemB"); 0888 QTest::addColumn<QStringList>("emailsItemC"); 0889 QTest::addColumn<QStringList>("emails"); 0890 QTest::newRow("noEmails") << QStringList() << QStringList() << QStringList() << QStringList(); 0891 QStringList lst; 0892 lst << QStringLiteral("foo"); 0893 lst << QStringLiteral("foo1"); 0894 lst << QStringLiteral("foo2"); 0895 QTest::newRow("copyFromOnContact") << lst << QStringList() << QStringList() << lst; 0896 QTest::newRow("copyFromTwoIdenticContact") << lst << lst << QStringList() << lst; 0897 QStringList lst2; 0898 lst2 << QStringLiteral("foo5"); 0899 lst2 << QStringLiteral("foo6"); 0900 lst2 << QStringLiteral("foo7"); 0901 0902 QTest::newRow("copyFromTwoDifferentContact") << lst << lst2 << QStringList() << (QStringList() << lst << lst2); 0903 QStringList lst3; 0904 lst3 << QStringLiteral("foo2"); 0905 lst3 << lst2; 0906 // Identic => we will return merge between lst and lst2 0907 QTest::newRow("copyWithSomeIdenticEmail") << lst << lst3 << QStringList() << (QStringList() << lst << lst2); 0908 } 0909 0910 void MergeContactsTest::shouldMergeEmails() 0911 { 0912 QFETCH(QStringList, emailsItemA); 0913 QFETCH(QStringList, emailsItemB); 0914 QFETCH(QStringList, emailsItemC); 0915 QFETCH(QStringList, emails); 0916 0917 Akonadi::Item::List lst; 0918 Addressee addressA; 0919 Akonadi::Item itemA; 0920 addressA.setName(QStringLiteral("foo1")); 0921 addressA.setEmails(emailsItemA); 0922 itemA.setPayload<Addressee>(addressA); 0923 lst << itemA; 0924 0925 Addressee addressB; 0926 Akonadi::Item itemB; 0927 addressB.setName(QStringLiteral("foo1")); 0928 addressB.setEmails(emailsItemB); 0929 itemB.setPayload<Addressee>(addressB); 0930 lst << itemB; 0931 0932 Addressee addressC; 0933 Akonadi::Item itemC; 0934 addressC.setName(QStringLiteral("foo1")); 0935 addressC.setEmails(emailsItemC); 0936 itemC.setPayload<Addressee>(addressC); 0937 lst << itemC; 0938 0939 MergeContacts contacts(lst); 0940 0941 const Addressee result = contacts.mergedContact(); 0942 QCOMPARE(result.emails(), emails); 0943 } 0944 0945 void MergeContactsTest::shouldMergeFamilyname_data() 0946 { 0947 QTest::addColumn<QString>("nameItemA"); 0948 QTest::addColumn<QString>("nameItemB"); 0949 QTest::addColumn<QString>("nameItemC"); 0950 QTest::addColumn<bool>("isEmpty"); 0951 QTest::addColumn<QString>("result"); 0952 QTest::newRow("empty") << QString() << QString() << QString() << false << QString(); 0953 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false << QStringLiteral("foo"); 0954 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false << QStringLiteral("foo"); 0955 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false << QStringLiteral("foo"); 0956 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false << QStringLiteral("foo"); 0957 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false << QStringLiteral("foo"); 0958 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << false << QStringLiteral("foo"); 0959 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << false << QStringLiteral("foo1"); 0960 } 0961 0962 void MergeContactsTest::shouldMergeFamilyname() 0963 { 0964 QFETCH(QString, nameItemA); 0965 QFETCH(QString, nameItemB); 0966 QFETCH(QString, nameItemC); 0967 QFETCH(bool, isEmpty); 0968 QFETCH(QString, result); 0969 0970 Akonadi::Item::List lst; 0971 Addressee addressA; 0972 addressA.setFamilyName(nameItemA); 0973 Akonadi::Item itemA; 0974 itemA.setPayload<Addressee>(addressA); 0975 lst << itemA; 0976 0977 Addressee addressB; 0978 Akonadi::Item itemB; 0979 addressB.setFamilyName(nameItemB); 0980 itemB.setPayload<Addressee>(addressB); 0981 lst << itemB; 0982 0983 Addressee addressC; 0984 Akonadi::Item itemC; 0985 addressC.setFamilyName(nameItemC); 0986 itemC.setPayload<Addressee>(addressC); 0987 lst << itemC; 0988 0989 MergeContacts contacts(lst); 0990 Addressee resultAddr = contacts.mergedContact(); 0991 QCOMPARE(resultAddr.isEmpty(), isEmpty); 0992 QCOMPARE(resultAddr.familyName(), result); 0993 } 0994 0995 void MergeContactsTest::shouldMergeBlogFeed_data() 0996 { 0997 QTest::addColumn<QString>("nameItemA"); 0998 QTest::addColumn<QString>("nameItemB"); 0999 QTest::addColumn<QString>("nameItemC"); 1000 QTest::addColumn<bool>("isEmpty"); 1001 QTest::addColumn<QString>("result"); 1002 QTest::newRow("empty") << QString() << QString() << QString() << false << QString(); 1003 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("foo") << false << QStringLiteral("foo"); 1004 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("foo") << QString() << false << QStringLiteral("foo"); 1005 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("foo") << QString() << QString() << false << QStringLiteral("foo"); 1006 QTest::newRow("noConflictWithSameName") << QStringLiteral("foo") << QStringLiteral("foo") << QString() << false << QStringLiteral("foo"); 1007 QTest::newRow("noConflictWithSameName2") << QStringLiteral("foo") << QStringLiteral("foo") << QStringLiteral("foo") << false << QStringLiteral("foo"); 1008 QTest::newRow("conflict") << QStringLiteral("foo") << QStringLiteral("foo1") << QStringLiteral("foo") << false << QStringLiteral("foo"); 1009 QTest::newRow("conflict1") << QString() << QStringLiteral("foo1") << QStringLiteral("foo") << false << QStringLiteral("foo1"); 1010 } 1011 1012 void MergeContactsTest::shouldMergeBlogFeed() 1013 { 1014 QFETCH(QString, nameItemA); 1015 QFETCH(QString, nameItemB); 1016 QFETCH(QString, nameItemC); 1017 QFETCH(bool, isEmpty); 1018 QFETCH(QString, result); 1019 1020 const QString valueCustomStr = QStringLiteral("BlogFeed"); 1021 Akonadi::Item::List lst; 1022 Addressee addressA; 1023 addressA.insertCustom(QStringLiteral("KADDRESSBOOK"), valueCustomStr, nameItemA); 1024 Akonadi::Item itemA; 1025 itemA.setPayload<Addressee>(addressA); 1026 lst << itemA; 1027 1028 Addressee addressB; 1029 Akonadi::Item itemB; 1030 addressB.insertCustom(QStringLiteral("KADDRESSBOOK"), valueCustomStr, nameItemB); 1031 itemB.setPayload<Addressee>(addressB); 1032 lst << itemB; 1033 1034 Addressee addressC; 1035 Akonadi::Item itemC; 1036 addressC.insertCustom(QStringLiteral("KADDRESSBOOK"), valueCustomStr, nameItemC); 1037 itemC.setPayload<Addressee>(addressC); 1038 lst << itemC; 1039 1040 MergeContacts contacts(lst); 1041 Addressee resultAddr = contacts.mergedContact(); 1042 QCOMPARE(resultAddr.isEmpty(), isEmpty); 1043 const QString resultStr = resultAddr.custom(QStringLiteral("KADDRESSBOOK"), valueCustomStr); 1044 QCOMPARE(resultStr, result); 1045 } 1046 1047 void MergeContactsTest::shouldMergeHomePage_data() 1048 { 1049 QTest::addColumn<QUrl>("nameItemA"); 1050 QTest::addColumn<QUrl>("nameItemB"); 1051 QTest::addColumn<QUrl>("nameItemC"); 1052 QTest::addColumn<bool>("isEmpty"); 1053 QTest::addColumn<QUrl>("result"); 1054 QTest::newRow("noConflict") << QUrl() << QUrl() << QUrl() << false << QUrl(); 1055 QTest::newRow("noWithOneNameConflict") << QUrl() << QUrl() << QUrl(QStringLiteral("http://www.kde.org")) << false 1056 << QUrl(QStringLiteral("http://www.kde.org")); 1057 QTest::newRow("noWithOneNameConflict1") << QUrl() << QUrl(QStringLiteral("http://www.kde.org")) << QUrl() << false 1058 << QUrl(QStringLiteral("http://www.kde.org")); 1059 QTest::newRow("noWithOneNameConflict2") << QUrl(QStringLiteral("http://www.kde.org")) << QUrl() << QUrl() << false 1060 << QUrl(QStringLiteral("http://www.kde.org")); 1061 QTest::newRow("noConflictWithSameName") << QUrl(QStringLiteral("http://www.kde.org")) << QUrl(QStringLiteral("http://www.kde.org")) << QUrl() << false 1062 << QUrl(QStringLiteral("http://www.kde.org")); 1063 QTest::newRow("noConflictWithSameName2") << QUrl(QStringLiteral("http://www.kde.org")) << QUrl(QStringLiteral("http://www.kde.org")) 1064 << QUrl(QStringLiteral("http://www.kde.org")) << false << QUrl(QStringLiteral("http://www.kde.org")); 1065 QTest::newRow("conflictUrl") << QUrl(QStringLiteral("http://www.kde.org")) << QUrl(QStringLiteral("http://www.kde.org1")) 1066 << QUrl(QStringLiteral("http://www.kde.org")) << false << QUrl(QStringLiteral("http://www.kde.org")); 1067 QTest::newRow("conflict1") << QUrl() << QUrl(QStringLiteral("http://www.kde.org1")) << QUrl(QStringLiteral("http://www.kde.org")) << false 1068 << QUrl(QStringLiteral("http://www.kde.org1")); 1069 } 1070 1071 void MergeContactsTest::shouldMergeHomePage() 1072 { 1073 QFETCH(QUrl, nameItemA); 1074 QFETCH(QUrl, nameItemB); 1075 QFETCH(QUrl, nameItemC); 1076 QFETCH(bool, isEmpty); 1077 QFETCH(QUrl, result); 1078 Akonadi::Item::List lst; 1079 Addressee addressA; 1080 Akonadi::Item itemA; 1081 KContacts::ResourceLocatorUrl url; 1082 url.setUrl(nameItemA); 1083 addressA.setUrl(url); 1084 itemA.setPayload<KContacts::Addressee>(addressA); 1085 lst << itemA; 1086 1087 Addressee addressB; 1088 Akonadi::Item itemB; 1089 1090 url.setUrl(nameItemB); 1091 addressB.setUrl(url); 1092 itemB.setPayload<KContacts::Addressee>(addressB); 1093 lst << itemB; 1094 1095 Addressee addressC; 1096 Akonadi::Item itemC; 1097 url.setUrl(nameItemC); 1098 addressC.setUrl(url); 1099 itemC.setPayload<KContacts::Addressee>(addressC); 1100 lst << itemC; 1101 1102 MergeContacts contacts(lst); 1103 Addressee resultAddr = contacts.mergedContact(); 1104 QCOMPARE(resultAddr.isEmpty(), isEmpty); 1105 QCOMPARE(resultAddr.url().url(), result); 1106 } 1107 1108 void MergeContactsTest::checkNeedManualSelectionWithBirthday_data() 1109 { 1110 QTest::addColumn<QString>("nameItemA"); 1111 QTest::addColumn<QString>("nameItemB"); 1112 QTest::addColumn<QString>("nameItemC"); 1113 QTest::addColumn<bool>("needManualCheck"); 1114 QTest::newRow("noConflict") << QString() << QString() << QString() << false; 1115 QTest::newRow("noWithOneNameConflict") << QString() << QString() << QStringLiteral("20150606") << false; 1116 QTest::newRow("noWithOneNameConflict1") << QString() << QStringLiteral("20150606") << QString() << false; 1117 QTest::newRow("noWithOneNameConflict2") << QStringLiteral("20150606") << QString() << QString() << false; 1118 QTest::newRow("noConflictWithSameBirthday") << QStringLiteral("20150606") << QStringLiteral("20150606") << QString() << false; 1119 QTest::newRow("noConflictWithSameBirthday2") << QStringLiteral("20150606") << QStringLiteral("20150606") << QStringLiteral("20150606") << false; 1120 QTest::newRow("conflict") << QStringLiteral("20150606") << QStringLiteral("20150608") << QStringLiteral("20150606") << true; 1121 QTest::newRow("conflict1") << QString() << QStringLiteral("20150606") << QStringLiteral("20150608") << true; 1122 QTest::newRow("conflict2") << QStringLiteral("20150606") << QString() << QStringLiteral("20150608") << true; 1123 QTest::newRow("conflict2") << QStringLiteral("20150606") << QStringLiteral("20150608") << QString() << true; 1124 QTest::newRow("conflict4") << QStringLiteral("20180606") << QStringLiteral("20150608") << QStringLiteral("20150606") << true; 1125 } 1126 1127 void MergeContactsTest::checkNeedManualSelectionWithBirthday() 1128 { 1129 QFETCH(QString, nameItemA); 1130 QFETCH(QString, nameItemB); 1131 QFETCH(QString, nameItemC); 1132 QFETCH(bool, needManualCheck); 1133 1134 Akonadi::Item::List lst; 1135 Addressee addressA; 1136 Akonadi::Item itemA; 1137 QDate date = QDate::fromString(nameItemA, QStringLiteral("yyyyMMdd")); 1138 QDateTime dt(date.startOfDay()); 1139 addressA.setBirthday(dt); 1140 itemA.setPayload<Addressee>(addressA); 1141 lst << itemA; 1142 1143 Addressee addressB; 1144 Akonadi::Item itemB; 1145 date = QDate::fromString(nameItemB, QStringLiteral("yyyyMMdd")); 1146 dt = QDateTime(date.startOfDay()); 1147 1148 addressB.setBirthday(dt); 1149 itemB.setPayload<Addressee>(addressB); 1150 lst << itemB; 1151 1152 Addressee addressC; 1153 Akonadi::Item itemC; 1154 date = QDate::fromString(nameItemC, QStringLiteral("yyyyMMdd")); 1155 dt = QDateTime(date.startOfDay()); 1156 addressC.setBirthday(dt); 1157 itemC.setPayload<Addressee>(addressC); 1158 lst << itemC; 1159 1160 MergeContacts contacts(lst); 1161 const MergeContacts::ConflictInformations result = contacts.requiresManualSelectionOfInformation(); 1162 const bool bResult = (result == MergeContacts::Birthday); 1163 QCOMPARE(bResult, needManualCheck); 1164 } 1165 1166 QTEST_MAIN(MergeContactsTest) 1167 1168 #include "moc_mergecontactstest.cpp"