diff options
author | Jay Shrauner <shrauner@google.com> | 2013-02-27 11:26:01 -0800 |
---|---|---|
committer | Jay Shrauner <shrauner@google.com> | 2013-02-27 12:06:20 -0800 |
commit | 21cfa6019b9fb82c23edf978d27904757207d9b0 (patch) | |
tree | 61140a5fbce32541de3b0f1687f8a7db9179e71f /tests/src/com/android/providers/contacts | |
parent | 923bd87366167e0a569883993e9ec5b19104657a (diff) | |
download | packages_providers_ContactsProvider-21cfa6019b9fb82c23edf978d27904757207d9b0.zip packages_providers_ContactsProvider-21cfa6019b9fb82c23edf978d27904757207d9b0.tar.gz packages_providers_ContactsProvider-21cfa6019b9fb82c23edf978d27904757207d9b0.tar.bz2 |
Fix unit tests for ICU 50
Fix tests to account for fixes made in ICU 50. Add some additional tests.
Bug:
Change-Id: I7d1fb0588f56b58da5c5177823ed5c16c4603e24
Diffstat (limited to 'tests/src/com/android/providers/contacts')
-rw-r--r-- | tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java | 83 | ||||
-rw-r--r-- | tests/src/com/android/providers/contacts/HanziToPinyinTest.java | 2 |
2 files changed, 58 insertions, 27 deletions
diff --git a/tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java b/tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java index b43cff2..a650d3e 100644 --- a/tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java +++ b/tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java @@ -34,6 +34,7 @@ public class ContactLocaleUtilsTest extends AndroidTestCase { private static final String LATIN_NAME = "John Smith"; private static final String LATIN_NAME_2 = "John Paul Jones"; private static final String KANJI_NAME = "\u65e5"; + private static final String ARABIC_NAME = "\u0646\u0648\u0631"; /* Noor */ private static final String CHINESE_NAME = "\u675C\u9D51"; private static final String CHINESE_LATIN_MIX_NAME_1 = "D\u675C\u9D51"; private static final String CHINESE_LATIN_MIX_NAME_2 = "MARY \u675C\u9D51"; @@ -72,9 +73,40 @@ public class ContactLocaleUtilsTest extends AndroidTestCase { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "#", ""}; + private static final String[] LABELS_AR = { + "", "\u0627", "\u062a", "\u062b", "\u062c", "\u062d", "\u062e", + "\u062f", "\u0630", "\u0631", "\u0632", "\u0633", "\u0634", "\u0635", + "\u0636", "\u0637", "\u0638", "\u0639", "\u063a", "\u0641", "\u0642", + "\u0643", "\u0644", "\u0645", "\u0646", "\u0647", "\u0648", "\u064a", + "", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", + "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", + "#", ""}; private static final String JAPANESE_MISC = "\u4ed6"; + private static final Locale LOCALE_ARABIC = new Locale("ar"); + private boolean hasChineseCollator; + private boolean hasJapaneseCollator; + private boolean hasKoreanCollator; + private boolean hasArabicCollator; + + @Override + protected void setUp() throws Exception { + super.setUp(); + final Locale locale[] = Collator.getAvailableLocales(); + for (int i = 0; i < locale.length; i++) { + if (locale[i].equals(Locale.CHINA)) { + hasChineseCollator = true; + } else if (locale[i].equals(Locale.JAPAN)) { + hasJapaneseCollator = true; + } else if (locale[i].equals(Locale.KOREA)) { + hasKoreanCollator = true; + } else if (locale[i].equals(LOCALE_ARABIC)) { + hasArabicCollator = true; + } + } + } + private String getLabel(String name) { ContactLocaleUtils utils = ContactLocaleUtils.getInstance(); int bucketIndex = utils.getBucketIndex(name); @@ -105,7 +137,7 @@ public class ContactLocaleUtilsTest extends AndroidTestCase { } public void testJapaneseContactLocaleUtils() throws Exception { - if (!hasJapaneseCollator()) { + if (!hasJapaneseCollator) { return; } @@ -122,13 +154,13 @@ public class ContactLocaleUtilsTest extends AndroidTestCase { FullNameStyle.CHINESE); verifyKeys(keys, CHINESE_NAME_KEY); - // Following two tests are broken with ICU 4.9 + // Following two tests are broken with ICU 50 verifyLabels(getLabels(), LABELS_JA_JP); assertEquals("B", getLabel("Bob Smith")); } public void testChineseContactLocaleUtils() throws Exception { - if (!hasChineseCollator()) { + if (!hasChineseCollator) { return; } @@ -145,7 +177,7 @@ public class ContactLocaleUtilsTest extends AndroidTestCase { assertEquals("#", getLabel(PHONE_NUMBER_1)); assertEquals("#", getLabel(PHONE_NUMBER_2)); assertEquals("J", getLabel(LATIN_NAME)); - assertEquals("12\u5283", getLabel(CHINESE_NAME)); + assertEquals("7\u5283", getLabel(CHINESE_NAME)); assertEquals("D", getLabel(CHINESE_LATIN_MIX_NAME_1)); ContactLocaleUtils.setLocale(Locale.SIMPLIFIED_CHINESE); @@ -159,14 +191,14 @@ public class ContactLocaleUtilsTest extends AndroidTestCase { keys = getNameLookupKeys(CHINESE_LATIN_MIX_NAME_2, FullNameStyle.CHINESE); verifyKeys(keys, CHINESE_LATIN_MIX_NAME_2_KEY); - // Following test broken with ICU 4.9 + // Following test broken with ICU 50 ContactLocaleUtils.setLocale(Locale.TRADITIONAL_CHINESE); verifyLabels(getLabels(), LABELS_ZH_TW); assertEquals("B", getLabel("Bob Smith")); } public void testChineseStyleNameWithDifferentLocale() throws Exception { - if (!hasChineseCollator()) { + if (!hasChineseCollator) { return; } @@ -191,11 +223,30 @@ public class ContactLocaleUtilsTest extends AndroidTestCase { } public void testKoreanContactLocaleUtils() throws Exception { + if (!hasKoreanCollator) { + return; + } + ContactLocaleUtils.setLocale(Locale.KOREA); + assertEquals("\u1100", getLabel("\u1100")); + assertEquals("\u1100", getLabel("\u3131")); + assertEquals("\u1100", getLabel("\u1101")); + assertEquals("\u1112", getLabel("\u1161")); assertEquals("B", getLabel("Bob Smith")); verifyLabels(getLabels(), LABELS_KO); } + public void testArabicContactLocaleUtils() throws Exception { + if (!hasArabicCollator) { + return; + } + + ContactLocaleUtils.setLocale(LOCALE_ARABIC); + assertEquals("\u0646", getLabel(ARABIC_NAME)); + assertEquals("B", getLabel("Bob Smith")); + verifyLabels(getLabels(), LABELS_AR); + } + private void verifyKeys(final Iterator<String> resultKeys, final String[] expectedKeys) throws Exception { HashSet<String> allKeys = new HashSet<String>(); @@ -211,24 +262,4 @@ public class ContactLocaleUtilsTest extends AndroidTestCase { assertEquals(new ArrayList<String>(Arrays.asList(expectedLabels)), resultLabels); } - - private boolean hasChineseCollator() { - final Locale locale[] = Collator.getAvailableLocales(); - for (int i = 0; i < locale.length; i++) { - if (locale[i].equals(Locale.CHINA)) { - return true; - } - } - return false; - } - - private boolean hasJapaneseCollator() { - final Locale locale[] = Collator.getAvailableLocales(); - for (int i = 0; i < locale.length; i++) { - if (locale[i].equals(Locale.JAPAN)) { - return true; - } - } - return false; - } } diff --git a/tests/src/com/android/providers/contacts/HanziToPinyinTest.java b/tests/src/com/android/providers/contacts/HanziToPinyinTest.java index 2f1a071..4db1d34 100644 --- a/tests/src/com/android/providers/contacts/HanziToPinyinTest.java +++ b/tests/src/com/android/providers/contacts/HanziToPinyinTest.java @@ -10266,7 +10266,7 @@ public class HanziToPinyinTest extends TestCase { test('\u7562', "BI"); test('\u7563', "DA"); test('\u7564', "ZHI"); - test('\u7565', "E"); + test('\u7565', "LUE"); test('\u7566', "QI"); test('\u7567', "LUE"); test('\u7568', "PAN"); |