Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Locale/Bug8001562.java
38813 views
/*1* Copyright (c) 2012, 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 800156226* @summary Verify that getAvailableLocales() in locale sensitive services27* classes return compatible set of locales as in JDK7.28* @run main Bug800156229*/3031import java.text.*;32import java.util.*;3334public class Bug8001562 {3536static final String[] jdk7availTags = {37"ar", "ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IQ", "ar-JO", "ar-KW",38"ar-LB", "ar-LY", "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SD", "ar-SY",39"ar-TN", "ar-YE", "be", "be-BY", "bg", "bg-BG", "ca", "ca-ES", "cs",40"cs-CZ", "da", "da-DK", "de", "de-AT", "de-CH", "de-DE", "de-LU", "el",41"el-CY", "el-GR", "en", "en-AU", "en-CA", "en-GB", "en-IE", "en-IN",42"en-MT", "en-NZ", "en-PH", "en-SG", "en-US", "en-ZA", "es", "es-AR",43"es-BO", "es-CL", "es-CO", "es-CR", "es-DO", "es-EC", "es-ES", "es-GT",44"es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", "es-PY", "es-SV",45"es-US", "es-UY", "es-VE", "et", "et-EE", "fi", "fi-FI", "fr", "fr-BE",46"fr-CA", "fr-CH", "fr-FR", "fr-LU", "ga", "ga-IE", "he", "he-IL",47"hi-IN", "hr", "hr-HR", "hu", "hu-HU", "id", "id-ID", "is", "is-IS",48"it", "it-CH", "it-IT", "ja", "ja-JP",49"ja-JP-u-ca-japanese-x-lvariant-JP", "ko", "ko-KR", "lt", "lt-LT", "lv",50"lv-LV", "mk", "mk-MK", "ms", "ms-MY", "mt", "mt-MT", "nl", "nl-BE",51"nl-NL", "no", "no-NO", "no-NO-x-lvariant-NY", "pl", "pl-PL", "pt",52"pt-BR", "pt-PT", "ro", "ro-RO", "ru", "ru-RU", "sk", "sk-SK", "sl",53"sl-SI", "sq", "sq-AL", "sr", "sr-BA", "sr-CS", "sr-Latn", "sr-Latn-BA",54"sr-Latn-ME", "sr-Latn-RS", "sr-ME", "sr-RS", "sv", "sv-SE", "th",55"th-TH", "th-TH-u-nu-thai-x-lvariant-TH", "tr", "tr-TR", "uk", "uk-UA",56"vi", "vi-VN", "zh", "zh-CN", "zh-HK", "zh-SG", "zh-TW", };57static List<Locale> jdk7availLocs = new ArrayList<>();58static {59for (String locStr : jdk7availTags) {60jdk7availLocs.add(Locale.forLanguageTag(locStr));61}62}6364public static void main(String[] args) {65List<Locale> avail = Arrays.asList(BreakIterator.getAvailableLocales());66diffLocale(BreakIterator.class, avail);6768avail = Arrays.asList(Collator.getAvailableLocales());69diffLocale(Collator.class, avail);7071avail = Arrays.asList(DateFormat.getAvailableLocales());72diffLocale(DateFormat.class, avail);7374avail = Arrays.asList(DateFormatSymbols.getAvailableLocales());75diffLocale(DateFormatSymbols.class, avail);7677avail = Arrays.asList(DecimalFormatSymbols.getAvailableLocales());78diffLocale(DecimalFormatSymbols.class, avail);7980avail = Arrays.asList(NumberFormat.getAvailableLocales());81diffLocale(NumberFormat.class, avail);8283avail = Arrays.asList(Locale.getAvailableLocales());84diffLocale(Locale.class, avail);85}8687static void diffLocale(Class c, List<Locale> locs) {88String diff = "";8990System.out.printf("Only in target locales (%s.getAvailableLocales()): ", c.getSimpleName());91for (Locale l : locs) {92if (!jdk7availLocs.contains(l)) {93diff += "\""+l.toLanguageTag()+"\", ";94}95}96System.out.println(diff);97diff = "";9899System.out.printf("Only in JDK7 (%s.getAvailableLocales()): ", c.getSimpleName());100for (Locale l : jdk7availLocs) {101if (!locs.contains(l)) {102diff += "\""+l.toLanguageTag()+"\", ";103}104}105System.out.println(diff);106107if (diff.length() > 0) {108throw new RuntimeException("Above locale(s) were not included in the target available locales");109}110}111}112113114