1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package ifc.i18n; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import lib.MultiMethodTest; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir import com.sun.star.i18n.TransliterationModules; 33*cdf0e10cSrcweir import com.sun.star.i18n.TransliterationModulesNew; 34*cdf0e10cSrcweir import com.sun.star.i18n.TransliterationType; 35*cdf0e10cSrcweir import com.sun.star.i18n.XTransliteration; 36*cdf0e10cSrcweir import com.sun.star.lang.Locale; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir /** 39*cdf0e10cSrcweir * Testing <code>com.sun.star.i18n.XTransliteration</code> 40*cdf0e10cSrcweir * interface methods : 41*cdf0e10cSrcweir * <ul> 42*cdf0e10cSrcweir * <li><code> getName()</code></li> 43*cdf0e10cSrcweir * <li><code> getType()</code></li> 44*cdf0e10cSrcweir * <li><code> loadModule()</code></li> 45*cdf0e10cSrcweir * <li><code> loadModuleNew()</code></li> 46*cdf0e10cSrcweir * <li><code> loadModuleByImplName()</code></li> 47*cdf0e10cSrcweir * <li><code> loadModulesByImplNames()</code></li> 48*cdf0e10cSrcweir * <li><code> getAvailableModules()</code></li> 49*cdf0e10cSrcweir * <li><code> transliterate()</code></li> 50*cdf0e10cSrcweir * <li><code> folding()</code></li> 51*cdf0e10cSrcweir * <li><code> equals()</code></li> 52*cdf0e10cSrcweir * <li><code> transliterateRange()</code></li> 53*cdf0e10cSrcweir * </ul> <p> 54*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 55*cdf0e10cSrcweir * @see com.sun.star.i18n.XTransliteration 56*cdf0e10cSrcweir */ 57*cdf0e10cSrcweir public class _XTransliteration extends MultiMethodTest { 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir public XTransliteration oObj = null; 60*cdf0e10cSrcweir private String[] mod = null ; 61*cdf0e10cSrcweir private Locale loc = new Locale("en", "EN", "") ; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir /** 64*cdf0e10cSrcweir * Gets all available transliteration modules. <p> 65*cdf0e10cSrcweir * Has <b>OK</b> status if array returned has at least 66*cdf0e10cSrcweir * one module name. 67*cdf0e10cSrcweir */ 68*cdf0e10cSrcweir public void _getAvailableModules() { 69*cdf0e10cSrcweir mod = oObj.getAvailableModules(loc, TransliterationType.ONE_TO_ONE); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir if (mod != null) { 72*cdf0e10cSrcweir log.println("Available modules :") ; 73*cdf0e10cSrcweir for (int i = 0; i < mod.length; i++) { 74*cdf0e10cSrcweir log.println(" '" + mod[i] + "'") ; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir } else { 77*cdf0e10cSrcweir log.println("!!! NULL returned !!!") ; 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir tRes.tested("getAvailableModules()", mod != null && mod.length > 0) ; 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir /** 84*cdf0e10cSrcweir * Calls the method for load IGNORE_CASE module and checks the name returned 85*cdf0e10cSrcweir * by the method <code>getName</code>. <p> 86*cdf0e10cSrcweir * Has <b>OK</b> status if the method <code>getName</code> returns the 87*cdf0e10cSrcweir * string "case ignore (generic)". 88*cdf0e10cSrcweir */ 89*cdf0e10cSrcweir public void _loadModule() { 90*cdf0e10cSrcweir log.println("Load module IGNORE_CASE"); 91*cdf0e10cSrcweir oObj.loadModule(TransliterationModules.IGNORE_CASE, loc); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir String name = oObj.getName(); 94*cdf0e10cSrcweir boolean res = name.equals("case ignore (generic)"); 95*cdf0e10cSrcweir log.println("getName return: " + name); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir tRes.tested("loadModule()", res ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir /** 101*cdf0e10cSrcweir * Loads <code>LOWERCASE_UPPERCASE</code> module and checks the current 102*cdf0e10cSrcweir * name of object. <p> 103*cdf0e10cSrcweir * 104*cdf0e10cSrcweir * Has <b>OK</b> status if the name of the object is equals to 105*cdf0e10cSrcweir * 'lower_to_upper(generic)' 106*cdf0e10cSrcweir */ 107*cdf0e10cSrcweir public void _loadModuleNew() { 108*cdf0e10cSrcweir boolean result = true ; 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir oObj.loadModuleNew( 111*cdf0e10cSrcweir new TransliterationModulesNew[] 112*cdf0e10cSrcweir {TransliterationModulesNew.LOWERCASE_UPPERCASE}, loc); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir String name = oObj.getName(); 115*cdf0e10cSrcweir result = name.equals("lower_to_upper(generic)"); 116*cdf0e10cSrcweir log.println("getName return: " + name); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir tRes.tested("loadModuleNew()", result); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir /** 122*cdf0e10cSrcweir * Calls the method for load LOWERCASE_UPPERCASE module and 123*cdf0e10cSrcweir * checks the name returned by the method <code>getName</code>. <p> 124*cdf0e10cSrcweir * Has <b>OK</b> status if the method <code>getName</code> returns the 125*cdf0e10cSrcweir * string "lower_to_upper(generic)". 126*cdf0e10cSrcweir */ 127*cdf0e10cSrcweir public void _loadModuleByImplName() { 128*cdf0e10cSrcweir log.println("Load module LOWERCASE_UPPERCASE"); 129*cdf0e10cSrcweir oObj.loadModuleByImplName("LOWERCASE_UPPERCASE", loc); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir String name = oObj.getName(); 132*cdf0e10cSrcweir boolean res = name.equals("lower_to_upper(generic)"); 133*cdf0e10cSrcweir log.println("getName return: " + name); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir tRes.tested("loadModuleByImplName()", res); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir /** 139*cdf0e10cSrcweir * Calls the method for load UPPERCASE_LOWERCASE module and 140*cdf0e10cSrcweir * checks the name returned by the method <code>getName</code>. <p> 141*cdf0e10cSrcweir * Has <b>OK</b> status if the method <code>getName</code> returns the 142*cdf0e10cSrcweir * string "upper_to_lower(generic)". 143*cdf0e10cSrcweir */ 144*cdf0e10cSrcweir public void _loadModulesByImplNames() { 145*cdf0e10cSrcweir log.println("Load module UPPERCASE_LOWERCASE"); 146*cdf0e10cSrcweir oObj.loadModulesByImplNames(new String[]{"UPPERCASE_LOWERCASE"}, loc); 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir String name = oObj.getName(); 149*cdf0e10cSrcweir boolean res = name.equals("upper_to_lower(generic)"); 150*cdf0e10cSrcweir log.println("getName return: " + name); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir tRes.tested("loadModulesByImplNames()", res); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir /** 156*cdf0e10cSrcweir * Loads <code>LOWERCASE_UPPERCASE</code> module and checks current type. 157*cdf0e10cSrcweir * <p>Has <b>OK</b> status if the type is <code>ONE_TO_ONE</code> 158*cdf0e10cSrcweir */ 159*cdf0e10cSrcweir public void _getType() { 160*cdf0e10cSrcweir oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc); 161*cdf0e10cSrcweir boolean result = oObj.getType() == TransliterationType.ONE_TO_ONE; 162*cdf0e10cSrcweir tRes.tested("getType()", result); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir /** 166*cdf0e10cSrcweir * Loads UPPERCASE_LOWERCASE module and 167*cdf0e10cSrcweir * checks the name returned by the method <code>getName</code>. <p> 168*cdf0e10cSrcweir * 169*cdf0e10cSrcweir * Has <b>OK</b> status if the method <code>getName</code> returns the 170*cdf0e10cSrcweir * string "upper_to_lower(generic)". 171*cdf0e10cSrcweir */ 172*cdf0e10cSrcweir public void _getName() { 173*cdf0e10cSrcweir oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir String name = oObj.getName(); 176*cdf0e10cSrcweir boolean res = name.equals("lower_to_upper(generic)"); 177*cdf0e10cSrcweir log.println("getName return: " + name); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir tRes.tested("getName()", res); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir /** 183*cdf0e10cSrcweir * First loads <code>LOWERCASE_UPPERCASE</code> module. 184*cdf0e10cSrcweir * Then tries to transliterate (make uppercase) a substring. <p> 185*cdf0e10cSrcweir * Has <b>OK</b> status if all chars were made uppercase, 186*cdf0e10cSrcweir * and array returned has size as substring length, and its 187*cdf0e10cSrcweir * elements are positions of substring characters in the source 188*cdf0e10cSrcweir * string. 189*cdf0e10cSrcweir */ 190*cdf0e10cSrcweir public void _transliterate() { 191*cdf0e10cSrcweir oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir int[][] offs = new int[1][] ; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir String out = oObj.transliterate("AaBbCc", 1, 4, offs) ; 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir boolean result = "ABBC".equals(out) && offs[0].length == 4 && 198*cdf0e10cSrcweir offs[0][0] == 1 && 199*cdf0e10cSrcweir offs[0][1] == 2 && 200*cdf0e10cSrcweir offs[0][2] == 3 && 201*cdf0e10cSrcweir offs[0][3] == 4 ; 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir tRes.tested("transliterate()", result) ; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir /** 208*cdf0e10cSrcweir * First loads <code>LOWERCASE_UPPERCASE</code> module. 209*cdf0e10cSrcweir * Tries to transliterate a range of two characters. <p> 210*cdf0e10cSrcweir * Has <b>OK</b> status if the appropriate String array 211*cdf0e10cSrcweir * returned (not null, length = 4, with two ranges 212*cdf0e10cSrcweir * (a, i), (A, I) in any order). 213*cdf0e10cSrcweir */ 214*cdf0e10cSrcweir public void _transliterateRange() { 215*cdf0e10cSrcweir oObj.loadModule(TransliterationModules.IGNORE_CASE, loc); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir String[] out = oObj.transliterateRange("a", "i") ; 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir log.println("transliterateRange return:"); 220*cdf0e10cSrcweir for(int i = 0; i < out.length; i++) { 221*cdf0e10cSrcweir log.println(out[i]); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir boolean bOK = out != null && 225*cdf0e10cSrcweir out.length == 4 && 226*cdf0e10cSrcweir ("A".equals(out[0]) && "I".equals(out[1]) && 227*cdf0e10cSrcweir "a".equals(out[2]) && "i".equals(out[3])) || 228*cdf0e10cSrcweir ("a".equals(out[0]) && "i".equals(out[1]) && 229*cdf0e10cSrcweir "A".equals(out[2]) && "I".equals(out[3])) ; 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir if (!bOK) { 232*cdf0e10cSrcweir log.println("Unexpected range returned :"); 233*cdf0e10cSrcweir for (int i = 0; i < out.length; i++) { 234*cdf0e10cSrcweir log.print("'" + out[i] +"', "); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir log.println(); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir tRes.tested("transliterateRange()", bOK); 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir /** 243*cdf0e10cSrcweir * This method is used internally by <code>equals</code> 244*cdf0e10cSrcweir * method so it indirectly tested in this method. <p> 245*cdf0e10cSrcweir * Always has <b>OK</b> status. 246*cdf0e10cSrcweir */ 247*cdf0e10cSrcweir public void _folding() { 248*cdf0e10cSrcweir oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc); 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir int[][] offs = new int[1][] ; 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir String out = oObj.folding("AaBbCc", 1, 4, offs) ; 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir boolean result = "ABBC".equals(out) && offs[0].length == 4 && 255*cdf0e10cSrcweir offs[0][0] == 1 && 256*cdf0e10cSrcweir offs[0][1] == 2 && 257*cdf0e10cSrcweir offs[0][2] == 3 && 258*cdf0e10cSrcweir offs[0][3] == 4 ; 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir tRes.tested("folding()", result) ; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir /** 266*cdf0e10cSrcweir * First loads <code>LOWERCASE_UPPERCASE</code> module. 267*cdf0e10cSrcweir * Tries to compare two equal substrings. <p> 268*cdf0e10cSrcweir * Has <b>OK</b> status if the method returned <code>true</code>. 269*cdf0e10cSrcweir */ 270*cdf0e10cSrcweir public void _equals() { 271*cdf0e10cSrcweir oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc); 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir int[] match1 = new int[1], 274*cdf0e10cSrcweir match2 = new int[1] ; 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir boolean res = oObj.equals("aAbBcC", 1, 3, match1, "aAbBcC", 1, 277*cdf0e10cSrcweir 3, match2) ; 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir log.println("Returned : " + res + " Match1 = " + match1[0] + 280*cdf0e10cSrcweir " Match2 = " + match2[0]) ; 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir tRes.tested("equals()", res) ; 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir /** 286*cdf0e10cSrcweir * Test performed for sets of equal substrings, not equal 287*cdf0e10cSrcweir * substrings, and with out of bounds offset and length 288*cdf0e10cSrcweir * parameters.<p> 289*cdf0e10cSrcweir * 290*cdf0e10cSrcweir * Has <b>OK</b> status if comparings of equal substrings 291*cdf0e10cSrcweir * always return 0, if comparisons of none equal returns 292*cdf0e10cSrcweir * proper value according to lexicographical order and if 293*cdf0e10cSrcweir * comparisons with invalid parameters return none 0 value. 294*cdf0e10cSrcweir */ 295*cdf0e10cSrcweir public void _compareSubstring() { 296*cdf0e10cSrcweir oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc); 297*cdf0e10cSrcweir boolean result = true ; 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir // substrings below must be equal 300*cdf0e10cSrcweir result &= testSubstring("", 0, 0, "", 0, 0, 0) ; 301*cdf0e10cSrcweir result &= testSubstring("aa", 1, 0, "", 0, 0, 0) ; 302*cdf0e10cSrcweir result &= testSubstring("aa", 1, 0, "aa", 2, 0, 0) ; 303*cdf0e10cSrcweir result &= testSubstring("a", 0, 1, "a", 0, 1, 0) ; 304*cdf0e10cSrcweir result &= testSubstring("ab", 0, 2, "ab", 0, 2, 0) ; 305*cdf0e10cSrcweir result &= testSubstring("abc", 1, 2, "abc", 1, 2, 0) ; 306*cdf0e10cSrcweir result &= testSubstring("abcdef", 0, 3, "123abc", 3, 3, 0) ; 307*cdf0e10cSrcweir result &= testSubstring("abcdef", 1, 1, "123abc", 4, 1, 0) ; 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir // substrings below must NOT be equal 310*cdf0e10cSrcweir result &= testSubstring("a", 0, 1, "a", 0, 0, 1) ; 311*cdf0e10cSrcweir result &= testSubstring("aaa", 1, 1, "", 0, 0, 1) ; 312*cdf0e10cSrcweir result &= testSubstring("bbb", 2, 1, "aaa", 2, 1, 1) ; 313*cdf0e10cSrcweir result &= testSubstring("abc", 0, 3, "abc", 0, 2, 1) ; 314*cdf0e10cSrcweir result &= testSubstring("bbc", 1, 2, "bbc", 0, 2, 1) ; 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir // testing with wrong offsets and lengths 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir tRes.tested("compareSubstring()", result) ; 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir /** 322*cdf0e10cSrcweir * Performs tesing of two substrings. Also testing of opposite 323*cdf0e10cSrcweir * substrings order performed. 324*cdf0e10cSrcweir * @return <code>true</code> if substrings are equal and retruned 325*cdf0e10cSrcweir * value is 0 for both orders, 326*cdf0e10cSrcweir * if substrings are different and expected value 327*cdf0e10cSrcweir * returned for direct order and opposite value returned for 328*cdf0e10cSrcweir * opposite order. 329*cdf0e10cSrcweir */ 330*cdf0e10cSrcweir private boolean testSubstring(String str1, int p1, int len1, 331*cdf0e10cSrcweir String str2, int p2, int len2, int expRes) { 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir boolean ret = true ; 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir int res = -666 ; 336*cdf0e10cSrcweir try { 337*cdf0e10cSrcweir res = oObj.compareSubstring(str1, p1, len1, str2, p2, len2); 338*cdf0e10cSrcweir } catch (java.lang.NullPointerException e) { 339*cdf0e10cSrcweir log.println("Exception while method calling occurs :" + e); 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir if (res != expRes) { 343*cdf0e10cSrcweir log.print("Comparing FAILED; return: " + res + ", expected: " + 344*cdf0e10cSrcweir expRes + " "); 345*cdf0e10cSrcweir ret = false ; 346*cdf0e10cSrcweir } else { 347*cdf0e10cSrcweir log.print("Comparing OK : "); 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir log.println("('" + str1 + "', " + p1 + ", " + len1 + ", '" + 350*cdf0e10cSrcweir str2 + "', " + p2 + ", " + len2 + ")"); 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir res = -666 ; 353*cdf0e10cSrcweir try { 354*cdf0e10cSrcweir res = oObj.compareSubstring(str2, p2, len2, str1, p1, len1); 355*cdf0e10cSrcweir } catch (java.lang.NullPointerException e) { 356*cdf0e10cSrcweir log.println("Exception while method calling occurs :" + e); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir if (res != -expRes) { 360*cdf0e10cSrcweir log.print("Comparing FAILED; return: " + res + ", expected: " + 361*cdf0e10cSrcweir -expRes + " "); 362*cdf0e10cSrcweir ret = false ; 363*cdf0e10cSrcweir } else { 364*cdf0e10cSrcweir log.print("Comparing OK :"); 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir log.println("('" + str2 + "', " + p2 + ", " + len2 + ", '" + 367*cdf0e10cSrcweir str1 + "', " + p1 + ", " + len1 + ")"); 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir return ret ; 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir /** 373*cdf0e10cSrcweir * Test performed for sets of equal strings and not equal 374*cdf0e10cSrcweir * strings.<p> 375*cdf0e10cSrcweir * 376*cdf0e10cSrcweir * Has <b>OK</b> status if comparings of equal strings 377*cdf0e10cSrcweir * always return 0 and if comparisons of none equal returns 378*cdf0e10cSrcweir * proper value according to lexicographical order . 379*cdf0e10cSrcweir */ 380*cdf0e10cSrcweir public void _compareString() { 381*cdf0e10cSrcweir oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc); 382*cdf0e10cSrcweir boolean result = true ; 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir result &= testString("", "", 0) ; 385*cdf0e10cSrcweir result &= testString("a", "", 1) ; 386*cdf0e10cSrcweir result &= testString("a", "a", 0) ; 387*cdf0e10cSrcweir result &= testString("A", "a", 0) ; 388*cdf0e10cSrcweir result &= testString("b", "a", 1) ; 389*cdf0e10cSrcweir result &= testString("\n", "\n", 0) ; 390*cdf0e10cSrcweir result &= testString("\n", "\t", 1) ; 391*cdf0e10cSrcweir result &= testString("aaa", "aaa", 0) ; 392*cdf0e10cSrcweir result &= testString("aaA", "aaa", 0) ; 393*cdf0e10cSrcweir result &= testString("aaa", "aa", 1) ; 394*cdf0e10cSrcweir result &= testString("ab", "aaa", 1) ; 395*cdf0e10cSrcweir result &= testString("aba", "aa", 1) ; 396*cdf0e10cSrcweir result &= testString("aaa\t\na", "aaa\t\na", 0) ; 397*cdf0e10cSrcweir result &= testString("aaa\t\nb", "aaa\t\na", 1) ; 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir tRes.tested("compareString()", result) ; 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir /** 403*cdf0e10cSrcweir * Performs tesing of two strings. If the expected value is not 0 404*cdf0e10cSrcweir * (i.e. strings are not equal), then also testing of opposite 405*cdf0e10cSrcweir * strings order performed. 406*cdf0e10cSrcweir * @return <code>true</code> if strings are equal and retruned 407*cdf0e10cSrcweir * value is 0, if strings are different and expected value 408*cdf0e10cSrcweir * returned for direct order and opposite value returned for 409*cdf0e10cSrcweir * opposite order. 410*cdf0e10cSrcweir */ 411*cdf0e10cSrcweir protected boolean testString(String str1, String str2, int expRes) { 412*cdf0e10cSrcweir if (expRes == 0) return testString(str1, str2, expRes, false) ; 413*cdf0e10cSrcweir return testString(str1, str2, expRes, true) ; 414*cdf0e10cSrcweir } 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir private boolean testString(String str1, String str2, int expRes, 417*cdf0e10cSrcweir boolean testReverse) { 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir boolean ret = true ; 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir int res = -666 ; 422*cdf0e10cSrcweir try { 423*cdf0e10cSrcweir res = oObj.compareString(str1, str2); 424*cdf0e10cSrcweir } catch (java.lang.NullPointerException e) { 425*cdf0e10cSrcweir log.println("Exception while method calling occurs :" + e); 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir if (res == expRes) { 429*cdf0e10cSrcweir log.println("Comparing of '" + str1 + "' and '" + str2 + "' OK" ); 430*cdf0e10cSrcweir } else { 431*cdf0e10cSrcweir log.println("Comparing of '" + str1 + "' and '" + str2 + 432*cdf0e10cSrcweir "' FAILED; return: " + res + ", expected: " + expRes); 433*cdf0e10cSrcweir ret = false ; 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir if (!testReverse) return ret ; 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir res = -666 ; 439*cdf0e10cSrcweir try { 440*cdf0e10cSrcweir res = oObj.compareString(str2, str1); 441*cdf0e10cSrcweir } catch (java.lang.NullPointerException e) { 442*cdf0e10cSrcweir log.println("Exception while method calling occurs :" + e); 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir if (res == -expRes) { 446*cdf0e10cSrcweir log.println("Comparing of '" + str2 + "' and '" + str1 + "' OK" ); 447*cdf0e10cSrcweir } else { 448*cdf0e10cSrcweir log.println("Comparing of '" + str2 + "' and '" + str1 + 449*cdf0e10cSrcweir "' FAILED; return: " + res + ", expected: " + -expRes); 450*cdf0e10cSrcweir ret = false ; 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir return ret ; 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir 457