1 /*
2 * Copyright (c) 2012, 2019, 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 8129881 8130845 8136518 8181157 8210490 8220037
27 * @modules jdk.localedata
28 * @run main/othervm -Djava.locale.providers=CLDR CLDRDisplayNamesTest
29 * @summary Make sure that localized time zone names of CLDR are used
30 * if specified.
31 */
32
33 import java.text.*;
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 = {
78 public static void main(String[] args) {
79 // Make sure that localized time zone names of CLDR are used
80 // if specified.
81 TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
82 int errors = 0;
83 for (String[] data : CLDR_DATA) {
84 Locale locale = Locale.forLanguageTag(data[0]);
85 for (int i = 1; i < data.length; i++) {
86 int style = ((i % 2) == 1) ? LONG : SHORT;
87 boolean daylight = (i == 3 || i == 4);
88 String name = tz.getDisplayName(daylight, style, locale);
89 if (!data[i].equals(name)) {
90 System.err.printf("error: got '%s' expected '%s' (style=%d, daylight=%s, locale=%s)%n",
91 name, data[i], style, daylight, locale);
92 errors++;
93 }
94 }
95 }
96
97 // for 8129881
98 tz = TimeZone.getTimeZone("Europe/Vienna");
99 String name = tz.getDisplayName(false, SHORT, Locale.ENGLISH);
100 if (!"CET".equals(name)) {
101 System.err.printf("error: got '%s' expected 'CET' %n", name);
102 errors++;
103 }
104
105 // for 8130845
106 SimpleDateFormat fmtROOT = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.ROOT);
107 SimpleDateFormat fmtUS = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.US);
108 SimpleDateFormat fmtUK = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.UK);
109 Locale originalLocale = Locale.getDefault();
110 try {
111 Locale.setDefault(Locale.ROOT);
112 fmtROOT.parse("Thu Nov 13 04:35:51 AKST 2008");
113 fmtUS.parse("Thu Nov 13 04:35:51 AKST 2008");
114 fmtUK.parse("Thu Nov 13 04:35:51 GMT-09:00 2008");
115 } catch (ParseException pe) {
116 System.err.println(pe);
117 errors++;
118 } finally {
119 Locale.setDefault(originalLocale);
120 }
121
122 // for 8210490
123 // Check that TimeZone.getDisplayName should honor passed locale parameter,
124 // even if default locale is set to some other locale.
125 Locale.setDefault(Locale.forLanguageTag("ar-PK"));
126 TimeZone zi = TimeZone.getTimeZone("Etc/GMT-5");
127 String displayName = zi.getDisplayName(false, TimeZone.SHORT, Locale.US);
128 Locale.setDefault(originalLocale);
129 if (!displayName.equals("GMT+05:00")) {
130 System.err.printf("Wrong display name for timezone Etc/GMT-5 : expected GMT+05:00, Actual " + displayName);
131 errors++;
132 }
137 Locale.CHINA,
138 Locale.GERMANY,
139 Locale.JAPAN,
140 Locale.UK,
141 Locale.US,
142 Locale.forLanguageTag("hi-IN"),
143 Locale.forLanguageTag("es-419")).stream()
144 .peek(System.out::println)
145 .map(l -> DateFormatSymbols.getInstance(l).getZoneStrings())
146 .flatMap(zoneStrings -> Arrays.stream(zoneStrings))
147 .filter(namesArray -> Arrays.stream(namesArray)
148 .anyMatch(aName -> aName.equals(NO_INHERITANCE_MARKER)))
149 .peek(marker -> {
150 System.err.println("No-inheritance-marker is detected with tzid: "
151 + marker[0]);
152 })
153 .count();
154
155 // 8220037: Make sure CLDRConverter uniquely produces bundles, regardless of the
156 // source file enumeration order.
157 tz = TimeZone.getTimeZone("America/Argentina/La_Rioja");
158 if (!"ARST".equals(tz.getDisplayName(true, TimeZone.SHORT,
159 new Locale.Builder()
160 .setLanguage("en")
161 .setRegion("CA")
162 .build()))) {
163 System.err.println("Short display name of \"" + tz.getID() + "\" was not \"ARST\"");
164 errors++;
165 }
166
167 if (errors > 0) {
168 throw new RuntimeException("test failed");
169 }
170 }
171 }
|
1 /*
2 * Copyright (c) 2012, 2020, 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 8129881 8130845 8136518 8181157 8210490 8220037
27 * 8234347 8236548
28 * @modules jdk.localedata
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.text.*;
35 import java.util.*;
36 import static java.util.TimeZone.*;
37
38 public class CLDRDisplayNamesTest {
39 /*
40 * The first element is a language tag. The rest are localized
41 * display names of America/Los_Angeles copied from the CLDR
42 * resources data. If data change in CLDR, test data below will
43 * need to be changed accordingly.
44 *
45 * Generic names are NOT tested (until they are supported by API).
46 */
47 static final String[][] CLDR_DATA = {
79 public static void main(String[] args) {
80 // Make sure that localized time zone names of CLDR are used
81 // if specified.
82 TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
83 int errors = 0;
84 for (String[] data : CLDR_DATA) {
85 Locale locale = Locale.forLanguageTag(data[0]);
86 for (int i = 1; i < data.length; i++) {
87 int style = ((i % 2) == 1) ? LONG : SHORT;
88 boolean daylight = (i == 3 || i == 4);
89 String name = tz.getDisplayName(daylight, style, locale);
90 if (!data[i].equals(name)) {
91 System.err.printf("error: got '%s' expected '%s' (style=%d, daylight=%s, locale=%s)%n",
92 name, data[i], style, daylight, locale);
93 errors++;
94 }
95 }
96 }
97
98 // for 8129881
99 /* 8234347: CLDR Converter will not pre-fill short display names from COMPAT anymore.
100 tz = TimeZone.getTimeZone("Europe/Vienna");
101 String name = tz.getDisplayName(false, SHORT, Locale.ENGLISH);
102 if (!"CET".equals(name)) {
103 System.err.printf("error: got '%s' expected 'CET' %n", name);
104 errors++;
105 }
106 */
107
108 // for 8130845
109 SimpleDateFormat fmtROOT = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.ROOT);
110 SimpleDateFormat fmtUS = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.US);
111 SimpleDateFormat fmtUK = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.UK);
112 Locale originalLocale = Locale.getDefault();
113 try {
114 Locale.setDefault(Locale.ROOT);
115 fmtROOT.parse("Thu Nov 13 04:35:51 GMT-09:00 2008");
116 fmtUS.parse("Thu Nov 13 04:35:51 AKST 2008");
117 fmtUK.parse("Thu Nov 13 04:35:51 GMT-09:00 2008");
118 } catch (ParseException pe) {
119 System.err.println(pe);
120 errors++;
121 } finally {
122 Locale.setDefault(originalLocale);
123 }
124
125 // for 8210490
126 // Check that TimeZone.getDisplayName should honor passed locale parameter,
127 // even if default locale is set to some other locale.
128 Locale.setDefault(Locale.forLanguageTag("ar-PK"));
129 TimeZone zi = TimeZone.getTimeZone("Etc/GMT-5");
130 String displayName = zi.getDisplayName(false, TimeZone.SHORT, Locale.US);
131 Locale.setDefault(originalLocale);
132 if (!displayName.equals("GMT+05:00")) {
133 System.err.printf("Wrong display name for timezone Etc/GMT-5 : expected GMT+05:00, Actual " + displayName);
134 errors++;
135 }
140 Locale.CHINA,
141 Locale.GERMANY,
142 Locale.JAPAN,
143 Locale.UK,
144 Locale.US,
145 Locale.forLanguageTag("hi-IN"),
146 Locale.forLanguageTag("es-419")).stream()
147 .peek(System.out::println)
148 .map(l -> DateFormatSymbols.getInstance(l).getZoneStrings())
149 .flatMap(zoneStrings -> Arrays.stream(zoneStrings))
150 .filter(namesArray -> Arrays.stream(namesArray)
151 .anyMatch(aName -> aName.equals(NO_INHERITANCE_MARKER)))
152 .peek(marker -> {
153 System.err.println("No-inheritance-marker is detected with tzid: "
154 + marker[0]);
155 })
156 .count();
157
158 // 8220037: Make sure CLDRConverter uniquely produces bundles, regardless of the
159 // source file enumeration order.
160 /* 8234347: CLDR Converter will not pre-fill short display names from COMPAT anymore.
161 tz = TimeZone.getTimeZone("America/Argentina/La_Rioja");
162 if (!"ARST".equals(tz.getDisplayName(true, TimeZone.SHORT,
163 new Locale.Builder()
164 .setLanguage("en")
165 .setRegion("CA")
166 .build()))) {
167 System.err.println("Short display name of \"" + tz.getID() + "\" was not \"ARST\"");
168 errors++;
169 }
170 */
171
172 if (errors > 0) {
173 throw new RuntimeException("test failed");
174 }
175 }
176 }
|