harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r694221 - in /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io: BufferedReaderTest.java ObjectStreamClassTest.java
Date Thu, 11 Sep 2008 12:04:12 GMT
Author: tellison
Date: Thu Sep 11 05:04:10 2008
New Revision: 694221

URL: http://svn.apache.org/viewvc?rev=694221&view=rev
Log:
Apply patch for HARMONY-5980 ([classlib][luni] - add some tests for BufferedReader and ObjectStreamClass)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java?rev=694221&r1=694220&r2=694221&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java
Thu Sep 11 05:04:10 2008
@@ -194,11 +194,27 @@
 		char[] ca = new char[2];
 		BufferedReader toRet = new BufferedReader(new InputStreamReader(
 				new ByteArrayInputStream(new byte[0])));
+		
+		/* Null buffer should throw NPE even when len == 0 */
+		try {
+			toRet.read(null, 1, 0);
+			fail("null buffer reading zero bytes should throw NPE");
+		} catch (NullPointerException e) {
+			//expected
+		}
+		
 		try {
 			toRet.close();
 		} catch (IOException e) {
 			fail("unexpected 1: " + e);
 		}
+		
+		try {
+			toRet.read(null, 1, 0);
+			fail("null buffer reading zero bytes on closed stream should throw IOException");
+		} catch (IOException e) {
+			//expected
+		}
 
 		/* Closed reader should throw IOException reading zero bytes */
 		try {

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=694221&r1=694220&r2=694221&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
Thu Sep 11 05:04:10 2008
@@ -17,10 +17,13 @@
 
 package org.apache.harmony.luni.tests.java.io;
 
+import java.io.File;
 import java.io.ObjectStreamClass;
 import java.io.ObjectStreamField;
 import java.io.Serializable;
 import java.lang.reflect.Proxy;
+import java.net.URL;
+import java.net.URLClassLoader;
 
 import junit.framework.TestCase;
 
@@ -45,8 +48,8 @@
         // 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));
+        assertEquals("forClass returned an object: " + osc.forClass(),
+                DummyClass.class, osc.forClass());
     }
 
     /**
@@ -66,9 +69,9 @@
     public void test_getFields() {
         ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
         ObjectStreamField[] osfArray = osc.getFields();
-        assertTrue(
+        assertEquals(
                 "Array of fields should be of length 2 but is instead of length: "
-                        + osfArray.length, osfArray.length == 2);
+                        + osfArray.length, 2, osfArray.length);
     }
 
     /**
@@ -76,12 +79,10 @@
      */
     public void test_getName() {
         ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
-        assertTrue(
+        assertEquals(
                 "getName returned incorrect name: " + osc.getName(),
-                osc
-                        .getName()
-                        .equals(
-                                "org.apache.harmony.luni.tests.java.io.ObjectStreamClassTest$DummyClass"));
+                "org.apache.harmony.luni.tests.java.io.ObjectStreamClassTest$DummyClass",
+                osc.getName());
     }
 
     /**
@@ -89,10 +90,61 @@
      */
     public void test_getSerialVersionUID() {
         ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
-        assertTrue("getSerialversionUID returned incorrect uid: "
+        assertEquals("getSerialversionUID returned incorrect uid: "
                 + osc.getSerialVersionUID() + " instead of "
-                + DummyClass.getUID(), osc.getSerialVersionUID() == DummyClass
-                .getUID());
+                + DummyClass.getUID(), DummyClass.getUID(), osc
+                .getSerialVersionUID());
+    }
+
+    static class SyntheticTest implements Serializable {
+        private int i;
+
+        private class X implements Serializable {
+            public int get() {
+                return i;
+            }
+        }
+
+        public X foo() {
+            return new X();
+        }
+    }
+
+    /**
+     * @tests java.io.ObjectStreamClass#getSerialVersionUID()
+     */
+    public void test_getSerialVersionUID_inner_private_class() {
+        ObjectStreamClass osc1 = ObjectStreamClass.lookup(SyntheticTest.class);
+        assertEquals("SyntheticTest unexpected UID: "
+                + osc1.getSerialVersionUID(), -7784078941584535183L, osc1
+                .getSerialVersionUID());
+
+        ObjectStreamClass osc2 = ObjectStreamClass
+                .lookup(SyntheticTest.X.class);
+        assertEquals("SyntheticTest.X unexpected UID: "
+                + osc2.getSerialVersionUID(), -7703000075736397332L, osc2
+                .getSerialVersionUID());
+    }
+
+    /**
+     * @tests java.io.ObjectStreamClass#getSerialVersionUID()
+     */
+    public void test_getSerialVersionUID_classloader() throws Exception {
+        File file = new File(
+                "src/test/resources/org/apache/harmony/luni/tests/ObjectStreamClassTest.jar");
+        ClassLoader loader = new URLClassLoader(new URL[] { file.toURL() },
+                null);
+        Class cl1 = Class.forName("Test1$TestVarArgs", false, loader);
+        ObjectStreamClass osc1 = ObjectStreamClass.lookup(cl1);
+        assertEquals("Test1$TestVarArgs unexpected UID: "
+                + osc1.getSerialVersionUID(), -6051121963037986215L, osc1
+                .getSerialVersionUID());
+
+        Class cl2 = Class.forName("Test1$TestBridge", false, loader);
+        ObjectStreamClass osc2 = ObjectStreamClass.lookup(cl2);
+        assertEquals("Test1$TestBridge unexpected UID: "
+                + osc2.getSerialVersionUID(), 568585976855071180L, osc2
+                .getSerialVersionUID());
     }
 
     /**
@@ -100,12 +152,10 @@
      */
     public void test_lookupLjava_lang_Class() {
         ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
-        assertTrue(
+        assertEquals(
                 "lookup returned wrong class: " + osc.getName(),
-                osc
-                        .getName()
-                        .equals(
-                                "org.apache.harmony.luni.tests.java.io.ObjectStreamClassTest$DummyClass"));
+                "org.apache.harmony.luni.tests.java.io.ObjectStreamClassTest$DummyClass",
+                osc.getName());
     }
 
     /**
@@ -120,7 +170,6 @@
         assertTrue("toString returned incorrect string: " + osc.toString(),
                 oscString.indexOf("serialVersionUID") >= 0
                         && oscString.indexOf("999999999999999L") >= 0);
-        ;
     }
 
     public void testSerialization() {



Mime
View raw message