diff options
author | Dmitri Plotnikov <dplotnikov@google.com> | 2010-10-22 14:27:02 -0700 |
---|---|---|
committer | Dmitri Plotnikov <dplotnikov@google.com> | 2010-10-22 14:27:02 -0700 |
commit | 47fd3881dfd2a21de29e917b6114974ff0a67b1b (patch) | |
tree | 5b7bb213641ccb3a29c87e368508cb721c389695 /tests | |
parent | 0a940aaca6fb1ba9e3ca6485fe1d1a02eef5b019 (diff) | |
download | packages_providers_ContactsProvider-47fd3881dfd2a21de29e917b6114974ff0a67b1b.tar.gz packages_providers_ContactsProvider-47fd3881dfd2a21de29e917b6114974ff0a67b1b.tar.bz2 packages_providers_ContactsProvider-47fd3881dfd2a21de29e917b6114974ff0a67b1b.zip |
Fixing unit tests
A bunch of tests were broken by the recent change
of the aggregation policy, because they relied
on the old policy.
Some other tests stopped working after we upgraded
to a new version of ICU.
Updating the tests accordingly.
Change-Id: I97a785015834632a896ed4fc6079744962c7a04c
Diffstat (limited to 'tests')
8 files changed, 90 insertions, 67 deletions
diff --git a/tests/assets/test1/expected_contacts.txt b/tests/assets/test1/expected_contacts.txt index ebe4dadd..a73f0fef 100644 --- a/tests/assets/test1/expected_contacts.txt +++ b/tests/assets/test1/expected_contacts.txt @@ -10,7 +10,7 @@ 10 starred=0 11 in_visible_group=0 12 has_phone_number=0 -13 lookup=2273r1-523450522C46324E483C32 +13 lookup=2273r1-533551532D47334F493D33 14 } 15 1 { 16 _id=2 @@ -52,5 +52,5 @@ 52 starred=0 53 in_visible_group=1 54 has_phone_number=1 -55 lookup=2187r11-2C3232343248462C46324E483C32 +55 lookup=2187r11-2D3333353349472D47334F493D33 56 } diff --git a/tests/assets/testSynced/expected_contacts.txt b/tests/assets/testSynced/expected_contacts.txt index 8ce6f031..bcb5cf81 100644 --- a/tests/assets/testSynced/expected_contacts.txt +++ b/tests/assets/testSynced/expected_contacts.txt @@ -10,7 +10,7 @@ 10 starred=0 11 in_visible_group=0 12 has_phone_number=0 -13 lookup=2273r1-423444445C52345052 +13 lookup=2273r1-433545455D53355153 14 } 15 1 { 16 _id=2 @@ -94,7 +94,7 @@ 94 starred=0 95 in_visible_group=1 96 has_phone_number=1 -97 lookup=389r7-464852505C463034324654442E344E +97 lookup=389r7-474953515D473135334755452F354F 98 } 99 7 { 100 _id=8 @@ -108,7 +108,7 @@ 108 starred=0 109 in_visible_group=1 110 has_phone_number=1 -111 lookup=389r8-464852505C463034324654442E344E442C3C42 +111 lookup=389r8-474953515D473135334755452F354F452D3D43 112 } 113 8 { 114 _id=9 @@ -122,7 +122,7 @@ 122 starred=0 123 in_visible_group=1 124 has_phone_number=0 -125 lookup=389r9-464852505C46303432442C3C42 +125 lookup=389r9-474953515D47313533452D3D43 126 } 127 9 { 128 _id=10 @@ -136,7 +136,7 @@ 136 starred=0 137 in_visible_group=1 138 has_phone_number=0 -139 lookup=389r10-464852505C46303432 +139 lookup=389r10-474953515D47313533 140 } 141 10 { 142 _id=11 @@ -150,7 +150,7 @@ 150 starred=0 151 in_visible_group=1 152 has_phone_number=1 -153 lookup=389r11-297E297E297E297E297E297E297E297E297E297E +153 lookup=389r11-2A902A902A902A902A902A902A902A902A902A90 154 } 155 11 { 156 _id=12 @@ -164,5 +164,5 @@ 164 starred=0 165 in_visible_group=1 166 has_phone_number=0 -167 lookup=389r12-464852505C4630343238442C3C42304844 +167 lookup=389r12-474953515D4731353339452D3D43314945 168 }
\ No newline at end of file diff --git a/tests/assets/testUnsynced/expected_contacts.txt b/tests/assets/testUnsynced/expected_contacts.txt index 32dfdfb0..e6f95bab 100644 --- a/tests/assets/testUnsynced/expected_contacts.txt +++ b/tests/assets/testUnsynced/expected_contacts.txt @@ -10,7 +10,7 @@ 10 starred=0 11 in_visible_group=1 12 has_phone_number=1 -13 lookup=0r1-4654442E344E2C4632442C3C42 +13 lookup=0r1-4755452F354F2D4733452D3D43 14 } 15 1 { 16 _id=2 @@ -24,7 +24,7 @@ 24 starred=0 25 in_visible_group=1 26 has_phone_number=1 -27 lookup=0r2-4654442E344E +27 lookup=0r2-4755452F354F 28 } 29 2 { 30 _id=3 @@ -38,7 +38,7 @@ 38 starred=0 39 in_visible_group=1 40 has_phone_number=0 -41 lookup=0r3-442C3C42 +41 lookup=0r3-452D3D43 42 } 43 3 { 44 _id=4 @@ -52,7 +52,7 @@ 52 starred=0 53 in_visible_group=1 54 has_phone_number=1 -55 lookup=0r4-2988298E298C297E2984298A297C2980 +55 lookup=0r4-2A9A2AA02A9E2A902A962A9C2A8E2A92 56 } 57 4 { 58 _id=5 @@ -66,5 +66,5 @@ 66 starred=0 67 in_visible_group=1 68 has_phone_number=0 -69 lookup=0r5-442C3C42324844304844 +69 lookup=0r5-452D3D43334945314945 70 } diff --git a/tests/src/com/android/providers/contacts/ContactLookupKeyTest.java b/tests/src/com/android/providers/contacts/ContactLookupKeyTest.java index c4128657..ebadc55e 100644 --- a/tests/src/com/android/providers/contacts/ContactLookupKeyTest.java +++ b/tests/src/com/android/providers/contacts/ContactLookupKeyTest.java @@ -42,8 +42,8 @@ public class ContactLookupKeyTest extends BaseContactsProvider2Test { public void testLookupKeyUsingDisplayNameAndNoAccount() { long rawContactId1 = createRawContactWithName("John", "Doe"); long rawContactId2 = createRawContactWithName("johndoe", null); - - assertAggregated(rawContactId1, rawContactId2); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1, rawContactId2); // Normalized display name String normalizedName = NameNormalizer.normalize("johndoe"); @@ -74,7 +74,8 @@ public class ContactLookupKeyTest extends BaseContactsProvider2Test { long rawContactId2 = createRawContactWithName("johndoe", null); storeValue(RawContacts.CONTENT_URI, rawContactId2, RawContacts.SOURCE_ID, "4.5.6"); - assertAggregated(rawContactId1, rawContactId2); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1, rawContactId2); // Two source ids, of them escaped String expectedLookupKey = "0i123.0e4..5..6"; @@ -127,6 +128,10 @@ public class ContactLookupKeyTest extends BaseContactsProvider2Test { long rawContactId3 = createRawContactWithName("John", "Doe"); storeValue(RawContacts.CONTENT_URI, rawContactId3, RawContacts.SOURCE_ID, "3"); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1, rawContactId2); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1, rawContactId3); String lookupKey = "0i1.0i2.0i3"; diff --git a/tests/src/com/android/providers/contacts/ContactsActor.java b/tests/src/com/android/providers/contacts/ContactsActor.java index 6e0e47ad..bf03d4ca 100644 --- a/tests/src/com/android/providers/contacts/ContactsActor.java +++ b/tests/src/com/android/providers/contacts/ContactsActor.java @@ -30,6 +30,7 @@ import android.net.Uri; import android.os.Binder; import android.provider.BaseColumns; import android.provider.ContactsContract; +import android.provider.ContactsContract.AggregationExceptions; import android.provider.ContactsContract.CommonDataKinds; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Data; @@ -259,27 +260,27 @@ public class ContactsActor { } } - public long createContact(boolean isRestricted, String name) { + public long createRawContact(boolean isRestricted, String name) { ensureCallingPackage(); - long contactId = createContact(isRestricted); - createName(contactId, name); - return contactId; + long rawContactId = createRawContact(isRestricted); + createName(rawContactId, name); + return rawContactId; } - public long createContact(boolean isRestricted) { + public long createRawContact(boolean isRestricted) { ensureCallingPackage(); final ContentValues values = new ContentValues(); if (isRestricted) { values.put(RawContacts.IS_RESTRICTED, 1); } - Uri contactUri = resolver.insert(RawContacts.CONTENT_URI, values); - return ContentUris.parseId(contactUri); + Uri rawContactUri = resolver.insert(RawContacts.CONTENT_URI, values); + return ContentUris.parseId(rawContactUri); } - public long createContactWithStatus(boolean isRestricted, String name, String address, + public long createRawContactWithStatus(boolean isRestricted, String name, String address, String status) { - final long rawContactId = createContact(isRestricted, name); + final long rawContactId = createRawContact(isRestricted, name); final long dataId = createEmail(rawContactId, address); createStatus(dataId, status); return rawContactId; @@ -409,6 +410,14 @@ public class ContactsActor { return ContentUris.parseId(dataUri); } + protected void setAggregationException(int type, long rawContactId1, long rawContactId2) { + ContentValues values = new ContentValues(); + values.put(AggregationExceptions.RAW_CONTACT_ID1, rawContactId1); + values.put(AggregationExceptions.RAW_CONTACT_ID2, rawContactId2); + values.put(AggregationExceptions.TYPE, type); + resolver.update(AggregationExceptions.CONTENT_URI, values, null, null); + } + /** * Various internal database projections. */ diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index 5b404858..ce2828d5 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -79,6 +79,9 @@ import java.util.Locale; @LargeTest public class ContactsProvider2Test extends BaseContactsProvider2Test { + private static final Account ACCOUNT_1 = new Account("account_name_1", "account_type_1"); + private static final Account ACCOUNT_2 = new Account("account_name_2", "account_type_2"); + public void testRawContactsInsert() { ContentValues values = new ContentValues(); @@ -185,11 +188,11 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { } public void testPhonesFilterQuery() { - long rawContactId1 = createRawContactWithName("Hot", "Tamale"); + long rawContactId1 = createRawContactWithName("Hot", "Tamale", ACCOUNT_1); insertPhoneNumber(rawContactId1, "18004664411"); insertPhoneNumber(rawContactId1, "1-800-466-4411"); - long rawContactId2 = createRawContactWithName("Hot", "Tamale"); + long rawContactId2 = createRawContactWithName("Hot", "Tamale", ACCOUNT_2); insertPhoneNumber(rawContactId2, "1-800-466-4411"); Uri filterUri1 = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "tamale"); @@ -338,11 +341,11 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { } public void testEmailsFilterQuery() { - long rawContactId1 = createRawContactWithName("Hot", "Tamale"); + long rawContactId1 = createRawContactWithName("Hot", "Tamale", ACCOUNT_1); insertEmail(rawContactId1, "tamale@acme.com"); insertEmail(rawContactId1, "tamale@acme.com"); - long rawContactId2 = createRawContactWithName("Hot", "Tamale"); + long rawContactId2 = createRawContactWithName("Hot", "Tamale", ACCOUNT_2); insertEmail(rawContactId2, "tamale@acme.com"); Uri filterUri1 = Uri.withAppendedPath(Email.CONTENT_FILTER_URI, "tam"); @@ -1736,9 +1739,8 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { public void testRawContactDeletionKeepingAggregateContact() { long rawContactId1 = createRawContactWithName(mAccount); long rawContactId2 = createRawContactWithName(mAccount); - - // Same name - should be aggregated - assertAggregated(rawContactId1, rawContactId2); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1, rawContactId2); long contactId = queryContactId(rawContactId1); @@ -1853,8 +1855,8 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { } public void testContactDeletion() { - long rawContactId1 = createRawContactWithName("John", "Doe"); - long rawContactId2 = createRawContactWithName("John", "Doe"); + long rawContactId1 = createRawContactWithName("John", "Doe", ACCOUNT_1); + long rawContactId2 = createRawContactWithName("John", "Doe", ACCOUNT_2); long contactId = queryContactId(rawContactId1); @@ -2133,8 +2135,8 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { Uri rawContactUri1 = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId1); long rawContactId2 = createRawContactWithName(); Uri rawContactUri2 = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId2); - - assertAggregated(rawContactId1, rawContactId2); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1, rawContactId2); long contactId = queryContactId(rawContactId1); Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); diff --git a/tests/src/com/android/providers/contacts/GroupsTest.java b/tests/src/com/android/providers/contacts/GroupsTest.java index f244d4b8..18463217 100644 --- a/tests/src/com/android/providers/contacts/GroupsTest.java +++ b/tests/src/com/android/providers/contacts/GroupsTest.java @@ -78,11 +78,13 @@ public class GroupsTest extends BaseContactsProvider2Test { long groupBlue = mActor.createGroup(GROUP_BLUE); // Create a handful of contacts - long contactAlpha = mActor.createContact(false, PERSON_ALPHA); - long contactBravo = mActor.createContact(false, PERSON_BRAVO); - long contactCharlie = mActor.createContact(false, PERSON_CHARLIE); - long contactCharlieDupe = mActor.createContact(false, PERSON_CHARLIE); - long contactDelta = mActor.createContact(false, PERSON_DELTA); + long contactAlpha = mActor.createRawContact(false, PERSON_ALPHA); + long contactBravo = mActor.createRawContact(false, PERSON_BRAVO); + long contactCharlie = mActor.createRawContact(false, PERSON_CHARLIE); + long contactCharlieDupe = mActor.createRawContact(false, PERSON_CHARLIE); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, contactCharlie, contactCharlieDupe); + long contactDelta = mActor.createRawContact(false, PERSON_DELTA); assertAggregated(contactCharlie, contactCharlieDupe); diff --git a/tests/src/com/android/providers/contacts/RestrictionExceptionsTest.java b/tests/src/com/android/providers/contacts/RestrictionExceptionsTest.java index 6209e549..0eb2c2b3 100644 --- a/tests/src/com/android/providers/contacts/RestrictionExceptionsTest.java +++ b/tests/src/com/android/providers/contacts/RestrictionExceptionsTest.java @@ -27,6 +27,7 @@ import android.content.res.AssetFileDescriptor; import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract; +import android.provider.ContactsContract.AggregationExceptions; import android.provider.LiveFolders; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Data; @@ -99,42 +100,44 @@ public class RestrictionExceptionsTest extends AndroidTestCase { public void testRestrictedInsertRestrictedQuery() { // Restricted query can read restricted data - final long rawContact = mGrey.createContact(true, GENERIC_NAME); + final long rawContact = mGrey.createRawContact(true, GENERIC_NAME); final int count = mGrey.getDataCountForRawContact(rawContact); assertEquals(1, count); } public void testRestrictedInsertGenericQuery() { // Generic query is denied restricted data - final long rawContact = mGrey.createContact(true, GENERIC_NAME); + final long rawContact = mGrey.createRawContact(true, GENERIC_NAME); final int count = mRed.getDataCountForRawContact(rawContact); assertEquals(0, count); } public void testGenericInsertRestrictedQuery() { // Restricted query can read generic data - final long rawContact = mRed.createContact(false, GENERIC_NAME); + final long rawContact = mRed.createRawContact(false, GENERIC_NAME); final int count = mGrey.getDataCountForRawContact(rawContact); assertEquals(1, count); } public void testGenericInsertGenericQuery() { // Generic query can read generic data - final long rawContact = mRed.createContact(false, GENERIC_NAME); + final long rawContact = mRed.createRawContact(false, GENERIC_NAME); final int count = mRed.getDataCountForRawContact(rawContact); assertEquals(1, count); } public void testMixedAggregateRestrictedQuery() { // Create mixed aggregate with a restricted phone number - final long greyContact = mGrey.createContact(true, GENERIC_NAME); - final long greyPhone = mGrey.createPhone(greyContact, PHONE_GREY); - final long redContact = mRed.createContact(false, GENERIC_NAME); - final long redPhone = mRed.createPhone(redContact, PHONE_RED); + final long greyRawContactId = mGrey.createRawContact(true, GENERIC_NAME); + mGrey.createPhone(greyRawContactId, PHONE_GREY); + final long redRawContactId = mRed.createRawContact(false, GENERIC_NAME); + mRed.createPhone(redRawContactId, PHONE_RED); + mGrey.setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, greyRawContactId, redRawContactId); // Make sure both aggregates were joined - final long greyAgg = mGrey.getContactForRawContact(greyContact); - final long redAgg = mRed.getContactForRawContact(redContact); + final long greyAgg = mGrey.getContactForRawContact(greyRawContactId); + final long redAgg = mRed.getContactForRawContact(redRawContactId); assertEquals(greyAgg, redAgg); // Restricted reader should have access to both numbers @@ -148,7 +151,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { public void testUpdateRestricted() { // Assert that we can't un-restrict something - final long greyContact = mGrey.createContact(true, GENERIC_NAME); + final long greyContact = mGrey.createRawContact(true, GENERIC_NAME); final long greyPhone = mGrey.createPhone(greyContact, PHONE_GREY); int count = mRed.getDataCountForRawContact(greyContact); @@ -167,14 +170,16 @@ public class RestrictionExceptionsTest extends AndroidTestCase { public void testExportVCard() throws Exception { // Create mixed aggregate with a restricted phone number - final long greyContact = mGrey.createContact(true, GENERIC_NAME); - final long greyPhone = mGrey.createPhone(greyContact, PHONE_GREY); - final long redContact = mRed.createContact(false, GENERIC_NAME); - final long redPhone = mRed.createPhone(redContact, PHONE_RED); + final long greyRawContactId = mGrey.createRawContact(true, GENERIC_NAME); + mGrey.createPhone(greyRawContactId, PHONE_GREY); + final long redRawContactId = mRed.createRawContact(false, GENERIC_NAME); + mRed.createPhone(redRawContactId, PHONE_RED); + mGrey.setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, greyRawContactId, redRawContactId); // Make sure both aggregates were joined - final long greyAgg = mGrey.getContactForRawContact(greyContact); - final long redAgg = mRed.getContactForRawContact(redContact); + final long greyAgg = mGrey.getContactForRawContact(greyRawContactId); + final long redAgg = mRed.getContactForRawContact(redRawContactId); assertEquals(greyAgg, redAgg); // Exported vCard shouldn't contain restricted phone @@ -202,7 +207,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testContactsLiveFolder() { - final long greyContact = mGrey.createContact(true, GENERIC_NAME); + final long greyContact = mGrey.createRawContact(true, GENERIC_NAME); final long greyPhone = mGrey.createPhone(greyContact, PHONE_GREY); // Protected contact should be omitted from live folder @@ -222,7 +227,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testRestrictedQueryParam() throws Exception { - final long greyContact = mGrey.createContact(true, GENERIC_NAME); + final long greyContact = mGrey.createRawContact(true, GENERIC_NAME); final long greyPhone = mGrey.createPhone(greyContact, PHONE_GREY); Uri greyUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, greyContact); @@ -254,7 +259,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testRestrictedEmailLookupRestricted() { - final long greyContact = mGrey.createContact(true, GENERIC_NAME); + final long greyContact = mGrey.createRawContact(true, GENERIC_NAME); final long greyEmail = mGrey.createEmail(greyContact, EMAIL_GREY); // Restricted caller should see protected data @@ -273,7 +278,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testRestrictedEmailLookupGeneric() { - final long greyContact = mGrey.createContact(true, GENERIC_NAME); + final long greyContact = mGrey.createRawContact(true, GENERIC_NAME); final long greyEmail = mGrey.createEmail(greyContact, EMAIL_GREY); // Generic caller should never see protected data @@ -292,7 +297,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testStatusRestrictedInsertRestrictedQuery() { - final long rawContactId = mGrey.createContactWithStatus(true, + final long rawContactId = mGrey.createRawContactWithStatus(true, GENERIC_NAME, EMAIL_GREY, GENERIC_STATUS); final long aggId = mGrey.getContactForRawContact(rawContactId); @@ -301,7 +306,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testStatusRestrictedInsertGenericQuery() { - final long rawContactId = mGrey.createContactWithStatus(true, + final long rawContactId = mGrey.createRawContactWithStatus(true, GENERIC_NAME, EMAIL_GREY, GENERIC_STATUS); final long aggId = mGrey.getContactForRawContact(rawContactId); @@ -310,7 +315,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testStatusGenericInsertRestrictedQuery() { - final long rawContactId = mRed.createContactWithStatus(false, + final long rawContactId = mRed.createRawContactWithStatus(false, GENERIC_NAME, EMAIL_RED, GENERIC_STATUS); final long aggId = mRed.getContactForRawContact(rawContactId); @@ -319,7 +324,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testStatusGenericInsertGenericQuery() { - final long rawContactId = mRed.createContactWithStatus(false, + final long rawContactId = mRed.createRawContactWithStatus(false, GENERIC_NAME, EMAIL_RED, GENERIC_STATUS); final long aggId = mRed.getContactForRawContact(rawContactId); |