< prev index next >

test/jdk/java/util/TimeZone/TimeZoneRegression.java

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 1998, 2016, 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.
--- 1,7 ---
  /*
!  * Copyright (c) 1998, 2023, 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.

*** 25,46 ***
   * @test
   * @bug 4052967 4073209 4073215 4084933 4096952 4109314 4126678 4151406 4151429
   * 4154525 4154537 4154542 4154650 4159922 4162593 4173604 4176686 4184229 4208960
   * 4966229 6433179 6851214 8007520 8008577
   * @library /java/text/testlib
!  * @run main/othervm -Djava.locale.providers=COMPAT,SPI TimeZoneRegression
   */
  
  import java.util.*;
  import java.io.*;
  import java.text.*;
  
! public class TimeZoneRegression extends IntlTest {
  
!     public static void main(String[] args) throws Exception {
!         new TimeZoneRegression().run(args);
!     }
  
      public void Test4073209() {
          TimeZone z1 = TimeZone.getTimeZone("PST");
          TimeZone z2 = TimeZone.getTimeZone("PST");
          if (z1 == z2) {
!             errln("Fail: TimeZone should return clones");
          }
      }
  
      @SuppressWarnings("deprecation")
      public void Test4073215() {
          SimpleTimeZone z = new SimpleTimeZone(0, "GMT");
          if (z.useDaylightTime()) {
!             errln("Fail: Fix test to start with non-DST zone");
          }
          z.setStartRule(Calendar.FEBRUARY, 1, Calendar.SUNDAY, 0);
          z.setEndRule(Calendar.MARCH, -1, Calendar.SUNDAY, 0);
          if (!z.useDaylightTime()) {
!             errln("Fail: DST not active");
          }
          if (z.inDaylightTime(new Date(97, Calendar.JANUARY, 31)) ||
              !z.inDaylightTime(new Date(97, Calendar.MARCH, 1)) ||
              z.inDaylightTime(new Date(97, Calendar.MARCH, 31))) {
!             errln("Fail: DST not working as expected");
          }
      }
  
      /**
       * The expected behavior of TimeZone around the boundaries is:
--- 25,48 ---
   * @test
   * @bug 4052967 4073209 4073215 4084933 4096952 4109314 4126678 4151406 4151429
   * 4154525 4154537 4154542 4154650 4159922 4162593 4173604 4176686 4184229 4208960
   * 4966229 6433179 6851214 8007520 8008577
   * @library /java/text/testlib
!  * @run junit/othervm -Djava.locale.providers=COMPAT,SPI TimeZoneRegression
   */
  
  import java.util.*;
  import java.io.*;
  import java.text.*;
  
! import org.junit.jupiter.api.Test;
  
! import static org.junit.jupiter.api.Assertions.fail;
! 
! public class TimeZoneRegression {
  
+     @Test
      public void Test4073209() {
          TimeZone z1 = TimeZone.getTimeZone("PST");
          TimeZone z2 = TimeZone.getTimeZone("PST");
          if (z1 == z2) {
!             fail("Fail: TimeZone should return clones");
          }
      }
  
      @SuppressWarnings("deprecation")
+     @Test
      public void Test4073215() {
          SimpleTimeZone z = new SimpleTimeZone(0, "GMT");
          if (z.useDaylightTime()) {
!             fail("Fail: Fix test to start with non-DST zone");
          }
          z.setStartRule(Calendar.FEBRUARY, 1, Calendar.SUNDAY, 0);
          z.setEndRule(Calendar.MARCH, -1, Calendar.SUNDAY, 0);
          if (!z.useDaylightTime()) {
!             fail("Fail: DST not active");
          }
          if (z.inDaylightTime(new Date(97, Calendar.JANUARY, 31)) ||
              !z.inDaylightTime(new Date(97, Calendar.MARCH, 1)) ||
              z.inDaylightTime(new Date(97, Calendar.MARCH, 31))) {
!             fail("Fail: DST not working as expected");
          }
      }
  
      /**
       * The expected behavior of TimeZone around the boundaries is:

*** 72,10 ***
--- 74,11 ---
       *    day of onset 1:59 AM STD  = display name 1:59 AM ST
       *                 2:00 AM STD  = display name 3:00 AM DT
       *    day of end   0:59 AM STD  = display name 1:59 AM DT
       *                 1:00 AM STD  = display name 1:00 AM ST
       */
+     @Test
      public void Test4084933() {
          // test both SimpleTimeZone and ZoneInfo objects.
          // @since 1.4
          sub4084933(getPST());
          sub4084933(TimeZone.getTimeZone("PST"));

*** 111,22 ***
          long DToffset = -7 * 60*60*1000L;
          if (offset1 != SToffset || offset2 != SToffset ||
              offset3 != SToffset || offset4 != DToffset ||
              offset5 != DToffset || offset6 != SToffset ||
              offset7 != SToffset || offset8 != SToffset)
!             errln("Fail: TimeZone misbehaving"); {
          }
      }
  
      public void Test4096952() {
          String[] ZONES = { "GMT", "MET", "IST" };
          boolean pass = true;
          try {
              for (int i=0; i<ZONES.length; ++i) {
                  TimeZone zone = TimeZone.getTimeZone(ZONES[i]);
                  if (!zone.getID().equals(ZONES[i]))
!                     errln("Fail: Test broken; zones not instantiating");
  
                  ByteArrayOutputStream baos;
                  ObjectOutputStream ostream =
                      new ObjectOutputStream(baos = new
                                             ByteArrayOutputStream());
--- 114,23 ---
          long DToffset = -7 * 60*60*1000L;
          if (offset1 != SToffset || offset2 != SToffset ||
              offset3 != SToffset || offset4 != DToffset ||
              offset5 != DToffset || offset6 != SToffset ||
              offset7 != SToffset || offset8 != SToffset)
!             fail("Fail: TimeZone misbehaving"); {
          }
      }
  
+     @Test
      public void Test4096952() {
          String[] ZONES = { "GMT", "MET", "IST" };
          boolean pass = true;
          try {
              for (int i=0; i<ZONES.length; ++i) {
                  TimeZone zone = TimeZone.getTimeZone(ZONES[i]);
                  if (!zone.getID().equals(ZONES[i]))
!                     fail("Fail: Test broken; zones not instantiating");
  
                  ByteArrayOutputStream baos;
                  ObjectOutputStream ostream =
                      new ObjectOutputStream(baos = new
                                             ByteArrayOutputStream());

*** 138,31 ***
                                            ByteArrayInputStream(baos.toByteArray()));
                  TimeZone frankenZone = (TimeZone) istream.readObject();
                  //logln("Zone:        " + zone);
                  //logln("FrankenZone: " + frankenZone);
                  if (!zone.equals(frankenZone)) {
!                     logln("TimeZone " + zone.getID() +
                            " not equal to serialized/deserialized one");
                      pass = false;
                  }
              }
!             if (!pass) errln("Fail: TimeZone serialization/equality bug");
          }
          catch (IOException e) {
!             errln("Fail: " + e);
              e.printStackTrace();
          }
          catch (ClassNotFoundException e) {
!             errln("Fail: " + e);
              e.printStackTrace();
          }
      }
  
      public void Test4109314() {
          Locale locale = Locale.getDefault();
          if (!TestUtils.usesGregorianCalendar(locale)) {
!             logln("Skipping this test because locale is " + locale);
              return;
          }
  
          // test both SimpleTimeZone and ZoneInfo objects.
          // @since 1.4
--- 142,32 ---
                                            ByteArrayInputStream(baos.toByteArray()));
                  TimeZone frankenZone = (TimeZone) istream.readObject();
                  //logln("Zone:        " + zone);
                  //logln("FrankenZone: " + frankenZone);
                  if (!zone.equals(frankenZone)) {
!                     System.out.println("TimeZone " + zone.getID() +
                            " not equal to serialized/deserialized one");
                      pass = false;
                  }
              }
!             if (!pass) fail("Fail: TimeZone serialization/equality bug");
          }
          catch (IOException e) {
!             fail("Fail: " + e);
              e.printStackTrace();
          }
          catch (ClassNotFoundException e) {
!             fail("Fail: " + e);
              e.printStackTrace();
          }
      }
  
