1032 c = cm->contact(contacts.at(2).id().localId()); |
1032 c = cm->contact(contacts.at(2).id().localId()); |
1033 QVERIFY(contacts.at(0).detail(QContactName::DefinitionName) == na); |
1033 QVERIFY(contacts.at(0).detail(QContactName::DefinitionName) == na); |
1034 QVERIFY(contacts.at(1).detail(QContactName::DefinitionName) == nb); |
1034 QVERIFY(contacts.at(1).detail(QContactName::DefinitionName) == nb); |
1035 QVERIFY(contacts.at(2).detail(QContactName::DefinitionName) == nc); |
1035 QVERIFY(contacts.at(2).detail(QContactName::DefinitionName) == nc); |
1036 |
1036 |
|
1037 /* Save again, with a null error map */ |
|
1038 QVERIFY(cm->saveContacts(&contacts, NULL)); |
|
1039 QVERIFY(cm->error() == QContactManager::NoError); |
|
1040 |
1037 /* Now make an update to them all */ |
1041 /* Now make an update to them all */ |
1038 QContactPhoneNumber number; |
1042 QContactPhoneNumber number; |
1039 number.setNumber("1234567"); |
1043 number.setNumber("1234567"); |
1040 |
1044 |
1041 QVERIFY(contacts[0].saveDetail(&number)); |
1045 QVERIFY(contacts[0].saveDetail(&number)); |
1089 QVERIFY(cm->error() == QContactManager::DoesNotExistError); |
1093 QVERIFY(cm->error() == QContactManager::DoesNotExistError); |
1090 QVERIFY(errorMap.count() == 3); |
1094 QVERIFY(errorMap.count() == 3); |
1091 QVERIFY(errorMap.values().at(0) == QContactManager::DoesNotExistError); |
1095 QVERIFY(errorMap.values().at(0) == QContactManager::DoesNotExistError); |
1092 QVERIFY(errorMap.values().at(1) == QContactManager::DoesNotExistError); |
1096 QVERIFY(errorMap.values().at(1) == QContactManager::DoesNotExistError); |
1093 QVERIFY(errorMap.values().at(2) == QContactManager::DoesNotExistError); |
1097 QVERIFY(errorMap.values().at(2) == QContactManager::DoesNotExistError); |
|
1098 |
|
1099 /* And again with a null error map */ |
|
1100 QVERIFY(!cm->removeContacts(ids, NULL)); |
|
1101 QVERIFY(cm->error() == QContactManager::DoesNotExistError); |
1094 |
1102 |
1095 /* Try adding some new ones again, this time one with an error */ |
1103 /* Try adding some new ones again, this time one with an error */ |
1096 contacts.clear(); |
1104 contacts.clear(); |
1097 a.setId(QContactId()); |
1105 a.setId(QContactId()); |
1098 b.setId(QContactId()); |
1106 b.setId(QContactId()); |
1986 QTRY_COMPARE(spyCM.count(), 0); |
1994 QTRY_COMPARE(spyCM.count(), 0); |
1987 QTRY_COMPARE(spyCR.count(), 0); |
1995 QTRY_COMPARE(spyCR.count(), 0); |
1988 |
1996 |
1989 /* Batch modifies */ |
1997 /* Batch modifies */ |
1990 QContactName modifiedName = c.detail(QContactName::DefinitionName); |
1998 QContactName modifiedName = c.detail(QContactName::DefinitionName); |
1991 saveContactName(&c, nameDef, &modifiedName, "This is modified number 1"); |
1999 saveContactName(&c, nameDef, &modifiedName, "Modified number 1"); |
1992 modifiedName = c2.detail(QContactName::DefinitionName); |
2000 modifiedName = c2.detail(QContactName::DefinitionName); |
1993 saveContactName(&c2, nameDef, &modifiedName, "This is modified number 2"); |
2001 saveContactName(&c2, nameDef, &modifiedName, "Modified number 2"); |
1994 modifiedName = c3.detail(QContactName::DefinitionName); |
2002 modifiedName = c3.detail(QContactName::DefinitionName); |
1995 saveContactName(&c3, nameDef, &modifiedName, "This is modified number 3"); |
2003 saveContactName(&c3, nameDef, &modifiedName, "Modified number 3"); |
1996 |
2004 |
1997 batchAdd.clear(); |
2005 batchAdd.clear(); |
1998 batchAdd << c << c2 << c3; |
2006 batchAdd << c << c2 << c3; |
1999 QVERIFY(m1->saveContacts(&batchAdd, &errorMap)); |
2007 QVERIFY(m1->saveContacts(&batchAdd, &errorMap)); |
2000 |
2008 |
2010 |
2018 |
2011 QTRY_COMPARE(spyCA.count(), 0); |
2019 QTRY_COMPARE(spyCA.count(), 0); |
2012 QTRY_COMPARE(spyCM.count(), 0); |
2020 QTRY_COMPARE(spyCM.count(), 0); |
2013 |
2021 |
2014 QScopedPointer<QContactManager> m2(QContactManager::fromUri(uri)); |
2022 QScopedPointer<QContactManager> m2(QContactManager::fromUri(uri)); |
|
2023 |
|
2024 // During construction SIM backend (m2) will try writing contacts with |
|
2025 // nickname, email and additional number to find out if the SIM card |
|
2026 // will support these fields. The other backend (m1) will then receive |
|
2027 // signals about that. These need to be caught so they don't interfere |
|
2028 // with the tests. (This trial and error method is used because existing |
|
2029 // API for checking the availability of these fields is not public.) |
|
2030 // NOTE: This applies only to pre 10.1 platforms (S60 3.1, 3.2, ect.) |
|
2031 if (uri.contains("symbiansim")) { |
|
2032 QTest::qWait(0); |
|
2033 spyCA.clear(); |
|
2034 spyCM.clear(); |
|
2035 spyCR.clear(); |
|
2036 } |
2015 |
2037 |
2016 QVERIFY(m1->hasFeature(QContactManager::Anonymous) == |
2038 QVERIFY(m1->hasFeature(QContactManager::Anonymous) == |
2017 m2->hasFeature(QContactManager::Anonymous)); |
2039 m2->hasFeature(QContactManager::Anonymous)); |
2018 |
2040 |
2019 /* Now some cross manager testing */ |
2041 /* Now some cross manager testing */ |
2944 else { |
2966 else { |
2945 QVERIFY(source.relatedContacts(availableRelationshipTypes.at(0), QContactRelationship::Second).contains(dest3.id())); |
2967 QVERIFY(source.relatedContacts(availableRelationshipTypes.at(0), QContactRelationship::Second).contains(dest3.id())); |
2946 } |
2968 } |
2947 |
2969 |
2948 // Cleanup a bit |
2970 // Cleanup a bit |
2949 QVERIFY(cm->removeRelationship(customRelationshipOne)); |
2971 QMap<int, QContactManager::Error> errorMap; |
2950 QVERIFY(cm->removeRelationship(customRelationshipTwo)); |
2972 QList<QContactRelationship> moreRels; |
|
2973 |
|
2974 moreRels << customRelationshipOne << customRelationshipTwo; |
|
2975 errorMap.insert(5, QContactManager::BadArgumentError); |
|
2976 QVERIFY(cm->removeRelationships(moreRels, &errorMap)); |
|
2977 QVERIFY(errorMap.count() == 0); |
2951 |
2978 |
2952 // test batch API and ordering in contacts |
2979 // test batch API and ordering in contacts |
2953 QList<QContactRelationship> currentRelationships = cm->relationships(source.id(), QContactRelationship::First); |
2980 QList<QContactRelationship> currentRelationships = cm->relationships(source.id(), QContactRelationship::First); |
2954 QList<QContactRelationship> batchList; |
2981 QList<QContactRelationship> batchList; |
2955 QContactRelationship br1, br2, br3; |
2982 QContactRelationship br1, br2, br3; |
3055 |
3082 |
3056 // now we want to ensure that a relationship is removed if one of the contacts is removed. |
3083 // now we want to ensure that a relationship is removed if one of the contacts is removed. |
3057 customRelationshipOne.setFirst(source.id()); |
3084 customRelationshipOne.setFirst(source.id()); |
3058 customRelationshipOne.setSecond(dest2.id()); |
3085 customRelationshipOne.setSecond(dest2.id()); |
3059 customRelationshipOne.setRelationshipType(availableRelationshipTypes.at(0)); |
3086 customRelationshipOne.setRelationshipType(availableRelationshipTypes.at(0)); |
3060 QVERIFY(cm->saveRelationship(&customRelationshipOne)); |
3087 |
|
3088 // Test batch save with an error map |
|
3089 moreRels.clear(); |
|
3090 moreRels << customRelationshipOne; |
|
3091 errorMap.insert(0, QContactManager::BadArgumentError); |
|
3092 QVERIFY(cm->saveRelationships(&moreRels, &errorMap)); |
|
3093 QVERIFY(cm->error() == QContactManager::NoError); |
|
3094 QVERIFY(errorMap.count() == 0); // should be reset |
3061 source = cm->contact(source.localId()); |
3095 source = cm->contact(source.localId()); |
3062 dest2 = cm->contact(dest2.localId()); |
3096 dest2 = cm->contact(dest2.localId()); |
3063 QVERIFY(cm->removeContact(dest2.localId())); // remove dest2, the relationship should be removed |
3097 QVERIFY(cm->removeContact(dest2.localId())); // remove dest2, the relationship should be removed |
3064 QVERIFY(cm->relationships(availableRelationshipTypes.at(0), dest2.id(), QContactRelationship::Second).isEmpty()); |
3098 QVERIFY(cm->relationships(availableRelationshipTypes.at(0), dest2.id(), QContactRelationship::Second).isEmpty()); |
3065 source = cm->contact(source.localId()); |
3099 source = cm->contact(source.localId()); |