summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-11 12:11:54 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-11 12:11:54 -0700
commitab28398a565e5ce8a56cdfd50ac6226e5317cf66 (patch)
tree589d7add2659de2974805a9def858204999f1fa7 /luni
parent7a237c50c718d326c49da2a449ba6eb0c668837a (diff)
downloadlibcore-ab28398a565e5ce8a56cdfd50ac6226e5317cf66.zip
libcore-ab28398a565e5ce8a56cdfd50ac6226e5317cf66.tar.gz
libcore-ab28398a565e5ce8a56cdfd50ac6226e5317cf66.tar.bz2
auto import from //branches/cupcake/...@137873
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/java/util/ComparableTimSort.java14
-rw-r--r--luni/src/main/java/java/util/TimSort.java10
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassLoaderTest.java11
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/EnumTest.java4
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java9
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PackageTest.java3
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringTest.java2
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java9
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java5
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java70
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java4
-rw-r--r--luni/src/test/java/tests/api/java/io/AllTests.java4
-rw-r--r--luni/src/test/java/tests/api/java/io/FileTest.java19
-rw-r--r--luni/src/test/java/tests/api/java/io/SerializationStressTest.java1005
-rw-r--r--luni/src/test/java/tests/api/java/io/SerializationStressTest0.java1000
-rw-r--r--luni/src/test/java/tests/api/java/io/SerializationStressTest1.java10
-rw-r--r--luni/src/test/java/tests/api/java/io/SerializationStressTest2.java11
-rw-r--r--luni/src/test/java/tests/api/java/io/SerializationStressTest3.java19
-rw-r--r--luni/src/test/java/tests/api/java/io/SerializationStressTest4.java12
-rw-r--r--luni/src/test/java/tests/api/java/lang/ProcessManagerTest.java14
-rw-r--r--luni/src/test/java/tests/api/java/net/CookieHandlerTest.java1
-rw-r--r--luni/src/test/java/tests/api/java/net/DatagramSocketTest.java3
-rw-r--r--luni/src/test/java/tests/api/java/net/MulticastSocketTest.java14
-rw-r--r--luni/src/test/java/tests/api/java/net/ResponseCacheTest.java9
-rw-r--r--luni/src/test/java/tests/api/java/net/SocketPermissionTest.java52
-rw-r--r--luni/src/test/java/tests/api/java/util/CurrencyTest.java94
-rw-r--r--luni/src/test/java/tests/api/java/util/FormatterTest.java140
-rw-r--r--luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java10
-rw-r--r--luni/src/test/java/tests/api/java/util/PropertiesTest.java4
-rw-r--r--luni/src/test/java/tests/api/java/util/ResourceBundleTest.java4
-rw-r--r--luni/src/test/java/tests/api/java/util/TimeZoneTest.java3
-rw-r--r--luni/src/test/resources/tests/api/java/net/file1.cache1
32 files changed, 1376 insertions, 1194 deletions
diff --git a/luni/src/main/java/java/util/ComparableTimSort.java b/luni/src/main/java/java/util/ComparableTimSort.java
index b9f7145..882add1 100644
--- a/luni/src/main/java/java/util/ComparableTimSort.java
+++ b/luni/src/main/java/java/util/ComparableTimSort.java
@@ -105,7 +105,7 @@ class ComparableTimSort {
*
* @param a the array to be sorted
*/
- private ComparableTimSort(Object[] a) {
+ private ComparableTimSort(Object[] a) {
this.a = a;
// Allocate temp storage (which may be increased later if necessary)
@@ -675,7 +675,7 @@ class ComparableTimSort {
dest += count1;
cursor1 += count1;
len1 -= count1;
- if (len1 == 1)
+ if (len1 <= 1) // len1 == 1 || len1 == 0
break outer;
}
a[dest++] = a[cursor2++];
@@ -706,6 +706,9 @@ class ComparableTimSort {
if (DEBUG) assert len2 > 0;
System.arraycopy(a, cursor2, a, dest, len2);
a[dest + len2] = tmp[cursor1]; // Last elt of run 1 to end of merge
+ } else if (len1 == 0) {
+ throw new IllegalArgumentException(
+ "Comparison method violates its general contract!");
} else {
if (DEBUG) assert len2 == 0;
if (DEBUG) assert len1 > 1;
@@ -804,8 +807,8 @@ class ComparableTimSort {
cursor2 -= count2;
len2 -= count2;
System.arraycopy(tmp, cursor2 + 1, a, dest + 1, count2);
- if (len2 == 1)
- break outer;
+ if (len2 <= 1)
+ break outer; // len2 == 1 || len2 == 0
}
a[dest--] = a[cursor1--];
if (--len1 == 0)
@@ -824,6 +827,9 @@ class ComparableTimSort {
cursor1 -= len1;
System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
a[dest] = tmp[cursor2]; // Move first elt of run2 to front of merge
+ } else if (len2 == 0) {
+ throw new IllegalArgumentException(
+ "Comparison method violates its general contract!");
} else {
if (DEBUG) assert len1 == 0;
if (DEBUG) assert len2 > 0;
diff --git a/luni/src/main/java/java/util/TimSort.java b/luni/src/main/java/java/util/TimSort.java
index 3c73a2c..9c27ddc 100644
--- a/luni/src/main/java/java/util/TimSort.java
+++ b/luni/src/main/java/java/util/TimSort.java
@@ -708,7 +708,7 @@ class TimSort<T> {
dest += count1;
cursor1 += count1;
len1 -= count1;
- if (len1 == 1)
+ if (len1 <= 1) // len1 == 1 || len1 == 0
break outer;
}
a[dest++] = a[cursor2++];
@@ -739,6 +739,9 @@ class TimSort<T> {
if (DEBUG) assert len2 > 0;
System.arraycopy(a, cursor2, a, dest, len2);
a[dest + len2] = tmp[cursor1]; // Last elt of run 1 to end of merge
+ } else if (len1 == 0) {
+ throw new IllegalArgumentException(
+ "Comparison method violates its general contract!");
} else {
if (DEBUG) assert len2 == 0;
if (DEBUG) assert len1 > 1;
@@ -837,7 +840,7 @@ class TimSort<T> {
cursor2 -= count2;
len2 -= count2;
System.arraycopy(tmp, cursor2 + 1, a, dest + 1, count2);
- if (len2 == 1)
+ if (len2 <= 1) // len2 == 1 || len2 == 0
break outer;
}
a[dest--] = a[cursor1--];
@@ -857,6 +860,9 @@ class TimSort<T> {
cursor1 -= len1;
System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
a[dest] = tmp[cursor2]; // Move first elt of run2 to front of merge
+ } else if (len2 == 0) {
+ throw new IllegalArgumentException(
+ "Comparison method violates its general contract!");
} else {
if (DEBUG) assert len1 == 0;
if (DEBUG) assert len2 > 0;
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassLoaderTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassLoaderTest.java
index fd68f66..9d9a086 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassLoaderTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassLoaderTest.java
@@ -124,9 +124,8 @@ public class ClassLoaderTest extends TestCase {
method = "clearAssertionStatus",
args = {}
)
- @AndroidOnly("clearAssertionStatus method is not supported.")
- @BrokenTest("Android doesn't support assertions to be activated through " +
- "the api")
+ @KnownFailure("Android doesn't support assertions to be activated " +
+ "through the api")
public void test_clearAssertionStatus() {
String className = getClass().getPackage().getName() + ".TestAssertions";
String className1 = getClass().getPackage().getName() + ".TestAssertions1";
@@ -805,9 +804,9 @@ public class ClassLoaderTest extends TestCase {
method = "getPackages",
args = {}
)
- @KnownFailure("The package canot be found. Seems like the cache is not"
- + "shared between the class loaders. But this test seems to"
- + "expect exactly that. this tests works on the RI.")
+ @KnownFailure("The package canot be found. Seems like the cache is not " +
+ "shared between the class loaders. But this test seems to " +
+ "expect exactly that. this tests works on the RI.")
public void test_getPackages() {
PackageClassLoader pcl = new PackageClassLoader();
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/EnumTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/EnumTest.java
index ccaddeb..94b495f 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/EnumTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/EnumTest.java
@@ -275,10 +275,10 @@ public class EnumTest extends TestCase {
method = "!SerializationGolden",
args = {}
)
- public void _test_compatibilitySerialization_inClass_Complex_Harmony() throws Exception{
+ public void test_compatibilitySerialization_inClass_Complex_Harmony() throws Exception{
// TODO migrate to the new testing framework
assertTrue(SerializationTester.assertCompabilityEquals(new MockEnum2(),
- "serialization/org/apache/harmony/luni/tests/java/lang/EnumTest.harmony.ser"));
+ "/serialization/org/apache/harmony/luni/tests/java/lang/EnumTest.harmony.ser"));
}
/**
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java
index 4d5f04d..02bed3c 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java
@@ -17,8 +17,6 @@
package org.apache.harmony.luni.tests.java.lang;
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
@@ -796,9 +794,6 @@ public class MathTest extends junit.framework.TestCase {
method = "pow",
args = {double.class, double.class}
)
- @KnownFailure("Math.pow(double a, double b) returns 1.0 if " +
- "the absolute value of the first argument equals 1 and " +
- "the second argument is infinite. It should return NaN.")
public void test_powDD() {
// Test for method double java.lang.Math.pow(double, double)
assertTrue("pow returned incorrect value",
@@ -825,9 +820,9 @@ public class MathTest extends junit.framework.TestCase {
Math.pow(0.9, Double.POSITIVE_INFINITY));
assertEquals("pow returned incorrect value", Double.NaN,
- Math.pow(1.0, Double.NEGATIVE_INFINITY));
+ Math.pow(1.0, Double.NEGATIVE_INFINITY));
assertEquals("pow returned incorrect value", Double.NaN,
- Math.pow(1.0, Double.POSITIVE_INFINITY));
+ Math.pow(1.0, Double.POSITIVE_INFINITY));
assertEquals("pow returned incorrect value", 0.0, Math.pow(0, 1));
assertEquals("pow returned incorrect value", 0.0,
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PackageTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PackageTest.java
index e38ee63..b1b7408 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PackageTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PackageTest.java
@@ -259,7 +259,7 @@ public class PackageTest extends junit.framework.TestCase {
method = "getPackage",
args = {java.lang.String.class}
)
- @KnownFailure("Package information missing on android")
+ @KnownFailure("Real package information missing on android.")
public void test_getPackageLjava_lang_String() throws Exception {
assertSame("Package getPackage failed for java.lang", Package
.getPackage("java.lang"), Package.getPackage("java.lang"));
@@ -302,7 +302,6 @@ public class PackageTest extends junit.framework.TestCase {
method = "hashCode",
args = {}
)
- @KnownFailure("Package information missing on android")
public void test_hashCode() {
Package p1 = Package.getPackage("java.lang");
if (p1 != null) {
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringTest.java
index 30510c2..4ad0c52 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringTest.java
@@ -705,7 +705,7 @@ public class StringTest extends TestCase {
level = TestLevel.ADDITIONAL,
notes = "Regression test for some existing bugs and crashes",
method = "format",
- args = { String.class, Object.class }
+ args = { String.class, Object[].class }
)
public void testProblemCases() {
BigDecimal[] input = new BigDecimal[] {
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java
index 7e8030a..39bc92d 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java
@@ -17,8 +17,7 @@
package org.apache.harmony.luni.tests.java.lang;
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestTargets;
+import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
@@ -999,7 +998,7 @@ public class ThreadGroupTest extends junit.framework.TestCase implements Thread.
args = {}
)
@SuppressWarnings("deprecation")
- @AndroidOnly("Thread.resume is implemented on some RI")
+ @BrokenTest("Thread.resume is implemented on some RI")
public void test_resume() throws OutOfMemoryError {
// Test for method void java.lang.ThreadGroup.resume()
final ThreadGroup originalCurrent = getInitialThreadGroup();
@@ -1236,7 +1235,7 @@ public class ThreadGroupTest extends junit.framework.TestCase implements Thread.
method = "stop",
args = {}
)
- @AndroidOnly("stop() method not implemented. throws UnsupportedOperationException.")
+ @BrokenTest("stop() method not implemented.")
@SuppressWarnings("deprecation")
public void test_stop() throws OutOfMemoryError {
// Test for method void java.lang.ThreadGroup.stop()
@@ -1305,7 +1304,7 @@ public class ThreadGroupTest extends junit.framework.TestCase implements Thread.
method = "suspend",
args = {}
)
- @AndroidOnly("suspend() method not implemented. throws UnsupportedOperationException.")
+ @BrokenTest("suspend() method not implemented.")
@SuppressWarnings("deprecation")
public void test_suspend() throws OutOfMemoryError {
// Test for method void java.lang.ThreadGroup.suspend()
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
index 29d26da..968a056 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
@@ -17,7 +17,6 @@
package org.apache.harmony.luni.tests.java.net;
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
@@ -28,12 +27,10 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.CacheRequest;
import java.net.CacheResponse;
-import java.net.DatagramSocket;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.ResponseCache;
-import java.net.SocketException;
import java.net.SocketPermission;
import java.net.URI;
import java.net.URL;
@@ -592,7 +589,6 @@ public class HttpURLConnectionTest extends junit.framework.TestCase {
method = "setUseCaches",
args = {boolean.class}
)
- @KnownFailure("getInputStream doesn't call get method of cache")
public void test_UseCache_HttpURLConnection_NonCached() throws IOException {
ResponseCache.setDefault(new MockNonCachedResponseCache());
uc = (HttpURLConnection) url.openConnection();
@@ -600,7 +596,6 @@ public class HttpURLConnectionTest extends junit.framework.TestCase {
// default useCaches is true
assertTrue(uc.getUseCaches());
uc.setDoInput(true);
- uc.connect();
// make sure ResponseCache.get/put is called
isGetCalled = false;
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java
index 1b2aa22..498c486 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java
@@ -18,12 +18,10 @@
package org.apache.harmony.luni.tests.java.net;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import java.io.Serializable;
-import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
@@ -1173,23 +1171,57 @@ public class Inet6AddressTest extends junit.framework.TestCase {
args = {}
)
public void test_getHostAddress() throws Exception {
- InetAddress addr = Inet6Address.getByName("localhost");
- assertEquals("127.0.0.1", addr.getHostAddress());
-
- addr = Inet6Address.getByName("127.0.0.1");
- assertEquals("127.0.0.1", addr.getHostAddress());
-
- addr = Inet6Address.getByName("224.0.0.0");
- assertEquals("224.0.0.0", addr.getHostAddress());
-
- addr = Inet6Address.getByName("1");
- assertEquals("0.0.0.1", addr.getHostAddress());
-
- addr = Inet6Address.getByName("1.1");
- assertEquals("1.0.0.1", addr.getHostAddress());
-
- addr = Inet6Address.getByName("1.1.1");
- assertEquals("1.1.0.1", addr.getHostAddress());
+ InetAddress aAddr = Inet6Address.getByName("localhost");
+ assertEquals("127.0.0.1", aAddr.getHostAddress());
+
+ aAddr = Inet6Address.getByName("127.0.0.1");
+ assertEquals("127.0.0.1", aAddr.getHostAddress());
+
+ aAddr = Inet6Address.getByName("224.0.0.0");
+ assertEquals("224.0.0.0", aAddr.getHostAddress());
+
+ aAddr = Inet6Address.getByName("1");
+ assertEquals("0.0.0.1", aAddr.getHostAddress());
+
+ aAddr = Inet6Address.getByName("1.1");
+ assertEquals("1.0.0.1", aAddr.getHostAddress());
+
+ aAddr = Inet6Address.getByName("1.1.1");
+ assertEquals("1.1.0.1", aAddr.getHostAddress());
+
+ byte[] bAddr = { (byte) 0xFE, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x11,
+ 0x25, (byte) 0xFF, (byte) 0xFE, (byte) 0xF8, (byte) 0x7C,
+ (byte) 0xB2 };
+ aAddr = Inet6Address.getByAddress(bAddr);
+ assertEquals("fe80:0:0:0:211:25ff:fef8:7cb2", aAddr.getHostAddress());
+
+ byte[] cAddr = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
+ aAddr = Inet6Address.getByAddress(cAddr);
+ assertEquals("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", aAddr.getHostAddress());
+
+ byte[] dAddr = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
+ aAddr = Inet6Address.getByAddress(dAddr);
+ assertEquals("0:0:0:0:0:0:0:0", aAddr.getHostAddress());
+
+ byte[] eAddr = { (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03,
+ (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07,
+ (byte) 0x08, (byte) 0x09, (byte) 0x0a, (byte) 0x0b,
+ (byte) 0x0c, (byte) 0x0d, (byte) 0x0e, (byte) 0x0f};
+ aAddr = Inet6Address.getByAddress(eAddr);
+ assertEquals("1:203:405:607:809:a0b:c0d:e0f", aAddr.getHostAddress());
+
+ byte[] fAddr = { (byte) 0x00, (byte) 0x10, (byte) 0x20, (byte) 0x30,
+ (byte) 0x40, (byte) 0x50, (byte) 0x60, (byte) 0x70,
+ (byte) 0x80, (byte) 0x90, (byte) 0xa0, (byte) 0xb0,
+ (byte) 0xc0, (byte) 0xd0, (byte) 0xe0, (byte) 0xf0};
+ aAddr = Inet6Address.getByAddress(fAddr);
+ assertEquals("10:2030:4050:6070:8090:a0b0:c0d0:e0f0", aAddr.getHostAddress());
}
@TestTargetNew(
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java
index 15f3a5a..b979628 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java
@@ -15,6 +15,7 @@
*/
package org.apache.harmony.luni.tests.java.net;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
@@ -323,7 +324,8 @@ public class InetSocketAddressTest extends TestCase {
method = "!SerializationGolden",
args = {}
)
- public void _testSerializationCompatibility() throws Exception {
+ @KnownFailure("Problem with deserialization of Localhost vs. localhost")
+ public void testSerializationCompatibility() throws Exception {
Object[] testCases = {
InetSocketAddress.createUnresolved("badhost", 1000), // unresolved
diff --git a/luni/src/test/java/tests/api/java/io/AllTests.java b/luni/src/test/java/tests/api/java/io/AllTests.java
index 295d4d8..2747ab2 100644
--- a/luni/src/test/java/tests/api/java/io/AllTests.java
+++ b/luni/src/test/java/tests/api/java/io/AllTests.java
@@ -90,13 +90,11 @@ public class AllTests {
suite.addTestSuite(RandomAccessFileTest.class);
suite.addTestSuite(SequenceInputStreamTest.class);
suite.addTestSuite(SerializablePermissionTest.class);
- suite.addTestSuite(SerializationStressTest.class);
+ suite.addTestSuite(SerializationStressTest0.class);
suite.addTestSuite(SerializationStressTest1.class);
suite.addTestSuite(SerializationStressTest2.class);
suite.addTestSuite(SerializationStressTest3.class);
suite.addTestSuite(SerializationStressTest4.class);
- suite.addTestSuite(SerializationStressTest4.class);
- suite.addTestSuite(SerializationStressTest5.class);
suite.addTestSuite(StreamCorruptedExceptionTest.class);
suite.addTestSuite(StreamTokenizerTest.class);
suite.addTestSuite(StringBufferInputStreamTest.class);
diff --git a/luni/src/test/java/tests/api/java/io/FileTest.java b/luni/src/test/java/tests/api/java/io/FileTest.java
index 865717e..85c4bc4 100644
--- a/luni/src/test/java/tests/api/java/io/FileTest.java
+++ b/luni/src/test/java/tests/api/java/io/FileTest.java
@@ -1097,8 +1097,9 @@ public class FileTest extends junit.framework.TestCase {
args = {}
)
public void test_getPath() {
- System.setProperty("user.home", System.getProperty("java.io.tmpdir"));
- String base = System.getProperty("user.home");
+ String oldUserDir = System.getProperty("java.io.tmpdir");
+ System.setProperty("user.dir", System.getProperty("java.io.tmpdir"));
+ String base = System.getProperty("user.dir");
String fname;
File f1;
if (!base.regionMatches((base.length() - 1), slash, 0, 1))
@@ -1122,6 +1123,7 @@ public class FileTest extends junit.framework.TestCase {
f2.delete();
f3.delete();
f4.delete();
+ System.setProperty("user.dir", oldUserDir);
}
/**
@@ -2099,27 +2101,27 @@ public class FileTest extends junit.framework.TestCase {
f1.createNewFile();
long orgTime = f1.lastModified();
// Subtracting 100 000 milliseconds from the orgTime of File f1
- f1.setLastModified(orgTime - 100000);
+ assertTrue(f1.setLastModified(orgTime - 100000));
long lastModified = f1.lastModified();
assertTrue("Test 1: LastModifed time incorrect: " + lastModified,
lastModified == (orgTime - 100000));
// Subtracting 10 000 000 milliseconds from the orgTime of File f1
- f1.setLastModified(orgTime - 10000000);
+ assertTrue(f1.setLastModified(orgTime - 10000000));
lastModified = f1.lastModified();
assertTrue("Test 2: LastModifed time incorrect: " + lastModified,
lastModified == (orgTime - 10000000));
// Adding 100 000 milliseconds to the orgTime of File f1
- f1.setLastModified(orgTime + 100000);
+ assertTrue(f1.setLastModified(orgTime + 100000));
lastModified = f1.lastModified();
assertTrue("Test 3: LastModifed time incorrect: " + lastModified,
lastModified == (orgTime + 100000));
// Adding 10 000 000 milliseconds from the orgTime of File f1
- f1.setLastModified(orgTime + 10000000);
+ assertTrue(f1.setLastModified(orgTime + 10000000));
lastModified = f1.lastModified();
assertTrue("Test 4: LastModifed time incorrect: " + lastModified,
lastModified == (orgTime + 10000000));
// Trying to set time to an exact number
- f1.setLastModified(315550800000L);
+ assertTrue(f1.setLastModified(315550800000L));
lastModified = f1.lastModified();
assertTrue("Test 5: LastModified time incorrect: " + lastModified,
lastModified == 315550800000L);
@@ -2139,6 +2141,9 @@ public class FileTest extends junit.framework.TestCase {
fail("IllegalArgumentException not thrown.");
} catch (IllegalArgumentException e) {
}
+
+ File f2 = new File("/does not exist.txt");
+ assertFalse(f2.setLastModified(42));
} catch (IOException e) {
fail("Unexpected IOException during test : " + e.getMessage());
} finally {
diff --git a/luni/src/test/java/tests/api/java/io/SerializationStressTest.java b/luni/src/test/java/tests/api/java/io/SerializationStressTest.java
index 7c4d0b1..45d92bd 100644
--- a/luni/src/test/java/tests/api/java/io/SerializationStressTest.java
+++ b/luni/src/test/java/tests/api/java/io/SerializationStressTest.java
@@ -17,7 +17,7 @@
package tests.api.java.io;
-import dalvik.annotation.TestTargets;
+import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
@@ -95,29 +95,40 @@ public class SerializationStressTest extends junit.framework.TestCase implements
protected transient ByteArrayOutputStream bao;
- // -----------------------------------------------------------------------------------
+ protected void t_MixPrimitivesAndObjects() throws IOException,
+ ClassNotFoundException {
+ int i = 7;
+ String s1 = "string 1";
+ String s2 = "string 2";
+ byte[] bytes = { 1, 2, 3 };
- private static class ObjectInputStreamSubclass extends ObjectInputStream {
- private Vector resolvedClasses = new Vector();
+ oos.writeInt(i);
+ oos.writeObject(s1);
+ oos.writeUTF(s2);
+ oos.writeObject(bytes);
+ oos.close();
+ try {
+ ois = new ObjectInputStream(loadStream());
- public ObjectInputStreamSubclass(InputStream in) throws IOException,
- StreamCorruptedException {
- super(in);
- }
+ int j = ois.readInt();
+ assertTrue("Wrong int :" + j, i == j);
- public Class resolveClass(ObjectStreamClass osClass)
- throws IOException, ClassNotFoundException {
- Class result = super.resolveClass(osClass);
- resolvedClasses.addElement(result);
- return result;
- }
+ String l1 = (String) ois.readObject();
+ assertTrue("Wrong obj String :" + l1, s1.equals(l1));
+
+ String l2 = (String) ois.readUTF();
+ assertTrue("Wrong UTF String :" + l2, s2.equals(l2));
+
+ byte[] bytes2 = (byte[]) ois.readObject();
+ assertTrue("Wrong byte[]", Arrays.equals(bytes, bytes2));
- public Class[] resolvedClasses() {
- return (Class[]) resolvedClasses.toArray(new Class[resolvedClasses
- .size()]);
+ } finally {
+ ois.close();
}
}
+ // -----------------------------------------------------------------------------------
+
static final Map TABLE = new Hashtable();
static final Map MAP = new HashMap();
@@ -290,965 +301,5 @@ public class SerializationStressTest extends junit.framework.TestCase implements
}
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_1_Constructor() {
- // Test for method java.io.ObjectOutputStream(java.io.OutputStream)
-
- try {
- oos.close();
- oos = new ObjectOutputStream(new ByteArrayOutputStream());
- oos.close();
- } catch (Exception e) {
- fail("Failed to create ObjectOutputStream : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_2_close() {
- // Test for method void java.io.ObjectOutputStream.close()
- try {
- oos.close();
- oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
- oos.close();
- oos.writeChar('T');
- oos.writeObject(FOO);
- // Writing to a closed stream does not cause problems. This is
- // the expected behavior
- } catch (IOException e) {
- fail("Operation on closed stream threw IOException : "
- + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_3_defaultWriteObject() {
- // Test for method void java.io.ObjectOutputStream.defaultWriteObject()
-
- try {
- oos.defaultWriteObject();
- } catch (NotActiveException e) {
- // Correct
- return;
- } catch (IOException e) {
- }
- fail(
- "Failed to throw NotActiveException when invoked outside readObject");
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_4_flush() {
- // Test for method void java.io.ObjectOutputStream.flush()
- try {
- oos.close();
- oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
- int size = bao.size();
- oos.writeByte(127);
- assertTrue("Data flushed already", bao.size() == size);
- oos.flush();
- assertTrue("Failed to flush data", bao.size() > size);
- // we don't know how many bytes are actually written for 1 byte,
- // so we test > <before>
- oos.close();
- oos = null;
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_5_reset() {
- // Test for method void java.io.ObjectOutputStream.reset()
- try {
- String o = "HelloWorld";
- oos.writeObject(o);
- oos.writeObject(o);
- oos.reset();
- oos.writeObject(o);
- ois = new ObjectInputStream(loadStream());
- ois.close();
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_6_write() {
- // Test for method void java.io.ObjectOutputStream.write(byte [], int,
- // int)
- try {
- byte[] buf = new byte[255];
- byte[] output = new byte[255];
- for (int i = 0; i < output.length; i++)
- output[i] = (byte) i;
- oos.write(output, 0, output.length);
- oos.close();
- ois = new ObjectInputStream(loadStream());
- ois.readFully(buf);
- ois.close();
- for (int i = 0; i < output.length; i++)
- if (buf[i] != output[i])
- fail("Read incorrect byte: " + i);
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_6a_write() {
- // Test for method void java.io.ObjectOutputStream.write(byte [], int,
- // int)
- try {
- byte[] buf = new byte[256];
- byte[] output = new byte[256];
- for (int i = 0; i < output.length; i++)
- output[i] = (byte) (i & 0xff);
- oos.write(output, 0, output.length);
- oos.close();
- ois = new ObjectInputStream(loadStream());
- ois.readFully(buf);
- ois.close();
- for (int i = 0; i < output.length; i++)
- if (buf[i] != output[i])
- fail("Read incorrect byte: " + i);
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_7_write() {
- // Test for method void java.io.ObjectOutputStream.write(int)
- try {
- byte[] buf = new byte[10];
- oos.write('T');
- oos.close();
- ois = new ObjectInputStream(loadStream());
- assertEquals("Read incorrect byte", 'T', ois.read());
- ois.close();
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_8_write() {
- // Test for method void java.io.ObjectOutputStream.write(byte [])
- try {
- byte[] buf = new byte[10];
- oos.write("HelloWorld".getBytes());
- oos.close();
- ois = new ObjectInputStream(loadStream());
- ois.read(buf, 0, 10);
- ois.close();
- assertEquals("Read incorrect bytes", "HelloWorld", new String(buf, 0, 10)
- );
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_9_writeBoolean() {
- // Test for method void java.io.ObjectOutputStream.writeBoolean(boolean)
- try {
- oos.writeBoolean(true);
- oos.close();
- ois = new ObjectInputStream(loadStream());
- assertTrue("Wrote incorrect byte value", ois.readBoolean());
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_10_writeByte() {
- // Test for method void java.io.ObjectOutputStream.writeByte(int)
- try {
- oos.writeByte(127);
- oos.close();
- ois = new ObjectInputStream(loadStream());
- assertEquals("Wrote incorrect byte value", 127, ois.readByte());
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_11_writeBytes() {
- // Test for method void
- // java.io.ObjectOutputStream.writeBytes(java.lang.String)
- try {
- byte[] buf = new byte[10];
- oos.writeBytes("HelloWorld");
- oos.close();
- ois = new ObjectInputStream(loadStream());
- ois.readFully(buf);
- ois.close();
- assertEquals("Wrote incorrect bytes value", "HelloWorld", new String(buf, 0, 10)
- );
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_12_writeChar() {
- // Test for method void java.io.ObjectOutputStream.writeChar(int)
- try {
- oos.writeChar('T');
- oos.close();
- ois = new ObjectInputStream(loadStream());
- assertEquals("Wrote incorrect char value", 'T', ois.readChar());
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_13_writeChars() {
- // Test for method void
- // java.io.ObjectOutputStream.writeChars(java.lang.String)
- try {
- int avail = 0;
- char[] buf = new char[10];
- oos.writeChars("HelloWorld");
- oos.close();
- ois = new ObjectInputStream(loadStream());
- // Number of prim data bytes in stream / 2 to give char index
- avail = ois.available() / 2;
- for (int i = 0; i < avail; ++i)
- buf[i] = ois.readChar();
- ois.close();
- assertEquals("Wrote incorrect chars", "HelloWorld", new String(buf, 0, 10)
- );
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_14_writeDouble() {
- // Test for method void java.io.ObjectOutputStream.writeDouble(double)
- try {
- oos.writeDouble(Double.MAX_VALUE);
- oos.close();
- ois = new ObjectInputStream(loadStream());
- assertTrue("Wrote incorrect double value",
- ois.readDouble() == Double.MAX_VALUE);
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_15_writeFloat() {
- // Test for method void java.io.ObjectOutputStream.writeFloat(float)
- try {
- oos.writeFloat(Float.MAX_VALUE);
- oos.close();
- ois = new ObjectInputStream(loadStream());
- assertTrue("Wrote incorrect double value",
- ois.readFloat() == Float.MAX_VALUE);
- ois.close();
- ois = null;
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_16_writeInt() {
- // Test for method void java.io.ObjectOutputStream.writeInt(int)
- try {
- oos.writeInt(Integer.MAX_VALUE);
- oos.close();
- ois = new ObjectInputStream(loadStream());
- assertTrue("Wrote incorrect double value",
- ois.readInt() == Integer.MAX_VALUE);
- ois.close();
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_17_writeLong() {
- // Test for method void java.io.ObjectOutputStream.writeLong(long)
- try {
- oos.writeLong(Long.MAX_VALUE);
- oos.close();
- ois = new ObjectInputStream(loadStream());
- assertTrue("Wrote incorrect double value",
- ois.readLong() == Long.MAX_VALUE);
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_19_writeShort() {
- // Test for method void java.io.ObjectOutputStream.writeShort(int)
- try {
- oos.writeShort(127);
- oos.close();
- ois = new ObjectInputStream(loadStream());
- assertEquals("Wrote incorrect short value", 127, ois.readShort());
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_20_writeUTF() {
- // Test for method void
- // java.io.ObjectOutputStream.writeUTF(java.lang.String)
- try {
- oos.writeUTF("HelloWorld");
- oos.close();
- ois = new ObjectInputStream(loadStream());
- assertEquals("Wrote incorrect UTF value",
- "HelloWorld", ois.readUTF());
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_25_available() {
- try {
- oos.writeObject(FOO);
- oos.writeObject(FOO);
- oos.flush();
- int available1 = 0;
- int available2 = 0;
- Object obj1 = null;
- Object obj2 = null;
- ObjectInputStream ois = new ObjectInputStream(loadStream());
- available1 = ois.available();
- obj1 = ois.readObject();
- available2 = ois.available();
- obj2 = ois.readObject();
-
- assertEquals("available returned incorrect value", 0, available1);
- assertEquals("available returned incorrect value", 0, available2);
-
- assertTrue("available caused incorrect reading", FOO.equals(obj1));
- assertTrue("available returned incorrect value", FOO.equals(obj2));
-
- } catch (IOException e) {
- fail("IOException serializing object : " + e.getMessage());
- } catch (ClassNotFoundException e) {
- fail("Unable to read Object type : " + e.toString());
- } catch (Error err) {
- System.out.println("Error " + err);
- throw err;
- }
- }
-
- protected void t_MixPrimitivesAndObjects() throws IOException,
- ClassNotFoundException {
- int i = 7;
- String s1 = "string 1";
- String s2 = "string 2";
- byte[] bytes = { 1, 2, 3 };
-
- oos.writeInt(i);
- oos.writeObject(s1);
- oos.writeUTF(s2);
- oos.writeObject(bytes);
- oos.close();
- try {
- ois = new ObjectInputStream(loadStream());
-
- int j = ois.readInt();
- assertTrue("Wrong int :" + j, i == j);
-
- String l1 = (String) ois.readObject();
- assertTrue("Wrong obj String :" + l1, s1.equals(l1));
-
- String l2 = (String) ois.readUTF();
- assertTrue("Wrong UTF String :" + l2, s2.equals(l2));
-
- byte[] bytes2 = (byte[]) ois.readObject();
- assertTrue("Wrong byte[]", Arrays.equals(bytes, bytes2));
-
- } finally {
- ois.close();
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_resolveClass() {
- try {
- oos.writeObject(new Object[] { Integer.class, new Integer(1) });
- oos.close();
-
- ois = new ObjectInputStreamSubclass(loadStream());
- ois.readObject();
- ois.close();
- } catch (IOException e1) {
- fail("IOException : " + e1.getMessage());
- } catch (ClassNotFoundException e2) {
- fail("ClassNotFoundException : " + e2.getMessage());
- }
-
- Class[] resolvedClasses = ((ObjectInputStreamSubclass) ois)
- .resolvedClasses();
- assertEquals("missing resolved", 3, resolvedClasses.length);
- assertTrue("resolved class 1", resolvedClasses[0] == Object[].class);
- assertTrue("resolved class 2", resolvedClasses[1] == Integer.class);
- assertTrue("resolved class 3", resolvedClasses[2] == Number.class);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_reset() {
- try {
- oos.reset();
- oos.writeObject("R");
- oos.reset();
- oos.writeByte(24);
- oos.close();
-
- DataInputStream dis = new DataInputStream(loadStream());
- byte[] input = new byte[dis.available()];
- dis.readFully(input);
- byte[] result = new byte[] { (byte) 0xac, (byte) 0xed, (byte) 0,
- (byte) 5, (byte) 0x79, (byte) 0x74, (byte) 0, (byte) 1,
- (byte) 'R', (byte) 0x79, (byte) 0x77, (byte) 1, (byte) 24 };
- assertTrue("incorrect output", Arrays.equals(input, result));
-
- ois = new ObjectInputStreamSubclass(loadStream());
- assertEquals("Wrong result from readObject()", "R", ois.readObject()
- );
- assertEquals("Wrong result from readByte()", 24, ois.readByte());
- ois.close();
- } catch (IOException e1) {
- fail("IOException : " + e1.getMessage());
- } catch (ClassNotFoundException e2) {
- fail("ClassNotFoundException : " + e2.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_serialVersionUID(Class clazz, long svUID) {
- final String idWrong = "serialVersionUID is wrong for: ";
- long reflectedSvUID = 0L;
- try {
- reflectedSvUID = clazz.getField("serialVersionUID").getLong(null);
- } catch (Exception e) {
- fail("Unable to determine serialVersionUID of " + clazz);
- }
- assertTrue(idWrong + clazz + ": " + reflectedSvUID + " does not equal "
- + svUID, reflectedSvUID == svUID);
- }
-
- private static class ResolveObjectTest implements Serializable {
- Object field1, field2;
- }
-
- private static class ResolveObjectInputStream extends ObjectInputStream {
- ResolveObjectInputStream(InputStream in)
- throws StreamCorruptedException, IOException {
- super(in);
- }
-
- public void enableResolve() {
- enableResolveObject(true);
- }
-
- public Object resolveObject(Object obj) {
- if (obj instanceof Vector) // test_1_resolveObject()
- return new Hashtable();
- else if ("abc".equals(obj)) // test_2_resolveObject()
- return "ABC";
- else if (obj instanceof String) // test_3_resolveObject()
- return String.valueOf(((String) obj).length());
- else if (obj instanceof int[]) // test_4_resolveObject()
- return new Object[1];
- else if (obj instanceof Object[] && ((Object[]) obj).length == 2) // test_5_resolveObject()
- return new char[1];
- return obj;
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_1_resolveObject() {
- try {
- ResolveObjectTest obj = new ResolveObjectTest();
- obj.field1 = new Vector();
- obj.field2 = obj.field1;
- oos.writeObject(obj);
- oos.close();
- ois = new ResolveObjectInputStream(loadStream());
- ((ResolveObjectInputStream) ois).enableResolve();
- ResolveObjectTest result = null;
- try {
- result = (ResolveObjectTest) ois.readObject();
- } catch (ClassNotFoundException e) {
- fail(e.toString());
- }
- assertTrue("Object not resolved",
- result.field1 instanceof Hashtable);
- assertTrue("Second reference not resolved",
- result.field1 == result.field2);
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_2_resolveObject() {
- try {
- ResolveObjectTest obj = new ResolveObjectTest();
- obj.field1 = "abc";
- obj.field2 = obj.field1;
- oos.writeObject(obj);
- oos.close();
- ois = new ResolveObjectInputStream(loadStream());
- ((ResolveObjectInputStream) ois).enableResolve();
- ResolveObjectTest result = null;
- try {
- result = (ResolveObjectTest) ois.readObject();
- } catch (ClassNotFoundException e) {
- fail(e.toString());
- }
- assertEquals("String not resolved", "ABC", result.field1);
- assertTrue("Second reference not resolved",
- result.field1 == result.field2);
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_3_resolveObject() {
- try {
- ResolveObjectTest obj = new ResolveObjectTest();
- char[] lchars = new char[70000];
- obj.field1 = new String(lchars);
- obj.field2 = obj.field1;
- oos.writeObject(obj);
- oos.close();
- ois = new ResolveObjectInputStream(loadStream());
- ((ResolveObjectInputStream) ois).enableResolve();
- ResolveObjectTest result = null;
- try {
- result = (ResolveObjectTest) ois.readObject();
- } catch (ClassNotFoundException e) {
- fail(e.toString());
- }
- assertTrue("Long String not resolved", "70000"
- .equals(result.field1));
- assertTrue("Second reference not resolved",
- result.field1 == result.field2);
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_4_resolveObject() {
- try {
- ResolveObjectTest obj = new ResolveObjectTest();
- obj.field1 = new int[5];
- obj.field2 = obj.field1;
- oos.writeObject(obj);
- oos.close();
- ois = new ResolveObjectInputStream(loadStream());
- ((ResolveObjectInputStream) ois).enableResolve();
- ResolveObjectTest result = null;
- try {
- result = (ResolveObjectTest) ois.readObject();
- } catch (ClassNotFoundException e) {
- fail(e.toString());
- }
- Class cl = new Object[0].getClass();
- assertTrue("int[] not resolved", result.field1.getClass() == cl);
- assertTrue("Second reference not resolved",
- result.field1 == result.field2);
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_5_resolveObject() {
- try {
- ResolveObjectTest obj = new ResolveObjectTest();
- obj.field1 = new Object[2];
- obj.field2 = obj.field1;
- oos.writeObject(obj);
- oos.close();
- ois = new ResolveObjectInputStream(loadStream());
- ((ResolveObjectInputStream) ois).enableResolve();
- ResolveObjectTest result = null;
- try {
- result = (ResolveObjectTest) ois.readObject();
- } catch (ClassNotFoundException e) {
- fail(e.toString());
- }
- Class cl = new char[0].getClass();
- assertTrue("int[] not resolved", result.field1.getClass() == cl);
- assertTrue("Second reference not resolved",
- result.field1 == result.field2);
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- }
- }
-
- static class WriteReplaceTestA implements Serializable {
- public Object writeReplace() throws ObjectStreamException {
- return new ReadResolveTestB();
- }
- }
-
- static class WriteReplaceTestB extends WriteReplaceTestA {
- }
-
- static class WriteReplaceTestC extends WriteReplaceTestA {
- public Object writeReplace() throws ObjectStreamException {
- return new ReadResolveTestC();
- }
- }
-
- static class WriteReplaceTestD implements Serializable {
- private Object writeReplace() throws ObjectStreamException {
- return new ReadResolveTestD();
- }
- }
-
- static class WriteReplaceTestE extends WriteReplaceTestD {
- }
-
- static class WriteReplaceTestF implements Serializable {
- int type, readType;
-
- public WriteReplaceTestF(int type, int readType) {
- this.type = type;
- this.readType = readType;
- }
-
- public Object writeReplace() throws ObjectStreamException {
- switch (type) {
- case 0:
- throw new InvalidObjectException("invalid");
- case 1:
- throw new RuntimeException("runtime");
- case 2:
- throw new Error("error");
- default:
- return new ReadResolveTestE(readType);
- }
- }
- }
-
- static class ReadResolveTestA implements Serializable {
- public Object readResolve() throws ObjectStreamException {
- return new ReadResolveTestA();
- }
- }
-
- static class ReadResolveTestB extends ReadResolveTestA {
- }
-
- static class ReadResolveTestC implements Serializable {
- private Object readResolve() throws ObjectStreamException {
- return new ReadResolveTestB();
- }
- }
-
- static class ReadResolveTestD extends ReadResolveTestC {
- }
-
- static class ReadResolveTestE implements Serializable {
- int type;
-
- public ReadResolveTestE(int type) {
- this.type = type;
- }
-
- public Object readResolve() throws ObjectStreamException {
- switch (type) {
- case 0:
- throw new InvalidObjectException("invalid");
- case 1:
- throw new RuntimeException("runtime");
- case 2:
- throw new Error("error");
- case 3:
- return this;
- default:
- return new ReadResolveTestF();
- }
- }
- }
-
- static class ReadResolveTestF implements Serializable {
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_1_writeReplace() {
- try {
- Vector v = new Vector();
- v.addElement(new WriteReplaceTestA());
- v.addElement(new WriteReplaceTestB());
- v.addElement(new WriteReplaceTestB());
- v.addElement(new WriteReplaceTestC());
- v.addElement(new WriteReplaceTestD());
- v.addElement(new WriteReplaceTestE());
- oos.writeObject(v);
- oos.close();
- ois = new ObjectInputStream(loadStream());
- Vector result = (Vector) ois.readObject();
- assertTrue("invalid 0 : " + result.elementAt(0), result
- .elementAt(0).getClass() == ReadResolveTestA.class);
- assertTrue("invalid 1 : " + result.elementAt(1), result
- .elementAt(1).getClass() == ReadResolveTestA.class);
- assertTrue("invalid 2 : " + result.elementAt(2), result
- .elementAt(2).getClass() == ReadResolveTestA.class);
- assertTrue("invalid 3 : " + result.elementAt(3), result
- .elementAt(3).getClass() == ReadResolveTestB.class);
- assertTrue("invalid 4 : " + result.elementAt(4), result
- .elementAt(4).getClass() == ReadResolveTestD.class);
- assertTrue("invalid 5 : " + result.elementAt(5), result
- .elementAt(5).getClass() == WriteReplaceTestE.class);
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- } catch (ClassNotFoundException e) {
- fail("ClassNotFoundException serializing data : " + e.getMessage());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!Serialization",
- args = {}
- )
- public void test_2_writeReplace() {
- try {
- boolean exception = false;
- try {
- oos.writeObject(new WriteReplaceTestF(0, -1));
- } catch (ObjectStreamException e) {
- exception = true;
- }
- assertTrue("Should throw ObjectStreamException", exception);
- exception = false;
- try {
- oos.writeObject(new WriteReplaceTestF(1, -1));
- } catch (RuntimeException e) {
- exception = true;
- }
- assertTrue("Should throw RuntimeException", exception);
- exception = false;
- try {
- oos.writeObject(new WriteReplaceTestF(2, -1));
- } catch (Error e) {
- exception = true;
- }
- assertTrue("Should throw Error", exception);
-
- oos.writeObject(new WriteReplaceTestF(3, 0));
- oos.writeObject(new WriteReplaceTestF(3, 1));
- oos.writeObject(new WriteReplaceTestF(3, 2));
- WriteReplaceTestF test = new WriteReplaceTestF(3, 3);
- oos.writeObject(test);
- oos.writeObject(test);
- WriteReplaceTestF test2 = new WriteReplaceTestF(3, 4);
- oos.writeObject(test2);
- oos.writeObject(test2);
- oos.close();
- ois = new ObjectInputStream(loadStream());
- try {
- ois.readObject();
- } catch (WriteAbortedException e) {
- }
-
- exception = false;
- try {
- ois.readObject();
- } catch (ObjectStreamException e) {
- exception = true;
- }
- assertTrue("Expected ObjectStreamException", exception);
- exception = false;
- try {
- ois.readObject();
- } catch (RuntimeException e) {
- exception = true;
- }
- assertTrue("Expected RuntimeException", exception);
- exception = false;
- try {
- ois.readObject();
- } catch (Error e) {
- exception = true;
- }
- assertTrue("Expected Error", exception);
-
- Object readE1 = ois.readObject();
- Object readE2 = ois.readObject();
- assertTrue("Replaced objects should be identical", readE1 == readE2);
- Object readF1 = ois.readObject();
- Object readF2 = ois.readObject();
- assertTrue("Replaced resolved objects should be identical: "
- + readF1 + " " + readF2, readF1 == readF2);
- } catch (IOException e) {
- fail("IOException serializing data : " + e.getMessage());
- } catch (ClassNotFoundException e) {
- fail("ClassNotFoundException serializing data : " + e.getMessage());
- }
- }
}
diff --git a/luni/src/test/java/tests/api/java/io/SerializationStressTest0.java b/luni/src/test/java/tests/api/java/io/SerializationStressTest0.java
new file mode 100644
index 0000000..b9d7eb6
--- /dev/null
+++ b/luni/src/test/java/tests/api/java/io/SerializationStressTest0.java
@@ -0,0 +1,1000 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.io;
+
+import dalvik.annotation.BrokenTest;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InvalidObjectException;
+import java.io.NotActiveException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.io.StreamCorruptedException;
+import java.io.WriteAbortedException;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/**
+ * Automated Test Suite for class java.io.ObjectOutputStream
+ *
+ */
+@TestTargetClass(Serializable.class)
+public class SerializationStressTest0 extends SerializationStressTest {
+
+ private static class ObjectInputStreamSubclass extends ObjectInputStream {
+ private Vector resolvedClasses = new Vector();
+
+ public ObjectInputStreamSubclass(InputStream in) throws IOException,
+ StreamCorruptedException {
+ super(in);
+ }
+
+ public Class resolveClass(ObjectStreamClass osClass)
+ throws IOException, ClassNotFoundException {
+ Class result = super.resolveClass(osClass);
+ resolvedClasses.addElement(result);
+ return result;
+ }
+
+ public Class[] resolvedClasses() {
+ return (Class[]) resolvedClasses.toArray(new Class[resolvedClasses
+ .size()]);
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_1_Constructor() {
+ // Test for method java.io.ObjectOutputStream(java.io.OutputStream)
+
+ try {
+ oos.close();
+ oos = new ObjectOutputStream(new ByteArrayOutputStream());
+ oos.close();
+ } catch (Exception e) {
+ fail("Failed to create ObjectOutputStream : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_2_close() {
+ // Test for method void java.io.ObjectOutputStream.close()
+ try {
+ oos.close();
+ oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
+ oos.close();
+ oos.writeChar('T');
+ oos.writeObject(FOO);
+ // Writing to a closed stream does not cause problems. This is
+ // the expected behavior
+ } catch (IOException e) {
+ fail("Operation on closed stream threw IOException : "
+ + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_3_defaultWriteObject() {
+ // Test for method void java.io.ObjectOutputStream.defaultWriteObject()
+
+ try {
+ oos.defaultWriteObject();
+ } catch (NotActiveException e) {
+ // Correct
+ return;
+ } catch (IOException e) {
+ }
+ fail(
+ "Failed to throw NotActiveException when invoked outside readObject");
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_4_flush() {
+ // Test for method void java.io.ObjectOutputStream.flush()
+ try {
+ oos.close();
+ oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
+ int size = bao.size();
+ oos.writeByte(127);
+ assertTrue("Data flushed already", bao.size() == size);
+ oos.flush();
+ assertTrue("Failed to flush data", bao.size() > size);
+ // we don't know how many bytes are actually written for 1 byte,
+ // so we test > <before>
+ oos.close();
+ oos = null;
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_5_reset() {
+ // Test for method void java.io.ObjectOutputStream.reset()
+ try {
+ String o = "HelloWorld";
+ oos.writeObject(o);
+ oos.writeObject(o);
+ oos.reset();
+ oos.writeObject(o);
+ ois = new ObjectInputStream(loadStream());
+ ois.close();
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_6_write() {
+ // Test for method void java.io.ObjectOutputStream.write(byte [], int,
+ // int)
+ try {
+ byte[] buf = new byte[255];
+ byte[] output = new byte[255];
+ for (int i = 0; i < output.length; i++)
+ output[i] = (byte) i;
+ oos.write(output, 0, output.length);
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ ois.readFully(buf);
+ ois.close();
+ for (int i = 0; i < output.length; i++)
+ if (buf[i] != output[i])
+ fail("Read incorrect byte: " + i);
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_6a_write() {
+ // Test for method void java.io.ObjectOutputStream.write(byte [], int,
+ // int)
+ try {
+ byte[] buf = new byte[256];
+ byte[] output = new byte[256];
+ for (int i = 0; i < output.length; i++)
+ output[i] = (byte) (i & 0xff);
+ oos.write(output, 0, output.length);
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ ois.readFully(buf);
+ ois.close();
+ for (int i = 0; i < output.length; i++)
+ if (buf[i] != output[i])
+ fail("Read incorrect byte: " + i);
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_7_write() {
+ // Test for method void java.io.ObjectOutputStream.write(int)
+ try {
+ byte[] buf = new byte[10];
+ oos.write('T');
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ assertEquals("Read incorrect byte", 'T', ois.read());
+ ois.close();
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_8_write() {
+ // Test for method void java.io.ObjectOutputStream.write(byte [])
+ try {
+ byte[] buf = new byte[10];
+ oos.write("HelloWorld".getBytes());
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ ois.read(buf, 0, 10);
+ ois.close();
+ assertEquals("Read incorrect bytes", "HelloWorld", new String(buf, 0, 10)
+ );
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_9_writeBoolean() {
+ // Test for method void java.io.ObjectOutputStream.writeBoolean(boolean)
+ try {
+ oos.writeBoolean(true);
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ assertTrue("Wrote incorrect byte value", ois.readBoolean());
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_10_writeByte() {
+ // Test for method void java.io.ObjectOutputStream.writeByte(int)
+ try {
+ oos.writeByte(127);
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ assertEquals("Wrote incorrect byte value", 127, ois.readByte());
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_11_writeBytes() {
+ // Test for method void
+ // java.io.ObjectOutputStream.writeBytes(java.lang.String)
+ try {
+ byte[] buf = new byte[10];
+ oos.writeBytes("HelloWorld");
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ ois.readFully(buf);
+ ois.close();
+ assertEquals("Wrote incorrect bytes value", "HelloWorld", new String(buf, 0, 10)
+ );
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_12_writeChar() {
+ // Test for method void java.io.ObjectOutputStream.writeChar(int)
+ try {
+ oos.writeChar('T');
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ assertEquals("Wrote incorrect char value", 'T', ois.readChar());
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_13_writeChars() {
+ // Test for method void
+ // java.io.ObjectOutputStream.writeChars(java.lang.String)
+ try {
+ int avail = 0;
+ char[] buf = new char[10];
+ oos.writeChars("HelloWorld");
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ // Number of prim data bytes in stream / 2 to give char index
+ avail = ois.available() / 2;
+ for (int i = 0; i < avail; ++i)
+ buf[i] = ois.readChar();
+ ois.close();
+ assertEquals("Wrote incorrect chars", "HelloWorld", new String(buf, 0, 10)
+ );
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_14_writeDouble() {
+ // Test for method void java.io.ObjectOutputStream.writeDouble(double)
+ try {
+ oos.writeDouble(Double.MAX_VALUE);
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ assertTrue("Wrote incorrect double value",
+ ois.readDouble() == Double.MAX_VALUE);
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_15_writeFloat() {
+ // Test for method void java.io.ObjectOutputStream.writeFloat(float)
+ try {
+ oos.writeFloat(Float.MAX_VALUE);
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ assertTrue("Wrote incorrect double value",
+ ois.readFloat() == Float.MAX_VALUE);
+ ois.close();
+ ois = null;
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_16_writeInt() {
+ // Test for method void java.io.ObjectOutputStream.writeInt(int)
+ try {
+ oos.writeInt(Integer.MAX_VALUE);
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ assertTrue("Wrote incorrect double value",
+ ois.readInt() == Integer.MAX_VALUE);
+ ois.close();
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_17_writeLong() {
+ // Test for method void java.io.ObjectOutputStream.writeLong(long)
+ try {
+ oos.writeLong(Long.MAX_VALUE);
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ assertTrue("Wrote incorrect double value",
+ ois.readLong() == Long.MAX_VALUE);
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_19_writeShort() {
+ // Test for method void java.io.ObjectOutputStream.writeShort(int)
+ try {
+ oos.writeShort(127);
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ assertEquals("Wrote incorrect short value", 127, ois.readShort());
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_20_writeUTF() {
+ // Test for method void
+ // java.io.ObjectOutputStream.writeUTF(java.lang.String)
+ try {
+ oos.writeUTF("HelloWorld");
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ assertEquals("Wrote incorrect UTF value",
+ "HelloWorld", ois.readUTF());
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_25_available() {
+ try {
+ oos.writeObject(FOO);
+ oos.writeObject(FOO);
+ oos.flush();
+ int available1 = 0;
+ int available2 = 0;
+ Object obj1 = null;
+ Object obj2 = null;
+ ObjectInputStream ois = new ObjectInputStream(loadStream());
+ available1 = ois.available();
+ obj1 = ois.readObject();
+ available2 = ois.available();
+ obj2 = ois.readObject();
+
+ assertEquals("available returned incorrect value", 0, available1);
+ assertEquals("available returned incorrect value", 0, available2);
+
+ assertTrue("available caused incorrect reading", FOO.equals(obj1));
+ assertTrue("available returned incorrect value", FOO.equals(obj2));
+
+ } catch (IOException e) {
+ fail("IOException serializing object : " + e.getMessage());
+ } catch (ClassNotFoundException e) {
+ fail("Unable to read Object type : " + e.toString());
+ } catch (Error err) {
+ System.out.println("Error " + err);
+ throw err;
+ }
+
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_resolveClass() {
+ try {
+ oos.writeObject(new Object[] { Integer.class, new Integer(1) });
+ oos.close();
+
+ ois = new ObjectInputStreamSubclass(loadStream());
+ ois.readObject();
+ ois.close();
+ } catch (IOException e1) {
+ fail("IOException : " + e1.getMessage());
+ } catch (ClassNotFoundException e2) {
+ fail("ClassNotFoundException : " + e2.getMessage());
+ }
+
+ Class[] resolvedClasses = ((ObjectInputStreamSubclass) ois)
+ .resolvedClasses();
+ assertEquals("missing resolved", 3, resolvedClasses.length);
+ assertTrue("resolved class 1", resolvedClasses[0] == Object[].class);
+ assertTrue("resolved class 2", resolvedClasses[1] == Integer.class);
+ assertTrue("resolved class 3", resolvedClasses[2] == Number.class);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_reset() {
+ try {
+ oos.reset();
+ oos.writeObject("R");
+ oos.reset();
+ oos.writeByte(24);
+ oos.close();
+
+ DataInputStream dis = new DataInputStream(loadStream());
+ byte[] input = new byte[dis.available()];
+ dis.readFully(input);
+ byte[] result = new byte[] { (byte) 0xac, (byte) 0xed, (byte) 0,
+ (byte) 5, (byte) 0x79, (byte) 0x74, (byte) 0, (byte) 1,
+ (byte) 'R', (byte) 0x79, (byte) 0x77, (byte) 1, (byte) 24 };
+ assertTrue("incorrect output", Arrays.equals(input, result));
+
+ ois = new ObjectInputStreamSubclass(loadStream());
+ assertEquals("Wrong result from readObject()", "R", ois.readObject()
+ );
+ assertEquals("Wrong result from readByte()", 24, ois.readByte());
+ ois.close();
+ } catch (IOException e1) {
+ fail("IOException : " + e1.getMessage());
+ } catch (ClassNotFoundException e2) {
+ fail("ClassNotFoundException : " + e2.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_serialVersionUID(Class clazz, long svUID) {
+ final String idWrong = "serialVersionUID is wrong for: ";
+ long reflectedSvUID = 0L;
+ try {
+ reflectedSvUID = clazz.getField("serialVersionUID").getLong(null);
+ } catch (Exception e) {
+ fail("Unable to determine serialVersionUID of " + clazz);
+ }
+ assertTrue(idWrong + clazz + ": " + reflectedSvUID + " does not equal "
+ + svUID, reflectedSvUID == svUID);
+ }
+
+ private static class ResolveObjectTest implements Serializable {
+ Object field1, field2;
+ }
+
+ private static class ResolveObjectInputStream extends ObjectInputStream {
+ ResolveObjectInputStream(InputStream in)
+ throws StreamCorruptedException, IOException {
+ super(in);
+ }
+
+ public void enableResolve() {
+ enableResolveObject(true);
+ }
+
+ public Object resolveObject(Object obj) {
+ if (obj instanceof Vector) // test_1_resolveObject()
+ return new Hashtable();
+ else if ("abc".equals(obj)) // test_2_resolveObject()
+ return "ABC";
+ else if (obj instanceof String) // test_3_resolveObject()
+ return String.valueOf(((String) obj).length());
+ else if (obj instanceof int[]) // test_4_resolveObject()
+ return new Object[1];
+ else if (obj instanceof Object[] && ((Object[]) obj).length == 2) // test_5_resolveObject()
+ return new char[1];
+ return obj;
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_1_resolveObject() {
+ try {
+ ResolveObjectTest obj = new ResolveObjectTest();
+ obj.field1 = new Vector();
+ obj.field2 = obj.field1;
+ oos.writeObject(obj);
+ oos.close();
+ ois = new ResolveObjectInputStream(loadStream());
+ ((ResolveObjectInputStream) ois).enableResolve();
+ ResolveObjectTest result = null;
+ try {
+ result = (ResolveObjectTest) ois.readObject();
+ } catch (ClassNotFoundException e) {
+ fail(e.toString());
+ }
+ assertTrue("Object not resolved",
+ result.field1 instanceof Hashtable);
+ assertTrue("Second reference not resolved",
+ result.field1 == result.field2);
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_2_resolveObject() {
+ try {
+ ResolveObjectTest obj = new ResolveObjectTest();
+ obj.field1 = "abc";
+ obj.field2 = obj.field1;
+ oos.writeObject(obj);
+ oos.close();
+ ois = new ResolveObjectInputStream(loadStream());
+ ((ResolveObjectInputStream) ois).enableResolve();
+ ResolveObjectTest result = null;
+ try {
+ result = (ResolveObjectTest) ois.readObject();
+ } catch (ClassNotFoundException e) {
+ fail(e.toString());
+ }
+ assertEquals("String not resolved", "ABC", result.field1);
+ assertTrue("Second reference not resolved",
+ result.field1 == result.field2);
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_3_resolveObject() {
+ try {
+ ResolveObjectTest obj = new ResolveObjectTest();
+ char[] lchars = new char[70000];
+ obj.field1 = new String(lchars);
+ obj.field2 = obj.field1;
+ oos.writeObject(obj);
+ oos.close();
+ ois = new ResolveObjectInputStream(loadStream());
+ ((ResolveObjectInputStream) ois).enableResolve();
+ ResolveObjectTest result = null;
+ try {
+ result = (ResolveObjectTest) ois.readObject();
+ } catch (ClassNotFoundException e) {
+ fail(e.toString());
+ }
+ assertTrue("Long String not resolved", "70000"
+ .equals(result.field1));
+ assertTrue("Second reference not resolved",
+ result.field1 == result.field2);
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_4_resolveObject() {
+ try {
+ ResolveObjectTest obj = new ResolveObjectTest();
+ obj.field1 = new int[5];
+ obj.field2 = obj.field1;
+ oos.writeObject(obj);
+ oos.close();
+ ois = new ResolveObjectInputStream(loadStream());
+ ((ResolveObjectInputStream) ois).enableResolve();
+ ResolveObjectTest result = null;
+ try {
+ result = (ResolveObjectTest) ois.readObject();
+ } catch (ClassNotFoundException e) {
+ fail(e.toString());
+ }
+ Class cl = new Object[0].getClass();
+ assertTrue("int[] not resolved", result.field1.getClass() == cl);
+ assertTrue("Second reference not resolved",
+ result.field1 == result.field2);
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_5_resolveObject() {
+ try {
+ ResolveObjectTest obj = new ResolveObjectTest();
+ obj.field1 = new Object[2];
+ obj.field2 = obj.field1;
+ oos.writeObject(obj);
+ oos.close();
+ ois = new ResolveObjectInputStream(loadStream());
+ ((ResolveObjectInputStream) ois).enableResolve();
+ ResolveObjectTest result = null;
+ try {
+ result = (ResolveObjectTest) ois.readObject();
+ } catch (ClassNotFoundException e) {
+ fail(e.toString());
+ }
+ Class cl = new char[0].getClass();
+ assertTrue("int[] not resolved", result.field1.getClass() == cl);
+ assertTrue("Second reference not resolved",
+ result.field1 == result.field2);
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ }
+ }
+
+ static class WriteReplaceTestA implements Serializable {
+ public Object writeReplace() throws ObjectStreamException {
+ return new ReadResolveTestB();
+ }
+ }
+
+ static class WriteReplaceTestB extends WriteReplaceTestA {
+ }
+
+ static class WriteReplaceTestC extends WriteReplaceTestA {
+ public Object writeReplace() throws ObjectStreamException {
+ return new ReadResolveTestC();
+ }
+ }
+
+ static class WriteReplaceTestD implements Serializable {
+ private Object writeReplace() throws ObjectStreamException {
+ return new ReadResolveTestD();
+ }
+ }
+
+ static class WriteReplaceTestE extends WriteReplaceTestD {
+ }
+
+ static class WriteReplaceTestF implements Serializable {
+ int type, readType;
+
+ public WriteReplaceTestF(int type, int readType) {
+ this.type = type;
+ this.readType = readType;
+ }
+
+ public Object writeReplace() throws ObjectStreamException {
+ switch (type) {
+ case 0:
+ throw new InvalidObjectException("invalid");
+ case 1:
+ throw new RuntimeException("runtime");
+ case 2:
+ throw new Error("error");
+ default:
+ return new ReadResolveTestE(readType);
+ }
+ }
+ }
+
+ static class ReadResolveTestA implements Serializable {
+ public Object readResolve() throws ObjectStreamException {
+ return new ReadResolveTestA();
+ }
+ }
+
+ static class ReadResolveTestB extends ReadResolveTestA {
+ }
+
+ static class ReadResolveTestC implements Serializable {
+ private Object readResolve() throws ObjectStreamException {
+ return new ReadResolveTestB();
+ }
+ }
+
+ static class ReadResolveTestD extends ReadResolveTestC {
+ }
+
+ static class ReadResolveTestE implements Serializable {
+ int type;
+
+ public ReadResolveTestE(int type) {
+ this.type = type;
+ }
+
+ public Object readResolve() throws ObjectStreamException {
+ switch (type) {
+ case 0:
+ throw new InvalidObjectException("invalid");
+ case 1:
+ throw new RuntimeException("runtime");
+ case 2:
+ throw new Error("error");
+ case 3:
+ return this;
+ default:
+ return new ReadResolveTestF();
+ }
+ }
+ }
+
+ static class ReadResolveTestF implements Serializable {
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ public void test_1_writeReplace() {
+ try {
+ Vector v = new Vector();
+ v.addElement(new WriteReplaceTestA());
+ v.addElement(new WriteReplaceTestB());
+ v.addElement(new WriteReplaceTestB());
+ v.addElement(new WriteReplaceTestC());
+ v.addElement(new WriteReplaceTestD());
+ v.addElement(new WriteReplaceTestE());
+ oos.writeObject(v);
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ Vector result = (Vector) ois.readObject();
+ assertTrue("invalid 0 : " + result.elementAt(0), result
+ .elementAt(0).getClass() == ReadResolveTestA.class);
+ assertTrue("invalid 1 : " + result.elementAt(1), result
+ .elementAt(1).getClass() == ReadResolveTestA.class);
+ assertTrue("invalid 2 : " + result.elementAt(2), result
+ .elementAt(2).getClass() == ReadResolveTestA.class);
+ assertTrue("invalid 3 : " + result.elementAt(3), result
+ .elementAt(3).getClass() == ReadResolveTestB.class);
+ assertTrue("invalid 4 : " + result.elementAt(4), result
+ .elementAt(4).getClass() == ReadResolveTestD.class);
+ assertTrue("invalid 5 : " + result.elementAt(5), result
+ .elementAt(5).getClass() == WriteReplaceTestE.class);
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ } catch (ClassNotFoundException e) {
+ fail("ClassNotFoundException serializing data : " + e.getMessage());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization.",
+ method = "!Serialization",
+ args = {}
+ )
+ @BrokenTest("Needs investigation. succeeds on android, fails on RI")
+ public void test_2_writeReplace() {
+ try {
+ boolean exception = false;
+ try {
+ oos.writeObject(new WriteReplaceTestF(0, -1));
+ } catch (ObjectStreamException e) {
+ exception = true;
+ }
+ assertTrue("Should throw ObjectStreamException", exception);
+ exception = false;
+ try {
+ oos.writeObject(new WriteReplaceTestF(1, -1));
+ } catch (RuntimeException e) {
+ exception = true;
+ }
+ assertTrue("Should throw RuntimeException", exception);
+ exception = false;
+ try {
+ oos.writeObject(new WriteReplaceTestF(2, -1));
+ } catch (Error e) {
+ exception = true;
+ }
+ assertTrue("Should throw Error", exception);
+
+ oos.writeObject(new WriteReplaceTestF(3, 0));
+ oos.writeObject(new WriteReplaceTestF(3, 1));
+ oos.writeObject(new WriteReplaceTestF(3, 2));
+ WriteReplaceTestF test = new WriteReplaceTestF(3, 3);
+ oos.writeObject(test);
+ oos.writeObject(test);
+ WriteReplaceTestF test2 = new WriteReplaceTestF(3, 4);
+ oos.writeObject(test2);
+ oos.writeObject(test2);
+ oos.close();
+ ois = new ObjectInputStream(loadStream());
+ try {
+ ois.readObject();
+ } catch (WriteAbortedException e) {
+ }
+
+ exception = false;
+ try {
+ ois.readObject();
+ } catch (ObjectStreamException e) {
+ exception = true;
+ }
+ assertTrue("Expected ObjectStreamException", exception);
+ exception = false;
+ try {
+ ois.readObject();
+ } catch (RuntimeException e) {
+ exception = true;
+ }
+ assertTrue("Expected RuntimeException", exception);
+ exception = false;
+ try {
+ ois.readObject();
+ } catch (Error e) {
+ exception = true;
+ }
+ assertTrue("Expected Error", exception);
+
+ Object readE1 = ois.readObject();
+ Object readE2 = ois.readObject();
+ assertTrue("Replaced objects should be identical", readE1 == readE2);
+ Object readF1 = ois.readObject();
+ Object readF2 = ois.readObject();
+ assertTrue("Replaced resolved objects should be identical: "
+ + readF1 + " " + readF2, readF1 == readF2);
+ } catch (IOException e) {
+ fail("IOException serializing data : " + e.getMessage());
+ } catch (ClassNotFoundException e) {
+ fail("ClassNotFoundException serializing data : " + e.getMessage());
+ }
+ }
+}
diff --git a/luni/src/test/java/tests/api/java/io/SerializationStressTest1.java b/luni/src/test/java/tests/api/java/io/SerializationStressTest1.java
index b4d8677..d097d67 100644
--- a/luni/src/test/java/tests/api/java/io/SerializationStressTest1.java
+++ b/luni/src/test/java/tests/api/java/io/SerializationStressTest1.java
@@ -16,7 +16,7 @@
*/
package tests.api.java.io;
-import dalvik.annotation.TestTargets;
+import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
@@ -812,7 +812,8 @@ public class SerializationStressTest1 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_18_14_writeObject() {
+ @BrokenTest("throws IllegalAccessException on Android and InvalidClassException on RI")
+ public void test_18_14_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
@@ -857,7 +858,8 @@ public class SerializationStressTest1 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_18_15_writeObject() {
+ @BrokenTest("throws IllegalAccessException on Android and InvalidClassException on RI")
+ public void test_18_15_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
@@ -1345,6 +1347,7 @@ public class SerializationStressTest1 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
+ @BrokenTest("Needs investigation. fails on RI, succeeds on Android. Maybe a bug in the RI.")
public void test_18_28_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
@@ -1612,6 +1615,7 @@ public class SerializationStressTest1 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
+ @BrokenTest("succeeds on Android, but fails on RI with MyException being thrown.")
public void test_18_33_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
diff --git a/luni/src/test/java/tests/api/java/io/SerializationStressTest2.java b/luni/src/test/java/tests/api/java/io/SerializationStressTest2.java
index 989469c..899cd8f 100644
--- a/luni/src/test/java/tests/api/java/io/SerializationStressTest2.java
+++ b/luni/src/test/java/tests/api/java/io/SerializationStressTest2.java
@@ -17,7 +17,7 @@
package tests.api.java.io;
-import dalvik.annotation.TestTargets;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
@@ -1419,7 +1419,8 @@ public class SerializationStressTest2 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_18_57_writeObject() {
+ @KnownFailure("Executed replacement when it should not: class java.lang.String")
+ public void test_18_57_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
@@ -1457,7 +1458,8 @@ public class SerializationStressTest2 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_18_58_writeObject() {
+ @KnownFailure("Executed replacement when it should not: class java.lang.String")
+ public void test_18_58_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
@@ -1898,7 +1900,8 @@ public class SerializationStressTest2 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_DeepNestingWithWriteObject() {
+ @KnownFailure("Maybe the stack gets too deep for android. Change the test?")
+ public void test_DeepNestingWithWriteObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
diff --git a/luni/src/test/java/tests/api/java/io/SerializationStressTest3.java b/luni/src/test/java/tests/api/java/io/SerializationStressTest3.java
index f3617a3..3674418 100644
--- a/luni/src/test/java/tests/api/java/io/SerializationStressTest3.java
+++ b/luni/src/test/java/tests/api/java/io/SerializationStressTest3.java
@@ -16,6 +16,8 @@
*/
package tests.api.java.io;
+import dalvik.annotation.BrokenTest;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
@@ -510,7 +512,8 @@ public class SerializationStressTest3 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_18_85_writeObject() {
+ @BrokenTest("Needs investigation.Fails on Android with IlegalAccessException and RI with IOException: no valid constructor")
+ public void test_18_85_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
@@ -1343,7 +1346,7 @@ public class SerializationStressTest3 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_18_109_writeObject() {
+ public void test_18_109_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
@@ -1377,7 +1380,7 @@ public class SerializationStressTest3 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_18_110_writeObject() {
+ public void test_18_110_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
@@ -1412,7 +1415,7 @@ public class SerializationStressTest3 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_18_111_writeObject() {
+ public void test_18_111_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
@@ -1447,7 +1450,7 @@ public class SerializationStressTest3 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_18_112_writeObject() {
+ public void test_18_112_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
@@ -1482,7 +1485,8 @@ public class SerializationStressTest3 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_18_113_writeObject() {
+ @KnownFailure("Serialization of SimpleDateFormat object fails")
+ public void test_18_113_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
@@ -1550,7 +1554,8 @@ public class SerializationStressTest3 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_18_115_writeObject() {
+ @KnownFailure("Serialization of NumberFormat object fails")
+ public void test_18_115_writeObject() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.lang.Object)
diff --git a/luni/src/test/java/tests/api/java/io/SerializationStressTest4.java b/luni/src/test/java/tests/api/java/io/SerializationStressTest4.java
index 1ec1211..6cd919a 100644
--- a/luni/src/test/java/tests/api/java/io/SerializationStressTest4.java
+++ b/luni/src/test/java/tests/api/java/io/SerializationStressTest4.java
@@ -17,7 +17,8 @@
package tests.api.java.io;
-import dalvik.annotation.TestTargets;
+import dalvik.annotation.BrokenTest;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
@@ -717,7 +718,7 @@ public class SerializationStressTest4 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_writeObject_Calendar() {
+ public void test_writeObject_Calendar() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.util.Calendar)
@@ -1198,7 +1199,8 @@ public class SerializationStressTest4 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_writeObject_Collections_UnmodifiableMap_UnmodifiableEntrySet() {
+ @BrokenTest("Needs investigation. Fails on RI and on Android with the same IOException.")
+ public void test_writeObject_Collections_UnmodifiableMap_UnmodifiableEntrySet() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.util.Collections.UnmodifiableMap.UnmodifiableEntrySet)
@@ -2677,7 +2679,7 @@ public class SerializationStressTest4 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
- public void _test_writeObject_Proxy() {
+ public void test_writeObject_Proxy() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.security.GuardedObject)
@@ -2881,6 +2883,7 @@ public class SerializationStressTest4 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
+ @KnownFailure("deserialization of a date fomat field seems to fail")
public void test_writeObject_DateFormat_Field() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.text.DateFormat.Field)
@@ -2925,6 +2928,7 @@ public class SerializationStressTest4 extends SerializationStressTest {
method = "!Serialization",
args = {}
)
+ @KnownFailure("deserialization of a number fomat field seems to fail")
public void test_writeObject_NumberFormat_Field() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.text.NumberFormat.Field)
diff --git a/luni/src/test/java/tests/api/java/lang/ProcessManagerTest.java b/luni/src/test/java/tests/api/java/lang/ProcessManagerTest.java
index 8a6da3b..7129cdc 100644
--- a/luni/src/test/java/tests/api/java/lang/ProcessManagerTest.java
+++ b/luni/src/test/java/tests/api/java/lang/ProcessManagerTest.java
@@ -210,6 +210,13 @@ public class ProcessManagerTest extends TestCase {
InputStream in;
+ @TestTargetNew(
+ level = TestLevel.ADDITIONAL,
+ notes = "Check non standard fd behavior",
+ clazz = Runtime.class,
+ method = "exec",
+ args = {String[].class, String[].class, java.io.File.class}
+ )
public void testCloseNonStandardFds()
throws IOException, InterruptedException {
String[] commands = { "ls", "/proc/self/fd" };
@@ -245,6 +252,13 @@ public class ProcessManagerTest extends TestCase {
return count;
}
+ @TestTargetNew(
+ level = TestLevel.ADDITIONAL,
+ notes = "Check non standard fd behavior",
+ clazz = Runtime.class,
+ method = "exec",
+ args = {String[].class, String[].class, java.io.File.class}
+ )
public void testInvalidCommand()
throws IOException, InterruptedException {
try {
diff --git a/luni/src/test/java/tests/api/java/net/CookieHandlerTest.java b/luni/src/test/java/tests/api/java/net/CookieHandlerTest.java
index 3d43205..256c5ba 100644
--- a/luni/src/test/java/tests/api/java/net/CookieHandlerTest.java
+++ b/luni/src/test/java/tests/api/java/net/CookieHandlerTest.java
@@ -23,7 +23,6 @@ import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import java.io.IOException;
-import java.io.InputStream;
import java.net.CookieHandler;
import java.net.MalformedURLException;
import java.net.NetPermission;
diff --git a/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java b/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java
index 1930f53..b422761 100644
--- a/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java
+++ b/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java
@@ -19,7 +19,6 @@ package tests.api.java.net;
import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
@@ -38,7 +37,6 @@ import java.net.NetworkInterface;
import java.net.PortUnreachableException;
import java.net.SocketAddress;
import java.net.SocketException;
-import java.net.SocketPermission;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.nio.channels.DatagramChannel;
@@ -300,7 +298,6 @@ public class DatagramSocketTest extends SocketTestCase {
method = "connect",
args = {java.net.InetAddress.class, int.class}
)
- @KnownFailure("An unexpected Exception was thrown in the last part of the test")
public void test_connectLjava_net_InetAddressI() {
try {
ds = new java.net.DatagramSocket();
diff --git a/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java b/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java
index 46c7e98..f6957e2 100644
--- a/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java
+++ b/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java
@@ -19,14 +19,12 @@ package tests.api.java.net;
import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import java.io.IOException;
import java.net.BindException;
import java.net.DatagramPacket;
-import java.net.DatagramSocket;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
@@ -273,13 +271,13 @@ public class MulticastSocketTest extends SocketTestCase {
groupPort = Support_PortManager.getNextPortForUDP();
mss = new MulticastSocket(groupPort);
mss.setNetworkInterface(networkInterface1);
- assertTrue(
+ InetAddress addr = mss.getInterface();
+ NetworkInterface if1 = NetworkInterface.getByInetAddress(addr);
+ assertEquals(
"getInterface did not return interface set by " +
- "setNeworkInterface Expected: "
- + firstAddress + "Got:"
- + mss.getInterface(), NetworkInterface
- .getByInetAddress(mss.getInterface())
- .equals(networkInterface1));
+ "setNeworkInterface Expected: " + firstAddress
+ + "Got:" + mss.getInterface(),
+ networkInterface1, if1);
}
mss.close();
try {
diff --git a/luni/src/test/java/tests/api/java/net/ResponseCacheTest.java b/luni/src/test/java/tests/api/java/net/ResponseCacheTest.java
index 449fbba..c64fd82 100644
--- a/luni/src/test/java/tests/api/java/net/ResponseCacheTest.java
+++ b/luni/src/test/java/tests/api/java/net/ResponseCacheTest.java
@@ -22,13 +22,8 @@ import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.CacheRequest;
import java.net.CacheResponse;
@@ -40,7 +35,6 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.security.Permission;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -168,7 +162,8 @@ public class ResponseCacheTest extends TestCase {
method = "get",
args = {java.net.URI.class, java.lang.String.class, java.util.Map.class}
)
- @BrokenTest("cache seems not to be used")
+ @BrokenTest("This test fails on both RI and android. Also only getting " +
+ "from the cache is tested. The put method is not tested.")
public void test_get_put() throws Exception {
URL url = new URL("http://" +
diff --git a/luni/src/test/java/tests/api/java/net/SocketPermissionTest.java b/luni/src/test/java/tests/api/java/net/SocketPermissionTest.java
index fecf50c..f600ef4 100644
--- a/luni/src/test/java/tests/api/java/net/SocketPermissionTest.java
+++ b/luni/src/test/java/tests/api/java/net/SocketPermissionTest.java
@@ -17,6 +17,8 @@
package tests.api.java.net;
+import org.apache.harmony.testframework.serialization.SerializationTest;
+
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
@@ -273,6 +275,56 @@ public class SocketPermissionTest extends junit.framework.TestCase {
}
/**
+ * @tests serialization/deserialization.
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization/deserialization compatibility.",
+ method = "!SerializationSelf",
+ args = {}
+ )
+ public void testSerializationSelf() throws Exception {
+ SocketPermission permission = new SocketPermission("harmony.apache.org", "connect");;
+
+ SerializationTest.verifySelf(permission);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SocketPermission",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
+ public void test_ConstructorLjava_lang_StringLjava_lang_String_subtestIPv6() {
+ String[] goodTestStrings = {
+ "12334.0.0.01", "[fe80::1]",
+ "[FE80:0000:0000:0000:0000:0000:0000:0001]:80",
+ "[::ffff]:80-82", "[ffff::]:80-82", "[fe80::1]:80",
+ "FE80:0000:0000:0000:0000:0000:0000:0001",
+ "FE80:0000:0000:0000:0000:0000:0000:0001:80"
+ };
+ String[] badTestStrings = {"someName:withColonInit:80", "fg80::1", "[ffff:::80-82]",
+ ":[:fff]:80", "FE80:0000:0000:0000:0000:0000:0000:0001:80:82", "FE80::1"
+ };
+
+ for (int i=0; i < goodTestStrings.length; i++) {
+ try {
+ SocketPermission sp = new SocketPermission(goodTestStrings[i], "connect");
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ fail("SocketPermission named: " + goodTestStrings[i] + " failed construction: " + e.getMessage());
+ }
+ }
+
+ for (int i=0; i < badTestStrings.length; i++) {
+ try {
+ SocketPermission sp = new SocketPermission(badTestStrings[i], "connect");
+ fail("SocketPermission named: " + badTestStrings[i] + " should have thrown an IllegalArgumentException on construction");
+ } catch (IllegalArgumentException e) {}
+ }
+ }
+
+ /**
* Sets up the fixture, for example, open a network connection. This method
* is called before a test is executed.
*/
diff --git a/luni/src/test/java/tests/api/java/util/CurrencyTest.java b/luni/src/test/java/tests/api/java/util/CurrencyTest.java
index 04c92ee..d41f719 100644
--- a/luni/src/test/java/tests/api/java/util/CurrencyTest.java
+++ b/luni/src/test/java/tests/api/java/util/CurrencyTest.java
@@ -18,13 +18,10 @@
package tests.api.java.util;
import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.AndroidOnly;
-import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Currency;
@@ -58,7 +55,6 @@ public class CurrencyTest extends junit.framework.TestCase {
method = "getInstance",
args = {java.util.Locale.class}
)
- @KnownFailure("getInstance instead of returning null value for region without currency throws exception which should be thrown only in case of locale does not support country code.")
public void test_getInstanceLjava_util_Locale() {
/*
* the behaviour in all these three cases should be the same since this
@@ -150,30 +146,32 @@ public class CurrencyTest extends junit.framework.TestCase {
method = "getSymbol",
args = {}
)
- @KnownFailure("getSymbol() returns wrong value for currency symbol")
+ @AndroidOnly("icu and the RI have different data. Because Android"
+ + "only defines a few locales as a must have, it was not possible"
+ + "to find a set of combinations where no differences between"
+ + "the RI and Android exist.")
public void test_getSymbol() {
-
+
Currency currK = Currency.getInstance("KRW");
- Currency currI = Currency.getInstance("INR");
+ Currency currI = Currency.getInstance("IEP");
Currency currUS = Currency.getInstance("USD");
Locale.setDefault(Locale.US);
assertEquals("currK.getSymbol()", "KRW", currK.getSymbol());
- assertEquals("currI.getSymbol()", "INR", currI.getSymbol());
+ assertEquals("currI.getSymbol()", "IR\u00a3", currI.getSymbol());
assertEquals("currUS.getSymbol()", "$", currUS.getSymbol());
- Locale.setDefault(new Locale("ko", "KR"));
- assertEquals("currK.getSymbol()", "\uffe6", currK.getSymbol());
- assertEquals("currI.getSymbol()", "INR", currI.getSymbol());
+ Locale.setDefault(new Locale("en", "IE"));
+ assertEquals("currK.getSymbol()", "KRW", currK.getSymbol());
+ assertEquals("currI.getSymbol()", "\u00a3", currI.getSymbol());
assertEquals("currUS.getSymbol()", "USD", currUS.getSymbol());
// test what happens if this is an invalid locale,
// one with Korean country but an India language
- // this method should return the currency codes in that case
Locale.setDefault(new Locale("kr", "KR"));
assertEquals("currK.getSymbol()", "KRW", currK.getSymbol());
- assertEquals("currI.getSymbol()", "INR", currI.getSymbol());
- assertEquals("currUS.getSymbol()", "USD", currUS.getSymbol());
+ assertEquals("currI.getSymbol()", "IR\u00a3", currI.getSymbol());
+ assertEquals("currUS.getSymbol()", "$", currUS.getSymbol());
}
/**
@@ -220,24 +218,20 @@ public class CurrencyTest extends junit.framework.TestCase {
new Locale("en", "")};
String[] euro = new String[] {"EUR", "\u20ac"};
- String[] yen = new String[] {"JPY", "\uffe5", "\uffe5JP", "JP\uffe5"};
+ // \u00a5 and \uffe5 are actually the same symbol, just different code points.
+ // But the RI returns the \uffe5 and Android returns those with \u00a5
+ String[] yen = new String[] {"JPY", "\u00a5", "\u00a5JP", "JP\u00a5", "\uffe5", "\uffe5JP", "JP\uffe5"};
String[] dollar = new String[] {"USD", "$", "US$", "$US"};
String[] cDollar = new String[] {"CAD", "$", "Can$", "$Ca"};
- String[] crone = new String[] {"DKK", "kr", "CrD"};
Currency currE = Currency.getInstance("EUR");
Currency currJ = Currency.getInstance("JPY");
Currency currUS = Currency.getInstance("USD");
Currency currCA = Currency.getInstance("CAD");
- Currency currDKK = Currency.getInstance("DKK");
int i, j, k;
boolean flag;
- Locale.setDefault(Locale.US);
- Locale.setDefault(new Locale("ja", "JP"));
- Locale.setDefault(new Locale("da", "DK"));
-
for(k = 0; k < loc1.length; k++) {
Locale.setDefault(loc1[k]);
@@ -249,7 +243,12 @@ public class CurrencyTest extends junit.framework.TestCase {
break;
}
}
- assertTrue(flag);
+ assertTrue("Default Locale is: " + Locale.getDefault()
+ + ". For locale " + loc1[i]
+ + " the Euro currency returned "
+ + currE.getSymbol(loc1[i])
+ + ". Expected was one of these: "
+ + Arrays.toString(euro), flag);
}
for (i = 0; i < loc1.length; i++) {
@@ -262,7 +261,12 @@ public class CurrencyTest extends junit.framework.TestCase {
break;
}
}
- assertTrue(flag);
+ assertTrue("Default Locale is: " + Locale.getDefault()
+ + ". For locale " + loc1[i]
+ + " the Yen currency returned "
+ + currJ.getSymbol(loc1[i])
+ + ". Expected was one of these: "
+ + Arrays.toString(yen), flag);
}
for (i = 0; i < loc1.length; i++) {
@@ -273,7 +277,12 @@ public class CurrencyTest extends junit.framework.TestCase {
break;
}
}
- assertTrue(flag);
+ assertTrue("Default Locale is: " + Locale.getDefault()
+ + ". For locale " + loc1[i]
+ + " the Dollar currency returned "
+ + currUS.getSymbol(loc1[i])
+ + ". Expected was one of these: "
+ + Arrays.toString(dollar), flag);
}
for (i = 0; i < loc1.length; i++) {
@@ -284,18 +293,12 @@ public class CurrencyTest extends junit.framework.TestCase {
break;
}
}
- assertTrue(flag);
- }
-
- for (i = 0; i < loc1.length; i++) {
- flag = false;
- for (j = 0; j < dollar.length; j++) {
- if (currCA.getSymbol(loc1[i]).equals(cDollar[j])) {
- flag = true;
- break;
- }
- }
- assertTrue(flag);
+ assertTrue("Default Locale is: " + Locale.getDefault()
+ + ". For locale " + loc1[i]
+ + " the Canadian Dollar currency returned "
+ + currCA.getSymbol(loc1[i])
+ + ". Expected was one of these: "
+ + Arrays.toString(cDollar), flag);
}
}
}
@@ -309,26 +312,31 @@ public class CurrencyTest extends junit.framework.TestCase {
method = "getDefaultFractionDigits",
args = {}
)
- @KnownFailure("method return wrong number of digits for pseudo-currency")
public void test_getDefaultFractionDigits() {
- Currency c1 = Currency.getInstance("EUR");
+
+ Currency c1 = Currency.getInstance("TND");
c1.getDefaultFractionDigits();
assertEquals(" Currency.getInstance(\"" + c1
- + "\") returned incorrect number of digits. ", 2, c1
+ + "\") returned incorrect number of digits. ", 3, c1
.getDefaultFractionDigits());
- Currency c2 = Currency.getInstance("JPY");
+ Currency c2 = Currency.getInstance("EUR");
c2.getDefaultFractionDigits();
assertEquals(" Currency.getInstance(\"" + c2
- + "\") returned incorrect number of digits. ", 0, c2
+ + "\") returned incorrect number of digits. ", 2, c2
.getDefaultFractionDigits());
- Currency c3 = Currency.getInstance("XBD");
+ Currency c3 = Currency.getInstance("JPY");
c3.getDefaultFractionDigits();
assertEquals(" Currency.getInstance(\"" + c3
- + "\") returned incorrect number of digits. ", -1, c3
+ + "\") returned incorrect number of digits. ", 0, c3
.getDefaultFractionDigits());
+ Currency c4 = Currency.getInstance("XXX");
+ c4.getDefaultFractionDigits();
+ assertEquals(" Currency.getInstance(\"" + c4
+ + "\") returned incorrect number of digits. ", -1, c4
+ .getDefaultFractionDigits());
}
/**
diff --git a/luni/src/test/java/tests/api/java/util/FormatterTest.java b/luni/src/test/java/tests/api/java/util/FormatterTest.java
index 6e1c86e..06a7797 100644
--- a/luni/src/test/java/tests/api/java/util/FormatterTest.java
+++ b/luni/src/test/java/tests/api/java/util/FormatterTest.java
@@ -16,7 +16,6 @@
package tests.api.java.util;
import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.KnownFailure;
@@ -194,6 +193,7 @@ public class FormatterTest extends TestCase {
method = "Formatter",
args = {java.lang.Appendable.class}
)
+ @AndroidOnly("the RI trows an exception that makes no sense. See comment.")
public void test_ConstructorLjava_lang_Appendable() {
MockAppendable ma = new MockAppendable();
Formatter f1 = new Formatter(ma);
@@ -267,6 +267,7 @@ public class FormatterTest extends TestCase {
method = "Formatter",
args = {java.lang.String.class}
)
+ @KnownFailure("The Exception is not thrown on linux if the user is root")
public void test_ConstructorLjava_lang_String() throws IOException {
Formatter f = null;
try {
@@ -284,7 +285,7 @@ public class FormatterTest extends TestCase {
assertEquals(0, fileWithContent.length());
f.close();
- // FIXME This exception will not be thrown out on linux.
+ // FIXME This exception will not be thrown on linux if the user is root.
try {
f = new Formatter(readOnly.getPath());
fail("should throw FileNotFoundException");
@@ -313,6 +314,7 @@ public class FormatterTest extends TestCase {
method = "Formatter",
args = {java.lang.String.class, java.lang.String.class}
)
+ @KnownFailure("The Exception is not thrown on linux if the user is root")
public void test_ConstructorLjava_lang_StringLjava_lang_String()
throws IOException {
Formatter f = null;
@@ -345,7 +347,7 @@ public class FormatterTest extends TestCase {
assertEquals(0, fileWithContent.length());
f.close();
- // FIXME This exception will not be thrown out on linux.
+ // FIXME This exception will not be thrown on linux if the user is root.
try {
f = new Formatter(readOnly.getPath(), "UTF-16BE");
fail("should throw FileNotFoundException");
@@ -374,6 +376,7 @@ public class FormatterTest extends TestCase {
method = "Formatter",
args = {java.lang.String.class, java.lang.String.class, java.util.Locale.class}
)
+ @KnownFailure("The Exception is not thrown on linux if the user is root")
public void test_ConstructorLjava_lang_StringLjava_lang_StringLjava_util_Locale()
throws IOException {
Formatter f = null;
@@ -414,6 +417,7 @@ public class FormatterTest extends TestCase {
assertEquals(0, fileWithContent.length());
f.close();
+ // FIXME This exception will not be thrown on linux if the user is root.
try {
f = new Formatter(readOnly.getPath(), Charset.defaultCharset()
.name(), Locale.ITALY);
@@ -444,6 +448,7 @@ public class FormatterTest extends TestCase {
method = "Formatter",
args = {java.io.File.class}
)
+ @KnownFailure("The Exception is not thrown on linux if the user is root")
public void test_ConstructorLjava_io_File() throws IOException {
Formatter f = null;
try {
@@ -461,7 +466,7 @@ public class FormatterTest extends TestCase {
assertEquals(0, fileWithContent.length());
f.close();
- // FIXME This exception will not be thrown out on linux.
+ // FIXME This exception will not be thrown on linux if the user is root.
try {
f = new Formatter(readOnly);
fail("should throw FileNotFoundException");
@@ -490,6 +495,7 @@ public class FormatterTest extends TestCase {
method = "Formatter",
args = {java.io.File.class, java.lang.String.class}
)
+ @KnownFailure("The Exception is not thrown on linux if the user is root")
public void test_ConstructorLjava_io_FileLjava_lang_String()
throws IOException {
Formatter f = null;
@@ -508,7 +514,7 @@ public class FormatterTest extends TestCase {
assertEquals(0, fileWithContent.length());
f.close();
- // FIXME This exception will not be thrown out on linux.
+ // FIXME This exception will not be thrown on linux if the user is root.
try {
f = new Formatter(readOnly, Charset.defaultCharset().name());
fail("should throw FileNotFoundException");
@@ -563,6 +569,7 @@ public class FormatterTest extends TestCase {
method = "Formatter",
args = {java.io.File.class, java.lang.String.class, java.util.Locale.class}
)
+ @KnownFailure("The Exception is not thrown on linux if the user is root")
public void test_ConstructorLjava_io_FileLjava_lang_StringLjava_util_Locale()
throws IOException {
Formatter f = null;
@@ -601,7 +608,7 @@ public class FormatterTest extends TestCase {
assertEquals(0, fileWithContent.length());
f.close();
- // FIXME This exception will not be thrown out on linux.
+ // FIXME This exception will not be thrown on linux if the user is root.
try {
f = new Formatter(readOnly.getPath(), Charset.defaultCharset()
.name(), Locale.ITALY);
@@ -2021,7 +2028,7 @@ public class FormatterTest extends TestCase {
method = "format",
args = {java.lang.String.class, java.lang.Object[].class}
)
- @KnownFailure("Conversion for japanese locale works improperly")
+ @AndroidOnly("Icu data for Czech locale differs a bit from the RI")
public void test_formatLjava_lang_String$Ljava_lang_Object_DateTimeConversion() {
Formatter f = null;
Date now = new Date(1147327147578L);
@@ -2223,25 +2230,25 @@ public class FormatterTest extends TestCase {
};
- final Object[][] lowerCaseJapanTriple = {
- {0L, 'a', "\u6728"}, //$NON-NLS-2$
- {Long.MAX_VALUE, 'a', "\u65e5"}, //$NON-NLS-2$
- {-1000L, 'a', "\u6728"}, //$NON-NLS-2$
- {new Date(1147327147578L), 'a', "\u6728"}, //$NON-NLS-2$
- {paris, 'a', "\u6708"}, //$NON-NLS-2$
- {china, 'a', "\u6708"}, //$NON-NLS-2$
+ final Object[][] lowerCaseCzechTriple = {
+ {0L, 'a', "\u010dt"}, //$NON-NLS-2$
+ {Long.MAX_VALUE, 'a', "ne"}, //$NON-NLS-2$
+ {-1000L, 'a', "\u010dt"}, //$NON-NLS-2$
+ {new Date(1147327147578L), 'a', "\u010dt"}, //$NON-NLS-2$
+ {paris, 'a', "po"}, //$NON-NLS-2$
+ {china, 'a', "po"}, //$NON-NLS-2$
{0L, 'b', "1"}, //$NON-NLS-2$
{Long.MAX_VALUE, 'b', "8"}, //$NON-NLS-2$
{-1000L, 'b', "1"}, //$NON-NLS-2$
{new Date(1147327147578L), 'b', "5"}, //$NON-NLS-2$
{paris, 'b', "5"}, //$NON-NLS-2$
{china, 'b', "5"}, //$NON-NLS-2$
- {0L, 'c', "\u6728 1 01 08:00:00 CST 1970"}, //$NON-NLS-2$
- {Long.MAX_VALUE, 'c', "\u65e5 8 17 15:12:55 CST 292278994"}, //$NON-NLS-2$
- {-1000L, 'c', "\u6728 1 01 07:59:59 CST 1970"}, //$NON-NLS-2$
- {new Date(1147327147578L), 'c', "\u6728 5 11 13:59:07 CST 2006"}, //$NON-NLS-2$
- {paris, 'c', "\u6708 5 08 12:00:00 CEST 2006"}, //$NON-NLS-2$
- {china, 'c', "\u6708 5 08 12:00:00 GMT-08:00 2006"}, //$NON-NLS-2$
+ {0L, 'c', "\u010dt I 01 08:00:00 CST 1970"}, //$NON-NLS-2$
+ {Long.MAX_VALUE, 'c', "ne VIII 17 15:12:55 CST 292278994"}, //$NON-NLS-2$
+ {-1000L, 'c', "\u010dt I 01 07:59:59 CST 1970"}, //$NON-NLS-2$
+ {new Date(1147327147578L), 'c', "\u010dt V 11 13:59:07 CST 2006"}, //$NON-NLS-2$
+ {paris, 'c', "po V 08 12:00:00 CEST 2006"}, //$NON-NLS-2$
+ {china, 'c', "po V 08 12:00:00 GMT-08:00 2006"}, //$NON-NLS-2$
{0L, 'd', "01"}, //$NON-NLS-2$
{Long.MAX_VALUE, 'd', "17"}, //$NON-NLS-2$
{-1000L, 'd', "01"}, //$NON-NLS-2$
@@ -2254,12 +2261,12 @@ public class FormatterTest extends TestCase {
{new Date(1147327147578L), 'e', "11"}, //$NON-NLS-2$
{paris, 'e', "8"}, //$NON-NLS-2$
{china, 'e', "8"}, //$NON-NLS-2$
- {0L, 'h', "1"}, //$NON-NLS-2$
- {Long.MAX_VALUE, 'h', "8"}, //$NON-NLS-2$
- {-1000L, 'h', "1"}, //$NON-NLS-2$
- {new Date(1147327147578L), 'h', "5"}, //$NON-NLS-2$
- {paris, 'h', "5"}, //$NON-NLS-2$
- {china, 'h', "5"}, //$NON-NLS-2$
+ {0L, 'h', "I"}, //$NON-NLS-2$
+ {Long.MAX_VALUE, 'h', "VIII"}, //$NON-NLS-2$
+ {-1000L, 'h', "I"}, //$NON-NLS-2$
+ {new Date(1147327147578L), 'h', "V"}, //$NON-NLS-2$
+ {paris, 'h', "V"}, //$NON-NLS-2$
+ {china, 'h', "V"}, //$NON-NLS-2$
{0L, 'j', "001"}, //$NON-NLS-2$
{Long.MAX_VALUE, 'j', "229"}, //$NON-NLS-2$
{-1000L, 'j', "001"}, //$NON-NLS-2$
@@ -2284,18 +2291,18 @@ public class FormatterTest extends TestCase {
{new Date(1147327147578L), 'm', "05"}, //$NON-NLS-2$
{paris, 'm', "05"}, //$NON-NLS-2$
{china, 'm', "05"}, //$NON-NLS-2$
- {0L, 'p', "\u5348\u524d"}, //$NON-NLS-2$
- {Long.MAX_VALUE, 'p', "\u5348\u5f8c"}, //$NON-NLS-2$
- {-1000L, 'p', "\u5348\u524d"}, //$NON-NLS-2$
- {new Date(1147327147578L), 'p', "\u5348\u5f8c"}, //$NON-NLS-2$
- {paris, 'p', "\u5348\u5f8c"}, //$NON-NLS-2$
- {china, 'p', "\u5348\u5f8c"}, //$NON-NLS-2$
- {0L, 'r', "08:00:00 \u5348\u524d"}, //$NON-NLS-2$
- {Long.MAX_VALUE, 'r', "03:12:55 \u5348\u5f8c"}, //$NON-NLS-2$
- {-1000L, 'r', "07:59:59 \u5348\u524d"}, //$NON-NLS-2$
- {new Date(1147327147578L), 'r', "01:59:07 \u5348\u5f8c"}, //$NON-NLS-2$
- {paris, 'r', "12:00:00 \u5348\u5f8c"}, //$NON-NLS-2$
- {china, 'r', "12:00:00 \u5348\u5f8c"}, //$NON-NLS-2$
+ {0L, 'p', "dop."}, //$NON-NLS-2$
+ {Long.MAX_VALUE, 'p', "odp."}, //$NON-NLS-2$
+ {-1000L, 'p', "dop."}, //$NON-NLS-2$
+ {new Date(1147327147578L), 'p', "odp."}, //$NON-NLS-2$
+ {paris, 'p', "odp."}, //$NON-NLS-2$
+ {china, 'p', "odp."}, //$NON-NLS-2$
+ {0L, 'r', "08:00:00 DOP."}, //$NON-NLS-2$
+ {Long.MAX_VALUE, 'r', "03:12:55 ODP."}, //$NON-NLS-2$
+ {-1000L, 'r', "07:59:59 DOP."}, //$NON-NLS-2$
+ {new Date(1147327147578L), 'r', "01:59:07 ODP."}, //$NON-NLS-2$
+ {paris, 'r', "12:00:00 ODP."}, //$NON-NLS-2$
+ {china, 'r', "12:00:00 ODP."}, //$NON-NLS-2$
{0L, 's', "0"}, //$NON-NLS-2$
{Long.MAX_VALUE, 's', "9223372036854775"}, //$NON-NLS-2$
{-1000L, 's', "-1"}, //$NON-NLS-2$
@@ -2337,10 +2344,10 @@ public class FormatterTest extends TestCase {
lowerCaseFranceTriple[i][output], f.toString());
f = new Formatter(Locale.GERMAN);
- f.format(Locale.JAPAN, formatSpecifier, lowerCaseJapanTriple[i][input]);
+ f.format(new Locale("cs", "CZ"), formatSpecifier, lowerCaseCzechTriple[i][input]);
assertEquals("Format pattern: " + formatSpecifier //$NON-NLS-2$
- + " Argument: " + lowerCaseJapanTriple[i][input], //$NON-NLS-2$
- lowerCaseJapanTriple[i][output], f.toString());
+ + " Argument: " + lowerCaseCzechTriple[i][input], //$NON-NLS-2$
+ lowerCaseCzechTriple[i][output], f.toString());
// test '%T'
f = new Formatter(Locale.GERMAN);
@@ -2358,10 +2365,10 @@ public class FormatterTest extends TestCase {
.toUpperCase(Locale.US), f.toString());
f = new Formatter(Locale.GERMAN);
- f.format(Locale.JAPAN, formatSpecifierUpper, lowerCaseJapanTriple[i][input]);
+ f.format(new Locale("cs", "CZ"), formatSpecifierUpper, lowerCaseCzechTriple[i][input]);
assertEquals("Format pattern: " + formatSpecifierUpper //$NON-NLS-2$
- + " Argument: " + lowerCaseJapanTriple[i][input], //$NON-NLS-2$
- ((String)lowerCaseJapanTriple[i][output])
+ + " Argument: " + lowerCaseCzechTriple[i][input], //$NON-NLS-2$
+ ((String)lowerCaseCzechTriple[i][output])
.toUpperCase(Locale.US), f.toString());
}
@@ -2565,19 +2572,19 @@ public class FormatterTest extends TestCase {
};
- final Object[][] upperCaseJapanTriple = {
- {0L, 'A', "\u6728\u66dc\u65e5"}, //$NON-NLS-2$
- {Long.MAX_VALUE, 'A', "\u65e5\u66dc\u65e5"}, //$NON-NLS-2$
- {-1000L, 'A', "\u6728\u66dc\u65e5"}, //$NON-NLS-2$
- {new Date(1147327147578L), 'A', "\u6728\u66dc\u65e5"}, //$NON-NLS-2$
- {paris, 'A', "\u6708\u66dc\u65e5"}, //$NON-NLS-2$
- {china, 'A', "\u6708\u66dc\u65e5"}, //$NON-NLS-2$
- {0L, 'B', "1\u6708"}, //$NON-NLS-2$
- {Long.MAX_VALUE, 'B', "8\u6708"}, //$NON-NLS-2$
- {-1000L, 'B', "1\u6708"}, //$NON-NLS-2$
- {new Date(1147327147578L), 'B', "5\u6708"}, //$NON-NLS-2$
- {paris, 'B', "5\u6708"}, //$NON-NLS-2$
- {china, 'B', "5\u6708"}, //$NON-NLS-2$
+ final Object[][] upperCaseCzechTriple = {
+ {0L, 'A', "\u010ctvrtek"}, //$NON-NLS-2$
+ {Long.MAX_VALUE, 'A', "Ned\u011ble"}, //$NON-NLS-2$
+ {-1000L, 'A', "\u010ctvrtek"}, //$NON-NLS-2$
+ {new Date(1147327147578L), 'A', "\u010ctvrtek"}, //$NON-NLS-2$
+ {paris, 'A', "Pond\u011bl\u00ed"}, //$NON-NLS-2$
+ {china, 'A', "Pond\u011bl\u00ed"}, //$NON-NLS-2$
+ {0L, 'B', "leden"}, //$NON-NLS-2$
+ {Long.MAX_VALUE, 'B', "srpen"}, //$NON-NLS-2$
+ {-1000L, 'B', "leden"}, //$NON-NLS-2$
+ {new Date(1147327147578L), 'B', "kv\u011bten"}, //$NON-NLS-2$
+ {paris, 'B', "kv\u011bten"}, //$NON-NLS-2$
+ {china, 'B', "kv\u011bten"}, //$NON-NLS-2$
{0L, 'C', "19"}, //$NON-NLS-2$
{Long.MAX_VALUE, 'C', "2922789"}, //$NON-NLS-2$
{-1000L, 'C', "19"}, //$NON-NLS-2$
@@ -2673,19 +2680,19 @@ public class FormatterTest extends TestCase {
continue;
}
// test '%t'
- f = new Formatter(Locale.JAPAN);
- f.format(formatSpecifier, upperCaseJapanTriple[i][input]);
+ f = new Formatter(new Locale("cs", "CZ"));
+ f.format(formatSpecifier, upperCaseCzechTriple[i][input]);
assertEquals("Format pattern: " + formatSpecifier //$NON-NLS-2$
- + " Argument: " + upperCaseJapanTriple[i][input], //$NON-NLS-2$
- upperCaseJapanTriple[i][output], f.toString());
+ + " Argument: " + upperCaseCzechTriple[i][input], //$NON-NLS-2$
+ upperCaseCzechTriple[i][output], f.toString());
- f = new Formatter(Locale.JAPAN);
+ f = new Formatter(new Locale("cs", "CZ"));
f.format(Locale.GERMAN, formatSpecifier, upperCaseGermanTriple[i][input]);
assertEquals("Format pattern: " + formatSpecifier //$NON-NLS-2$
+ " Argument: " + upperCaseGermanTriple[i][input], //$NON-NLS-2$
upperCaseGermanTriple[i][output], f.toString());
- f = new Formatter(Locale.JAPAN);
+ f = new Formatter(new Locale("cs", "CZ"));
f.format(Locale.FRANCE, formatSpecifier, upperCaseFranceTriple[i][input]);
assertEquals("Format pattern: " + formatSpecifier //$NON-NLS-2$
+ " Argument: " + upperCaseFranceTriple[i][input], //$NON-NLS-2$
@@ -2700,10 +2707,10 @@ public class FormatterTest extends TestCase {
.toUpperCase(Locale.US), f.toString());
f = new Formatter(Locale.GERMAN);
- f.format(Locale.JAPAN, formatSpecifierUpper, upperCaseJapanTriple[i][input]);
+ f.format(new Locale("cs", "CZ"), formatSpecifierUpper, upperCaseCzechTriple[i][input]);
assertEquals("Format pattern: " + formatSpecifierUpper //$NON-NLS-2$
- + " Argument: " + upperCaseJapanTriple[i][input], //$NON-NLS-2$
- ((String)upperCaseJapanTriple[i][output])
+ + " Argument: " + upperCaseCzechTriple[i][input], //$NON-NLS-2$
+ ((String)upperCaseCzechTriple[i][output])
.toUpperCase(Locale.US), f.toString());
f = new Formatter(Locale.GERMAN);
@@ -2766,6 +2773,7 @@ public class FormatterTest extends TestCase {
method = "format",
args = {java.lang.String.class, java.lang.Object[].class}
)
+ @KnownFailure("flaky! results. differs if debugger is attached.")
public void test_formatLjava_lang_String$LBigInteger() {
final Object[][] tripleD = {
{new BigInteger("123456789012345678901234567890"), "%d", "123456789012345678901234567890"}, //$NON-NLS-2$
diff --git a/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java b/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java
index 76026bf..6d2ef74 100644
--- a/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java
+++ b/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java
@@ -17,8 +17,8 @@
package tests.api.java.util;
+import dalvik.annotation.AndroidOnly;
import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.KnownFailure;
@@ -208,7 +208,6 @@ public class GregorianCalendarTest extends junit.framework.TestCase {
method = "GregorianCalendar",
args = {java.util.TimeZone.class, java.util.Locale.class}
)
- @KnownFailure("same objects for different locales are not considered equal")
public void test_ConstructorLjava_util_TimeZoneLjava_util_Locale() {
// Test for method java.util.GregorianCalendar(java.util.TimeZone,
// java.util.Locale)
@@ -248,6 +247,8 @@ public class GregorianCalendarTest extends junit.framework.TestCase {
method = "add",
args = {int.class, int.class}
)
+ @AndroidOnly("This test fails on the RI with version 1.5 but succeeds"
+ + "on the RI with version 1.6")
public void test_addII() {
// Test for method void java.util.GregorianCalendar.add(int, int)
GregorianCalendar gc1 = new GregorianCalendar(1998, 11, 6);
@@ -763,7 +764,8 @@ public class GregorianCalendarTest extends junit.framework.TestCase {
method = "getMinimalDaysInFirstWeek",
args = {}
)
- @KnownFailure("Looks like there're some mistakes in timezones and/or locales data")
+ @KnownFailure("Some difference in timezones and/or locales data"
+ + "Who is right, the CLDR or the RI?")
public void test_getMinimalDaysInFirstWeek() {
// Regression for Harmony-1037
GregorianCalendar g = new GregorianCalendar(TimeZone
@@ -772,7 +774,7 @@ public class GregorianCalendarTest extends junit.framework.TestCase {
assertEquals(4, minimalDaysInFirstWeek);
g = new GregorianCalendar(TimeZone.getTimeZone("Paris/France"),
- new Locale("fr"));
+ new Locale("fr", "FR"));
minimalDaysInFirstWeek = g.getMinimalDaysInFirstWeek();
assertEquals(4, minimalDaysInFirstWeek);
diff --git a/luni/src/test/java/tests/api/java/util/PropertiesTest.java b/luni/src/test/java/tests/api/java/util/PropertiesTest.java
index 61d7c35..ddf9994 100644
--- a/luni/src/test/java/tests/api/java/util/PropertiesTest.java
+++ b/luni/src/test/java/tests/api/java/util/PropertiesTest.java
@@ -387,14 +387,14 @@ public class PropertiesTest extends junit.framework.TestCase {
method = "loadFromXML",
args = {java.io.InputStream.class}
)
- @KnownFailure("ToT fixed?")
+ @KnownFailure("Expected Exception is not thrown.")
public void test_loadFromXMLLjava_io_InputStream() throws IOException {
Properties myProps = new Properties();
myProps.put("Property A", " aye\\\f\t\n\r\b");
myProps.put("Property B", "b ee#!=:");
myProps.put("Property C", "see");
-
Properties myProps2 = new Properties();
+
ByteArrayOutputStream out = new ByteArrayOutputStream();
myProps.storeToXML(out, "A Header");
out.close();
diff --git a/luni/src/test/java/tests/api/java/util/ResourceBundleTest.java b/luni/src/test/java/tests/api/java/util/ResourceBundleTest.java
index 8fecc7e..480c998 100644
--- a/luni/src/test/java/tests/api/java/util/ResourceBundleTest.java
+++ b/luni/src/test/java/tests/api/java/util/ResourceBundleTest.java
@@ -17,6 +17,7 @@
package tests.api.java.util;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
@@ -138,6 +139,9 @@ public class ResourceBundleTest extends junit.framework.TestCase {
method = "getBundle",
args = {java.lang.String.class, java.util.Locale.class, java.lang.ClassLoader.class}
)
+ @KnownFailure("It's not allowed to pass null as parent class loader to"
+ + " a new ClassLoader anymore. Maybe we need to change"
+ + " URLClassLoader to allow this? It's not specified.")
public void test_getBundleLjava_lang_StringLjava_util_LocaleLjava_lang_ClassLoader() {
String classPath = System.getProperty("java.class.path");
StringTokenizer tok = new StringTokenizer(classPath, File.pathSeparator);
diff --git a/luni/src/test/java/tests/api/java/util/TimeZoneTest.java b/luni/src/test/java/tests/api/java/util/TimeZoneTest.java
index 87a5e87..4637f10 100644
--- a/luni/src/test/java/tests/api/java/util/TimeZoneTest.java
+++ b/luni/src/test/java/tests/api/java/util/TimeZoneTest.java
@@ -61,7 +61,7 @@ public class TimeZoneTest extends junit.framework.TestCase {
method = "getDSTSavings",
args = {}
)
- @KnownFailure("method returns wrong time shift")
+ @KnownFailure("Might be a difference in data.")
public void test_getDSTSavings() {
// Test for method int java.util.TimeZone.getDSTSavings()
@@ -136,6 +136,7 @@ public class TimeZoneTest extends junit.framework.TestCase {
method = "getTimeZone",
args = {java.lang.String.class}
)
+ @KnownFailure("Android fails the last test.")
public void test_getTimeZoneLjava_lang_String() {
assertEquals("Must return GMT when given an invalid TimeZone id SMT-8.",
"GMT", TimeZone.getTimeZone("SMT-8").getID());
diff --git a/luni/src/test/resources/tests/api/java/net/file1.cache b/luni/src/test/resources/tests/api/java/net/file1.cache
new file mode 100644
index 0000000..9245960
--- /dev/null
+++ b/luni/src/test/resources/tests/api/java/net/file1.cache
@@ -0,0 +1 @@
+Cache test \ No newline at end of file