/** ******************************************************************************* * Copyright (C) 1996-2010, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ package com.ibm.icu.dev.test.lang; import java.util.Locale; import com.ibm.icu.dev.test.TestFmwk; import com.ibm.icu.lang.UScript; import com.ibm.icu.util.ULocale; public class TestUScript extends TestFmwk { /** * Constructor */ public TestUScript() { } public static void main(String[] args) throws Exception { new TestUScript().run(args); } public void TestLocaleGetCode(){ final ULocale[] testNames={ /* test locale */ new ULocale("en"), new ULocale("en_US"), new ULocale("sr"), new ULocale("ta") , new ULocale("te_IN"), new ULocale("hi"), new ULocale("he"), new ULocale("ar"), new ULocale("abcde"), new ULocale("abcde_cdef"), new ULocale("iw") }; final int[] expected ={ /* locales should return */ UScript.LATIN, UScript.LATIN, UScript.CYRILLIC, UScript.TAMIL, UScript.TELUGU,UScript.DEVANAGARI, UScript.HEBREW, UScript.ARABIC, UScript.INVALID_CODE,UScript.INVALID_CODE, UScript.HEBREW }; int i =0; int numErrors =0; for( ; i0) { // assume missing locale data, so not an error, just a warning if (isModularBuild() || noData()) { // if nodata is set don't even warn warnln("Could not find locale data"); } else { errln("encountered " + numErrors + " errors."); } } } public void TestMultipleCode(){ final String[] testNames = { "ja" ,"ko_KR","zh","zh_TW"}; final int[][] expected = { {UScript.KATAKANA,UScript.HIRAGANA,UScript.HAN}, {UScript.HANGUL, UScript.HAN}, {UScript.HAN}, {UScript.HAN,UScript.BOPOMOFO} }; int numErrors = 0; for(int i=0; i0 ){ warnln("encountered " + numErrors + " errors in UScript.getName()"); } } public void TestGetShortName(){ final int[] testCodes={ /* abbr should return */ UScript.HAN, UScript.HANGUL, UScript.HEBREW, UScript.HIRAGANA, UScript.KANNADA, UScript.KATAKANA, UScript.KHMER, UScript.LAO, UScript.LATIN, UScript.MALAYALAM, UScript.MONGOLIAN, }; final String[] expectedAbbr={ /* test abbr */ "Hani", "Hang","Hebr","Hira", "Knda","Kana","Khmr","Laoo", "Latn", "Mlym", "Mong", }; int i=0; int numErrors=0; while(i0 ){ warnln("encountered " + numErrors + " errors in UScript.getShortName()"); } } public void TestGetScript(){ int codepoints[][] = new int[][] { {0x0000FF9D, UScript.KATAKANA }, {0x0000FFBE, UScript.HANGUL }, {0x0000FFC7, UScript.HANGUL }, {0x0000FFCF, UScript.HANGUL }, {0x0000FFD7, UScript.HANGUL}, {0x0000FFDC, UScript.HANGUL}, {0x00010300, UScript.OLD_ITALIC}, {0x00010330, UScript.GOTHIC}, {0x0001034A, UScript.GOTHIC}, {0x00010400, UScript.DESERET}, {0x00010428, UScript.DESERET}, {0x0001D167, UScript.INHERITED}, {0x0001D17B, UScript.INHERITED}, {0x0001D185, UScript.INHERITED}, {0x0001D1AA, UScript.INHERITED}, {0x00020000, UScript.HAN}, {0x00000D02, UScript.MALAYALAM}, {0x00000D00, UScript.UNKNOWN}, {0x00000000, UScript.COMMON}, {0x0001D169, UScript.INHERITED }, {0x0001D182, UScript.INHERITED }, {0x0001D18B, UScript.INHERITED }, {0x0001D1AD, UScript.INHERITED }, }; int i =0; int code = UScript.INVALID_CODE; boolean passed = true; while(i< codepoints.length){ code = UScript.getScript(codepoints[i][0]); if(code != codepoints[i][1]){ logln("UScript.getScript for codepoint 0x"+ hex(codepoints[i][0])+" failed"); passed = false; } i++; } if(!passed){ errln("UScript.getScript failed."); } } public void TestScriptNames(){ for(int i=0; i=0){ errln("UScript.getScript for codepoint 0x"+ hex(i)+" failed"); } String abbr = UScript.getShortName(code); if(abbr.indexOf("INV")>=0){ errln("UScript.getScript for codepoint 0x"+ hex(i)+" failed"); } } } public void TestNewCode(){ /* * These script codes were originally added to ICU pre-3.6, so that ICU would * have all ISO 15924 script codes. ICU was then based on Unicode 4.1. * These script codes were added with only short names because we don't * want to invent long names ourselves. * Unicode 5 and later encode some of these scripts and give them long names. * Whenever this happens, the long script names here need to be updated. */ String[] expectedLong = new String[]{ "Balinese", "Batk", "Blis", "Brah", "Cham", "Cirt", "Cyrs", "Egyd", "Egyh", "Egyptian_Hieroglyphs", "Geok", "Hans", "Hant", "Hmng", "Hung", "Inds", "Javanese", "Kayah_Li", "Latf", "Latg", "Lepcha", "Lina", "Mand", "Maya", "Mero", "Nko", "Old_Turkic", "Perm", "Phags_Pa", "Phoenician", "Plrd", "Roro", "Sara", "Syre", "Syrj", "Syrn", "Teng", "Vai", "Visp", "Cuneiform", "Zxxx", "Unknown", "Carian", "Jpan", "Tai_Tham", "Lycian", "Lydian", "Ol_Chiki", "Rejang", "Saurashtra", "Sgnw", "Sundanese", "Moon", "Meetei_Mayek", // ICU 4.0 "Imperial_Aramaic", "Avestan", "Cakm", "Kore", "Kaithi", "Mani", "Inscriptional_Pahlavi", "Phlp", "Phlv", "Inscriptional_Parthian", "Samaritan", "Tai_Viet", "Zmth", "Zsym", /* new in ICU 4.4 */ "Bamum", "Lisu", "Nkgb", "Old_South_Arabian", }; String[] expectedShort = new String[]{ "Bali", "Batk", "Blis", "Brah", "Cham", "Cirt", "Cyrs", "Egyd", "Egyh", "Egyp", "Geok", "Hans", "Hant", "Hmng", "Hung", "Inds", "Java", "Kali", "Latf", "Latg", "Lepc", "Lina", "Mand", "Maya", "Mero", "Nkoo", "Orkh", "Perm", "Phag", "Phnx", "Plrd", "Roro", "Sara", "Syre", "Syrj", "Syrn", "Teng", "Vaii", "Visp", "Xsux", "Zxxx", "Zzzz", "Cari", "Jpan", "Lana", "Lyci", "Lydi", "Olck", "Rjng", "Saur", "Sgnw", "Sund", "Moon", "Mtei", // ICU 4.0 "Armi", "Avst", "Cakm", "Kore", "Kthi", "Mani", "Phli", "Phlp", "Phlv", "Prti", "Samr", "Tavt", "Zmth", "Zsym", /* new in ICU 4.4 */ "Bamu", "Lisu", "Nkgb", "Sarb", }; if(expectedLong.length!=(UScript.CODE_LIMIT-UScript.BALINESE)) { errln("need to add new script codes in lang.TestUScript.java!"); return; } int j = 0; int i = 0; for(i=UScript.BALINESE; i