1 // 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 /* 4 ******************************************************************************* 5 * Copyright (C) 2009, International Business Machines Corporation and * 6 * others. All Rights Reserved. * 7 ******************************************************************************* 8 */ 9 10 package com.ibm.icu.dev.test.util; 11 12 import java.util.HashMap; 13 14 import org.junit.Before; 15 import org.junit.Test; 16 import org.junit.runner.RunWith; 17 import org.junit.runners.JUnit4; 18 19 import com.ibm.icu.text.Collator; 20 import com.ibm.icu.util.ULocale; 21 22 @RunWith(JUnit4.class) 23 public class LocaleAliasCollationTest extends com.ibm.icu.dev.test.TestFmwk { 24 private static final ULocale[][] _LOCALES = { 25 {new ULocale("en", "RH"), new ULocale("en", "ZW")}, 26 {new ULocale("in"), new ULocale("id")}, 27 {new ULocale("in", "ID"), new ULocale("id", "ID")}, 28 {new ULocale("iw"), new ULocale("he")}, 29 {new ULocale("iw", "IL"), new ULocale("he", "IL")}, 30 {new ULocale("ji"), new ULocale("yi")}, 31 32 {new ULocale("en", "BU"), new ULocale("en", "MM")}, 33 {new ULocale("en", "DY"), new ULocale("en", "BJ")}, 34 {new ULocale("en", "HV"), new ULocale("en", "BF")}, 35 {new ULocale("en", "NH"), new ULocale("en", "VU")}, 36 {new ULocale("en", "TP"), new ULocale("en", "TL")}, 37 {new ULocale("en", "ZR"), new ULocale("en", "CD")} 38 }; 39 40 private static final int _LOCALE_NUMBER = _LOCALES.length; 41 private ULocale[] available = null; 42 private HashMap availableMap = new HashMap(); 43 private static final ULocale _DEFAULT_LOCALE = ULocale.US; 44 45 public LocaleAliasCollationTest() { 46 } 47 48 @Before 49 public void init() { 50 available = ULocale.getAvailableLocales(); 51 for(int i=0; i<available.length;i++){ 52 availableMap.put(available[i].toString(),""); 53 } 54 } 55 56 @Test 57 public void TestCollation() { 58 ULocale defLoc = ULocale.getDefault(); 59 ULocale.setDefault(_DEFAULT_LOCALE); 60 for (int i=0; i<_LOCALE_NUMBER; i++) { 61 ULocale oldLoc = _LOCALES[i][0]; 62 ULocale newLoc = _LOCALES[i][1]; 63 if(availableMap.get(_LOCALES[i][1])==null){ 64 logln(_LOCALES[i][1]+" is not available. Skipping!"); 65 continue; 66 } 67 Collator c1 = Collator.getInstance(oldLoc); 68 Collator c2 = Collator.getInstance(newLoc); 69 70 if (!c1.equals(c2)) { 71 errln("CollationTest: c1!=c2: newLoc= "+newLoc +" oldLoc= "+oldLoc); 72 } 73 74 logln("Collation old:"+oldLoc+" new:"+newLoc); 75 } 76 ULocale.setDefault(defLoc); 77 } 78 } 79