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