summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrs Grob <>2009-04-16 10:44:56 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-04-16 10:44:56 -0700
commit891ecb7a2426a152c486a2d71ebe0019174234ec (patch)
tree5a053203bae45c9928ebc49f47eed85966a98229
parentdf92b7ef64e9d70aaedc49230597bd7f617b2b97 (diff)
downloaddalvik-891ecb7a2426a152c486a2d71ebe0019174234ec.tar.gz
AI 146479: Fixes for tests in the sql module.
Some tests are still failing in the cts host environment. this CL fixes most of them in the sql module. BUG=1285921 Automated import of CL 146479
-rw-r--r--libcore/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java17
-rw-r--r--libcore/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java61
2 files changed, 54 insertions, 24 deletions
diff --git a/libcore/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java b/libcore/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
index d8451de02..558e00d88 100644
--- a/libcore/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
+++ b/libcore/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
@@ -78,6 +78,18 @@ public class TimeTest extends TestCase {
static String[][] STRING_ARRAYS = { STRING_GMT_ARRAY, STRING_LA_ARRAY,
STRING_JP_ARRAY };
+ private TimeZone old;
+
+ @Override
+ protected void setUp() {
+ old = TimeZone.getDefault();
+ }
+
+ @Override
+ protected void tearDown() {
+ TimeZone.setDefault(old);
+ }
+
@SuppressWarnings("deprecation")
@TestTargetNew(
level = TestLevel.COMPLETE,
@@ -99,11 +111,12 @@ public class TimeTest extends TestCase {
args = {long.class}
)
public void testTime() {
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
Time theTime = new Time(TIME_TEST1);
// The date should have been created
assertNotNull(theTime);
- assertTrue(theTime.toString().contains("10:45:20"));
+ assertTrue(theTime.toString().contains(STRING_TEST1));
} // end method testTime()
@TestTargetNew(
@@ -150,7 +163,7 @@ public class TimeTest extends TestCase {
Time[] theReturns = { new Time(38720000), new Time(80279000),
new Time(47680000)};
- String[] validTime = { "10:45:20", "22:17:59", "13:14:40", };
+ String[] validTime = { STRING_TEST1, STRING_TEST2, STRING_TEST3, };
String[] invalidTime = { null, "ABCDEFGHI", "233104", "21-43-48" };
for (int i = 0; i < validTime.length; i++) {
diff --git a/libcore/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java b/libcore/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
index cdbc63c88..c2e0f2613 100644
--- a/libcore/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
+++ b/libcore/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
@@ -389,17 +389,37 @@ public class TimestampTest extends TestCase {
public void testValueOfString1() {
Timestamp theReturn;
- long[] theReturnTime = { 38720231, 38720231, 80279000, -38720691,
- 38720000};
- int[] theReturnNanos = { 231000000, 231987654, 0, 309000000, 0,};
+
+ theReturn = Timestamp.valueOf("1970-01-01 10:45:20.231");
+ assertEquals("Wrong result for time test", 38720231,
+ theReturn.getTime());
+ assertEquals("Wrong result for nanos test", 231000000,
+ theReturn.getNanos());
+
+ theReturn = Timestamp.valueOf("1970-01-01 10:45:20.231987654");
+ assertEquals("Wrong result for time test", 38720231,
+ theReturn.getTime());
+ assertEquals("Wrong result for nanos test", 231987654,
+ theReturn.getNanos());
+
+ theReturn = Timestamp.valueOf("1970-01-01 22:17:59.0");
+ assertEquals("Wrong result for time test", 80279000,
+ theReturn.getTime());
+ assertEquals("Wrong result for nanos test", 0,
+ theReturn.getNanos());
+
+ theReturn = Timestamp.valueOf("1969-12-31 13:14:39.309");
+ assertEquals("Wrong result for time test", 38720691,
+ theReturn.getTime());
+ assertEquals("Wrong result for nanos test", 309000000,
+ theReturn.getNanos());
+
+ theReturn = Timestamp.valueOf("1970-01-01 10:45:20");
+ assertEquals("Wrong result for time test", 38720000,
+ theReturn.getTime());
+ assertEquals("Wrong result for nanos test", 0,
+ theReturn.getNanos());
- String[] valid = {
- "1970-01-01 10:45:20.231",
- "1970-01-01 10:45:20.231987654",
- "1970-01-01 22:17:59.0",
- "1969-12-31 13:14:39.309",
- "1970-01-01 10:45:20",
- };
String[] invalid = {
null,
"ABCDEFGHI",
@@ -410,17 +430,10 @@ public class TimestampTest extends TestCase {
"1970-01-01 10:45:20.ABCD87654",
"21-43-48",
};
-
- for (int i = 0; i < valid.length; i++) {
- theReturn = Timestamp.valueOf(valid[i]);
- assertEquals(theReturnTime[i], theReturn.getTime());
- assertEquals(theReturnNanos[i], theReturn.getNanos());
- } // end for
-
for (String element : invalid) {
try {
theReturn = Timestamp.valueOf(element);
- fail("Should throw IllegalArgumentException.");
+ fail("Should throw IllegalArgumentException for " + element);
} catch (IllegalArgumentException e) {
//expected
}
@@ -440,7 +453,8 @@ public class TimestampTest extends TestCase {
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());
+ assertEquals("Wrong conversion for test " + i, STRING_GMT_ARRAY[i],
+ theTimestamp.toString());
} // end for
} // end method testtoString
@@ -457,7 +471,8 @@ public class TimestampTest extends TestCase {
public void testGetNanos() {
for (int i = 0; i < TIME_ARRAY.length; i++) {
Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- assertEquals(NANOS_ARRAY[i], theTimestamp.getNanos());
+ assertEquals("Wrong conversion for test " + i, NANOS_ARRAY[i],
+ theTimestamp.getNanos());
} // end for
} // end method testgetNanos
@@ -478,11 +493,13 @@ public class TimestampTest extends TestCase {
theTimestamp.setNanos(NANOS_ARRAY2[i]);
- assertEquals(NANOS_ARRAY2[i], theTimestamp.getNanos());
+ assertEquals("Wrong conversion for test " + i, NANOS_ARRAY2[i],
+ theTimestamp.getNanos());
// Also check that these Timestamps with detailed nanos values
// convert to
// strings correctly
- assertEquals(STRING_NANOS_ARRAY[i], theTimestamp.toString());
+ assertEquals("Wrong conversion for test " + i,
+ STRING_NANOS_ARRAY[i], theTimestamp.toString());
} // end for
for (int i = 0; i < NANOS_INVALID.length; i++) {