SSL TestZoneInfo310.java
Interaktion und PortierbarkeitJAVA
/* * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 8007572 8008161 8157792 8212970 8224560 * @summary Test whether the TimeZone generated from JSR310 tzdb is the same * as the one from the tz data from javazic * @modules java.base/sun.util.calendar:+open * @build BackEnd Checksum DayOfWeek Gen GenDoc Main Mappings Month * Rule RuleDay RuleRec Simple TestZoneInfo310 Time Timezone * TzIDOldMapping Zone ZoneInfoFile ZoneInfoOld ZoneRec Zoneinfo * @run main TestZoneInfo310
*/
for (String zid : zids_new) {
ZoneInfoOld zi = toZoneInfoOld(TimeZone.getTimeZone(zid));
ZoneInfoOld ziOLD = (ZoneInfoOld)ZoneInfoOld.getTimeZone(zid); /* * Temporary ignoring the failing TimeZones which are having zone * rules defined till year 2037 and/or above and have negative DST * save time in IANA tzdata. This bug is tracked via JDK-8223388. * * These are the zones/rules that employ negative DST in vanguard * format (as of 2019a), Palestine added in 2022d: * * - Rule "Eire" * - Rule "Morocco" * - Rule "Namibia" * - Rule "Palestine" * - Zone "Europe/Prague" * * Tehran/Iran rule has rules beyond 2037, in which javazic assumes * to be the last year. Thus javazic's rule is based on year 2037 * (Mar 20th/Sep 20th are the cutover dates), while the real rule * has year 2087 where Mar 21st/Sep 21st are the cutover dates.
*/ if (zid.equals("Africa/Casablanca") || // uses "Morocco" rule
zid.equals("Africa/El_Aaiun") || // uses "Morocco" rule
zid.equals("Africa/Windhoek") || // uses "Namibia" rule
zid.equals("Eire") ||
zid.equals("Europe/Bratislava") || // link to "Europe/Prague"
zid.equals("Europe/Dublin") || // uses "Eire" rule
zid.equals("Europe/Prague") ||
zid.equals("Asia/Tehran") || // last rule mismatch
zid.equals("Asia/Gaza") || // uses "Palestine" rule
zid.equals("Asia/Hebron") || // uses "Palestine" rule
zid.equals("Iran")) { // last rule mismatch continue;
} if (! zi.equalsTo(ziOLD)) {
System.out.println(zi.diffsTo(ziOLD)); thrownew RuntimeException(" FAILED: " + zid);
}
} delete(fZidir);
// test tzdb version if (!ver.equals(sun.util.calendar.ZoneInfoFile.getVersion())) {
System.out.printf(" FAILED: ver=%s, expected=%s%n",
sun.util.calendar.ZoneInfoFile.getVersion(), ver); thrownew RuntimeException("Version test failed");
}
// test getAvailableIDs(raw);
zids_new = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
Arrays.sort(zids_new);
zids_old = ZoneInfoOld.getAvailableIDs(-8 * 60 * 60 * 1000);
Arrays.sort(zids_old); if (!Arrays.equals(zids_new, zids_old)) {
System.out.println("------------------------");
System.out.println("NEW.getAvailableIDs(-8:00)"); for (String zid : zids_new) {
System.out.println(zid);
}
System.out.println("------------------------");
System.out.println("OLD.getAvailableIDs(-8:00)"); for (String zid : zids_old) {
System.out.println(zid);
} thrownew RuntimeException(" FAILED: availableIds(offset) don't match");
}
}
privatestaticvoiddelete(File f) { if (f.isDirectory()) { for (File f0 : f.listFiles()) { delete(f0);
}
}
f.delete();
}
// to access sun.util.calendar.ZoneInfo's private fields staticClass<?> ziClz; static Field rawOffset; static Field checksum; static Field dstSavings; static Field transitions; static Field offsets; static Field simpleTimeZoneParams; static Field willGMTOffsetChange; static { try {
ziClz = Class.forName("sun.util.calendar.ZoneInfo");
rawOffset = ziClz.getDeclaredField("rawOffset");
checksum = ziClz.getDeclaredField("checksum");
dstSavings = ziClz.getDeclaredField("dstSavings");
transitions = ziClz.getDeclaredField("transitions");
offsets = ziClz.getDeclaredField("offsets");
simpleTimeZoneParams = ziClz.getDeclaredField("simpleTimeZoneParams");
willGMTOffsetChange = ziClz.getDeclaredField("willGMTOffsetChange");
rawOffset.setAccessible(true);
checksum.setAccessible(true);
dstSavings.setAccessible(true);
transitions.setAccessible(true);
offsets.setAccessible(true);
simpleTimeZoneParams.setAccessible(true);
willGMTOffsetChange.setAccessible(true);
} catch (Exception x) { thrownew RuntimeException(x);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.