+     @Test
      public void Test4109314() {
          Locale locale = Locale.getDefault();
          if (!TestUtils.usesGregorianCalendar(locale)) {
!             System.out.println("Skipping this test because locale is " + locale);
              return;
          }
  
          // test both SimpleTimeZone and ZoneInfo objects.
          // @since 1.4

*** 188,11 ***
                  if (!checkCalendar314(testCal, (TimeZone) testData[i]))
                      pass = false;
                  t += 60*60*1000L;
              }
          }
!         if (!pass) errln("Fail: TZ API inconsistent");
      }
  
      boolean checkCalendar314(GregorianCalendar testCal, TimeZone testTZ) {
          // GregorianCalendar testCal = (GregorianCalendar)aCal.clone();
  
--- 193,11 ---
                  if (!checkCalendar314(testCal, (TimeZone) testData[i]))
                      pass = false;
                  t += 60*60*1000L;
              }
          }
!         if (!pass) fail("Fail: TZ API inconsistent");
      }
  
      boolean checkCalendar314(GregorianCalendar testCal, TimeZone testTZ) {
          // GregorianCalendar testCal = (GregorianCalendar)aCal.clone();
  

*** 266,11 ***
          if (passed)
              output += "     ";
          else
              output += "ERROR";
  
!         if (passed) logln(output); else errln(output);
          return passed;
      }
  
      /**
       * CANNOT REPRODUDE
--- 271,11 ---
          if (passed)
              output += "     ";
          else
              output += "ERROR";
  
!         if (passed) System.out.println(output); else fail(output);
          return passed;
      }
  
      /**
       * CANNOT REPRODUDE

*** 282,14 ***
       * (1) Call Calendar.setTime() before getting the fields!
       * (2) Use the right millis (as usual) for getOffset(); they were passing
       *     in the MILLIS field, instead of the STANDARD MILLIS IN DAY.
       * When you fix these two problems, the test passes, as expected.
       */
      public void Test4126678() {
          Locale locale = Locale.getDefault();
          if (!TestUtils.usesGregorianCalendar(locale)) {
!             logln("Skipping this test because locale is " + locale);
              return;
          }
  
          // Note: this test depends on the PST time zone.
          TimeZone initialZone = TimeZone.getDefault();
--- 287,15 ---
       * (1) Call Calendar.setTime() before getting the fields!
       * (2) Use the right millis (as usual) for getOffset(); they were passing
       *     in the MILLIS field, instead of the STANDARD MILLIS IN DAY.
       * When you fix these two problems, the test passes, as expected.
       */
+     @Test
      public void Test4126678() {
          Locale locale = Locale.getDefault();
          if (!TestUtils.usesGregorianCalendar(locale)) {
!             System.out.println("Skipping this test because locale is " + locale);
              return;
          }
  
          // Note: this test depends on the PST time zone.
          TimeZone initialZone = TimeZone.getDefault();

*** 311,11 ***
          cal.setTimeZone(tz);
  
          Date dt = new Date(1998-1900, Calendar.APRIL, 5, 10, 0);
          // the dt value is local time in PST.
          if (!tz.inDaylightTime(dt))
!             errln("We're not in Daylight Savings Time and we should be.\n");
  
          cal.setTime(dt);
          int era = cal.get(Calendar.ERA);
          int year = cal.get(Calendar.YEAR);
          int month = cal.get(Calendar.MONTH);
--- 317,11 ---
          cal.setTimeZone(tz);
  
          Date dt = new Date(1998-1900, Calendar.APRIL, 5, 10, 0);
          // the dt value is local time in PST.
          if (!tz.inDaylightTime(dt))
!             fail("We're not in Daylight Savings Time and we should be.\n");
  
          cal.setTime(dt);
          int era = cal.get(Calendar.ERA);
          int year = cal.get(Calendar.YEAR);
          int month = cal.get(Calendar.MONTH);

*** 328,18 ***
              cal.get(Calendar.DST_OFFSET);
  
          long offset = tz.getOffset(era, year, month, day, dayOfWeek, millis);
          long raw_offset = tz.getRawOffset();
          if (offset == raw_offset) {
!             errln("Offsets should not match when in DST");
          }
      }
  
      /**
       * TimeZone.getAvailableIDs(int) throws exception for certain values,
       * due to a faulty constant in TimeZone.java.
       */
      public void Test4151406() {
          int max = 0;
          for (int h=-28; h<=30; ++h) {
              // h is in half-hours from GMT; rawoffset is in millis
              int rawoffset = h * 1800000;
--- 334,19 ---
              cal.get(Calendar.DST_OFFSET);
  
          long offset = tz.getOffset(era, year, month, day, dayOfWeek, millis);
          long raw_offset = tz.getRawOffset();
          if (offset == raw_offset) {
!             fail("Offsets should not match when in DST");
          }
      }
  
      /**
       * TimeZone.getAvailableIDs(int) throws exception for certain values,
       * due to a faulty constant in TimeZone.java.
       */
+     @Test
      public void Test4151406() {
          int max = 0;
          for (int h=-28; h<=30; ++h) {
              // h is in half-hours from GMT; rawoffset is in millis
              int rawoffset = h * 1800000;

*** 349,32 ***
                  (hh/2) + ':' +
                  ((hh%2==0) ? "00" : "30");
              try {
                  String[] ids = TimeZone.getAvailableIDs(rawoffset);
                  if (ids.length > max) max = ids.length;
!                 logln(hname + ' ' + ids.length +
                        ((ids.length > 0) ? (" e.g. " + ids[0]) : ""));
              } catch (Exception e) {
!                 errln(hname + ' ' + "Fail: " + e);
              }
          }
!         logln("Maximum zones per offset = " + max);
      }
  
      public void Test4151429() {
          try {
              TimeZone tz = TimeZone.getTimeZone("GMT");
              String name = tz.getDisplayName(true, Integer.MAX_VALUE,
                                              Locale.getDefault());
!             errln("IllegalArgumentException not thrown by TimeZone.getDisplayName()");
          } catch(IllegalArgumentException e) {}
      }
  
      /**
       * SimpleTimeZone accepts illegal DST savings values.  These values
       * must be non-zero.  There is no upper limit at this time.
       */
      public void Test4154525() {
          final int GOOD = 1, BAD = 0;
          int[] DATA = {
              1, GOOD,
              0, BAD,
--- 356,34 ---
                  (hh/2) + ':' +
                  ((hh%2==0) ? "00" : "30");
              try {
                  String[] ids = TimeZone.getAvailableIDs(rawoffset);
                  if (ids.length > max) max = ids.length;
!                 System.out.println(hname + ' ' + ids.length +
                        ((ids.length > 0) ? (" e.g. " + ids[0]) : ""));
              } catch (Exception e) {
!                 fail(hname + ' ' + "Fail: " + e);
              }
          }
!         System.out.println("Maximum zones per offset = " + max);
      }
  
+     @Test
      public void Test4151429() {
          try {
              TimeZone tz = TimeZone.getTimeZone("GMT");
              String name = tz.getDisplayName(true, Integer.MAX_VALUE,
                                              Locale.getDefault());
!             fail("IllegalArgumentException not thrown by TimeZone.getDisplayName()");
          } catch(IllegalArgumentException e) {}
      }
  
      /**
       * SimpleTimeZone accepts illegal DST savings values.  These values
       * must be non-zero.  There is no upper limit at this time.
       */
+     @Test
      public void Test4154525() {
          final int GOOD = 1, BAD = 0;
          int[] DATA = {
              1, GOOD,
              0, BAD,

*** 402,29 ***
                          z = new SimpleTimeZone(0, "GMT");
                          z.setDSTSavings(savings);
                          break;
                      }
                      if (valid) {
!                         logln("Pass: DST savings of " + savings + " accepted by " + method);
                      } else {
!                         errln("Fail: DST savings of " + savings + " accepted by " + method);
                      }
                  } catch (IllegalArgumentException e) {
                      if (valid) {
!                         errln("Fail: DST savings of " + savings + " to " + method + " gave " + e);
                      } else {
!                         logln("Pass: DST savings of " + savings + " to " + method + " gave " + e);
                      }
                  }
              }
          }
      }
  
      /**
       * SimpleTimeZone.hasSameRules() doesn't work for zones with no DST
       * and different DST parameters.
       */
      public void Test4154537() {
          // tz1 and tz2 have no DST and different rule parameters
          SimpleTimeZone tz1 = new SimpleTimeZone(0, "1", 0, 0, 0, 0, 2, 0, 0, 0);
          SimpleTimeZone tz2 = new SimpleTimeZone(0, "2", 1, 0, 0, 0, 3, 0, 0, 0);
          // tza and tzA have the same rule params
--- 411,30 ---
                          z = new SimpleTimeZone(0, "GMT");
                          z.setDSTSavings(savings);
                          break;
                      }
                      if (valid) {
!                         System.out.println("Pass: DST savings of " + savings + " accepted by " + method);
                      } else {
!                         fail("Fail: DST savings of " + savings + " accepted by " + method);
                      }
                  } catch (IllegalArgumentException e) {
                      if (valid) {
!                         fail("Fail: DST savings of " + savings + " to " + method + " gave " + e);
                      } else {
!                         System.out.println("Pass: DST savings of " + savings + " to " + method + " gave " + e);
                      }
                  }
              }
          }
      }
  
      /**
       * SimpleTimeZone.hasSameRules() doesn't work for zones with no DST
       * and different DST parameters.
       */
