harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r391587 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ test/java/org/apache/harmony/tests/java/io/ test/java/tests/luni/
Date Wed, 05 Apr 2006 11:36:51 GMT
Author: gharley
Date: Wed Apr  5 04:36:45 2006
New Revision: 391587

URL: http://svn.apache.org/viewcvs?rev=391587&view=rev
Log:
HARMONY-231 : Tests pass successfully on Harmony. 

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/ReaderTest.java
  (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTestsWithExclusions.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Closeable.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/OutputStream.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Reader.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Closeable.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Closeable.java?rev=391587&r1=391586&r2=391587&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Closeable.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Closeable.java
Wed Apr  5 04:36:45 2006
@@ -15,6 +15,18 @@
 
 package java.io;
 
+/**
+ * Closeable represents the source or destination of some data which can be
+ * called its close method to release resources it holds.
+ */
 public interface Closeable {
-    public void close() throws IOException;
+	
+	/**
+	 * Close the object and release any system resources it holds. If the object
+	 * has been close, then invoke this method has no effect.
+	 * 
+	 * @throws IOException
+	 *             if any error raises when closing the object.
+	 */
+	public void close() throws IOException;
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java?rev=391587&r1=391586&r2=391587&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java
Wed Apr  5 04:36:45 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
  * 
  * @see OutputStream
  */
-public abstract class InputStream extends Object {
+public abstract class InputStream extends Object implements Closeable {
 
 	private static byte[] skipBuf;
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/OutputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/OutputStream.java?rev=391587&r1=391586&r2=391587&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/OutputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/OutputStream.java
Wed Apr  5 04:36:45 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
  * @see InputStream
  */
 
-public abstract class OutputStream {
+public abstract class OutputStream implements Closeable,Flushable{
 	/**
 	 * This constructor does nothing interesting. Provided for signature
 	 * compatibility.

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Reader.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Reader.java?rev=391587&r1=391586&r2=391587&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Reader.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Reader.java
Wed Apr  5 04:36:45 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
 
 package java.io;
 
+import java.nio.CharBuffer;
 
 /**
  * Reader is an Abstract class for reading Character Streams. Subclasses of
@@ -23,7 +24,7 @@
  * 
  * @see Writer
  */
-public abstract class Reader {
+public abstract class Reader implements Readable, Closeable {
 	/**
 	 * The object used to synchronize access to the reader.
 	 */
@@ -226,5 +227,34 @@
 			}
 		}
 		throw new IllegalArgumentException();
+	}
+
+	/**
+	 * Read chars from the Reader and then put them to the <code>target</code>
+	 * CharBuffer. Only put method is called on the <code>target</code>.
+	 * 
+	 * @param target
+	 *            the destination CharBuffer
+	 * @return the actual number of chars put to the <code>target</code>. -1
+	 *         when the Reader has reached the end before the method is called.
+	 * @throws IOException
+	 *             if any I/O error raises in the procedure
+	 * @throws NullPointerException
+	 *             if the target CharBuffer is null
+	 * @throws ReadOnlyBufferException
+	 *             if the target CharBuffer is readonly
+	 * 
+	 */
+	public int read(CharBuffer target) throws IOException {
+		if (null == target) {
+			throw new NullPointerException();
+		}
+		int length = target.length();
+		char[] buf = new char[length];
+		length = Math.min(length, read(buf));
+		if (length > 0) {
+			target.put(buf, 0, length);
+		}
+		return length;
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java?rev=391587&r1=391586&r2=391587&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java
Wed Apr  5 04:36:45 2006
@@ -35,6 +35,7 @@
 		suite.addTestSuite(BufferedReaderTest.class);
 		suite.addTestSuite(PushBackInputStreamTest.class);
 		suite.addTestSuite(RandomAccessFileTest.class);
+        suite.addTestSuite(ReaderTest.class);
 		suite.addTestSuite(ObjectStreamConstantsTest.class);
 		//$JUnit-END$
 		return suite;

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/ReaderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/ReaderTest.java?rev=391587&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/ReaderTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/ReaderTest.java
Wed Apr  5 04:36:45 2006
@@ -0,0 +1,107 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.io;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.CharBuffer;
+
+import junit.framework.TestCase;
+
+public class ReaderTest extends TestCase {
+
+    public void test_Reader_CharBuffer_null() throws IOException {
+        String s = "MY TEST STRING";
+        MockReader mockReader = new MockReader(s.toCharArray());
+        CharBuffer charBuffer = null;
+        try {
+            mockReader.read(charBuffer);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            //expected;
+        }
+    }
+
+    public void test_Reader_CharBuffer_ZeroChar() throws IOException {
+        //the charBuffer has the capacity of 0, then there the number of char read
+        // to the CharBuffer is 0. Furthermore, the MockReader is intact in its content.
+        String s = "MY TEST STRING";
+        char[] srcBuffer = s.toCharArray();
+        MockReader mockReader = new MockReader(srcBuffer);
+        CharBuffer charBuffer = CharBuffer.allocate(0);
+        int result = mockReader.read(charBuffer);
+        assertEquals(0, result);
+        char[] destBuffer = new char[srcBuffer.length];
+        mockReader.read(destBuffer);
+        assertEquals(s, String.valueOf(destBuffer));
+    }
+
+    public void test_Reader_CharBufferChar() throws IOException {
+        String s = "MY TEST STRING";
+        char[] srcBuffer = s.toCharArray();
+        final int CHARBUFFER_SIZE = 10;
+        MockReader mockReader = new MockReader(srcBuffer);
+        CharBuffer charBuffer = CharBuffer.allocate(CHARBUFFER_SIZE);
+        charBuffer.append('A');
+        final int CHARBUFFER_REMAINING = charBuffer.remaining();
+        int result = mockReader.read(charBuffer);
+        assertEquals(CHARBUFFER_REMAINING, result);
+        charBuffer.rewind();
+        assertEquals(s.substring(0, CHARBUFFER_REMAINING), charBuffer
+                .subSequence(CHARBUFFER_SIZE - CHARBUFFER_REMAINING,
+                        CHARBUFFER_SIZE).toString());
+        char[] destBuffer = new char[srcBuffer.length - CHARBUFFER_REMAINING];
+        mockReader.read(destBuffer);
+        assertEquals(s.substring(CHARBUFFER_REMAINING), String
+                .valueOf(destBuffer));
+    }
+
+    class MockReader extends Reader {
+
+        private char[] contents;
+
+        private int current_offset = 0;
+
+        private int length = 0;
+
+        public MockReader(char[] data) {
+            contents = data;
+            length = contents.length;
+        }
+
+        public void close() throws IOException {
+
+            contents = null;
+        }
+
+        public int read(char[] buf, int offset, int count) throws IOException {
+
+            if (null == contents)
+                return -1;
+            if (length <= current_offset)
+                return -1;
+            if (buf.length < offset + count)
+                throw new IndexOutOfBoundsException();
+
+            count = Math.min(count, length - current_offset);
+            for (int i = 0; i < count; i++)
+                buf[offset + i] = contents[current_offset + i];
+            current_offset += count;
+            return count;
+        }
+
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/ReaderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTests.java?rev=391587&r1=391586&r2=391587&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTests.java
Wed Apr  5 04:36:45 2006
@@ -37,6 +37,10 @@
 		suite.addTest(tests.api.java.net.AllTests.suite());
 		suite.addTest(tests.api.java.util.AllTests.suite());
 		suite.addTest(tests.impl.com.ibm.misc.util.AllTests.suite());
+        suite.addTest(org.apache.harmony.tests.java.io.AllTests.suite());
+        suite.addTest(org.apache.harmony.tests.java.lang.AllTests.suite());
+        suite.addTest(org.apache.harmony.tests.java.net.AllTests.suite());
+        suite.addTest(org.apache.harmony.tests.java.util.AllTests.suite());
 		// $JUnit-END$
 		return suite;
 	}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTestsWithExclusions.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTestsWithExclusions.java?rev=391587&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTestsWithExclusions.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/luni/AllTestsWithExclusions.java
Wed Apr  5 04:36:45 2006
@@ -0,0 +1,36 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.luni;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes only some of the tests for the LUNI project. 
+ */
+public class AllTestsWithExclusions {
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(AllTestsWithExclusions.suite());
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite("Some LUNI test suites");
+		suite.addTest(AllTests.suite());
+		tests.util.SomeTests some = new tests.util.SomeTests(suite);
+		return some;
+	}
+}
\ No newline at end of file



Mime
View raw message