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.KParseTokens; 33*cdf0e10cSrcweir import com.sun.star.i18n.KParseType; 34*cdf0e10cSrcweir import com.sun.star.i18n.ParseResult; 35*cdf0e10cSrcweir import com.sun.star.i18n.XCharacterClassification; 36*cdf0e10cSrcweir import com.sun.star.lang.Locale; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir /** 39*cdf0e10cSrcweir * Testing <code>com.sun.star.i18n.XCharacterClassification</code> 40*cdf0e10cSrcweir * interface methods: 41*cdf0e10cSrcweir * <ul> 42*cdf0e10cSrcweir * <li><code> toUpper() </code></li> 43*cdf0e10cSrcweir * <li><code> toLower() </code></li> 44*cdf0e10cSrcweir * <li><code> toTitle() </code></li> 45*cdf0e10cSrcweir * <li><code> getType() </code></li> 46*cdf0e10cSrcweir * <li><code> getCharacterType() </code></li> 47*cdf0e10cSrcweir * <li><code> getStringType() </code></li> 48*cdf0e10cSrcweir * <li><code> getCharacterDirection() </code></li> 49*cdf0e10cSrcweir * <li><code> getScript() </code></li> 50*cdf0e10cSrcweir * <li><code> parseAnyToken() </code></li> 51*cdf0e10cSrcweir * <li><code> parsePredefinedToken() </code></li> 52*cdf0e10cSrcweir * </ul><p> 53*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 54*cdf0e10cSrcweir * @see com.sun.star.i18n.XCharacterClassification 55*cdf0e10cSrcweir */ 56*cdf0e10cSrcweir public class _XCharacterClassification extends MultiMethodTest { 57*cdf0e10cSrcweir public XCharacterClassification oObj = null; 58*cdf0e10cSrcweir public String[] languages = new String[]{"de","en","es","fr","ja","ko","zh"}; 59*cdf0e10cSrcweir public String[] countries = new String[]{"DE","US","ES","FR","JP","KR","CN"}; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir public String[] charstyles_java = new String[] {"UNASSIGNED","UPPERCASE_LETTER", 62*cdf0e10cSrcweir "LOWERCASE_LETTER","TITLECASE_LETTER","MODIFIER_LETTER","OTHER_LETTER", 63*cdf0e10cSrcweir "NON_SPACING_MARK","ENCLOSING_MARK","COMBINING_SPACING_MARK", 64*cdf0e10cSrcweir "DECIMAL_DIGIT_NUMBER","LETTER_NUMBER","OTHER_NUMBER","SPACE_SEPARATOR", 65*cdf0e10cSrcweir "LINE_SEPARATOR","PARAGRAPH_SEPARATOR","CONTROL","FORMAT","none17", 66*cdf0e10cSrcweir "PRIVATE_USE","none19","DASH_PUNCTUATION","START_PUNCTUATION","END_PUNCTUATION", 67*cdf0e10cSrcweir "CONNECTOR_PUNCTUATION","OTHER_PUNCTUATION","MATH_SYMBOL","CURRENCY_SYMBOL", 68*cdf0e10cSrcweir "MODIFIER_SYMBOL","OTHER_SYMBOL"}; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir public String[] charstyles_office = new String[] {"UNASSIGNED","UPPERCASE_LETTER", 71*cdf0e10cSrcweir "LOWERCASE_LETTER","TITLECASE_LETTER","MODIFIER_LETTER","OTHER_LETTER", 72*cdf0e10cSrcweir "NON_SPACING_MARK","ENCLOSING_MARK","COMBINING_SPACING_MARK", 73*cdf0e10cSrcweir "DECIMAL_DIGIT_NUMBER","LETTER_NUMBER","OTHER_NUMBER","SPACE_SEPARATOR", 74*cdf0e10cSrcweir "LINE_SEPARATOR","PARAGRAPH_SEPARATOR","CONTROL","FORMAT","PRIVATE_USE", 75*cdf0e10cSrcweir "OTHER_PUNCTUATION","DASH_PUNCTUATION","START_PUNCTUATION","END_PUNCTUATION", 76*cdf0e10cSrcweir "CONNECTOR_PUNCTUATION", 77*cdf0e10cSrcweir "OTHER_PUNCTUATION","MATH_SYMBOL","CURRENCY_SYMBOL","MODIFIER_SYMBOL", 78*cdf0e10cSrcweir "OTHER_SYMBOL","INITIAL_PUNCTUATION","FINAL_PUNCTUATION","GENERAL_TYPES_COUNT"}; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir public String[] unicode_script = new String[] {"U_BASIC_LATIN","U_LATIN_1_SUPPLEMENT", 81*cdf0e10cSrcweir "U_LATIN_EXTENDED_A","U_LATIN_EXTENDED_B","U_IPA_EXTENSIONS","U_SPACING_MODIFIER_LETTERS", 82*cdf0e10cSrcweir "U_COMBINING_DIACRITICAL_MARKS","U_GREEK","U_CYRILLIC","U_ARMENIAN","U_HEBREW", 83*cdf0e10cSrcweir "U_ARABIC","U_SYRIAC","U_THAANA","U_DEVANAGARI","U_BENGALI","U_GURMUKHI", 84*cdf0e10cSrcweir "U_GUJARATI","U_ORIYA","U_TAMIL","U_TELUGU","U_KANNADA","U_MALAYALAM", 85*cdf0e10cSrcweir "U_SINHALA","U_THAI","U_LAO","U_TIBETAN","U_MYANMAR","U_GEORGIAN", 86*cdf0e10cSrcweir "U_HANGUL_JAMO","U_ETHIOPIC","U_CHEROKEE","U_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS", 87*cdf0e10cSrcweir "U_OGHAM","U_RUNIC","U_KHMER","U_MONGOLIAN","U_LATIN_EXTENDED_ADDITIONAL", 88*cdf0e10cSrcweir "U_GREEK_EXTENDED","U_GENERAL_PUNCTUATION","U_SUPERSCRIPTS_AND_SUBSCRIPTS", 89*cdf0e10cSrcweir "U_CURRENCY_SYMBOLS","U_COMBINING_MARKS_FOR_SYMBOLS","U_LETTERLIKE_SYMBOLS", 90*cdf0e10cSrcweir "U_NUMBER_FORMS","U_ARROWS","U_MATHEMATICAL_OPERATORS","U_MISCELLANEOUS_TECHNICAL", 91*cdf0e10cSrcweir "U_CONTROL_PICTURES","U_OPTICAL_CHARACTER_RECOGNITION","U_ENCLOSED_ALPHANUMERICS", 92*cdf0e10cSrcweir "U_BOX_DRAWING","U_BLOCK_ELEMENTS","U_GEOMETRIC_SHAPES","U_MISCELLANEOUS_SYMBOLS", 93*cdf0e10cSrcweir "U_DINGBATS","U_BRAILLE_PATTERNS","U_CJK_RADICALS_SUPPLEMENT","U_KANGXI_RADICALS", 94*cdf0e10cSrcweir "U_IDEOGRAPHIC_DESCRIPTION_CHARACTERS","U_CJK_SYMBOLS_AND_PUNCTUATION", 95*cdf0e10cSrcweir "U_HIRAGANA","U_KATAKANA","U_BOPOMOFO","U_HANGUL_COMPATIBILITY_JAMO","U_KANBUN", 96*cdf0e10cSrcweir "U_BOPOMOFO_EXTENDED","U_ENCLOSED_CJK_LETTERS_AND_MONTHS","U_CJK_COMPATIBILITY", 97*cdf0e10cSrcweir "U_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A","U_CJK_UNIFIED_IDEOGRAPHS","U_YI_SYLLABLES", 98*cdf0e10cSrcweir "U_YI_RADICALS","U_HANGUL_SYLLABLES","U_HIGH_SURROGATES","U_HIGH_PRIVATE_USE_SURROGATES", 99*cdf0e10cSrcweir "U_LOW_SURROGATES","U_PRIVATE_USE_AREA","U_CJK_COMPATIBILITY_IDEOGRAPHS", 100*cdf0e10cSrcweir "U_ALPHABETIC_PRESENTATION_FORMS","U_ARABIC_PRESENTATION_FORMS_A","U_COMBINING_HALF_MARKS", 101*cdf0e10cSrcweir "U_CJK_COMPATIBILITY_FORMS","U_SMALL_FORM_VARIANTS","U_ARABIC_PRESENTATION_FORMS_B", 102*cdf0e10cSrcweir "U_SPECIALS","U_HALFWIDTH_AND_FULLWIDTH_FORMS","U_CHAR_SCRIPT_COUNT","U_NO_SCRIPT"}; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir /** 105*cdf0e10cSrcweir * Test calls the method for different locales. Then each result is compared 106*cdf0e10cSrcweir * with a string, converted to a upper case using 107*cdf0e10cSrcweir * <code>java.lang.String</code> method <code>toUpperCase()</code>.<p> 108*cdf0e10cSrcweir * Has <b> OK </b> status if string, returned by the method is equal to 109*cdf0e10cSrcweir * a string that is returned by String.toUpperCase() for all locales. 110*cdf0e10cSrcweir */ 111*cdf0e10cSrcweir public void _toUpper() { 112*cdf0e10cSrcweir boolean res = true; 113*cdf0e10cSrcweir char[] characters = new char[]{586,65,97,498,721,4588,772,8413,3404}; 114*cdf0e10cSrcweir String toCheck = new String(characters); 115*cdf0e10cSrcweir String get = ""; 116*cdf0e10cSrcweir String exp = ""; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir for (int i=0;i<7;i++) { 119*cdf0e10cSrcweir get = oObj.toUpper(toCheck, 0, toCheck.length(), getLocale(i)); 120*cdf0e10cSrcweir exp = toCheck.toUpperCase( 121*cdf0e10cSrcweir new java.util.Locale(languages[i], countries[i])); 122*cdf0e10cSrcweir res &= get.equals(exp); 123*cdf0e10cSrcweir if (!res) { 124*cdf0e10cSrcweir log.println("FAILED for: language=" + languages[i] + 125*cdf0e10cSrcweir " ; country=" + countries[i]); 126*cdf0e10cSrcweir log.println("Expected: " + exp); 127*cdf0e10cSrcweir log.println("Gained : " + get); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir tRes.tested("toUpper()", res); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir /** 134*cdf0e10cSrcweir * Test calls the method for different locales. Then each result is compared 135*cdf0e10cSrcweir * with a string, converted to a lower case using 136*cdf0e10cSrcweir * <code>java.lang.String</code> method <code>toLowerCase()</code>.<p> 137*cdf0e10cSrcweir * Has <b> OK </b> status if string, returned by the method is equal to 138*cdf0e10cSrcweir * a string that is returned by String.toLowerCase() for all locales. 139*cdf0e10cSrcweir */ 140*cdf0e10cSrcweir public void _toLower() { 141*cdf0e10cSrcweir boolean res = true; 142*cdf0e10cSrcweir char[] characters = new char[]{586,65,97,498,721,4588,772,8413,3404}; 143*cdf0e10cSrcweir String toCheck = new String(characters); 144*cdf0e10cSrcweir String get = ""; 145*cdf0e10cSrcweir String exp = ""; 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir for (int i=0;i<7;i++) { 148*cdf0e10cSrcweir get = oObj.toLower(toCheck,0,toCheck.length(),getLocale(i)); 149*cdf0e10cSrcweir exp = toCheck.toLowerCase( 150*cdf0e10cSrcweir new java.util.Locale(languages[i],countries[i])); 151*cdf0e10cSrcweir res &= get.equals(exp); 152*cdf0e10cSrcweir if (!res) { 153*cdf0e10cSrcweir log.println("FAILED for: language=" + languages[i] 154*cdf0e10cSrcweir + " ; country=" + countries[i]); 155*cdf0e10cSrcweir log.println("Expected: " + exp); 156*cdf0e10cSrcweir log.println("Gained : " + get); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir tRes.tested("toLower()", res); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir /** 163*cdf0e10cSrcweir * Test calls the method for different locales. Then each result is compared 164*cdf0e10cSrcweir * with a string, converted to a title case using 165*cdf0e10cSrcweir * <code>java.lang.Character</code> method <code>toTitleCase()</code>.<p> 166*cdf0e10cSrcweir * Has <b> OK </b> status if string, returned by the method is equal to 167*cdf0e10cSrcweir * a string that was converted using Character.toTitleCase() for all locales. 168*cdf0e10cSrcweir */ 169*cdf0e10cSrcweir public void _toTitle() { 170*cdf0e10cSrcweir boolean res = true; 171*cdf0e10cSrcweir String toCheck = new String(new char[]{8112}); 172*cdf0e10cSrcweir String get = ""; 173*cdf0e10cSrcweir String exp = ""; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir for (int i=0;i<7;i++) { 176*cdf0e10cSrcweir get = oObj.toTitle(toCheck, 0, 1, getLocale(i)); 177*cdf0e10cSrcweir exp = new String( 178*cdf0e10cSrcweir new char[]{Character.toTitleCase(toCheck.toCharArray()[0])}); 179*cdf0e10cSrcweir res &= get.equals(exp); 180*cdf0e10cSrcweir if (!res) { 181*cdf0e10cSrcweir log.println("FAILED for: language=" + languages[i] 182*cdf0e10cSrcweir + " ; country=" + countries[i]); 183*cdf0e10cSrcweir log.println("Expected: " + exp); 184*cdf0e10cSrcweir log.println("Gained : " + get); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir tRes.tested("toTitle()", res); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir /** 191*cdf0e10cSrcweir * At first we define <code>int[]</code> and <code>char[]</code> arrays of 192*cdf0e10cSrcweir * unicode symbol numbers, arranged as sequences, where symbols are sorted 193*cdf0e10cSrcweir * by type, so the character of <code>i<sup><small>th</small></sup></code> 194*cdf0e10cSrcweir * type is located on <code>i<sup><small>th</small></sup></code> position.<p> 195*cdf0e10cSrcweir * Has <b> OK </b> status if for all 30 types the method returns value, that 196*cdf0e10cSrcweir * is equal to an element number.<p> 197*cdf0e10cSrcweir * @see com.sun.star.i18n.CharType 198*cdf0e10cSrcweir */ 199*cdf0e10cSrcweir public void _getType() { 200*cdf0e10cSrcweir boolean res = true; 201*cdf0e10cSrcweir char[] characters = new char[]{586,65,97,498,721,4588,772,8413,3404, 202*cdf0e10cSrcweir 48,8544,179,32,8232,8233,144,8204,57344,56320,173,40,41,95,3852,247, 203*cdf0e10cSrcweir 3647,901,3896,171,187}; 204*cdf0e10cSrcweir int[] charsInt = new int[]{586,65,97,498,721,4588,772,8413,3404,48, 205*cdf0e10cSrcweir 8544,179,32,8232,8233,144,8204,57344,56320,173,40,41,95,3852,247, 206*cdf0e10cSrcweir 3647,901,3896,171,187}; 207*cdf0e10cSrcweir String toCheck = new String(characters); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir for (int i=0;i<characters.length;i++) { 210*cdf0e10cSrcweir int get = oObj.getType(toCheck, i); 211*cdf0e10cSrcweir res &= (charstyles_office[get] == charstyles_office[i]); 212*cdf0e10cSrcweir if (!res) { 213*cdf0e10cSrcweir log.println("Code :" + Integer.toHexString(charsInt[i])); 214*cdf0e10cSrcweir log.println("Gained: " + charstyles_office[get]); 215*cdf0e10cSrcweir log.println("Expected : " + charstyles_office[i]); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir tRes.tested("getType()", res); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir /** 222*cdf0e10cSrcweir * After defining string to be checked and array of expected types, test 223*cdf0e10cSrcweir * calls the method for each character of a string and for all locales.<p> 224*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns type, expected for a given 225*cdf0e10cSrcweir * character and locale. 226*cdf0e10cSrcweir */ 227*cdf0e10cSrcweir public void _getCharacterType() { 228*cdf0e10cSrcweir boolean res = true; 229*cdf0e10cSrcweir String toCheck = "Ab0)"; 230*cdf0e10cSrcweir int[] expected = new int[]{226,228,97,32}; 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir for (int i=0;i<toCheck.length();i++) { 233*cdf0e10cSrcweir for (int j=1;j<7;j++) { 234*cdf0e10cSrcweir int get = oObj.getCharacterType(toCheck, i, getLocale(j)); 235*cdf0e10cSrcweir res &= (get == expected[i]); 236*cdf0e10cSrcweir if (!res) { 237*cdf0e10cSrcweir log.println("FAILED for: language=" + languages[j] + 238*cdf0e10cSrcweir " ; country=" + countries[j]); 239*cdf0e10cSrcweir log.println("Sysmbol :" + toCheck.toCharArray()[i]); 240*cdf0e10cSrcweir log.println("Gained: " + get); 241*cdf0e10cSrcweir log.println("Expected : " + expected[i]); 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir tRes.tested("getCharacterType()", res); 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir /** 249*cdf0e10cSrcweir * After defining array of strings to be checked and array of expected types, 250*cdf0e10cSrcweir * test calls the method for each string of an array and for all locales.<p> 251*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns type, expected for a given 252*cdf0e10cSrcweir * string and locale. 253*cdf0e10cSrcweir */ 254*cdf0e10cSrcweir public void _getStringType() { 255*cdf0e10cSrcweir boolean res = true; 256*cdf0e10cSrcweir String[] toCheck = new String[]{"01234","AAAAA","bbbbb","AA()bb"}; 257*cdf0e10cSrcweir int[] exp = new int[]{97,226,228,230}; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir for (int j=0;j<toCheck.length;j++) { 260*cdf0e10cSrcweir for (int i=0;i<7;i++) { 261*cdf0e10cSrcweir int get = oObj.getStringType(toCheck[j], 0, 262*cdf0e10cSrcweir toCheck[j].length(), getLocale(i)); 263*cdf0e10cSrcweir res &= (get == exp[j]); 264*cdf0e10cSrcweir if (!res) { 265*cdf0e10cSrcweir log.println("FAILED for: language=" + languages[i] + 266*cdf0e10cSrcweir " ; country=" + countries[i]); 267*cdf0e10cSrcweir log.println("Expected: " + exp[j]); 268*cdf0e10cSrcweir log.println("Gained : " + get); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir tRes.tested("getStringType()", res); 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir /** 276*cdf0e10cSrcweir * After string to be checked is initialized (all symbols are sorted 277*cdf0e10cSrcweir * by direction, so the character of <code>i<sup><small>th</small></sup></code> 278*cdf0e10cSrcweir * direction is located on <code>i<sup><small>th</small></sup></code> 279*cdf0e10cSrcweir * position), test calls the method for every character of that string. <p> 280*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns direction, that's equal to 281*cdf0e10cSrcweir * a symbol position in the string. 282*cdf0e10cSrcweir */ 283*cdf0e10cSrcweir public void _getCharacterDirection() { 284*cdf0e10cSrcweir boolean res = true; 285*cdf0e10cSrcweir String toCheck = new String(new char[]{65,1470,48,47,35,1632,44,10, 286*cdf0e10cSrcweir 9,12,33,8234,8237,1563,8235,8238,8236,768,1}); 287*cdf0e10cSrcweir for (short i=0;i<19;i++) { 288*cdf0e10cSrcweir short get = oObj.getCharacterDirection(toCheck, i); 289*cdf0e10cSrcweir res &= (get == i); 290*cdf0e10cSrcweir if (!res) { 291*cdf0e10cSrcweir log.println("Code :" + toCheck.toCharArray()[i]); 292*cdf0e10cSrcweir log.println("Gained: " + get); 293*cdf0e10cSrcweir log.println("Expected: " + i); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir tRes.tested("getCharacterDirection()", res); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir /** 300*cdf0e10cSrcweir * At first we define <code>int[]</code> and <code>char[]</code> arrays of 301*cdf0e10cSrcweir * unicode symbol numbers, arranged as sequences, where symbols are sorted 302*cdf0e10cSrcweir * by type, so the character of <code>i<sup><small>th</small></sup></code> 303*cdf0e10cSrcweir * type is located on <code>i<sup><small>th</small></sup></code> position.<p> 304*cdf0e10cSrcweir * Has <b> OK </b> status if for each character method returns value, that 305*cdf0e10cSrcweir * is equal to a number where element is located in array. Also method has 306*cdf0e10cSrcweir * <b> OK </b> status for symbol with code 55296, because it doesn't work 307*cdf0e10cSrcweir * since it hasn't the right neighborhood.<p> 308*cdf0e10cSrcweir * @see http://ppewww.ph.gla.ac.uk/~flavell/unicode/unidata.html 309*cdf0e10cSrcweir */ 310*cdf0e10cSrcweir public void _getScript() { 311*cdf0e10cSrcweir boolean res = true; 312*cdf0e10cSrcweir char[] characters = new char[]{65,128,256,384,592,750,773,924,1030,1331,1448, 313*cdf0e10cSrcweir 1569,1792,1936,2313,2465,2570,2707,2822,2972,3079,3240,3337,3464,3590, 314*cdf0e10cSrcweir 3745,3906,4097,4274,4357,4621,5040,5200,5776,5806,6030,6155,7683,7943, 315*cdf0e10cSrcweir 8202,8319,8352,8413,8452,8545,8616,8715,8965,9217,9281,9336,9474,9608,9719, 316*cdf0e10cSrcweir 9734,9999,10247,11911,12034,12274,12294,12358,12456,12552,12605,12688,12727, 317*cdf0e10cSrcweir 12806,13065,13312,19968,40964,42152,44032,55296,56192,56320,57344,63744, 318*cdf0e10cSrcweir 64257,64370,65056,65073,65131,65146,65532,65288}; 319*cdf0e10cSrcweir int[] charsInt = new int[]{65,128,256,384,592,750,773,924,1030,1331,1448, 320*cdf0e10cSrcweir 1569,1792,1936,2313,2465,2570,2707,2822,2972,3079,3240,3337,3464,3590, 321*cdf0e10cSrcweir 3745,3906,4097,4274,4357,4621,5040,5200,5776,5806,6030,6155,7683,7943, 322*cdf0e10cSrcweir 8202,8319,8352,8413,8452,8545,8616,8715,8965,9217,9281,9336,9474,9608,9719, 323*cdf0e10cSrcweir 9734,9999,10247,11911,12034,12274,12294,12358,12456,12552,12605,12688,12727, 324*cdf0e10cSrcweir 12806,13065,13312,19968,40964,42152,44032,55296,56192,56320,57344,63744, 325*cdf0e10cSrcweir 64257,64370,65056,65073,65131,65146,65532,65288}; 326*cdf0e10cSrcweir String toCheck = new String(characters); 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir for (int i=0;i<characters.length;i++) { 329*cdf0e10cSrcweir int get = oObj.getScript(toCheck, i); 330*cdf0e10cSrcweir res &= (get == i); 331*cdf0e10cSrcweir //The HIGH_SURROGATE 55296 doesn't work since it hasn't the right 332*cdf0e10cSrcweir //neighborhood 333*cdf0e10cSrcweir if (toCheck.substring(i, i + 1).hashCode() == 55296) res = true; 334*cdf0e10cSrcweir if (!res) { 335*cdf0e10cSrcweir log.println("-- " + toCheck.substring(i, i + 1).hashCode()); 336*cdf0e10cSrcweir log.println("Code: " + Integer.toHexString(charsInt[i])); 337*cdf0e10cSrcweir log.println("Gained: " + unicode_script[get]); 338*cdf0e10cSrcweir log.println("Expected: " + unicode_script[i]); 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir tRes.tested("getScript()", res); 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir /** 345*cdf0e10cSrcweir * After defining a string to be parsed and parse conditions (flags), test 346*cdf0e10cSrcweir * calls the method for different locales three times with different parameters, 347*cdf0e10cSrcweir * checking result after every call. <p> 348*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns right results all three 349*cdf0e10cSrcweir * times. 350*cdf0e10cSrcweir */ 351*cdf0e10cSrcweir public void _parseAnyToken() { 352*cdf0e10cSrcweir int nStartFlags = KParseTokens.ANY_ALPHA | KParseTokens.ASC_UNDERSCORE; 353*cdf0e10cSrcweir int nContFlags = KParseTokens.ANY_ALNUM | KParseTokens.ASC_UNDERSCORE 354*cdf0e10cSrcweir | KParseTokens.ASC_DOT; 355*cdf0e10cSrcweir String toCheck = " 18 i18n ^"; 356*cdf0e10cSrcweir ParseResult pRes = null; 357*cdf0e10cSrcweir boolean res = true; 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir for (int i=0;i<7;i++) { 360*cdf0e10cSrcweir pRes = oObj.parseAnyToken(toCheck, 1, getLocale(i), 361*cdf0e10cSrcweir nStartFlags, "", nContFlags, ""); 362*cdf0e10cSrcweir res = ( (pRes.CharLen==2) 363*cdf0e10cSrcweir && (pRes.TokenType==32) 364*cdf0e10cSrcweir && (pRes.Value==18.0) ); 365*cdf0e10cSrcweir pRes = oObj.parseAnyToken(toCheck, 4, getLocale(i), 366*cdf0e10cSrcweir nStartFlags, "", nContFlags, ""); 367*cdf0e10cSrcweir res &= ( (pRes.CharLen==4) 368*cdf0e10cSrcweir && (pRes.TokenType==4) 369*cdf0e10cSrcweir && (pRes.Value==0.0) ); 370*cdf0e10cSrcweir pRes = oObj.parseAnyToken(toCheck, 9, getLocale(i), 371*cdf0e10cSrcweir nStartFlags, "", nContFlags, ""); 372*cdf0e10cSrcweir res &= ( (pRes.CharLen==1) 373*cdf0e10cSrcweir && (pRes.TokenType==1) 374*cdf0e10cSrcweir && (pRes.Value==0.0) ); 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir tRes.tested("parseAnyToken()", res); 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir /** 380*cdf0e10cSrcweir * After defining a string to be parsed and parse conditions (flags), test 381*cdf0e10cSrcweir * calls the method for different locales two times with different parameters, 382*cdf0e10cSrcweir * checking result after every call. <p> 383*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns right results. 384*cdf0e10cSrcweir */ 385*cdf0e10cSrcweir public void _parsePredefinedToken() { 386*cdf0e10cSrcweir int nStartFlags = KParseTokens.ANY_ALPHA | KParseTokens.ASC_UNDERSCORE; 387*cdf0e10cSrcweir int nContFlags = nStartFlags; 388*cdf0e10cSrcweir String toCheck = " 18 int"; 389*cdf0e10cSrcweir ParseResult pRes = null; 390*cdf0e10cSrcweir boolean res = true; 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir for (int i=0;i<7;i++) { 393*cdf0e10cSrcweir pRes = oObj.parsePredefinedToken(KParseType.IDENTNAME, toCheck, 394*cdf0e10cSrcweir 1, getLocale(i), nStartFlags, "", nContFlags, ""); 395*cdf0e10cSrcweir res = (pRes.CharLen==0); 396*cdf0e10cSrcweir pRes = oObj.parsePredefinedToken(KParseType.IDENTNAME, toCheck, 397*cdf0e10cSrcweir 4, getLocale(i), nStartFlags, "", nContFlags, ""); 398*cdf0e10cSrcweir res &= ( (pRes.CharLen==3) 399*cdf0e10cSrcweir && (pRes.TokenType==4) 400*cdf0e10cSrcweir && (pRes.Value==0.0) ); 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir tRes.tested("parsePredefinedToken()", res); 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir /** 407*cdf0e10cSrcweir * Method returns locale for a given language and country. 408*cdf0e10cSrcweir * @param localeIndex index of needed locale. 409*cdf0e10cSrcweir */ 410*cdf0e10cSrcweir private Locale getLocale(int k) { 411*cdf0e10cSrcweir return new Locale(languages[k],countries[k],""); 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir } // end XCharacterClassification 416*cdf0e10cSrcweir 417