test/jdk/sun/util/calendar/zi/TestZoneInfo310.java
changeset 57544 99d2dd7b84a8
parent 55634 0f1e29c77e50
child 58679 9c3209ff7550
equal deleted inserted replaced
57542:db740ced41c4 57544:99d2dd7b84a8
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 8007572 8008161 8157792 8224560
    26  * @bug 8007572 8008161 8157792 8212970 8224560
    27  * @summary Test whether the TimeZone generated from JSR310 tzdb is the same
    27  * @summary Test whether the TimeZone generated from JSR310 tzdb is the same
    28  * as the one from the tz data from javazic
    28  * as the one from the tz data from javazic
    29  * @modules java.base/sun.util.calendar:+open
    29  * @modules java.base/sun.util.calendar:+open
    30  * @build BackEnd Checksum DayOfWeek Gen GenDoc Main Mappings Month
    30  * @build BackEnd Checksum DayOfWeek Gen GenDoc Main Mappings Month
    31  *        Rule RuleDay RuleRec Simple TestZoneInfo310 Time Timezone
    31  *        Rule RuleDay RuleRec Simple TestZoneInfo310 Time Timezone
    44 public class TestZoneInfo310 {
    44 public class TestZoneInfo310 {
    45 
    45 
    46     public static void main(String[] args) throws Throwable {
    46     public static void main(String[] args) throws Throwable {
    47 
    47 
    48         String TESTDIR = System.getProperty("test.dir", ".");
    48         String TESTDIR = System.getProperty("test.dir", ".");
    49         String SRCDIR = System.getProperty("test.src", ".");
    49         Path tzdir = Paths.get(System.getProperty("test.root"),
    50         String tzdir = SRCDIR + File.separator + "tzdata";
    50             "..", "..", "make", "data", "tzdata");
    51         String tzfiles = "africa antarctica asia australasia europe northamerica pacificnew southamerica backward etcetera systemv";
    51         String tzfiles = "africa antarctica asia australasia europe northamerica pacificnew southamerica backward etcetera systemv gmt";
    52         String jdk_tzdir = SRCDIR + File.separator + "tzdata_jdk";
    52         Path jdk_tzdir = Paths.get(System.getProperty("test.src"), "tzdata_jdk");
    53         String jdk_tzfiles = "gmt jdk11_backward";
    53         String jdk_tzfiles = "jdk11_backward";
    54         String zidir = TESTDIR + File.separator + "zi";
    54         String zidir = TESTDIR + File.separator + "zi";
    55         File fZidir = new File(zidir);
    55         File fZidir = new File(zidir);
    56         if (!fZidir.exists()) {
    56         if (!fZidir.exists()) {
    57             fZidir.mkdirs();
    57             fZidir.mkdirs();
    58         }
    58         }
    59         Matcher m = Pattern.compile("tzdata(?<ver>[0-9]{4}[A-z])")
    59         Matcher m = Pattern.compile("tzdata(?<ver>[0-9]{4}[A-z])")
    60                            .matcher(new String(Files.readAllBytes(Paths.get(tzdir, "VERSION")), "ascii"));
    60                            .matcher(new String(Files.readAllBytes(tzdir.resolve("VERSION")), "ascii"));
    61         String ver = m.find() ? m.group("ver") : "NULL";
    61         String ver = m.find() ? m.group("ver") : "NULL";
    62 
    62 
    63         ArrayList<String> alist = new ArrayList<>();
    63         ArrayList<String> alist = new ArrayList<>();
    64         alist.add("-V");
    64         alist.add("-V");
    65         alist.add(ver);
    65         alist.add(ver);
    66         alist.add("-d");
    66         alist.add("-d");
    67         alist.add(zidir);
    67         alist.add(zidir);
    68         for (String f : tzfiles.split(" ")) {
    68         for (String f : tzfiles.split(" ")) {
    69             alist.add(tzdir + File.separator + f);
    69             alist.add(tzdir.resolve(f).toString());
    70         }
    70         }
    71         for (String f : jdk_tzfiles.split(" ")) {
    71         for (String f : jdk_tzfiles.split(" ")) {
    72             alist.add(jdk_tzdir + File.separator + f);
    72             alist.add(jdk_tzdir.resolve(f).toString());
    73         }
    73         }
    74         System.out.println("Compiling tz files!");
    74         System.out.println("Compiling tz files!");
    75         Main.main(alist.toArray(new String[alist.size()]));
    75         Main.main(alist.toArray(new String[alist.size()]));
    76 
    76 
    77         //////////////////////////////////
    77         //////////////////////////////////
   172             ZoneInfoOld ziOLD = (ZoneInfoOld)ZoneInfoOld.getTimeZone(zid);
   172             ZoneInfoOld ziOLD = (ZoneInfoOld)ZoneInfoOld.getTimeZone(zid);
   173             /*
   173             /*
   174              * Temporary ignoring the failing TimeZones which are having zone
   174              * Temporary ignoring the failing TimeZones which are having zone
   175              * rules defined till year 2037 and/or above and have negative DST
   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.
   176              * save time in IANA tzdata. This bug is tracked via JDK-8223388.
       
   177              *
       
   178              * These are the zones/rules that employ negative DST in vanguard
       
   179              * format (as of 2019a):
       
   180              *
       
   181              *  - Rule "Eire"
       
   182              *  - Rule "Morocco"
       
   183              *  - Rule "Namibia"
       
   184              *  - Zone "Europe/Prague"
       
   185              *
       
   186              * Tehran/Iran rule has rules beyond 2037, in which javazic assumes
       
   187              * to be the last year. Thus javazic's rule is based on year 2037
       
   188              * (Mar 20th/Sep 20th are the cutover dates), while the real rule
       
   189              * has year 2087 where Mar 21st/Sep 21st are the cutover dates.
   177              */
   190              */
   178             if (zid.equals("Africa/Casablanca") || zid.equals("Africa/El_Aaiun")
   191             if (zid.equals("Africa/Casablanca") || // uses "Morocco" rule
   179                 || zid.equals("Asia/Tehran") || zid.equals("Iran")) {
   192                 zid.equals("Africa/El_Aaiun") || // uses "Morocco" rule
   180                 continue;
   193                 zid.equals("Africa/Windhoek") || // uses "Namibia" rule
       
   194                 zid.equals("Eire") ||
       
   195                 zid.equals("Europe/Bratislava") || // link to "Europe/Prague"
       
   196                 zid.equals("Europe/Dublin") || // uses "Eire" rule
       
   197                 zid.equals("Europe/Prague") ||
       
   198                 zid.equals("Asia/Tehran") || // last rule mismatch
       
   199                 zid.equals("Iran")) { // last rule mismatch
       
   200                     continue;
   181             }
   201             }
   182             if (! zi.equalsTo(ziOLD)) {
   202             if (! zi.equalsTo(ziOLD)) {
   183                 System.out.println(zi.diffsTo(ziOLD));
   203                 System.out.println(zi.diffsTo(ziOLD));
   184                 throw new RuntimeException("  FAILED:  " + zid);
   204                 throw new RuntimeException("  FAILED:  " + zid);
   185             }
   205             }