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 insertNameShorthandLookup(
     long rawContactId, long dataId, String name, int fullNameStyle) {
   Iterator<String> it = ContactLocaleUtils.getIntance().getNameLookupKeys(name, fullNameStyle);
   if (it != null) {
     while (it.hasNext()) {
       String key = it.next();
       insertNameLookup(rawContactId, dataId, NameLookupType.NAME_SHORTHAND, normalizeName(key));
     }
   }
 }
  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);
  }
  public void testChineseStyleNameWithDifferentLocale() throws Exception {
    if (!hasChineseCollator) {
      return;
    }

    ContactLocaleUtils.setLocale(Locale.ENGLISH);
    assertNull(getNameLookupKeys(CHINESE_NAME, FullNameStyle.CHINESE));
    assertNull(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);
    keys = getNameLookupKeys(LATIN_NAME_2, FullNameStyle.WESTERN);
    verifyKeys(keys, LATIN_NAME_KEY_2);

    ContactLocaleUtils.setLocale(Locale.TRADITIONAL_CHINESE);
    assertNull(getNameLookupKeys(CHINESE_NAME, FullNameStyle.CJK));
  }
  public void testEnglishContactLocaleUtils() throws Exception {
    ContactLocaleUtils.setLocale(Locale.ENGLISH);
    assertEquals("#", getLabel(PHONE_NUMBER_1));
    assertEquals("#", getLabel(PHONE_NUMBER_2));
    assertEquals("J", getLabel(LATIN_NAME));
    assertEquals("", getLabel(CHINESE_NAME));
    assertEquals("D", getLabel(CHINESE_LATIN_MIX_NAME_1));
    assertEquals("B", getLabel("Bob Smith"));

    assertNull(getNameLookupKeys(LATIN_NAME, FullNameStyle.UNDEFINED));
    verifyLabels(getLabels(), LABELS_EN_US);
  }
  public void testKoreanContactLocaleUtils() throws Exception {
    if (!hasKoreanCollator) {
      return;
    }

    ContactLocaleUtils.setLocale(Locale.KOREA);
    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);
  }
  public void testChineseContactLocaleUtils() throws Exception {
    if (!hasChineseCollator) {
      return;
    }

    ContactLocaleUtils.setLocale(Locale.SIMPLIFIED_CHINESE);
    assertEquals("#", getLabel(PHONE_NUMBER_1));
    assertEquals("#", getLabel(PHONE_NUMBER_2));
    assertEquals("J", getLabel(LATIN_NAME));
    assertEquals("D", getLabel(CHINESE_NAME));
    assertEquals("D", getLabel(CHINESE_LATIN_MIX_NAME_1));
    assertEquals("B", getLabel("Bob Smith"));
    verifyLabels(getLabels(), LABELS_EN_US);

    ContactLocaleUtils.setLocale(Locale.TRADITIONAL_CHINESE);
    assertEquals("#", getLabel(PHONE_NUMBER_1));
    assertEquals("#", getLabel(PHONE_NUMBER_2));
    assertEquals("J", getLabel(LATIN_NAME));
    assertEquals("7\u5283", getLabel(CHINESE_NAME));
    assertEquals("D", getLabel(CHINESE_LATIN_MIX_NAME_1));

    ContactLocaleUtils.setLocale(Locale.SIMPLIFIED_CHINESE);
    Iterator<String> keys = getNameLookupKeys(CHINESE_NAME, FullNameStyle.CHINESE);
    verifyKeys(keys, CHINESE_NAME_KEY);

    keys = getNameLookupKeys(CHINESE_LATIN_MIX_NAME_1, FullNameStyle.CHINESE);
    verifyKeys(keys, CHINESE_LATIN_MIX_NAME_1_KEY);

    keys = getNameLookupKeys(CHINESE_LATIN_MIX_NAME_2, FullNameStyle.CHINESE);
    verifyKeys(keys, CHINESE_LATIN_MIX_NAME_2_KEY);

    // Following test broken with ICU 50
    ContactLocaleUtils.setLocale(Locale.TRADITIONAL_CHINESE);
    verifyLabels(getLabels(), LABELS_ZH_TW);
    assertEquals("B", getLabel("Bob Smith"));
  }
  public void testJapaneseContactLocaleUtils() throws Exception {
    if (!hasJapaneseCollator) {
      return;
    }

    ContactLocaleUtils.setLocale(Locale.JAPAN);
    assertEquals("#", getLabel(PHONE_NUMBER_1));
    assertEquals("#", getLabel(PHONE_NUMBER_2));
    assertEquals(JAPANESE_MISC, getLabel(KANJI_NAME));
    assertEquals("J", getLabel(LATIN_NAME));
    assertEquals(JAPANESE_MISC, getLabel(CHINESE_NAME));
    assertEquals("D", getLabel(CHINESE_LATIN_MIX_NAME_1));

    assertNull(getNameLookupKeys(CHINESE_NAME, FullNameStyle.CJK));
    assertNull(getNameLookupKeys(CHINESE_NAME, FullNameStyle.CHINESE));

    // Following two tests are broken with ICU 50
    verifyLabels(getLabels(), LABELS_JA_JP);
    assertEquals("B", getLabel("Bob Smith"));
  }
 private ArrayList<String> getLabels() {
   ContactLocaleUtils utils = ContactLocaleUtils.getInstance();
   return utils.getLabels();
 }
 private Iterator<String> getNameLookupKeys(String name, int nameStyle) {
   ContactLocaleUtils utils = ContactLocaleUtils.getInstance();
   return utils.getNameLookupKeys(name, nameStyle);
 }
 private String getLabel(String name) {
   ContactLocaleUtils utils = ContactLocaleUtils.getInstance();
   int bucketIndex = utils.getBucketIndex(name);
   return utils.getBucketLabel(bucketIndex);
 }