harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r614506 - /harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/
Date Wed, 23 Jan 2008 11:48:50 GMT
Author: tonywu
Date: Wed Jan 23 03:48:43 2008
New Revision: 614506

URL: http://svn.apache.org/viewvc?rev=614506&view=rev
Log:
Retrieve the IO testcases lost in latest merge from trunk.

Modified:
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/IOExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedReaderTest.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintStreamTest.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintWriterTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/IOExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/IOExceptionTest.java?rev=614506&r1=614505&r2=614506&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/IOExceptionTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/IOExceptionTest.java
Wed Jan 23 03:48:43 2008
@@ -51,6 +51,52 @@
 		fail("Failed to generate exception");
 	}
 
+    /**
+     * @tests java.io.IOException#IOException(java.lang.String,
+     *        java.lang.Throwable)
+     * @since 1.6
+     */
+    public void test_ConstructorLString_LThrowable() {
+        // Test for constructor java.io.IOException(java.lang.String, java.lang.Throwable)
+
+        IOException ioException = new IOException(
+                "A dummy IOException", new Throwable("A dummy Throwable")); //$NON-NLS-1$//$NON-NLS-2$
+        assertEquals("A dummy IOException", ioException.getMessage()); //$NON-NLS-1$
+
+        try {
+            throw new IOException(
+                    "A dummy error", new Throwable("Some error message")); //$NON-NLS-1$
//$NON-NLS-2$
+        } catch (IOException e) {
+            return;
+        } catch (Exception e) {
+            fail("Exception during IOException test" + e.toString()); //$NON-NLS-1$
+        }
+        fail("Failed to generate exception"); //$NON-NLS-1$
+    }
+
+    /**
+     * @tests java.io.IOException#IOException(java.lang.Throwable)
+     * @since 1.6
+     */
+    public void test_Constructor_LThrowable() {
+        // Test for constructor java.io.IOException(java.lang.Throwable)
+        Throwable cause = new Throwable("A dummy Throwable"); //$NON-NLS-1$
+        IOException ioException = new IOException(cause); 
+        assertEquals(cause.toString(), ioException.getMessage());
+        
+        ioException = new IOException((Throwable)null);
+        assertNull(ioException.getMessage());
+        
+        try {
+            throw new IOException(new Throwable("Some error message")); //$NON-NLS-1$
+        } catch (IOException e) {
+            return;
+        } catch (Exception e) {
+            fail("Exception during IOException test" + e.toString()); //$NON-NLS-1$
+        }
+        fail("Failed to generate exception"); //$NON-NLS-1$
+    }
+    
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method
 	 * is called before a test is executed.

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java?rev=614506&r1=614505&r2=614506&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java
Wed Jan 23 03:48:43 2008
@@ -17,6 +17,10 @@
 
 package org.apache.harmony.luni.tests.java.io;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.io.ObjectStreamClass;
 import java.io.ObjectStreamField;
 import java.io.Serializable;
@@ -35,6 +39,33 @@
 			return serialVersionUID;
 		}
 	}
+    
+    /**
+     * @since 1.6 
+     */
+    static class NonSerialzableClass {
+        private static final long serialVersionUID = 1l;
+        public static long getUID() {
+            return serialVersionUID;
+        }
+    }
+    
+    /**
+     * @since 1.6
+     */
+    static class ExternalizableClass implements Externalizable {
+
+        private static final long serialVersionUID = -4285635779249689129L;
+
+        public void readExternal(ObjectInput input) throws IOException, ClassNotFoundException
{
+            throw new ClassNotFoundException();
+        }
+
+        public void writeExternal(ObjectOutput output) throws IOException {
+            throw new IOException();
+        }
+        
+	}
 
 	/**
 	 * @tests java.io.ObjectStreamClass#forClass()
@@ -109,6 +140,33 @@
 						"org.apache.harmony.luni.tests.java.io.ObjectStreamClassTest$DummyClass"));
 	}
 
+    /**
+     * @tests java.io.ObjectStreamClass#lookupAny(java.lang.Class)
+     * @since 1.6
+     */
+    public void test_lookupAnyLjava_lang_Class() {
+        // Test for method java.io.ObjectStreamClass
+        // java.io.ObjectStreamClass.lookupAny(java.lang.Class)
+        ObjectStreamClass osc = ObjectStreamClass.lookupAny(DummyClass.class);
+        assertEquals("lookup returned wrong class: " + osc.getName(),
+                "org.apache.harmony.luni.tests.java.io.ObjectStreamClassTest$DummyClass",
osc
+                        .getName());
+        
+        osc = ObjectStreamClass.lookupAny(NonSerialzableClass.class);
+        assertEquals("lookup returned wrong class: " + osc.getName(),
+                "org.apache.harmony.luni.tests.java.io.ObjectStreamClassTest$NonSerialzableClass",
+                osc.getName());
+        
+        osc = ObjectStreamClass.lookupAny(ExternalizableClass.class);        
+        assertEquals("lookup returned wrong class: " + osc.getName(),
+                "org.apache.harmony.luni.tests.java.io.ObjectStreamClassTest$ExternalizableClass",
+                osc.getName());
+
+        osc = ObjectStreamClass.lookup(NonSerialzableClass.class);
+        assertNull(osc);
+        
+    }
+    
 	/**
 	 * @tests java.io.ObjectStreamClass#toString()
 	 */

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java?rev=614506&r1=614505&r2=614506&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java
Wed Jan 23 03:48:43 2008
@@ -46,6 +46,22 @@
 				bytes[i] = (byte) (System.currentTimeMillis() % 9);
 		}
 	}
