Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Calendar/CldrFormatNamesTest.java
47182 views
/*1* Copyright (c) 2013, 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 800650926* @compile -XDignore.symbol.file CldrFormatNamesTest.java27* @run main/othervm -Djava.locale.providers=CLDR CldrFormatNamesTest28* @summary Unit test for CLDR FormatData resources29*/3031import java.util.*;32import static java.util.Calendar.*;33import sun.util.locale.provider.*;3435public class CldrFormatNamesTest {36private static final Locale ARABIC = new Locale("ar");37private static final Locale ZH_HANT = Locale.forLanguageTag("zh-Hant");3839/*40* The first element is a Locale followed by key-value pairs41* in a FormatData resource bundle. The value type is either42* String or String[].43*/44static final Object[][] CLDR_DATA = {45{46Locale.JAPAN,47"field.zone", "\u30bf\u30a4\u30e0\u30be\u30fc\u30f3",48"java.time.japanese.DatePatterns", new String[] {49"Gy\u5e74M\u6708d\u65e5EEEE",50"Gy\u5e74M\u6708d\u65e5",51"Gy\u5e74M\u6708d\u65e5",52"Gyy/MM/dd",53},54"java.time.roc.DatePatterns", new String[] {55"Gy\u5e74M\u6708d\u65e5EEEE",56"Gy\u5e74M\u6708d\u65e5",57"Gy/MM/dd",58"Gy/MM/dd",59},60"calendarname.buddhist", "\u30bf\u30a4\u4ecf\u6559\u66a6",61},62{63Locale.PRC,64"field.zone", "\u533a\u57df",65"java.time.islamic.DatePatterns", new String[] {66"Gy\u5e74M\u6708d\u65e5EEEE",67"Gy\u5e74M\u6708d\u65e5",68"Gy\u5e74M\u6708d\u65e5",69"Gyy-MM-dd",70},71"calendarname.islamic", "\u4f0a\u65af\u5170\u65e5\u5386",72},73{74Locale.GERMANY,75"field.dayperiod", "Tagesh\u00e4lfte",76"java.time.islamic.DatePatterns", new String[] {77"EEEE d. MMMM y G",78"d. MMMM y G",79"d. MMM y G",80"d.M.y G",81},82"calendarname.islamic", "Islamischer Kalender",83},84};8586// Islamic calendar symbol names in ar87private static final String[] ISLAMIC_MONTH_NAMES = {88"\u0645\u062d\u0631\u0645",89"\u0635\u0641\u0631",90"\u0631\u0628\u064a\u0639 \u0627\u0644\u0623\u0648\u0644",91"\u0631\u0628\u064a\u0639 \u0627\u0644\u0622\u062e\u0631",92"\u062c\u0645\u0627\u062f\u0649 \u0627\u0644\u0623\u0648\u0644\u0649",93"\u062c\u0645\u0627\u062f\u0649 \u0627\u0644\u0622\u062e\u0631\u0629",94"\u0631\u062c\u0628",95"\u0634\u0639\u0628\u0627\u0646",96"\u0631\u0645\u0636\u0627\u0646",97"\u0634\u0648\u0627\u0644",98"\u0630\u0648 \u0627\u0644\u0642\u0639\u062f\u0629",99"\u0630\u0648 \u0627\u0644\u062d\u062c\u0629",100};101private static final String[] ISLAMIC_ERA_NAMES = {102"",103"\u0647\u0640",104};105106// Minguo calendar symbol names in zh_Hant107private static final String[] ROC_ERA_NAMES = {108"\u6c11\u570b\u524d",109"\u6c11\u570b",110};111112private static int errors = 0;113114// This test is CLDR data dependent.115public static void main(String[] args) {116for (Object[] data : CLDR_DATA) {117Locale locale = (Locale) data[0];118ResourceBundle rb = LocaleProviderAdapter.getResourceBundleBased()119.getLocaleResources(locale).getJavaTimeFormatData();120for (int i = 1; i < data.length; ) {121String key = (String) data[i++];122Object expected = data[i++];123if (rb.containsKey(key)) {124Object value = rb.getObject(key);125if (expected instanceof String) {126if (!expected.equals(value)) {127errors++;128System.err.printf("error: key='%s', got '%s' expected '%s'%n",129key, value, expected);130}131} else if (expected instanceof String[]) {132try {133if (!Arrays.equals((Object[]) value, (Object[]) expected)) {134errors++;135System.err.printf("error: key='%s', got '%s' expected '%s'%n",136key, Arrays.asList((Object[])value),137Arrays.asList((Object[])expected));138}139} catch (Exception e) {140errors++;141e.printStackTrace();142}143}144} else {145errors++;146System.err.println("No resource for " + key);147}148}149}150151// test Islamic calendar names in Arabic152testSymbolNames(ARABIC, "islamic", ISLAMIC_MONTH_NAMES, MONTH, LONG, "month");153testSymbolNames(ARABIC, "islamic", ISLAMIC_ERA_NAMES, ERA, SHORT, "era");154155// test ROC (Minguo) calendar names in zh-Hant156testSymbolNames(ZH_HANT, "roc", ROC_ERA_NAMES, ERA, SHORT, "era");157158if (errors > 0) {159throw new RuntimeException("test failed");160}161}162163private static void testSymbolNames(Locale locale, String calType, String[] expected,164int field, int style, String fieldName) {165for (int i = 0; i < expected.length; i++) {166String expt = expected[i];167String name = CalendarDataUtility.retrieveJavaTimeFieldValueName(calType, field, i, style, locale);168if (!expt.equals(name)) {169errors++;170System.err.printf("error: wrong %s %s name in %s: value=%d, got='%s', expected='%s'%n",171calType, fieldName, locale, i, name, expt);172}173}174}175}176177178