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 6405639 8008577
27 * @summary Validate timezone display names in
28 * src/java.base/share/classes/sun/util/resources/TimeZoneNames.java.
29 * @modules java.base/sun.util.resources
30 * @compile -XDignore.symbol.file CheckDisplayNames.java
31 * @run main/othervm -Djava.locale.providers=COMPAT,SPI CheckDisplayNames
32 */
33
34 import java.util.*;
35 import sun.util.resources.TimeZoneNames;
36
37 /**
38 * CheckDisplayNames checks all available time zones in the Java run
39 * time environment and sees if those have their display names besides doing
40 * some other test cases. It outputs time zones that don't have display names
41 * if -source option is specified.
42 * <blockquote>
43 * <pre>
44 * Usage: java CheckDisplayNames [-source]
45 * -source ... produces source code for editing TimeZoneNames.java.
46 * </pre>
47 * </blockquote>
48 */
49 public class CheckDisplayNames {
50
51 private static boolean err = false;
52 private static boolean src = false;
53
54 private static Locale[] locales = Locale.getAvailableLocales();
55 private static String[] zones = TimeZone.getAvailableIDs();
56
57 private static String[] zones_118 = {
58 "ACT", "Australia/Darwin",
59 "AET", "Australia/Sydney",
60 "AGT", "America/Buenos_Aires",
61 "ART", "Africa/Cairo",
62 "AST", "America/Anchorage",
63 "BET", "America/Sao_Paulo",
64 "BST", "Asia/Dacca",
65 "CAT", "Africa/Harare",
66 "CNT", "America/St_Johns",
67 "CST", "America/Chicago",
68 "CTT", "Asia/Shanghai",
69 "EAT", "Africa/Addis_Ababa",
70 "ECT", "Europe/Paris",
71 // "EET", "Africa/Istanbul",
72 "EST", "America/New_York",
73 "HST", "Pacific/Honolulu",
74 "IET", "America/Indiana/Indianapolis",
75 // Comment out for this test case fails as the result of L10N for hi_IN.
79 "MIT", "Pacific/Apia",
80 "MST", "America/Denver",
81 "NET", "Asia/Yerevan",
82 "NST", "Pacific/Auckland",
83 "PLT", "Asia/Karachi",
84 "PNT", "America/Phoenix",
85 "PRT", "America/Puerto_Rico",
86 "PST", "America/Los_Angeles",
87 "SST", "Pacific/Guadalcanal",
88 "VST", "Asia/Saigon",
89 };
90
91
92 public static void main(String[] argv) {
93 Locale reservedLocale = Locale.getDefault();
94 try {
95 if (argv.length == 1 && "-source".equals(argv[0])) {
96 src = true;
97 }
98
99 testDisplayNames();
100 testRAWoffsetAndDisplayNames();
101 test118DisplayNames();
102
103 if (err) {
104 throw new RuntimeException(
105 "TimeZone display name validation failed.");
106 } else {
107 System.out.println(
108 "\nAll test passed.\nTotal number of valid TimeZone id is "
109 + zones.length);
110 }
111 } finally {
112 // restore the reserved locale
113 Locale.setDefault(reservedLocale);
114 }
115
116 }
117
118 /*
137 System.out.println("Checking if each TimeZone ID has display names.");
138
139 for (int i = 0; i < zones.length; i++) {
140 String id = zones[i];
141
142 if (id != null) {
143 if (id.startsWith("Etc/GMT")) {
144 continue;
145 }
146 if (id.indexOf("Riyadh8") != -1) {
147 continue;
148 }
149 if (id.equals("GMT0")) {
150 continue;
151 }
152 }
153
154 TimeZone tz = TimeZone.getTimeZone(id);
155 String name = tz.getDisplayName();
156
157 if (name == null || name.startsWith("GMT+") || name.startsWith("GMT-")) {
158 if (src) {
159 System.out.println("\t {\"" + tz.getID() + "\", " +
160 "new String[] {\"Standard Time Name\", \"ST\",\n" +
161 "\t\t\t\t\t\t\"Daylight Time Name\", \"DT\"}},");
162 } else {
163 System.err.println("\t" + tz.getID() + " doesn't seem to have display names");
164 err = true;
165 }
166 }
167 }
168 }
169
170 /*
171 * Compares
172 * - raw DST offset
173 * - short display names in non-DST
174 * - short display names in DST
175 * - long display names in DST
176 * of two timezones whose long display names in non-DST are same.
177 * If one of these are different, there may be a bug.
|
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 6405639 8008577 8151876
27 * @summary Validate timezone display names in
28 * src/java.base/share/classes/sun/util/resources/TimeZoneNames.java.
29 * @modules java.base/sun.util.resources
30 * @compile -XDignore.symbol.file CheckDisplayNames.java
31 * @run main/othervm -Djava.locale.providers=COMPAT,SPI CheckDisplayNames
32 */
33
34 import java.util.*;
35 import sun.util.resources.TimeZoneNames;
36
37 /**
38 * CheckDisplayNames checks all available time zones in the Java run
39 * time environment and sees if those have their display names besides doing
40 * some other test cases. It outputs time zones that don't have display names
41 * if -source option is specified.
42 * <blockquote>
43 * <pre>
44 * Usage: java CheckDisplayNames [-source]
45 * -source ... produces source code for editing TimeZoneNames.java.
46 * </pre>
47 * </blockquote>
48 */
49 public class CheckDisplayNames {
50
51 private static boolean err = false;
52 private static boolean src = false;
53
54 private static Locale[] locales = Locale.getAvailableLocales();
55 private static String[] zones = TimeZone.getAvailableIDs();
56 private static List<String> newGMTzones = new ArrayList<>();
57
58 public static void setNewGMTzones() {
59 for (String zone : zones) {
60 String shortName = TimeZone.getTimeZone(zone).getDisplayName(false, TimeZone.SHORT);
61 String longName = TimeZone.getTimeZone(zone).getDisplayName(false, TimeZone.LONG);
62 if (!(zone.contains("GMT+") || zone.contains("GMT-")) && shortName.equals(longName)) {
63 newGMTzones.add(TimeZone.getTimeZone(zone).getDisplayName());
64 }
65 }
66 }
67
68 private static String[] zones_118 = {
69 "ACT", "Australia/Darwin",
70 "AET", "Australia/Sydney",
71 "AGT", "America/Buenos_Aires",
72 "ART", "Africa/Cairo",
73 "AST", "America/Anchorage",
74 "BET", "America/Sao_Paulo",
75 "BST", "Asia/Dacca",
76 "CAT", "Africa/Harare",
77 "CNT", "America/St_Johns",
78 "CST", "America/Chicago",
79 "CTT", "Asia/Shanghai",
80 "EAT", "Africa/Addis_Ababa",
81 "ECT", "Europe/Paris",
82 // "EET", "Africa/Istanbul",
83 "EST", "America/New_York",
84 "HST", "Pacific/Honolulu",
85 "IET", "America/Indiana/Indianapolis",
86 // Comment out for this test case fails as the result of L10N for hi_IN.
90 "MIT", "Pacific/Apia",
91 "MST", "America/Denver",
92 "NET", "Asia/Yerevan",
93 "NST", "Pacific/Auckland",
94 "PLT", "Asia/Karachi",
95 "PNT", "America/Phoenix",
96 "PRT", "America/Puerto_Rico",
97 "PST", "America/Los_Angeles",
98 "SST", "Pacific/Guadalcanal",
99 "VST", "Asia/Saigon",
100 };
101
102
103 public static void main(String[] argv) {
104 Locale reservedLocale = Locale.getDefault();
105 try {
106 if (argv.length == 1 && "-source".equals(argv[0])) {
107 src = true;
108 }
109
110 setNewGMTzones();
111 testDisplayNames();
112 testRAWoffsetAndDisplayNames();
113 test118DisplayNames();
114
115 if (err) {
116 throw new RuntimeException(
117 "TimeZone display name validation failed.");
118 } else {
119 System.out.println(
120 "\nAll test passed.\nTotal number of valid TimeZone id is "
121 + zones.length);
122 }
123 } finally {
124 // restore the reserved locale
125 Locale.setDefault(reservedLocale);
126 }
127
128 }
129
130 /*
149 System.out.println("Checking if each TimeZone ID has display names.");
150
151 for (int i = 0; i < zones.length; i++) {
152 String id = zones[i];
153
154 if (id != null) {
155 if (id.startsWith("Etc/GMT")) {
156 continue;
157 }
158 if (id.indexOf("Riyadh8") != -1) {
159 continue;
160 }
161 if (id.equals("GMT0")) {
162 continue;
163 }
164 }
165
166 TimeZone tz = TimeZone.getTimeZone(id);
167 String name = tz.getDisplayName();
168
169 if ((name == null || name.startsWith("GMT+") || name.startsWith("GMT-")) && !newGMTzones.contains(name)) {
170 if (src) {
171 System.out.println("\t {\"" + tz.getID() + "\", " +
172 "new String[] {\"Standard Time Name\", \"ST\",\n" +
173 "\t\t\t\t\t\t\"Daylight Time Name\", \"DT\"}},");
174 } else {
175 System.err.println("\t" + tz.getID() + " doesn't seem to have display names");
176 err = true;
177 }
178 }
179 }
180 }
181
182 /*
183 * Compares
184 * - raw DST offset
185 * - short display names in non-DST
186 * - short display names in DST
187 * - long display names in DST
188 * of two timezones whose long display names in non-DST are same.
189 * If one of these are different, there may be a bug.
|