2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import com
.sun
.star
.i18n
.CollatorOptions
;
21 import com
.sun
.star
.i18n
.XExtendedIndexEntrySupplier
;
22 import com
.sun
.star
.lang
.Locale
;
24 import java
.util
.HashMap
;
26 import lib
.MultiMethodTest
;
29 public class _XExtendedIndexEntrySupplier
extends MultiMethodTest
{
30 public XExtendedIndexEntrySupplier oObj
;
31 protected Locale
[] locales
= null;
32 protected HashMap
<Integer
, String
[]> algorithms
= new HashMap
<Integer
, String
[]>();
34 public void _compareIndexEntry() {
35 requiredMethod("getIndexKey()");
36 Locale locale
= new Locale("zh", "CN", "");
37 String val1
= new String(new char[]{UnicodeStringPair
.getUnicodeValue(0), UnicodeStringPair
.getUnicodeValue(1)});
38 String val2
= new String(new char[]{UnicodeStringPair
.getUnicodeValue(1), UnicodeStringPair
.getUnicodeValue(0)});
39 short result1
= oObj
.compareIndexEntry(val1
, "", locale
, val1
, "", locale
);
40 short result2
= oObj
.compareIndexEntry(val1
, "", locale
, val2
, "", locale
);
41 short result3
= oObj
.compareIndexEntry(val2
, "", locale
, val1
, "", locale
);
43 tRes
.tested("compareIndexEntry()", result1
== 0 && result2
+ result3
== 0);
47 * gets the list of all algorithms for each listed language
48 * is OK if everyone of the returned lists are filled
50 public void _getAlgorithmList() {
51 requiredMethod("getLocaleList()");
53 boolean result
= true;
55 for (int i
= 0; i
< locales
.length
; i
++) {
56 String
[] algNames
= oObj
.getAlgorithmList(locales
[i
]);
57 algorithms
.put(Integer
.valueOf(i
), algNames
);
59 boolean locResult
= algNames
.length
> 0;
60 System
.out
.println("Locale " + i
+ ": " + locales
[i
].Country
+","+locales
[i
].Language
);
62 for (int j
=0; j
<algNames
.length
; j
++) {
63 System
.out
.println("\tAlgorithm " + j
+ ": " + algNames
[j
]);
67 log
.println("No Algorithm found for " + locales
[i
].Country
+
68 "," + locales
[i
].Language
);
74 tRes
.tested("getAlgorithmList()", result
);
77 public void _getIndexKey() {
78 requiredMethod("loadAlgorithm()");
79 char[] characters
= new char[] { 19968 };
80 String getIndexFor
= new String(characters
);
81 for (int i
= 0; i
< locales
.length
; i
++) {
82 log
.println("Language: " + locales
[i
].Language
);
84 for (int j
= 0; j
< algorithms
.size(); j
++) {
85 String
[] algs
= algorithms
.get(Integer
.valueOf(j
));
86 for (int k
=0;k
<algs
.length
;k
++) {
87 log
.println("\t Algorithm :" +
89 oObj
.loadAlgorithm(locales
[i
], algs
[k
], CollatorOptions
.CollatorOptions_IGNORE_CASE
);
90 log
.println("\t\t Get: " +
91 oObj
.getIndexKey(getIndexFor
, "", locales
[i
]));
95 tRes
.tested("getIndexKey()", true);
99 * gets a list of all locales, is OK if this list isn't empty
101 public void _getLocaleList() {
102 locales
= oObj
.getLocaleList();
103 tRes
.tested("getLocaleList()", locales
.length
> 0);
107 * gets one phonetic candidate for the chinese local
108 * is ok if 'yi' is returned as expected.
110 public void _getPhoneticCandidate() {
111 requiredMethod("getLocaleList()");
115 Locale loc
= new Locale("zh", "CN", "");
117 for (int i
= 0;i
<UnicodeStringPair
.getValCount();i
++) {
119 char[] c
= new char[]{UnicodeStringPair
.getUnicodeValue(i
)};
121 String getting
= oObj
.getPhoneticCandidate(new String(c
), loc
);
123 boolean locResult
= getting
.equals(UnicodeStringPair
.getExpectedPhoneticString(i
));
126 log
.println("Char: "+ c
[0] + " (" + (int)c
[0] + ")");
127 log
.println("Expected " + UnicodeStringPair
.getExpectedPhoneticString(i
));
128 log
.println("Getting " + getting
);
133 tRes
.tested("getPhoneticCandidate()", res
);
137 * loads all algorithms available in all language.
138 * Is OK if no exception occurs and the method returns
139 * true for each valid algorithm and false otherwise
141 public void _loadAlgorithm() {
142 requiredMethod("getAlgorithmList()");
146 for (int i
= 0; i
< algorithms
.size(); i
++) {
147 String
[] names
= algorithms
.get(Integer
.valueOf(i
));
148 log
.println("loading algorithms for " + locales
[i
].Country
+
149 "," + locales
[i
].Language
);
151 for (int j
= 0; j
< names
.length
; j
++) {
152 log
.println("\t Loading " + names
[j
]);
154 boolean localres
= oObj
.loadAlgorithm(locales
[i
], names
[j
],
155 CollatorOptions
.CollatorOptions_IGNORE_CASE
);
158 log
.println("\t ... didn't work - FAILED");
160 log
.println("\t ... worked - OK");
167 tRes
.tested("loadAlgorithm()", res
);
171 * checks the method usePhoneticEntry(). Only the languages ja, ko and zh
172 * should return true. Has OK state if exactly this is the case.
174 public void _usePhoneticEntry() {
175 requiredMethod("getLocaleList()");
179 for (int i
= 0; i
< locales
.length
; i
++) {
180 boolean expected
= false;
182 if (locales
[i
].Language
.equals("ja") ||
183 locales
[i
].Language
.equals("ko") ||
184 locales
[i
].Language
.equals("zh")) {
188 boolean locResult
= oObj
.usePhoneticEntry(locales
[i
]) == expected
;
191 log
.println("Failure for language " + locales
[i
].Language
);
192 log
.println("Expected " + expected
);
193 log
.println("Getting " + oObj
.usePhoneticEntry(locales
[i
]));
199 tRes
.tested("usePhoneticEntry()", res
);
203 * Helper class to handle the phonetic equivalence of unicode characters
204 * This class delivers an amount of unicode characters and the equivalent phonetics
205 * for the "getPhoneticCandidate" test. Equivalents are only usable for zh,CN locale.
207 public static class UnicodeStringPair
{
208 static final int valCount
= 78;
209 static final String
[] sStringEquivalence
= new String
[valCount
];
210 static final char[] iUnicodeEquivalence
= new char[valCount
];
216 public static int getValCount() {
220 public static String
getExpectedPhoneticString(int index
) {
221 if (index
>= valCount
) return null;
222 return sStringEquivalence
[index
];
225 public static char getUnicodeValue(int index
) {
226 if (index
> valCount
) return 0;
227 return iUnicodeEquivalence
[index
];
230 private static void fillValues() {
231 iUnicodeEquivalence
[0] = 20049; sStringEquivalence
[0] = "zhong";
232 iUnicodeEquivalence
[1] = 19968; sStringEquivalence
[1] = "yi";
233 iUnicodeEquivalence
[2] = 19969; sStringEquivalence
[2] = "ding";
234 iUnicodeEquivalence
[3] = 19970; sStringEquivalence
[3] = "kao";
235 iUnicodeEquivalence
[4] = 19971; sStringEquivalence
[4] = "qi";
236 iUnicodeEquivalence
[5] = 19972; sStringEquivalence
[5] = "shang";
237 iUnicodeEquivalence
[6] = 19973; sStringEquivalence
[6] = "xia";
238 iUnicodeEquivalence
[7] = 19975; sStringEquivalence
[7] = "wan";
239 iUnicodeEquivalence
[8] = 19976; sStringEquivalence
[8] = "zhang";
240 iUnicodeEquivalence
[9] = 19977; sStringEquivalence
[9] = "san";
241 iUnicodeEquivalence
[10] = 19978; sStringEquivalence
[10] = "shang";
242 iUnicodeEquivalence
[11] = 19979; sStringEquivalence
[11] = "xia";
243 iUnicodeEquivalence
[12] = 19980; sStringEquivalence
[12] = "ji";
244 iUnicodeEquivalence
[13] = 19981; sStringEquivalence
[13] = "bu";
245 iUnicodeEquivalence
[14] = 19982; sStringEquivalence
[14] = "yu";
246 iUnicodeEquivalence
[15] = 19983; sStringEquivalence
[15] = "mian";
247 iUnicodeEquivalence
[16] = 19984; sStringEquivalence
[16] = "gai";
248 iUnicodeEquivalence
[17] = 19985; sStringEquivalence
[17] = "chou";
249 iUnicodeEquivalence
[18] = 19986; sStringEquivalence
[18] = "chou";
250 iUnicodeEquivalence
[19] = 19987; sStringEquivalence
[19] = "zhuan";
251 iUnicodeEquivalence
[20] = 19988; sStringEquivalence
[20] = "qie";
252 iUnicodeEquivalence
[21] = 19989; sStringEquivalence
[21] = "pi";
253 iUnicodeEquivalence
[22] = 19990; sStringEquivalence
[22] = "shi";
254 iUnicodeEquivalence
[23] = 19991; sStringEquivalence
[23] = "shi";
255 iUnicodeEquivalence
[24] = 19992; sStringEquivalence
[24] = "qiu";
256 iUnicodeEquivalence
[25] = 19993; sStringEquivalence
[25] = "bing";
257 iUnicodeEquivalence
[26] = 19994; sStringEquivalence
[26] = "ye";
258 iUnicodeEquivalence
[27] = 19995; sStringEquivalence
[27] = "cong";
259 iUnicodeEquivalence
[28] = 19996; sStringEquivalence
[28] = "dong";
260 iUnicodeEquivalence
[29] = 19997; sStringEquivalence
[29] = "si";
261 iUnicodeEquivalence
[30] = 19998; sStringEquivalence
[30] = "cheng";
262 iUnicodeEquivalence
[31] = 19999; sStringEquivalence
[31] = "diu";
263 iUnicodeEquivalence
[32] = 20000; sStringEquivalence
[32] = "qiu";
264 iUnicodeEquivalence
[33] = 20001; sStringEquivalence
[33] = "liang";
265 iUnicodeEquivalence
[34] = 20002; sStringEquivalence
[34] = "diu";
266 iUnicodeEquivalence
[35] = 20003; sStringEquivalence
[35] = "you";
267 iUnicodeEquivalence
[36] = 20004; sStringEquivalence
[36] = "liang";
268 iUnicodeEquivalence
[37] = 20005; sStringEquivalence
[37] = "yan";
269 iUnicodeEquivalence
[38] = 20006; sStringEquivalence
[38] = "bing";
270 iUnicodeEquivalence
[39] = 20007; sStringEquivalence
[39] = "sang";
271 iUnicodeEquivalence
[40] = 20008; sStringEquivalence
[40] = "shu";
272 iUnicodeEquivalence
[41] = 20009; sStringEquivalence
[41] = "jiu";
273 iUnicodeEquivalence
[42] = 20010; sStringEquivalence
[42] = "ge";
274 iUnicodeEquivalence
[43] = 20011; sStringEquivalence
[43] = "ya";
275 iUnicodeEquivalence
[44] = 20012; sStringEquivalence
[44] = "qiang";
276 iUnicodeEquivalence
[45] = 20013; sStringEquivalence
[45] = "zhong";
277 iUnicodeEquivalence
[46] = 20014; sStringEquivalence
[46] = "ji";
278 iUnicodeEquivalence
[47] = 20015; sStringEquivalence
[47] = "jie";
279 iUnicodeEquivalence
[48] = 20016; sStringEquivalence
[48] = "feng";
280 iUnicodeEquivalence
[49] = 20017; sStringEquivalence
[49] = "guan";
281 iUnicodeEquivalence
[50] = 20018; sStringEquivalence
[50] = "chuan";
282 iUnicodeEquivalence
[51] = 20019; sStringEquivalence
[51] = "chan";
283 iUnicodeEquivalence
[52] = 20020; sStringEquivalence
[52] = "lin";
284 iUnicodeEquivalence
[53] = 20021; sStringEquivalence
[53] = "zhuo";
285 iUnicodeEquivalence
[54] = 20022; sStringEquivalence
[54] = "zhu";
286 iUnicodeEquivalence
[55] = 20024; sStringEquivalence
[55] = "wan";
287 iUnicodeEquivalence
[56] = 20025; sStringEquivalence
[56] = "dan";
288 iUnicodeEquivalence
[57] = 20026; sStringEquivalence
[57] = "wei";
289 iUnicodeEquivalence
[58] = 20027; sStringEquivalence
[58] = "zhu";
290 iUnicodeEquivalence
[59] = 20028; sStringEquivalence
[59] = "jing";
291 iUnicodeEquivalence
[60] = 20029; sStringEquivalence
[60] = "li";
292 iUnicodeEquivalence
[61] = 20030; sStringEquivalence
[61] = "ju";
293 iUnicodeEquivalence
[62] = 20031; sStringEquivalence
[62] = "pie";
294 iUnicodeEquivalence
[63] = 20032; sStringEquivalence
[63] = "fu";
295 iUnicodeEquivalence
[64] = 20033; sStringEquivalence
[64] = "yi";
296 iUnicodeEquivalence
[65] = 20034; sStringEquivalence
[65] = "yi";
297 iUnicodeEquivalence
[66] = 20035; sStringEquivalence
[66] = "nai";
298 iUnicodeEquivalence
[67] = 20037; sStringEquivalence
[67] = "jiu";
299 iUnicodeEquivalence
[68] = 20038; sStringEquivalence
[68] = "jiu";
300 iUnicodeEquivalence
[69] = 20039; sStringEquivalence
[69] = "tuo";
301 iUnicodeEquivalence
[70] = 20040; sStringEquivalence
[70] = "me";
302 iUnicodeEquivalence
[71] = 20041; sStringEquivalence
[71] = "yi";
303 iUnicodeEquivalence
[72] = 20043; sStringEquivalence
[72] = "zhi";
304 iUnicodeEquivalence
[73] = 20044; sStringEquivalence
[73] = "wu";
305 iUnicodeEquivalence
[74] = 20045; sStringEquivalence
[74] = "zha";
306 iUnicodeEquivalence
[75] = 20046; sStringEquivalence
[75] = "hu";
307 iUnicodeEquivalence
[76] = 20047; sStringEquivalence
[76] = "fa";
308 iUnicodeEquivalence
[77] = 20048; sStringEquivalence
[77] = "le";