+     @Test
      public void Test4154537() {
          // tz1 and tz2 have no DST and different rule parameters
          SimpleTimeZone tz1 = new SimpleTimeZone(0, "1", 0, 0, 0, 0, 2, 0, 0, 0);
          SimpleTimeZone tz2 = new SimpleTimeZone(0, "2", 1, 0, 0, 0, 3, 0, 0, 0);
          // tza and tzA have the same rule params

*** 433,26 ***
          // tzb differs from tza
          SimpleTimeZone tzb = new SimpleTimeZone(0, "b", 0, 1, 0, 0, 3, 1, 0, 0);
          if (tz1.useDaylightTime() || tz2.useDaylightTime() ||
              !tza.useDaylightTime() || !tzA.useDaylightTime() ||
              !tzb.useDaylightTime()) {
!             errln("Test is broken -- rewrite it");
          }
          if (!tza.hasSameRules(tzA) || tza.hasSameRules(tzb)) {
!             errln("Fail: hasSameRules() broken for zones with rules");
          }
          if (!tz1.hasSameRules(tz2)) {
!             errln("Fail: hasSameRules() returns false for zones without rules");
!             errln("zone 1 = " + tz1);
!             errln("zone 2 = " + tz2);
          }
      }
  
      /**
       * SimpleTimeZone constructors, setStartRule(), and setEndRule() don't
       * check for out-of-range arguments.
       */
      public void Test4154542() {
          final int GOOD = 1;
          final int BAD  = 0;
  
          final int GOOD_MONTH       = Calendar.JANUARY;
--- 443,27 ---
          // tzb differs from tza
          SimpleTimeZone tzb = new SimpleTimeZone(0, "b", 0, 1, 0, 0, 3, 1, 0, 0);
          if (tz1.useDaylightTime() || tz2.useDaylightTime() ||
              !tza.useDaylightTime() || !tzA.useDaylightTime() ||
              !tzb.useDaylightTime()) {
!             fail("Test is broken -- rewrite it");
          }
          if (!tza.hasSameRules(tzA) || tza.hasSameRules(tzb)) {
!             fail("Fail: hasSameRules() broken for zones with rules");
          }
          if (!tz1.hasSameRules(tz2)) {
!             fail("Fail: hasSameRules() returns false for zones without rules");
!             fail("zone 1 = " + tz1);
!             fail("zone 2 = " + tz2);
          }
      }
  
      /**
       * SimpleTimeZone constructors, setStartRule(), and setEndRule() don't
       * check for out-of-range arguments.
       */
