Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/PluggableLocale/CollatorProviderTest.java
47209 views
/*1* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23*24*/2526import java.text.*;27import java.util.*;28import sun.util.locale.provider.*;29import sun.util.resources.*;3031public class CollatorProviderTest extends ProviderTest {3233com.foo.CollatorProviderImpl cp = new com.foo.CollatorProviderImpl();34List<Locale> availloc = Arrays.asList(Collator.getAvailableLocales());35List<Locale> providerloc = Arrays.asList(cp.getAvailableLocales());36List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());37List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getCollatorProvider().getAvailableLocales());3839public static void main(String[] s) {40new CollatorProviderTest();41}4243CollatorProviderTest() {44availableLocalesTest();45objectValidityTest();46}4748void availableLocalesTest() {49Set<Locale> localesFromAPI = new HashSet<>(availloc);50Set<Locale> localesExpected = new HashSet<>(jreloc);51localesExpected.addAll(providerloc);52if (localesFromAPI.equals(localesExpected)) {53System.out.println("availableLocalesTest passed.");54} else {55throw new RuntimeException("availableLocalesTest failed");56}57}5859void objectValidityTest() {60Collator def = Collator.getInstance(new Locale(""));61String defrules = ((RuleBasedCollator)def).getRules();6263for (Locale target: availloc) {64// pure JRE implementation65Set<Locale> jreimplloc = new HashSet<>();66for (String tag : ((AvailableLanguageTags)LocaleProviderAdapter.forJRE().getCollatorProvider()).getAvailableLanguageTags()) {67jreimplloc.add(Locale.forLanguageTag(tag));68}69ResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forJRE()).getLocaleData().getCollationData(target);70boolean jreSupportsLocale = jreimplloc.contains(target);7172// result object73Collator result = Collator.getInstance(target);7475// provider's object (if any)76Collator providersResult = null;77if (providerloc.contains(target)) {78providersResult = cp.getInstance(target);79}8081// JRE rule82Collator jresResult = null;83if (jreSupportsLocale) {84try {85String rules = rb.getString("Rule");86jresResult = new RuleBasedCollator(defrules+rules);87jresResult.setDecomposition(Collator.NO_DECOMPOSITION);88} catch (MissingResourceException mre) {89} catch (ParseException pe) {90}91}9293checkValidity(target, jresResult, providersResult, result, jreSupportsLocale);94}95}96}979899