]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScript.java
Upgrade ICU4J.
[Dictionary.git] / jars / icu4j-52_1 / main / tests / core / src / com / ibm / icu / dev / test / lang / TestUScript.java
1 /**
2 *******************************************************************************
3 * Copyright (C) 1996-2013, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
6 */
7
8 package com.ibm.icu.dev.test.lang;
9
10 import java.util.BitSet;
11 import java.util.Locale;
12
13 import com.ibm.icu.dev.test.TestFmwk;
14 import com.ibm.icu.lang.UProperty;
15 import com.ibm.icu.lang.UScript;
16 import com.ibm.icu.lang.UScript.ScriptUsage;
17 import com.ibm.icu.text.UnicodeSet;
18 import com.ibm.icu.util.ULocale;
19
20 public class TestUScript extends TestFmwk {
21
22     /**
23     * Constructor
24     */
25     public TestUScript()
26     {
27     }
28
29     public static void main(String[] args) throws Exception {
30         new TestUScript().run(args);
31     }
32     public void TestLocaleGetCode(){
33         final ULocale[] testNames={
34         /* test locale */
35         new ULocale("en"), new ULocale("en_US"),
36         new ULocale("sr"), new ULocale("ta") ,
37         new ULocale("te_IN"),
38         new ULocale("hi"),
39         new ULocale("he"), new ULocale("ar"),
40         new ULocale("abcde"),
41         new ULocale("abcde_cdef"),
42         new ULocale("iw")
43         };
44         final int[] expected ={
45                 /* locales should return */
46                 UScript.LATIN, UScript.LATIN,
47                 UScript.CYRILLIC, UScript.TAMIL,
48                 UScript.TELUGU,UScript.DEVANAGARI,
49                 UScript.HEBREW, UScript.ARABIC,
50                 UScript.INVALID_CODE,UScript.INVALID_CODE,
51                 UScript.HEBREW
52         };
53         int i =0;
54         int numErrors =0;
55
56         for( ; i<testNames.length; i++){
57             int[] code = UScript.getCode(testNames[i]);
58
59             if(code==null){
60                 if(expected[i]!=UScript.INVALID_CODE){
61                     logln("Error getting script code Got: null" + " Expected: " +expected[i] +" for name "+testNames[i]);
62                     numErrors++;
63                 }
64                 // getCode returns null if the code could not be found
65                 continue;
66             }
67             if((code[0] != expected[i])){
68                 logln("Error getting script code Got: " +code[0] + " Expected: " +expected[i] +" for name "+testNames[i]);
69                 numErrors++;
70             }
71         }
72         reportDataErrors(numErrors);
73         
74         // 
75         ULocale defaultLoc = ULocale.getDefault(); 
76         ULocale esparanto = new ULocale("eo_DE");
77         ULocale.setDefault(esparanto);
78         int[] code = UScript.getCode(esparanto); 
79         if(code != null){
80             if( code[0] != UScript.LATIN){
81                 errln("Did not get the expected script code for Esparanto");
82             }
83         }else{
84             warnln("Could not load the locale data.");
85         }
86         ULocale.setDefault(defaultLoc);
87     }
88
89     private void reportDataErrors(int numErrors) {
90         if (numErrors >0) {
91             // assume missing locale data, so not an error, just a warning
92             if (isModularBuild() || noData()) {
93                 // if nodata is set don't even warn
94                 warnln("Could not find locale data");
95             } else {
96                 errln("encountered " + numErrors + " errors.");
97             }
98         }
99     }
100
101     public void TestMultipleCode(){
102         final String[] testNames = { "ja" ,"ko_KR","zh","zh_TW"};
103         final int[][] expected = {
104                                 {UScript.KATAKANA,UScript.HIRAGANA,UScript.HAN},
105                                 {UScript.HANGUL, UScript.HAN},
106                                 {UScript.HAN},
107                                 {UScript.HAN,UScript.BOPOMOFO}
108                               };
109
110         int numErrors = 0;
111         for(int i=0; i<testNames.length;i++){
112             int[] code = UScript.getCode(testNames[i]);
113             int[] expt = (int[]) expected[i];
114             if(code!=null){
115                 for(int j =0; j< code.length;j++){
116                     if(code[j]!=expt[j]){
117                         numErrors++;
118                         logln("Error getting script code Got: " +code[j] + " Expected: " +expt[j] +" for name "+testNames[i]);
119                     }
120                 }
121             }else{
122                 numErrors++;
123                 logln("Error getting script code for name "+testNames[i]);
124             }
125         }
126         reportDataErrors(numErrors);
127         
128         //cover UScript.getCode(Locale)
129         Locale[] testLocales = new Locale[] {
130             Locale.JAPANESE,
131             Locale.KOREA,
132             Locale.CHINESE,
133             Locale.TAIWAN };
134         logln("Testing UScript.getCode(Locale) ...");
135         numErrors = 0;
136         for(int i=0; i<testNames.length;i++){
137             logln("  Testing locale: " + testLocales[i].getDisplayName());
138             int[] code = UScript.getCode(testLocales[i]);
139             int[] expt = (int[]) expected[i];
140             if(code!=null){
141                 for(int j =0; j< code.length;j++){
142                     if(code[j]!=expt[j]){
143                         numErrors++;
144                         logln("  Error getting script code Got: " +code[j] + " Expected: " +expt[j] +" for name "+testNames[i]);
145                     }
146                 }
147             }else{
148                 numErrors++;
149                 logln("  Error getting script code for name "+testNames[i]);
150             }
151         }
152         reportDataErrors(numErrors);                 
153     }
154
155     public void TestGetCode(){
156
157         final String[] testNames={
158             /* test locale */
159             "en", "en_US", "sr", "ta", "gu", "te_IN", 
160             "hi", "he", "ar",
161             /* test abbr */
162             "Hani", "Hang","Hebr","Hira",
163             "Knda","Kana","Khmr","Lao",
164             "Latn",/*"Latf","Latg",*/
165             "Mlym", "Mong",
166
167             /* test names */
168             "CYRILLIC","DESERET","DEVANAGARI","ETHIOPIC","GEORGIAN",
169             "GOTHIC",  "GREEK",  "GUJARATI", "COMMON", "INHERITED",
170             /* test lower case names */
171             "malayalam", "mongolian", "myanmar", "ogham", "old-italic",
172             "oriya",     "runic",     "sinhala", "syriac","tamil",
173             "telugu",    "thaana",    "thai",    "tibetan",
174             /* test the bounds*/
175             "Cans", "arabic","Yi","Zyyy"
176         };
177         final int[] expected ={
178             /* locales should return */
179             UScript.LATIN, UScript.LATIN,
180             UScript.CYRILLIC, UScript.TAMIL, UScript.GUJARATI,
181             UScript.TELUGU,UScript.DEVANAGARI,
182             UScript.HEBREW, UScript.ARABIC,
183             /* abbr should return */
184             UScript.HAN, UScript.HANGUL, UScript.HEBREW, UScript.HIRAGANA,
185             UScript.KANNADA, UScript.KATAKANA, UScript.KHMER, UScript.LAO,
186             UScript.LATIN,/* UScript.LATIN, UScript.LATIN,*/
187             UScript.MALAYALAM, UScript.MONGOLIAN,
188             /* names should return */
189             UScript.CYRILLIC, UScript.DESERET, UScript.DEVANAGARI, UScript.ETHIOPIC, UScript.GEORGIAN,
190             UScript.GOTHIC, UScript.GREEK, UScript.GUJARATI, UScript.COMMON, UScript.INHERITED,
191             /* lower case names should return */
192             UScript.MALAYALAM, UScript.MONGOLIAN, UScript.MYANMAR, UScript.OGHAM, UScript.OLD_ITALIC,
193             UScript.ORIYA, UScript.RUNIC, UScript.SINHALA, UScript.SYRIAC, UScript.TAMIL,
194             UScript.TELUGU, UScript.THAANA, UScript.THAI, UScript.TIBETAN,
195             /* bounds */
196             UScript.CANADIAN_ABORIGINAL, UScript.ARABIC, UScript.YI, UScript.COMMON
197         };
198         int i =0;
199         int numErrors =0;
200
201         for( ; i<testNames.length; i++){
202             int[] code = UScript.getCode(testNames[i]);
203             if(code == null){
204                 if(expected[i]==UScript.INVALID_CODE){
205                     // getCode returns null if the code could not be found
206                     continue;
207                 }
208                 // currently commented out until jitterbug#2678 is fixed
209                 logln("Error getting script code Got: null" + " Expected: " +expected[i] +" for name "+testNames[i]);
210                 numErrors++;
211                 continue;
212             }
213             if((code[0] != expected[i])){
214                 logln("Error getting script code Got: " +code[0] + " Expected: " +expected[i] +" for name "+testNames[i]);
215                 numErrors++;
216             }
217         }
218         reportDataErrors(numErrors);
219     }
220
221     public void TestGetName(){
222
223         final int[] testCodes={
224             /* names should return */
225             UScript.CYRILLIC, UScript.DESERET, UScript.DEVANAGARI, UScript.ETHIOPIC, UScript.GEORGIAN,
226             UScript.GOTHIC, UScript.GREEK, UScript.GUJARATI,
227         };
228
229         final String[] expectedNames={
230
231             /* test names */
232             "Cyrillic","Deseret","Devanagari","Ethiopic","Georgian",
233             "Gothic",  "Greek",  "Gujarati",
234         };
235         int i =0;
236         int numErrors=0;
237         while(i< testCodes.length){
238             String scriptName  = UScript.getName(testCodes[i]);
239             if(!expectedNames[i].equals(scriptName)){
240                 logln("Error getting abbreviations Got: " +scriptName +" Expected: "+expectedNames[i]);
241                 numErrors++;
242             }
243             i++;
244         }
245         if(numErrors >0 ){
246             warnln("encountered " + numErrors + " errors in UScript.getName()");
247         }
248
249     }
250     public void TestGetShortName(){
251         final int[] testCodes={
252             /* abbr should return */
253             UScript.HAN, UScript.HANGUL, UScript.HEBREW, UScript.HIRAGANA,
254             UScript.KANNADA, UScript.KATAKANA, UScript.KHMER, UScript.LAO,
255             UScript.LATIN,
256             UScript.MALAYALAM, UScript.MONGOLIAN,
257         };
258
259         final String[] expectedAbbr={
260               /* test abbr */
261             "Hani", "Hang","Hebr","Hira",
262             "Knda","Kana","Khmr","Laoo",
263             "Latn",
264             "Mlym", "Mong",
265         };
266         int i=0;
267         int numErrors=0;
268         while(i<testCodes.length){
269             String  shortName = UScript.getShortName(testCodes[i]);
270             if(!expectedAbbr[i].equals(shortName)){
271                 logln("Error getting abbreviations Got: " +shortName+ " Expected: " +expectedAbbr[i]);
272                 numErrors++;
273             }
274             i++;
275         }
276         if(numErrors >0 ){
277             warnln("encountered " + numErrors + " errors in UScript.getShortName()");
278         }
279     }
280     public void TestGetScript(){
281         int codepoints[][] = new int[][] {
282                 {0x0000FF9D, UScript.KATAKANA },
283                 {0x0000FFBE, UScript.HANGUL },
284                 {0x0000FFC7, UScript.HANGUL },
285                 {0x0000FFCF, UScript.HANGUL },
286                 {0x0000FFD7, UScript.HANGUL}, 
287                 {0x0000FFDC, UScript.HANGUL},
288                 {0x00010300, UScript.OLD_ITALIC},
289                 {0x00010330, UScript.GOTHIC},
290                 {0x0001034A, UScript.GOTHIC},
291                 {0x00010400, UScript.DESERET},
292                 {0x00010428, UScript.DESERET},
293                 {0x0001D167, UScript.INHERITED},
294                 {0x0001D17B, UScript.INHERITED},
295                 {0x0001D185, UScript.INHERITED},
296                 {0x0001D1AA, UScript.INHERITED},
297                 {0x00020000, UScript.HAN},
298                 {0x00000D02, UScript.MALAYALAM},
299                 {0x00000D00, UScript.UNKNOWN},
300                 {0x00000000, UScript.COMMON},
301                 {0x0001D169, UScript.INHERITED },
302                 {0x0001D182, UScript.INHERITED },
303                 {0x0001D18B, UScript.INHERITED },
304                 {0x0001D1AD, UScript.INHERITED },
305         };
306
307         int i =0;
308         int code = UScript.INVALID_CODE;
309         boolean passed = true;
310
311         while(i< codepoints.length){
312             code = UScript.getScript(codepoints[i][0]);
313
314             if(code != codepoints[i][1]){
315                 logln("UScript.getScript for codepoint 0x"+ hex(codepoints[i][0])+" failed");
316                 passed = false;
317             }
318
319             i++;
320         }
321         if(!passed){
322            errln("UScript.getScript failed.");
323         }
324     }
325
326     public void TestGetScriptOfCharsWithScriptExtensions() {
327         /* test characters which have Script_Extensions */
328         if(!(
329             UScript.COMMON==UScript.getScript(0x0640) &&
330             UScript.INHERITED==UScript.getScript(0x0650) &&
331             UScript.ARABIC==UScript.getScript(0xfdf2))
332         ) {
333             errln("UScript.getScript(character with Script_Extensions) failed");
334         }
335     }
336
337     public void TestHasScript() {
338         if(!(
339             !UScript.hasScript(0x063f, UScript.COMMON) &&
340             UScript.hasScript(0x063f, UScript.ARABIC) &&  /* main Script value */
341             !UScript.hasScript(0x063f, UScript.SYRIAC) &&
342             !UScript.hasScript(0x063f, UScript.THAANA))
343         ) {
344             errln("UScript.hasScript(U+063F, ...) is wrong");
345         }
346         if(!(
347             !UScript.hasScript(0x0640, UScript.COMMON) &&  /* main Script value */
348             UScript.hasScript(0x0640, UScript.ARABIC) &&
349             UScript.hasScript(0x0640, UScript.SYRIAC) &&
350             !UScript.hasScript(0x0640, UScript.THAANA))
351         ) {
352             errln("UScript.hasScript(U+0640, ...) is wrong");
353         }
354         if(!(
355             !UScript.hasScript(0x0650, UScript.INHERITED) &&  /* main Script value */
356             UScript.hasScript(0x0650, UScript.ARABIC) &&
357             UScript.hasScript(0x0650, UScript.SYRIAC) &&
358             !UScript.hasScript(0x0650, UScript.THAANA))
359         ) {
360             errln("UScript.hasScript(U+0650, ...) is wrong");
361         }
362         if(!(
363             !UScript.hasScript(0x0660, UScript.COMMON) &&  /* main Script value */
364             UScript.hasScript(0x0660, UScript.ARABIC) &&
365             !UScript.hasScript(0x0660, UScript.SYRIAC) &&
366             UScript.hasScript(0x0660, UScript.THAANA))
367         ) {
368             errln("UScript.hasScript(U+0660, ...) is wrong");
369         }
370         if(!(
371             !UScript.hasScript(0xfdf2, UScript.COMMON) &&
372             UScript.hasScript(0xfdf2, UScript.ARABIC) &&  /* main Script value */
373             !UScript.hasScript(0xfdf2, UScript.SYRIAC) &&
374             UScript.hasScript(0xfdf2, UScript.THAANA))
375         ) {
376             errln("UScript.hasScript(U+FDF2, ...) is wrong");
377         }
378         if(UScript.hasScript(0x0640, 0xaffe)) {
379             // An unguarded implementation might go into an infinite loop.
380             errln("UScript.hasScript(U+0640, bogus 0xaffe) is wrong");
381         }
382     }
383
384     public void TestGetScriptExtensions() {
385         BitSet scripts=new BitSet(UScript.CODE_LIMIT);
386
387         /* invalid code points */
388         if(UScript.getScriptExtensions(-1, scripts)!=UScript.UNKNOWN || scripts.cardinality()!=1 ||
389                 !scripts.get(UScript.UNKNOWN)) {
390             errln("UScript.getScriptExtensions(-1) is not {UNKNOWN}");
391         }
392         if(UScript.getScriptExtensions(0x110000, scripts)!=UScript.UNKNOWN || scripts.cardinality()!=1 ||
393                 !scripts.get(UScript.UNKNOWN)) {
394             errln("UScript.getScriptExtensions(0x110000) is not {UNKNOWN}");
395         }
396
397         /* normal usage */
398         if(UScript.getScriptExtensions(0x063f, scripts)!=UScript.ARABIC || scripts.cardinality()!=1 ||
399                 !scripts.get(UScript.ARABIC)) {
400             errln("UScript.getScriptExtensions(U+063F) is not {ARABIC}");
401         }
402         if(UScript.getScriptExtensions(0x0640, scripts)!=-3 || scripts.cardinality()!=3 ||
403            !scripts.get(UScript.ARABIC) || !scripts.get(UScript.SYRIAC) || !scripts.get(UScript.MANDAIC)
404         ) {
405             errln("UScript.getScriptExtensions(U+0640) failed");
406         }
407         if(UScript.getScriptExtensions(0xfdf2, scripts)!=-2 || scripts.cardinality()!=2 ||
408                 !scripts.get(UScript.ARABIC) || !scripts.get(UScript.THAANA)) {
409             errln("UScript.getScriptExtensions(U+FDF2) failed");
410         }
411         if(UScript.getScriptExtensions(0xff65, scripts)!=-6 || scripts.cardinality()!=6 ||
412                 !scripts.get(UScript.BOPOMOFO) || !scripts.get(UScript.YI)) {
413             errln("UScript.getScriptExtensions(U+FF65) failed");
414         }
415     }
416
417     public void TestScriptMetadataAPI() {
418         /* API & code coverage. */
419         String sample = UScript.getSampleString(UScript.LATIN);
420         if(sample.length()!=1 || UScript.getScript(sample.charAt(0))!=UScript.LATIN) {
421             errln("UScript.getSampleString(Latn) failed");
422         }
423         sample = UScript.getSampleString(UScript.INVALID_CODE);
424         if(sample.length()!=0) {
425             errln("UScript.getSampleString(invalid) failed");
426         }
427
428         if(UScript.getUsage(UScript.LATIN)!=ScriptUsage.RECOMMENDED ||
429                 UScript.getUsage(UScript.YI)!=ScriptUsage.ASPIRATIONAL ||
430                 UScript.getUsage(UScript.CHEROKEE)!=ScriptUsage.LIMITED_USE ||
431                 UScript.getUsage(UScript.COPTIC)!=ScriptUsage.EXCLUDED ||
432                 UScript.getUsage(UScript.CIRTH)!=ScriptUsage.NOT_ENCODED ||
433                 UScript.getUsage(UScript.INVALID_CODE)!=ScriptUsage.NOT_ENCODED ||
434                 UScript.getUsage(UScript.CODE_LIMIT)!=ScriptUsage.NOT_ENCODED) {
435             errln("UScript.getUsage() failed");
436         }
437
438         if(UScript.isRightToLeft(UScript.LATIN) ||
439                 UScript.isRightToLeft(UScript.CIRTH) ||
440                 !UScript.isRightToLeft(UScript.ARABIC) ||
441                 !UScript.isRightToLeft(UScript.HEBREW)) {
442             errln("UScript.isRightToLeft() failed");
443         }
444
445         if(UScript.breaksBetweenLetters(UScript.LATIN) ||
446                 UScript.breaksBetweenLetters(UScript.CIRTH) ||
447                 !UScript.breaksBetweenLetters(UScript.HAN) ||
448                 !UScript.breaksBetweenLetters(UScript.THAI)) {
449             errln("UScript.breaksBetweenLetters() failed");
450         }
451
452         if(UScript.isCased(UScript.CIRTH) ||
453                 UScript.isCased(UScript.HAN) ||
454                 !UScript.isCased(UScript.LATIN) ||
455                 !UScript.isCased(UScript.GREEK)) {
456             errln("UScript.isCased() failed");
457         }
458     }
459
460     /**
461      * Maps a special script code to the most common script of its encoded characters.
462      */
463     private static final int getCharScript(int script) {
464         switch(script) {
465         case UScript.SIMPLIFIED_HAN:
466         case UScript.TRADITIONAL_HAN:
467             return UScript.HAN;
468         case UScript.JAPANESE:
469             return UScript.HIRAGANA;
470         case UScript.KOREAN:
471             return UScript.HANGUL;
472         default:
473             return script;
474         }
475     }
476
477     public void TestScriptMetadata() {
478         UnicodeSet rtl = new UnicodeSet("[[:bc=R:][:bc=AL:]-[:Cn:]-[:sc=Common:]]");
479         // So far, sample characters are uppercase.
480         // Georgian is special.
481         UnicodeSet cased = new UnicodeSet("[[:Lu:]-[:sc=Common:]-[:sc=Geor:]]");
482         for(int sc = 0; sc < UScript.CODE_LIMIT; ++sc) {
483             String sn = UScript.getShortName(sc);
484             ScriptUsage usage = UScript.getUsage(sc);
485             String sample = UScript.getSampleString(sc);
486             UnicodeSet scriptSet = new UnicodeSet();
487             scriptSet.applyIntPropertyValue(UProperty.SCRIPT, sc);
488             if(usage == ScriptUsage.NOT_ENCODED) {
489                 assertTrue(sn + " not encoded, no sample", sample.length() == 0);  // Java 6: sample.isEmpty()
490                 assertFalse(sn + " not encoded, not RTL", UScript.isRightToLeft(sc));
491                 assertFalse(sn + " not encoded, not LB letters", UScript.breaksBetweenLetters(sc));
492                 assertFalse(sn + " not encoded, not cased", UScript.isCased(sc));
493                 assertTrue(sn + " not encoded, no characters", scriptSet.isEmpty());
494             } else {
495                 assertFalse(sn + " encoded, has a sample character", sample.length() == 0);  // Java 6: sample.isEmpty()
496                 int firstChar = sample.codePointAt(0);
497                 int charScript = getCharScript(sc);
498                 assertEquals(sn + " script(sample(script))",
499                              charScript, UScript.getScript(firstChar));
500                 assertEquals(sn + " RTL vs. set", rtl.contains(firstChar), UScript.isRightToLeft(sc));
501                 assertEquals(sn + " cased vs. set", cased.contains(firstChar), UScript.isCased(sc));
502                 assertEquals(sn + " encoded, has characters", sc == charScript, !scriptSet.isEmpty());
503                 if(UScript.isRightToLeft(sc)) {
504                     rtl.removeAll(scriptSet);
505                 }
506                 if(UScript.isCased(sc)) {
507                     cased.removeAll(scriptSet);
508                 }
509             }
510         }
511         assertEquals("no remaining RTL characters", "[]", rtl.toPattern(true));
512         assertEquals("no remaining cased characters", "[]", cased.toPattern(true));
513
514         assertTrue("Hani breaks between letters", UScript.breaksBetweenLetters(UScript.HAN));
515         assertTrue("Thai breaks between letters", UScript.breaksBetweenLetters(UScript.THAI));
516         assertFalse("Latn does not break between letters", UScript.breaksBetweenLetters(UScript.LATIN));
517     }
518
519     public void TestScriptNames(){
520         for(int i=0; i<UScript.CODE_LIMIT;i++){
521             String name = UScript.getName(i);
522             if(name.equals("") ){
523                 errln("FAILED: getName for code : "+i);
524             }
525             String shortName= UScript.getShortName(i);
526             if(shortName.equals("")){
527                 errln("FAILED: getName for code : "+i);
528             }
529         }
530     }
531     public void TestAllCodepoints(){
532         int code;
533         //String oldId="";
534         //String oldAbbrId="";
535         for( int i =0; i <= 0x10ffff; i++){
536           code =UScript.INVALID_CODE;
537           code = UScript.getScript(i);
538           if(code==UScript.INVALID_CODE){
539                 errln("UScript.getScript for codepoint 0x"+ hex(i)+" failed");
540           }
541           String id =UScript.getName(code);
542           if(id.indexOf("INVALID")>=0){
543                  errln("UScript.getScript for codepoint 0x"+ hex(i)+" failed");
544           }
545           String abbr = UScript.getShortName(code);
546           if(abbr.indexOf("INV")>=0){
547                  errln("UScript.getScript for codepoint 0x"+ hex(i)+" failed");
548           }
549         }
550     }
551     public void TestNewCode(){
552         /*
553          * These script codes were originally added to ICU pre-3.6, so that ICU would
554          * have all ISO 15924 script codes. ICU was then based on Unicode 4.1.
555          * These script codes were added with only short names because we don't
556          * want to invent long names ourselves.
557          * Unicode 5 and later encode some of these scripts and give them long names.
558          * Whenever this happens, the long script names here need to be updated.
559          */
560         String[] expectedLong = new String[]{
561             "Balinese", "Batak", "Blis", "Brahmi", "Cham", "Cirt", "Cyrs", "Egyd", "Egyh", "Egyptian_Hieroglyphs", 
562             "Geok", "Hans", "Hant", "Hmng", "Hung", "Inds", "Javanese", "Kayah_Li", "Latf", "Latg", 
563             "Lepcha", "Lina", "Mandaic", "Maya", "Meroitic_Hieroglyphs", "Nko", "Old_Turkic", "Perm", "Phags_Pa", "Phoenician", 
564             "Miao", "Roro", "Sara", "Syre", "Syrj", "Syrn", "Teng", "Vai", "Visp", "Cuneiform", 
565             "Zxxx", "Unknown",
566             "Carian", "Jpan", "Tai_Tham", "Lycian", "Lydian", "Ol_Chiki", "Rejang", "Saurashtra", "Sgnw", "Sundanese",
567             "Moon", "Meetei_Mayek",
568
569             // ICU 4.0
570             "Imperial_Aramaic", "Avestan", "Chakma", "Kore",
571             "Kaithi", "Mani", "Inscriptional_Pahlavi", "Phlp", "Phlv", "Inscriptional_Parthian", "Samaritan", "Tai_Viet",
572             "Zmth", "Zsym",
573             /* new in ICU 4.4 */
574             "Bamum", "Lisu", "Nkgb", "Old_South_Arabian",
575             /* new in ICU 4.6 */
576             "Bass", "Dupl", "Elba", "Gran", "Kpel", "Loma", "Mend", "Meroitic_Cursive",
577             "Narb", "Nbat", "Palm", "Sind", "Wara",
578             /* new in ICU 4.8 */
579             "Afak", "Jurc", "Mroo", "Nshu", "Sharada", "Sora_Sompeng", "Takri", "Tang", "Wole",
580             /* new in ICU 49 */
581             "Hluw", "Khoj", "Tirh",
582             /* new in ICU 52 */
583             "Aghb", "Mahj"
584         };
585         String[] expectedShort = new String[]{
586             "Bali", "Batk", "Blis", "Brah", "Cham", "Cirt", "Cyrs", "Egyd", "Egyh", "Egyp", 
587             "Geok", "Hans", "Hant", "Hmng", "Hung", "Inds", "Java", "Kali", "Latf", "Latg", 
588             "Lepc", "Lina", "Mand", "Maya", "Mero", "Nkoo", "Orkh", "Perm", "Phag", "Phnx", 
589             "Plrd", "Roro", "Sara", "Syre", "Syrj", "Syrn", "Teng", "Vaii", "Visp", "Xsux", 
590             "Zxxx", "Zzzz",
591             "Cari", "Jpan", "Lana", "Lyci", "Lydi", "Olck", "Rjng", "Saur", "Sgnw", "Sund",
592             "Moon", "Mtei", 
593
594             // ICU 4.0
595             "Armi", "Avst", "Cakm", "Kore", "Kthi", "Mani", "Phli", "Phlp", "Phlv", "Prti",
596             "Samr", "Tavt", "Zmth", "Zsym",
597             /* new in ICU 4.4 */
598             "Bamu", "Lisu", "Nkgb", "Sarb", 
599             /* new in ICU 4.6 */
600             "Bass", "Dupl", "Elba", "Gran", "Kpel", "Loma", "Mend", "Merc",
601             "Narb", "Nbat", "Palm", "Sind", "Wara",
602             /* new in ICU 4.8 */
603             "Afak", "Jurc", "Mroo", "Nshu", "Shrd", "Sora", "Takr", "Tang", "Wole",
604             /* new in ICU 49 */
605             "Hluw", "Khoj", "Tirh",
606             /* new in ICU 52 */
607             "Aghb", "Mahj"
608         };
609         if(expectedLong.length!=(UScript.CODE_LIMIT-UScript.BALINESE)) {
610             errln("need to add new script codes in lang.TestUScript.java!");
611             return;
612         }
613         int j = 0;
614         int i = 0;
615         for(i=UScript.BALINESE; i<UScript.CODE_LIMIT; i++, j++){
616             String name = UScript.getName(i);
617             if(name==null || !name.equals(expectedLong[j])){
618                 errln("UScript.getName failed for code"+ i + name +"!=" +expectedLong[j]);
619             }
620             name = UScript.getShortName(i);
621             if(name==null || !name.equals(expectedShort[j])){
622                 errln("UScript.getShortName failed for code"+ i + name +"!=" +expectedShort[j]);
623             }
624         }
625         for(i=0; i<expectedLong.length; i++){
626             int[] ret = UScript.getCode(expectedShort[i]);
627             if(ret.length>1){
628                 errln("UScript.getCode did not return expected number of codes for script"+ expectedShort[i]+". EXPECTED: 1 GOT: "+ ret.length);
629             }
630             if(ret[0]!= (UScript.BALINESE+i)){
631                 errln("UScript.getCode did not return expected code for script"+ expectedShort[i]+". EXPECTED: "+ (UScript.BALINESE+i)+" GOT: %i\n"+ ret[0] );
632             }
633         }
634     }
635 }