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") |
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) |
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 */ |