diff options
author | Dmitri Plotnikov <dplotnikov@google.com> | 2009-12-21 13:40:30 -0800 |
---|---|---|
committer | Dmitri Plotnikov <dplotnikov@google.com> | 2009-12-21 13:40:30 -0800 |
commit | 5dd6d5d4acb93adc05f1fde904080787f2397f51 (patch) | |
tree | 00ce4ba6e18b2bf04a5a1f2a5b15346d0a86a4a0 /tests/src/com | |
parent | f5bda8d8994a50c60e5d39fb66990040b1bb5622 (diff) | |
download | packages_providers_ContactsProvider-5dd6d5d4acb93adc05f1fde904080787f2397f51.zip packages_providers_ContactsProvider-5dd6d5d4acb93adc05f1fde904080787f2397f51.tar.gz packages_providers_ContactsProvider-5dd6d5d4acb93adc05f1fde904080787f2397f51.tar.bz2 |
Resubmit: Adding support for new Contacts columns for names and sorting
This is in preparation for fixing bugs:
Bug: 2075641
Bug: 2021660
Bug: 2164422
Bug: 2267198
Change-Id: I7696abe8c8fd17d8854632cc8e818b9e4d2e643c
Diffstat (limited to 'tests/src/com')
4 files changed, 222 insertions, 21 deletions
diff --git a/tests/src/com/android/providers/contacts/ContactsActor.java b/tests/src/com/android/providers/contacts/ContactsActor.java index 4568e5f..7dd980c 100644 --- a/tests/src/com/android/providers/contacts/ContactsActor.java +++ b/tests/src/com/android/providers/contacts/ContactsActor.java @@ -23,8 +23,8 @@ import android.content.ContentValues; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.content.res.Configuration; import android.content.res.Resources; -import android.content.res.Resources.NotFoundException; import android.database.Cursor; import android.net.Uri; import android.os.Binder; @@ -43,10 +43,10 @@ import android.test.mock.MockContentResolver; import android.test.mock.MockContext; import android.test.mock.MockPackageManager; import android.test.mock.MockResources; -import android.util.Log; import android.util.TypedValue; import java.util.HashMap; +import java.util.Locale; /** * Helper class that encapsulates an "actor" which is owned by a specific @@ -131,7 +131,11 @@ public class ContactsActor { mPackageManager.addPackage(3000, PACKAGE_GREEN); mPackageManager.addPackage(4000, PACKAGE_BLUE); - mRes = new RestrictionMockResources(overallContext.getResources()); + Resources resources = overallContext.getResources(); + Configuration configuration = new Configuration(resources.getConfiguration()); + configuration.locale = Locale.US; + resources.updateConfiguration(configuration, resources.getDisplayMetrics()); + mRes = new RestrictionMockResources(resources); } @Override diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index 9cd6d1f..7ec5a22 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -35,8 +35,10 @@ import android.provider.LiveFolders; import android.provider.ContactsContract.AggregationExceptions; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Data; +import android.provider.ContactsContract.DisplayNameSources; import android.provider.ContactsContract.Groups; import android.provider.ContactsContract.PhoneLookup; +import android.provider.ContactsContract.PhoneticNameStyle; import android.provider.ContactsContract.RawContacts; import android.provider.ContactsContract.RawContactsEntity; import android.provider.ContactsContract.Settings; @@ -52,6 +54,10 @@ import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; import android.test.MoreAsserts; import android.test.suitebuilder.annotation.LargeTest; +import java.text.Collator; +import java.util.Arrays; +import java.util.Locale; + /** * Unit tests for {@link ContactsProvider2}. @@ -594,6 +600,125 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { assertStructuredName(rawContactId, null, null, null, "Johnson", null); } + public void testContactWithoutPhoneticName() { + final long rawContactId = createRawContact(null); + + ContentValues values = new ContentValues(); + values.put(StructuredName.PREFIX, "Mr"); + values.put(StructuredName.GIVEN_NAME, "John"); + values.put(StructuredName.MIDDLE_NAME, "K."); + values.put(StructuredName.FAMILY_NAME, "Doe"); + values.put(StructuredName.SUFFIX, "Jr."); + Uri dataUri = insertStructuredName(rawContactId, values); + + values.clear(); + values.put(RawContacts.DISPLAY_NAME_SOURCE, DisplayNameSources.STRUCTURED_NAME); + values.put(RawContacts.DISPLAY_NAME_PRIMARY, "John K. Doe, Jr."); + values.put(RawContacts.DISPLAY_NAME_ALTERNATIVE, "Doe, John K., Jr."); + values.putNull(RawContacts.PHONETIC_NAME); + values.put(RawContacts.PHONETIC_NAME_STYLE, PhoneticNameStyle.UNDEFINED); + values.put(RawContacts.SORT_KEY_PRIMARY, "John K. Doe, Jr."); + values.put(RawContacts.SORT_KEY_ALTERNATIVE, "Doe, John K., Jr."); + + Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); + assertStoredValues(rawContactUri, values); + + values.clear(); + values.put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.STRUCTURED_NAME); + values.put(Contacts.DISPLAY_NAME_PRIMARY, "John K. Doe, Jr."); + values.put(Contacts.DISPLAY_NAME_ALTERNATIVE, "Doe, John K., Jr."); + values.putNull(Contacts.PHONETIC_NAME); + values.put(Contacts.PHONETIC_NAME_STYLE, PhoneticNameStyle.UNDEFINED); + values.put(Contacts.SORT_KEY_PRIMARY, "John K. Doe, Jr."); + values.put(Contacts.SORT_KEY_ALTERNATIVE, "Doe, John K., Jr."); + + Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, + queryContactId(rawContactId)); + assertStoredValues(contactUri, values); + + // The same values should be available through a join with Data + assertStoredValues(dataUri, values); + } + + public void testContactWithChineseName() { + + // Only run this test when Chinese collation is supported + if (!Arrays.asList(Collator.getAvailableLocales()).contains(Locale.CHINA)) { + return; + } + + long rawContactId = createRawContact(null); + + ContentValues values = new ContentValues(); + values.put(StructuredName.DISPLAY_NAME, "\u6BB5\u5C0F\u6D9B"); + Uri dataUri = insertStructuredName(rawContactId, values); + + values.clear(); + values.put(RawContacts.DISPLAY_NAME_SOURCE, DisplayNameSources.STRUCTURED_NAME); + values.put(RawContacts.DISPLAY_NAME_PRIMARY, "\u6BB5\u5C0F\u6D9B"); + values.put(RawContacts.DISPLAY_NAME_ALTERNATIVE, "\u6BB5\u5C0F\u6D9B"); + values.putNull(RawContacts.PHONETIC_NAME); + values.put(RawContacts.PHONETIC_NAME_STYLE, PhoneticNameStyle.UNDEFINED); + values.put(RawContacts.SORT_KEY_PRIMARY, "DUAN XIAO TAO"); + values.put(RawContacts.SORT_KEY_ALTERNATIVE, "DUAN XIAO TAO"); + + Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); + assertStoredValues(rawContactUri, values); + + values.clear(); + values.put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.STRUCTURED_NAME); + values.put(Contacts.DISPLAY_NAME_PRIMARY, "\u6BB5\u5C0F\u6D9B"); + values.put(Contacts.DISPLAY_NAME_ALTERNATIVE, "\u6BB5\u5C0F\u6D9B"); + values.putNull(Contacts.PHONETIC_NAME); + values.put(Contacts.PHONETIC_NAME_STYLE, PhoneticNameStyle.UNDEFINED); + values.put(Contacts.SORT_KEY_PRIMARY, "DUAN XIAO TAO"); + values.put(Contacts.SORT_KEY_ALTERNATIVE, "DUAN XIAO TAO"); + + Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, + queryContactId(rawContactId)); + assertStoredValues(contactUri, values); + + // The same values should be available through a join with Data + assertStoredValues(dataUri, values); + } + + public void testContactWithJapaneseName() { + long rawContactId = createRawContact(null); + + ContentValues values = new ContentValues(); + values.put(StructuredName.GIVEN_NAME, "\u7A7A\u6D77"); + values.put(StructuredName.PHONETIC_GIVEN_NAME, "\u304B\u3044\u304F\u3046"); + Uri dataUri = insertStructuredName(rawContactId, values); + + values.clear(); + values.put(RawContacts.DISPLAY_NAME_SOURCE, DisplayNameSources.STRUCTURED_NAME); + values.put(RawContacts.DISPLAY_NAME_PRIMARY, "\u7A7A\u6D77"); + values.put(RawContacts.DISPLAY_NAME_ALTERNATIVE, "\u7A7A\u6D77"); + values.put(RawContacts.PHONETIC_NAME, "\u304B\u3044\u304F\u3046"); + values.put(RawContacts.PHONETIC_NAME_STYLE, PhoneticNameStyle.JAPANESE); + values.put(RawContacts.SORT_KEY_PRIMARY, "\u304B\u3044\u304F\u3046"); + values.put(RawContacts.SORT_KEY_ALTERNATIVE, "\u304B\u3044\u304F\u3046"); + + Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); + assertStoredValues(rawContactUri, values); + + values.clear(); + values.put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.STRUCTURED_NAME); + values.put(Contacts.DISPLAY_NAME_PRIMARY, "\u7A7A\u6D77"); + values.put(Contacts.DISPLAY_NAME_ALTERNATIVE, "\u7A7A\u6D77"); + values.put(Contacts.PHONETIC_NAME, "\u304B\u3044\u304F\u3046"); + values.put(Contacts.PHONETIC_NAME_STYLE, PhoneticNameStyle.JAPANESE); + values.put(Contacts.SORT_KEY_PRIMARY, "\u304B\u3044\u304F\u3046"); + values.put(Contacts.SORT_KEY_ALTERNATIVE, "\u304B\u3044\u304F\u3046"); + + Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, + queryContactId(rawContactId)); + assertStoredValues(contactUri, values); + + // The same values should be available through a join with Data + assertStoredValues(dataUri, values); + } + public void testDisplayNameUpdate() { long rawContactId1 = createRawContact(); insertEmail(rawContactId1, "potato@acme.com", true); @@ -629,16 +754,10 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { insertPhoneNumber(rawContactId, "1-800-466-4411"); assertStoredValue(uri, Contacts.DISPLAY_NAME, "1-800-466-4411"); - // If there is title without company, the title is display name. - values.clear(); - values.put(Organization.TITLE, "Protagonist"); - Uri organizationUri = insertOrganization(rawContactId, values); - assertStoredValue(uri, Contacts.DISPLAY_NAME, "Protagonist"); - // If there are title and company, the company is display name. values.clear(); values.put(Organization.COMPANY, "Monsters Inc"); - mResolver.update(organizationUri, values, null, null); + Uri organizationUri = insertOrganization(rawContactId, values); assertStoredValue(uri, Contacts.DISPLAY_NAME, "Monsters Inc"); // If there is nickname, that is display name. @@ -651,7 +770,77 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { values.put(StructuredName.MIDDLE_NAME, "P."); values.put(StructuredName.FAMILY_NAME, "Sullivan"); insertStructuredName(rawContactId, values); - assertStoredValue(uri, Contacts.DISPLAY_NAME, "James Sullivan"); + assertStoredValue(uri, Contacts.DISPLAY_NAME, "James P. Sullivan"); + } + + public void testDisplayNameFromOrganizationWithoutPhoneticName() { + long rawContactId = createRawContact(); + long contactId = queryContactId(rawContactId); + ContentValues values = new ContentValues(); + + Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); + + // If there is title without company, the title is display name. + values.clear(); + values.put(Organization.TITLE, "Protagonist"); + Uri organizationUri = insertOrganization(rawContactId, values); + assertStoredValue(uri, Contacts.DISPLAY_NAME, "Protagonist"); + + // If there are title and company, the company is display name. + values.clear(); + values.put(Organization.COMPANY, "Monsters Inc"); + mResolver.update(organizationUri, values, null, null); + + values.clear(); + values.put(Contacts.DISPLAY_NAME, "Monsters Inc"); + values.putNull(Contacts.PHONETIC_NAME); + values.put(Contacts.PHONETIC_NAME_STYLE, PhoneticNameStyle.UNDEFINED); + values.put(Contacts.SORT_KEY_PRIMARY, "Monsters Inc"); + values.put(Contacts.SORT_KEY_ALTERNATIVE, "Monsters Inc"); + assertStoredValues(uri, values); + } + + public void testDisplayNameFromOrganizationWithJapanesePhoneticName() { + long rawContactId = createRawContact(); + long contactId = queryContactId(rawContactId); + ContentValues values = new ContentValues(); + + Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); + + // If there is title without company, the title is display name. + values.clear(); + values.put(Organization.COMPANY, "DoCoMo"); + values.put(Organization.PHONETIC_NAME, "\u30C9\u30B3\u30E2"); + Uri organizationUri = insertOrganization(rawContactId, values); + + values.clear(); + values.put(Contacts.DISPLAY_NAME, "DoCoMo"); + values.put(Contacts.PHONETIC_NAME, "\u30C9\u30B3\u30E2"); + values.put(Contacts.PHONETIC_NAME_STYLE, PhoneticNameStyle.JAPANESE); + values.put(Contacts.SORT_KEY_PRIMARY, "\u30C9\u30B3\u30E2"); + values.put(Contacts.SORT_KEY_ALTERNATIVE, "\u30C9\u30B3\u30E2"); + assertStoredValues(uri, values); + } + + public void testDisplayNameFromOrganizationWithChineseName() { + long rawContactId = createRawContact(); + long contactId = queryContactId(rawContactId); + ContentValues values = new ContentValues(); + + Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); + + // If there is title without company, the title is display name. + values.clear(); + values.put(Organization.COMPANY, "\u4E2D\u56FD\u7535\u4FE1"); + Uri organizationUri = insertOrganization(rawContactId, values); + + values.clear(); + values.put(Contacts.DISPLAY_NAME, "\u4E2D\u56FD\u7535\u4FE1"); + values.putNull(Contacts.PHONETIC_NAME); + values.put(Contacts.PHONETIC_NAME_STYLE, PhoneticNameStyle.UNDEFINED); + values.put(Contacts.SORT_KEY_PRIMARY, "ZHONG GUO DIAN XIN"); + values.put(Contacts.SORT_KEY_ALTERNATIVE, "ZHONG GUO DIAN XIN"); + assertStoredValues(uri, values); } public void testDisplayNameUpdateFromStructuredNameUpdate() { diff --git a/tests/src/com/android/providers/contacts/NameSplitterTest.java b/tests/src/com/android/providers/contacts/NameSplitterTest.java index 1f0cf29..cb76dce 100644 --- a/tests/src/com/android/providers/contacts/NameSplitterTest.java +++ b/tests/src/com/android/providers/contacts/NameSplitterTest.java @@ -42,7 +42,7 @@ public class NameSplitterTest extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); - createNameSplitter(Locale.getDefault()); + createNameSplitter(Locale.US); } private void createNameSplitter(Locale locale) { @@ -191,6 +191,7 @@ public class NameSplitterTest extends TestCase { } public void testGuessFullNameStyleJapanese() { + createNameSplitter(Locale.JAPAN); // Hiragana: always Japanese assertFullNameStyle(FullNameStyle.JAPANESE, "\u3042\u3080\u308D\u306A\u307F\u3048"); @@ -201,8 +202,9 @@ public class NameSplitterTest extends TestCase { // Half-width Katakana: always Japanese assertFullNameStyle(FullNameStyle.JAPANESE, "\uFF71\uFF91\uFF9B \uFF85\uFF90\uFF74"); - // Kanji: we cannot tell if this is Japanese, Chinese or Korean - assertFullNameStyle(FullNameStyle.CJK, "\u5B89\u5BA4\u5948\u7F8E\u6075"); + // Kanji: we cannot tell if this is Japanese, Chinese or Korean, but we are + // in Locale.JAPAN, so assume Japanese + assertFullNameStyle(FullNameStyle.JAPANESE, "\u5B89\u5BA4\u5948\u7F8E\u6075"); // TODO: mix @@ -216,17 +218,19 @@ public class NameSplitterTest extends TestCase { } public void testGuessFullNameStyleChinese() { + createNameSplitter(Locale.CHINA); - // Hanzi: we cannot tell if this is Chinese, Japanese or Korean - assertFullNameStyle(FullNameStyle.CJK, "\u675C\u9D51"); + // Hanzi: we cannot tell if this is Chinese, Japanese or Korean, + // but we are in Locale.CHINA, so assume this is Chinese + assertFullNameStyle(FullNameStyle.CHINESE, "\u675C\u9D51"); // Accompanied by a phonetic name in Pinyin, we can safely assume that the - // name is Japanese + // name is Chinese assertFullNameStyle(FullNameStyle.CHINESE, "\u675C\u9D51", "du4", null, "juan1"); // Non-letters don't make a difference. This one starts with a vertical line - assertFullNameStyle(FullNameStyle.CJK, "\uFF5C--(\u675C\u9D51)"); + assertFullNameStyle(FullNameStyle.CHINESE, "\uFF5C--(\u675C\u9D51)"); } @@ -252,7 +256,6 @@ public class NameSplitterTest extends TestCase { } public void testSplitJapaneseName() { - createNameSplitter(Locale.JAPAN); // One word is interpreted as given name only @@ -271,7 +274,6 @@ public class NameSplitterTest extends TestCase { } public void testSplitChineseName() { - createNameSplitter(Locale.CHINA); // Two Hanzi characters: familyName+givenName @@ -285,7 +287,6 @@ public class NameSplitterTest extends TestCase { } public void testJoinJapaneseName() { - createNameSplitter(Locale.JAPAN); assertJoinedName("\u3042\u3080\u308D", FullNameStyle.JAPANESE, null, "\u3042\u3080\u308D", diff --git a/tests/src/com/android/providers/contacts/SynchronousContactsProvider2.java b/tests/src/com/android/providers/contacts/SynchronousContactsProvider2.java index 12b809d..865a4c9 100644 --- a/tests/src/com/android/providers/contacts/SynchronousContactsProvider2.java +++ b/tests/src/com/android/providers/contacts/SynchronousContactsProvider2.java @@ -20,6 +20,8 @@ import android.accounts.Account; import android.content.Context; import android.database.sqlite.SQLiteDatabase; +import java.util.Locale; + /** * A version of {@link ContactsProvider2} class that performs aggregation * synchronously and wipes all data at construction time. @@ -89,6 +91,11 @@ public class SynchronousContactsProvider2 extends ContactsProvider2 { } @Override + protected Locale getLocale() { + return Locale.US; + } + + @Override protected boolean isWritableAccount(Account account) { return true; } |