< prev index next >

test/jdk/sun/util/calendar/zi/TestZoneInfo310.java

Print this page
rev 55794 : [mq]: 8212970


   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  * @modules java.base/sun.util.calendar:+open
  30  * @build BackEnd Checksum DayOfWeek Gen GenDoc Main Mappings Month
  31  *        Rule RuleDay RuleRec Simple TestZoneInfo310 Time Timezone
  32  *        TzIDOldMapping Zone ZoneInfoFile ZoneInfoOld ZoneRec Zoneinfo
  33  * @run main TestZoneInfo310
  34  */
  35 
  36 import java.io.File;
  37 import java.lang.reflect.*;
  38 import java.nio.file.*;
  39 import java.util.*;
  40 import java.util.regex.*;
  41 import java.time.zone.*;
  42 import java.time.ZoneId;
  43 
  44 public class TestZoneInfo310 {
  45 
  46     public static void main(String[] args) throws Throwable {
  47 
  48         String TESTDIR = System.getProperty("test.dir", ".");
  49         String SRCDIR = System.getProperty("test.src", ".");
  50         String tzdir = SRCDIR + File.separator + "tzdata";
  51         String tzfiles = "africa antarctica asia australasia europe northamerica pacificnew southamerica backward etcetera systemv";
  52         String jdk_tzdir = SRCDIR + File.separator + "tzdata_jdk";
  53         String jdk_tzfiles = "gmt jdk11_backward";
  54         String zidir = TESTDIR + File.separator + "zi";
  55         File fZidir = new File(zidir);
  56         if (!fZidir.exists()) {
  57             fZidir.mkdirs();
  58         }
  59         Matcher m = Pattern.compile("tzdata(?<ver>[0-9]{4}[A-z])")
  60                            .matcher(new String(Files.readAllBytes(Paths.get(tzdir, "VERSION")), "ascii"));
  61         String ver = m.find() ? m.group("ver") : "NULL";
  62 
  63         ArrayList<String> alist = new ArrayList<>();
  64         alist.add("-V");
  65         alist.add(ver);
  66         alist.add("-d");
  67         alist.add(zidir);
  68         for (String f : tzfiles.split(" ")) {
  69             alist.add(tzdir + File.separator + f);
  70         }
  71         for (String f : jdk_tzfiles.split(" ")) {
  72             alist.add(jdk_tzdir + File.separator + f);
  73         }
  74         System.out.println("Compiling tz files!");
  75         Main.main(alist.toArray(new String[alist.size()]));
  76 
  77         //////////////////////////////////
  78         System.out.println("testing!");
  79         ZoneInfoFile.ziDir = zidir;
  80         long t0, t1;
  81 
  82         t0 = System.nanoTime();
  83         ZoneInfoOld.getTimeZone("America/Los_Angeles");
  84         t1 = System.nanoTime();
  85         System.out.printf("OLD.getZoneInfoOld()[1]=%d%n", (t1 - t0) / 1000);
  86 
  87         t0 = System.nanoTime();
  88         ZoneInfoOld.getTimeZone("America/New_York");
  89         t1 = System.nanoTime();
  90         System.out.printf("OLD.getZoneInfoOld()[2]=%d%n", (t1 - t0) / 1000);
  91 
  92         t0 = System.nanoTime();


 157             TimeZone.getTimeZone(zid);
 158         }
 159         t1 = System.currentTimeMillis();
 160         System.out.printf("NEW.TotalTZ()=%d (ms)%n", t1 - t0);
 161 
 162         if (!Arrays.equals(zids_old, zids_new)) {
 163             throw new RuntimeException("  FAILED:  availableIds don't match");
 164         }
 165 
 166         if (!Arrays.equals(alias_old, alias_new)) {
 167             throw new RuntimeException("  FAILED:  aliases don't match");
 168         }
 169 
 170         for (String zid : zids_new) {
 171             ZoneInfoOld zi = toZoneInfoOld(TimeZone.getTimeZone(zid));
 172             ZoneInfoOld ziOLD = (ZoneInfoOld)ZoneInfoOld.getTimeZone(zid);
 173             /*
 174              * Temporary ignoring the failing TimeZones which are having zone
 175              * rules defined till year 2037 and/or above and have negative DST
 176              * save time in IANA tzdata. This bug is tracked via JDK-8223388.













 177              */
 178             if (zid.equals("Africa/Casablanca") || zid.equals("Africa/El_Aaiun")
 179                 || zid.equals("Asia/Tehran") || zid.equals("Iran")) {







 180                 continue;
 181             }
 182             if (! zi.equalsTo(ziOLD)) {
 183                 System.out.println(zi.diffsTo(ziOLD));
 184                 throw new RuntimeException("  FAILED:  " + zid);
 185             }
 186         }
 187         delete(fZidir);
 188 
 189         // test tzdb version
 190         if (!ver.equals(sun.util.calendar.ZoneInfoFile.getVersion())) {
 191             System.out.printf("  FAILED:  ver=%s, expected=%s%n",
 192                               sun.util.calendar.ZoneInfoFile.getVersion(), ver);
 193             throw new RuntimeException("Version test failed");
 194         }
 195 
 196         // test getAvailableIDs(raw);
 197         zids_new = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
 198         //Arrays.sort(zids_new);
 199         zids_old = ZoneInfoOld.getAvailableIDs(-8 * 60 * 60 * 1000);




   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 8212970 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  * @modules java.base/sun.util.calendar:+open
  30  * @build BackEnd Checksum DayOfWeek Gen GenDoc Main Mappings Month
  31  *        Rule RuleDay RuleRec Simple TestZoneInfo310 Time Timezone
  32  *        TzIDOldMapping Zone ZoneInfoFile ZoneInfoOld ZoneRec Zoneinfo
  33  * @run main TestZoneInfo310
  34  */
  35 
  36 import java.io.File;
  37 import java.lang.reflect.*;
  38 import java.nio.file.*;
  39 import java.util.*;
  40 import java.util.regex.*;
  41 import java.time.zone.*;
  42 import java.time.ZoneId;
  43 
  44 public class TestZoneInfo310 {
  45 
  46     public static void main(String[] args) throws Throwable {
  47 
  48         String TESTDIR = System.getProperty("test.dir", ".");
  49         Path tzdir = Paths.get(System.getProperty("test.root"),
  50             "..", "..", "make", "data", "tzdata");
  51         String tzfiles = "africa antarctica asia australasia europe northamerica pacificnew southamerica backward etcetera systemv gmt jdk11_backward";


  52         String zidir = TESTDIR + File.separator + "zi";
  53         File fZidir = new File(zidir);
  54         if (!fZidir.exists()) {
  55             fZidir.mkdirs();
  56         }
  57         Matcher m = Pattern.compile("tzdata(?<ver>[0-9]{4}[A-z])")
  58                            .matcher(new String(Files.readAllBytes(tzdir.resolve("VERSION")), "ascii"));
  59         String ver = m.find() ? m.group("ver") : "NULL";
  60 
  61         ArrayList<String> alist = new ArrayList<>();
  62         alist.add("-V");
  63         alist.add(ver);
  64         alist.add("-d");
  65         alist.add(zidir);
  66         for (String f : tzfiles.split(" ")) {
  67             alist.add(tzdir.resolve(f).toString());



  68         }
  69         System.out.println("Compiling tz files!");
  70         Main.main(alist.toArray(new String[alist.size()]));
  71 
  72         //////////////////////////////////
  73         System.out.println("testing!");
  74         ZoneInfoFile.ziDir = zidir;
  75         long t0, t1;
  76 
  77         t0 = System.nanoTime();
  78         ZoneInfoOld.getTimeZone("America/Los_Angeles");
  79         t1 = System.nanoTime();
  80         System.out.printf("OLD.getZoneInfoOld()[1]=%d%n", (t1 - t0) / 1000);
  81 
  82         t0 = System.nanoTime();
  83         ZoneInfoOld.getTimeZone("America/New_York");
  84         t1 = System.nanoTime();
  85         System.out.printf("OLD.getZoneInfoOld()[2]=%d%n", (t1 - t0) / 1000);
  86 
  87         t0 = System.nanoTime();


 152             TimeZone.getTimeZone(zid);
 153         }
 154         t1 = System.currentTimeMillis();
 155         System.out.printf("NEW.TotalTZ()=%d (ms)%n", t1 - t0);
 156 
 157         if (!Arrays.equals(zids_old, zids_new)) {
 158             throw new RuntimeException("  FAILED:  availableIds don't match");
 159         }
 160 
 161         if (!Arrays.equals(alias_old, alias_new)) {
 162             throw new RuntimeException("  FAILED:  aliases don't match");
 163         }
 164 
 165         for (String zid : zids_new) {
 166             ZoneInfoOld zi = toZoneInfoOld(TimeZone.getTimeZone(zid));
 167             ZoneInfoOld ziOLD = (ZoneInfoOld)ZoneInfoOld.getTimeZone(zid);
 168             /*
 169              * Temporary ignoring the failing TimeZones which are having zone
 170              * rules defined till year 2037 and/or above and have negative DST
 171              * save time in IANA tzdata. This bug is tracked via JDK-8223388.
 172              *
 173              * These are the zones/rules that employ negative DST in vanguard
 174              * format (as of 2019a):
 175              *
 176              *  - Rule "Eire"
 177              *  - Rule "Morocco"
 178              *  - Rule "Namibia"
 179              *  - Zone "Europe/Prague"
 180              *
 181              * Tehran/Iran rule has rules beyond 2037, in which javazic assumes
 182              * to be the last year. Thus javazic's rule is based on year 2037
 183              * (Mar 20th/Sep 20th are the cutover dates), while the real rule
 184              * has year 2087 where Mar 21st/Sep 21st are the cutover dates.
 185              */
 186             if (zid.equals("Africa/Casablanca") || // uses "Morocco" rule
 187                 zid.equals("Africa/El_Aaiun") || // uses "Morocco" rule
 188                 zid.equals("Africa/Windhoek") || // uses "Namibia" rule
 189                 zid.equals("Eire") ||
 190                 zid.equals("Europe/Bratislava") || // link to "Europe/Prague"
 191                 zid.equals("Europe/Dublin") || // uses "Eire" rule
 192                 zid.equals("Europe/Prague") ||
 193                 zid.equals("Asia/Tehran") || // last rule mismatch
 194                 zid.equals("Iran")) { // last rule mismatch
 195                     continue;
 196             }
 197             if (! zi.equalsTo(ziOLD)) {
 198                 System.out.println(zi.diffsTo(ziOLD));
 199                 throw new RuntimeException("  FAILED:  " + zid);
 200             }
 201         }
 202         delete(fZidir);
 203 
 204         // test tzdb version
 205         if (!ver.equals(sun.util.calendar.ZoneInfoFile.getVersion())) {
 206             System.out.printf("  FAILED:  ver=%s, expected=%s%n",
 207                               sun.util.calendar.ZoneInfoFile.getVersion(), ver);
 208             throw new RuntimeException("Version test failed");
 209         }
 210 
 211         // test getAvailableIDs(raw);
 212         zids_new = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
 213         //Arrays.sort(zids_new);
 214         zids_old = ZoneInfoOld.getAvailableIDs(-8 * 60 * 60 * 1000);


< prev index next >