Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java Mon Jan 28 04:07:47 2008
@@ -20,6 +20,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Externalizable;
+import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -40,425 +41,426 @@
import java.security.Permission;
import java.util.Arrays;
+import junit.framework.TestCase;
+
@SuppressWarnings( { "unused", "serial" })
-public class ObjectOutputStreamTest extends junit.framework.TestCase implements
- Serializable {
+public class ObjectOutputStreamTest extends TestCase implements Serializable {
+
+ File f;
+
+ public class SerializableTestHelper implements Serializable {
+ public String aField1;
- java.io.File f;
+ public String aField2;
+
+ SerializableTestHelper() {
+ aField1 = null;
+ aField2 = null;
+ }
- public class SerializableTestHelper implements Serializable {
- public String aField1;
+ SerializableTestHelper(String s, String t) {
+ aField1 = s;
+ aField2 = t;
+ }
- public String aField2;
-
- SerializableTestHelper() {
- aField1 = null;
- aField2 = null;
- }
-
- SerializableTestHelper(String s, String t) {
- aField1 = s;
- aField2 = t;
- }
-
- private void readObject(ObjectInputStream ois) throws IOException {
- // note aField2 is not read
- try {
- ObjectInputStream.GetField fields = ois.readFields();
- aField1 = (String) fields.get("aField1", "Zap");
- } catch (Exception e) {
- }
- }
-
- private void writeObject(ObjectOutputStream oos) throws IOException {
- // note aField2 is not written
- ObjectOutputStream.PutField fields = oos.putFields();
- fields.put("aField1", aField1);
- oos.writeFields();
- }
-
- public String getText1() {
- return aField1;
- }
-
- public void setText1(String s) {
- aField1 = s;
- }
-
- public String getText2() {
- return aField2;
- }
-
- public void setText2(String s) {
- aField2 = s;
- }
- }
-
- private static class SerializationTest implements java.io.Serializable {
- int anInt = INIT_INT_VALUE;
-
- public SerializationTest() {
- super();
- }
- }
+ private void readObject(ObjectInputStream ois) throws IOException {
+ // note aField2 is not read
+ try {
+ ObjectInputStream.GetField fields = ois.readFields();
+ aField1 = (String) fields.get("aField1", "Zap");
+ } catch (Exception e) {
+ }
+ }
+
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+ // note aField2 is not written
+ ObjectOutputStream.PutField fields = oos.putFields();
+ fields.put("aField1", aField1);
+ oos.writeFields();
+ }
+
+ public String getText1() {
+ return aField1;
+ }
+
+ public void setText1(String s) {
+ aField1 = s;
+ }
+
+ public String getText2() {
+ return aField2;
+ }
+
+ public void setText2(String s) {
+ aField2 = s;
+ }
+ }
+
+ private static class SerializationTest implements java.io.Serializable {
+ int anInt = INIT_INT_VALUE;
+
+ public SerializationTest() {
+ super();
+ }
+ }
private static class SerializationTestSubclass1 extends SerializationTest
- implements Serializable {
- String aString = INIT_STR_VALUE;
+ implements Serializable {
+ String aString = INIT_STR_VALUE;
+
+ public SerializationTestSubclass1() {
+ super();
+ // Just to change default superclass init value
+ anInt = INIT_INT_VALUE / 2;
+ }
+ }
+
+ private static class SpecTestSuperClass implements Runnable, Serializable {
+ protected java.lang.String instVar;
+
+ public void run() {
+ }
+ }
+
+ private static class SpecTest extends SpecTestSuperClass implements
+ Cloneable, Serializable {
+ public java.lang.String instVar1;
+
+ public static java.lang.String staticVar1;
+
+ public static java.lang.String staticVar2;
+ {
+ instVar1 = "NonStaticInitialValue";
+ }
+ static {
+ staticVar1 = "StaticInitialValue";
+ staticVar1 = new String(staticVar1);
+ }
+
+ public Object method(Object objParam, Object objParam2) {
+ return new Object();
+ }
+
+ public boolean method(boolean bParam, Object objParam) {
+ return true;
+ }
+
+ public boolean method(boolean bParam, Object objParam, Object objParam2) {
+ return true;
+ }
+
+ }
+
+ private static class SpecTestSubclass extends SpecTest implements
+ Serializable {
+ public transient java.lang.String transientInstVar = "transientValue";
+ }
+
+ private static class ReadWriteObject implements java.io.Serializable {
+ public boolean calledWriteObject = false;
+
+ public boolean calledReadObject = false;
+
+ public ReadWriteObject() {
+ super();
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws java.io.IOException, ClassNotFoundException {
+ calledReadObject = true;
+ in.readObject();
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws java.io.IOException {
+ calledWriteObject = true;
+ out.writeObject(FOO);
+ }
+ }
+
+ private static class PublicReadWriteObject implements java.io.Serializable {
+ public boolean calledWriteObject = false;
+
+ public boolean calledReadObject = false;
+
+ public PublicReadWriteObject() {
+ super();
+ }
+
+ public void readObject(java.io.ObjectInputStream in)
+ throws java.io.IOException, ClassNotFoundException {
+ calledReadObject = true;
+ in.readObject();
+ }
+
+ public void writeObject(java.io.ObjectOutputStream out)
+ throws java.io.IOException {
+ calledWriteObject = true;
+ out.writeObject(FOO);
+ }
+ }
+
+ private static class FieldOrder implements Serializable {
+ String aaa1NonPrimitive = "aaa1";
+
+ int bbb1PrimitiveInt = 5;
+
+ boolean aaa2PrimitiveBoolean = true;
+
+ String bbb2NonPrimitive = "bbb2";
+ }
- public SerializationTestSubclass1() {
- super();
- // Just to change default superclass init value
- anInt = INIT_INT_VALUE / 2;
- }
- }
-
- private static class SpecTestSuperClass implements Runnable, Serializable {
- protected java.lang.String instVar;
-
- public void run() {
- }
- }
-
- private static class SpecTest extends SpecTestSuperClass implements
- Cloneable, Serializable {
- public java.lang.String instVar1;
-
- public static java.lang.String staticVar1;
-
- public static java.lang.String staticVar2;
- {
- instVar1 = "NonStaticInitialValue";
- }
- static {
- staticVar1 = "StaticInitialValue";
- staticVar1 = new String(staticVar1);
- }
-
- public Object method(Object objParam, Object objParam2) {
- return new Object();
- }
-
- public boolean method(boolean bParam, Object objParam) {
- return true;
- }
-
- public boolean method(boolean bParam, Object objParam, Object objParam2) {
- return true;
- }
-
- }
-
- private static class SpecTestSubclass extends SpecTest implements
- Serializable {
- public transient java.lang.String transientInstVar = "transientValue";
- }
-
- private static class ReadWriteObject implements java.io.Serializable {
- public boolean calledWriteObject = false;
-
- public boolean calledReadObject = false;
-
- public ReadWriteObject() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- calledReadObject = true;
- in.readObject();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException {
- calledWriteObject = true;
- out.writeObject(FOO);
- }
- }
-
- private static class PublicReadWriteObject implements java.io.Serializable {
- public boolean calledWriteObject = false;
-
- public boolean calledReadObject = false;
-
- public PublicReadWriteObject() {
- super();
- }
-
- public void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- calledReadObject = true;
- in.readObject();
- }
-
- public void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException {
- calledWriteObject = true;
- out.writeObject(FOO);
- }
- }
-
- private static class FieldOrder implements Serializable {
- String aaa1NonPrimitive = "aaa1";
-
- int bbb1PrimitiveInt = 5;
-
- boolean aaa2PrimitiveBoolean = true;
-
- String bbb2NonPrimitive = "bbb2";
- }
-
- private static class JustReadObject implements java.io.Serializable {
- public boolean calledReadObject = false;
-
- public JustReadObject() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- calledReadObject = true;
- in.defaultReadObject();
- }
- }
-
- private static class JustWriteObject implements java.io.Serializable {
- public boolean calledWriteObject = false;
-
- public JustWriteObject() {
- super();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- calledWriteObject = true;
- out.defaultWriteObject();
- }
- }
-
- private static class ClassBasedReplacementWhenDumping implements
- java.io.Serializable {
- public boolean calledReplacement = false;
-
- public ClassBasedReplacementWhenDumping() {
- super();
- }
-
- private Object writeReplace() {
- calledReplacement = true;
- return FOO; // Replacement is a String
- }
- }
-
- private static class MultipleClassBasedReplacementWhenDumping implements
- java.io.Serializable {
- private static class C1 implements java.io.Serializable {
- private Object writeReplace() {
- return new C2();
- }
- }
-
- private static class C2 implements java.io.Serializable {
- private Object writeReplace() {
- return new C3();
- }
- }
-
- private static class C3 implements java.io.Serializable {
- private Object writeReplace() {
- return FOO;
- }
- }
-
- public MultipleClassBasedReplacementWhenDumping() {
- super();
- }
-
- private Object writeReplace() {
- return new C1();
- }
- }
-
- private static class ClassBasedReplacementWhenLoading implements
- java.io.Serializable {
- public ClassBasedReplacementWhenLoading() {
- super();
- }
-
- private Object readResolve() {
- return FOO; // Replacement is a String
- }
- }
-
- private static class ClassBasedReplacementWhenLoadingViolatesFieldType
- implements java.io.Serializable {
- public ClassBasedReplacementWhenLoading classBasedReplacementWhenLoading = new ClassBasedReplacementWhenLoading();
-
- public ClassBasedReplacementWhenLoadingViolatesFieldType() {
- super();
- }
- }
-
- private static class MyExceptionWhenDumping implements java.io.Serializable {
- private static class MyException extends java.io.IOException {
- };
-
- public boolean anInstanceVar = false;
-
- public MyExceptionWhenDumping() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- in.defaultReadObject();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- throw new MyException();
- }
- }
-
- private static class NonSerializableExceptionWhenDumping implements
- java.io.Serializable {
- public Object anInstanceVar = new Object();
-
- public NonSerializableExceptionWhenDumping() {
- super();
- }
- }
-
- private static class MyUnserializableExceptionWhenDumping implements
- java.io.Serializable {
- private static class MyException extends java.io.IOException {
- private Object notSerializable = new Object();
- };
-
- public boolean anInstanceVar = false;
-
- public MyUnserializableExceptionWhenDumping() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- in.defaultReadObject();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- throw new MyException();
- }
- }
-
- private static class WithUnmatchingSerialPersistentFields implements
- java.io.Serializable {
- private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
- "value", String.class) };
-
- public int anInstanceVar = 5;
-
- public WithUnmatchingSerialPersistentFields() {
- super();
- }
- }
-
- private static class WithMatchingSerialPersistentFields implements
- java.io.Serializable {
- private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
- "anInstanceVar", String.class) };
-
- public String anInstanceVar = FOO + FOO;
-
- public WithMatchingSerialPersistentFields() {
- super();
- }
- }
-
- private static class SerialPersistentFields implements java.io.Serializable {
- private static final String SIMULATED_FIELD_NAME = "text";
-
- private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
- SIMULATED_FIELD_NAME, String.class) };
-
- public int anInstanceVar = 5;
-
- public SerialPersistentFields() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- ObjectInputStream.GetField fields = in.readFields();
- anInstanceVar = Integer.parseInt((String) fields.get(
- SIMULATED_FIELD_NAME, "-5"));
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- ObjectOutputStream.PutField fields = out.putFields();
- fields.put(SIMULATED_FIELD_NAME, Integer.toString(anInstanceVar));
- out.writeFields();
- }
- }
-
- private static class WriteFieldsWithoutFetchingPutFields implements
- java.io.Serializable {
- private static final String SIMULATED_FIELD_NAME = "text";
-
- private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
- SIMULATED_FIELD_NAME, String.class) };
-
- public int anInstanceVar = 5;
-
- public WriteFieldsWithoutFetchingPutFields() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- in.readFields();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- out.writeFields();
- }
- }
-
- private static class SerialPersistentFieldsWithoutField implements
- java.io.Serializable {
- public int anInstanceVar = 5;
-
- public SerialPersistentFieldsWithoutField() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- in.readFields();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- out.putFields();
- out.writeFields();
- }
- }
-
- private static class NotSerializable {
- private int foo;
-
- public NotSerializable() {
- }
-
- protected Object writeReplace() throws ObjectStreamException {
- return new Integer(42);
- }
- }
-
- private static class WriteReplaceObject implements Serializable {
+ private static class JustReadObject implements java.io.Serializable {
+ public boolean calledReadObject = false;
+
+ public JustReadObject() {
+ super();
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws java.io.IOException, ClassNotFoundException {
+ calledReadObject = true;
+ in.defaultReadObject();
+ }
+ }
+
+ private static class JustWriteObject implements java.io.Serializable {
+ public boolean calledWriteObject = false;
+
+ public JustWriteObject() {
+ super();
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws java.io.IOException, ClassNotFoundException {
+ calledWriteObject = true;
+ out.defaultWriteObject();
+ }
+ }
+
+ private static class ClassBasedReplacementWhenDumping implements
+ java.io.Serializable {
+ public boolean calledReplacement = false;
+
+ public ClassBasedReplacementWhenDumping() {
+ super();
+ }
+
+ private Object writeReplace() {
+ calledReplacement = true;
+ return FOO; // Replacement is a String
+ }
+ }
+
+ private static class MultipleClassBasedReplacementWhenDumping implements
+ java.io.Serializable {
+ private static class C1 implements java.io.Serializable {
+ private Object writeReplace() {
+ return new C2();
+ }
+ }
+
+ private static class C2 implements java.io.Serializable {
+ private Object writeReplace() {
+ return new C3();
+ }
+ }
+
+ private static class C3 implements java.io.Serializable {
+ private Object writeReplace() {
+ return FOO;
+ }
+ }
+
+ public MultipleClassBasedReplacementWhenDumping() {
+ super();
+ }
+
+ private Object writeReplace() {
+ return new C1();
+ }
+ }
+
+ private static class ClassBasedReplacementWhenLoading implements
+ java.io.Serializable {
+ public ClassBasedReplacementWhenLoading() {
+ super();
+ }
+
+ private Object readResolve() {
+ return FOO; // Replacement is a String
+ }
+ }
+
+ private static class ClassBasedReplacementWhenLoadingViolatesFieldType
+ implements java.io.Serializable {
+ public ClassBasedReplacementWhenLoading classBasedReplacementWhenLoading = new ClassBasedReplacementWhenLoading();
+
+ public ClassBasedReplacementWhenLoadingViolatesFieldType() {
+ super();
+ }
+ }
+
+ private static class MyExceptionWhenDumping implements java.io.Serializable {
+ private static class MyException extends java.io.IOException {
+ };
+
+ public boolean anInstanceVar = false;
+
+ public MyExceptionWhenDumping() {
+ super();
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws java.io.IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws java.io.IOException, ClassNotFoundException {
+ throw new MyException();
+ }
+ }
+
+ private static class NonSerializableExceptionWhenDumping implements
+ java.io.Serializable {
+ public Object anInstanceVar = new Object();
+
+ public NonSerializableExceptionWhenDumping() {
+ super();
+ }
+ }
+
+ private static class MyUnserializableExceptionWhenDumping implements
+ java.io.Serializable {
+ private static class MyException extends java.io.IOException {
+ private Object notSerializable = new Object();
+ };
+
+ public boolean anInstanceVar = false;
+
+ public MyUnserializableExceptionWhenDumping() {
+ super();
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws java.io.IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws java.io.IOException, ClassNotFoundException {
+ throw new MyException();
+ }
+ }
+
+ private static class WithUnmatchingSerialPersistentFields implements
+ java.io.Serializable {
+ private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
+ "value", String.class) };
+
+ public int anInstanceVar = 5;
+
+ public WithUnmatchingSerialPersistentFields() {
+ super();
+ }
+ }
+
+ private static class WithMatchingSerialPersistentFields implements
+ java.io.Serializable {
+ private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
+ "anInstanceVar", String.class) };
+
+ public String anInstanceVar = FOO + FOO;
+
+ public WithMatchingSerialPersistentFields() {
+ super();
+ }
+ }
+
+ private static class SerialPersistentFields implements java.io.Serializable {
+ private static final String SIMULATED_FIELD_NAME = "text";
+
+ private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
+ SIMULATED_FIELD_NAME, String.class) };
+
+ public int anInstanceVar = 5;
+
+ public SerialPersistentFields() {
+ super();
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws java.io.IOException, ClassNotFoundException {
+ ObjectInputStream.GetField fields = in.readFields();
+ anInstanceVar = Integer.parseInt((String) fields.get(
+ SIMULATED_FIELD_NAME, "-5"));
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws java.io.IOException, ClassNotFoundException {
+ ObjectOutputStream.PutField fields = out.putFields();
+ fields.put(SIMULATED_FIELD_NAME, Integer.toString(anInstanceVar));
+ out.writeFields();
+ }
+ }
+
+ private static class WriteFieldsWithoutFetchingPutFields implements
+ java.io.Serializable {
+ private static final String SIMULATED_FIELD_NAME = "text";
+
+ private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
+ SIMULATED_FIELD_NAME, String.class) };
+
+ public int anInstanceVar = 5;
+
+ public WriteFieldsWithoutFetchingPutFields() {
+ super();
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws java.io.IOException, ClassNotFoundException {
+ in.readFields();
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws java.io.IOException, ClassNotFoundException {
+ out.writeFields();
+ }
+ }
+
+ private static class SerialPersistentFieldsWithoutField implements
+ java.io.Serializable {
+ public int anInstanceVar = 5;
+
+ public SerialPersistentFieldsWithoutField() {
+ super();
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws java.io.IOException, ClassNotFoundException {
+ in.readFields();
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws java.io.IOException, ClassNotFoundException {
+ out.putFields();
+ out.writeFields();
+ }
+ }
+
+ private static class NotSerializable {
+ private int foo;
+
+ public NotSerializable() {
+ }
+
+ protected Object writeReplace() throws ObjectStreamException {
+ return new Integer(42);
+ }
+ }
+
+ private static class WriteReplaceObject implements Serializable {
private Object replaceObject;
private static enum Color {
@@ -474,25 +476,27 @@
}
}
- private static class ExternalizableWithReplace implements Externalizable {
- private int foo;
+ private static class ExternalizableWithReplace implements Externalizable {
+ private int foo;
- public ExternalizableWithReplace() {
- }
+ public ExternalizableWithReplace() {
+ }
- protected Object writeReplace() throws ObjectStreamException {
- return new Integer(42);
- }
+ protected Object writeReplace() throws ObjectStreamException {
+ return new Integer(42);
+ }
- public void writeExternal(ObjectOutput out) {
- }
+ public void writeExternal(ObjectOutput out) {
+ }
- public void readExternal(ObjectInput in) {
- }
- }
+ public void readExternal(ObjectInput in) {
+ }
+ }
- private static class ObjectOutputStreamWithReplace extends ObjectOutputStream {
- public ObjectOutputStreamWithReplace(OutputStream out) throws IOException {
+ private static class ObjectOutputStreamWithReplace extends
+ ObjectOutputStream {
+ public ObjectOutputStreamWithReplace(OutputStream out)
+ throws IOException {
super(out);
enableReplaceObject(true);
}
@@ -504,10 +508,10 @@
if (obj instanceof Integer) {
return new Long(((Integer) obj).longValue());
}
- return super.replaceObject(obj);
+ return super.replaceObject(obj);
}
}
-
+
private static class ObjectOutputStreamWithReplace2 extends
ObjectOutputStream {
public ObjectOutputStreamWithReplace2(OutputStream out)
@@ -520,8 +524,9 @@
return new Long(10);
}
}
-
- private static class ObjectOutputStreamWriteOverride extends ObjectOutputStream {
+
+ private static class ObjectOutputStreamWriteOverride extends
+ ObjectOutputStream {
String test = "test";
protected ObjectOutputStreamWriteOverride() throws IOException,
@@ -536,34 +541,34 @@
}
}
- protected static final String MODE_XLOAD = "xload";
+ protected static final String MODE_XLOAD = "xload";
- protected static final String MODE_XDUMP = "xdump";
+ protected static final String MODE_XDUMP = "xdump";
- static final String FOO = "foo";
+ static final String FOO = "foo";
- static final String MSG_WITE_FAILED = "Failed to write: ";
+ static final String MSG_WITE_FAILED = "Failed to write: ";
- private static final boolean DEBUG = false;
+ private static final boolean DEBUG = false;
- protected static boolean xload = false;
+ protected static boolean xload = false;
- protected static boolean xdump = false;
+ protected static boolean xdump = false;
- protected static String xFileName = null;
+ protected static String xFileName = null;
- protected ObjectInputStream ois;
+ protected ObjectInputStream ois;
- protected ObjectOutputStream oos;
+ protected ObjectOutputStream oos;
- protected ByteArrayOutputStream bao;
+ protected ByteArrayOutputStream bao;
- static final int INIT_INT_VALUE = 7;
+ static final int INIT_INT_VALUE = 7;
- static final String INIT_STR_VALUE = "a string that is blortz";
+ static final String INIT_STR_VALUE = "a string that is blortz";
- /**
- * @tests java.io.ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)
+ /**
+ * @tests java.io.ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)
*/
public void test_ConstructorLjava_io_OutputStream() throws IOException {
// Test for method java.io.ObjectOutputStream(java.io.OutputStream)
@@ -572,97 +577,98 @@
oos.close();
}
- /**
- * @tests java.io.ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)
- */
- public void test_ConstructorLjava_io_OutputStream_subtest0() throws IOException {
-
- // custom security manager
- SecurityManager sm = new SecurityManager() {
-
- final SerializablePermission forbidenPermission =
- new SerializablePermission("enableSubclassImplementation");
-
- public void checkPermission(Permission perm) {
- if (forbidenPermission.equals(perm)) {
- throw new SecurityException();
- }
- }
- };
-
- SecurityManager oldSm = System.getSecurityManager();
- System.setSecurityManager(sm);
- try {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- // should not cause SecurityException
- new ObjectOutputStream(out);
- // should not cause SecurityException
- class SubTest1 extends ObjectOutputStream {
- SubTest1(OutputStream out) throws IOException {
- super(out);
- }
- }
-
- // should not cause SecurityException
- new SubTest1(out);
- class SubTest2 extends ObjectOutputStream {
- SubTest2(OutputStream out) throws IOException {
- super(out);
- }
-
- public void writeUnshared(Object obj) throws IOException {
- }
- }
+ /**
+ * @tests java.io.ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)
+ */
+ public void test_ConstructorLjava_io_OutputStream_subtest0()
+ throws IOException {
+
+ // custom security manager
+ SecurityManager sm = new SecurityManager() {
+
+ final SerializablePermission forbidenPermission = new SerializablePermission(
+ "enableSubclassImplementation");
+
+ public void checkPermission(Permission perm) {
+ if (forbidenPermission.equals(perm)) {
+ throw new SecurityException();
+ }
+ }
+ };
+
+ SecurityManager oldSm = System.getSecurityManager();
+ System.setSecurityManager(sm);
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ // should not cause SecurityException
+ new ObjectOutputStream(out);
+ // should not cause SecurityException
+ class SubTest1 extends ObjectOutputStream {
+ SubTest1(OutputStream out) throws IOException {
+ super(out);
+ }
+ }
+
+ // should not cause SecurityException
+ new SubTest1(out);
+ class SubTest2 extends ObjectOutputStream {
+ SubTest2(OutputStream out) throws IOException {
+ super(out);
+ }
+
+ public void writeUnshared(Object obj) throws IOException {
+ }
+ }
try {
- new SubTest2(out);
- fail("should throw SecurityException 1");
- } catch (SecurityException e) {
- }
- class SubTest3 extends ObjectOutputStream {
- SubTest3(OutputStream out) throws IOException {
- super(out);
- }
-
- public PutField putFields() throws IOException {
- return null;
- }
- }
-
- try {
- new SubTest3(out);
- fail("should throw SecurityException 2");
- } catch (SecurityException e) {
- }
- } finally {
- System.setSecurityManager(oldSm);
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#close()
- */
- public void test_close() {
- // Test for method void java.io.ObjectOutputStream.close()
- }
-
- /**
- * @tests java.io.ObjectOutputStream#defaultWriteObject()
- */
- public void test_defaultWriteObject() throws IOException {
- // Test for method void java.io.ObjectOutputStream.defaultWriteObject()
- try {
- oos.defaultWriteObject();
+ new SubTest2(out);
+ fail("should throw SecurityException 1");
+ } catch (SecurityException e) {
+ }
+ class SubTest3 extends ObjectOutputStream {
+ SubTest3(OutputStream out) throws IOException {
+ super(out);
+ }
+
+ public PutField putFields() throws IOException {
+ return null;
+ }
+ }
+
+ try {
+ new SubTest3(out);
+ fail("should throw SecurityException 2");
+ } catch (SecurityException e) {
+ }
+ } finally {
+ System.setSecurityManager(oldSm);
+ }
+ }
+
+ /**
+ * @tests java.io.ObjectOutputStream#close()
+ */
+ public void test_close() {
+ // Test for method void java.io.ObjectOutputStream.close()
+ }
+
+ /**
+ * @tests java.io.ObjectOutputStream#defaultWriteObject()
+ */
+ public void test_defaultWriteObject() throws IOException {
+ // Test for method void java.io.ObjectOutputStream.defaultWriteObject()
+ try {
+ oos.defaultWriteObject();
fail("Failed to throw NotActiveException");
- } catch (NotActiveException e) {
- // Correct
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#flush()
- */
- public void test_flush() throws Exception {
+ } catch (NotActiveException e) {
+ // Correct
+ }
+ }
+
+ /**
+ * @tests java.io.ObjectOutputStream#flush()
+ */
+ public void test_flush() throws Exception {
// Test for method void java.io.ObjectOutputStream.flush()
int size = bao.size();
oos.writeByte(127);
@@ -675,21 +681,21 @@
oos = null;
}
- /**
- * @tests java.io.ObjectOutputStream#putFields()
- */
- public void test_putFields() throws Exception {
- // Test for method java.io.ObjectOutputStream$PutField
- // java.io.ObjectOutputStream.putFields()
-
- SerializableTestHelper sth;
-
- /*
- * "SerializableTestHelper" is an object created for these tests with
- * two fields (Strings) and simple implementations of readObject and
- * writeObject which simply read and write the first field but not the
- * second
- */
+ /**
+ * @tests java.io.ObjectOutputStream#putFields()
+ */
+ public void test_putFields() throws Exception {
+ // Test for method java.io.ObjectOutputStream$PutField
+ // java.io.ObjectOutputStream.putFields()
+
+ SerializableTestHelper sth;
+
+ /*
+ * "SerializableTestHelper" is an object created for these tests with
+ * two fields (Strings) and simple implementations of readObject and
+ * writeObject which simply read and write the first field but not the
+ * second
+ */
oos.writeObject(new SerializableTestHelper("Gabba", "Jabba"));
oos.flush();
@@ -702,10 +708,10 @@
sth.getText2());
}
- /**
- * @tests java.io.ObjectOutputStream#reset()
- */
- public void test_reset() throws Exception {
+ /**
+ * @tests java.io.ObjectOutputStream#reset()
+ */
+ public void test_reset() throws Exception {
// Test for method void java.io.ObjectOutputStream.reset()
String o = "HelloWorld";
oos.writeObject(o);
@@ -716,41 +722,41 @@
ois.close();
}
- private static class ExternalTest implements Externalizable {
- public String value;
+ private static class ExternalTest implements Externalizable {
+ public String value;
+
+ public ExternalTest() {
+ }
+
+ public void setValue(String val) {
+ value = val;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void writeExternal(ObjectOutput output) {
+ try {
+ output.writeUTF(value);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
- public ExternalTest() {
- }
+ public void readExternal(ObjectInput input) {
+ try {
+ value = input.readUTF();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
- public void setValue(String val) {
- value = val;
- }
-
- public String getValue() {
- return value;
- }
-
- public void writeExternal(ObjectOutput output) {
- try {
- output.writeUTF(value);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public void readExternal(ObjectInput input) {
- try {
- value = input.readUTF();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#useProtocolVersion(int)
- */
- public void test_useProtocolVersionI() throws Exception {
+ /**
+ * @tests java.io.ObjectOutputStream#useProtocolVersion(int)
+ */
+ public void test_useProtocolVersionI() throws Exception {
// Test for method void
// java.io.ObjectOutputStream.useProtocolVersion(int)
oos.useProtocolVersion(ObjectOutputStream.PROTOCOL_VERSION_1);
@@ -766,7 +772,8 @@
+ t2.getValue(), t1.getValue().equals(t2.getValue()));
// Cannot set protocol version when stream in-flight
- ObjectOutputStream out = new ObjectOutputStream(new ByteArrayOutputStream());
+ ObjectOutputStream out = new ObjectOutputStream(
+ new ByteArrayOutputStream());
out.writeObject("hello world");
try {
out.useProtocolVersion(ObjectStreamConstants.PROTOCOL_VERSION_1);
@@ -776,10 +783,10 @@
}
}
- /**
- * @tests java.io.ObjectOutputStream#write(byte[])
- */
- public void test_write$B() throws Exception {
+ /**
+ * @tests java.io.ObjectOutputStream#write(byte[])
+ */
+ public void test_write$B() throws Exception {
// Test for method void java.io.ObjectOutputStream.write(byte [])
byte[] buf = new byte[10];
oos.write("HelloWorld".getBytes());
@@ -791,7 +798,7 @@
10));
}
- /**
+ /**
* @tests java.io.ObjectOutputStream#write(byte[], int, int)
*/
public void test_write$BII() throws Exception {
@@ -979,10 +986,11 @@
out = new ObjectOutputStream(new ByteArrayOutputStream());
out.writeObject(new NotSerializable());
fail("Expected NotSerializableException");
- } catch (NotSerializableException e) {}
+ } catch (NotSerializableException e) {
+ }
out.writeObject(new ExternalizableWithReplace());
}
-
+
/**
* @tests {@link java.io.ObjectOutputStream#writeObjectOverride(Object)}
*/
@@ -1014,11 +1022,12 @@
ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
assertEquals("Wrote incorrect UTF value", "HelloWorld", ois.readUTF());
}
-
+
/**
* @tests java.io.ObjectOutputStream#writeObject(java.lang.Object)
*/
- public void test_writeObject_Exception() throws ClassNotFoundException, IOException {
+ public void test_writeObject_Exception() throws ClassNotFoundException,
+ IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
ObjectOutputStream oos = new ObjectOutputStream(baos);
@@ -1063,7 +1072,8 @@
if (oos != null) {
try {
oos.close();
- } catch (Exception e) {}
+ } catch (Exception e) {
+ }
}
if (f != null && f.exists()) {
if (!f.delete()) {
@@ -1149,7 +1159,8 @@
oos.close();
if (ois != null)
ois.close();
- } catch (IOException e) {}
+ } catch (IOException e) {
+ }
}
}
@@ -1157,7 +1168,7 @@
* @tests java.io.ObjectOutputStream#writeUnshared(java.lang.Object)
*/
public void test_writeUnshared() throws Exception {
- //Regression for HARMONY-187
+ // Regression for HARMONY-187
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
@@ -1167,7 +1178,8 @@
oos.writeObject(o);
oos.flush();
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
+ baos.toByteArray()));
Object[] oa = new Object[3];
for (int i = 0; i < oa.length; i++) {
@@ -1187,7 +1199,7 @@
* @tests java.io.ObjectOutputStream#writeUnshared(java.lang.Object)
*/
public void test_writeUnshared2() throws Exception {
- //Regression for HARMONY-187
+ // Regression for HARMONY-187
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
@@ -1197,7 +1209,8 @@
oos.writeObject(o);
oos.flush();
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
+ baos.toByteArray()));
Object[] oa = new Object[3];
for (int i = 0; i < oa.length; i++) {
@@ -1242,55 +1255,57 @@
* @tests java.io.ObjectOutputStream#replaceObject(java.lang.Object)
*/
public void test_replaceObject() throws Exception {
- //Regression for HARMONY-1429
+ // Regression for HARMONY-1429
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStreamWithReplace oos = new ObjectOutputStreamWithReplace(baos);
+ ObjectOutputStreamWithReplace oos = new ObjectOutputStreamWithReplace(
+ baos);
oos.writeObject(new NotSerializable());
oos.flush();
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
+ baos.toByteArray()));
Object obj = ois.readObject();
oos.close();
ois.close();
assertTrue("replaceObject has not been called", (obj instanceof Long));
- //Regression for HARMONY-2239
- Object replaceObject = int.class;
- baos = new ByteArrayOutputStream();
- ObjectOutputStreamWithReplace2 oos2 = new ObjectOutputStreamWithReplace2(
- baos);
- oos2.writeObject(new WriteReplaceObject(replaceObject));
- oos2.flush();
- ois = new ObjectInputStream(
- new ByteArrayInputStream(baos.toByteArray()));
- obj = ois.readObject();
- oos.close();
- ois.close();
- assertTrue("replaceObject has not been called", (obj instanceof Long));
-
- replaceObject = ObjectStreamClass.lookup(Integer.class);
- baos = new ByteArrayOutputStream();
- oos2 = new ObjectOutputStreamWithReplace2(baos);
- oos2.writeObject(new WriteReplaceObject(replaceObject));
- oos2.flush();
- ois = new ObjectInputStream(
- new ByteArrayInputStream(baos.toByteArray()));
- obj = ois.readObject();
- oos.close();
- ois.close();
- assertTrue("replaceObject has not been called", (obj instanceof Long));
-
- replaceObject = WriteReplaceObject.Color.red;
- baos = new ByteArrayOutputStream();
- oos2 = new ObjectOutputStreamWithReplace2(baos);
- oos2.writeObject(new WriteReplaceObject(replaceObject));
- oos2.flush();
- ois = new ObjectInputStream(
- new ByteArrayInputStream(baos.toByteArray()));
- obj = ois.readObject();
- oos.close();
- ois.close();
- assertTrue("replaceObject has not been called", (obj instanceof Long));
+ // Regression for HARMONY-2239
+ Object replaceObject = int.class;
+ baos = new ByteArrayOutputStream();
+ ObjectOutputStreamWithReplace2 oos2 = new ObjectOutputStreamWithReplace2(
+ baos);
+ oos2.writeObject(new WriteReplaceObject(replaceObject));
+ oos2.flush();
+ ois = new ObjectInputStream(
+ new ByteArrayInputStream(baos.toByteArray()));
+ obj = ois.readObject();
+ oos.close();
+ ois.close();
+ assertTrue("replaceObject has not been called", (obj instanceof Long));
+
+ replaceObject = ObjectStreamClass.lookup(Integer.class);
+ baos = new ByteArrayOutputStream();
+ oos2 = new ObjectOutputStreamWithReplace2(baos);
+ oos2.writeObject(new WriteReplaceObject(replaceObject));
+ oos2.flush();
+ ois = new ObjectInputStream(
+ new ByteArrayInputStream(baos.toByteArray()));
+ obj = ois.readObject();
+ oos.close();
+ ois.close();
+ assertTrue("replaceObject has not been called", (obj instanceof Long));
+
+ replaceObject = WriteReplaceObject.Color.red;
+ baos = new ByteArrayOutputStream();
+ oos2 = new ObjectOutputStreamWithReplace2(baos);
+ oos2.writeObject(new WriteReplaceObject(replaceObject));
+ oos2.flush();
+ ois = new ObjectInputStream(
+ new ByteArrayInputStream(baos.toByteArray()));
+ obj = ois.readObject();
+ oos.close();
+ ois.close();
+ assertTrue("replaceObject has not been called", (obj instanceof Long));
// Regression for HARMONY-3158
Object obj1;
@@ -1305,7 +1320,8 @@
oos.writeObject(ObjectStreamClass.lookup(Integer.class));
oos.flush();
- ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
+ ois = new ObjectInputStream(
+ new ByteArrayInputStream(baos.toByteArray()));
obj1 = ois.readObject();
obj2 = ois.readObject();
obj3 = ois.readObject();
@@ -1313,10 +1329,11 @@
ois.close();
assertTrue("1st replaceObject worked incorrectly", obj1 instanceof Long);
- assertEquals("1st replaceObject worked incorrectly",
- 99, ((Long) obj1).longValue());
- assertEquals("2nd replaceObject worked incorrectly", Integer.class, obj2);
+ assertEquals("1st replaceObject worked incorrectly", 99, ((Long) obj1)
+ .longValue());
+ assertEquals("2nd replaceObject worked incorrectly", Integer.class,
+ obj2);
assertEquals("3rd replaceObject worked incorrectly",
ObjectStreamClass.class, obj3.getClass());
- }
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java Mon Jan 28 04:07:47 2008
@@ -22,113 +22,113 @@
import java.io.Serializable;
import java.lang.reflect.Proxy;
-public class ObjectStreamClassTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
- static class DummyClass implements Serializable {
- private static final long serialVersionUID = 999999999999999L;
+public class ObjectStreamClassTest extends TestCase {
- long bam = 999L;
+ static class DummyClass implements Serializable {
+ private static final long serialVersionUID = 999999999999999L;
- int ham = 9999;
+ long bam = 999L;
- public static long getUID() {
- return serialVersionUID;
- }
- }
-
- /**
- * @tests java.io.ObjectStreamClass#forClass()
- */
- public void test_forClass() {
- // Test for method java.lang.Class java.io.ObjectStreamClass.forClass()
- // Need to test during serialization to be sure an instance is
- // returned
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertTrue("forClass returned an object: " + osc.forClass(), osc
- .forClass().equals(DummyClass.class));
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getField(java.lang.String)
- */
- public void test_getFieldLjava_lang_String() {
- // Test for method java.io.ObjectStreamField
- // java.io.ObjectStreamClass.getField(java.lang.String)
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertEquals("getField did not return correct field", 'J', osc.getField("bam")
- .getTypeCode());
- assertNull("getField did not null for non-existent field", osc
- .getField("wham"));
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getFields()
- */
- public void test_getFields() {
- // Test for method java.io.ObjectStreamField []
- // java.io.ObjectStreamClass.getFields()
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- ObjectStreamField[] osfArray = osc.getFields();
- assertTrue(
- "Array of fields should be of length 2 but is instead of length: "
- + osfArray.length, osfArray.length == 2);
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getName()
- */
- public void test_getName() {
- // Test for method java.lang.String java.io.ObjectStreamClass.getName()
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertTrue("getName returned incorrect name: " + osc.getName(), osc
- .getName().equals(
- "org.apache.harmony.luni.tests.java.io.ObjectStreamClassTest$DummyClass"));
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getSerialVersionUID()
- */
- public void test_getSerialVersionUID() {
- // Test for method long java.io.ObjectStreamClass.getSerialVersionUID()
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertTrue("getSerialversionUID returned incorrect uid: "
- + osc.getSerialVersionUID() + " instead of "
- + DummyClass.getUID(), osc.getSerialVersionUID() == DummyClass
- .getUID());
- }
-
- /**
- * @tests java.io.ObjectStreamClass#lookup(java.lang.Class)
- */
- public void test_lookupLjava_lang_Class() {
- // Test for method java.io.ObjectStreamClass
- // java.io.ObjectStreamClass.lookup(java.lang.Class)
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertTrue("lookup returned wrong class: " + osc.getName(), osc
- .getName().equals(
- "org.apache.harmony.luni.tests.java.io.ObjectStreamClassTest$DummyClass"));
- }
-
- /**
- * @tests java.io.ObjectStreamClass#toString()
- */
- public void test_toString() {
- // Test for method java.lang.String java.io.ObjectStreamClass.toString()
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- String oscString = osc.toString();
- // The previous test was more specific than the spec so it was replaced
- // with the test below
- assertTrue("toString returned incorrect string: " + osc.toString(),
- oscString.indexOf("serialVersionUID") >= 0
- && oscString.indexOf("999999999999999L") >= 0);
- ;
- }
+ int ham = 9999;
+
+ public static long getUID() {
+ return serialVersionUID;
+ }
+ }
+
+ /**
+ * @tests java.io.ObjectStreamClass#forClass()
+ */
+ public void test_forClass() {
+ // Need to test during serialization to be sure an instance is
+ // returned
+ ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
+ assertTrue("forClass returned an object: " + osc.forClass(), osc
+ .forClass().equals(DummyClass.class));
+ }
+
+ /**
+ * @tests java.io.ObjectStreamClass#getField(java.lang.String)
+ */
+ public void test_getFieldLjava_lang_String() {
+ ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
+ assertEquals("getField did not return correct field", 'J', osc
+ .getField("bam").getTypeCode());
+ assertNull("getField did not null for non-existent field", osc
+ .getField("wham"));
+ }
+
+ /**
+ * @tests java.io.ObjectStreamClass#getFields()
+ */
+ public void test_getFields() {
+ ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
+ ObjectStreamField[] osfArray = osc.getFields();
+ assertTrue(
+ "Array of fields should be of length 2 but is instead of length: "
+ + osfArray.length, osfArray.length == 2);
+ }
+
+ /**
+ * @tests java.io.ObjectStreamClass#getName()
+ */
+ public void test_getName() {
+ ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
+ assertTrue(
+ "getName returned incorrect name: " + osc.getName(),
+ osc
+ .getName()
+ .equals(
+ "org.apache.harmony.luni.tests.java.io.ObjectStreamClassTest$DummyClass"));
+ }
+
+ /**
+ * @tests java.io.ObjectStreamClass#getSerialVersionUID()
+ */
+ public void test_getSerialVersionUID() {
+ ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
+ assertTrue("getSerialversionUID returned incorrect uid: "
+ + osc.getSerialVersionUID() + " instead of "
+ + DummyClass.getUID(), osc.getSerialVersionUID() == DummyClass
+ .getUID());
+ }
+
+ /**
+ * @tests java.io.ObjectStreamClass#lookup(java.lang.Class)
+ */
+ public void test_lookupLjava_lang_Class() {
+ ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
+ assertTrue(
+ "lookup returned wrong class: " + osc.getName(),
+ osc
+ .getName()
+ .equals(
+ "org.apache.harmony.luni.tests.java.io.ObjectStreamClassTest$DummyClass"));
+ }
+
+ /**
+ * @tests java.io.ObjectStreamClass#toString()
+ */
+ public void test_toString() {
+ ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
+ String oscString = osc.toString();
+
+ // The previous test was more specific than the spec so it was replaced
+ // with the test below
+ assertTrue("toString returned incorrect string: " + osc.toString(),
+ oscString.indexOf("serialVersionUID") >= 0
+ && oscString.indexOf("999999999999999L") >= 0);
+ ;
+ }
public void testSerialization() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(ObjectStreamClass.class);
+ ObjectStreamClass osc = ObjectStreamClass
+ .lookup(ObjectStreamClass.class);
assertEquals(0, osc.getFields().length);
}
-
+
public void test_specialTypes() {
Class<?> proxyClass = Proxy.getProxyClass(this.getClass()
.getClassLoader(), new Class[] { Runnable.class });
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java Mon Jan 28 04:07:47 2008
@@ -17,28 +17,29 @@
package org.apache.harmony.luni.tests.java.io;
import java.io.ObjectStreamConstants;
+
import junit.framework.TestCase;
public class ObjectStreamConstantsTest extends TestCase {
- /**
- * @tests java.io.ObjectStreamConstants#TC_ENUM
- */
- public void test_TC_ENUM() {
- assertEquals(126, ObjectStreamConstants.TC_ENUM);
- }
+ /**
+ * @tests java.io.ObjectStreamConstants#TC_ENUM
+ */
+ public void test_TC_ENUM() {
+ assertEquals(126, ObjectStreamConstants.TC_ENUM);
+ }
- /**
- * @tests java.io.ObjectStreamConstants#SC_ENUM
- */
- public void test_SC_ENUM() {
- assertEquals(16, ObjectStreamConstants.SC_ENUM);
- }
+ /**
+ * @tests java.io.ObjectStreamConstants#SC_ENUM
+ */
+ public void test_SC_ENUM() {
+ assertEquals(16, ObjectStreamConstants.SC_ENUM);
+ }
- /**
- * @tests java.io.ObjectStreamConstants#TC_MAX
- */
- public void test_TC_MAX() {
- assertEquals(126, ObjectStreamConstants.TC_MAX);
- }
+ /**
+ * @tests java.io.ObjectStreamConstants#TC_MAX
+ */
+ public void test_TC_MAX() {
+ assertEquals(126, ObjectStreamConstants.TC_MAX);
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java Mon Jan 28 04:07:47 2008
@@ -32,133 +32,125 @@
public class ObjectStreamFieldTest extends junit.framework.TestCase {
- static class DummyClass implements Serializable {
- private static final long serialVersionUID = 999999999999998L;
+ static class DummyClass implements Serializable {
+ private static final long serialVersionUID = 999999999999998L;
- long bam = 999L;
+ long bam = 999L;
- int ham = 9999;
+ int ham = 9999;
- int sam = 8888;
+ int sam = 8888;
+
+ Object hola = new Object();
+
+ public static long getUID() {
+ return serialVersionUID;
+ }
+ }
+
+ ObjectStreamClass osc;
+
+ ObjectStreamField hamField;
+
+ ObjectStreamField samField;
+
+ ObjectStreamField bamField;
+
+ ObjectStreamField holaField;
+
+ /**
+ * @tests java.io.ObjectStreamField#ObjectStreamField(java.lang.String,
+ * java.lang.Class)
+ */
+ public void test_ConstructorLjava_lang_StringLjava_lang_Class() {
+ assertTrue("Used to test", true);
+ }
+
+ public void test_equalsLjava_lang_Object() {
+ // Regression test for HARMONY-4273
+ assertTrue(samField.equals(samField));
+ assertFalse(samField.equals(hamField));
+ assertFalse(samField.equals("fish"));
+ assertFalse(samField.equals(null));
+ }
+
+ /**
+ * @tests java.io.ObjectStreamField#compareTo(java.lang.Object)
+ */
+ public void test_compareToLjava_lang_Object() {
+ assertTrue("Object compared to int did not return > 0", holaField
+ .compareTo(hamField) > 0);
+ assertEquals("Int compared to itself did not return 0", 0, hamField
+ .compareTo(hamField));
+ assertTrue("(Int)ham compared to (Int)sam did not return < 0", hamField
+ .compareTo(samField) < 0);
+ }
+
+ /**
+ * @tests java.io.ObjectStreamField#getName()
+ */
+ public void test_getName() {
+ assertEquals("Field did not return correct name", "hola", holaField
+ .getName());
+ }
+
+ /**
+ * @tests java.io.ObjectStreamField#getOffset()
+ */
+ public void test_getOffset() {
+ ObjectStreamField[] osfArray;
+ osfArray = osc.getFields();
+ assertTrue("getOffset did not return reasonable values", osfArray[0]
+ .getOffset() != osfArray[1].getOffset());
+ assertEquals("getOffset for osfArray[0].getOffset() did not return 0",
+ 0, osfArray[0].getOffset());
+ assertEquals("osfArray[1].getOffset() did not return 8", 8, osfArray[1]
+ .getOffset());
+ assertEquals("osfArray[2].getOffset() did not return 12", 12,
+ osfArray[2].getOffset());
+ }
+
+ /**
+ * @tests java.io.ObjectStreamField#getType()
+ */
+ public void test_getType() {
+ assertTrue("getType on an Object field did not answer Object",
+ holaField.getType().equals(Object.class));
+ }
+
+ /**
+ * @tests java.io.ObjectStreamField#getTypeCode()
+ */
+ public void test_getTypeCode() {
+ assertEquals("getTypeCode on an Object field did not answer 'L'", 'L',
+ holaField.getTypeCode());
+ assertEquals("getTypeCode on a long field did not answer 'J'", 'J',
+ bamField.getTypeCode());
+ }
+
+ /**
+ * @tests java.io.ObjectStreamField#getTypeString()
+ */
+ public void test_getTypeString() {
+ assertTrue("getTypeString returned: " + holaField.getTypeString(),
+ holaField.getTypeString().indexOf("Object") >= 0);
+ assertNull("Primitive types' strings should be null", hamField
+ .getTypeString());
- Object hola = new Object();
-
- public static long getUID() {
- return serialVersionUID;
- }
- }
-
- ObjectStreamClass osc;
-
- ObjectStreamField hamField;
-
- ObjectStreamField samField;
-
- ObjectStreamField bamField;
-
- ObjectStreamField holaField;
-
- /**
- * @tests java.io.ObjectStreamField#ObjectStreamField(java.lang.String,
- * java.lang.Class)
- */
- public void test_ConstructorLjava_lang_StringLjava_lang_Class() {
- // Test for method java.io.ObjectStreamField(java.lang.String,
- // java.lang.Class)
- assertTrue("Used to test", true);
- }
-
- public void test_equalsLjava_lang_Object() {
- // Regression test for HARMONY-4273
- assertTrue(samField.equals(samField));
- assertFalse(samField.equals(hamField));
- assertFalse(samField.equals("fish"));
- assertFalse(samField.equals(null));
- }
-
- /**
- * @tests java.io.ObjectStreamField#compareTo(java.lang.Object)
- */
- public void test_compareToLjava_lang_Object() {
- // Test for method int
- // java.io.ObjectStreamField.compareTo(java.lang.Object)
- assertTrue("Object compared to int did not return > 0", holaField
- .compareTo(hamField) > 0);
- assertEquals("Int compared to itself did not return 0", 0, hamField
- .compareTo(hamField));
- assertTrue("(Int)ham compared to (Int)sam did not return < 0", hamField
- .compareTo(samField) < 0);
- }
-
- /**
- * @tests java.io.ObjectStreamField#getName()
- */
- public void test_getName() {
- // Test for method java.lang.String java.io.ObjectStreamField.getName()
- assertEquals("Field did not return correct name", "hola", holaField.getName()
- );
- }
-
- /**
- * @tests java.io.ObjectStreamField#getOffset()
- */
- public void test_getOffset() {
- // Test for method int java.io.ObjectStreamField.getOffset()
- ObjectStreamField[] osfArray;
- osfArray = osc.getFields();
- assertTrue("getOffset did not return reasonable values", osfArray[0]
- .getOffset() != osfArray[1].getOffset());
- assertEquals("getOffset for osfArray[0].getOffset() did not return 0",
- 0, osfArray[0].getOffset());
- assertEquals("osfArray[1].getOffset() did not return 8", 8, osfArray[1]
- .getOffset());
- assertEquals("osfArray[2].getOffset() did not return 12", 12, osfArray[2]
- .getOffset());
- }
-
- /**
- * @tests java.io.ObjectStreamField#getType()
- */
- public void test_getType() {
- // Test for method java.lang.Class java.io.ObjectStreamField.getType()
- assertTrue("getType on an Object field did not answer Object",
- holaField.getType().equals(Object.class));
- }
-
- /**
- * @tests java.io.ObjectStreamField#getTypeCode()
- */
- public void test_getTypeCode() {
- // Test for method char java.io.ObjectStreamField.getTypeCode()
- assertEquals("getTypeCode on an Object field did not answer 'L'",
- 'L', holaField.getTypeCode());
- assertEquals("getTypeCode on a long field did not answer 'J'", 'J', bamField
- .getTypeCode());
- }
-
- /**
- * @tests java.io.ObjectStreamField#getTypeString()
- */
- public void test_getTypeString() {
- assertTrue("getTypeString returned: " + holaField.getTypeString(),
- holaField.getTypeString().indexOf("Object") >= 0);
- assertNull("Primitive types' strings should be null", hamField.getTypeString());
-
ObjectStreamField osf = new ObjectStreamField("s", String.class, true);
assertTrue(osf.getTypeString() == "Ljava/lang/String;");
- }
+ }
- /**
- * @tests java.io.ObjectStreamField#toString()
- */
- public void test_toString() {
- // Test for method java.lang.String java.io.ObjectStreamField.toString()
- assertTrue("toString on a long returned: " + bamField.toString(),
- bamField.toString().indexOf("bam") >= 0);
- }
-
/**
- * @tests java.io.ObjectStreamField#getType()
+ * @tests java.io.ObjectStreamField#toString()
+ */
+ public void test_toString() {
+ assertTrue("toString on a long returned: " + bamField.toString(),
+ bamField.toString().indexOf("bam") >= 0);
+ }
+
+ /**
+ * @tests java.io.ObjectStreamField#getType()
*/
public void test_getType_Deserialized() throws IOException,
ClassNotFoundException {
@@ -177,11 +169,12 @@
ObjectStreamField field = oc.getField("i");
assertEquals(Object.class, field.getType());
}
-
+
/**
* @tests java.io.ObjectStreamField#getType()
*/
- public void test_getType_MockObjectInputStream() throws IOException, ClassNotFoundException {
+ public void test_getType_MockObjectInputStream() throws IOException,
+ ClassNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(new SerializableObject());
@@ -197,10 +190,10 @@
ObjectStreamField field = oc.getField("i");
assertEquals(Object.class, field.getType());
}
-
+
public void test_isUnshared() throws Exception {
SerializableObject2 obj = new SerializableObject2();
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
@@ -210,43 +203,36 @@
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
SerializableObject2 newObj = (SerializableObject2) ois.readObject();
-
+
ObjectInputStream.GetField getField = newObj.getGetField();
ObjectStreamClass objectStreamClass = getField.getObjectStreamClass();
-
+
assertTrue(objectStreamClass.getField("i").isUnshared());
assertFalse(objectStreamClass.getField("d").isUnshared());
assertTrue(objectStreamClass.getField("s").isUnshared());
-
+
assertEquals(1000, getField.get("i", null));
assertEquals(SerializableObject2.today, getField.get("d", null));
assertEquals("Richard", getField.get("s", null));
-
+
assertTrue(objectStreamClass.getField("s").getTypeString() == "Ljava/lang/String;");
-
+
assertEquals(0, objectStreamClass.getField("d").getOffset());
assertEquals(1, objectStreamClass.getField("i").getOffset());
assertEquals(2, objectStreamClass.getField("s").getOffset());
}
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- osc = ObjectStreamClass.lookup(DummyClass.class);
- bamField = osc.getField("bam");
- samField = osc.getField("sam");
- hamField = osc.getField("ham");
- holaField = osc.getField("hola");
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ osc = ObjectStreamClass.lookup(DummyClass.class);
+ bamField = osc.getField("bam");
+ samField = osc.getField("sam");
+ hamField = osc.getField("ham");
+ holaField = osc.getField("hola");
+ }
}
class SerializableObject implements Serializable {
@@ -257,9 +243,9 @@
public Date d;
public Integer i;
-
+
public Exception e;
-
+
public SerializableObject() {
d = new Date();
i = new Integer(1);
@@ -299,7 +285,7 @@
public ObjectStreamClass readClassDescriptor() throws IOException,
ClassNotFoundException {
ObjectStreamClass osc = super.readClassDescriptor();
- //To get the ObjectStreamClass of SerializableObject
+ // To get the ObjectStreamClass of SerializableObject
if (osc.getSerialVersionUID() == -2953957835918368056L) {
temp = osc;
}
@@ -314,21 +300,20 @@
class SerializableObject2 implements Serializable {
private static final long serialVersionUID = 1L;
-
+
private static final ObjectStreamField[] serialPersistentFields = {
- new ObjectStreamField("i", Integer.class, true),
- new ObjectStreamField("d", Date.class, false),
- new ObjectStreamField("s", String.class, true),
- };
-
+ new ObjectStreamField("i", Integer.class, true),
+ new ObjectStreamField("d", Date.class, false),
+ new ObjectStreamField("s", String.class, true), };
+
private ObjectInputStream.GetField getField;
-
+
public static Date today = new Date(1172632429156l);
-
+
public ObjectInputStream.GetField getGetField() {
return getField;
}
-
+
private void writeObject(ObjectOutputStream o) throws IOException {
ObjectOutputStream.PutField putField = o.putFields();
putField.put("i", new Integer(1000));
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OpenRandomFileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OpenRandomFileTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OpenRandomFileTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OpenRandomFileTest.java Mon Jan 28 04:07:47 2008
@@ -23,47 +23,36 @@
import junit.framework.TestCase;
-/**
- * TODO Type description
- */
public class OpenRandomFileTest extends TestCase {
- public static void main(String[] args) {
- new OpenRandomFileTest().testOpenEmptyFile();
- }
-
- public OpenRandomFileTest() {
- super();
- }
-
- public void testOpenNonEmptyFile() {
- try {
- File file = File.createTempFile("test", "tmp");
- assertTrue(file.exists());
- file.deleteOnExit();
- FileOutputStream fos = new FileOutputStream(file);
- fos.write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
- fos.close();
-
- String fileName = file.getCanonicalPath();
- RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
- raf.close();
- } catch (IOException ex) {
- fail(ex.getLocalizedMessage());
- }
- }
-
- public void testOpenEmptyFile() {
- try {
- File file = File.createTempFile("test", "tmp");
- assertTrue(file.exists());
- file.deleteOnExit();
-
- String fileName = file.getCanonicalPath();
- RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
- raf.close();
- } catch (IOException ex) {
- fail(ex.getLocalizedMessage());
- }
- }
+ public static void main(String[] args) throws IOException {
+ new OpenRandomFileTest().testOpenEmptyFile();
+ }
+
+ public OpenRandomFileTest() {
+ super();
+ }
+
+ public void testOpenNonEmptyFile() throws IOException {
+ File file = File.createTempFile("test", "tmp");
+ assertTrue(file.exists());
+ file.deleteOnExit();
+ FileOutputStream fos = new FileOutputStream(file);
+ fos.write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
+ fos.close();
+
+ String fileName = file.getCanonicalPath();
+ RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
+ raf.close();
+ }
+
+ public void testOpenEmptyFile() throws IOException {
+ File file = File.createTempFile("test", "tmp");
+ assertTrue(file.exists());
+ file.deleteOnExit();
+
+ String fileName = file.getCanonicalPath();
+ RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
+ raf.close();
+ }
}
|