/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
public XTransliteration oObj = null; privatefinal Locale loc = new Locale("en", "EN", "") ;
/** * Gets all available transliteration modules. <p> * Has <b>OK</b> status if array returned has at least * one module name.
*/ publicvoid _getAvailableModules() {
String[] mod = oObj.getAvailableModules(loc, TransliterationType.ONE_TO_ONE);
if (mod != null) {
log.println("Available modules :") ; for (int i = 0; i < mod.length; i++) {
log.println(" '" + mod[i] + "'") ;
}
} else {
log.println("!!! NULL returned !!!") ;
}
tRes.tested("getAvailableModules()", mod != null && mod.length > 0) ;
}
/** * Calls the method for load IGNORE_CASE module and checks the name returned * by the method <code>getName</code>. <p> * Has <b>OK</b> status if the method <code>getName</code> returns the * string "case ignore (generic)".
*/ publicvoid _loadModule() {
log.println("Load module IGNORE_CASE");
oObj.loadModule(TransliterationModules.IGNORE_CASE, loc);
String name = oObj.getName(); boolean res = name.equals("case ignore (generic)");
log.println("getName return: " + name);
tRes.tested("loadModule()", res );
}
/** * Loads <code>LOWERCASE_UPPERCASE</code> module and checks the current * name of object. <p> * * Has <b>OK</b> status if the name of the object is equals to * 'lower_to_upper(generic)'
*/ publicvoid _loadModuleNew() { boolean result = true ;
oObj.loadModuleNew( new TransliterationModulesNew[]
{TransliterationModulesNew.LOWERCASE_UPPERCASE}, loc);
String name = oObj.getName();
result = name.equals("lower_to_upper(generic)");
log.println("getName return: " + name);
tRes.tested("loadModuleNew()", result);
}
/** * Calls the method for load LOWERCASE_UPPERCASE module and * checks the name returned by the method <code>getName</code>. <p> * Has <b>OK</b> status if the method <code>getName</code> returns the * string "lower_to_upper(generic)".
*/ publicvoid _loadModuleByImplName() {
log.println("Load module LOWERCASE_UPPERCASE");
oObj.loadModuleByImplName("LOWERCASE_UPPERCASE", loc);
String name = oObj.getName(); boolean res = name.equals("lower_to_upper(generic)");
log.println("getName return: " + name);
tRes.tested("loadModuleByImplName()", res);
}
/** * Calls the method for load UPPERCASE_LOWERCASE module and * checks the name returned by the method <code>getName</code>. <p> * Has <b>OK</b> status if the method <code>getName</code> returns the * string "upper_to_lower(generic)".
*/ publicvoid _loadModulesByImplNames() {
log.println("Load module UPPERCASE_LOWERCASE");
oObj.loadModulesByImplNames(new String[]{"UPPERCASE_LOWERCASE"}, loc);
String name = oObj.getName(); boolean res = name.equals("upper_to_lower(generic)");
log.println("getName return: " + name);
tRes.tested("loadModulesByImplNames()", res);
}
/** * Loads <code>LOWERCASE_UPPERCASE</code> module and checks current type. * <p>Has <b>OK</b> status if the type is <code>ONE_TO_ONE</code>
*/ publicvoid _getType() {
oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc); boolean result = oObj.getType() == TransliterationType.ONE_TO_ONE;
tRes.tested("getType()", result);
}
/** * Loads UPPERCASE_LOWERCASE module and * checks the name returned by the method <code>getName</code>. <p> * * Has <b>OK</b> status if the method <code>getName</code> returns the * string "upper_to_lower(generic)".
*/ publicvoid _getName() {
oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc);
String name = oObj.getName(); boolean res = name.equals("lower_to_upper(generic)");
log.println("getName return: " + name);
tRes.tested("getName()", res);
}
/** * First loads <code>LOWERCASE_UPPERCASE</code> module. * Then tries to transliterate (make uppercase) a substring. <p> * Has <b>OK</b> status if all chars were made uppercase, * and array returned has size as substring length, and its * elements are positions of substring characters in the source * string.
*/ publicvoid _transliterate() {
oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc);
int[][] offs = newint[1][] ;
String out = oObj.transliterate("AaBbCc", 1, 4, offs) ;
/** * First loads <code>LOWERCASE_UPPERCASE</code> module. * Tries to transliterate a range of two characters. <p> * Has <b>OK</b> status if the appropriate String array * returned (not null, length = 4, with two ranges * (a, i), (A, I) in any order).
*/ publicvoid _transliterateRange() {
oObj.loadModule(TransliterationModules.IGNORE_CASE, loc);
String[] out = oObj.transliterateRange("a", "i") ;
log.println("transliterateRange return:"); for(int i = 0; i < out.length; i++) {
log.println(out[i]);
}
if (!bOK) {
log.println("Unexpected range returned :"); for (int i = 0; i < out.length; i++) {
log.print("'" + out[i] +"', ");
}
log.println();
}
tRes.tested("transliterateRange()", bOK);
}
/** * This method is used internally by <code>equals</code> * method so it indirectly tested in this method. <p> * Always has <b>OK</b> status.
*/ publicvoid _folding() {
oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc);
/** * First loads <code>LOWERCASE_UPPERCASE</code> module. * Tries to compare two equal substrings. <p> * Has <b>OK</b> status if the method returned <code>true</code>.
*/ publicvoid _equals() {
oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc);
/** * Test performed for sets of equal substrings, not equal * substrings, and without of bounds offset and length * parameters.<p> * * Has <b>OK</b> status if comparings of equal substrings * always return 0, if comparisons of none equal returns * proper value according to lexicographical order and if * comparisons with invalid parameters return none 0 value.
*/ publicvoid _compareSubstring() {
oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc); boolean result = true ;
// substrings below must be equal
result &= testSubstring("", 0, 0, "", 0, 0, 0) ;
result &= testSubstring("aa", 1, 0, "", 0, 0, 0) ;
result &= testSubstring("aa", 1, 0, "aa", 2, 0, 0) ;
result &= testSubstring("a", 0, 1, "a", 0, 1, 0) ;
result &= testSubstring("ab", 0, 2, "ab", 0, 2, 0) ;
result &= testSubstring("abc", 1, 2, "abc", 1, 2, 0) ;
result &= testSubstring("abcdef", 0, 3, "123abc", 3, 3, 0) ;
result &= testSubstring("abcdef", 1, 1, "123abc", 4, 1, 0) ;
// substrings below must NOT be equal
result &= testSubstring("a", 0, 1, "a", 0, 0, 1) ;
result &= testSubstring("aaa", 1, 1, "", 0, 0, 1) ;
result &= testSubstring("bbb", 2, 1, "aaa", 2, 1, 1) ;
result &= testSubstring("abc", 0, 3, "abc", 0, 2, 1) ;
result &= testSubstring("bbc", 1, 2, "bbc", 0, 2, 1) ;
// testing with wrong offsets and lengths
tRes.tested("compareSubstring()", result) ;
}
/** * Performs tesing of two substrings. Also testing of opposite * substrings order performed. * @return <code>true</code> if substrings are equal and returned * value is 0 for both orders, * if substrings are different and expected value * returned for direct order and opposite value returned for * opposite order.
*/ privateboolean testSubstring(String str1, int p1, int len1,
String str2, int p2, int len2, int expRes) {
boolean ret = true ;
int res = oObj.compareSubstring(str1, p1, len1, str2, p2, len2);
/** * Test performed for sets of equal strings and not equal * strings.<p> * * Has <b>OK</b> status if comparings of equal strings * always return 0 and if comparisons of none equal returns * proper value according to lexicographical order .
*/ publicvoid _compareString() {
oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc); boolean result = true ;
result &= testString("", "", 0) ;
result &= testString("a", "", 1) ;
result &= testString("a", "a", 0) ;
result &= testString("A", "a", 0) ;
result &= testString("b", "a", 1) ;
result &= testString("\n", "\n", 0) ;
result &= testString("\n", "\t", 1) ;
result &= testString("aaa", "aaa", 0) ;
result &= testString("aaA", "aaa", 0) ;
result &= testString("aaa", "aa", 1) ;
result &= testString("ab", "aaa", 1) ;
result &= testString("aba", "aa", 1) ;
result &= testString("aaa\t\na", "aaa\t\na", 0) ;
result &= testString("aaa\t\nb", "aaa\t\na", 1) ;
tRes.tested("compareString()", result) ;
}
/** * Performs tesing of two strings. If the expected value is not 0 * (i.e. strings are not equal), then also testing of opposite * strings order performed. * @return <code>true</code> if strings are equal and returned * value is 0, if strings are different and expected value * returned for direct order and opposite value returned for * opposite order.
*/ protectedboolean testString(String str1, String str2, int expRes) { if (expRes == 0) return testString(str1, str2, expRes, false) ; return testString(str1, str2, expRes, true) ;
}
privateboolean testString(String str1, String str2, int expRes, boolean testReverse) {
boolean ret = true ;
int res = oObj.compareString(str1, str2);
if (res == expRes) {
log.println("Comparing of '" + str1 + "' and '" + str2 + "' OK" );
} else {
log.println("Comparing of '" + str1 + "' and '" + str2 + "' FAILED; return: " + res + ", expected: " + expRes);
ret = false ;
}
if (!testReverse) return ret ;
res = oObj.compareString(str2, str1);
if (res == -expRes) {
log.println("Comparing of '" + str2 + "' and '" + str1 + "' OK" );
} else {
log.println("Comparing of '" + str2 + "' and '" + str1 + "' FAILED; return: " + res + ", expected: " + -expRes);
ret = false ;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.