2 *******************************************************************************
\r
3 * Copyright (C) 2009, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.dev.test.util;
\r
9 import java.util.MissingResourceException;
\r
11 import com.ibm.icu.dev.test.TestFmwk;
\r
12 import com.ibm.icu.impl.ICUResourceBundle;
\r
13 import com.ibm.icu.text.Collator;
\r
14 import com.ibm.icu.util.ULocale;
\r
15 import com.ibm.icu.util.UResourceBundle;
\r
18 public final class ICUResourceBundleCollationTest extends TestFmwk {
\r
19 private static final String COLLATION_RESNAME = "collations";
\r
20 private static final String COLLATION_KEYWORD = "collation";
\r
21 private static final String DEFAULT_NAME = "default";
\r
22 private static final String STANDARD_NAME = "standard";
\r
24 public static void main(String args[]) throws Exception {
\r
25 new ICUResourceBundleCollationTest().run(args);
\r
28 public void TestFunctionalEquivalent(){
\r
29 String[] collCases = {
\r
30 // avail locale equiv
\r
31 "f", "de_US_CALIFORNIA", "de",
\r
32 "f", "zh_TW@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_TW */
\r
33 "t", "zh_Hant_TW@collation=stroke", "zh@collation=stroke",
\r
34 "f", "de_CN@collation=pinyin", "de",
\r
35 "t", "zh@collation=pinyin", "zh",
\r
36 "f", "zh_CN@collation=pinyin", "zh", /* alias of zh_Hans_CN */
\r
37 "t", "zh_Hans_CN@collation=pinyin", "zh",
\r
38 "f", "zh_HK@collation=pinyin", "zh", /* alias of zh_Hant_HK */
\r
39 "t", "zh_Hant_HK@collation=pinyin", "zh",
\r
40 "f", "zh_HK@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_HK */
\r
41 "t", "zh_Hant_HK@collation=stroke", "zh@collation=stroke",
\r
42 "f", "zh_HK", "zh@collation=stroke", /* alias of zh_Hant_HK */
\r
43 "t", "zh_Hant_HK", "zh@collation=stroke",
\r
44 "f", "zh_MO", "zh@collation=stroke", /* alias of zh_Hant_MO */
\r
45 "t", "zh_Hant_MO", "zh@collation=stroke",
\r
46 "f", "zh_TW_STROKE", "zh@collation=stroke",
\r
47 "f", "zh_TW_STROKE@collation=big5han", "zh@collation=big5han",
\r
48 "f", "de_CN@calendar=japanese", "de",
\r
49 "t", "de@calendar=japanese", "de",
\r
50 "f", "zh_TW@collation=big5han", "zh@collation=big5han", /* alias of zh_Hant_TW */
\r
51 "t", "zh_Hant_TW@collation=big5han", "zh@collation=big5han",
\r
52 "f", "zh_TW@collation=gb2312han", "zh@collation=gb2312han", /* alias of zh_Hant_TW */
\r
53 "t", "zh_Hant_TW@collation=gb2312han", "zh@collation=gb2312han",
\r
54 "f", "zh_CN@collation=big5han", "zh@collation=big5han", /* alias of zh_Hans_CN */
\r
55 "t", "zh_Hans_CN@collation=big5han", "zh@collation=big5han",
\r
56 "f", "zh_CN@collation=gb2312han", "zh@collation=gb2312han", /* alias of zh_Hans_CN */
\r
57 "t", "zh_Hans_CN@collation=gb2312han", "zh@collation=gb2312han",
\r
58 "t", "zh@collation=big5han", "zh@collation=big5han",
\r
59 "t", "zh@collation=gb2312han", "zh@collation=gb2312han",
\r
60 "t", "hi_IN@collation=direct", "hi@collation=direct",
\r
61 "t", "hi@collation=standard", "hi",
\r
62 "t", "hi@collation=direct", "hi@collation=direct",
\r
63 "f", "hi_AU@collation=direct;currency=CHF;calendar=buddhist", "hi@collation=direct",
\r
64 "f", "hi_AU@collation=standard;currency=CHF;calendar=buddhist", "hi",
\r
65 "t", "de_DE@collation=pinyin", "de", /* bug 4582 tests */
\r
66 "f", "de_DE_BONN@collation=pinyin", "de",
\r
68 "t", "nl_NL", "root",
\r
69 "f", "nl_NL_EEXT", "root",
\r
70 "t", "nl@collation=stroke", "root",
\r
71 "t", "nl_NL@collation=stroke", "root",
\r
72 "f", "nl_NL_EEXT@collation=stroke", "root",
\r
75 logln("Testing functional equivalents for collation...");
\r
76 getFunctionalEquivalentTestCases(ICUResourceBundle.ICU_COLLATION_BASE_NAME,
\r
77 Collator.class.getClassLoader(),
\r
78 COLLATION_RESNAME, COLLATION_KEYWORD, true, collCases);
\r
81 public void TestGetWithFallback(){
\r
83 UResourceBundle bundle =(UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN");
\r
84 String key = bundle.getStringWithFallback("Keys/collation");
\r
85 if(!key.equals("COLLATION")){
\r
86 errln("Did not get the expected result from getStringWithFallback method.");
\r
88 String type = bundle.getStringWithFallback("Types/collation/direct");
\r
89 if(!type.equals("DIRECT")){
\r
90 errln("Did not get the expected result form getStringWithFallback method.");
\r
93 ICUResourceBundle bundle = null;
\r
96 bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,ULocale.canonicalize("de__PHONEBOOK"));
\r
98 if(!bundle.getULocale().equals("de")){
\r
99 errln("did not get the expected bundle");
\r
101 key = bundle.getStringWithFallback("collations/collation/default");
\r
102 if(!key.equals("phonebook")){
\r
103 errln("Did not get the expected result from getStringWithFallback method.");
\r
106 }catch(MissingResourceException ex){
\r
107 logln("got the expected exception");
\r
111 bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,"fr_FR");
\r
112 key = bundle.getStringWithFallback("collations/default");
\r
113 if(!key.equals("standard")){
\r
114 errln("Did not get the expected result from getStringWithFallback method.");
\r
118 public void TestKeywordValues(){
\r
120 boolean foundStandard = false;
\r
123 logln("Testing getting collation values:");
\r
124 kwVals = ICUResourceBundle.getKeywordValues(ICUResourceBundle.ICU_COLLATION_BASE_NAME,COLLATION_RESNAME);
\r
125 for(n=0;n<kwVals.length;n++) {
\r
126 logln(new Integer(n).toString() + ": " + kwVals[n]);
\r
127 if(DEFAULT_NAME.equals(kwVals[n])) {
\r
128 errln("getKeywordValues for collation returned 'default' in the list.");
\r
129 } else if(STANDARD_NAME.equals(kwVals[n])) {
\r
130 if(foundStandard == false) {
\r
131 foundStandard = true;
\r
132 logln("found 'standard'");
\r
134 errln("Error - 'standard' is in the keyword list twice!");
\r
139 if(foundStandard == false) {
\r
140 errln("Error - 'standard' was not in the collation tree as a keyword.");
\r
142 logln("'standard' was found as a collation keyword.");
\r
146 public void TestOpen(){
\r
147 UResourceBundle bundle = (UResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME, "en_US_POSIX");
\r
149 errln("could not load the stream");
\r
153 private void getFunctionalEquivalentTestCases(String path, ClassLoader cl, String resName, String keyword,
\r
154 boolean truncate, String[] testCases) {
\r
155 //String F_STR = "f";
\r
156 String T_STR = "t";
\r
157 boolean isAvail[] = new boolean[1];
\r
159 logln("Testing functional equivalents...");
\r
160 for(int i = 0; i < testCases.length ;i+=3) {
\r
161 boolean expectAvail = T_STR.equals(testCases[i+0]);
\r
162 ULocale inLocale = new ULocale(testCases[i+1]);
\r
163 ULocale expectLocale = new ULocale(testCases[i+2]);
\r
165 logln(new Integer(i/3).toString() + ": " + new Boolean(expectAvail).toString() + "\t\t" +
\r
166 inLocale.toString() + "\t\t" + expectLocale.toString());
\r
168 ULocale equivLocale = ICUResourceBundle.getFunctionalEquivalent(path, cl, resName, keyword, inLocale, isAvail, truncate);
\r
169 boolean gotAvail = isAvail[0];
\r
171 if((gotAvail != expectAvail) || !equivLocale.equals(expectLocale)) {
\r
172 errln(new Integer(i/3).toString() + ": Error, expected Equiv=" + new Boolean(expectAvail).toString() + "\t\t" +
\r
173 inLocale.toString() + "\t\t--> " + expectLocale.toString() + ", but got " + new Boolean(gotAvail).toString() + " " +
\r
174 equivLocale.toString());
\r