Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/TimeZone/CLDRDisplayNamesTest.java
38812 views
/*1* Copyright (c) 2012, 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 800547126* @run main/othervm -Djava.locale.providers=CLDR CLDRDisplayNamesTest27* @summary Make sure that localized time zone names of CLDR are used28* if specified.29*/3031import java.util.*;32import static java.util.TimeZone.*;3334public class CLDRDisplayNamesTest {35/*36* The first element is a language tag. The rest are localized37* display names of America/Los_Angeles copied from the CLDR38* resources data. If data change in CLDR, test data below will39* need to be changed accordingly.40*41* Generic names are NOT tested (until they are supported by API).42*/43static final String[][] CLDR_DATA = {44{45"ja-JP",46"\u30a2\u30e1\u30ea\u30ab\u592a\u5e73\u6d0b\u6a19\u6e96\u6642",47"PST",48"\u30a2\u30e1\u30ea\u30ab\u592a\u5e73\u6d0b\u590f\u6642\u9593",49"PDT",50//"\u30a2\u30e1\u30ea\u30ab\u592a\u5e73\u6d0b\u6642\u9593",51//"PT"52},53{54"zh-CN",55"\u592a\u5e73\u6d0b\u6807\u51c6\u65f6\u95f4",56"PST",57"\u592a\u5e73\u6d0b\u590f\u4ee4\u65f6\u95f4",58"PDT",59//"\u7f8e\u56fd\u592a\u5e73\u6d0b\u65f6\u95f4",60//"PT"61},62{63"de-DE",64"Nordamerikanische Westk\u00fcsten-Winterzeit",65"PST",66"Nordamerikanische Westk\u00fcsten-Sommerzeit",67"PDT",68//"Nordamerikanische Westk\u00fcstenzeit",69//"PT"70},71};7273public static void main(String[] args) {74TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");75int errors = 0;76for (String[] data : CLDR_DATA) {77Locale locale = Locale.forLanguageTag(data[0]);78for (int i = 1; i < data.length; i++) {79int style = ((i % 2) == 1) ? LONG : SHORT;80boolean daylight = (i == 3 || i == 4);81String name = tz.getDisplayName(daylight, style, locale);82if (!data[i].equals(name)) {83System.err.printf("error: got '%s' expected '%s' (style=%d, daylight=%s, locale=%s)%n",84name, data[i], style, daylight, locale);85errors++;86}87}88}89if (errors > 0) {90throw new RuntimeException("test failed");91}92}93}949596