Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/PluggableLocale/GenericTest.java
47209 views
/*1* Copyright (c) 2007, 2012, 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.*;2930public class GenericTest {3132// test providers33com.foo.BreakIteratorProviderImpl breakIP = new com.foo.BreakIteratorProviderImpl();34com.foo.CollatorProviderImpl collatorP = new com.foo.CollatorProviderImpl();35com.foo.DateFormatProviderImpl dateFP = new com.foo.DateFormatProviderImpl();36com.foo.DateFormatSymbolsProviderImpl dateFSP = new com.foo.DateFormatSymbolsProviderImpl();37com.foo.DecimalFormatSymbolsProviderImpl decimalFSP = new com.foo.DecimalFormatSymbolsProviderImpl();38com.foo.NumberFormatProviderImpl numberFP = new com.foo.NumberFormatProviderImpl();39com.bar.CurrencyNameProviderImpl currencyNP = new com.bar.CurrencyNameProviderImpl();40com.bar.CurrencyNameProviderImpl2 currencyNP2 = new com.bar.CurrencyNameProviderImpl2();41com.bar.LocaleNameProviderImpl localeNP = new com.bar.LocaleNameProviderImpl();42com.bar.TimeZoneNameProviderImpl tzNP = new com.bar.TimeZoneNameProviderImpl();43com.bar.GenericTimeZoneNameProviderImpl tzGenNP = new com.bar.GenericTimeZoneNameProviderImpl();44com.bar.CalendarDataProviderImpl calDataP = new com.bar.CalendarDataProviderImpl();45com.bar.CalendarNameProviderImpl calNameP = new com.bar.CalendarNameProviderImpl();4647public static void main(String[] s) {48new GenericTest();49}5051GenericTest() {52availableLocalesTest();53localeFallbackTest();54}5556/**57* Make sure that all the locales are available from the existing providers58*/59void availableLocalesTest() {60// Check that Locale.getAvailableLocales() returns the union of the JRE supported61// locales and providers' locales62HashSet<Locale> result =63new HashSet<>(Arrays.asList(Locale.getAvailableLocales()));64HashSet<Locale> expected =65new HashSet<>(Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales()));66expected.addAll(Arrays.asList(breakIP.getAvailableLocales()));67expected.addAll(Arrays.asList(collatorP.getAvailableLocales()));68expected.addAll(Arrays.asList(dateFP.getAvailableLocales()));69expected.addAll(Arrays.asList(dateFSP.getAvailableLocales()));70expected.addAll(Arrays.asList(decimalFSP.getAvailableLocales()));71expected.addAll(Arrays.asList(numberFP.getAvailableLocales()));72expected.addAll(Arrays.asList(currencyNP.getAvailableLocales()));73expected.addAll(Arrays.asList(currencyNP2.getAvailableLocales()));74expected.addAll(Arrays.asList(localeNP.getAvailableLocales()));75expected.addAll(Arrays.asList(tzNP.getAvailableLocales()));76expected.addAll(Arrays.asList(tzGenNP.getAvailableLocales()));77expected.addAll(Arrays.asList(calDataP.getAvailableLocales()));78expected.addAll(Arrays.asList(calNameP.getAvailableLocales()));79if (!result.equals(expected)) {80throw new RuntimeException("Locale.getAvailableLocales() does not return the union of locales: diff="81+ getDiff(result, expected));82}83}8485/**86* test with "xx_YY_ZZ", which is an example locale not contained87* in Locale.getAvailableLocales(). Fallback tests for supported locales88* are done in each xxxProviderTest test cases.89*/90void localeFallbackTest() {91Locale xx = new Locale("xx");92Locale dispLocale = new Locale ("xx", "YY", "ZZ");9394String xxname = xx.getDisplayLanguage(xx);95String expected = localeNP.getDisplayLanguage(xx.getLanguage(), dispLocale);96if (!xxname.equals(expected)) {97throw new RuntimeException("Locale fallback did not perform correctly. got: "+xxname+" expected: "+expected);98}99}100101private static String getDiff(Set set1, Set set2) {102Set s1 = (Set)((HashSet)set1).clone();103s1.removeAll(set2);104105Set s2 = (Set)((HashSet)set2).clone();106s2.removeAll(set1);107s2.addAll(s1);108return s2.toString();109}110}111112113