+     @Test
      public void Test4154542() {
          final int GOOD = 1;
          final int BAD  = 0;
  
          final int GOOD_MONTH       = Calendar.JANUARY;

*** 494,11 ***
                  zone.setStartRule(month, day, dayOfWeek, time);
              } catch (IllegalArgumentException e) {
                  ex = e;
              }
              if ((ex == null) != shouldBeGood) {
!                 errln("setStartRule(month=" + month + ", day=" + day +
                        ", dayOfWeek=" + dayOfWeek + ", time=" + time +
                        (shouldBeGood ? (") should work but throws " + ex)
                         : ") should fail but doesn't"));
              }
  
--- 505,11 ---
                  zone.setStartRule(month, day, dayOfWeek, time);
              } catch (IllegalArgumentException e) {
                  ex = e;
              }
              if ((ex == null) != shouldBeGood) {
!                 fail("setStartRule(month=" + month + ", day=" + day +
                        ", dayOfWeek=" + dayOfWeek + ", time=" + time +
                        (shouldBeGood ? (") should work but throws " + ex)
                         : ") should fail but doesn't"));
              }
  

*** 507,11 ***
                  zone.setEndRule(month, day, dayOfWeek, time);
              } catch (IllegalArgumentException e) {
                  ex = e;
              }
              if ((ex == null) != shouldBeGood) {
!                 errln("setEndRule(month=" + month + ", day=" + day +
                        ", dayOfWeek=" + dayOfWeek + ", time=" + time +
                        (shouldBeGood ? (") should work but throws " + ex)
                         : ") should fail but doesn't"));
              }
  
--- 518,11 ---
                  zone.setEndRule(month, day, dayOfWeek, time);
              } catch (IllegalArgumentException e) {
                  ex = e;
              }
              if ((ex == null) != shouldBeGood) {
!                 fail("setEndRule(month=" + month + ", day=" + day +
                        ", dayOfWeek=" + dayOfWeek + ", time=" + time +
                        (shouldBeGood ? (") should work but throws " + ex)
                         : ") should fail but doesn't"));
              }
  

*** 522,11 ***
                          GOOD_MONTH, GOOD_DAY, GOOD_DAY_OF_WEEK, GOOD_TIME);
              } catch (IllegalArgumentException e) {
                  ex = e;
              }
              if ((ex == null) != shouldBeGood) {
!                 errln("SimpleTimeZone(month=" + month + ", day=" + day +
                        ", dayOfWeek=" + dayOfWeek + ", time=" + time +
                        (shouldBeGood ? (", <end>) should work but throws " + ex)
                         : ", <end>) should fail but doesn't"));
              }
  
--- 533,11 ---
                          GOOD_MONTH, GOOD_DAY, GOOD_DAY_OF_WEEK, GOOD_TIME);
              } catch (IllegalArgumentException e) {
                  ex = e;
              }
              if ((ex == null) != shouldBeGood) {
!                 fail("SimpleTimeZone(month=" + month + ", day=" + day +
                        ", dayOfWeek=" + dayOfWeek + ", time=" + time +
                        (shouldBeGood ? (", <end>) should work but throws " + ex)
                         : ", <end>) should fail but doesn't"));
              }
  

*** 537,21 ***
                          month, day, dayOfWeek, time);
              } catch (IllegalArgumentException e) {
                  ex = e;
              }
              if ((ex == null) != shouldBeGood) {
!                 errln("SimpleTimeZone(<start>, month=" + month + ", day=" + day +
                        ", dayOfWeek=" + dayOfWeek + ", time=" + time +
                        (shouldBeGood ? (") should work but throws " + ex)
                         : ") should fail but doesn't"));
              }
          }
      }
  
      /**
       * SimpleTimeZone.getOffset accepts illegal arguments.
       */
      public void Test4154650() {
          final int GOOD=1, BAD=0;
          final int GOOD_ERA=GregorianCalendar.AD, GOOD_YEAR=1998, GOOD_MONTH=Calendar.AUGUST;
          final int GOOD_DAY=2, GOOD_DOW=Calendar.SUNDAY, GOOD_TIME=16*3600000;
          int[] DATA = {
--- 548,22 ---
                          month, day, dayOfWeek, time);
              } catch (IllegalArgumentException e) {
                  ex = e;
              }
              if ((ex == null) != shouldBeGood) {
!                 fail("SimpleTimeZone(<start>, month=" + month + ", day=" + day +
                        ", dayOfWeek=" + dayOfWeek + ", time=" + time +
                        (shouldBeGood ? (") should work but throws " + ex)
                         : ") should fail but doesn't"));
              }
          }
      }
  
      /**
       * SimpleTimeZone.getOffset accepts illegal arguments.
       */
