harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r999716 [1/2] - in /harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java: io/BufferedInputStreamTest.java io/InputStreamReaderTest.java net/URLEncoderTest.java util/FormatterTest.java
Date Wed, 22 Sep 2010 01:32:57 GMT
Author: tellison
Date: Wed Sep 22 01:32:56 2010
New Revision: 999716

URL: http://svn.apache.org/viewvc?rev=999716&view=rev
Log:
Add svn property eol-style, with thanks to rmuir.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedInputStreamTest.java   (contents, props changed)
    harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java   (contents, props changed)
    harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLEncoderTest.java   (contents, props changed)
    harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/FormatterTest.java   (contents, props changed)

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedInputStreamTest.java?rev=999716&r1=999715&r2=999716&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedInputStreamTest.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedInputStreamTest.java Wed Sep 22 01:32:56 2010
@@ -1,524 +1,524 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You 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.luni.tests.java.io;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import junit.framework.TestCase;
-import tests.support.Support_PlatformFile;
-
-public class BufferedInputStreamTest extends TestCase {
-
-    public String fileName;
-
-    private BufferedInputStream is;
-
-    private FileInputStream isFile;
-
-    byte[] ibuf = new byte[4096];
-
-    public String fileString = "Test_All_Tests\nTest_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_Cl
 assNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_
 Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_Sock
 etException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
-    /*
-     * @tests java.io.BufferedInputStream(InputStream)
-     */
-    public void test_ConstructorLjava_io_InputStream() {
-        try {
-            BufferedInputStream str = new BufferedInputStream(null);
-            str.read();
-            fail("Expected an IOException");
-        } catch (IOException e) {
-            // Expected
-        }
-    }
-
-    /*
-     * @tests java.io.BufferedInputStream(InputStream)
-     */
-    public void test_ConstructorLjava_io_InputStreamI() throws IOException {
-        try {
-            BufferedInputStream str = new BufferedInputStream(null, 1);
-            str.read();
-            fail("Expected an IOException");
-        } catch (IOException e) {
-            // Expected
-        }
-
-        // Test for method java.io.BufferedInputStream(java.io.InputStream, int)
-
-        // Create buffer with exact size of file
-        is = new BufferedInputStream(isFile, this.fileString.length());
-        // Ensure buffer gets filled by evaluating one read
-        is.read();
-        // Close underlying FileInputStream, all but 1 buffered bytes should
-        // still be available.
-        isFile.close();
-        // Read the remaining buffered characters, no IOException should
-        // occur.
-        is.skip(this.fileString.length() - 2);
-        is.read();
-        try {
-            // is.read should now throw an exception because it will have to
-            // be filled.
-            is.read();
-            fail("Exception should have been triggered by read()");
-        } catch (IOException e) {
-            // Expected
-        }
-
-        // regression test for harmony-2407
-        new MockBufferedInputStream(null);
-        assertNotNull(MockBufferedInputStream.buf);
-        MockBufferedInputStream.buf = null;
-        new MockBufferedInputStream(null, 100);
-        assertNotNull(MockBufferedInputStream.buf);
-    }
-
-    static class MockBufferedInputStream extends BufferedInputStream {
-        static byte[] buf;
-
-        MockBufferedInputStream(InputStream is) throws IOException {
-            super(is);
-            buf = super.buf;
-        }
-
-        MockBufferedInputStream(InputStream is, int size) throws IOException {
-            super(is, size);
-            buf = super.buf;
-        }
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#available()
-     */
-    public void test_available() throws IOException {
-        assertTrue("Returned incorrect number of available bytes", is
-                .available() == fileString.length());
-
-        // Test that a closed stream throws an IOE for available()
-        BufferedInputStream bis = new BufferedInputStream(
-                new ByteArrayInputStream(new byte[] { 'h', 'e', 'l', 'l', 'o',
-                        ' ', 't', 'i', 'm' }));
-        int available = bis.available();
-        bis.close();
-        assertTrue(available != 0);
-
-        try {
-            bis.available();
-            fail("Expected test to throw IOE.");
-        } catch (IOException ex) {
-            // expected
-        }
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#close()
-     */
-    public void test_close() throws IOException {
-        new BufferedInputStream(isFile).close();
-
-        // regression for HARMONY-667
-        BufferedInputStream buf = new BufferedInputStream(null, 5);
-        buf.close();
-
-        InputStream in = new InputStream() {
-            Object lock = new Object();
-
-            @Override
-            public int read() {
-                return 1;
-            }
-
-            @Override
-            public int read(byte[] buf, int offset, int length) {
-                synchronized (lock) {
-                    try {
-                        lock.wait(3000);
-                    } catch (InterruptedException e) {
-                        // Ignore
-                    }
-                }
-                return 1;
-            }
-
-            @Override
-            public void close() {
-                synchronized (lock) {
-                    lock.notifyAll();
-                }
-            }
-        };
-        final BufferedInputStream bufin = new BufferedInputStream(in);
-        Thread thread = new Thread(new Runnable() {
-            public void run() {
-                try {
-                    Thread.sleep(1000);
-                    bufin.close();
-                } catch (Exception e) {
-                    // Ignored
-                }
-            }
-        });
-        thread.start();
-        try {
-            bufin.read(new byte[100], 0, 99);
-            fail("Should throw IOException");
-        } catch (IOException e) {
-            // Expected
-        }
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#mark(int)
-     */
-    public void test_markI() throws IOException {
-        byte[] buf1 = new byte[100];
-        byte[] buf2 = new byte[100];
-        is.skip(3000);
-        is.mark(1000);
-        is.read(buf1, 0, buf1.length);
-        is.reset();
-        is.read(buf2, 0, buf2.length);
-        is.reset();
-        assertTrue("Failed to mark correct position", new String(buf1, 0,
-                buf1.length).equals(new String(buf2, 0, buf2.length)));
-
-        byte[] bytes = new byte[256];
-        for (int i = 0; i < 256; i++) {
-            bytes[i] = (byte) i;
-        }
-        InputStream in = new BufferedInputStream(
-                new ByteArrayInputStream(bytes), 12);
-        in.skip(6);
-        in.mark(14);
-        in.read(new byte[14], 0, 14);
-        in.reset();
-        assertTrue("Wrong bytes", in.read() == 6 && in.read() == 7);
-
-        in = new BufferedInputStream(new ByteArrayInputStream(bytes), 12);
-        in.skip(6);
-        in.mark(8);
-        in.skip(7);
-        in.reset();
-        assertTrue("Wrong bytes 2", in.read() == 6 && in.read() == 7);
-
-        BufferedInputStream buf = new BufferedInputStream(
-                new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4 }), 2);
-        buf.mark(3);
-        bytes = new byte[3];
-        int result = buf.read(bytes);
-        assertEquals(3, result);
-        assertEquals("Assert 0:", 0, bytes[0]);
-        assertEquals("Assert 1:", 1, bytes[1]);
-        assertEquals("Assert 2:", 2, bytes[2]);
-        assertEquals("Assert 3:", 3, buf.read());
-
-        buf = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 0,
-                1, 2, 3, 4 }), 2);
-        buf.mark(3);
-        bytes = new byte[4];
-        result = buf.read(bytes);
-        assertEquals(4, result);
-        assertEquals("Assert 4:", 0, bytes[0]);
-        assertEquals("Assert 5:", 1, bytes[1]);
-        assertEquals("Assert 6:", 2, bytes[2]);
-        assertEquals("Assert 7:", 3, bytes[3]);
-        assertEquals("Assert 8:", 4, buf.read());
-        assertEquals("Assert 9:", -1, buf.read());
-
-        buf = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 0,
-                1, 2, 3, 4 }), 2);
-        buf.mark(Integer.MAX_VALUE);
-        buf.read();
-        buf.close();
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#markSupported()
-     */
-    public void test_markSupported() {
-        assertTrue("markSupported returned incorrect value", is.markSupported());
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#read()
-     */
-    public void test_read() throws IOException {
-        InputStreamReader isr = new InputStreamReader(is);
-        int c = isr.read();
-        assertTrue("read returned incorrect char", c == fileString.charAt(0));
-
-        byte[] bytes = new byte[256];
-        for (int i = 0; i < 256; i++) {
-            bytes[i] = (byte) i;
-        }
-        InputStream in = new BufferedInputStream(
-                new ByteArrayInputStream(bytes), 12);
-        assertEquals("Wrong initial byte", 0, in.read()); // Fill the
-        // buffer
-        byte[] buf = new byte[14];
-        in.read(buf, 0, 14); // Read greater than the buffer
-        assertTrue("Wrong block read data", new String(buf, 0, 14)
-                .equals(new String(bytes, 1, 14)));
-        assertEquals("Wrong bytes", 15, in.read()); // Check next byte
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#read(byte[], int, int)
-     */
-    public void test_read$BII_Exception() throws IOException {
-        BufferedInputStream bis = new BufferedInputStream(null);
-        try {
-            bis.read(null, -1, -1);
-            fail("should throw NullPointerException");
-        } catch (NullPointerException e) {
-            // expected
-        }
-
-        try {
-            bis.read(new byte[0], -1, -1);
-            fail("should throw IndexOutOfBoundsException");
-        } catch (IndexOutOfBoundsException e) {
-            // expected
-        }
-
-        try {
-            bis.read(new byte[0], 1, -1);
-            fail("should throw IndexOutOfBoundsException");
-        } catch (IndexOutOfBoundsException e) {
-            // expected
-        }
-
-        try {
-            bis.read(new byte[0], 1, 1);
-            fail("should throw IndexOutOfBoundsException");
-        } catch (IndexOutOfBoundsException e) {
-            // expected
-        }
-
-        bis.close();
-
-        try {
-            bis.read(null, -1, -1);
-            fail("should throw IOException");
-        } catch (IOException e) {
-            // expected
-        }
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#read(byte[], int, int)
-     */
-    public void test_read$BII() throws IOException {
-        byte[] buf1 = new byte[100];
-        is.skip(3000);
-        is.mark(1000);
-        is.read(buf1, 0, buf1.length);
-        assertTrue("Failed to read correct data", new String(buf1, 0,
-                buf1.length).equals(fileString.substring(3000, 3100)));
-
-        BufferedInputStream bufin = new BufferedInputStream(new InputStream() {
-            int size = 2, pos = 0;
-
-            byte[] contents = new byte[size];
-
-            @Override
-            public int read() throws IOException {
-                if (pos >= size) {
-                    throw new IOException("Read past end of data");
-                }
-                return contents[pos++];
-            }
-
-            @Override
-            public int read(byte[] buf, int off, int len) throws IOException {
-                if (pos >= size) {
-                    throw new IOException("Read past end of data");
-                }
-                int toRead = len;
-                if (toRead > available()) {
-                    toRead = available();
-                }
-                System.arraycopy(contents, pos, buf, off, toRead);
-                pos += toRead;
-                return toRead;
-            }
-
-            @Override
-            public int available() {
-                return size - pos;
-            }
-        });
-        bufin.read();
-        int result = bufin.read(new byte[2], 0, 2);
-        assertTrue("Incorrect result: " + result, result == 1);
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#reset()
-     */
-    public void test_reset() throws IOException {
-        byte[] buf1 = new byte[10];
-        byte[] buf2 = new byte[10];
-        is.mark(2000);
-        is.read(buf1, 0, 10);
-        is.reset();
-        is.read(buf2, 0, 10);
-        is.reset();
-        assertTrue("Reset failed", new String(buf1, 0, buf1.length)
-                .equals(new String(buf2, 0, buf2.length)));
-
-        BufferedInputStream bIn = new BufferedInputStream(
-                new ByteArrayInputStream("1234567890".getBytes()));
-        bIn.mark(10);
-        for (int i = 0; i < 11; i++) {
-            bIn.read();
-        }
-        bIn.reset();
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#reset()
-     */
-    public void test_reset_Exception() throws IOException {
-        BufferedInputStream bis = new BufferedInputStream(null);
-
-        // throws IOException with message "Mark has been invalidated"
-        try {
-            bis.reset();
-            fail("should throw IOException");
-        } catch (IOException e) {
-            // expected
-        }
-
-        // does not throw IOException
-        bis.mark(1);
-        bis.reset();
-
-        bis.close();
-
-        // throws IOException with message "stream is closed"
-        try {
-            bis.reset();
-            fail("should throw IOException");
-        } catch (IOException e) {
-            // expected
-        }
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#reset()
-     */
-    public void test_reset_scenario1() throws IOException {
-        byte[] input = "12345678900".getBytes();
-        BufferedInputStream buffis = new BufferedInputStream(
-                new ByteArrayInputStream(input));
-        buffis.read();
-        buffis.mark(5);
-        buffis.skip(5);
-        buffis.reset();
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#reset()
-     */
-    public void test_reset_scenario2() throws IOException {
-        byte[] input = "12345678900".getBytes();
-        BufferedInputStream buffis = new BufferedInputStream(
-                new ByteArrayInputStream(input));
-        buffis.mark(5);
-        buffis.skip(6);
-        buffis.reset();
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#skip(long)
-     */
-    public void test_skipJ() throws IOException {
-        byte[] buf1 = new byte[10];
-        is.mark(2000);
-        is.skip(1000);
-        is.read(buf1, 0, buf1.length);
-        is.reset();
-        assertTrue("Failed to skip to correct position", new String(buf1, 0,
-                buf1.length).equals(fileString.substring(1000, 1010)));
-
-        // regression for HARMONY-667
-        try {
-            BufferedInputStream buf = new BufferedInputStream(null, 5);
-            buf.skip(10);
-            fail("Should throw IOException");
-        } catch (IOException e) {
-            // Expected
-        }
-    }
-
-    /**
-     * @tests java.io.BufferedInputStream#skip(long)
-     */
-    public void test_skip_NullInputStream() throws IOException {
-        BufferedInputStream buf = new BufferedInputStream(null, 5);
-        assertEquals(0, buf.skip(0));
-    }
-
-    /**
-     * Sets up the fixture, for example, open a network connection. This method
-     * is called before a test is executed.
-     */
-    @Override
-    protected void setUp() throws IOException {
-        fileName = System.getProperty("user.dir");
-        String separator = System.getProperty("file.separator");
-        if (fileName.charAt(fileName.length() - 1) == separator.charAt(0)) {
-            fileName = Support_PlatformFile.getNewPlatformFile(fileName,
-                    "input.tst");
-        } else {
-            fileName = Support_PlatformFile.getNewPlatformFile(fileName
-                    + separator, "input.tst");
-        }
-        OutputStream fos = new FileOutputStream(fileName);
-        fos.write(fileString.getBytes());
-        fos.close();
-        isFile = new FileInputStream(fileName);
-        is = new BufferedInputStream(isFile);
-    }
-
-    /**
-     * Tears down the fixture, for example, close a network connection. This
-     * method is called after a test is executed.
-     */
-    @Override
-    protected void tearDown() {
-        try {
-            is.close();
-        } catch (Exception e) {
-        }
-        try {
-            File f = new File(fileName);
-            f.delete();
-        } catch (Exception e) {
-        }
-    }
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.luni.tests.java.io;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import junit.framework.TestCase;
+import tests.support.Support_PlatformFile;
+
+public class BufferedInputStreamTest extends TestCase {
+
+    public String fileName;
+
+    private BufferedInputStream is;
+
+    private FileInputStream isFile;
+
+    byte[] ibuf = new byte[4096];
+
+    public String fileString = "Test_All_Tests\nTest_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_Cl
 assNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_
 Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_Sock
 etException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
+
+    /*
+     * @tests java.io.BufferedInputStream(InputStream)
+     */
+    public void test_ConstructorLjava_io_InputStream() {
+        try {
+            BufferedInputStream str = new BufferedInputStream(null);
+            str.read();
+            fail("Expected an IOException");
+        } catch (IOException e) {
+            // Expected
+        }
+    }
+
+    /*
+     * @tests java.io.BufferedInputStream(InputStream)
+     */
+    public void test_ConstructorLjava_io_InputStreamI() throws IOException {
+        try {
+            BufferedInputStream str = new BufferedInputStream(null, 1);
+            str.read();
+            fail("Expected an IOException");
+        } catch (IOException e) {
+            // Expected
+        }
+
+        // Test for method java.io.BufferedInputStream(java.io.InputStream, int)
+
+        // Create buffer with exact size of file
+        is = new BufferedInputStream(isFile, this.fileString.length());
+        // Ensure buffer gets filled by evaluating one read
+        is.read();
+        // Close underlying FileInputStream, all but 1 buffered bytes should
+        // still be available.
+        isFile.close();
+        // Read the remaining buffered characters, no IOException should
+        // occur.
+        is.skip(this.fileString.length() - 2);
+        is.read();
+        try {
+            // is.read should now throw an exception because it will have to
+            // be filled.
+            is.read();
+            fail("Exception should have been triggered by read()");
+        } catch (IOException e) {
+            // Expected
+        }
+
+        // regression test for harmony-2407
+        new MockBufferedInputStream(null);
+        assertNotNull(MockBufferedInputStream.buf);
+        MockBufferedInputStream.buf = null;
+        new MockBufferedInputStream(null, 100);
+        assertNotNull(MockBufferedInputStream.buf);
+    }
+
+    static class MockBufferedInputStream extends BufferedInputStream {
+        static byte[] buf;
+
+        MockBufferedInputStream(InputStream is) throws IOException {
+            super(is);
+            buf = super.buf;
+        }
+
+        MockBufferedInputStream(InputStream is, int size) throws IOException {
+            super(is, size);
+            buf = super.buf;
+        }
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#available()
+     */
+    public void test_available() throws IOException {
+        assertTrue("Returned incorrect number of available bytes", is
+                .available() == fileString.length());
+
+        // Test that a closed stream throws an IOE for available()
+        BufferedInputStream bis = new BufferedInputStream(
+                new ByteArrayInputStream(new byte[] { 'h', 'e', 'l', 'l', 'o',
+                        ' ', 't', 'i', 'm' }));
+        int available = bis.available();
+        bis.close();
+        assertTrue(available != 0);
+
+        try {
+            bis.available();
+            fail("Expected test to throw IOE.");
+        } catch (IOException ex) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#close()
+     */
+    public void test_close() throws IOException {
+        new BufferedInputStream(isFile).close();
+
+        // regression for HARMONY-667
+        BufferedInputStream buf = new BufferedInputStream(null, 5);
+        buf.close();
+
+        InputStream in = new InputStream() {
+            Object lock = new Object();
+
+            @Override
+            public int read() {
+                return 1;
+            }
+
+            @Override
+            public int read(byte[] buf, int offset, int length) {
+                synchronized (lock) {
+                    try {
+                        lock.wait(3000);
+                    } catch (InterruptedException e) {
+                        // Ignore
+                    }
+                }
+                return 1;
+            }
+
+            @Override
+            public void close() {
+                synchronized (lock) {
+                    lock.notifyAll();
+                }
+            }
+        };
+        final BufferedInputStream bufin = new BufferedInputStream(in);
+        Thread thread = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    Thread.sleep(1000);
+                    bufin.close();
+                } catch (Exception e) {
+                    // Ignored
+                }
+            }
+        });
+        thread.start();
+        try {
+            bufin.read(new byte[100], 0, 99);
+            fail("Should throw IOException");
+        } catch (IOException e) {
+            // Expected
+        }
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#mark(int)
+     */
+    public void test_markI() throws IOException {
+        byte[] buf1 = new byte[100];
+        byte[] buf2 = new byte[100];
+        is.skip(3000);
+        is.mark(1000);
+        is.read(buf1, 0, buf1.length);
+        is.reset();
+        is.read(buf2, 0, buf2.length);
+        is.reset();
+        assertTrue("Failed to mark correct position", new String(buf1, 0,
+                buf1.length).equals(new String(buf2, 0, buf2.length)));
+
+        byte[] bytes = new byte[256];
+        for (int i = 0; i < 256; i++) {
+            bytes[i] = (byte) i;
+        }
+        InputStream in = new BufferedInputStream(
+                new ByteArrayInputStream(bytes), 12);
+        in.skip(6);
+        in.mark(14);
+        in.read(new byte[14], 0, 14);
+        in.reset();
+        assertTrue("Wrong bytes", in.read() == 6 && in.read() == 7);
+
+        in = new BufferedInputStream(new ByteArrayInputStream(bytes), 12);
+        in.skip(6);
+        in.mark(8);
+        in.skip(7);
+        in.reset();
+        assertTrue("Wrong bytes 2", in.read() == 6 && in.read() == 7);
+
+        BufferedInputStream buf = new BufferedInputStream(
+                new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4 }), 2);
+        buf.mark(3);
+        bytes = new byte[3];
+        int result = buf.read(bytes);
+        assertEquals(3, result);
+        assertEquals("Assert 0:", 0, bytes[0]);
+        assertEquals("Assert 1:", 1, bytes[1]);
+        assertEquals("Assert 2:", 2, bytes[2]);
+        assertEquals("Assert 3:", 3, buf.read());
+
+        buf = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 0,
+                1, 2, 3, 4 }), 2);
+        buf.mark(3);
+        bytes = new byte[4];
+        result = buf.read(bytes);
+        assertEquals(4, result);
+        assertEquals("Assert 4:", 0, bytes[0]);
+        assertEquals("Assert 5:", 1, bytes[1]);
+        assertEquals("Assert 6:", 2, bytes[2]);
+        assertEquals("Assert 7:", 3, bytes[3]);
+        assertEquals("Assert 8:", 4, buf.read());
+        assertEquals("Assert 9:", -1, buf.read());
+
+        buf = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 0,
+                1, 2, 3, 4 }), 2);
+        buf.mark(Integer.MAX_VALUE);
+        buf.read();
+        buf.close();
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#markSupported()
+     */
+    public void test_markSupported() {
+        assertTrue("markSupported returned incorrect value", is.markSupported());
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#read()
+     */
+    public void test_read() throws IOException {
+        InputStreamReader isr = new InputStreamReader(is);
+        int c = isr.read();
+        assertTrue("read returned incorrect char", c == fileString.charAt(0));
+
+        byte[] bytes = new byte[256];
+        for (int i = 0; i < 256; i++) {
+            bytes[i] = (byte) i;
+        }
+        InputStream in = new BufferedInputStream(
+                new ByteArrayInputStream(bytes), 12);
+        assertEquals("Wrong initial byte", 0, in.read()); // Fill the
+        // buffer
+        byte[] buf = new byte[14];
+        in.read(buf, 0, 14); // Read greater than the buffer
+        assertTrue("Wrong block read data", new String(buf, 0, 14)
+                .equals(new String(bytes, 1, 14)));
+        assertEquals("Wrong bytes", 15, in.read()); // Check next byte
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#read(byte[], int, int)
+     */
+    public void test_read$BII_Exception() throws IOException {
+        BufferedInputStream bis = new BufferedInputStream(null);
+        try {
+            bis.read(null, -1, -1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            bis.read(new byte[0], -1, -1);
+            fail("should throw IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            bis.read(new byte[0], 1, -1);
+            fail("should throw IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            bis.read(new byte[0], 1, 1);
+            fail("should throw IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        bis.close();
+
+        try {
+            bis.read(null, -1, -1);
+            fail("should throw IOException");
+        } catch (IOException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#read(byte[], int, int)
+     */
+    public void test_read$BII() throws IOException {
+        byte[] buf1 = new byte[100];
+        is.skip(3000);
+        is.mark(1000);
+        is.read(buf1, 0, buf1.length);
+        assertTrue("Failed to read correct data", new String(buf1, 0,
+                buf1.length).equals(fileString.substring(3000, 3100)));
+
+        BufferedInputStream bufin = new BufferedInputStream(new InputStream() {
+            int size = 2, pos = 0;
+
+            byte[] contents = new byte[size];
+
+            @Override
+            public int read() throws IOException {
+                if (pos >= size) {
+                    throw new IOException("Read past end of data");
+                }
+                return contents[pos++];
+            }
+
+            @Override
+            public int read(byte[] buf, int off, int len) throws IOException {
+                if (pos >= size) {
+                    throw new IOException("Read past end of data");
+                }
+                int toRead = len;
+                if (toRead > available()) {
+                    toRead = available();
+                }
+                System.arraycopy(contents, pos, buf, off, toRead);
+                pos += toRead;
+                return toRead;
+            }
+
+            @Override
+            public int available() {
+                return size - pos;
+            }
+        });
+        bufin.read();
+        int result = bufin.read(new byte[2], 0, 2);
+        assertTrue("Incorrect result: " + result, result == 1);
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#reset()
+     */
+    public void test_reset() throws IOException {
+        byte[] buf1 = new byte[10];
+        byte[] buf2 = new byte[10];
+        is.mark(2000);
+        is.read(buf1, 0, 10);
+        is.reset();
+        is.read(buf2, 0, 10);
+        is.reset();
+        assertTrue("Reset failed", new String(buf1, 0, buf1.length)
+                .equals(new String(buf2, 0, buf2.length)));
+
+        BufferedInputStream bIn = new BufferedInputStream(
+                new ByteArrayInputStream("1234567890".getBytes()));
+        bIn.mark(10);
+        for (int i = 0; i < 11; i++) {
+            bIn.read();
+        }
+        bIn.reset();
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#reset()
+     */
+    public void test_reset_Exception() throws IOException {
+        BufferedInputStream bis = new BufferedInputStream(null);
+
+        // throws IOException with message "Mark has been invalidated"
+        try {
+            bis.reset();
+            fail("should throw IOException");
+        } catch (IOException e) {
+            // expected
+        }
+
+        // does not throw IOException
+        bis.mark(1);
+        bis.reset();
+
+        bis.close();
+
+        // throws IOException with message "stream is closed"
+        try {
+            bis.reset();
+            fail("should throw IOException");
+        } catch (IOException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#reset()
+     */
+    public void test_reset_scenario1() throws IOException {
+        byte[] input = "12345678900".getBytes();
+        BufferedInputStream buffis = new BufferedInputStream(
+                new ByteArrayInputStream(input));
+        buffis.read();
+        buffis.mark(5);
+        buffis.skip(5);
+        buffis.reset();
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#reset()
+     */
+    public void test_reset_scenario2() throws IOException {
+        byte[] input = "12345678900".getBytes();
+        BufferedInputStream buffis = new BufferedInputStream(
+                new ByteArrayInputStream(input));
+        buffis.mark(5);
+        buffis.skip(6);
+        buffis.reset();
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#skip(long)
+     */
+    public void test_skipJ() throws IOException {
+        byte[] buf1 = new byte[10];
+        is.mark(2000);
+        is.skip(1000);
+        is.read(buf1, 0, buf1.length);
+        is.reset();
+        assertTrue("Failed to skip to correct position", new String(buf1, 0,
+                buf1.length).equals(fileString.substring(1000, 1010)));
+
+        // regression for HARMONY-667
+        try {
+            BufferedInputStream buf = new BufferedInputStream(null, 5);
+            buf.skip(10);
+            fail("Should throw IOException");
+        } catch (IOException e) {
+            // Expected
+        }
+    }
+
+    /**
+     * @tests java.io.BufferedInputStream#skip(long)
+     */
+    public void test_skip_NullInputStream() throws IOException {
+        BufferedInputStream buf = new BufferedInputStream(null, 5);
+        assertEquals(0, buf.skip(0));
+    }
+
+    /**
+     * Sets up the fixture, for example, open a network connection. This method
+     * is called before a test is executed.
+     */
+    @Override
+    protected void setUp() throws IOException {
+        fileName = System.getProperty("user.dir");
+        String separator = System.getProperty("file.separator");
+        if (fileName.charAt(fileName.length() - 1) == separator.charAt(0)) {
+            fileName = Support_PlatformFile.getNewPlatformFile(fileName,
+                    "input.tst");
+        } else {
+            fileName = Support_PlatformFile.getNewPlatformFile(fileName
+                    + separator, "input.tst");
+        }
+        OutputStream fos = new FileOutputStream(fileName);
+        fos.write(fileString.getBytes());
+        fos.close();
+        isFile = new FileInputStream(fileName);
+        is = new BufferedInputStream(isFile);
+    }
+
+    /**
+     * Tears down the fixture, for example, close a network connection. This
+     * method is called after a test is executed.
+     */
+    @Override
+    protected void tearDown() {
+        try {
+            is.close();
+        } catch (Exception e) {
+        }
+        try {
+            File f = new File(fileName);
+            f.delete();
+        } catch (Exception e) {
+        }
+    }
+}

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java?rev=999716&r1=999715&r2=999716&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java Wed Sep 22 01:32:56 2010
@@ -1,538 +1,538 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You 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.luni.tests.java.io;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintStream;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CodingErrorAction;
-import java.nio.charset.MalformedInputException;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-public class InputStreamReaderTest extends TestCase {
-
-    static class LimitedByteArrayInputStream extends ByteArrayInputStream {
-
-        // A ByteArrayInputStream that only returns a single byte per read
-        byte[] bytes;
-
-        int count;
-
-        public LimitedByteArrayInputStream(int type) {
-            super(new byte[0]);
-            switch (type) {
-            case 0:
-                bytes = new byte[] { 0x61, 0x72 };
-                break;
-            case 1:
-                bytes = new byte[] { (byte) 0xff, (byte) 0xfe, 0x61, 0x72 };
-                break;
-            case 2:
-                bytes = new byte[] { '\u001b', '$', 'B', '6', 'e', 'B', 'h',
-                        '\u001b', '(', 'B' };
-                break;
-            }
-            count = bytes.length;
-        }
-
-        @Override
-        public int available() {
-            return count;
-        }
-
-        @Override
-        public int read() {
-            if (count == 0) {
-                return -1;
-            }
-            count--;
-            return bytes[bytes.length - count];
-        }
-
-        @Override
-        public int read(byte[] buffer, int offset, int length) {
-            if (count == 0) {
-                return -1;
-            }
-            if (length == 0) {
-                return 0;
-            }
-            buffer[offset] = bytes[bytes.length - count];
-            count--;
-            return 1;
-        }
-    }
-
-    public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
-
-    private InputStream fis;
-
-    private InputStream in;
-
-    private InputStreamReader is;
-
-    private InputStreamReader reader;
-
-    private final String source = "This is a test message with Unicode character. \u4e2d\u56fd is China's name in Chinese";
-
-    /*
-     * @see TestCase#setUp()
-     */
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        in = new ByteArrayInputStream(source.getBytes("UTF-8"));
-        reader = new InputStreamReader(in, "UTF-8");
-
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        OutputStreamWriter osw = new OutputStreamWriter(bos);
-        char[] buf = new char[fileString.length()];
-        fileString.getChars(0, fileString.length(), buf, 0);
-        osw.write(buf);
-        osw.close();
-        fis = new ByteArrayInputStream(bos.toByteArray());
-        is = new InputStreamReader(fis);
-    }
-
-    /*
-     * @see TestCase#tearDown()
-     */
-    @Override
-    protected void tearDown() throws Exception {
-        try {
-            in.close();
-            is.close();
-            fis.close();
-        } catch (IOException e) {
-            // Ignored
-        }
-
-        super.tearDown();
-    }
-
-    /**
-     * @tests java.io.InputStreamReader#close()
-     */
-    public void test_close() throws IOException {
-        is.close();
-        try {
-            is.read();
-            fail("Should throw IOException");
-        } catch (IOException e) {
-            // Expected
-        }
-
-        reader.close();
-        try {
-            reader.ready();
-            fail("Should throw IOException");
-        } catch (IOException e) {
-            // Expected
-        }
-
-        // Should be a no-op
-        reader.close();
-
-        // Tests after reader closed
-        in = new BufferedInputStream(
-                this
-                        .getClass()
-                        .getClassLoader()
-                        .getResourceAsStream(
-                                "org/apache/harmony/luni/tests/java/io/testfile-utf8.txt"));
-        reader = new InputStreamReader(in, "utf-8");
-        in.close();
-        try {
-            int count = reader.read(new char[1]);
-            fail("count:" + count);
-        } catch (IOException e) {
-            // Expected
-        }
-        try {
-            reader.read();
-            fail();
-        } catch (IOException e) {
-            // Expected
-        }
-
-        assertFalse(reader.ready());
-        Charset cs = Charset.forName("utf-8");
-        assertEquals(cs, Charset.forName(reader.getEncoding()));
-    }
-
-    /**
-     * @tests java.io.InputStreamReader#InputStreamReader(java.io.InputStream)
-     */
-    public void test_ConstructorLjava_io_InputStream() throws IOException {
-        try {
-            reader = new InputStreamReader(null);
-            fail();
-        } catch (NullPointerException e) {
-            // Expected
-        }
-        InputStreamReader reader2 = new InputStreamReader(in);
-        reader2.close();
-    }
-
-    /**
-     * @tests java.io.InputStreamReader#InputStreamReader(java.io.InputStream,
-     *        java.lang.String)
-     */
-    public void test_ConstructorLjava_io_InputStreamLjava_lang_String()
-            throws IOException {
-        is = new InputStreamReader(fis, "8859_1");
-
-        try {
-            is = new InputStreamReader(fis, "Bogus");
-            fail("Failed to throw Unsupported Encoding exception");
-        } catch (UnsupportedEncodingException e) {
-            assertNotNull(e.getMessage());
-        }
-
-        try {
-            reader = new InputStreamReader(null, "utf-8");
-            fail();
-        } catch (NullPointerException e) {
-            // Expected
-        }
-        try {
-            reader = new InputStreamReader(in, (String) null);
-            fail();
-        } catch (NullPointerException e) {
-            // Expected
-        }
-        try {
-            reader = new InputStreamReader(in, "");
-            fail();
-        } catch (UnsupportedEncodingException e) {
-            // Expected
-        }
-        try {
-            reader = new InputStreamReader(in, "badname");
-            fail();
-        } catch (UnsupportedEncodingException e) {
-            // Expected
-        }
-        InputStreamReader reader2 = new InputStreamReader(in, "utf-8");
-        assertEquals(Charset.forName(reader2.getEncoding()), Charset
-                .forName("utf-8"));
-        reader2.close();
-        reader2 = new InputStreamReader(in, "utf8");
-        assertEquals(Charset.forName(reader2.getEncoding()), Charset
-                .forName("utf-8"));
-        reader2.close();
-    }
-
-    /**
-     * @tests java.io.InputStreamReader(java.io.InputStream,
-     *        java.nio.charset.Charset)
-     */
-    public void test_ConstructorLjava_io_InputStreamLjava_nio_charset_Charset()
-            throws IOException {
-        Charset cs = Charset.forName("utf-8");
-        try {
-            reader = new InputStreamReader(null, cs);
-            fail();
-        } catch (NullPointerException e) {
-            // Expected
-        }
-        try {
-            reader = new InputStreamReader(in, (Charset) null);
-            fail();
-        } catch (NullPointerException e) {
-            // Expected
-        }
-        InputStreamReader reader2 = new InputStreamReader(in, cs);
-        assertEquals(Charset.forName(reader2.getEncoding()), cs);
-        reader2.close();
-    }
-
-    /**
-     * @tests java.io.InputStreamReader(java.io.InputStream,
-     *        java.nio.charset.CharsetDecoder)
-     */
-    public void test_ConstructorLjava_io_InputStreamLjava_nio_charset_CharsetDecoder()
-            throws IOException {
-        CharsetDecoder decoder = Charset.forName("utf-8").newDecoder();
-        try {
-            reader = new InputStreamReader(null, decoder);
-            fail();
-        } catch (NullPointerException e) {
-            // Expected
-        }
-        try {
-            reader = new InputStreamReader(in, (CharsetDecoder) null);
-            fail();
-        } catch (NullPointerException e) {
-            // Expected
-        }
-        InputStreamReader reader2 = new InputStreamReader(in, decoder);
-        assertEquals(Charset.forName(reader2.getEncoding()), decoder.charset());
-        reader2.close();
-    }
-
-    /**
-     * @tests java.io.InputStreamReader#getEncoding()
-     */
-    public void test_getEncoding() throws IOException {
-        InputStreamReader isr = new InputStreamReader(fis, "8859_1");
-        assertEquals("Returned incorrect encoding when setting 8859_1",
-                "ISO8859_1", isr.getEncoding());
-
-        isr = new InputStreamReader(fis, "ISO-8859-1");
-        assertEquals("Returned incorrect encoding when setting ISO-8859-1",
-                "ISO8859_1", isr.getEncoding());
-
-        byte b[] = new byte[5];
-        isr = new InputStreamReader(new ByteArrayInputStream(b), "UTF-16BE");
-        isr.close();
-        assertNull(isr.getEncoding());
-
-        try {
-            isr = new InputStreamReader(System.in, "UTF-16BE");
-        } catch (UnsupportedEncodingException e) {
-            // Ignored
-        }
-        assertEquals("UnicodeBigUnmarked", isr.getEncoding());
-    }
-
-    /**
-     * @tests java.io.InputStreamReader#read()
-     */
-    public void test_read() throws IOException {
-        assertEquals('T', (char) reader.read());
-        assertEquals('h', (char) reader.read());
-        assertEquals('i', (char) reader.read());
-        assertEquals('s', (char) reader.read());
-        assertEquals(' ', (char) reader.read());
-        reader.read(new char[source.length() - 5], 0, source.length() - 5);
-        assertEquals(-1, reader.read());
-
-        int c = is.read();
-        assertTrue("returned incorrect char", (char) c == fileString.charAt(0));
-        InputStreamReader reader = new InputStreamReader(
-                new ByteArrayInputStream(new byte[] { (byte) 0xe8, (byte) 0x9d,
-                        (byte) 0xa5 }), "UTF8");
-        assertTrue("wrong double byte char", reader.read() == '\u8765');
-
-        // Regression for HARMONY-166
-        InputStream in;
-
-        in = new LimitedByteArrayInputStream(0);
-        reader = new InputStreamReader(in, "UTF-16BE");
-        assertEquals("Incorrect byte UTF-16BE", '\u6172', reader.read());
-
-        in = new LimitedByteArrayInputStream(0);
-        reader = new InputStreamReader(in, "UTF-16LE");
-        assertEquals("Incorrect byte UTF-16BE", '\u7261', reader.read());
-
-        in = new LimitedByteArrayInputStream(1);
-        reader = new InputStreamReader(in, "UTF-16");
-        assertEquals("Incorrect byte UTF-16BE", '\u7261', reader.read());
-
-        /*
-         * Temporarily commented out due to lack of ISO2022 support in ICU4J 3.8
-         * in = new LimitedByteArrayInputStream(2); reader = new
-         * InputStreamReader(in, "ISO2022JP"); assertEquals("Incorrect byte
-         * ISO2022JP 1", '\u4e5d', reader.read()); assertEquals("Incorrect byte
-         * ISO2022JP 2", '\u7b2c', reader.read());
-         */
-    }
-
-    /*
-     * Class under test for int read() Regression for Harmony-411
-     */
-    public void test_read_1() throws IOException {
-        // if the decoder is constructed by InputStreamReader itself, the
-        // decoder's default error action is REPLACE
-        InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(
-                new byte[] { -32, -96 }), "UTF-8");
-        assertEquals("read() return incorrect value", 65533, isr.read());
-
-        InputStreamReader isr2 = new InputStreamReader(
-                new ByteArrayInputStream(new byte[] { -32, -96 }), Charset
-                        .forName("UTF-8"));
-        assertEquals("read() return incorrect value", 65533, isr2.read());
-
-        // if the decoder is passed in, keep its status intact
-        CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
-        decoder.onMalformedInput(CodingErrorAction.REPORT);
-        InputStreamReader isr3 = new InputStreamReader(
-                new ByteArrayInputStream(new byte[] { -32, -96 }), decoder);
-        try {
-            isr3.read();
-            fail("Should throw MalformedInputException");
-        } catch (MalformedInputException e) {
-            // expected
-        }
-
-        CharsetDecoder decoder2 = Charset.forName("UTF-8").newDecoder();
-        decoder2.onMalformedInput(CodingErrorAction.IGNORE);
-        InputStreamReader isr4 = new InputStreamReader(
-                new ByteArrayInputStream(new byte[] { -32, -96 }), decoder2);
-        assertEquals("read() return incorrect value", -1, isr4.read());
-
-        CharsetDecoder decoder3 = Charset.forName("UTF-8").newDecoder();
-        decoder3.onMalformedInput(CodingErrorAction.REPLACE);
-        InputStreamReader isr5 = new InputStreamReader(
-                new ByteArrayInputStream(new byte[] { -32, -96 }), decoder3);
-        assertEquals("read() return incorrect value", 65533, isr5.read());
-    }
-
-    public void test_read_specialCharset() throws IOException {
-        reader.close();
-        in = this.getClass().getClassLoader().getResourceAsStream(
-                "org/apache/harmony/luni/tests/java/io/testfile-utf8.txt");
-        reader = new InputStreamReader(in, "utf-8");
-        int c;
-        StringBuffer sb = new StringBuffer();
-        while ((c = reader.read()) != -1) {
-            sb.append((char) c);
-        }
-        // delete BOM
-        assertEquals(source, sb.deleteCharAt(0).toString());
-
-        sb.setLength(0);
-        reader.close();
-        in = this.getClass().getClassLoader().getResourceAsStream(
-                "org/apache/harmony/luni/tests/java/io/testfile.txt");
-        try {
-            reader = new InputStreamReader(in, "gb18030");
-        } catch (UnsupportedEncodingException e) {
-            System.out
-                    .println("GB18030 is not supported, abort test InputStreamReaderTest.testSpecialCharsetReading().");
-        }
-        while ((c = reader.read()) != -1) {
-            sb.append((char) c);
-        }
-        assertEquals(source, sb.toString());
-    }
-
-    /**
-     * @tests java.io.InputStreamReader#read(char[], int, int)
-     */
-    public void test_read$CII() throws IOException {
-        char[] rbuf = new char[100];
-        char[] sbuf = new char[100];
-        fileString.getChars(0, 100, sbuf, 0);
-        is.read(rbuf, 0, 100);
-        for (int i = 0; i < rbuf.length; i++) {
-            assertTrue("returned incorrect chars", rbuf[i] == sbuf[i]);
-        }
-
-        // Test successive reads
-        byte[] data = new byte[8192 * 2];
-        Arrays.fill(data, (byte) 116); // 116 = ISO-8859-1 value for 't'
-        ByteArrayInputStream bis = new ByteArrayInputStream(data);
-        InputStreamReader isr = new InputStreamReader(bis, "ISO-8859-1");
-
-        // One less than the InputStreamReader.BUFFER_SIZE
-        char[] buf = new char[8191];
-        int bytesRead = isr.read(buf, 0, buf.length);
-        assertFalse(-1 == bytesRead);
-        bytesRead = isr.read(buf, 0, buf.length);
-        assertFalse(-1 == bytesRead);
-
-        bis = new ByteArrayInputStream(source.getBytes("UTF-8"));
-        isr = new InputStreamReader(in, "UTF-8");
-        char[] chars = new char[source.length()];
-        assertEquals(source.length() - 3, isr.read(chars, 0, chars.length - 3));
-        assertEquals(3, isr.read(chars, 0, 10));
-    }
-
-    /*
-     * Class under test for int read(char[], int, int)
-     */
-    public void test_read$CII_1() throws IOException {
-        try {
-            // Throws IndexOutOfBoundsException before NullPointerException
-            reader.read(null, -1, 1);
-            fail("Should throw IndexOutOfBoundsException");
-        } catch (IndexOutOfBoundsException e) {
-            // expected
-        }
-
-        try {
-            // Throws NullPointerException before IndexOutOfBoundsException
-            reader.read(null, 0, -1);
-            fail("Should throw NullPointerException");
-        } catch (NullPointerException e) {
-            // expected
-        }
-
-        try {
-            reader.read(null, 0, 1);
-            fail();
-        } catch (NullPointerException e) {
-            // Expected
-        }
-        try {
-            reader.read(new char[3], -1, 1);
-            fail();
-        } catch (IndexOutOfBoundsException e) {
-            // Expected
-        }
-        try {
-            reader.read(new char[3], 0, -1);
-            fail();
-        } catch (IndexOutOfBoundsException e) {
-            // Expected
-        }
-        try {
-            reader.read(new char[3], 1, 3);
-            fail();
-        } catch (IndexOutOfBoundsException e) {
-            // Expected
-        }
-        assertEquals(0, reader.read(new char[3], 3, 0));
-        char[] chars = new char[source.length()];
-        assertEquals(0, reader.read(chars, 0, 0));
-        assertEquals(0, chars[0]);
-        assertEquals(3, reader.read(chars, 0, 3));
-        assertEquals(5, reader.read(chars, 3, 5));
-        assertEquals(source.length() - 8, reader.read(chars, 8,
-                chars.length - 8));
-        assertTrue(Arrays.equals(chars, source.toCharArray()));
-        assertEquals(-1, reader.read(chars, 0, chars.length));
-        assertTrue(Arrays.equals(chars, source.toCharArray()));
-    }
-
-    /**
-     * @tests java.io.InputStreamReader#ready()
-     */
-    public void test_ready() throws IOException {
-        assertTrue("Ready test failed", is.ready());
-        is.read();
-        assertTrue("More chars, but not ready", is.ready());
-
-        assertTrue(reader.ready());
-        reader.read(new char[source.length()]);
-        assertFalse(reader.ready());
-    }
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.luni.tests.java.io;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CodingErrorAction;
+import java.nio.charset.MalformedInputException;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+public class InputStreamReaderTest extends TestCase {
+
+    static class LimitedByteArrayInputStream extends ByteArrayInputStream {
+
+        // A ByteArrayInputStream that only returns a single byte per read
+        byte[] bytes;
+
+        int count;
+
+        public LimitedByteArrayInputStream(int type) {
+            super(new byte[0]);
+            switch (type) {
+            case 0:
+                bytes = new byte[] { 0x61, 0x72 };
+                break;
+            case 1:
+                bytes = new byte[] { (byte) 0xff, (byte) 0xfe, 0x61, 0x72 };
+                break;
+            case 2:
+                bytes = new byte[] { '\u001b', '$', 'B', '6', 'e', 'B', 'h',
+                        '\u001b', '(', 'B' };
+                break;
+            }
+            count = bytes.length;
+        }
+
+        @Override
+        public int available() {
+            return count;
+        }
+
+        @Override
+        public int read() {
+            if (count == 0) {
+                return -1;
+            }
+            count--;
+            return bytes[bytes.length - count];
+        }
+
+        @Override
+        public int read(byte[] buffer, int offset, int length) {
+            if (count == 0) {
+                return -1;
+            }
+            if (length == 0) {
+                return 0;
+            }
+            buffer[offset] = bytes[bytes.length - count];
+            count--;
+            return 1;
+        }
+    }
+
+    public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
+
+    private InputStream fis;
+
+    private InputStream in;
+
+    private InputStreamReader is;
+
+    private InputStreamReader reader;
+
+    private final String source = "This is a test message with Unicode character. \u4e2d\u56fd is China's name in Chinese";
+
+    /*
+     * @see TestCase#setUp()
+     */
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        in = new ByteArrayInputStream(source.getBytes("UTF-8"));
+        reader = new InputStreamReader(in, "UTF-8");
+
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        OutputStreamWriter osw = new OutputStreamWriter(bos);
+        char[] buf = new char[fileString.length()];
+        fileString.getChars(0, fileString.length(), buf, 0);
+        osw.write(buf);
+        osw.close();
+        fis = new ByteArrayInputStream(bos.toByteArray());
+        is = new InputStreamReader(fis);
+    }
+
+    /*
+     * @see TestCase#tearDown()
+     */
+    @Override
+    protected void tearDown() throws Exception {
+        try {
+            in.close();
+            is.close();
+            fis.close();
+        } catch (IOException e) {
+            // Ignored
+        }
+
+        super.tearDown();
+    }
+
+    /**
+     * @tests java.io.InputStreamReader#close()
+     */
+    public void test_close() throws IOException {
+        is.close();
+        try {
+            is.read();
+            fail("Should throw IOException");
+        } catch (IOException e) {
+            // Expected
+        }
+
+        reader.close();
+        try {
+            reader.ready();
+            fail("Should throw IOException");
+        } catch (IOException e) {
+            // Expected
+        }
+
+        // Should be a no-op
+        reader.close();
+
+        // Tests after reader closed
+        in = new BufferedInputStream(
+                this
+                        .getClass()
+                        .getClassLoader()
+                        .getResourceAsStream(
+                                "org/apache/harmony/luni/tests/java/io/testfile-utf8.txt"));
+        reader = new InputStreamReader(in, "utf-8");
+        in.close();
+        try {
+            int count = reader.read(new char[1]);
+            fail("count:" + count);
+        } catch (IOException e) {
+            // Expected
+        }
+        try {
+            reader.read();
+            fail();
+        } catch (IOException e) {
+            // Expected
+        }
+
+        assertFalse(reader.ready());
+        Charset cs = Charset.forName("utf-8");
+        assertEquals(cs, Charset.forName(reader.getEncoding()));
+    }
+
+    /**
+     * @tests java.io.InputStreamReader#InputStreamReader(java.io.InputStream)
+     */
+    public void test_ConstructorLjava_io_InputStream() throws IOException {
+        try {
+            reader = new InputStreamReader(null);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        InputStreamReader reader2 = new InputStreamReader(in);
+        reader2.close();
+    }
+
+    /**
+     * @tests java.io.InputStreamReader#InputStreamReader(java.io.InputStream,
+     *        java.lang.String)
+     */
+    public void test_ConstructorLjava_io_InputStreamLjava_lang_String()
+            throws IOException {
+        is = new InputStreamReader(fis, "8859_1");
+
+        try {
+            is = new InputStreamReader(fis, "Bogus");
+            fail("Failed to throw Unsupported Encoding exception");
+        } catch (UnsupportedEncodingException e) {
+            assertNotNull(e.getMessage());
+        }
+
+        try {
+            reader = new InputStreamReader(null, "utf-8");
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        try {
+            reader = new InputStreamReader(in, (String) null);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        try {
+            reader = new InputStreamReader(in, "");
+            fail();
+        } catch (UnsupportedEncodingException e) {
+            // Expected
+        }
+        try {
+            reader = new InputStreamReader(in, "badname");
+            fail();
+        } catch (UnsupportedEncodingException e) {
+            // Expected
+        }
+        InputStreamReader reader2 = new InputStreamReader(in, "utf-8");
+        assertEquals(Charset.forName(reader2.getEncoding()), Charset
+                .forName("utf-8"));
+        reader2.close();
+        reader2 = new InputStreamReader(in, "utf8");
+        assertEquals(Charset.forName(reader2.getEncoding()), Charset
+                .forName("utf-8"));
+        reader2.close();
+    }
+
+    /**
+     * @tests java.io.InputStreamReader(java.io.InputStream,
+     *        java.nio.charset.Charset)
+     */
+    public void test_ConstructorLjava_io_InputStreamLjava_nio_charset_Charset()
+            throws IOException {
+        Charset cs = Charset.forName("utf-8");
+        try {
+            reader = new InputStreamReader(null, cs);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        try {
+            reader = new InputStreamReader(in, (Charset) null);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        InputStreamReader reader2 = new InputStreamReader(in, cs);
+        assertEquals(Charset.forName(reader2.getEncoding()), cs);
+        reader2.close();
+    }
+
+    /**
+     * @tests java.io.InputStreamReader(java.io.InputStream,
+     *        java.nio.charset.CharsetDecoder)
+     */
+    public void test_ConstructorLjava_io_InputStreamLjava_nio_charset_CharsetDecoder()
+            throws IOException {
+        CharsetDecoder decoder = Charset.forName("utf-8").newDecoder();
+        try {
+            reader = new InputStreamReader(null, decoder);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        try {
+            reader = new InputStreamReader(in, (CharsetDecoder) null);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        InputStreamReader reader2 = new InputStreamReader(in, decoder);
+        assertEquals(Charset.forName(reader2.getEncoding()), decoder.charset());
+        reader2.close();
+    }
+
+    /**
+     * @tests java.io.InputStreamReader#getEncoding()
+     */
+    public void test_getEncoding() throws IOException {
+        InputStreamReader isr = new InputStreamReader(fis, "8859_1");
+        assertEquals("Returned incorrect encoding when setting 8859_1",
+                "ISO8859_1", isr.getEncoding());
+
+        isr = new InputStreamReader(fis, "ISO-8859-1");
+        assertEquals("Returned incorrect encoding when setting ISO-8859-1",
+                "ISO8859_1", isr.getEncoding());
+
+        byte b[] = new byte[5];
+        isr = new InputStreamReader(new ByteArrayInputStream(b), "UTF-16BE");
+        isr.close();
+        assertNull(isr.getEncoding());
+
+        try {
+            isr = new InputStreamReader(System.in, "UTF-16BE");
+        } catch (UnsupportedEncodingException e) {
+            // Ignored
+        }
+        assertEquals("UnicodeBigUnmarked", isr.getEncoding());
+    }
+
+    /**
+     * @tests java.io.InputStreamReader#read()
+     */
+    public void test_read() throws IOException {
+        assertEquals('T', (char) reader.read());
+        assertEquals('h', (char) reader.read());
+        assertEquals('i', (char) reader.read());
+        assertEquals('s', (char) reader.read());
+        assertEquals(' ', (char) reader.read());
+        reader.read(new char[source.length() - 5], 0, source.length() - 5);
+        assertEquals(-1, reader.read());
+
+        int c = is.read();
+        assertTrue("returned incorrect char", (char) c == fileString.charAt(0));
+        InputStreamReader reader = new InputStreamReader(
+                new ByteArrayInputStream(new byte[] { (byte) 0xe8, (byte) 0x9d,
+                        (byte) 0xa5 }), "UTF8");
+        assertTrue("wrong double byte char", reader.read() == '\u8765');
+
+        // Regression for HARMONY-166
+        InputStream in;
+
+        in = new LimitedByteArrayInputStream(0);
+        reader = new InputStreamReader(in, "UTF-16BE");
+        assertEquals("Incorrect byte UTF-16BE", '\u6172', reader.read());
+
+        in = new LimitedByteArrayInputStream(0);
+        reader = new InputStreamReader(in, "UTF-16LE");
+        assertEquals("Incorrect byte UTF-16BE", '\u7261', reader.read());
+
+        in = new LimitedByteArrayInputStream(1);
+        reader = new InputStreamReader(in, "UTF-16");
+        assertEquals("Incorrect byte UTF-16BE", '\u7261', reader.read());
+
+        /*
+         * Temporarily commented out due to lack of ISO2022 support in ICU4J 3.8
+         * in = new LimitedByteArrayInputStream(2); reader = new
+         * InputStreamReader(in, "ISO2022JP"); assertEquals("Incorrect byte
+         * ISO2022JP 1", '\u4e5d', reader.read()); assertEquals("Incorrect byte
+         * ISO2022JP 2", '\u7b2c', reader.read());
+         */
+    }
+
+    /*
+     * Class under test for int read() Regression for Harmony-411
+     */
+    public void test_read_1() throws IOException {
+        // if the decoder is constructed by InputStreamReader itself, the
+        // decoder's default error action is REPLACE
+        InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(
+                new byte[] { -32, -96 }), "UTF-8");
+        assertEquals("read() return incorrect value", 65533, isr.read());
+
+        InputStreamReader isr2 = new InputStreamReader(
+                new ByteArrayInputStream(new byte[] { -32, -96 }), Charset
+                        .forName("UTF-8"));
+        assertEquals("read() return incorrect value", 65533, isr2.read());
+
+        // if the decoder is passed in, keep its status intact
+        CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
+        decoder.onMalformedInput(CodingErrorAction.REPORT);
+        InputStreamReader isr3 = new InputStreamReader(
+                new ByteArrayInputStream(new byte[] { -32, -96 }), decoder);
+        try {
+            isr3.read();
+            fail("Should throw MalformedInputException");
+        } catch (MalformedInputException e) {
+            // expected
+        }
+
+        CharsetDecoder decoder2 = Charset.forName("UTF-8").newDecoder();
+        decoder2.onMalformedInput(CodingErrorAction.IGNORE);
+        InputStreamReader isr4 = new InputStreamReader(
+                new ByteArrayInputStream(new byte[] { -32, -96 }), decoder2);
+        assertEquals("read() return incorrect value", -1, isr4.read());
+
+        CharsetDecoder decoder3 = Charset.forName("UTF-8").newDecoder();
+        decoder3.onMalformedInput(CodingErrorAction.REPLACE);
+        InputStreamReader isr5 = new InputStreamReader(
+                new ByteArrayInputStream(new byte[] { -32, -96 }), decoder3);
+        assertEquals("read() return incorrect value", 65533, isr5.read());
+    }
+
+    public void test_read_specialCharset() throws IOException {
+        reader.close();
+        in = this.getClass().getClassLoader().getResourceAsStream(
+                "org/apache/harmony/luni/tests/java/io/testfile-utf8.txt");
+        reader = new InputStreamReader(in, "utf-8");
+        int c;
+        StringBuffer sb = new StringBuffer();
+        while ((c = reader.read()) != -1) {
+            sb.append((char) c);
+        }
+        // delete BOM
+        assertEquals(source, sb.deleteCharAt(0).toString());
+
+        sb.setLength(0);
+        reader.close();
+        in = this.getClass().getClassLoader().getResourceAsStream(
+                "org/apache/harmony/luni/tests/java/io/testfile.txt");
+        try {
+            reader = new InputStreamReader(in, "gb18030");
+        } catch (UnsupportedEncodingException e) {
+            System.out
+                    .println("GB18030 is not supported, abort test InputStreamReaderTest.testSpecialCharsetReading().");
+        }
+        while ((c = reader.read()) != -1) {
+            sb.append((char) c);
+        }
+        assertEquals(source, sb.toString());
+    }
+
+    /**
+     * @tests java.io.InputStreamReader#read(char[], int, int)
+     */
+    public void test_read$CII() throws IOException {
+        char[] rbuf = new char[100];
+        char[] sbuf = new char[100];
+        fileString.getChars(0, 100, sbuf, 0);
+        is.read(rbuf, 0, 100);
+        for (int i = 0; i < rbuf.length; i++) {
+            assertTrue("returned incorrect chars", rbuf[i] == sbuf[i]);
+        }
+
+        // Test successive reads
+        byte[] data = new byte[8192 * 2];
+        Arrays.fill(data, (byte) 116); // 116 = ISO-8859-1 value for 't'
+        ByteArrayInputStream bis = new ByteArrayInputStream(data);
+        InputStreamReader isr = new InputStreamReader(bis, "ISO-8859-1");
+
+        // One less than the InputStreamReader.BUFFER_SIZE
+        char[] buf = new char[8191];
+        int bytesRead = isr.read(buf, 0, buf.length);
+        assertFalse(-1 == bytesRead);
+        bytesRead = isr.read(buf, 0, buf.length);
+        assertFalse(-1 == bytesRead);
+
+        bis = new ByteArrayInputStream(source.getBytes("UTF-8"));
+        isr = new InputStreamReader(in, "UTF-8");
+        char[] chars = new char[source.length()];
+        assertEquals(source.length() - 3, isr.read(chars, 0, chars.length - 3));
+        assertEquals(3, isr.read(chars, 0, 10));
+    }
+
+    /*
+     * Class under test for int read(char[], int, int)
+     */
+    public void test_read$CII_1() throws IOException {
+        try {
+            // Throws IndexOutOfBoundsException before NullPointerException
+            reader.read(null, -1, 1);
+            fail("Should throw IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            // Throws NullPointerException before IndexOutOfBoundsException
+            reader.read(null, 0, -1);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            reader.read(null, 0, 1);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        try {
+            reader.read(new char[3], -1, 1);
+            fail();
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+        try {
+            reader.read(new char[3], 0, -1);
+            fail();
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+        try {
+            reader.read(new char[3], 1, 3);
+            fail();
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+        assertEquals(0, reader.read(new char[3], 3, 0));
+        char[] chars = new char[source.length()];
+        assertEquals(0, reader.read(chars, 0, 0));
+        assertEquals(0, chars[0]);
+        assertEquals(3, reader.read(chars, 0, 3));
+        assertEquals(5, reader.read(chars, 3, 5));
+        assertEquals(source.length() - 8, reader.read(chars, 8,
+                chars.length - 8));
+        assertTrue(Arrays.equals(chars, source.toCharArray()));
+        assertEquals(-1, reader.read(chars, 0, chars.length));
+        assertTrue(Arrays.equals(chars, source.toCharArray()));
+    }
+
+    /**
+     * @tests java.io.InputStreamReader#ready()
+     */
+    public void test_ready() throws IOException {
+        assertTrue("Ready test failed", is.ready());
+        is.read();
+        assertTrue("More chars, but not ready", is.ready());
+
+        assertTrue(reader.ready());
+        reader.read(new char[source.length()]);
+        assertFalse(reader.ready());
+    }
+}

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLEncoderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLEncoderTest.java?rev=999716&r1=999715&r2=999716&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLEncoderTest.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLEncoderTest.java Wed Sep 22 01:32:56 2010
@@ -1,67 +1,67 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You 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.luni.tests.java.net;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-
-import junit.framework.TestCase;
-import tests.support.Support_Configuration;
-
-public class URLEncoderTest extends TestCase {
-
-    /**
-     * @tests java.net.URLEncoder#encode(java.lang.String)
-     */
-    @SuppressWarnings("deprecation")
-    public void test_encodeLjava_lang_String() {
-        final String URL = "http://" + Support_Configuration.HomeAddress;
-        final String URL2 = "telnet://justWantToHaveFun.com:400";
-        final String URL3 = "file://myServer.org/a file with spaces.jpg";
-
-        assertTrue("1. Incorrect encoding/decoding", URLDecoder.decode(
-                URLEncoder.encode(URL)).equals(URL));
-        assertTrue("2. Incorrect encoding/decoding", URLDecoder.decode(
-                URLEncoder.encode(URL2)).equals(URL2));
-        assertTrue("3. Incorrect encoding/decoding", URLDecoder.decode(
-                URLEncoder.encode(URL3)).equals(URL3));
-    }
-
-    /**
-     * @tests URLEncoder#encode(String, String)
-     */
-    public void test_encodeLjava_lang_StringLjava_lang_String()
-            throws Exception {
-        // Regression for HARMONY-24
-        try {
-            URLEncoder.encode("str", "unknown_enc");
-            fail("Assert 0: Should throw UEE for invalid encoding");
-        } catch (UnsupportedEncodingException e) {
-            // expected
-        }
-
-        // Regression for HARMONY-1233
-        try {
-            URLEncoder.encode(null, "harmony");
-            fail("NullPointerException expected");
-        } catch (NullPointerException e) {
-            // expected
-        }
-    }
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.luni.tests.java.net;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+
+import junit.framework.TestCase;
+import tests.support.Support_Configuration;
+
+public class URLEncoderTest extends TestCase {
+
+    /**
+     * @tests java.net.URLEncoder#encode(java.lang.String)
+     */
+    @SuppressWarnings("deprecation")
+    public void test_encodeLjava_lang_String() {
+        final String URL = "http://" + Support_Configuration.HomeAddress;
+        final String URL2 = "telnet://justWantToHaveFun.com:400";
+        final String URL3 = "file://myServer.org/a file with spaces.jpg";
+
+        assertTrue("1. Incorrect encoding/decoding", URLDecoder.decode(
+                URLEncoder.encode(URL)).equals(URL));
+        assertTrue("2. Incorrect encoding/decoding", URLDecoder.decode(
+                URLEncoder.encode(URL2)).equals(URL2));
+        assertTrue("3. Incorrect encoding/decoding", URLDecoder.decode(
+                URLEncoder.encode(URL3)).equals(URL3));
+    }
+
+    /**
+     * @tests URLEncoder#encode(String, String)
+     */
+    public void test_encodeLjava_lang_StringLjava_lang_String()
+            throws Exception {
+        // Regression for HARMONY-24
+        try {
+            URLEncoder.encode("str", "unknown_enc");
+            fail("Assert 0: Should throw UEE for invalid encoding");
+        } catch (UnsupportedEncodingException e) {
+            // expected
+        }
+
+        // Regression for HARMONY-1233
+        try {
+            URLEncoder.encode(null, "harmony");
+            fail("NullPointerException expected");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+}



Mime
View raw message