diff options
author | Zheng Fu <zhengfu@google.com> | 2015-07-17 16:38:43 -0700 |
---|---|---|
committer | Zheng Fu <zhengfu@google.com> | 2015-07-17 16:41:36 -0700 |
commit | e5bd832dd7743f98fd816f7e6568f715015764bd (patch) | |
tree | c2a3898cbd556a8e5ec6fc69722ed5378c2e2502 | |
parent | f3d2981b53b7d4715da1d35f5425b19766a92f8b (diff) | |
download | packages_providers_ContactsProvider-e5bd832dd7743f98fd816f7e6568f715015764bd.zip packages_providers_ContactsProvider-e5bd832dd7743f98fd816f7e6568f715015764bd.tar.gz packages_providers_ContactsProvider-e5bd832dd7743f98fd816f7e6568f715015764bd.tar.bz2 |
Fix failing tests due to logic changes in the new aggregator.
1. All the raw contacts with same name and no data will group together,
so we need to assign different names in this test.
2. We don't have split step anymore, so there is no unpin operation.
3. Fix Long comparison in the aggregator.
Bug:22566083
Change-Id: I1a963bf17866e7569012e4cceca034e7c8312aa3
4 files changed, 31 insertions, 12 deletions
diff --git a/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java b/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java index c18c1d6..5895f51 100644 --- a/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java +++ b/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java @@ -867,8 +867,6 @@ public abstract class AbstractContactAggregator { contactId = mContactInsert.executeInsert(); } for (Long rawContactId : rawContactIds) { - // Regrouped contacts should automatically be unpinned. - unpinRawContact(rawContactId); setContactIdAndMarkAggregated(rawContactId, contactId); setPresenceContactId(rawContactId, contactId); } diff --git a/src/com/android/providers/contacts/aggregation/ContactAggregator2.java b/src/com/android/providers/contacts/aggregation/ContactAggregator2.java index 9beb6c2..5372bbd 100644 --- a/src/com/android/providers/contacts/aggregation/ContactAggregator2.java +++ b/src/com/android/providers/contacts/aggregation/ContactAggregator2.java @@ -340,7 +340,7 @@ public class ContactAggregator2 extends AbstractContactAggregator { contactId = currentCidForRawContact; for (Long connectedRawContactId : connectedRawContactIds) { Long cid = matchingCandidates.getContactId(connectedRawContactId); - if (cid != null && cid != contactId) { + if (cid != null && !cid.equals(contactId)) { cidsNeedToBeUpdated.add(cid); } } diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index 4f05f88..7072763 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -8568,12 +8568,18 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { } public void testPinnedPositionsAfterJoinAndSplit() { - final DatabaseAsserts.ContactIdPair i1 = DatabaseAsserts.assertAndCreateContact(mResolver); - final DatabaseAsserts.ContactIdPair i2 = DatabaseAsserts.assertAndCreateContact(mResolver); - final DatabaseAsserts.ContactIdPair i3 = DatabaseAsserts.assertAndCreateContact(mResolver); - final DatabaseAsserts.ContactIdPair i4 = DatabaseAsserts.assertAndCreateContact(mResolver); - final DatabaseAsserts.ContactIdPair i5 = DatabaseAsserts.assertAndCreateContact(mResolver); - final DatabaseAsserts.ContactIdPair i6 = DatabaseAsserts.assertAndCreateContact(mResolver); + final DatabaseAsserts.ContactIdPair i1 = DatabaseAsserts.assertAndCreateContactWithName( + mResolver, "A", "Smith"); + final DatabaseAsserts.ContactIdPair i2 = DatabaseAsserts.assertAndCreateContactWithName( + mResolver, "B", "Smith"); + final DatabaseAsserts.ContactIdPair i3 = DatabaseAsserts.assertAndCreateContactWithName( + mResolver, "C", "Smith"); + final DatabaseAsserts.ContactIdPair i4 = DatabaseAsserts.assertAndCreateContactWithName( + mResolver, "D", "Smith"); + final DatabaseAsserts.ContactIdPair i5 = DatabaseAsserts.assertAndCreateContactWithName( + mResolver, "E", "Smith"); + final DatabaseAsserts.ContactIdPair i6 = DatabaseAsserts.assertAndCreateContactWithName( + mResolver, "F", "Smith"); final ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(); @@ -8643,7 +8649,7 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { // raw contacts should be unpinned after being split, but still starred assertStoredValuesWithProjection(RawContacts.CONTENT_URI, - cv(RawContacts._ID, i1.mRawContactId, RawContacts.PINNED, PinnedPositions.UNPINNED, + cv(RawContacts._ID, i1.mRawContactId, RawContacts.PINNED, 1, RawContacts.STARRED, 1), cv(RawContacts._ID, i2.mRawContactId, RawContacts.PINNED, 2, RawContacts.STARRED, 1), @@ -8668,7 +8674,7 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { final long cId4 = RawContactUtil.queryContactIdByRawContactId(mResolver, i4.mRawContactId); assertStoredValuesWithProjection(Contacts.CONTENT_URI, - cv(Contacts._ID, cId1, Contacts.PINNED, PinnedPositions.UNPINNED), + cv(Contacts._ID, cId1, Contacts.PINNED, 1), cv(Contacts._ID, i2.mContactId, Contacts.PINNED, 2), cv(Contacts._ID, cId4, Contacts.PINNED, PinnedPositions.UNPINNED), cv(Contacts._ID, i5.mContactId, Contacts.PINNED, PinnedPositions.DEMOTED), @@ -8681,7 +8687,7 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { // The resulting contact should have a pinned value of 6 assertStoredValuesWithProjection(Contacts.CONTENT_URI, - cv(Contacts._ID, cId1, Contacts.PINNED, PinnedPositions.UNPINNED), + cv(Contacts._ID, cId1, Contacts.PINNED, 1), cv(Contacts._ID, i2.mContactId, Contacts.PINNED, 2), cv(Contacts._ID, cId4, Contacts.PINNED, PinnedPositions.UNPINNED), cv(Contacts._ID, i5.mContactId, Contacts.PINNED, 6) diff --git a/tests/src/com/android/providers/contacts/testutil/DatabaseAsserts.java b/tests/src/com/android/providers/contacts/testutil/DatabaseAsserts.java index ac4df17..2af9829 100644 --- a/tests/src/com/android/providers/contacts/testutil/DatabaseAsserts.java +++ b/tests/src/com/android/providers/contacts/testutil/DatabaseAsserts.java @@ -64,6 +64,21 @@ public class DatabaseAsserts { } /** + * Create a contact with name and assert that the record exists. + * + * @return The created contact id pair. + */ + public static ContactIdPair assertAndCreateContactWithName(ContentResolver resolver, + String firstName, String lastName) { + long rawContactId = RawContactUtil.createRawContactWithName(resolver, firstName, lastName); + + long contactId = RawContactUtil.queryContactIdByRawContactId(resolver, rawContactId); + MoreAsserts.assertNotEqual(CommonDatabaseUtils.NOT_FOUND, contactId); + + return new ContactIdPair(contactId, rawContactId); + } + + /** * Asserts that a contact id was deleted, has a delete log, and that log has a timestamp greater * than the given timestamp. * |