aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Shrauner <shrauner@google.com>2013-03-11 21:00:36 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-03-11 21:00:36 +0000
commit016d2f04b46a45e8ebd105f22814adf6e6ad57fd (patch)
treedbc3dc17b30c55ffb9d85b22f96fa849d13e7834
parentb3ba1435441188ca2ce4802a754d2255f1aa5e98 (diff)
parent1f8895bc9efd6c20adb02652bccb2c011ebca114 (diff)
downloadContactsProvider-016d2f04b46a45e8ebd105f22814adf6e6ad57fd.tar.gz
Merge "Fix unit tests for ICU 51 patches" into jb-mr2-dev
-rw-r--r--src/com/android/providers/contacts/ContactLocaleUtils.java56
-rw-r--r--tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java46
-rw-r--r--tests/src/com/android/providers/contacts/ContactsProvider2Test.java36
3 files changed, 72 insertions, 66 deletions
diff --git a/src/com/android/providers/contacts/ContactLocaleUtils.java b/src/com/android/providers/contacts/ContactLocaleUtils.java
index 85bf490c..b53dab48 100644
--- a/src/com/android/providers/contacts/ContactLocaleUtils.java
+++ b/src/com/android/providers/contacts/ContactLocaleUtils.java
@@ -261,7 +261,7 @@ public class ContactLocaleUtils {
* labels: unchanged
* Simplified Chinese labels are the same as English: [A-Z], #, " "
* Traditional Chinese labels are stroke count, then English labels:
- * [1-18], [A-Z], #, " "
+ * [1-33, 35, 36, 48]劃, [A-Z], #, " "
*/
private static class ChineseContactUtils extends ContactLocaleUtilsBase {
public ChineseContactUtils(Locale locale) {
@@ -309,54 +309,6 @@ public class ContactLocaleUtils {
}
}
- /**
- * Traditional Chinese specific locale overrides. Rewrites ICU labels
- * to correct ICU 50 labels.
- *
- * TODO: remove once ICU is upgraded to 51 and labels are fixed
- *
- * sortKey: unchanged from base class (same as name)
- * nameLookupKeys: unchanged from ChineseContactUtils
- * labels: unchanged
- * Simplified Chinese labels are the same as English: [A-Z], #, " "
- * Traditional Chinese labels are stroke count, then English labels:
- * [1-18]劃, [A-Z], #, " "
- */
- private static class TraditionalChineseContactUtils
- extends ChineseContactUtils {
- // Remap ICU 50 labels to desired values
- private static final Map<String, String> labelMap;
- static {
- Map<String, String> map = new HashMap<String, String>();
- final List<String> oldLabels =
- Arrays.asList("\u4E00", "\u4E01", "\u4E08", "\u4E0D",
- "\u4E14", "\u4E1E", "\u4E32", "\u4E26",
- "\u4EAD", "\u4E58", "\u4E7E", "\u5080",
- "\u4E82", "\u50CE", "\u50F5", "\u5110",
- "\u511F", "\u53E2", "\u5133", "\u56B4",
- "\u5137", "\u513B", "\u56CC", "\u56D1",
- "\u5EF3");
- int strokeCount = 1;
- for(String oldLabel : oldLabels) {
- String newLabel = "" + strokeCount + "\u5283";
- map.put(oldLabel, newLabel);
- ++strokeCount;
- }
- labelMap = Collections.unmodifiableMap(map);
- }
-
- public TraditionalChineseContactUtils(Locale locale) {
- super(locale);
- }
-
- @Override
- public String getBucketLabel(int bucketIndex) {
- final String label = super.getBucketLabel(bucketIndex);
- final String remappedLabel = labelMap.get(label);
- return remappedLabel != null ? remappedLabel : label;
- }
- }
-
private static final String CHINESE_LANGUAGE = Locale.CHINESE.getLanguage().toLowerCase();
private static final String JAPANESE_LANGUAGE = Locale.JAPANESE.getLanguage().toLowerCase();
private static final String KOREAN_LANGUAGE = Locale.KOREAN.getLanguage().toLowerCase();
@@ -377,11 +329,7 @@ public class ContactLocaleUtils {
if (mLanguage.equals(JAPANESE_LANGUAGE)) {
mUtils = new JapaneseContactUtils(mLocale);
} else if (mLanguage.equals(CHINESE_LANGUAGE)) {
- if (isLocale(Locale.TRADITIONAL_CHINESE)) {
- mUtils = new TraditionalChineseContactUtils(mLocale);
- } else {
- mUtils = new ChineseContactUtils(mLocale);
- }
+ mUtils = new ChineseContactUtils(mLocale);
} else {
mUtils = new ContactLocaleUtilsBase(mLocale);
}
diff --git a/tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java b/tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java
index a650d3e2..637c4e3b 100644
--- a/tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java
+++ b/tests/src/com/android/providers/contacts/ContactLocaleUtilsTest.java
@@ -51,6 +51,10 @@ 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_DE = {
+ "", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
+ "N", "O", "P", "Q", "R", "S", "Sch", "St", "T", "U", "V", "W", "X",
+ "Y", "Z", "#", ""};
private static final String[] LABELS_JA_JP = {
"", "\u3042", "\u304B", "\u3055", "\u305F", "\u306A", "\u306F",
"\u307E", "\u3084", "\u3089", "\u308F", "\u4ED6",
@@ -62,22 +66,25 @@ public class ContactLocaleUtilsTest extends AndroidTestCase {
"7\u5283", "8\u5283", "9\u5283", "10\u5283", "11\u5283", "12\u5283",
"13\u5283", "14\u5283", "15\u5283", "16\u5283", "17\u5283", "18\u5283",
"19\u5283", "20\u5283", "21\u5283", "22\u5283", "23\u5283", "24\u5283",
- "25\u5283",
+ "25\u5283", "26\u5283", "27\u5283", "28\u5283", "29\u5283", "30\u5283",
+ "31\u5283", "32\u5283", "33\u5283",
+ "35\u5283", "36\u5283", "39\u5283", "48\u5283",
"", "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_KO = {
- "", "\u1100", "\u1102", "\u1103", "\u1105", "\u1106", "\u1107",
- "\u1109", "\u110B", "\u110C", "\u110E", "\u110F", "\u1110", "\u1111",
- "\u1112",
+ "", "\u3131", "\u3134", "\u3137", "\u3139", "\u3141", "\u3142",
+ "\u3145", "\u3147", "\u3148", "\u314A", "\u314B", "\u314C", "\u314D",
+ "\u314E",
"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",
+ "", "\u0627", "\u0628", "\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",
"#", ""};
@@ -89,6 +96,7 @@ public class ContactLocaleUtilsTest extends AndroidTestCase {
private boolean hasJapaneseCollator;
private boolean hasKoreanCollator;
private boolean hasArabicCollator;
+ private boolean hasGermanCollator;
@Override
protected void setUp() throws Exception {
@@ -103,6 +111,8 @@ public class ContactLocaleUtilsTest extends AndroidTestCase {
hasKoreanCollator = true;
} else if (locale[i].equals(LOCALE_ARABIC)) {
hasArabicCollator = true;
+ } else if (locale[i].equals(Locale.GERMANY)) {
+ hasGermanCollator = true;
}
}
}
@@ -228,10 +238,10 @@ public class ContactLocaleUtilsTest extends AndroidTestCase {
}
ContactLocaleUtils.setLocale(Locale.KOREA);
- assertEquals("\u1100", getLabel("\u1100"));
- assertEquals("\u1100", getLabel("\u3131"));
- assertEquals("\u1100", getLabel("\u1101"));
- assertEquals("\u1112", getLabel("\u1161"));
+ assertEquals("\u3131", getLabel("\u1100"));
+ assertEquals("\u3131", getLabel("\u3131"));
+ assertEquals("\u3131", getLabel("\u1101"));
+ assertEquals("\u314e", getLabel("\u1161"));
assertEquals("B", getLabel("Bob Smith"));
verifyLabels(getLabels(), LABELS_KO);
}
@@ -247,6 +257,18 @@ public class ContactLocaleUtilsTest extends AndroidTestCase {
verifyLabels(getLabels(), LABELS_AR);
}
+ public void testGermanContactLocaleUtils() throws Exception {
+ if (!hasGermanCollator) {
+ return;
+ }
+
+ ContactLocaleUtils.setLocale(Locale.GERMANY);
+ assertEquals("S", getLabel("Sacher"));
+ assertEquals("Sch", getLabel("Schiller"));
+ assertEquals("St", getLabel("Steiff"));
+ verifyLabels(getLabels(), LABELS_DE);
+ }
+
private void verifyKeys(final Iterator<String> resultKeys, final String[] expectedKeys)
throws Exception {
HashSet<String> allKeys = new HashSet<String>();
diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
index a00017e8..d7a93d4a 100644
--- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
+++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
@@ -6311,6 +6311,32 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test {
cursor.close();
}
+ public void testContactCountsWithGermanNames() {
+ if (!hasGermanCollator()) {
+ return;
+ }
+ ContactLocaleUtils.setLocale(Locale.GERMANY);
+
+ Uri uri = Contacts.CONTENT_URI.buildUpon()
+ .appendQueryParameter(ContactCounts.ADDRESS_BOOK_INDEX_EXTRAS, "true").build();
+
+ createRawContactWithName("Josef", "Sacher");
+ createRawContactWithName("Franz", "Schiller");
+ createRawContactWithName("Eckart", "Steiff");
+ createRawContactWithName("Klaus", "Seiler");
+ createRawContactWithName("Lars", "Sultan");
+ createRawContactWithName("Heidi", "Rilke");
+ createRawContactWithName("Suse", "Thomas");
+
+ Cursor cursor = mResolver.query(uri,
+ new String[]{Contacts.DISPLAY_NAME},
+ null, null, Contacts.SORT_KEY_ALTERNATIVE);
+
+ assertFirstLetterValues(cursor, "R", "S", "Sch", "St", "T");
+ assertFirstLetterCounts(cursor, 1, 3, 1, 1, 1);
+ cursor.close();
+ }
+
private void assertFirstLetterValues(Cursor cursor, String... expected) {
String[] actual = cursor.getExtras()
.getStringArray(ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_TITLES);
@@ -7381,4 +7407,14 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test {
}
return false;
}
+
+ private boolean hasGermanCollator() {
+ final Locale locale[] = Collator.getAvailableLocales();
+ for (int i = 0; i < locale.length; i++) {
+ if (locale[i].equals(Locale.GERMANY)) {
+ return true;
+ }
+ }
+ return false;
+ }
}