Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/PluggableLocale/DecimalFormatSymbolsProviderTest.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 DecimalFormatSymbolsProviderTest extends ProviderTest {3233com.foo.DecimalFormatSymbolsProviderImpl dfsp = new com.foo.DecimalFormatSymbolsProviderImpl();34List<Locale> availloc = Arrays.asList(DecimalFormatSymbols.getAvailableLocales());35List<Locale> providerloc = Arrays.asList(dfsp.getAvailableLocales());36List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());37List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getDecimalFormatSymbolsProvider().getAvailableLocales());3839public static void main(String[] s) {40new DecimalFormatSymbolsProviderTest();41}4243DecimalFormatSymbolsProviderTest() {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() {6061for (Locale target: availloc) {62// pure JRE implementation63Object[] data = LocaleProviderAdapter.forJRE().getLocaleResources(target).getDecimalFormatSymbolsData();64boolean jreSupportsLocale = jreimplloc.contains(target);6566// JRE string arrays67String[] jres = new String[2];68if (jreSupportsLocale) {69String[] tmp = (String[]) data[0];70jres[0] = tmp[9]; // infinity71jres[1] = tmp[10]; // NaN72}7374// result object75DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(target);76String[] result = new String[2];77result[0] = dfs.getInfinity();78result[1] = dfs.getNaN();7980// provider's object (if any)81DecimalFormatSymbols providersDfs= null;82String[] providers = new String[2];83if (providerloc.contains(target)) {84providersDfs = dfsp.getInstance(target);85providers[0] = providersDfs.getInfinity();86providers[1] = providersDfs.getNaN();87}8889for (int i = 0; i < result.length; i ++) {90checkValidity(target, jres[i], providers[i], result[i], jreSupportsLocale);91}92}93}94}959697