qtmobility/plugins/contacts/symbian/tsrc/tst_qcontactmanagersymbian/tst_qcontactmanagersymbian.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
    66     QTRY_COMPARE(spyContactsAdded.count(), contactsAdded); \
    66     QTRY_COMPARE(spyContactsAdded.count(), contactsAdded); \
    67     QTRY_COMPARE(spyContactsChanged.count(), contactsChanged); \
    67     QTRY_COMPARE(spyContactsChanged.count(), contactsChanged); \
    68     QTRY_COMPARE(spyContactsRemoved.count(), contactsRemoved); \
    68     QTRY_COMPARE(spyContactsRemoved.count(), contactsRemoved); \
    69     QTRY_COMPARE(spyRelationshipsAdded.count(), relationshipsAdded); \
    69     QTRY_COMPARE(spyRelationshipsAdded.count(), relationshipsAdded); \
    70     QTRY_COMPARE(spyRelationshipsRemoved.count(), relationshipsRemoved); \
    70     QTRY_COMPARE(spyRelationshipsRemoved.count(), relationshipsRemoved); \
    71     QTRY_COMPARE(spySelfContactIdChanged.count(), selfContactIdChanged); \
    71     QTRY_COMPARE(spySelfContactIdChanged.count(), selfContactIdChanged);
       
    72 
       
    73 #define QTRY_COMPARE_SIGNAL_COUNTS2() \
    72     QTRY_COMPARE(spyContactsAdded2.count(), contactsAdded); \
    74     QTRY_COMPARE(spyContactsAdded2.count(), contactsAdded); \
    73     QTRY_COMPARE(spyContactsChanged2.count(), contactsChanged); \
    75     QTRY_COMPARE(spyContactsChanged2.count(), contactsChanged); \
    74     QTRY_COMPARE(spyContactsRemoved2.count(), contactsRemoved); \
    76     QTRY_COMPARE(spyContactsRemoved2.count(), contactsRemoved); \
    75     QTRY_COMPARE(spyRelationshipsAdded2.count(), relationshipsAdded); \
    77     QTRY_COMPARE(spyRelationshipsAdded2.count(), relationshipsAdded); \
    76     QTRY_COMPARE(spyRelationshipsRemoved2.count(), relationshipsRemoved); \
    78     QTRY_COMPARE(spyRelationshipsRemoved2.count(), relationshipsRemoved); \
    99     void init();
   101     void init();
   100     void cleanup();
   102     void cleanup();
   101 
   103 
   102 private slots:
   104 private slots:
   103     void signalEmission();
   105     void signalEmission();
       
   106     void signalEmissionWithContactModel();
   104     void filtering();
   107     void filtering();
   105     void avatarImage();
   108     void avatarImage();
   106     void avatarImage_data();
   109     void avatarImage_data();
   107     void thumbnail_data();
   110     void thumbnail_data();
   108     void thumbnail();
   111     void thumbnail();
   109     void ringTone();
   112     void ringTone();
   110     void displayLabel_data();
   113     void displayLabel_data();
   111     void displayLabel();
   114     void displayLabel();
   112     void timestamp();
   115     void timestamp();
       
   116     void onlineAccount_data();
       
   117     void onlineAccount();
   113     void invalidContactItems();
   118     void invalidContactItems();
   114 
   119 
   115 private:
   120 private:
   116     QContact createContact(QString type, QString firstName, QString lastName);
   121     QContact createContact(QString type, QString firstName, QString lastName);
   117     void addContactItemWithInvalidFieldsL(TContactItemId& itemId);
   122     void addContactItemWithInvalidFieldsL(TContactItemId& itemId);
   150 
   155 
   151 void tst_QContactManagerSymbian::cleanup()
   156 void tst_QContactManagerSymbian::cleanup()
   152 {
   157 {
   153     // If the following is commented out => the generated contacts are left into
   158     // If the following is commented out => the generated contacts are left into
   154     // the database
   159     // the database
   155     QVERIFY(m_cm->removeContact(m_contactId.localId()));
   160     QList<QContactLocalId> ids = m_cm->contactIds();
       
   161     QVERIFY(m_cm->removeContacts(ids, 0));
   156 }
   162 }
   157 
   163 
   158 void tst_QContactManagerSymbian::signalEmission()
   164 void tst_QContactManagerSymbian::signalEmission()
   159 {
   165 {
   160     QScopedPointer<QContactManager> cm2(QContactManager::fromUri("qtcontacts:symbian"));
   166     QScopedPointer<QContactManager> cm2(QContactManager::fromUri("qtcontacts:symbian"));
   189     // create a group
   195     // create a group
   190     QContact group = createContact(QContactType::TypeGroup, "Hesketh", "");
   196     QContact group = createContact(QContactType::TypeGroup, "Hesketh", "");
   191     QVERIFY(m_cm->saveContact(&group));
   197     QVERIFY(m_cm->saveContact(&group));
   192     contactsAdded++;
   198     contactsAdded++;
   193     QTRY_COMPARE_SIGNAL_COUNTS();
   199     QTRY_COMPARE_SIGNAL_COUNTS();
       
   200     QTRY_COMPARE_SIGNAL_COUNTS2();
   194 
   201 
   195     // change the group
   202     // change the group
   196     QContactName name = group.detail(QContactName::DefinitionName);
   203     QContactName name = group.detail(QContactName::DefinitionName);
   197     name.setCustomLabel("McLaren");
   204     name.setCustomLabel("McLaren");
   198     group.saveDetail(&name);
   205     group.saveDetail(&name);
   199     QVERIFY(m_cm->saveContact(&group));
   206     QVERIFY(m_cm->saveContact(&group));
   200     contactsChanged++;
   207     contactsChanged++;
   201     QTRY_COMPARE_SIGNAL_COUNTS();
   208     QTRY_COMPARE_SIGNAL_COUNTS();
       
   209     QTRY_COMPARE_SIGNAL_COUNTS2();
   202 
   210 
   203     // remove the group
   211     // remove the group
   204     QVERIFY(m_cm->removeContact(group.localId()));
   212     QVERIFY(m_cm->removeContact(group.localId()));
   205     contactsRemoved++;
   213     contactsRemoved++;
   206     QTRY_COMPARE_SIGNAL_COUNTS();
   214     QTRY_COMPARE_SIGNAL_COUNTS();
       
   215     QTRY_COMPARE_SIGNAL_COUNTS2();
   207 
   216 
   208     // Add two contacts
   217     // Add two contacts
   209     QContact contact1 = createContact(QContactType::TypeContact, "James", "Hunt");
   218     QContact contact1 = createContact(QContactType::TypeContact, "James", "Hunt");
   210     QVERIFY(m_cm->saveContact(&contact1));
   219     QVERIFY(m_cm->saveContact(&contact1));
   211     contactsAdded++;
   220     contactsAdded++;
   212     QTRY_COMPARE_SIGNAL_COUNTS();
   221     QTRY_COMPARE_SIGNAL_COUNTS();
       
   222     QTRY_COMPARE_SIGNAL_COUNTS2();
   213     QContact contact2 = createContact(QContactType::TypeContact, "Jochen", "Mass");
   223     QContact contact2 = createContact(QContactType::TypeContact, "Jochen", "Mass");
   214     QVERIFY(m_cm->saveContact(&contact2));
   224     QVERIFY(m_cm->saveContact(&contact2));
   215     contactsAdded++;
   225     contactsAdded++;
   216     QTRY_COMPARE_SIGNAL_COUNTS();
   226     QTRY_COMPARE_SIGNAL_COUNTS();
       
   227     QTRY_COMPARE_SIGNAL_COUNTS2();
   217 
   228 
   218     // Add group 2
   229     // Add group 2
   219     QContact group2 = createContact(QContactType::TypeGroup, "McLaren", "");
   230     QContact group2 = createContact(QContactType::TypeGroup, "McLaren", "");
   220     QVERIFY(m_cm->saveContact(&group2));
   231     QVERIFY(m_cm->saveContact(&group2));
   221     contactsAdded++;
   232     contactsAdded++;
   222     QTRY_COMPARE_SIGNAL_COUNTS();
   233     QTRY_COMPARE_SIGNAL_COUNTS();
       
   234     QTRY_COMPARE_SIGNAL_COUNTS2();
   223 
   235 
   224     // Add a relationship
   236     // Add a relationship
   225     QContactRelationship r;
   237     QContactRelationship r;
   226     r.setFirst(group2.id());
   238     r.setFirst(group2.id());
   227     r.setSecond(contact1.id());
   239     r.setSecond(contact1.id());
   228     r.setRelationshipType(QContactRelationship::HasMember);
   240     r.setRelationshipType(QContactRelationship::HasMember);
   229     QVERIFY(m_cm->saveRelationship(&r));
   241     QVERIFY(m_cm->saveRelationship(&r));
   230     relationshipsAdded++;
   242     relationshipsAdded++;
   231     QTRY_COMPARE_SIGNAL_COUNTS();
   243     QTRY_COMPARE_SIGNAL_COUNTS();
       
   244     QTRY_COMPARE_SIGNAL_COUNTS2();
   232 
   245 
   233     // Create one more contact manager instance
   246     // Create one more contact manager instance
   234     QScopedPointer<QContactManager> cm3(QContactManager::fromUri("qtcontacts:symbian"));
   247     QScopedPointer<QContactManager> cm3(QContactManager::fromUri("qtcontacts:symbian"));
   235     QSignalSpy spyRelationshipsAdded3(cm3.data(), SIGNAL(relationshipsAdded(QList<QContactLocalId>)));
   248     QSignalSpy spyRelationshipsAdded3(cm3.data(), SIGNAL(relationshipsAdded(QList<QContactLocalId>)));
   236     QSignalSpy spyRelationshipsRemoved3(cm3.data(), SIGNAL(relationshipsRemoved(QList<QContactLocalId>)));
   249     QSignalSpy spyRelationshipsRemoved3(cm3.data(), SIGNAL(relationshipsRemoved(QList<QContactLocalId>)));
   241     r2.setSecond(contact2.id());
   254     r2.setSecond(contact2.id());
   242     r2.setRelationshipType(QContactRelationship::HasMember);
   255     r2.setRelationshipType(QContactRelationship::HasMember);
   243     QVERIFY(m_cm->saveRelationship(&r2));
   256     QVERIFY(m_cm->saveRelationship(&r2));
   244     relationshipsAdded++;
   257     relationshipsAdded++;
   245     QTRY_COMPARE_SIGNAL_COUNTS();
   258     QTRY_COMPARE_SIGNAL_COUNTS();
       
   259     QTRY_COMPARE_SIGNAL_COUNTS2();
   246 
   260 
   247     // Remove relationship 1
   261     // Remove relationship 1
   248     QVERIFY(m_cm->removeRelationship(r));
   262     QVERIFY(m_cm->removeRelationship(r));
   249     relationshipsRemoved++;
   263     relationshipsRemoved++;
   250     QTRY_COMPARE_SIGNAL_COUNTS();
   264     QTRY_COMPARE_SIGNAL_COUNTS();
       
   265     QTRY_COMPARE_SIGNAL_COUNTS2();
   251     QTRY_COMPARE(spyRelationshipsAdded3.count(), 1);
   266     QTRY_COMPARE(spyRelationshipsAdded3.count(), 1);
   252     QTRY_COMPARE(spyRelationshipsRemoved3.count(), 1);
   267     QTRY_COMPARE(spyRelationshipsRemoved3.count(), 1);
   253 
   268 
   254     // Remove relationship 2
   269     // Remove relationship 2
   255     QVERIFY(m_cm->removeRelationship(r2));
   270     QVERIFY(m_cm->removeRelationship(r2));
   256     relationshipsRemoved++;
   271     relationshipsRemoved++;
   257     QTRY_COMPARE_SIGNAL_COUNTS();
   272     QTRY_COMPARE_SIGNAL_COUNTS();
       
   273     QTRY_COMPARE_SIGNAL_COUNTS2();
   258     QTRY_COMPARE(spyRelationshipsAdded3.count(), 1);
   274     QTRY_COMPARE(spyRelationshipsAdded3.count(), 1);
   259     QTRY_COMPARE(spyRelationshipsRemoved3.count(), 2);
   275     QTRY_COMPARE(spyRelationshipsRemoved3.count(), 2);
   260 
   276 
   261     // Remove contacts
   277     // Remove contacts
   262     QVERIFY(m_cm->removeContact(contact1.localId()));
   278     QVERIFY(m_cm->removeContact(contact1.localId()));
   263     contactsRemoved++;
   279     contactsRemoved++;
   264     QTRY_COMPARE_SIGNAL_COUNTS();
   280     QTRY_COMPARE_SIGNAL_COUNTS();
       
   281     QTRY_COMPARE_SIGNAL_COUNTS2();
   265     QVERIFY(m_cm->removeContact(contact2.localId()));
   282     QVERIFY(m_cm->removeContact(contact2.localId()));
   266     contactsRemoved++;
   283     contactsRemoved++;
   267     QTRY_COMPARE_SIGNAL_COUNTS();
   284     QTRY_COMPARE_SIGNAL_COUNTS();
       
   285     QTRY_COMPARE_SIGNAL_COUNTS2();
   268     QVERIFY(m_cm->removeContact(group2.localId()));
   286     QVERIFY(m_cm->removeContact(group2.localId()));
   269     contactsRemoved++;
   287     contactsRemoved++;
   270     QTRY_COMPARE_SIGNAL_COUNTS();
   288     QTRY_COMPARE_SIGNAL_COUNTS();
   271 
   289     QTRY_COMPARE_SIGNAL_COUNTS2();
       
   290     
       
   291     // create a group + a contact and create a relationship3 
       
   292     QContact group3 = createContact(QContactType::TypeGroup, "Outlaws", "");
       
   293     QVERIFY(m_cm->saveContact(&group3));
       
   294     contactsAdded++;
       
   295     QContact contact3 = createContact(QContactType::TypeContact, "Jesse", "James");
       
   296     QVERIFY(m_cm->saveContact(&contact3));
       
   297     contactsAdded++;
       
   298     QTRY_COMPARE_SIGNAL_COUNTS();
       
   299     QTRY_COMPARE_SIGNAL_COUNTS2();
       
   300     QContactRelationship r3;
       
   301     r3.setFirst(group3.id());
       
   302     r3.setSecond(contact3.id());
       
   303     r3.setRelationshipType(QContactRelationship::HasMember);
       
   304     QVERIFY(m_cm->saveRelationship(&r3));
       
   305     relationshipsAdded++;
       
   306     QTRY_COMPARE_SIGNAL_COUNTS();
       
   307     QTRY_COMPARE_SIGNAL_COUNTS2();
       
   308     
       
   309     // Remove contact from relationship3
       
   310     QVERIFY(m_cm->removeContact(contact3.localId()));
       
   311     contactsRemoved++;
       
   312     relationshipsRemoved++;
       
   313     QTRY_COMPARE_SIGNAL_COUNTS();
       
   314     QTRY_COMPARE_SIGNAL_COUNTS2();
       
   315     
       
   316     // Restore contact and relationship3
       
   317     contact3.setId(QContactId());
       
   318     QVERIFY(m_cm->saveContact(&contact3));
       
   319     contactsAdded++;
       
   320     r3.setSecond(contact3.id());
       
   321     QTRY_COMPARE_SIGNAL_COUNTS();
       
   322     QTRY_COMPARE_SIGNAL_COUNTS2();
       
   323     QVERIFY(m_cm->saveRelationship(&r3));
       
   324     relationshipsAdded++;
       
   325     QTRY_COMPARE_SIGNAL_COUNTS();
       
   326     QTRY_COMPARE_SIGNAL_COUNTS2();
       
   327     
       
   328     // Remove group from relationship3
       
   329     QVERIFY(m_cm->removeContact(group3.localId()));
       
   330     contactsRemoved++;
       
   331     relationshipsRemoved++;
       
   332     QTRY_COMPARE_SIGNAL_COUNTS();
       
   333     QTRY_COMPARE_SIGNAL_COUNTS2();
       
   334     
   272     // Self contact
   335     // Self contact
   273     QContact memyself = createContact(QContactType::TypeContact, "Kimi", "Raikkonen");
   336     QContact memyself = createContact(QContactType::TypeContact, "Kimi", "Raikkonen");
   274     QVERIFY(m_cm->saveContact(&memyself));
   337     QVERIFY(m_cm->saveContact(&memyself));
   275     contactsAdded++;
   338     contactsAdded++;
   276     QTRY_COMPARE_SIGNAL_COUNTS();
   339     QTRY_COMPARE_SIGNAL_COUNTS();
       
   340     QTRY_COMPARE_SIGNAL_COUNTS2();
   277     QVERIFY(m_cm->setSelfContactId(memyself.localId()));
   341     QVERIFY(m_cm->setSelfContactId(memyself.localId()));
   278     selfContactIdChanged++;
   342     selfContactIdChanged++;
   279     QTRY_COMPARE_SIGNAL_COUNTS();
   343     QTRY_COMPARE_SIGNAL_COUNTS();
       
   344     QTRY_COMPARE_SIGNAL_COUNTS2();
       
   345 
       
   346     // Modify self contact
       
   347     QContactName myname = memyself.detail(QContactName::DefinitionName);
       
   348     myname.setFirstName("Iceman");
       
   349     memyself.saveDetail(&myname);
       
   350     QVERIFY(m_cm->saveContact(&memyself));
       
   351     contactsChanged++;
       
   352     QTRY_COMPARE_SIGNAL_COUNTS();
       
   353     QTRY_COMPARE_SIGNAL_COUNTS2();
       
   354 
       
   355     // Remove self contact
   280     QVERIFY(m_cm->removeContact(memyself.localId()));
   356     QVERIFY(m_cm->removeContact(memyself.localId()));
   281     contactsRemoved++;
   357     contactsRemoved++;
   282     selfContactIdChanged++;
   358     selfContactIdChanged++;
   283     QTRY_COMPARE_SIGNAL_COUNTS();
   359     QTRY_COMPARE_SIGNAL_COUNTS();
       
   360     QTRY_COMPARE_SIGNAL_COUNTS2();
       
   361 }
       
   362 
       
   363 void tst_QContactManagerSymbian::signalEmissionWithContactModel()
       
   364 {
       
   365     // Wait a moment to make sure there are no pending database observer events
       
   366     QTest::qWait(500);
       
   367 
       
   368     // counters to keep track of the expected signal counts
       
   369     int contactsAdded(0);
       
   370     int contactsChanged(0);
       
   371     int contactsRemoved(0);
       
   372     int relationshipsAdded(0);
       
   373     int relationshipsRemoved(0);
       
   374     int selfContactIdChanged(0);
       
   375 
       
   376     // Signal spys for verifying signal emissions
       
   377     qRegisterMetaType<QContactLocalId>("QContactLocalId");
       
   378     qRegisterMetaType<QList<QContactLocalId> >("QList<QContactLocalId>");
       
   379     QSignalSpy spyContactsAdded(m_cm, SIGNAL(contactsAdded(QList<QContactLocalId>)));
       
   380     QSignalSpy spyContactsChanged(m_cm, SIGNAL(contactsChanged(QList<QContactLocalId>)));
       
   381     QSignalSpy spyContactsRemoved(m_cm, SIGNAL(contactsRemoved(QList<QContactLocalId>)));
       
   382     QSignalSpy spyRelationshipsAdded(m_cm, SIGNAL(relationshipsAdded(QList<QContactLocalId>)));
       
   383     QSignalSpy spyRelationshipsRemoved(m_cm, SIGNAL(relationshipsRemoved(QList<QContactLocalId>)));
       
   384     QSignalSpy spySelfContactIdChanged(m_cm, SIGNAL(selfContactIdChanged(QContactLocalId, QContactLocalId)));
       
   385 
       
   386     // Add a contact via Qt API and remove it via CntModel API
       
   387     QContact contact1 = createContact(QContactType::TypeContact, "Kimi", "Räikkönen");
       
   388     QVERIFY(m_cm->saveContact(&contact1));
       
   389     contactsAdded++;
       
   390     QTRY_COMPARE_SIGNAL_COUNTS();
       
   391     m_contactDatabase->DeleteContactL(contact1.localId());
       
   392     contactsRemoved++;
       
   393     QTRY_COMPARE_SIGNAL_COUNTS();
       
   394 
       
   395     // Add a contact, a group and a relationship between those via
       
   396     // CntModel API and verify signal emissions
       
   397     CContactCard* contactCard = CContactCard::NewL();
       
   398     CleanupStack::PushL(contactCard);
       
   399     m_contactDatabase->AddNewContactL(*contactCard);
       
   400     contactsAdded++;
       
   401     CContactItem *groupItem = m_contactDatabase->CreateContactGroupLC();
       
   402     contactsAdded++;
       
   403     m_contactDatabase->AddContactToGroupL(contactCard->Id(), groupItem->Id());
       
   404     relationshipsAdded++;
       
   405     CleanupStack::PopAndDestroy(groupItem);
       
   406     CleanupStack::PopAndDestroy(contactCard);
       
   407     QTRY_COMPARE_SIGNAL_COUNTS();
       
   408 
       
   409     // Add a contact, a group and a relationship between those via Qt API
       
   410     // and then remove the contact via contact database API
       
   411     QContact contact2 = createContact(QContactType::TypeContact, "Kimi", "Räikkönen");
       
   412     QVERIFY(m_cm->saveContact(&contact2));
       
   413     contactsAdded++;
       
   414     QTRY_COMPARE_SIGNAL_COUNTS();
       
   415     QContact group = createContact(QContactType::TypeGroup, "Reb Bull", "");
       
   416     QVERIFY(m_cm->saveContact(&group));
       
   417     contactsAdded++;
       
   418     QTRY_COMPARE_SIGNAL_COUNTS();
       
   419     QContactRelationship r;
       
   420     r.setFirst(group.id());
       
   421     r.setSecond(contact2.id());
       
   422     r.setRelationshipType(QContactRelationship::HasMember);
       
   423     QVERIFY(m_cm->saveRelationship(&r));
       
   424     relationshipsAdded++;
       
   425     QTRY_COMPARE_SIGNAL_COUNTS();
       
   426     m_contactDatabase->DeleteContactL(contact2.localId());
       
   427     contactsRemoved++;
       
   428     relationshipsRemoved++;
       
   429     QTRY_COMPARE_SIGNAL_COUNTS();
       
   430     
       
   431     // restore contact and relationship
       
   432     contact2.setId(QContactId());
       
   433     QVERIFY(m_cm->saveContact(&contact2));
       
   434     contactsAdded++;
       
   435     r.setSecond(contact2.id());
       
   436     QVERIFY(m_cm->saveRelationship(&r));
       
   437     relationshipsAdded++;
       
   438     QTRY_COMPARE_SIGNAL_COUNTS();
       
   439     
       
   440     // Remove group from relationship
       
   441     m_contactDatabase->DeleteContactL(group.localId());
       
   442     contactsRemoved++;
       
   443     relationshipsRemoved++;
       
   444     QTRY_COMPARE_SIGNAL_COUNTS();
       
   445 	
       
   446    // TODO: Create a group which has members already
   284 }
   447 }
   285 
   448 
   286 /*
   449 /*
   287  * Special filtering cases that cannot be covered in QtMobility system level
   450  * Special filtering cases that cannot be covered in QtMobility system level
   288  * test cases.
   451  * test cases.
   451 }
   614 }
   452 
   615 
   453 void tst_QContactManagerSymbian::displayLabel_data()
   616 void tst_QContactManagerSymbian::displayLabel_data()
   454 {
   617 {
   455     // Expected display label
   618     // Expected display label
       
   619     QTest::addColumn<QString>("contactType");
   456     QTest::addColumn<QString>("displayLabel");
   620     QTest::addColumn<QString>("displayLabel");
   457     // A string list containing the detail fields in format <detail definition name>:<field name>:<value>
   621     // A string list containing the detail fields in format <detail definition name>:<field name>:<value>
   458     // For example first name: Name:First:James
   622     // For example first name: Name:First:James
   459     // Note: With the current implementation the value must not contain a ':' character
   623     // Note: With the current implementation the value must not contain a ':' character
   460     QTest::addColumn<QStringList>("details");
   624     QTest::addColumn<QStringList>("details");
   461 
   625 
       
   626     QString typeContact = QContactType::TypeContact;
       
   627     QString typeGroup = QContactType::TypeGroup;
       
   628 
   462     QTest::newRow("first name")
   629     QTest::newRow("first name")
       
   630         << typeContact
   463         << "James"
   631         << "James"
   464         << (QStringList()
   632         << (QStringList()
   465             << "Name:FirstName:James");
   633             << "Name:FirstName:James");
   466 
   634 
   467     QTest::newRow("last name")
   635     QTest::newRow("last name")
       
   636         << typeContact
   468         << "Hunt"
   637         << "Hunt"
   469         << (QStringList()
   638         << (QStringList()
   470             << "Name:LastName:Hunt");
   639             << "Name:LastName:Hunt");
   471 
   640 
   472     QTest::newRow("first and last name") // fail
   641     QTest::newRow("first and last name") // fail
       
   642         << typeContact
   473         << "James Hunt"
   643         << "James Hunt"
   474         << (QStringList()
   644         << (QStringList()
   475             << "Name:FirstName:James"
   645             << "Name:FirstName:James"
   476             << "Name:LastName:Hunt");
   646             << "Name:LastName:Hunt");
   477 
   647 
   478     QTest::newRow("multi-part first name and last name") // fail
   648     QTest::newRow("multi-part first name and last name") // fail
       
   649         << typeContact
   479         << "James Simon Wallis Hunt"
   650         << "James Simon Wallis Hunt"
   480         << (QStringList()
   651         << (QStringList()
   481             << "Name:FirstName:James Simon Wallis"
   652             << "Name:FirstName:James Simon Wallis"
   482             << "Name:LastName:Hunt");
   653             << "Name:LastName:Hunt");
   483 
   654 
   484     QTest::newRow("all names")
   655     QTest::newRow("all names")
       
   656         << typeContact
   485         << "James Hunt"
   657         << "James Hunt"
   486         << (QStringList()
   658         << (QStringList()
   487             << "Name:FirstName:James"
   659             << "Name:FirstName:James"
   488             << "Name:LastName:Hunt"
   660             << "Name:LastName:Hunt"
   489             << "Name:MiddleName:Simon Wallis"
   661             << "Name:MiddleName:Simon Wallis"
   490             << "Name:Suffix:Suffix"
   662             << "Name:Suffix:Suffix"
   491             << "Name:Prefix:Pre");
   663             << "Name:Prefix:Pre");
   492 
   664 
   493     QTest::newRow("first name, organization")
   665     QTest::newRow("first name, organization")
       
   666         << typeContact
   494         << "James"
   667         << "James"
   495         << (QStringList()
   668         << (QStringList()
   496             << "Name:FirstName:James"
   669             << "Name:FirstName:James"
   497             << "Organization:Name:McLaren");
   670             << "Organization:Name:McLaren");
   498 
   671 
   499     QTest::newRow("last name, organization")
   672     QTest::newRow("last name, organization")
       
   673         << typeContact
   500         << "Hunt"
   674         << "Hunt"
   501         << (QStringList()
   675         << (QStringList()
   502             << "Name:LastName:Hunt"
   676             << "Name:LastName:Hunt"
   503             << "Organization:Name:McLaren");
   677             << "Organization:Name:McLaren");
   504 
   678 
   505     QTest::newRow("first name, last name, organization")
   679     QTest::newRow("first name, last name, organization")
       
   680         << typeContact
   506         << "James Hunt"
   681         << "James Hunt"
   507         << (QStringList()
   682         << (QStringList()
   508             << "Name:FirstName:James"
   683             << "Name:FirstName:James"
   509             << "Name:LastName:Hunt"
   684             << "Name:LastName:Hunt"
   510             << "Organization:Name:McLaren");
   685             << "Organization:Name:McLaren");
   511 
   686 
   512     QTest::newRow("organization")
   687     QTest::newRow("organization")
       
   688         << typeContact
   513         << "McLaren"
   689         << "McLaren"
   514         << (QStringList()
   690         << (QStringList()
   515             << "Organization:Name:McLaren");
   691             << "Organization:Name:McLaren");
       
   692 
       
   693     QTest::newRow("nick name")
       
   694         << typeContact
       
   695         << ""
       
   696         << (QStringList()
       
   697             << "Nickname:Nickname:The Shunt");
       
   698 
       
   699     QTest::newRow("phone number")
       
   700         << typeContact
       
   701         << ""
       
   702         << (QStringList()
       
   703             << "PhoneNumber:PhoneNumber:+44759999999");
       
   704 
       
   705     QTest::newRow("no details")
       
   706         << typeContact
       
   707         << ""
       
   708         << QStringList();
       
   709 
       
   710     QTest::newRow("group, custom label")
       
   711         << typeGroup
       
   712         << "McLaren"
       
   713         << (QStringList()
       
   714             << "Name:CustomLabel:McLaren");
       
   715 
       
   716     QTest::newRow("group, no details")
       
   717         << typeGroup
       
   718         << ""
       
   719         << QStringList();
   516 }
   720 }
   517 
   721 
   518 /*
   722 /*
   519  * Special display label test cases for testing symbian backend specific
   723  * Special display label test cases for testing symbian backend specific
   520  * display label generation.
   724  * display label generation.
   521  */
   725  */
   522 void tst_QContactManagerSymbian::displayLabel()
   726 void tst_QContactManagerSymbian::displayLabel()
   523 {
   727 {
   524     qDebug() << QTest::currentDataTag();
   728     //qDebug() << QTest::currentDataTag();
       
   729     QFETCH(QString, contactType);
   525     QFETCH(QString, displayLabel);
   730     QFETCH(QString, displayLabel);
   526     QFETCH(QStringList, details);
   731     QFETCH(QStringList, details);
   527 
   732 
       
   733     QContact contact;
       
   734     if (contactType == QContactType::TypeGroup) {
       
   735         contact.setType(QContactType::TypeGroup);
       
   736     }
       
   737 
   528     // Parse details and add them to the contact
   738     // Parse details and add them to the contact
   529     QContact contact;
       
   530     foreach(const QString& detail, details) {
   739     foreach(const QString& detail, details) {
   531         // the expected format is <detail definition name>:<field name>:<value>
   740         // the expected format is <detail definition name>:<field name>:<value>
   532         QStringList detailParts = detail.split(QChar(':'), QString::KeepEmptyParts, Qt::CaseSensitive);
   741         QStringList detailParts = detail.split(QChar(':'), QString::KeepEmptyParts, Qt::CaseSensitive);
   533         QVERIFY(detailParts.count() == 3);
   742         QVERIFY(detailParts.count() == 3);
   534         QContactDetail contactDetail(detailParts[0]);
   743         QContactDetail contactDetail(detailParts[0]);
   554     QVERIFY(m_cm->removeContact(contact.localId()));
   763     QVERIFY(m_cm->removeContact(contact.localId()));
   555 }
   764 }
   556 
   765 
   557 void tst_QContactManagerSymbian::timestamp()
   766 void tst_QContactManagerSymbian::timestamp()
   558 {
   767 {
       
   768     if (!m_cm->detailDefinitions().keys().contains(QContactTimestamp::DefinitionName)) {
       
   769         // S60 3.1 does not support timestamps because cntmodel API for
       
   770         // that is not exported.
       
   771         QSKIP("Backend does not support timestamp!", SkipSingle);
       
   772     }
       
   773     
   559     // Save a contact
   774     // Save a contact
   560     QContact contact = createContact(QContactType::TypeContact, "Jame", "Hunt");
   775     QContact contact = createContact(QContactType::TypeContact, "Jame", "Hunt");
   561     QVERIFY(m_cm->saveContact(&contact));
   776     QVERIFY(m_cm->saveContact(&contact));
   562 
   777 
   563     // Wait a second to make the contact's timestamp a little older
   778     // Wait a second to make the contact's timestamp a little older
   577     QVERIFY(timestamp.created().secsTo(current) >= 1);
   792     QVERIFY(timestamp.created().secsTo(current) >= 1);
   578     QVERIFY(timestamp.lastModified().secsTo(current) <= 1);
   793     QVERIFY(timestamp.lastModified().secsTo(current) <= 1);
   579     QVERIFY(timestamp.lastModified().secsTo(current) >= 0);
   794     QVERIFY(timestamp.lastModified().secsTo(current) >= 0);
   580 
   795 
   581     // Delete the contact
   796     // Delete the contact
       
   797     QVERIFY(m_cm->removeContact(contact.localId()));
       
   798 }
       
   799 
       
   800 void tst_QContactManagerSymbian::onlineAccount_data()
       
   801 {
       
   802     QTest::addColumn<QString>("accountUri");
       
   803     QTest::addColumn<QStringList>("subTypes");
       
   804 
       
   805     QTest::newRow("SubTypeSip")
       
   806         << QString("+44728888888")
       
   807         << (QStringList()
       
   808             << QContactOnlineAccount::SubTypeSip);
       
   809     
       
   810     QTest::newRow("SubTypeSipVoip")
       
   811         << QString("+44727777777")
       
   812         << (QStringList()
       
   813             << QContactOnlineAccount::SubTypeSipVoip);
       
   814 
       
   815     QTest::newRow("SubTypeVideoShare")
       
   816         << QString("+44726666666")
       
   817         << (QStringList()
       
   818             << QContactOnlineAccount::SubTypeVideoShare);
       
   819 }
       
   820 
       
   821 void tst_QContactManagerSymbian::onlineAccount()
       
   822 {
       
   823     QFETCH(QString, accountUri);
       
   824     QFETCH(QStringList, subTypes);
       
   825 
       
   826     // Save a contact
       
   827     QContact contact = createContact(QContactType::TypeContact, "James", "Hunt");
       
   828     QVERIFY(m_cm->saveContact(&contact));
       
   829     QContactOnlineAccount onlineAccount;
       
   830     onlineAccount.setAccountUri(accountUri);
       
   831     onlineAccount.setSubTypes(subTypes);
       
   832     contact.saveDetail(&onlineAccount);
       
   833     QVERIFY(m_cm->saveContact(&contact));
       
   834 
       
   835     // verify by reading the saved contact and comparing online account data
       
   836     QContact retrievedContact = m_cm->contact(contact.localId());
       
   837     QContactOnlineAccount retrievedOnlineAccount = contact.detail(QContactOnlineAccount::DefinitionName);
       
   838     QCOMPARE(retrievedOnlineAccount.accountUri(), accountUri);
       
   839     QCOMPARE(retrievedOnlineAccount.subTypes(), subTypes);
       
   840 
       
   841     // Remove contact
   582     QVERIFY(m_cm->removeContact(contact.localId()));
   842     QVERIFY(m_cm->removeContact(contact.localId()));
   583 }
   843 }
   584 
   844 
   585 /*
   845 /*
   586  * Special contact handling test cases that cannot be covered in QtMobility
   846  * Special contact handling test cases that cannot be covered in QtMobility