Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/PluggableLocale/BreakIteratorProviderTest.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.text.resources.*;29import sun.util.locale.provider.*;30import sun.util.resources.*;3132public class BreakIteratorProviderTest extends ProviderTest {3334com.foo.BreakIteratorProviderImpl bip = new com.foo.BreakIteratorProviderImpl();35List<Locale> availloc = Arrays.asList(BreakIterator.getAvailableLocales());36List<Locale> providerloc = Arrays.asList(bip.getAvailableLocales());37List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());38List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getBreakIteratorProvider().getAvailableLocales());3940private static final int CHARACTER_INDEX = 0;41private static final int WORD_INDEX = 1;42private static final int LINE_INDEX = 2;43private static final int SENTENCE_INDEX = 3;4445public static void main(String[] s) {46new BreakIteratorProviderTest();47}4849BreakIteratorProviderTest() {50availableLocalesTest();51objectValidityTest();52}5354void availableLocalesTest() {55Set<Locale> localesFromAPI = new HashSet<>(availloc);56Set<Locale> localesExpected = new HashSet<>(jreloc);57localesExpected.addAll(providerloc);58if (localesFromAPI.equals(localesExpected)) {59System.out.println("availableLocalesTest passed.");60} else {61throw new RuntimeException("availableLocalesTest failed");62}63}6465void objectValidityTest() {6667for (Locale target: availloc) {68// pure JRE implementation69ResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forJRE()).getLocaleData().getBreakIteratorInfo(target);70String[] classNames = rb.getStringArray("BreakIteratorClasses");71boolean jreSupportsLocale = jreimplloc.contains(target);7273// result object74String[] result = new String[4];75result[0] = BreakIterator.getCharacterInstance(target).getClass().getName();76result[1] = BreakIterator.getWordInstance(target).getClass().getName();77result[2] = BreakIterator.getLineInstance(target).getClass().getName();78result[3] = BreakIterator.getSentenceInstance(target).getClass().getName();7980// provider's object (if any)81String[] providersResult = new String[4];82if (providerloc.contains(target)) {83providersResult[0] = bip.getCharacterInstance(target).getClass().getName();84providersResult[1] = bip.getWordInstance(target).getClass().getName();85providersResult[2] = bip.getLineInstance(target).getClass().getName();86providersResult[3] = bip.getSentenceInstance(target).getClass().getName();87}8889// JRE90String[] jresResult = new String[4];91if (jreSupportsLocale) {92for (int i = 0; i < 4; i++) {93jresResult[i] = "sun.util.locale.provider."+classNames[i];94}95}9697for (int i = 0; i < 4; i++) {98checkValidity(target, jresResult[i], providersResult[i], result[i], jreSupportsLocale);99}100}101}102}103104105