tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / i18n / _XTransliteration.java
blob49ee580d3b32228ccc21babcef01b669f87cd00a
1 /*
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 .
19 package ifc.i18n;
21 import lib.MultiMethodTest;
23 import com.sun.star.i18n.TransliterationModules;
24 import com.sun.star.i18n.TransliterationModulesNew;
25 import com.sun.star.i18n.TransliterationType;
26 import com.sun.star.i18n.XTransliteration;
27 import com.sun.star.lang.Locale;
29 /**
30 * Testing <code>com.sun.star.i18n.XTransliteration</code>
31 * interface methods :
32 * <ul>
33 * <li><code> getName()</code></li>
34 * <li><code> getType()</code></li>
35 * <li><code> loadModule()</code></li>
36 * <li><code> loadModuleNew()</code></li>
37 * <li><code> loadModuleByImplName()</code></li>
38 * <li><code> loadModulesByImplNames()</code></li>
39 * <li><code> getAvailableModules()</code></li>
40 * <li><code> transliterate()</code></li>
41 * <li><code> folding()</code></li>
42 * <li><code> equals()</code></li>
43 * <li><code> transliterateRange()</code></li>
44 * </ul> <p>
45 * Test is <b> NOT </b> multithread compliant. <p>
46 * @see com.sun.star.i18n.XTransliteration
48 public class _XTransliteration extends MultiMethodTest {
50 public XTransliteration oObj = null;
51 private final Locale loc = new Locale("en", "EN", "") ;
53 /**
54 * Gets all available transliteration modules. <p>
55 * Has <b>OK</b> status if array returned has at least
56 * one module name.
58 public void _getAvailableModules() {
59 String[] mod = oObj.getAvailableModules(loc, TransliterationType.ONE_TO_ONE);
61 if (mod != null) {
62 log.println("Available modules :") ;
63 for (int i = 0; i < mod.length; i++) {
64 log.println(" '" + mod[i] + "'") ;
66 } else {
67 log.println("!!! NULL returned !!!") ;
70 tRes.tested("getAvailableModules()", mod != null && mod.length > 0) ;
73 /**
74 * Calls the method for load IGNORE_CASE module and checks the name returned
75 * by the method <code>getName</code>. <p>
76 * Has <b>OK</b> status if the method <code>getName</code> returns the
77 * string "case ignore (generic)".
79 public void _loadModule() {
80 log.println("Load module IGNORE_CASE");
81 oObj.loadModule(TransliterationModules.IGNORE_CASE, loc);
83 String name = oObj.getName();
84 boolean res = name.equals("case ignore (generic)");
85 log.println("getName return: " + name);
87 tRes.tested("loadModule()", res );
90 /**
91 * Loads <code>LOWERCASE_UPPERCASE</code> module and checks the current
92 * name of object. <p>
94 * Has <b>OK</b> status if the name of the object is equals to
95 * 'lower_to_upper(generic)'
97 public void _loadModuleNew() {
98 boolean result = true ;
100 oObj.loadModuleNew(
101 new TransliterationModulesNew[]
102 {TransliterationModulesNew.LOWERCASE_UPPERCASE}, loc);
104 String name = oObj.getName();
105 result = name.equals("lower_to_upper(generic)");
106 log.println("getName return: " + name);
108 tRes.tested("loadModuleNew()", result);
112 * Calls the method for load LOWERCASE_UPPERCASE module and
113 * checks the name returned by the method <code>getName</code>. <p>
114 * Has <b>OK</b> status if the method <code>getName</code> returns the
115 * string "lower_to_upper(generic)".
117 public void _loadModuleByImplName() {
118 log.println("Load module LOWERCASE_UPPERCASE");
119 oObj.loadModuleByImplName("LOWERCASE_UPPERCASE", loc);
121 String name = oObj.getName();
122 boolean res = name.equals("lower_to_upper(generic)");
123 log.println("getName return: " + name);
125 tRes.tested("loadModuleByImplName()", res);
129 * Calls the method for load UPPERCASE_LOWERCASE module and
130 * checks the name returned by the method <code>getName</code>. <p>
131 * Has <b>OK</b> status if the method <code>getName</code> returns the
132 * string "upper_to_lower(generic)".
134 public void _loadModulesByImplNames() {
135 log.println("Load module UPPERCASE_LOWERCASE");
136 oObj.loadModulesByImplNames(new String[]{"UPPERCASE_LOWERCASE"}, loc);
138 String name = oObj.getName();
139 boolean res = name.equals("upper_to_lower(generic)");
140 log.println("getName return: " + name);
142 tRes.tested("loadModulesByImplNames()", res);
146 * Loads <code>LOWERCASE_UPPERCASE</code> module and checks current type.
147 * <p>Has <b>OK</b> status if the type is <code>ONE_TO_ONE</code>
149 public void _getType() {
150 oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc);
151 boolean result = oObj.getType() == TransliterationType.ONE_TO_ONE;
152 tRes.tested("getType()", result);
156 * Loads UPPERCASE_LOWERCASE module and
157 * checks the name returned by the method <code>getName</code>. <p>
159 * Has <b>OK</b> status if the method <code>getName</code> returns the
160 * string "upper_to_lower(generic)".
162 public void _getName() {
163 oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc);
165 String name = oObj.getName();
166 boolean res = name.equals("lower_to_upper(generic)");
167 log.println("getName return: " + name);
169 tRes.tested("getName()", res);
173 * First loads <code>LOWERCASE_UPPERCASE</code> module.
174 * Then tries to transliterate (make uppercase) a substring. <p>
175 * Has <b>OK</b> status if all chars were made uppercase,
176 * and array returned has size as substring length, and its
177 * elements are positions of substring characters in the source
178 * string.
180 public void _transliterate() {
181 oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc);
183 int[][] offs = new int[1][] ;
185 String out = oObj.transliterate("AaBbCc", 1, 4, offs) ;
187 boolean result = "ABBC".equals(out) && offs[0].length == 4 &&
188 offs[0][0] == 1 &&
189 offs[0][1] == 2 &&
190 offs[0][2] == 3 &&
191 offs[0][3] == 4 ;
193 tRes.tested("transliterate()", result) ;
198 * First loads <code>LOWERCASE_UPPERCASE</code> module.
199 * Tries to transliterate a range of two characters. <p>
200 * Has <b>OK</b> status if the appropriate String array
201 * returned (not null, length = 4, with two ranges
202 * (a, i), (A, I) in any order).
204 public void _transliterateRange() {
205 oObj.loadModule(TransliterationModules.IGNORE_CASE, loc);
207 String[] out = oObj.transliterateRange("a", "i") ;
209 log.println("transliterateRange return:");
210 for(int i = 0; i < out.length; i++) {
211 log.println(out[i]);
214 boolean bOK = out.length == 4 &&
215 ("A".equals(out[0]) && "I".equals(out[1]) &&
216 "a".equals(out[2]) && "i".equals(out[3])) ||
217 ("a".equals(out[0]) && "i".equals(out[1]) &&
218 "A".equals(out[2]) && "I".equals(out[3])) ;
220 if (!bOK) {
221 log.println("Unexpected range returned :");
222 for (int i = 0; i < out.length; i++) {
223 log.print("'" + out[i] +"', ");
225 log.println();
228 tRes.tested("transliterateRange()", bOK);
232 * This method is used internally by <code>equals</code>
233 * method so it indirectly tested in this method. <p>
234 * Always has <b>OK</b> status.
236 public void _folding() {
237 oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc);
239 int[][] offs = new int[1][] ;
241 String out = oObj.folding("AaBbCc", 1, 4, offs) ;
243 boolean result = "ABBC".equals(out) && offs[0].length == 4 &&
244 offs[0][0] == 1 &&
245 offs[0][1] == 2 &&
246 offs[0][2] == 3 &&
247 offs[0][3] == 4 ;
250 tRes.tested("folding()", result) ;
255 * First loads <code>LOWERCASE_UPPERCASE</code> module.
256 * Tries to compare two equal substrings. <p>
257 * Has <b>OK</b> status if the method returned <code>true</code>.
259 public void _equals() {
260 oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc);
262 int[] match1 = new int[1],
263 match2 = new int[1] ;
265 boolean res = oObj.equals("aAbBcC", 1, 3, match1, "aAbBcC", 1,
266 3, match2) ;
268 log.println("Returned : " + res + " Match1 = " + match1[0] +
269 " Match2 = " + match2[0]) ;
271 tRes.tested("equals()", res) ;
275 * Test performed for sets of equal substrings, not equal
276 * substrings, and without of bounds offset and length
277 * parameters.<p>
279 * Has <b>OK</b> status if comparings of equal substrings
280 * always return 0, if comparisons of none equal returns
281 * proper value according to lexicographical order and if
282 * comparisons with invalid parameters return none 0 value.
284 public void _compareSubstring() {
285 oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc);
286 boolean result = true ;
288 // substrings below must be equal
289 result &= testSubstring("", 0, 0, "", 0, 0, 0) ;
290 result &= testSubstring("aa", 1, 0, "", 0, 0, 0) ;
291 result &= testSubstring("aa", 1, 0, "aa", 2, 0, 0) ;
292 result &= testSubstring("a", 0, 1, "a", 0, 1, 0) ;
293 result &= testSubstring("ab", 0, 2, "ab", 0, 2, 0) ;
294 result &= testSubstring("abc", 1, 2, "abc", 1, 2, 0) ;
295 result &= testSubstring("abcdef", 0, 3, "123abc", 3, 3, 0) ;
296 result &= testSubstring("abcdef", 1, 1, "123abc", 4, 1, 0) ;
298 // substrings below must NOT be equal
299 result &= testSubstring("a", 0, 1, "a", 0, 0, 1) ;
300 result &= testSubstring("aaa", 1, 1, "", 0, 0, 1) ;
301 result &= testSubstring("bbb", 2, 1, "aaa", 2, 1, 1) ;
302 result &= testSubstring("abc", 0, 3, "abc", 0, 2, 1) ;
303 result &= testSubstring("bbc", 1, 2, "bbc", 0, 2, 1) ;
305 // testing with wrong offsets and lengths
307 tRes.tested("compareSubstring()", result) ;
311 * Performs tesing of two substrings. Also testing of opposite
312 * substrings order performed.
313 * @return <code>true</code> if substrings are equal and returned
314 * value is 0 for both orders,
315 * if substrings are different and expected value
316 * returned for direct order and opposite value returned for
317 * opposite order.
319 private boolean testSubstring(String str1, int p1, int len1,
320 String str2, int p2, int len2, int expRes) {
322 boolean ret = true ;
324 int res = oObj.compareSubstring(str1, p1, len1, str2, p2, len2);
326 if (res != expRes) {
327 log.print("Comparing FAILED; return: " + res + ", expected: " +
328 expRes + " ");
329 ret = false ;
330 } else {
331 log.print("Comparing OK : ");
333 log.println("('" + str1 + "', " + p1 + ", " + len1 + ", '" +
334 str2 + "', " + p2 + ", " + len2 + ")");
336 res = oObj.compareSubstring(str2, p2, len2, str1, p1, len1);
338 if (res != -expRes) {
339 log.print("Comparing FAILED; return: " + res + ", expected: " +
340 -expRes + " ");
341 ret = false ;
342 } else {
343 log.print("Comparing OK :");
345 log.println("('" + str2 + "', " + p2 + ", " + len2 + ", '" +
346 str1 + "', " + p1 + ", " + len1 + ")");
348 return ret ;
352 * Test performed for sets of equal strings and not equal
353 * strings.<p>
355 * Has <b>OK</b> status if comparings of equal strings
356 * always return 0 and if comparisons of none equal returns
357 * proper value according to lexicographical order .
359 public void _compareString() {
360 oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc);
361 boolean result = true ;
363 result &= testString("", "", 0) ;
364 result &= testString("a", "", 1) ;
365 result &= testString("a", "a", 0) ;
366 result &= testString("A", "a", 0) ;
367 result &= testString("b", "a", 1) ;
368 result &= testString("\n", "\n", 0) ;
369 result &= testString("\n", "\t", 1) ;
370 result &= testString("aaa", "aaa", 0) ;
371 result &= testString("aaA", "aaa", 0) ;
372 result &= testString("aaa", "aa", 1) ;
373 result &= testString("ab", "aaa", 1) ;
374 result &= testString("aba", "aa", 1) ;
375 result &= testString("aaa\t\na", "aaa\t\na", 0) ;
376 result &= testString("aaa\t\nb", "aaa\t\na", 1) ;
378 tRes.tested("compareString()", result) ;
382 * Performs tesing of two strings. If the expected value is not 0
383 * (i.e. strings are not equal), then also testing of opposite
384 * strings order performed.
385 * @return <code>true</code> if strings are equal and returned
386 * value is 0, if strings are different and expected value
387 * returned for direct order and opposite value returned for
388 * opposite order.
390 protected boolean testString(String str1, String str2, int expRes) {
391 if (expRes == 0) return testString(str1, str2, expRes, false) ;
392 return testString(str1, str2, expRes, true) ;
395 private boolean testString(String str1, String str2, int expRes,
396 boolean testReverse) {
398 boolean ret = true ;
400 int res = oObj.compareString(str1, str2);
402 if (res == expRes) {
403 log.println("Comparing of '" + str1 + "' and '" + str2 + "' OK" );
404 } else {
405 log.println("Comparing of '" + str1 + "' and '" + str2 +
406 "' FAILED; return: " + res + ", expected: " + expRes);
407 ret = false ;
410 if (!testReverse) return ret ;
412 res = oObj.compareString(str2, str1);
414 if (res == -expRes) {
415 log.println("Comparing of '" + str2 + "' and '" + str1 + "' OK" );
416 } else {
417 log.println("Comparing of '" + str2 + "' and '" + str1 +
418 "' FAILED; return: " + res + ", expected: " + -expRes);
419 ret = false ;
422 return ret ;