Path: blob/master/test/jdk/java/util/PluggableLocale/DecimalFormatSymbolsProviderTest.java
41149 views
/*1* Copyright (c) 2007, 2018, 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*/2223/*24* @test25* @bug 4052440 8062588 821040626* @summary DecimalFormatSymbolsProvider tests27* @library providersrc/foobarutils28* providersrc/fooprovider29* @modules java.base/sun.util.locale.provider30* @build com.foobar.Utils31* com.foo.*32* @run main/othervm -Djava.locale.providers=JRE,SPI DecimalFormatSymbolsProviderTest33*/3435import java.text.DecimalFormatSymbols;36import java.util.Arrays;37import java.util.HashSet;38import java.util.List;39import java.util.Locale;40import java.util.Set;4142import com.foo.DecimalFormatSymbolsProviderImpl;4344import sun.util.locale.provider.LocaleProviderAdapter;4546public class DecimalFormatSymbolsProviderTest extends ProviderTest {4748DecimalFormatSymbolsProviderImpl dfsp = new DecimalFormatSymbolsProviderImpl();49List<Locale> availloc = Arrays.asList(DecimalFormatSymbols.getAvailableLocales());50List<Locale> providerloc = Arrays.asList(dfsp.getAvailableLocales());51List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());52List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getDecimalFormatSymbolsProvider().getAvailableLocales());5354public static void main(String[] s) {55new DecimalFormatSymbolsProviderTest();56}5758DecimalFormatSymbolsProviderTest() {59availableLocalesTest();60objectValidityTest();61}6263void availableLocalesTest() {64Set<Locale> localesFromAPI = new HashSet<>(availloc);65Set<Locale> localesExpected = new HashSet<>(jreloc);66localesExpected.addAll(providerloc);67if (localesFromAPI.equals(localesExpected)) {68System.out.println("availableLocalesTest passed.");69} else {70throw new RuntimeException("availableLocalesTest failed");71}72}7374void objectValidityTest() {7576for (Locale target: availloc) {77// pure JRE implementation78Object[] data = LocaleProviderAdapter.forJRE().getLocaleResources(target).getDecimalFormatSymbolsData();79boolean jreSupportsLocale = jreimplloc.contains(target);8081// JRE string arrays82String[] jres = new String[2];83if (jreSupportsLocale) {84String[] tmp = (String[]) data[0];85jres[0] = tmp[9]; // infinity86jres[1] = tmp[10]; // NaN87}8889// result object90DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(target);91String[] result = new String[2];92result[0] = dfs.getInfinity();93result[1] = dfs.getNaN();9495// provider's object (if any)96DecimalFormatSymbols providersDfs= null;97String[] providers = new String[2];98if (providerloc.contains(target)) {99providersDfs = dfsp.getInstance(target);100providers[0] = providersDfs.getInfinity();101providers[1] = providersDfs.getNaN();102}103104for (int i = 0; i < result.length; i ++) {105checkValidity(target, jres[i], providers[i], result[i], jreSupportsLocale);106}107}108}109}110111