You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2008/01/28 13:08:04 UTC
svn commit: r615857 [1/5] -
/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/
Author: tellison
Date: Mon Jan 28 04:07:47 2008
New Revision: 615857
URL: http://svn.apache.org/viewvc?rev=615857&view=rev
Log:
Another round of java.io test tidy-ups, including formatting, tidy-up imports, and letting JUnit handle the exceptions.
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileDescriptorTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileNotFoundExceptionTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileReaderTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileWriterTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterInputStreamTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterOutputStreamTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/IOExceptionTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InterruptedIOExceptionTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InvalidClassExceptionTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/LineNumberInputStreamTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/LineNumberReaderTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/NotActiveExceptionTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/NotSerializableExceptionTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectInputStream2Test.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectInputStreamTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OpenRandomFileTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedReaderTest.java
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileDescriptorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileDescriptorTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileDescriptorTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileDescriptorTest.java Mon Jan 28 04:07:47 2008
@@ -25,7 +25,9 @@
import java.io.IOException;
import java.io.RandomAccessFile;
-public class FileDescriptorTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
+
+public class FileDescriptorTest extends TestCase {
private static String platformId = "JDK"
+ System.getProperty("java.vm.version").replace('.', '-');
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java Mon Jan 28 04:07:47 2008
@@ -24,9 +24,10 @@
import java.io.IOException;
import java.security.Permission;
+import junit.framework.TestCase;
import tests.support.Support_PlatformFile;
-public class FileInputStreamTest extends junit.framework.TestCase {
+public class FileInputStreamTest extends TestCase {
public String fileName;
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileNotFoundExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileNotFoundExceptionTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileNotFoundExceptionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileNotFoundExceptionTest.java Mon Jan 28 04:07:47 2008
@@ -19,7 +19,9 @@
import java.io.FileNotFoundException;
-public class FileNotFoundExceptionTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
+
+public class FileNotFoundExceptionTest extends TestCase {
/**
* @tests java.io.FileNotFoundException#FileNotFoundException()
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java Mon Jan 28 04:07:47 2008
@@ -23,7 +23,9 @@
import java.io.FileOutputStream;
import java.io.IOException;
-public class FileOutputStreamTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
+
+public class FileOutputStreamTest extends TestCase {
public String fileName;
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java Mon Jan 28 04:07:47 2008
@@ -21,7 +21,9 @@
import java.io.FilePermission;
import java.security.PermissionCollection;
-public class FilePermissionTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
+
+public class FilePermissionTest extends TestCase {
FilePermission readAllFiles = new FilePermission("<<ALL FILES>>", "read");
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileReaderTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileReaderTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileReaderTest.java Mon Jan 28 04:07:47 2008
@@ -24,7 +24,9 @@
import java.io.FileWriter;
import java.io.IOException;
-public class FileReaderTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
+
+public class FileReaderTest extends TestCase {
FileReader br;
@@ -101,14 +103,20 @@
protected void tearDown() {
try {
bw.close();
+ } catch (Exception e) {
+ // Ignore
+ }
+ try {
br.close();
} catch (Exception e) {
+ // Ignore
}
-
try {
- if (fis != null)
+ if (fis != null) {
fis.close();
+ }
} catch (Exception e) {
+ // Ignore
}
f.delete();
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileWriterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileWriterTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileWriterTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileWriterTest.java Mon Jan 28 04:07:47 2008
@@ -26,7 +26,9 @@
import java.io.FileWriter;
import java.io.IOException;
-public class FileWriterTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
+
+public class FileWriterTest extends TestCase {
FileWriter fw;
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterInputStreamTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterInputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterInputStreamTest.java Mon Jan 28 04:07:47 2008
@@ -18,21 +18,24 @@
package org.apache.harmony.luni.tests.java.io;
import java.io.File;
+import java.io.FilterInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import junit.framework.TestCase;
import tests.support.Support_PlatformFile;
-public class FilterInputStreamTest extends junit.framework.TestCase {
+public class FilterInputStreamTest extends TestCase {
- static class MyFilterInputStream extends java.io.FilterInputStream {
- public MyFilterInputStream(java.io.InputStream is) {
+ static class MyFilterInputStream extends FilterInputStream {
+ public MyFilterInputStream(InputStream is) {
super(is);
}
}
private String fileName;
- private java.io.InputStream is;
+ private InputStream is;
byte[] ibuf = new byte[4096];
@@ -157,6 +160,7 @@
try {
is.close();
} catch (Exception e) {
+ // Ignored
}
new File(fileName).delete();
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterOutputStreamTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterOutputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterOutputStreamTest.java Mon Jan 28 04:07:47 2008
@@ -17,16 +17,21 @@
package org.apache.harmony.luni.tests.java.io;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FilterOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+
import junit.framework.TestCase;
public class FilterOutputStreamTest extends TestCase {
- private java.io.OutputStream os;
+ private OutputStream os;
- java.io.ByteArrayOutputStream bos;
+ ByteArrayOutputStream bos;
- java.io.ByteArrayInputStream bis;
+ ByteArrayInputStream bis;
byte[] ibuf = new byte[4096];
@@ -36,8 +41,8 @@
* @tests java.io.FilterOutputStream#FilterOutputStream(java.io.OutputStream)
*/
public void test_ConstructorLjava_io_OutputStream() throws IOException {
- bos = new java.io.ByteArrayOutputStream();
- os = new java.io.FilterOutputStream(bos);
+ bos = new ByteArrayOutputStream();
+ os = new FilterOutputStream(bos);
os.write('t');
}
@@ -45,8 +50,8 @@
* @tests java.io.FilterOutputStream#close()
*/
public void test_close() throws IOException {
- bos = new java.io.ByteArrayOutputStream();
- os = new java.io.FilterOutputStream(bos);
+ bos = new ByteArrayOutputStream();
+ os = new FilterOutputStream(bos);
os.write(fileString.getBytes(), 0, 500);
os.flush();
assertEquals("Bytes not written after flush", 500, bos.size());
@@ -57,8 +62,8 @@
* @tests java.io.FilterOutputStream#flush()
*/
public void test_flush() throws IOException {
- bos = new java.io.ByteArrayOutputStream();
- os = new java.io.FilterOutputStream(bos);
+ bos = new ByteArrayOutputStream();
+ os = new FilterOutputStream(bos);
os.write(fileString.getBytes(), 0, 500);
os.flush();
assertEquals("Bytes not written after flush", 500, bos.size());
@@ -69,10 +74,10 @@
* @tests java.io.FilterOutputStream#write(byte[])
*/
public void test_write$B() throws IOException {
- bos = new java.io.ByteArrayOutputStream();
- os = new java.io.FilterOutputStream(bos);
+ bos = new ByteArrayOutputStream();
+ os = new FilterOutputStream(bos);
os.write(fileString.getBytes());
- bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+ bis = new ByteArrayInputStream(bos.toByteArray());
os.flush();
assertTrue("Bytes not written after flush",
bis.available() == fileString.length());
@@ -86,10 +91,10 @@
* @tests java.io.FilterOutputStream#write(byte[], int, int)
*/
public void test_write$BII() throws IOException {
- bos = new java.io.ByteArrayOutputStream();
- os = new java.io.FilterOutputStream(bos);
+ bos = new ByteArrayOutputStream();
+ os = new FilterOutputStream(bos);
os.write(fileString.getBytes(), 0, fileString.length());
- bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+ bis = new ByteArrayInputStream(bos.toByteArray());
os.flush();
assertTrue("Bytes not written after flush",
bis.available() == fileString.length());
@@ -103,10 +108,10 @@
* @tests java.io.FilterOutputStream#write(int)
*/
public void test_writeI() throws IOException {
- bos = new java.io.ByteArrayOutputStream();
- os = new java.io.FilterOutputStream(bos);
+ bos = new ByteArrayOutputStream();
+ os = new FilterOutputStream(bos);
os.write('t');
- bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+ bis = new ByteArrayInputStream(bos.toByteArray());
os.flush();
assertEquals("Byte not written after flush", 1, bis.available());
byte[] wbytes = new byte[1];
@@ -127,6 +132,7 @@
if (os != null)
os.close();
} catch (Exception e) {
+ // Ignored
}
}
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/IOExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/IOExceptionTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/IOExceptionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/IOExceptionTest.java Mon Jan 28 04:07:47 2008
@@ -19,49 +19,35 @@
import java.io.IOException;
-public class IOExceptionTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
- /**
- * @tests java.io.IOException#IOException()
- */
- public void test_Constructor() {
- // Test for method java.io.IOException()
- try {
- throw new IOException();
- } catch (IOException e) {
- return;
- } catch (Exception e) {
- fail("Exception during IOException test" + e.toString());
- }
- fail("Failed to generate exception");
- }
+public class IOExceptionTest extends TestCase {
- /**
- * @tests java.io.IOException#IOException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.IOException(java.lang.String)
- try {
- throw new IOException("Some error message");
- } catch (IOException e) {
- return;
- } catch (Exception e) {
- fail("Exception during IOException test" + e.toString());
- }
- fail("Failed to generate exception");
- }
+ /**
+ * @tests java.io.IOException#IOException()
+ */
+ public void test_Constructor() {
+ try {
+ if (true) {
+ throw new IOException();
+ }
+ fail("Exception during IOException test");
+ } catch (IOException e) {
+ // Expected
+ }
+ }
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
+ /**
+ * @tests java.io.IOException#IOException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ try {
+ if (true) {
+ throw new IOException("Some error message");
+ }
+ fail("Failed to generate exception");
+ } catch (IOException e) {
+ // Expected
+ }
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java Mon Jan 28 04:07:47 2008
@@ -1,582 +1,533 @@
-/*
- * 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.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 {
-
- private final String source = "This is a test message with Unicode character. \u4e2d\u56fd is China's name in Chinese";
-
- private InputStream in;
-
- private InputStreamReader reader;
-
- private InputStreamReader is;
-
- private InputStream fis;
-
- 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";
-
- 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;
- }
-
- public int read() {
- if (count == 0)
- return -1;
- count--;
- return bytes[bytes.length - count];
- }
-
- 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 int available() {
- return count;
- }
- }
-
- /*
- * @see TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
-
- try {
- 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);
- } catch (Exception e) {
- fail("Exception during setUp : " + e.getMessage());
- }
- }
-
- /*
- * @see TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- try {
- in.close();
- is.close();
- fis.close();
- } catch (IOException e) {
- }
-
- super.tearDown();
- }
-
-
- public void testGetEncoding_StreamClosed() throws IOException {
- InputStreamReader in = null;
- byte b[] = new byte[5];
- in = new InputStreamReader(new ByteArrayInputStream(b), "UTF-16BE");
- in.close();
- String result = in.getEncoding();
- assertNull(result);
- }
-
- /**
- * @tests java.io.InputStreamReader#read()
- */
- public void testGetEncoding_NotHistorical() {
- InputStreamReader in = null;
- try {
- in = new InputStreamReader(System.in, "UTF-16BE");
- } catch (UnsupportedEncodingException e) {
- // ok
- }
- String result = in.getEncoding();
- assertEquals("UnicodeBigUnmarked", result);
-
- }
-
- public void testClose() throws IOException {
- reader.close();
- try {
- reader.ready();
- fail("Should throw IOException");
- } catch (IOException e) {
- }
- reader.close();
- }
-
- /*
- * Class under test for int read()
- */
- public void testRead() 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());
- }
-
- /*
- * Class under test for int read()
- * Regression for Harmony-411
- */
- public void testRead1() 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 intacted
- 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());
- }
-
- /*
- * Class under test for int read(char[], int, int)
- */
- public void testReadcharArrayintint() throws IOException {
- //throws IndexOutOfBoundsException before NullPointerException
- try {
- reader.read(null, -1, 1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- //throws NullPointerException before IndexOutOfBoundsException
- try {
- reader.read(null, 0, -1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- //expected
- }
-
- try {
- reader.read(null, 0, 1);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- reader.read(new char[3], -1, 1);
- fail();
- } catch (IndexOutOfBoundsException e) {
- }
- try {
- reader.read(new char[3], 0, -1);
- fail();
- } catch (IndexOutOfBoundsException e) {
- }
- try {
- reader.read(new char[3], 1, 3);
- fail();
- } catch (IndexOutOfBoundsException e) {
- }
- 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()));
- }
-
- public void testReadcharArrayintint2() throws IOException {
- char[] chars = new char[source.length()];
- assertEquals(source.length() - 3, reader.read(chars, 0,
- chars.length - 3));
- assertEquals(3, reader.read(chars, 0, 10));
- }
-
- public void testReady() throws IOException {
- assertTrue(reader.ready());
- reader.read(new char[source.length()]);
- assertFalse(reader.ready());
- }
-
- public void testSpecialCharsetReading() 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());
- }
-
- public void testAfterClose() throws IOException {
- reader.close();
- 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) {
- }
- try {
- reader.read();
- fail();
- } catch (IOException e) {
- }
-
- assertFalse(reader.ready());
- Charset cs = Charset.forName("utf-8");
- assertEquals(cs, Charset.forName(reader.getEncoding()));
- reader.close();
- }
-
- /*
- * Class under test for void InputStreamReader(InputStream)
- */
- public void testInputStreamReaderInputStream() throws IOException {
- try {
- reader = new InputStreamReader(null);
- fail();
- } catch (NullPointerException e) {
- }
- InputStreamReader reader2 = new InputStreamReader(in);
- reader2.close();
- }
-
- /*
- * Class under test for void InputStreamReader(InputStream, String)
- */
- public void testInputStreamReaderInputStreamString() throws IOException {
- try {
- reader = new InputStreamReader(null, "utf-8");
- fail();
- } catch (NullPointerException e) {
- }
- try {
- reader = new InputStreamReader(in, (String) null);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- reader = new InputStreamReader(in, "");
- fail();
- } catch (UnsupportedEncodingException e) {
- }
- try {
- reader = new InputStreamReader(in, "badname");
- fail();
- } catch (UnsupportedEncodingException e) {
- }
- 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();
- }
-
- /*
- * Class under test for void InputStreamReader(InputStream, CharsetDecoder)
- */
- public void testInputStreamReaderInputStreamCharsetDecoder()
- throws Exception {
- CharsetDecoder decoder = Charset.forName("utf-8").newDecoder();
- try {
- reader = new InputStreamReader(null, decoder);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- reader = new InputStreamReader(in, (CharsetDecoder) null);
- fail();
- } catch (NullPointerException e) {
- }
- InputStreamReader reader2 = new InputStreamReader(in, decoder);
- assertEquals(Charset.forName(reader2.getEncoding()), decoder.charset());
- reader2.close();
- }
-
- /*
- * Class under test for void InputStreamReader(InputStream, Charset)
- */
- public void testInputStreamReaderInputStreamCharset() throws IOException {
- Charset cs = Charset.forName("utf-8");
- try {
- reader = new InputStreamReader(null, cs);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- reader = new InputStreamReader(in, (Charset) null);
- fail();
- } catch (NullPointerException e) {
- }
- InputStreamReader reader2 = new InputStreamReader(in, cs);
- assertEquals(Charset.forName(reader2.getEncoding()), cs);
- reader2.close();
- }
-
- public void testInputStreamReaderSuccessiveReads() throws IOException {
- 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);
- if (bytesRead == -1) {
- throw new RuntimeException();
- }
- bytesRead = isr.read(buf, 0, buf.length);
- if (bytesRead == -1) {
- throw new RuntimeException();
- }
- }
-
- /**
- * @tests java.io.InputStreamReader#InputStreamReader(java.io.InputStream)
- */
- public void test_ConstructorLjava_io_InputStream() {
- // Test for method java.io.InputStreamReader(java.io.InputStream)
- assertTrue("Used to test other methods", true);
- }
-
- /**
- * @tests java.io.InputStreamReader#InputStreamReader(java.io.InputStream,
- * java.lang.String)
- */
- public void test_ConstructorLjava_io_InputStreamLjava_lang_String() {
- // Test for method java.io.InputStreamReader(java.io.InputStream,
- // java.lang.String)
- try {
- is = new InputStreamReader(fis, "8859_1");
- } catch (UnsupportedEncodingException e) {
- fail("Unable to create input stream : " + e.getMessage());
- }
-
- try {
- is = new InputStreamReader(fis, "Bogus");
- } catch (UnsupportedEncodingException e) {
- return;
- }
- fail("Failed to throw Unsupported Encoding exception");
- }
-
- /**
- * @tests java.io.InputStreamReader#close()
- */
- public void test_close() {
- // Test for method void java.io.InputStreamReader.close()
- try {
- is.close();
- } catch (IOException e) {
- fail("Failed to close reader : " + e.getMessage());
- }
- try {
- is.read();
- fail("Should throw IOException");
- } catch (IOException e) {
- // Exception means read failed due to close
- }
-
- }
-
- /**
- * @tests java.io.InputStreamReader#getEncoding()
- */
- public void test_getEncoding() {
- // Test for method java.lang.String
- // java.io.InputStreamReader.getEncoding()
- try {
- is = new InputStreamReader(fis, "8859_1");
- } catch (UnsupportedEncodingException e) {
- assertEquals("Returned incorrect encoding",
- "8859_1", is.getEncoding());
- }
- }
-
- /**
- * @tests java.io.InputStreamReader#read()
- */
- public void test_read() throws IOException{
- // Test for method int java.io.InputStreamReader.read()
- try {
- 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');
- } catch (IOException e) {
- fail("Exception during read test : " + e.getMessage());
- }
-
- // Regression for HARMONY-166
- InputStream in;
- InputStreamReader reader;
-
- 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());*/
- }
-
- /**
- * @tests java.io.InputStreamReader#read(char[], int, int)
- */
- public void test_read$CII() {
- // Test for method int java.io.InputStreamReader.read(char [], int, int)
- try {
- 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]);
- } catch (IOException e) {
- fail("Exception during read test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.InputStreamReader#ready()
- */
- public void test_ready() {
- // Test for method boolean java.io.InputStreamReader.ready()
- try {
- assertTrue("Ready test failed", is.ready());
- is.read();
- assertTrue("More chars, but not ready", is.ready());
- } catch (IOException e) {
- fail("Exception during ready test : " + e.getMessage());
- }
- }
-
-
-}
+/*
+ * 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.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) {
+ // Expected
+ }
+
+ 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 {
+ is = new InputStreamReader(fis, "8859_1");
+ assertEquals("Returned incorrect encoding", "8859_1", is.getEncoding());
+
+ InputStreamReader in = null;
+ byte b[] = new byte[5];
+ in = new InputStreamReader(new ByteArrayInputStream(b), "UTF-16BE");
+ in.close();
+ assertNull(in.getEncoding());
+
+ try {
+ in = new InputStreamReader(System.in, "UTF-16BE");
+ } catch (UnsupportedEncodingException e) {
+ // Ignored
+ }
+ assertEquals("UnicodeBigUnmarked", in.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/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InterruptedIOExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InterruptedIOExceptionTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InterruptedIOExceptionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InterruptedIOExceptionTest.java Mon Jan 28 04:07:47 2008
@@ -19,43 +19,29 @@
import java.io.InterruptedIOException;
-public class InterruptedIOExceptionTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
- /**
- * @tests java.io.InterruptedIOException#InterruptedIOException()
- */
- public void test_Constructor() {
- // Test for method java.io.InterruptedIOException()
- try {
- throw new InterruptedIOException();
- } catch (InterruptedIOException e) {
- return;
- }
- }
+public class InterruptedIOExceptionTest extends TestCase {
- /**
- * @tests java.io.InterruptedIOException#InterruptedIOException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.InterruptedIOException(java.lang.String)
- try {
- throw new InterruptedIOException("Some error message");
- } catch (InterruptedIOException e) {
- return;
- }
- }
+ /**
+ * @tests java.io.InterruptedIOException#InterruptedIOException()
+ */
+ public void test_Constructor() {
+ try {
+ throw new InterruptedIOException();
+ } catch (InterruptedIOException e) {
+ // Expected
+ }
+ }
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
+ /**
+ * @tests java.io.InterruptedIOException#InterruptedIOException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ try {
+ throw new InterruptedIOException("Some error message");
+ } catch (InterruptedIOException e) {
+ // Expected
+ }
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InvalidClassExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InvalidClassExceptionTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InvalidClassExceptionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InvalidClassExceptionTest.java Mon Jan 28 04:07:47 2008
@@ -19,67 +19,53 @@
import java.io.InvalidClassException;
-public class InvalidClassExceptionTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
- /**
- * @tests java.io.InvalidClassException#InvalidClassException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- final String message = "A message";
- try {
- if (true)
- throw new java.io.InvalidClassException(message);
- } catch (InvalidClassException e) {
- // correct
- assertTrue("Incorrect message read", e.getMessage().equals(message));
- return;
- }
- fail("Failed to throw exception");
- }
+public class InvalidClassExceptionTest extends TestCase {
- /**
- * @tests java.io.InvalidClassException#InvalidClassException(java.lang.String,
- * java.lang.String)
- */
- public void test_ConstructorLjava_lang_StringLjava_lang_String() {
- // Test for method java.io.InvalidClassException(java.lang.String,
- // java.lang.String)
- final String message = "A message";
- final String className = "Object";
- try {
- if (true)
- throw new java.io.InvalidClassException(className, message);
- } catch (InvalidClassException e) {
- // correct
- String returnedMessage = e.getMessage();
- assertTrue("Incorrect message read: " + e.getMessage(),
- returnedMessage.indexOf(className) >= 0
- && returnedMessage.indexOf(message) >= 0);
- return;
- }
- fail("Failed to throw exception");
- }
+ /**
+ * @tests java.io.InvalidClassException#InvalidClassException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ final String message = "A message";
+ try {
+ if (true) {
+ throw new InvalidClassException(message);
+ }
+ fail("Failed to throw exception");
+ } catch (InvalidClassException e) {
+ // correct
+ assertTrue("Incorrect message read", e.getMessage().equals(message));
+ }
+ }
- /**
- * @tests java.io.InvalidClassException#getMessage()
- */
- public void test_getMessage() {
- // Test for method java.lang.String
- // java.io.InvalidClassException.getMessage()
- // used to test
- }
+ /**
+ * @tests java.io.InvalidClassException#InvalidClassException(java.lang.String,
+ * java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_StringLjava_lang_String() {
+ final String message = "A message";
+ final String className = "Object";
+ try {
+ if (true) {
+ throw new InvalidClassException(className, message);
+ }
+ fail("Failed to throw exception");
+ } catch (InvalidClassException e) {
+ // correct
+ String returnedMessage = e.getMessage();
+ assertTrue("Incorrect message read: " + e.getMessage(),
+ returnedMessage.indexOf(className) >= 0
+ && returnedMessage.indexOf(message) >= 0);
+ }
+ }
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
+ /**
+ * @tests java.io.InvalidClassException#getMessage()
+ */
+ public void test_getMessage() {
+ // Test for method java.lang.String
+ // java.io.InvalidClassException.getMessage()
+ // used to test
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/LineNumberInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/LineNumberInputStreamTest.java?rev=615857&r1=615856&r2=615857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/LineNumberInputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/LineNumberInputStreamTest.java Mon Jan 28 04:07:47 2008
@@ -21,186 +21,146 @@
import java.io.IOException;
import java.io.LineNumberInputStream;
+import junit.framework.TestCase;
+
@SuppressWarnings("deprecation")
-public class LineNumberInputStreamTest extends junit.framework.TestCase {
+public class LineNumberInputStreamTest extends TestCase {
- String text = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100\n101\n102\n103\n104\n105\n106\n107\n108\n109\n110\n111\n112\n113\n114\n115\n116\n117\n118\n119\n120\n121\n122\n123\n124\n125\n126\n127\n128\n129\n130\n131\n132\n133\n134\n135\n136\n137\n138\n139\n140\n141\n142\n143\n144\n145\n146\n147\n148\n149\n150\n151\n152\n153\n154\n155\n156\n157\n158\n159\n160\n161\n162\n163\n164\n165\n166\n167\n168\n169\n170\n171\n172\n173\n174\n175\n176\n177\n178\n179\n180\n181\n182\n183\n184\n185\n186\n187\n188\n189\n190\n191\n192\n193\n194\n195\n196\n197\n198\n199\n200\n201\n202\n203\n204\n205\n206\n207\n208\n209\n210\n211\n212\n213\n214\n215\n216
\n217\n218\n219\n220\n221\n222\n223\n224\n225\n226\n227\n228\n229\n230\n231\n232\n233\n234\n235\n236\n237\n238\n239\n240\n241\n242\n243\n244\n245\n246\n247\n248\n249\n250\n251\n252\n253\n254\n255\n256\n257\n258\n259\n260\n261\n262\n263\n264\n265\n266\n267\n268\n269\n270\n271\n272\n273\n274\n275\n276\n277\n278\n279\n280\n281\n282\n283\n284\n285\n286\n287\n288\n289\n290\n291\n292\n293\n294\n295\n296\n297\n298\n299\n300\n301\n302\n303\n304\n305\n306\n307\n308\n309\n310\n311\n312\n313\n314\n315\n316\n317\n318\n319\n320\n321\n322\n323\n324\n325\n326\n327\n328\n329\n330\n331\n332\n333\n334\n335\n336\n337\n338\n339\n340\n341\n342\n343\n344\n345\n346\n347\n348\n349\n350\n351\n352\n353\n354\n355\n356\n357\n358\n359\n360\n361\n362\n363\n364\n365\n366\n367\n368\n369\n370\n371\n372\n373\n374\n375\n376\n377\n378\n379\n380\n381\n382\n383\n384\n385\n386\n387\n388\n389\n390\n391\n392\n393\n394\n395\n396\n397\n398\n399\n400\n401\n402\n403\n404\n405\n406\n407\n408\n409\n410\n411\n412\n413\n41
4\n415\n416\n417\n418\n419\n420\n421\n422\n423\n424\n425\n426\n427\n428\n429\n430\n431\n432\n433\n434\n435\n436\n437\n438\n439\n440\n441\n442\n443\n444\n445\n446\n447\n448\n449\n450\n451\n452\n453\n454\n455\n456\n457\n458\n459\n460\n461\n462\n463\n464\n465\n466\n467\n468\n469\n470\n471\n472\n473\n474\n475\n476\n477\n478\n479\n480\n481\n482\n483\n484\n485\n486\n487\n488\n489\n490\n491\n492\n493\n494\n495\n496\n497\n498\n499\n500\n501";
+ String text = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100\n101\n102\n103\n104\n105\n106\n107\n108\n109\n110\n111\n112\n113\n114\n115\n116\n117\n118\n119\n120\n121\n122\n123\n124\n125\n126\n127\n128\n129\n130\n131\n132\n133\n134\n135\n136\n137\n138\n139\n140\n141\n142\n143\n144\n145\n146\n147\n148\n149\n150\n151\n152\n153\n154\n155\n156\n157\n158\n159\n160\n161\n162\n163\n164\n165\n166\n167\n168\n169\n170\n171\n172\n173\n174\n175\n176\n177\n178\n179\n180\n181\n182\n183\n184\n185\n186\n187\n188\n189\n190\n191\n192\n193\n194\n195\n196\n197\n198\n199\n200\n201\n202\n203\n204\n205\n206\n207\n208\n209\n210\n211\n212\n213\n214\n215\n
216\n217\n218\n219\n220\n221\n222\n223\n224\n225\n226\n227\n228\n229\n230\n231\n232\n233\n234\n235\n236\n237\n238\n239\n240\n241\n242\n243\n244\n245\n246\n247\n248\n249\n250\n251\n252\n253\n254\n255\n256\n257\n258\n259\n260\n261\n262\n263\n264\n265\n266\n267\n268\n269\n270\n271\n272\n273\n274\n275\n276\n277\n278\n279\n280\n281\n282\n283\n284\n285\n286\n287\n288\n289\n290\n291\n292\n293\n294\n295\n296\n297\n298\n299\n300\n301\n302\n303\n304\n305\n306\n307\n308\n309\n310\n311\n312\n313\n314\n315\n316\n317\n318\n319\n320\n321\n322\n323\n324\n325\n326\n327\n328\n329\n330\n331\n332\n333\n334\n335\n336\n337\n338\n339\n340\n341\n342\n343\n344\n345\n346\n347\n348\n349\n350\n351\n352\n353\n354\n355\n356\n357\n358\n359\n360\n361\n362\n363\n364\n365\n366\n367\n368\n369\n370\n371\n372\n373\n374\n375\n376\n377\n378\n379\n380\n381\n382\n383\n384\n385\n386\n387\n388\n389\n390\n391\n392\n393\n394\n395\n396\n397\n398\n399\n400\n401\n402\n403\n404\n405\n406\n407\n408\n409\n410\n411\n412\n413\
n414\n415\n416\n417\n418\n419\n420\n421\n422\n423\n424\n425\n426\n427\n428\n429\n430\n431\n432\n433\n434\n435\n436\n437\n438\n439\n440\n441\n442\n443\n444\n445\n446\n447\n448\n449\n450\n451\n452\n453\n454\n455\n456\n457\n458\n459\n460\n461\n462\n463\n464\n465\n466\n467\n468\n469\n470\n471\n472\n473\n474\n475\n476\n477\n478\n479\n480\n481\n482\n483\n484\n485\n486\n487\n488\n489\n490\n491\n492\n493\n494\n495\n496\n497\n498\n499\n500\n501";
- String dosText = "0\r\n1\r\n2";
+ String dosText = "0\r\n1\r\n2";
LineNumberInputStream lnis;
- LineNumberInputStream lnis2;
+ LineNumberInputStream lnis2;
- /**
- * @tests java.io.LineNumberInputStream#LineNumberInputStream(java.io.InputStream)
- */
- public void test_ConstructorLjava_io_InputStream() {
- // Test for method java.io.LineNumberInputStream(java.io.InputStream)
- // Used in other tests
- }
-
- /**
- * @tests java.io.LineNumberInputStream#available()
- */
- public void test_available() {
- // Test for method int java.io.LineNumberInputStream.available()
- try {
- assertTrue("Returned incorrect number of available bytes", lnis
- .available() == text.length() / 2);
- } catch (IOException e) {
- fail("Exception during available test: " + e.toString());
- }
- }
-
- /**
- * @tests java.io.LineNumberInputStream#getLineNumber()
- */
- public void test_getLineNumber() {
- // Test for method int java.io.LineNumberInputStream.getLineNumber()
- assertEquals("New stream returned line number other than zero", 0, lnis
- .getLineNumber());
- try {
- lnis.read();
- lnis.read();
- } catch (IOException e) {
- fail("Exception during getLineNumber test : " + e.getMessage());
- }
- assertEquals("stream returned incorrect line number after read", 1, lnis
- .getLineNumber());
- lnis.setLineNumber(89);
- assertEquals("stream returned incorrect line number after set", 89, lnis
- .getLineNumber());
- }
-
- /**
- * @tests java.io.LineNumberInputStream#mark(int)
- */
- public void test_markI() {
- // Test for method void java.io.LineNumberInputStream.mark(int)
- try {
- lnis.mark(40);
- lnis.skip(4);
- lnis.reset();
- assertEquals("Failed to mark", 0, lnis.getLineNumber());
- assertEquals("Failed to mark", '0', lnis.read());
- } catch (IOException e) {
- fail("Exception during mark test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.LineNumberInputStream#read()
- */
- public void test_read() {
- // Test for method int java.io.LineNumberInputStream.read()
- try {
- assertEquals("Failed to read correct byte", '0', lnis.read());
- assertEquals("Failed to read correct byte on dos text",
- '0', lnis2.read());
- assertTrue("Failed to read correct byte on dos text",
- lnis2.read() == '\n');
- assertEquals("Failed to read correct byte on dos text",
- '1', lnis2.read());
- assertTrue("Failed to read correct byte on dos text",
- lnis2.read() == '\n');
- assertEquals("Failed to read correct byte on dos text",
- '2', lnis2.read());
- } catch (IOException e) {
- fail("Exception during read test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.LineNumberInputStream#read(byte[], int, int)
- */
- public void test_read$BII() {
- // Test for method int java.io.LineNumberInputStream.read(byte [], int,
- // int)
- try {
- byte[] buf = new byte[100];
- lnis.read(buf, 0, 100);
- assertTrue("Failed to read correct bytes on normal text",
- new String(buf, 0, 100).equals(text.substring(0, 100)));
- } catch (IOException e) {
- fail("Exception during mark test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.LineNumberInputStream#reset()
- */
- public void test_reset() {
- // Test for method void java.io.LineNumberInputStream.reset()
-
- try {
- lnis.mark(40);
- lnis.skip(4);
- lnis.reset();
- assertEquals("Failed to reset", 0, lnis.getLineNumber());
- assertEquals("Failed to reset", '0', lnis.read());
- lnis.reset();
- } catch (IOException e) {
- fail("Exception during mark test : " + e.getMessage());
- }
- // see comment for setup
- try {
- lnis.mark(5);
- lnis.skip(100);
- lnis.reset();
- } catch (IOException e) {
- // Correct mark has been invalidated
- return;
- }
- fail("Failed to invalidate mark");
- }
-
- /**
- * @tests java.io.LineNumberInputStream#setLineNumber(int)
- */
- public void test_setLineNumberI() {
- // Test for method void java.io.LineNumberInputStream.setLineNumber(int)
- lnis.setLineNumber(89);
- assertEquals("Failed to set line number", 89, lnis.getLineNumber());
- }
-
- /**
- * @tests java.io.LineNumberInputStream#skip(long)
- */
- public void test_skipJ() {
- // Test for method long java.io.LineNumberInputStream.skip(long)
- try {
- lnis.skip(4);
- assertEquals("Skip failed to increment lineNumber", 2, lnis
- .getLineNumber());
- } catch (IOException e) {
- fail("Exception during skip test : " + e.getMessage());
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- /*
- * In order for IOException to be thrown in reset(),the inputStream to
- * the constructor cannot be a byteArrayInputstream because the reset()
- * in byteArrayInputStream does not throw IOException. When
- * BufferedInputStream is used, the size of the buffer must be smaller
- * than the readlimit in mark inorder for IOException to be thrown
- */
- BufferedInputStream buftemp = new BufferedInputStream(
- new ByteArrayInputStream(text.getBytes()), 4);
- lnis = new LineNumberInputStream(buftemp);
- lnis2 = new LineNumberInputStream(new ByteArrayInputStream(dosText
- .getBytes()));
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
+ /**
+ * @tests java.io.LineNumberInputStream#LineNumberInputStream(java.io.InputStream)
+ */
+ public void test_ConstructorLjava_io_InputStream() {
+ // Used in other tests
+ }
+
+ /**
+ * @tests java.io.LineNumberInputStream#available()
+ */
+ public void test_available() throws IOException {
+ assertTrue("Returned incorrect number of available bytes", lnis
+ .available() == text.length() / 2);
+ }
+
+ /**
+ * @tests java.io.LineNumberInputStream#getLineNumber()
+ */
+ public void test_getLineNumber() throws IOException {
+ assertEquals("New stream returned line number other than zero", 0, lnis
+ .getLineNumber());
+
+ lnis.read();
+ lnis.read();
+
+ assertEquals("stream returned incorrect line number after read", 1,
+ lnis.getLineNumber());
+
+ lnis.setLineNumber(89);
+ assertEquals("stream returned incorrect line number after set", 89,
+ lnis.getLineNumber());
+ }
+
+ /**
+ * @tests java.io.LineNumberInputStream#mark(int)
+ */
+ public void test_markI() throws IOException {
+ lnis.mark(40);
+ lnis.skip(4);
+ lnis.reset();
+ assertEquals("Failed to mark", 0, lnis.getLineNumber());
+ assertEquals("Failed to mark", '0', lnis.read());
+ }
+
+ /**
+ * @tests java.io.LineNumberInputStream#read()
+ */
+ public void test_read() throws IOException {
+ assertEquals("Failed to read correct byte", '0', lnis.read());
+ assertEquals("Failed to read correct byte on dos text", '0', lnis2
+ .read());
+ assertTrue("Failed to read correct byte on dos text",
+ lnis2.read() == '\n');
+ assertEquals("Failed to read correct byte on dos text", '1', lnis2
+ .read());
+ assertTrue("Failed to read correct byte on dos text",
+ lnis2.read() == '\n');
+ assertEquals("Failed to read correct byte on dos text", '2', lnis2
+ .read());
+ }
+
+ /**
+ * @tests java.io.LineNumberInputStream#read(byte[], int, int)
+ */
+ public void test_read$BII() throws IOException {
+ byte[] buf = new byte[100];
+ lnis.read(buf, 0, 100);
+ assertTrue("Failed to read correct bytes on normal text", new String(
+ buf, 0, 100).equals(text.substring(0, 100)));
+ }
+
+ /**
+ * @tests java.io.LineNumberInputStream#reset()
+ */
+ public void test_reset() throws IOException {
+ lnis.mark(40);
+ lnis.skip(4);
+ lnis.reset();
+ assertEquals("Failed to reset", 0, lnis.getLineNumber());
+ assertEquals("Failed to reset", '0', lnis.read());
+ lnis.reset();
+
+ // see comment for setup
+ try {
+ lnis.mark(5);
+ lnis.skip(100);
+ lnis.reset();
+ fail("Failed to invalidate mark");
+ } catch (IOException e) {
+ // Correct mark has been invalidated
+ // Expected
+ }
+ }
+
+ /**
+ * @tests java.io.LineNumberInputStream#setLineNumber(int)
+ */
+ public void test_setLineNumberI() {
+ lnis.setLineNumber(89);
+ assertEquals("Failed to set line number", 89, lnis.getLineNumber());
+ }
+
+ /**
+ * @tests java.io.LineNumberInputStream#skip(long)
+ */
+ public void test_skipJ() throws IOException {
+ lnis.skip(4);
+ assertEquals("Skip failed to increment lineNumber", 2, lnis
+ .getLineNumber());
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ /*
+ * In order for IOException to be thrown in reset(),the inputStream to
+ * the constructor cannot be a byteArrayInputstream because the reset()
+ * in byteArrayInputStream does not throw IOException. When
+ * BufferedInputStream is used, the size of the buffer must be smaller
+ * than the readlimit in mark inorder for IOException to be thrown
+ */
+ BufferedInputStream buftemp = new BufferedInputStream(
+ new ByteArrayInputStream(text.getBytes()), 4);
+ lnis = new LineNumberInputStream(buftemp);
+ lnis2 = new LineNumberInputStream(new ByteArrayInputStream(dosText
+ .getBytes()));
+ }
}
Re: svn commit: r615857 [1/5] - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/
Posted by Tim Ellison <t....@gmail.com>.
Fixed in r616781.
Sorry 'bout that.
Regards,
Tim
Alexei Zakharov wrote:
> Tim,
>
> The changes you made to
> org.apache.harmony.luni.tests.java.io.InputStreamReaderTest by this
> commit cause InputStreamReaderTest.test_getEncoding() to fail with the
> following message:
>
> Returned incorrect encoding expected:<[]8859_1> but was:<[ISO]8859_1>
>
> junit.framework.ComparisonFailure: Returned incorrect encoding
> expected:<[]8859_1> but was:<[ISO]8859_1>
> at org.apache.harmony.luni.tests.java.io.InputStreamReaderTest.test_getEncoding(InputStreamReaderTest.java:304)
> at java.lang.reflect.VMReflection.invokeMethod(VMReflection.java)
>
> The link to CC failure notification is here:
> http://people.apache.org/~smishura/r616407/Windows_x86/classlib-test/
> I am also able to reproduce it on my laptop (Win32). Could you please
> take a look?
>
> Thanks,
> Alexei
>
>
> 2008/1/28, tellison@apache.org <te...@apache.org>:
>> Author: tellison
>> Date: Mon Jan 28 04:07:47 2008
>> New Revision: 615857
>>
>> URL: http://svn.apache.org/viewvc?rev=615857&view=rev
>> Log:
>> Another round of java.io test tidy-ups, including formatting, tidy-up imports, and letting JUnit handle the exceptions.
>>
>> Modified:
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileDescriptorTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileNotFoundExceptionTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileReaderTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileWriterTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterInputStreamTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterOutputStreamTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/IOExceptionTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InterruptedIOExceptionTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InvalidClassExceptionTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/LineNumberInputStreamTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/LineNumberReaderTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/NotActiveExceptionTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/NotSerializableExceptionTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectInputStream2Test.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectInputStreamTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OpenRandomFileTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedReaderTest.java
>>
>
Re: svn commit: r615857 [1/5] - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/
Posted by Alexei Zakharov <al...@gmail.com>.
Tim,
The changes you made to
org.apache.harmony.luni.tests.java.io.InputStreamReaderTest by this
commit cause InputStreamReaderTest.test_getEncoding() to fail with the
following message:
Returned incorrect encoding expected:<[]8859_1> but was:<[ISO]8859_1>
junit.framework.ComparisonFailure: Returned incorrect encoding
expected:<[]8859_1> but was:<[ISO]8859_1>
at org.apache.harmony.luni.tests.java.io.InputStreamReaderTest.test_getEncoding(InputStreamReaderTest.java:304)
at java.lang.reflect.VMReflection.invokeMethod(VMReflection.java)
The link to CC failure notification is here:
http://people.apache.org/~smishura/r616407/Windows_x86/classlib-test/
I am also able to reproduce it on my laptop (Win32). Could you please
take a look?
Thanks,
Alexei
2008/1/28, tellison@apache.org <te...@apache.org>:
> Author: tellison
> Date: Mon Jan 28 04:07:47 2008
> New Revision: 615857
>
> URL: http://svn.apache.org/viewvc?rev=615857&view=rev
> Log:
> Another round of java.io test tidy-ups, including formatting, tidy-up imports, and letting JUnit handle the exceptions.
>
> Modified:
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileDescriptorTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileNotFoundExceptionTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileReaderTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileWriterTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterInputStreamTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilterOutputStreamTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/IOExceptionTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InterruptedIOExceptionTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InvalidClassExceptionTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/LineNumberInputStreamTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/LineNumberReaderTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/NotActiveExceptionTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/NotSerializableExceptionTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectInputStream2Test.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectInputStreamTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamClassTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OpenRandomFileTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedReaderTest.java
>