1 /* 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /* 27 * @test 28 * @bug 8005471 29 * @run main/othervm -Djava.locale.providers=CLDR CLDRDisplayNamesTest 30 * @summary Make sure that localized time zone names of CLDR are used 31 * if specified. 32 */ 33 34 import java.util.*; 35 import static java.util.TimeZone.*; 36 37 public class CLDRDisplayNamesTest { 38 /* 39 * The first element is a language tag. The rest are localized 40 * display names of America/Los_Angeles copied from the CLDR 41 * resources data. If data change in CLDR, test data below will 42 * need to be changed accordingly. 43 * 44 * Generic names are NOT tested (until they are supported by API). 45 */ 46 static final String[][] CLDR_DATA = { 47 { 48 "ja-JP", 49 "\u30a2\u30e1\u30ea\u30ab\u592a\u5e73\u6d0b\u6a19\u6e96\u6642", 50 "PST", 51 "\u30a2\u30e1\u30ea\u30ab\u592a\u5e73\u6d0b\u590f\u6642\u9593", 52 "PDT", 53 //"\u30a2\u30e1\u30ea\u30ab\u592a\u5e73\u6d0b\u6642\u9593", 54 //"PT" 55 }, 56 { 57 "zh-CN", 58 "\u592a\u5e73\u6d0b\u6807\u51c6\u65f6\u95f4", 59 "PST", 60 "\u592a\u5e73\u6d0b\u590f\u4ee4\u65f6\u95f4", 61 "PDT", 62 //"\u7f8e\u56fd\u592a\u5e73\u6d0b\u65f6\u95f4", 63 //"PT" 64 }, 65 { 66 "de-DE", 67 "Nordamerikanische Westk\u00fcsten-Winterzeit", 68 "PST", 69 "Nordamerikanische Westk\u00fcsten-Sommerzeit", 70 "PDT", 71 //"Nordamerikanische Westk\u00fcstenzeit", 72 //"PT" 73 }, 74 }; 75 76 public static void main(String[] args) { 77 TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); 78 int errors = 0; 79 for (String[] data : CLDR_DATA) { 80 Locale locale = Locale.forLanguageTag(data[0]); 81 for (int i = 1; i < data.length; i++) { 82 int style = ((i % 2) == 1) ? LONG : SHORT; 83 boolean daylight = (i == 3 || i == 4); 84 String name = tz.getDisplayName(daylight, style, locale); 85 if (!data[i].equals(name)) { 86 System.err.printf("error: got '%s' expected '%s' (style=%d, daylight=%s, locale=%s)%n", 87 name, data[i], style, daylight, locale); 88 errors++; 89 } 90 } 91 } 92 if (errors > 0) { 93 throw new RuntimeException("test failed"); 94 } 95 } 96 }