2 *******************************************************************************
\r
3 * Copyright (C) 2008-2009, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.dev.test.collator;
\r
9 import java.util.ArrayList;
\r
10 import java.util.Collection;
\r
11 import java.util.Iterator;
\r
12 import java.util.List;
\r
13 import java.util.Map;
\r
15 import com.ibm.icu.dev.test.TestFmwk;
\r
16 import com.ibm.icu.text.Collator;
\r
17 import com.ibm.icu.text.IndexCharacters;
\r
18 import com.ibm.icu.util.ULocale;
\r
24 public class IndexCharactersTest extends TestFmwk {
\r
25 public static void main(String[] args) throws Exception{
\r
26 new IndexCharactersTest().run(args);
\r
29 public void TestBasics() {
\r
30 ULocale[] list = ULocale.getAvailableLocales();
\r
31 // get keywords combinations
\r
32 // don't bother with multiple combinations at this poin
\r
33 List keywords = new ArrayList();
\r
36 String[] collationValues = Collator.getKeywordValues("collation");
\r
37 for (int j = 0; j < collationValues.length; ++j) {
\r
38 keywords.add("@collation=" + collationValues[j]);
\r
41 for (int i = 0; i < list.length; ++i) {
\r
42 for (Iterator it = keywords.iterator(); it.hasNext();) {
\r
43 String collationValue = (String) it.next();
\r
44 ULocale locale = new ULocale(list[i].toString() + collationValue);
\r
45 if (collationValue.length() > 0 && !Collator.getFunctionalEquivalent("collation", locale).equals(locale)) {
\r
46 //logln("Skipping " + locale);
\r
50 if (locale.getCountry().length() != 0) {
\r
53 IndexCharacters indexCharacters = new IndexCharacters(locale);
\r
54 final Collection mainChars = indexCharacters.getIndexCharacters();
\r
55 String mainCharString = mainChars.toString();
\r
56 if (mainCharString.length() > 500) {
\r
57 mainCharString = mainCharString.substring(0,500) + "...";
\r
59 logln(mainChars.size() + "\t" + locale + "\t" + locale.getDisplayName(ULocale.ENGLISH));
\r
60 logln("Index:\t" + mainCharString);
\r
61 if (mainChars.size() > 100) {
\r
62 errln("Index character set too large");
\r
64 showIfNotEmpty("A sequence sorting the same is already present", indexCharacters.getAlreadyIn());
\r
65 showIfNotEmpty("A sequence sorts the same as components", indexCharacters.getNoDistinctSorting());
\r
66 showIfNotEmpty("A sequence has only Marks or Nonalphabetics", indexCharacters.getNotAlphabetic());
\r
70 private void showIfNotEmpty(String title, List alreadyIn) {
\r
71 if (alreadyIn.size() != 0) {
\r
72 logln("\t" + title + ":\t" + alreadyIn);
\r
75 private void showIfNotEmpty(String title, Map alreadyIn) {
\r
76 if (alreadyIn.size() != 0) {
\r
77 logln("\t" + title + ":\t" + alreadyIn);
\r
81 /* Test the method public ULocale getLocale() */
\r
82 public void TestGetLocale(){
\r
83 IndexCharacters ic = new IndexCharacters(new ULocale("en_US"));
\r
84 if(!ic.getLocale().equals(new ULocale("en_US"))){
\r
85 errln("IndexCharacter.getLocale() was suppose to return the same " +
\r
86 "ULocale that was passed for the object.");
\r
88 if(ic.getLocale().equals(new ULocale("jp_JP"))){
\r
89 errln("IndexCharacter.getLocale() was not suppose to return the same " +
\r
90 "ULocale that was passed for the object.");
\r