Path: blob/master/test/jdk/sun/util/resources/cldr/Bug8204603.java
41153 views
/*1* Copyright (c) 2018, 2020, 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 8204603 825131726* @summary Test that correct data is retrieved for zh_CN and zh_TW locales27* and CLDR provider supports all locales for which aliases exist.28* @modules java.base/sun.util.locale.provider29* jdk.localedata30* @run main Bug820460331*/3233import java.text.DateFormatSymbols;34import java.text.DecimalFormatSymbols;35import java.util.Arrays;36import java.util.Calendar;37import java.util.List;38import java.util.Locale;39import java.util.Map;40import java.util.Set;41import java.util.stream.Collectors;4243import sun.util.locale.provider.LocaleProviderAdapter;4445/**46* This test is dependent on a particular version of CLDR data.47*/48public class Bug8204603 {4950/**51* List of sample locales for which CLDR provides alias Mappings. e.g alias of52* zh-HK is zh-Hant-HK53*/54private static final List<Locale> ALIAS_LOCALES = List.of(55Locale.forLanguageTag("az-AZ"), Locale.forLanguageTag("bs-BA"),56Locale.forLanguageTag("ha-Latn-NG"), Locale.forLanguageTag("i-lux"),57Locale.forLanguageTag("kk-Cyrl-KZ"), Locale.forLanguageTag("ks-Arab-IN"),58Locale.forLanguageTag("ky-Cyrl-KG"), Locale.forLanguageTag("lb"),59Locale.forLanguageTag("lb"), Locale.forLanguageTag("mn-Cyrl-MN"),60Locale.forLanguageTag("mo"),61Locale.forLanguageTag("ms-Latn-MY"),62Locale.forLanguageTag("pa-IN"), Locale.forLanguageTag("pa-PK"),63Locale.forLanguageTag("scc"), Locale.forLanguageTag("scr"),64Locale.forLanguageTag("sh"), Locale.forLanguageTag("shi-MA"),65Locale.forLanguageTag("sr-RS"),66Locale.forLanguageTag("tl"),67Locale.forLanguageTag("tzm-Latn-MA"), Locale.forLanguageTag("ug-Arab-CN"),68Locale.forLanguageTag("uz-AF"), Locale.forLanguageTag("uz-UZ"),69Locale.forLanguageTag("vai-LR"), Locale.forLanguageTag("vai-LR"),70Locale.forLanguageTag("yue-CN"), Locale.forLanguageTag("yue-HK"),71Locale.forLanguageTag("zh-CN"), Locale.forLanguageTag("zh-HK"),72Locale.forLanguageTag("zh-MO"),73Locale.forLanguageTag("zh-TW"));74private static final Map<Locale, String> CALENDAR_DATA_MAP = Map.of(75Locale.forLanguageTag("zh-CN"), "\u5468\u65E5",76Locale.forLanguageTag("zh-TW"), "\u9031\u65E5");77private static final Map<Locale, String> NAN_DATA_MAP = Map.of(78Locale.forLanguageTag("zh-CN"), "NaN",79Locale.forLanguageTag("zh-TW"), "\u975E\u6578\u503C");8081public static void main(String[] args) {82testCldrSupportedLocales();83CALENDAR_DATA_MAP.forEach(Bug8204603::testCalendarData);84NAN_DATA_MAP.forEach(Bug8204603::testNanData);85}8687/**88* tests that CLDR provider should return true for alias locales.89*/90private static void testCldrSupportedLocales() {91LocaleProviderAdapter cldr = LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.CLDR);92Set<String> langtags = Arrays.stream(cldr.getAvailableLocales())93.map(Locale::toLanguageTag)94.collect(Collectors.toSet());95ALIAS_LOCALES.stream()96.filter(loc -> !cldr.isSupportedProviderLocale(loc, langtags))97.findAny()98.ifPresent(l -> {99throw new RuntimeException("Locale " + l100+ " is not supported by CLDR locale provider");101});102}103104private static void testCalendarData(Locale loc, String expected) {105DateFormatSymbols dfs = DateFormatSymbols.getInstance(loc);106String[] shortDays = dfs.getShortWeekdays();107String actual = shortDays[Calendar.SUNDAY];108if (!actual.equals(expected)) {109throw new RuntimeException("Calendar data mismatch for locale: "110+ loc + ", expected is: " + expected + ", actual is: " + actual);111}112}113114private static void testNanData(Locale loc, String expected) {115DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(loc);116String actual = dfs.getNaN();117if (!actual.equals(expected)) {118throw new RuntimeException("NaN mismatch for locale: "119+ loc + ", expected is: " + expected + ", actual is: " + actual);120}121}122}123124125