harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r518898 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
Date Fri, 16 Mar 2007 09:20:05 GMT
Author: liangyx
Date: Fri Mar 16 02:20:04 2007
New Revision: 518898

URL: http://svn.apache.org/viewvc?view=rev&rev=518898
Log:
Apply patch for HARMONY-3400([classlib][luni] Add testcase for ObjectInputStream's resolveObject(Object)
function)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java?view=diff&rev=518898&r1=518897&r2=518898
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
Fri Mar 16 02:20:04 2007
@@ -773,6 +773,47 @@
         }
     }
 	
+    static class ObjectInputStreamWithResolveObject extends ObjectInputStream {
+        
+        public static Integer intObj = Integer.valueOf(1000);
+        
+        public ObjectInputStreamWithResolveObject(InputStream in) throws IOException {
+            super(in);
+            enableResolveObject(true);
+        }
+        
+        protected Object resolveObject(Object obj) throws IOException {
+            if(obj instanceof Integer){
+                obj = intObj;
+            }
+            return super.resolveObject(obj);
+        }        
+    }
+    
+    /**
+     * @tests java.io.ObjectInputStream#resolveObject(Object)
+     */
+    public void test_resolveObjectLjava_lang_Object() throws Exception {
+        // Write an Integer object into memory
+        Integer original = new Integer(10);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(original);
+        oos.flush();
+        oos.close();
+
+        // Read the object from memory
+        byte[] bytes = baos.toByteArray();
+        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+        ObjectInputStreamWithResolveObject ois = 
+            new ObjectInputStreamWithResolveObject(bais);
+        Integer actual = (Integer) ois.readObject();
+        ois.close();
+
+        // object should be resolved from 10 to 1000 
+        assertEquals(ObjectInputStreamWithResolveObject.intObj, actual);
+    }
+    
 	public void test_readClassDescriptor() throws IOException,
 			ClassNotFoundException {
 



Mime
View raw message