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