tests/libjava-mauve/src/gnu/testlet/java/util/SimpleTimeZone/getOffset.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: JDK1.4
       
     2 
       
     3 // Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
       
     4 
       
     5 // Mauve is free software; you can redistribute it and/or modify
       
     6 // it under the terms of the GNU General Public License as published by
       
     7 // the Free Software Foundation; either version 2, or (at your option)
       
     8 // any later version.
       
     9 
       
    10 // Mauve is distributed in the hope that it will be useful,
       
    11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13 // GNU General Public License for more details. 
       
    14 
       
    15 // You should have received a copy of the GNU General Public License
       
    16 // along with Mauve; see the file COPYING.  If not, write to
       
    17 // the Free Software Foundation, 59 Temple Place - Suite 330,
       
    18 // Boston, MA 02111-1307, USA.  */
       
    19 
       
    20 package gnu.testlet.java.util.SimpleTimeZone;
       
    21 
       
    22 import gnu.testlet.TestHarness;
       
    23 import gnu.testlet.Testlet;
       
    24 
       
    25 import java.util.Calendar;
       
    26 import java.util.GregorianCalendar;
       
    27 import java.util.SimpleTimeZone;
       
    28 
       
    29 /**
       
    30  * Some checks for the getOffset() methods in the SimpleTimeZone class.
       
    31  */
       
    32 public class getOffset implements Testlet {
       
    33 
       
    34   /**
       
    35    * Runs the test using the specified harness.
       
    36    * 
       
    37    * @param harness  the test harness (<code>null</code> not permitted).
       
    38    */
       
    39   public void test(TestHarness harness) 
       
    40   {
       
    41     testMethod1(harness);
       
    42     testMethod2(harness);
       
    43   }
       
    44   
       
    45   private void testMethod1(TestHarness harness) 
       
    46   {
       
    47     harness.checkPoint("(int, int, int, int, int, int)");
       
    48     int offset = -6 * 60 * 60 * 1000;
       
    49     int t1 = 5 * 60 * 60 * 1000;
       
    50     int t2 = 6 * 60 * 60 * 1000;
       
    51     int dst = 2 * 60 * 60 * 1000;
       
    52     SimpleTimeZone z = new SimpleTimeZone(offset, "Z1", 
       
    53       Calendar.APRIL, 26, 0, t1,
       
    54       Calendar.OCTOBER, 25, 0, t2, dst);
       
    55     harness.check(z.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 26, Calendar.MONDAY, t1 - 1000), offset);
       
    56     harness.check(z.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 26, Calendar.MONDAY, t1 + 1000), offset + dst);
       
    57     harness.check(z.getOffset(GregorianCalendar.AD, 2004, Calendar.OCTOBER, 25, Calendar.MONDAY, t2 - dst - 1000), offset + dst);
       
    58     harness.check(z.getOffset(GregorianCalendar.AD, 2004, Calendar.OCTOBER, 25, Calendar.MONDAY, t2 - dst + 1000), offset);    
       
    59   }
       
    60 
       
    61   private void testMethod2(TestHarness harness) 
       
    62   {
       
    63     harness.checkPoint("(Date)");
       
    64     int offset = -6 * 60 * 60 * 1000;
       
    65     int t1 = 5 * 60 * 60 * 1000;
       
    66     int t2 = 6 * 60 * 60 * 1000;
       
    67     int dst = 2 * 60 * 60 * 1000;
       
    68     SimpleTimeZone z = new SimpleTimeZone(offset, "Z1", 
       
    69       Calendar.APRIL, 26, 0, t1,
       
    70       Calendar.OCTOBER, 25, 0, t2, dst);
       
    71     GregorianCalendar c = new GregorianCalendar(z);
       
    72     c.set(2004, Calendar.APRIL, 26, 4, 59, 59);
       
    73     long d1 = c.getTimeInMillis();
       
    74     harness.check(z.getOffset(d1), offset);
       
    75     harness.check(z.getOffset(d1 + 2000), offset + dst);
       
    76     
       
    77     // to do : check end date  
       
    78   }
       
    79 }