args = {}
)
@KnownFailure("IOException not thrown when using getNextJarEntry() after close().")
- // This is the original test_getNextJarEntry including the failing section.
public void test_getNextJarEntry_Ex() throws Exception {
final Set<String> desired = new HashSet<String>(Arrays
.asList(new String[] {
import tests.support.resource.Support_Resources;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
assertTrue(packFile2.length()>packFile3.length());
}
-/*
- * java.beans.* not implemented yet on android platform
- * class MyPCL implements PropertyChangeListener {
+ class MyPCL implements PropertyChangeListener {
boolean flag = false;
public boolean isCalled() {
flag = true;
}
}
-@TestInfo(
- level = TestLevel.COMPLETE,
-
- targets = {
- @TestTarget(
- methodName = "addPropertyChangeListener",
- methodArgs = {java.beans.PropertyChangeListener.class}
- )
- })
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "addPropertyChangeListener",
+ args = {java.beans.PropertyChangeListener.class}
+ )
+ @KnownFailure("No Implementation in Android!")
public void testAddPropertyChangeListener() {
MyPCL pcl = new MyPCL();
packer.addPropertyChangeListener(pcl);
assertTrue(pcl.isCalled());
}
-@TestInfo(
- level = TestLevel.COMPLETE,
-
- targets = {
- @TestTarget(
- methodName = "removePropertyChangeListener",
- methodArgs = {java.beans.PropertyChangeListener.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "removePropertyChangeListener",
+ args = {java.beans.PropertyChangeListener.class}
+ )
+ @KnownFailure("No Implementation in Android!")
public void testRemovePropertyChangeListener() {
MyPCL pcl = new MyPCL();
packer.addPropertyChangeListener(pcl);
properties.put(Packer.EFFORT, "7");
assertFalse(pcl.isCalled());
}
-*/
+
@Override
protected void setUp() {
packer = Pack200.newPacker();
import tests.support.resource.Support_Resources;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
assertEquals(jarEntries, new JarFile(jarFile2).size());
assertEquals(jarEntries, new JarFile(jarFile3).size());
}
-/*
- * java.beans.* not implemented yet on android platform
- * class MyPCL implements PropertyChangeListener {
+
+ class MyPCL implements PropertyChangeListener {
boolean flag = false;
public boolean isCalled() {
}
}
-@TestInfo(
- level = TestLevel.COMPLETE,
-
- targets = {
- @TestTarget(
- methodName = "addPropertyChangeListener",
- methodArgs = {java.beans.PropertyChangeListener.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "addPropertyChangeListener",
+ args = {java.beans.PropertyChangeListener.class}
+ )
+ @KnownFailure("No Implementation in Android!")
public void testAddPropertyChangeListener() {
MyPCL pcl = new MyPCL();
unpacker.addPropertyChangeListener(pcl);
assertTrue(pcl.isCalled());
}
-@TestInfo(
- level = TestLevel.COMPLETE,
-
- targets = {
- @TestTarget(
- methodName = "removePropertyChangeListener",
- methodArgs = {java.beans.PropertyChangeListener.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "removePropertyChangeListener",
+ args = {java.beans.PropertyChangeListener.class}
+ )
+ @KnownFailure("No Implementation in Android!")
public void testRemovePropertyChangeListener() {
MyPCL pcl = new MyPCL();
unpacker.addPropertyChangeListener(pcl);
properties.put(Unpacker.PROGRESS, "7");
assertFalse(pcl.isCalled());
}
-*/
+
@Override
protected void setUp() {
unpacker = Pack200.newUnpacker();
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
-import java.util.zip.ZipException;
@TestTargetClass(InflaterInputStream.class)
public class InflaterInputStreamTest extends TestCase {
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.AndroidOnly;
import dalvik.annotation.KnownFailure;
+import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.FilePermission;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@TestTargetClass(ZipFile.class)
public class ZipFileTest extends junit.framework.TestCase {
- // BEGIN android-added
public byte[] getAllBytesFromStream(InputStream is) throws IOException {
ByteArrayOutputStream bs = new ByteArrayOutputStream();
- byte[] buf = new byte[666];
+ byte[] buf = new byte[512];
int iRead;
int off;
while (is.available() > 0) {
return bs.toByteArray();
}
- // END android-added
-
// the file hyts_zipFile.zip in setup must be included as a resource
private String tempFileName;
public void checkPermission(Permission perm) {
- if (perm.getActions().equals(forbidenPermissionAction)) {
+ // only check if it's a FilePermission because Locale checks
+ // for a PropertyPermission with action"read" to get system props.
+ if (perm instanceof FilePermission
+ && perm.getActions().equals(forbidenPermissionAction)) {
throw new SecurityException();
}
}
method = "getEntry",
args = {java.lang.String.class}
)
- @AndroidOnly("God knows why!")
+ @BrokenTest("Needs investigation. AndroidOnly?")
public void test_getEntryLjava_lang_String_AndroidOnly() throws IOException {
java.util.zip.ZipEntry zentry = zfile.getEntry("File1.txt");
assertNotNull("Could not obtain ZipEntry", zentry);
method = "getEntry",
args = {java.lang.String.class}
)
- @KnownFailure("Android does not throw IllegalStateException when using getEntry() after close().")
+ @KnownFailure("Android does not throw IllegalStateException when using "
+ + "getEntry() after close().")
public void test_getEntryLjava_lang_String_Ex() throws IOException {
java.util.zip.ZipEntry zentry = zfile.getEntry("File1.txt");
assertNotNull("Could not obtain ZipEntry", zentry);
method = "size",
args = {}
)
- @KnownFailure("IllegalStateException not thrown when using ZipFile.size() after close().")
+ @KnownFailure("IllegalStateException not thrown when using ZipFile.size() "
+ + "after close().")
public void test_size() throws IOException {
assertEquals(6, zfile.size());
zfile.close();
@Override
protected void setUp() {
try {
- // BEGIN android-changed
// Create a local copy of the file since some tests want to alter
// information.
tempFileName = System.getProperty("java.io.tmpdir");
f.delete();
InputStream is = Support_Resources.getStream("hyts_ZipFile.zip");
FileOutputStream fos = new FileOutputStream(f);
- // END android-changed
byte[] rbuf = getAllBytesFromStream(is);
fos.write(rbuf, 0, rbuf.length);
is.close();
method = "close",
args = {}
)
- @KnownFailure("The behaviour is different from RI, but not neccessarily wrong.")
+ @KnownFailure("after an exception has been thrown wile reading a "
+ + "call to close also throws an exception.")
public void test_closeAfterException() throws Exception {
File resources = Support_Resources.createTempFolder();
Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
// expected
}
- zis1.close(); // Android throws exception here, but RI only when getNextEntry/read/skip are called.
+ zis1.close();
try {
zis1.getNextEntry();
fail("IOException expected");
method = "available",
args = {}
)
- @KnownFailure("Needs investigation!!!")
public void test_available() throws Exception {
File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
- File fl = new File(resources, "Broken_manifest.jar");
+ Support_Resources.copyFile(resources, null, "hyts_ZipFile.zip");
+ File fl = new File(resources, "hyts_ZipFile.zip");
FileInputStream fis = new FileInputStream(fl);
ZipInputStream zis1 = new ZipInputStream(fis);
+ ZipEntry entry = zis1.getNextEntry();
+ assertNotNull("No entry in the archive.", entry);
+ long entrySize = entry.getSize();
+ assertTrue("Entry size was < 1", entrySize > 0);
int i = 0;
-System.out.println(fl.length());
- for (i = 0; i < fl.length(); i++) {
-//System.out.println(i);
+ for (i = 0; i < entrySize; i++) {
zis1.skip(1);
-//System.out.println("Skipped 1");
-int avail = zis1.available();
-//System.out.println(avail);
- if (zis1.available() == 0) break; // RI breaks at i = 0 already; Android loops till the end!
-//System.out.println("Looping...");
+ if (zis1.available() == 0) break;
}
- if (i == fl.length()) {
- fail("ZipInputStream.available or ZipInputStream.skip does not working properly");
+ if (i != entrySize) {
+ fail("ZipInputStream.available or ZipInputStream.skip does not " +
+ "working properly. Only skipped " + i +
+ " bytes instead of " + entrySize);
}
- assertTrue(zis1.available() == 0);
zis1.skip(1);
+ assertTrue(zis1.available() == 0);
+ zis1.closeEntry();
assertFalse(zis.available() == 0);
zis1.close();
try {
+++ /dev/null
-package com.ibm.icu4jni.math;
-
-public class BigDecimal extends Number {
-
- @Override
- public double doubleValue() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public float floatValue() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public int intValue() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public long longValue() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public String toString() {
- return "";
- }
-
-}
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream;
import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
LogManager manager = LogManager.getLogManager();
- // MockPropertyChangeListener listener;
+ MockPropertyChangeListener listener;
Properties props;
/*
* @see TestCase#setUp()
*/
+ @Override
protected void setUp() throws Exception {
super.setUp();
mockManager = new MockLogManager();
/*
* @see TestCase#tearDown()
*/
+ @Override
protected void tearDown() throws Exception {
super.tearDown();
handler = null;
Enumeration<String> enumar = mockManager.getLoggerNames();
int i = 0;
while (enumar.hasMoreElements()) {
- String name = (String)enumar.nextElement();
+ String name = enumar.nextElement();
i++;
assertEquals(FOO, name);
}
args = {java.lang.String.class}
)
})
- public void testAddGetLogger_addRoot() throws IOException {
+ public void testAddGetLogger_addRoot() {
Logger foo = new MockLogger(FOO, null);
Logger fooChild = new MockLogger(FOO + ".child", null);
Logger other = new MockLogger("other", null);
Enumeration<String> enumar = mockManager.getLoggerNames();
int i = 0;
while (enumar.hasMoreElements()) {
- String name = (String)enumar.nextElement();
+ String name = enumar.nextElement();
i++;
assertEquals("name logger should be equal to foreseen name", FOO, name);
}
notes = "Verifies SecurityException.",
method = "getLogManager",
args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Verifies SecurityException.",
+ method = "addPropertyChangeListener",
+ args = {java.beans.PropertyChangeListener.class}
)
})
public void testLoggingPermission() throws IOException {
fail("should throw SecurityException");
} catch (SecurityException e) {
}
- // try {
- // mockManager
- // .addPropertyChangeListener(new MockPropertyChangeListener());
- // fail("should throw SecurityException");
- // } catch (SecurityException e) {
- // }
- // try {
- // mockManager.addPropertyChangeListener(null);
- // fail("should throw NPE");
- // } catch (NullPointerException e) {
- // }
- // try {
- // mockManager.removePropertyChangeListener(null);
- // fail("should throw SecurityException");
- // } catch (SecurityException e) {
- // }
+ try {
+ mockManager
+ .addPropertyChangeListener(new MockPropertyChangeListener());
+ fail("should throw SecurityException");
+ } catch (SecurityException e) {
+ }
+ try {
+ mockManager.addPropertyChangeListener(null);
+ fail("should throw NPE");
+ } catch (NullPointerException e) {
+ }
+ try {
+ mockManager.removePropertyChangeListener(null);
+ fail("should throw SecurityException");
+ } catch (SecurityException e) {
+ }
try {
mockManager.reset();
fail("should throw SecurityException");
manager.reset();
}
- // public void testAddRemovePropertyChangeListener() throws Exception {
- // MockPropertyChangeListener listener1 = new MockPropertyChangeListener();
- // MockPropertyChangeListener listener2 = new MockPropertyChangeListener();
- // // add same listener1 two times
- // mockManager.addPropertyChangeListener(listener1);
- // mockManager.addPropertyChangeListener(listener1);
- // mockManager.addPropertyChangeListener(listener2);
- //
- // assertNull(listener1.getEvent());
- // assertNull(listener2.getEvent());
- // mockManager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
- // // if (!hasConfigClass) {
- // assertNotNull(listener1.getEvent());
- // assertNotNull(listener2.getEvent());
- // // }
- //
- // listener1.reset();
- // listener2.reset();
- //
- // // remove listener1, no effect
- // mockManager.removePropertyChangeListener(listener1);
- // mockManager.readConfiguration(EnvironmentHelper
- // .PropertiesToInputStream(props));
- // assertNotNull(listener1.getEvent());
- // assertNotNull(listener2.getEvent());
- // listener1.reset();
- // listener2.reset();
- //
- // // remove listener1 again and it works
- // mockManager.removePropertyChangeListener(listener1);
- // mockManager.readConfiguration(EnvironmentHelper
- // .PropertiesToInputStream(props));
- // assertNull(listener1.getEvent());
- // assertNotNull(listener2.getEvent());
- // listener2.reset();
- //
- // // reset don't produce event
- // mockManager.reset();
- // assertNull(listener2.getEvent());
- //
- // mockManager.removePropertyChangeListener(listener2);
- // mockManager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
- // assertNull(listener1.getEvent());
- // assertNull(listener2.getEvent());
- // }
- //
- // public void testAddRemovePropertyChangeListener_null() {
- // // seems nothing happened
- // try{
- // mockManager.addPropertyChangeListener(null);
- // fail("Should throw NPE");
- // }catch(NullPointerException e){
- // }
- // mockManager.removePropertyChangeListener(null);
- // }
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "addPropertyChangeListener",
+ args = {java.beans.PropertyChangeListener.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "removePropertyChangeListener",
+ args = {java.beans.PropertyChangeListener.class}
+ )
+ })
+ public void testAddRemovePropertyChangeListener() throws Exception {
+ MockPropertyChangeListener listener1 = new MockPropertyChangeListener();
+ MockPropertyChangeListener listener2 = new MockPropertyChangeListener();
+ // add same listener1 two times
+ mockManager.addPropertyChangeListener(listener1);
+ mockManager.addPropertyChangeListener(listener1);
+ mockManager.addPropertyChangeListener(listener2);
+
+ assertNull(listener1.getEvent());
+ assertNull(listener2.getEvent());
+ mockManager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
+ // if (!hasConfigClass) {
+ assertNotNull(listener1.getEvent());
+ assertNotNull(listener2.getEvent());
+ // }
+
+ listener1.reset();
+ listener2.reset();
+
+ // remove listener1, no effect
+ mockManager.removePropertyChangeListener(listener1);
+ mockManager.readConfiguration(EnvironmentHelper
+ .PropertiesToInputStream(props));
+ assertNotNull(listener1.getEvent());
+ assertNotNull(listener2.getEvent());
+ listener1.reset();
+ listener2.reset();
+
+ // remove listener1 again and it works
+ mockManager.removePropertyChangeListener(listener1);
+ mockManager.readConfiguration(EnvironmentHelper
+ .PropertiesToInputStream(props));
+ assertNull(listener1.getEvent());
+ assertNotNull(listener2.getEvent());
+ listener2.reset();
+
+ // reset don't produce event
+ mockManager.reset();
+ assertNull(listener2.getEvent());
+
+ mockManager.removePropertyChangeListener(listener2);
+ mockManager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
+ assertNull(listener1.getEvent());
+ assertNull(listener2.getEvent());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "addPropertyChangeListener",
+ args = {java.beans.PropertyChangeListener.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "removePropertyChangeListener",
+ args = {java.beans.PropertyChangeListener.class}
+ )
+ })
+ public void testAddRemovePropertyChangeListener_null() {
+ // seems nothing happened
+ try{
+ mockManager.addPropertyChangeListener(null);
+ fail("Should throw NPE");
+ }catch(NullPointerException e){
+ }
+ mockManager.removePropertyChangeListener(null);
+ }
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
}
}
- // public static class MockPropertyChangeListener implements
- // IPropertyChangeListener {
- //
- // IPropertyChangeEvent event = null;
- //
- // public void propertyChange(IPropertyChangeEvent event) {
- // this.event = event;
- // }
- //
- // public IPropertyChangeEvent getEvent() {
- // return event;
- // }
- //
- // public void reset() {
- // event = null;
- // }
- //
- // }
+ public static class MockPropertyChangeListener implements
+ PropertyChangeListener {
+
+ PropertyChangeEvent event = null;
+
+ public void propertyChange(PropertyChangeEvent event) {
+ this.event = event;
+ }
+
+ public PropertyChangeEvent getEvent() {
+ return event;
+ }
+
+ public void reset() {
+ event = null;
+ }
+
+ }
public static class MockSecurityManagerLogPermission extends SecurityManager {
package org.apache.harmony.logging.tests.java.util.logging;
-import dalvik.annotation.AndroidOnly;
import dalvik.annotation.BrokenTest;
import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargets;
*
* @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)
dest += count1;
cursor1 += count1;
len1 -= count1;
- if (len1 == 1)
+ if (len1 <= 1) // len1 == 1 || len1 == 0
break outer;
}
a[dest++] = a[cursor2++];
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;
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)
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;
dest += count1;
cursor1 += count1;
len1 -= count1;
- if (len1 == 1)
+ if (len1 <= 1) // len1 == 1 || len1 == 0
break outer;
}
a[dest++] = a[cursor2++];
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;
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--];
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;
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";
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();
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"));
}
/**
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;
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",
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,
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"));
method = "hashCode",
args = {}
)
- @KnownFailure("Package information missing on android")
public void test_hashCode() {
Package p1 = Package.getPackage("java.lang");
if (p1 != null) {
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[] {
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;
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();
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()
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()
package org.apache.harmony.luni.tests.java.net;
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
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;
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();
// default useCaches is true
assertTrue(uc.getUseCaches());
uc.setDoInput(true);
- uc.connect();
// make sure ResponseCache.get/put is called
isGetCalled = false;
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;
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(
*/
package org.apache.harmony.luni.tests.java.net;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
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
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);
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))
f2.delete();
f3.delete();
f4.delete();
+ System.setProperty("user.dir", oldUserDir);
}
/**
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);
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 {
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;
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();
}
}
- @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());
- }
- }
}
--- /dev/null
+/*
+ * 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());
+ }
+ }
+}
*/
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;
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)
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)
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)
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)
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;
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)
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)
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)
*/
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;
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)
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)
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)
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)
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)
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)
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)
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;
method = "!Serialization",
args = {}
)
- public void _test_writeObject_Calendar() {
+ public void test_writeObject_Calendar() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.util.Calendar)
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)
method = "!Serialization",
args = {}
)
- public void _test_writeObject_Proxy() {
+ public void test_writeObject_Proxy() {
// Test for method void
// java.io.ObjectOutputStream.writeObject(java.security.GuardedObject)
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)
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)
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" };
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 {
import dalvik.annotation.TestTargetNew;
import java.io.IOException;
-import java.io.InputStream;
import java.net.CookieHandler;
import java.net.MalformedURLException;
import java.net.NetPermission;
import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
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;
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();
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;
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 {
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;
import java.net.URL;
import java.net.URLConnection;
import java.security.Permission;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
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://" +
package tests.api.java.net;
+import org.apache.harmony.testframework.serialization.SerializationTest;
+
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
}
/**
+ * @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.
*/
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;
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
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());
}
/**
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]);
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++) {
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++) {
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++) {
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);
}
}
}
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());
}
/**
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;
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);
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 {
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");
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;
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");
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;
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);
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 {
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");
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;
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");
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;
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);
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);
};
- 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$
{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$
{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$
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);
.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());
}
};
- 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$
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$
.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);
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$
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;
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)
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);
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
assertEquals(4, minimalDaysInFirstWeek);
g = new GregorianCalendar(TimeZone.getTimeZone("Paris/France"),
- new Locale("fr"));
+ new Locale("fr", "FR"));
minimalDaysInFirstWeek = g.getMinimalDaysInFirstWeek();
assertEquals(4, minimalDaysInFirstWeek);
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();
package tests.api.java.util;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
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);
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()
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());
--- /dev/null
+Cache test
\ No newline at end of file
method = "add",
args = {java.math.BigDecimal.class, java.math.MathContext.class}
)
- @KnownFailure("Fix in BigDecimal.inplaceRound")
public void testAddMathContextNonTrivial() {
MathContext mc;
BigDecimal a, b, res;
method = "subtract",
args = {java.math.BigDecimal.class, java.math.MathContext.class}
)
- @KnownFailure("Fix in BigDecimal.inplaceRound")
public void testSubtractMathContextNonTrivial() {
MathContext mc;
BigDecimal a, b, res;
method = "multiply",
args = {java.math.BigDecimal.class, java.math.MathContext.class}
)
- @KnownFailure("Fix in BigDecimal.inplaceRound")
public void testMultiplyMathContextNonTrivial() {
MathContext mc;
BigDecimal a, b, res;
method = "pow",
args = {int.class, java.math.MathContext.class}
)
- @KnownFailure("Fix in BigDecimal.inplaceRound")
public void testPowMathContextNonTrivial() {
MathContext mc;
BigDecimal a, b, res;
method = "divide",
args = {java.math.BigDecimal.class, int.class}
)
- @KnownFailure("Fix in BigDecimal.inplaceRound")
public void testDivideINonTrivial() {
MathContext mc;
BigDecimal a, b, res;
method = "divide",
args = {java.math.BigDecimal.class, int.class, java.math.RoundingMode.class}
)
- @KnownFailure("Fix in BigDecimal.inplaceRound IS INSUFFICIENT!!!")
+ @KnownFailure("Has a rounding problem. seems like the precision is"
+ + " 1 too small and cuts off the last digit. also this test might"
+ + "not be correct. The name implies that scale should be used.")
public void testDivideScaleRoundingModeNonTrivial() {
MathContext mc;
BigDecimal a, b, res;
method = "divide",
args = {java.math.BigDecimal.class, java.math.MathContext.class}
)
- @KnownFailure("Fix in BigDecimal.inplaceRound IS INSUFFICIENT!!!")
+ @KnownFailure("The same test and the same problem like "
+ + "testDivideScaleRoundingModeNonTrivial")
public void testDivideMathContextNonTrivial() {
MathContext mc;
BigDecimal a, b, res;
method = "divideToIntegralValue",
args = {java.math.BigDecimal.class, java.math.MathContext.class}
)
- @KnownFailure("Fix in BigDecimal.inplaceRound")
public void testDivideToIntegralValueMathContextNonTrivial() {
MathContext mc;
BigDecimal a, b, res;
method = "divideAndRemainder",
args = {java.math.BigDecimal.class, java.math.MathContext.class}
)
- @KnownFailure("WHY ISN'T THE LAST VALUE ROUNDED?")
public void testDivideAndRemainderMathContextNonTrivial() {
MathContext mc;
BigDecimal a, b, res[];
method = "remainder",
args = {java.math.BigDecimal.class, java.math.MathContext.class}
)
- @KnownFailure("WHY ISN'T THE LAST VALUE ROUNDED?")
public void testRemainderMathContextNonTrivial() {
MathContext mc;
BigDecimal a, b, res;
package org.apache.harmony.math.tests.java.math;
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
method = "abs",
args = {java.math.MathContext.class}
)
- @KnownFailure("Fix in BigDecimal.abs")
public void testAbsMathContextNeg() {
String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
BigDecimal aNumber = new BigDecimal(a);
method = "negate",
args = {java.math.MathContext.class}
)
- @KnownFailure("Fix in BigDecimal.negate")
public void testNegateMathContextPositive() {
String a = "92948782094488478231212478987482988429808779810457634781384756794987";
MathContext mc = new MathContext(37, RoundingMode.FLOOR);
method = "negate",
args = {java.math.MathContext.class}
)
- @KnownFailure("Fix in BigDecimal.negate")
public void testNegateMathContextNegative() {
String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
int aScale = 49;
package org.apache.harmony.math.tests.java.math;
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
method = "BigDecimal",
args = {java.math.BigInteger.class, int.class, java.math.MathContext.class}
)
- @KnownFailure("Fix in BigDecimal.inplaceRound")
public void testConstrBigIntegerScaleMathContext_AndroidFailure() {
MathContext mc;
BigDecimal bd;
method = "BigDecimal",
args = {double.class, java.math.MathContext.class}
)
- @KnownFailure("Fix in BigDecimal.inplaceRound")
public void testConstrDoubleMathContext_AndroidFailure() {
BigDecimal bd;
MathContext mc;
method = "movePointRight",
args = {int.class}
)
- @KnownFailure("Throws ArrayIndexOutOfBoundsException instead of ArithmeticException!")
+ @KnownFailure("Throws OutOfMemoryError instead of ArithmeticException!")
public void testMovePointRightEx2() {
BigDecimal a = new BigDecimal("123456789012345678901234567890123456789E25");
try {
package org.apache.harmony.nio.tests.java.nio;
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
method = "put",
args = {int[].class, int.class, int.class}
)
- @KnownFailure("ToT fixed")
public void testPutintArrayintint2() {
// Regression test
ByteBuffer buf = ByteBuffer.allocateDirect(20);
package org.apache.harmony.nio.tests.java.nio;
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import java.nio.IntBuffer;
import java.nio.InvalidMarkException;
import java.nio.ShortBuffer;
method = "put",
args = {short[].class, int.class, int.class}
)
- @KnownFailure("ToT fixed")
public void testPutshortArrayintint2() {
// Regression test
ByteBuffer buf = ByteBuffer.allocateDirect(10);
method = "functionalCoDec_REPR",
args = {}
)
- @KnownFailure("This Characterset is not properly supported in Android!")
@Override
public void test_CodecDynamic() throws CharacterCodingException {
super.test_CodecDynamic();
method = "functionalCoDec_REPR",
args = {}
)
- @KnownFailure("This Characterset is not properly supported in Android!")
@Override
public void test_CodecDynamic() throws CharacterCodingException {
super.test_CodecDynamic();
method = "functionalCoDec_REPR",
args = {}
)
- @KnownFailure("This Characterset is not properly supported in Android!")
@Override
public void test_CodecDynamic() throws CharacterCodingException {
super.test_CodecDynamic();
protected void setUp() throws Exception {
super.setUp();
+ Preferences.systemRoot().clear();
+ Preferences.userRoot().clear();
+
parent = (AbstractPreferences) Preferences.userNodeForPackage(this.getClass());
-/*
- String str[] = parent.childrenNames();
- for (int i = 0; i < str.length; i++) {
- System.out.print(str[i] + " ");
- }
- System.out.println();
-/**/
+
pref = (AbstractPreferences) parent.node(nodeName);
}
protected void tearDown() throws Exception {
-/* String str[] = parent.childrenNames();
- for (int i = 0; i < str.length; i++) {
- System.out.print(str[i] + " ");
- }
- System.out.println();/**/
parent.removeNode();
+ Preferences.systemRoot().clear();
+ Preferences.userRoot().clear();
super.tearDown();
}
package org.apache.harmony.prefs.tests.java.util.prefs;
import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import java.io.FilePermission;
-import java.io.IOException;
import java.security.Permission;
-import java.util.prefs.AbstractPreferences;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
@TestTargetClass(java.util.prefs.Preferences.class)
public class FilePreferencesImplTest extends TestCase {
- private String prevFactory;
- private Preferences uroot;
- private Preferences sroot;
-
public FilePreferencesImplTest() {
super();
}
- protected void setUp() throws Exception {
- // prevFactory = System.getProperty("java.util.prefs.PreferencesFactory");
- // System.setProperty("java.util.prefs.PreferencesFactory", "java.util.prefs.FilePreferencesFactoryImpl");
-
- // uroot = (AbstractPreferences) Preferences.userRoot();
- uroot = Preferences.userRoot();
- sroot = Preferences.systemRoot();
+ @Override
+ protected void setUp(){
}
-
- protected void tearDown() throws Exception {
- // if (prevFactory != null)
- // System.setProperty("java.util.prefs.PreferencesFactory", prevFactory);
- uroot = null;
- sroot = null;
+ @Override
+ protected void tearDown(){
}
@TestTargets({
args = {}
)
})
- public void testPutGet() throws IOException, BackingStoreException {
+ public void testUserPutGet() throws BackingStoreException {
+ Preferences uroot = Preferences.userRoot().node("test");
uroot.put("ukey1", "value1");
assertEquals("value1", uroot.get("ukey1", null));
String[] names = uroot.keys();
uroot.clear();
names = uroot.keys();
assertEquals(0, names.length);
+ }
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Exceptions checking missed, but method is abstract, probably it is OK",
+ method = "put",
+ args = {java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Exceptions checking missed, but method is abstract, probably it is OK",
+ method = "get",
+ args = {java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Exceptions checking missed, but method is abstract, probably it is OK",
+ method = "keys",
+ args = {}
+ )
+ })
+ public void testSystemPutGet() throws BackingStoreException {
+ Preferences sroot = Preferences.systemRoot().node("test");
sroot.put("skey1", "value1");
assertEquals("value1", sroot.get("skey1", null));
sroot.put("\u4e2d key1", "\u4e2d value1");
method = "childrenNames",
args = {}
)
- @AndroidOnly("Checking of childNames.length doesn't pass on RI because of " +
- "it depends on .userPrefs properties.")
- @KnownFailure("This test fails on emulator. " +
- "java.util.prefs.BackingStoreException is thrown during calling of" +
- "childrenNames() method.")
- public void testChildNodes() throws Exception {
-
+ public void testUserChildNodes() throws Exception {
+ Preferences uroot = Preferences.userRoot().node("test");
+
Preferences child1 = uroot.node("child1");
Preferences child2 = uroot.node("\u4e2d child2");
Preferences grandchild = child1.node("grand");
assertNotNull(grandchild);
String[] childNames = uroot.childrenNames();
- for (int i = 0; i < childNames.length; i++) {
- System.out.println("test:" + childNames[i]);
- }
- assertEquals(4, childNames.length);
+ assertContains(childNames, "child1");
+ assertContains(childNames, "\u4e2d child2");
+ assertNotContains(childNames, "grand");
childNames = child1.childrenNames();
- assertEquals(1, childNames.length);
- for (int i = 0; i < childNames.length; i++) {
- System.out.println(childNames[i]);
- }
+ assertContains(childNames, "grand");
childNames = child2.childrenNames();
assertEquals(0, childNames.length);
- for (int i = 0; i < childNames.length; i++) {
- System.out.println(childNames[i]);
- }
child1.removeNode();
childNames = uroot.childrenNames();
- assertEquals(3, childNames.length);
- for (int i = 0; i < childNames.length; i++) {
- System.out.println(childNames[i]);
- }
- // child2.removeNode();
- // childNames = uroot.childrenNames();
- // assertEquals(0, childNames.length);
+ assertNotContains(childNames, "child1");
+ assertContains(childNames, "\u4e2d child2");
+ assertNotContains(childNames, "grand");
- child1 = sroot.node("child1");
- child2 = sroot.node("child2");
- grandchild = child1.node("grand");
+ child2.removeNode();
+ childNames = uroot.childrenNames();
+ assertNotContains(childNames, "child1");
+ assertNotContains(childNames, "\u4e2d child2");
+ assertNotContains(childNames, "grand");
+ }
- childNames = sroot.childrenNames();
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Exceptions checking missed, but method is abstract, probably it is OK",
+ method = "childrenNames",
+ args = {}
+ )
+ @AndroidOnly("It seems like the RI can't remove nodes created in the system root.")
+ public void testSystemChildNodes() throws Exception {
+ Preferences sroot = Preferences.systemRoot().node("test");
- for (int i = 0; i < childNames.length; i++) {
- System.out.println(childNames[i]);
- }
- // assertEquals(2, childNames.length);
+ Preferences child1 = sroot.node("child1");
+ Preferences child2 = sroot.node("child2");
+ Preferences grandchild = child1.node("grand");
+
+ String[] childNames = sroot.childrenNames();
+ assertContains(childNames, "child1");
+ assertContains(childNames, "child2");
+ assertNotContains(childNames, "grand");
childNames = child1.childrenNames();
assertEquals(1, childNames.length);
- for (int i = 0; i < childNames.length; i++) {
- System.out.println(childNames[i]);
- }
childNames = child2.childrenNames();
assertEquals(0, childNames.length);
- for (int i = 0; i < childNames.length; i++) {
- System.out.println(childNames[i]);
- }
+
+ child1.removeNode();
+ childNames = sroot.childrenNames();
+ assertNotContains(childNames, "child1");
+ assertContains(childNames, "child2");
+ assertNotContains(childNames, "grand");
+
+ child2.removeNode();
+ childNames = sroot.childrenNames();
+ assertNotContains(childNames, "child1");
+ assertNotContains(childNames, "child2");
+ assertNotContains(childNames, "grand");
}
@TestTargets({
)
})
public void testSecurityException() throws BackingStoreException {
+ Preferences uroot = Preferences.userRoot().node("test");
+
Preferences child1 = uroot.node("child1");
MockFileSecurityManager manager = new MockFileSecurityManager();
manager.install();
}
}
+ private void assertContains(String[] childNames, String name) {
+ for (String childName : childNames) {
+ if (childName == name) {
+ return;
+ }
+ }
+ fail("No child with name " + name + " was found. It was expected to exist.");
+ }
+
+ private void assertNotContains(String[] childNames, String name) {
+ for (String childName : childNames) {
+ if (childName == name) {
+ fail("Child with name " + name + " was found. This was unexpected.");
+ }
+ }
+ }
+
static class MockFileSecurityManager extends SecurityManager {
SecurityManager dflt;
@TestTargetClass(Preferences.class)
public class PreferencesTest extends TestCase {
+ private String oldJavaHome;
+ private String oldUserHome;
+
MockSecurityManager manager = new MockSecurityManager();
MockInputStream stream = null;
"<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\"><preferences><root type=\"user\"><map></map></root></preferences>"
.getBytes("UTF-8"));
stream = new MockInputStream(in);
-
- String userHome = System.getProperty("user.home");
- if (userHome != null) {
- File userHomeDir = new File(userHome);
- if (!userHomeDir.isDirectory() || !userHomeDir.canWrite()) {
- userHome = null;
- }
- }
- if (userHome == null) {
- System.setProperty("user.home", System.getProperty("java.io.tmpdir"));
- }
-
+
+ Preferences.systemRoot().clear();
+ Preferences.userRoot().clear();
+
Preferences p = Preferences.userNodeForPackage(Preferences.class);
p.clear();
try {
p.removeNode();
} catch (BackingStoreException e) {
}
+
+ Preferences.systemRoot().clear();
+ Preferences.userRoot().clear();
}
@TestTargetNew(
}
try {
- p = Preferences.userNodeForPackage(null);
+ p = Preferences.systemNodeForPackage(null);
fail("NullPointerException has not been thrown");
} catch (NullPointerException e) {
// expected
import SQLite.Stmt;
import SQLite.TableResult;
import dalvik.annotation.AndroidOnly;
+import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
* @tests {@link Stmt#reset()}
*/
@TestTargetNew(
- level = TestLevel.TODO,
+ level = TestLevel.COMPLETE,
notes = "method test",
method = "reset",
args = {}
)
- @AndroidOnly("Tableresult is not cleared when resetting statement: "+
+ @BrokenTest("Tableresult is not cleared when resetting statement: "+
"Either complete spec or change implementation accordingly.")
public void testReset() throws Exception {
db.exec("create table TEST (res integer not null)", null);
// Second example
/**
* Certificate:
+ * <pre>
Data:
Version: 3 (0x2)
Serial Number: 0 (0x0)
99:1c:f5:cb:77:86:36:cd:43:37:99:09:c2:9a:d8:f2:28:05:
06:0c
+ * </pre>
*/
public static final String rootCert = "-----BEGIN CERTIFICATE-----\n" +
"MIIDGzCCAoSgAwIBAgIBADANBgkqhkiG9w0BAQUFADBtMQswCQYDVQQGEwJBTjEQ\n" +
/**
* Certificate:
+ * <pre>
Data:
Version: 3 (0x2)
Serial Number: 1 (0x1)
ba:b4:a2:c7:2c:cb:b1:3a:c2:d8:0c:21:31:ee:68:7e:97:ce:
98:22:2e:c6:cf:f0:1a:11:04:ca:9a:06:de:98:48:85:ac:6c:
6f:98
+ * </pre>
*/
public static final String endCert =
"-----BEGIN CERTIFICATE-----\n" +
private static Serializable getObject(TestCase test, String toAppend)
throws Exception {
- StringBuilder path = new StringBuilder("serialization");
+ StringBuilder path = new StringBuilder("/serialization");
path.append(File.separatorChar);
path.append(test.getClass().getName().replace('.', File.separatorChar));
path.append(toAppend);
- InputStream in = ClassLoader.getSystemClassLoader()
+ InputStream in = SerializationTest.class
.getResourceAsStream(path.toString());
Assert.assertNotNull("Failed to load serialization resource file: "
// test with simple example
format.applyPattern("h:m z");
- super.text = "5:19 EDT";
+ super.text = "5:19 GMT-05:00";
t_FormatWithField(21, format, date, null, Field.HOUR1, 0, 1);
t_FormatWithField(22, format, date, null, Field.MINUTE, 2, 4);
- t_FormatWithField(23, format, date, null, Field.TIME_ZONE, 5, 8);
+ t_FormatWithField(23, format, date, null, Field.TIME_ZONE, 5, 14);
// test fields that are not included in the formatted text
// test with simple example with pattern char Z
format.applyPattern("h:m Z z");
- super.text = "5:19 -0400 EDT";
+ super.text = "5:19 -0400 GMT-05:00";
t_FormatWithField(40, format, date, null, Field.HOUR1, 0, 1);
t_FormatWithField(41, format, date, null, Field.MINUTE, 2, 4);
t_FormatWithField(42, format, date, null, Field.TIME_ZONE, 5, 10);
}
public void t_formatToCharacterIterator() {
- TimeZone tz = TimeZone.getTimeZone("EST");
+ TimeZone tz = TimeZone.getTimeZone("GMT-05:00");
Calendar cal = new GregorianCalendar(tz);
cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01);
cal.set(Calendar.MILLISECOND, 0);
}
private Vector<FieldContainer> getDateVector3() {
- // "5:19 EDT"
+ // "5:19 GMT-05:00"
Vector<FieldContainer> v = new Vector<FieldContainer>();
v.add(new FieldContainer(0, 1, Field.HOUR1));
v.add(new FieldContainer(2, 4, Field.MINUTE));
- v.add(new FieldContainer(5, 8, Field.TIME_ZONE));
+ v.add(new FieldContainer(5, 14, Field.TIME_ZONE));
return v;
}
// 05
// 005 19 019 1 01 001 0 00 000 Mon Monday 256 256 256 2 02 38 038 3 003
// PM
- // PM 5 005 EDT Eastern Daylight Time -0400 -0400"
+ // PM 5 005 GMT-05:00 GMT-05:00 -0500 -0500"
v.add(new FieldContainer(0, 2, Field.ERA));
v.add(new FieldContainer(3, 5, Field.ERA));
v.add(new FieldContainer(6, 8, Field.YEAR));
v.add(new FieldContainer(145, 147, Field.AM_PM));
v.add(new FieldContainer(149, 150, Field.HOUR0));
v.add(new FieldContainer(151, 154, Field.HOUR0));
- v.add(new FieldContainer(155, 158, Field.TIME_ZONE));
- v.add(new FieldContainer(159, 180, Field.TIME_ZONE));
+ v.add(new FieldContainer(155, 164, Field.TIME_ZONE));
+ v.add(new FieldContainer(165, 174, Field.TIME_ZONE));
+ v.add(new FieldContainer(175, 180, Field.TIME_ZONE));
v.add(new FieldContainer(181, 186, Field.TIME_ZONE));
- v.add(new FieldContainer(187, 192, Field.TIME_ZONE));
return v;
}
)
public void testCreateLineBidiInvalid() {
// regression for HARMONY-1050
- Bidi bidi = new Bidi("str", 1);
+ Bidi bidi = new Bidi("str", Bidi.DIRECTION_RIGHT_TO_LEFT);
try {
bidi.createLineBidi(-1, 1);
fail("Expected IAE");
)
@KnownFailure("Is this a failure or just a different behaviour of ICU?")
public void testCreateLineBidi_AndroidFailure() {
- Bidi bidi = new Bidi("str", 1);
+ Bidi bidi = new Bidi("str", Bidi.DIRECTION_RIGHT_TO_LEFT);
bidi.createLineBidi(2, 2);
}
method = "setDecomposition",
args = {int.class}
)
- @KnownFailure("Already fixed?")
+ @KnownFailure("uses decomposition even if set to NO_DECOMPOSITION")
public void test_setDecompositionI() {
Collator c = Collator.getInstance(Locale.FRENCH);
c.setStrength(Collator.IDENTICAL);
c.setDecomposition(Collator.NO_DECOMPOSITION);
- assertTrue("Collator should not be using decomposition", !c.equals(
+ assertFalse("Collator should not be using decomposition", c.equals(
"\u212B", "\u00C5")); // "ANGSTROM SIGN" and "LATIN CAPITAL
- // LETTER A WITH RING ABOVE"
+ // LETTER A WITH RING ABOVE"
c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
assertTrue("Collator should be using decomposition", c.equals("\u212B",
"\u00C5")); // "ANGSTROM SIGN" and "LATIN CAPITAL LETTER A WITH
package org.apache.harmony.text.tests.java.text;
import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.BrokenTest;
import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
assertTrue("Returned incorrect currency",
dfsUS.getCurrency() == currency);
- // BEGIN android-changed
// use cs_CZ instead
//Currency currK = Currency.getInstance("KRW");
Currency currC = Currency.getInstance("CZK");
dfs1.getInternationalCurrencySymbol());
dfs1 = new DecimalFormatSymbols(new Locale("de", "AT"));
- // END android-changed
assertTrue("Test4: Returned incorrect currency",
dfs1.getCurrency() == currE);
assertEquals("Test4: Returned incorrect currencySymbol", "\u20ac", dfs1
assertTrue("Hash codes of equal object are equal", dfs2
.hashCode() == dfs1.hashCode());
dfs1.setInfinity("infinity_infinity");
- // BEGIN android-changed
assertTrue("Hash codes of non-equal objects are equal", dfs2
.hashCode() != dfs1.hashCode());
- // END android-changed
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
method = "setInternationalCurrencySymbol",
args = {java.lang.String.class}
)
- @KnownFailure("getCurrency() doesn't return null. Test passes on RI.")
+ @KnownFailure("getCurrency() doesn't return null for bogus currency code.")
public void test_setInternationalCurrencySymbolLjava_lang_String() {
Locale locale = Locale.CANADA;
DecimalFormatSymbols dfs = ((DecimalFormat) NumberFormat
method = "!SerializationGolden",
args = {}
)
- @BrokenTest("Deserialized object is not equal to the original object." +
+ @KnownFailure("Deserialized object is not equal to the original object." +
"Test passes on RI.")
public void test_RIHarmony_compatible() throws Exception {
ObjectInputStream i = null;
method = "getMinimumIntegerDigits",
args = {}
)
- @KnownFailure("Something seems wrong with Android implementation, here!")
- public void test_getMaximumIntegerDigits_AndroidFailure() {
+ @AndroidOnly("second 0 needs to be quoted in icu." +
+ "(quoting special characters in prefix and suffix necessary)")
+ public void test_getMaximumIntegerDigits2() {
// regression test for HARMONY-878
- assertTrue(new DecimalFormat("0\t0").getMaximumIntegerDigits() > 0);
+ assertTrue(new DecimalFormat("0\t'0'").getMaximumIntegerDigits() > 0);
}
@TestTargetNew(
method = "applyPattern",
args = {java.lang.String.class}
)
- @KnownFailure("Something seems wrong with Android implementation, here!")
- public void test_applyPatternLjava_lang_String_AndroidFailure() {
+ @AndroidOnly("icu supports 2 grouping sizes.")
+ public void test_applyPatternLjava_lang_String2() {
DecimalFormat decFormat = new DecimalFormat("#.#");
String [] patterns = {"####.##", "######.######", "000000.000000",
"######.000000", "000000.######", " ###.###", "$#####.######",
"$$####.######", "%#,##,###,####", "#,##0.00;(#,##0.00)",
"##.##-E"};
- String [] expResult = {"#0.##", "#0.######", "#000000.000000",
+ String [] expResult = {"#0.##", "#0.######", "#000000.000000",
"#.000000", "#000000.######", " #0.###", "$#0.######",
- "$$#0.######", "%#,####", "#,##0.00;(#,##0.00)",
- "#0.##-E"};
+ "$$#0.######",
+ "%#,###,####", // icu only. icu supports two grouping sizes
+ "#,##0.00;(#,##0.00)",
+ "#0.##-'E'"}; // icu only. E in the suffix does not need to be
+ // quoted. This is done automatically.
for (int i = 0; i < patterns.length; i++) {
decFormat.applyPattern(patterns[i]);
- assertEquals("Failed to apply following pattern: " + patterns[i],
- expResult[i], decFormat.toPattern());
+ String result = decFormat.toPattern();
+ assertEquals("Failed to apply following pattern: " + patterns[i] +
+ " expected: " + expResult[i] + " returned: " + result,
+ expResult[i], result);
}
}
method = "!SerializationGolden",
args = {}
)
+ @KnownFailure("a regression. This didn't fail before")
public void test_serializationHarmonyRICompatible() {
NumberFormat nf = NumberFormat.getInstance(Locale.FRANCE);
package org.apache.harmony.text.tests.java.text;
import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.BrokenTest;
import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
method = "equals",
args = {java.lang.Object.class}
)
- @KnownFailure("Succeeds against RI.")
public void testEqualsObject() throws ParseException {
String rule = "< a < b < c < d < e";
RuleBasedCollator coll = new RuleBasedCollator(rule);
method = "getCollationElementIterator",
args = {java.text.CharacterIterator.class}
)
- @KnownFailure("Succeeds against RI.")
+ @KnownFailure("ICU seems to miss collation data")
public void testGetCollationElementIteratorCharacterIterator() throws Exception {
{
- Locale locale = new Locale("es", "", "TRADITIONAL");
+ Locale locale = new Locale("cs", "CZ", "");
RuleBasedCollator coll = (RuleBasedCollator) Collator
.getInstance(locale);
String text = "cha";
StringCharacterIterator source = new StringCharacterIterator(text);
CollationElementIterator iterator = coll
.getCollationElementIterator(source);
- int[] e_offset = { 0, 1, 2 };
+ int[] e_offset = { 0, 2 };
int offset = iterator.getOffset();
int i = 0;
assertEquals(e_offset[i++], offset);
method = "getAvailableLocales",
args = {}
)
- @KnownFailure("Succeeds against RI.")
public void testGetAvaiableLocales() {
Locale[] locales = Collator.getAvailableLocales();
boolean isUS = false;
package org.apache.harmony.text.tests.java.text;
import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.BrokenTest;
import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
)
@KnownFailure("SimpleDateFormat.format(Date date, " +
"StringBuffer toAppendTo, FieldPosition pos) " +
- "return incorrect week number for \" W\" pattern. ")
+ "return incorrect week number for \" W\" pattern. " +
+ "Also Android doesn't support formatting of PST, EST, ...")
public void test_formatLjava_util_DateLjava_lang_StringBufferLjava_text_FieldPosition() {
// Test for method java.lang.StringBuffer
// java.text.SimpleDateFormat.format(java.util.Date,
" 0", DateFormat.HOUR0_FIELD);
test.test(" KK", cal, " 03", DateFormat.HOUR0_FIELD);
test.test(" KKKK", cal, " 0003", DateFormat.HOUR0_FIELD);
-
-// Android doesn't support EST/EDT time zones
-// format.setTimeZone(TimeZone.getTimeZone("EST"));
-// test.test(" z", cal, " EDT", DateFormat.TIMEZONE_FIELD);
-// Calendar temp2 = new GregorianCalendar(1999, Calendar.JANUARY, 12);
-// test.test(" z", temp2, " EST", DateFormat.TIMEZONE_FIELD);
-// test.test(" zz", cal, " EDT", DateFormat.TIMEZONE_FIELD);
-// test.test(" zzz", cal, " EDT", DateFormat.TIMEZONE_FIELD);
-// test.test(" zzzz", cal, " Eastern Daylight Time",
-// DateFormat.TIMEZONE_FIELD);
-// test.test(" zzzz", temp2, " Eastern Standard Time",
-// DateFormat.TIMEZONE_FIELD);
-// test.test(" zzzzz", cal, " Eastern Daylight Time",
-// DateFormat.TIMEZONE_FIELD);
format.setTimeZone(new SimpleTimeZone(60000, "ONE MINUTE"));
test.test(" z", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
} catch (Throwable ex) {
fail("Expected test to throw NPE, not " + ex.getClass().getName());
}
+
+ format.setTimeZone(TimeZone.getTimeZone("EST"));
+ test.test(" z", cal, " EDT", DateFormat.TIMEZONE_FIELD);
+ Calendar temp2 = new GregorianCalendar(1999, Calendar.JANUARY, 12);
+ test.test(" z", temp2, " EST", DateFormat.TIMEZONE_FIELD);
+ test.test(" zz", cal, " EDT", DateFormat.TIMEZONE_FIELD);
+ test.test(" zzz", cal, " EDT", DateFormat.TIMEZONE_FIELD);
+ test.test(" zzzz", cal, " Eastern Daylight Time",
+ DateFormat.TIMEZONE_FIELD);
+ test.test(" zzzz", temp2, " Eastern Standard Time",
+ DateFormat.TIMEZONE_FIELD);
+ test.test(" zzzzz", cal, " Eastern Daylight Time",
+ DateFormat.TIMEZONE_FIELD);
}
/**
args = {java.lang.String.class}
)
})
+ @KnownFailure("Android doesn't support formatting of PST, EST, ...")
public void test_timeZoneFormatting() {
// tests specific to formatting of timezones
Date summerDate = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3,
TestFormat test = new TestFormat(
"test_formatLjava_util_DateLjava_lang_StringBufferLjava_text_FieldPosition");
-// Android doesn't support this time zone
-// test.verifyFormatTimezone("PST", "PDT, Pacific Daylight Time",
-// "-0700, -0700", summerDate);
-// test.verifyFormatTimezone("PST", "PST, Pacific Standard Time",
-// "-0800, -0800", winterDate);
-
test.verifyFormatTimezone("GMT-7", "GMT-07:00, GMT-07:00",
"-0700, -0700", summerDate);
test.verifyFormatTimezone("GMT-7", "GMT-07:00, GMT-07:00",
"-0700, -0700", winterDate);
- // Pacific/Kiritimati is one of the timezones supported only in mJava
+ // Pacific/Kiritimati is one of the timezones supported only in Java
// Android doesn't support this time zone
// test.verifyFormatTimezone("Pacific/Kiritimati", "LINT, Line Is. Time",
// "+1400, +1400", summerDate);
// test.verifyFormatTimezone("Pacific/Kiritimati", "LINT, Line Is. Time",
// "+1400, +1400", winterDate);
-// test.verifyFormatTimezone("EDT", "EDT, Eastern Daylight Time",
-// "-0400, -0400", summerDate);
-// test.verifyFormatTimezone("EST", "EST, Eastern Standard Time",
-// "-0500, -0500", winterDate);
-
test.verifyFormatTimezone("GMT+14", "GMT+14:00, GMT+14:00",
"+1400, +1400", summerDate);
test.verifyFormatTimezone("GMT+14", "GMT+14:00, GMT+14:00",
"+1400, +1400", winterDate);
+
+ test.verifyFormatTimezone("PST", "PDT, Pacific Daylight Time",
+ "-0700, -0700", summerDate);
+ test.verifyFormatTimezone("PST", "PST, Pacific Standard Time",
+ "-0800, -0800", winterDate);
+
+ test.verifyFormatTimezone("EDT", "EDT, Eastern Daylight Time",
+ "-0400, -0400", summerDate);
+ test.verifyFormatTimezone("EST", "EST, Eastern Standard Time",
+ "-0500, -0500", winterDate);
}
/**
#include "org_apache_harmony_xnet_provider_jsse_common.h"
/**
- * Global variable used in module org_apache_harmony_xnet_provider_jsse_common.h.
- * It is correctly updated in the function accept().
- */
-int verify_callback_mydata_index = 0;
-
-/**
* Module scope variables initialized during JNI registration.
*/
static jfieldID field_ssl_ctx;
SSL_CTX *ssl_ctx;
mydata_t mydata;
- char name[] = "mydata index";
-
ssl_ctx = (SSL_CTX *)jssl_ctx;
ssl = create_ssl(env, object, ssl_ctx);
SSL_set_bio(ssl, bio, bio);
- /* Call to "register" some new application specific data. It takes three
- * optional function pointers which are called when the parent structure
- * (in this case an RSA structure) is initially created, when it is copied
- * and when it is freed up. If any or all of these function pointer
- * arguments are not used they should be set to NULL. Here we simply
- * register a dummy callback application with the index 0.
+ /*
+ * Fill in the mydata structure needed for the certificate callback and
+ * store this in the SSL application data slot.
*/
- verify_callback_mydata_index = SSL_get_ex_new_index(0, name, NULL, NULL, NULL);
-
- /* Fill in the mydata structure */
mydata.env = env;
mydata.object = object;
- SSL_set_ex_data(ssl, verify_callback_mydata_index, &mydata);
+ SSL_set_app_data(ssl, &mydata);
+ /*
+ * Do the actual SSL_accept(). It is possible this code is insufficient.
+ * Maybe we need to deal with all the special SSL error cases (WANT_*),
+ * just like we do for SSL_connect(). But currently it is looking ok.
+ */
ret = SSL_accept(ssl);
- if (ret < 1) {
+ /*
+ * Clear the SSL application data slot again, so we can safely use it for
+ * our ordinary synchronization structure afterwards. Also, we don't want
+ * sslDestroyAppData() to think that there is something that needs to be
+ * freed right now (in case of an error).
+ */
+ SSL_set_app_data(ssl, NULL);
+
+ if (ret == 0) {
/*
- * Translate the error, and throw if it turns out to be a real
- * problem.
+ * The other side closed the socket before the handshake could be
+ * completed, but everything is within the bounds of the TLS protocol.
+ * We still might want to find out the real reason of the failure.
*/
int sslErrorCode = SSL_get_error(ssl, ret);
- if (sslErrorCode != SSL_ERROR_ZERO_RETURN) {
- throwIOExceptionWithSslErrors(env, ret, sslErrorCode,
- "Trouble accepting connection");
- free_ssl(env, object);
- }
+ if (sslErrorCode == SSL_ERROR_NONE ||
+ sslErrorCode == SSL_ERROR_SYSCALL && errno == 0) {
+ throwIOExceptionStr(env, "Connection closed by peer");
+ } else {
+ throwIOExceptionWithSslErrors(env, ret, sslErrorCode,
+ "Trouble accepting connection");
+ }
+ free_ssl(env, object);
+ return;
+ } else if (ret < 0) {
+ /*
+ * Translate the error and throw exception. We are sure it is an error
+ * at this point.
+ */
+ int sslErrorCode = SSL_get_error(ssl, ret);
+ throwIOExceptionWithSslErrors(env, ret, sslErrorCode,
+ "Trouble accepting connection");
+ free_ssl(env, object);
+ return;
}
/*
}
}
-extern int verify_callback_mydata_index;
-
/**
* Verify the X509 certificate.
*/
/* Get the correct index to the SSLobject stored into X509_STORE_CTX. */
ssl = (SSL*)X509_STORE_CTX_get_ex_data(x509_store_ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
- mydata = (mydata_t*)SSL_get_ex_data(ssl, verify_callback_mydata_index);
+ mydata = (mydata_t*)SSL_get_app_data(ssl);
cls = mydata->env->GetObjectClass(mydata->object);