Path: blob/master/test/jdk/java/util/Calendar/CldrFormatNamesTest.java
41149 views
/*1* Copyright (c) 2013, 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 8004489 8006509 8008577 8145136 820253726* @summary Unit test for CLDR FormatData resources27* @modules java.base/sun.util.locale.provider28* jdk.localedata29* @compile -XDignore.symbol.file CldrFormatNamesTest.java30* @run main/othervm -Djava.locale.providers=CLDR CldrFormatNamesTest31*/3233import java.util.*;34import static java.util.Calendar.*;35import sun.util.locale.provider.*;3637public class CldrFormatNamesTest {38private static final Locale ARABIC = new Locale("ar");39private static final Locale ZH_HANT = Locale.forLanguageTag("zh-Hant");4041/*42* The first element is a Locale followed by key-value pairs43* in a FormatData resource bundle. The value type is either44* String or String[].45*/46static final Object[][] CLDR_DATA = {47{48Locale.JAPAN,49"field.zone", "\u30bf\u30a4\u30e0\u30be\u30fc\u30f3",50"java.time.japanese.DatePatterns", new String[] {51"Gy\u5e74M\u6708d\u65e5EEEE",52"Gy\u5e74M\u6708d\u65e5",53"Gy\u5e74M\u6708d\u65e5",54"GGGGGy/M/d",55},56"java.time.roc.DatePatterns", new String[] {57"Gy\u5e74M\u6708d\u65e5EEEE",58"Gy\u5e74M\u6708d\u65e5",59"Gy/MM/dd",60"Gy/MM/dd",61},62"calendarname.buddhist", "\u4ecf\u66a6",63},64{65Locale.PRC,66"field.zone", "\u65f6\u533a",67"java.time.islamic.DatePatterns", new String[] {68"Gy\u5e74M\u6708d\u65e5EEEE",69"Gy\u5e74M\u6708d\u65e5",70"Gy\u5e74M\u6708d\u65e5",71"Gy/M/d",72},73"calendarname.islamic", "\u4f0a\u65af\u5170\u5386",74},75{76Locale.GERMANY,77"field.dayperiod", "Tagesh\u00e4lfte",78"java.time.islamic.DatePatterns", new String[] {79"EEEE, d. MMMM y G",80"d. MMMM y G",81"dd.MM.y G",82"dd.MM.yy GGGGG",83},84"calendarname.islamic", "Islamischer Kalender",85},86{87Locale.FRANCE,88"field.dayperiod", "cadran",89"java.time.islamic.DatePatterns", new String[] {90"EEEE d MMMM y G",91"d MMMM y G",92"d MMM y G",93"dd/MM/y GGGGG",94},95"calendarname.islamic", "calendrier musulman",96},97};9899// Islamic calendar symbol names in ar100private static final String[] ISLAMIC_MONTH_NAMES = {101"\u0645\u062d\u0631\u0645",102"\u0635\u0641\u0631",103"\u0631\u0628\u064a\u0639 \u0627\u0644\u0623\u0648\u0644",104"\u0631\u0628\u064a\u0639 \u0627\u0644\u0622\u062e\u0631",105"\u062c\u0645\u0627\u062f\u0649 \u0627\u0644\u0623\u0648\u0644\u0649",106"\u062c\u0645\u0627\u062f\u0649 \u0627\u0644\u0622\u062e\u0631\u0629",107"\u0631\u062c\u0628",108"\u0634\u0639\u0628\u0627\u0646",109"\u0631\u0645\u0636\u0627\u0646",110"\u0634\u0648\u0627\u0644",111"\u0630\u0648 \u0627\u0644\u0642\u0639\u062f\u0629",112"\u0630\u0648 \u0627\u0644\u062d\u062c\u0629",113};114private static final String[] ISLAMIC_ERA_NAMES = {115"",116"\u0647\u0640",117};118119// Minguo calendar symbol names in zh_Hant120private static final String[] ROC_ERA_NAMES = {121"\u6c11\u570b\u524d",122"\u6c11\u570b",123};124125private static int errors = 0;126127// This test is CLDR data dependent.128public static void main(String[] args) {129for (Object[] data : CLDR_DATA) {130Locale locale = (Locale) data[0];131ResourceBundle rb = LocaleProviderAdapter.getResourceBundleBased()132.getLocaleResources(locale).getJavaTimeFormatData();133for (int i = 1; i < data.length; ) {134String key = (String) data[i++];135Object expected = data[i++];136if (rb.containsKey(key)) {137Object value = rb.getObject(key);138if (expected instanceof String) {139if (!expected.equals(value)) {140errors++;141System.err.printf("error: key='%s', got '%s' expected '%s', rb: %s%n",142key, value, expected, rb);143}144} else if (expected instanceof String[]) {145try {146if (!Arrays.equals((Object[]) value, (Object[]) expected)) {147errors++;148System.err.printf("error: key='%s', got '%s' expected '%s', rb: %s%n",149key, Arrays.asList((Object[])value),150Arrays.asList((Object[])expected), rb);151}152} catch (Exception e) {153errors++;154e.printStackTrace();155}156}157} else {158errors++;159System.err.println("No resource for " + key+", rb: "+rb);160}161}162}163164// test Islamic calendar names in Arabic165testSymbolNames(ARABIC, "islamic", ISLAMIC_MONTH_NAMES, MONTH, LONG, "month");166testSymbolNames(ARABIC, "islamic", ISLAMIC_ERA_NAMES, ERA, SHORT, "era");167168// test ROC (Minguo) calendar names in zh-Hant169testSymbolNames(ZH_HANT, "roc", ROC_ERA_NAMES, ERA, SHORT, "era");170171if (errors > 0) {172throw new RuntimeException("test failed");173}174}175176private static void testSymbolNames(Locale locale, String calType, String[] expected,177int field, int style, String fieldName) {178for (int i = 0; i < expected.length; i++) {179String expt = expected[i];180String name = CalendarDataUtility.retrieveJavaTimeFieldValueName(calType, field, i, style, locale);181if (!expt.equals(name)) {182errors++;183System.err.printf("error: wrong %s %s name in %s: value=%d, got='%s', expected='%s'%n",184calType, fieldName, locale, i, name, expt);185}186}187}188}189190191