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 2006/03/15 12:47:39 UTC
svn commit: r386058 [8/49] - in /incubator/harmony/enhanced/classlib/trunk:
make/ modules/archive/make/common/ modules/archive/src/test/java/tests/
modules/archive/src/test/java/tests/api/
modules/archive/src/test/java/tests/api/java/ modules/archive/s...
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilterInputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilterInputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilterInputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilterInputStreamTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,190 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.io;
+
+import tests.support.Support_PlatformFile;
+
+public class FilterInputStreamTest extends junit.framework.TestCase {
+
+ static class MyFilterInputStream extends java.io.FilterInputStream {
+ public MyFilterInputStream(java.io.InputStream is) {
+ super(is);
+ }
+ }
+
+ private String fileName;
+
+ private java.io.InputStream is;
+
+ byte[] ibuf = new byte[4096];
+
+ 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\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_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_Class
NotFoundException\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_Obj
ect\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_SocketE
xception\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.FilterInputStream#available()
+ */
+ public void test_available() {
+ // Test for method int java.io.FilterInputStream.available()
+ try {
+ assertTrue("Returned incorrect number of available bytes", is
+ .available() == fileString.length());
+ } catch (Exception e) {
+ fail("Exception during available test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.io.FilterInputStream#close()
+ */
+ public void test_close() {
+ // Test for method void java.io.FilterInputStream.close()
+ try {
+ is.close();
+ } catch (java.io.IOException e) {
+ fail("Exception attempting to close stream : " + e.getMessage());
+ }
+
+ try {
+ is.read();
+ } catch (java.io.IOException e) {
+ return;
+ }
+ fail("Able to read from closed stream");
+ }
+
+ /**
+ * @tests java.io.FilterInputStream#mark(int)
+ */
+ public void test_markI() {
+ // Test for method void java.io.FilterInputStream.mark(int)
+ assertTrue("Mark not supported by parent InputStream", true);
+ }
+
+ /**
+ * @tests java.io.FilterInputStream#markSupported()
+ */
+ public void test_markSupported() {
+ // Test for method boolean java.io.FilterInputStream.markSupported()
+ assertTrue("markSupported returned true", !is.markSupported());
+ }
+
+ /**
+ * @tests java.io.FilterInputStream#read()
+ */
+ public void test_read() {
+ // Test for method int java.io.FilterInputStream.read()
+ try {
+ int c = is.read();
+ assertTrue("read returned incorrect char", c == fileString
+ .charAt(0));
+ } catch (Exception e) {
+ fail("Exception during read test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.io.FilterInputStream#read(byte[])
+ */
+ public void test_read$B() {
+ // Test for method int java.io.FilterInputStream.read(byte [])
+ byte[] buf1 = new byte[100];
+ try {
+ is.read(buf1);
+ assertTrue("Failed to read correct data", new String(buf1, 0,
+ buf1.length).equals(fileString.substring(0, 100)));
+ } catch (Exception e) {
+ fail("Exception during read test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.io.FilterInputStream#read(byte[], int, int)
+ */
+ public void test_read$BII() {
+ // Test for method int java.io.FilterInputStream.read(byte [], int, int)
+ byte[] buf1 = new byte[100];
+ try {
+ 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)));
+ } catch (Exception e) {
+ fail("Exception during read test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.io.FilterInputStream#reset()
+ */
+ public void test_reset() {
+ // Test for method void java.io.FilterInputStream.reset()
+ assertTrue("Not supported by underlying stream", true);
+ }
+
+ /**
+ * @tests java.io.FilterInputStream#skip(long)
+ */
+ public void test_skipJ() {
+ // Test for method long java.io.FilterInputStream.skip(long)
+ byte[] buf1 = new byte[10];
+ try {
+ is.skip(1000);
+ is.read(buf1, 0, buf1.length);
+ assertTrue("Failed to skip to correct position", new String(buf1,
+ 0, buf1.length).equals(fileString.substring(1000, 1010)));
+ } catch (Exception e) {
+ fail("Exception during skip test");
+ }
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ try {
+ 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");
+ java.io.OutputStream fos = new java.io.FileOutputStream(fileName);
+ fos.write(fileString.getBytes());
+ fos.close();
+ is = new MyFilterInputStream(new java.io.FileInputStream(fileName));
+ } catch (java.io.IOException e) {
+ System.out.println("Exception during setup");
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ try {
+ is.close();
+ } catch (Exception e) {
+ System.out.println("Exception during BIS tearDown");
+ }
+ new java.io.File(fileName).delete();
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilterOutputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilterOutputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilterOutputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilterOutputStreamTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,165 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.io;
+
+public class FilterOutputStreamTest extends junit.framework.TestCase {
+
+ private java.io.OutputStream os;
+
+ java.io.ByteArrayOutputStream bos;
+
+ java.io.ByteArrayInputStream bis;
+
+ byte[] ibuf = new byte[4096];
+
+ 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\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_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_Class
NotFoundException\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_Obj
ect\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_SocketE
xception\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.FilterOutputStream#FilterOutputStream(java.io.OutputStream)
+ */
+ public void test_ConstructorLjava_io_OutputStream() {
+ // Test for method java.io.FilterOutputStream(java.io.OutputStream)
+ try {
+ bos = new java.io.ByteArrayOutputStream();
+ os = new java.io.FilterOutputStream(bos);
+ os.write('t');
+ } catch (java.io.IOException e) {
+ fail("Constructor test failed : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.io.FilterOutputStream#close()
+ */
+ public void test_close() {
+ // Test for method void java.io.FilterOutputStream.close()
+ try {
+ bos = new java.io.ByteArrayOutputStream();
+ os = new java.io.FilterOutputStream(bos);
+ os.write(fileString.getBytes(), 0, 500);
+ os.flush();
+ assertTrue("Bytes not written after flush", bos.size() == 500);
+ os.close();
+ } catch (java.io.IOException e) {
+ fail("Close test failed : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.io.FilterOutputStream#flush()
+ */
+ public void test_flush() {
+ // Test for method void java.io.FilterOutputStream.flush()
+ try {
+ bos = new java.io.ByteArrayOutputStream();
+ os = new java.io.FilterOutputStream(bos);
+ os.write(fileString.getBytes(), 0, 500);
+ os.flush();
+ assertTrue("Bytes not written after flush", bos.size() == 500);
+ os.close();
+ } catch (java.io.IOException e) {
+ fail("Flush test failed : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.io.FilterOutputStream#write(byte[])
+ */
+ public void test_write$B() {
+ // Test for method void java.io.FilterOutputStream.write(byte [])
+ try {
+ bos = new java.io.ByteArrayOutputStream();
+ os = new java.io.FilterOutputStream(bos);
+ os.write(fileString.getBytes());
+ bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+ os.flush();
+ assertTrue("Bytes not written after flush",
+ bis.available() == fileString.length());
+ byte[] wbytes = new byte[fileString.length()];
+ bis.read(wbytes, 0, fileString.length());
+ assertTrue("Incorrect bytes written", fileString.equals(new String(
+ wbytes, 0, wbytes.length)));
+ } catch (java.io.IOException e) {
+ fail("Write test failed : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.io.FilterOutputStream#write(byte[], int, int)
+ */
+ public void test_write$BII() {
+ // Test for method void java.io.FilterOutputStream.write(byte [], int,
+ // int)
+ try {
+ bos = new java.io.ByteArrayOutputStream();
+ os = new java.io.FilterOutputStream(bos);
+ os.write(fileString.getBytes(), 0, fileString.length());
+ bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+ os.flush();
+ assertTrue("Bytes not written after flush",
+ bis.available() == fileString.length());
+ byte[] wbytes = new byte[fileString.length()];
+ bis.read(wbytes, 0, fileString.length());
+ assertTrue("Incorrect bytes written", fileString.equals(new String(
+ wbytes, 0, wbytes.length)));
+ } catch (java.io.IOException e) {
+ fail("Write test failed : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.io.FilterOutputStream#write(int)
+ */
+ public void test_writeI() {
+ // Test for method void java.io.FilterOutputStream.write(int)
+ try {
+ bos = new java.io.ByteArrayOutputStream();
+ os = new java.io.FilterOutputStream(bos);
+ os.write('t');
+ bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+ os.flush();
+ assertTrue("Byte not written after flush", bis.available() == 1);
+ byte[] wbytes = new byte[1];
+ bis.read(wbytes, 0, 1);
+ assertTrue("Incorrect byte written", wbytes[0] == 't');
+ } catch (java.io.IOException e) {
+ fail("Write test failed : " + e.getMessage());
+ }
+ }
+
+ /**
+ * 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() {
+ try {
+ if (bos != null)
+ bos.close();
+ if (bis != null)
+ bis.close();
+ if (os != null)
+ os.close();
+ } catch (Exception e) {
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/IOExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/IOExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/IOExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/IOExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,65 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.io;
+
+import java.io.IOException;
+
+public class IOExceptionTest extends 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");
+ }
+
+ /**
+ * @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");
+ }
+
+ /**
+ * 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() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,514 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.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.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 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(char[], int, int)
+ */
+ public void testReadcharArrayintint() throws IOException {
+ 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(
+ "tests/api/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(
+ "tests/api/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("tests/api/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();
+ } 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) {
+ assertTrue("Returned incorrect encoding", is.getEncoding().equals(
+ "8859_1"));
+ }
+ }
+
+ /**
+ * @tests java.io.InputStreamReader#read()
+ */
+ public void test_read() {
+ // 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());
+ }
+
+ try {
+ LimitedByteArrayInputStream in = new LimitedByteArrayInputStream(0);
+ InputStreamReader reader = new InputStreamReader(in, "UTF-16BE");
+ assertTrue("Incorrect byte UTF-16BE", reader.read() == '\u6172');
+ } catch (UnsupportedEncodingException e) {
+ // Can't test without the converter
+ System.out.println(e);
+ } catch (IOException e) {
+ fail("UTF-16BE unexpected 1: " + e);
+ }
+ try {
+ LimitedByteArrayInputStream in = new LimitedByteArrayInputStream(0);
+ InputStreamReader reader = new InputStreamReader(in, "UTF-16LE");
+ assertTrue("Incorrect byte UTF-16BE", reader.read() == '\u7261');
+ } catch (UnsupportedEncodingException e) {
+ // Can't test without the converter
+ } catch (IOException e) {
+ fail("UTF-16BE unexpected 2: " + e);
+ }
+ try {
+ LimitedByteArrayInputStream in = new LimitedByteArrayInputStream(1);
+ InputStreamReader reader = new InputStreamReader(in, "UTF-16");
+ assertTrue("Incorrect byte UTF-16BE", reader.read() == '\u7261');
+ } catch (UnsupportedEncodingException e) {
+ // Can't test without the converter
+ } catch (IOException e) {
+ fail("UTF-16BE unexpected 3: " + e);
+ }
+
+ try {
+ LimitedByteArrayInputStream in = new LimitedByteArrayInputStream(2);
+ InputStreamReader reader = new InputStreamReader(in, "ISO2022JP");
+ int ch = reader.read();
+ assertTrue("Incorrect byte ISO2022JP 1: " + ch, ch == '\u4e5d');
+ ch = reader.read();
+ assertTrue("Incorrect byte ISO2022JP 2: " + ch, ch == '\u7b2c');
+ } catch (UnsupportedEncodingException e) {
+ // Can't test without the converter
+ System.out.println(e);
+ } catch (IOException e) {
+ fail("ISO2022JP unexpected: " + e);
+ }
+
+ }
+
+ /**
+ * @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());
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InterruptedIOExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InterruptedIOExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InterruptedIOExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InterruptedIOExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,67 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.io;
+
+import java.io.InterruptedIOException;
+
+public class InterruptedIOExceptionTest extends 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;
+ } catch (Exception e) {
+ fail("Exception during InterruptedIOException test"
+ + e.toString());
+ }
+ fail("Failed to generate exception");
+ }
+
+ /**
+ * @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;
+ } catch (Exception e) {
+ fail("Exception during InterruptedIOException test"
+ + e.toString());
+ }
+ fail("Failed to generate exception");
+ }
+
+ /**
+ * 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() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InvalidClassExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InvalidClassExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InvalidClassExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InvalidClassExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,83 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.io;
+
+import java.io.InvalidClassException;
+
+public class InvalidClassExceptionTest extends 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");
+ }
+
+ /**
+ * @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#getMessage()
+ */
+ public void test_getMessage() {
+ // Test for method java.lang.String
+ // java.io.InvalidClassException.getMessage()
+ // used to test
+ }
+
+ /**
+ * 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() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/LineNumberInputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/LineNumberInputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/LineNumberInputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/LineNumberInputStreamTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,203 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.io;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.LineNumberInputStream;
+
+public class LineNumberInputStreamTest extends junit.framework.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 dosText = "0\r\n1\r\n2";
+
+ LineNumberInputStream lnis;
+
+ 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()
+ assertTrue("New stream returned line number other than zero", lnis
+ .getLineNumber() == 0);
+ try {
+ lnis.read();
+ lnis.read();
+ } catch (IOException e) {
+ fail("Exception during getLineNumber test : " + e.getMessage());
+ }
+ assertTrue("stream returned incorrect line number after read", lnis
+ .getLineNumber() == 1);
+ lnis.setLineNumber(89);
+ assertTrue("stream returned incorrect line number after set", lnis
+ .getLineNumber() == 89);
+ }
+
+ /**
+ * @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();
+ assertTrue("Failed to mark", lnis.getLineNumber() == 0);
+ assertTrue("Failed to mark", lnis.read() == '0');
+ } 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 {
+ assertTrue("Failed to read correct byte", lnis.read() == '0');
+ assertTrue("Failed to read correct byte on dos text",
+ lnis2.read() == '0');
+ assertTrue("Failed to read correct byte on dos text",
+ lnis2.read() == '\n');
+ assertTrue("Failed to read correct byte on dos text",
+ lnis2.read() == '1');
+ assertTrue("Failed to read correct byte on dos text",
+ lnis2.read() == '\n');
+ assertTrue("Failed to read correct byte on dos text",
+ lnis2.read() == '2');
+ } 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();
+ assertTrue("Failed to reset", lnis.getLineNumber() == 0);
+ assertTrue("Failed to reset", lnis.read() == '0');
+ 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);
+ assertTrue("Failed to set line number", lnis.getLineNumber() == 89);
+ }
+
+ /**
+ * @tests java.io.LineNumberInputStream#skip(long)
+ */
+ public void test_skipJ() {
+ // Test for method long java.io.LineNumberInputStream.skip(long)
+ try {
+ lnis.skip(4);
+ assertTrue("Skip failed to increment lineNumber", lnis
+ .getLineNumber() == 2);
+ } 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() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/LineNumberReaderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/LineNumberReaderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/LineNumberReaderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/LineNumberReaderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,203 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.io;
+
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.StringReader;
+
+public class LineNumberReaderTest extends junit.framework.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\n";
+
+ LineNumberReader lnr;
+
+ /**
+ * @tests java.io.LineNumberReader#LineNumberReader(java.io.Reader)
+ */
+ public void test_ConstructorLjava_io_Reader() {
+ // Test for method java.io.LineNumberReader(java.io.Reader)
+ lnr = new LineNumberReader(new StringReader(text), 4092);
+ assertTrue("Failed to create reader", lnr.getLineNumber() == 0);
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#LineNumberReader(java.io.Reader, int)
+ */
+ public void test_ConstructorLjava_io_ReaderI() {
+ // Test for method java.io.LineNumberReader(java.io.Reader, int)
+ lnr = new LineNumberReader(new StringReader(text));
+ assertTrue("Failed to create reader", lnr.getLineNumber() == 0);
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#getLineNumber()
+ */
+ public void test_getLineNumber() {
+ // Test for method int java.io.LineNumberReader.getLineNumber()
+ lnr = new LineNumberReader(new StringReader(text));
+ assertTrue("Returned incorrect line number--expected 0, got ", lnr
+ .getLineNumber() == 0);
+ try {
+ lnr.readLine();
+ lnr.readLine();
+ } catch (IOException e) {
+ fail("Exception during getLineNumberTest: " + e.toString());
+ }
+ assertTrue("Returned incorrect line number--expected 2, got: "
+ + lnr.getLineNumber(), lnr.getLineNumber() == 2);
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#mark(int)
+ */
+ public void test_markI() {
+ // Test for method void java.io.LineNumberReader.mark(int)
+ lnr = new LineNumberReader(new StringReader(text));
+ String line;
+ try {
+ lnr.skip(80);
+ lnr.mark(100);
+ line = lnr.readLine();
+ lnr.reset();
+ assertTrue("Failed to return to marked position", line.equals(lnr
+ .readLine()));
+ } catch (IOException e) {
+ fail("Exception during mark test : " + e.getMessage());
+ }
+
+ // The spec does not say the mark has to be invalidated
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#read()
+ */
+ public void test_read() {
+ // Test for method int java.io.LineNumberReader.read()
+ lnr = new LineNumberReader(new StringReader(text));
+
+ try {
+ int c = lnr.read();
+ assertTrue("Read returned incorrect character", c == '0');
+ } catch (IOException e) {
+ fail("Exception during read test : " + e.getMessage());
+ }
+ try {
+ lnr.read();
+ assertTrue("Read failed to inc lineNumber",
+ lnr.getLineNumber() == 1);
+ } catch (IOException e) {
+ fail("Exception during read test:" + e.getMessage());
+ }
+
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#read(char[], int, int)
+ */
+ public void test_read$CII() {
+ // Test for method int java.io.LineNumberReader.read(char [], int, int)
+ lnr = new LineNumberReader(new StringReader(text));
+ char[] c = new char[100];
+ try {
+ lnr.read(c, 0, 4);
+ assertTrue("Read returned incorrect characters", "0\n1\n"
+ .equals(new String(c, 0, 4)));
+ } catch (IOException e) {
+ fail("Exception during read test : " + e.getMessage());
+ }
+ assertTrue("Read failed to inc lineNumber", lnr.getLineNumber() == 2);
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#readLine()
+ */
+ public void test_readLine() {
+ // Test for method java.lang.String java.io.LineNumberReader.readLine()
+ lnr = new LineNumberReader(new StringReader(text));
+ assertTrue("Returned incorrect line number", lnr.getLineNumber() == 0);
+ String line = null;
+ try {
+ lnr.readLine();
+ line = lnr.readLine();
+ } catch (IOException e) {
+ fail("Exception during getLineNumberTest: " + e.toString());
+ }
+ assertTrue("Returned incorrect string", "1".equals(line));
+ assertTrue("Returned incorrect line number :" + lnr.getLineNumber(),
+ lnr.getLineNumber() == 2);
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#reset()
+ */
+ public void test_reset() {
+ // Test for method void java.io.LineNumberReader.reset()
+ lnr = new LineNumberReader(new StringReader(text));
+ assertTrue("Returned incorrect line number", lnr.getLineNumber() == 0);
+ String line = null;
+ try {
+ lnr.mark(100);
+ lnr.readLine();
+ lnr.reset();
+ line = lnr.readLine();
+ } catch (IOException e) {
+ fail("Exception during getLineNumberTest: " + e.toString());
+ }
+ assertTrue("Failed to reset reader", "0".equals(line));
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#setLineNumber(int)
+ */
+ public void test_setLineNumberI() {
+ // Test for method void java.io.LineNumberReader.setLineNumber(int)
+ lnr = new LineNumberReader(new StringReader(text));
+ lnr.setLineNumber(1001);
+ assertTrue("set incorrect line number", lnr.getLineNumber() == 1001);
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#skip(long)
+ */
+ public void test_skipJ() {
+ // Test for method long java.io.LineNumberReader.skip(long)
+ lnr = new LineNumberReader(new StringReader(text));
+ char[] c = new char[100];
+ try {
+ lnr.skip(80);
+ lnr.read(c, 0, 100);
+ } catch (IOException e) {
+ fail("Exception during skip test : " + e.getMessage());
+ }
+ assertTrue("Failed to skip to correct position", text
+ .substring(80, 180).equals(new String(c, 0, c.length)));
+ }
+
+ /**
+ * 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() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/NotActiveExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/NotActiveExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/NotActiveExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/NotActiveExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,73 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.NotActiveException;
+import java.io.ObjectOutputStream;
+
+public class NotActiveExceptionTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.io.NotActiveException#NotActiveException()
+ */
+ public void test_Constructor() {
+ // Test for method java.io.NotActiveException()
+ try {
+ ObjectOutputStream os = new ObjectOutputStream(
+ new ByteArrayOutputStream());
+ os.defaultWriteObject();
+ } catch (NotActiveException e) {
+ // Correct
+ return;
+ } catch (Exception e) {
+ fail("Exception during test : " + e.getMessage());
+ }
+ fail("Failed to throw exception");
+ }
+
+ /**
+ * @tests java.io.NotActiveException#NotActiveException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method java.io.NotActiveException(java.lang.String)
+ try {
+ ObjectOutputStream os = new ObjectOutputStream(
+ new ByteArrayOutputStream());
+ os.defaultWriteObject();
+ } catch (NotActiveException e) {
+ // Correct
+ return;
+ } catch (Exception e) {
+ fail("Exception during test : " + e.getMessage());
+ }
+ fail("Failed to throw expected exception");
+ }
+
+ /**
+ * 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() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/NotSerializableExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/NotSerializableExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/NotSerializableExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/NotSerializableExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,75 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.NotSerializableException;
+import java.io.ObjectOutputStream;
+
+import tests.support.Support_StringReader;
+
+public class NotSerializableExceptionTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.io.NotSerializableException#NotSerializableException()
+ */
+ public void test_Constructor() {
+ // Test for method java.io.NotSerializableException()
+ try {
+ ObjectOutputStream os = new ObjectOutputStream(
+ new ByteArrayOutputStream());
+ os.writeObject(new Support_StringReader("l"));
+ } catch (NotSerializableException e) {
+ // Correct
+ return;
+ } catch (Exception e) {
+ fail("Exception during test : " + e.getMessage());
+ }
+ fail("Failed to throw expected exception");
+ }
+
+ /**
+ * @tests java.io.NotSerializableException#NotSerializableException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method java.io.NotSerializableException(java.lang.String)
+ try {
+ ObjectOutputStream os = new ObjectOutputStream(
+ new ByteArrayOutputStream());
+ os.writeObject(new Support_StringReader("l"));
+ } catch (NotSerializableException e) {
+ // Correct
+ return;
+ } catch (Exception e) {
+ fail("Exception during test : " + e.getMessage());
+ }
+ fail("Failed to throw expected exception");
+ }
+
+ /**
+ * 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() {
+ }
+}