diff options
author | Dmitri Plotnikov <dplotnikov@google.com> | 2009-09-04 18:29:09 -0700 |
---|---|---|
committer | Dmitri Plotnikov <dplotnikov@google.com> | 2009-09-04 18:31:18 -0700 |
commit | 0c0adda32be5de3acf392ab715cff468b6b340f8 (patch) | |
tree | 295a7dcfb9fcd499880c17ea0de3b9735c64f42a /tests | |
parent | 352a5f616ba5fc544689c235afab1174151748a6 (diff) | |
download | ContactsProvider-0c0adda32be5de3acf392ab715cff468b6b340f8.tar.gz |
Fixing contact aggregation exception API.
Diffstat (limited to 'tests')
3 files changed, 62 insertions, 56 deletions
diff --git a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java index dbc1e052..6d1f58e2 100644 --- a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java @@ -301,22 +301,17 @@ public abstract class BaseContactsProvider2Test extends AndroidTestCase { RawContacts.CONTENT_URI, rawContactId), values, null, null); } - protected void setAggregationException(int type, long contactId, long rawContactId) { - - // Aggregation exceptions only work between contacts that have already passed - // automatic aggregation - forceAggregation(); - + protected void setAggregationException(int type, long rawContactId1, long rawContactId2) { ContentValues values = new ContentValues(); - values.put(AggregationExceptions.CONTACT_ID, contactId); - values.put(AggregationExceptions.RAW_CONTACT_ID, rawContactId); + values.put(AggregationExceptions.RAW_CONTACT_ID1, rawContactId1); + values.put(AggregationExceptions.RAW_CONTACT_ID2, rawContactId2); values.put(AggregationExceptions.TYPE, type); assertEquals(1, mResolver.update(AggregationExceptions.CONTENT_URI, values, null, null)); } protected Cursor queryRawContact(long rawContactId) { - return mResolver.query(ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), null, - null, null, null); + return mResolver.query(ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), + null, null, null, null); } protected Cursor queryContact(long contactId) { diff --git a/tests/src/com/android/providers/contacts/ContactAggregatorTest.java b/tests/src/com/android/providers/contacts/ContactAggregatorTest.java index a8699285..67c94a29 100644 --- a/tests/src/com/android/providers/contacts/ContactAggregatorTest.java +++ b/tests/src/com/android/providers/contacts/ContactAggregatorTest.java @@ -36,50 +36,54 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test { private static final String[] AGGREGATION_EXCEPTION_PROJECTION = new String[] { AggregationExceptions.TYPE, - AggregationExceptions.CONTACT_ID, - AggregationExceptions.RAW_CONTACT_ID + AggregationExceptions.RAW_CONTACT_ID1, + AggregationExceptions.RAW_CONTACT_ID2 }; public void testCrudAggregationExceptions() throws Exception { long rawContactId1 = createRawContactWithName("zz", "top"); - long contactId = queryContactId(rawContactId1); long rawContactId2 = createRawContactWithName("aa", "bottom"); - setAggregationException(AggregationExceptions.TYPE_KEEP_IN, contactId, rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, + rawContactId1, rawContactId2); + + String selection = "(" + AggregationExceptions.RAW_CONTACT_ID1 + "=" + rawContactId1 + + " AND " + AggregationExceptions.RAW_CONTACT_ID2 + "=" + rawContactId2 + + ") OR (" + AggregationExceptions.RAW_CONTACT_ID1 + "=" + rawContactId2 + + " AND " + AggregationExceptions.RAW_CONTACT_ID2 + "=" + rawContactId1 + ")"; // Refetch the row we have just inserted Cursor c = mResolver.query(AggregationExceptions.CONTENT_URI, - AGGREGATION_EXCEPTION_PROJECTION, AggregationExceptions.CONTACT_ID + "=" - + contactId, null, null); + AGGREGATION_EXCEPTION_PROJECTION, selection, null, null); assertTrue(c.moveToFirst()); - assertEquals(AggregationExceptions.TYPE_KEEP_IN, c.getInt(0)); - assertEquals(contactId, c.getLong(1)); - assertEquals(rawContactId2, c.getLong(2)); + assertEquals(AggregationExceptions.TYPE_KEEP_TOGETHER, c.getInt(0)); + assertTrue((rawContactId1 == c.getLong(1) && rawContactId2 == c.getLong(2)) + || (rawContactId2 == c.getLong(1) && rawContactId1 == c.getLong(2))); assertFalse(c.moveToNext()); c.close(); // Change from TYPE_KEEP_IN to TYPE_KEEP_OUT - setAggregationException(AggregationExceptions.TYPE_KEEP_OUT, contactId, rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE, + rawContactId1, rawContactId2); - c = mResolver.query(AggregationExceptions.CONTENT_URI, - AGGREGATION_EXCEPTION_PROJECTION, AggregationExceptions.CONTACT_ID + "=" - + contactId, null, null); + c = mResolver.query(AggregationExceptions.CONTENT_URI, AGGREGATION_EXCEPTION_PROJECTION, + selection, null, null); assertTrue(c.moveToFirst()); - assertEquals(AggregationExceptions.TYPE_KEEP_OUT, c.getInt(0)); - assertEquals(contactId, c.getLong(1)); - assertEquals(rawContactId2, c.getLong(2)); + assertEquals(AggregationExceptions.TYPE_KEEP_SEPARATE, c.getInt(0)); + assertTrue((rawContactId1 == c.getLong(1) && rawContactId2 == c.getLong(2)) + || (rawContactId2 == c.getLong(1) && rawContactId1 == c.getLong(2))); assertFalse(c.moveToNext()); c.close(); // Delete the rule - setAggregationException(AggregationExceptions.TYPE_AUTOMATIC, contactId, rawContactId2); + setAggregationException(AggregationExceptions.TYPE_AUTOMATIC, + rawContactId1, rawContactId2); // Verify that the row is gone - c = mResolver.query(AggregationExceptions.CONTENT_URI, - AGGREGATION_EXCEPTION_PROJECTION, AggregationExceptions.CONTACT_ID + "=" - + contactId, null, null); + c = mResolver.query(AggregationExceptions.CONTENT_URI, AGGREGATION_EXCEPTION_PROJECTION, + selection, null, null); assertFalse(c.moveToFirst()); c.close(); } @@ -370,8 +374,8 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test { long contactId1 = queryContactId(rawContactId1); long contactId2 = queryContactId(rawContactId2); - setAggregationException(AggregationExceptions.TYPE_KEEP_IN, - queryContactId(rawContactId1), rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, + rawContactId1, rawContactId2); assertAggregated(rawContactId1, rawContactId2, "Johnkx Smithkx"); @@ -395,8 +399,8 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test { long rawContactId2 = createRawContact(); insertStructuredName(rawContactId2, "Johnh", "Smithh"); - setAggregationException(AggregationExceptions.TYPE_KEEP_OUT, - queryContactId(rawContactId1), rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE, + rawContactId1, rawContactId2); assertNotAggregated(rawContactId1, rawContactId2); } @@ -408,13 +412,13 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test { long rawContactId2 = createRawContact(); insertStructuredName(rawContactId2, "Johnj", "Smithj"); - setAggregationException(AggregationExceptions.TYPE_KEEP_IN, - queryContactId(rawContactId1), rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, + rawContactId1, rawContactId2); assertAggregated(rawContactId1, rawContactId2, "Johnj Smithj"); - setAggregationException(AggregationExceptions.TYPE_KEEP_OUT, - queryContactId(rawContactId1), rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE, + rawContactId1, rawContactId2); assertNotAggregated(rawContactId1, rawContactId2); @@ -432,8 +436,8 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test { // Exact name match long rawContactId2 = createRawContact(); insertStructuredName(rawContactId2, "Duane", null); - setAggregationException(AggregationExceptions.TYPE_KEEP_OUT, - queryContactId(rawContactId1), rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE, + rawContactId1, rawContactId2); // Edit distance == 0.84 long rawContactId3 = createRawContact(); @@ -513,7 +517,8 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test { insertStructuredName(rawContactId2, "Manny", "Spider"); long contactId1 = queryContactId(rawContactId1); - setAggregationException(AggregationExceptions.TYPE_KEEP_OUT, contactId1, rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE, + rawContactId1, rawContactId2); long contactId2 = queryContactId(rawContactId2); assertSuggestions(contactId1, contactId2); @@ -529,7 +534,8 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test { insertNickname(rawContactId2, "superman"); long contactId1 = queryContactId(rawContactId1); - setAggregationException(AggregationExceptions.TYPE_KEEP_OUT, contactId1, rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE, + rawContactId1, rawContactId2); long contactId2 = queryContactId(rawContactId2); assertSuggestions(contactId1, contactId2); @@ -543,7 +549,8 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test { insertStructuredName(rawContactId2, "Richard", "Cherry"); long contactId1 = queryContactId(rawContactId1); - setAggregationException(AggregationExceptions.TYPE_KEEP_OUT, contactId1, rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE, + rawContactId1, rawContactId2); long contactId2 = queryContactId(rawContactId2); assertSuggestions(contactId1, contactId2); @@ -552,18 +559,19 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test { public void testChoosePhoto() { long rawContactId1 = createRawContact(); setContactAccountName(rawContactId1, "donut"); - long donutId = ContentUris.parseId(insertPhoto(rawContactId1)); - long contactId = queryContactId(rawContactId1); + insertPhoto(rawContactId1); long rawContactId2 = createRawContact(); - setAggregationException(AggregationExceptions.TYPE_KEEP_IN, contactId, rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, + rawContactId1, rawContactId2); setContactAccountName(rawContactId2, "cupcake"); long cupcakeId = ContentUris.parseId(insertPhoto(rawContactId2)); long rawContactId3 = createRawContact(); - setAggregationException(AggregationExceptions.TYPE_KEEP_IN, contactId, rawContactId3); + setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, + rawContactId1, rawContactId3); setContactAccountName(rawContactId3, "flan"); - long flanId = ContentUris.parseId(insertPhoto(rawContactId3)); + insertPhoto(rawContactId3); assertEquals(cupcakeId, queryPhotoId(queryContactId(rawContactId2))); } diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index eb6ebc78..32cb7263 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -25,7 +25,6 @@ import android.content.Entity; import android.content.EntityIterator; import android.database.Cursor; import android.net.Uri; -import android.net.Uri.Builder; import android.os.RemoteException; import android.provider.ContactsContract; import android.provider.LiveFolders; @@ -485,8 +484,8 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { long rawContactId2 = createRawContact(); insertPhoneNumber(rawContactId2, "123456789", true); - long contactId = queryContactId(rawContactId1); - setAggregationException(AggregationExceptions.TYPE_KEEP_IN, contactId, rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, + rawContactId1, rawContactId2); assertAggregated(rawContactId1, rawContactId2, "123456789"); @@ -524,7 +523,8 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { updateSendToVoicemailAndRingtone(contactId2, true, "bar"); // Aggregate them - setAggregationException(AggregationExceptions.TYPE_KEEP_IN, contactId1, rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, + rawContactId1, rawContactId2); // Both contacts had "send to VM", the contact now has the same value assertSendToVoicemailAndRingtone(contactId1, true, "foo,bar"); // Either foo or bar @@ -540,10 +540,11 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { updateSendToVoicemailAndRingtone(contactId2, false, null); // Aggregate them - setAggregationException(AggregationExceptions.TYPE_KEEP_IN, contactId1, rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, + rawContactId1, rawContactId2); // Since one of the contacts had "don't send to VM" that setting wins for the aggregate - assertSendToVoicemailAndRingtone(contactId1, false, null); + assertSendToVoicemailAndRingtone(queryContactId(rawContactId1), false, null); } public void testSetSendToVoicemailAndRingtonePreservedAfterJoinAndSplit() { @@ -556,10 +557,12 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { updateSendToVoicemailAndRingtone(contactId2, false, "bar"); // Aggregate them - setAggregationException(AggregationExceptions.TYPE_KEEP_IN, contactId1, rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, + rawContactId1, rawContactId2); // Split them - setAggregationException(AggregationExceptions.TYPE_KEEP_OUT, contactId1, rawContactId2); + setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE, + rawContactId1, rawContactId2); assertSendToVoicemailAndRingtone(queryContactId(rawContactId1), true, "foo"); assertSendToVoicemailAndRingtone(queryContactId(rawContactId2), false, "bar"); |