harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r690847 - in /harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql: DateTest.java TimeTest.java TimestampTest.java
Date Mon, 01 Sep 2008 05:10:32 GMT
Author: tonywu
Date: Sun Aug 31 22:10:32 2008
New Revision: 690847

URL: http://svn.apache.org/viewvc?rev=690847&view=rev
Log:
Add some regression test for Date,Time and Timestamp in the locales other than GMT. Clean
up the side effect after setting the default locale.

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java?rev=690847&r1=690846&r2=690847&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java
Sun Aug 31 22:10:32 2008
@@ -234,16 +234,26 @@
      * toString() method.
      */
     public void testToString() {
-        // This test is set up for GMT time zone, so need to set the time zone
-        // to GMT first
-        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
-
-        for (int i = 0; i < TIME_ARRAY.length; i++) {
-            Date theDate = new Date(TIME_ARRAY[i]);
-            assertEquals(SQL_DATEARRAY[i], theDate.toString());
+		// Loop through the timezones testing the String conversion for each
+		for (int i = 0; i < TIMEZONES.length; i++) {
+			testToString(TIMEZONES[i], TIME_ARRAY, SQL_TZ_DATEARRAYS[i]);
+		} // end for
+
+	} // end method testToString()
+
+    private void testToString(String timeZone, long[] theDates, String[] theDateStrings)
{
+        // Set the timezone
+        TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+
+        for (int i = 0; i < theDates.length; i++) {
+            // Create the Date object
+            Date theDate = new Date(theDates[i]);
+            // Convert to a date string ... and compare
+            String JDBCString = theDate.toString();
+            assertEquals(theDateStrings[i], JDBCString);
         } // end for
 
-    } // end method testToString()
+    } // end testToString( String, long[], String[] )
 
     /*
      * Test of the void setTime(int) method This does depend on the Time Zone
@@ -374,6 +384,13 @@
             // expected
         }
     }
+    
+    // Reset defualt timezone
+    static TimeZone defaultTimeZone = TimeZone.getDefault();
+    
+    protected void tearDown(){
+    	TimeZone.setDefault(defaultTimeZone);
+    }
 
 } // end class DateTest
 

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java?rev=690847&r1=690846&r2=690847&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
Sun Aug 31 22:10:32 2008
@@ -299,5 +299,13 @@
             // expected
         }
     }
+    
+    
+    // Reset defualt timezone
+    static TimeZone defaultTimeZone = TimeZone.getDefault();
+    
+    protected void tearDown(){
+    	TimeZone.setDefault(defaultTimeZone);
+    }
 } // end class TimeTest
 

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java?rev=690847&r1=690846&r2=690847&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
Sun Aug 31 22:10:32 2008
@@ -109,6 +109,13 @@
     static String[][] STRING_ARRAYS = { STRING_GMT_ARRAY, STRING_LA_ARRAY,
             STRING_JP_ARRAY };
 
+    // Test ToString
+	static String[][] STRING_TIMESTAMP_ARRAYS = {
+			STRING_GMT_ARRAY,
+			new String[] { "1970-01-01 02:45:20.231", "1970-01-01 14:17:59.0",
+					"1969-12-31 05:14:39.309" },
+			new String[]{"1970-01-01 19:45:20.231","1970-01-02 07:17:59.0","1969-12-31 22:14:39.309"}
};
+    
     /*
      * Constructor test
      */
