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 "ut_qversitcontactexporter.h" |
|
43 #include "qversitcontactexporter.h" |
|
44 #include "qversitcontactexporter_p.h" |
|
45 #include "qversitproperty.h" |
|
46 #include "qversitdefs_p.h" |
|
47 #include <QString> |
|
48 #include <QStringList> |
|
49 #include <QList> |
|
50 #include <QPixmap> |
|
51 #include <QImageWriter> |
|
52 #include <QtTest/QtTest> |
|
53 #include <qcontact.h> |
|
54 #include <qcontactaddress.h> |
|
55 #include <qcontactemailaddress.h> |
|
56 #include <qcontactname.h> |
|
57 #include <qcontactphonenumber.h> |
|
58 #include <qcontacturl.h> |
|
59 #include <qcontactguid.h> |
|
60 #include <qcontacttimestamp.h> |
|
61 #include <qcontactbirthday.h> |
|
62 #include <qcontactnote.h> |
|
63 #include <qcontactgeolocation.h> |
|
64 #include <qcontactorganization.h> |
|
65 #include <qcontactavatar.h> |
|
66 #include <qcontactgender.h> |
|
67 #include <qcontactnickname.h> |
|
68 #include <qcontactanniversary.h> |
|
69 #include <qcontactonlineaccount.h> |
|
70 #include <qcontactfamily.h> |
|
71 #include <qcontactdisplaylabel.h> |
|
72 |
|
73 QTM_BEGIN_NAMESPACE |
|
74 |
|
75 class MyQVersitContactExporterDetailHandler : public QVersitContactExporterDetailHandler |
|
76 { |
|
77 public: |
|
78 MyQVersitContactExporterDetailHandler() : mPreProcess(false) |
|
79 { |
|
80 } |
|
81 |
|
82 bool preProcessDetail(const QContact& contact, |
|
83 const QContactDetail& detail, |
|
84 QVersitDocument* document) |
|
85 { |
|
86 Q_UNUSED(contact) |
|
87 Q_UNUSED(document) |
|
88 mPreProcessedDetails.append(detail); |
|
89 return mPreProcess; |
|
90 } |
|
91 |
|
92 bool postProcessDetail(const QContact& contact, |
|
93 const QContactDetail& detail, |
|
94 bool alreadyProcessed, |
|
95 QVersitDocument* document) |
|
96 { |
|
97 Q_UNUSED(contact) |
|
98 Q_UNUSED(document) |
|
99 if (!alreadyProcessed) |
|
100 mUnknownDetails.append(detail); |
|
101 else |
|
102 mPostProcessedDetails.append(detail); |
|
103 return false; |
|
104 } |
|
105 |
|
106 void clear() |
|
107 { |
|
108 mPreProcess = false; |
|
109 mDefinitionNamesToProcess.clear(); |
|
110 mUnknownDetails.clear(); |
|
111 mPreProcessedDetails.clear(); |
|
112 mPostProcessedDetails.clear(); |
|
113 } |
|
114 |
|
115 // a hook to control what preProcess returns: |
|
116 bool mPreProcess; |
|
117 QStringList mDefinitionNamesToProcess; |
|
118 QList<QContactDetail> mUnknownDetails; |
|
119 QList<QContactDetail> mPreProcessedDetails; |
|
120 QList<QContactDetail> mPostProcessedDetails; |
|
121 }; |
|
122 |
|
123 class MyQVersitResourceHandler : public QVersitResourceHandler |
|
124 { |
|
125 public: |
|
126 MyQVersitResourceHandler() |
|
127 : mLoadResourceCalled(false), |
|
128 mLoadSuccess(true) |
|
129 { |
|
130 } |
|
131 |
|
132 bool loadResource(const QString& location, QByteArray* contents, QString* mimeType) |
|
133 { |
|
134 mLocation = location; |
|
135 *contents = mSimulatedData; |
|
136 *mimeType = mSimulatedMimeType; |
|
137 mLoadResourceCalled = true; |
|
138 return mLoadSuccess; |
|
139 } |
|
140 |
|
141 bool saveResource(const QByteArray &contents, const QVersitProperty &property, QString *location) |
|
142 { |
|
143 Q_UNUSED(contents) |
|
144 Q_UNUSED(property) |
|
145 Q_UNUSED(location) |
|
146 return false; |
|
147 } |
|
148 |
|
149 void clear() |
|
150 { |
|
151 mSimulatedData.clear(); |
|
152 mSimulatedMimeType.clear(); |
|
153 mLocation.clear(); |
|
154 mLoadResourceCalled = false; |
|
155 mLoadSuccess = true; |
|
156 } |
|
157 |
|
158 QByteArray mSimulatedData; |
|
159 QString mSimulatedMimeType; |
|
160 QString mLocation; |
|
161 bool mLoadResourceCalled; |
|
162 bool mLoadSuccess; // A hook to control what loadResource returns. |
|
163 }; |
|
164 |
|
165 const static QByteArray SAMPLE_GIF(QByteArray::fromBase64( |
|
166 "R0lGODlhEgASAIAAAAAAAP///yH5BAEAAAEALAAAAAASABIAAAIdjI+py+0G" |
|
167 "wEtxUmlPzRDnzYGfN3KBaKGT6rDmGxQAOw==")); |
|
168 |
|
169 QTM_END_NAMESPACE |
|
170 |
|
171 QTM_USE_NAMESPACE |
|
172 |
|
173 const QString TEST_PHOTO_FILE(QLatin1String("versitTest001.jpg")); |
|
174 const QString TEST_AUDIO_FILE(QLatin1String("versitTest001.wav")); |
|
175 |
|
176 void UT_QVersitContactExporter::init() |
|
177 { |
|
178 mExporter = new QVersitContactExporter(); |
|
179 mDetailHandler = new MyQVersitContactExporterDetailHandler; |
|
180 mExporter->setDetailHandler(mDetailHandler); |
|
181 mResourceHandler = new MyQVersitResourceHandler; |
|
182 mExporter->setResourceHandler(mResourceHandler); |
|
183 } |
|
184 |
|
185 void UT_QVersitContactExporter::cleanup() |
|
186 { |
|
187 QVERIFY(mExporter->detailHandler() == mDetailHandler); |
|
188 mExporter->setDetailHandler(0); |
|
189 delete mDetailHandler; |
|
190 QVERIFY(mExporter->resourceHandler() == mResourceHandler); |
|
191 mExporter->setResourceHandler(0); |
|
192 delete mResourceHandler; |
|
193 delete mExporter; |
|
194 } |
|
195 |
|
196 void UT_QVersitContactExporter::testConvertContact() |
|
197 { |
|
198 QContact contact; |
|
199 |
|
200 // Adding name to the contact |
|
201 QContactName name; |
|
202 name.setFirstName(QString::fromAscii("Moido")); |
|
203 contact.saveDetail(&name); |
|
204 |
|
205 // Adding phone number to the Contact. |
|
206 QContactPhoneNumber phoneNumber; |
|
207 phoneNumber.setNumber(QString::fromAscii("12345678")); |
|
208 contact.saveDetail(&phoneNumber); |
|
209 |
|
210 // Convert contact into versit properties |
|
211 QList<QContact> list; |
|
212 list.append(contact); |
|
213 QList<QVersitDocument> documents = mExporter->exportContacts(list); |
|
214 |
|
215 // Each Contact has display label detail by default. Display label is enocded |
|
216 // if some value exisit for the Label or if value for Name exisit. |
|
217 QCOMPARE(documents.size(), 1); |
|
218 QCOMPARE(documents.first().properties().count(), 3); |
|
219 } |
|
220 |
|
221 void UT_QVersitContactExporter::testContactDetailHandler() |
|
222 { |
|
223 // Test1: Un-supported Avatar Test |
|
224 QContact contact; |
|
225 QVersitDocument document; |
|
226 QContactAvatar contactAvatar; |
|
227 contactAvatar.setSubType(QContactAvatar::SubTypeTexturedMesh); |
|
228 contact.saveDetail(&contactAvatar); |
|
229 QList<QContact> contacts; |
|
230 contacts.append(contact); |
|
231 document = mExporter->exportContacts(contacts).first(); |
|
232 QCOMPARE(document.properties().count(), 0); |
|
233 QList<QContactDetail> unknownDetails = mDetailHandler->mUnknownDetails; |
|
234 QVERIFY(unknownDetails.size() > 0); |
|
235 QString definitionName = contactAvatar.definitionName(); |
|
236 QContactDetail detail = searchDetail(unknownDetails,definitionName); |
|
237 QCOMPARE(definitionName, detail.definitionName()); |
|
238 |
|
239 // Test2: Un-supported Online Account |
|
240 QContactOnlineAccount onlineAccount; |
|
241 QString testUri = QString::fromAscii("sip:abc@temp.com"); |
|
242 onlineAccount.setAccountUri(testUri); |
|
243 onlineAccount.setSubTypes(QString::fromAscii("unsupported")); |
|
244 contact.saveDetail(&onlineAccount); |
|
245 contacts.clear(); |
|
246 contacts.append(contact); |
|
247 mDetailHandler->clear(); |
|
248 document = mExporter->exportContacts(contacts).first(); |
|
249 QCOMPARE(document.properties().count(), 0); |
|
250 unknownDetails = mDetailHandler->mUnknownDetails; |
|
251 QVERIFY(unknownDetails.size() > 0); |
|
252 definitionName = onlineAccount.definitionName(); |
|
253 detail = searchDetail(unknownDetails, definitionName); |
|
254 QCOMPARE(definitionName, detail.definitionName()); |
|
255 |
|
256 // Test that preProcessDetail return true stops the exporter from doing anything. |
|
257 contact.clearDetails(); |
|
258 QContactName contactName; |
|
259 contactName.setFirstName(QLatin1String("John")); |
|
260 contact.saveDetail(&contactName); |
|
261 mDetailHandler->clear(); |
|
262 mDetailHandler->mPreProcess = true; |
|
263 contacts.clear(); |
|
264 contacts.append(contact); |
|
265 document = mExporter->exportContacts(contacts).first(); |
|
266 QCOMPARE(document.properties().count(), 0); |
|
267 QVERIFY(mDetailHandler->mPreProcessedDetails.count() > 0); |
|
268 QCOMPARE(mDetailHandler->mPostProcessedDetails.count(), 0); |
|
269 QCOMPARE(mDetailHandler->mUnknownDetails.count(), 0); |
|
270 |
|
271 QVERIFY(mExporter->detailHandler() == mDetailHandler); |
|
272 } |
|
273 |
|
274 void UT_QVersitContactExporter::testEncodeName() |
|
275 { |
|
276 QContact contact; |
|
277 QContactName name; |
|
278 |
|
279 // vCard 2.1 |
|
280 name.setFirstName(QString::fromAscii("Heido")); |
|
281 name.setLastName(QString::fromAscii("HH")); |
|
282 name.setMiddleName(QString::fromAscii("A")); |
|
283 name.setPrefix(QString::fromAscii("Mr.")); |
|
284 name.setContexts(QContactDetail::ContextHome); |
|
285 contact.saveDetail(&name); |
|
286 QList<QContact> contacts; |
|
287 contacts.append(contact); |
|
288 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
289 |
|
290 // Each Contact has display label detail by default. Display label is enocded |
|
291 // if some value exisit for the Label or if value for Name exisit. |
|
292 QCOMPARE(document.properties().count(), 2); |
|
293 |
|
294 QVersitProperty displayProperty = document.properties().at(0); |
|
295 // Check name |
|
296 QCOMPARE(displayProperty.name(), QString::fromAscii("FN")); |
|
297 // Check value |
|
298 QCOMPARE(displayProperty.value(), QString::fromAscii("Heido HH")); |
|
299 |
|
300 QVersitProperty nameProperty = document.properties().at(1); |
|
301 // Check parameters, contexts not allowed for N property |
|
302 QCOMPARE(nameProperty.parameters().count(), 0); |
|
303 // Check name |
|
304 QCOMPARE(nameProperty.name(), QString::fromAscii("N")); |
|
305 // Check value |
|
306 QCOMPARE(nameProperty.value(), QString::fromAscii("HH;Heido;A;Mr.;")); |
|
307 |
|
308 // vCard 3.0, special characters in the name parts are backslash escaped |
|
309 contact.removeDetail(&name); |
|
310 name.setFirstName(QString::fromAscii("Hom,er")); |
|
311 name.setLastName(QString::fromAscii("Simp;son")); |
|
312 name.setMiddleName(QString::fromAscii("J;")); |
|
313 name.setPrefix(QString::fromAscii(";Mr.")); |
|
314 name.setSuffix(QString::fromAscii("Sir,")); |
|
315 contact.saveDetail(&name); |
|
316 contacts.clear(); |
|
317 contacts.append(contact); |
|
318 document = mExporter->exportContacts(contacts, QVersitDocument::VCard30Type).first(); |
|
319 QCOMPARE(document.type(),QVersitDocument::VCard30Type); |
|
320 |
|
321 // Each Contact has display label detail by default. Display label is enocded |
|
322 // if some value exists for the Label or if value for Name exisit. |
|
323 QCOMPARE(document.properties().count(), 2); |
|
324 displayProperty = document.properties().at(0); |
|
325 nameProperty = document.properties().at(1); |
|
326 // Check parameters |
|
327 QCOMPARE(displayProperty.parameters().count(), 0); |
|
328 QCOMPARE(nameProperty.parameters().count(), 0); |
|
329 // Check name |
|
330 QCOMPARE(displayProperty.name(), QString::fromAscii("FN")); |
|
331 QCOMPARE(nameProperty.name(), QString::fromAscii("N")); |
|
332 // Check value |
|
333 |
|
334 QCOMPARE(displayProperty.value(), QString::fromAscii("Hom\\,er Simp\\;son")); |
|
335 |
|
336 QCOMPARE(nameProperty.value(), |
|
337 QString::fromAscii("Simp\\;son;Hom\\,er;J\\;;\\;Mr.;Sir\\,")); |
|
338 } |
|
339 |
|
340 void UT_QVersitContactExporter::testEncodePhoneNumber() |
|
341 { |
|
342 QContact contact; |
|
343 QContactPhoneNumber phoneNumber; |
|
344 phoneNumber.setNumber(QString::fromAscii("12345678")); |
|
345 phoneNumber.setContexts(QContactDetail::ContextHome); |
|
346 phoneNumber.setSubTypes(QContactPhoneNumber::SubTypeMobile); |
|
347 contact.saveDetail(&phoneNumber); |
|
348 QList<QContact> contacts; |
|
349 contacts.append(contact); |
|
350 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
351 QCOMPARE(document.properties().count(), 1); |
|
352 QVersitProperty property = document.properties().at(0); |
|
353 // Check parameters |
|
354 QCOMPARE(property.parameters().count(), 2); |
|
355 QVERIFY(property.parameters().contains( |
|
356 QString::fromAscii("TYPE"),QString::fromAscii("HOME"))); |
|
357 QVERIFY(property.parameters().contains( |
|
358 QString::fromAscii("TYPE"),QString::fromAscii("CELL"))); |
|
359 // Check name |
|
360 QCOMPARE(property.name(), QString::fromAscii("TEL")); |
|
361 // Check value |
|
362 QCOMPARE(property.value(), phoneNumber.number()); |
|
363 } |
|
364 |
|
365 void UT_QVersitContactExporter::testEncodeEmailAddress() |
|
366 { |
|
367 QContact contact; |
|
368 QContactEmailAddress email; |
|
369 email.setEmailAddress(QString::fromAscii("test@test")); |
|
370 email.setContexts(QContactDetail::ContextHome); |
|
371 contact.saveDetail(&email); |
|
372 QList<QContact> contacts; |
|
373 contacts.append(contact); |
|
374 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
375 QCOMPARE(document.properties().count(), 1); |
|
376 QVersitProperty property = document.properties().at(0); |
|
377 // Check parameters |
|
378 QCOMPARE(property.parameters().count(), 1); |
|
379 QVERIFY(property.parameters().contains( |
|
380 QString::fromAscii("TYPE"),QString::fromAscii("HOME"))); |
|
381 // Check name |
|
382 QCOMPARE(property.name(), QString::fromAscii("EMAIL")); |
|
383 // Check value |
|
384 QCOMPARE(property.value(), email.emailAddress()); |
|
385 } |
|
386 |
|
387 void UT_QVersitContactExporter::testEncodeStreetAddress() |
|
388 { |
|
389 QContact contact; |
|
390 QContactAddress address; |
|
391 |
|
392 // vCard 2.1 |
|
393 address.setCountry(QString::fromAscii("Finland")); |
|
394 address.setPostcode(QString::fromAscii("00440")); |
|
395 address.setStreet(QString::fromAscii("HKKI 1X 90")); |
|
396 address.setLocality(QString::fromAscii("Helsinki")); |
|
397 address.setContexts(QContactDetail::ContextHome); |
|
398 address.setSubTypes(QContactAddress::SubTypePostal); |
|
399 contact.saveDetail(&address); |
|
400 QList<QContact> contacts; |
|
401 contacts.append(contact); |
|
402 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
403 QCOMPARE(document.properties().count(), 1); |
|
404 QVersitProperty property = document.properties().at(0); |
|
405 // Check parameters |
|
406 QCOMPARE(property.parameters().count(), 2); |
|
407 QVERIFY(property.parameters().contains( |
|
408 QString::fromAscii("TYPE"),QString::fromAscii("HOME"))); |
|
409 QVERIFY(property.parameters().contains( |
|
410 QString::fromAscii("TYPE"),QString::fromAscii("POSTAL"))); |
|
411 // Check name |
|
412 QCOMPARE(property.name(), QString::fromAscii("ADR")); |
|
413 // Check value |
|
414 QCOMPARE(property.value(), QString::fromAscii(";;HKKI 1X 90;Helsinki;;00440;Finland")); |
|
415 |
|
416 // vCard 3.0, special characters in the address parts are backslash escaped |
|
417 contact.removeDetail(&address); |
|
418 address.setPostOfficeBox(QString::fromAscii("PO;Box")); |
|
419 address.setStreet(QString::fromAscii("My;Street")); |
|
420 address.setLocality(QString::fromAscii("My;Town")); |
|
421 address.setRegion(QString::fromAscii("My;State")); |
|
422 address.setPostcode(QString::fromAscii("12345;")); |
|
423 address.setCountry(QString::fromAscii("My;Country")); |
|
424 contact.saveDetail(&address); |
|
425 contacts.clear(); |
|
426 contacts.append(contact); |
|
427 document = mExporter->exportContacts(contacts, QVersitDocument::VCard30Type).first(); |
|
428 QCOMPARE(document.type(),QVersitDocument::VCard30Type); |
|
429 QCOMPARE(document.properties().count(), 1); |
|
430 property = document.properties().at(0); |
|
431 // Check name |
|
432 QCOMPARE(property.name(), QString::fromAscii("ADR")); |
|
433 // Check value |
|
434 QCOMPARE(property.value(), |
|
435 QString::fromAscii("PO\\;Box;;My\\;Street;My\\;Town;My\\;State;12345\\;;My\\;Country")); |
|
436 } |
|
437 |
|
438 void UT_QVersitContactExporter::testEncodeUrl() |
|
439 { |
|
440 QContact contact; |
|
441 QContactUrl url; |
|
442 url.setUrl(QString::fromAscii("http://www.myhome.com")); |
|
443 url.setContexts(QContactDetail::ContextHome); |
|
444 url.setSubType(QContactUrl::SubTypeHomePage); |
|
445 contact.saveDetail(&url); |
|
446 QList<QContact> contacts; |
|
447 contacts.append(contact); |
|
448 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
449 QCOMPARE(document.properties().count(), 1); |
|
450 QVersitProperty property = document.properties().at(0); |
|
451 // Check parameters |
|
452 QCOMPARE(property.parameters().count(), 1); |
|
453 QVERIFY(property.parameters().contains( |
|
454 QString::fromAscii("TYPE"),QString::fromAscii("HOME"))); |
|
455 // Check name |
|
456 QCOMPARE(property.name(), QString::fromAscii("URL")); |
|
457 // Check value |
|
458 QCOMPARE(property.value(), url.url()); |
|
459 } |
|
460 |
|
461 void UT_QVersitContactExporter::testEncodeUid() |
|
462 { |
|
463 QContact contact; |
|
464 QContactGuid guid; |
|
465 |
|
466 // vCard 2.1 |
|
467 guid.setContexts(QContactDetail::ContextHome); |
|
468 guid.setGuid(QString::fromAscii("0101222")); |
|
469 contact.saveDetail(&guid); |
|
470 QList<QContact> contacts; |
|
471 contacts.append(contact); |
|
472 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
473 QCOMPARE(document.properties().count(), 1); |
|
474 QVersitProperty property = document.properties().at(0); |
|
475 // Check parameters |
|
476 // Contexts are not allowed for UID |
|
477 QCOMPARE(property.parameters().count(), 0); |
|
478 // Check name |
|
479 QCOMPARE(property.name(), QString::fromAscii("UID")); |
|
480 // Check value |
|
481 QCOMPARE(property.value(), guid.guid()); |
|
482 |
|
483 // vCard 3.0, special characters in the value are backslash escaped |
|
484 contact.removeDetail(&guid); |
|
485 guid.setGuid(QString::fromAscii("1;2,3\r\n4\\5")); |
|
486 contact.saveDetail(&guid); |
|
487 contacts.clear(); |
|
488 contacts.append(contact); |
|
489 document = mExporter->exportContacts(contacts, QVersitDocument::VCard30Type).first(); |
|
490 QCOMPARE(document.type(),QVersitDocument::VCard30Type); |
|
491 QCOMPARE(document.properties().count(), 1); |
|
492 property = document.properties().at(0); |
|
493 // Check name |
|
494 QCOMPARE(property.name(), QString::fromAscii("UID")); |
|
495 // Check value |
|
496 QCOMPARE(property.value(), QString::fromAscii("1\\;2\\,3\\n4\\\\5")); |
|
497 } |
|
498 |
|
499 void UT_QVersitContactExporter::testEncodeRev() |
|
500 { |
|
501 QContact contact; |
|
502 QContactTimestamp timeStamp; |
|
503 |
|
504 // Last modified time found |
|
505 QDateTime revisionTime = |
|
506 QDateTime::fromString( |
|
507 QString::fromAscii("M1d1y200906:01:02"), |
|
508 QString::fromAscii("'M'M'd'd'y'yyyyhh:mm:ss")); |
|
509 revisionTime.setTimeSpec(Qt::UTC); |
|
510 timeStamp.setLastModified(revisionTime); |
|
511 // Contexts not allowed in REV property, check that they are not added |
|
512 timeStamp.setContexts(QContactDetail::ContextHome); |
|
513 contact.saveDetail(&timeStamp); |
|
514 QList<QContact> contacts; |
|
515 contacts.append(contact); |
|
516 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
517 QCOMPARE(document.properties().count(), 1); |
|
518 QVersitProperty property = document.properties().at(0); |
|
519 QCOMPARE(property.parameters().count(), 0); |
|
520 QCOMPARE(property.name(), QString::fromAscii("REV")); |
|
521 QString expectedValueUTCEncoded = QString::fromAscii("2009-01-01T06:01:02Z"); |
|
522 QCOMPARE(property.value(), expectedValueUTCEncoded); |
|
523 |
|
524 // Last modified time not found, use the creation time |
|
525 QDateTime emptyTime; |
|
526 timeStamp.setLastModified(emptyTime); |
|
527 timeStamp.setCreated(revisionTime); |
|
528 contact.saveDetail(&timeStamp); |
|
529 contacts.clear(); |
|
530 contacts.append(contact); |
|
531 document = mExporter->exportContacts(contacts).first(); |
|
532 QCOMPARE(document.properties().count(), 1); |
|
533 property = document.properties().at(0); |
|
534 QCOMPARE(property.value(), expectedValueUTCEncoded); |
|
535 |
|
536 // Last modified time found, Local Time spec not UTC |
|
537 QDateTime localTime; |
|
538 timeStamp.setLastModified(revisionTime); |
|
539 timeStamp.setCreated(localTime); |
|
540 revisionTime.setTimeSpec(Qt::LocalTime); |
|
541 contact.saveDetail(&timeStamp); |
|
542 contacts.clear(); |
|
543 contacts.append(contact); |
|
544 document = mExporter->exportContacts(contacts).first(); |
|
545 QCOMPARE(document.properties().count(), 1); |
|
546 property = document.properties().at(0); |
|
547 QString expectedValueEncoded = QString::fromAscii("2009-01-01T06:01:02"); |
|
548 QCOMPARE(property.value(), expectedValueUTCEncoded); |
|
549 |
|
550 // Last modified time not found, creation time not found |
|
551 timeStamp.setLastModified(emptyTime); |
|
552 timeStamp.setCreated(emptyTime); |
|
553 contact.saveDetail(&timeStamp); |
|
554 contacts.clear(); |
|
555 contacts.append(contact); |
|
556 document = mExporter->exportContacts(contacts).first(); |
|
557 QCOMPARE(document.properties().count(), 0); |
|
558 } |
|
559 |
|
560 void UT_QVersitContactExporter::testEncodeBirthDay() |
|
561 { |
|
562 QContact contact; |
|
563 QDate date(2009,1,1); |
|
564 QContactBirthday birthDay; |
|
565 birthDay.setDate(date); |
|
566 // Contexts not allowed in BDAY property, check that they are not added |
|
567 birthDay.setContexts(QContactDetail::ContextHome); |
|
568 contact.saveDetail(&birthDay); |
|
569 QList<QContact> contacts; |
|
570 contacts.append(contact); |
|
571 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
572 QCOMPARE(document.properties().count(), 1); |
|
573 QVersitProperty property = document.properties().at(0); |
|
574 QCOMPARE(property.parameters().count(), 0); |
|
575 QCOMPARE(property.name(), QString::fromAscii("BDAY")); |
|
576 QCOMPARE(property.value(), QString::fromAscii("2009-01-01")); |
|
577 } |
|
578 |
|
579 void UT_QVersitContactExporter::testEncodeNote() |
|
580 { |
|
581 QContact contact; |
|
582 QContactNote note; |
|
583 note.setNote(QString::fromAscii("My Note")); |
|
584 // Contexts not allowed in NOTE property, check that they are not added |
|
585 note.setContexts(QContactDetail::ContextHome); |
|
586 contact.saveDetail(¬e); |
|
587 QList<QContact> contacts; |
|
588 contacts.append(contact); |
|
589 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
590 QCOMPARE(document.properties().count(), 1); |
|
591 QVersitProperty property = document.properties().at(0); |
|
592 QCOMPARE(property.parameters().count(), 0); |
|
593 QCOMPARE(property.name(), QString::fromAscii("NOTE")); |
|
594 QCOMPARE(property.value(), note.note()); |
|
595 } |
|
596 |
|
597 void UT_QVersitContactExporter::testEncodeGeoLocation() |
|
598 { |
|
599 QContact contact; |
|
600 QContactGeoLocation geoLocation; |
|
601 QString longitude = QString::fromAscii("99.9"); |
|
602 geoLocation.setLongitude(longitude.toDouble()); |
|
603 QString latitude = QString::fromAscii("98.9"); |
|
604 geoLocation.setLatitude(latitude.toDouble()); |
|
605 // Contexts not allowed in GEO property, check that they are not added |
|
606 geoLocation.setContexts(QContactDetail::ContextHome); |
|
607 contact.saveDetail(&geoLocation); |
|
608 QList<QContact> contacts; |
|
609 contacts.append(contact); |
|
610 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
611 QCOMPARE(document.properties().count(), 1); |
|
612 QVersitProperty property = document.properties().at(0); |
|
613 QCOMPARE(property.parameters().count(), 0); |
|
614 QCOMPARE(property.name(), QString::fromAscii("GEO")); |
|
615 QString expectedValue = longitude + QString::fromAscii(",") + latitude; |
|
616 QCOMPARE(property.value(), expectedValue); |
|
617 } |
|
618 |
|
619 void UT_QVersitContactExporter::testEncodeOrganization() |
|
620 { |
|
621 QList<QContact> contacts; |
|
622 QContact contact; |
|
623 QContactOrganization organization; |
|
624 QVersitDocument document; |
|
625 QVersitProperty property; |
|
626 QString title(QString::fromAscii("Developer")); |
|
627 QString organizationName(QString::fromAscii("Nokia")); |
|
628 QString department(QString::fromAscii("R&D")); |
|
629 |
|
630 // TITLE |
|
631 organization.setTitle(title); |
|
632 contact.saveDetail(&organization); |
|
633 contacts.clear(); |
|
634 contacts.append(contact); |
|
635 document = mExporter->exportContacts(contacts).first(); |
|
636 QCOMPARE(document.properties().count(), 1); |
|
637 property = document.properties().at(0); |
|
638 QCOMPARE(property.name(), QString::fromAscii("TITLE")); |
|
639 QCOMPARE(property.value(), title); |
|
640 |
|
641 // ORG with name |
|
642 organization.setTitle(QString()); |
|
643 organization.setName(QString::fromAscii("Nokia")); |
|
644 contact.saveDetail(&organization); |
|
645 contacts.clear(); |
|
646 contacts.append(contact); |
|
647 document = mExporter->exportContacts(contacts).first(); |
|
648 QCOMPARE(document.properties().count(), 1); |
|
649 property = document.properties().at(0); |
|
650 QCOMPARE(property.name(), QString::fromAscii("ORG")); |
|
651 QCOMPARE(property.value(), QString::fromAscii("Nokia;")); |
|
652 |
|
653 // ORG with department/unit |
|
654 organization.setName(QString()); |
|
655 QStringList departments(QString::fromAscii("R&D")); |
|
656 departments.append(QString::fromAscii("Qt")); |
|
657 organization.setDepartment(departments); |
|
658 contact.saveDetail(&organization); |
|
659 contacts.clear(); |
|
660 contacts.append(contact); |
|
661 document = mExporter->exportContacts(contacts).first(); |
|
662 QCOMPARE(document.properties().count(), 1); |
|
663 property = document.properties().at(0); |
|
664 QCOMPARE(property.name(), QString::fromAscii("ORG")); |
|
665 QCOMPARE(property.value(), QString::fromAscii(";R&D;Qt")); |
|
666 |
|
667 // ORG with name and department/unit |
|
668 organization.setName(QString::fromAscii("Nokia")); |
|
669 contact.saveDetail(&organization); |
|
670 contacts.clear(); |
|
671 contacts.append(contact); |
|
672 document = mExporter->exportContacts(contacts).first(); |
|
673 QCOMPARE(document.properties().count(), 1); |
|
674 property = document.properties().at(0); |
|
675 QCOMPARE(property.name(), QString::fromAscii("ORG")); |
|
676 QCOMPARE(property.value(), QString::fromAscii("Nokia;R&D;Qt")); |
|
677 |
|
678 // TITLE and ORG |
|
679 organization.setTitle(QString::fromAscii("Developer")); |
|
680 contact.saveDetail(&organization); |
|
681 contacts.clear(); |
|
682 contacts.append(contact); |
|
683 document = mExporter->exportContacts(contacts).first(); |
|
684 QCOMPARE(document.properties().count(), 2); |
|
685 property = document.properties().at(0); |
|
686 QCOMPARE(property.name(), QString::fromAscii("TITLE")); |
|
687 QCOMPARE(property.value(), title); |
|
688 property = document.properties().at(1); |
|
689 QCOMPARE(property.name(), QString::fromAscii("ORG")); |
|
690 QCOMPARE(property.value(), QString::fromAscii("Nokia;R&D;Qt")); |
|
691 |
|
692 // ORG LOGO Test1: LOGO as remote Resouce |
|
693 const QString url = QString::fromAscii("http://myhome.com/test.jpg"); |
|
694 contact = QContact(); |
|
695 organization = QContactOrganization(); |
|
696 organization.setLogo(url); |
|
697 contact.saveDetail(&organization); |
|
698 contacts.clear(); |
|
699 contacts.append(contact); |
|
700 mResourceHandler->mSimulatedMimeType = QLatin1String("image/jpeg"); |
|
701 mExporter->setResourceHandler(mResourceHandler); |
|
702 document = mExporter->exportContacts(contacts).first(); |
|
703 QVERIFY(!mResourceHandler->mLoadResourceCalled); |
|
704 |
|
705 // Source type is encoded, but media type is not for a URL. |
|
706 QCOMPARE(document.properties().at(0).parameters().count(), 1); |
|
707 |
|
708 QVERIFY(document.properties().at(0).parameters().contains( |
|
709 QString::fromAscii("VALUE"), QString::fromAscii("URL"))); |
|
710 |
|
711 //Check property Name |
|
712 QString propertyName = document.properties().at(0).name(); |
|
713 QCOMPARE(propertyName, QString::fromAscii("LOGO")); |
|
714 |
|
715 //Check property value |
|
716 QString value = document.properties().at(0).value(); |
|
717 QCOMPARE(value, url); |
|
718 |
|
719 // ORG LOGO Test2: LOGO File. |
|
720 mResourceHandler->mSimulatedData = "simulated data"; |
|
721 contact = QContact(); |
|
722 organization = QContactOrganization(); |
|
723 organization.setLogo(TEST_PHOTO_FILE); |
|
724 contact.saveDetail(&organization); |
|
725 contacts.clear(); |
|
726 contacts.append(contact); |
|
727 document = mExporter->exportContacts(contacts).first(); |
|
728 QVERIFY(mResourceHandler->mLoadResourceCalled); |
|
729 QCOMPARE(mResourceHandler->mLocation, TEST_PHOTO_FILE); |
|
730 |
|
731 // It should be stored in the property as a QVariant of QByteArray |
|
732 property = document.properties().at(0); |
|
733 QMultiHash<QString,QString> parameters = property.parameters(); |
|
734 // Media type is encoded |
|
735 QCOMPARE(parameters.count(), 1); |
|
736 QVERIFY(parameters.contains( |
|
737 QString::fromAscii("TYPE"), QString::fromAscii("JPEG"))); |
|
738 // Verify value. |
|
739 QVariant variantValue = property.variantValue(); |
|
740 QVERIFY(variantValue.type() == QVariant::ByteArray); |
|
741 QCOMPARE(variantValue.value<QByteArray>(), mResourceHandler->mSimulatedData); |
|
742 |
|
743 // Assistant Name Test. |
|
744 contact = QContact(); |
|
745 organization = QContactOrganization(); |
|
746 organization.setAssistantName(QString::fromAscii("myAssistant")); |
|
747 contact.saveDetail(&organization); |
|
748 contacts.clear(); |
|
749 contacts.append(contact); |
|
750 document = mExporter->exportContacts(contacts).first(); |
|
751 QCOMPARE(document.properties().count(), 1); |
|
752 property = document.properties().at(0); |
|
753 QCOMPARE(property.name(), QString::fromAscii("X-ASSISTANT")); |
|
754 QCOMPARE(property.value(), QString::fromAscii("myAssistant")); |
|
755 |
|
756 // Test: Role |
|
757 contact = QContact(); |
|
758 organization = QContactOrganization(); |
|
759 organization.setRole(QString::fromAscii("Executive")); |
|
760 contact.saveDetail(&organization); |
|
761 contacts.clear(); |
|
762 contacts.append(contact); |
|
763 document = mExporter->exportContacts(contacts).first(); |
|
764 QCOMPARE(document.properties().count(), 1); |
|
765 property = document.properties().at(0); |
|
766 QCOMPARE(property.name(), QString::fromAscii("ROLE")); |
|
767 QCOMPARE(property.value(), QString::fromAscii("Executive")); |
|
768 |
|
769 } |
|
770 |
|
771 void UT_QVersitContactExporter::testEncodeAvatar() |
|
772 { |
|
773 QContact contact; |
|
774 QContactAvatar contactAvatar; |
|
775 QPixmap pixmap; |
|
776 pixmap.loadFromData(SAMPLE_GIF); |
|
777 mResourceHandler->mSimulatedData = "simulated data"; |
|
778 mResourceHandler->mSimulatedMimeType = QLatin1String("image/jpeg"); |
|
779 |
|
780 // Test1: Web URL |
|
781 const QString url = QString::fromAscii("http://www.myhome.com/test.jpg"); |
|
782 contactAvatar.setAvatar(url); |
|
783 contactAvatar.setSubType(QContactAvatar::SubTypeImage); |
|
784 contact.saveDetail(&contactAvatar); |
|
785 QList<QContact> contacts; |
|
786 contacts.append(contact); |
|
787 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
788 QVERIFY(document.properties().length() > 0); |
|
789 QVersitProperty property = document.properties().at(0); |
|
790 QCOMPARE(property.parameters().count(), 1); |
|
791 QVERIFY(!mResourceHandler->mLoadResourceCalled); |
|
792 |
|
793 // Test 2: Local Media PHOTO |
|
794 contactAvatar.setAvatar(TEST_PHOTO_FILE); |
|
795 contactAvatar.setPixmap(pixmap); // Should be ignored if the file can be loaded. |
|
796 contactAvatar.setSubType(QContactAvatar::SubTypeImage); |
|
797 contact.saveDetail(&contactAvatar); |
|
798 contacts.clear(); |
|
799 contacts.append(contact); |
|
800 document = mExporter->exportContacts(contacts).first(); |
|
801 QVERIFY(mResourceHandler->mLoadResourceCalled); |
|
802 QCOMPARE(mResourceHandler->mLocation, TEST_PHOTO_FILE); |
|
803 // verify the value |
|
804 QVERIFY(document.properties().length() > 0); |
|
805 property = document.properties().at(0); |
|
806 QVariant variantValue = property.variantValue(); |
|
807 QVERIFY(variantValue.type() == QVariant::ByteArray); |
|
808 QCOMPARE(variantValue.value<QByteArray>(), mResourceHandler->mSimulatedData); |
|
809 QVERIFY(property.parameters().contains(QString::fromAscii("TYPE"), |
|
810 QString::fromAscii("JPEG"))); |
|
811 |
|
812 // Test3: UnSupported Media Type, properties and parameters are not encoded |
|
813 mResourceHandler->clear(); |
|
814 const QString testUrl2 = QString::fromAscii("http://www.myhome.com/test.jpg"); |
|
815 contactAvatar.setAvatar(testUrl2); |
|
816 // un-supported media type is encoded |
|
817 contactAvatar.setSubType(QContactAvatar::SubTypeTexturedMesh); |
|
818 contact.saveDetail(&contactAvatar); |
|
819 contacts.clear(); |
|
820 contacts.append(contact); |
|
821 document = mExporter->exportContacts(contacts).first(); |
|
822 QCOMPARE(document.properties().count(), 0); |
|
823 QVERIFY(!mResourceHandler->mLoadResourceCalled); |
|
824 |
|
825 // Test 4: Load resource fails but there is a pixmap. The pixmap should be saved. |
|
826 // This feature is only supported if we can write PNGs. |
|
827 if (QImageWriter::supportedImageFormats().contains("png")) { |
|
828 mResourceHandler->clear(); |
|
829 mResourceHandler->mLoadSuccess = false; |
|
830 contactAvatar.setAvatar(QLatin1String("")); |
|
831 contactAvatar.setSubType(QContactAvatar::SubTypeImage); |
|
832 contactAvatar.setPixmap(pixmap); |
|
833 contact.saveDetail(&contactAvatar); |
|
834 contacts.clear(); |
|
835 contacts.append(contact); |
|
836 document = mExporter->exportContacts(contacts).first(); |
|
837 // verify the value |
|
838 QVERIFY(document.properties().length() > 0); |
|
839 property = document.properties().at(0); |
|
840 variantValue = property.variantValue(); |
|
841 QVERIFY(variantValue.type() == QVariant::ByteArray); |
|
842 QByteArray retrievedData = variantValue.value<QByteArray>(); |
|
843 QPixmap retrievedPixmap; |
|
844 retrievedPixmap.loadFromData(retrievedData); |
|
845 QCOMPARE(retrievedPixmap, pixmap); |
|
846 } |
|
847 } |
|
848 |
|
849 |
|
850 void UT_QVersitContactExporter::testEncodeEmbeddedContent() |
|
851 { |
|
852 QContact contact; |
|
853 QContactAvatar contactAvatar; |
|
854 QVariant variantValue; |
|
855 |
|
856 // Test 1: URL |
|
857 const QString url = QString::fromAscii("http://www.myhome.com/test.jpg"); |
|
858 contactAvatar.setAvatar(url); |
|
859 contactAvatar.setSubType(QContactAvatar::SubTypeImage); |
|
860 contact.saveDetail(&contactAvatar); |
|
861 QList<QContact> contacts; |
|
862 contacts.append(contact); |
|
863 mResourceHandler->mSimulatedMimeType = QLatin1String("image/jpeg"); |
|
864 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
865 QVERIFY(!mResourceHandler->mLoadResourceCalled); |
|
866 QVersitProperty photoProperty = document.properties().at(0); |
|
867 QCOMPARE(photoProperty.parameters().count(), 1); |
|
868 QVERIFY(photoProperty.parameters().contains( |
|
869 QString::fromAscii("VALUE"),QString::fromAscii("URL"))); |
|
870 QCOMPARE(photoProperty.name(), QString::fromAscii("PHOTO")); |
|
871 QCOMPARE(photoProperty.value(), url); |
|
872 |
|
873 // Test 2: Local PHOTO, image loaded by the loader |
|
874 contactAvatar.setAvatar(TEST_PHOTO_FILE); |
|
875 contactAvatar.setSubType(QContactAvatar::SubTypeImage); |
|
876 contact.saveDetail(&contactAvatar); |
|
877 contacts.clear(); |
|
878 contacts.append(contact); |
|
879 mResourceHandler->clear(); |
|
880 mResourceHandler->mSimulatedMimeType = QLatin1String("image/jpeg"); |
|
881 mResourceHandler->mSimulatedData = "simulated image data"; |
|
882 document = mExporter->exportContacts(contacts).first(); |
|
883 QVERIFY(mResourceHandler->mLoadResourceCalled); |
|
884 photoProperty = document.properties().at(0); |
|
885 QCOMPARE(photoProperty.parameters().count(), 1); |
|
886 QVERIFY(photoProperty.parameters().contains(QString::fromAscii("TYPE"), |
|
887 QString::fromAscii("JPEG"))); |
|
888 variantValue = photoProperty.variantValue(); |
|
889 QVERIFY(variantValue.type() == QVariant::ByteArray); |
|
890 QCOMPARE(variantValue.value<QByteArray>(), mResourceHandler->mSimulatedData); |
|
891 |
|
892 // Test 3: Local SOUND |
|
893 mResourceHandler->clear(); |
|
894 mResourceHandler->mSimulatedMimeType = QLatin1String("audio/wav"); |
|
895 mResourceHandler->mSimulatedData = "simulated audio data"; |
|
896 contactAvatar.setAvatar(TEST_AUDIO_FILE); |
|
897 contactAvatar.setSubType(QContactAvatar::SubTypeAudioRingtone); |
|
898 contact.saveDetail(&contactAvatar); |
|
899 contacts.clear(); |
|
900 contacts.append(contact); |
|
901 document = mExporter->exportContacts(contacts).first(); |
|
902 QVERIFY(mResourceHandler->mLoadResourceCalled); |
|
903 QVersitProperty soundProperty = document.properties().at(0); |
|
904 QCOMPARE(soundProperty.parameters().count(), 1); |
|
905 QVERIFY(soundProperty.parameters().contains( |
|
906 QString::fromAscii("TYPE"), |
|
907 QString::fromAscii("WAV"))); |
|
908 variantValue = soundProperty.variantValue(); |
|
909 QVERIFY(variantValue.type() == QVariant::ByteArray); |
|
910 QCOMPARE(variantValue.value<QByteArray>(), mResourceHandler->mSimulatedData); |
|
911 |
|
912 // Test 4: Unsupported media type, properties and parameters are not encoded |
|
913 mResourceHandler->clear(); |
|
914 mResourceHandler->mSimulatedMimeType = QLatin1String("text/jpeg"); |
|
915 const QString testUrl2 = QString::fromAscii("http://www.myhome.com/test.jpg"); |
|
916 contactAvatar.setAvatar(testUrl2); |
|
917 // un-supported media type is encoded |
|
918 contactAvatar.setSubType(QContactAvatar::SubTypeTexturedMesh); |
|
919 contact.saveDetail(&contactAvatar); |
|
920 contacts.clear(); |
|
921 contacts.append(contact); |
|
922 document = mExporter->exportContacts(contacts).first(); |
|
923 QCOMPARE(document.properties().count(), 0); |
|
924 QVERIFY(!mResourceHandler->mLoadResourceCalled); |
|
925 |
|
926 // Without a resource handler |
|
927 mExporter->setResourceHandler(0); |
|
928 contactAvatar.setAvatar(TEST_PHOTO_FILE); |
|
929 contactAvatar.setSubType(QContactAvatar::SubTypeImage); |
|
930 contact.saveDetail(&contactAvatar); |
|
931 contacts.clear(); |
|
932 contacts.append(contact); |
|
933 document = mExporter->exportContacts(contacts).first(); |
|
934 QCOMPARE(document.properties().count(), 0); |
|
935 |
|
936 mExporter->setResourceHandler(mResourceHandler); |
|
937 } |
|
938 |
|
939 void UT_QVersitContactExporter::testEncodeParameters() |
|
940 { |
|
941 QContact contact; |
|
942 QContactPhoneNumber phoneNumber; |
|
943 phoneNumber.setNumber(QString::fromAscii("12345678")); |
|
944 QStringList subtypes; |
|
945 subtypes.append(QContactPhoneNumber::SubTypeMobile); |
|
946 subtypes.append(QContactPhoneNumber::SubTypeVideo); |
|
947 // Add a not supported subtype in vCard, to make sure its not encoded. |
|
948 subtypes.append(QContactPhoneNumber::SubTypeDtmfMenu); |
|
949 phoneNumber.setSubTypes(subtypes); |
|
950 contact.saveDetail(&phoneNumber); |
|
951 QList<QContact> contacts; |
|
952 contacts.append(contact); |
|
953 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
954 QCOMPARE(document.properties().count(), 1); |
|
955 QVersitProperty property = document.properties().at(0); |
|
956 QCOMPARE(property.parameters().count(), 2); |
|
957 QVERIFY(property.parameters().contains( |
|
958 QString::fromAscii("TYPE"), QString::fromAscii("CELL"))); |
|
959 QVERIFY(property.parameters().contains( |
|
960 QString::fromAscii("TYPE"),QString::fromAscii("VIDEO"))); |
|
961 } |
|
962 |
|
963 void UT_QVersitContactExporter::testIsValidRemoteUrl() |
|
964 { |
|
965 QContact contact; |
|
966 QContactAvatar contactAvatar; |
|
967 mResourceHandler->mLoadSuccess = false; |
|
968 |
|
969 // Test1: http URL |
|
970 QString url = QString::fromAscii("http://www.nonoh.com/test.jpg"); |
|
971 contactAvatar.setAvatar(url); |
|
972 contactAvatar.setSubType(QContactAvatar::SubTypeImage); |
|
973 contact.saveDetail(&contactAvatar); |
|
974 QList<QContact> contacts; |
|
975 contacts.append(contact); |
|
976 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
977 QCOMPARE(document.properties().count(), 1); |
|
978 |
|
979 // Test2: FTP URL |
|
980 url = QString::fromAscii("ftp://nonoh.com/test.jpg"); |
|
981 contactAvatar.setAvatar(url); |
|
982 contactAvatar.setSubType(QContactAvatar::SubTypeImage); |
|
983 contact.saveDetail(&contactAvatar); |
|
984 contacts.clear(); |
|
985 contacts.append(contact); |
|
986 document = mExporter->exportContacts(contacts).first(); |
|
987 QCOMPARE(document.properties().count(), 1); |
|
988 |
|
989 // Test3: NEW Protocol URL |
|
990 url = QString::fromAscii("myProtocol://nonoh.com/test.jpg"); |
|
991 contactAvatar.setAvatar(url); |
|
992 contactAvatar.setSubType(QContactAvatar::SubTypeImage); |
|
993 contact.saveDetail(&contactAvatar); |
|
994 contacts.clear(); |
|
995 contacts.append(contact); |
|
996 document = mExporter->exportContacts(contacts).first(); |
|
997 QCOMPARE(document.properties().count(), 1); |
|
998 |
|
999 // Test4: URL without scheme |
|
1000 url = QString::fromAscii("www.nonoh.com/test.jpg"); |
|
1001 contactAvatar.setAvatar(url); |
|
1002 contactAvatar.setSubType(QContactAvatar::SubTypeImage); |
|
1003 contact.saveDetail(&contactAvatar); |
|
1004 contacts.clear(); |
|
1005 contacts.append(contact); |
|
1006 document = mExporter->exportContacts(contacts).first(); |
|
1007 QCOMPARE(document.properties().count(), 1); |
|
1008 |
|
1009 // Test5: File Name but File does not Exisit |
|
1010 url = QString::fromAscii("c:/filedoesnotexisit.jok"); |
|
1011 contactAvatar.setAvatar(url); |
|
1012 contactAvatar.setSubType(QContactAvatar::SubTypeImage); |
|
1013 contact.saveDetail(&contactAvatar); |
|
1014 contacts.clear(); |
|
1015 contacts.append(contact); |
|
1016 document = mExporter->exportContacts(contacts).first(); |
|
1017 QCOMPARE(document.properties().count(), 0); |
|
1018 } |
|
1019 |
|
1020 void UT_QVersitContactExporter::testEncodeGender() |
|
1021 { |
|
1022 QContact contact; |
|
1023 QContactGender gender; |
|
1024 gender.setGender(QContactGender::GenderMale); |
|
1025 gender.setContexts(QContactGender::ContextHome); // Should not be encoded |
|
1026 contact.saveDetail(&gender); |
|
1027 QList<QContact> contacts; |
|
1028 contacts.append(contact); |
|
1029 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
1030 QCOMPARE(document.properties().count(), 1); |
|
1031 QVersitProperty property = document.properties().at(0); |
|
1032 QCOMPARE(property.parameters().count(), 0); |
|
1033 QCOMPARE(property.name(), QString::fromAscii("X-GENDER")); |
|
1034 QCOMPARE(property.value(), gender.gender()); |
|
1035 } |
|
1036 |
|
1037 void UT_QVersitContactExporter::testEncodeNickName() |
|
1038 { |
|
1039 QContact contact; |
|
1040 |
|
1041 // Add an extra detail |
|
1042 QContactGender gender; |
|
1043 gender.setGender(QContactGender::GenderMale); |
|
1044 contact.saveDetail(&gender); |
|
1045 |
|
1046 // One nickname given |
|
1047 QContactNickname firstNickname; |
|
1048 firstNickname.setNickname(QLatin1String("Homie")); |
|
1049 contact.saveDetail(&firstNickname); |
|
1050 QList<QContact> contacts; |
|
1051 contacts.append(contact); |
|
1052 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
1053 QCOMPARE(document.properties().count(), 2); |
|
1054 QVersitProperty property = document.properties().at(1); |
|
1055 QCOMPARE(property.name(), QLatin1String("X-NICKNAME")); |
|
1056 QCOMPARE(property.value(), QLatin1String("Homie")); |
|
1057 |
|
1058 // Two nicknames given, should be collated into a single property |
|
1059 contact.clearDetails(); |
|
1060 contact.saveDetail(&gender); |
|
1061 contact.saveDetail(&firstNickname); |
|
1062 QContactNickname secondNickname; |
|
1063 secondNickname.setNickname(QLatin1String("Jay")); |
|
1064 contact.saveDetail(&secondNickname); |
|
1065 contacts.clear(); |
|
1066 contacts.append(contact); |
|
1067 document = mExporter->exportContacts(contacts).first(); |
|
1068 QCOMPARE(document.properties().count(), 2); |
|
1069 property = document.properties().at(1); |
|
1070 QCOMPARE(property.name(), QString::fromAscii("X-NICKNAME")); |
|
1071 QCOMPARE(property.value(), QString::fromAscii("Homie,Jay")); |
|
1072 } |
|
1073 |
|
1074 void UT_QVersitContactExporter::testEncodeAnniversary() |
|
1075 { |
|
1076 QContact contact; |
|
1077 QContactAnniversary anniversary; |
|
1078 QDate date(2009,1,1); |
|
1079 anniversary.setOriginalDate(date); |
|
1080 anniversary.setContexts(QContactDetail::ContextHome); |
|
1081 anniversary.setSubType(QContactAnniversary::SubTypeWedding); |
|
1082 contact.saveDetail(&anniversary); |
|
1083 QList<QContact> contacts; |
|
1084 contacts.append(contact); |
|
1085 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
1086 QCOMPARE(document.properties().count(), 1); |
|
1087 QVersitProperty property = document.properties().at(0); |
|
1088 // The contexts and subtypes are not defined for X-ANNIVERSARY property |
|
1089 QCOMPARE(property.parameters().count(), 0); |
|
1090 // Check name |
|
1091 QCOMPARE(property.name(), QString::fromAscii("X-ANNIVERSARY")); |
|
1092 // Check value |
|
1093 QCOMPARE(property.value(), date.toString(Qt::ISODate)); |
|
1094 } |
|
1095 |
|
1096 |
|
1097 void UT_QVersitContactExporter::testEncodeOnlineAccount() |
|
1098 { |
|
1099 QContact contact; |
|
1100 QContactOnlineAccount onlineAccount; |
|
1101 QString accountUri(QString::fromAscii("sip:abc@temp.com")); |
|
1102 onlineAccount.setAccountUri(accountUri); |
|
1103 |
|
1104 // Video sharing |
|
1105 onlineAccount.setSubTypes(QContactOnlineAccount::SubTypeVideoShare); |
|
1106 onlineAccount.setContexts(QContactDetail::ContextHome); |
|
1107 contact.saveDetail(&onlineAccount); |
|
1108 QList<QContact> contacts; |
|
1109 contacts.append(contact); |
|
1110 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
1111 QCOMPARE(document.properties().count(), 1); |
|
1112 QVersitProperty property = document.properties().at(0); |
|
1113 // Check parameters |
|
1114 QCOMPARE(property.parameters().count(), 2); |
|
1115 QVERIFY(property.parameters().contains( |
|
1116 QString::fromAscii("TYPE"),QString::fromAscii("HOME"))); |
|
1117 QVERIFY(property.parameters().contains( |
|
1118 QString::fromAscii("TYPE"),QString::fromAscii("SWIS"))); |
|
1119 // Check name |
|
1120 QCOMPARE(property.name(), QString::fromAscii("X-SIP")); |
|
1121 // Check value |
|
1122 QCOMPARE(property.value(), accountUri); |
|
1123 |
|
1124 // VoIP |
|
1125 onlineAccount.setSubTypes(QContactOnlineAccount::SubTypeSipVoip); |
|
1126 onlineAccount.setContexts(QContactDetail::ContextWork); |
|
1127 contact.saveDetail(&onlineAccount); |
|
1128 contacts.clear(); |
|
1129 contacts.append(contact); |
|
1130 document = mExporter->exportContacts(contacts).first(); |
|
1131 QCOMPARE(document.properties().count(), 1); |
|
1132 property = document.properties().at(0); |
|
1133 // Check parameters |
|
1134 QCOMPARE(property.parameters().count(), 2); |
|
1135 QVERIFY(property.parameters().contains( |
|
1136 QString::fromAscii("TYPE"),QString::fromAscii("WORK"))); |
|
1137 QVERIFY(property.parameters().contains( |
|
1138 QString::fromAscii("TYPE"),QString::fromAscii("VOIP"))); |
|
1139 // Check name |
|
1140 QCOMPARE(property.name(), QString::fromAscii("X-SIP")); |
|
1141 // Check value |
|
1142 QCOMPARE(property.value(), accountUri); |
|
1143 |
|
1144 // Plain SIP |
|
1145 onlineAccount.setSubTypes(QContactOnlineAccount::SubTypeSip); |
|
1146 onlineAccount.setContexts(QContactDetail::ContextWork); |
|
1147 contact.saveDetail(&onlineAccount); |
|
1148 contacts.clear(); |
|
1149 contacts.append(contact); |
|
1150 document = mExporter->exportContacts(contacts).first(); |
|
1151 QCOMPARE(document.properties().count(), 1); |
|
1152 property = document.properties().at(0); |
|
1153 // Check parameters, SIP not added as a TYPE parameter |
|
1154 QCOMPARE(property.parameters().count(), 1); |
|
1155 QVERIFY(property.parameters().contains( |
|
1156 QString::fromAscii("TYPE"),QString::fromAscii("WORK"))); |
|
1157 // Check name |
|
1158 QCOMPARE(property.name(), QString::fromAscii("X-SIP")); |
|
1159 // Check value |
|
1160 QCOMPARE(property.value(), accountUri); |
|
1161 |
|
1162 // IMPP / X-IMPP |
|
1163 onlineAccount.setSubTypes(QContactOnlineAccount::SubTypeImpp); |
|
1164 onlineAccount.setContexts(QContactDetail::ContextHome); |
|
1165 contact.saveDetail(&onlineAccount); |
|
1166 contacts.clear(); |
|
1167 contacts.append(contact); |
|
1168 document = mExporter->exportContacts(contacts).first(); |
|
1169 QCOMPARE(document.properties().count(), 1); |
|
1170 property = document.properties().at(0); |
|
1171 // Check parameters, SIP not added as a TYPE parameter |
|
1172 QCOMPARE(property.parameters().count(), 1); |
|
1173 QVERIFY(property.parameters().contains( |
|
1174 QString::fromAscii("TYPE"),QString::fromAscii("HOME"))); |
|
1175 // Check name |
|
1176 QCOMPARE(property.name(), QString::fromAscii("X-IMPP")); |
|
1177 // Check value |
|
1178 QCOMPARE(property.value(), accountUri); |
|
1179 |
|
1180 // Other subtypes not converted |
|
1181 onlineAccount.setSubTypes(QString::fromAscii("INVALIDSUBTYPE")); |
|
1182 contact.saveDetail(&onlineAccount); |
|
1183 contacts.clear(); |
|
1184 contacts.append(contact); |
|
1185 document = mExporter->exportContacts(contacts).first(); |
|
1186 QCOMPARE(document.properties().count(), 0); |
|
1187 } |
|
1188 |
|
1189 void UT_QVersitContactExporter::testEncodeFamily() |
|
1190 { |
|
1191 QContact contact; |
|
1192 QContactFamily family; |
|
1193 |
|
1194 // No spouse, no family |
|
1195 family.setContexts(QContactDetail::ContextHome); |
|
1196 contact.saveDetail(&family); |
|
1197 QList<QContact> contacts; |
|
1198 contacts.append(contact); |
|
1199 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
1200 QCOMPARE(document.properties().count(), 0); |
|
1201 |
|
1202 // Only spouse present |
|
1203 QString spouce = QString::fromAscii("ABC"); |
|
1204 family.setSpouse(spouce); |
|
1205 contact.saveDetail(&family); |
|
1206 contacts.clear(); |
|
1207 contacts.append(contact); |
|
1208 document = mExporter->exportContacts(contacts).first(); |
|
1209 QCOMPARE(document.properties().count(), 1); |
|
1210 QVersitProperty spouseProperty = document.properties().at(0); |
|
1211 QCOMPARE(spouseProperty.parameters().count(), 0); |
|
1212 QCOMPARE(spouseProperty.name(), QString::fromAscii("X-SPOUSE")); |
|
1213 QCOMPARE(spouseProperty.value(), spouce); |
|
1214 |
|
1215 // Spouse and children |
|
1216 QStringList children; |
|
1217 children << QString::fromAscii("A") << QString::fromAscii("B") ; |
|
1218 family.setChildren(children); |
|
1219 family.setSpouse(spouce); |
|
1220 contact.saveDetail(&family); |
|
1221 contacts.clear(); |
|
1222 contacts.append(contact); |
|
1223 document = mExporter->exportContacts(contacts).first(); |
|
1224 QCOMPARE(document.properties().count(), 2); |
|
1225 spouseProperty = document.properties().at(0); |
|
1226 QCOMPARE(spouseProperty.parameters().count(), 0); |
|
1227 QCOMPARE(spouseProperty.name(), QString::fromAscii("X-SPOUSE")); |
|
1228 QCOMPARE(spouseProperty.value(), spouce); |
|
1229 QVersitProperty childrenProperty = document.properties().at(1); |
|
1230 QCOMPARE(childrenProperty.parameters().count(), 0); |
|
1231 QCOMPARE(childrenProperty.name(), QString::fromAscii("X-CHILDREN")); |
|
1232 QCOMPARE(childrenProperty.value(), QString::fromAscii("A\\,B")); |
|
1233 } |
|
1234 |
|
1235 |
|
1236 void UT_QVersitContactExporter::testEncodeDisplayLabel() |
|
1237 { |
|
1238 QContact contact; |
|
1239 QContactName contactName; |
|
1240 |
|
1241 // No display label and no QContactName |
|
1242 QList<QContact> contacts; |
|
1243 contacts.append(contact); |
|
1244 QVersitDocument document = mExporter->exportContacts(contacts).first(); |
|
1245 QCOMPARE(document.properties().count(), 0); |
|
1246 |
|
1247 // No display label, but QContactName found |
|
1248 contactName.setFirstName(QString::fromAscii("First")); |
|
1249 contactName.setLastName(QString::fromAscii("Last")); |
|
1250 contactName.setMiddleName(QString::fromAscii("Middle")); |
|
1251 contact.saveDetail(&contactName); |
|
1252 contacts.clear(); |
|
1253 contacts.append(contact); |
|
1254 document = mExporter->exportContacts(contacts).first(); |
|
1255 QCOMPARE(document.properties().count(), 2); |
|
1256 QVersitProperty displayProperty = document.properties().at(0); |
|
1257 QCOMPARE(displayProperty.name(), QString::fromAscii("FN")); |
|
1258 QCOMPARE(displayProperty.value(), QString::fromAscii("First Last")); |
|
1259 QVersitProperty nameProperty = document.properties().at(1); |
|
1260 QCOMPARE(nameProperty.name(), QString::fromAscii("N")); |
|
1261 QCOMPARE(nameProperty.value(), |
|
1262 QString::fromAscii("Last;First;Middle;;")); |
|
1263 |
|
1264 // Custom label in QContactName, use vCard 3.0 to test the backslash escaping |
|
1265 contact = QContact(); |
|
1266 contactName.setCustomLabel(QString::fromAscii("Custom,Label")); |
|
1267 contact.saveDetail(&contactName); |
|
1268 contacts.clear(); |
|
1269 contacts.append(contact); |
|
1270 document = mExporter->exportContacts(contacts, QVersitDocument::VCard30Type).first(); |
|
1271 displayProperty = document.properties().at(0); |
|
1272 QCOMPARE(displayProperty.name(), QString::fromAscii("FN")); |
|
1273 QCOMPARE(displayProperty.value(), |
|
1274 QString::fromAscii("Custom\\,Label")); |
|
1275 } |
|
1276 |
|
1277 void UT_QVersitContactExporter::testDefaultResourceHandler() |
|
1278 { |
|
1279 QVersitDefaultResourceHandler handler; |
|
1280 QByteArray contents; |
|
1281 QString mimeType; |
|
1282 handler.loadResource(QLatin1String("test.jpg"), &contents, &mimeType); |
|
1283 QCOMPARE(mimeType, QLatin1String("image/jpeg")); |
|
1284 |
|
1285 QVersitProperty property; |
|
1286 QString location; |
|
1287 QVERIFY(!handler.saveResource("test contents", property, &location)); |
|
1288 } |
|
1289 |
|
1290 // Test utility functions |
|
1291 QContactDetail UT_QVersitContactExporter::searchDetail( |
|
1292 QList<QContactDetail> details, |
|
1293 QString search) |
|
1294 { |
|
1295 QContactDetail detail; |
|
1296 for (int i= 0; i < details.count(); i++) { |
|
1297 if ( details.at(i).definitionName() == search ) |
|
1298 detail = details.at(i); |
|
1299 } |
|
1300 return detail; |
|
1301 } |
|
1302 |
|
1303 QTEST_MAIN(UT_QVersitContactExporter) |
|
1304 |
|