+     @Test
      public void Test4154650() {
          final int GOOD=1, BAD=0;
          final int GOOD_ERA=GregorianCalendar.AD, GOOD_YEAR=1998, GOOD_MONTH=Calendar.AUGUST;
          final int GOOD_DAY=2, GOOD_DOW=Calendar.SUNDAY, GOOD_TIME=16*3600000;
          int[] DATA = {

*** 592,85 ***
                                            DATA[i+4], DATA[i+5], DATA[i+6]);
             } catch (IllegalArgumentException ex) {
                  e = ex;
              }
              if (good != (e == null)) {
!                 errln("Fail: getOffset(" +
                        DATA[i+1] + ", " + DATA[i+2] + ", " + DATA[i+3] + ", " +
                        DATA[i+4] + ", " + DATA[i+5] + ", " + DATA[i+6] +
                        (good ? (") threw " + e) : ") accepts invalid args"));
              }
          }
      }
  
      /**
       * TimeZone constructors allow null IDs.
       */
      public void Test4159922() {
          TimeZone z = null;
  
          // TimeZone API.  Only hasSameRules() and setDefault() should
          // allow null.
          try {
              z = TimeZone.getTimeZone((String)null);
!             errln("FAIL: Null allowed in getTimeZone");
          } catch (NullPointerException e) {}
          z = TimeZone.getTimeZone("GMT");
          try {
              z.getDisplayName(false, TimeZone.SHORT, null);
!             errln("FAIL: Null allowed in getDisplayName(3)");
          } catch (NullPointerException e) {}
          try {
              z.getDisplayName(null);
!             errln("FAIL: Null allowed in getDisplayName(1)");
          } catch (NullPointerException e) {}
          try {
              if (z.hasSameRules(null)) {
!                 errln("FAIL: hasSameRules returned true");
              }
          } catch (NullPointerException e) {
!             errln("FAIL: Null NOT allowed in hasSameRules");
          }
          try {
              z.inDaylightTime(null);
!             errln("FAIL: Null allowed in inDaylightTime");
          } catch (NullPointerException e) {}
          try {
              z.setID(null);
!             errln("FAIL: Null allowed in setID");
          } catch (NullPointerException e) {}
  
          TimeZone save = TimeZone.getDefault();
          try {
              TimeZone.setDefault(null);
          } catch (NullPointerException e) {
!             errln("FAIL: Null NOT allowed in setDefault");
          } finally {
              TimeZone.setDefault(save);
          }
  
          // SimpleTimeZone API
          SimpleTimeZone s = null;
          try {
              s = new SimpleTimeZone(0, null);
!             errln("FAIL: Null allowed in SimpleTimeZone(2)");
          } catch (NullPointerException e) {}
          try {
              s = new SimpleTimeZone(0, null, 0, 1, 0, 0, 0, 1, 0, 0);
!             errln("FAIL: Null allowed in SimpleTimeZone(10)");
          } catch (NullPointerException e) {}
          try {
              s = new SimpleTimeZone(0, null, 0, 1, 0, 0, 0, 1, 0, 0, 1000);
!             errln("FAIL: Null allowed in SimpleTimeZone(11)");
          } catch (NullPointerException e) {}
      }
  
      /**
       * TimeZone broken at midnight.  The TimeZone code fails to handle
       * transitions at midnight correctly.
       */
      @SuppressWarnings("deprecation")
      public void Test4162593() {
          SimpleDateFormat fmt = new SimpleDateFormat("z", Locale.US);
          final int ONE_HOUR = 60*60*1000;
          TimeZone initialZone = TimeZone.getDefault();
  
--- 604,87 ---
                                            DATA[i+4], DATA[i+5], DATA[i+6]);
             } catch (IllegalArgumentException ex) {
                  e = ex;
              }
              if (good != (e == null)) {
!                 fail("Fail: getOffset(" +
                        DATA[i+1] + ", " + DATA[i+2] + ", " + DATA[i+3] + ", " +
                        DATA[i+4] + ", " + DATA[i+5] + ", " + DATA[i+6] +
                        (good ? (") threw " + e) : ") accepts invalid args"));
              }
          }
      }
  
      /**
       * TimeZone constructors allow null IDs.
       */
+     @Test
      public void Test4159922() {
          TimeZone z = null;
  
          // TimeZone API.  Only hasSameRules() and setDefault() should
          // allow null.
          try {
              z = TimeZone.getTimeZone((String)null);
!             fail("FAIL: Null allowed in getTimeZone");
          } catch (NullPointerException e) {}
          z = TimeZone.getTimeZone("GMT");
          try {
              z.getDisplayName(false, TimeZone.SHORT, null);
!             fail("FAIL: Null allowed in getDisplayName(3)");
          } catch (NullPointerException e) {}
          try {
              z.getDisplayName(null);
!             fail("FAIL: Null allowed in getDisplayName(1)");
          } catch (NullPointerException e) {}
          try {
              if (z.hasSameRules(null)) {
!                 fail("FAIL: hasSameRules returned true");
              }
          } catch (NullPointerException e) {
!             fail("FAIL: Null NOT allowed in hasSameRules");
          }
          try {
              z.inDaylightTime(null);
!             fail("FAIL: Null allowed in inDaylightTime");
          } catch (NullPointerException e) {}
          try {
              z.setID(null);
!             fail("FAIL: Null allowed in setID");
          } catch (NullPointerException e) {}
  
          TimeZone save = TimeZone.getDefault();
          try {
              TimeZone.setDefault(null);
          } catch (NullPointerException e) {
!             fail("FAIL: Null NOT allowed in setDefault");
          } finally {
              TimeZone.setDefault(save);
          }
  
          // SimpleTimeZone API
          SimpleTimeZone s = null;
          try {
              s = new SimpleTimeZone(0, null);
!             fail("FAIL: Null allowed in SimpleTimeZone(2)");
          } catch (NullPointerException e) {}
          try {
              s = new SimpleTimeZone(0, null, 0, 1, 0, 0, 0, 1, 0, 0);
!             fail("FAIL: Null allowed in SimpleTimeZone(10)");
          } catch (NullPointerException e) {}
          try {
              s = new SimpleTimeZone(0, null, 0, 1, 0, 0, 0, 1, 0, 0, 1000);
!             fail("FAIL: Null allowed in SimpleTimeZone(11)");
          } catch (NullPointerException e) {}
      }
  
      /**
       * TimeZone broken at midnight.  The TimeZone code fails to handle
       * transitions at midnight correctly.
       */
      @SuppressWarnings("deprecation")
