1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package ifc.i18n; 28 29 import com.sun.star.i18n.CollatorOptions; 30 import com.sun.star.i18n.XExtendedIndexEntrySupplier; 31 import com.sun.star.lang.Locale; 32 33 import java.util.HashMap; 34 35 import lib.MultiMethodTest; 36 37 38 public class _XExtendedIndexEntrySupplier extends MultiMethodTest { 39 public XExtendedIndexEntrySupplier oObj; 40 protected Locale[] locales = null; 41 protected HashMap algorithms = new HashMap(); 42 43 public void _compareIndexEntry() { 44 requiredMethod("getIndexKey()"); 45 Locale locale = new Locale("zh", "CN", ""); 46 String val1 = new String(new char[]{UnicodeStringPair.getUnicodeValue(0), UnicodeStringPair.getUnicodeValue(1)}); 47 String val2 = new String(new char[]{UnicodeStringPair.getUnicodeValue(1), UnicodeStringPair.getUnicodeValue(0)}); 48 short result1 = oObj.compareIndexEntry(val1, "", locale, val1, "", locale); 49 short result2 = oObj.compareIndexEntry(val1, "", locale, val2, "", locale); 50 short result3 = oObj.compareIndexEntry(val2, "", locale, val1, "", locale); 51 52 tRes.tested("compareIndexEntry()", result1 == 0 && result2 + result3 == 0); 53 } 54 55 /* 56 * gets the list of all algorithms for each listed language 57 * is OK if everyone of the returned lists are filled 58 */ 59 public void _getAlgorithmList() { 60 requiredMethod("getLocaleList()"); 61 62 boolean result = true; 63 boolean locResult = false; 64 65 for (int i = 0; i < locales.length; i++) { 66 String[] algNames = oObj.getAlgorithmList(locales[i]); 67 algorithms.put(new Integer(i), algNames); 68 69 locResult = algNames != null && algNames.length > 0; 70 System.out.println("Locale " + i + ": " + locales[i].Country+","+locales[i].Language); 71 72 for (int j=0; j<algNames.length; j++) { 73 System.out.println("\tAlgorithm " + j + ": " + algNames[j]); 74 } 75 76 if (!locResult) { 77 log.println("No Algorithm found for " + locales[i].Country + 78 "," + locales[i].Language); 79 } 80 81 result &= locResult; 82 } 83 84 tRes.tested("getAlgorithmList()", result); 85 } 86 87 public void _getIndexKey() { 88 requiredMethod("loadAlgorithm()"); 89 char[] characters = new char[] { 19968 }; 90 String getIndexFor = new String(characters); 91 for (int i = 0; i < locales.length; i++) { 92 log.println("Language: " + locales[i].Language); 93 94 for (int j = 0; j < algorithms.size(); j++) { 95 String[] algs = (String[])algorithms.get(new Integer(j)); 96 for (int k=0;k<algs.length;k++) { 97 log.println("\t Algorythm :" + 98 algs[k]); 99 oObj.loadAlgorithm(locales[i], algs[k], CollatorOptions.CollatorOptions_IGNORE_CASE); 100 log.println("\t\t Get: " + 101 oObj.getIndexKey(getIndexFor, "", locales[i])); 102 } 103 } 104 } 105 tRes.tested("getIndexKey()", true); 106 } 107 108 /* 109 * gets a list of all locales, is OK if this list isn't empty 110 */ 111 public void _getLocaleList() { 112 locales = oObj.getLocaleList(); 113 tRes.tested("getLocaleList()", locales.length > 0); 114 } 115 116 /* 117 * gets one phonetic canidate for the chinese local 118 * is ok if 'yi' is returned as expected. 119 */ 120 public void _getPhoneticCandidate() { 121 requiredMethod("getLocaleList()"); 122 123 boolean res = true; 124 125 Locale loc = new Locale("zh", "CN", ""); 126 127 for (int i = 0;i<UnicodeStringPair.getValCount();i++) { 128 129 char[] c = new char[]{UnicodeStringPair.getUnicodeValue(i)}; 130 131 String getting = oObj.getPhoneticCandidate(new String(c), loc); 132 133 boolean locResult = getting.equals(UnicodeStringPair.getExpectedPhoneticString(i)); 134 135 if (!locResult) { 136 log.println("Char: "+ c[0] + " (" + (int)c[0] + ")"); 137 log.println("Expected " + UnicodeStringPair.getExpectedPhoneticString(i)); 138 log.println("Getting " + getting); 139 } 140 141 res &= locResult; 142 } 143 tRes.tested("getPhoneticCandidate()", res); 144 } 145 146 /* 147 * loads all algorithms available in all language. 148 * Is OK if no exception occurs and the method returns 149 * true for each valid algorithm and false otherwise 150 */ 151 public void _loadAlgorithm() { 152 requiredMethod("getAlgorithmList()"); 153 154 boolean res = true; 155 156 for (int i = 0; i < algorithms.size(); i++) { 157 String[] names = (String[]) algorithms.get(new Integer(i)); 158 log.println("loading algorithms for " + locales[i].Country + 159 "," + locales[i].Language); 160 161 for (int j = 0; j < names.length; j++) { 162 log.println("\t Loading " + names[j]); 163 164 boolean localres = oObj.loadAlgorithm(locales[i], names[j], 165 CollatorOptions.CollatorOptions_IGNORE_CASE); 166 167 if (!localres) { 168 log.println("\t ... didn't work - FAILED"); 169 } else { 170 log.println("\t ... worked - OK"); 171 } 172 173 res &= localres; 174 } 175 176 /* log.println("\tTrying to load 'dummy' algorithm"); 177 178 boolean localres = !oObj.loadAlgorithm(locales[i], "dummy", 179 CollatorOptions.CollatorOptions_IGNORE_WIDTH); 180 181 if (!localres) { 182 log.println("\t ... didn't work as expected - FAILED"); 183 } else { 184 log.println("\t ... worked - OK"); 185 } 186 187 res &= localres;*/ 188 } 189 190 tRes.tested("loadAlgorithm()", res); 191 } 192 193 /* 194 * checks the method usePhoneticEntry(). Only the languages ja, ko and zh 195 * should return true. Has OK state if exactly this is the case. 196 */ 197 public void _usePhoneticEntry() { 198 requiredMethod("getLocaleList()"); 199 200 boolean res = true; 201 202 for (int i = 0; i < locales.length; i++) { 203 boolean expected = false; 204 205 if (locales[i].Language.equals("ja") || 206 locales[i].Language.equals("ko") || 207 locales[i].Language.equals("zh")) { 208 expected = true; 209 } 210 211 boolean locResult = oObj.usePhoneticEntry(locales[i]) == expected; 212 213 if (!locResult) { 214 log.println("Failure for language " + locales[i].Language); 215 log.println("Expected " + expected); 216 log.println("Getting " + oObj.usePhoneticEntry(locales[i])); 217 } 218 219 res &= locResult; 220 } 221 222 tRes.tested("usePhoneticEntry()", res); 223 } 224 225 /** 226 * Helper class to handle the phonetic equivalence of unicode characters 227 * This class delivers an amount oif unicode characters and the equivalent phonetics 228 * for the "getPhoneticCandidate" test. Euivalents are only usable for zh,CN locale. 229 */ 230 public static class UnicodeStringPair { 231 final static int valCount = 78; 232 static String[] sStringEquivalence = null; 233 static char[] iUnicodeEquivalence = null; 234 235 static { 236 sStringEquivalence = new String[valCount]; 237 iUnicodeEquivalence = new char[valCount]; 238 fillValues(); 239 } 240 241 public static int getValCount() { 242 return valCount; 243 } 244 245 public static String getExpectedPhoneticString(int index) { 246 if (index >= valCount) return null; 247 return sStringEquivalence[index]; 248 } 249 250 public static char getUnicodeValue(int index) { 251 if (index > valCount) return 0; 252 return iUnicodeEquivalence[index]; 253 } 254 255 private static void fillValues() { 256 iUnicodeEquivalence[0] = 20049; sStringEquivalence[0] = "zhong"; 257 iUnicodeEquivalence[1] = 19968; sStringEquivalence[1] = "yi"; 258 iUnicodeEquivalence[2] = 19969; sStringEquivalence[2] = "ding"; 259 iUnicodeEquivalence[3] = 19970; sStringEquivalence[3] = "kao"; 260 iUnicodeEquivalence[4] = 19971; sStringEquivalence[4] = "qi"; 261 iUnicodeEquivalence[5] = 19972; sStringEquivalence[5] = "shang"; 262 iUnicodeEquivalence[6] = 19973; sStringEquivalence[6] = "xia"; 263 iUnicodeEquivalence[7] = 19975; sStringEquivalence[7] = "wan"; 264 iUnicodeEquivalence[8] = 19976; sStringEquivalence[8] = "zhang"; 265 iUnicodeEquivalence[9] = 19977; sStringEquivalence[9] = "san"; 266 iUnicodeEquivalence[10] = 19978; sStringEquivalence[10] = "shang"; 267 iUnicodeEquivalence[11] = 19979; sStringEquivalence[11] = "xia"; 268 iUnicodeEquivalence[12] = 19980; sStringEquivalence[12] = "ji"; 269 iUnicodeEquivalence[13] = 19981; sStringEquivalence[13] = "bu"; 270 iUnicodeEquivalence[14] = 19982; sStringEquivalence[14] = "yu"; 271 iUnicodeEquivalence[15] = 19983; sStringEquivalence[15] = "mian"; 272 iUnicodeEquivalence[16] = 19984; sStringEquivalence[16] = "gai"; 273 iUnicodeEquivalence[17] = 19985; sStringEquivalence[17] = "chou"; 274 iUnicodeEquivalence[18] = 19986; sStringEquivalence[18] = "chou"; 275 iUnicodeEquivalence[19] = 19987; sStringEquivalence[19] = "zhuan"; 276 iUnicodeEquivalence[20] = 19988; sStringEquivalence[20] = "qie"; 277 iUnicodeEquivalence[21] = 19989; sStringEquivalence[21] = "pi"; 278 iUnicodeEquivalence[22] = 19990; sStringEquivalence[22] = "shi"; 279 iUnicodeEquivalence[23] = 19991; sStringEquivalence[23] = "shi"; 280 iUnicodeEquivalence[24] = 19992; sStringEquivalence[24] = "qiu"; 281 iUnicodeEquivalence[25] = 19993; sStringEquivalence[25] = "bing"; 282 iUnicodeEquivalence[26] = 19994; sStringEquivalence[26] = "ye"; 283 iUnicodeEquivalence[27] = 19995; sStringEquivalence[27] = "cong"; 284 iUnicodeEquivalence[28] = 19996; sStringEquivalence[28] = "dong"; 285 iUnicodeEquivalence[29] = 19997; sStringEquivalence[29] = "si"; 286 iUnicodeEquivalence[30] = 19998; sStringEquivalence[30] = "cheng"; 287 iUnicodeEquivalence[31] = 19999; sStringEquivalence[31] = "diu"; 288 iUnicodeEquivalence[32] = 20000; sStringEquivalence[32] = "qiu"; 289 iUnicodeEquivalence[33] = 20001; sStringEquivalence[33] = "liang"; 290 iUnicodeEquivalence[34] = 20002; sStringEquivalence[34] = "diu"; 291 iUnicodeEquivalence[35] = 20003; sStringEquivalence[35] = "you"; 292 iUnicodeEquivalence[36] = 20004; sStringEquivalence[36] = "liang"; 293 iUnicodeEquivalence[37] = 20005; sStringEquivalence[37] = "yan"; 294 iUnicodeEquivalence[38] = 20006; sStringEquivalence[38] = "bing"; 295 iUnicodeEquivalence[39] = 20007; sStringEquivalence[39] = "sang"; 296 iUnicodeEquivalence[40] = 20008; sStringEquivalence[40] = "shu"; 297 iUnicodeEquivalence[41] = 20009; sStringEquivalence[41] = "jiu"; 298 iUnicodeEquivalence[42] = 20010; sStringEquivalence[42] = "ge"; 299 iUnicodeEquivalence[43] = 20011; sStringEquivalence[43] = "ya"; 300 iUnicodeEquivalence[44] = 20012; sStringEquivalence[44] = "qiang"; 301 iUnicodeEquivalence[45] = 20013; sStringEquivalence[45] = "zhong"; 302 iUnicodeEquivalence[46] = 20014; sStringEquivalence[46] = "ji"; 303 iUnicodeEquivalence[47] = 20015; sStringEquivalence[47] = "jie"; 304 iUnicodeEquivalence[48] = 20016; sStringEquivalence[48] = "feng"; 305 iUnicodeEquivalence[49] = 20017; sStringEquivalence[49] = "guan"; 306 iUnicodeEquivalence[50] = 20018; sStringEquivalence[50] = "chuan"; 307 iUnicodeEquivalence[51] = 20019; sStringEquivalence[51] = "chan"; 308 iUnicodeEquivalence[52] = 20020; sStringEquivalence[52] = "lin"; 309 iUnicodeEquivalence[53] = 20021; sStringEquivalence[53] = "zhuo"; 310 iUnicodeEquivalence[54] = 20022; sStringEquivalence[54] = "zhu"; 311 iUnicodeEquivalence[55] = 20024; sStringEquivalence[55] = "wan"; 312 iUnicodeEquivalence[56] = 20025; sStringEquivalence[56] = "dan"; 313 iUnicodeEquivalence[57] = 20026; sStringEquivalence[57] = "wei"; 314 iUnicodeEquivalence[58] = 20027; sStringEquivalence[58] = "zhu"; 315 iUnicodeEquivalence[59] = 20028; sStringEquivalence[59] = "jing"; 316 iUnicodeEquivalence[60] = 20029; sStringEquivalence[60] = "li"; 317 iUnicodeEquivalence[61] = 20030; sStringEquivalence[61] = "ju"; 318 iUnicodeEquivalence[62] = 20031; sStringEquivalence[62] = "pie"; 319 iUnicodeEquivalence[63] = 20032; sStringEquivalence[63] = "fu"; 320 iUnicodeEquivalence[64] = 20033; sStringEquivalence[64] = "yi"; 321 iUnicodeEquivalence[65] = 20034; sStringEquivalence[65] = "yi"; 322 iUnicodeEquivalence[66] = 20035; sStringEquivalence[66] = "nai"; 323 iUnicodeEquivalence[67] = 20037; sStringEquivalence[67] = "jiu"; 324 iUnicodeEquivalence[68] = 20038; sStringEquivalence[68] = "jiu"; 325 iUnicodeEquivalence[69] = 20039; sStringEquivalence[69] = "tuo"; 326 iUnicodeEquivalence[70] = 20040; sStringEquivalence[70] = "me"; 327 iUnicodeEquivalence[71] = 20041; sStringEquivalence[71] = "yi"; 328 iUnicodeEquivalence[72] = 20043; sStringEquivalence[72] = "zhi"; 329 iUnicodeEquivalence[73] = 20044; sStringEquivalence[73] = "wu"; 330 iUnicodeEquivalence[74] = 20045; sStringEquivalence[74] = "zha"; 331 iUnicodeEquivalence[75] = 20046; sStringEquivalence[75] = "hu"; 332 iUnicodeEquivalence[76] = 20047; sStringEquivalence[76] = "fa"; 333 iUnicodeEquivalence[77] = 20048; sStringEquivalence[77] = "le"; 334 } 335 } 336 } 337