diff options
46 files changed, 430 insertions, 163 deletions
diff --git a/NativeCode.mk b/NativeCode.mk index 733f62e..2a16598 100644 --- a/NativeCode.mk +++ b/NativeCode.mk @@ -114,6 +114,7 @@ endif # LIBCORE_SKIP_TESTS ifeq ($(WITH_HOST_DALVIK),true) include $(CLEAR_VARS) + LOCAL_CLANG := true LOCAL_SRC_FILES += $(core_src_files) LOCAL_CFLAGS += $(core_cflags) LOCAL_C_INCLUDES += $(core_c_includes) @@ -128,6 +129,7 @@ ifeq ($(WITH_HOST_DALVIK),true) ifeq ($(LIBCORE_SKIP_TESTS),) include $(CLEAR_VARS) + LOCAL_CLANG := true LOCAL_SRC_FILES += $(core_test_files) LOCAL_CFLAGS += $(core_cflags) LOCAL_C_INCLUDES += libcore/include external/openssl/include diff --git a/dalvik/src/main/java/dalvik/annotation/BrokenTest.java b/dalvik/src/main/java/dalvik/annotation/BrokenTest.java index 401d652..16788d0 100644 --- a/dalvik/src/main/java/dalvik/annotation/BrokenTest.java +++ b/dalvik/src/main/java/dalvik/annotation/BrokenTest.java @@ -25,6 +25,8 @@ import java.lang.annotation.Target; * Marks a test case as broken. This means the test case should be fixed. * * @hide + * + * @deprecated - use expectations/brokentests.txt instead */ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD }) diff --git a/dalvik/src/main/java/dalvik/annotation/SideEffect.java b/dalvik/src/main/java/dalvik/annotation/SideEffect.java index b92e9bc..2d691e3 100644 --- a/dalvik/src/main/java/dalvik/annotation/SideEffect.java +++ b/dalvik/src/main/java/dalvik/annotation/SideEffect.java @@ -27,6 +27,8 @@ import java.lang.annotation.Target; * isolated manner. * * @hide + * + * @deprecated - use expectations/brokentests.txt instead */ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD, ElementType.TYPE }) diff --git a/expectations/brokentests.txt b/expectations/brokentests.txt index c108c6b..5cebb63 100644 --- a/expectations/brokentests.txt +++ b/expectations/brokentests.txt @@ -96,5 +96,71 @@ names: [ "org.apache.harmony.tests.java.util.ControlTest#test_needsReload_LStringLLocaleLStringLClassLoaderResourceBundleJ" ] +}, +{ + description: "Fails in CTS, passes in CoreTestRunner.", + result: EXEC_FAILED, + names: [ + "org.apache.harmony.tests.java.net.URLConnection#test_getContentEncoding", + "libcore.java.text.OldNumberFormatTest#test_parseLjava_lang_String", + "libcore.java.nio.channels.OldSocketChannelTest#test_writeLjava_nio_ByteBuffer_Nonblocking_HugeData", + "org.apache.harmony.tests.java.lang.ProcessManagerTest#testSleep", + "libcore.java.security.cert.OldPKIXParametersTest#testPKIXParametersKeyStore04" + ] +}, +{ + description: "Suffers from DH slowness, disabling for now.", + result: EXEC_FAILED, + names: [ + "libcore.java.security.OldDHTest#testDHGen", + "libcore.java.security.OldKeyPairGeneratorTestDH#testKeyPairGenerator", + "libcore.javax.crypto.spec.KeyPairGeneratorTestDH#testKeyPairGenerator", + "libcore.javax.crypto.spec.AlgorithmParametersTestDH#testAlgorithmParameters", + "libcore.javax.crypto.spec.AlgorithmParameterGeneratorTestDH#testAlgorithmParameterGenerator" + ] +}, +{ + description: "Destroys MD5 provider, hurts succeeding tests", + result: EXEC_FAILED, + names: [ + "tests.api.javax.security.cert.X509CertificateTest#testVerifyPublicKey", + "tests.api.javax.security.cert.X509CertificateTest#testVerifyPublicKeyString" + ] +}, +{ + description: "Suffers from side effect of other, currently unknown test", + result: EXEC_FAILED, + names: [ + "org.apache.harmony.luni.tests.internal.net.www.protocol.http.HttpURLConnectionTest#testProxyAuthorization" + ] +}, +{ + description: "Support_TestWebServer requires isolation.", + result: EXEC_FAILED, + names: [ + "libcore.java.net.OldURLClassLoaderTest#test_findResourceLjava_lang_String" + ] +}, +{ + description: "This test affects tests that are run after this one due to caching in URLConnection.", + result: EXEC_FAILED, + names: [ + "org.apache.harmony.luni.tests.java.net.ContentHandlerFactoryTest#test_createContentHandler" + ] +}, +{ + description: "Causes OutOfMemoryError to test finalization", + result: EXEC_FAILED, + names: [ + "org.apache.harmony.tests.java.lang.ref.SoftReferenceTest#test_get_SoftReference", + "org.apache.harmony.crypto.tests.javax.crypto#ExemptionMechanismTest#test_finalize" + ] +}, +{ + description: "Causes open dex file error", + result: EXEC_FAILED, + names: [ + "org.apache.harmony.tests.java.lang.reflect.GenericSignatureFormatErrorTest#test_signatureFormatError" + ] } ] diff --git a/expectations/knownfailures.txt b/expectations/knownfailures.txt index e6715ab..e0b4d38 100644 --- a/expectations/knownfailures.txt +++ b/expectations/knownfailures.txt @@ -606,7 +606,10 @@ { description: "statement.close() does not wrap up", bug: 3403706, - name: "libcore.java.sql.OldResultSetTest#testBeforeFirst" + names: [ + "libcore.java.sql.OldResultSetTest#testBeforeFirst", + "libcore.java.sql.OldResultSetTest#testAfterLast" + ] }, { description: "Resultset.close() does not wrap up", diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ProcessManagerTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ProcessManagerTest.java index 3930b59..9f7474a 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ProcessManagerTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ProcessManagerTest.java @@ -16,8 +16,6 @@ package org.apache.harmony.tests.java.lang; -import dalvik.annotation.BrokenTest; - import junit.framework.TestCase; import java.io.BufferedReader; @@ -47,7 +45,7 @@ public class ProcessManagerTest extends TestCase { assertEquals(greeting, readLine(process)); } - @BrokenTest("Sporadic failures in CTS, but not in CoreTestRunner") + // BrokenTest: Sporadic failures in CTS, but not in CoreTestRunner public void testSleep() throws IOException { String[] commands = { "sleep", "1" }; process = Runtime.getRuntime().exec(commands, null, null); diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ref/SoftReferenceTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ref/SoftReferenceTest.java index cfc5d0d..f66cbbf 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ref/SoftReferenceTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ref/SoftReferenceTest.java @@ -16,8 +16,6 @@ */ package org.apache.harmony.tests.java.lang.ref; -import dalvik.annotation.SideEffect; - import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.SoftReference; @@ -79,7 +77,7 @@ public class SoftReferenceTest extends junit.framework.TestCase { assertTrue("Same object not returned.", bool == sr.get()); } - @SideEffect("Causes OutOfMemoryError to test finalization") + // SideEffect: Causes OutOfMemoryError to test finalization public void test_get_SoftReference() { class TestObject { diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/reflect/GenericSignatureFormatErrorTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/reflect/GenericSignatureFormatErrorTest.java index 9cd4947..0cad681 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/reflect/GenericSignatureFormatErrorTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/reflect/GenericSignatureFormatErrorTest.java @@ -1,7 +1,6 @@ package org.apache.harmony.tests.java.lang.reflect; import dalvik.annotation.AndroidOnly; -import dalvik.annotation.SideEffect; import dalvik.system.DexFile; import junit.framework.TestCase; @@ -34,9 +33,9 @@ public class GenericSignatureFormatErrorTest extends TestCase{ @AndroidOnly("Uses Android specific class dalvik.system.DexFile " + "for loading classes.") - @SideEffect("strange issue (exception: 'could not open dex file', " + - "dalvikvm: 'waitpid failed' log msg - only occurs when @SideEffect is removed " + - "and this test is run via running tests.luni.AllTestsLang TestSuite") + // SideEffect: strange issue (exception: 'could not open dex file', + // dalvikvm: 'waitpid failed' log msg - only occurs when @SideEffect is removed + // and this test is run via running tests.luni.AllTestsLang TestSuite public void test_signatureFormatError() throws Exception { /* * dex1.bytes is a jar file with a classes.dex in it. diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/security/cert/X509CertificateTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/security/cert/X509CertificateTest.java index e937db9..64bfbb3 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/security/cert/X509CertificateTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/security/cert/X509CertificateTest.java @@ -22,9 +22,6 @@ package tests.api.javax.security.cert; -import dalvik.annotation.BrokenTest; -import dalvik.annotation.SideEffect; - import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -661,7 +658,7 @@ public class X509CertificateTest extends TestCase { * @throws CertificateException * {@link Certificate#verify(PublicKey)} */ - @SideEffect("Destroys MD5 provider, hurts succeeding tests") + // Side Effect: Destroys MD5 provider, hurts succeeding tests public void testVerifyPublicKey() throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException, CertificateException { @@ -744,7 +741,7 @@ public class X509CertificateTest extends TestCase { * @throws CertificateException * {@link Certificate#verify(PublicKey, String)} */ - @SideEffect("Destroys MD5 provider, hurts succeeding tests") + // SideEffect: Destroys MD5 provider, hurts succeeding tests public void testVerifyPublicKeyString() throws InvalidKeyException, java.security.cert.CertificateException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException, IOException, diff --git a/libart/src/main/java/dalvik/system/VMRuntime.java b/libart/src/main/java/dalvik/system/VMRuntime.java index ae65950..48b2dfa 100644 --- a/libart/src/main/java/dalvik/system/VMRuntime.java +++ b/libart/src/main/java/dalvik/system/VMRuntime.java @@ -89,6 +89,21 @@ public final class VMRuntime { public native String vmLibrary(); /** + * Returns the VM's instruction set. + */ + public native String vmInstructionSet(); + + /** + * Returns whether the VM is running in 64-bit mode. + */ + public native boolean is64Bit(); + + /** + * Returns whether the VM is running with JNI checking enabled. + */ + public native boolean isCheckJniEnabled(); + + /** * Gets the current ideal heap utilization, represented as a number * between zero and one. After a GC happens, the Dalvik heap may * be resized so that (size of live objects) / (size of heap) is diff --git a/libdvm/src/main/java/dalvik/system/VMRuntime.java b/libdvm/src/main/java/dalvik/system/VMRuntime.java index d532210..1d58d8d 100644 --- a/libdvm/src/main/java/dalvik/system/VMRuntime.java +++ b/libdvm/src/main/java/dalvik/system/VMRuntime.java @@ -87,6 +87,25 @@ public final class VMRuntime { public native String vmLibrary(); /** + * Returns the VM's instruction set. + */ + public String vmInstructionSet() { + return ""; + } + + /** + * Returns whether the VM is running in 64-bit mode. + */ + public boolean is64Bit() { + return false; + } + + /** + * Returns whether the VM is running with JNI checking enabled. + */ + public native boolean isCheckJniEnabled(); + + /** * Gets the current ideal heap utilization, represented as a number * between zero and one. After a GC happens, the Dalvik heap may * be resized so that (size of live objects) / (size of heap) is diff --git a/luni/src/main/java/java/nio/ByteBuffer.java b/luni/src/main/java/java/nio/ByteBuffer.java index 4c0f4a6..31bf481 100644 --- a/luni/src/main/java/java/nio/ByteBuffer.java +++ b/luni/src/main/java/java/nio/ByteBuffer.java @@ -766,16 +766,15 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer * if no changes may be made to the contents of this buffer. */ public ByteBuffer put(ByteBuffer src) { - if (!src.isAccessible() || !isAccessible()) { - throw new IllegalStateException("buffer is inaccessible"); - } - if (isReadOnly()) { throw new ReadOnlyBufferException(); } if (src == this) { throw new IllegalArgumentException("src == this"); } + if (!src.isAccessible() || !isAccessible()) { + throw new IllegalStateException("buffer is inaccessible"); + } int srcByteCount = src.remaining(); if (srcByteCount > remaining()) { throw new BufferOverflowException(); diff --git a/luni/src/main/java/java/nio/MemoryBlock.java b/luni/src/main/java/java/nio/MemoryBlock.java index a619b8d..b62e3c6 100644 --- a/luni/src/main/java/java/nio/MemoryBlock.java +++ b/luni/src/main/java/java/nio/MemoryBlock.java @@ -95,6 +95,7 @@ class MemoryBlock { protected long address; protected final long size; private boolean accessible; + private boolean freed; public static MemoryBlock mmap(FileDescriptor fd, long offset, long size, MapMode mapMode) throws IOException { if (size == 0) { @@ -140,6 +141,7 @@ class MemoryBlock { this.address = address; this.size = size; accessible = true; + freed = false; } // Used to support array/arrayOffset/hasArray for direct buffers. @@ -149,10 +151,11 @@ class MemoryBlock { public void free() { address = 0; + freed = true; } public boolean isFreed() { - return address == 0; + return freed; } public boolean isAccessible() { diff --git a/luni/src/main/java/java/security/MessageDigest.java b/luni/src/main/java/java/security/MessageDigest.java index 70202ac..1d37a90 100644 --- a/luni/src/main/java/java/security/MessageDigest.java +++ b/luni/src/main/java/java/security/MessageDigest.java @@ -352,14 +352,6 @@ public abstract class MessageDigest extends MessageDigestSpi { } } - @Override - public Object clone() throws CloneNotSupportedException { - if (this instanceof Cloneable) { - return super.clone(); - } - throw new CloneNotSupportedException(); - } - /** * Updates this {@code MessageDigest} using the given {@code input}. * @@ -421,12 +413,8 @@ public abstract class MessageDigest extends MessageDigestSpi { // Returns a clone if the spiImpl is cloneable @Override public Object clone() throws CloneNotSupportedException { - if (spiImpl instanceof Cloneable) { - MessageDigestSpi spi = (MessageDigestSpi) spiImpl.clone(); - return new MessageDigestImpl(spi, getProvider(), getAlgorithm()); - } - - throw new CloneNotSupportedException(); + MessageDigestSpi spi = (MessageDigestSpi) spiImpl.clone(); + return new MessageDigestImpl(spi, getProvider(), getAlgorithm()); } } } diff --git a/luni/src/main/java/java/security/Signature.java b/luni/src/main/java/java/security/Signature.java index 24f5298..7dd7d93 100644 --- a/luni/src/main/java/java/security/Signature.java +++ b/luni/src/main/java/java/security/Signature.java @@ -624,14 +624,6 @@ public abstract class Signature extends SignatureSpi { return engineGetParameter(param); } - @Override - public Object clone() throws CloneNotSupportedException { - if (this instanceof Cloneable) { - return super.clone(); - } - throw new CloneNotSupportedException(); - } - /** * Internal Signature implementation */ @@ -711,11 +703,8 @@ public abstract class Signature extends SignatureSpi { @Override public Object clone() throws CloneNotSupportedException { - if (spiImpl instanceof Cloneable) { - SignatureSpi spi = (SignatureSpi) spiImpl.clone(); - return new SignatureImpl(getAlgorithm(), getProvider(), spiImpl); - } - throw new CloneNotSupportedException(); + SignatureSpi spi = (SignatureSpi) spiImpl.clone(); + return new SignatureImpl(getAlgorithm(), getProvider(), spi); } /** diff --git a/luni/src/main/java/java/security/SignatureSpi.java b/luni/src/main/java/java/security/SignatureSpi.java index 27be30c..66c43d7 100644 --- a/luni/src/main/java/java/security/SignatureSpi.java +++ b/luni/src/main/java/java/security/SignatureSpi.java @@ -307,9 +307,6 @@ public abstract class SignatureSpi { @Override public Object clone() throws CloneNotSupportedException { - if (this instanceof Cloneable) { - return super.clone(); - } - throw new CloneNotSupportedException(); + return super.clone(); } } diff --git a/luni/src/main/java/java/security/spec/ECParameterSpec.java b/luni/src/main/java/java/security/spec/ECParameterSpec.java index 9860ac0..37b39ac 100644 --- a/luni/src/main/java/java/security/spec/ECParameterSpec.java +++ b/luni/src/main/java/java/security/spec/ECParameterSpec.java @@ -32,7 +32,7 @@ public class ECParameterSpec implements AlgorithmParameterSpec { // Cofactor private final int cofactor; // Name of curve if available. - private final String curveName; + private String curveName; /** * Creates a new {@code ECParameterSpec} with the specified elliptic curve, @@ -52,23 +52,10 @@ public class ECParameterSpec implements AlgorithmParameterSpec { */ public ECParameterSpec(EllipticCurve curve, ECPoint generator, BigInteger order, int cofactor) { - this(curve, generator, order, cofactor, null); - } - - /** - * Creates a new {@code ECParameterSpec} with the specified named curve - * and all of its parameters. - * - * @see #ECParameterSpec(EllipticCurve, ECPoint, BigInteger, int) - * @hide - */ - public ECParameterSpec(EllipticCurve curve, ECPoint generator, - BigInteger order, int cofactor, String curveName) { this.curve = curve; this.generator = generator; this.order = order; this.cofactor = cofactor; - this.curveName = curveName; // throw NullPointerException if curve, generator or order is null if (this.curve == null) { throw new NullPointerException("curve == null"); @@ -125,6 +112,15 @@ public class ECParameterSpec implements AlgorithmParameterSpec { } /** + * Used to set the curve name if available. + * + * @hide + */ + public void setCurveName(String curveName) { + this.curveName = curveName; + } + + /** * Returns the name of the curve if this is a named curve. Returns * {@code null} if this is not known to be a named curve. * diff --git a/luni/src/main/java/javax/net/ssl/SSLSocket.java b/luni/src/main/java/javax/net/ssl/SSLSocket.java index 820b884..498b8e0 100644 --- a/luni/src/main/java/javax/net/ssl/SSLSocket.java +++ b/luni/src/main/java/javax/net/ssl/SSLSocket.java @@ -501,14 +501,14 @@ import java.net.UnknownHostException; * <td></td> * </tr> * <tr> - * <td>TLS_EMPTY_RENEGOTIATION_INFO_SCSV</td> - * <td>11+</td> + * <td>TLS_ECDH_anon_WITH_RC4_128_SHA</td> * <td>11+</td> + * <td></td> * </tr> * <tr> - * <td>TLS_ECDH_anon_WITH_RC4_128_SHA</td> + * <td>TLS_EMPTY_RENEGOTIATION_INFO_SCSV</td> + * <td>11+</td> * <td>11+</td> - * <td></td> * </tr> * <tr> * <td>TLS_RSA_WITH_AES_128_CBC_SHA</td> diff --git a/luni/src/main/native/libcore_io_Posix.cpp b/luni/src/main/native/libcore_io_Posix.cpp index b1217c0..2721758 100644 --- a/luni/src/main/native/libcore_io_Posix.cpp +++ b/luni/src/main/native/libcore_io_Posix.cpp @@ -93,6 +93,7 @@ struct addrinfo_deleter { } \ if (_wasSignaled) { \ jniThrowException(jni_env, "java/net/SocketException", "Socket closed"); \ + _rc = -1; \ break; \ } \ if (_rc == -1 && _syscallErrno != EINTR) { \ @@ -131,6 +132,7 @@ struct addrinfo_deleter { } \ if (_wasSignaled) { \ jniThrowException(jni_env, "java/io/InterruptedIOException", # syscall_name " interrupted"); \ + _rc = -1; \ break; \ } \ if (_rc == -1 && _syscallErrno != EINTR) { \ diff --git a/luni/src/test/java/com/android/org/bouncycastle/crypto/digests/DigestTest.java b/luni/src/test/java/com/android/org/bouncycastle/crypto/digests/DigestTest.java index d2247cf..8708214 100644 --- a/luni/src/test/java/com/android/org/bouncycastle/crypto/digests/DigestTest.java +++ b/luni/src/test/java/com/android/org/bouncycastle/crypto/digests/DigestTest.java @@ -36,7 +36,7 @@ public class DigestTest extends TestCase { * @param newDigest The new digest implementation, provided by OpenSSL */ public void doTestMessageDigest(Digest oldDigest, Digest newDigest) { - final int ITERATIONS = 10; + final int ITERATIONS = 100; byte[] data = new byte[1024]; diff --git a/luni/src/test/java/dalvik/system/VMRuntimeTest.java b/luni/src/test/java/dalvik/system/VMRuntimeTest.java index 44af461..251ecd8 100644 --- a/luni/src/test/java/dalvik/system/VMRuntimeTest.java +++ b/luni/src/test/java/dalvik/system/VMRuntimeTest.java @@ -59,7 +59,7 @@ public final class VMRuntimeTest extends TestCase { try { Object array = VMRuntime.getRuntime().newNonMovableArray(void.class, 0); assertTrue(false); - } catch (IllegalArgumentException expected) { + } catch (NoClassDefFoundError expected) { } int maxLengthForLoop = 16 * 1024; @@ -113,7 +113,7 @@ public final class VMRuntimeTest extends TestCase { try { Object array = VMRuntime.getRuntime().newUnpaddedArray(void.class, 0); assertTrue(false); - } catch (IllegalArgumentException expected) { + } catch (NoClassDefFoundError expected) { } int maxLengthForLoop = 16 * 1024; diff --git a/luni/src/test/java/libcore/java/lang/CharacterTest.java b/luni/src/test/java/libcore/java/lang/CharacterTest.java index f0c5a23..0028521 100644 --- a/luni/src/test/java/libcore/java/lang/CharacterTest.java +++ b/luni/src/test/java/libcore/java/lang/CharacterTest.java @@ -242,7 +242,14 @@ public class CharacterTest extends junit.framework.TestCase { Method m = Character.class.getDeclaredMethod("isSpaceChar" + "Impl", int.class); m.setAccessible(true); for (int i = 0; i <= 0xffff; ++i) { - if((Boolean) m.invoke(null, i) != Character.isSpaceChar(i)) System.out.println(i); + // ICU and the RI disagree about character 0x180e. Remove this special case if this changes + // or Android decides to follow ICU exactly. + if (i == 0x180e) { + assertTrue(Character.isSpaceChar(i)); + assertFalse((Boolean) m.invoke(null, i)); + } else { + assertEquals("Failed for character " + i, m.invoke(null, i), Character.isSpaceChar(i)); + } } } @@ -260,7 +267,14 @@ public class CharacterTest extends junit.framework.TestCase { Method m = Character.class.getDeclaredMethod("isWhitespace" + "Impl", int.class); m.setAccessible(true); for (int i = 0; i <= 0xffff; ++i) { - assertEquals(m.invoke(null, i), Character.isWhitespace(i)); + // ICU and the RI disagree about character 0x180e. Remove this special case if this changes + // or Android decides to follow ICU exactly. + if (i == 0x180e) { + assertTrue(Character.isWhitespace(i)); + assertFalse((Boolean) m.invoke(null, i)); + } else { + assertEquals("Failed for character " + i, m.invoke(null, i), Character.isWhitespace(i)); + } } } diff --git a/luni/src/test/java/libcore/java/lang/SystemTest.java b/luni/src/test/java/libcore/java/lang/SystemTest.java index 4efecd7..1a672b0 100644 --- a/luni/src/test/java/libcore/java/lang/SystemTest.java +++ b/luni/src/test/java/libcore/java/lang/SystemTest.java @@ -149,8 +149,12 @@ public class SystemTest extends TestCase { done.set(true); } - public void testSystemProperties_immtuable() { + public void testSystemProperties_immutable() { + // Android-specific: The RI does not have a concept of immutable properties. + + // user.dir is an immutable property String userDir = System.getProperty("user.dir"); + assertNotNull(userDir); System.setProperty("user.dir", "not poop"); assertEquals(userDir, System.getProperty("user.dir")); @@ -166,4 +170,56 @@ public class SystemTest extends TestCase { assertEquals(userDir, System.getProperty("user.dir")); } + + public void testSystemProperties_setProperties_null() { + // user.dir is an immutable property + String userDir = System.getProperty("user.dir"); + assertNotNull(userDir); + + // Add a non-standard property + System.setProperty("p1", "v1"); + + // Reset using setProperties(null) + System.setProperties(null); + + // All the immutable properties should be reset. + assertEquals(userDir, System.getProperty("user.dir")); + // Non-standard properties are cleared. + assertNull(System.getProperty("p1")); + } + + public void testSystemProperties_setProperties_nonNull() { + String userDir = System.getProperty("user.dir"); + + Properties newProperties = new Properties(); + // Immutable property + newProperties.setProperty("user.dir", "v1"); + // Non-standard property + newProperties.setProperty("p1", "v2"); + + System.setProperties(newProperties); + + // Android-specific: The RI makes the setProperties() argument the system properties object, + // Android makes a new Properties object and copies the properties. + assertNotSame(newProperties, System.getProperties()); + // Android-specific: The RI does not have a concept of immutable properties. + assertEquals(userDir, System.getProperty("user.dir")); + + assertEquals("v2", System.getProperty("p1")); + } + + public void testSystemProperties_getProperties_clear() { + String userDir = System.getProperty("user.dir"); + assertNotNull(userDir); + System.setProperty("p1", "v1"); + + Properties properties = System.getProperties(); + assertEquals("v1", properties.getProperty("p1")); + + properties.clear(); + + // Android-specific: The RI clears everything, Android resets to immutable defaults. + assertEquals(userDir, System.getProperty("user.dir")); + assertNull(System.getProperty("p1")); + } } diff --git a/luni/src/test/java/libcore/java/net/InetAddressTest.java b/luni/src/test/java/libcore/java/net/InetAddressTest.java index c7617ab..4b656cc 100644 --- a/luni/src/test/java/libcore/java/net/InetAddressTest.java +++ b/luni/src/test/java/libcore/java/net/InetAddressTest.java @@ -49,13 +49,16 @@ public class InetAddressTest extends junit.framework.TestCase { "1234", "0", // Single out the deprecated form of the ANY address. - // Hex. + // Hex. Not supported by Android but supported by the RI. "0x1.0x2.0x3.0x4", "0x7f.0x00.0x00.0x01", "7f.0.0.1", - // Octal. - "0177.00.00.01", // Historically, this would have been interpreted as 127.0.0.1. + // Octal. Not supported by Android but supported by the RI. In the RI, if any of the numbers + // cannot be treated as a decimal the entire IP is interpreted differently, leading to + // "0177.00.00.01" -> 177.0.0.1, but "0177.0x0.00.01" -> 127.0.0.1. + // Android does not do this. + "0256.00.00.01", // Historically, this could have been interpreted as 174.0.0.1. // Negative numbers. "-1.0.0.1", @@ -89,6 +92,9 @@ public class InetAddressTest extends junit.framework.TestCase { } catch (IllegalArgumentException expected) { } + // Android does not recognize Octal (leading 0) cases: they are treated as decimal. + assertEquals("/177.0.0.1", InetAddress.parseNumericAddress("0177.00.00.01").toString()); + for (String invalid : INVALID_IPv4_NUMERIC_ADDRESSES) { try { InetAddress.parseNumericAddress(invalid); @@ -121,6 +127,9 @@ public class InetAddressTest extends junit.framework.TestCase { // Negative test assertFalse(InetAddress.isNumeric("example.com")); + // Android does not handle Octal (leading 0) cases: they are treated as decimal. + assertTrue(InetAddress.isNumeric("0177.00.00.01")); // Interpreted as 177.0.0.1 + for (String invalid : INVALID_IPv4_NUMERIC_ADDRESSES) { assertFalse(invalid, InetAddress.isNumeric(invalid)); } diff --git a/luni/src/test/java/libcore/java/net/OldURLClassLoaderTest.java b/luni/src/test/java/libcore/java/net/OldURLClassLoaderTest.java index 3a5608c..c076f1d 100644 --- a/luni/src/test/java/libcore/java/net/OldURLClassLoaderTest.java +++ b/luni/src/test/java/libcore/java/net/OldURLClassLoaderTest.java @@ -17,7 +17,6 @@ package libcore.java.net; -import dalvik.annotation.SideEffect; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -26,15 +25,11 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.security.CodeSource; -import java.security.Permission; import java.security.PermissionCollection; -import java.security.cert.Certificate; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.jar.Manifest; -import org.apache.harmony.security.tests.support.TestCertUtils; -import tests.support.Support_Configuration; import tests.support.Support_TestWebData; import tests.support.Support_TestWebServer; import tests.support.resource.Support_Resources; @@ -42,15 +37,6 @@ import tests.support.resource.Support_Resources; public class OldURLClassLoaderTest extends junit.framework.TestCase { URLClassLoader ucl; - SecurityManager sm = new SecurityManager() { - - public void checkPermission(Permission perm) { - } - - public void checkCreateClassLoader() { - throw new SecurityException(); - } - }; /** * java.net.URLClassLoader#URLClassLoader(java.net.URL[]) @@ -58,8 +44,8 @@ public class OldURLClassLoaderTest extends junit.framework.TestCase { public void test_Constructor$Ljava_net_URL() throws MalformedURLException { URL[] u = new URL[0]; ucl = new URLClassLoader(u); - assertTrue("Failed to set parent", ucl != null - && ucl.getParent() == URLClassLoader.getSystemClassLoader()); + assertTrue("Failed to set parent", + ucl.getParent() == URLClassLoader.getSystemClassLoader()); URL [] urls = {new URL("http://foo.com/foo"), @@ -87,7 +73,6 @@ public class OldURLClassLoaderTest extends junit.framework.TestCase { * java.net.URLClassLoader#findResources(java.lang.String) */ public void test_findResourcesLjava_lang_String() throws Exception { - Enumeration<URL> res = null; String[] resValues = { "This is a test resource file.", "This is a resource from a subdir"}; @@ -115,7 +100,7 @@ public class OldURLClassLoaderTest extends junit.framework.TestCase { urls[1] = new URL("file://" + subDir.getAbsolutePath() + "/"); ucl = new URLClassLoader(urls); - res = ucl.findResources("test0"); + Enumeration<URL> res = ucl.findResources("test0"); assertNotNull("Failed to locate resources", res); int i = 0; @@ -207,7 +192,7 @@ public class OldURLClassLoaderTest extends junit.framework.TestCase { } } - @SideEffect("Support_TestWebServer requires isolation.") + // SideEffect: Support_TestWebServer requires isolation. public void test_findResourceLjava_lang_String() throws Exception { File tmp = File.createTempFile("test", ".txt"); @@ -232,7 +217,7 @@ public class OldURLClassLoaderTest extends junit.framework.TestCase { /** * Regression for Harmony-2237 */ - @SideEffect("Support_TestWebServer requires isolation.") + // SideEffect: Support_TestWebServer requires isolation. public void test_findResource_String() throws Exception { File tempFile1 = File.createTempFile("textFile", ".txt"); tempFile1.createNewFile(); @@ -250,19 +235,17 @@ public class OldURLClassLoaderTest extends junit.framework.TestCase { "/tests/resources/hyts_patch.jar"); Support_Resources.copyLocalFileto(tempFile2, is); String tempPath2 = tempFile2.getAbsolutePath(); - String tempPath3 = "http://localhost:" + port + "/"; URLClassLoader urlLoader = getURLClassLoader(tempPath1, tempPath2); - assertNull("Found inexistant resource", - urlLoader.findResource("XXX")); + assertNull("Found nonexistent resource", urlLoader.findResource("XXX")); assertNotNull("Couldn't find resource from directory", urlLoader.findResource(tempFile1.getName())); - assertNotNull("Couldn't find resource from jar", - urlLoader.findResource("Blah.txt")); + assertNotNull("Couldn't find resource from jar", urlLoader.findResource("Blah.txt")); + + String tempPath3 = "http://localhost:" + port + "/"; urlLoader = getURLClassLoader(tempPath1, tempPath2, tempPath3); - assertNotNull("Couldn't find resource from web", - urlLoader.findResource("test1")); - assertNull("Found inexistant resource from web", - urlLoader.findResource("test3")); + assertNotNull("Couldn't find resource from web", urlLoader.findResource("test1")); + // Attempt to find a resource using a URL that will produce a 404. + assertNull("Found nonexistent resource from web", urlLoader.findResource("test9999")); } finally { server.close(); } diff --git a/luni/src/test/java/libcore/java/nio/BufferTest.java b/luni/src/test/java/libcore/java/nio/BufferTest.java index de4e0f1..613c6fa 100644 --- a/luni/src/test/java/libcore/java/nio/BufferTest.java +++ b/luni/src/test/java/libcore/java/nio/BufferTest.java @@ -731,7 +731,7 @@ public class BufferTest extends TestCase { Class<?> c = Class.forName("java.nio.DirectByteBuffer"); Constructor<?> ctor = c.getDeclaredConstructor(long.class, int.class); ctor.setAccessible(true); - ByteBuffer bb = (ByteBuffer) ctor.newInstance(1, 0); + ByteBuffer bb = (ByteBuffer) ctor.newInstance(0, 0); try { bb.array(); diff --git a/luni/src/test/java/libcore/java/nio/channels/OldSocketChannelTest.java b/luni/src/test/java/libcore/java/nio/channels/OldSocketChannelTest.java index 0d0c69f..f849c33 100644 --- a/luni/src/test/java/libcore/java/nio/channels/OldSocketChannelTest.java +++ b/luni/src/test/java/libcore/java/nio/channels/OldSocketChannelTest.java @@ -17,7 +17,6 @@ package libcore.java.nio.channels; -import dalvik.annotation.BrokenTest; import java.io.IOException; import java.net.InetSocketAddress; import java.net.ServerSocket; @@ -235,7 +234,7 @@ public class OldSocketChannelTest extends TestCase { return connected; } - @BrokenTest("Occasionally fail in CTS, but works in CoreTestRunner") + // Broken Test: Occasionally fail in CTS, but works in CoreTestRunner public void test_writeLjava_nio_ByteBuffer_Nonblocking_HugeData() throws IOException { // initialize write content ByteBuffer writeContent = ByteBuffer.allocate(CAPACITY_HUGE); diff --git a/luni/src/test/java/libcore/java/security/KeyStoreTest.java b/luni/src/test/java/libcore/java/security/KeyStoreTest.java index 04fd7af..9185ea8 100644 --- a/luni/src/test/java/libcore/java/security/KeyStoreTest.java +++ b/luni/src/test/java/libcore/java/security/KeyStoreTest.java @@ -56,20 +56,17 @@ import junit.framework.TestCase; public class KeyStoreTest extends TestCase { - private static HashMap<String, PrivateKeyEntry> sPrivateKeys + private static final HashMap<String, PrivateKeyEntry> sPrivateKeys = new HashMap<String, PrivateKeyEntry>(); - private static TestKeyStore TEST_KEY_STORE = new TestKeyStore.Builder() - .keyAlgorithms("RSA", "DH_RSA", "DSA", "EC") - .aliasPrefix("rsa-dsa-ec-dh") - .build(); + private static TestKeyStore sTestKeyStore; private static final String[] KEY_TYPES = new String[] { "DH", "DSA", "RSA", "EC" }; - private static PrivateKeyEntry PRIVATE_KEY_2; + private static PrivateKeyEntry sPrivateKey2; - private static SecretKey SECRET_KEY; - private static SecretKey SECRET_KEY_2; + private static SecretKey sSecretKey; + private static SecretKey sSecretKey2; private static final String ALIAS_PRIVATE = "private"; private static final String ALIAS_CERTIFICATE = "certificate"; @@ -101,16 +98,25 @@ public class KeyStoreTest extends TestCase { } private static PrivateKeyEntry getPrivateKey(String keyType) { + // Avoiding initialization of TestKeyStore in the static initializer: it breaks CTS tests + // by causing a NetworkOnMainThreadException. + if (sTestKeyStore == null) { + sTestKeyStore = new TestKeyStore.Builder() + .keyAlgorithms("RSA", "DH_RSA", "DSA", "EC") + .aliasPrefix("rsa-dsa-ec-dh") + .build(); + } + PrivateKeyEntry entry = sPrivateKeys.get(keyType); if (entry == null) { if ("RSA".equals(keyType)) { - entry = TEST_KEY_STORE.getPrivateKey("RSA", "RSA"); + entry = sTestKeyStore.getPrivateKey("RSA", "RSA"); } else if ("DH".equals(keyType)) { - entry = TEST_KEY_STORE.getPrivateKey("DH", "RSA"); + entry = sTestKeyStore.getPrivateKey("DH", "RSA"); } else if ("DSA".equals(keyType)) { - entry = TEST_KEY_STORE.getPrivateKey("DSA", "DSA"); + entry = sTestKeyStore.getPrivateKey("DSA", "DSA"); } else if ("EC".equals(keyType)) { - entry = TEST_KEY_STORE.getPrivateKey("EC", "EC"); + entry = sTestKeyStore.getPrivateKey("EC", "EC"); } else { throw new IllegalArgumentException("Unexpected key type " + keyType); } @@ -120,24 +126,24 @@ public class KeyStoreTest extends TestCase { } private static PrivateKeyEntry getPrivateKey2() { - if (PRIVATE_KEY_2 == null) { - PRIVATE_KEY_2 = TestKeyStore.getClientCertificate().getPrivateKey("RSA", "RSA"); + if (sPrivateKey2 == null) { + sPrivateKey2 = TestKeyStore.getClientCertificate().getPrivateKey("RSA", "RSA"); } - return PRIVATE_KEY_2; + return sPrivateKey2; } private static SecretKey getSecretKey() { - if (SECRET_KEY == null) { - SECRET_KEY = generateSecretKey(); + if (sSecretKey == null) { + sSecretKey = generateSecretKey(); } - return SECRET_KEY; + return sSecretKey; } private static SecretKey getSecretKey2() { - if (SECRET_KEY_2 == null) { - SECRET_KEY_2 = generateSecretKey(); + if (sSecretKey2 == null) { + sSecretKey2 = generateSecretKey(); } - return SECRET_KEY_2; + return sSecretKey2; } private static SecretKey generateSecretKey() { diff --git a/luni/src/test/java/libcore/java/security/OldDHTest.java b/luni/src/test/java/libcore/java/security/OldDHTest.java index 421d153..58d96ed 100644 --- a/luni/src/test/java/libcore/java/security/OldDHTest.java +++ b/luni/src/test/java/libcore/java/security/OldDHTest.java @@ -15,7 +15,6 @@ */ package libcore.java.security; -import dalvik.annotation.BrokenTest; import java.security.AlgorithmParameterGenerator; import java.security.AlgorithmParameters; import java.security.KeyPair; @@ -27,7 +26,7 @@ import junit.framework.TestCase; public class OldDHTest extends TestCase { - @BrokenTest("Suffers from DH slowness, disabling for now") + // BrokenTest Suffers from DH slowness, disabling for now public void testDHGen() throws Exception { KeyPairGenerator gen = null; try { diff --git a/luni/src/test/java/libcore/java/security/OldKeyPairGeneratorTestDH.java b/luni/src/test/java/libcore/java/security/OldKeyPairGeneratorTestDH.java index f39705b..9be282d 100644 --- a/luni/src/test/java/libcore/java/security/OldKeyPairGeneratorTestDH.java +++ b/luni/src/test/java/libcore/java/security/OldKeyPairGeneratorTestDH.java @@ -15,7 +15,6 @@ */ package libcore.java.security; -import dalvik.annotation.BrokenTest; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; @@ -24,7 +23,7 @@ import tests.security.KeyAgreementHelper; public class OldKeyPairGeneratorTestDH extends TestCase { - @BrokenTest("Takes ages due to DH computations. Disabling for now.") + // Broken Test: Takes ages due to DH computations. Disabling for now. public void testKeyPairGenerator() throws NoSuchAlgorithmException { KeyPairGenerator generator = KeyPairGenerator.getInstance("DH"); diff --git a/luni/src/test/java/libcore/java/security/cert/OldPKIXParametersTest.java b/luni/src/test/java/libcore/java/security/cert/OldPKIXParametersTest.java index d69e0e2..0832dae 100644 --- a/luni/src/test/java/libcore/java/security/cert/OldPKIXParametersTest.java +++ b/luni/src/test/java/libcore/java/security/cert/OldPKIXParametersTest.java @@ -22,7 +22,6 @@ package libcore.java.security.cert; -import dalvik.annotation.BrokenTest; import java.io.ByteArrayInputStream; import java.security.InvalidAlgorithmParameterException; import java.security.KeyStore; @@ -176,7 +175,7 @@ public class OldPKIXParametersTest extends TestCase { * @throws InvalidAlgorithmParameterException * @throws KeyStoreException */ - @BrokenTest("Fails in CTS environment, but passes in CoreTestRunner") + // Broken Test: Fails in CTS environment, but passes in CoreTestRunner public final void testPKIXParametersKeyStore04() throws Exception { diff --git a/luni/src/test/java/libcore/java/sql/OldResultSetTest.java b/luni/src/test/java/libcore/java/sql/OldResultSetTest.java index ea18db6..a1654cf 100644 --- a/luni/src/test/java/libcore/java/sql/OldResultSetTest.java +++ b/luni/src/test/java/libcore/java/sql/OldResultSetTest.java @@ -80,7 +80,7 @@ public final class OldResultSetTest extends OldSQLTest { try { target.close(); - target.beforeFirst(); + target.afterLast(); fail("Should get SQLException"); } catch (SQLException e) { } diff --git a/luni/src/test/java/libcore/java/text/DecimalFormatTest.java b/luni/src/test/java/libcore/java/text/DecimalFormatTest.java index 1e40f8a..c58f83a 100644 --- a/luni/src/test/java/libcore/java/text/DecimalFormatTest.java +++ b/luni/src/test/java/libcore/java/text/DecimalFormatTest.java @@ -21,7 +21,9 @@ import java.math.BigInteger; import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; +import java.text.FieldPosition; import java.text.NumberFormat; +import java.text.ParsePosition; import java.util.Currency; import java.util.Locale; @@ -197,4 +199,65 @@ public class DecimalFormatTest extends junit.framework.TestCase { df.setCurrency(Currency.getInstance("CHF")); df.setCurrency(Currency.getInstance("GBP")); } + + // Check we don't crash on null inputs. + public void testBug15081434() throws Exception { + DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance(Locale.US); + try { + df.parse(null); + fail(); + } catch (NullPointerException expected) { + } + + try { + df.applyLocalizedPattern(null); + fail(); + } catch (NullPointerException expected) { + } + + try { + df.applyPattern(null); + fail(); + } catch (NullPointerException expected) { + } + + try { + df.applyPattern(null); + fail(); + } catch (NullPointerException expected) { + } + + try { + df.format(null, new StringBuffer(), new FieldPosition(0)); + fail(); + } catch (IllegalArgumentException expected) { + } + + try { + df.parse(null, new ParsePosition(0)); + fail(); + } catch (NullPointerException expected) { + } + + // This just ignores null. + df.setDecimalFormatSymbols(null); + + try { + df.setCurrency(null); + fail(); + } catch (NullPointerException expected) { + } + + // These just ignore null. + df.setNegativePrefix(null); + df.setNegativeSuffix(null); + df.setPositivePrefix(null); + df.setPositiveSuffix(null); + + try { + df.setRoundingMode(null); + fail(); + } catch (NullPointerException expected) { + } + } } diff --git a/luni/src/test/java/libcore/java/text/OldNumberFormatTest.java b/luni/src/test/java/libcore/java/text/OldNumberFormatTest.java index 356d0a9..d281a91 100644 --- a/luni/src/test/java/libcore/java/text/OldNumberFormatTest.java +++ b/luni/src/test/java/libcore/java/text/OldNumberFormatTest.java @@ -16,7 +16,6 @@ */ package libcore.java.text; -import dalvik.annotation.BrokenTest; import java.text.ChoiceFormat; import java.text.DecimalFormat; import java.text.FieldPosition; @@ -733,7 +732,7 @@ public class OldNumberFormatTest extends TestCase { + " instead of Integer.MIN_VALUE", result == 0); } - @BrokenTest("Fails in CTS, passes in CoreTestRunner") + // Broken Test: Fails in CTS, passes in CoreTestRunner public void test_parseLjava_lang_String() { NumberFormat nf1 = NumberFormat.getInstance(); try { diff --git a/luni/src/test/java/libcore/java/util/CalendarTest.java b/luni/src/test/java/libcore/java/util/CalendarTest.java index dd44789..b0ba4dd 100644 --- a/luni/src/test/java/libcore/java/util/CalendarTest.java +++ b/luni/src/test/java/libcore/java/util/CalendarTest.java @@ -187,8 +187,10 @@ public class CalendarTest extends junit.framework.TestCase { + "10000000500000001000000200000000178"; Calendar calendar = new GregorianCalendar(1970, 1, 1, 0, 0, 0); calendar.setTimeZone(TimeZone.getTimeZone("GMT-08:00")); - // Starting from ICU4.8 release, the default minimalDaysInFirstWeek changed from 4 to 1. + // Calendar fields firstDayOfWeek and minimalDaysInFirstWeek are are sensitive to the Locale + // and ICU data. Specifying the values here makes the serialized form stable. calendar.setMinimalDaysInFirstWeek(4); + calendar.setFirstDayOfWeek(Calendar.SUNDAY); new SerializationTester<Calendar>(calendar, s).test(); } diff --git a/luni/src/test/java/libcore/java/util/prefs/OldAbstractPreferencesTest.java b/luni/src/test/java/libcore/java/util/prefs/OldAbstractPreferencesTest.java index 6384059..693f0c2 100644 --- a/luni/src/test/java/libcore/java/util/prefs/OldAbstractPreferencesTest.java +++ b/luni/src/test/java/libcore/java/util/prefs/OldAbstractPreferencesTest.java @@ -28,6 +28,8 @@ import java.util.prefs.NodeChangeListener; import java.util.prefs.PreferenceChangeEvent; import java.util.prefs.PreferenceChangeListener; import java.util.prefs.Preferences; +import java.util.prefs.PreferencesFactory; + import junit.framework.TestCase; import libcore.io.IoUtils; @@ -35,6 +37,8 @@ public final class OldAbstractPreferencesTest extends TestCase { static final String nodeName = "mock"; + private PreferencesFactory defaultFactory; + AbstractPreferences pref; AbstractPreferences root; AbstractPreferences parent = null; @@ -42,9 +46,9 @@ public final class OldAbstractPreferencesTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - File rootDir = IoUtils.createTemporaryDirectory("OldAbstractPreferencesTest"); - Preferences.setPreferencesFactory( - new PreferencesTest.TestPreferencesFactory(rootDir.getAbsolutePath())); + File tmpDir = IoUtils.createTemporaryDirectory("OldAbstractPreferencesTest"); + defaultFactory = Preferences.setPreferencesFactory( + new PreferencesTest.TestPreferencesFactory(tmpDir.getAbsolutePath())); root = (AbstractPreferences) Preferences.userRoot(); assertEquals(0, root.childrenNames().length); @@ -54,6 +58,12 @@ public final class OldAbstractPreferencesTest extends TestCase { pref = (AbstractPreferences) parent.node(nodeName); } + @Override + public void tearDown() throws Exception { + Preferences.setPreferencesFactory(defaultFactory); + super.tearDown(); + } + public void testToString() { assertTrue(pref.toString().contains(nodeName)); } diff --git a/luni/src/test/java/libcore/java/util/prefs/OldFilePreferencesImplTest.java b/luni/src/test/java/libcore/java/util/prefs/OldFilePreferencesImplTest.java index 93ba485..ea8cb39 100644 --- a/luni/src/test/java/libcore/java/util/prefs/OldFilePreferencesImplTest.java +++ b/luni/src/test/java/libcore/java/util/prefs/OldFilePreferencesImplTest.java @@ -16,11 +16,32 @@ package libcore.java.util.prefs; +import java.io.File; import java.util.prefs.Preferences; +import java.util.prefs.PreferencesFactory; + import junit.framework.TestCase; +import libcore.io.IoUtils; + public final class OldFilePreferencesImplTest extends TestCase { + private PreferencesFactory defaultFactory; + + @Override + public void setUp() throws Exception { + super.setUp(); + File tmpDir = IoUtils.createTemporaryDirectory("OldFilePreferencesImplTest"); + defaultFactory = Preferences.setPreferencesFactory( + new PreferencesTest.TestPreferencesFactory(tmpDir.getAbsolutePath())); + } + + @Override + public void tearDown() throws Exception { + Preferences.setPreferencesFactory(defaultFactory); + super.tearDown(); + } + // AndroidOnly: the RI can't remove nodes created in the system root. public void testSystemChildNodes() throws Exception { Preferences sroot = Preferences.systemRoot().node("test"); diff --git a/luni/src/test/java/libcore/java/util/prefs/OldNodeChangeEventTest.java b/luni/src/test/java/libcore/java/util/prefs/OldNodeChangeEventTest.java index f2d483e..7ba1dfe 100644 --- a/luni/src/test/java/libcore/java/util/prefs/OldNodeChangeEventTest.java +++ b/luni/src/test/java/libcore/java/util/prefs/OldNodeChangeEventTest.java @@ -16,15 +16,36 @@ package libcore.java.util.prefs; +import java.io.File; import java.util.prefs.AbstractPreferences; import java.util.prefs.BackingStoreException; import java.util.prefs.NodeChangeEvent; import java.util.prefs.NodeChangeListener; import java.util.prefs.Preferences; +import java.util.prefs.PreferencesFactory; + import junit.framework.TestCase; +import libcore.io.IoUtils; + public final class OldNodeChangeEventTest extends TestCase { + private PreferencesFactory defaultFactory; + + @Override + public void setUp() throws Exception { + super.setUp(); + File tmpDir = IoUtils.createTemporaryDirectory("OldNodeChangeEventTest"); + defaultFactory = Preferences.setPreferencesFactory( + new PreferencesTest.TestPreferencesFactory(tmpDir.getAbsolutePath())); + } + + @Override + public void tearDown() throws Exception { + Preferences.setPreferencesFactory(defaultFactory); + super.tearDown(); + } + public void testGetChild() throws BackingStoreException { AbstractPreferences parent = (AbstractPreferences) Preferences .userNodeForPackage(Preferences.class); diff --git a/luni/src/test/java/libcore/java/util/prefs/OldPreferenceChangeEventTest.java b/luni/src/test/java/libcore/java/util/prefs/OldPreferenceChangeEventTest.java index acdbd69..d77a11c 100644 --- a/luni/src/test/java/libcore/java/util/prefs/OldPreferenceChangeEventTest.java +++ b/luni/src/test/java/libcore/java/util/prefs/OldPreferenceChangeEventTest.java @@ -16,14 +16,35 @@ package libcore.java.util.prefs; +import java.io.File; import java.util.prefs.AbstractPreferences; import java.util.prefs.PreferenceChangeEvent; import java.util.prefs.PreferenceChangeListener; import java.util.prefs.Preferences; +import java.util.prefs.PreferencesFactory; + import junit.framework.TestCase; +import libcore.io.IoUtils; + public final class OldPreferenceChangeEventTest extends TestCase { + private PreferencesFactory defaultFactory; + + @Override + public void setUp() throws Exception { + super.setUp(); + File tmpDir = IoUtils.createTemporaryDirectory("OldPreferenceChangeEventTest"); + defaultFactory = Preferences.setPreferencesFactory( + new PreferencesTest.TestPreferencesFactory(tmpDir.getAbsolutePath())); + } + + @Override + public void tearDown() throws Exception { + Preferences.setPreferencesFactory(defaultFactory); + super.tearDown(); + } + public void testGetKey() { AbstractPreferences parent = (AbstractPreferences) Preferences .userNodeForPackage(Preferences.class); diff --git a/luni/src/test/java/libcore/javax/crypto/spec/AlgorithmParameterGeneratorTestDH.java b/luni/src/test/java/libcore/javax/crypto/spec/AlgorithmParameterGeneratorTestDH.java index 578ee6b..e64fb9e 100644 --- a/luni/src/test/java/libcore/javax/crypto/spec/AlgorithmParameterGeneratorTestDH.java +++ b/luni/src/test/java/libcore/javax/crypto/spec/AlgorithmParameterGeneratorTestDH.java @@ -26,7 +26,7 @@ public class AlgorithmParameterGeneratorTestDH extends super("DH", new AlgorithmParameterKeyAgreementHelper("DH")); } - @BrokenTest("Suffers from DH slowness, disabling for now") + // Broken Test: Suffers from DH slowness, disabling for now public void testAlgorithmParameterGenerator() { super.testAlgorithmParameterGenerator(); } diff --git a/luni/src/test/java/libcore/javax/crypto/spec/AlgorithmParametersTestDH.java b/luni/src/test/java/libcore/javax/crypto/spec/AlgorithmParametersTestDH.java index 165daa1..897e62b 100644 --- a/luni/src/test/java/libcore/javax/crypto/spec/AlgorithmParametersTestDH.java +++ b/luni/src/test/java/libcore/javax/crypto/spec/AlgorithmParametersTestDH.java @@ -15,7 +15,6 @@ */ package libcore.javax.crypto.spec; -import dalvik.annotation.BrokenTest; import java.math.BigInteger; import javax.crypto.spec.DHParameterSpec; import tests.security.AlgorithmParameterKeyAgreementHelper; @@ -61,7 +60,7 @@ public class AlgorithmParametersTestDH extends AlgorithmParametersTest { } - @BrokenTest("Suffers from DH slowness, disabling for now") + // Broken Test: Suffers from DH slowness, disabling for now public void testAlgorithmParameters() { super.testAlgorithmParameters(); } diff --git a/luni/src/test/java/libcore/javax/crypto/spec/KeyPairGeneratorTestDH.java b/luni/src/test/java/libcore/javax/crypto/spec/KeyPairGeneratorTestDH.java index c4322ff..8e500e1 100644 --- a/luni/src/test/java/libcore/javax/crypto/spec/KeyPairGeneratorTestDH.java +++ b/luni/src/test/java/libcore/javax/crypto/spec/KeyPairGeneratorTestDH.java @@ -15,7 +15,6 @@ */ package libcore.javax.crypto.spec; -import dalvik.annotation.BrokenTest; import java.security.NoSuchAlgorithmException; import tests.security.KeyAgreementHelper; import tests.security.KeyPairGeneratorTest; @@ -26,7 +25,7 @@ public class KeyPairGeneratorTestDH extends KeyPairGeneratorTest { super("DH", new KeyAgreementHelper("DH")); } - @BrokenTest("Takes ages due to DH computations. Disabling for now.") + // Broken Test: Takes ages due to DH computations. Disabling for now. public void testKeyPairGenerator() throws NoSuchAlgorithmException { super.testKeyPairGenerator(); } diff --git a/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java b/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java index f617adb..87b2913 100644 --- a/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java +++ b/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java @@ -17,8 +17,6 @@ package org.apache.harmony.crypto.tests.javax.crypto; -import dalvik.annotation.SideEffect; - import java.math.BigInteger; import java.security.AlgorithmParameters; import java.security.InvalidAlgorithmParameterException; @@ -186,7 +184,7 @@ public class ExemptionMechanismTest extends TestCase { } } - @SideEffect("Causes OutOfMemoryError to test finalization") + // Side Effect: Causes OutOfMemoryError to test finalization public void test_finalize () { Mock_ExemptionMechanism mem = new Mock_ExemptionMechanism(null, null, "Name"); assertNotNull(mem); diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java index 5d8c621..290ae9a 100644 --- a/luni/src/test/java/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java +++ b/luni/src/test/java/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java @@ -17,8 +17,6 @@ package org.apache.harmony.luni.tests.internal.net.www.protocol.http; -import dalvik.annotation.SideEffect; - import java.io.IOException; import java.net.Authenticator; import java.net.HttpURLConnection; @@ -270,7 +268,7 @@ public class HttpURLConnectionTest extends TestCase { ProxySelector.setDefault(defPS); } } - @SideEffect("Suffers from side effect of other, currently unknown test") + // SideEffect: Suffers from side effect of other, currently unknown test public void testProxyAuthorization() throws Exception { // Set up test Authenticator Authenticator.setDefault(new Authenticator() { diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerFactoryTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerFactoryTest.java index 74b2276..f3d5518 100644 --- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerFactoryTest.java +++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/ContentHandlerFactoryTest.java @@ -1,7 +1,5 @@ package org.apache.harmony.luni.tests.java.net; -import dalvik.annotation.SideEffect; - import junit.framework.TestCase; import tests.support.Support_Configuration; @@ -24,9 +22,9 @@ public class ContentHandlerFactoryTest extends TestCase { boolean isGetContentCalled = false; boolean isCreateContentHandlerCalled = false; - @SideEffect("This test affects tests that are run after this one." + - " The reason are side effects due to caching in URLConnection." + - " Maybe this test needs to be run in isolation.") + // SideEffect: This test affects tests that are run after this one. + // The reason are side effects due to caching in URLConnection. + // Maybe this test needs to be run in isolation. public void test_createContentHandler() throws IOException { TestContentHandlerFactory factory = new TestContentHandlerFactory(); diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java index e2a3a47..d3da174 100644 --- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java +++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java @@ -16,7 +16,6 @@ package org.apache.harmony.luni.tests.java.net; -import dalvik.annotation.BrokenTest; import junit.framework.TestCase; import tests.support.Support_Configuration; import tests.support.Support_TestWebData; @@ -442,7 +441,7 @@ public class URLConnectionTest extends TestCase { * @throws IOException * {@link java.net.URLConnection#getContentEncoding()} */ - @BrokenTest("Fails in CTS, passes in CoreTestRunner") + // broken test - Fails in CTS, passes in CoreTestRunner public void test_getContentEncoding() throws IOException { // faulty setup try { |