Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/util/calendar/zi/TestZoneInfo310.java
38855 views
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 8007572 8008161 8157792 8224560
27
* @summary Test whether the TimeZone generated from JSR310 tzdb is the same
28
* as the one from the tz data from javazic
29
* @build BackEnd Checksum DayOfWeek Gen GenDoc Main Mappings Month
30
* Rule RuleDay RuleRec Simple TestZoneInfo310 Time Timezone
31
* TzIDOldMapping Zone ZoneInfoFile ZoneInfoOld ZoneRec Zoneinfo
32
* @run main TestZoneInfo310
33
*/
34
35
import java.io.File;
36
import java.lang.reflect.*;
37
import java.nio.file.*;
38
import java.util.*;
39
import java.util.regex.*;
40
import java.time.zone.*;
41
import java.time.ZoneId;
42
43
public class TestZoneInfo310 {
44
45
public static void main(String[] args) throws Throwable {
46
47
String TESTDIR = System.getProperty("test.dir", ".");
48
String SRCDIR = System.getProperty("test.src", ".");
49
String tzdir = SRCDIR + File.separator + "tzdata";
50
String tzfiles = "africa antarctica asia australasia europe northamerica southamerica backward etcetera";
51
String jdk_tzdir = SRCDIR + File.separator + "tzdata_jdk";
52
String jdk_tzfiles = "gmt jdk11_backward";
53
String zidir = TESTDIR + File.separator + "zi";
54
File fZidir = new File(zidir);
55
if (!fZidir.exists()) {
56
fZidir.mkdirs();
57
}
58
Matcher m = Pattern.compile("tzdata(?<ver>[0-9]{4}[A-z])")
59
.matcher(new String(Files.readAllBytes(Paths.get(tzdir, "VERSION")), "ascii"));
60
String ver = m.find() ? m.group("ver") : "NULL";
61
62
ArrayList<String> alist = new ArrayList<>();
63
alist.add("-V");
64
alist.add(ver);
65
alist.add("-d");
66
alist.add(zidir);
67
for (String f : tzfiles.split(" ")) {
68
alist.add(tzdir + File.separator + f);
69
}
70
for (String f : jdk_tzfiles.split(" ")) {
71
alist.add(jdk_tzdir + File.separator + f);
72
}
73
System.out.println("Compiling tz files!");
74
Main.main(alist.toArray(new String[alist.size()]));
75
76
//////////////////////////////////
77
System.out.println("testing!");
78
ZoneInfoFile.ziDir = zidir;
79
long t0, t1;
80
81
t0 = System.nanoTime();
82
ZoneInfoOld.getTimeZone("America/Los_Angeles");
83
t1 = System.nanoTime();
84
System.out.printf("OLD.getZoneInfoOld()[1]=%d%n", (t1 - t0) / 1000);
85
86
t0 = System.nanoTime();
87
ZoneInfoOld.getTimeZone("America/New_York");
88
t1 = System.nanoTime();
89
System.out.printf("OLD.getZoneInfoOld()[2]=%d%n", (t1 - t0) / 1000);
90
91
t0 = System.nanoTime();
92
ZoneInfoOld.getTimeZone("America/Denver");
93
t1 = System.nanoTime();
94
System.out.printf("OLD.getZoneInfoOld()[3]=%d%n", (t1 - t0) / 1000);
95
96
t0 = System.nanoTime();
97
String[] zids_old = ZoneInfoOld.getAvailableIDs();
98
t1 = System.nanoTime();
99
System.out.printf("OLD.getAvailableIDs()=%d, total=%d%n",
100
(t1 - t0) / 1000, zids_old.length);
101
Arrays.sort(zids_old);
102
103
t0 = System.nanoTime();
104
String[] alias_old = ZoneInfoOld.getAliasTable()
105
.keySet().toArray(new String[0]);
106
t1 = System.nanoTime();
107
System.out.printf("OLD.getAliasTable()=%d, total=%d%n",
108
(t1 - t0) / 1000, alias_old.length);
109
Arrays.sort(alias_old);
110
111
t0 = System.currentTimeMillis();
112
for (String zid : zids_old) {
113
ZoneInfoOld.getTimeZone(zid);
114
}
115
t1 = System.currentTimeMillis();
116
System.out.printf("OLD.TotalTZ()=%d (ms)%n", t1 - t0);
117
118
/*
119
t0 = System.nanoTime();
120
ZoneId.of("America/Los_Angeles").getRules();
121
t1 = System.nanoTime();
122
System.out.printf("NEW.ZoneId.of()[1]=%d%n", (t1 - t0) / 1000);
123
*/
124
t0 = System.nanoTime();
125
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
126
t1 = System.nanoTime();
127
System.out.printf("NEW.getTimeZone()[1]=%d%n", (t1 - t0) / 1000);
128
129
t0 = System.nanoTime();
130
tz = TimeZone.getTimeZone("America/New_York");
131
t1 = System.nanoTime();
132
System.out.printf("NEW.getTimeZone()[2]=%d%n", (t1 - t0) / 1000);
133
134
t0 = System.nanoTime();
135
tz = TimeZone.getTimeZone("America/Denver");
136
t1 = System.nanoTime();
137
System.out.printf("NEW.getTimeZone()[3]=%d%n", (t1 - t0) / 1000);
138
139
t0 = System.nanoTime();
140
String[] zids_new = TimeZone.getAvailableIDs();
141
t1 = System.nanoTime();
142
System.out.printf("NEW.getAvailableIDs()=%d, total=%d%n",
143
(t1 - t0) / 1000, zids_new.length);
144
Arrays.sort(zids_new);
145
146
t0 = System.nanoTime();
147
String[] alias_new = sun.util.calendar.ZoneInfo.getAliasTable()
148
.keySet().toArray(new String[0]);
149
t1 = System.nanoTime();
150
System.out.printf("NEW.getAliasTable()=%d, total=%d%n",
151
(t1 - t0) / 1000, alias_new.length);
152
Arrays.sort(alias_new);
153
154
t0 = System.currentTimeMillis();
155
for (String zid : zids_new) {
156
TimeZone.getTimeZone(zid);
157
}
158
t1 = System.currentTimeMillis();
159
System.out.printf("NEW.TotalTZ()=%d (ms)%n", t1 - t0);
160
161
if (!Arrays.equals(zids_old, zids_new)) {
162
throw new RuntimeException(" FAILED: availableIds don't match");
163
}
164
165
if (!Arrays.equals(alias_old, alias_new)) {
166
throw new RuntimeException(" FAILED: aliases don't match");
167
}
168
169
for (String zid : zids_new) {
170
ZoneInfoOld zi = toZoneInfoOld(TimeZone.getTimeZone(zid));
171
ZoneInfoOld ziOLD = (ZoneInfoOld)ZoneInfoOld.getTimeZone(zid);
172
/*
173
* Temporary ignoring the failing TimeZones which are having zone
174
* rules defined till year 2037 and/or above and have negative DST
175
* save time in IANA tzdata. This bug is tracked via JDK-8223388.
176
*/
177
if (zid.equals("Africa/Casablanca") || zid.equals("Africa/El_Aaiun")
178
|| zid.equals("Asia/Tehran") || zid.equals("Iran")) {
179
continue;
180
}
181
if (! zi.equalsTo(ziOLD)) {
182
System.out.println(zi.diffsTo(ziOLD));
183
throw new RuntimeException(" FAILED: " + zid);
184
}
185
}
186
delete(fZidir);
187
188
// test tzdb version
189
if (!ver.equals(sun.util.calendar.ZoneInfoFile.getVersion())) {
190
System.out.printf(" FAILED: ver=%s, expected=%s%n",
191
sun.util.calendar.ZoneInfoFile.getVersion(), ver);
192
throw new RuntimeException("Version test failed");
193
}
194
195
// test getAvailableIDs(raw);
196
zids_new = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
197
Arrays.sort(zids_new);
198
zids_old = ZoneInfoOld.getAvailableIDs(-8 * 60 * 60 * 1000);
199
Arrays.sort(zids_old);
200
if (!Arrays.equals(zids_new, zids_old)) {
201
System.out.println("------------------------");
202
System.out.println("NEW.getAvailableIDs(-8:00)");
203
for (String zid : zids_new) {
204
System.out.println(zid);
205
}
206
System.out.println("------------------------");
207
System.out.println("OLD.getAvailableIDs(-8:00)");
208
for (String zid : zids_old) {
209
System.out.println(zid);
210
}
211
throw new RuntimeException(" FAILED: availableIds(offset) don't match");
212
}
213
}
214
215
private static void delete(File f) {
216
if (f.isDirectory()) {
217
for (File f0 : f.listFiles()) {
218
delete(f0);
219
}
220
}
221
f.delete();
222
}
223
224
// to access sun.util.calendar.ZoneInfo's private fields
225
static Class<?> ziClz;
226
static Field rawOffset;
227
static Field checksum;
228
static Field dstSavings;
229
static Field transitions;
230
static Field offsets;
231
static Field simpleTimeZoneParams;
232
static Field willGMTOffsetChange;
233
static {
234
try {
235
ziClz = Class.forName("sun.util.calendar.ZoneInfo");
236
rawOffset = ziClz.getDeclaredField("rawOffset");
237
checksum = ziClz.getDeclaredField("checksum");
238
dstSavings = ziClz.getDeclaredField("dstSavings");
239
transitions = ziClz.getDeclaredField("transitions");
240
offsets = ziClz.getDeclaredField("offsets");
241
simpleTimeZoneParams = ziClz.getDeclaredField("simpleTimeZoneParams");
242
willGMTOffsetChange = ziClz.getDeclaredField("willGMTOffsetChange");
243
rawOffset.setAccessible(true);
244
checksum.setAccessible(true);
245
dstSavings.setAccessible(true);
246
transitions.setAccessible(true);
247
offsets.setAccessible(true);
248
simpleTimeZoneParams.setAccessible(true);
249
willGMTOffsetChange.setAccessible(true);
250
} catch (Exception x) {
251
throw new RuntimeException(x);
252
}
253
}
254
255
private static ZoneInfoOld toZoneInfoOld(TimeZone tz) throws Exception {
256
return new ZoneInfoOld(tz.getID(),
257
rawOffset.getInt(tz),
258
dstSavings.getInt(tz),
259
checksum.getInt(tz),
260
(long[])transitions.get(tz),
261
(int[])offsets.get(tz),
262
(int[])simpleTimeZoneParams.get(tz),
263
willGMTOffsetChange.getBoolean(tz));
264
}
265
266
267
}
268
269