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 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 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. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.i18n; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.text.Collator; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import lib.MultiMethodTest; 29cdf0e10cSrcweir 30cdf0e10cSrcweir import com.sun.star.i18n.CollatorOptions; 31cdf0e10cSrcweir import com.sun.star.i18n.XCollator; 32cdf0e10cSrcweir import com.sun.star.lang.Locale; 33cdf0e10cSrcweir 34cdf0e10cSrcweir /** 35cdf0e10cSrcweir * Testing <code>com.sun.star.i18n.XCollator</code> 36cdf0e10cSrcweir * interface methods : 37cdf0e10cSrcweir * <ul> 38cdf0e10cSrcweir * <li><code> compareSubstring()</code></li> 39cdf0e10cSrcweir * <li><code> compareString()</code></li> 40cdf0e10cSrcweir * <li><code> loadDefaultCollator()</code></li> 41cdf0e10cSrcweir * <li><code> loadCollatorAlgorithm()</code></li> 42cdf0e10cSrcweir * <li><code> listCollatorAlgorithms()</code></li> 43cdf0e10cSrcweir * <li><code> loadCollatorAlgorithmWithEndUserOption()</code></li> 44cdf0e10cSrcweir * <li><code> listCollatorOptions()</code></li> 45cdf0e10cSrcweir * </ul> <p> 46cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 47cdf0e10cSrcweir * @see com.sun.star.i18n.XCollator 48cdf0e10cSrcweir */ 49cdf0e10cSrcweir public class _XCollator extends MultiMethodTest { 50cdf0e10cSrcweir public XCollator oObj = null; 51cdf0e10cSrcweir private String[] alg = null ; 52cdf0e10cSrcweir private int[] opt = null ; 53cdf0e10cSrcweir Locale loc = new Locale("en", "EN", ""); 54cdf0e10cSrcweir 55cdf0e10cSrcweir /** 56cdf0e10cSrcweir * Just retrieves a list of algorithms. <p> 57cdf0e10cSrcweir * Has <b>OK</b> status if non-zero length array returned. 58cdf0e10cSrcweir */ _listCollatorAlgorithms()59cdf0e10cSrcweir public void _listCollatorAlgorithms() { 60cdf0e10cSrcweir alg = oObj.listCollatorAlgorithms(loc) ; 61cdf0e10cSrcweir log.println("Collator algorithms :"); 62cdf0e10cSrcweir if (alg != null) { 63cdf0e10cSrcweir for (int i = 0; i < alg.length; i++) { 64cdf0e10cSrcweir log.println(" '" + alg[i] + "'") ; 65cdf0e10cSrcweir } 66cdf0e10cSrcweir tRes.tested("listCollatorAlgorithms()", alg.length > 0) ; 67cdf0e10cSrcweir } else { 68cdf0e10cSrcweir tRes.tested("listCollatorAlgorithms()", false) ; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir /** 73cdf0e10cSrcweir * Just gets a list of options for some collator. <p> 74cdf0e10cSrcweir * Has <b>OK</b> status if not null value returned.<p> 75cdf0e10cSrcweir * The following method tests are to be completed successfully before : 76cdf0e10cSrcweir * <ul> 77cdf0e10cSrcweir * <li> <code> listCollatorAlgorithms </code> : to have some 78cdf0e10cSrcweir * algorithm name. </li> 79cdf0e10cSrcweir * </ul> 80cdf0e10cSrcweir */ _listCollatorOptions()81cdf0e10cSrcweir public void _listCollatorOptions() { 82cdf0e10cSrcweir requiredMethod("listCollatorAlgorithms()") ; 83cdf0e10cSrcweir opt = oObj.listCollatorOptions(alg[0]) ; 84cdf0e10cSrcweir log.println("Collator '" + alg[0] + "' options :"); 85cdf0e10cSrcweir if (opt != null) { 86cdf0e10cSrcweir for (int i = 0; i < opt.length; i++) { 87cdf0e10cSrcweir log.println(" " + opt[i]) ; 88cdf0e10cSrcweir } 89cdf0e10cSrcweir tRes.tested("listCollatorOptions()", true) ; 90cdf0e10cSrcweir } else { 91cdf0e10cSrcweir tRes.tested("listCollatorOptions()", false) ; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir /** 96cdf0e10cSrcweir * Calls the method with no options and with options(IGNORE_CASE), 97cdf0e10cSrcweir * compares strings.<p> 98cdf0e10cSrcweir * Has <b>OK</b> status if compareString() returned correct values. 99cdf0e10cSrcweir */ _loadDefaultCollator()100cdf0e10cSrcweir public void _loadDefaultCollator() { 101cdf0e10cSrcweir oObj.loadDefaultCollator(loc, 0); 102cdf0e10cSrcweir boolean res = oObj.compareString("A", "a") != 0; 103cdf0e10cSrcweir oObj.loadDefaultCollator(loc, 104cdf0e10cSrcweir CollatorOptions.CollatorOptions_IGNORE_CASE); 105cdf0e10cSrcweir res &= oObj.compareString("a", "A") == 0; 106cdf0e10cSrcweir tRes.tested("loadDefaultCollator()", res) ; 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir /** 110cdf0e10cSrcweir * Calls the method with no options and with options(IGNORE_CASE), 111cdf0e10cSrcweir * compares strings.<p> 112cdf0e10cSrcweir * Has <b>OK</b> status if compareString() returned correct values. 113cdf0e10cSrcweir * The following method tests are to be completed successfully before : 114cdf0e10cSrcweir * <ul> 115cdf0e10cSrcweir * <li> <code> listCollatorAlgorithms </code> : to have some 116cdf0e10cSrcweir * algorithm name. </li> 117cdf0e10cSrcweir * </ul> 118cdf0e10cSrcweir */ _loadCollatorAlgorithm()119cdf0e10cSrcweir public void _loadCollatorAlgorithm() { 120cdf0e10cSrcweir requiredMethod("listCollatorAlgorithms()"); 121cdf0e10cSrcweir oObj.loadCollatorAlgorithm(alg[0], loc, 122cdf0e10cSrcweir CollatorOptions.CollatorOptions_IGNORE_CASE); 123cdf0e10cSrcweir boolean res = oObj.compareString("A", "a") == 0; 124cdf0e10cSrcweir oObj.loadCollatorAlgorithm(alg[0], loc, 0); 125cdf0e10cSrcweir res &= oObj.compareString("a", "A") != 0; 126cdf0e10cSrcweir tRes.tested("loadCollatorAlgorithm()", res); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir /** 130cdf0e10cSrcweir * Calls the method with no options and with options(IGNORE_CASE), 131cdf0e10cSrcweir * compares strings.<p> 132cdf0e10cSrcweir * Has <b>OK</b> status if compareString() returned correct values. 133cdf0e10cSrcweir * The following method tests are to be completed successfully before : 134cdf0e10cSrcweir * <ul> 135cdf0e10cSrcweir * <li> <code> listCollatorAlgorithms </code> : to have some 136cdf0e10cSrcweir * algorithm name. </li> 137cdf0e10cSrcweir * </ul> 138cdf0e10cSrcweir */ _loadCollatorAlgorithmWithEndUserOption()139cdf0e10cSrcweir public void _loadCollatorAlgorithmWithEndUserOption() { 140cdf0e10cSrcweir requiredMethod("listCollatorAlgorithms()"); 141cdf0e10cSrcweir oObj.loadCollatorAlgorithmWithEndUserOption(alg[0], loc, 142cdf0e10cSrcweir new int[] {0}); 143cdf0e10cSrcweir boolean res = oObj.compareString("A", "a") != 0; 144cdf0e10cSrcweir oObj.loadCollatorAlgorithmWithEndUserOption(alg[0], loc, 145cdf0e10cSrcweir new int[] {CollatorOptions.CollatorOptions_IGNORE_CASE}); 146cdf0e10cSrcweir res = oObj.compareString("A", "a") == 0; 147cdf0e10cSrcweir tRes.tested("loadCollatorAlgorithmWithEndUserOption()", res); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir /** 151cdf0e10cSrcweir * Test is performed for locales : en, ru, ja, zh, ko. 152cdf0e10cSrcweir * Default collator is loaded for each locale. Then collation 153cdf0e10cSrcweir * is performed for different combination of symbols from range of 154cdf0e10cSrcweir * this locale.<p> 155cdf0e10cSrcweir * Has <b>OK</b> status if comparing of different strings 156cdf0e10cSrcweir * returns not 0 value, then comparing in the opposite 157cdf0e10cSrcweir * order returns value with opposite sign, and comparing 158cdf0e10cSrcweir * of two equal strings returns 0. The such comparing is performed 159cdf0e10cSrcweir * for one character strings. 160cdf0e10cSrcweir */ _compareSubstring()161cdf0e10cSrcweir public void _compareSubstring() { 162cdf0e10cSrcweir boolean result = true ; 163cdf0e10cSrcweir char[] chars = new char[2] ; 164cdf0e10cSrcweir Collator col = null ; 165cdf0e10cSrcweir 166cdf0e10cSrcweir log.println(" #### Testing English locale ####") ; 167cdf0e10cSrcweir oObj.loadDefaultCollator(loc, 0) ; 168cdf0e10cSrcweir col = Collator.getInstance(new java.util.Locale("en", "EN")) ; 169cdf0e10cSrcweir for (char ch = 0x0020; ch < 0x007F; ch ++) { 170cdf0e10cSrcweir chars[0] = ch ; chars[1] = (char) (ch + 1) ; 171cdf0e10cSrcweir result &= testCompareSubstring(chars, col) ; 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir log.println(" #### Testing Russian locale ####") ; 175cdf0e10cSrcweir oObj.loadDefaultCollator( 176cdf0e10cSrcweir new com.sun.star.lang.Locale("ru", "RU", ""), 0) ; 177cdf0e10cSrcweir col = Collator.getInstance(new java.util.Locale("ru", "RU")) ; 178cdf0e10cSrcweir for (char ch = 0x0410; ch < 0x0450; ch ++) { 179cdf0e10cSrcweir chars[0] = ch ; chars[1] = (char) (ch + 1) ; 180cdf0e10cSrcweir result &= testCompareSubstring(chars, col) ; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir log.println(" #### Testing Japan locale ####") ; 184cdf0e10cSrcweir oObj.loadDefaultCollator( 185cdf0e10cSrcweir new com.sun.star.lang.Locale("ja", "JP", ""), 0) ; 186cdf0e10cSrcweir col = Collator.getInstance(new java.util.Locale("ja", "JP")) ; 187cdf0e10cSrcweir for (char ch = 0x4E00; ch < 0x4EFD; ch ++) { 188cdf0e10cSrcweir chars[0] = ch ; chars[1] = (char) (ch + 1) ; 189cdf0e10cSrcweir result &= testCompareSubstring(chars, col) ; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir log.println(" #### Testing China locale ####") ; 193cdf0e10cSrcweir oObj.loadDefaultCollator(new Locale("zh", "CN", ""), 0) ; 194cdf0e10cSrcweir col = Collator.getInstance(new java.util.Locale("zh", "CN")) ; 195cdf0e10cSrcweir for (char ch = 0x4E00; ch < 0x4EFD; ch ++) { 196cdf0e10cSrcweir chars[0] = ch ; chars[1] = (char) (ch + 1) ; 197cdf0e10cSrcweir result &= testCompareSubstring(chars, col) ; 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir log.println(" #### Testing Korean locale ####") ; 201cdf0e10cSrcweir oObj.loadDefaultCollator(new Locale("ko", "KR", ""), 0) ; 202cdf0e10cSrcweir col = Collator.getInstance(new java.util.Locale("ko", "KR")) ; 203cdf0e10cSrcweir for (char ch = 0x4E00; ch < 0x4EFD; ch ++) { 204cdf0e10cSrcweir chars[0] = ch ; chars[1] = (char) (ch + 1) ; 205cdf0e10cSrcweir result &= testCompareSubstring(chars, col) ; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir tRes.tested("compareSubstring()", result) ; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir /** 212cdf0e10cSrcweir * Test is performed for locales : en, ru, ja, zh, ko. 213cdf0e10cSrcweir * Default collator is loaded for each locale. Then collation 214cdf0e10cSrcweir * is performed for different combination of symbols from range of 215cdf0e10cSrcweir * this locale.<p> 216cdf0e10cSrcweir * Has <b>OK</b> status if comparing of different strings 217cdf0e10cSrcweir * returns not 0 value, then comparing in the opposite 218cdf0e10cSrcweir * order returns value with opposite sign, and comparing 219cdf0e10cSrcweir * of two equal strings returns 0. The such comparing is performed 220cdf0e10cSrcweir * for one character strings. 221cdf0e10cSrcweir */ _compareString()222cdf0e10cSrcweir public void _compareString() { 223cdf0e10cSrcweir boolean result = true ; 224cdf0e10cSrcweir char[] chars = new char[2] ; 225cdf0e10cSrcweir Collator col = null ; 226cdf0e10cSrcweir log.println(" #### Testing English locale ####") ; 227cdf0e10cSrcweir oObj.loadDefaultCollator( 228cdf0e10cSrcweir new com.sun.star.lang.Locale("en", "EN", ""), 0) ; 229cdf0e10cSrcweir col = Collator.getInstance(new java.util.Locale("en", "EN")) ; 230cdf0e10cSrcweir for (char ch = 0x0020; ch < 0x007F; ch ++) { 231cdf0e10cSrcweir chars[0] = ch ; chars[1] = (char) (ch + 1) ; 232cdf0e10cSrcweir result &= testCompareString(chars, col) ; 233cdf0e10cSrcweir } 234cdf0e10cSrcweir 235cdf0e10cSrcweir log.println(" #### Testing Russian locale ####") ; 236cdf0e10cSrcweir oObj.loadDefaultCollator( 237cdf0e10cSrcweir new com.sun.star.lang.Locale("ru", "RU", ""), 0) ; 238cdf0e10cSrcweir col = Collator.getInstance(new java.util.Locale("ru", "RU")) ; 239cdf0e10cSrcweir for (char ch = 0x0410; ch < 0x0450; ch ++) { 240cdf0e10cSrcweir chars[0] = ch ; chars[1] = (char) (ch + 1) ; 241cdf0e10cSrcweir result &= testCompareString(chars, col) ; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir log.println(" #### Testing Japan locale ####") ; 245cdf0e10cSrcweir oObj.loadDefaultCollator( 246cdf0e10cSrcweir new com.sun.star.lang.Locale("ja", "JP", ""), 0) ; 247cdf0e10cSrcweir col = Collator.getInstance(new java.util.Locale("ja", "JP")) ; 248cdf0e10cSrcweir for (char ch = 0x4E00; ch < 0x4EFD; ch ++) { 249cdf0e10cSrcweir chars[0] = ch ; chars[1] = (char) (ch + 1) ; 250cdf0e10cSrcweir result &= testCompareString(chars, col) ; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir log.println(" #### Testing China locale ####") ; 254cdf0e10cSrcweir oObj.loadDefaultCollator(new Locale("zh", "CN", ""), 0) ; 255cdf0e10cSrcweir col = Collator.getInstance(new java.util.Locale("zh", "CN")) ; 256cdf0e10cSrcweir for (char ch = 0x4E00; ch < 0x4EFD; ch ++) { 257cdf0e10cSrcweir chars[0] = ch ; chars[1] = (char) (ch + 1) ; 258cdf0e10cSrcweir result &= testCompareString(chars, col) ; 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir log.println(" #### Testing Korean locale ####") ; 262cdf0e10cSrcweir oObj.loadDefaultCollator(new Locale("ko", "KR", ""), 0) ; 263cdf0e10cSrcweir col = Collator.getInstance(new java.util.Locale("ko", "KR")) ; 264cdf0e10cSrcweir for (char ch = 0x4E00; ch < 0x4EFD; ch ++) { 265cdf0e10cSrcweir chars[0] = ch ; chars[1] = (char) (ch + 1) ; 266cdf0e10cSrcweir result &= testCompareString(chars, col) ; 267cdf0e10cSrcweir } 268cdf0e10cSrcweir 269cdf0e10cSrcweir tRes.tested("compareString()", result) ; 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir 273cdf0e10cSrcweir /** 274cdf0e10cSrcweir * Testing compareString() method. At first method is testing single chars 275cdf0e10cSrcweir * comparing, then strings comparing. 276cdf0e10cSrcweir * @param locChar sequence of at list two characters of a given locale 277cdf0e10cSrcweir * to be used in comparing. 278cdf0e10cSrcweir * @param col Collator for a given locale 279cdf0e10cSrcweir * @return true if: 280cdf0e10cSrcweir * <ol> 281cdf0e10cSrcweir * <li> if comparing of two identical characters returns zero</li> 282cdf0e10cSrcweir * <li> if comparing of two different characters returns non zero</li> 283cdf0e10cSrcweir * <li> if comparing of two identical strings, composed of given chars 284cdf0e10cSrcweir * returns zero</li> 285cdf0e10cSrcweir * <li> if comparing of two different strings, composed of given chars 286cdf0e10cSrcweir * returns non zero</li> 287cdf0e10cSrcweir * </ol> 288cdf0e10cSrcweir */ testCompareString(char[] locChar, Collator col)289cdf0e10cSrcweir public boolean testCompareString(char[] locChar, Collator col) { 290cdf0e10cSrcweir boolean result = true; 291cdf0e10cSrcweir int res; 292cdf0e10cSrcweir String msg = ""; 293cdf0e10cSrcweir 294cdf0e10cSrcweir String char0 = "_"+new String(new char[] {locChar[0]}); 295cdf0e10cSrcweir String char1 = "_"+new String(new char[] {locChar[1]}); 296cdf0e10cSrcweir res = oObj.compareString(char0 , char0) ; 297cdf0e10cSrcweir if (res != 0) { 298cdf0e10cSrcweir msg += " Testing collation of single equal characters (" 299cdf0e10cSrcweir + toUnicode(char0) + ") ... FAILED\n" ; 300cdf0e10cSrcweir } 301cdf0e10cSrcweir result &= res == 0 ; 302cdf0e10cSrcweir res = oObj.compareString(char0, char1) ; 303cdf0e10cSrcweir if (res == 0) { 304cdf0e10cSrcweir msg += " Testing collation of single different" + 305cdf0e10cSrcweir " characters (" + toUnicode(char0+char1) + 306cdf0e10cSrcweir ") ... FAILED (0 returned)\n" ; 307cdf0e10cSrcweir msg += " Java collator returned " + 308cdf0e10cSrcweir col.compare(char0, char1) + "\n" ; 309cdf0e10cSrcweir result = false ; 310cdf0e10cSrcweir } else { // opposite order - sum of results must be 0 311cdf0e10cSrcweir res += oObj.compareString(char1, char0) ; 312cdf0e10cSrcweir if (res != 0) { 313cdf0e10cSrcweir msg += " Testing collation of single different" + 314cdf0e10cSrcweir " characters (" + toUnicode(char0+char1) + 315cdf0e10cSrcweir ") ... FAILED\n" ; 316cdf0e10cSrcweir } 317cdf0e10cSrcweir result &= res == 0 ; 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir String str1 = new String(new char[] {locChar[0], locChar[0], 321cdf0e10cSrcweir locChar[1], locChar[1], locChar[1]}) ; 322cdf0e10cSrcweir String str2 = new String(new char[] {locChar[0], locChar[0], 323cdf0e10cSrcweir locChar[0], locChar[1], locChar[1]}) ; 324cdf0e10cSrcweir 325cdf0e10cSrcweir res = oObj.compareString(str1 , str1) ; 326cdf0e10cSrcweir if (res != 0) { 327cdf0e10cSrcweir msg += " Testing collation of equal strings (" + 328cdf0e10cSrcweir toUnicode(str1) + ") ... FAILED\n" ; 329cdf0e10cSrcweir } 330cdf0e10cSrcweir result &= res == 0 ; 331cdf0e10cSrcweir res = oObj.compareString(str1, str2) ; 332cdf0e10cSrcweir if (res == 0) { 333cdf0e10cSrcweir msg += " Testing collation of different strings ((" + 334cdf0e10cSrcweir toUnicode(str1) + "),(" + toUnicode(str2) + 335cdf0e10cSrcweir ")) ... FAILED (0 returned)\n" ; 336cdf0e10cSrcweir msg += " Java collator returned " + 337cdf0e10cSrcweir col.compare(str1, str2) + "\n" ; 338cdf0e10cSrcweir result = false ; 339cdf0e10cSrcweir } else { // opposite order - sum of results must be 340cdf0e10cSrcweir res += oObj.compareString(str2, str1) ; 341cdf0e10cSrcweir if (res != 0) { 342cdf0e10cSrcweir msg += " Testing collation of different strings ((" + 343cdf0e10cSrcweir toUnicode(str1) + "),(" + toUnicode(str2) + 344cdf0e10cSrcweir ")) ... FAILED\n" ; 345cdf0e10cSrcweir } 346cdf0e10cSrcweir result &= res == 0 ; 347cdf0e10cSrcweir } 348cdf0e10cSrcweir 349cdf0e10cSrcweir if (!result) { 350cdf0e10cSrcweir log.println(msg) ; 351cdf0e10cSrcweir } 352cdf0e10cSrcweir return result ; 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir 356cdf0e10cSrcweir /** 357cdf0e10cSrcweir * Testing compareSubstring() method. Method is testing substrings comparing. 358cdf0e10cSrcweir * @param locChar sequence of at list two characters of a given locale 359cdf0e10cSrcweir * to be used in comparing. 360cdf0e10cSrcweir * @param col Collator for a given locale 361cdf0e10cSrcweir * @return true if: 362cdf0e10cSrcweir * <ol> 363cdf0e10cSrcweir * <li> if comparing of two identical substrings of strings, composed 364cdf0e10cSrcweir * of given chars returns zero</li> 365cdf0e10cSrcweir * <li> if comparing of two different substrings of strings, composed 366cdf0e10cSrcweir * of given chars returns non zero</li> 367cdf0e10cSrcweir * </ol> 368cdf0e10cSrcweir */ testCompareSubstring(char[] locChar, Collator col)369cdf0e10cSrcweir public boolean testCompareSubstring(char[] locChar, Collator col) { 370cdf0e10cSrcweir boolean result = true ; 371cdf0e10cSrcweir int res ; 372cdf0e10cSrcweir String msg = "" ; 373cdf0e10cSrcweir 374cdf0e10cSrcweir String str1 = new String(new char[] {locChar[0], locChar[0], 375cdf0e10cSrcweir locChar[1], locChar[1], locChar[1]}) ; 376cdf0e10cSrcweir String str2 = new String(new char[] {locChar[0], locChar[0], 377cdf0e10cSrcweir locChar[0], locChar[1], locChar[1]}) ; 378cdf0e10cSrcweir 379cdf0e10cSrcweir res = oObj.compareSubstring(str1, 1, 2 , str2, 2, 2) ; 380cdf0e10cSrcweir if (res != 0) { 381cdf0e10cSrcweir msg += " Testing collation of equal substrings (" + 382cdf0e10cSrcweir toUnicode(str1) + ") ... FAILED\n" ; 383cdf0e10cSrcweir } 384cdf0e10cSrcweir result &= res == 0 ; 385cdf0e10cSrcweir res = oObj.compareSubstring(str1, 1, 2, str2, 1, 2) ; 386cdf0e10cSrcweir if (res == 0) { 387cdf0e10cSrcweir msg += " Testing collation of different strings ((" + 388cdf0e10cSrcweir toUnicode(str1.substring(1, 3)) + "),(" + 389cdf0e10cSrcweir toUnicode(str2.substring(1, 3)) 390cdf0e10cSrcweir + ")) ... FAILED (0 returned)\n" ; 391cdf0e10cSrcweir msg += " Java collator returned " + col.compare 392cdf0e10cSrcweir (str1.substring(1, 3), str2.substring(1, 3)) + "\n" ; 393cdf0e10cSrcweir result = false ; 394cdf0e10cSrcweir } else { // opposite order - sum of results must be 395cdf0e10cSrcweir res += oObj.compareSubstring(str2, 1, 2, str1, 1, 2) ; 396cdf0e10cSrcweir if (res != 0) { 397cdf0e10cSrcweir msg += " Testing collation of different strings ((" + 398cdf0e10cSrcweir toUnicode(str1) + "),(" + toUnicode(str2) + 399cdf0e10cSrcweir ")) ... FAILED\n" ; 400cdf0e10cSrcweir } 401cdf0e10cSrcweir result &= res == 0 ; 402cdf0e10cSrcweir } 403cdf0e10cSrcweir 404cdf0e10cSrcweir if (!result) { 405cdf0e10cSrcweir log.println(msg) ; 406cdf0e10cSrcweir } 407cdf0e10cSrcweir return result ; 408cdf0e10cSrcweir } 409cdf0e10cSrcweir 410cdf0e10cSrcweir 411cdf0e10cSrcweir /** 412cdf0e10cSrcweir * Transforms string to unicode hex codes. 413cdf0e10cSrcweir * @param str String to be transformed 414cdf0e10cSrcweir */ toUnicode(String str)415cdf0e10cSrcweir public String toUnicode(String str) { 416cdf0e10cSrcweir char[] chars = str.toCharArray() ; 417cdf0e10cSrcweir String res = "" ; 418cdf0e10cSrcweir for (int i = 0; i < chars.length; i++) { 419cdf0e10cSrcweir if (i != 0) res += "," ; 420cdf0e10cSrcweir res += Integer.toHexString(chars[i]) ; 421cdf0e10cSrcweir } 422cdf0e10cSrcweir return res ; 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir } 426cdf0e10cSrcweir 427