+     @Test
      public void Test4162593() {
          SimpleDateFormat fmt = new SimpleDateFormat("z", Locale.US);
          final int ONE_HOUR = 60*60*1000;
          TimeZone initialZone = TimeZone.getDefault();
  

*** 709,22 ***
                  // Must construct the Date object AFTER setting the default zone
                  int[] p = (int[])DATA[j+1];
                  Date d = new Date(p[0], p[1], p[2], p[3], p[4]);
                  boolean transitionExpected = ((Boolean)DATA[j+2]).booleanValue();
  
!                 logln(tz.getID() + ":");
                  for (int i=0; i<4; ++i) {
                      zone[i] = fmt.format(d);
!                     logln("" + i + ": " + d);
                      d = new Date(d.getTime() + ONE_HOUR);
                  }
                  if (zone[0].equals(zone[1]) &&
                      (zone[1].equals(zone[2]) != transitionExpected) &&
                      zone[2].equals(zone[3])) {
!                     logln("Ok: transition " + transitionExpected);
                  } else {
!                     errln("Fail: boundary transition incorrect");
                  }
              }
          }
          finally {
              // restore the initial time zone so that this test case
--- 723,22 ---
                  // Must construct the Date object AFTER setting the default zone
                  int[] p = (int[])DATA[j+1];
                  Date d = new Date(p[0], p[1], p[2], p[3], p[4]);
                  boolean transitionExpected = ((Boolean)DATA[j+2]).booleanValue();
  
!                 System.out.println(tz.getID() + ":");
                  for (int i=0; i<4; ++i) {
                      zone[i] = fmt.format(d);
!                     System.out.println("" + i + ": " + d);
                      d = new Date(d.getTime() + ONE_HOUR);
                  }
                  if (zone[0].equals(zone[1]) &&
                      (zone[1].equals(zone[2]) != transitionExpected) &&
                      zone[2].equals(zone[3])) {
!                     System.out.println("Ok: transition " + transitionExpected);
                  } else {
!                     fail("Fail: boundary transition incorrect");
                  }
              }
          }
          finally {
              // restore the initial time zone so that this test case

*** 734,10 ***
--- 748,11 ---
      }
  
      /**
       * TimeZone broken in last hour of year
       */
+     @Test
      public void Test4173604() {
          // test both SimpleTimeZone and ZoneInfo objects.
          // @since 1.4
          sub4173604(getPST());
          sub4173604(TimeZone.getTimeZone("PST"));

*** 746,11 ***
      private void sub4173604(TimeZone pst) {
          int o22 = pst.getOffset(1, 1998, 11, 31, Calendar.THURSDAY, 22*60*60*1000);
          int o23 = pst.getOffset(1, 1998, 11, 31, Calendar.THURSDAY, 23*60*60*1000);
          int o00 = pst.getOffset(1, 1999, 0, 1, Calendar.FRIDAY, 0);
          if (o22 != o23 || o22 != o00) {
!             errln("Offsets should be the same (for PST), but got: " +
                    "12/31 22:00 " + o22 +
                    ", 12/31 23:00 " + o23 +
                    ", 01/01 00:00 " + o00);
          }
  
--- 761,11 ---
      private void sub4173604(TimeZone pst) {
          int o22 = pst.getOffset(1, 1998, 11, 31, Calendar.THURSDAY, 22*60*60*1000);
          int o23 = pst.getOffset(1, 1998, 11, 31, Calendar.THURSDAY, 23*60*60*1000);
          int o00 = pst.getOffset(1, 1999, 0, 1, Calendar.FRIDAY, 0);
          if (o22 != o23 || o22 != o00) {
!             fail("Offsets should be the same (for PST), but got: " +
                    "12/31 22:00 " + o22 +
                    ", 12/31 23:00 " + o23 +
                    ", 01/01 00:00 " + o00);
          }
  

*** 765,23 ***
              cal.add(Calendar.MINUTE, delta);
              if (cal.get(Calendar.DST_OFFSET) != lastDST) {
                  ++transitions;
                  Calendar t = (Calendar)cal.clone();
                  t.add(Calendar.MINUTE, -delta);
!                 logln(t.getTime() + "  " + t.get(Calendar.DST_OFFSET));
!                 logln(cal.getTime() + "  " + (lastDST=cal.get(Calendar.DST_OFFSET)));
              }
          }
          if (transitions != 4) {
!             errln("Saw " + transitions + " transitions; should have seen 4");
          }
      }
  
      /**
       * getDisplayName doesn't work with unusual savings/offsets.
       */
      @SuppressWarnings("deprecation")
      public void Test4176686() {
          // Construct a zone that does not observe DST but
          // that does have a DST savings (which should be ignored).
          int offset = 90 * 60000; // 1:30
          SimpleTimeZone z1 = new SimpleTimeZone(offset, "_std_zone_");
--- 780,24 ---
              cal.add(Calendar.MINUTE, delta);
              if (cal.get(Calendar.DST_OFFSET) != lastDST) {
                  ++transitions;
                  Calendar t = (Calendar)cal.clone();
                  t.add(Calendar.MINUTE, -delta);
!                 System.out.println(t.getTime() + "  " + t.get(Calendar.DST_OFFSET));
!                 System.out.println(cal.getTime() + "  " + (lastDST=cal.get(Calendar.DST_OFFSET)));
              }
          }
          if (transitions != 4) {
!             fail("Saw " + transitions + " transitions; should have seen 4");
          }
      }
  
      /**
       * getDisplayName doesn't work with unusual savings/offsets.
       */
      @SuppressWarnings("deprecation")
