qtmobility/plugins/contacts/symbiansim/tsrc/tst_simcm/tst_simcm.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
   106     void batchOperations_data();
   106     void batchOperations_data();
   107     void batchOperations();
   107     void batchOperations();
   108 
   108 
   109     /* Test cases that take no data */
   109     /* Test cases that take no data */
   110     void signalEmission();
   110     void signalEmission();
       
   111     void sdnContacts();
   111 
   112 
   112 private:
   113 private:
   113     void initManager(QString simStore);
   114     void initManager(QString simStore);
   114     void getEtelStoreInfoL(const TDesC &phonebook, TDes8 &infoPckg) const;
   115     void getEtelStoreInfoL(const TDesC &phonebook, TDes8 &infoPckg) const;
   115     bool isContactSupported(QContact contact);
   116     bool isContactSupported(QContact contact);
   117     void compareDetails(QContact contact, QList<QContactDetail> expectedDetails);
   118     void compareDetails(QContact contact, QList<QContactDetail> expectedDetails);
   118     QContact createContact(QString name, QString number);
   119     QContact createContact(QString name, QString number);
   119 
   120 
   120 private:
   121 private:
   121     QContactManager* m_cm;
   122     QContactManager* m_cm;
       
   123 #ifdef SYMBIANSIM_BACKEND_PHONEBOOKINFOV1
       
   124     RMobilePhoneBookStore::TMobilePhoneBookInfoV1 m_etelStoreInfo;
       
   125     RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg m_etelStoreInfoPckg;
       
   126 #else
   122     RMobilePhoneBookStore::TMobilePhoneBookInfoV5 m_etelStoreInfo;
   127     RMobilePhoneBookStore::TMobilePhoneBookInfoV5 m_etelStoreInfo;
   123     RMobilePhoneBookStore::TMobilePhoneBookInfoV5Pckg m_etelStoreInfoPckg;
   128     RMobilePhoneBookStore::TMobilePhoneBookInfoV5Pckg m_etelStoreInfoPckg;
       
   129 #endif
   124 };
   130 };
   125 
   131 
   126 tst_SimCM::tst_SimCM() :
   132 tst_SimCM::tst_SimCM() :
   127     m_cm(0),
   133     m_cm(0),
   128     m_etelStoreInfoPckg(m_etelStoreInfo)
   134     m_etelStoreInfoPckg(m_etelStoreInfo)
   135 
   141 
   136 void tst_SimCM::init()
   142 void tst_SimCM::init()
   137 {
   143 {
   138     // remove all contacts
   144     // remove all contacts
   139     QList<QContactLocalId> ids = m_cm->contactIds();
   145     QList<QContactLocalId> ids = m_cm->contactIds();
   140     m_cm->removeContacts(&ids, 0);   
   146     m_cm->removeContacts(ids, 0);   
   141 }
   147 }
   142 
   148 
   143 void tst_SimCM::cleanup()
   149 void tst_SimCM::cleanup()
   144 {
   150 {
   145     // remove all contacts
   151     // remove all contacts
   146     QList<QContactLocalId> ids = m_cm->contactIds();
   152     QList<QContactLocalId> ids = m_cm->contactIds();
   147     m_cm->removeContacts(&ids, 0);   
   153     m_cm->removeContacts(ids, 0);   
   148 }
   154 }
   149 
   155 
   150 void tst_SimCM::initTestCase()
   156 void tst_SimCM::initTestCase()
   151 {
   157 {
   152     initManager(QString());
   158     initManager(QString());
   164 
   170 
   165 void tst_SimCM::initManager_data()
   171 void tst_SimCM::initManager_data()
   166 {
   172 {
   167     QTest::addColumn<QString>("simStore"); // empty (defaults to ADN), "ADN", "SDN" or "FDN"
   173     QTest::addColumn<QString>("simStore"); // empty (defaults to ADN), "ADN", "SDN" or "FDN"
   168 
   174 
   169     QString es = QString();
   175     QString es;
   170 
   176 
   171     QTest::newRow("Empty store string (defaults to ADN store)") << es;
   177     QTest::newRow("Empty store string (defaults to ADN store)") << es;
   172     QTest::newRow("Initialize SDN store") << "SDN";
   178     QTest::newRow("Initialize SDN store") << "SDN";
   173     QTest::newRow("Initialize FDN store") << "FDN";
   179     QTest::newRow("Initialize FDN store") << "FDN";
   174     QTest::newRow("Initialize ADN store") << "ADN";
   180     QTest::newRow("Initialize ADN store") << "ADN";
   218 void tst_SimCM::hasFeature_data()
   224 void tst_SimCM::hasFeature_data()
   219 {
   225 {
   220     QTest::addColumn<QString>("simStore");      // empty (defaults to ADN), "ADN", "SDN" or "FDN"
   226     QTest::addColumn<QString>("simStore");      // empty (defaults to ADN), "ADN", "SDN" or "FDN"
   221     QTest::addColumn<int>("managerFeature");              // one of QContactManager::ManagerFeature
   227     QTest::addColumn<int>("managerFeature");              // one of QContactManager::ManagerFeature
   222     QTest::addColumn<bool>("expectedResult");   // true = has feature, false = does not have feature
   228     QTest::addColumn<bool>("expectedResult");   // true = has feature, false = does not have feature
   223     QString es = QString();
   229     QString es;
   224 
   230 
   225     QTest::newRow("ADN store (default)") << es << (int) QContactManager::Groups << false;
   231     QTest::newRow("ADN store (default)") << es << (int) QContactManager::Groups << false;
   226     QTest::newRow("ADN store (default)") << es << (int) QContactManager::ActionPreferences << false;
   232     QTest::newRow("ADN store (default)") << es << (int) QContactManager::ActionPreferences << false;
   227     QTest::newRow("ADN store (default)") << es << (int) QContactManager::MutableDefinitions << false;
   233     QTest::newRow("ADN store (default)") << es << (int) QContactManager::MutableDefinitions << false;
   228     QTest::newRow("ADN store (default)") << es << (int) QContactManager::Relationships << false;
   234     QTest::newRow("ADN store (default)") << es << (int) QContactManager::Relationships << false;
   229     QTest::newRow("ADN store (default)") << es << (int) QContactManager::ArbitraryRelationshipTypes << false;
   235     QTest::newRow("ADN store (default)") << es << (int) QContactManager::ArbitraryRelationshipTypes << false;
   230     QTest::newRow("ADN store (default)") << es << (int) QContactManager::RelationshipOrdering << false;
       
   231     // TODO: self contact may be supported on ADN? (so called "own number store")
   236     // TODO: self contact may be supported on ADN? (so called "own number store")
   232     QTest::newRow("ADN store (default)") << es << (int) QContactManager::SelfContact << false;
   237     QTest::newRow("ADN store (default)") << es << (int) QContactManager::SelfContact << false;
   233     QTest::newRow("ADN store (default)") << es << (int) QContactManager::Anonymous << false;
   238     QTest::newRow("ADN store (default)") << es << (int) QContactManager::Anonymous << false;
   234     QTest::newRow("ADN store (default)") << es << (int) QContactManager::ChangeLogs << false;
   239     QTest::newRow("ADN store (default)") << es << (int) QContactManager::ChangeLogs << false;
   235 
   240 
   236     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::Groups << false;
   241     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::Groups << false;
   237     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::ActionPreferences << false;
   242     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::ActionPreferences << false;
   238     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::MutableDefinitions << false;
   243     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::MutableDefinitions << false;
   239     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::Relationships << false;
   244     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::Relationships << false;
   240     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::ArbitraryRelationshipTypes << false;
   245     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::ArbitraryRelationshipTypes << false;
   241     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::RelationshipOrdering << false;
       
   242     // TODO: self contact may be supported on ADN? (so called "own number store")
   246     // TODO: self contact may be supported on ADN? (so called "own number store")
   243     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::SelfContact << false;
   247     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::SelfContact << false;
   244     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::Anonymous << false;
   248     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::Anonymous << false;
   245     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::ChangeLogs << false;
   249     QTest::newRow("ADN store") << "ADN" << (int) QContactManager::ChangeLogs << false;
   246 
   250 
   247     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::Groups << false;
   251     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::Groups << false;
   248     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::ActionPreferences << false;
   252     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::ActionPreferences << false;
   249     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::MutableDefinitions << false;
   253     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::MutableDefinitions << false;
   250     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::Relationships << false;
   254     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::Relationships << false;
   251     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::ArbitraryRelationshipTypes << false;
   255     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::ArbitraryRelationshipTypes << false;
   252     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::RelationshipOrdering << false;
       
   253     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::SelfContact << false;
   256     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::SelfContact << false;
   254     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::Anonymous << false;
   257     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::Anonymous << false;
   255     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::ChangeLogs << false;
   258     QTest::newRow("SDN store") << "SDN" << (int) QContactManager::ChangeLogs << false;
   256 
   259 
   257     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::Groups << false;
   260     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::Groups << false;
   258     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::ActionPreferences << false;
   261     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::ActionPreferences << false;
   259     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::MutableDefinitions << false;
   262     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::MutableDefinitions << false;
   260     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::Relationships << false;
   263     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::Relationships << false;
   261     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::ArbitraryRelationshipTypes << false;
   264     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::ArbitraryRelationshipTypes << false;
   262     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::RelationshipOrdering << false;
       
   263     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::SelfContact << false;
   265     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::SelfContact << false;
   264     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::Anonymous << false;
   266     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::Anonymous << false;
   265     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::ChangeLogs << false;
   267     QTest::newRow("FDN store") << "FDN" << (int) QContactManager::ChangeLogs << false;
   266 }
   268 }
   267 
   269 
   351     QTest::addColumn<QString>("simStore"); // empty (defaults to ADN), "ADN", "SDN" or "FDN"
   353     QTest::addColumn<QString>("simStore"); // empty (defaults to ADN), "ADN", "SDN" or "FDN"
   352     QTest::addColumn<int>("expectedResult"); // 1 = pass, 0 = fail, -1 = depends on the SIM card
   354     QTest::addColumn<int>("expectedResult"); // 1 = pass, 0 = fail, -1 = depends on the SIM card
   353     QTest::addColumn<QString>("expectedDisplayLabel");
   355     QTest::addColumn<QString>("expectedDisplayLabel");
   354     QTest::addColumn<QStringList>("details"); // format is <detail definition name>:<field name>:<value>
   356     QTest::addColumn<QStringList>("details"); // format is <detail definition name>:<field name>:<value>
   355     QString unnamedLabel("Unnamed");
   357     QString unnamedLabel("Unnamed");
   356     QString es = QString();
   358     QString es;
   357     QString tooLongText("James Hunt the 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890th");
   359     QString tooLongText("James Hunt the 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890th");
   358 
   360 
   359     // TODO: what name field to use for a sim contact name?
   361     // TODO: what name field to use for a sim contact name?
   360     // Note: With the current implementation the value must not contain a ':' character
   362     // Note: With the current implementation the value must not contain a ':' character
   361     QTest::newRow("ADN custom label")
   363     QTest::newRow("ADN custom label")
   544         << 0 // It is not possible to save an SDN contact
   546         << 0 // It is not possible to save an SDN contact
   545         << "James"
   547         << "James"
   546         << (QStringList()
   548         << (QStringList()
   547             << "Name:CustomLabel:James");
   549             << "Name:CustomLabel:James");
   548 
   550 
   549     // TODO: Test saving FDN contacts?
   551     // Note: Executing FDN test cases has a pre-condition that the user must
       
   552     // have been entered the PIN2 code successfully. On pre-10.1 platforms this
       
   553     // can be done by opening S60 platform Phonebook and making some
       
   554     // modifications that require PIN2 code; for example activate and
       
   555     // de-activate FDN feature.
       
   556     QTest::newRow("FDN custom label and phone number")
       
   557         << "FDN"
       
   558         << 1
       
   559         << "James"
       
   560         << (QStringList()
       
   561             << "Name:CustomLabel:James"
       
   562             << "PhoneNumber:PhoneNumber:+44752222222");
   550 }
   563 }
   551 
   564 
   552 /*
   565 /*
   553  * Tests if different contacts can be saved to SIM card.
   566  * Tests if different contacts can be saved to SIM card.
   554  * Steps:
   567  * Steps:
   681         QVERIFY(contact.id() != QContactId());
   694         QVERIFY(contact.id() != QContactId());
   682         addedContacts.append(contact.localId());
   695         addedContacts.append(contact.localId());
   683     }
   696     }
   684 
   697 
   685     // 2. Fetch contacts
   698     // 2. Fetch contacts
   686     QList<QContact> contacts= m_cm->contacts(QList<QContactSortOrder>(), QStringList());
   699     QList<QContact> contacts= m_cm->contacts();
   687     QCOMPARE(m_cm->error(), QContactManager::NoError);
   700     QCOMPARE(m_cm->error(), QContactManager::NoError);
   688     QList<QContactLocalId> contactIds = m_cm->contactIds();
   701     QList<QContactLocalId> contactIds = m_cm->contactIds();
   689     QCOMPARE(m_cm->error(), QContactManager::NoError);
   702     QCOMPARE(m_cm->error(), QContactManager::NoError);
   690 
   703 
   691     // 3. Verify result
   704     // 3. Verify result
   692     QVERIFY(contacts.count() > 0);
   705     QVERIFY(contacts.count() > 0);
   693     QCOMPARE(contacts.count(), existingContactCount + contactCount);
   706     QCOMPARE(contacts.count(), existingContactCount + contactCount);
   694     foreach (QContact contact, contacts) {
   707     foreach (const QContact& contact, contacts) {
   695         QVERIFY(contact.id() != QContactId());
   708         QVERIFY(contact.id() != QContactId());
   696     }
   709     }
   697 
   710 
   698     QVERIFY(contactIds.count() > 0);
   711     QVERIFY(contactIds.count() > 0);
   699     QCOMPARE(contactIds.count(), existingContactCount + contactCount);
   712     QCOMPARE(contactIds.count(), existingContactCount + contactCount);
   836     QVERIFY(m_cm->saveContact(&contact));
   849     QVERIFY(m_cm->saveContact(&contact));
   837     QCOMPARE(m_cm->error(), QContactManager::NoError);
   850     QCOMPARE(m_cm->error(), QContactManager::NoError);
   838     compareDetails(contact, parsedDetails);
   851     compareDetails(contact, parsedDetails);
   839 
   852 
   840     // 3. Update contact detail and verify result
   853     // 3. Update contact detail and verify result
   841     foreach (QContactDetail detail, parsedDetails) {
   854     foreach (const QContactDetail& detail, parsedDetails) {
   842         QContactDetail savedDetail = contact.detail(detail.definitionName());
   855         QContactDetail savedDetail = contact.detail(detail.definitionName());
   843         QVERIFY(contact.removeDetail(&savedDetail));
   856         QVERIFY(contact.removeDetail(&savedDetail));
   844     }
   857     }
   845     parseDetails(contact, updatedDetails, parsedDetails);
   858     parseDetails(contact, updatedDetails, parsedDetails);
   846     if (!isContactSupported(contact)) {
   859     if (!isContactSupported(contact)) {
   908     // 1. Add contacts
   921     // 1. Add contacts
   909     if (expectedResult) {
   922     if (expectedResult) {
   910         QVERIFY(m_cm->saveContacts(&contacts, &errorMap));
   923         QVERIFY(m_cm->saveContacts(&contacts, &errorMap));
   911         QCOMPARE(m_cm->error(), QContactManager::NoError);
   924         QCOMPARE(m_cm->error(), QContactManager::NoError);
   912         QCOMPARE(errorMap.count(), 0);
   925         QCOMPARE(errorMap.count(), 0);
   913         foreach (QContact contact, contacts) {
   926         foreach (const QContact& contact, contacts) {
   914             QVERIFY(contact.id() != QContactId());
   927             QVERIFY(contact.id() != QContactId());
   915         }
   928         }
   916     } else {
   929     } else {
   917         QVERIFY(!m_cm->saveContacts(&contacts, &errorMap));
   930         QVERIFY(!m_cm->saveContacts(&contacts, &errorMap));
   918         QVERIFY(m_cm->error() != QContactManager::NoError);
   931         QVERIFY(m_cm->error() != QContactManager::NoError);
   919         QCOMPARE(errorMap.count(), 10);
   932         QCOMPARE(errorMap.count(), 10);
   920         foreach (QContact contact, contacts) {
   933         foreach (const QContact& contact, contacts) {
   921             QCOMPARE(contact.id(), QContactId());
   934             QCOMPARE(contact.id(), QContactId());
   922         }
   935         }
   923     }
   936     }
   924 
   937 
   925     // 2. Update contacts (updates name of each contact)
   938     // 2. Update contacts (updates name of each contact)
   937     }
   950     }
   938 
   951 
   939     // 3. Remove contacts
   952     // 3. Remove contacts
   940     if(expectedResult) {
   953     if(expectedResult) {
   941         QList<QContactLocalId> contactIds;
   954         QList<QContactLocalId> contactIds;
   942         foreach (QContact contact, contacts) {
   955         foreach (const QContact& contact, contacts) {
   943             contactIds.append(contact.localId());
   956             contactIds.append(contact.localId());
   944         }
   957         }
   945         QVERIFY(m_cm->removeContacts(&contactIds, &errorMap));
   958         QVERIFY(m_cm->removeContacts(contactIds, &errorMap));
   946         QCOMPARE(m_cm->error(), QContactManager::NoError);
   959         QCOMPARE(m_cm->error(), QContactManager::NoError);
   947         QCOMPARE(errorMap.count(), 0);
   960         QCOMPARE(errorMap.count(), 0);
   948     }
   961     }
   949 }
   962 }
   950 
   963 
   974     // 3. one contact removed
   987     // 3. one contact removed
   975     QVERIFY(m_cm->removeContact(contact.localId()));
   988     QVERIFY(m_cm->removeContact(contact.localId()));
   976     QTRY_COMPARE(spyRemoved.count(), 1);
   989     QTRY_COMPARE(spyRemoved.count(), 1);
   977 
   990 
   978     // 4. contacts added
   991     // 4. contacts added
       
   992     spyAdded.clear();
   979     int batchOpCount(10);
   993     int batchOpCount(10);
   980     QList<QContact> contacts;
   994     QList<QContact> contacts;
   981     for(int i(0); i < batchOpCount; i++) {
   995     for(int i(0); i < batchOpCount; i++) {
   982         QContact contact = createContact(
   996         QContact contact = createContact(
   983             QString("James").append(QString::number(i + 1)),
   997             QString("James").append(QString::number(i + 1)),
   987     QMap<int, QContactManager::Error> errorMap;
  1001     QMap<int, QContactManager::Error> errorMap;
   988     QVERIFY(m_cm->saveContacts(&contacts, &errorMap));
  1002     QVERIFY(m_cm->saveContacts(&contacts, &errorMap));
   989     QTRY_COMPARE(spyAdded.count(), batchOpCount);
  1003     QTRY_COMPARE(spyAdded.count(), batchOpCount);
   990 
  1004 
   991     // 5. contacts changed
  1005     // 5. contacts changed
       
  1006     spyChanged.clear();
   992     QVERIFY(m_cm->saveContacts(&contacts, &errorMap));
  1007     QVERIFY(m_cm->saveContacts(&contacts, &errorMap));
   993     QTRY_COMPARE(spyChanged.count(), batchOpCount);
  1008     QTRY_COMPARE(spyChanged.count(), batchOpCount);
   994 
  1009 
   995     // 6. contacts removed
  1010     // 6. contacts removed
       
  1011     spyRemoved.clear();
   996     QList<QContactLocalId> contactIds;
  1012     QList<QContactLocalId> contactIds;
   997     foreach(QContact contact, contacts) {
  1013     foreach(const QContact& contact, contacts) {
   998         contactIds.append(contact.localId());
  1014         contactIds.append(contact.localId());
   999     }
  1015     }
  1000     QVERIFY(m_cm->removeContacts(&contactIds, &errorMap));
  1016     QVERIFY(m_cm->removeContacts(contactIds, &errorMap));
  1001     QTRY_COMPARE(spyRemoved.count(), batchOpCount);
  1017     QTRY_COMPARE(spyRemoved.count(), batchOpCount);
       
  1018 }
       
  1019 
       
  1020 /*!
       
  1021  * Tests SDN store specific stuff
       
  1022  */
       
  1023 void tst_SimCM::sdnContacts()
       
  1024 {
       
  1025     QString uri("qtcontacts:symbiansim:store=SDN");
       
  1026     QScopedPointer<QContactManager> cm(QContactManager::fromUri(uri));
       
  1027     if (cm->error() == QContactManager::NotSupportedError)
       
  1028         QSKIP("The store not supported by the SIM card", SkipSingle);
       
  1029     
       
  1030     QVERIFY(cm->error() == QContactManager::NoError);
       
  1031     
       
  1032     // Verify that contact details have read only flag
       
  1033     QList<QContact> contacts = cm->contacts();
       
  1034     QVERIFY(contacts.count());
       
  1035     foreach(const QContact& c, contacts) {
       
  1036         foreach(const QContactDetail& d, c.details()) {
       
  1037             QVERIFY(d.accessConstraints().testFlag(QContactDetail::ReadOnly));
       
  1038         }
       
  1039     }
       
  1040 
       
  1041     // Writing should fail
       
  1042     QContact c = createContact("foo", "1234567");
       
  1043     QVERIFY(!cm->saveContact(&c));
  1002 }
  1044 }
  1003 
  1045 
  1004 /*!
  1046 /*!
  1005  * Private helper function for checking the data format that the store supports
  1047  * Private helper function for checking the data format that the store supports
  1006  */
  1048  */
  1043     if(!m_cm->supportedContactTypes().contains(contact.type()))
  1085     if(!m_cm->supportedContactTypes().contains(contact.type()))
  1044         return false;
  1086         return false;
  1045         
  1087         
  1046     QList<QString> uniqueDetails = QList<QString>();
  1088     QList<QString> uniqueDetails = QList<QString>();
  1047 
  1089 
  1048     foreach(QContactDetail detail, contact.details()) {
  1090     foreach(const QContactDetail& detail, contact.details()) {
  1049         QString definitionName = detail.definitionName();
  1091         QString definitionName = detail.definitionName();
  1050 
  1092 
  1051         // TODO: should we save a contact that has empty, non-supported details?
  1093         // TODO: should we save a contact that has empty, non-supported details?
  1052         // The current implementation is to ignore empty details here which
  1094         // The current implementation is to ignore empty details here which
  1053         // means that the backend should also ignore the empty details, even
  1095         // means that the backend should also ignore the empty details, even
  1069                     uniqueDetails.append(detail.definitionName());
  1111                     uniqueDetails.append(detail.definitionName());
  1070                 }
  1112                 }
  1071             }
  1113             }
  1072 
  1114 
  1073             // check the fields of the detail
  1115             // check the fields of the detail
  1074             foreach (QString fieldKey, detail.variantValues().keys()) {
  1116             foreach (const QString& fieldKey, detail.variantValues().keys()) {
  1075                 if (!detailDef.fields().contains(fieldKey)) {
  1117                 if (!detailDef.fields().contains(fieldKey)) {
  1076                     return false;
  1118                     return false;
  1077                 }
  1119                 }
  1078             }
  1120             }
  1079 
  1121 
  1091  * string lists).
  1133  * string lists).
  1092  */
  1134  */
  1093 void tst_SimCM::parseDetails(QContact &contact, QStringList details, QList<QContactDetail> &parsedDetails)
  1135 void tst_SimCM::parseDetails(QContact &contact, QStringList details, QList<QContactDetail> &parsedDetails)
  1094 {
  1136 {
  1095     parsedDetails.clear();
  1137     parsedDetails.clear();
  1096     foreach (QString detail, details) {
  1138     foreach (const QString& detail, details) {
  1097         // the expected format is <detail definition name>:<field name>:<value>
  1139         // the expected format is <detail definition name>:<field name>:<value>
  1098         QStringList detailParts = detail.split(QChar(':'), QString::KeepEmptyParts, Qt::CaseSensitive);
  1140         QStringList detailParts = detail.split(QChar(':'), QString::KeepEmptyParts, Qt::CaseSensitive);
  1099         QVERIFY(detailParts.count() == 3);
  1141         QVERIFY(detailParts.count() == 3);
  1100     
  1142     
  1101         // Use existing detail if available and would not cause an overwrite of
  1143         // Use existing detail if available and would not cause an overwrite of
  1140         }
  1182         }
  1141 
  1183 
  1142         if(!contact.details().contains(expectedDetail)) {
  1184         if(!contact.details().contains(expectedDetail)) {
  1143             // FAIL! Make it easier to debug the output by
  1185             // FAIL! Make it easier to debug the output by
  1144             // comparing the contact detail field contents
  1186             // comparing the contact detail field contents
  1145             foreach (QString key, expectedDetail.variantValues().keys()) {
  1187             foreach (const QString& key, expectedDetail.variantValues().keys()) {
  1146                 QVariant value1 = actualDetail.value(key);
  1188                 QVariant value1 = actualDetail.value(key);
  1147                 QVariant value2 = expectedDetail.value(key);
  1189                 QVariant value2 = expectedDetail.value(key);
  1148                 QCOMPARE(actualDetail.value(key), expectedDetail.value(key));
  1190                 QCOMPARE(actualDetail.value(key), expectedDetail.value(key));
  1149             }
  1191             }
  1150         }
  1192         }