@@ -228,6 +235,7 @@
      */
     @SuppressWarnings("deprecation")
     public void testGetDate() {
+    	TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
         for (int i = 0; i < TIME_ARRAY.length; i++) {
             Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
             assertEquals(DATE_ARRAY[i], theTimestamp.getDate());
@@ -240,6 +248,7 @@
      */
     @SuppressWarnings("deprecation")
     public void testGetHours() {
+    	TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
         for (int i = 0; i < TIME_ARRAY.length; i++) {
             Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
             assertEquals(HOURS_ARRAY[i], theTimestamp.getHours());
@@ -277,6 +286,7 @@
     static String theExceptionMessage = "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff";
 
     public void testValueOfString() {
+    	TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
         for (int i = 0; i < TIME_ARRAY.length; i++) {
             Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
             Timestamp theTimestamp2 = Timestamp.valueOf(STRING_GMT_ARRAY[i]);
@@ -308,7 +318,8 @@
      * Method test for valueOf
      */
     public void testValueOfString1() {
-
+    	TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+    	
         Timestamp theReturn;
         long[] theReturnTime = { 38720231, 38720231, 80279000, -38720691,
                 38720000 };
@@ -350,13 +361,34 @@
      * Method test for toString
      */
     public void testToString() {
-        for (int i = 0; i < TIME_ARRAY.length; i++) {
-            Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
-            assertEquals(STRING_GMT_ARRAY[i], theTimestamp.toString());
-        } // end for
+		for (int i = 0; i < TIME_ARRAY.length; i++) {
+			testToString(TIMEZONES[i], TIME_ARRAY, STRING_TIMESTAMP_ARRAYS[i]);
+		} // end for
+		
+		TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+
+		Timestamp t1 = new Timestamp(Long.MIN_VALUE);
+		assertEquals("292278994-08-17 07:12:55.192", t1.toString()); //$NON-NLS-1$
 
-    } // end method testtoString
+		Timestamp t2 = new Timestamp(Long.MIN_VALUE + 1);
+		assertEquals("292278994-08-17 07:12:55.193", t2.toString()); //$NON-NLS-1$
 
+		Timestamp t3 = new Timestamp(Long.MIN_VALUE + 807);
+		assertEquals("292278994-08-17 07:12:55.999", t3.toString()); //$NON-NLS-1$
+
+		Timestamp t4 = new Timestamp(Long.MIN_VALUE + 808);
+		assertEquals("292269055-12-02 16:47:05.0", t4.toString()); //$NON-NLS-1$
+	} // end method testtoString
+
+    private void testToString(String timeZone, long[] theTimeStamps, String[] theTimeStampStrings)
{
+    	TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+        for (int i = 0; i < TIME_ARRAY.length; i++) {
+            Timestamp theTimestamp = new Timestamp(theTimeStamps[i]);
+            assertEquals(theTimeStampStrings[i], theTimestamp.toString());
+        } // end for
+    	
+    }
+    
     /*
      * Method test for getNanos
      */
@@ -372,6 +404,8 @@
      * Method test for setNanos
      */
     public void testSetNanosint() {
+    	TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+    	
         int[] NANOS_INVALID = { -137891990, 1635665198, -1 };
         for (int i = 0; i < TIME_ARRAY.length; i++) {
             Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
@@ -599,22 +633,10 @@
         SerializationTest.verifyGolden(this, object);
     }
 
-    /**
-     * @tests java.sql.Timestamp#toString()
-     */
-    public void test_toString() {
-
-        Timestamp t1 = new Timestamp(Long.MIN_VALUE);
-        assertEquals("292278994-08-17 07:12:55.192", t1.toString()); //$NON-NLS-1$
-
-        Timestamp t2 = new Timestamp(Long.MIN_VALUE + 1);
-        assertEquals("292278994-08-17 07:12:55.193", t2.toString()); //$NON-NLS-1$
-
-        Timestamp t3 = new Timestamp(Long.MIN_VALUE + 807);
-        assertEquals("292278994-08-17 07:12:55.999", t3.toString()); //$NON-NLS-1$
-
-        Timestamp t4 = new Timestamp(Long.MIN_VALUE + 808);
-        assertEquals("292269055-12-02 16:47:05.0", t4.toString()); //$NON-NLS-1$
+    // Reset defualt timezone
+    TimeZone defaultTimeZone = TimeZone.getDefault();
+    
+    protected void tearDown(){
+    	TimeZone.setDefault(defaultTimeZone);
     }
-
 } // end class TimestampTest



Mime
View raw message