|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qversitdefs_p.h" |
|
43 #include "tst_qversitcontactimporter.h" |
|
44 #include "qversitcontactimporter.h" |
|
45 #include "qversitcontactimporter_p.h" |
|
46 #include <qversitproperty.h> |
|
47 #include <qversitdocument.h> |
|
48 #include <QtTest/QtTest> |
|
49 #include <qcontact.h> |
|
50 #include <qcontactdetail.h> |
|
51 #include <qcontactname.h> |
|
52 #include <qcontactaddress.h> |
|
53 #include <qcontactphonenumber.h> |
|
54 #include <qcontactemailaddress.h> |
|
55 #include <qcontacturl.h> |
|
56 #include <qcontactguid.h> |
|
57 #include <qcontactorganization.h> |
|
58 #include <qcontacttimestamp.h> |
|
59 #include <qcontactanniversary.h> |
|
60 #include <qcontactbirthday.h> |
|
61 #include <qcontactgender.h> |
|
62 #include <qcontactnickname.h> |
|
63 #include <qcontactavatar.h> |
|
64 #include <qcontactgeolocation.h> |
|
65 #include <qcontactnote.h> |
|
66 #include <qcontactonlineaccount.h> |
|
67 #include <qcontactfamily.h> |
|
68 #include <QDir> |
|
69 |
|
70 QTM_BEGIN_NAMESPACE |
|
71 class MyQVersitContactImporterPropertyHandler : public QVersitContactImporterPropertyHandler |
|
72 { |
|
73 public: |
|
74 MyQVersitContactImporterPropertyHandler() |
|
75 : mPreProcess(false) |
|
76 { |
|
77 } |
|
78 |
|
79 bool preProcessProperty(const QVersitDocument& document, |
|
80 const QVersitProperty& property, |
|
81 int contactIndex, |
|
82 QContact* contact) |
|
83 { |
|
84 Q_UNUSED(document) |
|
85 Q_UNUSED(contact) |
|
86 Q_UNUSED(contactIndex); |
|
87 mPreProcessedProperties.append(property); |
|
88 return mPreProcess; |
|
89 } |
|
90 |
|
91 bool postProcessProperty(const QVersitDocument& document, |
|
92 const QVersitProperty& property, |
|
93 bool alreadyProcessed, |
|
94 int contactIndex, |
|
95 QContact* contact) |
|
96 { |
|
97 Q_UNUSED(document) |
|
98 Q_UNUSED(contact) |
|
99 Q_UNUSED(contactIndex) |
|
100 if (!alreadyProcessed) |
|
101 mUnknownProperties.append(property); |
|
102 else |
|
103 mPostProcessedProperties.append(property); |
|
104 return false; |
|
105 } |
|
106 |
|
107 void clear() |
|
108 { |
|
109 mPreProcess = false; |
|
110 mPropertyNamesToProcess.clear(); |
|
111 mUnknownProperties.clear(); |
|
112 mPreProcessedProperties.clear(); |
|
113 mPostProcessedProperties.clear(); |
|
114 } |
|
115 |
|
116 // a hook to control what preProcess returns: |
|
117 bool mPreProcess; |
|
118 QStringList mPropertyNamesToProcess; |
|
119 QList<QVersitProperty> mUnknownProperties; |
|
120 QList<QVersitProperty> mPreProcessedProperties; |
|
121 QList<QVersitProperty> mPostProcessedProperties; |
|
122 }; |
|
123 |
|
124 class MyQVersitResourceHandler : public QVersitResourceHandler |
|
125 { |
|
126 public: |
|
127 MyQVersitResourceHandler() : mIndex(0) |
|
128 { |
|
129 } |
|
130 |
|
131 bool saveResource(const QByteArray& contents, const QVersitProperty& property, |
|
132 QString* location) |
|
133 { |
|
134 Q_UNUSED(property); |
|
135 *location = QString::number(mIndex++); |
|
136 mObjects.insert(*location, contents); |
|
137 return true; |
|
138 } |
|
139 |
|
140 bool loadResource(const QString &location, QByteArray *contents, QString *mimeType) |
|
141 { |
|
142 Q_UNUSED(location) |
|
143 Q_UNUSED(contents) |
|
144 Q_UNUSED(mimeType) |
|
145 return false; |
|
146 } |
|
147 |
|
148 void clear() |
|
149 { |
|
150 mIndex = 0; |
|
151 mObjects.clear(); |
|
152 } |
|
153 |
|
154 int mIndex; |
|
155 QMap<QUrl, QByteArray> mObjects; |
|
156 }; |
|
157 |
|
158 const static QByteArray SAMPLE_GIF(QByteArray::fromBase64( |
|
159 "R0lGODlhEgASAIAAAAAAAP///yH5BAEAAAEALAAAAAASABIAAAIdjI+py+0G" |
|
160 "wEtxUmlPzRDnzYGfN3KBaKGT6rDmGxQAOw==")); |
|
161 |
|
162 const static QByteArray NOKIA_GIF(QByteArray::fromBase64( |
|
163 "R0lGODdhOAAKAIQRAAAvwQAwwwAwxAAxxwAyygAzywAzzBBHwC9nz0+A0HCf35+/4LDQ78/f79/o" |
|
164 "8O/v8PD3/////////////////////////////////////////////////////////////ywAAAAA" |
|
165 "OAAKAAAFsCAiik9kRqPJHIfhGixjisuJpqk9Inb0vjaBC0UwFH+uhM+gNBUCw6Wh92vYDAXkCZhF" |
|
166 "apMmA3Qajppav6tr8TqUp0DqEIwtqsmRR/Kl2A4RfFKCcnBMbYR+Uw5xg2lAjIlLCS88dyYNLn1S" |
|
167 "TYwvk3NmkXSQLgVvXmQuBCcQXlI7Io9MpyWCbKgublgCNgxfP0eOs6dvUgsPyMgvEAUAeCafUWhe" |
|
168 "bpI2LQMFenuhZy8hADs=")); |
|
169 |
|
170 QTM_END_NAMESPACE |
|
171 |
|
172 QTM_USE_NAMESPACE |
|
173 |
|
174 void tst_QVersitContactImporter::init() |
|
175 { |
|
176 mImporter = new QVersitContactImporter(); |
|
177 mResourceHandler = new MyQVersitResourceHandler(); |
|
178 mImporter->setResourceHandler(mResourceHandler); |
|
179 mPropertyHandler = new MyQVersitContactImporterPropertyHandler(); |
|
180 mImporter->setPropertyHandler(mPropertyHandler); |
|
181 } |
|
182 |
|
183 void tst_QVersitContactImporter::cleanup() |
|
184 { |
|
185 QVERIFY(mImporter->propertyHandler() == mPropertyHandler); |
|
186 mImporter->setPropertyHandler(0); |
|
187 delete mPropertyHandler; |
|
188 QVERIFY(mImporter->resourceHandler() == mResourceHandler); |
|
189 mImporter->setResourceHandler(0); |
|
190 delete mResourceHandler; |
|
191 delete mImporter; |
|
192 } |
|
193 |
|
194 void tst_QVersitContactImporter::testName() |
|
195 { |
|
196 QVersitDocument document(QVersitDocument::VCard30Type); |
|
197 QVersitProperty nameProperty; |
|
198 QStringList value; |
|
199 value.append(QString::fromAscii("John"));//FirstName |
|
200 value.append(QString::fromAscii("Citizen"));//LastName |
|
201 value.append(QString::fromAscii("Anonymous"));//GivenName |
|
202 value.append(QString::fromAscii("Dr"));//PreFix |
|
203 value.append(QString::fromAscii("MSc"));//Suffix |
|
204 nameProperty.setName(QString::fromAscii("N")); |
|
205 nameProperty.setValue(value); |
|
206 nameProperty.setValueType(QVersitProperty::CompoundType); |
|
207 document.addProperty(nameProperty); |
|
208 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
209 QContact contact = mImporter->contacts().first(); |
|
210 QContactName name = (QContactName)contact.detail(QContactName::DefinitionName); |
|
211 QCOMPARE(name.lastName(),value[0]); |
|
212 QCOMPARE(name.firstName(),value[1]); |
|
213 QCOMPARE(name.middleName(),value[2]); |
|
214 QCOMPARE(name.prefix(),value[3]); |
|
215 QCOMPARE(name.suffix(),value[4]); |
|
216 |
|
217 // Multiple names, first one will be picked and rest will be discarded |
|
218 nameProperty = QVersitProperty(); |
|
219 QStringList anotherValue; |
|
220 anotherValue.append(QString::fromAscii("FakeJohn"));//FirstName |
|
221 anotherValue.append(QString::fromAscii("FakeCitizen"));//LastName |
|
222 anotherValue.append(QString::fromAscii("FakeAnonymous"));//GivenName |
|
223 anotherValue.append(QString::fromAscii("FakeDr"));//PreFix |
|
224 anotherValue.append(QString::fromAscii("FakeMSc"));//Suffix |
|
225 nameProperty.setName(QString::fromAscii("N")); |
|
226 nameProperty.setValue(anotherValue); |
|
227 nameProperty.setValueType(QVersitProperty::CompoundType); |
|
228 document.addProperty(nameProperty); |
|
229 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
230 contact = mImporter->contacts().first(); |
|
231 QList<QContactDetail> names = contact.details(QContactName::DefinitionName); |
|
232 QCOMPARE(names.count(),1); |
|
233 // anotherValue should be discarded, so check for value |
|
234 name = (QContactName)names[0]; |
|
235 QCOMPARE(name.lastName(),value[0]); |
|
236 QCOMPARE(name.firstName(),value[1]); |
|
237 QCOMPARE(name.middleName(),value[2]); |
|
238 QCOMPARE(name.prefix(),value[3]); |
|
239 QCOMPARE(name.suffix(),value[4]); |
|
240 } |
|
241 |
|
242 // check that it doesn't crash if the FN property comes before the N property. |
|
243 void tst_QVersitContactImporter::testNameWithFormatted() |
|
244 { |
|
245 QVersitDocument document(QVersitDocument::VCard30Type); |
|
246 QVersitProperty fnProperty; |
|
247 fnProperty.setName(QString::fromAscii("FN")); |
|
248 fnProperty.setValue(QString::fromAscii("First Last")); |
|
249 document.addProperty(fnProperty); |
|
250 QVersitProperty nProperty; |
|
251 nProperty.setName(QString::fromAscii("N")); |
|
252 nProperty.setValue(QStringList() << QLatin1String("Last") << QLatin1String("First") << QLatin1String("Middle") << QLatin1String("Prefix") << QLatin1String("Suffix")); |
|
253 nProperty.setValueType(QVersitProperty::CompoundType); |
|
254 document.addProperty(nProperty); |
|
255 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
256 QContact contact = mImporter->contacts().first(); |
|
257 QContactName name = contact.detail<QContactName>(); |
|
258 QCOMPARE(name.firstName(), QString::fromAscii("First")); |
|
259 QCOMPARE(name.lastName(), QString::fromAscii("Last")); |
|
260 QCOMPARE(name.middleName(), QString::fromAscii("Middle")); |
|
261 QCOMPARE(name.prefix(), QString::fromAscii("Prefix")); |
|
262 QCOMPARE(name.suffix(), QString::fromAscii("Suffix")); |
|
263 QCOMPARE(name.customLabel(), QString::fromAscii("First Last")); |
|
264 } |
|
265 |
|
266 void tst_QVersitContactImporter::testAddress() |
|
267 { |
|
268 QVersitDocument document(QVersitDocument::VCard30Type); |
|
269 QVersitProperty property; |
|
270 property.setName(QString::fromAscii("ADR")); |
|
271 property.setValue(QStringList(QString())); |
|
272 property.setValueType(QVersitProperty::CompoundType); |
|
273 |
|
274 // Empty value for the address |
|
275 document = createDocumentWithProperty(property); |
|
276 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
277 QContact contact = mImporter->contacts().first(); |
|
278 QContactAddress address = contact.detail<QContactAddress>(); |
|
279 QCOMPARE(address.postOfficeBox(),QString()); |
|
280 QCOMPARE(address.street(),QString()); |
|
281 QCOMPARE(address.locality(),QString()); |
|
282 QCOMPARE(address.region(),QString()); |
|
283 QCOMPARE(address.postcode(),QString()); |
|
284 QCOMPARE(address.country(),QString()); |
|
285 |
|
286 // Address with all the fields filled |
|
287 property.setValue(QStringList() |
|
288 << QLatin1String("PO Box") |
|
289 << QLatin1String("E") |
|
290 << QLatin1String("My Street") |
|
291 << QLatin1String("My Town") |
|
292 << QLatin1String("My State") |
|
293 << QLatin1String("12345") |
|
294 << QLatin1String("My Country") |
|
295 ); |
|
296 property.setValueType(QVersitProperty::CompoundType); |
|
297 document = createDocumentWithProperty(property); |
|
298 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
299 contact = mImporter->contacts().first(); |
|
300 address = contact.detail<QContactAddress>(); |
|
301 QCOMPARE(address.postOfficeBox(),QString::fromAscii("PO Box")); |
|
302 QCOMPARE(address.street(),QString::fromAscii("My Street")); |
|
303 QCOMPARE(address.locality(),QString::fromAscii("My Town")); |
|
304 QCOMPARE(address.region(),QString::fromAscii("My State")); |
|
305 QCOMPARE(address.postcode(),QString::fromAscii("12345")); |
|
306 QCOMPARE(address.country(),QString::fromAscii("My Country")); |
|
307 |
|
308 // Address with TYPE parameters converted to contexts and subtypes |
|
309 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("HOME")); |
|
310 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("WORK")); |
|
311 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("DOM")); |
|
312 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("INTL")); |
|
313 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("POSTAL")); |
|
314 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("PARCEL")); |
|
315 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("X-EXTENSION")); |
|
316 document = createDocumentWithProperty(property); |
|
317 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
318 contact = mImporter->contacts().first(); |
|
319 address = contact.detail<QContactAddress>(); |
|
320 QStringList contexts = address.contexts(); |
|
321 QVERIFY(contexts.contains(QContactDetail::ContextHome)); |
|
322 QVERIFY(contexts.contains(QContactDetail::ContextWork)); |
|
323 QStringList subTypes = address.subTypes(); |
|
324 QVERIFY(subTypes.contains(QContactAddress::SubTypeDomestic)); |
|
325 QVERIFY(subTypes.contains(QContactAddress::SubTypeInternational)); |
|
326 QVERIFY(subTypes.contains(QContactAddress::SubTypePostal)); |
|
327 QVERIFY(subTypes.contains(QContactAddress::SubTypeParcel)); |
|
328 } |
|
329 |
|
330 void tst_QVersitContactImporter::testOrganizationName() |
|
331 { |
|
332 QVersitDocument document(QVersitDocument::VCard30Type); |
|
333 QVersitProperty property; |
|
334 |
|
335 // Empty value for the organization |
|
336 property.setName(QString::fromAscii("ORG")); |
|
337 document = createDocumentWithProperty(property); |
|
338 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
339 QContact contact = mImporter->contacts().first(); |
|
340 QContactOrganization organization = contact.detail<QContactOrganization>(); |
|
341 QCOMPARE(organization.name(),QString()); |
|
342 QCOMPARE(organization.department().count(),0); |
|
343 |
|
344 // Organization with single value |
|
345 property.setValueType(QVersitProperty::CompoundType); |
|
346 property.setValue(QStringList(QLatin1String("Nokia"))); |
|
347 document = createDocumentWithProperty(property); |
|
348 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
349 contact = mImporter->contacts().first(); |
|
350 organization = contact.detail<QContactOrganization>(); |
|
351 QCOMPARE(organization.name(),QString::fromAscii("Nokia")); |
|
352 QCOMPARE(organization.department().count(),0); |
|
353 |
|
354 // Organization with one Organizational Unit |
|
355 property.setValue(QStringList() << QLatin1String("Nokia") << QLatin1String("R&D")); |
|
356 document = createDocumentWithProperty(property); |
|
357 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
358 contact = mImporter->contacts().first(); |
|
359 organization = contact.detail<QContactOrganization>(); |
|
360 QCOMPARE(organization.name(),QString::fromAscii("Nokia")); |
|
361 QCOMPARE(organization.department().count(),1); |
|
362 QCOMPARE(organization.department().at(0),QString::fromAscii("R&D")); |
|
363 |
|
364 // Organization with more Organizational Units |
|
365 property.setValue(QStringList() |
|
366 << QLatin1String("Nokia") |
|
367 << QLatin1String("R&D") |
|
368 << QLatin1String("Devices") |
|
369 << QLatin1String("Qt")); |
|
370 property.setValueType(QVersitProperty::CompoundType); |
|
371 document = createDocumentWithProperty(property); |
|
372 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
373 contact = mImporter->contacts().first(); |
|
374 organization = contact.detail<QContactOrganization>(); |
|
375 QCOMPARE(organization.name(),QString::fromAscii("Nokia")); |
|
376 QCOMPARE(organization.department().count(),3); |
|
377 QCOMPARE(organization.department().at(0),QString::fromAscii("R&D")); |
|
378 QCOMPARE(organization.department().at(1),QString::fromAscii("Devices")); |
|
379 QCOMPARE(organization.department().at(2),QString::fromAscii("Qt")); |
|
380 } |
|
381 |
|
382 void tst_QVersitContactImporter::testOrganizationTitle() |
|
383 { |
|
384 QVersitDocument document(QVersitDocument::VCard30Type); |
|
385 QVersitProperty property; |
|
386 |
|
387 // One title |
|
388 property.setName(QString::fromAscii("TITLE")); |
|
389 QString titleValue(QString::fromAscii("Developer")); |
|
390 property.setValue(titleValue); |
|
391 document = createDocumentWithProperty(property); |
|
392 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
393 QContact contact = mImporter->contacts().first(); |
|
394 QList<QContactDetail> organizationDetails = |
|
395 contact.details(QContactOrganization::DefinitionName); |
|
396 QCOMPARE(organizationDetails.count(), 1); |
|
397 QContactOrganization organization = static_cast<QContactOrganization>(organizationDetails[0]); |
|
398 QCOMPARE(organization.title(),titleValue); |
|
399 |
|
400 // Two titles -> two QContactOrganizations created |
|
401 property.setName(QString::fromAscii("TITLE")); |
|
402 QString secondTitleValue(QString::fromAscii("Hacker")); |
|
403 property.setValue(secondTitleValue); |
|
404 document.addProperty(property); |
|
405 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
406 contact = mImporter->contacts().first(); |
|
407 organizationDetails = contact.details(QContactOrganization::DefinitionName); |
|
408 QCOMPARE(organizationDetails.count(), 2); |
|
409 QContactOrganization firstOrganization = |
|
410 static_cast<QContactOrganization>(organizationDetails[0]); |
|
411 QCOMPARE(firstOrganization.title(),titleValue); |
|
412 QContactOrganization secondOrganization = |
|
413 static_cast<QContactOrganization>(organizationDetails[1]); |
|
414 QCOMPARE(secondOrganization.title(),secondTitleValue); |
|
415 |
|
416 // Two titles and one organization name -> two QContactOrganizations created |
|
417 property.setName(QString::fromAscii("ORG")); |
|
418 property.setValueType(QVersitProperty::CompoundType); |
|
419 property.setValue(QStringList(QLatin1String("Nokia"))); |
|
420 document.addProperty(property); |
|
421 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
422 contact = mImporter->contacts().first(); |
|
423 organizationDetails = contact.details(QContactOrganization::DefinitionName); |
|
424 QCOMPARE(organizationDetails.count(), 2); |
|
425 firstOrganization = static_cast<QContactOrganization>(organizationDetails[0]); |
|
426 QCOMPARE(firstOrganization.title(),titleValue); |
|
427 QCOMPARE(firstOrganization.name(),QLatin1String("Nokia")); |
|
428 secondOrganization = static_cast<QContactOrganization>(organizationDetails[1]); |
|
429 QCOMPARE(secondOrganization.title(),secondTitleValue); |
|
430 QCOMPARE(secondOrganization.name(),QString()); |
|
431 } |
|
432 |
|
433 void tst_QVersitContactImporter::testOrganizationAssistant() |
|
434 { |
|
435 QContact contact; |
|
436 QVersitDocument document(QVersitDocument::VCard30Type); |
|
437 QVersitProperty property; |
|
438 property.setName(QString::fromAscii("X-ASSISTANT")); |
|
439 QString assistantValue(QString::fromAscii("Jenny")); |
|
440 property.setValue(assistantValue); |
|
441 document = createDocumentWithProperty(property); |
|
442 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
443 contact = mImporter->contacts().first(); |
|
444 QContactOrganization organization = contact.detail<QContactOrganization>(); |
|
445 QCOMPARE(organization.assistantName(), assistantValue); |
|
446 } |
|
447 |
|
448 void tst_QVersitContactImporter::testOrganizationLogo() |
|
449 { |
|
450 QContact contact; |
|
451 QVersitDocument document(QVersitDocument::VCard30Type); |
|
452 QVersitProperty property; |
|
453 |
|
454 // Embedded LOGO |
|
455 property.setName(QString::fromAscii("LOGO")); |
|
456 QByteArray logo(QByteArray::fromBase64( |
|
457 "R0lGODlhEgASAIAAAAAAAP///yH5BAEAAAEALAAAAAASABIAAAIdjI+py+0G")); |
|
458 property.setValue(logo); |
|
459 property.insertParameter(QString::fromAscii("TYPE"), |
|
460 QString::fromAscii("GIF")); |
|
461 document = createDocumentWithProperty(property); |
|
462 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
463 contact = mImporter->contacts().first(); |
|
464 QContactOrganization organization = contact.detail<QContactOrganization>(); |
|
465 QByteArray content = mResourceHandler->mObjects.value(organization.logoUrl().toString()); |
|
466 QCOMPARE(content, logo); |
|
467 |
|
468 // LOGO as a URL |
|
469 property.setName(QString::fromAscii("LOGO")); |
|
470 QString logoUrl(QString::fromAscii("http://www.organization.org/logo.gif")); |
|
471 property.setValue(logoUrl); |
|
472 property.insertParameter(QString::fromAscii("VALUE"),QString::fromAscii("URL")); |
|
473 document = createDocumentWithProperty(property); |
|
474 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
475 contact = mImporter->contacts().first(); |
|
476 organization = contact.detail<QContactOrganization>(); |
|
477 QCOMPARE(organization.logoUrl().toString(),logoUrl); |
|
478 } |
|
479 |
|
480 void tst_QVersitContactImporter::testOrganizationRole() |
|
481 { |
|
482 QContact contact; |
|
483 QVersitDocument document(QVersitDocument::VCard30Type); |
|
484 QVersitProperty property; |
|
485 |
|
486 // Setting the role is not yet supported by QContactOrganization |
|
487 property.setName(QString::fromAscii("ROLE")); |
|
488 QString roleValue(QString::fromAscii("Very important manager and proud of it")); |
|
489 property.setValue(roleValue); |
|
490 document = createDocumentWithProperty(property); |
|
491 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
492 contact = mImporter->contacts().first(); |
|
493 QContactOrganization organization = contact.detail<QContactOrganization>(); |
|
494 QCOMPARE(organization.role(), roleValue); |
|
495 } |
|
496 |
|
497 void tst_QVersitContactImporter::testTel() |
|
498 { |
|
499 QVersitDocument document(QVersitDocument::VCard30Type); |
|
500 QVersitProperty property; |
|
501 property.setName(QString::fromAscii("TEL")); |
|
502 QString value(QString::fromAscii("+35850987654321")); |
|
503 property.setValue(value); |
|
504 |
|
505 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("VOICE")); |
|
506 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("CELL")); |
|
507 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("MODEM")); |
|
508 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("CAR")); |
|
509 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("VIDEO")); |
|
510 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("FAX")); |
|
511 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("BBS")); |
|
512 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("PAGER")); |
|
513 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("HOME")); |
|
514 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("WORK")); |
|
515 |
|
516 document.addProperty(property); |
|
517 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
518 QContact contact = mImporter->contacts().first(); |
|
519 const QContactPhoneNumber& phone = contact.detail<QContactPhoneNumber>(); |
|
520 QCOMPARE(phone.number(),QString(value)); |
|
521 |
|
522 const QStringList subTypes = phone.subTypes(); |
|
523 QCOMPARE(subTypes.count(),8); |
|
524 QVERIFY(subTypes.contains(QContactPhoneNumber::SubTypeVoice)); |
|
525 QVERIFY(subTypes.contains(QContactPhoneNumber::SubTypeMobile)); |
|
526 QVERIFY(subTypes.contains(QContactPhoneNumber::SubTypeModem)); |
|
527 QVERIFY(subTypes.contains(QContactPhoneNumber::SubTypeCar)); |
|
528 QVERIFY(subTypes.contains(QContactPhoneNumber::SubTypeVideo)); |
|
529 QVERIFY(subTypes.contains(QContactPhoneNumber::SubTypeFax)); |
|
530 QVERIFY(subTypes.contains(QContactPhoneNumber::SubTypeBulletinBoardSystem)); |
|
531 QVERIFY(subTypes.contains(QContactPhoneNumber::SubTypePager)); |
|
532 |
|
533 const QStringList contexts = phone.contexts(); |
|
534 QCOMPARE(contexts.count(),2); |
|
535 QVERIFY(contexts.contains(QContactDetail::ContextWork)); |
|
536 QVERIFY(contexts.contains(QContactDetail::ContextHome)); |
|
537 } |
|
538 |
|
539 void tst_QVersitContactImporter::testEmail() |
|
540 { |
|
541 QVersitProperty property; |
|
542 property.setName(QString::fromAscii("EMAIL")); |
|
543 QString value(QString::fromAscii("john.citizen@example.com")); |
|
544 property.setValue(value); |
|
545 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("WORK")); |
|
546 QVersitDocument document = createDocumentWithProperty(property); |
|
547 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
548 QContact contact = mImporter->contacts().first(); |
|
549 QContactEmailAddress email = contact.detail<QContactEmailAddress>(); |
|
550 QCOMPARE(email.emailAddress(),value); |
|
551 const QStringList contexts = email.contexts(); |
|
552 QCOMPARE(contexts.count(),1); |
|
553 QVERIFY(contexts.contains(QContactDetail::ContextWork)); |
|
554 |
|
555 QCOMPARE(mPropertyHandler->mUnknownProperties.size(), 0); |
|
556 } |
|
557 |
|
558 void tst_QVersitContactImporter::testUrl() |
|
559 { |
|
560 QVersitProperty property; |
|
561 property.setName(QString::fromAscii("URL")); |
|
562 QString value(QString::fromAscii("http://example.com")); |
|
563 property.setValue(value); |
|
564 property.insertParameter(QString::fromAscii("TYPE"),QString::fromAscii("WORK")); |
|
565 QVersitDocument document = createDocumentWithProperty(property); |
|
566 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
567 QContact contact = mImporter->contacts().first(); |
|
568 QContactUrl url = contact.detail<QContactUrl>(); |
|
569 QCOMPARE(url.url(),value); |
|
570 const QStringList contexts = url.contexts(); |
|
571 QCOMPARE(contexts.count(),1); |
|
572 QVERIFY(contexts.contains(QContactDetail::ContextWork)); |
|
573 } |
|
574 |
|
575 void tst_QVersitContactImporter::testUid() |
|
576 { |
|
577 QVersitProperty property; |
|
578 property.setName(QString::fromAscii("UID")); |
|
579 QString value(QString::fromAscii("unique identifier")); |
|
580 property.setValue(value); |
|
581 QVersitDocument document = createDocumentWithProperty(property); |
|
582 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
583 QContact contact = mImporter->contacts().first(); |
|
584 QContactGuid uid = contact.detail<QContactGuid>(); |
|
585 QCOMPARE(uid.guid(),value); |
|
586 } |
|
587 |
|
588 void tst_QVersitContactImporter::testTimeStamp() |
|
589 { |
|
590 // Simple date : ISO 8601 extended format |
|
591 QVersitProperty property; |
|
592 property.setName(QString::fromAscii("REV")); |
|
593 QString dateValue(QString::fromAscii("1981-05-20")); |
|
594 property.setValue(dateValue); |
|
595 QVersitDocument document = createDocumentWithProperty(property); |
|
596 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
597 QContact contact = mImporter->contacts().first(); |
|
598 QContactTimestamp timeStamp = contact.detail<QContactTimestamp>(); |
|
599 QCOMPARE(timeStamp.lastModified().date().toString(Qt::ISODate),dateValue); |
|
600 |
|
601 // Date and Time : ISO 8601 extended format without utc offset |
|
602 QString dateAndTimeValue(QString::fromAscii("1981-05-20T23:55:55")); |
|
603 property.setValue(dateAndTimeValue); |
|
604 document = createDocumentWithProperty(property); |
|
605 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
606 contact = mImporter->contacts().first(); |
|
607 timeStamp = contact.detail<QContactTimestamp>(); |
|
608 QCOMPARE(timeStamp.lastModified().toString(Qt::ISODate),dateAndTimeValue); |
|
609 |
|
610 // Date and Time : ISO 8601 extented format with utc offset |
|
611 QString utcOffset(QString::fromAscii("Z")); |
|
612 QString dateAndTimeWithUtcValue = dateAndTimeValue+utcOffset; |
|
613 property.setValue(dateAndTimeWithUtcValue); |
|
614 document = createDocumentWithProperty(property); |
|
615 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
616 contact = mImporter->contacts().first(); |
|
617 timeStamp = contact.detail<QContactTimestamp>(); |
|
618 QCOMPARE(timeStamp.lastModified().toString(Qt::ISODate),dateAndTimeValue); |
|
619 QCOMPARE(timeStamp.lastModified().timeSpec(),Qt::UTC); |
|
620 |
|
621 // Date and Time : ISO 8601 in basic format without utc offset |
|
622 dateAndTimeValue = QString::fromAscii("19810520T235555"); |
|
623 property.setValue(dateAndTimeValue); |
|
624 document = createDocumentWithProperty(property); |
|
625 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
626 contact = mImporter->contacts().first(); |
|
627 timeStamp = contact.detail<QContactTimestamp>(); |
|
628 |
|
629 QCOMPARE(timeStamp.lastModified().toString(QString::fromAscii("yyyyMMddThhmmss")), |
|
630 dateAndTimeValue); |
|
631 |
|
632 // Date and Time : ISO 8601 in basic format with utc offset |
|
633 dateAndTimeValue = QString::fromAscii("19810520T235555"); |
|
634 dateAndTimeWithUtcValue = dateAndTimeValue+utcOffset; |
|
635 property.setValue(dateAndTimeWithUtcValue); |
|
636 document = createDocumentWithProperty(property); |
|
637 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
638 contact = mImporter->contacts().first(); |
|
639 timeStamp = contact.detail<QContactTimestamp>(); |
|
640 QCOMPARE(timeStamp.lastModified().toString(QString::fromAscii("yyyyMMddThhmmss")), |
|
641 dateAndTimeValue); |
|
642 QCOMPARE(timeStamp.lastModified().timeSpec(),Qt::UTC); |
|
643 } |
|
644 |
|
645 void tst_QVersitContactImporter::testAnniversary() |
|
646 { |
|
647 // Date : ISO 8601 extended format |
|
648 QVersitProperty property; |
|
649 property.setName(QString::fromAscii("X-ANNIVERSARY")); |
|
650 QString dateValue(QString::fromAscii("1981-05-20")); |
|
651 property.setValue(dateValue); |
|
652 QVersitDocument document = createDocumentWithProperty(property); |
|
653 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
654 QContact contact = mImporter->contacts().first(); |
|
655 QContactAnniversary anniversary = contact.detail<QContactAnniversary>(); |
|
656 QCOMPARE(anniversary.originalDate().toString(Qt::ISODate),dateValue); |
|
657 |
|
658 // Date : ISO 8601 in basic format |
|
659 dateValue = QString::fromAscii("19810520"); |
|
660 property.setValue(dateValue); |
|
661 document = createDocumentWithProperty(property); |
|
662 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
663 contact = mImporter->contacts().first(); |
|
664 anniversary = contact.detail<QContactAnniversary>(); |
|
665 QCOMPARE(anniversary.originalDate().toString(QString::fromAscii("yyyyMMdd")), |
|
666 dateValue); |
|
667 |
|
668 } |
|
669 |
|
670 void tst_QVersitContactImporter::testBirthday() |
|
671 { |
|
672 // Date : ISO 8601 extended format |
|
673 QVersitProperty property; |
|
674 property.setName(QString::fromAscii("BDAY")); |
|
675 QString dateValue(QString::fromAscii("1981-05-20")); |
|
676 property.setValue(dateValue); |
|
677 QVersitDocument document = createDocumentWithProperty(property); |
|
678 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
679 QContact contact = mImporter->contacts().first(); |
|
680 QContactBirthday bday = contact.detail<QContactBirthday>(); |
|
681 QCOMPARE(bday.date().toString(Qt::ISODate), |
|
682 dateValue); |
|
683 |
|
684 // Date : ISO 8601 in basic format |
|
685 dateValue = QString::fromAscii("19810520"); |
|
686 property.setValue(dateValue); |
|
687 document = createDocumentWithProperty(property); |
|
688 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
689 contact = mImporter->contacts().first(); |
|
690 bday = contact.detail<QContactBirthday>(); |
|
691 QCOMPARE(bday.date().toString(QString::fromAscii("yyyyMMdd")), |
|
692 dateValue); |
|
693 |
|
694 } |
|
695 |
|
696 void tst_QVersitContactImporter::testGender() |
|
697 { |
|
698 // Date : ISO 8601 extended format |
|
699 QVersitProperty property; |
|
700 property.setName(QString::fromAscii("X-GENDER")); |
|
701 QString val(QString::fromAscii("Male")); |
|
702 property.setValue(val); |
|
703 QVersitDocument document = createDocumentWithProperty(property); |
|
704 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
705 QContact contact = mImporter->contacts().first(); |
|
706 QContactGender gender = contact.detail<QContactGender >(); |
|
707 QCOMPARE(gender.gender(),val); |
|
708 } |
|
709 |
|
710 void tst_QVersitContactImporter::testNickname() |
|
711 { |
|
712 // one value |
|
713 QVersitDocument document(QVersitDocument::VCard30Type); |
|
714 QVersitProperty nameProperty; |
|
715 nameProperty.setName(QString::fromAscii("NICKNAME")); |
|
716 nameProperty.setValue(QStringList(QLatin1String("Homie"))); |
|
717 nameProperty.setValueType(QVersitProperty::ListType); |
|
718 document.addProperty(nameProperty); |
|
719 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
720 QContact contact = mImporter->contacts().first(); |
|
721 QContactNickname nickName = (QContactNickname)contact.detail(QContactNickname::DefinitionName); |
|
722 QCOMPARE(nickName.nickname(), QLatin1String("Homie")); |
|
723 |
|
724 // comma separated values should generate multiple nickname fields |
|
725 contact.clearDetails(); |
|
726 document.clear(); |
|
727 document.setType(QVersitDocument::VCard30Type); |
|
728 QStringList multiVal; |
|
729 multiVal.append(QString::fromAscii("Homie")); |
|
730 multiVal.append(QString::fromAscii("SuperHero")); |
|
731 multiVal.append(QString::fromAscii("NukeSpecialist")); |
|
732 nameProperty.setName(QString::fromAscii("NICKNAME")); |
|
733 nameProperty.setValue(multiVal); |
|
734 nameProperty.setValueType(QVersitProperty::ListType); |
|
735 document.addProperty(nameProperty); |
|
736 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
737 contact = mImporter->contacts().first(); |
|
738 QList<QContactDetail> nickNames = contact.details(QContactNickname::DefinitionName); |
|
739 QCOMPARE(nickNames.count(),3); |
|
740 nickName = static_cast<QContactNickname>(nickNames[0]); |
|
741 QCOMPARE(nickName.nickname(),QString::fromAscii("Homie")); |
|
742 nickName = static_cast<QContactNickname>(nickNames[1]); |
|
743 QCOMPARE(nickName.nickname(),QString::fromAscii("SuperHero")); |
|
744 nickName = static_cast<QContactNickname>(nickNames[2]); |
|
745 QCOMPARE(nickName.nickname(),QString::fromAscii("NukeSpecialist")); |
|
746 |
|
747 // X-NICKNAME |
|
748 document.clear(); |
|
749 document.setType(QVersitDocument::VCard30Type); |
|
750 nameProperty = QVersitProperty(); |
|
751 nameProperty.setName(QString::fromAscii("X-NICKNAME")); |
|
752 nameProperty.setValue(QStringList(QLatin1String("Homie"))); |
|
753 nameProperty.setValueType(QVersitProperty::ListType); |
|
754 document.addProperty(nameProperty); |
|
755 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
756 contact = mImporter->contacts().first(); |
|
757 nickName = contact.detail<QContactNickname>(); |
|
758 QCOMPARE(nickName.nickname(),QLatin1String("Homie")); |
|
759 } |
|
760 |
|
761 void tst_QVersitContactImporter::testAvatarThumbnail() |
|
762 { |
|
763 QByteArray gif(SAMPLE_GIF); |
|
764 QString name = QLatin1String("John Citizen"); |
|
765 QVersitDocument document = createDocumentWithNameAndPhoto(name, gif, QLatin1String("GIF")); |
|
766 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
767 QContact contact = mImporter->contacts().first(); |
|
768 QContactAvatar avatar = contact.detail<QContactAvatar>(); |
|
769 QByteArray content = mResourceHandler->mObjects.value(avatar.imageUrl()); |
|
770 QCOMPARE(content, gif); |
|
771 QContactThumbnail thumbnail = contact.detail<QContactThumbnail>(); |
|
772 QImage image(thumbnail.thumbnail()); |
|
773 QImage expectedImage; |
|
774 expectedImage.loadFromData(gif); |
|
775 QCOMPARE(image, expectedImage); |
|
776 |
|
777 // Without the resource handler, the thumbnail should still be set, but no avatar should be made |
|
778 mImporter->setResourceHandler(0); |
|
779 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
780 contact = mImporter->contacts().first(); |
|
781 QCOMPARE(contact.details<QContactAvatar>().size(), 0); |
|
782 thumbnail = contact.detail<QContactThumbnail>(); |
|
783 image = thumbnail.thumbnail(); |
|
784 QCOMPARE(image, expectedImage); |
|
785 |
|
786 mImporter->setResourceHandler(mResourceHandler); |
|
787 |
|
788 // Empty photo. The avatar should not be added to the QContact and the thumbnail will be empty. |
|
789 QVersitProperty property; |
|
790 property.setName(QLatin1String("PHOTO")); |
|
791 property.setValue(QByteArray()); |
|
792 document.clear(); |
|
793 document.setType(QVersitDocument::VCard30Type); |
|
794 document.addProperty(property); |
|
795 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
796 contact = mImporter->contacts().first(); |
|
797 QCOMPARE(contact.details<QContactAvatar>().size(), 0); |
|
798 thumbnail = contact.detail<QContactThumbnail>(); |
|
799 QVERIFY(thumbnail.isEmpty()); |
|
800 |
|
801 // Test multiple PHOTOs. The chosen Thumbnail should be the smallest image supplied. |
|
802 // All should be made into Avatars |
|
803 QByteArray nonPhoto(QByteArray::fromBase64("UXQgaXMgZ3JlYXQh")); // the string "Qt is great!" |
|
804 QByteArray bigPhoto(NOKIA_GIF); |
|
805 document.clear(); |
|
806 document.setType(QVersitDocument::VCard30Type); |
|
807 property.setName(QLatin1String("PHOTO")); |
|
808 property.setValue(nonPhoto); // shouldn't be the thumbnail because it's not an image |
|
809 document.addProperty(property); |
|
810 property.setValue(bigPhoto); // shouldn't be the thumbnail because it's not the smallest |
|
811 document.addProperty(property); |
|
812 property.setValue(gif); // should be the thumbnail |
|
813 document.addProperty(property); |
|
814 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
815 contact = mImporter->contacts().first(); |
|
816 QList<QContactThumbnail> thumbnails = contact.details<QContactThumbnail>(); |
|
817 QCOMPARE(thumbnails.size(), 1); |
|
818 thumbnail = thumbnails.first(); |
|
819 image = thumbnail.thumbnail(); |
|
820 QCOMPARE(image, expectedImage); |
|
821 QCOMPARE(contact.details<QContactAvatar>().size(), 3); |
|
822 } |
|
823 |
|
824 void tst_QVersitContactImporter::testAvatarUrl() |
|
825 { |
|
826 QVersitProperty property; |
|
827 property.setName(QLatin1String("PHOTO")); |
|
828 QString value(QLatin1String("http://example.com/example.jpg")); |
|
829 property.setValue(value); |
|
830 property.insertParameter(QLatin1String("VALUE"), QLatin1String("URL")); |
|
831 |
|
832 QVersitDocument document(QVersitDocument::VCard30Type); |
|
833 document.addProperty(property); |
|
834 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
835 QContact contact = mImporter->contacts().first(); |
|
836 QContactAvatar avatar = contact.detail<QContactAvatar>(); |
|
837 QCOMPARE(avatar.imageUrl(), QUrl(QLatin1String("http://example.com/example.jpg"))); |
|
838 |
|
839 |
|
840 // A URL disguised inside a QByteArray. |
|
841 document.clear(); |
|
842 document.setType(QVersitDocument::VCard30Type); |
|
843 property.clear(); |
|
844 property.setName(QLatin1String("PHOTO")); |
|
845 property.setValue(QByteArray("http://example.com/example.jpg")); |
|
846 property.insertParameter(QLatin1String("VALUE"), QLatin1String("URL")); |
|
847 property.insertParameter(QLatin1String("CHARSET"), QLatin1String("UTF-8")); |
|
848 document.addProperty(property); |
|
849 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
850 contact = mImporter->contacts().first(); |
|
851 avatar = contact.detail<QContactAvatar>(); |
|
852 QCOMPARE(avatar.imageUrl(), QUrl(QLatin1String("http://example.com/example.jpg"))); |
|
853 } |
|
854 |
|
855 void tst_QVersitContactImporter::testAvatarInvalid() |
|
856 { |
|
857 // An avatar that's a QVersitDocument? It shouldn't work. |
|
858 QVersitDocument document(QVersitDocument::VCard30Type); |
|
859 QVersitProperty property; |
|
860 property.setName(QLatin1String("PHOTO")); |
|
861 QVersitDocument nestedDocument; |
|
862 property.setValue(QVariant::fromValue(nestedDocument)); |
|
863 property.insertParameter(QLatin1String("VALUE"), QLatin1String("URL")); |
|
864 document.addProperty(property); |
|
865 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
866 QContact contact = mImporter->contacts().first(); |
|
867 QCOMPARE(contact.details(QContactAvatar::DefinitionName).size(), 0); |
|
868 |
|
869 document.clear(); |
|
870 document.setType(QVersitDocument::VCard30Type); |
|
871 property.clear(); |
|
872 property.setName(QLatin1String("PHOTO")); |
|
873 property.setValue(QVariant::fromValue(nestedDocument)); |
|
874 document.addProperty(property); |
|
875 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
876 contact = mImporter->contacts().first(); |
|
877 QCOMPARE(contact.details(QContactAvatar::DefinitionName).size(), 0); |
|
878 } |
|
879 |
|
880 void tst_QVersitContactImporter::testGeo() |
|
881 { |
|
882 // some positive values |
|
883 QVersitDocument document(QVersitDocument::VCard30Type); |
|
884 QVersitProperty nameProperty; |
|
885 QStringList val; |
|
886 val.append(QString::fromAscii("18.53"));// Longtitude |
|
887 val.append(QString::fromAscii("45.32")); // Latitude |
|
888 nameProperty.setName(QString::fromAscii("GEO")); |
|
889 nameProperty.setValue(val); |
|
890 nameProperty.setValueType(QVersitProperty::CompoundType); |
|
891 document.addProperty(nameProperty); |
|
892 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
893 QContact contact = mImporter->contacts().first(); |
|
894 QContactGeoLocation geo = (QContactGeoLocation)contact.detail(QContactGeoLocation::DefinitionName); |
|
895 QString str; |
|
896 str.setNum(geo.longitude(),'.',2); |
|
897 QCOMPARE(str,val[0]); |
|
898 str.setNum(geo.latitude(),'.',2); |
|
899 QCOMPARE(str,val[1]); |
|
900 |
|
901 // some negative values |
|
902 document.clear(); |
|
903 document.setType(QVersitDocument::VCard30Type); |
|
904 nameProperty = QVersitProperty(); |
|
905 val.append(QString::fromAscii("18.53"));// Longtitude |
|
906 val.append(QString::fromAscii("-45.32")); // Latitude |
|
907 nameProperty.setName(QString::fromAscii("GEO")); |
|
908 nameProperty.setValue(val); |
|
909 nameProperty.setValueType(QVersitProperty::CompoundType); |
|
910 document.addProperty(nameProperty); |
|
911 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
912 contact = mImporter->contacts().first(); |
|
913 geo = (QContactGeoLocation)contact.detail(QContactGeoLocation::DefinitionName); |
|
914 str.setNum(geo.longitude(),'.',2); |
|
915 QCOMPARE(str,val[0]); |
|
916 str.setNum(geo.latitude(),'.',2); |
|
917 QCOMPARE(str,val[1]); |
|
918 } |
|
919 |
|
920 void tst_QVersitContactImporter::testNote() |
|
921 { |
|
922 // single line value |
|
923 QVersitDocument document(QVersitDocument::VCard30Type); |
|
924 QVersitProperty nameProperty; |
|
925 QString val(QString::fromAscii("I will not sleep at my work -John")); |
|
926 nameProperty.setName(QString::fromAscii("NOTE")); |
|
927 nameProperty.setValue(val); |
|
928 document.addProperty(nameProperty); |
|
929 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
930 QContact contact = mImporter->contacts().first(); |
|
931 QContactNote note = (QContactNote)contact.detail(QContactNote::DefinitionName); |
|
932 QCOMPARE(note.note(),val); |
|
933 |
|
934 // Multiline value and quoted printable encoding |
|
935 document.clear(); |
|
936 document.setType(QVersitDocument::VCard30Type); |
|
937 nameProperty = QVersitProperty(); |
|
938 val = QString::fromAscii("My Dad acts like he belongs,=0D=0AHe belongs in the zoo.=0D=0A"); |
|
939 nameProperty.setName(QString::fromAscii("NOTE")); |
|
940 nameProperty.setValue(val); |
|
941 QMultiHash<QString,QString> params; |
|
942 params.insert(QString::fromAscii("QUOTED-PRINTABLE"),val); |
|
943 nameProperty.setParameters(params); |
|
944 document.addProperty(nameProperty); |
|
945 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
946 contact = mImporter->contacts().first(); |
|
947 note = (QContactNote)contact.detail(QContactNote::DefinitionName); |
|
948 QCOMPARE(note.note(),val); |
|
949 } |
|
950 |
|
951 void tst_QVersitContactImporter::testCustomLabel() |
|
952 { |
|
953 QVersitDocument document(QVersitDocument::VCard30Type); |
|
954 QVersitProperty nameProperty; |
|
955 QString val(QString::fromAscii("John Citizen")); |
|
956 nameProperty.setName(QString::fromAscii("FN")); |
|
957 nameProperty.setValue(val); |
|
958 document.addProperty(nameProperty); |
|
959 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
960 QContact contact = mImporter->contacts().first(); |
|
961 QContactName name = |
|
962 (QContactName)contact.detail(QContactName::DefinitionName); |
|
963 QCOMPARE(name.customLabel(),val); |
|
964 } |
|
965 |
|
966 void tst_QVersitContactImporter::testDisplayLabel() |
|
967 { |
|
968 QVersitDocument document(QVersitDocument::VCard30Type); |
|
969 QVersitProperty orgProperty; |
|
970 // ORG: should be used as last resort |
|
971 orgProperty.setName(QLatin1String("ORG")); |
|
972 orgProperty.setValue(QStringList(QLatin1String("org"))); |
|
973 orgProperty.setValueType(QVersitProperty::CompoundType); |
|
974 document.addProperty(orgProperty); |
|
975 |
|
976 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
977 QContact contact = mImporter->contacts().first(); |
|
978 QString displayLabel = contact.displayLabel(); |
|
979 QCOMPARE(displayLabel, QLatin1String("org")); |
|
980 |
|
981 // NICKNAME: should be used if FN and N don't exist |
|
982 QVersitProperty nickProperty; |
|
983 nickProperty.setName(QLatin1String("NICKNAME")); |
|
984 nickProperty.setValue(QStringList(QLatin1String("nick"))); |
|
985 nickProperty.setValueType(QVersitProperty::ListType); |
|
986 document.addProperty(nickProperty); |
|
987 |
|
988 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
989 contact = mImporter->contacts().first(); |
|
990 displayLabel = contact.displayLabel(); |
|
991 QCOMPARE(displayLabel, QLatin1String("nick")); |
|
992 |
|
993 // N: should be used in FN doesn't exist |
|
994 QVersitProperty nameProperty; |
|
995 nameProperty.setName(QLatin1String("N")); |
|
996 nameProperty.setValue(QStringList() |
|
997 << QLatin1String("last") |
|
998 << QLatin1String("first") |
|
999 << QLatin1String("middle") |
|
1000 << QLatin1String("prefix") |
|
1001 << QLatin1String("suffix")); |
|
1002 nameProperty.setValueType(QVersitProperty::CompoundType); |
|
1003 document.addProperty(nameProperty); |
|
1004 |
|
1005 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1006 contact = mImporter->contacts().first(); |
|
1007 displayLabel = contact.displayLabel(); |
|
1008 QCOMPARE(displayLabel, QLatin1String("prefix first middle last suffix")); |
|
1009 |
|
1010 // FN: should be used if it exists |
|
1011 QVersitProperty fnProperty; |
|
1012 fnProperty.setName(QLatin1String("FN")); |
|
1013 fnProperty.setValue(QLatin1String("fn")); |
|
1014 document.addProperty(fnProperty); |
|
1015 |
|
1016 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1017 contact = mImporter->contacts().first(); |
|
1018 displayLabel = contact.displayLabel(); |
|
1019 QCOMPARE(displayLabel, QLatin1String("fn")); |
|
1020 } |
|
1021 |
|
1022 void tst_QVersitContactImporter::testOnlineAccount() |
|
1023 { |
|
1024 QString accountUri(QString::fromAscii("sip:john.citizen@example.com")); |
|
1025 |
|
1026 // Plain X-SIP, no TYPE -> |
|
1027 QVersitDocument document(QVersitDocument::VCard30Type); |
|
1028 QVersitProperty property; |
|
1029 property.setName(QString::fromAscii("X-SIP")); |
|
1030 property.setValue(accountUri); |
|
1031 document.addProperty(property); |
|
1032 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1033 QContact contact = mImporter->contacts().first(); |
|
1034 QContactOnlineAccount onlineAccount = contact.detail<QContactOnlineAccount>(); |
|
1035 QCOMPARE(onlineAccount.accountUri(),accountUri); |
|
1036 QStringList subTypes = onlineAccount.subTypes(); |
|
1037 QCOMPARE(subTypes.count(),1); |
|
1038 QVERIFY(subTypes.first() == QContactOnlineAccount::SubTypeSip); |
|
1039 |
|
1040 // X-SIP;SWIS |
|
1041 document.clear(); |
|
1042 document.setType(QVersitDocument::VCard30Type); |
|
1043 property = QVersitProperty(); |
|
1044 property.setName(QString::fromAscii("X-SIP")); |
|
1045 property.setValue(accountUri); |
|
1046 QMultiHash<QString,QString> params; |
|
1047 params.insert(QString::fromAscii("TYPE"),QString::fromAscii("SWIS")); |
|
1048 property.setParameters(params); |
|
1049 document.addProperty(property); |
|
1050 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1051 contact = mImporter->contacts().first(); |
|
1052 onlineAccount = contact.detail<QContactOnlineAccount>(); |
|
1053 QCOMPARE(onlineAccount.accountUri(),accountUri); |
|
1054 subTypes = onlineAccount.subTypes(); |
|
1055 QCOMPARE(subTypes.count(),1); |
|
1056 QVERIFY(subTypes.first() == QContactOnlineAccount::SubTypeVideoShare); |
|
1057 |
|
1058 // X-SIP;VOIP |
|
1059 document.clear(); |
|
1060 document.setType(QVersitDocument::VCard30Type); |
|
1061 property = QVersitProperty(); |
|
1062 property.setName(QString::fromAscii("X-SIP")); |
|
1063 property.setValue(accountUri); |
|
1064 params.clear(); |
|
1065 params.insert(QString::fromAscii("TYPE"),QString::fromAscii("VOIP")); |
|
1066 property.setParameters(params); |
|
1067 document.addProperty(property); |
|
1068 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1069 contact = mImporter->contacts().first(); |
|
1070 onlineAccount = contact.detail<QContactOnlineAccount>(); |
|
1071 QCOMPARE(onlineAccount.accountUri(),accountUri); |
|
1072 subTypes = onlineAccount.subTypes(); |
|
1073 QCOMPARE(subTypes.count(),1); |
|
1074 QVERIFY(subTypes.first() == QContactOnlineAccount::SubTypeSipVoip); |
|
1075 |
|
1076 // X-IMPP |
|
1077 document.clear(); |
|
1078 document.setType(QVersitDocument::VCard30Type); |
|
1079 property = QVersitProperty(); |
|
1080 property.setName(QString::fromAscii("X-IMPP")); |
|
1081 property.setValue(accountUri); |
|
1082 document.addProperty(property); |
|
1083 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1084 contact = mImporter->contacts().first(); |
|
1085 onlineAccount = contact.detail<QContactOnlineAccount>(); |
|
1086 QCOMPARE(onlineAccount.accountUri(),accountUri); |
|
1087 subTypes = onlineAccount.subTypes(); |
|
1088 QCOMPARE(subTypes.count(),1); |
|
1089 QVERIFY(subTypes.first() == QContactOnlineAccount::SubTypeImpp); |
|
1090 |
|
1091 // IMPP |
|
1092 document.clear(); |
|
1093 document.setType(QVersitDocument::VCard30Type); |
|
1094 property = QVersitProperty(); |
|
1095 property.setName(QString::fromAscii("IMPP")); |
|
1096 property.setValue(accountUri); |
|
1097 document.addProperty(property); |
|
1098 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1099 contact = mImporter->contacts().first(); |
|
1100 onlineAccount = contact.detail<QContactOnlineAccount>(); |
|
1101 QCOMPARE(onlineAccount.accountUri(),accountUri); |
|
1102 subTypes = onlineAccount.subTypes(); |
|
1103 QCOMPARE(subTypes.count(),1); |
|
1104 QVERIFY(subTypes.first() == QContactOnlineAccount::SubTypeImpp); |
|
1105 |
|
1106 // X-JABBER |
|
1107 document.clear(); |
|
1108 document.setType(QVersitDocument::VCard30Type); |
|
1109 property = QVersitProperty(); |
|
1110 property.setName(QString::fromAscii("X-JABBER")); |
|
1111 property.setValue(accountUri); |
|
1112 document.addProperty(property); |
|
1113 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1114 contact = mImporter->contacts().first(); |
|
1115 onlineAccount = contact.detail<QContactOnlineAccount>(); |
|
1116 QCOMPARE(onlineAccount.accountUri(),accountUri); |
|
1117 subTypes = onlineAccount.subTypes(); |
|
1118 QCOMPARE(subTypes.count(),1); |
|
1119 QVERIFY(subTypes.first() == QContactOnlineAccount::SubTypeImpp); |
|
1120 } |
|
1121 |
|
1122 void tst_QVersitContactImporter::testFamily() |
|
1123 { |
|
1124 // Interesting : kid but no wife :) |
|
1125 QVersitDocument document(QVersitDocument::VCard30Type); |
|
1126 QVersitProperty nameProperty; |
|
1127 QString val(QString::fromAscii("Jane")); // one is enough |
|
1128 nameProperty.setName(QString::fromAscii("X-CHILDREN")); |
|
1129 nameProperty.setValue(QStringList(val)); |
|
1130 nameProperty.setValueType(QVersitProperty::ListType); |
|
1131 document.addProperty(nameProperty); |
|
1132 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1133 QContact contact = mImporter->contacts().first(); |
|
1134 QContactFamily family = (QContactFamily)contact.detail(QContactFamily::DefinitionName); |
|
1135 QStringList children = family.children(); |
|
1136 QCOMPARE(children.count(),1); // ensure no other kids in list |
|
1137 QCOMPARE(family.spouse(),QString()); // make sure no wife |
|
1138 QCOMPARE(children[0],val); // ensure it is your kid |
|
1139 |
|
1140 // Critical : wife but no kids , happy hours |
|
1141 document.clear(); |
|
1142 document.setType(QVersitDocument::VCard30Type); |
|
1143 nameProperty = QVersitProperty(); |
|
1144 nameProperty.setName(QString::fromAscii("X-SPOUSE")); |
|
1145 val = QString::fromAscii("Jenny"); |
|
1146 nameProperty.setValue(val); |
|
1147 document.addProperty(nameProperty); |
|
1148 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1149 contact = mImporter->contacts().first(); |
|
1150 family = (QContactFamily)contact.detail(QContactFamily::DefinitionName); |
|
1151 children = family.children(); |
|
1152 QCOMPARE(children.count(),0); // list should be empty as you know |
|
1153 QCOMPARE(family.spouse(),val); // make sure thats your wife:( |
|
1154 |
|
1155 // Hopeless : couple of kids and wife |
|
1156 document.clear(); |
|
1157 document.setType(QVersitDocument::VCard30Type); |
|
1158 // Add kids first |
|
1159 nameProperty = QVersitProperty(); |
|
1160 nameProperty.setName(QString::fromAscii("X-CHILDREN")); |
|
1161 QStringList kidsVal; |
|
1162 kidsVal.append(QString::fromAscii("James")); |
|
1163 kidsVal.append(QString::fromAscii("Jake")); |
|
1164 kidsVal.append(QString::fromAscii("Jane")); |
|
1165 nameProperty.setValue(kidsVal); |
|
1166 nameProperty.setValueType(QVersitProperty::ListType); |
|
1167 document.addProperty(nameProperty); |
|
1168 // Add wife next |
|
1169 val = QString::fromAscii("Jenny"); |
|
1170 nameProperty = QVersitProperty(); |
|
1171 nameProperty.setName(QString::fromAscii("X-SPOUSE")); |
|
1172 nameProperty.setValue(val); |
|
1173 document.addProperty(nameProperty); |
|
1174 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1175 contact = mImporter->contacts().first(); |
|
1176 family = (QContactFamily)contact.detail(QContactFamily::DefinitionName); |
|
1177 children = family.children(); |
|
1178 QCOMPARE(children.count(),3); // too late , count them now. |
|
1179 // painfull but ensure they are your kids |
|
1180 QCOMPARE(children, kidsVal); |
|
1181 QCOMPARE(family.spouse(),val); // make sure thats your wife:( |
|
1182 } |
|
1183 |
|
1184 void tst_QVersitContactImporter::testSound() |
|
1185 { |
|
1186 QVersitDocument document(QVersitDocument::VCard30Type); |
|
1187 QVersitProperty soundProperty; |
|
1188 QMultiHash<QString,QString> param; |
|
1189 param.insert(QString::fromAscii("TYPE"),QString::fromAscii("WAVE")); |
|
1190 soundProperty.setName(QString::fromAscii("SOUND")); |
|
1191 QByteArray val("111110000011111"); |
|
1192 soundProperty.setValue(val); |
|
1193 soundProperty.setParameters(param); |
|
1194 document.addProperty(soundProperty); |
|
1195 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1196 QContact contact = mImporter->contacts().first(); |
|
1197 QContactRingtone ringtone = contact.detail<QContactRingtone>(); |
|
1198 QByteArray content = mResourceHandler->mObjects.value(ringtone.audioRingtoneUrl()); |
|
1199 QCOMPARE(content, val); |
|
1200 } |
|
1201 |
|
1202 void tst_QVersitContactImporter::testTag() |
|
1203 { |
|
1204 // one value |
|
1205 QVersitDocument document(QVersitDocument::VCard30Type); |
|
1206 QVersitProperty tagProperty; |
|
1207 tagProperty.setName(QLatin1String("CATEGORIES")); |
|
1208 tagProperty.setValue(QStringList(QLatin1String("red"))); |
|
1209 tagProperty.setValueType(QVersitProperty::ListType); |
|
1210 document.addProperty(tagProperty); |
|
1211 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1212 QContact contact = mImporter->contacts().first(); |
|
1213 QContactTag tagDetail = contact.detail<QContactTag>(); |
|
1214 QCOMPARE(tagDetail.tag(), QLatin1String("red")); |
|
1215 |
|
1216 // multiple values |
|
1217 document.clear(); |
|
1218 document.setType(QVersitDocument::VCard30Type); |
|
1219 tagProperty.setName(QLatin1String("CATEGORIES")); |
|
1220 tagProperty.setValue(QStringList() |
|
1221 << QLatin1String("red") |
|
1222 << QLatin1String("green") |
|
1223 << QLatin1String("blue")); |
|
1224 tagProperty.setValueType(QVersitProperty::ListType); |
|
1225 document.addProperty(tagProperty); |
|
1226 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1227 contact = mImporter->contacts().first(); |
|
1228 QList<QContactTag> tagDetails = contact.details<QContactTag>(); |
|
1229 QCOMPARE(tagDetails.count(), 3); |
|
1230 QCOMPARE(tagDetails.at(0).tag(), QLatin1String("red")); |
|
1231 QCOMPARE(tagDetails.at(1).tag(), QLatin1String("green")); |
|
1232 QCOMPARE(tagDetails.at(2).tag(), QLatin1String("blue")); |
|
1233 } |
|
1234 |
|
1235 void tst_QVersitContactImporter::testPref() |
|
1236 { |
|
1237 QVersitDocument document(QVersitDocument::VCard30Type); |
|
1238 QVersitProperty property1; |
|
1239 property1.setName(QLatin1String("TEL")); |
|
1240 property1.setValue(QLatin1String("1")); |
|
1241 document.addProperty(property1); |
|
1242 QVersitProperty property2; |
|
1243 property2.setName(QLatin1String("TEL")); |
|
1244 property2.setValue(QLatin1String("2")); |
|
1245 property2.insertParameter(QLatin1String("TYPE"), QLatin1String("PREF")); |
|
1246 document.addProperty(property2); |
|
1247 QVersitProperty property3; |
|
1248 property3.setName(QLatin1String("TEL")); |
|
1249 property3.setValue(QLatin1String("3")); |
|
1250 property3.insertParameter(QLatin1String("TYPE"), QLatin1String("PREF")); |
|
1251 document.addProperty(property3); |
|
1252 QVersitProperty property4; |
|
1253 property4.setName(QLatin1String("TEL")); |
|
1254 property4.setValue(QLatin1String("4")); |
|
1255 document.addProperty(property4); |
|
1256 |
|
1257 // Test that pref details comes first. |
|
1258 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1259 QContact contact = mImporter->contacts().first(); |
|
1260 QContactPhoneNumber firstNumber = contact.detail<QContactPhoneNumber>(); |
|
1261 QCOMPARE(firstNumber.number(), QLatin1String("2")); |
|
1262 QList<QContactPhoneNumber> numbers = contact.details<QContactPhoneNumber>(); |
|
1263 QCOMPARE(numbers.at(0).number(), QLatin1String("2")); |
|
1264 QCOMPARE(numbers.at(1).number(), QLatin1String("3")); |
|
1265 QCOMPARE(numbers.at(2).number(), QLatin1String("1")); |
|
1266 QCOMPARE(numbers.at(3).number(), QLatin1String("4")); |
|
1267 } |
|
1268 |
|
1269 void tst_QVersitContactImporter::testPropertyHandler() |
|
1270 { |
|
1271 QVersitDocument document(QVersitDocument::VCard30Type); |
|
1272 QVersitProperty property; |
|
1273 |
|
1274 // No unconverted properties, no converted properties either. Fails with EmptyDocumentError |
|
1275 QVERIFY(!mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1276 QCOMPARE(mPropertyHandler->mUnknownProperties.size(), 0); |
|
1277 QCOMPARE(mPropertyHandler->mPreProcessedProperties.size(), 0); |
|
1278 QCOMPARE(mPropertyHandler->mPostProcessedProperties.size(), 0); |
|
1279 |
|
1280 // No unconverted properties, one converted property |
|
1281 mPropertyHandler->clear(); |
|
1282 property.setName(QString::fromAscii("FN")); |
|
1283 property.setValue(QString::fromAscii("John Citizen")); |
|
1284 document.addProperty(property); |
|
1285 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1286 QContact contact = mImporter->contacts().first(); |
|
1287 QCOMPARE(mPropertyHandler->mUnknownProperties.size(), 0); |
|
1288 QCOMPARE(mPropertyHandler->mPreProcessedProperties.size(), 1); |
|
1289 QCOMPARE(mPropertyHandler->mPostProcessedProperties.size(), 1); |
|
1290 |
|
1291 // Set the handler to override handling of the property |
|
1292 mPropertyHandler->clear(); |
|
1293 mPropertyHandler->mPreProcess = true; |
|
1294 document.clear(); |
|
1295 document.setType(QVersitDocument::VCard30Type); |
|
1296 property.setName(QString::fromAscii("FN")); |
|
1297 property.setValue(QString::fromAscii("John Citizen")); |
|
1298 document.addProperty(property); |
|
1299 QVERIFY(mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1300 contact = mImporter->contacts().first(); |
|
1301 QCOMPARE(mPropertyHandler->mUnknownProperties.size(), 0); |
|
1302 QCOMPARE(mPropertyHandler->mPreProcessedProperties.size(), 1); |
|
1303 QCOMPARE(mPropertyHandler->mPostProcessedProperties.size(), 0); |
|
1304 QContactDetail nameDetail = contact.detail(QContactName::DefinitionName); |
|
1305 QVERIFY(nameDetail.isEmpty()); |
|
1306 |
|
1307 // One unknown property |
|
1308 mPropertyHandler->clear(); |
|
1309 property.setName(QString::fromAscii("X-EXTENSION-1")); |
|
1310 property.setValue(QString::fromAscii("extension value 1")); |
|
1311 document.addProperty(property); |
|
1312 mImporter->importDocuments(QList<QVersitDocument>() << document); |
|
1313 QList<QVersitProperty> unknownProperties = mPropertyHandler->mUnknownProperties; |
|
1314 QCOMPARE(unknownProperties.count(), 1); |
|
1315 QCOMPARE(unknownProperties[0].name(), QString::fromAscii("X-EXTENSION-1")); |
|
1316 QCOMPARE(unknownProperties[0].value(), QString::fromAscii("extension value 1")); |
|
1317 |
|
1318 // Two unknown properties |
|
1319 mPropertyHandler->clear(); |
|
1320 property.setName(QString::fromAscii("X-EXTENSION-2")); |
|
1321 property.setValue(QString::fromAscii("extension value 2")); |
|
1322 document.addProperty(property); |
|
1323 mImporter->importDocuments(QList<QVersitDocument>() << document); |
|
1324 unknownProperties = mPropertyHandler->mUnknownProperties; |
|
1325 QCOMPARE(unknownProperties.count(), 2); |
|
1326 QCOMPARE(unknownProperties[0].name(), QString::fromAscii("X-EXTENSION-1")); |
|
1327 QCOMPARE(unknownProperties[0].value(), QString::fromAscii("extension value 1")); |
|
1328 QCOMPARE(unknownProperties[1].name(), QString::fromAscii("X-EXTENSION-2")); |
|
1329 QCOMPARE(unknownProperties[1].value(), QString::fromAscii("extension value 2")); |
|
1330 } |
|
1331 |
|
1332 void tst_QVersitContactImporter::testInvalidDocument() |
|
1333 { |
|
1334 // invalid document (invalid type) |
|
1335 QList<QVersitDocument> documents; |
|
1336 QVersitDocument document(QVersitDocument::InvalidType); |
|
1337 QVersitProperty nameProperty; |
|
1338 nameProperty.setName(QLatin1String("FN")); |
|
1339 nameProperty.setValue(QLatin1String("John Citizen")); |
|
1340 document.addProperty(nameProperty); |
|
1341 documents.append(document); |
|
1342 |
|
1343 // valid document in the same list |
|
1344 QVersitProperty telProperty; |
|
1345 telProperty.setName(QLatin1String("TEL")); |
|
1346 telProperty.setValue(QLatin1String("1234")); |
|
1347 document.addProperty(telProperty); |
|
1348 document.setType(QVersitDocument::VCard21Type); |
|
1349 documents.append(document); |
|
1350 QVERIFY(!mImporter->importDocuments(documents)); |
|
1351 QMap<int, QVersitContactImporter::Error> errors = mImporter->errors(); |
|
1352 QCOMPARE(errors.size(), 1); |
|
1353 QVERIFY(errors.contains(0)); |
|
1354 QVERIFY(errors.value(0) == QVersitContactImporter::InvalidDocumentError); |
|
1355 QList<QContact> contacts = mImporter->contacts(); |
|
1356 QCOMPARE(contacts.size(), 1); |
|
1357 QContactPhoneNumber phoneDetail = contacts.first().detail<QContactPhoneNumber>(); |
|
1358 QCOMPARE(phoneDetail.number(), QLatin1String("1234")); |
|
1359 |
|
1360 // empty document |
|
1361 document.clear(); |
|
1362 document.setType(QVersitDocument::VCard21Type); |
|
1363 QVERIFY(!mImporter->importDocuments(QList<QVersitDocument>() << document)); |
|
1364 errors = mImporter->errors(); |
|
1365 QCOMPARE(errors.size(), 1); |
|
1366 QCOMPARE(errors.value(0), QVersitContactImporter::EmptyDocumentError); |
|
1367 } |
|
1368 |
|
1369 QVersitDocument tst_QVersitContactImporter::createDocumentWithProperty( |
|
1370 const QVersitProperty& property) |
|
1371 { |
|
1372 QVersitDocument document(QVersitDocument::VCard30Type); |
|
1373 document.addProperty(property); |
|
1374 return document; |
|
1375 } |
|
1376 |
|
1377 QVersitDocument tst_QVersitContactImporter::createDocumentWithNameAndPhoto( |
|
1378 const QString& name, |
|
1379 QByteArray image, |
|
1380 const QString& imageType) |
|
1381 { |
|
1382 QVersitDocument document(QVersitDocument::VCard30Type); |
|
1383 |
|
1384 QVersitProperty nameProperty; |
|
1385 nameProperty.setName(QString::fromAscii("FN")); |
|
1386 nameProperty.setValue(name); |
|
1387 document.addProperty(nameProperty); |
|
1388 |
|
1389 QVersitProperty property; |
|
1390 property.setName(QString::fromAscii("PHOTO")); |
|
1391 property.setValue(image); |
|
1392 if (imageType != QString()) { |
|
1393 property.insertParameter(QString::fromAscii("TYPE"), imageType); |
|
1394 } |
|
1395 document.addProperty(property); |
|
1396 |
|
1397 return document; |
|
1398 } |
|
1399 |
|
1400 QTEST_MAIN(tst_QVersitContactImporter) |
|
1401 |