0N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A/*
0N/A *
0N/A */
0N/A
0N/Aimport java.text.*;
0N/Aimport java.util.*;
0N/Aimport sun.util.resources.*;
0N/A
0N/Apublic class GenericTest {
0N/A
0N/A // test providers
0N/A com.foo.BreakIteratorProviderImpl breakIP = new com.foo.BreakIteratorProviderImpl();
0N/A com.foo.CollatorProviderImpl collatorP = new com.foo.CollatorProviderImpl();
0N/A com.foo.DateFormatProviderImpl dateFP = new com.foo.DateFormatProviderImpl();
0N/A com.foo.DateFormatSymbolsProviderImpl dateFSP = new com.foo.DateFormatSymbolsProviderImpl();
0N/A com.foo.DecimalFormatSymbolsProviderImpl decimalFSP = new com.foo.DecimalFormatSymbolsProviderImpl();
0N/A com.foo.NumberFormatProviderImpl numberFP = new com.foo.NumberFormatProviderImpl();
0N/A com.bar.CurrencyNameProviderImpl currencyNP = new com.bar.CurrencyNameProviderImpl();
0N/A com.bar.LocaleNameProviderImpl localeNP = new com.bar.LocaleNameProviderImpl();
0N/A com.bar.TimeZoneNameProviderImpl tzNP = new com.bar.TimeZoneNameProviderImpl();
0N/A
0N/A public static void main(String[] s) {
0N/A new GenericTest();
0N/A }
0N/A
0N/A GenericTest() {
0N/A availableLocalesTest();
0N/A localeFallbackTest();
0N/A }
0N/A
0N/A /**
0N/A * Make sure that all the locales are available from the existing providers
0N/A */
0N/A void availableLocalesTest() {
0N/A // Check that Locale.getAvailableLocales() returns the union of the JRE supported
0N/A // locales and providers' locales
0N/A HashSet<Locale> result =
0N/A new HashSet<Locale>(Arrays.asList(Locale.getAvailableLocales()));
0N/A HashSet<Locale> expected =
0N/A new HashSet<Locale>(Arrays.asList(LocaleData.getAvailableLocales()));
0N/A expected.addAll(Arrays.asList(breakIP.getAvailableLocales()));
0N/A expected.addAll(Arrays.asList(collatorP.getAvailableLocales()));
0N/A expected.addAll(Arrays.asList(dateFP.getAvailableLocales()));
0N/A expected.addAll(Arrays.asList(dateFSP.getAvailableLocales()));
0N/A expected.addAll(Arrays.asList(decimalFSP.getAvailableLocales()));
0N/A expected.addAll(Arrays.asList(numberFP.getAvailableLocales()));
0N/A expected.addAll(Arrays.asList(currencyNP.getAvailableLocales()));
0N/A expected.addAll(Arrays.asList(localeNP.getAvailableLocales()));
0N/A expected.addAll(Arrays.asList(tzNP.getAvailableLocales()));
0N/A if (!result.equals(expected)) {
0N/A throw new RuntimeException("Locale.getAvailableLocales() does not return the union of locales");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * test with "xx_YY_ZZ", which is an example locale not contained
0N/A * in Locale.getAvailableLocales(). Fallback tests for supported locales
0N/A * are done in each xxxProviderTest test cases.
0N/A */
0N/A void localeFallbackTest() {
0N/A Locale xx = new Locale("xx");
0N/A Locale dispLocale = new Locale ("xx", "YY", "ZZ");
0N/A
0N/A String xxname = xx.getDisplayLanguage(xx);
0N/A String expected = localeNP.getDisplayLanguage(xx.getLanguage(), dispLocale);
0N/A if (!xxname.equals(expected)) {
0N/A throw new RuntimeException("Locale fallback did not perform correctly. got: "+xxname+" expected: "+expected);
0N/A }
0N/A }
0N/A}