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