+    
+     static class MockPipedInputStream extends PipedInputStream {
+
+        public MockPipedInputStream(java.io.PipedOutputStream src,
+                int bufferSize) throws IOException {
+            super(src, bufferSize);
+        }
+
+        public MockPipedInputStream(int bufferSize) {
+            super(bufferSize);
+        }
+
+        public int bufferLength() {
+            return super.buffer.length;
+        }
+    }
 
 	Thread t;
 
@@ -71,6 +87,60 @@
         pis = new PipedInputStream(new PipedOutputStream());
         pis.available();
     }
+    
+     /**
+     * @tests java.io.PipedInputStream#PipedInputStream(java.io.PipedOutputStream,
+     *        int)
+     * @since 1.6
+     */
+    public void test_Constructor_LPipedOutputStream_I() throws Exception {
+        // Test for method java.io.PipedInputStream(java.io.PipedOutputStream,
+        // int)
+        MockPipedInputStream mpis = new MockPipedInputStream(
+                new PipedOutputStream(), 100);
+        int bufferLength = mpis.bufferLength();
+        assertEquals(100, bufferLength);
+        
+        try {
+            pis = new PipedInputStream(null, -1);
+            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            pis = new PipedInputStream(null, 0);
+            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests java.io.PipedInputStream#PipedInputStream(int)
+     * @since 1.6
+     */
+    public void test_Constructor_I() throws Exception {
+        // Test for method java.io.PipedInputStream(int)
+        MockPipedInputStream mpis = new MockPipedInputStream(100);
+        int bufferLength = mpis.bufferLength();
+        assertEquals(100, bufferLength);
+
+        try {
+            pis = new PipedInputStream(-1);
+            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            pis = new PipedInputStream(0);
+            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
 
 	/**
 	 * @tests java.io.PipedInputStream#available()

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedReaderTest.java?rev=614506&r1=614505&r2=614506&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedReaderTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedReaderTest.java
Wed Jan 23 03:48:43 2008
@@ -72,6 +72,50 @@
         // Test for method java.io.PipedReader(java.io.PipedWriter)
         preader = new PipedReader(new PipedWriter());
     }
+    
+    /**
+     * @tests java.io.PipedReader#PipedReader(java.io.PipedWriter,
+     *        int)
+     * @since 1.6
+     */
+    public void test_Constructor_LPipedWriter_I() throws Exception {
+        // Test for method java.io.PipedReader(java.io.PipedWriter,
+        // int)
+        try {
+            preader = new PipedReader(null, -1);
+            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            preader = new PipedReader(null, 0);
+            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests java.io.PipedReader#PipedReader(int)
+     * @since 1.6
+     */
+    public void test_Constructor_I() throws Exception {
+        // Test for method java.io.PipedReader(int)
+        try {
+            preader = new PipedReader(-1);
+            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            preader = new PipedReader(0);
+            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
 
     /**
      * @tests java.io.PipedReader#close()

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintStreamTest.java?rev=614506&r1=614505&r2=614506&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintStreamTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintStreamTest.java
Wed Jan 23 03:48:43 2008
@@ -53,7 +53,12 @@
 		public MockPrintStream(OutputStream os) {
 			super(os);
 		}
-		
+        
+        @Override
+        public void clearError() {
+            super.clearError();
+        }
+        
 		@Override
 		public void setError() {
 			super.setError();
@@ -139,6 +144,19 @@
         assertTrue("Checkerror should return true", os.checkError());
     }
 
+    /**
+     * @tests {@link java.io.PrintStream#clearError()} 
+     */
+    public void test_clearError() throws FileNotFoundException {        
+        MockPrintStream os = new MockPrintStream(testFilePath);     
+        assertFalse(os.checkError());
+        os.setError();
+        assertTrue(os.checkError());
+        os.clearError();
+        assertFalse(os.checkError());
+        os.close();
+    }
+    
     /**
      * @tests java.io.PrintStream#close()
      */

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintWriterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintWriterTest.java?rev=614506&r1=614505&r2=614506&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintWriterTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintWriterTest.java
Wed Jan 23 03:48:43 2008
@@ -22,6 +22,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.nio.charset.Charset;
 import java.util.Locale;
@@ -36,6 +37,22 @@
 			return "Bogus";
 		}
 	}
+    
+    /**
+     * @since 1.6
+     */
+    static class MockPrintWriter extends PrintWriter {
+
+        public MockPrintWriter(OutputStream out, boolean autoflush) {
+            super(out, autoflush);
+        }
+
+        @Override
+        public void clearError() {
+            super.clearError();
+        }
+
+    }
 
 	PrintWriter pw;
 
@@ -184,6 +201,20 @@
 		assertTrue("Failed to return error", pw.checkError());
 	}
 
+    /**
+     * @tests java.io.PrintWriter#clearError()
+     * @since 1.6
+     */
+    public void test_clearError() {
+        // Test for method boolean java.io.PrintWriter.clearError()
+        MockPrintWriter mpw = new MockPrintWriter(new ByteArrayOutputStream(), false);
+        mpw.close();
+        mpw.print(490000000000.08765);
+        assertTrue("Failed to return error", mpw.checkError());
+        mpw.clearError();
+        assertFalse("Internal error state has not be cleared", mpw.checkError());
+    }
+    
 	/**
 	 * @tests java.io.PrintWriter#close()
 	 */



Mime
View raw message