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