+     @Test
      public void Test4176686() {
          // Construct a zone that does not observe DST but
          // that does have a DST savings (which should be ignored).
          int offset = 90 * 60000; // 1:30
          SimpleTimeZone z1 = new SimpleTimeZone(offset, "_std_zone_");

*** 825,76 ***
              "DateFormat.format(dst)/dst zone", fmt2.format(dst), "GMT+02:15",
          };
  
          for (int i=0; i<DATA.length; i+=3) {
              if (!DATA[i+1].equals(DATA[i+2])) {
!                 errln("FAIL: " + DATA[i] + " -> " + DATA[i+1] + ", exp " + DATA[i+2]);
              }
          }
      }
  
      /**
       * SimpleTimeZone allows invalid DOM values.
       */
      public void Test4184229() {
          SimpleTimeZone zone = null;
          try {
              zone = new SimpleTimeZone(0, "A", 0, -1, 0, 0, 0, 0, 0, 0);
!             errln("Failed. No exception has been thrown for DOM -1 startDay");
          } catch(IllegalArgumentException e) {
!             logln("(a) " + e.getMessage());
          }
          try {
              zone = new SimpleTimeZone(0, "A", 0, 0, 0, 0, 0, -1, 0, 0);
!             errln("Failed. No exception has been thrown for DOM -1 endDay");
          } catch(IllegalArgumentException e) {
!             logln("(b) " + e.getMessage());
          }
          try {
              zone = new SimpleTimeZone(0, "A", 0, -1, 0, 0, 0, 0, 0, 0, 1000);
!             errln("Failed. No exception has been thrown for DOM -1 startDay +savings");
          } catch(IllegalArgumentException e) {
!             logln("(c) " + e.getMessage());
          }
          try {
              zone = new SimpleTimeZone(0, "A", 0, 0, 0, 0, 0, -1, 0, 0, 1000);
!             errln("Failed. No exception has been thrown for DOM -1 endDay +savings");
          } catch(IllegalArgumentException e) {
!             logln("(d) " + e.getMessage());
          }
          // Make a valid constructor call for subsequent tests.
          zone = new SimpleTimeZone(0, "A", 0, 1, 0, 0, 0, 1, 0, 0);
          try {
              zone.setStartRule(0, -1, 0, 0);
!             errln("Failed. No exception has been thrown for DOM -1 setStartRule +savings");
          } catch(IllegalArgumentException e) {
!             logln("(e) " + e.getMessage());
          }
          try {
              zone.setStartRule(0, -1, 0);
!             errln("Failed. No exception has been thrown for DOM -1 setStartRule");
          } catch(IllegalArgumentException e) {
!             logln("(f) " + e.getMessage());
          }
          try {
              zone.setEndRule(0, -1, 0, 0);
!             errln("Failed. No exception has been thrown for DOM -1 setEndRule +savings");
          } catch(IllegalArgumentException e) {
!             logln("(g) " + e.getMessage());
          }
          try {
              zone.setEndRule(0, -1, 0);
!             errln("Failed. No exception has been thrown for DOM -1 setEndRule");
          } catch(IllegalArgumentException e) {
!             logln("(h) " + e.getMessage());
          }
      }
  
      /**
       * SimpleTimeZone.getOffset() throws IllegalArgumentException when to get
       * of 2/29/1996 (leap day).
       */
      public void Test4208960 () {
          // test both SimpleTimeZone and ZoneInfo objects.
          // @since 1.4
          sub4208960(getPST());
          sub4208960(TimeZone.getTimeZone("PST"));
--- 841,78 ---
              "DateFormat.format(dst)/dst zone", fmt2.format(dst), "GMT+02:15",
          };
  
          for (int i=0; i<DATA.length; i+=3) {
              if (!DATA[i+1].equals(DATA[i+2])) {
!                 fail("FAIL: " + DATA[i] + " -> " + DATA[i+1] + ", exp " + DATA[i+2]);
              }
          }
      }
  
      /**
       * SimpleTimeZone allows invalid DOM values.
       */
+     @Test
      public void Test4184229() {
          SimpleTimeZone zone = null;
          try {
              zone = new SimpleTimeZone(0, "A", 0, -1, 0, 0, 0, 0, 0, 0);
!             fail("Failed. No exception has been thrown for DOM -1 startDay");
          } catch(IllegalArgumentException e) {
!             System.out.println("(a) " + e.getMessage());
          }
          try {
              zone = new SimpleTimeZone(0, "A", 0, 0, 0, 0, 0, -1, 0, 0);
!             fail("Failed. No exception has been thrown for DOM -1 endDay");
          } catch(IllegalArgumentException e) {
!             System.out.println("(b) " + e.getMessage());
          }
          try {
              zone = new SimpleTimeZone(0, "A", 0, -1, 0, 0, 0, 0, 0, 0, 1000);
!             fail("Failed. No exception has been thrown for DOM -1 startDay +savings");
          } catch(IllegalArgumentException e) {
!             System.out.println("(c) " + e.getMessage());
          }
          try {
              zone = new SimpleTimeZone(0, "A", 0, 0, 0, 0, 0, -1, 0, 0, 1000);
!             fail("Failed. No exception has been thrown for DOM -1 endDay +savings");
          } catch(IllegalArgumentException e) {
!             System.out.println("(d) " + e.getMessage());
          }
          // Make a valid constructor call for subsequent tests.
          zone = new SimpleTimeZone(0, "A", 0, 1, 0, 0, 0, 1, 0, 0);
          try {
              zone.setStartRule(0, -1, 0, 0);
!             fail("Failed. No exception has been thrown for DOM -1 setStartRule +savings");
          } catch(IllegalArgumentException e) {
!             System.out.println("(e) " + e.getMessage());
          }
          try {
              zone.setStartRule(0, -1, 0);
!             fail("Failed. No exception has been thrown for DOM -1 setStartRule");
          } catch(IllegalArgumentException e) {
!             System.out.println("(f) " + e.getMessage());
          }
          try {
              zone.setEndRule(0, -1, 0, 0);
!             fail("Failed. No exception has been thrown for DOM -1 setEndRule +savings");
          } catch(IllegalArgumentException e) {
!             System.out.println("(g) " + e.getMessage());
          }
          try {
              zone.setEndRule(0, -1, 0);
!             fail("Failed. No exception has been thrown for DOM -1 setEndRule");
          } catch(IllegalArgumentException e) {
!             System.out.println("(h) " + e.getMessage());
          }
      }
  
      /**
       * SimpleTimeZone.getOffset() throws IllegalArgumentException when to get
       * of 2/29/1996 (leap day).
       */
