Loading tests/src/com/android/contacts/model/RawContactDeltaListTests.java +35 −19 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package com.android.contacts.model; import android.content.ContentProviderOperation; import android.content.ContentProviderResult; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.net.Uri; Loading Loading @@ -56,6 +58,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { public static final long CONTACT_BOB = 10; public static final long CONTACT_MARY = 11; public static final long INSERTED_CONTACT_ID = 3; public static final long PHONE_RED = 20; public static final long PHONE_GREEN = 21; public static final long PHONE_BLUE = 22; Loading Loading @@ -182,6 +186,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { static void assertDiffPattern(ArrayList<CPOWrapper> diff, CPOWrapper... pattern) { assertEquals("Unexpected operations", pattern.length, diff.size()); ContentProviderResult[] fakeBackReferences = new ContentProviderResult[diff.size()]; for (int i = 0; i < pattern.length; i++) { final CPOWrapper expected = pattern[i]; final CPOWrapper found = diff.get(i); Loading @@ -193,21 +199,25 @@ public class RawContactDeltaListTests extends AndroidTestCase { final String foundType = getTypeString(found); assertEquals("Unexpected type", expectedType, foundType); if (CompatUtils.isDeleteCompat(expected)) continue; if (CompatUtils.isDeleteCompat(expected)) { continue; } try { final ContentValues expectedValues = getValues(expected.getOperation()); final ContentValues foundValues = getValues(found.getOperation()); if (CompatUtils.isInsertCompat(found)) { fakeBackReferences[i] = new ContentProviderResult( ContentUris.withAppendedId(RawContacts.CONTENT_URI, INSERTED_CONTACT_ID)); } else if (CompatUtils.isUpdateCompat(found)) { fakeBackReferences[i] = new ContentProviderResult(1); } ContentValues expectedValues = expected.getOperation().resolveValueBackReferences( new ContentProviderResult[0], 0); ContentValues foundValues = found.getOperation().resolveValueBackReferences( fakeBackReferences, fakeBackReferences.length); expectedValues.remove(BaseColumns._ID); foundValues.remove(BaseColumns._ID); assertEquals("Unexpected values", expectedValues, foundValues); } catch (NoSuchFieldException e) { fail(e.toString()); } catch (IllegalAccessException e) { fail(e.toString()); } } } Loading Loading @@ -247,6 +257,7 @@ public class RawContactDeltaListTests extends AndroidTestCase { static CPOWrapper buildUpdateAggregationKeepTogether(long rawContactId) { final ContentValues values = new ContentValues(); values.put(AggregationExceptions.RAW_CONTACT_ID1, rawContactId); values.put(AggregationExceptions.RAW_CONTACT_ID2, INSERTED_CONTACT_ID); values.put(AggregationExceptions.TYPE, AggregationExceptions.TYPE_KEEP_TOGETHER); return buildCPOWrapper(AggregationExceptions.CONTENT_URI, TYPE_UPDATE, values); } Loading Loading @@ -462,7 +473,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { assertDiffPattern(first, buildAssertVersion(VER_FIRST), buildUpdateAggregationSuspended(), buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bluePhone, CONTACT_BOB)), buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bluePhone, CONTACT_BOB)), buildUpdateAggregationDefault()); // Merge in the second version, verify that our insert remains Loading @@ -470,7 +482,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { assertDiffPattern(merged, buildAssertVersion(VER_SECOND), buildUpdateAggregationSuspended(), buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bluePhone, CONTACT_BOB)), buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bluePhone, CONTACT_BOB)), buildUpdateAggregationDefault()); } Loading @@ -483,6 +496,7 @@ public class RawContactDeltaListTests extends AndroidTestCase { // Add new contact locally, should remain insert final ContentValues joePhoneInsert = buildPhone(PHONE_BLUE); joePhoneInsert.put(Data.RAW_CONTACT_ID, INSERTED_CONTACT_ID); final RawContactDelta joeContact = buildAfterEntity(joePhoneInsert); final ContentValues joeContactInsert = joeContact.getValues().getCompleteValues(); joeContactInsert.put(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_SUSPENDED); Loading Loading @@ -542,6 +556,7 @@ public class RawContactDeltaListTests extends AndroidTestCase { buildUpdateAggregationDefault()); final ContentValues phoneInsert = phone.getCompleteValues(); phoneInsert.put(Data.RAW_CONTACT_ID, INSERTED_CONTACT_ID); final ContentValues contactInsert = first.getByRawContactId(CONTACT_MARY).getValues() .getCompleteValues(); contactInsert.put(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_SUSPENDED); Loading Loading @@ -585,7 +600,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { assertDiffPattern(first, buildAssertVersion(VER_FIRST), buildUpdateAggregationSuspended(), buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bobPhone, CONTACT_BOB)), buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bobPhone, CONTACT_BOB)), buildUpdateAggregationDefault()); // Trim values and ensure that we don't insert things Loading Loading
tests/src/com/android/contacts/model/RawContactDeltaListTests.java +35 −19 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package com.android.contacts.model; import android.content.ContentProviderOperation; import android.content.ContentProviderResult; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.net.Uri; Loading Loading @@ -56,6 +58,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { public static final long CONTACT_BOB = 10; public static final long CONTACT_MARY = 11; public static final long INSERTED_CONTACT_ID = 3; public static final long PHONE_RED = 20; public static final long PHONE_GREEN = 21; public static final long PHONE_BLUE = 22; Loading Loading @@ -182,6 +186,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { static void assertDiffPattern(ArrayList<CPOWrapper> diff, CPOWrapper... pattern) { assertEquals("Unexpected operations", pattern.length, diff.size()); ContentProviderResult[] fakeBackReferences = new ContentProviderResult[diff.size()]; for (int i = 0; i < pattern.length; i++) { final CPOWrapper expected = pattern[i]; final CPOWrapper found = diff.get(i); Loading @@ -193,21 +199,25 @@ public class RawContactDeltaListTests extends AndroidTestCase { final String foundType = getTypeString(found); assertEquals("Unexpected type", expectedType, foundType); if (CompatUtils.isDeleteCompat(expected)) continue; if (CompatUtils.isDeleteCompat(expected)) { continue; } try { final ContentValues expectedValues = getValues(expected.getOperation()); final ContentValues foundValues = getValues(found.getOperation()); if (CompatUtils.isInsertCompat(found)) { fakeBackReferences[i] = new ContentProviderResult( ContentUris.withAppendedId(RawContacts.CONTENT_URI, INSERTED_CONTACT_ID)); } else if (CompatUtils.isUpdateCompat(found)) { fakeBackReferences[i] = new ContentProviderResult(1); } ContentValues expectedValues = expected.getOperation().resolveValueBackReferences( new ContentProviderResult[0], 0); ContentValues foundValues = found.getOperation().resolveValueBackReferences( fakeBackReferences, fakeBackReferences.length); expectedValues.remove(BaseColumns._ID); foundValues.remove(BaseColumns._ID); assertEquals("Unexpected values", expectedValues, foundValues); } catch (NoSuchFieldException e) { fail(e.toString()); } catch (IllegalAccessException e) { fail(e.toString()); } } } Loading Loading @@ -247,6 +257,7 @@ public class RawContactDeltaListTests extends AndroidTestCase { static CPOWrapper buildUpdateAggregationKeepTogether(long rawContactId) { final ContentValues values = new ContentValues(); values.put(AggregationExceptions.RAW_CONTACT_ID1, rawContactId); values.put(AggregationExceptions.RAW_CONTACT_ID2, INSERTED_CONTACT_ID); values.put(AggregationExceptions.TYPE, AggregationExceptions.TYPE_KEEP_TOGETHER); return buildCPOWrapper(AggregationExceptions.CONTENT_URI, TYPE_UPDATE, values); } Loading Loading @@ -462,7 +473,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { assertDiffPattern(first, buildAssertVersion(VER_FIRST), buildUpdateAggregationSuspended(), buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bluePhone, CONTACT_BOB)), buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bluePhone, CONTACT_BOB)), buildUpdateAggregationDefault()); // Merge in the second version, verify that our insert remains Loading @@ -470,7 +482,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { assertDiffPattern(merged, buildAssertVersion(VER_SECOND), buildUpdateAggregationSuspended(), buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bluePhone, CONTACT_BOB)), buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bluePhone, CONTACT_BOB)), buildUpdateAggregationDefault()); } Loading @@ -483,6 +496,7 @@ public class RawContactDeltaListTests extends AndroidTestCase { // Add new contact locally, should remain insert final ContentValues joePhoneInsert = buildPhone(PHONE_BLUE); joePhoneInsert.put(Data.RAW_CONTACT_ID, INSERTED_CONTACT_ID); final RawContactDelta joeContact = buildAfterEntity(joePhoneInsert); final ContentValues joeContactInsert = joeContact.getValues().getCompleteValues(); joeContactInsert.put(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_SUSPENDED); Loading Loading @@ -542,6 +556,7 @@ public class RawContactDeltaListTests extends AndroidTestCase { buildUpdateAggregationDefault()); final ContentValues phoneInsert = phone.getCompleteValues(); phoneInsert.put(Data.RAW_CONTACT_ID, INSERTED_CONTACT_ID); final ContentValues contactInsert = first.getByRawContactId(CONTACT_MARY).getValues() .getCompleteValues(); contactInsert.put(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_SUSPENDED); Loading Loading @@ -585,7 +600,8 @@ public class RawContactDeltaListTests extends AndroidTestCase { assertDiffPattern(first, buildAssertVersion(VER_FIRST), buildUpdateAggregationSuspended(), buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bobPhone, CONTACT_BOB)), buildCPOWrapper(Data.CONTENT_URI, TYPE_INSERT, buildDataInsert(bobPhone, CONTACT_BOB)), buildUpdateAggregationDefault()); // Trim values and ensure that we don't insert things Loading