tests/libjava-mauve/src/gnu/testlet/java/sql/Timestamp/TimestampTest.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 /*************************************************************************
       
     2 /* TimestampTest.java - Test java.sql.Timestamp
       
     3 /*
       
     4 /* Copyright (c) 2003 Dalibor Topic (robilad@yahoo.de)
       
     5 /*
       
     6 /* This program is free software; you can redistribute it and/or modify
       
     7 /* it under the terms of the GNU General Public License as published 
       
     8 /* by the Free Software Foundation, either version 2 of the License, or
       
     9 /* (at your option) any later version.
       
    10 /*
       
    11 /* This program is distributed in the hope that it will be useful, but
       
    12 /* WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    14 /* GNU General Public License for more details.
       
    15 /*
       
    16 /* You should have received a copy of the GNU General Public License
       
    17 /* along with this program; if not, write to the Free Software Foundation
       
    18 /* Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
       
    19 /*************************************************************************/
       
    20 
       
    21 // Tags: JDK1.2
       
    22 
       
    23 package gnu.testlet.java.sql.Timestamp;
       
    24 
       
    25 import gnu.testlet.Testlet;
       
    26 import gnu.testlet.TestHarness;
       
    27 
       
    28 import java.sql.*;
       
    29 
       
    30 import java.util.SimpleTimeZone;
       
    31 import java.util.TimeZone;
       
    32 
       
    33 public class TimestampTest implements Testlet
       
    34 {
       
    35   public void
       
    36   test(TestHarness harness)
       
    37   {
       
    38      // Set a common timezone to get the same result everywhere.
       
    39     SimpleTimeZone stz = new SimpleTimeZone(-5 * 1000 * 3600, "GMT");
       
    40     TimeZone.setDefault(stz);
       
    41 
       
    42     try {
       
    43       Timestamp.valueOf("NoSuchTime");
       
    44       harness.check(false, "valueOf");
       
    45     }
       
    46     catch (IllegalArgumentException e) {
       
    47       harness.check(true, "valueOf");
       
    48     }
       
    49 
       
    50 
       
    51     Timestamp ts = new Timestamp(1099999999333L);
       
    52     harness.check(ts.getNanos() == 333000000, "getNanos");
       
    53     harness.check(ts.toString().equals("2004-11-09 06:33:19.333"),
       
    54                   "toString");
       
    55     harness.debug(ts.toString());
       
    56 
       
    57     ts.setNanos(42);
       
    58     harness.check(ts.getNanos() == 42, "getNanos");
       
    59     harness.check(ts.toString().equals("2004-11-09 06:33:19.000000042"),
       
    60                   "toString");
       
    61 
       
    62     harness.debug(ts.toString());
       
    63 
       
    64     ts.setNanos(0);
       
    65     harness.check(ts.getNanos() == 0, "getNanos");
       
    66     harness.check(ts.toString().equals("2004-11-09 06:33:19.0"),
       
    67                   "toString");
       
    68 
       
    69     harness.debug(ts.toString());
       
    70 
       
    71     Timestamp ts2 = new Timestamp(1099999999999L);
       
    72     harness.check(ts.equals(ts2) == false, "equals");
       
    73     ts.setNanos(999000000);
       
    74     harness.check(ts.equals(ts2), "equals");
       
    75 
       
    76     harness.debug(ts.toString());
       
    77     
       
    78     // Restore Timezone
       
    79     TimeZone.setDefault(null);
       
    80   }
       
    81 }