diff options
Diffstat (limited to 'tests/src')
3 files changed, 46 insertions, 18 deletions
diff --git a/tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java b/tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java index 637c4e3..ea4ef0f 100644 --- a/tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java +++ b/tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Locale; @SmallTest @@ -160,9 +161,7 @@ public class ContactLocaleUtilsTest extends AndroidTestCase { assertEquals("D", getLabel(CHINESE_LATIN_MIX_NAME_1)); assertNull(getNameLookupKeys(CHINESE_NAME, FullNameStyle.CJK)); - Iterator<String> keys = getNameLookupKeys(CHINESE_NAME, - FullNameStyle.CHINESE); - verifyKeys(keys, CHINESE_NAME_KEY); + assertNull(getNameLookupKeys(CHINESE_NAME, FullNameStyle.CHINESE)); // Following two tests are broken with ICU 50 verifyLabels(getLabels(), LABELS_JA_JP); @@ -213,14 +212,12 @@ public class ContactLocaleUtilsTest extends AndroidTestCase { } ContactLocaleUtils.setLocale(Locale.ENGLISH); - Iterator<String> keys = getNameLookupKeys(CHINESE_NAME, - FullNameStyle.CHINESE); - verifyKeys(keys, CHINESE_NAME_KEY); - keys = getNameLookupKeys(CHINESE_NAME, FullNameStyle.CJK); - verifyKeys(keys, CHINESE_NAME_KEY); + assertNull(getNameLookupKeys(CHINESE_NAME, FullNameStyle.CHINESE)); + assertNull(getNameLookupKeys(CHINESE_NAME, FullNameStyle.CJK)); - ContactLocaleUtils.setLocale(Locale.CHINESE); - keys = getNameLookupKeys(CHINESE_NAME, FullNameStyle.CJK); + ContactLocaleUtils.setLocale(Locale.CHINA); + Iterator<String> keys = getNameLookupKeys(CHINESE_NAME, + FullNameStyle.CJK); verifyKeys(keys, CHINESE_NAME_KEY); keys = getNameLookupKeys(LATIN_NAME, FullNameStyle.WESTERN); verifyKeys(keys, LATIN_NAME_KEY); @@ -228,8 +225,7 @@ public class ContactLocaleUtilsTest extends AndroidTestCase { verifyKeys(keys, LATIN_NAME_KEY_2); ContactLocaleUtils.setLocale(Locale.TRADITIONAL_CHINESE); - keys = getNameLookupKeys(CHINESE_NAME, FullNameStyle.CJK); - verifyKeys(keys, CHINESE_NAME_KEY); + assertNull(getNameLookupKeys(CHINESE_NAME, FullNameStyle.CJK)); } public void testKoreanContactLocaleUtils() throws Exception { @@ -278,10 +274,14 @@ public class ContactLocaleUtilsTest extends AndroidTestCase { assertEquals(new HashSet<String>(Arrays.asList(expectedKeys)), allKeys); } + // Verify that the initial set of resultLabels matches the expectedLabels. + // Ignore the (large) number of secondary locale labels that make up the + // tail labels in the result set right before the final "#" and "" buckets. private void verifyLabels(final ArrayList<String> resultLabels, - final String[] expectedLabels) - throws Exception { - assertEquals(new ArrayList<String>(Arrays.asList(expectedLabels)), - resultLabels); + final String[] expectedLabels) throws Exception { + final List<String> expectedLabelList = Arrays.asList(expectedLabels); + final int numLabels = expectedLabelList.size() - 2; + assertEquals(expectedLabelList.subList(0, numLabels), + resultLabels.subList(0, numLabels)); } } diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index df8e6d6..3f8b001 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -3383,6 +3383,27 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { assertStoredValues(dataUri, values); } + public void testJapaneseNameContactInEnglishLocale() { + // Need Japanese locale data for transliteration + if (!hasJapaneseCollator()) { + return; + } + ContactLocaleUtils.setLocale(Locale.US); + 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"); + insertStructuredName(rawContactId, values); + + long contactId = queryContactId(rawContactId); + // en_US should behave same as ja_JP (match on Hiragana and Romaji + // but not Pinyin) + assertContactFilter(contactId, "\u304B\u3044\u304F\u3046"); + assertContactFilter(contactId, "kaiku"); + assertContactFilterNoResult("kong"); + } + public void testContactWithJapaneseName() { if (!hasJapaneseCollator()) { return; @@ -3426,6 +3447,12 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { // The same values should be available through a join with Data assertStoredValues(dataUri, values); + + long contactId = queryContactId(rawContactId); + // ja_JP should match on Hiragana and Romaji but not Pinyin + assertContactFilter(contactId, "\u304B\u3044\u304F\u3046"); + assertContactFilter(contactId, "kaiku"); + assertContactFilterNoResult("kong"); } public void testDisplayNameUpdate() { @@ -3616,8 +3643,8 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { } private void assertContactFilterNoResult(String filter) { - Uri filterUri4 = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, filter); - assertEquals(0, getCount(filterUri4, null, null)); + Uri filterUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(filter)); + assertEquals(0, getCount(filterUri, null, null)); } public void testSearchSnippetOrganization() throws Exception { diff --git a/tests/src/com/android/providers/contacts/SearchIndexManagerTest.java b/tests/src/com/android/providers/contacts/SearchIndexManagerTest.java index 3abdc3f..ac6e5e3 100644 --- a/tests/src/com/android/providers/contacts/SearchIndexManagerTest.java +++ b/tests/src/com/android/providers/contacts/SearchIndexManagerTest.java @@ -87,6 +87,7 @@ public class SearchIndexManagerTest extends BaseContactsProvider2Test { if (!Arrays.asList(Collator.getAvailableLocales()).contains(Locale.CHINA)) { return; } + ContactLocaleUtils.setLocale(Locale.SIMPLIFIED_CHINESE); long rawContactId = createRawContact(); ContentValues values = new ContentValues(); |