+     @Test
      public void Test4208960 () {
          // test both SimpleTimeZone and ZoneInfo objects.
          // @since 1.4
          sub4208960(getPST());
          sub4208960(TimeZone.getTimeZone("PST"));

*** 903,26 ***
      private void sub4208960(TimeZone tz) {
          try {
              int offset = tz.getOffset(GregorianCalendar.AD, 1996, Calendar.FEBRUARY, 29,
                                        Calendar.THURSDAY, 0);
          } catch (IllegalArgumentException e) {
!             errln("FAILED: to get TimeZone.getOffset(2/29/96)");
          }
          try {
              int offset = tz.getOffset(GregorianCalendar.AD, 1997, Calendar.FEBRUARY, 29,
                                        Calendar.THURSDAY, 0);
!             errln("FAILED: TimeZone.getOffset(2/29/97) expected to throw Exception.");
          } catch (IllegalArgumentException e) {
!             logln("got IllegalArgumentException");
          }
      }
  
      /**
       * 4966229: java.util.Date methods may works incorrect.
       * sun.util.calendar.ZoneInfo doesn't clone properly.
       */
      @SuppressWarnings("deprecation")
      public void Test4966229() {
          TimeZone savedTZ = TimeZone.getDefault();
          try {
              TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
              Date d = new Date(2100-1900, 5, 1); // specify year >2037
--- 921,27 ---
      private void sub4208960(TimeZone tz) {
          try {
              int offset = tz.getOffset(GregorianCalendar.AD, 1996, Calendar.FEBRUARY, 29,
                                        Calendar.THURSDAY, 0);
          } catch (IllegalArgumentException e) {
!             fail("FAILED: to get TimeZone.getOffset(2/29/96)");
          }
          try {
              int offset = tz.getOffset(GregorianCalendar.AD, 1997, Calendar.FEBRUARY, 29,
                                        Calendar.THURSDAY, 0);
!             fail("FAILED: TimeZone.getOffset(2/29/97) expected to throw Exception.");
          } catch (IllegalArgumentException e) {
!             System.out.println("got IllegalArgumentException");
          }
      }
  
      /**
       * 4966229: java.util.Date methods may works incorrect.
       * sun.util.calendar.ZoneInfo doesn't clone properly.
       */
      @SuppressWarnings("deprecation")
+     @Test
      public void Test4966229() {
          TimeZone savedTZ = TimeZone.getDefault();
          try {
              TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
              Date d = new Date(2100-1900, 5, 1); // specify year >2037

*** 943,21 ***
              // Restore the GMT offset in tz which shouldn't affect tz2
              tz.setRawOffset(offset);
              cal2.setTime(d);
              int hourOfDay = cal2.get(cal.HOUR_OF_DAY);
              if (hourOfDay != expectedHourOfDay) {
!                 errln("wrong hour of day: got: " + hourOfDay
                        + ", expected: " + expectedHourOfDay);
              }
          } finally {
              TimeZone.setDefault(savedTZ);
          }
      }
  
      /**
       * 6433179: (tz) Incorrect DST end for America/Winnipeg and Canada/Central in 2038+
       */
      public void Test6433179() {
          // Use the old America/Winnipeg rule for testing. Note that
          // startMode is WALL_TIME for testing. It's actually
          // STANDARD_TIME, though.
          //Rule  Winn    1966    2005    -       Oct     lastSun 2:00s   0       S
--- 962,22 ---
              // Restore the GMT offset in tz which shouldn't affect tz2
              tz.setRawOffset(offset);
              cal2.setTime(d);
              int hourOfDay = cal2.get(cal.HOUR_OF_DAY);
              if (hourOfDay != expectedHourOfDay) {
!                 fail("wrong hour of day: got: " + hourOfDay
                        + ", expected: " + expectedHourOfDay);
              }
          } finally {
              TimeZone.setDefault(savedTZ);
          }
      }
  
      /**
       * 6433179: (tz) Incorrect DST end for America/Winnipeg and Canada/Central in 2038+
       */
+     @Test
      public void Test6433179() {
          // Use the old America/Winnipeg rule for testing. Note that
          // startMode is WALL_TIME for testing. It's actually
          // STANDARD_TIME, though.
          //Rule  Winn    1966    2005    -       Oct     lastSun 2:00s   0       S

*** 972,11 ***
          cal.getTime();
          cal.set(cal.DAY_OF_WEEK, cal.SUNDAY);
          cal.set(cal.DAY_OF_WEEK_IN_MONTH, -1);
          cal.add(Calendar.HOUR_OF_DAY, 2);
          if (cal.get(cal.DST_OFFSET) == 0) {
!             errln("Should still be in DST.");
          }
      }
  
      private static final int ONE_HOUR = 60 * 60 * 1000;
      /**
--- 992,11 ---
          cal.getTime();
          cal.set(cal.DAY_OF_WEEK, cal.SUNDAY);
          cal.set(cal.DAY_OF_WEEK_IN_MONTH, -1);
          cal.add(Calendar.HOUR_OF_DAY, 2);
          if (cal.get(cal.DST_OFFSET) == 0) {
!             fail("Should still be in DST.");
          }
      }
  
      private static final int ONE_HOUR = 60 * 60 * 1000;
      /**
< prev index next >