Remove java.io tests duplicated with Harmony.
Change-Id: I5bb51064a476628349977049a374b45a91cdeecf
http://b/3246523
diff --git a/expectations/knownfailures.txt b/expectations/knownfailures.txt
index 0f73d66..f20bf57 100644
--- a/expectations/knownfailures.txt
+++ b/expectations/knownfailures.txt
@@ -224,7 +224,7 @@
{
description: "Fails in CTS but passes under run-core-tests",
result: EXEC_FAILED,
- name: "tests.api.java.io.FileTest#test_deleteOnExit"
+ name: "libcore.java.io.OldFileTest#test_deleteOnExit"
},
{
description: "Fails in CTS but passes under run-core-tests",
diff --git a/luni/src/test/java/libcore/java/io/OldBufferedInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldBufferedInputStreamTest.java
new file mode 100644
index 0000000..a3ef4e4
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldBufferedInputStreamTest.java
@@ -0,0 +1,228 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import junit.framework.TestCase;
+import tests.support.Support_ASimpleInputStream;
+import tests.support.Support_PlatformFile;
+
+public class OldBufferedInputStreamTest extends TestCase {
+
+ public String fileName;
+ private BufferedInputStream is;
+ private FileInputStream isFile;
+ public String fileString = "Test_All_Tests\nTest_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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";
+
+ public void test_ConstructorLjava_io_InputStream() {
+ is = new BufferedInputStream(isFile);
+
+ try {
+ is.read();
+ } catch (Exception e) {
+ fail("Test 1: Read failed on a freshly constructed buffer.");
+ }
+ }
+
+ public void test_ConstructorLjava_io_InputStreamI() throws IOException {
+ // regression test for harmony-2407
+ new testBufferedInputStream(null);
+ assertNotNull(testBufferedInputStream.buf);
+ testBufferedInputStream.buf = null;
+ new testBufferedInputStream(null, 100);
+ assertNotNull(testBufferedInputStream.buf);
+ }
+
+ static class testBufferedInputStream extends BufferedInputStream {
+ static byte[] buf;
+ testBufferedInputStream(InputStream is) throws IOException {
+ super(is);
+ buf = super.buf;
+ }
+
+ testBufferedInputStream(InputStream is, int size) throws IOException {
+ super(is, size);
+ buf = super.buf;
+ }
+ }
+
+ public void test_available() {
+ // Test for method int java.io.BufferedInputStream.available()
+ try {
+ assertTrue("Returned incorrect number of available bytes", is
+ .available() == fileString.length());
+ } catch (IOException e) {
+ fail("Exception during available test");
+ }
+
+ // Test that a closed stream throws an IOE for available()
+ BufferedInputStream bis = new BufferedInputStream(
+ new ByteArrayInputStream(new byte[] { 'h', 'e', 'l', 'l', 'o',
+ ' ', 't', 'i', 'm' }));
+ int available = 0;
+ try {
+ available = bis.available();
+ bis.close();
+ } catch (IOException ex) {
+ fail();
+ }
+ assertTrue(available != 0);
+
+ try {
+ bis.available();
+ fail("Expected test to throw IOE.");
+ } catch (IOException ex) {
+ // expected
+ } catch (Throwable ex) {
+ fail("Expected test to throw IOE not "
+ + ex.getClass().getName());
+ }
+ }
+
+ public void test_close() throws IOException {
+ is.close();
+
+ try {
+ is.read();
+ fail("Test 1: IOException expected when reading after closing " +
+ "the stream.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
+ is = new BufferedInputStream(sis);
+ try {
+ is.close();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sis.throwExceptionOnNextUse = false;
+ }
+
+ public void test_markI_reset() throws IOException {
+ byte[] buf1 = new byte[100];
+ byte[] buf2 = new byte[100];
+
+ // Test 1: Check that reset fails if no mark has been set.
+ try {
+ is.reset();
+ fail("Test 1: IOException expected if no mark has been set.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ // Test 2: Check that mark / reset works when the mark is not invalidated.
+ is.skip(10);
+ is.mark(100);
+ is.read(buf1, 0, buf1.length);
+ is.reset();
+ is.read(buf2, 0, buf2.length);
+ is.reset();
+ assertTrue("Test 2: Failed to mark correct position or reset failed.",
+ new String(buf1, 0, buf1.length).equals(new String(buf2, 0, buf2.length)));
+
+ // Tests 3 and 4: Check that skipping less than readlimit bytes does
+ // not invalidate the mark.
+ is.skip(10);
+ try {
+ is.reset();
+ } catch (IOException e) {
+ fail("Test 3: Unexpected IOException " + e.getMessage());
+ }
+ is.read(buf2, 0, buf2.length);
+ is.reset();
+ assertTrue("Test 4: Failed to mark correct position, or reset failed.",
+ new String(buf1, 0, buf1.length).equals(new String(buf2, 0, buf2.length)));
+
+ // Test 8: Check that reset fails for a closed input stream.
+ is.close();
+ try {
+ is.reset();
+ fail("Test 8: IOException expected because the input stream is closed.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read() throws IOException {
+ int c = is.read();
+ assertTrue("Test 1: Incorrect character read.",
+ c == fileString.charAt(0));
+
+ byte[] bytes = new byte[256];
+ for (int i = 0; i < 256; i++) {
+ bytes[i] = (byte) i;
+ }
+
+ BufferedInputStream in = new BufferedInputStream(
+ new ByteArrayInputStream(bytes), 5);
+
+ // Read more bytes than are buffered.
+ for (int i = 0; i < 10; i++) {
+ assertEquals("Test 2: Incorrect byte read;", bytes[i], in.read());
+ }
+
+ in.close();
+ try {
+ in.read();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ @Override
+ protected void setUp() throws IOException {
+ fileName = System.getProperty("user.dir");
+ String separator = System.getProperty("file.separator");
+ if (fileName.charAt(fileName.length() - 1) == separator.charAt(0)) {
+ fileName = Support_PlatformFile.getNewPlatformFile(fileName,
+ "input.tst");
+ } else {
+ fileName = Support_PlatformFile.getNewPlatformFile(fileName
+ + separator, "input.tst");
+ }
+ OutputStream fos = new FileOutputStream(fileName);
+ fos.write(fileString.getBytes());
+ fos.close();
+ isFile = new FileInputStream(fileName);
+ is = new BufferedInputStream(isFile);
+ }
+
+ @Override
+ protected void tearDown() {
+ try {
+ is.close();
+ } catch (Exception e) {
+ }
+ try {
+ File f = new File(fileName);
+ f.delete();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/tests/api/java/io/BufferedOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldBufferedOutputStreamTest.java
similarity index 85%
rename from luni/src/test/java/tests/api/java/io/BufferedOutputStreamTest.java
rename to luni/src/test/java/libcore/java/io/OldBufferedOutputStreamTest.java
index 7ed516c..cfb317b 100644
--- a/luni/src/test/java/tests/api/java/io/BufferedOutputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/OldBufferedOutputStreamTest.java
@@ -15,20 +15,15 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
-
import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-@TestTargetClass(BufferedOutputStream.class)
-public class BufferedOutputStreamTest extends junit.framework.TestCase {
+public class OldBufferedOutputStreamTest extends junit.framework.TestCase {
private java.io.OutputStream os;
@@ -40,35 +35,17 @@
public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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.BufferedOutputStream#BufferedOutputStream(java.io.OutputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedOutputStream",
- args = {java.io.OutputStream.class}
- )
public void test_ConstructorLjava_io_OutputStream() {
try {
baos = new java.io.ByteArrayOutputStream();
os = new java.io.BufferedOutputStream(baos);
os.write(fileString.getBytes(), 0, 500);
} catch (java.io.IOException e) {
- fail("Constrcutor test failed");
+ fail("Constructor test failed");
}
}
- /**
- * @tests java.io.BufferedOutputStream#BufferedOutputStream(java.io.OutputStream,
- * int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IllegalArgumentException checking missed.",
- method = "BufferedOutputStream",
- args = {java.io.OutputStream.class, int.class}
- )
public void test_ConstructorLjava_io_OutputStreamI() {
baos = new java.io.ByteArrayOutputStream();
@@ -86,14 +63,6 @@
}
}
- /**
- * @tests java.io.BufferedOutputStream#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "flush",
- args = {}
- )
public void test_flush() throws IOException {
baos = new ByteArrayOutputStream();
os = new java.io.BufferedOutputStream(baos, 600);
@@ -115,14 +84,6 @@
sos.setThrowsException(false);
}
- /**
- * @tests java.io.BufferedOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
public void test_write$BII() throws IOException {
os = new java.io.BufferedOutputStream(
baos = new java.io.ByteArrayOutputStream(),512);
@@ -157,14 +118,6 @@
sos.setThrowsException(false);
}
- /**
- * @tests java.io.BufferedOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
public void test_write$BII_Exception() throws IOException {
OutputStream bos = new BufferedOutputStream(new ByteArrayOutputStream());
byte[] nullByteArray = null;
@@ -199,14 +152,6 @@
}
}
- /**
- * @tests java.io.BufferedOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {int.class}
- )
public void test_writeI() throws IOException {
baos = new java.io.ByteArrayOutputStream();
os = new java.io.BufferedOutputStream(baos);
diff --git a/luni/src/test/java/tests/api/java/io/BufferedReaderTest.java b/luni/src/test/java/libcore/java/io/OldBufferedReaderTest.java
similarity index 66%
rename from luni/src/test/java/tests/api/java/io/BufferedReaderTest.java
rename to luni/src/test/java/libcore/java/io/OldBufferedReaderTest.java
index ba75bbe..214c1b2 100644
--- a/luni/src/test/java/tests/api/java/io/BufferedReaderTest.java
+++ b/luni/src/test/java/libcore/java/io/OldBufferedReaderTest.java
@@ -15,53 +15,30 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
import java.io.CharArrayReader;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.PipedReader;
import java.io.Reader;
import java.io.StringReader;
-
import tests.support.Support_ASimpleReader;
import tests.support.Support_StringReader;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
import tests.support.ThrowingReader;
-@TestTargetClass(BufferedReader.class)
-public class BufferedReaderTest extends junit.framework.TestCase {
+public class OldBufferedReaderTest extends junit.framework.TestCase {
BufferedReader br;
String testString = "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_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_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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.BufferedReader#BufferedReader(java.io.Reader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedReader",
- args = {java.io.Reader.class}
- )
public void test_ConstructorLjava_io_Reader() {
// Test for method java.io.BufferedReader(java.io.Reader)
br = new BufferedReader(new Support_StringReader(testString));
assertNotNull(br);
}
- /**
- * @tests java.io.BufferedReader#BufferedReader(java.io.Reader, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedReader",
- args = {java.io.Reader.class, int.class}
- )
public void test_ConstructorLjava_io_ReaderI() {
// Illegal negative size argument test.
try {
@@ -73,14 +50,6 @@
assertNotNull(br);
}
- /**
- * @tests java.io.BufferedReader#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
public void test_close() {
Support_ASimpleReader ssr = new Support_ASimpleReader(true);
try {
@@ -105,15 +74,7 @@
ssr.throwExceptionOnNextUse = false;
}
- /**
- * @tests java.io.BufferedReader#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "mark",
- args = {int.class}
- )
- public void test_markI() {
+ public void test_markI() throws IOException {
// Test for method void java.io.BufferedReader.mark(int)
char[] buf = null;
try {
@@ -168,28 +129,12 @@
}
}
- /**
- * @tests java.io.BufferedReader#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "markSupported",
- args = {}
- )
public void test_markSupported() {
// Test for method boolean java.io.BufferedReader.markSupported()
br = new BufferedReader(new Support_StringReader(testString));
assertTrue("markSupported returned false.", br.markSupported());
}
- /**
- * @tests java.io.BufferedReader#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
public void test_read() throws IOException {
Support_ASimpleReader ssr = new Support_ASimpleReader(true);
try {
@@ -235,110 +180,6 @@
ssr.throwExceptionOnNextUse = false;
}
- /**
- * @tests java.io.BufferedReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "The test verifies read(char[] cbuf, int off, int len) method.",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII() throws Exception {
- char[] ca = new char[2];
- BufferedReader toRet = new BufferedReader(new InputStreamReader(
- new ByteArrayInputStream(new byte[0])));
- try {
- toRet.close();
- } catch (IOException e) {
- fail("unexpected 1: " + e);
- }
-
- /* Closed reader should throw IOException reading zero bytes */
- try {
- toRet.read(ca, 0, 0);
- fail("Reading zero bytes on a closed reader should not work");
- } catch (IOException e) {
- // expected
- }
-
- // Test to ensure that a drained stream returns 0 at EOF
- toRet = new BufferedReader(new InputStreamReader(
- new ByteArrayInputStream(new byte[2])));
- try {
- assertEquals("Emptying the reader should return two bytes", 2,
- toRet.read(ca, 0, 2));
- assertEquals("EOF on a reader should be -1", -1, toRet.read(ca, 0,
- 2));
- assertEquals("Reading zero bytes at EOF should work", 0, toRet
- .read(ca, 0, 0));
- } catch (IOException ex) {
- fail("Unexpected IOException : " + ex.getLocalizedMessage());
- }
-
- // Test for method int java.io.BufferedReader.read(char [], int, int)
- try {
- char[] buf = new char[testString.length()];
- br = new BufferedReader(new Support_StringReader(testString));
- br.read(buf, 50, 500);
- assertTrue("Chars read improperly", new String(buf, 50, 500)
- .equals(testString.substring(0, 500)));
-
- br = new BufferedReader(new Support_StringReader(testString));
- assertEquals(0, br.read(buf, 0, 0));
- assertEquals(buf.length, br.read(buf, 0, buf.length));
- assertEquals(0, br.read(buf, buf.length, 0));
- } catch (java.io.IOException e) {
- fail("Exception during read test");
- }
-
- BufferedReader bufin = new BufferedReader(new Reader() {
- int size = 2, pos = 0;
-
- char[] contents = new char[size];
-
- public int read() throws IOException {
- if (pos >= size)
- throw new IOException("Read past end of data");
- return contents[pos++];
- }
-
- public int read(char[] buf, int off, int len) throws IOException {
- if (pos >= size)
- throw new IOException("Read past end of data");
- int toRead = len;
- if (toRead > (size - pos))
- toRead = size - pos;
- System.arraycopy(contents, pos, buf, off, toRead);
- pos += toRead;
- return toRead;
- }
-
- public boolean ready() throws IOException {
- return size - pos > 0;
- }
-
- public void close() throws IOException {
- }
- });
- try {
- bufin.read();
- int result = bufin.read(new char[2], 0, 2);
- assertTrue("Incorrect result: " + result, result == 1);
- } catch (IOException e) {
- fail("Unexpected: " + e);
- }
- }
-
- /**
- * @tests java.io.BufferedReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "The test verifies read(char[] cbuf, int off, int len) method.",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
public void test_read$CII_Exception() throws Exception {
br = new BufferedReader(new Support_StringReader(testString));
try{
@@ -370,14 +211,6 @@
}
}
- /**
- * @tests java.io.BufferedReader#readLine()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readLine",
- args = {}
- )
public void test_readLine() throws IOException {
String line;
br = new BufferedReader(new Support_StringReader("Lorem\nipsum\rdolor sit amet..."));
@@ -401,14 +234,6 @@
}
}
- /**
- * @tests java.io.BufferedReader#ready()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ready",
- args = {}
- )
public void test_ready() throws IOException {
Support_ASimpleReader ssr = new Support_ASimpleReader(true);
try {
@@ -430,50 +255,6 @@
ssr.throwExceptionOnNextUse = false;
}
- /**
- * @tests java.io.BufferedReader#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "The test verifies reset() method.",
- method = "reset",
- args = {}
- )
- public void test_reset() {
- // Test for method void java.io.BufferedReader.reset()
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- br.skip(500);
- br.mark(900);
- br.skip(500);
- br.reset();
- char[] buf = new char[testString.length()];
- br.read(buf, 0, 500);
- assertTrue("Failed to reset properly", testString.substring(500,
- 1000).equals(new String(buf, 0, 500)));
- } catch (java.io.IOException e) {
- fail("Exception during reset test");
- }
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- br.skip(500);
- br.reset();
- fail("Reset succeeded on unmarked stream");
- } catch (IOException x) {
- return;
-
- }
-
- }
-
- /**
- * @tests java.io.BufferedReader#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- )
public void test_skipJ() throws IOException {
Support_ASimpleReader ssr = new Support_ASimpleReader(true);
br = new BufferedReader(new Support_StringReader(testString));
@@ -531,10 +312,6 @@
assertEquals('F', br.read());
}
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
protected void tearDown() {
try {
br.close();
diff --git a/luni/src/test/java/tests/api/java/io/BufferedWriterTest.java b/luni/src/test/java/libcore/java/io/OldBufferedWriterTest.java
similarity index 82%
rename from luni/src/test/java/tests/api/java/io/BufferedWriterTest.java
rename to luni/src/test/java/libcore/java/io/OldBufferedWriterTest.java
index 0d2783c..ed5b862 100644
--- a/luni/src/test/java/tests/api/java/io/BufferedWriterTest.java
+++ b/luni/src/test/java/libcore/java/io/OldBufferedWriterTest.java
@@ -15,19 +15,14 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
import java.io.BufferedWriter;
import java.io.IOException;
-
import tests.support.Support_ASimpleWriter;
import tests.support.Support_StringWriter;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-@TestTargetClass(BufferedWriter.class)
-public class BufferedWriterTest extends junit.framework.TestCase {
+public class OldBufferedWriterTest extends junit.framework.TestCase {
BufferedWriter bw;
@@ -37,14 +32,6 @@
public String testString = "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_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_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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.BufferedWriter#BufferedWriter(java.io.Writer)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedWriter",
- args = {java.io.Writer.class}
- )
public void test_ConstructorLjava_io_Writer() {
bw = new BufferedWriter(sw);
try {
@@ -57,14 +44,6 @@
}
}
- /**
- * @tests java.io.BufferedWriter#BufferedWriter(java.io.Writer, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedWriter",
- args = {java.io.Writer.class, int.class}
- )
public void test_ConstructorLjava_io_WriterI() {
try {
bw = new BufferedWriter(sw, 0);
@@ -84,14 +63,6 @@
}
}
- /**
- * @tests java.io.BufferedWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
public void test_close() {
// Test for method void java.io.BufferedWriter.close()
try {
@@ -112,14 +83,6 @@
}
}
- /**
- * @tests java.io.BufferedWriter#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "flush",
- args = {}
- )
public void test_flush() throws IOException {
bw.write("This should not cause a flush");
assertTrue("Test 1: Bytes written without flush.",
@@ -138,14 +101,6 @@
}
}
- /**
- * @tests java.io.BufferedWriter#newLine()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "newLine",
- args = {}
- )
public void test_newLine() throws IOException {
String separator = System.getProperty("line.separator");
bw.write("Hello");
@@ -165,14 +120,6 @@
}
}
- /**
- * @tests java.io.BufferedWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {char[].class, int.class, int.class}
- )
public void test_write$CII() {
// Test for method void java.io.BufferedWriter.write(char [], int, int)
try {
@@ -195,15 +142,6 @@
}
- /**
- * @tests java.io.BufferedWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument tests.",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
public void test_write$CII_Exception() throws IOException {
char[] nullCharArray = null;
char[] charArray = testString.toCharArray();
@@ -275,14 +213,6 @@
}
}
- /**
- * @tests java.io.BufferedWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {int.class}
- )
public void test_writeI() throws IOException {
bw.write('T');
assertTrue("Test 1: Char written without flush.",
@@ -311,14 +241,6 @@
}
}
- /**
- * @tests java.io.BufferedWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
public void test_writeLjava_lang_StringII() {
// Test for method void java.io.BufferedWriter.write(java.lang.String,
// int, int)
@@ -332,15 +254,6 @@
}
}
- /**
- * @tests java.io.BufferedWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument checking.",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
public void test_writeLjava_lang_StringII_Exception() throws IOException {
bw.write((String) null , -1, -1);
@@ -387,22 +300,13 @@
}
}
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
protected void setUp() {
sw = new Support_StringWriter();
ssw = new Support_ASimpleWriter(true);
bw = new BufferedWriter(sw, 500);
}
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
protected void tearDown() {
-
ssw.throwExceptionOnNextUse = false;
try {
bw.close();
diff --git a/luni/src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldByteArrayInputStreamTest.java
similarity index 70%
rename from luni/src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java
rename to luni/src/test/java/libcore/java/io/OldByteArrayInputStreamTest.java
index cf9673a..b5f3f4e 100644
--- a/luni/src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/OldByteArrayInputStreamTest.java
@@ -15,31 +15,17 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.InputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(ByteArrayInputStream.class)
-public class ByteArrayInputStreamTest extends junit.framework.TestCase {
+public class OldByteArrayInputStreamTest extends junit.framework.TestCase {
private ByteArrayInputStream is;
public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
- /**
- * @tests java.io.ByteArrayInputStream#ByteArrayInputStream(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ByteArrayInputStream",
- args = {byte[].class}
- )
public void test_Constructor$B() {
// Test for method java.io.ByteArrayInputStream(byte [])
@@ -54,16 +40,6 @@
}
}
- /**
- * @throws IOException
- * @tests java.io.ByteArrayInputStream#ByteArrayInputStream(byte[], int,
- * int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ByteArrayInputStream",
- args = {byte[].class, int.class, int.class}
- )
public void test_Constructor$BII() throws IOException {
// Test for method java.io.ByteArrayInputStream(byte [], int, int)
@@ -99,15 +75,6 @@
}
}
- /**
- * @tests java.io.ByteArrayInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies available() method.",
- method = "available",
- args = {}
- )
public void test_available() {
// Test for method int java.io.ByteArrayInputStream.available()
try {
@@ -118,14 +85,6 @@
}
}
- /**
- * @tests java.io.ByteArrayInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
public void test_close() {
is.read();
try {
@@ -140,15 +99,6 @@
}
}
- /**
- * @tests java.io.ByteArrayInputStream#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies mark(int readAheadLimit) method.",
- method = "mark",
- args = {int.class}
- )
public void test_markI() {
// Test for method void java.io.ByteArrayInputStream.mark(int)
byte[] buf1 = new byte[100];
@@ -169,29 +119,11 @@
}
- /**
- * @tests java.io.ByteArrayInputStream#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies markSupported() method.",
- method = "markSupported",
- args = {}
- )
public void test_markSupported() {
// Test for method boolean java.io.ByteArrayInputStream.markSupported()
assertTrue("markSupported returned incorrect value", is.markSupported());
}
- /**
- * @tests java.io.ByteArrayInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies read() method.",
- method = "read",
- args = {}
- )
public void test_read() {
// Test for method int java.io.ByteArrayInputStream.read()
try {
@@ -205,14 +137,6 @@
}
}
- /**
- * @tests java.io.ByteArrayInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII() throws IOException {
byte[] buf1 = new byte[20];
is.skip(50);
@@ -252,15 +176,6 @@
}
}
- /**
- * @tests java.io.ByteArrayInputStream#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "The test verifies reset() method.",
- method = "reset",
- args = {}
- )
public void test_reset() {
// Test for method void java.io.ByteArrayInputStream.reset()
byte[] buf1 = new byte[10];
@@ -278,15 +193,6 @@
}
}
- /**
- * @tests java.io.ByteArrayInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "skip",
- args = {long.class}
- )
public void test_skipJ() {
// Test for method long java.io.ByteArrayInputStream.skip(long)
byte[] buf1 = new byte[10];
@@ -300,25 +206,14 @@
}
}
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
protected void setUp() {
-
- is = new java.io.ByteArrayInputStream(fileString.getBytes());
+ is = new ByteArrayInputStream(fileString.getBytes());
}
- /**
- * 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) {
}
}
diff --git a/luni/src/test/java/libcore/java/io/OldByteArrayOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldByteArrayOutputStreamTest.java
new file mode 100644
index 0000000..0ef7f75
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldByteArrayOutputStreamTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import junit.framework.TestCase;
+import tests.support.Support_OutputStream;
+
+/**
+ * Automated Test Suite for class java.io.ByteArrayOutputStream
+ *
+ * @see java.io.ByteArrayOutputStream
+ */
+public class OldByteArrayOutputStreamTest extends TestCase {
+
+ ByteArrayOutputStream bos = null;
+
+ public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
+
+ public void test_ConstructorI() {
+ bos = new java.io.ByteArrayOutputStream(100);
+ assertEquals("Test 1: Failed to create stream;", 0, bos.size());
+
+ try {
+ bos = new ByteArrayOutputStream(-1);
+ fail("Test 2: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ }
+
+ public void test_toStringLjava_lang_String() throws Exception {
+ bos = new ByteArrayOutputStream();
+
+ bos.write(fileString.getBytes(), 0, fileString.length());
+ assertTrue("Test 1: Returned incorrect 8859-1 String",
+ bos.toString("8859_1").equals(fileString));
+ assertTrue("Test 2: Returned incorrect 8859-2 String",
+ bos.toString("8859_2").equals(fileString));
+
+ try {
+ bos.toString("NotAnEcoding");
+ fail("Test 3: UnsupportedEncodingException expected.");
+ } catch (UnsupportedEncodingException e) {
+ // Expected.
+ }
+ }
+
+ public void test_write$BII_Exception() {
+ byte[] target = new byte[10];
+ bos = new ByteArrayOutputStream();
+ try {
+ bos.write(target, -1, 1);
+ fail("Test 1: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ bos.write(target, 0, -1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ bos.write(target, 1, target.length);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ bos.write(null, 1, 1);
+ fail("Test 4: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeToLjava_io_OutputStream() throws Exception {
+ Support_OutputStream sos = new Support_OutputStream();
+ bos = new java.io.ByteArrayOutputStream();
+ bos.write(fileString.getBytes(), 0, 10);
+ bos.writeTo(sos);
+ assertTrue("Test 1: Incorrect string written.",
+ sos.toString().equals(
+ fileString.substring(0, 10)));
+
+ sos.setThrowsException(true);
+ try {
+ bos.writeTo(sos);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+}
diff --git a/luni/src/test/java/tests/api/java/io/CharArrayReaderTest.java b/luni/src/test/java/libcore/java/io/OldCharArrayReaderTest.java
similarity index 75%
rename from luni/src/test/java/tests/api/java/io/CharArrayReaderTest.java
rename to luni/src/test/java/libcore/java/io/OldCharArrayReaderTest.java
index 95d3734..31277e0 100644
--- a/luni/src/test/java/tests/api/java/io/CharArrayReaderTest.java
+++ b/luni/src/test/java/libcore/java/io/OldCharArrayReaderTest.java
@@ -15,18 +15,12 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
import java.io.CharArrayReader;
import java.io.IOException;
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(CharArrayReader.class)
-public class CharArrayReaderTest extends junit.framework.TestCase {
+public class OldCharArrayReaderTest extends junit.framework.TestCase {
char[] hw = { 'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd' };
@@ -35,12 +29,6 @@
/**
* @tests java.io.CharArrayReader#CharArrayReader(char[])
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies CharArrayReader(char[] buf) constructor.",
- method = "CharArrayReader",
- args = {char[].class}
- )
public void test_Constructor$C() {
// Test for method java.io.CharArrayReader(char [])
@@ -55,11 +43,6 @@
/**
* @tests java.io.CharArrayReader#CharArrayReader(char[], int, int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "CharArrayReader",
- args = {char[].class, int.class, int.class}
- )
public void test_Constructor$CII() throws IOException {
try {
cr = new CharArrayReader(null, 0, 0);
@@ -95,12 +78,6 @@
/**
* @tests java.io.CharArrayReader#close()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies close() method.",
- method = "close",
- args = {}
- )
public void test_close() {
cr = new CharArrayReader(hw);
cr.close();
@@ -116,13 +93,7 @@
/**
* @tests java.io.CharArrayReader#mark(int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "mark",
- args = {int.class}
- )
public void test_markI() throws IOException {
- // Test for method void java.io.CharArrayReader.mark(int)
cr = new CharArrayReader(hw);
cr.skip(5L);
cr.mark(100);
@@ -143,14 +114,7 @@
/**
* @tests java.io.CharArrayReader#markSupported()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies markSupported() method.",
- method = "markSupported",
- args = {}
- )
public void test_markSupported() {
- // Test for method boolean java.io.CharArrayReader.markSupported()
cr = new CharArrayReader(hw);
assertTrue("markSupported returned false", cr.markSupported());
}
@@ -158,11 +122,6 @@
/**
* @tests java.io.CharArrayReader#read()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
public void test_read() throws IOException {
cr = new CharArrayReader(hw);
assertEquals("Test 1: Read returned incorrect char;",
@@ -183,14 +142,6 @@
/**
* @tests java.io.CharArrayReader#read(char[], int, int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- @AndroidOnly("The RI throws an IndexOutOfBoundsException instead of an" +
- "ArrayIndexOutOfBoundsException. The RI specification does not" +
- "define the expected behavior.")
public void test_read$CII() throws IOException {
// Test for method int java.io.CharArrayReader.read(char [], int, int)
char[] c = new char[11];
@@ -237,15 +188,6 @@
}
}
- /**
- * @tests java.io.CharArrayReader#ready()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies ready() method.",
- method = "ready",
- args = {}
- )
public void test_ready() {
// Test for method boolean java.io.CharArrayReader.ready()
cr = new CharArrayReader(hw);
@@ -269,17 +211,11 @@
fail("No exception 2");
} catch (IOException e) {
}
-
}
/**
* @tests java.io.CharArrayReader#reset()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- )
public void test_reset() throws IOException {
cr = new CharArrayReader(hw);
cr.skip(5L);
@@ -298,14 +234,6 @@
}
}
- /**
- * @tests java.io.CharArrayReader#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- )
public void test_skipJ() throws IOException {
long skipped = 0;
cr = new CharArrayReader(hw);
@@ -324,17 +252,6 @@
}
}
- /**
- * 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() {
if (cr != null)
cr.close();
diff --git a/luni/src/test/java/libcore/java/io/OldCharArrayWriterTest.java b/luni/src/test/java/libcore/java/io/OldCharArrayWriterTest.java
new file mode 100644
index 0000000..662ad24
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldCharArrayWriterTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.CharArrayReader;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import tests.support.Support_ASimpleWriter;
+
+public class OldCharArrayWriterTest extends junit.framework.TestCase {
+
+ CharArrayWriter cw;
+ CharArrayReader cr;
+
+ public void test_ConstructorI() {
+ // Test for method java.io.CharArrayWriter(int)
+ cw = new CharArrayWriter(90);
+ assertEquals("Test 1: Incorrect writer created.", 0, cw.size());
+
+ try {
+ cw = new CharArrayWriter(-1);
+ fail("IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ }
+
+ public void test_write$CII_Exception() {
+ char[] target = new char[10];
+ cw = new CharArrayWriter();
+ try {
+ cw.write(target, -1, 1);
+ fail("Test 1: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ cw.write(target, 0, -1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ cw.write(target, 1, target.length);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ cw.write((char[]) null, 1, 1);
+ fail("Test 4: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeToLjava_io_Writer() {
+ Support_ASimpleWriter ssw = new Support_ASimpleWriter(true);
+ cw.write("HelloWorld", 0, 10);
+ StringWriter sw = new StringWriter();
+ try {
+ cw.writeTo(sw);
+ assertEquals("Test 1: Writer failed to write correct chars;",
+ "HelloWorld", sw.toString());
+ } catch (IOException e) {
+ fail("Exception during writeTo test : " + e.getMessage());
+ }
+
+ try {
+ cw.writeTo(ssw);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_appendLjava_langCharSequenceII() {
+ String testString = "My Test String";
+ CharArrayWriter writer = new CharArrayWriter(10);
+
+ // Illegal argument checks.
+ try {
+ writer.append(testString, -1, 0);
+ fail("Test 1: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ try {
+ writer.append(testString, 0, -1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ try {
+ writer.append(testString, 1, 0);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ try {
+ writer.append(testString, 1, testString.length() + 1);
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ writer.append(testString, 1, 3);
+ writer.flush();
+ assertEquals("Test 5: Appending failed;",
+ testString.substring(1, 3), writer.toString());
+ writer.close();
+ }
+
+ protected void setUp() {
+ cw = new CharArrayWriter();
+ }
+
+ protected void tearDown() {
+ if (cr != null) {
+ cr.close();
+ }
+ cw.close();
+ }
+}
diff --git a/luni/src/test/java/tests/api/java/io/DataInputOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldDataInputOutputStreamTest.java
similarity index 61%
rename from luni/src/test/java/tests/api/java/io/DataInputOutputStreamTest.java
rename to luni/src/test/java/libcore/java/io/OldDataInputOutputStreamTest.java
index 7d8d6a1..ca2e325 100644
--- a/luni/src/test/java/tests/api/java/io/DataInputOutputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/OldDataInputOutputStreamTest.java
@@ -14,22 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package tests.api.java.io;
+
+package libcore.java.io;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
-
import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-@TestTargetClass(DataOutputStream.class)
-public class DataInputOutputStreamTest extends junit.framework.TestCase {
+public class OldDataInputOutputStreamTest extends junit.framework.TestCase {
private DataOutputStream os;
@@ -39,25 +34,6 @@
String unihw = "\u0048\u0065\u006C\u006C\u006F\u0020\u0057\u006F\u0072\u006C\u0064";
- /**
- * @tests java.io.DataInputStream#readBoolean()
- * @tests java.io.DataOutputStream#writeBoolean(boolean)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeBoolean",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readBoolean",
- args = {},
- clazz = DataInputStream.class
- )
- })
public void test_read_writeBoolean() throws IOException {
os.writeBoolean(true);
sos.setThrowsException(true);
@@ -90,25 +66,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readByte()
- * @tests java.io.DataOutputStream#writeByte(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeByte",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readByte",
- args = {},
- clazz = DataInputStream.class
- )
- })
public void test_read_writeByte() throws IOException {
os.writeByte((byte) 127);
sos.setThrowsException(true);
@@ -141,25 +98,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readChar()
- * @tests java.io.DataOutputStream#writeChar(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeChar",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readChar",
- args = {},
- clazz = DataInputStream.class
- )
- })
public void test_read_writeChar() throws IOException {
os.writeChar('b');
sos.setThrowsException(true);
@@ -192,25 +130,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readDouble()
- * @tests java.io.DataOutputStream#writeDouble(double)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeDouble",
- args = {double.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readDouble",
- args = {},
- clazz = DataInputStream.class
- )
- })
public void test_read_writeDouble() throws IOException {
os.writeDouble(2345.76834720202);
sos.setThrowsException(true);
@@ -243,25 +162,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readFloat()
- * @tests java.io.DataOutputStream#writeFloat(float)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeFloat",
- args = {float.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readFloat",
- args = {},
- clazz = DataInputStream.class
- )
- })
public void test_read_writeFloat() throws IOException {
os.writeFloat(29.08764f);
sos.setThrowsException(true);
@@ -294,25 +194,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readInt()
- * @tests java.io.DataOutputStream#writeInt(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeInt",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readInt",
- args = {},
- clazz = DataInputStream.class
- )
- })
public void test_read_writeInt() throws IOException {
os.writeInt(768347202);
sos.setThrowsException(true);
@@ -345,25 +226,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readLong()
- * @tests java.io.DataOutputStream#writeLong(long)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeLong",
- args = {long.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readLong",
- args = {},
- clazz = DataInputStream.class
- )
- })
public void test_read_writeLong() throws IOException {
os.writeLong(9875645283333L);
sos.setThrowsException(true);
@@ -396,25 +258,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readShort()
- * @tests java.io.DataOutputStream#writeShort(short)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeShort",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readShort",
- args = {},
- clazz = DataInputStream.class
- )
- })
public void test_read_writeShort() throws IOException {
os.writeShort(9875);
sos.setThrowsException(true);
@@ -447,26 +290,6 @@
}
}
-
- /**
- * @tests java.io.DataInputStream#readUTF()
- * @tests java.io.DataOutputStream#writeUTF(java.lang.String)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeUTF",
- args = {String.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readUTF",
- args = {},
- clazz = DataInputStream.class
- )
- })
public void test_read_writeUTF() throws IOException {
os.writeUTF(unihw);
sos.setThrowsException(true);
@@ -503,19 +326,11 @@
dis = new DataInputStream(new ByteArrayInputStream(sos.toByteArray()));
}
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
protected void setUp() {
sos = new Support_OutputStream(256);
os = new DataOutputStream(sos);
}
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
protected void tearDown() {
try {
os.close();
diff --git a/luni/src/test/java/tests/api/java/io/DataInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldDataInputStreamTest.java
similarity index 73%
rename from luni/src/test/java/tests/api/java/io/DataInputStreamTest.java
rename to luni/src/test/java/libcore/java/io/OldDataInputStreamTest.java
index 08dcb77..27240e6 100644
--- a/luni/src/test/java/tests/api/java/io/DataInputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/OldDataInputStreamTest.java
@@ -14,7 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package tests.api.java.io;
+
+package libcore.java.io;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -22,14 +23,9 @@
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
-
import tests.support.Support_ASimpleInputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-@TestTargetClass(DataInputStream.class)
-public class DataInputStreamTest extends junit.framework.TestCase {
+public class OldDataInputStreamTest extends junit.framework.TestCase {
private DataOutputStream os;
@@ -43,17 +39,7 @@
private final int testLength = fileString.length();
- /**
- * @tests java.io.DataInputStream#DataInputStream(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies DataInputStream(java.io.InputStream) constructor.",
- method = "DataInputStream",
- args = {java.io.InputStream.class}
- )
public void test_ConstructorLjava_io_InputStream() {
- // Test for method java.io.DataInputStream(java.io.InputStream)
try {
os.writeChar('t');
os.close();
@@ -69,14 +55,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#read(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {byte[].class}
- )
public void test_read$B() throws IOException {
byte rbytes[] = new byte[testLength - 5];
Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
@@ -108,14 +86,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII() throws IOException {
byte rbytes[] = new byte[testLength - 5];
Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
@@ -148,14 +118,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII_Exception() throws IOException {
byte rbytes[] = new byte[testLength - 5];
@@ -185,14 +147,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readFully(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readFully",
- args = {byte[].class}
- )
public void test_readFully$B() throws IOException {
byte rbytes[] = new byte[testLength];
@@ -222,15 +176,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readFully(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies everything except illegal argument values.",
- method = "readFully",
- args = {byte[].class, int.class, int.class}
- )
public void test_readFully$BII() throws IOException {
byte rbytes[] = new byte[testLength];
@@ -261,15 +206,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readFully(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that exceptions are thrown for illegal arguments.",
- method = "readFully",
- args = {byte[].class, int.class, int.class}
- )
public void test_readFully$BII_Exception() throws IOException {
DataInputStream is = new DataInputStream(new ByteArrayInputStream(new byte[testLength]));
@@ -320,15 +256,7 @@
}
}
- /**
- * @tests java.io.DataInputStream#readLine()
- */
@SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readLine",
- args = {}
- )
public void test_readLine() throws IOException {
String line;
os.writeBytes("Lorem\nipsum\rdolor sit amet...");
@@ -353,14 +281,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readUnsignedByte()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readUnsignedByte",
- args = {}
- )
public void test_readUnsignedByte() throws IOException {
os.writeByte((byte) -127);
os.close();
@@ -384,14 +304,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readUnsignedShort()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readUnsignedShort",
- args = {}
- )
public void test_readUnsignedShort() throws IOException {
os.writeShort(Short.MIN_VALUE);
os.close();
@@ -415,14 +327,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#readUTF(java.io.DataInput)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readUTF",
- args = {java.io.DataInput.class}
- )
public void test_readUTFLjava_io_DataInput() throws IOException {
os.writeUTF(unihw);
os.close();
@@ -446,47 +350,6 @@
}
}
- /**
- * @tests java.io.DataInputStream#skipBytes(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skipBytes",
- args = {int.class}
- )
- public void test_skipBytesI() {
- // Test for method int java.io.DataInputStream.skipBytes(int)
- try {
- byte fileBytes[] = fileString.getBytes();
- os.write(fileBytes);
- os.close();
- openDataInputStream();
- dis.skipBytes(100);
- byte rbytes[] = new byte[testLength];
- dis.read(rbytes, 0, 50);
- dis.close();
- assertTrue("Incorrect data read", new String(rbytes, 0, 50)
- .equals(fileString.substring(100, 150)));
- } catch (IOException e) {
- fail("IOException during skipBytes test 1 : " + e.getMessage());
- }
- try {
- // boolean eofException = false; //what is this var for?
- int skipped = 0;
- openDataInputStream();
- try {
- skipped = dis.skipBytes(50000);
- } catch (EOFException e) {
- // eofException = true;
- }
- ;
- assertTrue("Skipped should report " + testLength + " not "
- + skipped, skipped == testLength);
- } catch (IOException e) {
- fail("IOException during skipBytes test 2 : " + e.getMessage());
- }
- }
-
private void openDataInputStream() throws IOException {
dis = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
}
diff --git a/luni/src/test/java/tests/api/java/io/DataOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldDataOutputStreamTest.java
similarity index 67%
rename from luni/src/test/java/tests/api/java/io/DataOutputStreamTest.java
rename to luni/src/test/java/libcore/java/io/OldDataOutputStreamTest.java
index 9325b91..a4bfc8e 100644
--- a/luni/src/test/java/tests/api/java/io/DataOutputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/OldDataOutputStreamTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
@@ -23,24 +23,9 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
-
import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-@TestTargetClass(
- value = DataOutputStream.class,
- untestedMethods = {
- @TestTargetNew(
- level = TestLevel.NOT_NECESSARY,
- notes = "Implicitely tested in setUp().",
- method = "DataOutputStream",
- args = {java.io.OutputStream.class}
- )
- }
-)
-public class DataOutputStreamTest extends junit.framework.TestCase {
+public class OldDataOutputStreamTest extends junit.framework.TestCase {
private DataOutputStream os;
@@ -58,14 +43,6 @@
private static final int testLength = testString.length();
- /**
- * @tests java.io.DataOutputStream#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "flush",
- args = {}
- )
public void test_flush() throws IOException {
BufferedOutputStream buf = new BufferedOutputStream(bos);
@@ -92,40 +69,6 @@
}
}
- /**
- * @tests java.io.DataOutputStream#size()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies size() method.",
- method = "size",
- args = {}
- )
- public void test_size() {
- // Test for method int java.io.DataOutputStream.size()
-
- try {
- os.write(testString.getBytes(), 0, testLength / 2);
- os.close();
- assertEquals("Incorrect size returned", testLength / 2, os.size());
- openDataInputStream();
- byte[] rbuf = new byte[testLength / 2];
- dis.read(rbuf, 0, testLength / 2);
- dis.close();
- } catch (IOException e) {
- fail("Exception during write test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.DataOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
public void test_write$BII() throws IOException {
int r;
os.write(testString.getBytes(), 5, testLength - 7);
@@ -141,15 +84,6 @@
testString.substring(5, testLength - 2)));
}
- /**
- * @tests java.io.DataOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument checks.",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
public void test_write$BII_Exception() throws IOException {
byte[] nullByteArray = null;
byte[] byteArray = new byte[10];
@@ -183,14 +117,6 @@
}
}
- /**
- * @tests java.io.DataOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {int.class}
- )
public void test_writeI() throws IOException {
os.write(42);
os.close();
@@ -209,14 +135,6 @@
}
}
- /**
- * @tests java.io.DataOutputStream#writeBytes(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "writeBytes",
- args = {java.lang.String.class}
- )
public void test_writeBytesLjava_lang_String() throws IOException {
os.writeBytes(testString);
os.close();
@@ -237,14 +155,6 @@
}
}
- /**
- * @tests java.io.DataOutputStream#writeChars(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "writeChars",
- args = {java.lang.String.class}
- )
public void test_writeCharsLjava_lang_String() throws IOException {
os.writeChars(unihw);
os.close();
@@ -270,20 +180,12 @@
dis = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
}
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
protected void setUp() {
sos = new Support_OutputStream(true);
bos = new ByteArrayOutputStream();
os = new DataOutputStream(bos);
}
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
protected void tearDown() {
sos.setThrowsException(false);
try {
diff --git a/luni/src/test/java/libcore/java/io/OldFileInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldFileInputStreamTest.java
new file mode 100644
index 0000000..894849a
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFileInputStreamTest.java
@@ -0,0 +1,209 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.channels.FileChannel;
+import junit.framework.TestCase;
+import tests.support.Support_PlatformFile;
+
+public class OldFileInputStreamTest extends TestCase {
+
+ public String fileName;
+ private FileInputStream is;
+ 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_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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";
+
+ public void test_ConstructorLjava_io_File() {
+ // Test for method FileInputStream(File)
+ try {
+ File f = new File(fileName);
+ is = new FileInputStream(f);
+ is.close();
+ } catch (Exception e) {
+ fail("Failed to create FileInputStream : " + e.getMessage());
+ }
+ File f2 = new File("ImprobableFile.42");
+ try {
+ is = new FileInputStream(f2);
+ is.close();
+ f2.delete();
+ fail("FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ } catch (IOException e) {
+ fail("Unexpected IOException: " + e.getMessage());
+ }
+ }
+
+ public void test_ConstructorLjava_io_FileDescriptor() {
+ try {
+ FileInputStream fis = new FileInputStream((FileDescriptor) null);
+ fis.close();
+ fail("NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ } catch (IOException e) {
+ fail("Unexpected IOException: " + e.getMessage());
+ }
+ }
+
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method FileInputStream(java.lang.String)
+ try {
+ is = new FileInputStream(fileName);
+ is.close();
+ } catch (Exception e) {
+ fail("Failed to create FileInputStream : " + e.getMessage());
+ }
+ try {
+ is = new FileInputStream("ImprobableFile.42");
+ is.close();
+ new File("ImprobableFile.42").delete();
+ fail("FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ } catch (IOException e) {
+ fail("Unexpected IOException: " + e.getMessage());
+ }
+ }
+
+ public void test_available() throws IOException {
+ is = new FileInputStream(fileName);
+ assertEquals("Test 1: Returned incorrect number of available bytes;",
+ fileString.length(), is.available());
+ is.close();
+ try {
+ is.available();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_getChannel() {
+ // Test for method FileChannel FileInputStream.getChannel()
+ FileChannel channel;
+ byte[] buffer = new byte[100];
+ byte[] stringBytes;
+ final int offset = 5;
+ boolean equal = true;
+
+ try {
+ FileInputStream fis = new FileInputStream(fileName);
+ channel = fis.getChannel();
+ assertNotNull(channel);
+ assertTrue("Channel is closed.", channel.isOpen());
+
+ // Check that the channel is associated with the input stream.
+ channel.position(offset);
+ fis.read(buffer, 0, 10);
+ stringBytes = fileString.getBytes();
+ for (int i = 0; i < 10; i++) {
+ equal &= (buffer[i] == stringBytes[i + offset]);
+ }
+ assertTrue("Channel is not associated with this stream.", equal);
+
+ fis.close();
+ assertFalse("Channel has not been closed.", channel.isOpen());
+ } catch (FileNotFoundException e) {
+ fail("Could not find : " + fileName);
+ }
+
+ catch (IOException e) {
+ fail("Exception during test : " + e.getMessage());
+ }
+ }
+
+ public void test_read() throws IOException {
+ is = new FileInputStream(fileName);
+ int c = is.read();
+ assertEquals("Test 1: Read returned incorrect char;",
+ fileString.charAt(0), c);
+
+ is.close();
+ try {
+ is.read();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read$B() throws IOException {
+ byte[] buf1 = new byte[100];
+ is = new FileInputStream(fileName);
+ is.skip(3000);
+ is.read(buf1);
+ is.close();
+ assertTrue("Test 1: Failed to read correct data.",
+ new String(buf1, 0, buf1.length).equals(
+ fileString.substring(3000, 3100)));
+
+ is.close();
+ try {
+ is.read(buf1);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_skipJ() throws IOException {
+ byte[] buf1 = new byte[10];
+ is = new FileInputStream(fileName);
+ is.skip(1000);
+ is.read(buf1, 0, buf1.length);
+ assertTrue("Test 1: Failed to skip to correct position.",
+ new String(buf1, 0, buf1.length).equals(
+ fileString.substring(1000, 1010)));
+
+ is.close();
+ try {
+ is.read();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ protected void setUp() throws Exception {
+ fileName = System.getProperty("java.io.tmpdir");
+ 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 FileOutputStream(fileName);
+ fos.write(fileString.getBytes());
+ fos.close();
+ }
+
+ protected void tearDown() throws Exception {
+ if (is != null) {
+ is.close();
+ }
+ new File(fileName).delete();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFileOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldFileOutputStreamTest.java
new file mode 100644
index 0000000..3661b3e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFileOutputStreamTest.java
@@ -0,0 +1,204 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class OldFileOutputStreamTest extends junit.framework.TestCase {
+
+ public String fileName;
+
+ FileOutputStream fos;
+
+ FileInputStream fis;
+
+ File f;
+
+ String tmpDirName = System.getProperty("java.io.tmpdir");
+
+ File tmpDir = new File(tmpDirName);
+
+ 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_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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";
+
+ public void test_ConstructorLjava_io_File() throws Exception {
+ try {
+ fos = new FileOutputStream(tmpDir);
+ fail("Test 1: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ }
+
+ f = new File(fileName = System.getProperty("java.io.tmpdir"), "fos.tst");
+ fos = new FileOutputStream(f);
+ }
+
+ public void test_ConstructorLjava_io_FileZ() throws Exception {
+ try {
+ fos = new FileOutputStream(tmpDir, false);
+ fail("Test 1: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ }
+
+ f = new File(tmpDirName, "fos.tst");
+ fos = new FileOutputStream(f, false);
+ fos.write("FZ1".getBytes(), 0, 3);
+ fos.close();
+ // Append data to existing file
+ fos = new FileOutputStream(f, true);
+ fos.write(fileString.getBytes());
+ fos.close();
+ byte[] buf = new byte[fileString.length() + 3];
+ fis = new FileInputStream(f);
+ fis.read(buf, 0, buf.length);
+ assertTrue("Test 2: Failed to create appending stream.", new String(buf, 0,
+ buf.length).equals("FZ1" + fileString));
+ fis.close();
+
+ // Check that the existing file is overwritten
+ fos = new FileOutputStream(f, false);
+ fos.write("FZ2".getBytes(), 0, 3);
+ fos.close();
+ fis = new FileInputStream(f);
+ int bytesRead = fis.read(buf, 0, buf.length);
+ assertTrue("Test 3: Failed to overwrite stream.", new String(buf, 0,
+ bytesRead).equals("FZ2"));
+ }
+
+ public void test_ConstructorLjava_lang_String() throws Exception {
+ try {
+ fos = new FileOutputStream(tmpDirName);
+ fail("Test 1: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ConstructorLjava_lang_StringZ() throws Exception {
+ try {
+ fos = new FileOutputStream(tmpDirName, true);
+ fail("Test 1: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ }
+
+ f = new File(tmpDirName, "fos.tst");
+ fos = new FileOutputStream(f.getPath(), false);
+ fos.write("HI".getBytes(), 0, 2);
+ fos.close();
+ // Append data to existing file
+ fos = new FileOutputStream(f.getPath(), true);
+ fos.write(fileString.getBytes());
+ fos.close();
+ byte[] buf = new byte[fileString.length() + 2];
+ fis = new FileInputStream(f.getPath());
+ fis.read(buf, 0, buf.length);
+ assertTrue("Failed to create appending stream", new String(buf, 0,
+ buf.length).equals("HI" + fileString));
+ fis.close();
+
+ // Check that the existing file is overwritten
+ fos = new FileOutputStream(f.getPath(), false);
+ fos.write("HI".getBytes(), 0, 2);
+ fos.close();
+ fis = new FileInputStream(f.getPath());
+ int bytesRead = fis.read(buf, 0, buf.length);
+ assertTrue("Failed to overwrite stream", new String(buf, 0,
+ bytesRead).equals("HI"));
+ }
+
+ public void test_write$B() throws Exception {
+ // Test for method void java.io.FileOutputStream.write(byte [])
+ f = new File(System.getProperty("java.io.tmpdir"), "output.tst");
+ fos = new FileOutputStream(f.getPath());
+ fos.write(fileString.getBytes());
+ fos.close();
+ try {
+ fos.write(fileString.getBytes());
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ fis = new FileInputStream(f.getPath());
+ byte rbytes[] = new byte[4000];
+ fis.read(rbytes, 0, fileString.length());
+ assertTrue("Test 2: Incorrect string written or read.",
+ new String(rbytes, 0, fileString.length()).equals(fileString));
+ }
+
+ public void test_writeI() throws IOException {
+ // Test for method void java.io.FileOutputStream.write(int)
+ f = new File(System.getProperty("java.io.tmpdir"), "output.tst");
+ fos = new FileOutputStream(f.getPath());
+ fos.write('t');
+ fos.close();
+ try {
+ fos.write(42);
+ fail("Test: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ fis = new FileInputStream(f.getPath());
+ assertEquals("Test 1: Incorrect char written or read.",
+ 't', fis.read());
+ }
+
+ public void test_write$BII3() {
+ try {
+ new FileOutputStream(new FileDescriptor()).write(new byte[1], 0, 0);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ public void test_getChannel() throws Exception {
+ // Make sure that system properties are set correctly
+ if (tmpDir == null) {
+ throw new Exception("System property java.io.tmpdir not defined.");
+ }
+ File tmpfile = File.createTempFile("FileOutputStream", "tmp");
+ tmpfile.deleteOnExit();
+ FileOutputStream fos = new FileOutputStream(tmpfile);
+ byte[] b = new byte[10];
+ for (int i = 10; i < b.length; i++) {
+ b[i] = (byte) i;
+ }
+ fos.write(b);
+ fos.flush();
+ fos.close();
+ FileOutputStream f = new FileOutputStream(tmpfile, true);
+ assertEquals(10, f.getChannel().position());
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (f != null)
+ f.delete();
+ if (fis != null)
+ fis.close();
+ if (fos != null)
+ fos.close();
+ }
+}
diff --git a/luni/src/test/java/tests/api/java/io/FilePermissionTest.java b/luni/src/test/java/libcore/java/io/OldFilePermissionTest.java
similarity index 81%
rename from luni/src/test/java/tests/api/java/io/FilePermissionTest.java
rename to luni/src/test/java/libcore/java/io/OldFilePermissionTest.java
index fc499c4..66fbbf6 100644
--- a/luni/src/test/java/tests/api/java/io/FilePermissionTest.java
+++ b/luni/src/test/java/libcore/java/io/OldFilePermissionTest.java
@@ -15,18 +15,13 @@
* limitations under the License.
*/
-package tests.api.java.io;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
+package libcore.java.io;
import java.io.File;
import java.io.FilePermission;
import java.security.PermissionCollection;
-@TestTargetClass(FilePermission.class)
-public class FilePermissionTest extends junit.framework.TestCase {
+public class OldFilePermissionTest extends junit.framework.TestCase {
FilePermission readAllFiles;
FilePermission alsoReadAllFiles;
@@ -44,16 +39,6 @@
readInFile = new FilePermission("aFile.file", "read");
}
- /**
- * @tests java.io.FilePermission#FilePermission(java.lang.String,
- * java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies FilePermission(java.lang.String, java.lang.String) constructor.",
- method = "FilePermission",
- args = {java.lang.String.class, java.lang.String.class}
- )
public void test_ConstructorLjava_lang_StringLjava_lang_String() {
// Test for method java.io.FilePermission(java.lang.String,
// java.lang.String)
@@ -89,15 +74,6 @@
}
}
- /**
- * @tests java.io.FilePermission#getActions()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getActions() method.",
- method = "getActions",
- args = {}
- )
public void test_getActions() {
// Test for method java.lang.String java.io.FilePermission.getActions()
assertEquals("getActions should have returned only read", "read", readAllFiles
@@ -106,15 +82,6 @@
.getActions());
}
- /**
- * @tests java.io.FilePermission#equals(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies equals(java.lang.Object) method.",
- method = "equals",
- args = {java.lang.Object.class}
- )
public void test_equalsLjava_lang_Object() {
// test for method java.io.FilePermission.equals()
assertTrue(
@@ -125,15 +92,6 @@
!(readInCurrent.equals(readInFile)));
}
- /**
- * @tests java.io.FilePermission#implies(java.security.Permission)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies implies(java.security.Permission) method.",
- method = "implies",
- args = {java.security.Permission.class}
- )
public void test_impliesLjava_security_Permission() {
// Test for method boolean
// java.io.FilePermission.implies(java.security.Permission)
@@ -187,15 +145,6 @@
.implies(fp10));
}
- /**
- * @tests java.io.FilePermission#newPermissionCollection()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies newPermissionCollection() method.",
- method = "newPermissionCollection",
- args = {}
- )
public void test_newPermissionCollection() {
// test for method java.io.FilePermission.newPermissionCollection
char s = File.separatorChar;
@@ -229,15 +178,6 @@
assertTrue("collection does not collate", fpc.implies(fp2));
}
- /**
- * @tests java.io.FilePermission#hashCode()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies hashCode() method.",
- method = "hashCode",
- args = {}
- )
public void test_hashCode() {
// test method java.io.FilePermission.hasCode()
assertTrue(
diff --git a/luni/src/test/java/libcore/java/io/OldFileReaderTest.java b/luni/src/test/java/libcore/java/io/OldFileReaderTest.java
new file mode 100644
index 0000000..fb541f3
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFileReaderTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+
+public class OldFileReaderTest extends junit.framework.TestCase {
+
+ FileReader br;
+
+ public void test_ConstructorLjava_io_File() {
+ File noFile = new File(System.getProperty("java.io.tmpdir"), "noreader.tst");
+ try {
+ br = new FileReader(noFile);
+ fail("Test 2: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ConstructorLjava_lang_String() {
+ try {
+ br = new FileReader(System.getProperty("java.io.tmpdir") + "/noreader.tst");
+ fail("Test 2: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFileTest.java b/luni/src/test/java/libcore/java/io/OldFileTest.java
new file mode 100644
index 0000000..8265d20
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFileTest.java
@@ -0,0 +1,241 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import junit.framework.TestCase;
+import static tests.support.Support_Exec.execAndGetOutput;
+import static tests.support.Support_Exec.javaProcessBuilder;
+
+public class OldFileTest extends TestCase {
+
+ /** Location to store tests in */
+ private File tempDirectory;
+
+ /** Temp file that does exist */
+ private File tempFile;
+
+ /** File separator */
+ private String slash = File.separator;
+
+ 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_File\nTest_FileDescriptor\nTest_FileInputStream\nTest_FileNotFoundException\nTest_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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";
+
+ private static String platformId = "Android"
+ + System.getProperty("java.vm.version").replace('.', '-');
+
+ {
+ // Delete all old temporary files
+ File tempDir = new File(System.getProperty("java.io.tmpdir"));
+ String[] files = tempDir.list();
+ for (int i = 0; i < files.length; i++) {
+ File f = new File(tempDir, files[i]);
+ if (f.isDirectory()) {
+ if (files[i].startsWith("hyts_resources"))
+ deleteTempFolder(f);
+ }
+ if (files[i].startsWith("hyts_") || files[i].startsWith("hyjar_"))
+ new File(tempDir, files[i]).delete();
+ }
+ }
+
+ private void deleteTempFolder(File dir) {
+ String files[] = dir.list();
+ for (int i = 0; i < files.length; i++) {
+ File f = new File(dir, files[i]);
+ if (f.isDirectory())
+ deleteTempFolder(f);
+ else {
+ f.delete();
+ }
+ }
+ dir.delete();
+
+ }
+
+ public void test_ConstructorLjava_io_FileLjava_lang_String() throws Exception {
+ String error;
+ String dirName = System.getProperty("java.io.tmpdir");
+ System.setProperty("user.dir", dirName);
+
+ File d = new File(dirName);
+ File f = new File(d, "input.tst");
+ if (!dirName.regionMatches((dirName.length() - 1), slash, 0, 1))
+ dirName += slash;
+ dirName += "input.tst";
+ error = String.format("Test 1: Incorrect file created: %s; %s expected.", f.getPath(), dirName);
+ assertTrue(error, f.getPath().equals(dirName));
+
+ String fileName = null;
+ try {
+ f = new File(d, fileName);
+ fail("Test 2: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ }
+
+ d = null;
+ f = new File(d, "input.tst");
+ error = String.format("Test 3: Incorrect file created: %s; %s expected.",
+ f.getAbsolutePath(), dirName);
+ assertTrue(error, f.getAbsolutePath().equals(dirName));
+
+ // Regression test for Harmony-382
+ File s = null;
+ f = new File("/abc");
+ d = new File(s, "/abc");
+ assertEquals("Test 4: Incorrect file created;",
+ f.getAbsolutePath(), d.getAbsolutePath());
+ }
+
+ public void test_ConstructorLjava_lang_StringLjava_lang_String() throws IOException {
+ String dirName = null;
+ String fileName = "input.tst";
+
+ String userDir = System.getProperty("java.io.tmpdir");
+ System.setProperty("user.dir", userDir);
+
+ File f = new File(dirName, fileName);
+ if (!userDir.regionMatches((userDir.length() - 1), slash, 0, 1))
+ userDir += slash;
+ userDir += "input.tst";
+ String error = String.format("Test 1: Incorrect file created: %s; %s expected.",
+ f.getAbsolutePath(), userDir);
+ assertTrue(error, f.getAbsolutePath().equals(userDir));
+
+ dirName = System.getProperty("java.io.tmpdir");
+ fileName = null;
+ try {
+ f = new File(dirName, fileName);
+ fail("Test 2: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ fileName = "input.tst";
+ f = new File(dirName, fileName);
+ assertTrue("Test 3: Incorrect file created.", f.getPath()
+ .equals(userDir));
+
+ // Regression test for Harmony-382
+ String s = null;
+ f = new File("/abc");
+ File d = new File(s, "/abc");
+ assertEquals("Test 4: Incorrect file created;", d.getAbsolutePath(), f
+ .getAbsolutePath());
+ assertEquals("Test3: Created Incorrect File", "/abc", f
+ .getAbsolutePath());
+ }
+
+ public void test_createTempFileLjava_lang_StringLjava_lang_String() {
+ try {
+ // Providing an illegal file prefix.
+ File f3 = File.createTempFile("/../../../../../", null);
+ f3.delete();
+ fail("IOException not thrown");
+ } catch (IOException e) {
+ }
+ }
+
+ public void test_renameToLjava_io_File() {
+ String base = System.getProperty("java.io.tmpdir");
+ File dir = new File(base, platformId);
+ dir.mkdir();
+ File f = new File(dir, "xxx.xxx");
+ try {
+ f.renameTo(null);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ }
+
+ public void test_toURL3() throws MalformedURLException {
+ File dir = new File(""); // current directory
+ String newDirURL = dir.toURL().toString();
+ assertTrue("Test 1: URL does not end with slash.",
+ newDirURL.endsWith("/"));
+ }
+
+ public void test_deleteOnExit() throws IOException, InterruptedException {
+ String cts = System.getProperty("java.io.tmpdir");
+ File dir = new File(cts + "/hello");
+ dir.mkdir();
+ assertTrue(dir.exists());
+ File subDir = new File(cts + "/hello/world");
+ subDir.mkdir();
+ assertTrue(subDir.exists());
+
+ URL url = getClass().getResource("/HelloWorld.txt");
+ String classPath = url.toString();
+ int idx = classPath.indexOf("!");
+ assertTrue("could not find the path of the test jar/apk", idx > 0);
+ classPath = classPath.substring(9, idx); // cutting off jar:file:
+
+ ProcessBuilder builder = javaProcessBuilder();
+ builder.command().add("-cp");
+ builder.command().add(System.getProperty("java.class.path"));
+ builder.command().add("tests.support.Support_DeleteOnExitTest");
+ builder.command().add(dir.getAbsolutePath());
+ builder.command().add(subDir.getAbsolutePath());
+ execAndGetOutput(builder);
+
+ assertFalse(dir.exists());
+ assertFalse(subDir.exists());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // Make sure that system properties are set correctly
+ String userDir = System.getProperty("java.io.tmpdir");
+ if (userDir == null)
+ throw new Exception("System property java.io.tmpdir not defined.");
+ System.setProperty("java.io.tmpdir", userDir);
+
+ /** Setup the temporary directory */
+ if (!userDir.regionMatches((userDir.length() - 1), slash, 0, 1))
+ userDir += slash;
+ tempDirectory = new File(userDir + "tempDir"
+ + String.valueOf(System.currentTimeMillis()));
+ if (!tempDirectory.mkdir())
+ System.out.println("Setup for OldFileTest failed (1).");
+
+ /** Setup the temporary file */
+ tempFile = new File(tempDirectory, "tempfile");
+ FileOutputStream tempStream;
+ try {
+ tempStream = new FileOutputStream(tempFile.getPath(), false);
+ tempStream.close();
+ } catch (IOException e) {
+ System.out.println("Setup for OldFileTest failed (2).");
+ return;
+ }
+ }
+
+ protected void tearDown() {
+ if (tempFile.exists() && !tempFile.delete())
+ System.out
+ .println("OldFileTest.tearDown() failed, could not delete file!");
+ if (!tempDirectory.delete())
+ System.out
+ .println("OldFileTest.tearDown() failed, could not delete directory!");
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFileWriterTest.java b/luni/src/test/java/libcore/java/io/OldFileWriterTest.java
new file mode 100644
index 0000000..1db9a3e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFileWriterTest.java
@@ -0,0 +1,164 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import junit.framework.TestCase;
+
+public class OldFileWriterTest extends TestCase {
+
+ FileWriter fw;
+
+ FileInputStream fis;
+
+ BufferedWriter bw;
+
+ File f;
+
+ public void test_ConstructorLjava_io_File_IOException() {
+ File dir = new File(System.getProperty("java.io.tmpdir"));
+
+ try {
+ fw = new FileWriter(dir);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ConstructorLjava_io_FileZ_IOException() {
+ File dir = new File(System.getProperty("java.io.tmpdir"));
+
+ try {
+ fw = new FileWriter(dir, true);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ConstructorLjava_lang_String_IOException() {
+ try {
+ fw = new FileWriter(System.getProperty("java.io.tmpdir"));
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+
+ public void test_ConstructorLjava_lang_StringZ_IOException() {
+ try {
+ fw = new FileWriter(System.getProperty("java.io.tmpdir"), false);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_handleEarlyEOFChar_1() {
+ String str = "All work and no play makes Jack a dull boy\n";
+ int NUMBER = 2048;
+ int j = 0;
+ int len = str.length() * NUMBER;
+ /* == 88064 *//* NUMBER compulsively written copies of the same string */
+ char[] strChars = new char[len];
+ for (int i = 0; i < NUMBER; ++i) {
+ for (int k = 0; k < str.length(); ++k) {
+ strChars[j++] = str.charAt(k);
+ }
+ }
+ File f = null;
+ FileWriter fw = null;
+ try {
+ f = File.createTempFile("ony", "by_one");
+ fw = new FileWriter(f);
+ fw.write(strChars);
+ fw.close();
+ InputStreamReader in = null;
+ FileInputStream fis = new FileInputStream(f);
+ in = new InputStreamReader(fis);
+ int b;
+ int errors = 0;
+ for (int offset = 0; offset < strChars.length; ++offset) {
+ b = in.read();
+ if (b == -1) {
+ fail("Early EOF at offset " + offset + "\n");
+ return;
+ }
+ }
+ assertEquals(0, errors);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void test_handleEarlyEOFChar_2() throws IOException {
+ int capacity = 65536;
+ byte[] bytes = new byte[capacity];
+ byte[] bs = {
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'
+ };
+ for (int i = 0; i < bytes.length; i++) {
+ bytes[i] = bs[i / 8192];
+ }
+ String inputStr = new String(bytes);
+ int len = inputStr.length();
+ File f = File.createTempFile("FileWriterBugTest ", null);
+ FileWriter writer = new FileWriter(f);
+ writer.write(inputStr);
+ writer.close();
+ long flen = f.length();
+
+ FileReader reader = new FileReader(f);
+ char[] outChars = new char[capacity];
+ int outCount = reader.read(outChars);
+ String outStr = new String(outChars, 0, outCount);
+
+ f.deleteOnExit();
+ assertEquals(len, flen);
+ assertEquals(inputStr, outStr);
+ }
+
+ protected void setUp() throws Exception {
+ f = File.createTempFile("writer", ".tst");
+
+ if (f.exists())
+ if (!f.delete()) {
+ fail("Unable to delete test file");
+ }
+ }
+
+ protected void tearDown() {
+ try {
+ bw.close();
+ } catch (Exception e) {
+ }
+ try {
+ fis.close();
+ } catch (Exception e) {
+ }
+ f.delete();
+ }
+}
diff --git a/luni/src/test/java/tests/api/java/io/FilterInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldFilterInputStreamTest.java
similarity index 73%
rename from luni/src/test/java/tests/api/java/io/FilterInputStreamTest.java
rename to luni/src/test/java/libcore/java/io/OldFilterInputStreamTest.java
index 0c4848e..848b1bf 100644
--- a/luni/src/test/java/tests/api/java/io/FilterInputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/OldFilterInputStreamTest.java
@@ -15,22 +15,16 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
import java.io.BufferedInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.util.Arrays;
-
import tests.support.Support_ASimpleInputStream;
import tests.support.Support_PlatformFile;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-@TestTargetClass(FilterInputStream.class)
-public class FilterInputStreamTest extends junit.framework.TestCase {
+public class OldFilterInputStreamTest extends junit.framework.TestCase {
static class MyFilterInputStream extends java.io.FilterInputStream {
public MyFilterInputStream(java.io.InputStream is) {
@@ -50,15 +44,6 @@
private static final int testLength = testString.length();
- /**
- * @tests java.io.FilterInputStream#InputStream()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies constructor FilterInputStream(InputStream).",
- method = "FilterInputStream",
- args = {java.io.InputStream.class}
- )
public void test_Constructor() {
// The FilterInputStream object has already been created in setUp().
// If anything has gone wrong, closing it should throw a
@@ -72,14 +57,6 @@
}
}
- /**
- * @tests java.io.FilterInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "available",
- args = {}
- )
public void test_available() throws IOException {
assertEquals("Test 1: Returned incorrect number of available bytes;",
testLength, is.available());
@@ -93,14 +70,6 @@
}
}
- /**
- * @tests java.io.FilterInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
public void test_close() throws IOException {
is.close();
@@ -122,23 +91,6 @@
sis.throwExceptionOnNextUse = false;
}
- /**
- * @tests java.io.FilterInputStream#mark(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies mark(int) in combination with reset().",
- method = "mark",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies mark(int) in combination with reset().",
- method = "reset",
- args = {}
- )
- })
public void test_markI() throws Exception {
// Test for method void java.io.FilterInputStream.mark(int)
final int bufSize = 10;
@@ -173,15 +125,6 @@
Arrays.equals(buf1, buf2));
}
- /**
- * @tests java.io.FilterInputStream#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies markSupported() method.",
- method = "markSupported",
- args = {}
- )
public void test_markSupported() throws Exception {
// Test for method boolean java.io.FilterInputStream.markSupported()
@@ -198,14 +141,6 @@
"for a BufferedInputStream.", is.markSupported());
}
- /**
- * @tests java.io.FilterInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
public void test_read() throws IOException {
int c = is.read();
assertEquals("Test 1: Read returned incorrect char;",
@@ -220,14 +155,6 @@
}
}
- /**
- * @tests java.io.FilterInputStream#read(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {byte[].class}
- )
public void test_read$B() throws IOException {
// Test for method int java.io.FilterInputStream.read(byte [])
byte[] buf1 = new byte[100];
@@ -245,31 +172,6 @@
}
}
- /**
- * @tests java.io.FilterInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() throws IOException {
- byte[] buf1 = new byte[20];
- is.skip(10);
- is.read(buf1, 0, buf1.length);
- assertTrue("Failed to read correct data", new String(buf1, 0,
- buf1.length).equals(testString.substring(10, 30)));
- }
-
- /**
- * @tests FilterInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument checks.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII_Exception() throws IOException {
byte[] buf = null;
try {
@@ -331,23 +233,6 @@
}
}
- /**
- * @tests java.io.FilterInputStream#reset()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies reset() in combination with mark().",
- method = "reset",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies reset() in combination with mark().",
- method = "mark",
- args = { int.class }
- )
- })
public void test_reset() throws Exception {
// Test for method void java.io.FilterInputStream.reset()
@@ -390,14 +275,6 @@
Arrays.equals(buf1, buf2));
}
- /**
- * @tests java.io.FilterInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- )
public void test_skipJ() throws IOException {
byte[] buf1 = new byte[10];
is.skip(10);
@@ -415,10 +292,6 @@
}
}
- /**
- * 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("java.io.tmpdir");
@@ -439,10 +312,6 @@
}
}
- /**
- * 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();
diff --git a/luni/src/test/java/tests/api/java/io/FilterOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldFilterOutputStreamTest.java
similarity index 83%
rename from luni/src/test/java/tests/api/java/io/FilterOutputStreamTest.java
rename to luni/src/test/java/libcore/java/io/OldFilterOutputStreamTest.java
index 3ae1271..da8b85d 100644
--- a/luni/src/test/java/tests/api/java/io/FilterOutputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/OldFilterOutputStreamTest.java
@@ -15,20 +15,15 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
-
import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-@TestTargetClass(java.io.FilterOutputStream.class)
-public class FilterOutputStreamTest extends junit.framework.TestCase {
+public class OldFilterOutputStreamTest extends junit.framework.TestCase {
private java.io.FilterOutputStream os;
@@ -43,15 +38,6 @@
private final int testLength = fileString.length();
- /**
- * @tests java.io.FilterOutputStream#FilterOutputStream(java.io.OutputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies FilterOutputStream(java.io.OutputStream) constructor.",
- method = "FilterOutputStream",
- args = {java.io.OutputStream.class}
- )
public void test_ConstructorLjava_io_OutputStream() {
// Test for method java.io.FilterOutputStream(java.io.OutputStream)
try {
@@ -63,14 +49,6 @@
}
}
- /**
- * @tests java.io.FilterOutputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
public void test_close() throws IOException {
Support_OutputStream sos = new Support_OutputStream();
os = new FilterOutputStream(sos);
@@ -99,14 +77,6 @@
}
}
- /**
- * @tests java.io.FilterOutputStream#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "flush",
- args = {}
- )
public void test_flush() throws IOException {
Support_OutputStream sos = new Support_OutputStream(550);
os = new FilterOutputStream(sos);
@@ -125,14 +95,6 @@
sos.setThrowsException(false);
}
- /**
- * @tests java.io.FilterOutputStream#write(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {byte[].class}
- )
public void test_write$B() throws IOException {
Support_OutputStream sos = new Support_OutputStream(testLength);
os = new FilterOutputStream(sos);
@@ -156,14 +118,6 @@
}
}
- /**
- * @tests java.io.FilterOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
public void test_write$BII() throws IOException {
Support_OutputStream sos = new Support_OutputStream(testLength);
os = new FilterOutputStream(sos);
@@ -187,14 +141,6 @@
}
}
- /**
- * @tests java.io.FilterOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
public void test_write$BII_Exception() throws IOException {
Support_OutputStream sos = new Support_OutputStream(testLength);
os = new FilterOutputStream(sos);
@@ -222,14 +168,6 @@
}
}
- /**
- * @tests java.io.FilterOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {int.class}
- )
public void test_writeI() throws IOException {
Support_OutputStream sos = new Support_OutputStream(1);
os = new FilterOutputStream(sos);
@@ -251,10 +189,6 @@
}
}
- /**
- * 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)
diff --git a/luni/src/test/java/tests/api/java/io/FilterReaderTest.java b/luni/src/test/java/libcore/java/io/OldFilterReaderTest.java
similarity index 63%
rename from luni/src/test/java/tests/api/java/io/FilterReaderTest.java
rename to luni/src/test/java/libcore/java/io/OldFilterReaderTest.java
index 644a511..7d1d3de 100644
--- a/luni/src/test/java/tests/api/java/io/FilterReaderTest.java
+++ b/luni/src/test/java/libcore/java/io/OldFilterReaderTest.java
@@ -15,19 +15,14 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
import java.io.ByteArrayInputStream;
import java.io.FilterReader;
import java.io.IOException;
import java.io.InputStreamReader;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(FilterReader.class)
-public class FilterReaderTest extends junit.framework.TestCase {
+public class OldFilterReaderTest extends junit.framework.TestCase {
private boolean called;
private FilterReader fr;
@@ -80,15 +75,6 @@
}
}
- /**
- * @tests java.io.FilterReader#FilterReader(java.io.Reader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies constructor FilterReader(java.io.Reader).",
- method = "FilterReader",
- args = {java.io.Reader.class}
- )
public void test_ConstructorLjava_io_Reader() {
FilterReader myReader = null;
@@ -103,86 +89,32 @@
}
}
- /**
- * @tests java.io.FilterReader#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies close().",
- method = "close",
- args = {}
- )
public void test_close() throws IOException {
fr.close();
assertTrue("close() has not been called.", called);
}
- /**
- * @tests java.io.FilterReader#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies mark(int).",
- method = "mark",
- args = {int.class}
- )
public void test_markI() throws IOException {
fr.mark(0);
assertTrue("mark(int) has not been called.", called);
}
- /**
- * @tests java.io.FilterReader#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies markSupported().",
- method = "markSupported",
- args = {}
- )
public void test_markSupported() {
fr.markSupported();
assertTrue("markSupported() has not been called.", called);
}
- /**
- * @tests java.io.FilterReader#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies read().",
- method = "read",
- args = {}
- )
public void test_read() throws IOException {
fr.read();
assertTrue("read() has not been called.", called);
}
- /**
- * @tests java.io.FilterReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies read(char[], int, int).",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
public void test_read$CII() throws IOException {
char[] buffer = new char[5];
fr.read(buffer, 0, 5);
assertTrue("read(char[], int, int) has not been called.", called);
}
- /**
- * @tests java.io.FilterReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies read(char[], int, int).",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
public void test_read$CII_Exception() throws IOException {
byte[] bbuffer = new byte[20];
char[] buffer = new char[10];
@@ -212,62 +144,27 @@
}
}
- /**
- * @tests java.io.FilterReader#ready()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies ready().",
- method = "ready",
- args = {}
- )
public void test_ready() throws IOException {
fr.ready();
assertTrue("ready() has not been called.", called);
}
- /**
- * @tests java.io.FilterReader#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies reset().",
- method = "reset",
- args = {}
- )
public void test_reset() throws IOException {
fr.reset();
assertTrue("reset() has not been called.", called);
}
- /**
- * @tests java.io.FilterReader#skip()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies skip(long).",
- method = "skip",
- args = {long.class}
- )
public void test_skip() throws IOException {
fr.skip(10);
assertTrue("skip(long) has not been called.", called);
}
- /**
- * This method is called before a test is executed. It creates a
- * FilterReader instance.
- */
protected void setUp() {
fr = new MyFilterReader(new MockReader());
called = false;
}
- /**
- * This method is called after a test is executed. It closes the
- * FilterReader instance.
- */
protected void tearDown() {
try {
diff --git a/luni/src/test/java/tests/api/java/io/FilterWriterTest.java b/luni/src/test/java/libcore/java/io/OldFilterWriterTest.java
similarity index 62%
rename from luni/src/test/java/tests/api/java/io/FilterWriterTest.java
rename to luni/src/test/java/libcore/java/io/OldFilterWriterTest.java
index 99ddc6a..f4c9797 100644
--- a/luni/src/test/java/tests/api/java/io/FilterWriterTest.java
+++ b/luni/src/test/java/libcore/java/io/OldFilterWriterTest.java
@@ -15,23 +15,14 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
-import tests.api.java.io.FilterReaderTest.MyFilterReader;
-
-import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FilterWriter;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(FilterWriter.class)
-public class FilterWriterTest extends junit.framework.TestCase {
+public class OldFilterWriterTest extends junit.framework.TestCase {
private boolean called;
private FilterWriter fw;
@@ -72,15 +63,6 @@
}
}
- /**
- * @tests java.io.FilterWriter#FilterReader(java.io.Reader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies constructor FilterWriter(java.io.Writer).",
- method = "FilterWriter",
- args = {java.io.Writer.class}
- )
public void test_ConstructorLjava_io_Writer() {
FilterWriter myWriter = null;
@@ -95,72 +77,27 @@
}
}
- /**
- * @tests java.io.FilterWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies close().",
- method = "close",
- args = {}
- )
public void test_close() throws IOException {
fw.close();
assertTrue("close() has not been called.", called);
}
- /**
- * @tests java.io.FilterWriter#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies flush().",
- method = "flush",
- args = {}
- )
public void test_flush() throws IOException {
fw.flush();
assertTrue("flush() has not been called.", called);
}
- /**
- * @tests java.io.FilterWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(int).",
- method = "write",
- args = {int.class}
- )
public void test_writeI() throws IOException {
fw.write(0);
assertTrue("write(int) has not been called.", called);
}
- /**
- * @tests java.io.FilterWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(char[], int, int).",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
public void test_write$CII() throws IOException {
char[] buffer = new char[5];
fw.write(buffer, 0, 5);
assertTrue("write(char[], int, int) has not been called.", called);
}
- /**
- * @tests java.io.FilterReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(char[], int, int).",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
public void test_write$CII_Exception() throws IOException {
char[] buffer = new char[10];
@@ -189,40 +126,23 @@
}
}
- /**
- * @tests java.io.FilterWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(String, int, int).",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
public void test_writeLjava_lang_StringII() throws IOException {
fw.write("Hello world", 0, 5);
assertTrue("write(String, int, int) has not been called.", called);
}
- /**
- * This method is called before a test is executed. It creates a
- * FilterWriter instance.
- */
protected void setUp() {
fw = new MyFilterWriter(new MockWriter());
called = false;
}
- /**
- * This method is called after a test is executed. It closes the
- * FilterWriter instance.
- */
protected void tearDown() {
try {
fw.close();
} catch (Exception e) {
- System.out.println("Exception during FilterWriterTest tear down.");
+ System.out.println("Exception during OldFilterWriterTest tear down.");
}
}
}
diff --git a/luni/src/test/java/libcore/java/io/OldInputStreamReaderTest.java b/luni/src/test/java/libcore/java/io/OldInputStreamReaderTest.java
new file mode 100644
index 0000000..db5a374
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldInputStreamReaderTest.java
@@ -0,0 +1,295 @@
+/*
+ * 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 libcore.java.io;
+
+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.util.Arrays;
+import junit.framework.TestCase;
+import tests.support.Support_ASimpleInputStream;
+
+public class OldInputStreamReaderTest 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";
+
+ 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);
+ }
+
+ protected void tearDown() throws Exception {
+ try {
+ in.close();
+ is.close();
+ fis.close();
+ } catch (IOException e) {
+ }
+
+ super.tearDown();
+ }
+
+ public void testReadcharArrayintint() throws IOException {
+ try {
+ reader.read(new char[3], -1, 0);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+ try {
+ reader.read(new char[3], 0, -1);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+ try {
+ reader.read(new char[3], 4, 0);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+ try {
+ reader.read(new char[3], 3, 1);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+ try {
+ reader.read(new char[3], 1, 3);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+ try {
+ reader.read(new char[3], 0, 4);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+
+ try {
+ reader.read(null, 0, 0);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException 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()));
+ }
+
+ 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 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();
+ }
+ }
+
+ public void test_ConstructorLjava_io_InputStream() {
+ // Test for method java.io.InputStreamReader(java.io.InputStream)
+ assertTrue("Used to test other methods", true);
+ }
+
+ 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");
+ }
+
+ 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("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Exception means read failed due to close
+ }
+
+ is = new InputStreamReader(new Support_ASimpleInputStream(true));
+ try {
+ is.read();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ }
+
+ public void testClose() throws IOException {
+ reader.close();
+ try {
+ reader.ready();
+ fail("Should throw IOException");
+ } catch (IOException e) {
+ }
+ reader.close();
+ }
+
+ 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());
+ }
+ }
+
+ 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());
+ }
+ }
+
+ /**
+ * Test for regression of a bug that dropped characters when
+ * multibyte encodings spanned buffer boundaries.
+ */
+ public void test_readWhenCharacterSpansBuffer() {
+ final byte[] suffix = {
+ (byte) 0x93, (byte) 0xa1, (byte) 0x8c, (byte) 0xb4,
+ (byte) 0x97, (byte) 0x43, (byte) 0x88, (byte) 0xea,
+ (byte) 0x98, (byte) 0x59
+ };
+ final char[] decodedSuffix = {
+ (char) 0x85e4, (char) 0x539f, (char) 0x4f51, (char) 0x4e00,
+ (char) 0x90ce
+ };
+ final int prefixLength = 8189;
+
+ byte[] bytes = new byte[prefixLength + 10];
+ Arrays.fill(bytes, (byte) ' ');
+ System.arraycopy(suffix, 0, bytes, prefixLength, suffix.length);
+ ByteArrayInputStream is = new ByteArrayInputStream(bytes);
+
+ try {
+ InputStreamReader isr = new InputStreamReader(is, "SHIFT_JIS");
+ char[] chars = new char[8192];
+ int at = 0;
+
+ for (;;) {
+ int amt = isr.read(chars);
+ if (amt <= 0) {
+ break;
+ }
+
+ for (int i = 0; i < amt; i++) {
+ char c = chars[i];
+ if (at < prefixLength) {
+ if (c != ' ') {
+ fail("Found bad prefix character " +
+ (int) c + " at " + at);
+ }
+ } else {
+ char decoded = decodedSuffix[at - prefixLength];
+ if (c != decoded) {
+ fail("Found mismatched character " +
+ (int) c + " at " + at);
+ }
+ }
+ at++;
+ }
+ }
+ } catch (IOException ex) {
+ throw new RuntimeException("unexpected exception", ex);
+ }
+ }
+}
diff --git a/luni/src/test/java/tests/api/java/io/InputStreamTest.java b/luni/src/test/java/libcore/java/io/OldInputStreamTest.java
similarity index 67%
rename from luni/src/test/java/tests/api/java/io/InputStreamTest.java
rename to luni/src/test/java/libcore/java/io/OldInputStreamTest.java
index d1f531c..04ec124 100644
--- a/luni/src/test/java/tests/api/java/io/InputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/OldInputStreamTest.java
@@ -15,19 +15,12 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.InputStream;
import java.io.IOException;
-import java.io.ObjectInput;
+import java.io.InputStream;
-@TestTargetClass(InputStream.class)
-public class InputStreamTest extends junit.framework.TestCase {
+public class OldInputStreamTest extends junit.framework.TestCase {
public static final String testString = "Lorem ipsum dolor sit amet,\n" +
"consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut" +
@@ -56,15 +49,6 @@
}
}
- /**
- * @tests java.io.InputStream#InputStream()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies constructor InputStream(). Since this constructor does nothing, this test is intentionally kept basic.",
- method = "InputStream",
- args = {}
- )
public void test_Constructor() {
try {
InputStream myIS = new MockInputStream();
@@ -74,28 +58,10 @@
}
}
- /**
- * @tests java.io.InputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that available() returns 0.",
- method = "available",
- args = {}
- )
public void test_available() throws IOException {
assertEquals(is.available(), 0);
}
- /**
- * @tests java.io.InputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies close(). Since this method does nothing, this test is intentionally kept basic.",
- method = "close",
- args = {}
- )
public void test_close() {
try {
is.close();
@@ -104,15 +70,6 @@
}
}
- /**
- * @tests java.io.InputStream#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies mark(int). Since this method does nothing, this test is intentionally kept basic.",
- method = "mark",
- args = {int.class}
- )
public void test_markI() {
try {
is.mark(10);
@@ -121,42 +78,11 @@
}
}
- /**
- * @tests java.io.InputStream#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that markSupported() returns false.",
- method = "markSupported",
- args = {}
- )
public void test_markSupported() throws IOException {
assertFalse("markSupported() has returned the wrong default value.",
is.markSupported());
}
- /**
- * @tests java.io.InputStream#read(byte[])
- */
- @TestTargets (
- { @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies read(byte[]).",
- method = "read",
- args = {byte[].class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies ObjectInput.read(byte[]) since " +
- "ObjectInputStream inherits the implementation " +
- "of read(byte[]) from InputStream.",
- clazz = ObjectInput.class,
- method = "read",
- args = {byte[].class}
- )
- }
-
- )
public void test_read$B() throws IOException {
byte[] b = new byte[10];
byte[] ref = testString.getBytes();
@@ -191,15 +117,6 @@
assertEquals("Test 3:", bytesRead, -1);
}
- /**
- * @tests java.io.InputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Verifies argument checking of read(byte[], int, int).",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII_Exception() throws IOException {
byte[] b = new byte[10];
int bytesRead = 0;
@@ -246,15 +163,6 @@
assertEquals("Test 5:", bytesRead, 0);
}
- /**
- * @tests java.io.InputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies read(byte[], int, int).",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII() throws IOException {
byte[] b = new byte[10];
byte[] ref = testString.getBytes();
@@ -302,15 +210,6 @@
assertEquals("Test 4:", is.read(b, 0, 2), -1);
}
- /**
- * @tests java.io.InputStream#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that reset() throws an IOException.",
- method = "reset",
- args = {}
- )
public void test_reset() {
try {
is.reset();
@@ -320,27 +219,6 @@
}
}
- /**
- * @tests java.io.InputStream#skip(long)
- */
- @TestTargets (
- { @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies skip(long).",
- method = "skip",
- args = {long.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies ObjectInput.skip(long) since " +
- "ObjectInputStream inherits the implementation " +
- "of skip(long) from InputStream.",
- clazz = ObjectInput.class,
- method = "skip",
- args = {long.class}
- )
- }
- )
public void test_skipL() throws IOException {
byte[] b = new byte[12];
byte[] ref = testString.getBytes();
@@ -381,18 +259,10 @@
assertEquals("Test 5:", is.skip(10), 0);
}
- /**
- * This method is called before a test is executed. It creates a
- * MockInputStream instance.
- */
protected void setUp() {
is = new MockInputStream();
}
- /**
- * This method is called after a test is executed. It closes the
- * MockInputStream instance.
- */
protected void tearDown() {
try {
is.close();
diff --git a/luni/src/test/java/tests/api/java/io/LineNumberInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldLineNumberInputStreamTest.java
similarity index 67%
rename from luni/src/test/java/tests/api/java/io/LineNumberInputStreamTest.java
rename to luni/src/test/java/libcore/java/io/OldLineNumberInputStreamTest.java
index 119df10..1f5544b 100644
--- a/luni/src/test/java/tests/api/java/io/LineNumberInputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/OldLineNumberInputStreamTest.java
@@ -14,31 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.LineNumberInputStream;
+import junit.framework.TestCase;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@SuppressWarnings("deprecation")
-@TestTargetClass(
- value = LineNumberInputStream.class,
- untestedMethods = {
- @TestTargetNew(
- method = "LineNumberInputStream",
- args = {java.io.InputStream.class},
- level = TestLevel.NOT_NECESSARY,
- notes = "Simply calls super(in). If this fails, " +
- "none of the other tests would work."
- )
- }
-)
-public class LineNumberInputStreamTest extends junit.framework.TestCase {
+public class OldLineNumberInputStreamTest extends TestCase {
final 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\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";
@@ -48,14 +32,6 @@
LineNumberInputStream lnis2;
- /**
- * @tests java.io.LineNumberInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "available",
- args = {}
- )
public void test_available() throws IOException {
assertEquals("Test 1: Returned incorrect number of available bytes;",
text.length() / 2, lnis.available());
@@ -69,62 +45,6 @@
}
}
- /**
- * @tests java.io.LineNumberInputStream#getLineNumber()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLineNumber",
- args = {}
- )
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "mark",
- args = {int.class}
- )
- 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()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
public void test_read() throws IOException {
assertEquals("Test 1: Failed to read correct byte;",
'0', lnis.read());
@@ -148,14 +68,6 @@
}
}
- /**
- * @tests java.io.LineNumberInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII() throws IOException {
byte[] buf = new byte[100];
lnis.read(buf, 0, 100);
@@ -171,14 +83,6 @@
}
}
- /**
- * @tests java.io.LineNumberInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII_Exception() throws IOException {
byte[] buf = new byte[10];
@@ -204,15 +108,6 @@
}
}
- /**
- * @tests java.io.LineNumberInputStream#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException checking missed.",
- method = "reset",
- args = {}
- )
public void test_reset() throws IOException {
lnis.mark(40);
lnis.skip(4);
@@ -240,15 +135,6 @@
}
}
- /**
- * @tests java.io.LineNumberInputStream#setLineNumber(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setLineNumber",
- args = {int.class}
- )
public void test_setLineNumberI() {
lnis.setLineNumber(42);
assertEquals("Test 1: Failed to set line number;",
@@ -260,14 +146,6 @@
89, lnis.getLineNumber());
}
- /**
- * @tests java.io.LineNumberInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- )
public void test_skipJ() throws IOException {
long skipped = lnis.skip(4);
assertEquals("Test 1: Incorrect number of characters skipped;",
@@ -298,11 +176,4 @@
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() {
- }
}
diff --git a/luni/src/test/java/libcore/java/io/OldLineNumberReaderTest.java b/luni/src/test/java/libcore/java/io/OldLineNumberReaderTest.java
new file mode 100644
index 0000000..7e27698
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldLineNumberReaderTest.java
@@ -0,0 +1,186 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.StringReader;
+import junit.framework.TestCase;
+
+public class OldLineNumberReaderTest 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\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\n";
+
+ LineNumberReader lnr;
+
+ public void test_markI() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+ String line;
+ lnr.skip(80);
+ lnr.mark(100);
+ line = lnr.readLine();
+ lnr.reset();
+ assertTrue("Test 1: Failed to return to marked position.",
+ line.equals(lnr.readLine()));
+
+ lnr.close();
+ try {
+ lnr.mark(42);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ // The spec does not say the mark has to be invalidated
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#read()
+ */
+ public void test_read() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+
+ int c = lnr.read();
+ assertEquals("Test 1: Read returned incorrect character;",
+ '0', c);
+ lnr.read();
+ assertEquals("Test 2: Read failed to increase the line number;",
+ 1, lnr.getLineNumber());
+
+ lnr.close();
+ try {
+ lnr.read();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#read(char[], int, int)
+ */
+ public void test_read$CII() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+ char[] c = new char[100];
+ lnr.read(c, 0, 4);
+ assertTrue("Test 1: Read returned incorrect characters.", "0\n1\n"
+ .equals(new String(c, 0, 4)));
+ assertEquals("Test 2: Read failed to inc lineNumber",
+ 2, lnr.getLineNumber());
+
+ lnr.close();
+ try {
+ lnr.read(c, 0, 4);
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read$CII_Exception() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+ char[] c = new char[10];
+
+ try {
+ lnr.read(c, -1, 1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ lnr.read(c, 0, -1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ lnr.read(c, 10, 1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void test_readLine() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+ assertEquals("Returned incorrect line number", 0, lnr.getLineNumber());
+ String line = null;
+ lnr.readLine();
+ line = lnr.readLine();
+ assertEquals("Test 1: Returned incorrect string;", "1", line);
+ assertTrue("Test 2: Returned incorrect line number:" + lnr.getLineNumber(),
+ lnr.getLineNumber() == 2);
+
+ lnr.close();
+ try {
+ lnr.readLine();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_reset() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+ assertEquals("Test 1: Returned incorrect line number;",
+ 0, lnr.getLineNumber());
+ String line = null;
+ lnr.mark(100);
+ lnr.readLine();
+ lnr.reset();
+ line = lnr.readLine();
+ assertEquals("Test 2: Failed to reset reader", "0", line);
+
+ lnr.mark(100);
+ lnr.close();
+ try {
+ lnr.reset();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_skipJ() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+ char[] c = new char[100];
+ long skipped = lnr.skip(80);
+ assertEquals("Test 1: Incorrect number of characters skipped;",
+ 80, skipped);
+ lnr.read(c, 0, 100);
+ assertTrue("Test 2: Failed to skip to correct position.",
+ text.substring(80, 180).equals(new String(c, 0, c.length)));
+
+ try {
+ lnr.skip(-1);
+ fail("Test 3: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ lnr.close();
+ try {
+ lnr.skip(1);
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldObjectInputOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldObjectInputOutputStreamTest.java
new file mode 100644
index 0000000..cb3e92f
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldObjectInputOutputStreamTest.java
@@ -0,0 +1,272 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import tests.support.Support_OutputStream;
+
+public class OldObjectInputOutputStreamTest extends junit.framework.TestCase {
+
+ private ObjectOutputStream os;
+
+ private ObjectInputStream is;
+
+ private Support_OutputStream sos;
+
+ String unihw = "\u0048\u0065\u006C\u006C\u006F\u0020\u0057\u006F\u0072\u006C\u0064";
+
+ public void test_read_writeBoolean() throws IOException {
+ os.writeBoolean(true);
+
+ os.close();
+ openObjectInputStream();
+ assertTrue("Test 1: Incorrect boolean written or read.",
+ is.readBoolean());
+
+ try {
+ is.readBoolean();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readBoolean();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeByte() throws IOException {
+ os.writeByte((byte) 127);
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect byte written or read;",
+ (byte) 127, is.readByte());
+
+ try {
+ is.readByte();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readByte();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeChar() throws IOException {
+ os.writeChar('b');
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect char written or read;",
+ 'b', is.readChar());
+
+ try {
+ is.readChar();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readChar();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeDouble() throws IOException {
+ os.writeDouble(2345.76834720202);
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect double written or read;",
+ 2345.76834720202, is.readDouble());
+
+ try {
+ is.readDouble();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readDouble();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeFloat() throws IOException {
+ os.writeFloat(29.08764f);
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect float written or read;",
+ 29.08764f, is.readFloat());
+
+ try {
+ is.readFloat();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readFloat();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeInt() throws IOException {
+ os.writeInt(768347202);
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect int written or read;",
+ 768347202, is.readInt());
+
+ try {
+ is.readInt();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readInt();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeLong() throws IOException {
+ os.writeLong(9875645283333L);
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect long written or read;",
+ 9875645283333L, is.readLong());
+
+ try {
+ is.readLong();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readLong();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeShort() throws IOException {
+ os.writeShort(9875);
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect short written or read;",
+ 9875, is.readShort());
+
+ try {
+ is.readShort();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readShort();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeUTF() throws IOException {
+ os.writeUTF(unihw);
+
+ os.close();
+ openObjectInputStream();
+ assertTrue("Test 1: Incorrect UTF-8 string written or read.",
+ is.readUTF().equals(unihw));
+
+ try {
+ is.readUTF();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readUTF();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ private void openObjectInputStream() throws IOException {
+ is = new ObjectInputStream(
+ new ByteArrayInputStream(sos.toByteArray()));
+ }
+
+ protected void setUp() throws IOException {
+ sos = new Support_OutputStream(256);
+ os = new ObjectOutputStream(sos);
+ }
+
+ protected void tearDown() {
+ try {
+ os.close();
+ } catch (Exception e) {
+ }
+ try {
+ is.close();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectInputStreamGetFieldTest.java b/luni/src/test/java/libcore/java/io/OldObjectInputStreamGetFieldTest.java
similarity index 66%
rename from luni/src/test/java/tests/api/java/io/ObjectInputStreamGetFieldTest.java
rename to luni/src/test/java/libcore/java/io/OldObjectInputStreamGetFieldTest.java
index 13d5419..696d130 100644
--- a/luni/src/test/java/tests/api/java/io/ObjectInputStreamGetFieldTest.java
+++ b/luni/src/test/java/libcore/java/io/OldObjectInputStreamGetFieldTest.java
@@ -15,15 +15,9 @@
* limitations under the License.
*/
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
+package libcore.java.io;
import java.io.ObjectInputStream;
-
import tests.support.Support_GetPutFields;
import tests.support.Support_GetPutFieldsDefaulted;
@@ -58,8 +52,7 @@
* resource stored at {@code tests/api/java/io}.
* </p>
*/
-@TestTargetClass(ObjectInputStream.GetField.class)
-public class ObjectInputStreamGetFieldTest extends junit.framework.TestCase {
+public class OldObjectInputStreamGetFieldTest extends junit.framework.TestCase {
private ObjectInputStream ois = null;
@@ -73,65 +66,7 @@
public char charValue;
public int intValue;
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, byte.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, char.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, double.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, float.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, long.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, java.lang.Object.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, short.class}
- )
- })
public void test_get() throws Exception {
-
initOis(FILENAME);
Support_GetPutFields object = (Support_GetPutFields) ois.readObject();
Support_GetPutFields newObject = new Support_GetPutFields();
@@ -159,15 +94,7 @@
// NullPointerException is thrown.
}
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies defaulted(String).",
- method = "defaulted",
- args = {java.lang.String.class}
- )
public void test_defaultedLjava_lang_String() throws Exception {
-
initOis(FILENAME);
Support_GetPutFields object = (Support_GetPutFields) ois.readObject();
ObjectInputStream.GetField fields = object.getField;
@@ -191,65 +118,7 @@
}
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, byte.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, char.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, double.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, float.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, long.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, java.lang.Object.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, short.class}
- )
- })
public void test_getException() throws Exception {
-
initOis(FILENAME);
Support_GetPutFields object = (Support_GetPutFields) ois.readObject();
ObjectInputStream.GetField fields = object.getField;
@@ -365,22 +234,13 @@
} catch (IllegalArgumentException e) {}
}
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that getObjectStreamClass() does not return null.",
- method = "getObjectStreamClass",
- args = {}
- )
public void test_getObjectStreamClass() throws Exception {
-
initOis(FILENAME);
Support_GetPutFields object = (Support_GetPutFields) ois.readObject();
assertNotNull("Return value of getObjectStreamClass() should not be null.",
object.getField.getObjectStreamClass());
}
-
private void initOis(String fileName) throws Exception {
if (ois != null) {
ois.close();
@@ -390,7 +250,6 @@
}
protected void tearDown() throws Exception {
-
if (ois != null) {
ois.close();
}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectOutputStreamPutFieldTest.java b/luni/src/test/java/libcore/java/io/OldObjectOutputStreamPutFieldTest.java
similarity index 66%
rename from luni/src/test/java/tests/api/java/io/ObjectOutputStreamPutFieldTest.java
rename to luni/src/test/java/libcore/java/io/OldObjectOutputStreamPutFieldTest.java
index ff264bc..59008ab 100644
--- a/luni/src/test/java/tests/api/java/io/ObjectOutputStreamPutFieldTest.java
+++ b/luni/src/test/java/libcore/java/io/OldObjectOutputStreamPutFieldTest.java
@@ -15,19 +15,13 @@
* limitations under the License.
*/
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
+package libcore.java.io;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
-import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.util.Arrays;
-
+import junit.framework.TestCase;
import tests.support.Support_GetPutFields;
import tests.support.Support_GetPutFieldsDeprecated;
@@ -66,70 +60,13 @@
* called by the test methods.
* </p>
*/
-@TestTargetClass(ObjectOutputStream.PutField.class)
-public class ObjectOutputStreamPutFieldTest extends junit.framework.TestCase {
+public class OldObjectOutputStreamPutFieldTest extends TestCase {
private final String FILENAME =
"/tests/api/java/io/testFields.ser";
private final String DEPRECATED_FILENAME =
"/tests/api/java/io/testFieldsDeprecated.ser";
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, byte.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, char.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, double.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, float.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, long.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, java.lang.Object.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, short.class}
- )
- })
public void test_put() throws Exception {
Support_GetPutFields toSerialize = new Support_GetPutFields();
byte[] content;
@@ -155,12 +92,6 @@
}
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies the deprecated write(ObjectOutput) method.",
- method = "write",
- args = {java.io.ObjectOutput.class}
- )
public void test_writeLjava_io_ObjectOutputStream() throws Exception {
Support_GetPutFieldsDeprecated toSerialize = new Support_GetPutFieldsDeprecated();
byte[] content;
diff --git a/luni/src/test/java/libcore/java/io/OldObjectOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldObjectOutputStreamTest.java
new file mode 100644
index 0000000..cf01d9d
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldObjectOutputStreamTest.java
@@ -0,0 +1,435 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.NotActiveException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import junit.framework.TestCase;
+import tests.support.Support_ASimpleOutputStream;
+import tests.support.Support_OutputStream;
+
+public class OldObjectOutputStreamTest extends TestCase implements Serializable {
+
+ static final long serialVersionUID = 1L;
+
+ java.io.File f;
+
+ public class SerializableTestHelper implements Serializable {
+ public String aField1;
+
+ public String aField2;
+
+ SerializableTestHelper(String s, String t) {
+ aField1 = s;
+ aField2 = t;
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException {
+ // note aField2 is not read
+ try {
+ ObjectInputStream.GetField fields = ois.readFields();
+ aField1 = (String) fields.get("aField1", "Zap");
+ } catch (Exception e) {
+ }
+ }
+
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+ // note aField2 is not written
+ ObjectOutputStream.PutField fields = oos.putFields();
+ fields.put("aField1", aField1);
+ oos.writeFields();
+ }
+
+ public String getText1() {
+ return aField1;
+ }
+
+ public String getText2() {
+ return aField2;
+ }
+ }
+
+ private static class BasicObjectOutputStream extends ObjectOutputStream {
+ public boolean writeStreamHeaderCalled;
+
+ public BasicObjectOutputStream() throws IOException, SecurityException {
+ super();
+ writeStreamHeaderCalled = false;
+ }
+
+ public BasicObjectOutputStream(OutputStream output) throws IOException {
+ super(output);
+ }
+
+ public void drain() throws IOException {
+ super.drain();
+ }
+
+ public boolean enableReplaceObject(boolean enable)
+ throws SecurityException {
+ return super.enableReplaceObject(enable);
+ }
+
+ public void writeObjectOverride(Object object) throws IOException {
+ super.writeObjectOverride(object);
+ }
+
+ public void writeStreamHeader() throws IOException {
+ super.writeStreamHeader();
+ writeStreamHeaderCalled = true;
+ }
+}
+
+ private static class NoFlushTestOutputStream extends ByteArrayOutputStream {
+ public boolean flushCalled;
+
+ public NoFlushTestOutputStream() {
+ super();
+ flushCalled = false;
+ }
+
+ public void flush() throws IOException {
+ super.flush();
+ flushCalled = true;
+ }
+ }
+
+ protected static final String MODE_XLOAD = "xload";
+
+ protected static final String MODE_XDUMP = "xdump";
+
+ static final String FOO = "foo";
+
+ static final String MSG_WITE_FAILED = "Failed to write: ";
+
+ private static final boolean DEBUG = false;
+
+ protected static boolean xload = false;
+
+ protected static boolean xdump = false;
+
+ protected static String xFileName = null;
+
+ protected ObjectInputStream ois;
+
+ protected ObjectOutputStream oos;
+
+ protected ObjectOutputStream oos_ioe;
+
+ protected Support_OutputStream sos;
+
+ protected ByteArrayOutputStream bao;
+
+ static final int INIT_INT_VALUE = 7;
+
+ static final String INIT_STR_VALUE = "a string that is blortz";
+
+ /**
+ * @tests java.io.ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)
+ */
+ public void test_ConstructorLjava_io_OutputStream() throws IOException {
+ oos.close();
+ oos = new ObjectOutputStream(new ByteArrayOutputStream());
+ oos.close();
+
+ try {
+ oos = new ObjectOutputStream(null);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ Support_ASimpleOutputStream sos = new Support_ASimpleOutputStream(true);
+ try {
+ oos = new ObjectOutputStream(sos);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_close() throws IOException {
+ int outputSize = bao.size();
+ // Writing of a primitive type should be buffered.
+ oos.writeInt(42);
+ assertTrue("Test 1: Primitive data unexpectedly written to the target stream.",
+ bao.size() == outputSize);
+ // Closing should write the buffered data to the target stream.
+ oos.close();
+ assertTrue("Test 2: Primitive data has not been written to the the target stream.",
+ bao.size() > outputSize);
+
+ try {
+ oos_ioe.close();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_drain() throws IOException {
+ NoFlushTestOutputStream target = new NoFlushTestOutputStream();
+ BasicObjectOutputStream boos = new BasicObjectOutputStream(target);
+ int initialSize = target.size();
+ boolean written = false;
+
+ boos.writeBytes("Lorem ipsum");
+ // If there is no buffer then the bytes have already been written.
+ written = (target.size() > initialSize);
+
+ boos.drain();
+ assertTrue("Content has not been written to the target.",
+ written || (target.size() > initialSize));
+ assertFalse("flush() has been called on the target.",
+ target.flushCalled);
+ }
+
+ public void test_enableReplaceObjectB() throws IOException {
+ // Start testing without a SecurityManager.
+ BasicObjectOutputStream boos = new BasicObjectOutputStream();
+ assertFalse("Test 1: Object resolving must be disabled by default.",
+ boos.enableReplaceObject(true));
+
+ assertTrue("Test 2: enableReplaceObject did not return the previous value.",
+ boos.enableReplaceObject(false));
+ }
+
+ public void test_flush() throws Exception {
+ // Test for method void java.io.ObjectOutputStream.flush()
+ int size = bao.size();
+ oos.writeByte(127);
+ assertTrue("Test 1: Data already flushed.", bao.size() == size);
+ oos.flush();
+ assertTrue("Test 2: Failed to flush data.", bao.size() > size);
+
+ try {
+ oos_ioe.flush();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_putFields() throws Exception {
+ /*
+ * "SerializableTestHelper" is an object created for these tests with
+ * two fields (Strings) and simple implementations of readObject and
+ * writeObject which simply read and write the first field but not the
+ * second one.
+ */
+ SerializableTestHelper sth;
+
+ try {
+ oos.putFields();
+ fail("Test 1: NotActiveException expected.");
+ } catch (NotActiveException e) {
+ // Expected.
+ }
+
+ oos.writeObject(new SerializableTestHelper("Gabba", "Jabba"));
+ oos.flush();
+ ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+ sth = (SerializableTestHelper) (ois.readObject());
+ assertEquals("Test 2: readFields or writeFields failed; first field not set.",
+ "Gabba", sth.getText1());
+ assertNull("Test 3: readFields or writeFields failed; second field should not have been set.",
+ sth.getText2());
+ }
+
+ public void test_reset() throws Exception {
+ String o = "HelloWorld";
+ sos = new Support_OutputStream(200);
+ oos.close();
+ oos = new ObjectOutputStream(sos);
+ oos.writeObject(o);
+ oos.writeObject(o);
+ oos.reset();
+ oos.writeObject(o);
+
+ sos.setThrowsException(true);
+ try {
+ oos.reset();
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sos.setThrowsException(false);
+
+ ois = new ObjectInputStream(new ByteArrayInputStream(sos.toByteArray()));
+ assertEquals("Test 2: Incorrect object read.", o, ois.readObject());
+ assertEquals("Test 3: Incorrect object read.", o, ois.readObject());
+ assertEquals("Test 4: Incorrect object read.", o, ois.readObject());
+ ois.close();
+ }
+
+ public void test_write$BII() throws Exception {
+ byte[] buf = new byte[10];
+ ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+ try {
+ ois.read(buf, 0, -1);
+ fail("IndexOutOfBoundsException not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ ois.read(buf, -1, 1);
+ fail("IndexOutOfBoundsException not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ ois.read(buf, 10, 1);
+ fail("IndexOutOfBoundsException not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ ois.close();
+
+ }
+
+ public void test_writeObjectOverrideLjava_lang_Object() throws IOException {
+ BasicObjectOutputStream boos =
+ new BasicObjectOutputStream(new ByteArrayOutputStream());
+
+ try {
+ boos.writeObjectOverride(new Object());
+ fail("IOException expected.");
+ }
+ catch (IOException e) {
+ }
+ finally {
+ boos.close();
+ }
+ }
+
+ public void test_writeStreamHeader() throws IOException {
+ BasicObjectOutputStream boos;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ short s;
+ byte[] buffer;
+
+ // Test 1: Make sure that writeStreamHeader() has been called.
+ boos = new BasicObjectOutputStream(baos);
+ try {
+ assertTrue("Test 1: writeStreamHeader() has not been called.",
+ boos.writeStreamHeaderCalled);
+
+ // Test 2: Check that at least four bytes have been written.
+ buffer = baos.toByteArray();
+ assertTrue("Test 2: At least four bytes should have been written",
+ buffer.length >= 4);
+
+ // Test 3: Check the magic number.
+ s = buffer[0];
+ s <<= 8;
+ s += ((short) buffer[1] & 0x00ff);
+ assertEquals("Test 3: Invalid magic number written.",
+ java.io.ObjectStreamConstants.STREAM_MAGIC, s);
+
+ // Test 4: Check the stream version number.
+ s = buffer[2];
+ s <<= 8;
+ s += ((short) buffer[3] & 0x00ff);
+ assertEquals("Invalid stream version number written.",
+ java.io.ObjectStreamConstants.STREAM_VERSION, s);
+ }
+ finally {
+ boos.close();
+ }
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
+ oos_ioe = new ObjectOutputStream(sos = new Support_OutputStream());
+ sos.setThrowsException(true);
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (oos != null) {
+ try {
+ oos.close();
+ } catch (Exception e) {}
+ }
+ if (oos_ioe != null) {
+ try {
+ oos_ioe.close();
+ } catch (Exception e) {}
+ }
+ if (f != null && f.exists()) {
+ if (!f.delete()) {
+ fail("Error cleaning up files during teardown");
+ }
+ }
+ }
+
+ protected Object reload() throws IOException, ClassNotFoundException {
+
+ // Choose the load stream
+ if (xload || xdump) {
+ // Load from pre-existing file
+ ois = new ObjectInputStream(new FileInputStream(xFileName + "-"
+ + getName() + ".ser"));
+ } else {
+ // Just load from memory, we dumped to memory
+ ois = new ObjectInputStream(new ByteArrayInputStream(bao
+ .toByteArray()));
+ }
+
+ try {
+ return ois.readObject();
+ } finally {
+ ois.close();
+ }
+ }
+
+ protected void dump(Object o) throws IOException, ClassNotFoundException {
+
+ // Choose the dump stream
+ if (xdump) {
+ oos = new ObjectOutputStream(new FileOutputStream(
+ f = new java.io.File(xFileName + "-" + getName() + ".ser")));
+ } else {
+ oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
+ }
+
+ // Dump the object
+ try {
+ oos.writeObject(o);
+ } finally {
+ oos.close();
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldObjectStreamFieldTest.java b/luni/src/test/java/libcore/java/io/OldObjectStreamFieldTest.java
new file mode 100644
index 0000000..ee09221
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldObjectStreamFieldTest.java
@@ -0,0 +1,179 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.ObjectStreamClass;
+import java.io.ObjectStreamField;
+import java.io.Serializable;
+
+public class OldObjectStreamFieldTest extends junit.framework.TestCase {
+
+ static class DummyClass implements Serializable {
+ private static final long serialVersionUID = 999999999999998L;
+
+ boolean bField = true;
+ char cField = 'c';
+ double dField = 424242.4242;
+ float fField = 24.12F;
+ int iField = 1965;
+ long lField = 9999999L;
+ short sField = 42;
+
+ long bam = 999L;
+
+ int ham = 9999;
+
+ int sam = 8888;
+
+ Object hola = new Object();
+
+ public static long getUID() {
+ return serialVersionUID;
+ }
+ }
+
+ class MyObjectStreamField extends ObjectStreamField {
+ public MyObjectStreamField(String name, Class<?> cl) {
+ super(name, cl);
+ }
+
+ public void setOffset(int newValue) {
+ super.setOffset(newValue);
+ }
+ }
+
+ ObjectStreamClass osc;
+
+ ObjectStreamField hamField;
+
+ ObjectStreamField samField;
+
+ ObjectStreamField bamField;
+
+ ObjectStreamField holaField;
+
+ public void test_ConstructorLjava_lang_StringLjava_lang_Class() {
+ ObjectStreamField osf = new ObjectStreamField("aField", int.class);
+ assertTrue("Test 1: Name member not set correctly.",
+ osf.getName().equals("aField"));
+ assertTrue("Test 2: Type member not set correctly.",
+ osf.getType().equals(int.class));
+
+ // Repeat the tests with a different object to make sure
+ // that we have not tested against default values.
+ osf = new ObjectStreamField("anotherField", String.class);
+ assertTrue("Test 3: Name member not set correctly.",
+ osf.getName().equals("anotherField"));
+ assertTrue("Test 4: Type member not set correctly.",
+ osf.getType().equals(String.class));
+
+ // Invalid argument tests.
+ try {
+ osf = new ObjectStreamField(null, boolean.class);
+ fail("Test 5: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ try {
+ osf = new ObjectStreamField("thisField", null);
+ fail("Test 6: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ConstructorLjava_lang_StringLjava_lang_ClassB() {
+ ObjectStreamField osf = new ObjectStreamField("aField", int.class, false);
+ assertTrue("Test 1: Name member not set correctly.",
+ osf.getName().equals("aField"));
+ assertTrue("Test 2: Type member not set correctly.",
+ osf.getType().equals(int.class));
+ assertFalse("Test 3: Unshared member not set correctly.",
+ osf.isUnshared());
+
+ // Repeat the tests with a different object to make sure
+ // that we have not tested against default values.
+ osf = new ObjectStreamField("anotherField", String.class, true);
+ assertTrue("Test 4: Name member not set correctly.",
+ osf.getName().equals("anotherField"));
+ assertTrue("Test 5: Type member not set correctly.",
+ osf.getType().equals(String.class));
+ assertTrue("Test 6: Unshared member not set correctly.",
+ osf.isUnshared());
+
+ // Invalid argument tests.
+ try {
+ osf = new ObjectStreamField(null, boolean.class);
+ fail("Test 7: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ try {
+ osf = new ObjectStreamField("thisField", null);
+ fail("Test 8: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ }
+
+
+ public void test_getOffset() {
+ ObjectStreamField[] osfArray;
+ osfArray = osc.getFields();
+ int[] expectedOffsets = {0, 1, 9, 11, 19, 23, 27, 31, 39, 41, 0};
+
+ assertTrue("getOffset() did not return reasonable values.", osfArray[0]
+ .getOffset() != osfArray[1].getOffset());
+
+ for (int i = 0; i < expectedOffsets.length; i++) {
+ assertEquals(String.format("Unexpected value for osfArray[%d].getOffset(): ", i),
+ expectedOffsets[i], osfArray[i].getOffset());
+
+ }
+ }
+
+ public void test_setOffsetI() {
+ MyObjectStreamField f = new MyObjectStreamField("aField", int.class);
+ f.setOffset(42);
+ assertEquals("Test 1: Unexpected offset value.", 42, f.getOffset());
+ f.setOffset(2008);
+ assertEquals("Test 2: Unexpected offset value.", 2008, f.getOffset());
+ }
+
+ public void test_isPrimitive() {
+ // Test for method int java.io.ObjectStreamField.getOffset()
+ ObjectStreamField[] osfArray;
+ osfArray = osc.getFields();
+
+ for (int i = 0; i < (osfArray.length - 1); i++) {
+ assertTrue(String.format("osfArray[%d].isPrimitive() should return true.", i),
+ osfArray[i].isPrimitive());
+ }
+ assertFalse(String.format("osfArray[%d].isPrimitive() should return false.",
+ osfArray.length - 1),
+ osfArray[(osfArray.length - 1)].isPrimitive());
+ }
+
+ protected void setUp() {
+ osc = ObjectStreamClass.lookup(DummyClass.class);
+ bamField = osc.getField("bam");
+ samField = osc.getField("sam");
+ hamField = osc.getField("ham");
+ holaField = osc.getField("hola");
+ }
+}
diff --git a/luni/src/test/java/tests/api/java/io/OutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldOutputStreamTest.java
similarity index 72%
rename from luni/src/test/java/tests/api/java/io/OutputStreamTest.java
rename to luni/src/test/java/libcore/java/io/OldOutputStreamTest.java
index 7acd737..585612b 100644
--- a/luni/src/test/java/tests/api/java/io/OutputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/OldOutputStreamTest.java
@@ -15,43 +15,12 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.OutputStream;
import java.io.IOException;
+import java.io.OutputStream;
-@TestTargetClass(
- value = OutputStream.class,
- untestedMethods = {
- @TestTargetNew(
- method = "OutputStream",
- args = {},
- level = TestLevel.NOT_NECESSARY,
- notes = "Constructor just calls super()."
- ),
- @TestTargetNew(
- method = "close",
- args = {},
- level = TestLevel.NOT_NECESSARY,
- notes = "According to specification, the implementation " +
- "does nothing."
- ),
- @TestTargetNew(
- method = "flush",
- args = {},
- level = TestLevel.NOT_NECESSARY,
- notes = "According to specification, the implementation " +
- "does nothing."
- )
- }
-)
-public class OutputStreamTest extends junit.framework.TestCase {
+public class OldOutputStreamTest extends junit.framework.TestCase {
class BasicOutputStream extends OutputStream {
@@ -81,12 +50,6 @@
private final byte[] shortByteArray = "Lorem ipsum...".getBytes();
private final byte[] longByteArray = "Lorem ipsum dolor sit amet...".getBytes();
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(byte[]).",
- method = "write",
- args = {byte[].class}
- )
public void test_write$B() {
BasicOutputStream bos = new BasicOutputStream();
boolean expected;
@@ -112,12 +75,6 @@
} catch (IOException e) {}
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(byte[], int, int).",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
public void test_write$BII() {
BasicOutputStream bos = new BasicOutputStream();
boolean expected;
diff --git a/luni/src/test/java/tests/api/java/io/OutputStreamWriterTest.java b/luni/src/test/java/libcore/java/io/OldOutputStreamWriterTest.java
similarity index 69%
rename from luni/src/test/java/tests/api/java/io/OutputStreamWriterTest.java
rename to luni/src/test/java/libcore/java/io/OldOutputStreamWriterTest.java
index fe6e3f2..dc51553 100644
--- a/luni/src/test/java/tests/api/java/io/OutputStreamWriterTest.java
+++ b/luni/src/test/java/libcore/java/io/OldOutputStreamWriterTest.java
@@ -15,12 +15,7 @@
* limitations under the License.
*/
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
+package libcore.java.io;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -30,44 +25,24 @@
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
-
+import junit.framework.TestCase;
import tests.support.Support_OutputStream;
-import junit.framework.TestCase;
-
-/**
- *
- */
-@TestTargetClass(OutputStreamWriter.class)
-public class OutputStreamWriterTest extends TestCase {
-
- private static final int UPPER = 0xd800;
-
- private static final int BUFFER_SIZE = 10000;
-
- static private final String[] MINIMAL_CHARSETS = new String[] { "US-ASCII",
- "ISO-8859-1", "UTF-16BE", "UTF-16LE", "UTF-16", "UTF-8" };
+public class OldOutputStreamWriterTest extends TestCase {
OutputStreamWriter osw;
-
InputStreamReader isr;
private Support_OutputStream fos;
public String testString = "This is a test message with Unicode characters. \u4e2d\u56fd is China's name in Chinese";
- /*
- * @see TestCase#setUp()
- */
protected void setUp() throws Exception {
super.setUp();
fos = new Support_OutputStream(500);
osw = new OutputStreamWriter(fos, "UTF-8");
}
- /*
- * @see TestCase#tearDown()
- */
protected void tearDown() throws Exception {
try {
if (isr != null) isr.close();
@@ -78,15 +53,6 @@
super.tearDown();
}
- /**
- * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "OutputStreamWriter",
- args = {java.io.OutputStream.class}
- )
public void test_ConstructorLjava_io_OutputStream() throws IOException {
OutputStreamWriter writer = null;
@@ -111,16 +77,6 @@
if (writer != null) writer.close();
}
- /**
- * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream,
- * java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "OutputStreamWriter",
- args = {java.io.OutputStream.class, java.lang.String.class}
- )
public void test_ConstructorLjava_io_OutputStreamLjava_lang_String()
throws UnsupportedEncodingException {
@@ -159,20 +115,10 @@
}
assertEquals("Test 6: Encoding not set correctly. ",
- Charset.forName("8859_1"),
- Charset.forName(osw.getEncoding()));
+ Charset.forName("8859_1"),
+ Charset.forName(osw.getEncoding()));
}
- /**
- * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream,
- * java.nio.charset.Charset)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "OutputStreamWriter",
- args = {java.io.OutputStream.class, java.nio.charset.Charset.class}
- )
public void test_ConstructorLjava_io_OutputStreamLjava_nio_charset_Charset()
throws IOException {
OutputStreamWriter writer;
@@ -199,16 +145,6 @@
writer.close();
}
- /**
- * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream,
- * java.nio.charset.CharsetEncoder)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "OutputStreamWriter",
- args = {java.io.OutputStream.class, java.nio.charset.CharsetEncoder.class}
- )
public void test_ConstructorLjava_io_OutputStreamLjava_nio_charset_CharsetEncoder()
throws IOException {
OutputStreamWriter writer;
@@ -236,15 +172,6 @@
writer.close();
}
- /**
- * @tests java.io.OutputStreamWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "An issue in the API code has been identified (ticket #87). This test must be updated when the ticket is closed.",
- method = "close",
- args = {}
- )
public void test_close() {
fos.setThrowsException(true);
@@ -315,15 +242,6 @@
}
}
- /**
- * @tests java.io.OutputStreamWriter#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "flush",
- args = {}
- )
public void test_flush() {
// Test for method void java.io.OutputStreamWriter.flush()
try {
@@ -348,197 +266,26 @@
fos.setThrowsException(false);
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {},
- clazz = InputStreamReader.class
- )
- })
- public void test_singleCharIO() throws Exception {
- int upper;
- OutputStreamWriter writer = null;
- ByteArrayOutputStream out;
- InputStreamReader isr = null;
-
- for (int i = 0; i < MINIMAL_CHARSETS.length; ++i) {
- try {
- out = new ByteArrayOutputStream();
- writer = new OutputStreamWriter(out, MINIMAL_CHARSETS[i]);
-
- switch (i) {
- case 0:
- upper = 128;
- break;
- case 1:
- upper = 256;
- break;
- default:
- upper = UPPER;
- }
-
- for (int c = 0; c < upper; ++c) {
- writer.write(c);
- }
- writer.flush();
- byte[] result = out.toByteArray();
-
- isr = new InputStreamReader(new ByteArrayInputStream(result),
- MINIMAL_CHARSETS[i]);
- for (int expected = 0; expected < upper; ++expected) {
- assertEquals("Error when reading bytes in "
- + MINIMAL_CHARSETS[i], expected, isr.read());
- }
- } finally {
- try {
- if (isr != null) isr.close();
- } catch (Exception e) {
- }
- try {
- if (writer != null) writer.close();
- } catch (Exception e) {
- }
- }
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {char[].class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {},
- clazz = InputStreamReader.class
- )
- })
- public void test_write$C() throws Exception {
- int upper;
- InputStreamReader isr = null;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- OutputStreamWriter writer = null;
-
- char[] largeBuffer = new char[BUFFER_SIZE];
- for (int i = 0; i < MINIMAL_CHARSETS.length; ++i) {
- try {
- baos = new ByteArrayOutputStream();
- writer = new OutputStreamWriter(baos, MINIMAL_CHARSETS[i]);
-
- switch (i) {
- case 0:
- upper = 128;
- break;
- case 1:
- upper = 256;
- break;
- default:
- upper = UPPER;
- }
-
- int m = 0;
- for (int c = 0; c < upper; ++c) {
- largeBuffer[m++] = (char) c;
- if (m == BUFFER_SIZE) {
- writer.write(largeBuffer);
- m = 0;
- }
- }
- writer.write(largeBuffer, 0, m);
- writer.flush();
- byte[] result = baos.toByteArray();
-
- isr = new InputStreamReader(new ByteArrayInputStream(result),
- MINIMAL_CHARSETS[i]);
- int expected = 0, read = 0, j = 0;
- while (expected < upper) {
- if (j == read) {
- read = isr.read(largeBuffer);
- j = 0;
- }
- assertEquals("Error when reading bytes in "
- + MINIMAL_CHARSETS[i] + " at " + j, expected++, largeBuffer[j++]);
- }
- } finally {
- try {
- if (isr != null) isr.close();
- } catch (Exception e) {
- }
- try {
- if (writer != null) writer.close();
- } catch (Exception e) {
- }
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
public void test_write_US_ASCII() throws Exception {
testEncodeCharset("US-ASCII", 128);
}
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
public void test_write_ISO_8859_1() throws Exception {
testEncodeCharset("ISO-8859-1", 256);
}
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
public void test_write_UTF_16BE() throws Exception {
testEncodeCharset("UTF-16BE", 0xd800);
}
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
public void test_write_UTF_16LE() throws Exception {
testEncodeCharset("UTF-16LE", 0xd800);
}
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
public void test_write_UTF_16() throws Exception {
testEncodeCharset("UTF-16", 0xd800);
}
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
public void test_write_UTF_8() throws Exception {
testEncodeCharset("UTF-8", 0xd800);
}
@@ -576,15 +323,6 @@
}
}
- /**
- * @tests java.io.OutputStreamWriter#getEncoding()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getEncoding",
- args = {}
- )
public void test_getEncoding() throws IOException {
OutputStreamWriter writer;
writer = new OutputStreamWriter(new Support_OutputStream(), "utf-8");
@@ -597,15 +335,6 @@
writer.getEncoding());
}
- /**
- * @tests java.io.OutputStreamWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
public void test_write$CII() throws IOException {
char[] chars = testString.toCharArray();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -701,15 +430,6 @@
}
}
- /**
- * @tests java.io.OutputStreamWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
public void test_writeI() throws IOException {
Support_OutputStream out = new Support_OutputStream(500);
OutputStreamWriter writer;
@@ -761,15 +481,6 @@
}
}
- /**
- * @tests java.io.OutputStreamWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
public void test_writeLjava_lang_StringII() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Support_OutputStream out = new Support_OutputStream(500);
diff --git a/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldPipedOutputStreamTest.java
similarity index 79%
rename from luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java
rename to luni/src/test/java/libcore/java/io/OldPipedOutputStreamTest.java
index 6a6e28c..a82a89a 100644
--- a/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/OldPipedOutputStreamTest.java
@@ -15,19 +15,13 @@
* limitations under the License.
*/
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
+package libcore.java.io;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
-@TestTargetClass(PipedOutputStream.class)
-public class PipedOutputStreamTest extends junit.framework.TestCase {
+public class OldPipedOutputStreamTest extends junit.framework.TestCase {
static class PReader implements Runnable {
PipedInputStream reader;
@@ -88,15 +82,6 @@
PipedOutputStream out;
- /**
- * @tests java.io.PipedOutputStream#PipedOutputStream()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PipedOutputStream",
- args = {}
- )
public void test_Constructor() {
out = new PipedOutputStream();
assertNotNull(out);
@@ -107,15 +92,6 @@
}
}
- /**
- * @tests java.io.PipedOutputStream#PipedOutputStream(java.io.PipedInputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PipedOutputStream",
- args = {java.io.PipedInputStream.class}
- )
public void test_ConstructorLjava_io_PipedInputStream() throws IOException {
// Test for method java.io.PipedOutputStream(java.io.PipedInputStream)
@@ -136,15 +112,6 @@
}
}
- /**
- * @tests java.io.PipedOutputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
public void test_close() {
out = new PipedOutputStream();
rt = new Thread(reader = new PReader(out));
@@ -156,15 +123,6 @@
}
}
- /**
- * @tests java.io.PipedOutputStream#connect(java.io.PipedInputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "connect",
- args = {java.io.PipedInputStream.class}
- )
public void test_connectLjava_io_PipedInputStream() throws IOException {
out = new PipedOutputStream();
@@ -196,15 +154,6 @@
}
}
- /**
- * @tests java.io.PipedOutputStream#flush()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException checking because it is never thrown in the source code.",
- method = "flush",
- args = {}
- )
public void test_flush() throws Exception {
out = new PipedOutputStream();
rt = new Thread(reader = new PReader(out));
@@ -216,15 +165,6 @@
testString.substring(0, 10), reader.read(10));
}
- /**
- * @tests java.io.PipedOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test 6 disabled due to incomplete implementation, see ticket #92.",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
public void test_write$BII() throws IOException {
out = new PipedOutputStream();
@@ -281,15 +221,6 @@
}
- /**
- * @tests java.io.PipedOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test 3 disabled due to incomplete implementation, see ticket #92.",
- method = "write",
- args = {int.class}
- )
public void test_writeI() throws IOException {
out = new PipedOutputStream();
diff --git a/luni/src/test/java/libcore/java/io/OldPipedWriterTest.java b/luni/src/test/java/libcore/java/io/OldPipedWriterTest.java
new file mode 100644
index 0000000..b6f686e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldPipedWriterTest.java
@@ -0,0 +1,277 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.IOException;
+import java.io.PipedReader;
+import java.io.PipedWriter;
+import java.util.Arrays;
+
+public class OldPipedWriterTest extends junit.framework.TestCase {
+
+ static final String testString = "Lorem ipsum...";
+ static final int testLength = testString.length();
+
+ static class PReader implements Runnable {
+ public PipedReader pr;
+
+ public char[] buf;
+
+ public PReader(PipedWriter pw) {
+ try {
+ pr = new PipedReader(pw);
+ } catch (IOException e) {
+ System.out.println("Exception setting up reader: "
+ + e.toString());
+ }
+ }
+
+ public PReader(PipedReader pr) {
+ this.pr = pr;
+ }
+
+ public void run() {
+ try {
+ while (true) {
+ Thread.sleep(1000);
+ Thread.yield();
+ }
+ } catch (InterruptedException e) {
+ }
+ }
+
+ public String read(int nbytes) {
+ buf = new char[nbytes];
+ try {
+ pr.read(buf, 0, nbytes);
+ return new String(buf);
+ } catch (IOException e) {
+ System.out.println("Exception reading ("
+ + Thread.currentThread().getName() + "): "
+ + e.toString());
+ return "ERROR";
+ }
+ }
+ }
+
+ Thread readerThread;
+ PReader reader;
+ PipedWriter pw;
+ char[] testBuf;
+
+ public void test_Constructor() {
+ pw = new PipedWriter();
+ assertNotNull(pw);
+ try {
+ pw.close();
+ } catch (IOException e) {
+ fail("Unexpeceted IOException.");
+ }
+ }
+
+ public void test_ConstructorLjava_io_PipedReader() throws Exception {
+ PipedReader rd = new PipedReader();
+
+ try {
+ pw = new PipedWriter(rd);
+ } catch (Exception e) {
+ fail("Test 1: Construtor failed:" + e.getMessage());
+ }
+
+ readerThread = new Thread(reader = new PReader(rd), "Constructor(Reader)");
+ readerThread.start();
+ try {
+ pw.write(testBuf);
+ } catch (Exception e) {
+ fail("Test 2: Could not write to the constructed writer: "
+ + e.getMessage());
+ }
+ pw.close();
+ assertEquals("Test 3: Incorrect character string received.", testString,
+ reader.read(testLength));
+
+ rd = new PipedReader(new PipedWriter());
+ try {
+ pw = new PipedWriter(rd);
+ fail("Test 4: IOException expected because the reader is already connected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_close() throws Exception {
+ PipedReader rd = new PipedReader();
+ pw = new PipedWriter(rd);
+ reader = new PReader(rd);
+ try {
+ pw.close();
+ } catch (IOException e) {
+ fail("Test 1: Unexpected IOException: " + e.getMessage());
+ }
+ }
+
+ public void test_connectLjava_io_PipedReader() throws Exception {
+ PipedReader rd = new PipedReader();
+ pw = new PipedWriter();
+
+ try {
+ pw.connect(rd);
+ } catch (Exception e) {
+ fail("Test 1: Unexpected exception when connecting: " +
+ e.getLocalizedMessage());
+ }
+
+ readerThread = new Thread(reader = new PReader(rd), "connect");
+ readerThread.start();
+
+ try {
+ pw.write(testBuf);
+ } catch (IOException e) {
+ fail("Test 2: Unexpected IOException when writing after connecting.");
+ }
+ assertEquals("Test 3: Incorrect character string received.", testString,
+ reader.read(testLength));
+
+ try {
+ pw.connect(new PipedReader());
+ fail("Test 4: IOException expected when reconnecting the writer.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_flush() throws Exception {
+ // Test for method void java.io.PipedWriter.flush()
+ pw = new PipedWriter();
+ readerThread = new Thread(reader = new PReader(pw), "flush");
+ readerThread.start();
+ pw.write(testBuf);
+ pw.flush();
+ assertEquals("Test 1: Flush failed. ", testString,
+ reader.read(testLength));
+ }
+
+ public void test_write$CII() throws Exception {
+ pw = new PipedWriter();
+
+ try {
+ pw.write(testBuf, 0, 5);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ pw = new PipedWriter(new PipedReader());
+
+ try {
+ pw.write(testBuf, -1, 1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ pw.write(testBuf, 0, -1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ pw.write(testBuf, 5, testString.length());
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ pw.close();
+ pw = new PipedWriter();
+ try {
+ readerThread = new Thread(reader = new PReader(pw), "writeCII");
+ readerThread.start();
+ pw.write(testBuf, 0, testLength);
+ pw.close();
+ reader.read(testLength);
+ assertTrue("Test 5: Characters read do not match the characters written.",
+ Arrays.equals( testBuf, reader.buf));
+ } catch (IOException e) {
+ fail("Test 5: Unexpected IOException: " + e.getMessage());
+ }
+
+ readerThread.interrupt();
+
+ try {
+ pw.write(testBuf, 0, 5);
+ fail("Test 6: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ reader.pr.close();
+ try {
+ pw.write(testBuf, 0, 5);
+ fail("Test 7: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeI() throws Exception {
+ // Test for method void java.io.PipedWriter.write(int)
+
+ pw = new PipedWriter();
+
+ try {
+ pw.write(42);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ readerThread = new Thread(reader = new PReader(pw), "writeI");
+ readerThread.start();
+ pw.write(1);
+ pw.write(2);
+ pw.write(3);
+ pw.close();
+ reader.read(3);
+ assertTrue("Test 2: The charaacters read do not match the characters written: " +
+ (int) reader.buf[0] + " " + (int) reader.buf[1] + " " + (int) reader.buf[2],
+ reader.buf[0] == 1 && reader.buf[1] == 2 && reader.buf[2] == 3);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ testBuf = new char[testLength];
+ testString.getChars(0, testLength, testBuf, 0);
+ }
+
+ protected void tearDown() throws Exception {
+ try {
+ if (readerThread != null) {
+ readerThread.interrupt();
+ }
+ } catch (Exception ignore) {}
+ try {
+ if (pw != null) {
+ pw.close();
+ }
+ } catch (Exception ignore) {}
+ super.tearDown();
+ }
+}
diff --git a/luni/src/test/java/tests/api/java/io/PushbackInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldPushbackInputStreamTest.java
similarity index 83%
rename from luni/src/test/java/tests/api/java/io/PushbackInputStreamTest.java
rename to luni/src/test/java/libcore/java/io/OldPushbackInputStreamTest.java
index a648840..270650e 100644
--- a/luni/src/test/java/tests/api/java/io/PushbackInputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/OldPushbackInputStreamTest.java
@@ -15,34 +15,21 @@
* limitations under the License.
*/
-package tests.api.java.io;
+package libcore.java.io;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PushbackInputStream;
import tests.support.Support_ASimpleInputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-@TestTargetClass(PushbackInputStream.class)
-public class PushbackInputStreamTest extends junit.framework.TestCase {
+public class OldPushbackInputStreamTest extends junit.framework.TestCase {
Support_ASimpleInputStream underlying = new Support_ASimpleInputStream();
PushbackInputStream pis;
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_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_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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.PushbackInputStream#PushbackInputStream(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PushbackInputStream",
- args = {java.io.InputStream.class}
- )
public void test_ConstructorLjava_io_InputStream() {
// Test for method java.io.PushbackInputStream(java.io.InputStream)
try {
@@ -58,15 +45,6 @@
fail("Failed to throw exception on unread when buffer full");
}
- /**
- * @tests java.io.PushbackInputStream#PushbackInputStream(java.io.InputStream,
- * int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "PushbackInputStream",
- args = {java.io.InputStream.class, int.class}
- )
public void test_ConstructorLjava_io_InputStreamI() {
ByteArrayInputStream bas = new ByteArrayInputStream("Hello".getBytes());
try {
@@ -91,12 +69,6 @@
}
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
public void test_close() throws IOException {
PushbackInputStream tobj;
@@ -113,16 +85,6 @@
}
}
- /**
- * @throws IOException
- * @tests java.io.PushbackInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "",
- method = "available",
- args = {}
- )
public void test_available() throws IOException {
PushbackInputStream tobj;
@@ -137,29 +99,11 @@
}
}
- /**
- * @tests java.io.PushbackInputStream#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "markSupported",
- args = {}
- )
public void test_markSupported() {
// Test for method boolean java.io.PushbackInputStream.markSupported()
assertTrue("markSupported returned true", !pis.markSupported());
}
- /**
- * @tests java.io.PushbackInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
public void test_read() throws IOException {
PushbackInputStream tobj;
@@ -177,15 +121,6 @@
fileString.getBytes()[0], pis.read());
}
- /**
- * @tests java.io.PushbackInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII() throws IOException {
PushbackInputStream tobj;
byte[] buf = ("01234567890123456789").getBytes();
@@ -203,15 +138,6 @@
}
}
- /**
- * @tests java.io.PushbackInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII_Exception() throws IOException {
PushbackInputStream tobj;
byte[] buf = new byte[10];
@@ -237,15 +163,6 @@
}
}
- /**
- * @tests java.io.PushbackInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "skip",
- args = {long.class}
- )
public void test_skipJ() throws IOException {
PushbackInputStream tobj;
byte[] buf = ("01234567890123456789").getBytes();
@@ -281,15 +198,6 @@
}
}
- /**
- * @tests java.io.PushbackInputStream#unread(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "unread",
- args = {byte[].class}
- )
public void test_unread$B() throws IOException {
PushbackInputStream tobj;
String str2 = "0123456789";
@@ -330,15 +238,6 @@
}
}
- /**
- * @tests java.io.PushbackInputStream#unread(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "unread",
- args = {byte[].class, int.class, int.class}
- )
public void test_unread$BII() throws IOException {
PushbackInputStream tobj;
String str2 = "0123456789";
@@ -404,15 +303,6 @@
}
}
- /**
- * @tests java.io.PushbackInputStream#unread(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "unread",
- args = {int.class}
- )
public void test_unreadI() throws IOException {
PushbackInputStream tobj;
diff --git a/luni/src/test/java/libcore/java/io/OldPushbackReaderTest.java b/luni/src/test/java/libcore/java/io/OldPushbackReaderTest.java
new file mode 100644
index 0000000..31d921b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldPushbackReaderTest.java
@@ -0,0 +1,385 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.IOException;
+import java.io.PushbackReader;
+import java.io.StringReader;
+import tests.support.Support_ASimpleReader;
+
+public class OldPushbackReaderTest extends junit.framework.TestCase {
+
+ Support_ASimpleReader underlying = new Support_ASimpleReader();
+ PushbackReader pbr;
+
+ String pbString = "Hello World";
+
+ /**
+ * @tests java.io.PushbackReader#PushbackReader(java.io.Reader)
+ */
+ public void test_ConstructorLjava_io_Reader() {
+ // Test for method java.io.PushbackReader(java.io.Reader)
+ try {
+ pbr.close();
+ pbr = new PushbackReader(new StringReader(pbString));
+ char buf[] = new char[5];
+ pbr.read(buf, 0, 5);
+ pbr.unread(buf);
+ fail("Created reader with buffer larger than 1");;
+ } catch (IOException e) {
+ // Expected
+ }
+
+ try {
+ pbr = new PushbackReader(null);
+ } catch (NullPointerException e) {
+ // EXpected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#PushbackReader(java.io.Reader, int)
+ */
+ public void test_ConstructorLjava_io_ReaderI() throws IOException {
+ PushbackReader tobj;
+
+ tobj = new PushbackReader(underlying, 10000);
+ tobj = new PushbackReader(underlying, 1);
+
+ try {
+ tobj = new PushbackReader(underlying, -1);
+ tobj.close();
+ fail("IOException not thrown.");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ try {
+ tobj = new PushbackReader(underlying, 0);
+ tobj.close();
+ fail("IOException not thrown.");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#close()
+ */
+ public void test_close() throws IOException {
+ PushbackReader tobj;
+
+ tobj = new PushbackReader(underlying);
+ tobj.close();
+ tobj.close();
+ tobj = new PushbackReader(underlying);
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.close();
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#markSupported()
+ */
+ public void test_markSupported() {
+ assertFalse("Test 1: markSupported() must return false.",
+ pbr.markSupported());
+ }
+
+ /**
+ * @tests java.io.PushbackReader#read()
+ */
+ public void test_read() throws IOException {
+ PushbackReader tobj;
+
+ tobj = new PushbackReader(underlying);
+ assertEquals("Wrong value read!", 66, tobj.read());
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.read();
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#read(char[], int, int)
+ */
+ public void test_read$CII() throws IOException {
+ PushbackReader tobj;
+ char[] buf = ("01234567890123456789").toCharArray();
+
+ tobj = new PushbackReader(underlying);
+ tobj.read(buf, 6, 5);
+ assertEquals("Wrong value read!", "BEGIN", new String(buf, 6, 5));
+ assertEquals("Too much read!", "012345BEGIN123456789", new String(buf));
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.read(buf, 6, 5);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+
+ // Test for method int java.io.PushbackReader.read(char [], int, int)
+ try {
+ char[] c = new char[5];
+ pbr.read(c, 0, 5);
+ assertTrue("Failed to read chars", new String(c).equals(pbString
+ .substring(0, 5)));
+
+ assertEquals(0, pbr.read(c, 0, 0));
+ assertEquals(c.length, pbr.read(c, 0, c.length));
+ assertEquals(0, pbr.read(c, c.length, 0));
+ } catch (IOException e) {
+ fail("IOException during read test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#read(char[], int, int)
+ */
+ public void test_read_$CII_Exception() throws IOException {
+ pbr = new PushbackReader(new StringReader(pbString), 10);
+
+ char[] nullCharArray = null;
+ char[] charArray = new char[10];
+
+ try {
+ pbr.read(nullCharArray, 0, 1);
+ fail("should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ pbr.read(charArray, 0, -1);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ pbr.read(charArray, -1, 0);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ pbr.read(charArray, charArray.length + 1, 0);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ pbr.read(charArray, charArray.length, 1);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ pbr.read(charArray, 1, charArray.length);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ pbr.read(charArray, 0, charArray.length + 1);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ pbr.close();
+
+ try {
+ pbr.read(charArray, 0, 1);
+ fail("should throw IOException");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#ready()
+ */
+ public void test_ready() throws IOException {
+ PushbackReader tobj;
+
+ tobj = new PushbackReader(underlying);
+ assertTrue("Should be ready!", tobj.ready());
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.ready();
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+ /**
+ * @tests java.io.PushbackReader#unread(char[])
+ */
+ public void test_unread$C() throws IOException {
+ PushbackReader tobj;
+ String str2 = "0123456789";
+ char[] buf2 = str2.toCharArray();
+ char[] readBuf = new char[10];
+
+ tobj = new PushbackReader(underlying, 10);
+ tobj.unread(buf2);
+ try {
+ tobj.unread(buf2);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ tobj.read(readBuf);
+ assertEquals("Incorrect bytes read", str2, new String(readBuf));
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.read(buf2);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+
+ // Test for method void java.io.PushbackReader.unread(char [])
+ try {
+ char[] c = new char[5];
+ pbr.read(c, 0, 5);
+ pbr.unread(c);
+ pbr.read(c, 0, 5);
+ assertTrue("Failed to unread chars", new String(c).equals(pbString
+ .substring(0, 5)));
+ } catch (IOException e) {
+ fail("IOException during read test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @throws IOException
+ * @tests java.io.PushbackReader#skip(long)
+ */
+ public void test_skip$J() throws IOException {
+ PushbackReader tobj;
+
+ tobj = new PushbackReader(underlying);
+ tobj.skip(6);
+ tobj.skip(1000000);
+ tobj.skip(1000000);
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.skip(1);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#unread(char[], int, int)
+ */
+ public void test_unread$CII() throws IOException {
+ PushbackReader tobj;
+ String str2 = "0123456789";
+ char[] buf2 = (str2 + str2 + str2).toCharArray();
+ char[] readBuf = new char[10];
+
+ tobj = new PushbackReader(underlying, 10);
+ tobj.unread(buf2, 15, 10);
+ try {
+ tobj.unread(buf2, 15, 10);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ tobj.read(readBuf);
+ assertEquals("Incorrect bytes read", "5678901234", new String(readBuf));
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.read(buf2, 15, 10);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_unread_$CII_ArrayIndexOutOfBoundsException() throws IOException {
+ //a pushback reader with one character buffer
+ pbr = new PushbackReader(new StringReader(pbString));
+ try {
+ pbr.unread(new char[pbString.length()], 0 , -1);
+ fail("should throw ArrayIndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ pbr.unread(new char[10], 10 , 1);
+ fail("should throw ArrayIndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#unread(int)
+ */
+ public void test_unreadI() throws IOException {
+ PushbackReader tobj;
+
+ tobj = new PushbackReader(underlying);
+ tobj.unread(23); // Why does this work?!?
+ tobj.skip(2);
+ tobj.unread(23);
+ assertEquals("Wrong value read!", 23, tobj.read());
+ tobj.unread(13);
+ try {
+ tobj.unread(13);
+ fail("IOException not thrown (ACTUALLY NOT SURE WHETHER IT REALLY MUST BE THROWN!).");
+ } 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() {
+ pbr = new PushbackReader(new StringReader(pbString), 10);
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ try {
+ pbr.close();
+ } catch (IOException e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldSequenceInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldSequenceInputStreamTest.java
new file mode 100644
index 0000000..f7d9a49
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldSequenceInputStreamTest.java
@@ -0,0 +1,160 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.IOException;
+import java.io.SequenceInputStream;
+import tests.support.Support_ASimpleInputStream;
+
+public class OldSequenceInputStreamTest extends junit.framework.TestCase {
+
+ Support_ASimpleInputStream simple1, simple2;
+ SequenceInputStream si;
+ String s1 = "Hello";
+ String s2 = "World";
+
+ public void test_available() throws IOException {
+ assertEquals("Returned incorrect number of bytes!", s1.length(), si.available());
+ simple2.throwExceptionOnNextUse = true;
+ assertTrue("IOException on second stream should not affect at this time!",
+ si.available() == s1.length());
+ simple1.throwExceptionOnNextUse = true;
+ try {
+ si.available();
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_close2() throws IOException {
+ simple1.throwExceptionOnNextUse = true;
+ try {
+ si.close();
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_read() throws IOException {
+ si.read();
+ assertEquals("Test 1: Incorrect char read;",
+ s1.charAt(1), (char) si.read());
+
+ // We are still reading from the first input stream, should be ok.
+ simple2.throwExceptionOnNextUse = true;
+ try {
+ assertEquals("Test 2: Incorrect char read;",
+ s1.charAt(2), (char) si.read());
+ } catch (IOException e) {
+ fail("Test 3: Unexpected IOException.");
+ }
+
+ simple1.throwExceptionOnNextUse = true;
+ try {
+ si.read();
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ simple1.throwExceptionOnNextUse = false;
+
+ // Reading bytes 4 and 5 of the first input stream should be ok again.
+ si.read();
+ si.read();
+
+ // Reading the first byte of the second input stream should fail.
+ try {
+ si.read();
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ // Reading from the second input stream should be ok now.
+ simple2.throwExceptionOnNextUse = false;
+ try {
+ assertEquals("Test 6: Incorrect char read;",
+ s2.charAt(0), (char) si.read());
+ } catch (IOException e) {
+ fail("Test 7: Unexpected IOException.");
+ }
+
+ si.close();
+ assertTrue("Test 8: -1 expected when reading from a closed " +
+ "sequence input stream.", si.read() == -1);
+ }
+
+ public void test_read_exc() throws IOException {
+ simple2.throwExceptionOnNextUse = true;
+ assertEquals("IOException on second stream should not affect at this time!", 72, si.read());
+ simple1.throwExceptionOnNextUse = true;
+ try {
+ si.read();
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_read$BII_Excpetion() throws IOException {
+ byte[] buf = new byte[4];
+ si.read(buf, 0, 2);
+ si.read(buf, 2, 1);
+ simple2.throwExceptionOnNextUse = true;
+ si.read(buf, 3, 1);
+ assertEquals("Wrong stuff read!", "Hell", new String(buf));
+ simple1.throwExceptionOnNextUse = true;
+ try {
+ si.read(buf, 3, 1);
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+
+ buf = new byte[10];
+ simple1 = new Support_ASimpleInputStream(s1);
+ simple2 = new Support_ASimpleInputStream(s2);
+ si = new SequenceInputStream(simple1, simple2);
+ try {
+ si.read(buf, -1, 1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ si.read(buf, 0, -1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ si.read(buf, 1, 10);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ }
+
+ protected void setUp() {
+ simple1 = new Support_ASimpleInputStream(s1);
+ simple2 = new Support_ASimpleInputStream(s2);
+ si = new SequenceInputStream(simple1, simple2);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldStreamTokenizerTest.java b/luni/src/test/java/libcore/java/io/OldStreamTokenizerTest.java
new file mode 100644
index 0000000..22b276b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldStreamTokenizerTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StreamTokenizer;
+import java.io.StringReader;
+import junit.framework.Assert;
+import tests.support.Support_ASimpleInputStream;
+import tests.support.Support_StringReader;
+
+public class OldStreamTokenizerTest extends junit.framework.TestCase {
+ StreamTokenizer st;
+
+ public void test_nextToken() throws IOException {
+ st = new StreamTokenizer(new Support_StringReader("\n \r\n#"));
+ st.ordinaryChar('\n'); // make \n ordinary
+ st.eolIsSignificant(true);
+ assertTrue("Wrong token 2,1", st.nextToken() == '\n');
+ assertTrue("Wrong token 2,2", st.nextToken() == '\n');
+ assertEquals("Wrong token 2,3", '#', st.nextToken());
+
+ Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
+ sis.throwExceptionOnNextUse = true;
+ st = new StreamTokenizer(sis);
+ try {
+ st.nextToken();
+ fail("IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_basicStringTokenizerMethods() throws IOException {
+ String str = "Testing 12345 \n alpha \r\n omega";
+ String strb = "-3.8 'BLIND mice' \r sEe /* how */ they run";
+ StringReader aa = new StringReader(str);
+ StringReader ba = new StringReader(strb);
+ StreamTokenizer a = new StreamTokenizer(aa);
+ StreamTokenizer b = new StreamTokenizer(ba);
+
+ Assert.assertTrue(a.lineno() == 1);
+ Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_WORD);
+ Assert.assertTrue(a.toString().equals("Token[Testing], line 1"));
+ Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_NUMBER);
+ Assert.assertTrue(a.toString().equals("Token[n=12345.0], line 1"));
+ Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_WORD);
+ Assert.assertTrue(a.toString().equals("Token[alpha], line 2"));
+ Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_WORD);
+ Assert.assertTrue(a.toString().equals("Token[omega], line 3"));
+ Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_EOF);
+ Assert.assertTrue(a.toString().equals("Token[EOF], line 3"));
+
+ b.commentChar('u');
+ b.eolIsSignificant(true);
+ b.lowerCaseMode(true);
+ b.ordinaryChar('y');
+ b.slashStarComments(true);
+
+ Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_NUMBER);
+ Assert.assertTrue(b.nval == -3.8);
+ Assert.assertTrue(b.toString().equals("Token[n=-3.8], line 1"));
+ Assert.assertTrue(b.nextToken() == 39); // '
+ Assert.assertTrue(b.toString().equals("Token[BLIND mice], line 1"));
+ Assert.assertTrue(b.nextToken() == 10); // \n
+ Assert.assertTrue(b.toString().equals("Token[EOL], line 2"));
+ Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_WORD);
+ Assert.assertTrue(b.toString().equals("Token[see], line 2"));
+ Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_WORD);
+ Assert.assertTrue(b.toString().equals("Token[the], line 2"));
+ Assert.assertTrue(b.nextToken() == 121); // y
+ Assert.assertTrue(b.toString().equals("Token['y'], line 2"));
+ Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_WORD);
+ Assert.assertTrue(b.toString().equals("Token[r], line 2"));
+ Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_EOF);
+ Assert.assertTrue(b.toString().equals("Token[EOF], line 2"));
+ }
+
+ public void test_harmonyRegressionTest() {
+ byte[] data = new byte[] {(byte) '-'};
+ StreamTokenizer tokenizer = new StreamTokenizer(new ByteArrayInputStream(data));
+ try {
+ tokenizer.nextToken();
+ } catch(Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ String result = tokenizer.toString();
+ Assert.assertEquals("Token['-'], line 1", result);
+ }
+
+ public void test_harmonyRegressionTest2() {
+ byte[] data = new byte[] {(byte) '"',
+ (byte) 'H',
+ (byte) 'e',
+ (byte) 'l',
+ (byte) 'l',
+ (byte) 'o',
+ (byte) '"'};
+ StreamTokenizer tokenizer = new StreamTokenizer(new ByteArrayInputStream(data));
+ try {
+ tokenizer.nextToken();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ String result = tokenizer.toString();
+ Assert.assertEquals("Token[Hello], line 1", result);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldStringBufferInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldStringBufferInputStreamTest.java
new file mode 100644
index 0000000..f7aaae9
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldStringBufferInputStreamTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.StringBufferInputStream;
+import junit.framework.TestCase;
+
+public class OldStringBufferInputStreamTest extends TestCase {
+
+ StringBufferInputStream sbis;
+
+ public void test_read$BII_Exception() {
+ // Test for method int java.io.StringBufferInputStream.read()
+ byte[] buf = new byte[10];
+ try {
+ sbis.read(buf, 0, -1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ sbis.read(buf, -1, 1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ sbis.read(buf, 10, 1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ }
+
+ protected void setUp() {
+ sbis = new StringBufferInputStream("Hello World");
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldStringReaderTest.java b/luni/src/test/java/libcore/java/io/OldStringReaderTest.java
new file mode 100644
index 0000000..a3c6bf0
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldStringReaderTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+public class OldStringReaderTest extends junit.framework.TestCase {
+
+ String testString = "This is a test string";
+
+ StringReader sr;
+
+ public void test_markI() throws IOException {
+ sr = new StringReader(testString);
+ try {
+ sr.mark(-1);
+ fail("IllegalArgumentException not thrown!");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void test_read$CII() throws Exception {
+ char[] buf = new char[testString.length()];
+ sr = new StringReader(testString);
+ try {
+ sr.read(buf, 0, -1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ sr.read(buf, -1, 1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ sr.read(buf, 1, testString.length());
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ }
+
+ protected void tearDown() {
+
+ try {
+ sr.close();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldStringWriterTest.java b/luni/src/test/java/libcore/java/io/OldStringWriterTest.java
new file mode 100644
index 0000000..6ff2b74
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldStringWriterTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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 libcore.java.io;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+public class OldStringWriterTest extends junit.framework.TestCase {
+
+ StringWriter sw;
+
+ public void test_appendCharSequenceIntInt() throws IOException {
+ try {
+ StringWriter tobj = new StringWriter(9);
+ tobj.append("01234567890123456789", 19, 2);
+ fail("IndexOutOfBoundsException not thrown!");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ StringWriter tobj = new StringWriter(9);
+ tobj.append("01234567890123456789", 29, 2);
+ fail("IndexOutOfBoundsException not thrown!");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() {
+ sw = new StringWriter();
+ }
+}
diff --git a/luni/src/test/java/tests/api/java/io/WriterTest.java b/luni/src/test/java/libcore/java/io/OldWriterTest.java
similarity index 63%
rename from luni/src/test/java/tests/api/java/io/WriterTest.java
rename to luni/src/test/java/libcore/java/io/OldWriterTest.java
index d8ff8b2..b88e3bb 100644
--- a/luni/src/test/java/tests/api/java/io/WriterTest.java
+++ b/luni/src/test/java/libcore/java/io/OldWriterTest.java
@@ -13,37 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package tests.api.java.io;
+
+package libcore.java.io;
import java.io.IOException;
import java.io.Writer;
-
import junit.framework.TestCase;
import tests.support.Support_ASimpleWriter;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-@TestTargetClass(Writer.class)
-public class WriterTest extends TestCase {
+public class OldWriterTest extends TestCase {
- /**
- * @tests java.io.Writer#append(char)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {char.class}
- )
public void test_appendChar() throws IOException {
- char testChar = ' ';
- MockWriter writer = new MockWriter(20);
- writer.append(testChar);
- assertEquals(String.valueOf(testChar), String.valueOf(writer
- .getContents()));
- writer.close();
-
Writer tobj = new Support_ASimpleWriter(2);
tobj.append('a');
tobj.append('b');
@@ -56,22 +36,8 @@
}
}
- /**
- * @tests java.io.Writer#append(CharSequence)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {java.lang.CharSequence.class}
- )
public void test_appendCharSequence() throws IOException {
String testString = "My Test String";
- MockWriter writer = new MockWriter(20);
- writer.append(testString);
- assertEquals(testString, String.valueOf(writer.getContents()));
- writer.close();
-
Writer tobj = new Support_ASimpleWriter(20);
tobj.append(testString);
assertEquals("Wrong stuff written!", testString, tobj.toString());
@@ -83,23 +49,8 @@
}
}
- /**
- * @tests java.io.Writer#append(CharSequence, int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "append",
- args = {CharSequence.class, int.class, int.class}
- )
public void test_appendCharSequenceIntInt() throws IOException {
String testString = "My Test String";
- MockWriter writer = new MockWriter(20);
- writer.append(testString, 1, 3);
- assertEquals(testString.substring(1, 3), String.valueOf(writer
- .getContents()));
- writer.close();
-
Writer tobj = new Support_ASimpleWriter(21);
testString = "0123456789abcdefghijABCDEFGHIJ";
tobj.append(testString, 0, 5);
@@ -123,15 +74,6 @@
}
}
- /**
- * @tests java.io.Writer#append(CharSequence, int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "append",
- args = {CharSequence.class, int.class, int.class}
- )
public void test_appendCharSequenceIntInt_Exception() throws IOException {
String testString = "My Test String";
Writer tobj = new Support_ASimpleWriter(21);
@@ -155,13 +97,6 @@
}
}
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
public void test_write$C() throws IOException {
Writer tobj = new Support_ASimpleWriter(21);
tobj.write("01234".toCharArray());
@@ -179,12 +114,6 @@
}
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
public void test_writeI() throws IOException {
Writer tobj = new Support_ASimpleWriter(2);
tobj.write('a');
@@ -198,12 +127,6 @@
}
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {java.lang.String.class}
- )
public void test_writeLjava_lang_String() throws IOException {
Writer tobj = new Support_ASimpleWriter(21);
tobj.write("01234");
@@ -221,15 +144,6 @@
}
}
- /**
- * @tests java.io.PrintWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {String.class, int.class, int.class}
- )
public void test_writeLjava_lang_StringII() throws IOException {
String testString;
Writer tobj = new Support_ASimpleWriter(21);
@@ -255,15 +169,6 @@
}
}
- /**
- * @tests java.io.Writer#append(CharSequence, int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {String.class, int.class, int.class}
- )
public void test_writeLjava_lang_StringII_Exception() throws IOException {
String testString = "My Test String";
Writer tobj = new Support_ASimpleWriter(21);
@@ -286,53 +191,4 @@
// expected
}
}
-
- class MockWriter extends Writer {
- private char[] contents;
-
- private int length;
-
- private int offset;
-
- MockWriter(int capacity) {
- contents = new char[capacity];
- length = capacity;
- offset = 0;
- }
-
- public synchronized void close() throws IOException {
- flush();
- contents = null;
- }
-
- public synchronized void flush() throws IOException {
- // do nothing
- }
-
- public void write(char[] buffer, int offset, int count)
- throws IOException {
- if (null == contents) {
- throw new IOException();
- }
- if (offset < 0 || count < 0 || offset >= buffer.length) {
- throw new IndexOutOfBoundsException();
- }
- count = Math.min(count, buffer.length - offset);
- count = Math.min(count, this.length - this.offset);
- for (int i = 0; i < count; i++) {
- contents[this.offset + i] = buffer[offset + i];
- }
- this.offset += count;
-
- }
-
- public char[] getContents() {
- char[] result = new char[offset];
- for (int i = 0; i < offset; i++) {
- result[i] = contents[i];
- }
- return result;
- }
- }
-
}
diff --git a/luni/src/test/java/tests/api/java/io/AllTests.java b/luni/src/test/java/tests/api/java/io/AllTests.java
index 9c5f129..d75d2c9 100644
--- a/luni/src/test/java/tests/api/java/io/AllTests.java
+++ b/luni/src/test/java/tests/api/java/io/AllTests.java
@@ -26,76 +26,7 @@
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("All tests for package tests.api.java.io;");
- // $JUnit-BEGIN$
-
- suite.addTestSuite(BufferedInputStreamTest.class);
- suite.addTestSuite(BufferedOutputStreamTest.class);
- suite.addTestSuite(BufferedReaderTest.class);
- suite.addTestSuite(BufferedWriterTest.class);
- suite.addTestSuite(ByteArrayInputStreamTest.class);
- suite.addTestSuite(ByteArrayOutputStreamTest.class);
- suite.addTestSuite(CharArrayReaderTest.class);
- suite.addTestSuite(CharArrayWriterTest.class);
- suite.addTestSuite(CharConversionExceptionTest.class);
- suite.addTestSuite(ComputeSerialVersionUIDTest.class);
- suite.addTestSuite(DataInputStreamTest.class);
- suite.addTestSuite(DataInputOutputStreamTest.class);
- suite.addTestSuite(DataOutputStreamTest.class);
- suite.addTestSuite(EOFExceptionTest.class);
- suite.addTestSuite(FileDescriptorTest.class);
- suite.addTestSuite(FileInputStreamTest.class);
- suite.addTestSuite(FileNotFoundExceptionTest.class);
- suite.addTestSuite(FileOutputStreamTest.class);
- suite.addTestSuite(FilePermissionTest.class);
- suite.addTestSuite(FileReaderTest.class);
- suite.addTestSuite(FileTest.class);
- suite.addTestSuite(FileWriterTest.class);
- suite.addTestSuite(FilterInputStreamTest.class);
- suite.addTestSuite(FilterOutputStreamTest.class);
- suite.addTestSuite(FilterReaderTest.class);
- suite.addTestSuite(FilterWriterTest.class);
- suite.addTestSuite(IOExceptionTest.class);
- suite.addTestSuite(InputStreamReaderTest.class);
- suite.addTestSuite(InterruptedIOExceptionTest.class);
- suite.addTestSuite(InvalidClassExceptionTest.class);
- suite.addTestSuite(InvalidObjectExceptionTest.class);
- suite.addTestSuite(LineNumberInputStreamTest.class);
- suite.addTestSuite(LineNumberReaderTest.class);
- suite.addTestSuite(NotActiveExceptionTest.class);
- suite.addTestSuite(NotSerializableExceptionTest.class);
suite.addTestSuite(ObjectInputStreamTest.class);
- suite.addTestSuite(ObjectInputStreamGetFieldTest.class);
- suite.addTestSuite(ObjectInputOutputStreamTest.class);
- suite.addTestSuite(ObjectOutputStreamTest.class);
- suite.addTestSuite(ObjectOutputStreamPutFieldTest.class);
- suite.addTestSuite(ObjectStreamClassTest.class);
- suite.addTestSuite(ObjectStreamExceptionTest.class);
- suite.addTestSuite(ObjectStreamFieldTest.class);
- suite.addTestSuite(OpenRandomFileTest.class);
- suite.addTestSuite(OutputStreamTest.class);
- suite.addTestSuite(OutputStreamWriterTest.class);
- suite.addTestSuite(PipedInputStreamTest.class);
- suite.addTestSuite(PipedOutputStreamTest.class);
- suite.addTestSuite(PipedReaderTest.class);
- suite.addTestSuite(PipedWriterTest.class);
- suite.addTestSuite(PrintStreamTest.class);
- suite.addTestSuite(PrintWriterTest.class);
- suite.addTestSuite(PushbackInputStreamTest.class);
- suite.addTestSuite(PushbackReaderTest.class);
- suite.addTestSuite(SequenceInputStreamTest.class);
- suite.addTestSuite(SerializablePermissionTest.class);
- suite.addTestSuite(StreamCorruptedExceptionTest.class);
- suite.addTestSuite(StreamTokenizerTest.class);
- suite.addTestSuite(StringBufferInputStreamTest.class);
- suite.addTestSuite(StringReaderTest.class);
- suite.addTestSuite(StringWriterTest.class);
- suite.addTestSuite(SyncFailedExceptionTest.class);
- suite.addTestSuite(UTFDataFormatExceptionTest.class);
- suite.addTestSuite(UnsupportedEncodingExceptionTest.class);
- suite.addTestSuite(WriteAbortedExceptionTest.class);
- suite.addTestSuite(WriterTest.class);
-
- // $JUnit-END$
return suite;
}
}
diff --git a/luni/src/test/java/tests/api/java/io/BufferedInputStreamTest.java b/luni/src/test/java/tests/api/java/io/BufferedInputStreamTest.java
deleted file mode 100644
index 27515d3..0000000
--- a/luni/src/test/java/tests/api/java/io/BufferedInputStreamTest.java
+++ /dev/null
@@ -1,578 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import junit.framework.TestCase;
-import tests.support.Support_ASimpleInputStream;
-import tests.support.Support_PlatformFile;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-@TestTargetClass(BufferedInputStream.class)
-public class BufferedInputStreamTest extends TestCase {
-
- public String fileName;
-
- private BufferedInputStream is;
-
- private FileInputStream isFile;
-
- byte[] ibuf = new byte[4096];
-
- public String fileString = "Test_All_Tests\nTest_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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";
-
- /**
- * @throws IOException
- * @tests java.io.BufferedInputStream#BufferedInputStream(java.io.InputStream,
- * int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedInputStream",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStream() {
- is = new BufferedInputStream(isFile);
-
- try {
- is.read();
- } catch (Exception e) {
- fail("Test 1: Read failed on a freshly constructed buffer.");
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.BufferedInputStream#BufferedInputStream(java.io.InputStream,
- * int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedInputStream",
- args = {java.io.InputStream.class, int.class}
- )
- public void test_ConstructorLjava_io_InputStreamI() throws IOException {
- // Test for method java.io.BufferedInputStream(java.io.InputStream, int)
- boolean exceptionFired = false;
-
- try {
- is = new BufferedInputStream(isFile, -1);
- fail("IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
-
- try {
- // Create buffer with exact size of file
- is = new BufferedInputStream(isFile, this.fileString
- .length());
- // Ensure buffer gets filled by evaluating one read
- is.read();
- // Close underlying FileInputStream, all but 1 buffered bytes should
- // still be available.
- isFile.close();
- // Read the remaining buffered characters, no IOException should
- // occur.
- is.skip(this.fileString.length() - 2);
- is.read();
- try {
- // is.read should now throw an exception because it will have to
- // be filled.
- is.read();
- } catch (IOException e) {
- exceptionFired = true;
- }
- assertTrue("Exception should have been triggered by read()",
- exceptionFired);
- } catch (IOException e) {
- fail("Exception during test_1_Constructor");
- }
-
- // regression test for harmony-2407
- new testBufferedInputStream(null);
- assertNotNull(testBufferedInputStream.buf);
- testBufferedInputStream.buf = null;
- new testBufferedInputStream(null, 100);
- assertNotNull(testBufferedInputStream.buf);
- }
-
- static class testBufferedInputStream extends BufferedInputStream {
- static byte[] buf;
- testBufferedInputStream(InputStream is) throws IOException {
- super(is);
- buf = super.buf;
- }
-
- testBufferedInputStream(InputStream is, int size) throws IOException {
- super(is, size);
- buf = super.buf;
- }
- }
-
- /**
- * @tests java.io.BufferedInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies the available() method.",
- method = "available",
- args = {}
- )
- public void test_available() {
- // Test for method int java.io.BufferedInputStream.available()
- try {
- assertTrue("Returned incorrect number of available bytes", is
- .available() == fileString.length());
- } catch (IOException e) {
- fail("Exception during available test");
- }
-
- // Test that a closed stream throws an IOE for available()
- BufferedInputStream bis = new BufferedInputStream(
- new ByteArrayInputStream(new byte[] { 'h', 'e', 'l', 'l', 'o',
- ' ', 't', 'i', 'm' }));
- int available = 0;
- try {
- available = bis.available();
- bis.close();
- } catch (IOException ex) {
- fail();
- }
- assertTrue(available != 0);
-
- try {
- bis.available();
- fail("Expected test to throw IOE.");
- } catch (IOException ex) {
- // expected
- } catch (Throwable ex) {
- fail("Expected test to throw IOE not "
- + ex.getClass().getName());
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.BufferedInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- is.close();
-
- try {
- is.read();
- fail("Test 1: IOException expected when reading after closing " +
- "the stream.");
- } catch (IOException e) {
- // Expected.
- }
-
- Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
- is = new BufferedInputStream(sis);
- try {
- is.close();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sis.throwExceptionOnNextUse = false;
- }
-
- /**
- * @tests java.io.BufferedInputStream#mark(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "mark",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- ) /* ,
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks that a marked position is invalidated.",
- method = "read",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks that a marked position is invalidated.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks that a marked position is invalidated.",
- method = "skip",
- args = {long.class}
- ) */
- })
- public void test_markI_reset() throws IOException {
- byte[] buf1 = new byte[100];
- byte[] buf2 = new byte[100];
-
- // Test 1: Check that reset fails if no mark has been set.
- try {
- is.reset();
- fail("Test 1: IOException expected if no mark has been set.");
- } catch (IOException e) {
- // Expected.
- }
-
- // Test 2: Check that mark / reset works when the mark is not invalidated.
- is.skip(10);
- is.mark(100);
- is.read(buf1, 0, buf1.length);
- is.reset();
- is.read(buf2, 0, buf2.length);
- is.reset();
- assertTrue("Test 2: Failed to mark correct position or reset failed.",
- new String(buf1, 0, buf1.length).equals(new String(buf2, 0, buf2.length)));
-
- // Tests 3 and 4: Check that skipping less than readlimit bytes does
- // not invalidate the mark.
- is.skip(10);
- try {
- is.reset();
- } catch (IOException e) {
- fail("Test 3: Unexpected IOException " + e.getMessage());
- }
- is.read(buf2, 0, buf2.length);
- is.reset();
- assertTrue("Test 4: Failed to mark correct position, or reset failed.",
- new String(buf1, 0, buf1.length).equals(new String(buf2, 0, buf2.length)));
-
-/* Tests disabled because they fail. The specification is ambiguous
- * regarding the invalidation of a set mark by read and skip operations.
-
- // Test 5: Check that the mark is invalidated by a sequence of reads.
- is.skip(200);
- is.mark(10);
- for (int i = 0; i < 11; i++) {
- is.read();
- }
- try {
- is.reset();
- fail("Test 5: IOException expected because the mark should be invalid.");
- } catch (IOException e) {
- // Expected.
- }
-
- // Test 6: Check that the mark is invalidated by a buffer read.
- is.skip(200);
- is.mark(10);
- is.read(buf1, 0, buf1.length);
- try {
- is.reset();
- fail("Test 6: IOException expected because the mark should be invalid.");
- } catch (IOException e) {
- // Expected.
- }
-
- // Test 7: Check that the mark is invalidated by a skip.
- is.mark(10);
- is.skip(11);
- try {
- is.reset();
- fail("Test 7: IOException expected because the mark should be invalid.");
- } catch (IOException e) {
- // Expected.
- }
-*/
-
- // Test 8: Check that reset fails for a closed input stream.
- is.close();
- try {
- is.reset();
- fail("Test 8: IOException expected because the input stream is closed.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.BufferedInputStream#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies markSupported() method.",
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() {
- // Test for method boolean java.io.BufferedInputStream.markSupported()
- assertTrue("markSupported returned incorrect value", is.markSupported());
- }
-
- /**
- * @tests java.io.BufferedInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "A partial read test in test_markI_reset() is disabled at " +
- "the moment because it fails. If this test is ever " +
- "enabled, then the level here must be changed to " +
- "PARTIAL_COMPLETE.",
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- int c = is.read();
- assertTrue("Test 1: Incorrect character read.",
- c == fileString.charAt(0));
-
- byte[] bytes = new byte[256];
- for (int i = 0; i < 256; i++) {
- bytes[i] = (byte) i;
- }
-
- BufferedInputStream in = new BufferedInputStream(
- new ByteArrayInputStream(bytes), 5);
-
- // Read more bytes than are buffered.
- for (int i = 0; i < 10; i++) {
- assertEquals("Test 2: Incorrect byte read;", bytes[i], in.read());
- }
-
- in.close();
- try {
- in.read();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.BufferedInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks exceptions only.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Exception() throws IOException {
- BufferedInputStream bis = new BufferedInputStream(null);
-
- try {
- bis.read(null, -1, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- //expected
- }
-
- try {
- bis.read(new byte[0], -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- bis.read(new byte[0], 1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- bis.read(new byte[0], 1, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- bis.close();
-
- try {
- bis.read(null, -1, -1);
- fail("should throw IOException");
- } catch (IOException e) {
- //expected
- }
- }
-
- /**
- * @tests java.io.BufferedInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Functional test.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() {
- // Test for method int java.io.BufferedInputStream.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 (IOException e) {
- fail("Exception during read test");
- }
-
- BufferedInputStream bufin = new BufferedInputStream(new InputStream() {
- int size = 2, pos = 0;
-
- byte[] contents = new byte[size];
-
- @Override
- public int read() throws IOException {
- if (pos >= size) {
- throw new IOException("Read past end of data");
- }
- return contents[pos++];
- }
-
- @Override
- public int read(byte[] buf, int off, int len) throws IOException {
- if (pos >= size) {
- throw new IOException("Read past end of data");
- }
- int toRead = len;
- if (toRead > available()) {
- toRead = available();
- }
- System.arraycopy(contents, pos, buf, off, toRead);
- pos += toRead;
- return toRead;
- }
-
- @Override
- public int available() {
- return size - pos;
- }
- });
- try {
- bufin.read();
- int result = bufin.read(new byte[2], 0, 2);
- assertTrue("Incorrect result: " + result, result == 1);
- } catch (IOException e) {
- fail("Unexpected: " + e);
- }
- }
-
- /**
- * @tests java.io.BufferedInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies skip(long n) method.",
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() {
- // Test for method long java.io.BufferedInputStream.skip(long)
- byte[] buf1 = new byte[10];
- try {
- is.mark(2000);
- is.skip(1000);
- is.read(buf1, 0, buf1.length);
- is.reset();
- assertTrue("Failed to skip to correct position", new String(buf1,
- 0, buf1.length).equals(fileString.substring(1000, 1010)));
- } catch (IOException e) {
- fail("Exception during skip test");
- }
-
- //regression for HARMONY-667
- BufferedInputStream buf = new BufferedInputStream(null, 5);
- try {
- buf.skip(10);
- fail("Should throw IOException");
- } catch (IOException e) {
- //expected
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- @Override
- protected void setUp() {
-
- try {
- fileName = System.getProperty("java.io.tmpdir");
- String separator = System.getProperty("file.separator");
- if (fileName.charAt(fileName.length() - 1) == separator.charAt(0)) {
- fileName = Support_PlatformFile.getNewPlatformFile(fileName,
- "input.tst");
- } else {
- fileName = Support_PlatformFile.getNewPlatformFile(fileName
- + separator, "input.tst");
- }
- OutputStream fos = new FileOutputStream(fileName);
- fos.write(fileString.getBytes());
- fos.close();
- isFile = new FileInputStream(fileName);
- is = new BufferedInputStream(isFile, 1000);
- } catch (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.
- */
- @Override
- protected void tearDown() {
-
- if (is != null) {
- try {
- is.close();
- } catch (Exception e) {
- System.out.println("Exception 1 during BIS tearDown: " + e.getMessage());
- }
- }
- try {
- File f = new File(fileName);
- f.delete();
- } catch (Exception e) {
- System.out.println("Exception 2 during BIS tearDown: " + e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ByteArrayOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/ByteArrayOutputStreamTest.java
deleted file mode 100644
index 00cf373..0000000
--- a/luni/src/test/java/tests/api/java/io/ByteArrayOutputStreamTest.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-
-import junit.framework.TestCase;
-import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-/**
- * Automated Test Suite for class java.io.ByteArrayOutputStream
- *
- * @see java.io.ByteArrayOutputStream
- */
-@TestTargetClass(ByteArrayOutputStream.class)
-public class ByteArrayOutputStreamTest extends TestCase {
-
- ByteArrayOutputStream bos = null;
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
-
- /**
- * @tests java.io.ByteArrayOutputStream#ByteArrayOutputStream(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ByteArrayOutputStream",
- args = {int.class}
- )
- public void test_ConstructorI() {
- bos = new java.io.ByteArrayOutputStream(100);
- assertEquals("Test 1: Failed to create stream;", 0, bos.size());
-
- try {
- bos = new ByteArrayOutputStream(-1);
- fail("Test 2: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#ByteArrayOutputStream()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ByteArrayOutputStream",
- args = {}
- )
- public void test_Constructor() {
- // Test for method java.io.ByteArrayOutputStream()
- bos = new java.io.ByteArrayOutputStream();
- assertEquals("Failed to create stream", 0, bos.size());
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException check since it is never thrown.",
- method = "close",
- args = {}
- )
- public void test_close() {
- // Test for method void java.io.ByteArrayOutputStream.close()
-
- assertTrue(
- "close() does nothing for this implementation of OutputSteam",
- true);
-
- // The spec seems to say that a closed output stream can't be written
- // to. We don't throw an exception if attempt is made to write.
- // Right now our implementation doesn't do anything testable but
- // should we decide to throw an exception if a closed stream is
- // written to, the appropriate test is commented out below.
-
- /***********************************************************************
- * java.io.ByteArrayOutputStream bos = new
- * java.io.ByteArrayOutputStream(); bos.write (fileString.getBytes(), 0,
- * 100); try { bos.close(); } catch (java.io.IOException e) {
- * fail("IOException closing stream"); } try { bos.write
- * (fileString.getBytes(), 0, 100); bos.toByteArray(); fail("Wrote
- * to closed stream"); } catch (Exception e) { }
- **********************************************************************/
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- )
- public void test_reset() {
- // Test for method void java.io.ByteArrayOutputStream.reset()
- bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, 100);
- bos.reset();
- assertEquals("Test 1: Reset failed;", 0, bos.size());
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#size()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies size() method.",
- method = "size",
- args = {}
- )
- public void test_size() {
- // Test for method int java.io.ByteArrayOutputStream.size()
- bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, 100);
- assertEquals("size test failed", 100, bos.size());
- bos.reset();
- assertEquals("size test failed", 0, bos.size());
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#toByteArray()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies toByteArray() method.",
- method = "toByteArray",
- args = {}
- )
- public void test_toByteArray() {
- // Test for method byte [] java.io.ByteArrayOutputStream.toByteArray()
- byte[] bytes;
- byte[] sbytes = fileString.getBytes();
- bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, fileString.length());
- bytes = bos.toByteArray();
- for (int i = 0; i < fileString.length(); i++) {
- assertTrue("Error in byte array", bytes[i] == sbytes[i]);
- }
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#toString(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "toString",
- args = {java.lang.String.class}
- )
- public void test_toStringLjava_lang_String() throws Exception {
- bos = new ByteArrayOutputStream();
-
- bos.write(fileString.getBytes(), 0, fileString.length());
- assertTrue("Test 1: Returned incorrect 8859-1 String",
- bos.toString("8859_1").equals(fileString));
- assertTrue("Test 2: Returned incorrect 8859-2 String",
- bos.toString("8859_2").equals(fileString));
-
- try {
- bos.toString("NotAnEcoding");
- fail("Test 3: UnsupportedEncodingException expected.");
- } catch (UnsupportedEncodingException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies toString() method.",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String
- // java.io.ByteArrayOutputStream.toString()
- java.io.ByteArrayOutputStream bos = null;
- bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, fileString.length());
- assertTrue("Returned incorrect String", bos.toString().equals(
- fileString));
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#toString(int)
- */
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies toString(int hibyte) method.",
- method = "toString",
- args = {int.class}
- )
- public void test_toStringI() {
- // Test for method java.lang.String
- // java.io.ByteArrayOutputStream.toString(int)
- java.io.ByteArrayOutputStream bos = null;
- bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, fileString.length());
- assertTrue("Returned incorrect String",
- bos.toString(5).length() == fileString.length());
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() {
- // Test for method void java.io.ByteArrayOutputStream.write(int)
- bos = new java.io.ByteArrayOutputStream();
- bos.write('t');
- byte[] result = bos.toByteArray();
- assertEquals("Wrote incorrect bytes",
- "t", new String(result, 0, result.length));
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() {
- // Test for method void java.io.ByteArrayOutputStream.write(byte [],
- // int, int)
- java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, 100);
- byte[] result = bos.toByteArray();
- assertTrue("Wrote incorrect bytes",
- new String(result, 0, result.length).equals(fileString
- .substring(0, 100)));
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument checks.",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII_Exception() {
- byte[] target = new byte[10];
- bos = new ByteArrayOutputStream();
- try {
- bos.write(target, -1, 1);
- fail("Test 1: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- bos.write(target, 0, -1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- bos.write(target, 1, target.length);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- bos.write(null, 1, 1);
- fail("Test 4: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#writeTo(java.io.OutputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "writeTo",
- args = {java.io.OutputStream.class}
- )
- public void test_writeToLjava_io_OutputStream() throws Exception {
- Support_OutputStream sos = new Support_OutputStream();
- bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, 10);
- bos.writeTo(sos);
- assertTrue("Test 1: Incorrect string written.",
- sos.toString().equals(
- fileString.substring(0, 10)));
-
- sos.setThrowsException(true);
- try {
- bos.writeTo(sos);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/CharArrayWriterTest.java b/luni/src/test/java/tests/api/java/io/CharArrayWriterTest.java
deleted file mode 100644
index 692c043..0000000
--- a/luni/src/test/java/tests/api/java/io/CharArrayWriterTest.java
+++ /dev/null
@@ -1,436 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.CharArrayReader;
-import java.io.CharArrayWriter;
-import java.io.IOException;
-import java.io.StringWriter;
-
-import tests.support.Support_ASimpleWriter;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(CharArrayWriter.class)
-public class CharArrayWriterTest extends junit.framework.TestCase {
-
- char[] hw = { 'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd' };
-
- CharArrayWriter cw;
-
- CharArrayReader cr;
-
- /**
- * @tests java.io.CharArrayWriter#CharArrayWriter(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "CharArrayWriter",
- args = {int.class}
- )
- public void test_ConstructorI() {
- // Test for method java.io.CharArrayWriter(int)
- cw = new CharArrayWriter(90);
- assertEquals("Test 1: Incorrect writer created.", 0, cw.size());
-
- try {
- cw = new CharArrayWriter(-1);
- fail("IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#CharArrayWriter()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies CharArrayWriter() method.",
- method = "CharArrayWriter",
- args = {}
- )
- public void test_Constructor() {
- // Test for method java.io.CharArrayWriter()
- cw = new CharArrayWriter();
- assertEquals("Created incorrect writer", 0, cw.size());
- }
-
- /**
- * @tests java.io.CharArrayWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies close() method.",
- method = "close",
- args = {}
- )
- public void test_close() {
- // Test for method void java.io.CharArrayWriter.close()
- cw.close();
- }
-
- /**
- * @tests java.io.CharArrayWriter#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies flush() method.",
- method = "flush",
- args = {}
- )
- public void test_flush() {
- // Test for method void java.io.CharArrayWriter.flush()
- cw.flush();
- }
-
- /**
- * @tests java.io.CharArrayWriter#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies reset() method.",
- method = "reset",
- args = {}
- )
- public void test_reset() {
- // Test for method void java.io.CharArrayWriter.reset()
- cw.write("HelloWorld", 5, 5);
- cw.reset();
- cw.write("HelloWorld", 0, 5);
- cr = new CharArrayReader(cw.toCharArray());
- try {
- char[] c = new char[100];
- cr.read(c, 0, 5);
- assertEquals("Reset failed to reset buffer",
- "Hello", new String(c, 0, 5));
- } catch (IOException e) {
- fail("Exception during reset test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#size()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies size() method.",
- method = "size",
- args = {}
- )
- public void test_size() {
- // Test for method int java.io.CharArrayWriter.size()
- assertEquals("Returned incorrect size", 0, cw.size());
- cw.write(hw, 5, 5);
- assertEquals("Returned incorrect size", 5, cw.size());
- }
-
- /**
- * @tests java.io.CharArrayWriter#toCharArray()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies toCharArray() method.",
- method = "toCharArray",
- args = {}
- )
- public void test_toCharArray() {
- // Test for method char [] java.io.CharArrayWriter.toCharArray()
- cw.write("HelloWorld", 0, 10);
- cr = new CharArrayReader(cw.toCharArray());
- try {
- char[] c = new char[100];
- cr.read(c, 0, 10);
- assertEquals("toCharArray failed to return correct array",
- "HelloWorld", new String(c, 0, 10));
- } catch (IOException e) {
- fail("Exception during toCharArray test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies toString() method.",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.io.CharArrayWriter.toString()
- cw.write("HelloWorld", 5, 5);
- cr = new CharArrayReader(cw.toCharArray());
- assertEquals("Returned incorrect string",
- "World", cw.toString());
- }
-
- /**
- * @tests java.io.CharArrayWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII() {
- // Test for method void java.io.CharArrayWriter.write(char [], int, int)
- cw.write(hw, 5, 5);
- cr = new CharArrayReader(cw.toCharArray());
- try {
- char[] c = new char[100];
- cr.read(c, 0, 5);
- assertEquals("Writer failed to write correct chars",
- "World", new String(c, 0, 5));
- } catch (IOException e) {
- fail("Exception during write test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#write(char[], int, int)
- * Regression for HARMONY-387
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument checks.",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII_Exception() {
- char[] target = new char[10];
- cw = new CharArrayWriter();
- try {
- cw.write(target, -1, 1);
- fail("Test 1: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- cw.write(target, 0, -1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- cw.write(target, 1, target.length);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- cw.write((char[]) null, 1, 1);
- fail("Test 4: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(int) method.",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() {
- // Test for method void java.io.CharArrayWriter.write(int)
- cw.write('T');
- cr = new CharArrayReader(cw.toCharArray());
- try {
- assertEquals("Writer failed to write char", 'T', cr.read());
- } catch (IOException e) {
- fail("Exception during write test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(java.lang.String, int, int) method. [Need to check different strings?]",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void test_writeLjava_lang_StringII() {
- // Test for method void java.io.CharArrayWriter.write(java.lang.String,
- // int, int)
- cw.write("HelloWorld", 5, 5);
- cr = new CharArrayReader(cw.toCharArray());
- try {
- char[] c = new char[100];
- cr.read(c, 0, 5);
- assertEquals("Writer failed to write correct chars",
- "World", new String(c, 0, 5));
- } catch (IOException e) {
- fail("Exception during write test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#write(java.lang.String, int, int)
- * Regression for HARMONY-387
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Regression for write(java.lang.String, int, int) method.",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void test_writeLjava_lang_StringII_2() throws StringIndexOutOfBoundsException {
- CharArrayWriter obj = new CharArrayWriter();
- try {
- obj.write((String) null, -1, 0);
- fail("NullPointerException expected");
- } catch (NullPointerException t) {
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#writeTo(java.io.Writer)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "writeTo",
- args = {java.io.Writer.class}
- )
- public void test_writeToLjava_io_Writer() {
- Support_ASimpleWriter ssw = new Support_ASimpleWriter(true);
- cw.write("HelloWorld", 0, 10);
- StringWriter sw = new StringWriter();
- try {
- cw.writeTo(sw);
- assertEquals("Test 1: Writer failed to write correct chars;",
- "HelloWorld", sw.toString());
- } catch (IOException e) {
- fail("Exception during writeTo test : " + e.getMessage());
- }
-
- try {
- cw.writeTo(ssw);
- fail("Test 2: IOException expected.");
- } 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() {
- cw = new CharArrayWriter();
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- if (cr != null)
- cr.close();
- cw.close();
- }
-
- /**
- * @tests java.io.CharArrayWriter#append(char)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies append(char c) method.",
- method = "append",
- args = {char.class}
- )
- public void test_appendChar() throws IOException {
- char testChar = ' ';
- CharArrayWriter writer = new CharArrayWriter(10);
- writer.append(testChar);
- writer.flush();
- assertEquals(String.valueOf(testChar), writer.toString());
- writer.close();
- }
-
- /**
- * @tests java.io.CharArrayWriter#append(CharSequence)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies append(CharSequence csq) method.",
- method = "append",
- args = {java.lang.CharSequence.class}
- )
- public void test_appendCharSequence() {
-
- String testString = "My Test String";
- CharArrayWriter writer = new CharArrayWriter(10);
- writer.append(testString);
- writer.flush();
- assertEquals(testString, writer.toString());
- writer.close();
- }
-
- /**
- * @tests java.io.CharArrayWriter#append(CharSequence, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "append",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- public void test_appendLjava_langCharSequenceII() {
- String testString = "My Test String";
- CharArrayWriter writer = new CharArrayWriter(10);
-
- // Illegal argument checks.
- try {
- writer.append(testString, -1, 0);
- fail("Test 1: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- try {
- writer.append(testString, 0, -1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- try {
- writer.append(testString, 1, 0);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- try {
- writer.append(testString, 1, testString.length() + 1);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- writer.append(testString, 1, 3);
- writer.flush();
- assertEquals("Test 5: Appending failed;",
- testString.substring(1, 3), writer.toString());
- writer.close();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/CharConversionExceptionTest.java b/luni/src/test/java/tests/api/java/io/CharConversionExceptionTest.java
deleted file mode 100644
index 537ab77..0000000
--- a/luni/src/test/java/tests/api/java/io/CharConversionExceptionTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.CharConversionException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(CharConversionException.class)
-public class CharConversionExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.CharConversionException#CharConversionException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "CharConversionException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new CharConversionException();
- fail("Test 1: CharConversionException expected.");
- } catch (CharConversionException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharConversionException#CharConversionException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "CharConversionException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new CharConversionException("Something went wrong.");
- fail("Test 1: CharConversionException expected.");
- } catch (CharConversionException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/EOFExceptionTest.java b/luni/src/test/java/tests/api/java/io/EOFExceptionTest.java
deleted file mode 100644
index 0144134..0000000
--- a/luni/src/test/java/tests/api/java/io/EOFExceptionTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.EOFException;
-
-@TestTargetClass(EOFException.class)
-public class EOFExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.EOFException#EOFException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "EOFException",
- args = {}
- )
- public void test_Constructor() {
- try {
- new DataInputStream(new ByteArrayInputStream(new byte[1]))
- .readShort();
- fail("Test 1: EOFException expected.");
- } catch (EOFException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- } catch (Exception e) {
- fail("Test 3: Unexpected exception: " + e.toString());
- }
- }
-
- /**
- * @tests java.io.EOFException#EOFException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "EOFException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // Needed to avoid unreachable code compilation error.
- throw new EOFException("Something went wrong.");
- fail("Test 1: EOFException expected.");
- } catch (EOFException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", 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() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ExternalizableTest.java b/luni/src/test/java/tests/api/java/io/ExternalizableTest.java
deleted file mode 100644
index 4c6d033..0000000
--- a/luni/src/test/java/tests/api/java/io/ExternalizableTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package tests.api.java.io;
-
-import junit.framework.TestCase;
-
-import java.io.Externalizable;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(
- value = Externalizable.class,
- untestedMethods = {
- @TestTargetNew(
- method = "readExternal",
- args = {ObjectInput.class},
- level = TestLevel.NOT_FEASIBLE,
- notes = "There are no classes in the current core " +
- "libraries that implement this method."
- ),
- @TestTargetNew(
- method = "writeExternal",
- args = {ObjectOutput.class},
- level = TestLevel.NOT_FEASIBLE,
- notes = "There are no classes in the current core " +
- "libraries that implement this method."
- )
- }
-)
-public class ExternalizableTest extends TestCase {
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileDescriptorTest.java b/luni/src/test/java/tests/api/java/io/FileDescriptorTest.java
deleted file mode 100644
index e7a2ac4..0000000
--- a/luni/src/test/java/tests/api/java/io/FileDescriptorTest.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.RandomAccessFile;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(FileDescriptor.class)
-public class FileDescriptorTest extends junit.framework.TestCase {
-
- private static String platformId = "JDK"
- + System.getProperty("java.vm.version").replace('.', '-');
-
- FileOutputStream fos;
-
- BufferedOutputStream os;
-
- FileInputStream fis;
-
- File f;
-
- /**
- * @tests java.io.FileDescriptor#FileDescriptor()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "FileDescriptor",
- args = {}
- )
- public void test_Constructor() {
- // Test for method java.io.FileDescriptor()
- FileDescriptor fd = new FileDescriptor();
- assertTrue("Failed to create FileDescriptor",
- fd instanceof FileDescriptor);
- }
-
- /**
- * @tests java.io.FileDescriptor#sync()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "SyncFailedException not checked since it is only thrown" +
- "by the native implementation of sync().",
- method = "sync",
- args = {}
- )
- public void test_sync() throws Exception {
- // Test for method void java.io.FileDescriptor.sync()
- f = File.createTempFile("fd" + platformId, ".tst");
- f.delete();
- fos = new FileOutputStream(f.getPath());
- fos.write("Test String".getBytes());
- fis = new FileInputStream(f.getPath());
- FileDescriptor fd = fos.getFD();
- fd.sync();
- int length = "Test String".length();
- assertEquals("Bytes were not written after sync", length, fis
- .available());
-
- // Regression test for Harmony-1494
- fd = fis.getFD();
- fd.sync();
- assertEquals("Bytes were not written after sync", length, fis
- .available());
-
- RandomAccessFile raf = new RandomAccessFile(f, "r");
- fd = raf.getFD();
- fd.sync();
- raf.close();
- }
-
- /**
- * @tests java.io.FileDescriptor#valid()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "valid",
- args = {}
- )
- public void test_valid() {
- // Test for method boolean java.io.FileDescriptor.valid()
- try {
- f = new File(System.getProperty("java.io.tmpdir"), "fd.tst");
- f.delete();
- os = new BufferedOutputStream(fos = new FileOutputStream(f
- .getPath()), 4096);
- FileDescriptor fd = fos.getFD();
- assertTrue("Valid fd returned false", fd.valid());
- os.close();
- assertTrue("Invalid fd returned true", !fd.valid());
- } catch (Exception e) {
- fail("Exception during 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() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- os.close();
- } catch (Exception e) {
- }
- try {
- fis.close();
- } catch (Exception e) {
- }
- try {
- fos.close();
- } catch (Exception e) {
- }
- try {
- f.delete();
- } catch (Exception e) {
- }
- }
-
- protected void doneSuite() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileFilterTest.java b/luni/src/test/java/tests/api/java/io/FileFilterTest.java
deleted file mode 100644
index 68bafc8..0000000
--- a/luni/src/test/java/tests/api/java/io/FileFilterTest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package tests.api.java.io;
-
-import java.io.File;
-import java.io.FileFilter;
-
-import junit.framework.TestCase;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(
- value = FileFilter.class,
- untestedMethods = {
- @TestTargetNew(
- method = "accept",
- args = {File.class},
- level = TestLevel.NOT_FEASIBLE,
- notes = "There are no classes in the current core " +
- "libraries that implement this method."
- )
- }
-)
-public class FileFilterTest extends TestCase {
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileInputStreamTest.java b/luni/src/test/java/tests/api/java/io/FileInputStreamTest.java
deleted file mode 100644
index 2296f26..0000000
--- a/luni/src/test/java/tests/api/java/io/FileInputStreamTest.java
+++ /dev/null
@@ -1,511 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.channels.FileChannel;
-
-import tests.support.Support_PlatformFile;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(
- value = FileInputStream.class,
- untestedMethods = {
- @TestTargetNew(
- method = "finalize",
- args = {},
- level = TestLevel.NOT_FEASIBLE,
- notes = "Hard to test since it requires that the " +
- "garbage collector runs; add test later."
- )
- }
-)
-public class FileInputStreamTest extends junit.framework.TestCase {
-
- public String fileName;
-
- private FileInputStream 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_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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 FileInputStream#FileInputStream(File)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileInputStream",
- args = {File.class}
- )
- public void test_ConstructorLjava_io_File() {
- // Test for method FileInputStream(File)
- try {
- File f = new File(fileName);
- is = new FileInputStream(f);
- is.close();
- } catch (Exception e) {
- fail("Failed to create FileInputStream : " + e.getMessage());
- }
- File f2 = new File("ImprobableFile.42");
- try {
- is = new FileInputStream(f2);
- is.close();
- f2.delete();
- fail("FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- }
- }
-
- /**
- * @tests FileInputStream#FileInputStream(FileDescriptor)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileInputStream",
- args = {FileDescriptor.class}
- )
- public void test_ConstructorLjava_io_FileDescriptor() {
- // Test for method FileInputStream(FileDescriptor)
- try {
- FileOutputStream fos = new FileOutputStream(fileName);
- FileInputStream fis = new FileInputStream(fos.getFD());
- fos.close();
- fis.close();
- } catch (Exception e) {
- fail("Exception during constrcutor test: " + e.toString());
- }
- try {
- FileInputStream fis = new FileInputStream((FileDescriptor) null);
- fis.close();
- fail("NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- }
- }
-
- /**
- * @tests FileInputStream#FileInputStream(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileInputStream",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method FileInputStream(java.lang.String)
- try {
- is = new FileInputStream(fileName);
- is.close();
- } catch (Exception e) {
- fail("Failed to create FileInputStream : " + e.getMessage());
- }
- try {
- is = new FileInputStream("ImprobableFile.42");
- is.close();
- new File("ImprobableFile.42").delete();
- fail("FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- }
- }
-
- /**
- * @tests FileInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "available",
- args = {}
- )
- public void test_available() throws IOException {
- is = new FileInputStream(fileName);
- assertEquals("Test 1: Returned incorrect number of available bytes;",
- fileString.length(), is.available());
- is.close();
- try {
- is.available();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests FileInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException test since this is only thrown" +
- "by a native method.",
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- is = new FileInputStream(fileName);
- is.close();
-
- try {
- is.read();
- fail("Test 1: Read from closed stream succeeded.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests FileInputStream#getChannel()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getChannel",
- args = {}
- )
- public void test_getChannel() {
- // Test for method FileChannel FileInputStream.getChannel()
- FileChannel channel;
- byte[] buffer = new byte[100];
- byte[] stringBytes;
- final int offset = 5;
- boolean equal = true;
-
- try {
- FileInputStream fis = new FileInputStream(fileName);
- channel = fis.getChannel();
- assertNotNull(channel);
- assertTrue("Channel is closed.", channel.isOpen());
-
- // Check that the channel is associated with the input stream.
- channel.position(offset);
- fis.read(buffer, 0, 10);
- stringBytes = fileString.getBytes();
- for (int i = 0; i < 10; i++) {
- equal &= (buffer[i] == stringBytes[i + offset]);
- }
- assertTrue("Channel is not associated with this stream.", equal);
-
- fis.close();
- assertFalse("Channel has not been closed.", channel.isOpen());
- } catch (FileNotFoundException e) {
- fail("Could not find : " + fileName);
- }
-
- catch (IOException e) {
- fail("Exception during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests FileInputStream#getFD()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException check since it is never thrown.",
- method = "getFD",
- args = {}
- )
- public void test_getFD() {
- // Test for method FileDescriptor
- // FileInputStream.getFD()
- try {
-
- FileInputStream fis = new FileInputStream(fileName);
- assertTrue("Returned invalid fd", fis.getFD().valid());
- fis.close();
- assertTrue("Returned invalid fd", !fis.getFD().valid());
- } catch (FileNotFoundException e) {
- fail("Could not find : " + fileName);
- }
- catch (IOException e) {
- fail("Exception during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests FileInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- is = new FileInputStream(fileName);
- int c = is.read();
- assertEquals("Test 1: Read returned incorrect char;",
- fileString.charAt(0), c);
-
- is.close();
- try {
- is.read();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests FileInputStream#read(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {byte[].class}
- )
- public void test_read$B() throws IOException {
- byte[] buf1 = new byte[100];
- is = new FileInputStream(fileName);
- is.skip(3000);
- is.read(buf1);
- is.close();
- assertTrue("Test 1: Failed to read correct data.",
- new String(buf1, 0, buf1.length).equals(
- fileString.substring(3000, 3100)));
-
- is.close();
- try {
- is.read(buf1);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests FileInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() {
- // Test for method int FileInputStream.read(byte [], int, int)
- byte[] buf1 = new byte[100];
- try {
- is = new FileInputStream(fileName);
- is.skip(3000);
- is.read(buf1, 0, buf1.length);
- is.close();
- 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 FileInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument checks.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Exception() throws IOException {
- byte[] buf = null;
- try {
- is = new FileInputStream(fileName);
- is.read(buf, 0, 0);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- buf = new byte[1000];
- try {
- is = new FileInputStream(fileName);
- is.read(buf, -1, 0);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- try {
- is = new FileInputStream(fileName);
- is.read(buf, 0, -1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- try {
- is = new FileInputStream(fileName);
- is.read(buf, -1, -1);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- try {
- is = new FileInputStream(fileName);
- is.read(buf, 0, 1001);
- fail("Test 5: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- try {
- is = new FileInputStream(fileName);
- is.read(buf, 1001, 0);
- fail("Test 6: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- try {
- is = new FileInputStream(fileName);
- is.read(buf, 500, 501);
- fail("Test 7: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- try {
- is = new FileInputStream(fileName);
- is.close();
- is.read(buf, 0, 100);
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- } finally {
- is.close();
- }
- }
-
- /**
- * @tests FileInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() throws IOException {
- byte[] buf1 = new byte[10];
- is = new FileInputStream(fileName);
- is.skip(1000);
- is.read(buf1, 0, buf1.length);
- assertTrue("Test 1: Failed to skip to correct position.",
- new String(buf1, 0, buf1.length).equals(
- fileString.substring(1000, 1010)));
-
- is.close();
- try {
- is.read();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests FileInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that skip(long) method throws IOException if " +
- "this method is called with negative argument.",
- method = "skip",
- args = {long.class}
- )
- public void test_skipNegativeArgumentJ() throws IOException{
-
- FileInputStream fis = new FileInputStream(fileName);
-
- try {
- fis.skip(-5);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected IOException
- } catch (Exception e) {
- fail("Test 2: IOException expected but found: " + e.getMessage());
- }
-
- fis.close();
- }
-
- /**
- * 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("java.io.tmpdir");
- 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 FileOutputStream(fileName);
- fos.write(fileString.getBytes());
- fos.close();
- } 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 {
- if (is != null) {
- is.close();
- }
- new File(fileName).delete();
- } catch (IOException e) {
- // Ignored.
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileNotFoundExceptionTest.java b/luni/src/test/java/tests/api/java/io/FileNotFoundExceptionTest.java
deleted file mode 100644
index f87d647..0000000
--- a/luni/src/test/java/tests/api/java/io/FileNotFoundExceptionTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.FileNotFoundException;
-
-@TestTargetClass(FileNotFoundException.class)
-public class FileNotFoundExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.FileNotFoundException#FileNotFoundException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "FileNotFoundException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new FileNotFoundException();
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.FileNotFoundException#FileNotFoundException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "FileNotFoundException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new FileNotFoundException("Something went wrong.");
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java
deleted file mode 100644
index 39543b4..0000000
--- a/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java
+++ /dev/null
@@ -1,451 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(
- value = FileOutputStream.class,
- untestedMethods = {
- @TestTargetNew(
- method = "finalize",
- args = {},
- level = TestLevel.NOT_FEASIBLE,
- notes = "Hard to test since it requires that the " +
- "garbage collector runs; add test later."
- )
- }
-)
-public class FileOutputStreamTest extends junit.framework.TestCase {
-
- public String fileName;
-
- FileOutputStream fos;
-
- FileInputStream fis;
-
- File f;
-
- String tmpDirName = System.getProperty("java.io.tmpdir");
-
- File tmpDir = new File(tmpDirName);
-
- 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_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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.FileOutputStream#FileOutputStream(java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileOutputStream",
- args = {java.io.File.class}
- )
- public void test_ConstructorLjava_io_File() throws Exception {
- try {
- fos = new FileOutputStream(tmpDir);
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- }
-
- f = new File(fileName = System.getProperty("java.io.tmpdir"), "fos.tst");
- fos = new FileOutputStream(f);
- }
-
- /**
- * @tests java.io.FileOutputStream#FileOutputStream(java.lang.String,
- * boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileOutputStream",
- args = {java.io.File.class, boolean.class}
- )
- public void test_ConstructorLjava_io_FileZ() throws Exception {
- try {
- fos = new FileOutputStream(tmpDir, false);
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- }
-
- f = new File(tmpDirName, "fos.tst");
- fos = new FileOutputStream(f, false);
- fos.write("FZ1".getBytes(), 0, 3);
- fos.close();
- // Append data to existing file
- fos = new FileOutputStream(f, true);
- fos.write(fileString.getBytes());
- fos.close();
- byte[] buf = new byte[fileString.length() + 3];
- fis = new FileInputStream(f);
- fis.read(buf, 0, buf.length);
- assertTrue("Test 2: Failed to create appending stream.", new String(buf, 0,
- buf.length).equals("FZ1" + fileString));
- fis.close();
-
- // Check that the existing file is overwritten
- fos = new FileOutputStream(f, false);
- fos.write("FZ2".getBytes(), 0, 3);
- fos.close();
- fis = new FileInputStream(f);
- int bytesRead = fis.read(buf, 0, buf.length);
- assertTrue("Test 3: Failed to overwrite stream.", new String(buf, 0,
- bytesRead).equals("FZ2"));
- }
-
- /**
- * @tests java.io.FileOutputStream#FileOutputStream(java.io.FileDescriptor)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileOutputStream",
- args = {java.io.FileDescriptor.class}
- )
- public void test_ConstructorLjava_io_FileDescriptor() throws Exception {
- // Test for method java.io.FileOutputStream(java.io.FileDescriptor)
- f = new File(tmpDirName, "fos.tst");
- fileName = f.getAbsolutePath();
- fos = new FileOutputStream(fileName);
- fos.write('l');
- fos.close();
- fis = new FileInputStream(fileName);
- fos = new FileOutputStream(fis.getFD());
- fos.close();
- fis.close();
- }
-
- /**
- * @tests java.io.FileOutputStream#FileOutputStream(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileOutputStream",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() throws Exception {
- try {
- fos = new FileOutputStream(tmpDirName);
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- }
-
- f = new File(tmpDirName, "fos.tst");
- fileName = f.getAbsolutePath();
- fos = new FileOutputStream(fileName);
- }
-
- /**
- * @tests java.io.FileOutputStream#FileOutputStream(java.lang.String,
- * boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileOutputStream",
- args = {java.lang.String.class, boolean.class}
- )
- public void test_ConstructorLjava_lang_StringZ() throws Exception {
- try {
- fos = new FileOutputStream(tmpDirName, true);
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- }
-
- f = new File(tmpDirName, "fos.tst");
- fos = new FileOutputStream(f.getPath(), false);
- fos.write("HI".getBytes(), 0, 2);
- fos.close();
- // Append data to existing file
- fos = new FileOutputStream(f.getPath(), true);
- fos.write(fileString.getBytes());
- fos.close();
- byte[] buf = new byte[fileString.length() + 2];
- fis = new FileInputStream(f.getPath());
- fis.read(buf, 0, buf.length);
- assertTrue("Failed to create appending stream", new String(buf, 0,
- buf.length).equals("HI" + fileString));
- fis.close();
-
- // Check that the existing file is overwritten
- fos = new FileOutputStream(f.getPath(), false);
- fos.write("HI".getBytes(), 0, 2);
- fos.close();
- fis = new FileInputStream(f.getPath());
- int bytesRead = fis.read(buf, 0, buf.length);
- assertTrue("Failed to overwrite stream", new String(buf, 0,
- bytesRead).equals("HI"));
- }
-
- /**
- * @tests java.io.FileOutputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException not checked because it would be thrown" +
- "by a native method.",
- method = "close",
- args = {}
- )
- public void test_close() throws Exception {
- f = new File(System.getProperty("java.io.tmpdir"), "output.tst");
- fos = new FileOutputStream(f.getPath());
- fos.close();
-
- try {
- fos.write(fileString.getBytes());
- fail("Test 1: IOException expected.");
- } catch (java.io.IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FileOutputStream#getFD()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException not checked because it never gets thrown.",
- method = "getFD",
- args = {}
- )
- public void test_getFD() throws Exception {
- // Test for method java.io.FileDescriptor
- // java.io.FileOutputStream.getFD()
- f = new File(fileName = System.getProperty("java.io.tmpdir"), "testfd");
- fileName = f.getAbsolutePath();
- fos = new FileOutputStream(f);
- assertTrue("Returned invalid fd", fos.getFD().valid());
- fos.close();
- assertTrue("Returned invalid fd", !fos.getFD().valid());
- }
-
- /**
- * @tests java.io.FileOutputStream#write(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {byte[].class}
- )
- public void test_write$B() throws Exception {
- // Test for method void java.io.FileOutputStream.write(byte [])
- f = new File(System.getProperty("java.io.tmpdir"), "output.tst");
- fos = new FileOutputStream(f.getPath());
- fos.write(fileString.getBytes());
- fos.close();
- try {
- fos.write(fileString.getBytes());
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- fis = new FileInputStream(f.getPath());
- byte rbytes[] = new byte[4000];
- fis.read(rbytes, 0, fileString.length());
- assertTrue("Test 2: Incorrect string written or read.",
- new String(rbytes, 0, fileString.length()).equals(fileString));
- }
-
- /**
- * @tests java.io.FileOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() throws Exception {
- // Test for method void java.io.FileOutputStream.write(byte [], int,
- // int)
- f = new File(System.getProperty("java.io.tmpdir"), "output.tst");
- fos = new FileOutputStream(f.getPath());
- fos.write(fileString.getBytes(), 0, fileString.length());
- fis = new FileInputStream(f.getPath());
- byte rbytes[] = new byte[4000];
- fis.read(rbytes, 0, fileString.length());
- assertTrue("Incorrect bytes written", new String(rbytes, 0, fileString
- .length()).equals(fileString));
- }
-
- /**
- * @tests java.io.FileOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws IOException {
- // Test for method void java.io.FileOutputStream.write(int)
- f = new File(System.getProperty("java.io.tmpdir"), "output.tst");
- fos = new FileOutputStream(f.getPath());
- fos.write('t');
- fos.close();
- try {
- fos.write(42);
- fail("Test: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- fis = new FileInputStream(f.getPath());
- assertEquals("Test 1: Incorrect char written or read.",
- 't', fis.read());
- }
-
- /**
- * @tests java.io.FileOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument and IOException checks.",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII2() throws Exception {
- f = new File(tmpDirName, "output.tst");
- fos = new FileOutputStream(f.getPath());
-
- try {
- fos.write(null, 0, 0);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {}
-
- try {
- fos.write(new byte[1], -1, 0);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- fos.write(new byte[1], 0, -1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- fos.write(new byte[1], 0, 5);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- fos.write(new byte[10], Integer.MAX_VALUE, 5);
- fail("Test 5: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- fos.write(new byte[10], 5, Integer.MAX_VALUE);
- fail("Test 6: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- fos.close();
- try {
- fos.write(new byte[10], 5, 4);
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- }
-
- /**
- * @tests java.io.FileOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII3() {
- try {
- new FileOutputStream(new FileDescriptor()).write(new byte[1], 0, 0);
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
- }
-
- /**
- * @tests java.io.FileOutputStream#getChannel()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getChannel() method.",
- method = "getChannel",
- args = {}
- )
- @AndroidOnly("The position of the FileChannel for a file opened in " +
- "append mode is 0 for the RI and corresponds to the " +
- "next position to write to on Android.")
- public void test_getChannel() throws Exception {
- // Make sure that system properties are set correctly
- if (tmpDir == null) {
- throw new Exception("System property java.io.tmpdir not defined.");
- }
- File tmpfile = File.createTempFile("FileOutputStream", "tmp");
- tmpfile.deleteOnExit();
- FileOutputStream fos = new FileOutputStream(tmpfile);
- byte[] b = new byte[10];
- for (int i = 10; i < b.length; i++) {
- b[i] = (byte) i;
- }
- fos.write(b);
- fos.flush();
- fos.close();
- FileOutputStream f = new FileOutputStream(tmpfile, true);
- assertEquals(10, f.getChannel().position());
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- try {
- if (f != null)
- f.delete();
- if (fis != null)
- fis.close();
- if (fos != null)
- fos.close();
- } catch (Exception e) {}
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileReaderTest.java b/luni/src/test/java/tests/api/java/io/FileReaderTest.java
deleted file mode 100644
index f16e9ad..0000000
--- a/luni/src/test/java/tests/api/java/io/FileReaderTest.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(FileReader.class)
-public class FileReaderTest extends junit.framework.TestCase {
-
- FileReader br;
-
- BufferedWriter bw;
-
- FileInputStream fis;
-
- File f;
-
- /**
- * @tests java.io.FileReader#FileReader(java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "FileReader",
- args = {java.io.File.class}
- )
- public void test_ConstructorLjava_io_File() {
- // Test for method java.io.FileReader(java.io.File)
- try {
- bw = new BufferedWriter(new FileWriter(f.getPath()));
- bw.write(" After test string", 0, 18);
- bw.close();
- br = new FileReader(f);
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- assertEquals("Test 1: Failed to read correct chars",
- " After test string", new String(buf, 0, r));
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
-
- File noFile = new File(System.getProperty("java.io.tmpdir"), "noreader.tst");
- try {
- br = new FileReader(noFile);
- fail("Test 2: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FileReader#FileReader(java.io.FileDescriptor)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies FileReader(java.io.FileDescriptor) constructor.",
- method = "FileReader",
- args = {java.io.FileDescriptor.class}
- )
- public void test_ConstructorLjava_io_FileDescriptor() {
- // Test for method java.io.FileReader(java.io.FileDescriptor)
- try {
- bw = new BufferedWriter(new FileWriter(f.getPath()));
- bw.write(" After test string", 0, 18);
- bw.close();
- FileInputStream fis = new FileInputStream(f.getPath());
- br = new FileReader(fis.getFD());
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- fis.close();
- assertEquals("Failed to read correct chars",
- " After test string", new String(buf, 0, r));
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
- }
-
- /**
- * @tests java.io.FileReader#FileReader(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "FileReader",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.FileReader(java.lang.String)
- try {
- bw = new BufferedWriter(new FileWriter(f.getPath()));
- bw.write(" After test string", 0, 18);
- bw.close();
- br = new FileReader(f.getPath());
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- assertEquals("Test 1: Failed to read correct chars",
- " After test string", new String(buf, 0, r));
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
-
- try {
- br = new FileReader(System.getProperty("java.io.tmpdir") + "/noreader.tst");
- fail("Test 2: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
-
- f = new File(System.getProperty("java.io.tmpdir"), "reader.tst");
-
- if (f.exists()) {
- if (!f.delete()) {
- fail("Unable to delete test file");
- }
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
-
- try {
- bw.close();
- br.close();
- } catch (Exception e) {
- }
-
- try {
- if (fis != null)
- fis.close();
- } catch (Exception e) {
- }
- f.delete();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileTest.java b/luni/src/test/java/tests/api/java/io/FileTest.java
deleted file mode 100644
index 43332ba..0000000
--- a/luni/src/test/java/tests/api/java/io/FileTest.java
+++ /dev/null
@@ -1,2532 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.ObjectStreamClass;
-import java.io.ObjectStreamField;
-import java.io.RandomAccessFile;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import static tests.support.Support_Exec.javaProcessBuilder;
-import static tests.support.Support_Exec.execAndGetOutput;
-
-@TestTargetClass(File.class)
-public class FileTest extends junit.framework.TestCase {
-
- /** Location to store tests in */
- private File tempDirectory;
-
- /** Temp file that does exist */
- private File tempFile;
-
- /** File separator */
- private String slash = File.separator;
-
- 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_File\nTest_FileDescriptor\nTest_FileInputStream\nTest_FileNotFoundException\nTest_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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";
-
- private static String platformId = "Android"
- + System.getProperty("java.vm.version").replace('.', '-');
-
- {
- // Delete all old temporary files
- File tempDir = new File(System.getProperty("java.io.tmpdir"));
- String[] files = tempDir.list();
- for (int i = 0; i < files.length; i++) {
- File f = new File(tempDir, files[i]);
- if (f.isDirectory()) {
- if (files[i].startsWith("hyts_resources"))
- deleteTempFolder(f);
- }
- if (files[i].startsWith("hyts_") || files[i].startsWith("hyjar_"))
- new File(tempDir, files[i]).delete();
- }
- }
-
- private void deleteTempFolder(File dir) {
- String files[] = dir.list();
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- if (f.isDirectory())
- deleteTempFolder(f);
- else {
- f.delete();
- }
- }
- dir.delete();
-
- }
-
- /**
- * @tests java.io.File#File(java.io.File, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "File",
- args = {java.io.File.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_io_FileLjava_lang_String() throws Exception {
- String error;
- String dirName = System.getProperty("java.io.tmpdir");
- System.setProperty("user.dir", dirName);
-
- File d = new File(dirName);
- File f = new File(d, "input.tst");
- if (!dirName.regionMatches((dirName.length() - 1), slash, 0, 1))
- dirName += slash;
- dirName += "input.tst";
- error = String.format("Test 1: Incorrect file created: %s; %s expected.", f.getPath(), dirName);
- assertTrue(error, f.getPath().equals(dirName));
-
- String fileName = null;
- try {
- f = new File(d, fileName);
- fail("Test 2: NullPointerException expected.");
- } catch (NullPointerException e) {
- }
-
- d = null;
- f = new File(d, "input.tst");
- error = String.format("Test 3: Incorrect file created: %s; %s expected.",
- f.getAbsolutePath(), dirName);
- assertTrue(error, f.getAbsolutePath().equals(dirName));
-
- // Regression test for Harmony-382
- File s = null;
- f = new File("/abc");
- d = new File(s, "/abc");
- assertEquals("Test 4: Incorrect file created;",
- f.getAbsolutePath(), d.getAbsolutePath());
- }
-
- /**
- * @tests java.io.File#File(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies File(java.lang.String) constructor.",
- method = "File",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.File(java.lang.String)
- String fileName = null;
- try {
- new File(fileName);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- }
-
- fileName = System.getProperty("java.io.tmpdir");
- if (!fileName.regionMatches((fileName.length() - 1), slash, 0, 1))
- fileName += slash;
- fileName += "input.tst";
-
- File f = new File(fileName);
- assertTrue("Created incorrect file " + f.getPath(), f.getPath().equals(
- fileName));
- }
-
- /**
- * @tests java.io.File#File(java.lang.String, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "File",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_String() {
- String error;
- String dirName = null;
- String fileName = "input.tst";
-
- String userDir = System.getProperty("java.io.tmpdir");
- System.setProperty("user.dir", userDir);
-
- File f = new File(dirName, fileName);
- if (!userDir.regionMatches((userDir.length() - 1), slash, 0, 1))
- userDir += slash;
- userDir += "input.tst";
- error = String.format("Test 1: Incorrect file created: %s; %s expected.",
- f.getAbsolutePath(), userDir);
- assertTrue(error, f.getAbsolutePath().equals(userDir));
-
- dirName = System.getProperty("java.io.tmpdir");
- fileName = null;
- try {
- f = new File(dirName, fileName);
- fail("Test 2: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- fileName = "input.tst";
- f = new File(dirName, fileName);
- assertTrue("Test 3: Incorrect file created.", f.getPath()
- .equals(userDir));
-
- // Regression test for Harmony-382
- String s = null;
- f = new File("/abc");
- File d = new File(s, "/abc");
- assertEquals("Test 4: Incorrect file created;", d.getAbsolutePath(), f
- .getAbsolutePath());
- assertEquals("Test3: Created Incorrect File", "/abc", f
- .getAbsolutePath());
- }
-
- /**
- * @tests java.io.File#File(java.lang.String, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "File",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_String_112270() {
- File ref1 = new File("/dir1/file1");
-
- File file1 = new File("/", "/dir1/file1");
- assertEquals("wrong result 1: " + file1, ref1.getPath(), file1
- .getPath());
- File file2 = new File("/", "//dir1/file1");
- assertTrue("wrong result 2: " + file2, file2.getPath().equals(
- ref1.getPath()));
- File file3 = new File("\\", "\\dir1\\file1");
- assertTrue("wrong result 3: " + file3, file3.getPath().equals(
- "\\/\\dir1\\file1"));
- File file4 = new File("\\", "\\\\dir1\\file1");
- assertTrue("wrong result 4: " + file4, file4.getPath().equals(
- "\\/\\\\dir1\\file1"));
-
- File ref2 = new File("/lib/content-types.properties");
- File file5 = new File("/", "lib/content-types.properties");
- assertTrue("wrong result 5: " + file5, file5.getPath().equals(
- ref2.getPath()));
-
- }
-
- /**
- * @tests java.io.File#File(java.io.File, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "File",
- args = {java.io.File.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_io_FileLjava_lang_String_112270() {
- File ref1 = new File("/dir1/file1");
-
- File root = new File("/");
- File file1 = new File(root, "/dir1/file1");
- assertTrue("wrong result 1: " + file1, file1.getPath().equals(
- ref1.getPath()));
- File file2 = new File(root, "//dir1/file1");
- assertTrue("wrong result 2: " + file2, file2.getPath().equals(
- ref1.getPath()));
- File file3 = new File(root, "\\dir1\\file1");
- assertTrue("wrong result 3: " + file3, file3.getPath().equals(
- "/\\dir1\\file1"));
- File file4 = new File(root, "\\\\dir1\\file1");
- assertTrue("wrong result 4: " + file4, file4.getPath().equals(
- "/\\\\dir1\\file1"));
-
- File ref2 = new File("/lib/content-types.properties");
- File file5 = new File(root, "lib/content-types.properties");
- assertTrue("wrong result 5: " + file5, file5.getPath().equals(
- ref2.getPath()));
- }
-
- /**
- * @tests java.io.File#File(java.net.URI)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies File(java.net.URI) constructor with incorrect parameter.",
- method = "File",
- args = {java.net.URI.class}
- )
- public void test_ConstructorLjava_net_URI() {
- // Test for method java.io.File(java.net.URI)
- URI uri = null;
- try {
- new File(uri);
- fail("NullPointerException Not Thrown.");
- } catch (NullPointerException e) {
- }
-
- // invalid file URIs
- String[] uris = new String[] { "mailto:user@domain.com", // not
- // hierarchical
- "ftp:///path", // not file scheme
- "//host/path/", // not absolute
- "file://host/path", // non empty authority
- "file:///path?query", // non empty query
- "file:///path#fragment", // non empty fragment
- "file:///path?", "file:///path#" };
-
- for (int i = 0; i < uris.length; i++) {
- try {
- uri = new URI(uris[i]);
- } catch (URISyntaxException e) {
- fail("Unexpected exception:" + e);
- }
- try {
- new File(uri);
- fail("Expected IllegalArgumentException for new File(" + uri
- + ")");
- } catch (IllegalArgumentException e) {
- }
- }
-
- // a valid File URI
- try {
- File f = new File(new URI("file:///pa%20th/another\u20ac/pa%25th"));
- assertTrue("Created incorrect File " + f.getPath(), f.getPath()
- .equals(
- slash + "pa th" + slash + "another\u20ac" + slash
- + "pa%th"));
- } catch (URISyntaxException e) {
- fail("Unexpected exception:" + e);
- } catch (IllegalArgumentException e) {
- fail("Unexpected exception:" + e);
- }
- }
-
- /**
- * @tests java.io.File#canRead()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canRead",
- args = {}
- )
- public void test_canRead() {
- // Test for method boolean java.io.File.canRead()
- // canRead only returns if the file exists so cannot be fully tested.
- File f = new File(System.getProperty("java.io.tmpdir"), platformId
- + "canRead.tst");
- try {
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("canRead returned false", f.canRead());
- f.delete();
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- } finally {
- f.delete();
- }
- }
-
- /**
- * @tests java.io.File#canWrite()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canWrite",
- args = {}
- )
- public void test_canWrite() {
- // Test for method boolean java.io.File.canWrite()
- // canWrite only returns if the file exists so cannot be fully tested.
- File f = new File(System.getProperty("java.io.tmpdir"), platformId
- + "canWrite.tst");
- try {
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("canWrite returned false", f.canWrite());
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- } finally {
- f.delete();
- }
- }
-
- /**
- * @tests java.io.File#compareTo(java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies compareTo(java.io.File) method.",
- method = "compareTo",
- args = {java.io.File.class}
- )
- public void test_compareToLjava_io_File() {
- File f1 = new File("thisFile.file");
- File f2 = new File("thisFile.file");
- File f3 = new File("thatFile.file");
- assertEquals("Equal files did not answer zero for compareTo", 0, f1
- .compareTo(f2));
- assertTrue("f3.compareTo(f1) did not result in value < 0", f3
- .compareTo(f1) < 0);
- assertTrue("f1.compareTo(f3) did not result in vale > 0", f1
- .compareTo(f3) > 0);
- }
-
- /**
- * @tests java.io.File#createNewFile()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checked.",
- method = "createNewFile",
- args = {}
- )
- public void test_createNewFile_EmptyString() {
- File f = new File("");
- try {
- f.createNewFile();
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.File#createNewFile()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "createNewFile",
- args = {}
- )
- public void test_createNewFile() throws IOException {
- // Test for method java.io.File.createNewFile()
- String base = System.getProperty("java.io.tmpdir");
- boolean dirExists = true;
- int numDir = 1;
- File dir = new File(base, String.valueOf(numDir));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number
- // (making
- // it a new directory name.)
- if (dir.exists()) {
- numDir++;
- dir = new File(base, String.valueOf(numDir));
- } else {
- dirExists = false;
- }
- }
-
- // Test for trying to create a file in a directory that does not
- // exist.
- try {
- // Try to create a file in a directory that does not exist
- File f1 = new File(dir, "tempfile.tst");
- f1.createNewFile();
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- dir.mkdir();
-
- File f1 = new File(dir, "tempfile.tst");
- File f2 = new File(dir, "tempfile.tst");
- f1.deleteOnExit();
- f2.deleteOnExit();
- dir.deleteOnExit();
- assertFalse("Test 2: File should not exist.", f1.isFile());
- f1.createNewFile();
- assertTrue("Test 3: File should exist.", f1.isFile());
- assertTrue("Test 4: File should exist.", f2.isFile());
- String dirName = f1.getParent();
- if (!dirName.endsWith(slash))
- dirName += slash;
- assertTrue("Test 5: File saved in the wrong directory.",
- dirName.equals(dir.getPath() + slash));
- assertEquals("Test 6: File saved with incorrect name;",
- "tempfile.tst", f1.getName());
-
- // Test for creating a file that already exists.
- assertFalse("Test 7: File already exists, createNewFile should " +
- "return false.", f2.createNewFile());
-
- // Trying to create an illegal file.
- String sep = File.separator;
- f1 = new File(sep+"a"+sep+".."+sep+".."+sep);
- try {
- f1.createNewFile();
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- f1 = new File(base);
- assertFalse("Test 9: False expected when trying to create an " +
- "existing file", f1.createNewFile());
- }
-
- /**
- * @tests java.io.File#createTempFile(java.lang.String, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "createTempFile",
- args = {java.lang.String.class, java.lang.String.class}
- )
- @AndroidOnly("The RI does not throw an IOException when an illegal" +
- "file prefix is passed to createTempFile.")
- public void test_createTempFileLjava_lang_StringLjava_lang_String() {
- // Test for method java.io.File.createTempFile(String, String)
- // Error protection against using a suffix without a "."?
- File f1 = null;
- File f2 = null;
- try {
- f1 = File.createTempFile("hyts_abc", ".tmp");
- f2 = File.createTempFile("hyts_tf", null);
- String fileLocation = f1.getParent();
- if (!fileLocation.endsWith(slash))
- ;
- fileLocation += slash;
- String tempDir = System.getProperty("java.io.tmpdir");
- if (!tempDir.endsWith(slash))
- tempDir += slash;
- assertTrue(
- "File did not save to the default temporary-file location.",
- fileLocation.equals(tempDir));
-
- // Test to see if correct suffix was used to create the tempfile.
- File currentFile;
- String fileName;
- // Testing two files, one with suffix ".tmp" and one with null
- for (int i = 0; i < 2; i++) {
- currentFile = i == 0 ? f1 : f2;
- fileName = currentFile.getPath();
- assertTrue("File Created With Incorrect Suffix.", fileName
- .endsWith(".tmp"));
- }
-
- // Tests to see if the correct prefix was used to create the
- // tempfiles.
- fileName = f1.getName();
- assertTrue("Test 1: File Created With Incorrect Prefix.", fileName
- .startsWith("hyts_abc"));
- fileName = f2.getName();
- assertTrue("Test 2: File Created With Incorrect Prefix.", fileName
- .startsWith("hyts_tf"));
-
- // Tests for creating a tempfile with a filename shorter than 3
- // characters.
- try {
- File f3 = File.createTempFile("ab", ".tst");
- f3.delete();
- fail("IllegalArgumentException Not Thrown.");
- } catch (IllegalArgumentException e) {
- }
- try {
- File f3 = File.createTempFile("a", ".tst");
- f3.delete();
- fail("IllegalArgumentException Not Thrown.");
- } catch (IllegalArgumentException e) {
- }
- try {
- File f3 = File.createTempFile("", ".tst");
- f3.delete();
- fail("IllegalArgumentException Not Thrown.");
- } catch (IllegalArgumentException e) {
- }
- try {
- // Providing an illegal file prefix.
- File f3 = File.createTempFile("/../../../../../", null);
- f3.delete();
- fail("IOException not thrown");
- } catch (IOException e) {
- }
-
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- } finally {
- if (f1 != null)
- f1.delete();
- if (f2 != null)
- f2.delete();
- }
- }
-
- /**
- * @tests java.io.File#createTempFile(java.lang.String, java.lang.String,
- * java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "createTempFile",
- args = {java.lang.String.class, java.lang.String.class, java.io.File.class}
- )
- public void test_createTempFileLjava_lang_StringLjava_lang_StringLjava_io_File() {
- // Test for method java.io.File.createTempFile(String, String, File)
- File f1 = null;
- File f2 = null;
- String base = System.getProperty("java.io.tmpdir");
- try {
-
- // Test to make sure that the tempfile was saved in the correct
- // location
- // and with the correct prefix/suffix.
- f1 = File.createTempFile("hyts_tf", null, null);
- File dir = new File(base);
- f2 = File.createTempFile("hyts_tf", ".tmp", dir);
- File currentFile;
- String fileLocation;
- String fileName;
- for (int i = 0; i < 2; i++) {
- currentFile = i == 0 ? f1 : f2;
- fileLocation = currentFile.getParent();
- if (!fileLocation.endsWith(slash))
- fileLocation += slash;
- if (!base.endsWith(slash))
- base += slash;
- assertTrue(
- "File not created in the default temporary-file location.",
- fileLocation.equals(base));
- fileName = currentFile.getName();
- assertTrue("File created with incorrect suffix.", fileName
- .endsWith(".tmp"));
- assertTrue("File created with incorrect prefix.", fileName
- .startsWith("hyts_tf"));
- currentFile.delete();
- }
-
- // Test for creating a tempfile in a directory that does not exist.
- int dirNumber = 1;
- boolean dirExists = true;
- // Set dir to a non-existent directory inside the temporary
- // directory
- dir = new File(base, String.valueOf(dirNumber));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number
- // (making it
- // a new directory name.)
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
- try {
- // Try to create a file in a directory that does not exist
- File f3 = File.createTempFile("hyts_tf", null, dir);
- f3.delete();
- fail("IOException not thrown");
- } catch (IOException e) {
- }
- dir.delete();
-
- // Tests for creating a tempfile with a filename shorter than 3
- // characters.
- try {
- File f4 = File.createTempFile("ab", null, null);
- f4.delete();
- fail("IllegalArgumentException not thrown.");
- } catch (IllegalArgumentException e) {
- }
- try {
- File f4 = File.createTempFile("a", null, null);
- f4.delete();
- fail("IllegalArgumentException not thrown.");
- } catch (IllegalArgumentException e) {
- }
- try {
- File f4 = File.createTempFile("", null, null);
- f4.delete();
- fail("IllegalArgumentException not thrown.");
- } catch (IllegalArgumentException e) {
- }
-
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- } finally {
- if (f1 != null)
- f1.delete();
- if (f2 != null)
- f1.delete();
- }
- }
-
- /**
- * @tests java.io.File#delete()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "delete",
- args = {}
- )
- public void test_delete() {
- // Test for method boolean java.io.File.delete()
- try {
- File dir = new File(System.getProperty("java.io.tmpdir"), platformId
- + "filechk");
- dir.mkdir();
- assertTrue("Directory Does Not Exist", dir.exists()
- && dir.isDirectory());
- File f = new File(dir, "filechk.tst");
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("Error Creating File For Delete Test", f.exists());
- dir.delete();
- assertTrue("Directory Should Not Have Been Deleted.", dir.exists());
- f.delete();
- assertTrue("File Was Not Deleted", !f.exists());
- dir.delete();
- assertTrue("Directory Was Not Deleted", !dir.exists());
- } catch (IOException e) {
- fail("Unexpected IOException During Delete Test : "
- + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#equals(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies equals() method.",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void test_equalsLjava_lang_Object() {
- // Test for method boolean java.io.File.equals(java.lang.Object)
- File f1 = new File("filechk.tst");
- File f2 = new File("filechk.tst");
- File f3 = new File("xxxx");
-
- assertTrue("Equality test failed", f1.equals(f2));
- assertTrue("Files Should Not Return Equal.", !f1.equals(f3));
-
- f3 = new File("FiLeChK.tst");
- boolean onWindows = File.separatorChar == '\\';
- boolean onUnix = File.separatorChar == '/';
- if (onWindows)
- assertTrue("Files Should Return Equal.", f1.equals(f3));
- else if (onUnix)
- assertTrue("Files Should NOT Return Equal.", !f1.equals(f3));
-
- try {
- f1 = new File(System.getProperty("java.io.tmpdir"), "casetest.tmp");
- f2 = new File(System.getProperty("java.io.tmpdir"), "CaseTest.tmp");
- new FileOutputStream(f1).close(); // create the file
- if (f1.equals(f2)) {
- try {
- new FileInputStream(f2);
- } catch (IOException e) {
- fail("File system is case sensitive");
- }
- } else {
- boolean exception = false;
- try {
- new FileInputStream(f2);
- } catch (IOException e) {
- exception = true;
- }
- assertTrue("File system is case insensitive", exception);
- }
- f1.delete();
- } catch (IOException e) {
- fail("Unexpected using case sensitive test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#exists()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "exists",
- args = {}
- )
- public void test_exists() {
- // Test for method boolean java.io.File.exists()
- try {
- File f = new File(System.getProperty("java.io.tmpdir"), platformId
- + "exists.tst");
- assertTrue("Exists returned true for non-existent file", !f
- .exists());
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("Exists returned false file", f.exists());
- f.delete();
- } catch (IOException e) {
- fail("Unexpected IOException During Test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#getAbsoluteFile()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "getAbsoluteFile",
- args = {}
- )
- public void test_getAbsoluteFile() {
- // Test for method java.io.File getAbsoluteFile()
- String base = System.getProperty("java.io.tmpdir");
- if (!base.endsWith(slash))
- base += slash;
- File f = new File(base, "temp.tst");
- File f2 = f.getAbsoluteFile();
- assertEquals("Test 1: Incorrect File Returned.", 0, f2.compareTo(f
- .getAbsoluteFile()));
- f = new File(base + "Temp" + slash + slash + "temp.tst");
- f2 = f.getAbsoluteFile();
- assertEquals("Test 2: Incorrect File Returned.", 0, f2.compareTo(f
- .getAbsoluteFile()));
- f = new File(base + slash + ".." + slash + "temp.tst");
- f2 = f.getAbsoluteFile();
- assertEquals("Test 3: Incorrect File Returned.", 0, f2.compareTo(f
- .getAbsoluteFile()));
- f.delete();
- f2.delete();
- }
-
- /**
- * @tests java.io.File#getAbsolutePath()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "getAbsolutePath",
- args = {}
- )
- public void test_getAbsolutePath() {
- // Test for method java.lang.String java.io.File.getAbsolutePath()
- String base = System.getProperty("java.io.tmpdir");
- if (!base.regionMatches((base.length() - 1), slash, 0, 1))
- base += slash;
- File f = new File(base, "temp.tst");
- assertTrue("Test 1: Incorrect path returned.", f.getAbsolutePath()
- .equals(base + "temp.tst"));
- f = new File(base + "Temp" + slash + slash + slash + "Testing" + slash
- + "temp.tst");
- assertTrue("Test 2: Incorrect path returned.", f.getAbsolutePath()
- .equals(base + "Temp" + slash + "Testing" + slash + "temp.tst"));
- f = new File(base + "a" + slash + slash + ".." + slash + "temp.tst");
- assertTrue("Test 3: Incorrect path returned." + f.getAbsolutePath(), f
- .getAbsolutePath().equals(
- base + "a" + slash + ".." + slash + "temp.tst"));
- f.delete();
- }
-
- /**
- * @tests java.io.File#getCanonicalFile()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException not checked since it may only occur if" +
- "the native access to the filesystem fails.",
- method = "getCanonicalFile",
- args = {}
- )
- public void test_getCanonicalFile() {
- // Test for method java.io.File.getCanonicalFile()
- try {
- String base = System.getProperty("java.io.tmpdir");
- if (!base.endsWith(slash))
- base += slash;
- File f = new File(base, "temp.tst");
- File f2 = f.getCanonicalFile();
- assertEquals("Test 1: Incorrect file returned.", 0, f2
- .getCanonicalFile().compareTo(f.getCanonicalFile()));
- f = new File(base + "Temp" + slash + slash + "temp.tst");
- f2 = f.getCanonicalFile();
- assertEquals("Test 2: Incorrect file returned.", 0, f2
- .getCanonicalFile().compareTo(f.getCanonicalFile()));
- f = new File(base + "Temp" + slash + slash + ".." + slash
- + "temp.tst");
- f2 = f.getCanonicalFile();
- assertEquals("Test 3: Incorrect file returned.", 0, f2
- .getCanonicalFile().compareTo(f.getCanonicalFile()));
-
- // Test for when long directory/file names in Windows
- boolean onWindows = File.separatorChar == '\\';
- // String userDir = System.getProperty("java.io.tmpdir");
- if (onWindows) {
- File testdir = new File(base, "long-" + platformId);
- testdir.mkdir();
- File dir = new File(testdir, "longdirectory" + platformId);
- try {
- dir.mkdir();
- f = new File(dir, "longfilename.tst");
- f2 = f.getCanonicalFile();
- assertEquals("Test 4: Incorrect file returned.",
- 0, f2.getCanonicalFile().compareTo(
- f.getCanonicalFile()));
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- f2 = new File(testdir + slash + "longdi~1" + slash
- + "longfi~1.tst");
- File canonicalf2 = f2.getCanonicalFile();
- /*
- * If the "short file name" doesn't exist, then assume that
- * the 8.3 file name compatibility is disabled.
- */
- if (canonicalf2.exists()) {
- assertTrue("Test 5: Incorrect file returned: "
- + canonicalf2, canonicalf2.compareTo(f
- .getCanonicalFile()) == 0);
- }
- } finally {
- f.delete();
- f2.delete();
- dir.delete();
- testdir.delete();
- }
- }
- } catch (IOException e) {
- fail ("Unexpected IOException during Test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#getCanonicalPath()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException not checked since it may only occur if" +
- "the native access to the filesystem fails.",
- method = "getCanonicalPath",
- args = {}
- )
- public void test_getCanonicalPath() {
- // Test for method java.lang.String java.io.File.getCanonicalPath()
- // Should work for Unix/Windows.
- String dots = "..";
- String expected;
- String error;
- String tmpDir = System.getProperty("java.io.tmpdir");
- System.setProperty("user.dir", tmpDir);
- try {
- String base = new File(tmpDir).getCanonicalPath();
- if (!base.regionMatches((base.length() - 1), slash, 0, 1))
- base += slash;
- File f = new File(base, "temp.tst");
- assertEquals("Test 1: Incorrect Path Returned.", base + "temp.tst", f
- .getCanonicalPath());
- f = new File(base + "Temp" + slash + dots + slash + "temp.tst");
- assertEquals("Test 2: Incorrect Path Returned.", base + "temp.tst", f
- .getCanonicalPath());
-
- // Finding a non-existent directory for tests 3 and 4
- // This is necessary because getCanonicalPath is case sensitive and
- // could
- // cause a failure in the test if the directory exists but with
- // different
- // case letters (e.g "Temp" and "temp")
- int dirNumber = 1;
- boolean dirExists = true;
- File dir1 = new File(base, String.valueOf(dirNumber));
- while (dirExists) {
- if (dir1.exists()) {
- dirNumber++;
- dir1 = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
- f = new File(base + dirNumber + slash + dots + slash + dirNumber + slash
- + "temp.tst");
- assertEquals("Test 3: Incorrect path returned.", base + dirNumber + slash
- + "temp.tst", f.getCanonicalPath());
- f = new File(base + dirNumber + slash + "Temp" + slash + dots + slash + "Test"
- + slash + "temp.tst");
- assertEquals("Test 4: Incorrect path returned.", base + dirNumber + slash + "Test"
- + slash + "temp.tst", f.getCanonicalPath());
-
- // Check that the implicit "user.dir" in a relative path gets canonicalized.
- f = new File("1234.567");
- File expectedFile = new File(System.getProperty("user.dir"), "1234.567");
- assertEquals(expectedFile.getCanonicalPath(), f.getCanonicalPath());
- } catch (IOException e) {
- fail("Unexpected IOException During Test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#getName()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getName() method.",
- method = "getName",
- args = {}
- )
- public void test_getName() {
- // Test for method java.lang.String java.io.File.getName()
- File f = new File("name.tst");
- assertEquals("Test 1: Returned incorrect name",
- "name.tst", f.getName());
-
- f = new File("");
- assertTrue("Test 2: Returned incorrect name", f.getName().equals(""));
-
- f.delete();
- }
-
- /**
- * @tests java.io.File#getParent()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getParent() method.",
- method = "getParent",
- args = {}
- )
- public void test_getParent() throws Exception {
- // Test for method java.lang.String java.io.File.getParent()
- String dir = System.getProperty("java.io.tmpdir");
- if (dir == null)
- throw new Exception("System property java.io.tmpdir not defined.");
-
- File f = new File("p.tst");
- assertNull("Test 1: Incorrect path returned", f.getParent());
- f = new File(dir, "p.tst");
- assertTrue("Test 2: Incorrect path returned",
- f.getParent().equals(dir));
- try {
- f.delete();
- } catch (Exception e) {
- fail("Unexpected exception during tests : " + e.getMessage());
- }
-
- File f1 = new File("/directory");
- assertTrue("Wrong parent test 1", f1.getParent().equals(slash));
- f1 = new File("/directory/file");
- assertTrue("Wrong parent test 2", f1.getParent().equals(
- slash + "directory"));
- f1 = new File("directory/file");
- assertEquals("Wrong parent test 3", "directory", f1.getParent());
- f1 = new File("/");
- assertNull("Wrong parent test 4", f1.getParent());
- f1 = new File("directory");
- assertNull("Wrong parent test 5", f1.getParent());
-
- if (File.separatorChar == '\\' && new File("d:/").isAbsolute()) {
- f1 = new File("d:/directory");
- assertTrue("Wrong parent test 1a", f1.getParent().equals(
- "d:" + slash));
- f1 = new File("d:/directory/file");
- assertTrue("Wrong parent test 2a", f1.getParent().equals(
- "d:" + slash + "directory"));
- f1 = new File("d:directory/file");
- assertEquals("Wrong parent test 3a",
- "d:directory", f1.getParent());
- f1 = new File("d:/");
- assertNull("Wrong parent test 4a", f1.getParent());
- f1 = new File("d:directory");
- assertEquals("Wrong parent test 5a", "d:", f1.getParent());
- }
- }
-
- /**
- * @tests java.io.File#getParentFile()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getParentFile() method.",
- method = "getParentFile",
- args = {}
- )
- public void test_getParentFile() {
- // Test for method java.io.File.getParentFile()
- File f = new File("tempfile.tst");
- assertNull("Incorrect path returned", f.getParentFile());
- f = new File(System.getProperty("java.io.tmpdir"), "tempfile1.tmp");
- File f2 = new File(System.getProperty("java.io.tmpdir"), "tempfile2.tmp");
- File f3 = new File(System.getProperty("java.io.tmpdir"), "/a/tempfile.tmp");
- assertEquals("Incorrect file returned", 0, f.getParentFile().compareTo(
- f2.getParentFile()));
- assertTrue("Incorrect file returned", f.getParentFile().compareTo(
- f3.getParentFile()) != 0);
- f.delete();
- f2.delete();
- f3.delete();
- }
-
- /**
- * @tests java.io.File#getPath()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getPath() method.",
- method = "getPath",
- args = {}
- )
- public void test_getPath() {
- System.setProperty("user.dir", System.getProperty("java.io.tmpdir"));
- String base = System.getProperty("user.dir");
- String fname;
- File f1;
- if (!base.regionMatches((base.length() - 1), slash, 0, 1))
- base += slash;
- fname = base + "filechk.tst";
- f1 = new File(base, "filechk.tst");
- File f2 = new File("filechk.tst");
- File f3 = new File("c:");
- File f4 = new File(base + "a" + slash + slash + ".." + slash
- + "filechk.tst");
- assertTrue("getPath returned incorrect path(f1) " + f1.getPath(), f1
- .getPath().equals(fname));
- assertTrue("getPath returned incorrect path(f2) " + f2.getPath(), f2
- .getPath().equals("filechk.tst"));
- assertTrue("getPath returned incorrect path(f3) " + f3.getPath(), f3
- .getPath().equals("c:"));
- assertTrue("getPath returned incorrect path(f4) " + f4.getPath(), f4
- .getPath().equals(
- base + "a" + slash + ".." + slash + "filechk.tst"));
- f1.delete();
- f2.delete();
- f3.delete();
- f4.delete();
- }
-
- /**
- * @tests java.io.File#isAbsolute()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies isAbsolute() method.",
- method = "isAbsolute",
- args = {}
- )
- public void test_isAbsolute() {
- // Test for method boolean java.io.File.isAbsolute()
- if (File.separatorChar == '\\') {
- File f = new File("c:\\test");
- File f1 = new File("\\test");
- // One or the other should be absolute on Windows or CE
- assertTrue("Absolute returned false", (f.isAbsolute() && !f1
- .isAbsolute())
- || (!f.isAbsolute() && f1.isAbsolute()));
- } else {
- File f = new File("/test");
- assertTrue("Absolute returned false", f.isAbsolute());
- }
- assertTrue("Non-Absolute returned true", !new File("../test")
- .isAbsolute());
- }
-
- /**
- * @tests java.io.File#isDirectory()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "isDirectory",
- args = {}
- )
- public void test_isDirectory() {
- // Test for method boolean java.io.File.isDirectory()
-
- String base = System.getProperty("java.io.tmpdir");
- if (!base.regionMatches((base.length() - 1), slash, 0, 1))
- base += slash;
- File f = new File(base);
- assertTrue("Test 1: Directory returned false", f.isDirectory());
- f = new File(base + "zxzxzxz" + platformId);
- assertTrue("Test 2: (Not created) directory returned true.", !f
- .isDirectory());
- f.mkdir();
- try {
- assertTrue("Test 3: Directory returned false.", f.isDirectory());
- } finally {
- f.delete();
- }
- }
-
- /**
- * @tests java.io.File#isFile()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "isFile",
- args = {}
- )
- public void test_isFile() {
- // Test for method boolean java.io.File.isFile()
- try {
- String base = System.getProperty("java.io.tmpdir");
- File f = new File(base);
- assertTrue("Directory returned true as being a file.", !f.isFile());
- if (!base.regionMatches((base.length() - 1), slash, 0, 1))
- base += slash;
- f = new File(base, platformId + "amiafile");
- assertTrue("Non-existent file returned true", !f.isFile());
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("File returned false", f.isFile());
- f.delete();
- } catch (IOException e) {
- fail("IOException during isFile " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#isHidden()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "isHidden",
- args = {}
- )
- public void test_isHidden() {
- // Test for method boolean java.io.File.isHidden()
- boolean onUnix = File.separatorChar == '/';
-
- try {
- File f = File.createTempFile("hyts_", ".tmp");
- // On Unix hidden files are marked with a "." at the beginning
- // of the file name.
- if (onUnix) {
- File f2 = new File(System.getProperty("java.io.tmpdir"), ".test.tst" + platformId);
- FileOutputStream fos2 = new FileOutputStream(f2);
- fos2.close();
- assertTrue("File returned hidden on Unix", !f.isHidden());
- assertTrue("File returned visible on Unix", f2.isHidden());
- assertTrue("File did not delete.", f2.delete());
- } else {
- // For windows, the file is being set hidden by the attrib
- // command.
- Runtime r = Runtime.getRuntime();
- assertTrue("File returned hidden", !f.isHidden());
- Process p = r.exec("attrib +h \"" + f.getAbsolutePath() + "\"");
- p.waitFor();
- assertTrue("File returned visible", f.isHidden());
- p = r.exec("attrib -h \"" + f.getAbsolutePath() + "\"");
- p.waitFor();
- assertTrue("File returned hidden", !f.isHidden());
- }
- f.delete();
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } catch (InterruptedException e) {
- fail("Unexpected InterruptedException during test : "
- + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#lastModified()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "lastModified",
- args = {}
- )
- public void test_lastModified() {
- // Test for method long java.io.File.lastModified()
- try {
- File f = new File(System.getProperty("java.io.tmpdir"), platformId
- + "lModTest.tst");
- f.delete();
- long lastModifiedTime = f.lastModified();
- assertEquals("LastModified Time Should Have Returned 0.",
- 0, lastModifiedTime);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- f.setLastModified(315550800000L);
- lastModifiedTime = f.lastModified();
- assertTrue("LastModified Time Incorrect: " + lastModifiedTime,
- lastModifiedTime == 315550800000L);
- f.delete();
-
- // Regression for Harmony-2146
- f = new File("/../");
- assertTrue(f.lastModified() > 0);
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#length()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "length",
- args = {}
- )
- public void test_length() throws Exception {
- // Test for method long java.io.File.length()
- try {
- File f = new File(System.getProperty("java.io.tmpdir"), platformId
- + "input.tst");
- assertEquals("File length should have returned 0.", 0, f.length());
- FileOutputStream fos = new FileOutputStream(f);
- fos.write(fileString.getBytes());
- fos.close();
- assertTrue("Incorrect file length returned: " + f.length(), f
- .length() == fileString.length());
- f.delete();
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- }
-
- // regression test for Harmony-1497
- File f = File.createTempFile("cts", ".tmp");
- f.deleteOnExit();
- RandomAccessFile raf = new RandomAccessFile(f, "rwd");
- raf.write(0x41);
- assertEquals(1, f.length());
- }
-
- /**
- * @tests java.io.File#list()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "list",
- args = {}
- )
- public void test_list() {
- // Test for method java.lang.String [] java.io.File.list()
-
- String base = System.getProperty("java.io.tmpdir");
- // Old test left behind "garbage files" so this time it creates a
- // directory
- // that is guaranteed not to already exist (and deletes it afterward.)
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = null;
- dir = new File(base, platformId + String.valueOf(dirNumber));
- while (dirExists) {
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- String[] flist = dir.list();
-
- assertNull("Method list() Should Have Returned null.", flist);
-
- assertTrue("Could not create parent directory for list test", dir
- .mkdir());
-
- String[] files = { "mtzz1.xx", "mtzz2.xx", "mtzz3.yy", "mtzz4.yy" };
- try {
- assertEquals("Method list() Should Have Returned An Array Of Length 0.",
- 0, dir.list().length);
-
- File file = new File(dir, "notADir.tst");
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.close();
- assertNull(
- "listFiles Should Have Returned Null When Used On A File Instead Of A Directory.",
- file.list());
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } finally {
- file.delete();
- }
-
- try {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- }
-
- flist = dir.list();
- if (flist.length != files.length) {
- fail("Incorrect list returned");
- }
-
- // Checking to make sure the correct files were are listed in the
- // array.
- boolean[] check = new boolean[flist.length];
- for (int i = 0; i < check.length; i++)
- check[i] = false;
- for (int i = 0; i < files.length; i++) {
- for (int j = 0; j < flist.length; j++) {
- if (flist[j].equals(files[i])) {
- check[i] = true;
- break;
- }
- }
- }
- int checkCount = 0;
- for (int i = 0; i < check.length; i++) {
- if (check[i] == false)
- checkCount++;
- }
- assertEquals("Invalid file returned in listing", 0, checkCount);
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
-
- assertTrue("Could not delete parent directory for list test.", dir
- .delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- dir.delete();
- }
-
- }
-
- /**
- * @tests java.io.File#listFiles()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "listFiles",
- args = {}
- )
- public void test_listFiles() {
- // Test for method java.io.File.listFiles()
-
- try {
- String base = System.getProperty("java.io.tmpdir");
- // Finding a non-existent directory to create.
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = new File(base, platformId + String.valueOf(dirNumber));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number
- // (making
- // it a new directory name.)
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
- // Test for attempting to cal listFiles on a non-existent directory.
- assertNull("listFiles Should Return Null.", dir.listFiles());
-
- assertTrue("Failed To Create Parent Directory.", dir.mkdir());
-
- String[] files = { "1.tst", "2.tst", "3.tst", "" };
- try {
- assertEquals("listFiles Should Return An Array Of Length 0.", 0, dir
- .listFiles().length);
-
- File file = new File(dir, "notADir.tst");
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.close();
- assertNull(
- "listFiles Should Have Returned Null When Used On A File Instead Of A Directory.",
- file.listFiles());
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } finally {
- file.delete();
- }
-
- for (int i = 0; i < (files.length - 1); i++) {
- File f = new File(dir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
-
- new File(dir, "doesNotExist.tst");
- File[] flist = dir.listFiles();
-
- // Test to make sure that only the 3 files that were created are
- // listed.
- assertEquals("Incorrect Number Of Files Returned.",
- 3, flist.length);
-
- // Test to make sure that listFiles can read hidden files.
- boolean onUnix = File.separatorChar == '/';
- boolean onWindows = File.separatorChar == '\\';
- if (onWindows) {
- files[3] = "4.tst";
- File f = new File(dir, "4.tst");
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- Runtime r = Runtime.getRuntime();
- Process p = r.exec("attrib +h \"" + f.getPath() + "\"");
- p.waitFor();
- }
- if (onUnix) {
- files[3] = ".4.tst";
- File f = new File(dir, ".4.tst");
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
- flist = dir.listFiles();
- assertEquals("Incorrect Number Of Files Returned.",
- 4, flist.length);
-
- // Checking to make sure the correct files were are listed in
- // the array.
- boolean[] check = new boolean[flist.length];
- for (int i = 0; i < check.length; i++)
- check[i] = false;
- for (int i = 0; i < files.length; i++) {
- for (int j = 0; j < flist.length; j++) {
- if (flist[j].getName().equals(files[i])) {
- check[i] = true;
- break;
- }
- }
- }
- int checkCount = 0;
- for (int i = 0; i < check.length; i++) {
- if (check[i] == false)
- checkCount++;
- }
- assertEquals("Invalid file returned in listing", 0, checkCount);
-
- if (onWindows) {
- Runtime r = Runtime.getRuntime();
- Process p = r.exec("attrib -h \""
- + new File(dir, files[3]).getPath() + "\"");
- p.waitFor();
- }
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- assertTrue("Parent Directory Not Deleted.", dir.delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- dir.delete();
- }
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } catch (InterruptedException e) {
- fail("Unexpected InterruptedException during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#listFiles(java.io.FileFilter)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "listFiles",
- args = {java.io.FileFilter.class}
- )
- public void test_listFilesLjava_io_FileFilter() {
- // Test for method java.io.File.listFiles(File Filter filter)
-
- String base = System.getProperty("java.io.tmpdir");
- // Finding a non-existent directory to create.
- int dirNumber = 1;
- boolean dirExists = true;
- File baseDir = new File(base, platformId + String.valueOf(dirNumber));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number (making
- // it a new directory name.)
- if (baseDir.exists()) {
- dirNumber++;
- baseDir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- // Creating a filter that catches directories.
- FileFilter dirFilter = new FileFilter() {
- public boolean accept(File f) {
- if (f.isDirectory())
- return true;
- else
- return false;
- }
- };
-
- assertNull("listFiles Should Return Null.", baseDir
- .listFiles(dirFilter));
-
- assertTrue("Failed To Create Parent Directory.", baseDir.mkdir());
-
- File dir1 = null;
- String[] files = { "1.tst", "2.tst", "3.tst" };
- try {
- assertEquals("listFiles Should Return An Array Of Length 0.", 0, baseDir
- .listFiles(dirFilter).length);
-
- File file = new File(baseDir, "notADir.tst");
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.close();
- assertNull(
- "listFiles Should Have Returned Null When Used On A File Instead Of A Directory.",
- file.listFiles(dirFilter));
- } catch (IOException e) {
- fail("Unexpected IOException During Test.");
- } finally {
- file.delete();
- }
-
- try {
- for (int i = 0; i < files.length; i++) {
- File f = new File(baseDir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- }
- dir1 = new File(baseDir, "Temp1");
- dir1.mkdir();
-
- // Creating a filter that catches files.
- FileFilter fileFilter = new FileFilter() {
- public boolean accept(File f) {
- if (f.isFile())
- return true;
- else
- return false;
- }
- };
-
- // Test to see if the correct number of directories are returned.
- File[] directories = baseDir.listFiles(dirFilter);
- assertEquals("Incorrect Number Of Directories Returned.",
- 1, directories.length);
-
- // Test to see if the directory was saved with the correct name.
- assertEquals("Incorrect Directory Returned.", 0, directories[0]
- .compareTo(dir1));
-
- // Test to see if the correct number of files are returned.
- File[] flist = baseDir.listFiles(fileFilter);
- assertTrue("Incorrect Number Of Files Returned.",
- flist.length == files.length);
-
- // Checking to make sure the correct files were are listed in the
- // array.
- boolean[] check = new boolean[flist.length];
- for (int i = 0; i < check.length; i++)
- check[i] = false;
- for (int i = 0; i < files.length; i++) {
- for (int j = 0; j < flist.length; j++) {
- if (flist[j].getName().equals(files[i])) {
- check[i] = true;
- break;
- }
- }
- }
- int checkCount = 0;
- for (int i = 0; i < check.length; i++) {
- if (check[i] == false)
- checkCount++;
- }
- assertEquals("Invalid file returned in listing", 0, checkCount);
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(baseDir, files[i]);
- f.delete();
- }
- dir1.delete();
- assertTrue("Parent Directory Not Deleted.", baseDir.delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(baseDir, files[i]);
- f.delete();
- }
- if (dir1 != null)
- dir1.delete();
- baseDir.delete();
- }
- }
-
- /**
- * @tests java.io.File#listFiles(java.io.FilenameFilter)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "listFiles",
- args = {java.io.FilenameFilter.class}
- )
- public void test_listFilesLjava_io_FilenameFilter() {
- // Test for method java.io.File.listFiles(FilenameFilter filter)
-
- String base = System.getProperty("java.io.tmpdir");
- // Finding a non-existent directory to create.
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = new File(base, platformId + String.valueOf(dirNumber));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number (making
- // it a new directory name.)
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, platformId + String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- // Creating a filter that catches "*.tst" files.
- FilenameFilter tstFilter = new FilenameFilter() {
- public boolean accept(File f, String fileName) {
- // If the suffix is ".tst" then send it to the array
- if (fileName.endsWith(".tst"))
- return true;
- else
- return false;
- }
- };
-
- assertNull("listFiles Should Return Null.",
- dir.listFiles(tstFilter));
-
- assertTrue("Failed To Create Parent Directory.", dir.mkdir());
-
- String[] files = { "1.tst", "2.tst", "3.tmp" };
- try {
- assertEquals("listFiles Should Return An Array Of Length 0.", 0, dir
- .listFiles(tstFilter).length);
-
- File file = new File(dir, "notADir.tst");
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.close();
- assertNull(
- "listFiles Should Have Returned Null When Used On A File Instead Of A Directory.",
- file.listFiles(tstFilter));
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } finally {
- file.delete();
- }
-
- try {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
- } catch (IOException e) {
- fail("Unexpected IOException During Test : " + e.getMessage());
- }
-
- // Creating a filter that catches "*.tmp" files.
- FilenameFilter tmpFilter = new FilenameFilter() {
- public boolean accept(File f, String fileName) {
- // If the suffix is ".tmp" then send it to the array
- if (fileName.endsWith(".tmp"))
- return true;
- else
- return false;
- }
- };
-
- // Tests to see if the correct number of files were returned.
- File[] flist = dir.listFiles(tstFilter);
- assertEquals("Incorrect Number Of Files Passed Through tstFilter.",
- 2, flist.length);
- for (int i = 0; i < flist.length; i++)
- assertTrue("File Should Not Have Passed The tstFilter.",
- flist[i].getPath().endsWith(".tst"));
-
- flist = dir.listFiles(tmpFilter);
- assertEquals("Incorrect Number Of Files Passed Through tmpFilter.",
- 1, flist.length);
- assertTrue("File Should Not Have Passed The tmpFilter.", flist[0]
- .getPath().endsWith(".tmp"));
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- assertTrue("Parent Directory Not Deleted.", dir.delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- dir.delete();
- }
- }
-
- /**
- * @tests java.io.File#list(java.io.FilenameFilter)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "list",
- args = {java.io.FilenameFilter.class}
- )
- public void test_listLjava_io_FilenameFilter() {
- // Test for method java.lang.String []
- // java.io.File.list(java.io.FilenameFilter)
-
- String base = System.getProperty("java.io.tmpdir");
- // Old test left behind "garbage files" so this time it creates a
- // directory
- // that is guaranteed not to already exist (and deletes it afterward.)
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = new File(base, platformId + String.valueOf(dirNumber));
- while (dirExists) {
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- FilenameFilter filter = new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return !name.equals("mtzz1.xx");
- }
- };
-
- String[] flist = dir.list(filter);
- assertNull("Method list(FilenameFilter) Should Have Returned Null.",
- flist);
-
- assertTrue("Could not create parent directory for test", dir.mkdir());
-
- String[] files = { "mtzz1.xx", "mtzz2.xx", "mtzz3.yy", "mtzz4.yy" };
- try {
- /*
- * Do not return null when trying to use list(Filename Filter) on a
- * file rather than a directory. All other "list" methods return
- * null for this test case.
- */
- /*
- * File file = new File(dir, "notADir.tst"); try { FileOutputStream
- * fos = new FileOutputStream(file); fos.close(); } catch
- * (IOException e) { fail("Unexpected IOException During
- * Test."); } flist = dir.list(filter); assertNull("listFiles
- * Should Have Returned Null When Used On A File Instead Of A
- * Directory.", flist); file.delete();
- */
-
- flist = dir.list(filter);
- assertEquals("Array Of Length 0 Should Have Returned.",
- 0, flist.length);
-
- try {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- }
-
- flist = dir.list(filter);
-
- if (flist.length != files.length - 1) {
- fail("Incorrect list returned");
- }
-
- // Checking to make sure the correct files were are listed in the
- // array.
- boolean[] check = new boolean[flist.length];
- for (int i = 0; i < check.length; i++)
- check[i] = false;
- String[] wantedFiles = { "mtzz2.xx", "mtzz3.yy", "mtzz4.yy" };
- for (int i = 0; i < wantedFiles.length; i++) {
- for (int j = 0; j < flist.length; j++) {
- if (flist[j].equals(wantedFiles[i])) {
- check[i] = true;
- break;
- }
- }
- }
- int checkCount = 0;
- for (int i = 0; i < check.length; i++) {
- if (check[i] == false)
- checkCount++;
- }
- assertEquals("Invalid file returned in listing", 0, checkCount);
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- assertTrue("Could not delete parent directory for test.", dir
- .delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- dir.delete();
- }
- }
-
- /**
- * @tests java.io.File#listRoots()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies listRoots() method.",
- method = "listRoots",
- args = {}
- )
- public void test_listRoots() {
- // Test for method java.io.File.listRoots()
-
- File[] roots = File.listRoots();
- boolean onUnix = File.separatorChar == '/';
- boolean onWindows = File.separatorChar == '\\';
- if (onUnix) {
- assertEquals("Incorrect Number Of Root Directories.",
- 1, roots.length);
- String fileLoc = roots[0].getPath();
- assertTrue("Incorrect Root Directory Returned.", fileLoc
- .startsWith(slash));
- } else if (onWindows) {
- // Need better test for Windows
- assertTrue("Incorrect Number Of Root Directories.",
- roots.length > 0);
- }
- }
-
- /**
- * @tests java.io.File#mkdir()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "mkdir",
- args = {}
- )
- public void test_mkdir() throws IOException {
- // Test for method boolean java.io.File.mkdir()
-
- String base = System.getProperty("java.io.tmpdir");
- // Old test left behind "garbage files" so this time it creates a
- // directory
- // that is guaranteed not to already exist (and deletes it afterward.)
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = new File(base, String.valueOf(dirNumber));
- while (dirExists) {
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- assertTrue("mkdir failed", dir.mkdir() && dir.exists());
- dir.deleteOnExit();
-
- String longDirName = "abcdefghijklmnopqrstuvwx";// 24 chars
- StringBuilder sb = new StringBuilder(dir + File.separator);
- StringBuilder sb2 = new StringBuilder(dir + File.separator);
-
- // Test make a long path
- while (dir.getCanonicalPath().length() < 256 - longDirName.length()) {
- sb.append(longDirName + File.separator);
- dir = new File(sb.toString());
- assertTrue("mkdir failed", dir.mkdir() && dir.exists());
- dir.deleteOnExit();
- }
-
- while (dir.getCanonicalPath().length() < 256) {
- sb.append(0);
- dir = new File(sb.toString());
- assertTrue("mkdir " + dir.getCanonicalPath().length() + " failed",
- dir.mkdir() && dir.exists());
- dir.deleteOnExit();
- }
-
- // Test make many paths
- while (dir.getCanonicalPath().length() < 256) {
- sb2.append(0);
- dir = new File(sb2.toString());
- assertTrue("mkdir " + dir.getCanonicalPath().length() + " failed",
- dir.mkdir() && dir.exists());
- dir.deleteOnExit();
- }
- }
-
- /**
- * @tests java.io.File#mkdirs()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "mkdirs",
- args = {}
- )
- public void test_mkdirs() {
- // Test for method boolean java.io.File.mkdirs()
-
- String userHome = System.getProperty("java.io.tmpdir");
- if (!userHome.endsWith(slash))
- userHome += slash;
- File f = new File(userHome + "mdtest" + platformId + slash + "mdtest2",
- "p.tst");
- File g = new File(userHome + "mdtest" + platformId + slash + "mdtest2");
- File h = new File(userHome + "mdtest" + platformId);
- f.mkdirs();
- try {
- assertTrue("Base Directory not created", h.exists());
- assertTrue("Directories not created", g.exists());
- assertTrue("File not created", f.exists());
- } finally {
- f.delete();
- g.delete();
- h.delete();
- }
- }
-
- /**
- * @tests java.io.File#renameTo(java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "renameTo",
- args = {java.io.File.class}
- )
- public void test_renameToLjava_io_File() {
- // Test for method boolean java.io.File.renameTo(java.io.File)
- String base = System.getProperty("java.io.tmpdir");
- File dir = new File(base, platformId);
- dir.mkdir();
- File f = new File(dir, "xxx.xxx");
- File rfile = new File(dir, "yyy.yyy");
- File f2 = new File(dir, "zzz.zzz");
- try {
- FileOutputStream fos = new FileOutputStream(f);
- fos.write(fileString.getBytes());
- fos.close();
- long lengthOfFile = f.length();
-
- rfile.delete(); // in case it already exists
-
- try {
- f.renameTo(null);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- assertTrue("Test 2: File rename failed.", f.renameTo(rfile));
- assertTrue("Test 3: File rename failed.", rfile.exists());
- assertTrue("Test 4: Size Of File Changed.",
- rfile.length() == lengthOfFile);
-
- fos = new FileOutputStream(rfile);
- fos.close();
-
- f2.delete(); // in case it already exists
- assertTrue("Test 5: File rename failed.", rfile.renameTo(f2));
- assertTrue("Test 6: File rename failed.", f2.exists());
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } finally {
- f.delete();
- rfile.delete();
- f2.delete();
- dir.delete();
- }
- }
-
- /**
- * @tests java.io.File#setLastModified(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "setLastModified",
- args = {long.class}
- )
- public void test_setLastModifiedJ() {
- // Test for method java.io.File.setLastModified()
- File f1 = null;
- try {
- // f1 = File.createTempFile("hyts_tf" , ".tmp");
- // jclRM does not include File.createTempFile
- f1 = new File(System.getProperty("java.io.tmpdir"),
- platformId + "hyts_tf_slm.tst");
- f1.createNewFile();
- long orgTime = f1.lastModified();
- // Subtracting 100 000 milliseconds from the orgTime of File f1
- assertTrue(f1.setLastModified(orgTime - 100000));
- long lastModified = f1.lastModified();
- assertTrue("Test 1: LastModifed time incorrect: " + lastModified,
- lastModified == (orgTime - 100000));
- // Subtracting 10 000 000 milliseconds from the orgTime of File f1
- assertTrue(f1.setLastModified(orgTime - 10000000));
- lastModified = f1.lastModified();
- assertTrue("Test 2: LastModifed time incorrect: " + lastModified,
- lastModified == (orgTime - 10000000));
- // Adding 100 000 milliseconds to the orgTime of File f1
- assertTrue(f1.setLastModified(orgTime + 100000));
- lastModified = f1.lastModified();
- assertTrue("Test 3: LastModifed time incorrect: " + lastModified,
- lastModified == (orgTime + 100000));
- // Adding 10 000 000 milliseconds from the orgTime of File f1
- assertTrue(f1.setLastModified(orgTime + 10000000));
- lastModified = f1.lastModified();
- assertTrue("Test 4: LastModifed time incorrect: " + lastModified,
- lastModified == (orgTime + 10000000));
- // Trying to set time to an exact number
- assertTrue(f1.setLastModified(315550800000L));
- lastModified = f1.lastModified();
- assertTrue("Test 5: LastModified time incorrect: " + lastModified,
- lastModified == 315550800000L);
- String osName = System.getProperty("os.name", "unknown");
- if (osName.equals("Windows 2000") || osName.equals("Windows NT")) {
- // Trying to set time to a large exact number
- boolean result = f1.setLastModified(4354837199000L);
- long next = f1.lastModified();
- // Dec 31 23:59:59 EST 2107 is overflow on FAT file systems, and
- // the call fails
- assertTrue("Test 6: LastModified time incorrect: " + next,
- !result || next == 4354837199000L);
- }
- // Trying to set time to a negative number
- try {
- f1.setLastModified(-25);
- fail("IllegalArgumentException not thrown.");
- } catch (IllegalArgumentException e) {
- }
-
- File f2 = new File("/does not exist.txt");
- assertFalse(f2.setLastModified(42));
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } finally {
- if (f1 != null)
- f1.delete();
- }
- }
-
- /**
- * @tests java.io.File#setReadOnly()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "setReadOnly",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canWrite",
- args = {}
- )
- })
- public void test_setReadOnly() {
- // Test for method java.io.File.setReadOnly()
-
- File f1 = null;
- File f2 = null;
- Runtime r = Runtime.getRuntime();
- Process p;
- try {
- f1 = File.createTempFile("hyts_tf", ".tmp");
- f2 = File.createTempFile("hyts_tf", ".tmp");
-
- assertTrue("Test 1: File is read-only." , f1.canWrite());
- f1.setReadOnly();
- assertTrue("Test 2: File is not read-only." , !f1.canWrite());
-
- try {
- // Attempt to write to a file that is read-only.
- new FileOutputStream(f1);
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- p = r.exec("chmod +w " + f1.getAbsolutePath());
- p.waitFor();
-
- assertTrue("Test 4: File is read-only." , f1.canWrite());
- try {
- FileOutputStream fos = new FileOutputStream(f1);
- fos.write(fileString.getBytes());
- fos.close();
- assertTrue("Test 5: Unable to write to the file.",
- f1.length() == fileString.length());
- } catch (IOException e) {
- fail("Test 6: Unexpected IOException while attempting to " +
- "write to the file. " + e);
- }
- assertTrue("Test 7: File has not been deleted.", f1.delete());
-
- // Assert is flawed because canWrite does not work.
- // assertTrue("File f2 Is Set To ReadOnly." , f2.canWrite());
- FileOutputStream fos = new FileOutputStream(f2);
- // Write to a file.
- fos.write(fileString.getBytes());
- fos.close();
- f2.setReadOnly();
- // Assert is flawed because canWrite does not work.
- // assertTrue("File f2 Is Not Set To ReadOnly." , !f2.canWrite());
- try {
- // Attempt to write to a file that has previously been written
- // to.
- // and is now set to read only.
- fos = new FileOutputStream(f2);
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- }
- p = r.exec("chmod +w " + f2.getAbsolutePath());
- p.waitFor();
- assertTrue("Test 9: File is read-only.", f2.canWrite());
- try {
- fos = new FileOutputStream(f2);
- fos.write(fileString.getBytes());
- fos.close();
- } catch (IOException e) {
- fail("Test 10: Unexpected IOException while attempting to " +
- "write to the file. " + e);
- }
- f2.setReadOnly();
- assertTrue("Test 11: File has not been deleted.", f2.delete());
- // Similarly, trying to delete a read-only directory should succeed
- f2 = new File(System.getProperty("java.io.tmpdir"), "deltestdir");
- f2.mkdir();
- f2.setReadOnly();
- assertTrue("Test 12: Directory has not been deleted.",
- f2.delete());
- assertTrue("Test 13: Directory has not been deleted.",
- ! f2.exists());
-
- } catch (IOException e) {
- fail("Test 14: Unexpected IOException: " + e.getMessage());
- } catch (InterruptedException e) {
- fail("Test 15: Unexpected InterruptedException: " + e);
- } finally {
- if (f1 != null)
- f1.delete();
- if (f2 != null)
- f2.delete();
- }
- }
-
- /**
- * @tests java.io.File#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies toString() method.",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.io.File.toString()
- String fileName = System.getProperty("java.io.tmpdir") + slash + "input.tst";
- File f = new File(fileName);
- assertTrue("Incorrect string returned", f.toString().equals(fileName));
-
- if (File.separatorChar == '\\') {
- String result = new File("c:\\").toString();
- assertTrue("Removed backslash: " + result, result.equals("c:\\"));
- }
- }
-
- /**
- * @tests java.io.File#toURI()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies toURI() method.",
- method = "toURI",
- args = {}
- )
- public void test_toURI() {
- // Test for method java.io.File.toURI()
- try {
- // Need a directory that exists
- File dir = new File(System.getProperty("java.io.tmpdir"));
-
- // Test for toURI when the file is a directory.
- String newURIPath = dir.getAbsolutePath();
- newURIPath = newURIPath.replace(File.separatorChar, '/');
- if (!newURIPath.startsWith("/"))
- newURIPath = "/" + newURIPath;
- if (!newURIPath.endsWith("/"))
- newURIPath += '/';
-
- URI uri = dir.toURI();
- assertTrue("Test 1A: Incorrect URI Returned.", new File(uri)
- .equals(dir.getAbsoluteFile()));
- assertTrue("Test 1B: Incorrect URI Returned.", uri.equals(new URI(
- "file", null, newURIPath, null, null)));
-
- // Test for toURI with a file name with illegal chars.
- File f = new File(dir, "te% \u20ac st.tst");
- newURIPath = f.getAbsolutePath();
- newURIPath = newURIPath.replace(File.separatorChar, '/');
- if (!newURIPath.startsWith("/"))
- newURIPath = "/" + newURIPath;
-
- uri = f.toURI();
- assertTrue("Test 2A: Incorrect URI Returned.", new File(uri)
- .equals(f.getAbsoluteFile()));
- assertTrue("Test 2B: Incorrect URI Returned.", uri.equals(new URI(
- "file", null, newURIPath, null, null)));
-
- // Regression test for HARMONY-3207
- dir = new File(""); // current directory
- uri = dir.toURI();
- assertTrue("Test current dir: URI does not end with slash.",
- uri.toString().endsWith("/"));
- } catch (URISyntaxException e1) {
- fail("Unexpected URISyntaxException: " + e1);
- }
- }
-
- /**
- * @tests java.io.File#toURI()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that toURI() method works with URIs created with null parameters.",
- method = "toURI",
- args = {}
- )
- public void test_toURI2() {
-
- File f = new File(System.getProperty("java.io.tmpdir"), "a/b/c/../d/e/./f");
-
- String path = f.getAbsolutePath();
- path = path.replace(File.separatorChar, '/');
- if (!path.startsWith("/"))
- path = "/" + path;
-
- try {
- URI uri1 = new URI("file", null, path, null);
- URI uri2 = f.toURI();
- assertEquals("uris not equal", uri1, uri2);
- } catch (URISyntaxException e1) {
- fail("Unexpected URISyntaxException," + e1);
- }
- }
-
- /**
- * @tests java.io.File#toURL()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "toURL",
- args = {}
- )
- public void test_toURL() {
- // Test for method java.io.File.toURL()
-
- try {
- // Need a directory that exists
- File dir = new File(System.getProperty("java.io.tmpdir"));
-
- // Test for toURL when the file is a directory.
- String newDirURL = dir.getAbsolutePath();
- newDirURL = newDirURL.replace(File.separatorChar, '/');
- if (newDirURL.startsWith("/"))
- newDirURL = "file:" + newDirURL;
- else
- newDirURL = "file:/" + newDirURL;
- if (!newDirURL.endsWith("/"))
- newDirURL += '/';
- assertEquals("Test 1: Incorrect URL returned;", newDirURL,
- dir.toURL().toString());
-
- // Test for toURL with a file.
- File f = new File(dir, "test.tst");
- String newURL = f.getAbsolutePath();
- newURL = newURL.replace(File.separatorChar, '/');
- if (newURL.startsWith("/"))
- newURL = "file:" + newURL;
- else
- newURL = "file:/" + newURL;
- assertEquals("Test 2: Incorrect URL returned;", newURL,
- f.toURL().toString());
- } catch (java.net.MalformedURLException e) {
- fail("Unexpected java.net.MalformedURLException during test.");
- }
- }
-
- /**
- * @tests java.io.File#toURL()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "toURL",
- args = {}
- )
- public void test_toURL2() {
-
- File f = new File(System.getProperty("java.io.tmpdir"), "a/b/c/../d/e/./f");
-
- String path = f.getAbsolutePath();
- path = path.replace(File.separatorChar, '/');
- if (!path.startsWith("/"))
- path = "/" + path;
-
- try {
- URL url1 = new URL("file", "", path);
- URL url2 = f.toURL();
- assertEquals("urls not equal", url1, url2);
- } catch (MalformedURLException e) {
- fail("Unexpected MalformedURLException," + e);
- }
- }
-
- /**
- * @tests java.io.File#toURL()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "toURL",
- args = {}
- )
- @AndroidOnly("Incorrectly fails on the RI.")
- public void test_toURL3() throws MalformedURLException {
- File dir = new File(""); // current directory
- String newDirURL = dir.toURL().toString();
- assertTrue("Test 1: URL does not end with slash.",
- newDirURL.endsWith("/"));
- }
-
- /**
- * @tests java.io.File#deleteOnExit()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "deleteOnExit",
- args = {}
- )
- @AndroidOnly("This test only runs on Android because it instantiates " +
- "a second Dalvik VM.")
- @KnownFailure("Fails in CTS but passes under run-core-tests")
- public void test_deleteOnExit() throws IOException, InterruptedException {
- String cts = System.getProperty("java.io.tmpdir");
- File dir = new File(cts + "/hello");
- dir.mkdir();
- assertTrue(dir.exists());
- File subDir = new File(cts + "/hello/world");
- subDir.mkdir();
- assertTrue(subDir.exists());
-
- URL url = getClass().getResource("/HelloWorld.txt");
- String classPath = url.toString();
- int idx = classPath.indexOf("!");
- assertTrue("could not find the path of the test jar/apk", idx > 0);
- classPath = classPath.substring(9, idx); // cutting off jar:file:
-
- ProcessBuilder builder = javaProcessBuilder();
- builder.command().add("-cp");
- builder.command().add(System.getProperty("java.class.path"));
- builder.command().add("tests.support.Support_DeleteOnExitTest");
- builder.command().add(dir.getAbsolutePath());
- builder.command().add(subDir.getAbsolutePath());
- execAndGetOutput(builder);
-
- assertFalse(dir.exists());
- assertFalse(subDir.exists());
- }
-
- /**
- * @tests serialization
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "regression test",
- method = "!Serialization",
- args = {}
- )
- public void test_objectStreamClass_getFields() throws Exception {
- //Regression for HARMONY-2674
- ObjectStreamClass objectStreamClass = ObjectStreamClass
- .lookup(File.class);
- ObjectStreamField[] objectStreamFields = objectStreamClass.getFields();
- assertEquals(1, objectStreamFields.length);
- ObjectStreamField objectStreamField = objectStreamFields[0];
- assertEquals("path", objectStreamField.getName());
- assertEquals(String.class, objectStreamField.getType());
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() throws Exception {
- super.setUp();
-
- // Make sure that system properties are set correctly
- String userDir = System.getProperty("java.io.tmpdir");
- if (userDir == null)
- throw new Exception("System property java.io.tmpdir not defined.");
- System.setProperty("java.io.tmpdir", userDir);
-
- /** Setup the temporary directory */
- if (!userDir.regionMatches((userDir.length() - 1), slash, 0, 1))
- userDir += slash;
- tempDirectory = new File(userDir + "tempDir"
- + String.valueOf(System.currentTimeMillis()));
- if (!tempDirectory.mkdir())
- System.out.println("Setup for FileTest failed (1).");
-
- /** Setup the temporary file */
- tempFile = new File(tempDirectory, "tempfile");
- FileOutputStream tempStream;
- try {
- tempStream = new FileOutputStream(tempFile.getPath(), false);
- tempStream.close();
- } catch (IOException e) {
- System.out.println("Setup for FileTest failed (2).");
- return;
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
-
- if (tempFile.exists() && !tempFile.delete())
- System.out
- .println("FileTest.tearDown() failed, could not delete file!");
- if (!tempDirectory.delete())
- System.out
- .println("FileTest.tearDown() failed, could not delete directory!");
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileWriterTest.java b/luni/src/test/java/tests/api/java/io/FileWriterTest.java
deleted file mode 100644
index 4f8358c..0000000
--- a/luni/src/test/java/tests/api/java/io/FileWriterTest.java
+++ /dev/null
@@ -1,409 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(FileWriter.class)
-public class FileWriterTest extends junit.framework.TestCase {
-
- FileWriter fw;
-
- FileInputStream fis;
-
- BufferedWriter bw;
-
- File f;
-
- FileOutputStream fos;
-
- BufferedReader br;
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileWriter",
- args = {java.io.File.class}
- )
- public void test_ConstructorLjava_io_File() {
- // Test for method java.io.FileWriter(java.io.File)
- try {
- fos = new FileOutputStream(f.getPath());
- fos.write("Test String".getBytes());
- fos.close();
- bw = new BufferedWriter(new FileWriter(f));
- bw.write(" After test string", 0, 18);
- bw.close();
- br = new BufferedReader(new FileReader(f.getPath()));
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- assertEquals("Failed to write correct chars", " After test string", new String(buf, 0, r)
- );
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "FileWriter",
- args = {java.io.File.class}
- )
- public void test_ConstructorLjava_io_File_IOException() {
- File dir = new File(System.getProperty("java.io.tmpdir"));
-
- try {
- fw = new FileWriter(dir);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.io.File, boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies FileWriter(java.io.File, boolean) constructor.",
- method = "FileWriter",
- args = {java.io.File.class, boolean.class}
- )
- public void test_ConstructorLjava_io_FileZ() throws Exception {
- // Test for method java.io.FileWriter(java.io.File)
- //append = true
- {
- FileWriter fileWriter = new FileWriter(f);
-
- String first = "The first string for testing. ";
- fileWriter.write(first);
- fileWriter.close();
-
- fileWriter = new FileWriter(f, true);
- String second = "The second String for testing.";
- fileWriter.write(second);
- fileWriter.close();
-
- FileReader fileReader = new FileReader(f);
- char[] out = new char[first.length() + second.length() + 10];
- int length = fileReader.read(out);
- fileReader.close();
- assertEquals(first + second, new String(out, 0, length));
- }
- //append = false
- {
- FileWriter fileWriter = new FileWriter(f);
- String first = "The first string for testing. ";
- fileWriter.write(first);
- fileWriter.close();
-
- fileWriter = new FileWriter(f, false);
- String second = "The second String for testing.";
- fileWriter.write(second);
- fileWriter.close();
-
- FileReader fileReader = new FileReader(f);
- char[] out = new char[first.length() + second.length() + 10];
- int length = fileReader.read(out);
- fileReader.close();
- assertEquals(second, new String(out, 0, length));
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.io.File, boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "FileWriter",
- args = {java.io.File.class, boolean.class}
- )
- public void test_ConstructorLjava_io_FileZ_IOException() {
- File dir = new File(System.getProperty("java.io.tmpdir"));
-
- try {
- fw = new FileWriter(dir, true);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.io.FileDescriptor)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies FileWriter(java.io.FileDescriptor) constructor.",
- method = "FileWriter",
- args = {java.io.FileDescriptor.class}
- )
- public void test_ConstructorLjava_io_FileDescriptor() {
- // Test for method java.io.FileWriter(java.io.FileDescriptor)
- try {
- fos = new FileOutputStream(f.getPath());
- fos.write("Test String".getBytes());
- fos.close();
- fis = new FileInputStream(f.getPath());
- br = new BufferedReader(new FileReader(fis.getFD()));
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- fis.close();
- assertTrue("Failed to write correct chars: "
- + new String(buf, 0, r), new String(buf, 0, r)
- .equals("Test String"));
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileWriter",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.FileWriter(java.lang.String)
- try {
- fos = new FileOutputStream(f.getPath());
- fos.write("Test String".getBytes());
- fos.close();
- bw = new BufferedWriter(new FileWriter(f.getPath()));
- bw.write(" After test string", 0, 18);
- bw.close();
- br = new BufferedReader(new FileReader(f.getPath()));
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- assertEquals("Failed to write correct chars", " After test string", new String(buf, 0, r)
- );
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "FileWriter",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String_IOException() {
- try {
- fw = new FileWriter(System.getProperty("java.io.tmpdir"));
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.lang.String, boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileWriter",
- args = {java.lang.String.class, boolean.class}
- )
- public void test_ConstructorLjava_lang_StringZ() {
- // Test for method java.io.FileWriter(java.lang.String, boolean)
-
- try {
- fos = new FileOutputStream(f.getPath());
- fos.write("Test String".getBytes());
- fos.close();
- bw = new BufferedWriter(new FileWriter(f.getPath(), true));
- bw.write(" After test string", 0, 18);
- bw.close();
- br = new BufferedReader(new FileReader(f.getPath()));
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- assertEquals("Failed to append to file", "Test String After test string", new String(buf, 0, r)
- );
-
- fos = new FileOutputStream(f.getPath());
- fos.write("Test String".getBytes());
- fos.close();
- bw = new BufferedWriter(new FileWriter(f.getPath(), false));
- bw.write(" After test string", 0, 18);
- bw.close();
- br = new BufferedReader(new FileReader(f.getPath()));
- buf = new char[100];
- r = br.read(buf);
- br.close();
- assertEquals("Failed to overwrite file", " After test string", new String(buf, 0, r)
- );
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
-
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.lang.String, boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "FileWriter",
- args = {java.lang.String.class, boolean.class}
- )
- public void test_ConstructorLjava_lang_StringZ_IOException() {
- try {
- fw = new FileWriter(System.getProperty("java.io.tmpdir"), false);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_handleEarlyEOFChar_1() {
- String str = "All work and no play makes Jack a dull boy\n";
- int NUMBER = 2048;
- int j = 0;
- int len = str.length() * NUMBER;
- /* == 88064 *//* NUMBER compulsively written copies of the same string */
- char[] strChars = new char[len];
- for (int i = 0; i < NUMBER; ++i) {
- for (int k = 0; k < str.length(); ++k) {
- strChars[j++] = str.charAt(k);
- }
- }
- File f = null;
- FileWriter fw = null;
- try {
- f = File.createTempFile("ony", "by_one");
- fw = new FileWriter(f);
- fw.write(strChars);
- fw.close();
- InputStreamReader in = null;
- FileInputStream fis = new FileInputStream(f);
- in = new InputStreamReader(fis);
- int b;
- int errors = 0;
- for (int offset = 0; offset < strChars.length; ++offset) {
- b = in.read();
- if (b == -1) {
- fail("Early EOF at offset " + offset + "\n");
- return;
- }
- }
- assertEquals(0, errors);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_handleEarlyEOFChar_2() throws IOException {
- int capacity = 65536;
- byte[] bytes = new byte[capacity];
- byte[] bs = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'
- };
- for (int i = 0; i < bytes.length; i++) {
- bytes[i] = bs[i / 8192];
- }
- String inputStr = new String(bytes);
- int len = inputStr.length();
- File f = File.createTempFile("FileWriterBugTest ", null);
- FileWriter writer = new FileWriter(f);
- writer.write(inputStr);
- writer.close();
- long flen = f.length();
-
- FileReader reader = new FileReader(f);
- char[] outChars = new char[capacity];
- int outCount = reader.read(outChars);
- String outStr = new String(outChars, 0, outCount);
-
- f.deleteOnExit();
- assertEquals(len, flen);
- assertEquals(inputStr, outStr);
- }
-
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() throws Exception {
-
- f = File.createTempFile("writer", ".tst");
-
- if (f.exists())
- if (!f.delete()) {
- fail("Unable to delete test file");
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- bw.close();
- } catch (Exception e) {
- }
- try {
- fis.close();
- } catch (Exception e) {
- }
- f.delete();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FilenameFilterTest.java b/luni/src/test/java/tests/api/java/io/FilenameFilterTest.java
deleted file mode 100644
index 32dfc5c..0000000
--- a/luni/src/test/java/tests/api/java/io/FilenameFilterTest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package tests.api.java.io;
-
-import junit.framework.TestCase;
-
-import java.io.FilenameFilter;
-import java.io.File;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(
- value = FilenameFilter.class,
- untestedMethods = {
- @TestTargetNew(
- method = "accept",
- args = {File.class , String.class},
- level = TestLevel.NOT_FEASIBLE,
- notes = "There are no classes in the current core " +
- "libraries that implement this method."
- )
- }
-)
-public class FilenameFilterTest extends TestCase {
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/IOExceptionTest.java b/luni/src/test/java/tests/api/java/io/IOExceptionTest.java
deleted file mode 100644
index 8223beb..0000000
--- a/luni/src/test/java/tests/api/java/io/IOExceptionTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.IOException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(IOException.class)
-public class IOExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.IOException#IOException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "IOException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // Needed to avoid unreachable code compilation error.
- throw new IOException();
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.IOException#IOException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "IOException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // Needed to avoid unreachable code compilation error.
- throw new IOException("Something went wrong.");
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java b/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java
deleted file mode 100644
index 879bf4e..0000000
--- a/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java
+++ /dev/null
@@ -1,756 +0,0 @@
-/*
- * 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 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.nio.charset.CodingErrorAction;
-import java.nio.charset.MalformedInputException;
-import java.util.Arrays;
-
-import tests.support.Support_ASimpleInputStream;
-
-import junit.framework.TestCase;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-/**
- *
- */
-@TestTargetClass(InputStreamReader.class)
-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();
- }
-
- /*
- * Class under test for int read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "read",
- args = {}
- )
- 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
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "read",
- args = {}
- )
-
- 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)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void testReadcharArrayintint() throws IOException {
- try {
- reader.read(new char[3], -1, 0);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- try {
- reader.read(new char[3], 0, -1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- try {
- reader.read(new char[3], 4, 0);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- try {
- reader.read(new char[3], 3, 1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- try {
- reader.read(new char[3], 1, 3);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- try {
- reader.read(new char[3], 0, 4);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- try {
- reader.read(null, 0, 0);
- fail("Should throw NullPointerException");
- } catch (NullPointerException 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()));
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- 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));
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "ready",
- args = {}
- )
- public void testReady() throws IOException {
- assertTrue(reader.ready());
- reader.read(new char[source.length()]);
- assertFalse(reader.ready());
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "read",
- args = {}
- )
- public void testSpecialCharsetReading() throws Exception {
- 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");
- reader = new InputStreamReader(in, "GB2312");
-
- while ((c = reader.read()) != -1) {
- sb.append((char) c);
- }
- assertEquals(source, sb.toString());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking.",
- method = "read",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking.",
- method = "ready",
- args = {}
- )
- })
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InputStreamReader",
- args = {java.io.InputStream.class}
- )
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InputStreamReader",
- args = {java.io.InputStream.class, java.lang.String.class}
- )
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InputStreamReader",
- args = {java.io.InputStream.class, java.nio.charset.CharsetDecoder.class}
- )
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InputStreamReader",
- args = {java.io.InputStream.class, java.nio.charset.Charset.class}
- )
- 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();
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "See setUp.",
- method = "InputStreamReader",
- args = {java.io.InputStream.class}
- )
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies InputStreamReader(java.io.InputStream) constructor.",
- method = "InputStreamReader",
- args = {java.io.InputStream.class}
- )
- 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()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "close",
- args = {}
- )
- 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("Test 1: IOException expected.");
- } catch (IOException e) {
- // Exception means read failed due to close
- }
-
- is = new InputStreamReader(new Support_ASimpleInputStream(true));
- try {
- is.read();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "close",
- args = {}
- )
- public void testClose() throws IOException {
- reader.close();
- try {
- reader.ready();
- fail("Should throw IOException");
- } catch (IOException e) {
- }
- reader.close();
- }
-
- /**
- * @tests java.io.InputStreamReader#getEncoding()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getEncoding() method.",
- method = "getEncoding",
- args = {}
- )
- 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()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
- 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());
-
- 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)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- 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()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "[No verification for empty buffer]",
- method = "ready",
- args = {}
- )
- 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());
- }
- }
-
- /**
- * Test for regression of a bug that dropped characters when
- * multibyte encodings spanned buffer boundaries.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
- public void test_readWhenCharacterSpansBuffer() {
- final byte[] suffix = {
- (byte) 0x93, (byte) 0xa1, (byte) 0x8c, (byte) 0xb4,
- (byte) 0x97, (byte) 0x43, (byte) 0x88, (byte) 0xea,
- (byte) 0x98, (byte) 0x59
- };
- final char[] decodedSuffix = {
- (char) 0x85e4, (char) 0x539f, (char) 0x4f51, (char) 0x4e00,
- (char) 0x90ce
- };
- final int prefixLength = 8189;
-
- byte[] bytes = new byte[prefixLength + 10];
- Arrays.fill(bytes, (byte) ' ');
- System.arraycopy(suffix, 0, bytes, prefixLength, suffix.length);
- ByteArrayInputStream is = new ByteArrayInputStream(bytes);
-
- try {
- InputStreamReader isr = new InputStreamReader(is, "SHIFT_JIS");
- char[] chars = new char[8192];
- int at = 0;
-
- for (;;) {
- int amt = isr.read(chars);
- if (amt <= 0) {
- break;
- }
-
- for (int i = 0; i < amt; i++) {
- char c = chars[i];
- if (at < prefixLength) {
- if (c != ' ') {
- fail("Found bad prefix character " +
- (int) c + " at " + at);
- }
- } else {
- char decoded = decodedSuffix[at - prefixLength];
- if (c != decoded) {
- fail("Found mismatched character " +
- (int) c + " at " + at);
- }
- }
- at++;
- }
- }
- } catch (IOException ex) {
- throw new RuntimeException("unexpected exception", ex);
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/InterruptedIOExceptionTest.java b/luni/src/test/java/tests/api/java/io/InterruptedIOExceptionTest.java
deleted file mode 100644
index 90ad5d8..0000000
--- a/luni/src/test/java/tests/api/java/io/InterruptedIOExceptionTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.InterruptedIOException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(InterruptedIOException.class)
-public class InterruptedIOExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.InterruptedIOException#InterruptedIOException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InterruptedIOException",
- args = {}
- )
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InterruptedIOException",
- args = {java.lang.String.class}
- )
- 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() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/InvalidClassExceptionTest.java b/luni/src/test/java/tests/api/java/io/InvalidClassExceptionTest.java
deleted file mode 100644
index 6bd184b..0000000
--- a/luni/src/test/java/tests/api/java/io/InvalidClassExceptionTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import java.io.InvalidClassException;
-
-@TestTargetClass(InvalidClassException.class)
-public class InvalidClassExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.InvalidClassException#InvalidClassException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InvalidClassException",
- args = {java.lang.String.class}
- )
- 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)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InvalidClassException",
- args = {java.lang.String.class, java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMessage",
- args = {}
- )
- })
- 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");
- }
-
- /**
- * 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() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/InvalidObjectExceptionTest.java b/luni/src/test/java/tests/api/java/io/InvalidObjectExceptionTest.java
deleted file mode 100644
index a3322f2..0000000
--- a/luni/src/test/java/tests/api/java/io/InvalidObjectExceptionTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.InvalidObjectException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(java.io.InvalidObjectException.class)
-public class InvalidObjectExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.InvalidObjectException#InvalidObjectException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies the InvalidObjectException(java.lang.String) constructor.",
- method = "InvalidObjectException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.InvalidObjectException(java.lang.String)
- try {
- if (true) throw new InvalidObjectException("This object is not valid.");
- fail("Exception not thrown.");
- } catch (InvalidObjectException e) {
- assertEquals("The exception message is not equal to the one " +
- "passed to the constructor.",
- "This object is not valid.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/LineNumberReaderTest.java b/luni/src/test/java/tests/api/java/io/LineNumberReaderTest.java
deleted file mode 100644
index 316ff44..0000000
--- a/luni/src/test/java/tests/api/java/io/LineNumberReaderTest.java
+++ /dev/null
@@ -1,359 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.IOException;
-import java.io.LineNumberReader;
-import java.io.Reader;
-import java.io.StringReader;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(LineNumberReader.class)
-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\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\n";
-
- LineNumberReader lnr;
-
- /**
- * @tests java.io.LineNumberReader#LineNumberReader(java.io.Reader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "LineNumberReader",
- args = {java.io.Reader.class, int.class}
- )
- public void test_ConstructorLjava_io_Reader() {
- // Test for method java.io.LineNumberReader(java.io.Reader)
- lnr = new LineNumberReader(new StringReader(text), 4092);
- assertEquals("Failed to create reader", 0, lnr.getLineNumber());
- }
-
- /**
- * @tests java.io.LineNumberReader#LineNumberReader(java.io.Reader, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "LineNumberReader",
- args = {java.io.Reader.class}
- )
- public void test_ConstructorLjava_io_ReaderI() {
- // Test for method java.io.LineNumberReader(java.io.Reader, int)
- lnr = new LineNumberReader(new StringReader(text));
- assertEquals("Failed to create reader", 0, lnr.getLineNumber());
- }
-
- /**
- * @tests java.io.LineNumberReader#getLineNumber()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLineNumber",
- args = {}
- )
- public void test_getLineNumber() {
- // Test for method int java.io.LineNumberReader.getLineNumber()
- lnr = new LineNumberReader(new StringReader(text));
- assertEquals("Returned incorrect line number--expected 0, got ", 0, lnr
- .getLineNumber());
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "mark",
- args = {int.class}
- )
- public void test_markI() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
- String line;
- lnr.skip(80);
- lnr.mark(100);
- line = lnr.readLine();
- lnr.reset();
- assertTrue("Test 1: Failed to return to marked position.",
- line.equals(lnr.readLine()));
-
- lnr.close();
- try {
- lnr.mark(42);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- // The spec does not say the mark has to be invalidated
- }
-
- /**
- * @tests java.io.LineNumberReader#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
-
- int c = lnr.read();
- assertEquals("Test 1: Read returned incorrect character;",
- '0', c);
- lnr.read();
- assertEquals("Test 2: Read failed to increase the line number;",
- 1, lnr.getLineNumber());
-
- lnr.close();
- try {
- lnr.read();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
- char[] c = new char[100];
- lnr.read(c, 0, 4);
- assertTrue("Test 1: Read returned incorrect characters.", "0\n1\n"
- .equals(new String(c, 0, 4)));
- assertEquals("Test 2: Read failed to inc lineNumber",
- 2, lnr.getLineNumber());
-
- lnr.close();
- try {
- lnr.read(c, 0, 4);
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII_Exception() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
- char[] c = new char[10];
-
- try {
- lnr.read(c, -1, 1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- lnr.read(c, 0, -1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- lnr.read(c, 10, 1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberReader#readLine()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readLine",
- args = {}
- )
- public void test_readLine() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
- assertEquals("Returned incorrect line number", 0, lnr.getLineNumber());
- String line = null;
- lnr.readLine();
- line = lnr.readLine();
- assertEquals("Test 1: Returned incorrect string;", "1", line);
- assertTrue("Test 2: Returned incorrect line number:" + lnr.getLineNumber(),
- lnr.getLineNumber() == 2);
-
- lnr.close();
- try {
- lnr.readLine();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberReader#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- )
- public void test_reset() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
- assertEquals("Test 1: Returned incorrect line number;",
- 0, lnr.getLineNumber());
- String line = null;
- lnr.mark(100);
- lnr.readLine();
- lnr.reset();
- line = lnr.readLine();
- assertEquals("Test 2: Failed to reset reader", "0", line);
-
- lnr.mark(100);
- lnr.close();
- try {
- lnr.reset();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- public void testReadLineSourceThrows() throws IOException {
- lnr = new LineNumberReader(new Reader() {
- private StringReader delegate = new StringReader("hello\nworld");
- private int calls = 0;
- @Override public void close() throws IOException {}
- @Override public int read(char[] buf, int offset, int len) throws IOException {
- if (calls++ < 2) {
- throw new IOException();
- } else {
- return delegate.read(buf, offset, len);
- }
- }
- });
-
- assertEquals(0, lnr.getLineNumber());
- try {
- lnr.readLine();
- fail();
- } catch (IOException expected) {
- }
-
- assertEquals(0, lnr.getLineNumber());
- try {
- lnr.readLine();
- fail();
- } catch (IOException expected) {
- }
-
- assertEquals(0, lnr.getLineNumber());
- assertEquals("hello", lnr.readLine());
- assertEquals(1, lnr.getLineNumber());
- assertEquals("world", lnr.readLine());
- assertEquals(2, lnr.getLineNumber());
- }
-
- public void testGetLineNumberAfterEnd() throws IOException {
- lnr = new LineNumberReader(new StringReader("hello\nworld"));
- assertEquals(0, lnr.getLineNumber());
- assertEquals("hello", lnr.readLine());
- assertEquals(1, lnr.getLineNumber());
- assertEquals("world", lnr.readLine());
- assertEquals(2, lnr.getLineNumber());
- assertEquals(null, lnr.readLine());
- assertEquals(2, lnr.getLineNumber());
- assertEquals(null, lnr.readLine());
- assertEquals(2, lnr.getLineNumber());
- }
-
- /**
- * @tests java.io.LineNumberReader#setLineNumber(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setLineNumber",
- args = {int.class}
- )
- public void test_setLineNumberI() {
- // Test for method void java.io.LineNumberReader.setLineNumber(int)
- lnr = new LineNumberReader(new StringReader(text));
- lnr.setLineNumber(1001);
- assertEquals("set incorrect line number", 1001, lnr.getLineNumber());
- }
-
- /**
- * @tests java.io.LineNumberReader#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
- char[] c = new char[100];
- long skipped = lnr.skip(80);
- assertEquals("Test 1: Incorrect number of characters skipped;",
- 80, skipped);
- lnr.read(c, 0, 100);
- assertTrue("Test 2: Failed to skip to correct position.",
- text.substring(80, 180).equals(new String(c, 0, c.length)));
-
- try {
- lnr.skip(-1);
- fail("Test 3: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
-
- lnr.close();
- try {
- lnr.skip(1);
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/NotActiveExceptionTest.java b/luni/src/test/java/tests/api/java/io/NotActiveExceptionTest.java
deleted file mode 100644
index 8f9ffe3..0000000
--- a/luni/src/test/java/tests/api/java/io/NotActiveExceptionTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.NotActiveException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(NotActiveException.class)
-public class NotActiveExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.NotActiveException#NotActiveException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "NotActiveException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new NotActiveException();
- fail("Test 1: NotActiveException expected.");
- } catch (NotActiveException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.NotActiveException#NotActiveException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "NotActiveException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new NotActiveException("Something went wrong.");
- fail("Test 1: NotActiveException expected.");
- } catch (NotActiveException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/NotSerializableExceptionTest.java b/luni/src/test/java/tests/api/java/io/NotSerializableExceptionTest.java
deleted file mode 100644
index 9bc7999..0000000
--- a/luni/src/test/java/tests/api/java/io/NotSerializableExceptionTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.NotSerializableException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(NotSerializableException.class)
-public class NotSerializableExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.NotSerializableException#NotSerializableException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "NotSerializableException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new NotSerializableException();
- fail("Test 1: NotSerializableException expected.");
- } catch (NotSerializableException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.NotSerializableException#NotSerializableException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "NotSerializableException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new NotSerializableException("Something went wrong.");
- fail("Test 1: NotSerializableException expected.");
- } catch (NotSerializableException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectInputOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/ObjectInputOutputStreamTest.java
deleted file mode 100644
index 68dff00..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectInputOutputStreamTest.java
+++ /dev/null
@@ -1,468 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-@TestTargetClass(ObjectOutputStream.class)
-public class ObjectInputOutputStreamTest extends junit.framework.TestCase {
-
- private ObjectOutputStream os;
-
- private ObjectInputStream is;
-
- private Support_OutputStream sos;
-
- String unihw = "\u0048\u0065\u006C\u006C\u006F\u0020\u0057\u006F\u0072\u006C\u0064";
-
- /**
- * @tests java.io.ObjectInputStream#readBoolean()
- * @tests java.io.ObjectOutputStream#writeBoolean(boolean)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeBoolean",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readBoolean",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeBoolean() throws IOException {
- os.writeBoolean(true);
-
- os.close();
- openObjectInputStream();
- assertTrue("Test 1: Incorrect boolean written or read.",
- is.readBoolean());
-
- try {
- is.readBoolean();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readBoolean();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readByte()
- * @tests java.io.ObjectOutputStream#writeByte(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeByte",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readByte",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeByte() throws IOException {
- os.writeByte((byte) 127);
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect byte written or read;",
- (byte) 127, is.readByte());
-
- try {
- is.readByte();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readByte();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readChar()
- * @tests java.io.ObjectOutputStream#writeChar(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeChar",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readChar",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeChar() throws IOException {
- os.writeChar('b');
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect char written or read;",
- 'b', is.readChar());
-
- try {
- is.readChar();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readChar();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readDouble()
- * @tests java.io.ObjectOutputStream#writeDouble(double)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeDouble",
- args = {double.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readDouble",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeDouble() throws IOException {
- os.writeDouble(2345.76834720202);
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect double written or read;",
- 2345.76834720202, is.readDouble());
-
- try {
- is.readDouble();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readDouble();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readFloat()
- * @tests java.io.ObjectOutputStream#writeFloat(float)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeFloat",
- args = {float.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readFloat",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeFloat() throws IOException {
- os.writeFloat(29.08764f);
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect float written or read;",
- 29.08764f, is.readFloat());
-
- try {
- is.readFloat();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readFloat();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readInt()
- * @tests java.io.ObjectOutputStream#writeInt(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeInt",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readInt",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeInt() throws IOException {
- os.writeInt(768347202);
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect int written or read;",
- 768347202, is.readInt());
-
- try {
- is.readInt();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readInt();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readLong()
- * @tests java.io.ObjectOutputStream#writeLong(long)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeLong",
- args = {long.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readLong",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeLong() throws IOException {
- os.writeLong(9875645283333L);
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect long written or read;",
- 9875645283333L, is.readLong());
-
- try {
- is.readLong();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readLong();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readShort()
- * @tests java.io.ObjectOutputStream#writeShort(short)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeShort",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readShort",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeShort() throws IOException {
- os.writeShort(9875);
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect short written or read;",
- 9875, is.readShort());
-
- try {
- is.readShort();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readShort();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
-
- /**
- * @tests java.io.ObjectInputStream#readUTF()
- * @tests java.io.ObjectOutputStream#writeUTF(java.lang.String)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeUTF",
- args = {String.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readUTF",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeUTF() throws IOException {
- os.writeUTF(unihw);
-
- os.close();
- openObjectInputStream();
- assertTrue("Test 1: Incorrect UTF-8 string written or read.",
- is.readUTF().equals(unihw));
-
- try {
- is.readUTF();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readUTF();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- private void openObjectInputStream() throws IOException {
- is = new ObjectInputStream(
- new ByteArrayInputStream(sos.toByteArray()));
- }
-
- protected void setUp() throws IOException {
- sos = new Support_OutputStream(256);
- os = new ObjectOutputStream(sos);
- }
-
- protected void tearDown() {
- try {
- os.close();
- } catch (Exception e) {
- }
- try {
- is.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java b/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
index 4f91e7d..434d31c 100644
--- a/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
+++ b/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
@@ -17,38 +17,24 @@
package tests.api.java.io;
-import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.NotActiveException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
-import java.io.OptionalDataException;
import java.io.OutputStream;
import java.io.Serializable;
import java.io.StreamCorruptedException;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Vector;
-
import org.apache.harmony.testframework.serialization.SerializationTest;
import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
import tests.support.Support_ASimpleInputStream;
-import tests.support.Support_IOTestSecurityManager;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-@TestTargetClass(ObjectInputStream.class)
public class ObjectInputStreamTest extends junit.framework.TestCase implements
Serializable {
@@ -66,37 +52,6 @@
private final int testLength = testString.length();
- /**
- * @tests java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "ObjectInputStream",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStream() throws IOException {
- // Test for method java.io.ObjectInputStream(java.io.InputStream)
- oos.writeDouble(Double.MAX_VALUE);
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- ois.close();
- oos.close();
-
- try {
- ois = new ObjectInputStream(new ByteArrayInputStream(new byte[90]));
- fail("StreamCorruptedException expected");
- } catch (StreamCorruptedException e) {}
- }
-
- /**
- * @tests java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "ObjectInputStream",
- args = {java.io.InputStream.class}
- )
public void test_ConstructorLjava_io_InputStream_IOException() throws IOException {
oos.writeObject(testString);
oos.close();
@@ -112,20 +67,6 @@
sis.throwExceptionOnNextUse = false;
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that object can be serialized and deserialized correctly with reading descriptor from serialization stream.",
- method = "readClassDescriptor",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that object can be serialized and deserialized correctly with reading descriptor from serialization stream.",
- method = "readObject",
- args = {}
- )
- })
public void test_ClassDescriptor() throws IOException,
ClassNotFoundException {
@@ -143,14 +84,6 @@
assertEquals(cls, obj);
}
- /**
- * @tests java.io.ObjectInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "available",
- args = {}
- )
public void test_available() throws IOException {
// Test for method int java.io.ObjectInputStream.available()
oos.writeBytes(testString);
@@ -162,15 +95,6 @@
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "available",
- args = {}
- )
public void test_available_IOException() throws IOException {
oos.writeObject(testString);
oos.close();
@@ -188,14 +112,6 @@
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
public void test_close() throws Exception {
// Test for method void java.io.ObjectInputStream.close()
oos.writeObject(testString);
@@ -214,42 +130,6 @@
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#defaultReadObject()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "defaultReadObject",
- args = {}
- )
- public void test_defaultReadObject() throws Exception {
- // Test for method void java.io.ObjectInputStream.defaultReadObject()
- // SM. This method may as well be private, as if called directly it
- // throws an exception.
- String s = testString;
- oos.writeObject(s);
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- try {
- ois.defaultReadObject();
- fail("NotActiveException expected");
- } catch (NotActiveException e) {
- // Desired behavior
- } finally {
- ois.close();
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#enableResolveObject(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies enableResolveObject(boolean).",
- method = "enableResolveObject",
- args = {boolean.class}
- )
public void test_enableResolveObjectB() throws IOException {
// Start testing without a SecurityManager.
BasicObjectInputStream bois = new BasicObjectInputStream();
@@ -260,32 +140,6 @@
bois.enableResolveObject(false));
}
- /**
- * @tests java.io.ObjectInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- // Test for method int java.io.ObjectInputStream.read()
- oos.write('T');
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- assertEquals("Read incorrect byte value", 'T', ois.read());
- ois.close();
- }
-
- /**
- * @tests java.io.ObjectInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "read",
- args = {}
- )
public void test_read_IOException() throws IOException {
oos.writeObject(testString);
oos.close();
@@ -303,14 +157,6 @@
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII() throws IOException {
// Test for method int java.io.ObjectInputStream.read(byte [], int, int)
byte[] buf = new byte[testLength];
@@ -322,15 +168,6 @@
assertEquals("Read incorrect bytes", testString, new String(buf));
}
- /**
- * @tests java.io.ObjectInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks Exceptions.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII_Exception() throws IOException {
byte[] buf = new byte[testLength];
oos.writeObject(testString);
@@ -371,55 +208,6 @@
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#readFields()
- * @tests java.io.ObjectOutputStream#writeFields()
- */
- @TestTargets({
- @TestTargetNew(
- method = "readFields",
- args = {},
- level = TestLevel.COMPLETE
- ),
- @TestTargetNew(
- method = "writeFields",
- args = {},
- clazz = ObjectOutputStream.class,
- level = TestLevel.COMPLETE
- )
- })
- public void test_readFields() throws Exception {
- // Test for method java.io.ObjectInputStream$GetField
- // java.io.ObjectInputStream.readFields()
-
- SerializableTestHelper sth;
-
- /*
- * "SerializableTestHelper" is an object created for these tests with
- * two fields (Strings) and simple implementations of readObject and
- * writeObject which simply read and write the first field but not the
- * second
- */
-
- oos.writeObject(new SerializableTestHelper("Gabba", "Jabba"));
- oos.flush();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- sth = (SerializableTestHelper) (ois.readObject());
- assertEquals("readFields / writeFields failed--first field not set",
- "Gabba", sth.getText1());
- assertNull(
- "readFields / writeFields failed--second field should not have been set",
- sth.getText2());
- }
-
- /**
- * @tests java.io.ObjectInputStream#readFully(byte[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "readFully",
- args = {byte[].class}
- )
public void test_readFully$B() throws IOException {
byte[] buf = new byte[testLength];
oos.writeBytes(testString);
@@ -440,15 +228,6 @@
}
}
- /**
- * @tests java.io.ObjectInputStream#readFully(byte[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "readFully",
- args = {byte[].class}
- )
public void test_readFully$B_Exception() throws IOException {
byte[] buf = new byte[testLength];
oos.writeObject(testString);
@@ -467,14 +246,6 @@
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#readFully(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "readFully",
- args = {byte[].class, int.class, int.class}
- )
public void test_readFully$BII() throws IOException {
// Test for method void java.io.ObjectInputStream.readFully(byte [],
// int, int)
@@ -496,15 +267,6 @@
}
}
- /**
- * @tests java.io.ObjectInputStream#readFully(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks Exceptions.",
- method = "readFully",
- args = {byte[].class, int.class, int.class}
- )
public void test_readFully$BII_Exception() throws IOException {
byte[] buf = new byte[testLength];
oos.writeObject(testString);
@@ -544,15 +306,7 @@
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#readLine()
- */
@SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "readLine",
- args = {}
- )
public void test_readLine() throws IOException {
String line;
oos.writeBytes("Lorem\nipsum\rdolor sit amet...");
@@ -571,16 +325,6 @@
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#readLine()
- */
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "readLine",
- args = {}
- )
public void test_readLine_IOException() throws IOException {
oos.writeObject(testString);
oos.close();
@@ -598,102 +342,6 @@
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#readObject()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "readObject",
- args = {}
- )
- public void test_readObject() throws Exception {
- // Test for method java.lang.Object
- // java.io.ObjectInputStream.readObject()
- String s = testString;
- oos.writeObject(s);
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- assertEquals("Read incorrect Object value", s, ois.readObject());
- ois.close();
-
- // Regression for HARMONY-91
- // dynamically create serialization byte array for the next hierarchy:
- // - class A implements Serializable
- // - class C extends A
-
- byte[] cName = C.class.getName().getBytes();
- byte[] aName = A.class.getName().getBytes();
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
-
- byte[] begStream = new byte[] { (byte) 0xac, (byte) 0xed, // STREAM_MAGIC
- (byte) 0x00, (byte) 0x05, // STREAM_VERSION
- (byte) 0x73, // TC_OBJECT
- (byte) 0x72, // TC_CLASSDESC
- (byte) 0x00, // only first byte for C class name length
- };
-
- out.write(begStream, 0, begStream.length);
- out.write(cName.length); // second byte for C class name length
- out.write(cName, 0, cName.length); // C class name
-
- byte[] midStream = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x21, // serialVersionUID = 33L
- (byte) 0x02, // flags
- (byte) 0x00, (byte) 0x00, // fields : none
- (byte) 0x78, // TC_ENDBLOCKDATA
- (byte) 0x72, // Super class for C: TC_CLASSDESC for A class
- (byte) 0x00, // only first byte for A class name length
- };
-
- out.write(midStream, 0, midStream.length);
- out.write(aName.length); // second byte for A class name length
- out.write(aName, 0, aName.length); // A class name
-
- byte[] endStream = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x0b, // serialVersionUID = 11L
- (byte) 0x02, // flags
- (byte) 0x00, (byte) 0x01, // fields
-
- (byte) 0x4c, // field description: type L (object)
- (byte) 0x00, (byte) 0x04, // length
- // field = 'name'
- (byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65,
-
- (byte) 0x74, // className1: TC_STRING
- (byte) 0x00, (byte) 0x12, // length
- //
- (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76,
- (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61,
- (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x53,
- (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e,
- (byte) 0x67, (byte) 0x3b,
-
- (byte) 0x78, // TC_ENDBLOCKDATA
- (byte) 0x70, // NULL super class for A class
-
- // classdata
- (byte) 0x74, // TC_STRING
- (byte) 0x00, (byte) 0x04, // length
- (byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65, // value
- };
-
- out.write(endStream, 0, endStream.length);
- out.flush();
-
- // read created serial. form
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
- out.toByteArray()));
- Object o = ois.readObject();
- assertEquals(C.class, o.getClass());
-
- // Regression for HARMONY-846
- assertNull(new ObjectInputStream() {}.readObject());
- }
-
private void fillStreamHeader(byte[] buffer) {
short magic = java.io.ObjectStreamConstants.STREAM_MAGIC;
short version = java.io.ObjectStreamConstants.STREAM_VERSION;
@@ -709,15 +357,6 @@
buffer[3] = (byte) (version);
}
- /**
- * @tests java.io.ObjectInputStream#readObjectOverride()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies readObjectOverride().",
- method = "readObjectOverride",
- args = {}
- )
public void test_readObjectOverride() throws Exception {
byte[] buffer = new byte[4];
@@ -740,15 +379,6 @@
bois.close();
}
- /**
- * @tests java.io.ObjectInputStream#readObject()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "readObject",
- args = {}
- )
public void test_readObjectMissingClasses() throws Exception {
SerializationTest.verifySelf(new A1(), new SerializableAssert() {
public void assertDeserialized(Serializable initial,
@@ -758,15 +388,6 @@
});
}
- /**
- * @tests java.io.ObjectInputStream#readObject()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "readObject",
- args = {}
- )
public void test_readObjectCorrupt() {
byte[] bytes = { 00, 00, 00, 0x64, 0x43, 0x48, (byte) 0xFD, 0x71, 00,
00, 0x0B, (byte) 0xB8, 0x4D, 0x65 };
@@ -786,15 +407,6 @@
assertTrue("Expected StreamCorruptedException", exception);
}
- /**
- * @tests java.io.ObjectInputStream#readStreamHeader()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies readStreamHeader().",
- method = "readStreamHeader",
- args = {}
- )
public void test_readStreamHeader() throws IOException {
String testString = "Lorem ipsum";
BasicObjectInputStream bois;
@@ -849,14 +461,6 @@
readStreamHeaderCalled);
}
- /**
- * @tests java.io.ObjectInputStream#readUnsignedByte()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readUnsignedByte",
- args = {}
- )
public void test_readUnsignedByte() throws IOException {
oos.writeByte(-1);
oos.close();
@@ -881,14 +485,6 @@
}
}
- /**
- * @tests java.io.ObjectInputStream#readUnsignedShort()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readUnsignedShort",
- args = {}
- )
public void test_readUnsignedShort() throws IOException {
// Test for method int java.io.ObjectInputStream.readUnsignedShort()
oos.writeShort(-1);
@@ -914,15 +510,6 @@
}
}
- /**
- * @tests java.io.ObjectInputStream#resolveProxyClass(String[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies resolveProxyClass(String[]).",
- method = "resolveProxyClass",
- args = {java.lang.String[].class}
- )
public void test_resolveProxyClass() throws IOException {
BasicObjectInputStream bois;
byte[] buffer = new byte[10];
@@ -967,44 +554,6 @@
bois.close();
}
- /**
- * @tests java.io.ObjectInputStream#skipBytes(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "skipBytes",
- args = {int.class}
- )
- public void test_skipBytesI() throws IOException {
- // Test for method int java.io.ObjectInputStream.skipBytes(int)
- byte[] buf = new byte[testLength];
- oos.writeBytes(testString);
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- ois.skipBytes(5);
- ois.read(buf, 0, 5);
- ois.close();
- assertEquals("Skipped incorrect bytes", testString.substring(5, 10),
- new String(buf, 0, 5));
-
- // Regression for HARMONY-844
- try {
- new ObjectInputStream() {}.skipBytes(0);
- fail("NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#skipBytes(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "skipBytes",
- args = {int.class}
- )
public void test_skipBytesI_IOException() throws IOException {
oos.writeObject(testString);
oos.close();
@@ -1022,32 +571,6 @@
ois.close();
}
- // Regression Test for JIRA 2192
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "readObject",
- args = {}
- )
- public void test_readObject_withPrimitiveClass() throws Exception {
- // Make sure that system properties are set correctly
- String dir = System.getProperty("java.io.tmpdir");
- if (dir == null)
- throw new Exception("System property java.io.tmpdir not defined.");
- File file = new File(dir, "test.ser");
- file.deleteOnExit();
- Test test = new Test();
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
- file));
- out.writeObject(test);
- out.close();
-
- ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
- Test another = (Test) in.readObject();
- in.close();
- assertEquals(test, another);
- }
-
public static class A implements Serializable {
private static final long serialVersionUID = 11L;
@@ -1080,60 +603,12 @@
Hashtable h = new Hashtable();
}
- public class SerializableTestHelper implements Serializable {
-
- public String aField1;
-
- public String aField2;
-
- SerializableTestHelper() {
- aField1 = null;
- aField2 = null;
- }
-
- SerializableTestHelper(String s, String t) {
- aField1 = s;
- aField2 = t;
- }
-
- private void readObject(ObjectInputStream ois) throws Exception {
- // note aField2 is not read
- ObjectInputStream.GetField fields = ois.readFields();
- aField1 = (String) fields.get("aField1", "Zap");
- }
-
- private void writeObject(ObjectOutputStream oos) throws IOException {
- // note aField2 is not written
- ObjectOutputStream.PutField fields = oos.putFields();
- fields.put("aField1", aField1);
- oos.writeFields();
- }
-
- public String getText1() {
- return aField1;
- }
-
- public void setText1(String s) {
- aField1 = s;
- }
-
- public String getText2() {
- return aField2;
- }
-
- public void setText2(String s) {
- aField2 = s;
- }
- }
-
-
class BasicObjectInputStream extends ObjectInputStream {
public BasicObjectInputStream() throws IOException, SecurityException {
super();
}
- public BasicObjectInputStream(InputStream input)
- throws StreamCorruptedException, IOException {
+ public BasicObjectInputStream(InputStream input) throws IOException {
super(input);
}
@@ -1142,13 +617,11 @@
return super.enableResolveObject(enable);
}
- public Object readObjectOverride() throws OptionalDataException,
- ClassNotFoundException, IOException {
+ public Object readObjectOverride() throws ClassNotFoundException, IOException {
return super.readObjectOverride();
}
- public void readStreamHeader() throws IOException,
- StreamCorruptedException {
+ public void readStreamHeader() throws IOException {
readStreamHeaderCalled = true;
super.readStreamHeader();
}
@@ -1193,272 +666,12 @@
private static final long serialVersionUID = 1L;
}
-
- // Regression Test for JIRA-2340
- public static class ObjectOutputStreamWithWriteDesc1 extends
- ObjectOutputStream {
- public ObjectOutputStreamWithWriteDesc1(OutputStream os)
- throws IOException {
- super(os);
- }
-
- public void writeClassDescriptor(ObjectStreamClass desc)
- throws IOException {
- super.writeClassDescriptor(desc);
- }
- }
-
- public static class ObjectInputStreamWithReadDesc1 extends
- ObjectInputStream {
-
- public ObjectInputStreamWithReadDesc1(InputStream is)
- throws IOException {
- super(is);
- }
-
- public ObjectStreamClass readClassDescriptor() throws IOException,
- ClassNotFoundException {
- return super.readClassDescriptor();
- }
- }
-
- // Regression test for Harmony-1921
- public static class ObjectInputStreamWithResolve extends ObjectInputStream {
- public ObjectInputStreamWithResolve(InputStream in) throws IOException {
- super(in);
- }
-
- protected Class<?> resolveClass(ObjectStreamClass desc)
- throws IOException, ClassNotFoundException {
- if (desc.getName().equals(
- "org.apache.harmony.luni.tests.pkg1.TestClass")) {
- return org.apache.harmony.luni.tests.pkg2.TestClass.class;
- }
- return super.resolveClass(desc);
- }
- }
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException testing since this seems not to be thrown.",
- method = "resolveClass",
- args = {java.io.ObjectStreamClass.class}
- )
- public void test_resolveClass() throws Exception {
- org.apache.harmony.luni.tests.pkg1.TestClass to1 = new org.apache.harmony.luni.tests.pkg1.TestClass();
- to1.i = 555;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(to1);
- oos.flush();
- byte[] bytes = baos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStream ois = new ObjectInputStreamWithResolve(bais);
- org.apache.harmony.luni.tests.pkg2.TestClass to2 = (org.apache.harmony.luni.tests.pkg2.TestClass) ois
- .readObject();
-
- if (to2.i != to1.i) {
- fail("Wrong object read. Expected val: " + to1.i + ", got: " + to2.i);
- }
- }
-
- static class ObjectInputStreamWithResolveObject extends ObjectInputStream {
-
- public static Integer intObj = Integer.valueOf(1000);
-
- public ObjectInputStreamWithResolveObject(InputStream in) throws IOException {
- super(in);
- enableResolveObject(true);
- }
-
- protected Object resolveObject(Object obj) throws IOException {
- if(obj instanceof Integer){
- obj = intObj;
- }
- return super.resolveObject(obj);
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#resolveObject(Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "resolveObject",
- args = {java.lang.Object.class}
- )
- public void test_resolveObjectLjava_lang_Object() throws Exception {
- // Write an Integer object into memory
- Integer original = new Integer(10);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(original);
- oos.flush();
- oos.close();
-
- // Read the object from memory
- byte[] bytes = baos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStreamWithResolveObject ois =
- new ObjectInputStreamWithResolveObject(bais);
- Integer actual = (Integer) ois.readObject();
- ois.close();
-
- // object should be resolved from 10 to 1000
- assertEquals(ObjectInputStreamWithResolveObject.intObj, actual);
- }
-
- /**
- * @tests java.io.ObjectInputStream#readClassDescriptor()
- * @tests java.io.ObjectOutputStream#writeClassDescriptor(ObjectStreamClass)
- */
- @TestTargets(
- {
- @TestTargetNew(
- method = "readClassDescriptor",
- args = {},
- level = TestLevel.PARTIAL_COMPLETE
- ),
- @TestTargetNew(
- method = "writeClassDescriptor",
- args = {ObjectStreamClass.class},
- clazz = ObjectOutputStream.class,
- level = TestLevel.COMPLETE
- )
- }
- )
- public void test_readClassDescriptor() throws IOException,
- ClassNotFoundException {
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStreamWithWriteDesc1 oos = new ObjectOutputStreamWithWriteDesc1(
- baos);
- ObjectStreamClass desc = ObjectStreamClass
- .lookup(TestClassForSerialization.class);
- oos.writeClassDescriptor(desc);
- oos.close();
-
- byte[] bytes = baos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStreamWithReadDesc1 ois = new ObjectInputStreamWithReadDesc1(
- bais);
- Object obj = ois.readClassDescriptor();
- ois.close();
- assertEquals(desc.getClass(), obj.getClass());
-
- //eof
- bais = new ByteArrayInputStream(bytes);
- ExceptionalBufferedInputStream bis = new ExceptionalBufferedInputStream(
- bais);
- ois = new ObjectInputStreamWithReadDesc1(bis);
-
- bis.setEOF(true);
-
- try {
- obj = ois.readClassDescriptor();
- } catch (IOException e) {
- //e.printStackTrace();
- } finally {
- ois.close();
- }
-
- //throw exception
- bais = new ByteArrayInputStream(bytes);
- bis = new ExceptionalBufferedInputStream(bais);
- ois = new ObjectInputStreamWithReadDesc1(bis);
-
- bis.setException(new IOException());
-
- try {
- obj = ois.readClassDescriptor();
- } catch (IOException e) {
- //e.printStackTrace();
- } finally {
- ois.close();
- }
-
- //corrupt
- bais = new ByteArrayInputStream(bytes);
- bis = new ExceptionalBufferedInputStream(bais);
- ois = new ObjectInputStreamWithReadDesc1(bis);
-
- bis.setCorrupt(true);
-
- try {
- obj = ois.readClassDescriptor();
- } catch (IOException e) {
- //e.printStackTrace();
- } finally {
- ois.close();
- }
-
- }
-
- static class ExceptionalBufferedInputStream extends BufferedInputStream {
- private boolean eof = false;
- private IOException exception = null;
- private boolean corrupt = false;
-
- public ExceptionalBufferedInputStream(InputStream in) {
- super(in);
- }
-
- public int read() throws IOException {
- if (exception != null) {
- throw exception;
- }
-
- if (eof) {
- return -1;
- }
-
- if (corrupt) {
- return 0;
- }
- return super.read();
- }
-
- public void setEOF(boolean eof) {
- this.eof = eof;
- }
-
- public void setException(IOException exception) {
- this.exception = exception;
- }
-
- public void setCorrupt(boolean corrupt) {
- this.corrupt = corrupt;
- }
- }
-
- // Regression Test for Harmony-2402
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "registerValidation",
- args = {java.io.ObjectInputValidation.class, int.class}
- )
- public void test_registerValidation() throws Exception {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- new ObjectOutputStream(baos);
- ObjectInputStream ois = new ObjectInputStream(
- new ByteArrayInputStream(baos.toByteArray()));
-
- try {
- ois.registerValidation(null, 256);
- fail("NotActiveException should be thrown");
- } catch (NotActiveException nae) {
- // expected
- }
- }
-
protected void setUp() throws Exception {
super.setUp();
oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
}
}
-
class Test implements Serializable {
private static final long serialVersionUID = 1L;
diff --git a/luni/src/test/java/tests/api/java/io/ObjectInputValidationTest.java b/luni/src/test/java/tests/api/java/io/ObjectInputValidationTest.java
deleted file mode 100644
index 53bc31a..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectInputValidationTest.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package tests.api.java.io;
-
-import junit.framework.TestCase;
-
-import java.io.ObjectInputValidation;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(
- value = ObjectInputValidation.class,
- untestedMethods = {
- @TestTargetNew(
- method = "validateObject",
- level = TestLevel.NOT_FEASIBLE,
- notes = "There are no classes in the current core " +
- "libraries that implement this method."
- )
- }
-)
-public class ObjectInputValidationTest extends TestCase {
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
deleted file mode 100644
index 054986d..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
+++ /dev/null
@@ -1,1518 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Externalizable;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.NotActiveException;
-import java.io.NotSerializableException;
-import java.io.ObjectInput;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamClass;
-import java.io.ObjectStreamException;
-import java.io.ObjectStreamField;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.io.SerializablePermission;
-import java.io.WriteAbortedException;
-import java.security.Permission;
-import java.util.Arrays;
-
-import tests.support.Support_ASimpleOutputStream;
-import tests.support.Support_IOTestSecurityManager;
-import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-@TestTargetClass(
- value = ObjectOutputStream.class,
- untestedMethods = {
- @TestTargetNew(
- method = "annotateClass",
- args = {Class.class},
- level = TestLevel.NOT_NECESSARY,
- notes = "According to specification, the implementation " +
- "does nothing."
- ),
- @TestTargetNew(
- method = "annotateProxyClass",
- args = {Class.class},
- level = TestLevel.NOT_NECESSARY,
- notes = "According to specification, the implementation " +
- "does nothing."
- )
- }
-)
-public class ObjectOutputStreamTest extends junit.framework.TestCase implements
- Serializable {
-
- static final long serialVersionUID = 1L;
-
- java.io.File f;
-
- public class SerializableTestHelper implements Serializable {
- public String aField1;
-
- public String aField2;
-
- SerializableTestHelper() {
- aField1 = null;
- aField2 = null;
- }
-
- SerializableTestHelper(String s, String t) {
- aField1 = s;
- aField2 = t;
- }
-
- private void readObject(ObjectInputStream ois) throws IOException {
- // note aField2 is not read
- try {
- ObjectInputStream.GetField fields = ois.readFields();
- aField1 = (String) fields.get("aField1", "Zap");
- } catch (Exception e) {
- }
- }
-
- private void writeObject(ObjectOutputStream oos) throws IOException {
- // note aField2 is not written
- ObjectOutputStream.PutField fields = oos.putFields();
- fields.put("aField1", aField1);
- oos.writeFields();
- }
-
- public String getText1() {
- return aField1;
- }
-
- public void setText1(String s) {
- aField1 = s;
- }
-
- public String getText2() {
- return aField2;
- }
-
- public void setText2(String s) {
- aField2 = s;
- }
- }
-
- private static class SpecTestSuperClass implements Runnable, Serializable {
- static final long serialVersionUID = 1L;
- protected java.lang.String instVar;
-
- public void run() {
- }
- }
-
- private static class SpecTest extends SpecTestSuperClass implements
- Cloneable, Serializable {
- static final long serialVersionUID = 1L;
-
- public java.lang.String instVar1;
-
- public static java.lang.String staticVar1;
-
- public static java.lang.String staticVar2;
- {
- instVar1 = "NonStaticInitialValue";
- }
- static {
- staticVar1 = "StaticInitialValue";
- staticVar1 = new String(staticVar1);
- }
-
- public Object method(Object objParam, Object objParam2) {
- return new Object();
- }
-
- public boolean method(boolean bParam, Object objParam) {
- return true;
- }
-
- public boolean method(boolean bParam, Object objParam, Object objParam2) {
- return true;
- }
-
- }
-
- private static class SpecTestSubclass extends SpecTest implements
- Serializable {
- static final long serialVersionUID = 1L;
- public transient java.lang.String transientInstVar = "transientValue";
- }
-
- private static class ReadWriteObject implements java.io.Serializable {
- static final long serialVersionUID = 1L;
-
- public boolean calledWriteObject = false;
-
- public boolean calledReadObject = false;
-
- public ReadWriteObject() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- calledReadObject = true;
- in.readObject();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException {
- calledWriteObject = true;
- out.writeObject(FOO);
- }
- }
-
- private static class PublicReadWriteObject implements java.io.Serializable {
- public boolean calledWriteObject = false;
-
- public boolean calledReadObject = false;
-
- public PublicReadWriteObject() {
- super();
- }
-
- public void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- calledReadObject = true;
- in.readObject();
- }
-
- public void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException {
- calledWriteObject = true;
- out.writeObject(FOO);
- }
- }
-
- private static class FieldOrder implements Serializable {
- String aaa1NonPrimitive = "aaa1";
-
- int bbb1PrimitiveInt = 5;
-
- boolean aaa2PrimitiveBoolean = true;
-
- String bbb2NonPrimitive = "bbb2";
- }
-
- private static class JustReadObject implements java.io.Serializable {
- public boolean calledReadObject = false;
-
- public JustReadObject() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- calledReadObject = true;
- in.defaultReadObject();
- }
- }
-
- private static class JustWriteObject implements java.io.Serializable {
- static final long serialVersionUID = 1L;
- public boolean calledWriteObject = false;
-
- public JustWriteObject() {
- super();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- calledWriteObject = true;
- out.defaultWriteObject();
- }
- }
-
- private static class ClassBasedReplacementWhenDumping implements
- java.io.Serializable {
- public boolean calledReplacement = false;
-
- public ClassBasedReplacementWhenDumping() {
- super();
- }
-
- private Object writeReplace() {
- calledReplacement = true;
- return FOO; // Replacement is a String
- }
- }
-
- private static class MultipleClassBasedReplacementWhenDumping implements
- java.io.Serializable {
- private static class C1 implements java.io.Serializable {
- private Object writeReplace() {
- return new C2();
- }
- }
-
- private static class C2 implements java.io.Serializable {
- private Object writeReplace() {
- return new C3();
- }
- }
-
- private static class C3 implements java.io.Serializable {
- private Object writeReplace() {
- return FOO;
- }
- }
-
- public MultipleClassBasedReplacementWhenDumping() {
- super();
- }
-
- private Object writeReplace() {
- return new C1();
- }
- }
-
- private static class ClassBasedReplacementWhenLoading implements
- java.io.Serializable {
- public ClassBasedReplacementWhenLoading() {
- super();
- }
-
- private Object readResolve() {
- return FOO; // Replacement is a String
- }
- }
-
- private static class ClassBasedReplacementWhenLoadingViolatesFieldType
- implements java.io.Serializable {
- public ClassBasedReplacementWhenLoading classBasedReplacementWhenLoading = new ClassBasedReplacementWhenLoading();
-
- public ClassBasedReplacementWhenLoadingViolatesFieldType() {
- super();
- }
- }
-
- private static class MyExceptionWhenDumping implements java.io.Serializable {
- private static class MyException extends java.io.IOException {
- };
-
- public boolean anInstanceVar = false;
-
- public MyExceptionWhenDumping() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- in.defaultReadObject();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- throw new MyException();
- }
- }
-
- private static class NonSerializableExceptionWhenDumping implements
- java.io.Serializable {
- public Object anInstanceVar = new Object();
-
- public NonSerializableExceptionWhenDumping() {
- super();
- }
- }
-
- private static class MyUnserializableExceptionWhenDumping implements
- java.io.Serializable {
- private static class MyException extends java.io.IOException {
- private Object notSerializable = new Object();
- };
-
- public boolean anInstanceVar = false;
-
- public MyUnserializableExceptionWhenDumping() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- in.defaultReadObject();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- throw new MyException();
- }
- }
-
- private static class WithUnmatchingSerialPersistentFields implements
- java.io.Serializable {
- private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
- "value", String.class) };
-
- public int anInstanceVar = 5;
-
- public WithUnmatchingSerialPersistentFields() {
- super();
- }
- }
-
- private static class WithMatchingSerialPersistentFields implements
- java.io.Serializable {
- private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
- "anInstanceVar", String.class) };
-
- public String anInstanceVar = FOO + FOO;
-
- public WithMatchingSerialPersistentFields() {
- super();
- }
- }
-
- private static class SerialPersistentFields implements java.io.Serializable {
- private static final String SIMULATED_FIELD_NAME = "text";
-
- private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
- SIMULATED_FIELD_NAME, String.class) };
-
- public int anInstanceVar = 5;
-
- public SerialPersistentFields() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- ObjectInputStream.GetField fields = in.readFields();
- anInstanceVar = Integer.parseInt((String) fields.get(
- SIMULATED_FIELD_NAME, "-5"));
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- ObjectOutputStream.PutField fields = out.putFields();
- fields.put(SIMULATED_FIELD_NAME, Integer.toString(anInstanceVar));
- out.writeFields();
- }
- }
-
- private static class WriteFieldsWithoutFetchingPutFields implements
- java.io.Serializable {
- private static final String SIMULATED_FIELD_NAME = "text";
-
- private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
- SIMULATED_FIELD_NAME, String.class) };
-
- public int anInstanceVar = 5;
-
- public WriteFieldsWithoutFetchingPutFields() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- in.readFields();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- out.writeFields();
- }
- }
-
- private static class SerialPersistentFieldsWithoutField implements
- java.io.Serializable {
- public int anInstanceVar = 5;
-
- public SerialPersistentFieldsWithoutField() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- in.readFields();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- out.putFields();
- out.writeFields();
- }
- }
-
- private static class NotSerializable {
- private int foo;
-
- public NotSerializable() {
- }
-
- protected Object writeReplace() throws ObjectStreamException {
- return new Integer(42);
- }
- }
-
- private static class WriteReplaceObject implements Serializable {
- private Object replaceObject;
-
- private static enum Color {
- red, blue, green
- };
-
- public WriteReplaceObject(Object o) {
- replaceObject = o;
- }
-
- protected Object writeReplace() throws ObjectStreamException {
- return replaceObject;
- }
- }
-
- private static class ExternalizableWithReplace implements Externalizable {
- private int foo;
-
- public ExternalizableWithReplace() {
- }
-
- protected Object writeReplace() throws ObjectStreamException {
- return new Integer(42);
- }
-
- public void writeExternal(ObjectOutput out) {
- }
-
- public void readExternal(ObjectInput in) {
- }
- }
-
- private static class ObjectOutputStreamWithReplace extends ObjectOutputStream {
- public ObjectOutputStreamWithReplace(OutputStream out) throws IOException {
- super(out);
- enableReplaceObject(true);
- }
-
- protected Object replaceObject(Object obj) throws IOException {
- if (obj instanceof NotSerializable) {
- return new Long(10);
- } else if (obj instanceof Integer) {
- return new Long(((Integer) obj).longValue());
- } else {
- return obj;
- }
- }
- }
-
- private static class ObjectOutputStreamWithReplace2 extends
- ObjectOutputStream {
- public ObjectOutputStreamWithReplace2(OutputStream out)
- throws IOException {
- super(out);
- enableReplaceObject(true);
- }
-
- protected Object replaceObject(Object obj) throws IOException {
- return new Long(10);
- }
- }
-
- private static class BasicObjectOutputStream extends ObjectOutputStream {
- public boolean writeStreamHeaderCalled;
-
- public BasicObjectOutputStream() throws IOException, SecurityException {
- super();
- writeStreamHeaderCalled = false;
- }
-
- public BasicObjectOutputStream(OutputStream output) throws IOException {
- super(output);
- }
-
- public void drain() throws IOException {
- super.drain();
- }
-
- public boolean enableReplaceObject(boolean enable)
- throws SecurityException {
- return super.enableReplaceObject(enable);
- }
-
- public void writeObjectOverride(Object object) throws IOException {
- super.writeObjectOverride(object);
- }
-
- public void writeStreamHeader() throws IOException {
- super.writeStreamHeader();
- writeStreamHeaderCalled = true;
- }
-}
-
- private static class NoFlushTestOutputStream extends ByteArrayOutputStream {
- public boolean flushCalled;
-
- public NoFlushTestOutputStream() {
- super();
- flushCalled = false;
- }
-
- public void flush() throws IOException {
- super.flush();
- flushCalled = true;
- }
- }
-
- protected static final String MODE_XLOAD = "xload";
-
- protected static final String MODE_XDUMP = "xdump";
-
- static final String FOO = "foo";
-
- static final String MSG_WITE_FAILED = "Failed to write: ";
-
- private static final boolean DEBUG = false;
-
- protected static boolean xload = false;
-
- protected static boolean xdump = false;
-
- protected static String xFileName = null;
-
- protected ObjectInputStream ois;
-
- protected ObjectOutputStream oos;
-
- protected ObjectOutputStream oos_ioe;
-
- protected Support_OutputStream sos;
-
- protected ByteArrayOutputStream bao;
-
- static final int INIT_INT_VALUE = 7;
-
- static final String INIT_STR_VALUE = "a string that is blortz";
-
- /**
- * @tests java.io.ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks valid construction, NullPointerException and IOException.",
- method = "ObjectOutputStream",
- args = {java.io.OutputStream.class}
- )
- public void test_ConstructorLjava_io_OutputStream() throws IOException {
- oos.close();
- oos = new ObjectOutputStream(new ByteArrayOutputStream());
- oos.close();
-
- try {
- oos = new ObjectOutputStream(null);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- Support_ASimpleOutputStream sos = new Support_ASimpleOutputStream(true);
- try {
- oos = new ObjectOutputStream(sos);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- int outputSize = bao.size();
- // Writing of a primitive type should be buffered.
- oos.writeInt(42);
- assertTrue("Test 1: Primitive data unexpectedly written to the target stream.",
- bao.size() == outputSize);
- // Closing should write the buffered data to the target stream.
- oos.close();
- assertTrue("Test 2: Primitive data has not been written to the the target stream.",
- bao.size() > outputSize);
-
- try {
- oos_ioe.close();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#drain()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "drain",
- args = {}
- )
- public void test_drain() throws IOException {
- NoFlushTestOutputStream target = new NoFlushTestOutputStream();
- BasicObjectOutputStream boos = new BasicObjectOutputStream(target);
- int initialSize = target.size();
- boolean written = false;
-
- boos.writeBytes("Lorem ipsum");
- // If there is no buffer then the bytes have already been written.
- written = (target.size() > initialSize);
-
- boos.drain();
- assertTrue("Content has not been written to the target.",
- written || (target.size() > initialSize));
- assertFalse("flush() has been called on the target.",
- target.flushCalled);
- }
-
- /**
- * @tests java.io.ObjectOutputStream#defaultWriteObject()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException can not be tested because this method" +
- "always throws a NotActiveException if called directly.",
- method = "defaultWriteObject",
- args = {}
- )
- public void test_defaultWriteObject() throws IOException {
- try {
- oos.defaultWriteObject();
- fail("Test 1: NotActiveException expected.");
- } catch (NotActiveException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#enableReplaceObject(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "enableReplaceObject",
- args = {boolean.class}
- )
- public void test_enableReplaceObjectB() throws IOException {
- // Start testing without a SecurityManager.
- BasicObjectOutputStream boos = new BasicObjectOutputStream();
- assertFalse("Test 1: Object resolving must be disabled by default.",
- boos.enableReplaceObject(true));
-
- assertTrue("Test 2: enableReplaceObject did not return the previous value.",
- boos.enableReplaceObject(false));
- }
-
- /**
- * @tests java.io.ObjectOutputStream#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "flush",
- args = {}
- )
- public void test_flush() throws Exception {
- // Test for method void java.io.ObjectOutputStream.flush()
- int size = bao.size();
- oos.writeByte(127);
- assertTrue("Test 1: Data already flushed.", bao.size() == size);
- oos.flush();
- assertTrue("Test 2: Failed to flush data.", bao.size() > size);
-
- try {
- oos_ioe.flush();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#putFields()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException can not be tested because this method" +
- "always throws a NotActiveException if called directly.",
- method = "putFields",
- args = {}
- )
- public void test_putFields() throws Exception {
- /*
- * "SerializableTestHelper" is an object created for these tests with
- * two fields (Strings) and simple implementations of readObject and
- * writeObject which simply read and write the first field but not the
- * second one.
- */
- SerializableTestHelper sth;
-
- try {
- oos.putFields();
- fail("Test 1: NotActiveException expected.");
- } catch (NotActiveException e) {
- // Expected.
- }
-
- oos.writeObject(new SerializableTestHelper("Gabba", "Jabba"));
- oos.flush();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- sth = (SerializableTestHelper) (ois.readObject());
- assertEquals("Test 2: readFields or writeFields failed; first field not set.",
- "Gabba", sth.getText1());
- assertNull("Test 3: readFields or writeFields failed; second field should not have been set.",
- sth.getText2());
- }
-
- /**
- * @tests java.io.ObjectOutputStream#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- )
- public void test_reset() throws Exception {
- String o = "HelloWorld";
- sos = new Support_OutputStream(200);
- oos.close();
- oos = new ObjectOutputStream(sos);
- oos.writeObject(o);
- oos.writeObject(o);
- oos.reset();
- oos.writeObject(o);
-
- sos.setThrowsException(true);
- try {
- oos.reset();
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sos.setThrowsException(false);
-
- ois = new ObjectInputStream(new ByteArrayInputStream(sos.toByteArray()));
- assertEquals("Test 2: Incorrect object read.", o, ois.readObject());
- assertEquals("Test 3: Incorrect object read.", o, ois.readObject());
- assertEquals("Test 4: Incorrect object read.", o, ois.readObject());
- ois.close();
- }
-
- private static class ExternalTest implements Externalizable {
- public String value;
-
- public ExternalTest() {
- }
-
- public void setValue(String val) {
- value = val;
- }
-
- public String getValue() {
- return value;
- }
-
- public void writeExternal(ObjectOutput output) {
- try {
- output.writeUTF(value);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public void readExternal(ObjectInput input) {
- try {
- value = input.readUTF();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#useProtocolVersion(int)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException seems to be never thrown, therefore there is no such test.",
- method = "useProtocolVersion",
- args = {int.class}
- )
- public void test_useProtocolVersionI() throws Exception {
-
- oos.useProtocolVersion(ObjectOutputStream.PROTOCOL_VERSION_1);
- ExternalTest t1 = new ExternalTest();
- t1.setValue("hello1");
- oos.writeObject(t1);
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- ExternalTest t2 = (ExternalTest) ois.readObject();
- ois.close();
- assertTrue(
- "Cannot read/write PROTOCAL_VERSION_1 Externalizable objects: "
- + t2.getValue(), t1.getValue().equals(t2.getValue()));
- }
-
- /**
- * @tests java.io.ObjectOutputStream#write(byte[])
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "write",
- args = {byte[].class}
- )
- public void test_write$B() throws Exception {
- // Test for method void java.io.ObjectOutputStream.write(byte [])
- byte[] buf = new byte[10];
- oos.write("HelloWorld".getBytes());
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- ois.read(buf, 0, 10);
- ois.close();
- assertEquals("Read incorrect bytes", "HelloWorld", new String(buf, 0,
- 10));
- }
-
- /**
- * @tests java.io.ObjectOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() throws Exception {
- // Test for method void java.io.ObjectOutputStream.write(byte [], int,
- // int)
- byte[] buf = new byte[10];
- oos.write("HelloWorld".getBytes(), 0, 10);
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- ois.read(buf, 0, 10);
- ois.close();
- assertEquals("Read incorrect bytes", "HelloWorld", new String(buf, 0,
- 10));
-
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- try {
- ois.read(buf, 0, -1);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- ois.read(buf, -1, 1);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- ois.read(buf, 10, 1);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- ois.close();
-
- }
-
- /**
- * @tests java.io.ObjectOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws Exception {
- // Test for method void java.io.ObjectOutputStream.write(int)
- oos.write('T');
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- assertEquals("Read incorrect byte", 'T', ois.read());
- ois.close();
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeBytes(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeBytes",
- args = {java.lang.String.class}
- )
- public void test_writeBytesLjava_lang_String() throws Exception {
- // Test for method void
- // java.io.ObjectOutputStream.writeBytes(java.lang.String)
- byte[] buf = new byte[10];
- oos.writeBytes("HelloWorld");
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- ois.readFully(buf);
- ois.close();
- assertEquals("Wrote incorrect bytes value", "HelloWorld", new String(
- buf, 0, 10));
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeChars(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeChars",
- args = {java.lang.String.class}
- )
- public void test_writeCharsLjava_lang_String() throws Exception {
- // Test for method void
- // java.io.ObjectOutputStream.writeChars(java.lang.String)
- int avail = 0;
- char[] buf = new char[10];
- oos.writeChars("HelloWorld");
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- // Number of prim data bytes in stream / 2 to give char index
- avail = ois.available() / 2;
- for (int i = 0; i < avail; ++i)
- buf[i] = ois.readChar();
- ois.close();
- assertEquals("Wrote incorrect chars", "HelloWorld", new String(buf, 0,
- 10));
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeObject(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "writeObject",
- args = {java.lang.Object.class}
- )
- public void test_writeObjectLjava_lang_Object() throws Exception {
- // Test for method void
- // java.io.ObjectOutputStream.writeObject(java.lang.Object)
-
- Object objToSave = null;
- Object objLoaded;
-
- SerialPersistentFieldsWithoutField spf = new SerialPersistentFieldsWithoutField();
- final int CONST = -500;
- spf.anInstanceVar = CONST;
- objToSave = spf;
- if (DEBUG)
- System.out.println("Obj = " + objToSave);
- objLoaded = dumpAndReload(objToSave);
- assertTrue(
- "serialPersistentFields do not work properly in this implementation",
- ((SerialPersistentFieldsWithoutField) objLoaded).anInstanceVar != CONST);
-
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeObject(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "writeObject",
- args = {java.lang.Object.class}
- )
- public void test_writeObject_NotSerializable() throws Exception {
- ObjectOutput out = null;
- try {
- out = new ObjectOutputStream(new ByteArrayOutputStream());
- out.writeObject(new NotSerializable());
- fail("Expected NotSerializableException");
- } catch (NotSerializableException e) {}
- out.writeObject(new ExternalizableWithReplace());
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeObjectOverride(Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that writeObjectOverride() throws an IOException.",
- method = "writeObjectOverride",
- args = {java.lang.Object.class}
- )
- public void test_writeObjectOverrideLjava_lang_Object() throws IOException {
- BasicObjectOutputStream boos =
- new BasicObjectOutputStream(new ByteArrayOutputStream());
-
- try {
- boos.writeObjectOverride(new Object());
- fail("IOException expected.");
- }
- catch (IOException e) {
- }
- finally {
- boos.close();
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeStreamHeader()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies writeStreamHeader().",
- method = "writeStreamHeader",
- args = {}
- )
- public void test_writeStreamHeader() throws IOException {
- BasicObjectOutputStream boos;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- short s;
- byte[] buffer;
-
- // Test 1: Make sure that writeStreamHeader() has been called.
- boos = new BasicObjectOutputStream(baos);
- try {
- assertTrue("Test 1: writeStreamHeader() has not been called.",
- boos.writeStreamHeaderCalled);
-
- // Test 2: Check that at least four bytes have been written.
- buffer = baos.toByteArray();
- assertTrue("Test 2: At least four bytes should have been written",
- buffer.length >= 4);
-
- // Test 3: Check the magic number.
- s = buffer[0];
- s <<= 8;
- s += ((short) buffer[1] & 0x00ff);
- assertEquals("Test 3: Invalid magic number written.",
- java.io.ObjectStreamConstants.STREAM_MAGIC, s);
-
- // Test 4: Check the stream version number.
- s = buffer[2];
- s <<= 8;
- s += ((short) buffer[3] & 0x00ff);
- assertEquals("Invalid stream version number written.",
- java.io.ObjectStreamConstants.STREAM_VERSION, s);
- }
- finally {
- boos.close();
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeUTF(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IOException checking missed.",
- method = "writeUTF",
- args = {java.lang.String.class}
- )
- public void test_writeUTFLjava_lang_String() throws Exception {
- // Test for method void
- // java.io.ObjectOutputStream.writeUTF(java.lang.String)
- oos.writeUTF("HelloWorld");
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- assertEquals("Wrote incorrect UTF value", "HelloWorld", ois.readUTF());
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeObject(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "writeObject",
- args = {java.lang.Object.class}
- )
- public void test_writeObject_Exception() throws ClassNotFoundException, IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- ObjectOutputStream oos = new ObjectOutputStream(baos);
-
- try {
- oos.writeObject(new Object());
- fail("should throw ObjectStreamException");
- } catch (ObjectStreamException e) {
- // expected
- } finally {
- oos.close();
- baos.close();
- }
-
- byte[] bytes = baos.toByteArray();
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
- bytes));
- try {
- ois.readObject();
- fail("should throw WriteAbortedException");
- } catch (WriteAbortedException e) {
- // expected
- } finally {
- ois.close();
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() throws Exception {
- super.setUp();
- oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
- oos_ioe = new ObjectOutputStream(sos = new Support_OutputStream());
- sos.setThrowsException(true);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- if (oos != null) {
- try {
- oos.close();
- } catch (Exception e) {}
- }
- if (oos_ioe != null) {
- try {
- oos_ioe.close();
- } catch (Exception e) {}
- }
- if (f != null && f.exists()) {
- if (!f.delete()) {
- fail("Error cleaning up files during teardown");
- }
- }
- }
-
- protected Object reload() throws IOException, ClassNotFoundException {
-
- // Choose the load stream
- if (xload || xdump) {
- // Load from pre-existing file
- ois = new ObjectInputStream(new FileInputStream(xFileName + "-"
- + getName() + ".ser"));
- } else {
- // Just load from memory, we dumped to memory
- ois = new ObjectInputStream(new ByteArrayInputStream(bao
- .toByteArray()));
- }
-
- try {
- return ois.readObject();
- } finally {
- ois.close();
- }
- }
-
- protected void dump(Object o) throws IOException, ClassNotFoundException {
-
- // Choose the dump stream
- if (xdump) {
- oos = new ObjectOutputStream(new FileOutputStream(
- f = new java.io.File(xFileName + "-" + getName() + ".ser")));
- } else {
- oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
- }
-
- // Dump the object
- try {
- oos.writeObject(o);
- } finally {
- oos.close();
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeInt(int)
- * @tests java.io.ObjectOutputStream#writeObject(java.lang.Object)
- * @tests java.io.ObjectOutputStream#writeUTF(java.lang.String)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "writeInt",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "writeObject",
- args = {java.lang.Object.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "writeUTF",
- args = {java.lang.String.class}
- )
- })
- public void testMixPrimitivesAndObjects() throws Exception {
- int i = 7;
- String s1 = "string 1";
- String s2 = "string 2";
- byte[] bytes = { 1, 2, 3 };
- try {
- oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
- oos.writeInt(i);
- oos.writeObject(s1);
- oos.writeUTF(s2);
- oos.writeObject(bytes);
- oos.close();
-
- ois = new ObjectInputStream(new ByteArrayInputStream(bao
- .toByteArray()));
-
- int j = ois.readInt();
- assertTrue("Wrong int :" + j, i == j);
-
- String l1 = (String) ois.readObject();
- assertTrue("Wrong obj String :" + l1, s1.equals(l1));
-
- String l2 = ois.readUTF();
- assertTrue("Wrong UTF String :" + l2, s2.equals(l2));
-
- byte[] bytes2 = (byte[]) ois.readObject();
- assertTrue("Wrong byte[]", Arrays.equals(bytes, bytes2));
- } finally {
- try {
- if (oos != null)
- oos.close();
- if (ois != null)
- ois.close();
- } catch (IOException e) {}
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeUnshared(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "writeUnshared",
- args = {java.lang.Object.class}
- )
- public void test_writeUnshared() throws Exception {
- //Regression for HARMONY-187
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
-
- Object o = "foobar";
- oos.writeObject(o);
- oos.writeUnshared(o);
- oos.writeObject(o);
- oos.flush();
-
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
-
- Object[] oa = new Object[3];
- for (int i = 0; i < oa.length; i++) {
- oa[i] = ois.readObject();
- }
-
- oos.close();
- ois.close();
-
- // All three conditions must be met
- assertNotSame("oa[0] != oa[1]", oa[0], oa[1]);
- assertNotSame("oa[1] != oa[2]", oa[1], oa[2]);
- assertSame("oa[0] == oa[2]", oa[0], oa[2]);
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeUnshared(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "writeUnshared",
- args = {java.lang.Object.class}
- )
- public void test_writeUnshared2() throws Exception {
- //Regression for HARMONY-187
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
-
- Object o = new Object[1];
- oos.writeObject(o);
- oos.writeUnshared(o);
- oos.writeObject(o);
- oos.flush();
-
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
-
- Object[] oa = new Object[3];
- for (int i = 0; i < oa.length; i++) {
- oa[i] = ois.readObject();
- }
-
- oos.close();
- ois.close();
-
- // All three conditions must be met
- assertNotSame("oa[0] != oa[1]", oa[0], oa[1]);
- assertNotSame("oa[1] != oa[2]", oa[1], oa[2]);
- assertSame("oa[0] == oa[2]", oa[0], oa[2]);
- }
-
- protected Object dumpAndReload(Object o) throws IOException,
- ClassNotFoundException {
- dump(o);
- return reload();
- }
-
- /**
- * @tests java.io.ObjectOutputStream#useProtocolVersion(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IOException & IllegalStateException checking missed.",
- method = "useProtocolVersion",
- args = {int.class}
- )
- public void test_useProtocolVersionI_2() throws Exception {
- ObjectOutputStream oos = new ObjectOutputStream(
- new ByteArrayOutputStream());
-
- oos.useProtocolVersion(ObjectOutputStream.PROTOCOL_VERSION_1);
- oos.useProtocolVersion(ObjectOutputStream.PROTOCOL_VERSION_2);
- try {
- oos.useProtocolVersion(3);
- fail("Protocol 3 should not be accepted");
- } catch (IllegalArgumentException e) {
- // expected
- } finally {
- oos.close();
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#replaceObject(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "replaceObject",
- args = {java.lang.Object.class}
- )
- public void test_replaceObject() throws Exception {
- //Regression for HARMONY-1429
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStreamWithReplace oos = new ObjectOutputStreamWithReplace(baos);
-
- oos.writeObject(new NotSerializable());
- oos.flush();
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
- Object obj = ois.readObject();
- oos.close();
- ois.close();
- assertTrue("replaceObject has not been called", (obj instanceof Long));
-
- //Regression for HARMONY-2239
- Object replaceObject = int.class;
- baos = new ByteArrayOutputStream();
- ObjectOutputStreamWithReplace2 oos2 = new ObjectOutputStreamWithReplace2(
- baos);
- oos2.writeObject(new WriteReplaceObject(replaceObject));
- oos2.flush();
- ois = new ObjectInputStream(
- new ByteArrayInputStream(baos.toByteArray()));
- obj = ois.readObject();
- oos.close();
- ois.close();
- assertTrue("replaceObject has not been called", (obj instanceof Long));
-
- replaceObject = ObjectStreamClass.lookup(Integer.class);
- baos = new ByteArrayOutputStream();
- oos2 = new ObjectOutputStreamWithReplace2(baos);
- oos2.writeObject(new WriteReplaceObject(replaceObject));
- oos2.flush();
- ois = new ObjectInputStream(
- new ByteArrayInputStream(baos.toByteArray()));
- obj = ois.readObject();
- oos.close();
- ois.close();
- assertTrue("replaceObject has not been called", (obj instanceof Long));
-
- replaceObject = WriteReplaceObject.Color.red;
- baos = new ByteArrayOutputStream();
- oos2 = new ObjectOutputStreamWithReplace2(baos);
- oos2.writeObject(new WriteReplaceObject(replaceObject));
- oos2.flush();
- ois = new ObjectInputStream(
- new ByteArrayInputStream(baos.toByteArray()));
- obj = ois.readObject();
- oos.close();
- ois.close();
- assertTrue("replaceObject has not been called", (obj instanceof Long));
-
- // Regression for HARMONY-3158
- Object obj1;
- Object obj2;
- Object obj3;
-
- baos = new ByteArrayOutputStream();
- oos = new ObjectOutputStreamWithReplace(baos);
-
- oos.writeObject(new Integer(99));
- oos.writeObject(Integer.class);
- oos.writeObject(ObjectStreamClass.lookup(Integer.class));
- oos.flush();
-
- ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
- obj1 = ois.readObject();
- obj2 = ois.readObject();
- obj3 = ois.readObject();
- oos.close();
- ois.close();
-
- assertTrue("1st replaceObject worked incorrectly", obj1 instanceof Long);
- assertEquals("1st replaceObject worked incorrectly",
- 99, ((Long) obj1).longValue());
- assertEquals("2nd replaceObject worked incorrectly", Integer.class, obj2);
- assertEquals("3rd replaceObject worked incorrectly",
- ObjectStreamClass.class, obj3.getClass());
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectStreamClassTest.java b/luni/src/test/java/tests/api/java/io/ObjectStreamClassTest.java
deleted file mode 100644
index 79cdebe..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectStreamClassTest.java
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import dalvik.system.DexClassLoader;
-import java.io.Externalizable;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.ObjectStreamClass;
-import java.io.ObjectStreamField;
-import java.io.Serializable;
-import java.lang.reflect.Proxy;
-import junit.framework.TestCase;
-import libcore.base.Streams;
-
-public class ObjectStreamClassTest extends TestCase {
-
- static class DummyClass implements Serializable {
- private static final long serialVersionUID = 999999999999999L;
-
- long bam = 999L;
-
- int ham = 9999;
-
- public static long getUID() {
- return serialVersionUID;
- }
- }
-
- /**
- * @tests java.io.ObjectStreamClass#forClass()
- */
- public void test_forClass() {
- // Need to test during serialization to be sure an instance is
- // returned
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertEquals("forClass returned an object: " + osc.forClass(),
- DummyClass.class, osc.forClass());
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getField(java.lang.String)
- */
- public void test_getFieldLjava_lang_String() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertEquals("getField did not return correct field", 'J', osc
- .getField("bam").getTypeCode());
- assertNull("getField did not null for non-existent field", osc
- .getField("wham"));
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getFields()
- */
- public void test_getFields() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- ObjectStreamField[] osfArray = osc.getFields();
- assertTrue(
- "Array of fields should be of length 2 but is instead of length: "
- + osfArray.length, osfArray.length == 2);
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getName()
- */
- public void test_getName() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertEquals(
- "getName returned incorrect name: " + osc.getName(),
- "tests.api.java.io.ObjectStreamClassTest$DummyClass", // android-changed
- osc.getName());
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getSerialVersionUID()
- */
- public void test_getSerialVersionUID() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertTrue("getSerialversionUID returned incorrect uid: "
- + osc.getSerialVersionUID() + " instead of "
- + DummyClass.getUID(), osc.getSerialVersionUID() == DummyClass
- .getUID());
- }
-
- static class SyntheticTest implements Serializable {
- private int i;
-
- private class X implements Serializable {
- public int get() {
- return i;
- }
- }
-
- public X foo() {
- return new X();
- }
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getSerialVersionUID()
- */
- public void test_getSerialVersionUID_inner_private_class() {
- ObjectStreamClass osc1 = ObjectStreamClass.lookup(SyntheticTest.class);
- assertEquals(4405770616475181267L, osc1.getSerialVersionUID());
-
- ObjectStreamClass osc2 = ObjectStreamClass.lookup(SyntheticTest.X.class);
- assertEquals(676101599466902119L, osc2.getSerialVersionUID());
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getSerialVersionUID()
- */
- public void test_getSerialVersionUID_classloader() throws Exception {
- ClassLoader loader = newClassLoaderForJar(
- "/org/apache/harmony/luni/tests/ObjectStreamClassTest.jar");
- Class cl1 = Class.forName("Test1$TestVarArgs", false, loader);
- ObjectStreamClass osc1 = ObjectStreamClass.lookup(cl1);
- assertEquals("Test1$TestVarArgs unexpected UID: "
- + osc1.getSerialVersionUID(), -6051121963037986215L, osc1
- .getSerialVersionUID());
-
- Class cl2 = Class.forName("Test1$TestBridge", false, loader);
- ObjectStreamClass osc2 = ObjectStreamClass.lookup(cl2);
- assertEquals("Test1$TestBridge unexpected UID: "
- + osc2.getSerialVersionUID(), 568585976855071180L, osc2
- .getSerialVersionUID());
- }
-
- private ClassLoader newClassLoaderForJar(String resourceJar) throws IOException {
- File dex = File.createTempFile("dex", "jar");
- Streams.copy(getClass().getResourceAsStream(resourceJar), new FileOutputStream(dex));
- return new DexClassLoader(dex.getPath(), dex.getParentFile().getPath(), null,
- getClass().getClassLoader());
- }
-
- /**
- * @tests java.io.ObjectStreamClass#lookup(java.lang.Class)
- */
- public void test_lookupLjava_lang_Class() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertEquals(
- "lookup returned wrong class: " + osc.getName(),
- "tests.api.java.io.ObjectStreamClassTest$DummyClass", // android-changed
- osc.getName());
- }
-
- /**
- * @tests java.io.ObjectStreamClass#toString()
- */
- public void test_toString() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- String oscString = osc.toString();
-
- // The previous test was more specific than the spec so it was replaced
- // with the test below
- assertTrue("toString returned incorrect string: " + osc.toString(),
- oscString.indexOf("serialVersionUID") >= 0
- && oscString.indexOf("999999999999999L") >= 0);
- }
-
- public void testSerialization() {
- ObjectStreamClass osc = ObjectStreamClass
- .lookup(ObjectStreamClass.class);
- assertEquals(0, osc.getFields().length);
- }
-
- public void test_specialTypes() {
- Class<?> proxyClass = Proxy.getProxyClass(this.getClass()
- .getClassLoader(), new Class[] { Runnable.class });
-
- ObjectStreamClass proxyStreamClass = ObjectStreamClass
- .lookup(proxyClass);
-
- assertEquals("Proxy classes should have zero serialVersionUID", 0,
- proxyStreamClass.getSerialVersionUID());
- ObjectStreamField[] proxyFields = proxyStreamClass.getFields();
- assertEquals("Proxy classes should have no serialized fields", 0,
- proxyFields.length);
-
- ObjectStreamClass enumStreamClass = ObjectStreamClass
- .lookup(Thread.State.class);
-
- assertEquals("Enum classes should have zero serialVersionUID", 0,
- enumStreamClass.getSerialVersionUID());
- ObjectStreamField[] enumFields = enumStreamClass.getFields();
- assertEquals("Enum classes should have no serialized fields", 0,
- enumFields.length);
- }
-
- /**
- * @since 1.6
- */
- static class NonSerialzableClass {
- private static final long serialVersionUID = 1l;
- public static long getUID() {
- return serialVersionUID;
- }
- }
-
- /**
- * @since 1.6
- */
- static class ExternalizableClass implements Externalizable {
-
- private static final long serialVersionUID = -4285635779249689129L;
-
- public void readExternal(ObjectInput input) throws IOException, ClassNotFoundException {
- throw new ClassNotFoundException();
- }
-
- public void writeExternal(ObjectOutput output) throws IOException {
- throw new IOException();
- }
-
- }
-
- /**
- * @tests java.io.ObjectStreamClass#lookupAny(java.lang.Class)
- * @since 1.6
- */
- public void test_lookupAnyLjava_lang_Class() {
- // Test for method java.io.ObjectStreamClass
- // java.io.ObjectStreamClass.lookupAny(java.lang.Class)
- ObjectStreamClass osc = ObjectStreamClass.lookupAny(DummyClass.class);
- assertEquals("lookup returned wrong class: " + osc.getName(),
- "tests.api.java.io.ObjectStreamClassTest$DummyClass", osc // android-changed
- .getName());
-
- osc = ObjectStreamClass.lookupAny(NonSerialzableClass.class);
- assertEquals("lookup returned wrong class: " + osc.getName(),
- "tests.api.java.io.ObjectStreamClassTest$NonSerialzableClass", // android-changed
- osc.getName());
-
- osc = ObjectStreamClass.lookupAny(ExternalizableClass.class);
- assertEquals("lookup returned wrong class: " + osc.getName(),
- "tests.api.java.io.ObjectStreamClassTest$ExternalizableClass", // android-changed
- osc.getName());
-
- osc = ObjectStreamClass.lookup(NonSerialzableClass.class);
- assertNull(osc);
-
- }
-
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectStreamExceptionTest.java b/luni/src/test/java/tests/api/java/io/ObjectStreamExceptionTest.java
deleted file mode 100644
index 30a0c4e..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectStreamExceptionTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.ObjectStreamException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(ObjectStreamException.class)
-public class ObjectStreamExceptionTest extends junit.framework.TestCase {
-
- class MyObjectStreamException extends ObjectStreamException {
- private static final long serialVersionUID = 1L;
-
- public MyObjectStreamException() {
- super();
- }
-
- public MyObjectStreamException(String detailMessage) {
- super(detailMessage);
- }
- }
-
- /**
- * @tests java.io.ObjectStreamException#ObjectStreamException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ObjectStreamException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new MyObjectStreamException();
- fail("Test 1: MyObjectStreamException expected.");
- } catch (MyObjectStreamException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.ObjectStreamException#ObjectStreamException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ObjectStreamException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new MyObjectStreamException("Something went wrong.");
- fail("Test 1: MyObjectStreamException expected.");
- } catch (MyObjectStreamException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectStreamFieldTest.java b/luni/src/test/java/tests/api/java/io/ObjectStreamFieldTest.java
deleted file mode 100644
index dd8545b..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectStreamFieldTest.java
+++ /dev/null
@@ -1,537 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.NotActiveException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamClass;
-import java.io.ObjectStreamField;
-import java.io.Serializable;
-import java.io.StreamCorruptedException;
-import java.util.Date;
-
-@TestTargetClass(ObjectStreamField.class)
-public class ObjectStreamFieldTest extends junit.framework.TestCase {
-
- static class DummyClass implements Serializable {
- private static final long serialVersionUID = 999999999999998L;
-
- boolean bField = true;
- char cField = 'c';
- double dField = 424242.4242;
- float fField = 24.12F;
- int iField = 1965;
- long lField = 9999999L;
- short sField = 42;
-
- long bam = 999L;
-
- int ham = 9999;
-
- int sam = 8888;
-
- Object hola = new Object();
-
- public static long getUID() {
- return serialVersionUID;
- }
- }
-
- class MyObjectStreamField extends ObjectStreamField {
- public MyObjectStreamField(String name, Class<?> cl) {
- super(name, cl);
- }
-
- public void setOffset(int newValue) {
- super.setOffset(newValue);
- }
- }
-
- ObjectStreamClass osc;
-
- ObjectStreamField hamField;
-
- ObjectStreamField samField;
-
- ObjectStreamField bamField;
-
- ObjectStreamField holaField;
-
- /**
- * @tests java.io.ObjectStreamField#ObjectStreamField(java.lang.String,
- * java.lang.Class)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies ObjectStreamField(String, Class<T>)",
- method = "ObjectStreamField",
- args = {java.lang.String.class, java.lang.Class.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_Class() {
- ObjectStreamField osf = new ObjectStreamField("aField", int.class);
- assertTrue("Test 1: Name member not set correctly.",
- osf.getName().equals("aField"));
- assertTrue("Test 2: Type member not set correctly.",
- osf.getType().equals(int.class));
-
- // Repeat the tests with a different object to make sure
- // that we have not tested against default values.
- osf = new ObjectStreamField("anotherField", String.class);
- assertTrue("Test 3: Name member not set correctly.",
- osf.getName().equals("anotherField"));
- assertTrue("Test 4: Type member not set correctly.",
- osf.getType().equals(String.class));
-
- // Invalid argument tests.
- try {
- osf = new ObjectStreamField(null, boolean.class);
- fail("Test 5: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- try {
- osf = new ObjectStreamField("thisField", null);
- fail("Test 6: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectStreamField#ObjectStreamField(java.lang.String,
- * java.lang.Class)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies ObjectStreamField(String, Class<T>, boolean)",
- method = "ObjectStreamField",
- args = {java.lang.String.class, java.lang.Class.class, boolean.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_ClassB() {
- ObjectStreamField osf = new ObjectStreamField("aField", int.class, false);
- assertTrue("Test 1: Name member not set correctly.",
- osf.getName().equals("aField"));
- assertTrue("Test 2: Type member not set correctly.",
- osf.getType().equals(int.class));
- assertFalse("Test 3: Unshared member not set correctly.",
- osf.isUnshared());
-
- // Repeat the tests with a different object to make sure
- // that we have not tested against default values.
- osf = new ObjectStreamField("anotherField", String.class, true);
- assertTrue("Test 4: Name member not set correctly.",
- osf.getName().equals("anotherField"));
- assertTrue("Test 5: Type member not set correctly.",
- osf.getType().equals(String.class));
- assertTrue("Test 6: Unshared member not set correctly.",
- osf.isUnshared());
-
- // Invalid argument tests.
- try {
- osf = new ObjectStreamField(null, boolean.class);
- fail("Test 7: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- try {
- osf = new ObjectStreamField("thisField", null);
- fail("Test 8: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectStreamField#compareTo(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.lang.Object.class}
- )
- public void test_compareToLjava_lang_Object() {
- // Test for method int
- // java.io.ObjectStreamField.compareTo(java.lang.Object)
- assertTrue("Object compared to int did not return > 0", holaField
- .compareTo(hamField) > 0);
- assertEquals("Int compared to itself did not return 0", 0, hamField
- .compareTo(hamField));
- assertTrue("(Int)ham compared to (Int)sam did not return < 0", hamField
- .compareTo(samField) < 0);
- }
-
- /**
- * @tests java.io.ObjectStreamField#getName()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getName",
- args = {}
- )
- public void test_getName() {
- // Test for method java.lang.String java.io.ObjectStreamField.getName()
- assertEquals("Field did not return correct name", "hola", holaField.getName());
- }
-
- /**
- * @tests java.io.ObjectStreamField#getOffset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getOffset",
- args = {}
- )
- public void test_getOffset() {
- // Test for method int java.io.ObjectStreamField.getOffset()
- ObjectStreamField[] osfArray;
- osfArray = osc.getFields();
- int[] expectedOffsets = {0, 1, 9, 11, 19, 23, 27, 31, 39, 41, 0};
-
- assertTrue("getOffset() did not return reasonable values.", osfArray[0]
- .getOffset() != osfArray[1].getOffset());
-
- for (int i = 0; i < expectedOffsets.length; i++) {
- assertEquals(String.format("Unexpected value for osfArray[%d].getOffset(): ", i),
- expectedOffsets[i], osfArray[i].getOffset());
-
- }
- }
-
- /**
- * @tests java.io.ObjectStreamField#getType()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getType",
- args = {}
- )
- public void test_getType() {
- // Test for method java.lang.Class java.io.ObjectStreamField.getType()
- assertTrue("getType on an Object field did not answer Object",
- holaField.getType().equals(Object.class));
- }
-
- /**
- * @tests java.io.ObjectStreamField#getTypeCode()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTypeCode",
- args = {}
- )
- public void test_getTypeCode() {
- // Test for method char java.io.ObjectStreamField.getTypeCode()
- assertEquals("getTypeCode on an Object field did not answer 'L'",
- 'L', holaField.getTypeCode());
- assertEquals("getTypeCode on a long field did not answer 'J'", 'J', bamField
- .getTypeCode());
- }
-
- /**
- * @tests java.io.ObjectStreamField#getTypeString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTypeString",
- args = {}
- )
- public void test_getTypeString() {
- assertTrue("getTypeString returned: " + holaField.getTypeString(),
- holaField.getTypeString().indexOf("Object") >= 0);
- assertNull("Primitive types' strings should be null", hamField.getTypeString());
-
- ObjectStreamField osf = new ObjectStreamField("s", String.class, true);
- assertTrue(osf.getTypeString() == "Ljava/lang/String;");
- }
-
- /**
- * @tests java.io.ObjectStreamField#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.io.ObjectStreamField.toString()
- assertTrue("toString on a long returned: " + bamField.toString(),
- bamField.toString().indexOf("bam") >= 0);
- }
-
- /**
- * @tests java.io.ObjectStreamField#getType()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getType",
- args = {}
- )
- public void test_getType_Deserialized() throws IOException,
- ClassNotFoundException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(new SerializableObject());
- oos.close();
- baos.close();
-
- byte[] bytes = baos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStream ois = new ObjectInputStream(bais);
- SerializableObject obj = (SerializableObject) ois.readObject();
-
- ObjectStreamClass oc = obj.getObjectStreamClass();
- ObjectStreamField field = oc.getField("i");
- assertEquals(Object.class, field.getType());
- }
-
- /**
- * @tests java.io.ObjectStreamField#setOffset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setOffset",
- args = {int.class}
- )
- public void test_setOffsetI() {
- MyObjectStreamField f = new MyObjectStreamField("aField", int.class);
- f.setOffset(42);
- assertEquals("Test 1: Unexpected offset value.", 42, f.getOffset());
- f.setOffset(2008);
- assertEquals("Test 2: Unexpected offset value.", 2008, f.getOffset());
- }
-
- /**
- * @tests java.io.ObjectStreamField#getType()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getType",
- args = {}
- )
- public void test_getType_MockObjectInputStream() throws IOException, ClassNotFoundException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(new SerializableObject());
- oos.close();
- baos.close();
-
- byte[] bytes = baos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- MockObjectInputStream ois = new MockObjectInputStream(bais);
- ois.readObject();
-
- ObjectStreamClass oc = ois.getObjectStreamClass();
- ObjectStreamField field = oc.getField("i");
- assertEquals(Object.class, field.getType());
- }
-
- /**
- * @tests java.io.ObjectStreamField#isPrimitive()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isPrimitive",
- args = {}
- )
- public void test_isPrimitive() {
- // Test for method int java.io.ObjectStreamField.getOffset()
- ObjectStreamField[] osfArray;
- osfArray = osc.getFields();
-
- for (int i = 0; i < (osfArray.length - 1); i++) {
- assertTrue(String.format("osfArray[%d].isPrimitive() should return true.", i),
- osfArray[i].isPrimitive());
- }
- assertFalse(String.format("osfArray[%d].isPrimitive() should return false.",
- osfArray.length - 1),
- osfArray[(osfArray.length - 1)].isPrimitive());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isUnshared",
- args = {}
- )
- public void test_isUnshared() throws Exception {
- SerializableObject2 obj = new SerializableObject2();
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(obj);
- oos.close();
- baos.close();
- byte[] bytes = baos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStream ois = new ObjectInputStream(bais);
- SerializableObject2 newObj = (SerializableObject2) ois.readObject();
-
- ObjectInputStream.GetField getField = newObj.getGetField();
- ObjectStreamClass objectStreamClass = getField.getObjectStreamClass();
-
- assertTrue(objectStreamClass.getField("i").isUnshared());
- assertFalse(objectStreamClass.getField("d").isUnshared());
- assertTrue(objectStreamClass.getField("s").isUnshared());
-
- assertEquals(1000, getField.get("i", null));
- assertEquals(SerializableObject2.today, getField.get("d", null));
- assertEquals("Richard", getField.get("s", null));
-
- assertTrue(objectStreamClass.getField("s").getTypeString() == "Ljava/lang/String;");
-
- assertEquals(0, objectStreamClass.getField("d").getOffset());
- assertEquals(1, objectStreamClass.getField("i").getOffset());
- assertEquals(2, objectStreamClass.getField("s").getOffset());
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- osc = ObjectStreamClass.lookup(DummyClass.class);
- bamField = osc.getField("bam");
- samField = osc.getField("sam");
- hamField = osc.getField("ham");
- holaField = osc.getField("hola");
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
-
-class SerializableObject implements Serializable {
- public ObjectInputStream.GetField getField = null;
-
- private static final long serialVersionUID = -2953957835918368056L;
-
- public Date d;
-
- public Integer i;
-
- public Exception e;
-
- public SerializableObject() {
- d = new Date();
- i = new Integer(1);
- e = new Exception("e");
- }
-
- private void writeObject(ObjectOutputStream o) throws IOException {
- o.putFields().put("d", new Date());
- o.putFields().put("i", new Integer(11));
- o.writeFields();
- }
-
- private void readObject(ObjectInputStream in) throws NotActiveException,
- IOException, ClassNotFoundException {
- getField = in.readFields();
- d = (Date) getField.get("d", null);
- i = (Integer) getField.get("i", null);
- }
-
- public ObjectStreamClass getObjectStreamClass() {
- return getField.getObjectStreamClass();
- }
-}
-
-class MockObjectInputStream extends ObjectInputStream {
- private ObjectStreamClass temp = null;
-
- public MockObjectInputStream() throws SecurityException, IOException {
- super();
- }
-
- public MockObjectInputStream(InputStream in)
- throws StreamCorruptedException, IOException {
- super(in);
- }
-
- public ObjectStreamClass readClassDescriptor() throws IOException,
- ClassNotFoundException {
- ObjectStreamClass osc = super.readClassDescriptor();
- //To get the ObjectStreamClass of SerializableObject
- if (osc.getSerialVersionUID() == -2953957835918368056L) {
- temp = osc;
- }
- return osc;
- }
-
- public ObjectStreamClass getObjectStreamClass() {
- return temp;
- }
-}
-
-class SerializableObject2 implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private static final ObjectStreamField[] serialPersistentFields = {
- new ObjectStreamField("i", Integer.class, true),
- new ObjectStreamField("d", Date.class, false),
- new ObjectStreamField("s", String.class, true),
- };
-
- private ObjectInputStream.GetField getField;
-
- public static Date today = new Date(1172632429156l);
-
- public ObjectInputStream.GetField getGetField() {
- return getField;
- }
-
- private void writeObject(ObjectOutputStream o) throws IOException {
- ObjectOutputStream.PutField putField = o.putFields();
- putField.put("i", new Integer(1000));
- putField.put("d", today);
- putField.put("s", "Richard");
- o.writeFields();
- }
-
- private void readObject(ObjectInputStream in) throws NotActiveException,
- IOException, ClassNotFoundException {
- getField = in.readFields();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/OpenRandomFileTest.java b/luni/src/test/java/tests/api/java/io/OpenRandomFileTest.java
deleted file mode 100644
index b2a1406..0000000
--- a/luni/src/test/java/tests/api/java/io/OpenRandomFileTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/* 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 tests.api.java.io;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-
-import junit.framework.TestCase;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-/**
- * TODO Type description
- */
-@TestTargetClass(RandomAccessFile.class)
-public class OpenRandomFileTest extends TestCase {
-
- public static void main(String[] args) {
- new OpenRandomFileTest().testOpenEmptyFile();
- }
-
- public OpenRandomFileTest() {
- super();
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "RandomAccessFile",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void testOpenNonEmptyFile() {
- try {
- File file = File.createTempFile("test", "tmp");
- assertTrue(file.exists());
- file.deleteOnExit();
- FileOutputStream fos = new FileOutputStream(file);
- fos.write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
- fos.close();
-
- String fileName = file.getCanonicalPath();
- RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
- raf.close();
- } catch (IOException ex) {
- fail(ex.getLocalizedMessage());
- }
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "RandomAccessFile",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void testOpenEmptyFile() {
- try {
- File file = File.createTempFile("test", "tmp");
- assertTrue(file.exists());
- file.deleteOnExit();
-
- String fileName = file.getCanonicalPath();
- RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
- raf.close();
- } catch (IOException ex) {
- fail(ex.getLocalizedMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java b/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java
deleted file mode 100644
index 171912b..0000000
--- a/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java
+++ /dev/null
@@ -1,451 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.IOException;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-
-public class PipedInputStreamTest extends junit.framework.TestCase {
-
- private final int BUFFER_SIZE = 1024;
-
- static class PWriter implements Runnable {
- PipedOutputStream pos;
-
- public byte bytes[];
-
- public void run() {
- try {
- pos.write(bytes);
- synchronized (this) {
- notify();
- }
- } catch (IOException e) {
- e.printStackTrace(System.out);
- System.out.println("Could not write bytes");
- }
- }
-
- public PWriter(PipedOutputStream pout, int nbytes) {
- pos = pout;
- bytes = new byte[nbytes];
- for (int i = 0; i < bytes.length; i++) {
- bytes[i] = (byte) (System.currentTimeMillis() % 9);
- }
- }
- }
-
- Thread t;
-
- PWriter pw;
-
- PipedInputStream pis;
-
- PipedOutputStream pos;
-
- /**
- * @tests java.io.PipedInputStream#PipedInputStream()
- */
- public void test_Constructor() {
- // Test for method java.io.PipedInputStream()
- // Used in tests
- }
-
- /**
- * @tests java.io.PipedInputStream#PipedInputStream(java.io.PipedOutputStream)
- */
- public void test_ConstructorLjava_io_PipedOutputStream() throws Exception {
- // Test for method java.io.PipedInputStream(java.io.PipedOutputStream)
- pis = new PipedInputStream(new PipedOutputStream());
- pis.available();
- }
-
-
- /**
- * @test java.io.PipedInputStream#read()
- */
- public void test_readException() throws IOException {
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
-
- try {
- pis.connect(pos);
- t = new Thread(pw = new PWriter(pos, 1000));
- t.start();
- assertTrue(t.isAlive());
- while (true) {
- pis.read();
- t.interrupt();
- }
- } catch (IOException e) {
- if (!e.getMessage().contains("Write end dead") && !e.getMessage().contains("Pipe broken")) { // android-changed
- throw e;
- }
- } finally {
- try {
- pis.close();
- pos.close();
- } catch (IOException ee) {}
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#available()
- */
- public void test_available() throws Exception {
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
-
- pis.connect(pos);
- t = new Thread(pw = new PWriter(pos, 1000));
- t.start();
-
- synchronized (pw) {
- pw.wait(10000);
- }
- assertTrue("Available returned incorrect number of bytes: "
- + pis.available(), pis.available() == 1000);
-
- PipedInputStream pin = new PipedInputStream();
- PipedOutputStream pout = new PipedOutputStream(pin);
- // Writing another byte would cause the write to wait
- // for a read before returning
- for (int i = 0; i < BUFFER_SIZE; i++) {
- pout.write(i);
- }
- assertEquals("Incorrect available count", BUFFER_SIZE , pin.available());
- }
-
- /**
- * @tests java.io.PipedInputStream#close()
- */
- public void test_close() throws IOException {
- // Test for method void java.io.PipedInputStream.close()
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
- pis.connect(pos);
- pis.close();
- try {
- pos.write((byte) 127);
- fail("Failed to throw expected exception");
- } catch (IOException e) {
- // The spec for PipedInput saya an exception should be thrown if
- // a write is attempted to a closed input. The PipedOuput spec
- // indicates that an exception should be thrown only when the
- // piped input thread is terminated without closing
- return;
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#connect(java.io.PipedOutputStream)
- */
- public void test_connectLjava_io_PipedOutputStream() throws Exception {
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
- assertEquals("Non-conected pipe returned non-zero available bytes", 0,
- pis.available());
-
- pis.connect(pos);
- t = new Thread(pw = new PWriter(pos, 1000));
- t.start();
-
- synchronized (pw) {
- pw.wait(10000);
- }
- assertEquals("Available returned incorrect number of bytes", 1000, pis
- .available());
- }
-
- /**
- * @tests java.io.PipedInputStream#read()
- */
- public void test_read() throws Exception {
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
-
- pis.connect(pos);
- t = new Thread(pw = new PWriter(pos, 1000));
- t.start();
-
- synchronized (pw) {
- pw.wait(10000);
- }
- assertEquals("Available returned incorrect number of bytes", 1000, pis
- .available());
- assertEquals("read returned incorrect byte", pw.bytes[0], (byte) pis
- .read());
- }
-
- /**
- * @tests java.io.PipedInputStream#read(byte[], int, int)
- */
- public void test_read$BII() throws Exception {
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
-
- pis.connect(pos);
- t = new Thread(pw = new PWriter(pos, 1000));
- t.start();
-
- byte[] buf = new byte[400];
- synchronized (pw) {
- pw.wait(10000);
- }
- assertTrue("Available returned incorrect number of bytes: "
- + pis.available(), pis.available() == 1000);
- pis.read(buf, 0, 400);
- for (int i = 0; i < 400; i++) {
- assertEquals("read returned incorrect byte[]", pw.bytes[i], buf[i]);
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#read(byte[], int, int)
- * Regression for HARMONY-387
- */
- public void test_read$BII_2() throws IOException {
- PipedInputStream obj = new PipedInputStream();
- try {
- obj.read(new byte[0], 0, -1);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- assertEquals(
- "IndexOutOfBoundsException rather than a subclass expected",
- IndexOutOfBoundsException.class, t.getClass());
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#read(byte[], int, int)
- */
- public void test_read$BII_3() throws IOException {
- PipedInputStream obj = new PipedInputStream();
- try {
- obj.read(new byte[0], -1, 0);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#read(byte[], int, int)
- */
- public void test_read$BII_4() throws IOException {
- PipedInputStream obj = new PipedInputStream();
- try {
- obj.read(new byte[0], -1, -1);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#receive(int)
- */
- public void test_receive() throws IOException {
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
-
- // test if writer recognizes dead reader
- pis.connect(pos);
- class WriteRunnable implements Runnable {
-
- boolean pass = false;
-
- volatile boolean readerAlive = true;
-
- public void run() {
- try {
- pos.write(1);
- while (readerAlive) {
- ;
- }
- try {
- pos.write(new byte[BUFFER_SIZE]);
- // should throw exception since buffer is full and
- // reader thread is now dead
- pos.write(1);
- } catch (IOException e) {
- pass = true;
- }
- } catch (IOException e) {
- }
- }
- }
- WriteRunnable writeRunnable = new WriteRunnable();
- Thread writeThread = new Thread(writeRunnable);
- class ReadRunnable implements Runnable {
-
- boolean pass;
-
- public void run() {
- try {
- pis.read();
- pass = true;
- } catch (IOException e) {
- }
- }
- }
- ;
- ReadRunnable readRunnable = new ReadRunnable();
- Thread readThread = new Thread(readRunnable);
- writeThread.start();
- readThread.start();
- while (readThread.isAlive()) {
- ;
- }
- writeRunnable.readerAlive = false;
- assertTrue("reader thread failed to read", readRunnable.pass);
- while (writeThread.isAlive()) {
- ;
- }
- assertTrue("writer thread failed to recognize dead reader",
- writeRunnable.pass);
-
- // attempt to write to stream after writer closed
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
-
- pis.connect(pos);
- class MyRunnable implements Runnable {
-
- boolean pass;
-
- public void run() {
- try {
- pos.write(1);
- } catch (IOException e) {
- pass = true;
- }
- }
- }
- MyRunnable myRun = new MyRunnable();
- synchronized (pis) {
- t = new Thread(myRun);
- // thread t will be blocked inside pos.write(1)
- // when it tries to call the synchronized method pis.receive
- // because we hold the monitor for object pis
- t.start();
- try {
- // wait for thread t to get to the call to pis.receive
- Thread.sleep(100);
- } catch (InterruptedException e) {
- }
- // now we close
- pos.close();
- }
- // we have exited the synchronized block, so now thread t will make
- // a call to pis.receive AFTER the output stream was closed,
- // in which case an IOException should be thrown
- while (t.isAlive()) {
- ;
- }
- assertTrue(
- "write failed to throw IOException on closed PipedOutputStream",
- myRun.pass);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() throws Exception {
- try {
- if (t != null) {
- t.interrupt();
- }
- } catch (Exception ignore) {
- }
- super.tearDown();
- }
-
-
- /**
- * @tests java.io.PipedInputStream#PipedInputStream(java.io.PipedOutputStream,
- * int)
- * @since 1.6
- */
- public void test_Constructor_LPipedOutputStream_I() throws Exception {
- // Test for method java.io.PipedInputStream(java.io.PipedOutputStream,
- // int)
- MockPipedInputStream mpis = new MockPipedInputStream(
- new PipedOutputStream(), 100);
- int bufferLength = mpis.bufferLength();
- assertEquals(100, bufferLength);
-
- try {
- pis = new PipedInputStream(null, -1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- pis = new PipedInputStream(null, 0);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#PipedInputStream(int)
- * @since 1.6
- */
- public void test_Constructor_I() throws Exception {
- // Test for method java.io.PipedInputStream(int)
- MockPipedInputStream mpis = new MockPipedInputStream(100);
- int bufferLength = mpis.bufferLength();
- assertEquals(100, bufferLength);
-
- try {
- pis = new PipedInputStream(-1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- pis = new PipedInputStream(0);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- static class MockPipedInputStream extends PipedInputStream {
-
- public MockPipedInputStream(java.io.PipedOutputStream src,
- int bufferSize) throws IOException {
- super(src, bufferSize);
- }
-
- public MockPipedInputStream(int bufferSize) {
- super(bufferSize);
- }
-
- public int bufferLength() {
- return super.buffer.length;
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/PipedReaderTest.java b/luni/src/test/java/tests/api/java/io/PipedReaderTest.java
deleted file mode 100644
index f237b9a..0000000
--- a/luni/src/test/java/tests/api/java/io/PipedReaderTest.java
+++ /dev/null
@@ -1,427 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.IOException;
-import java.io.PipedReader;
-import java.io.PipedWriter;
-
-import junit.framework.TestCase;
-
-public class PipedReaderTest extends TestCase {
-
- static class PWriter implements Runnable {
- public PipedWriter pw;
-
- public PWriter(PipedReader reader) {
- try {
- pw = new PipedWriter(reader);
- } catch (Exception e) {
- System.out.println("Couldn't create writer");
- }
- }
-
- public PWriter() {
- pw = new PipedWriter();
- }
-
- public void run() {
- try {
- char[] c = new char[11];
- "Hello World".getChars(0, 11, c, 0);
- pw.write(c);
- Thread.sleep(10000);
- } catch (InterruptedException e) {
- } catch (Exception e) {
- System.out.println("Exception occurred: " + e.toString());
- }
- }
- }
-
- PipedReader preader;
-
- PWriter pwriter;
-
- Thread t;
-
- /**
- * @tests java.io.PipedReader#PipedReader()
- */
- public void test_Constructor() {
- // Used in test
- }
-
- /**
- * @tests java.io.PipedReader#PipedReader(java.io.PipedWriter)
- */
- public void test_ConstructorLjava_io_PipedWriter() throws IOException {
- preader = new PipedReader(new PipedWriter());
- }
-
- /**
- * @tests java.io.PipedReader#PipedReader(java.io.PipedWriter,
- * int)
- * @since 1.6
- */
- public void test_Constructor_LPipedWriter_I() throws Exception {
- // Test for method java.io.PipedReader(java.io.PipedWriter,
- // int)
- try {
- preader = new PipedReader(null, -1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- preader = new PipedReader(null, 0);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PipedReader#PipedReader(int)
- * @since 1.6
- */
- public void test_Constructor_I() throws Exception {
- // Test for method java.io.PipedReader(int)
- try {
- preader = new PipedReader(-1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- preader = new PipedReader(0);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PipedReader#close()
- */
- public void test_close() throws Exception {
- char[] c = null;
- preader = new PipedReader();
- t = new Thread(new PWriter(preader), "");
- t.start();
- Thread.sleep(500); // Allow writer to start
- c = new char[11];
- preader.read(c, 0, 11);
- preader.close();
- assertEquals("Read incorrect chars", "Hello World", new String(c));
- }
-
- /**
- * @tests java.io.PipedReader#connect(java.io.PipedWriter)
- */
- public void test_connectLjava_io_PipedWriter() throws Exception {
- char[] c = null;
-
- preader = new PipedReader();
- t = new Thread(pwriter = new PWriter(), "");
- preader.connect(pwriter.pw);
- t.start();
- Thread.sleep(500); // Allow writer to start
- c = new char[11];
- preader.read(c, 0, 11);
-
- assertEquals("Read incorrect chars", "Hello World", new String(c));
- try {
- preader.connect(pwriter.pw);
- fail("Failed to throw exception connecting to pre-connected reader");
- } catch (IOException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.PipedReader#read()
- */
- public void test_read() throws Exception {
- char[] c = null;
- preader = new PipedReader();
- t = new Thread(new PWriter(preader), "");
- t.start();
- Thread.sleep(500); // Allow writer to start
- c = new char[11];
- for (int i = 0; i < c.length; i++) {
- c[i] = (char) preader.read();
- }
- assertEquals("Read incorrect chars", "Hello World", new String(c));
- }
-
- /**
- * @tests java.io.PipedReader#read(char[], int, int)
- */
- public void test_read$CII() throws Exception {
- char[] c = null;
- preader = new PipedReader();
- t = new Thread(new PWriter(preader), "");
- t.start();
- Thread.sleep(500); // Allow writer to start
- c = new char[11];
- int n = 0;
- int x = n;
- while (x < 11) {
- n = preader.read(c, x, 11 - x);
- x = x + n;
- }
- assertEquals("Read incorrect chars", "Hello World", new String(c));
- try {
- preader.close();
- preader.read(c, 8, 7);
- fail("Failed to throw exception reading from closed reader");
- } catch (IOException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.PipedReader#read(char[], int, int)
- */
- public void test_read$CII_2() throws IOException {
- // Regression for HARMONY-387
- PipedWriter pw = new PipedWriter();
- PipedReader obj = null;
- try {
- obj = new PipedReader(pw);
- obj.read(new char[0], (int) 0, (int) -1);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- assertEquals(
- "IndexOutOfBoundsException rather than a subclass expected",
- IndexOutOfBoundsException.class, t.getClass());
- }
- }
-
- /**
- * @tests java.io.PipedReader#read(char[], int, int)
- */
- public void test_read$CII_3() throws IOException {
- PipedWriter pw = new PipedWriter();
- PipedReader obj = null;
- try {
- obj = new PipedReader(pw);
- obj.read(new char[0], (int) -1, (int) 0);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.PipedReader#read(char[], int, int)
- */
- public void test_read$CII_4() throws IOException {
- PipedWriter pw = new PipedWriter();
- PipedReader obj = null;
- try {
- obj = new PipedReader(pw);
- obj.read(new char[0], (int) -1, (int) -1);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.PipedReader#read(char[], int, int)
- */
- public void test_read_$CII_IOException() throws IOException {
- PipedWriter pw = new PipedWriter();
- PipedReader pr = new PipedReader(pw);
- char[] buf = null;
- pr.close();
- try {
- pr.read(buf, 0, 10);
- fail("Should throws IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pr = new PipedReader();
- buf = null;
- pr.close();
- try {
- pr.read(buf, 0, 10);
- fail("Should throws IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- buf = new char[10];
- pr.close();
- try {
- pr.read(buf, -1, 0);
- fail("Should throws IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- buf = new char[10];
- pr.close();
- try {
- pr.read(buf, 0, -1);
- fail("Should throws IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- buf = new char[10];
- pr.close();
- try {
- pr.read(buf, 1, 10);
- fail("Should throws IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- pr.close();
- try {
- pr.read(new char[0], -1, -1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- pr.close();
- try {
- pr.read(null, 0, 1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- try {
- pr.read(null, -1, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (NullPointerException expected) { // android-added
- } catch (IndexOutOfBoundsException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- try {
- pr.read(null, 0, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- try {
- pr.read(new char[10], 11, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- try {
- pr.read(null, 1, 0);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
- }
-
- /**
- * @tests java.io.PipedReader#ready()
- */
- public void test_ready() throws Exception {
- char[] c = null;
- preader = new PipedReader();
- t = new Thread(new PWriter(preader), "");
- t.start();
- Thread.sleep(500); // Allow writer to start
- assertTrue("Reader should be ready", preader.ready());
- c = new char[11];
- for (int i = 0; i < c.length; i++)
- c[i] = (char) preader.read();
- assertFalse("Reader should not be ready after reading all chars",
- preader.ready());
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() throws Exception {
- if (t != null) {
- t.interrupt();
- }
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/PipedWriterTest.java b/luni/src/test/java/tests/api/java/io/PipedWriterTest.java
deleted file mode 100644
index bc18294..0000000
--- a/luni/src/test/java/tests/api/java/io/PipedWriterTest.java
+++ /dev/null
@@ -1,502 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.IOException;
-import java.io.PipedReader;
-import java.io.PipedWriter;
-import java.util.Arrays;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(PipedWriter.class)
-public class PipedWriterTest extends junit.framework.TestCase {
-
- static final String testString = "Lorem ipsum...";
- static final int testLength = testString.length();
-
- static class PReader implements Runnable {
- public PipedReader pr;
-
- public char[] buf;
-
- public PReader(PipedWriter pw) {
- try {
- pr = new PipedReader(pw);
- } catch (IOException e) {
- System.out.println("Exception setting up reader: "
- + e.toString());
- }
- }
-
- public PReader(PipedReader pr) {
- this.pr = pr;
- }
-
-/* public void run() {
- try {
- int r = 0;
- for (int i = 0; i < buf.length; i++) {
- r = pr.read();
- if (r == -1)
- break;
- buf[i] = (char) r;
- }
- } catch (Exception e) {
- System.out.println("Exception reading ("
- + Thread.currentThread().getName() + "): "
- + e.toString());
- }
- } */
-
- public void run() {
- try {
- while (true) {
- Thread.sleep(1000);
- Thread.yield();
- }
- } catch (InterruptedException e) {
- }
- }
-
- public String read(int nbytes) {
- buf = new char[nbytes];
- try {
- pr.read(buf, 0, nbytes);
- return new String(buf);
- } catch (IOException e) {
- System.out.println("Exception reading ("
- + Thread.currentThread().getName() + "): "
- + e.toString());
- return "ERROR";
- }
- }
- }
-
- Thread readerThread;
- PReader reader;
- PipedWriter pw;
- char[] testBuf;
-
- /**
- * @tests java.io.PipedWriter#PipedWriter()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PipedWriter",
- args = {}
- )
- public void test_Constructor() {
- pw = new PipedWriter();
- assertNotNull(pw);
- try {
- pw.close();
- } catch (IOException e) {
- fail("Unexpeceted IOException.");
- }
- }
-
- /**
- * @tests java.io.PipedWriter#PipedWriter(java.io.PipedReader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PipedWriter",
- args = {java.io.PipedReader.class}
- )
- public void test_ConstructorLjava_io_PipedReader() throws Exception {
- PipedReader rd = new PipedReader();
-
- try {
- pw = new PipedWriter(rd);
- } catch (Exception e) {
- fail("Test 1: Construtor failed:" + e.getMessage());
- }
-
- readerThread = new Thread(reader = new PReader(rd), "Constructor(Reader)");
- readerThread.start();
- try {
- pw.write(testBuf);
- } catch (Exception e) {
- fail("Test 2: Could not write to the constructed writer: "
- + e.getMessage());
- }
- pw.close();
- assertEquals("Test 3: Incorrect character string received.", testString,
- reader.read(testLength));
-
- rd = new PipedReader(new PipedWriter());
- try {
- pw = new PipedWriter(rd);
- fail("Test 4: IOException expected because the reader is already connected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.PipedWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- public void test_close() throws Exception {
- PipedReader rd = new PipedReader();
- pw = new PipedWriter(rd);
- reader = new PReader(rd);
- try {
- pw.close();
- } catch (IOException e) {
- fail("Test 1: Unexpected IOException: " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PipedWriter#connect(java.io.PipedReader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "connect",
- args = {java.io.PipedReader.class}
- )
- public void test_connectLjava_io_PipedReader() throws Exception {
- PipedReader rd = new PipedReader();
- pw = new PipedWriter();
-
- try {
- pw.connect(rd);
- } catch (Exception e) {
- fail("Test 1: Unexpected exception when connecting: " +
- e.getLocalizedMessage());
- }
-
- readerThread = new Thread(reader = new PReader(rd), "connect");
- readerThread.start();
-
- try {
- pw.write(testBuf);
- } catch (IOException e) {
- fail("Test 2: Unexpected IOException when writing after connecting.");
- }
- assertEquals("Test 3: Incorrect character string received.", testString,
- reader.read(testLength));
-
- try {
- pw.connect(new PipedReader());
- fail("Test 4: IOException expected when reconnecting the writer.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.PipedWriter#flush()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException checking because it is never thrown in the source code.",
- method = "flush",
- args = {}
- )
- public void test_flush() throws Exception {
- // Test for method void java.io.PipedWriter.flush()
- pw = new PipedWriter();
- readerThread = new Thread(reader = new PReader(pw), "flush");
- readerThread.start();
- pw.write(testBuf);
- pw.flush();
- assertEquals("Test 1: Flush failed. ", testString,
- reader.read(testLength));
- }
-
- /**
- * @tests java.io.PipedWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII() throws Exception {
- pw = new PipedWriter();
-
- try {
- pw.write(testBuf, 0, 5);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- pw = new PipedWriter(new PipedReader());
-
- try {
- pw.write(testBuf, -1, 1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- pw.write(testBuf, 0, -1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- pw.write(testBuf, 5, testString.length());
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- pw.close();
- pw = new PipedWriter();
- try {
- readerThread = new Thread(reader = new PReader(pw), "writeCII");
- readerThread.start();
- pw.write(testBuf, 0, testLength);
- pw.close();
- reader.read(testLength);
- assertTrue("Test 5: Characters read do not match the characters written.",
- Arrays.equals( testBuf, reader.buf));
- } catch (IOException e) {
- fail("Test 5: Unexpected IOException: " + e.getMessage());
- }
-
- readerThread.interrupt();
-
- try {
- pw.write(testBuf, 0, 5);
- fail("Test 6: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- reader.pr.close();
- try {
- pw.write(testBuf, 0, 5);
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.PipedWriter#write(char[],int,int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII_MultiThread() throws Exception {
- final PipedReader pr = new PipedReader();
- final PipedWriter pw = new PipedWriter();
-
- // test if writer recognizes dead reader
- pr.connect(pw);
-
- class WriteRunnable implements Runnable {
- boolean pass = false;
-
- boolean readerAlive = true;
-
- public void run() {
- try {
- pw.write(1);
- while (readerAlive) {
- // wait the reader thread dead
- Thread.sleep(100);
- }
- try {
- // should throw exception since reader thread
- // is now dead
- char[] buf = new char[10];
- pw.write(buf, 0, 10);
- } catch (IOException e) {
- pass = true;
- }
- } catch (IOException e) {
- //ignore
- } catch (InterruptedException e) {
- //ignore
- }
- }
- }
- WriteRunnable writeRunnable = new WriteRunnable();
- Thread writeThread = new Thread(writeRunnable);
- class ReadRunnable implements Runnable {
- boolean pass;
-
- public void run() {
- try {
- pr.read();
- pass = true;
- } catch (IOException e) {
- //ignore
- }
- }
- }
- ReadRunnable readRunnable = new ReadRunnable();
- Thread readThread = new Thread(readRunnable);
- writeThread.start();
- readThread.start();
- while (readThread.isAlive()) {
- //wait the reader thread dead
- }
- writeRunnable.readerAlive = false;
- assertTrue("reader thread failed to read", readRunnable.pass);
- while (writeThread.isAlive()) {
- //wait the writer thread dead
- }
- assertTrue("writer thread failed to recognize dead reader",
- writeRunnable.pass);
- }
-
- /**
- * @tests java.io.PipedWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws Exception {
- // Test for method void java.io.PipedWriter.write(int)
-
- pw = new PipedWriter();
-
- try {
- pw.write(42);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- readerThread = new Thread(reader = new PReader(pw), "writeI");
- readerThread.start();
- pw.write(1);
- pw.write(2);
- pw.write(3);
- pw.close();
- reader.read(3);
- assertTrue("Test 2: The charaacters read do not match the characters written: " +
- (int) reader.buf[0] + " " + (int) reader.buf[1] + " " + (int) reader.buf[2],
- reader.buf[0] == 1 && reader.buf[1] == 2 && reader.buf[2] == 3);
- }
-
- /**
- * @tests java.io.PipedWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
- public void test_writeI_MultiThread() throws IOException {
- final PipedReader pr = new PipedReader();
- final PipedWriter pw = new PipedWriter();
- // test if writer recognizes dead reader
- pr.connect(pw);
-
- class WriteRunnable implements Runnable {
- boolean pass = false;
- boolean readerAlive = true;
- public void run() {
- try {
- pw.write(1);
- while (readerAlive) {
- // wait the reader thread dead
- Thread.sleep(100);
- }
- try {
- // should throw exception since reader thread
- // is now dead
- pw.write(1);
- } catch (IOException e) {
- pass = true;
- }
- } catch (IOException e) {
- //ignore
- } catch (InterruptedException e) {
- //ignore
- }
- }
- }
- WriteRunnable writeRunnable = new WriteRunnable();
- Thread writeThread = new Thread(writeRunnable);
- class ReadRunnable implements Runnable {
- boolean pass;
- public void run() {
- try {
- pr.read();
- pass = true;
- } catch (IOException e) {
- //ignore
- }
- }
- }
- ReadRunnable readRunnable = new ReadRunnable();
- Thread readThread = new Thread(readRunnable);
- writeThread.start();
- readThread.start();
- while (readThread.isAlive()) {
- //wait the reader thread dead
- }
- writeRunnable.readerAlive = false;
- assertTrue("reader thread failed to read", readRunnable.pass);
- while (writeThread.isAlive()) {
- //wait the writer thread dead
- }
- assertTrue("writer thread failed to recognize dead reader",
- writeRunnable.pass);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- testBuf = new char[testLength];
- testString.getChars(0, testLength, testBuf, 0);
- }
-
- protected void tearDown() throws Exception {
- try {
- if (readerThread != null) {
- readerThread.interrupt();
- }
- } catch (Exception ignore) {}
- try {
- if (pw != null) {
- pw.close();
- }
- } catch (Exception ignore) {}
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/PrintStreamTest.java b/luni/src/test/java/tests/api/java/io/PrintStreamTest.java
deleted file mode 100644
index 7cd0fcb..0000000
--- a/luni/src/test/java/tests/api/java/io/PrintStreamTest.java
+++ /dev/null
@@ -1,663 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStreamReader;
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.io.UnsupportedEncodingException;
-import java.util.Locale;
-
-public class PrintStreamTest extends junit.framework.TestCase {
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- byte[] ibuf = new byte[4096];
-
- private File testFile = null;
-
- private String testFilePath = null;
-
- 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_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_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_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\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";
-
- private static class MockPrintStream extends PrintStream {
-
- public MockPrintStream(String fileName) throws FileNotFoundException {
- super(fileName);
- }
-
- public MockPrintStream(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
- super(fileName, csn);
- }
-
- public MockPrintStream(OutputStream os) {
- super(os);
- }
-
- @Override
- public void clearError() {
- super.clearError();
- }
-
- @Override
- public void setError() {
- super.setError();
- }
- }
-
- /**
- * @tests {@link java.io.PrintStream#PrintStream(String)}
- */
- public void test_Constructor_Ljava_lang_String() throws IOException {
- MockPrintStream os = new MockPrintStream(testFilePath);
- assertNotNull(os);
- os.close();
- }
-
- /**
- * @tests {@link java.io.PrintStream#PrintStream(String, String)}
- */
- public void test_Constructor_Ljava_lang_String_Ljava_lang_String() throws Exception {
- MockPrintStream os = new MockPrintStream(testFilePath, "utf-8");
- assertNotNull(os);
- os.close();
- }
-
- /**
- * @tests java.io.PrintStream#PrintStream(java.io.OutputStream)
- */
- public void test_ConstructorLjava_io_OutputStream() throws Exception {
- // Test for method java.io.PrintStream(java.io.OutputStream)
- PrintStream os = new PrintStream(bos);
- os.print(2345.76834720202);
- os.close();
-
- // regression for HARMONY-1195
- try {
- os = new PrintStream(bos, true, null);
- fail("Should throw NPE");
- } catch (NullPointerException e) {}
- }
-
- /**
- * @tests java.io.PrintStream#PrintStream(java.io.OutputStream, boolean)
- */
- public void test_ConstructorLjava_io_OutputStreamZ() {
- // Test for method java.io.PrintStream(java.io.OutputStream, boolean)
- PrintStream os = new PrintStream(bos);
- os.println(2345.76834720202);
- os.flush();
- assertTrue("Bytes not written", bos.size() > 0);
- os.close();
- }
-
- /**
- * @tests java.io.PrintStream#PrintStream(java.io.OutputStream, boolean, String)
- */
- public void test_ConstructorLjava_io_OutputStreamZLjava_lang_String() {
- try {
- new PrintStream(new ByteArrayOutputStream(), false,
- "%Illegal_name!");
- fail("Expected UnsupportedEncodingException");
- } catch (UnsupportedEncodingException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PrintStream#checkError()
- */
- public void test_checkError() throws Exception {
- // Test for method boolean java.io.PrintStream.checkError()
- PrintStream os = new PrintStream(new OutputStream() {
-
- public void write(int b) throws IOException {
- throw new IOException();
- }
-
- public void write(byte[] b, int o, int l) throws IOException {
- throw new IOException();
- }
- });
- os.print(fileString.substring(0, 501));
-
- assertTrue("Checkerror should return true", os.checkError());
- }
-
- /**
- * @tests {@link java.io.PrintStream#clearError()}
- */
- public void test_clearError() throws FileNotFoundException {
- MockPrintStream os = new MockPrintStream(testFilePath);
- assertFalse(os.checkError());
- os.setError();
- assertTrue(os.checkError());
- os.clearError();
- assertFalse(os.checkError());
- os.close();
- }
-
- /**
- * @tests java.io.PrintStream#close()
- */
- public void test_close() throws Exception {
- // Test for method void java.io.PrintStream.close()
- PrintStream os = new PrintStream(bos);
- os.close();
- bos.close();
- }
-
- /**
- * @tests java.io.PrintStream#flush()
- */
- public void test_flush() throws Exception {
- // Test for method void java.io.PrintStream.flush()
- PrintStream os = new PrintStream(bos);
- os.print(fileString.substring(0, 501));
- os.flush();
- assertEquals("Bytes not written after flush", 501, bos.size());
- bos.close();
- os.close();
- }
-
- /**
- * @tests java.io.PrintStream#print(char[])
- */
- public void test_print$C() {
- // Test for method void java.io.PrintStream.print(char [])
- PrintStream os = new PrintStream(bos, true);
- try {
- os.print((char[]) null);
- fail("NPE expected");
- } catch (NullPointerException ok) {}
-
- os = new PrintStream(bos, true);
- char[] sc = new char[4000];
- fileString.getChars(0, fileString.length(), sc, 0);
- os.print(sc);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- os.close();
-
- byte[] rbytes = new byte[4000];
- bis.read(rbytes, 0, fileString.length());
- assertEquals("Incorrect char[] written", fileString, new String(rbytes,
- 0, fileString.length()));
- }
-
- /**
- * @tests java.io.PrintStream#print(char)
- */
- public void test_printC() throws Exception {
- // Test for method void java.io.PrintStream.print(char)
- PrintStream os = new PrintStream(bos, true);
- os.print('t');
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- assertEquals("Incorrect char written", 't', isr.read());
- }
-
- /**
- * @tests java.io.PrintStream#print(double)
- */
- public void test_printD() {
- // Test for method void java.io.PrintStream.print(double)
- byte[] rbuf = new byte[100];
- PrintStream os = new PrintStream(bos, true);
- os.print(2345.76834720202);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- bis.read(rbuf, 0, 16);
- assertEquals("Incorrect double written", "2345.76834720202",
- new String(rbuf, 0, 16));
- }
-
- /**
- * @tests java.io.PrintStream#print(float)
- */
- public void test_printF() {
- // Test for method void java.io.PrintStream.print(float)
- PrintStream os = new PrintStream(bos, true);
- byte rbuf[] = new byte[10];
- os.print(29.08764f);
- os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- bis.read(rbuf, 0, 8);
- assertEquals("Incorrect float written", "29.08764", new String(rbuf, 0,
- 8));
-
- }
-
- /**
- * @tests java.io.PrintStream#print(int)
- */
- public void test_printI() {
- // Test for method void java.io.PrintStream.print(int)
- PrintStream os = new PrintStream(bos, true);
- os.print(768347202);
- byte[] rbuf = new byte[18];
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- bis.read(rbuf, 0, 9);
- assertEquals("Incorrect int written", "768347202", new String(rbuf, 0,
- 9));
- }
-
- /**
- * @tests java.io.PrintStream#print(long)
- */
- public void test_printJ() {
- // Test for method void java.io.PrintStream.print(long)
- byte[] rbuf = new byte[100];
- PrintStream os = new PrintStream(bos, true);
- os.print(9875645283333L);
- os.close();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- bis.read(rbuf, 0, 13);
- assertEquals("Incorrect long written", "9875645283333", new String(
- rbuf, 0, 13));
- }
-
- /**
- * @tests java.io.PrintStream#print(java.lang.Object)
- */
- public void test_printLjava_lang_Object() throws Exception {
- // Test for method void java.io.PrintStream.print(java.lang.Object)
- PrintStream os = new PrintStream(bos, true);
- os.print((Object) null);
- os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte[] nullbytes = new byte[4];
- bis.read(nullbytes, 0, 4);
- assertEquals("null should be written", "null", new String(nullbytes, 0,
- 4));
-
- bis.close();
- bos.close();
- os.close();
-
- ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
- os = new PrintStream(bos1, true);
- os.print(new java.util.Vector());
- bis = new ByteArrayInputStream(bos1.toByteArray());
- byte[] rbytes = new byte[2];
- bis.read(rbytes, 0, 2);
- assertEquals("Incorrect Object written", "[]", new String(rbytes, 0, 2));
- }
-
- /**
- * @tests java.io.PrintStream#print(java.lang.String)
- */
- public void test_printLjava_lang_String() throws Exception {
- // Test for method void java.io.PrintStream.print(java.lang.String)
- PrintStream os = new PrintStream(bos, true);
- os.print((String) null);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte[] nullbytes = new byte[4];
- bis.read(nullbytes, 0, 4);
- assertEquals("null should be written", "null", new String(nullbytes, 0,
- 4));
-
- bis.close();
- bos.close();
- os.close();
-
- ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
- os = new PrintStream(bos1, true);
- os.print("Hello World");
- bis = new ByteArrayInputStream(bos1.toByteArray());
- byte rbytes[] = new byte[100];
- bis.read(rbytes, 0, 11);
- assertEquals("Incorrect string written", "Hello World", new String(
- rbytes, 0, 11));
- }
-
- /**
- * @tests java.io.PrintStream#print(boolean)
- */
- public void test_printZ() throws Exception {
- // Test for method void java.io.PrintStream.print(boolean)
- PrintStream os = new PrintStream(bos, true);
- os.print(true);
- DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bos
- .toByteArray()));
-
- assertTrue("Incorrect boolean written", dis.readBoolean());
- }
-
- /**
- * @tests java.io.PrintStream#println()
- */
- public void test_println() throws Exception {
- // Test for method void java.io.PrintStream.println()
- char c;
- PrintStream os = new PrintStream(bos, true);
- os.println("");
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- assertTrue("Newline not written", (c = (char) isr.read()) == '\r'
- || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(char[])
- */
- public void test_println$C() throws Exception {
- // Test for method void java.io.PrintStream.println(char [])
- PrintStream os = new PrintStream(bos, true);
- char[] sc = new char[4000];
- fileString.getChars(0, fileString.length(), sc, 0);
- os.println(sc);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- byte[] rbytes = new byte[4000];
- bis.read(rbytes, 0, fileString.length());
- assertEquals("Incorrect char[] written", fileString, new String(rbytes,
- 0, fileString.length()));
-
- // In this particular test method, the end of data is not immediately
- // followed by newLine separator in the reading buffer, instead its
- // followed by zeros. The newline is written as the last entry
- // in the inputStream buffer. Therefore, we must keep reading until we
- // hit a new line.
- int r;
- boolean newline = false;
- while ((r = isr.read()) != -1) {
- if (r == '\r' || r == '\n')
- newline = true;
- }
- assertTrue("Newline not written", newline);
- }
-
- /**
- * @tests java.io.PrintStream#println(char)
- */
- public void test_printlnC() throws Exception {
- // Test for method void java.io.PrintStream.println(char)
- int c;
- PrintStream os = new PrintStream(bos, true);
- os.println('t');
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- assertEquals("Incorrect char written", 't', isr.read());
- assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(double)
- */
- public void test_printlnD() throws Exception {
- // Test for method void java.io.PrintStream.println(double)
- int c;
- PrintStream os = new PrintStream(bos, true);
- os.println(2345.76834720202);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- byte[] rbuf = new byte[100];
- bis.read(rbuf, 0, 16);
- assertEquals("Incorrect double written", "2345.76834720202",
- new String(rbuf, 0, 16));
- assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(float)
- */
- public void test_printlnF() throws Exception {
- // Test for method void java.io.PrintStream.println(float)
- int c;
- byte[] rbuf = new byte[100];
- PrintStream os = new PrintStream(bos, true);
- os.println(29.08764f);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- bis.read(rbuf, 0, 8);
- assertEquals("Incorrect float written", "29.08764", new String(rbuf, 0,
- 8));
- assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(int)
- */
- public void test_printlnI() throws Exception {
- // Test for method void java.io.PrintStream.println(int)
- int c;
- PrintStream os = new PrintStream(bos, true);
- os.println(768347202);
- byte[] rbuf = new byte[100];
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- bis.read(rbuf, 0, 9);
- assertEquals("Incorrect int written", "768347202", new String(rbuf, 0,
- 9));
- assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(long)
- */
- public void test_printlnJ() throws Exception {
- // Test for method void java.io.PrintStream.println(long)
- int c;
- PrintStream os = new PrintStream(bos, true);
- os.println(9875645283333L);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- byte[] rbuf = new byte[100];
- bis.read(rbuf, 0, 13);
- assertEquals("Incorrect long written", "9875645283333", new String(
- rbuf, 0, 13));
- assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(java.lang.Object)
- */
- public void test_printlnLjava_lang_Object() throws Exception {
- // Test for method void java.io.PrintStream.println(java.lang.Object)
- char c;
- PrintStream os = new PrintStream(bos, true);
- os.println(new java.util.Vector());
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- byte[] rbytes = new byte[2];
- bis.read(rbytes, 0, 2);
- assertEquals("Incorrect Vector written", "[]", new String(rbytes, 0, 2));
- assertTrue("Newline not written", (c = (char) isr.read()) == '\r'
- || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(java.lang.String)
- */
- public void test_printlnLjava_lang_String() throws Exception {
- // Test for method void java.io.PrintStream.println(java.lang.String)
- char c;
- PrintStream os = new PrintStream(bos, true);
- os.println("Hello World");
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- byte rbytes[] = new byte[100];
- bis.read(rbytes, 0, 11);
- assertEquals("Incorrect string written", "Hello World", new String(
- rbytes, 0, 11));
- assertTrue("Newline not written", (c = (char) isr.read()) == '\r'
- || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(boolean)
- */
- public void test_printlnZ() throws Exception {
- // Test for method void java.io.PrintStream.println(boolean)
- int c;
- PrintStream os = new PrintStream(bos, true);
- os.println(true);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- byte[] rbuf = new byte[100];
- bis.read(rbuf, 0, 4);
- assertEquals("Incorrect boolean written", "true",
- new String(rbuf, 0, 4));
- assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#write(byte[], int, int)
- */
- public void test_write$BII() {
- // Test for method void java.io.PrintStream.write(byte [], int, int)
- PrintStream os = new PrintStream(bos, true);
- os.write(fileString.getBytes(), 0, fileString.length());
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte rbytes[] = new byte[4000];
- bis.read(rbytes, 0, fileString.length());
- assertTrue("Incorrect bytes written", new String(rbytes, 0, fileString
- .length()).equals(fileString));
- }
-
- /**
- * @tests java.io.PrintStream#write(int)
- */
- public void test_writeI() {
- // Test for method void java.io.PrintStream.write(int)
- PrintStream os = new PrintStream(bos, true);
- os.write('t');
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- assertEquals("Incorrect char written", 't', bis.read());
- }
-
- /**
- * @tests java.io.PrintStream#append(char)
- */
- public void test_appendChar() throws IOException {
- char testChar = ' ';
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintStream printStream = new PrintStream(out);
- printStream.append(testChar);
- printStream.flush();
- assertEquals(String.valueOf(testChar), out.toString());
- printStream.close();
- }
-
- /**
- * @tests java.io.PrintStream#append(CharSequence)
- */
- public void test_appendCharSequence() {
- String testString = "My Test String";
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintStream printStream = new PrintStream(out);
- printStream.append(testString);
- printStream.flush();
- assertEquals(testString, out.toString());
- printStream.close();
- }
-
- /**
- * @tests java.io.PrintStream#append(CharSequence, int, int)
- */
- public void test_appendCharSequenceIntInt() {
- String testString = "My Test String";
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintStream printStream = new PrintStream(out);
- printStream.append(testString, 1, 3);
- printStream.flush();
- assertEquals(testString.substring(1, 3), out.toString());
- printStream.close();
- }
-
- /**
- * @tests java.io.PrintStream#format(java.lang.String, java.lang.Object...)
- */
- public void test_formatLjava_lang_String$Ljava_lang_Object() {
- PrintStream os = new PrintStream(bos, false);
- os.format("%s %s", "Hello", "World");
- os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte[] rbytes = new byte[11];
- bis.read(rbytes, 0, rbytes.length);
- assertEquals("Wrote incorrect string", "Hello World",
- new String(rbytes));
-
- }
-
- /**
- * @tests java.io.PrintStream#format(java.util.Locale, java.lang.String,
- * java.lang.Object...)
- */
- public void test_formatLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
- PrintStream os = new PrintStream(bos, false);
- os.format(Locale.US, "%s %s", "Hello", "World");
- os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte[] rbytes = new byte[11];
- bis.read(rbytes, 0, rbytes.length);
- assertEquals("Wrote incorrect string", "Hello World",
- new String(rbytes));
- }
-
- /**
- * @tests java.io.PrintStream#printf(java.lang.String, java.lang.Object...)
- */
- public void test_printfLjava_lang_String$Ljava_lang_Object() {
- PrintStream os = new PrintStream(bos, false);
- os.printf("%s %s", "Hello", "World");
- os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte[] rbytes = new byte[11];
- bis.read(rbytes, 0, rbytes.length);
- assertEquals("Wrote incorrect string", "Hello World",
- new String(rbytes));
- }
-
- /**
- * @tests java.io.PrintStream#printf(java.util.Locale, java.lang.String,
- * java.lang.Object...)
- */
- public void test_printfLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
- PrintStream os = new PrintStream(bos, false);
- os.printf(Locale.US, "%s %s", "Hello", "World");
- os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte[] rbytes = new byte[11];
- bis.read(rbytes, 0, rbytes.length);
- assertEquals("Wrote incorrect string", "Hello World",
- new String(rbytes));
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- testFile = File.createTempFile("test", null);
- testFilePath = testFile.getAbsolutePath();
- }
-
- @Override
- protected void tearDown() throws Exception {
- testFile.delete();
- testFile = null;
- testFilePath = null;
- super.tearDown();
- }
-
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/PrintWriterTest.java b/luni/src/test/java/tests/api/java/io/PrintWriterTest.java
deleted file mode 100644
index dfaa4a5..0000000
--- a/luni/src/test/java/tests/api/java/io/PrintWriterTest.java
+++ /dev/null
@@ -1,778 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.nio.charset.Charset;
-import java.util.Locale;
-
-import tests.support.Support_StringReader;
-import tests.support.Support_StringWriter;
-
-public class PrintWriterTest extends junit.framework.TestCase {
-
- static class Bogus {
- public String toString() {
- return "Bogus";
- }
- }
-
- /**
- * @since 1.6
- */
- static class MockPrintWriter extends PrintWriter {
-
- public MockPrintWriter(OutputStream out, boolean autoflush) {
- super(out, autoflush);
- }
-
- @Override
- public void clearError() {
- super.clearError();
- }
-
- }
-
- PrintWriter pw;
-
- ByteArrayOutputStream bao;
-
- ByteArrayInputStream bai;
-
- BufferedReader br;
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.OutputStream)
- */
- public void test_ConstructorLjava_io_OutputStream() {
- // Test for method java.io.PrintWriter(java.io.OutputStream)
- String s;
- pw.println("Random Chars");
- pw.write("Hello World");
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- assertTrue("Incorrect string written/read: " + s, s
- .equals("Random Chars"));
- s = br.readLine();
- assertTrue("Incorrect string written/read: " + s, s
- .equals("Hello World"));
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
- */
- public void test_ConstructorLjava_io_OutputStreamZ() {
- // Test for method java.io.PrintWriter(java.io.OutputStream, boolean)
- String s;
- pw = new PrintWriter(bao, true);
- pw.println("Random Chars");
- pw.write("Hello World");
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- assertTrue("Incorrect string written/read: " + s, s
- .equals("Random Chars"));
- pw.flush();
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- assertTrue("Incorrect string written/read: " + s, s
- .equals("Random Chars"));
- s = br.readLine();
- assertTrue("Incorrect string written/read: " + s, s
- .equals("Hello World"));
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.Writer)
- */
- public void test_ConstructorLjava_io_Writer() {
- // Test for method java.io.PrintWriter(java.io.Writer)
- Support_StringWriter sw;
- pw = new PrintWriter(sw = new Support_StringWriter());
- pw.print("Hello");
- pw.flush();
- assertEquals("Failed to construct proper writer",
- "Hello", sw.toString());
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.Writer, boolean)
- */
- public void test_ConstructorLjava_io_WriterZ() {
- // Test for method java.io.PrintWriter(java.io.Writer, boolean)
- Support_StringWriter sw;
- pw = new PrintWriter(sw = new Support_StringWriter(), true);
- pw.print("Hello");
- // Auto-flush should have happened
- assertEquals("Failed to construct proper writer",
- "Hello", sw.toString());
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.File)
- */
- public void test_ConstructorLjava_io_File() throws Exception {
- File file = File.createTempFile(getClass().getName(), null);
- try {
- PrintWriter writer = new PrintWriter(file);
- writer.close();
- } finally {
- file.delete();
- }
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.File, java.lang.String)
- */
- public void test_ConstructorLjava_io_File_Ljava_lang_String() throws Exception {
- File file = File.createTempFile(getClass().getName(), null);
- try {
- PrintWriter writer = new PrintWriter(file,
- Charset.defaultCharset().name());
- writer.close();
- } finally {
- file.delete();
- }
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() throws Exception {
- File file = File.createTempFile(getClass().getName(), null);
- try {
- PrintWriter writer = new PrintWriter(file.getPath());
- writer.close();
- } finally {
- file.delete();
- }
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.lang.String, java.lang.String)
- */
- public void test_ConstructorLjava_lang_String_Ljava_lang_String() throws Exception {
- File file = File.createTempFile(getClass().getName(), null);
- try {
- PrintWriter writer = new PrintWriter(file.getPath(),
- Charset.defaultCharset().name());
- writer.close();
- } finally {
- file.delete();
- }
- }
-
- /**
- * @tests java.io.PrintWriter#checkError()
- */
- public void test_checkError() {
- // Test for method boolean java.io.PrintWriter.checkError()
- pw.close();
- pw.print(490000000000.08765);
- assertTrue("Failed to return error", pw.checkError());
- }
-
- /**
- * @tests java.io.PrintWriter#clearError()
- * @since 1.6
- */
- public void test_clearError() {
- // Test for method boolean java.io.PrintWriter.clearError()
- MockPrintWriter mpw = new MockPrintWriter(new ByteArrayOutputStream(), false);
- mpw.close();
- mpw.print(490000000000.08765);
- assertTrue("Failed to return error", mpw.checkError());
- mpw.clearError();
- assertFalse("Internal error state has not be cleared", mpw.checkError());
- }
-
- /**
- * @tests java.io.PrintWriter#close()
- */
- public void test_close() {
- // Test for method void java.io.PrintWriter.close()
- pw.close();
- pw.println("l");
- assertTrue("Write on closed stream failed to generate error", pw
- .checkError());
- }
-
- /**
- * @tests java.io.PrintWriter#flush()
- */
- public void test_flush() {
- // Test for method void java.io.PrintWriter.flush()
- final double dub = 490000000000.08765;
- pw.print(dub);
- pw.flush();
- assertTrue("Failed to flush", new String(bao.toByteArray())
- .equals(String.valueOf(dub)));
- }
-
- /**
- * @tests java.io.PrintWriter#print(char[])
- */
- public void test_print$C() {
- // Test for method void java.io.PrintWriter.print(char [])
- String s = null;
- char[] schars = new char[11];
- "Hello World".getChars(0, 11, schars, 0);
- pw.print(schars);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect char[] string: " + s, s
- .equals("Hello World"));
- int r = 0;
- try {
- pw.print((char[]) null);
- } catch (NullPointerException e) {
- r = 1;
- }
- assertEquals("null pointer exception for printing null char[] is not caught",
- 1, r);
- }
-
- /**
- * @tests java.io.PrintWriter#print(char)
- */
- public void test_printC() {
- // Test for method void java.io.PrintWriter.print(char)
- pw.print('c');
- pw.flush();
- assertEquals("Wrote incorrect char string", "c", new String(bao.toByteArray())
- );
- }
-
- /**
- * @tests java.io.PrintWriter#print(double)
- */
- public void test_printD() {
- // Test for method void java.io.PrintWriter.print(double)
- final double dub = 490000000000.08765;
- pw.print(dub);
- pw.flush();
- assertTrue("Wrote incorrect double string", new String(bao
- .toByteArray()).equals(String.valueOf(dub)));
- }
-
- /**
- * @tests java.io.PrintWriter#print(float)
- */
- public void test_printF() {
- // Test for method void java.io.PrintWriter.print(float)
- final float flo = 49.08765f;
- pw.print(flo);
- pw.flush();
- assertTrue("Wrote incorrect float string",
- new String(bao.toByteArray()).equals(String.valueOf(flo)));
- }
-
- /**
- * @tests java.io.PrintWriter#print(int)
- */
- public void test_printI() {
- // Test for method void java.io.PrintWriter.print(int)
- pw.print(4908765);
- pw.flush();
- assertEquals("Wrote incorrect int string", "4908765", new String(bao.toByteArray())
- );
- }
-
- /**
- * @tests java.io.PrintWriter#print(long)
- */
- public void test_printJ() {
- // Test for method void java.io.PrintWriter.print(long)
- pw.print(49087650000L);
- pw.flush();
- assertEquals("Wrote incorrect long string", "49087650000", new String(bao.toByteArray())
- );
- }
-
- /**
- * @tests java.io.PrintWriter#print(java.lang.Object)
- */
- public void test_printLjava_lang_Object() {
- // Test for method void java.io.PrintWriter.print(java.lang.Object)
- pw.print((Object) null);
- pw.flush();
- assertEquals("Did not write null", "null", new String(bao.toByteArray())
- );
- bao.reset();
-
- pw.print(new Bogus());
- pw.flush();
- assertEquals("Wrote in incorrect Object string", "Bogus", new String(bao
- .toByteArray()));
- }
-
- /**
- * @tests java.io.PrintWriter#print(java.lang.String)
- */
- public void test_printLjava_lang_String() {
- // Test for method void java.io.PrintWriter.print(java.lang.String)
- pw.print((String) null);
- pw.flush();
- assertEquals("did not write null", "null", new String(bao.toByteArray())
- );
- bao.reset();
-
- pw.print("Hello World");
- pw.flush();
- assertEquals("Wrote incorrect string", "Hello World", new String(bao.toByteArray())
- );
- }
-
- /**
- * @tests java.io.PrintWriter#print(boolean)
- */
- public void test_printZ() {
- // Test for method void java.io.PrintWriter.print(boolean)
- pw.print(true);
- pw.flush();
- assertEquals("Wrote in incorrect boolean string", "true", new String(bao
- .toByteArray()));
- }
-
- /**
- * @tests java.io.PrintWriter#println()
- */
- public void test_println() {
- // Test for method void java.io.PrintWriter.println()
- String s;
- pw.println("Blarg");
- pw.println();
- pw.println("Bleep");
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- assertTrue("Wrote incorrect line: " + s, s.equals("Blarg"));
- s = br.readLine();
- assertTrue("Wrote incorrect line: " + s, s.equals(""));
- s = br.readLine();
- assertTrue("Wrote incorrect line: " + s, s.equals("Bleep"));
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PrintWriter#println(char[])
- */
- public void test_println$C() {
- // Test for method void java.io.PrintWriter.println(char [])
- String s = null;
- char[] schars = new char[11];
- "Hello World".getChars(0, 11, schars, 0);
- pw.println("Random Chars");
- pw.println(schars);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect char[] string: " + s, s
- .equals("Hello World"));
- }
-
- /**
- * @tests java.io.PrintWriter#println(char)
- */
- public void test_printlnC() {
- // Test for method void java.io.PrintWriter.println(char)
- String s = null;
- pw.println("Random Chars");
- pw.println('c');
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect char string: " + s, s.equals("c"));
- }
-
- /**
- * @tests java.io.PrintWriter#println(double)
- */
- public void test_printlnD() {
- // Test for method void java.io.PrintWriter.println(double)
- String s = null;
- final double dub = 4000000000000000.657483;
- pw.println("Random Chars");
- pw.println(dub);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect double string: " + s, s.equals(String
- .valueOf(dub)));
- }
-
- /**
- * @tests java.io.PrintWriter#println(float)
- */
- public void test_printlnF() {
- // Test for method void java.io.PrintWriter.println(float)
- String s;
- final float flo = 40.4646464f;
- pw.println("Random Chars");
- pw.println(flo);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- assertTrue("Wrote incorrect float string: " + s + " wanted: "
- + String.valueOf(flo), s.equals(String.valueOf(flo)));
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
-
- }
-
- /**
- * @tests java.io.PrintWriter#println(int)
- */
- public void test_printlnI() {
- // Test for method void java.io.PrintWriter.println(int)
- String s = null;
- pw.println("Random Chars");
- pw.println(400000);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect int string: " + s, s.equals("400000"));
- }
-
- /**
- * @tests java.io.PrintWriter#println(long)
- */
- public void test_printlnJ() {
- // Test for method void java.io.PrintWriter.println(long)
- String s = null;
- pw.println("Random Chars");
- pw.println(4000000000000L);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect long string: " + s, s
- .equals("4000000000000"));
- }
-
- /**
- * @tests java.io.PrintWriter#println(java.lang.Object)
- */
- public void test_printlnLjava_lang_Object() {
- // Test for method void java.io.PrintWriter.println(java.lang.Object)
- String s = null;
- pw.println("Random Chars");
- pw.println(new Bogus());
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect Object string: " + s, s.equals("Bogus"));
- }
-
- /**
- * @tests java.io.PrintWriter#println(java.lang.String)
- */
- public void test_printlnLjava_lang_String() {
- // Test for method void java.io.PrintWriter.println(java.lang.String)
- String s = null;
- pw.println("Random Chars");
- pw.println("Hello World");
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect string: " + s, s.equals("Hello World"));
- }
-
- /**
- * @tests java.io.PrintWriter#println(boolean)
- */
- public void test_printlnZ() {
- // Test for method void java.io.PrintWriter.println(boolean)
- String s = null;
- pw.println("Random Chars");
- pw.println(false);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect boolean string: " + s, s.equals("false"));
- }
-
- /**
- * @tests java.io.PrintWriter#write(char[])
- */
- public void test_write$C() {
- // Test for method void java.io.PrintWriter.write(char [])
- String s = null;
- char[] schars = new char[11];
- "Hello World".getChars(0, 11, schars, 0);
- pw.println("Random Chars");
- pw.write(schars);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test: " + e.getMessage());
- }
- assertTrue("Wrote incorrect char[] string: " + s, s
- .equals("Hello World"));
- }
-
- /**
- * @tests java.io.PrintWriter#write(char[], int, int)
- */
- public void test_write$CII() {
- // Test for method void java.io.PrintWriter.write(char [], int, int)
- String s = null;
- char[] schars = new char[11];
- "Hello World".getChars(0, 11, schars, 0);
- pw.println("Random Chars");
- pw.write(schars, 6, 5);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect char[] string: " + s, s.equals("World"));
- }
-
- /**
- * @tests java.io.PrintWriter#write(int)
- */
- public void test_writeI() throws IOException {
- // Test for method void java.io.PrintWriter.write(int)
- char[] cab = new char[3];
- pw.write('a');
- pw.write('b');
- pw.write('c');
- pw.flush();
- InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(bao.toByteArray()));
- cab[0] = (char) isr.read();
- cab[1] = (char) isr.read();
- cab[2] = (char) isr.read();
- assertTrue("Wrote incorrect ints", cab[0] == 'a' && cab[1] == 'b'
- && cab[2] == 'c');
-
- }
-
- /**
- * @tests java.io.PrintWriter#write(java.lang.String)
- */
- public void test_writeLjava_lang_String() {
- // Test for method void java.io.PrintWriter.write(java.lang.String)
- String s = null;
- pw.println("Random Chars");
- pw.write("Hello World");
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect char[] string: " + s, s
- .equals("Hello World"));
- }
-
- /**
- * @tests java.io.PrintWriter#write(java.lang.String, int, int)
- */
- public void test_writeLjava_lang_StringII() {
- // Test for method void java.io.PrintWriter.write(java.lang.String, int,
- // int)
- String s = null;
- pw.println("Random Chars");
- pw.write("Hello World", 6, 5);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect char[] string: " + s, s.equals("World"));
- }
-
- /**
- * @tests java.io.PrintWriter#append(char)
- */
- public void test_appendChar() {
- char testChar = ' ';
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintWriter printWriter = new PrintWriter(out);
- printWriter.append(testChar);
- printWriter.flush();
- assertEquals(String.valueOf(testChar),out.toString());
- printWriter.close();
- }
- /**
- * @tests java.io.PrintWriter#append(CharSequence)
- */
- public void test_appendCharSequence() {
-
- String testString = "My Test String";
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintWriter printWriter = new PrintWriter(out);
- printWriter.append(testString);
- printWriter.flush();
- assertEquals(testString, out.toString());
- printWriter.close();
-
- }
-
- /**
- * @tests java.io.PrintWriter#append(CharSequence, int, int)
- */
- public void test_appendCharSequenceIntInt() {
- String testString = "My Test String";
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintWriter printWriter = new PrintWriter(out);
- printWriter.append(testString, 1, 3);
- printWriter.flush();
- assertEquals(testString.substring(1, 3), out.toString());
- printWriter.close();
-
- }
-
- /**
- * @tests java.io.PrintWriter#format(java.lang.String, java.lang.Object...)
- */
- public void test_formatLjava_lang_String$Ljava_lang_Object() {
- pw.format("%s %s", "Hello", "World");
- pw.flush();
- assertEquals("Wrote incorrect string", "Hello World",
- new String(bao.toByteArray()));
- }
-
- /**
- * @tests java.io.PrintWriter#format(java.util.Locale, java.lang.String, java.lang.Object...)
- */
- public void test_formatLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
- pw.format(Locale.US, "%s %s", "Hello", "World");
- pw.flush();
- assertEquals("Wrote incorrect string", "Hello World",
- new String(bao.toByteArray()));
- }
-
- /**
- * @tests java.io.PrintWriter#printf(java.lang.String, java.lang.Object...)
- */
- public void test_printfLjava_lang_String$Ljava_lang_Object() {
- pw.printf("%s %s", "Hello", "World");
- pw.flush();
- assertEquals("Wrote incorrect string", "Hello World",
- new String(bao.toByteArray()));
- }
-
- /**
- * @tests java.io.PrintWriter#printf(java.util.Locale, java.lang.String, java.lang.Object...)
- */
- public void test_printfLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
- pw.printf(Locale.US, "%s %s", "Hello", "World");
- pw.flush();
- assertEquals("Wrote incorrect string", "Hello World",
- new String(bao.toByteArray()));
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- bao = new ByteArrayOutputStream();
- pw = new PrintWriter(bao, false);
-
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- pw.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/PushbackReaderTest.java b/luni/src/test/java/tests/api/java/io/PushbackReaderTest.java
deleted file mode 100644
index e4c0c7f..0000000
--- a/luni/src/test/java/tests/api/java/io/PushbackReaderTest.java
+++ /dev/null
@@ -1,673 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.CharArrayReader;
-import java.io.FilterReader;
-import java.io.IOException;
-import java.io.PushbackReader;
-import java.io.Reader;
-import java.io.StringReader;
-
-import tests.support.Support_ASimpleReader;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(PushbackReader.class)
-public class PushbackReaderTest extends junit.framework.TestCase {
-
- Support_ASimpleReader underlying = new Support_ASimpleReader();
- PushbackReader pbr;
-
- String pbString = "Hello World";
-
- /**
- * @tests java.io.PushbackReader#PushbackReader(java.io.Reader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "PushbackReader",
- args = {java.io.Reader.class}
- )
- public void test_ConstructorLjava_io_Reader() {
- // Test for method java.io.PushbackReader(java.io.Reader)
- try {
- pbr.close();
- pbr = new PushbackReader(new StringReader(pbString));
- char buf[] = new char[5];
- pbr.read(buf, 0, 5);
- pbr.unread(buf);
- fail("Created reader with buffer larger than 1");;
- } catch (IOException e) {
- // Expected
- }
-
- try {
- pbr = new PushbackReader(null);
- } catch (NullPointerException e) {
- // EXpected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#PushbackReader(java.io.Reader, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "PushbackReader",
- args = {java.io.Reader.class, int.class}
- )
- public void test_ConstructorLjava_io_ReaderI() throws IOException {
- PushbackReader tobj;
-
- tobj = new PushbackReader(underlying, 10000);
- tobj = new PushbackReader(underlying, 1);
-
- try {
- tobj = new PushbackReader(underlying, -1);
- tobj.close();
- fail("IOException not thrown.");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- tobj = new PushbackReader(underlying, 0);
- tobj.close();
- fail("IOException not thrown.");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- PushbackReader tobj;
-
- tobj = new PushbackReader(underlying);
- tobj.close();
- tobj.close();
- tobj = new PushbackReader(underlying);
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.close();
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method void java.io.PushbackReader.close()
- try {
- pbr.close();
- pbr.read();
- } catch (Exception e) {
- return;
- }
- fail("Failed to throw exception reading from closed reader");
-
- }
-
- /**
- * @tests java.io.PushbackReader#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "mark",
- args = {int.class}
- )
- public void test_markI() {
- try {
- pbr.mark(3);
- fail("Test 1: IOException expected because marking is not supported.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.PushbackReader#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() {
- assertFalse("Test 1: markSupported() must return false.",
- pbr.markSupported());
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- PushbackReader tobj;
-
- tobj = new PushbackReader(underlying);
- assertEquals("Wrong value read!", 66, tobj.read());
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.read();
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method int java.io.PushbackReader.read()
- try {
- char c;
- pbr.read();
- c = (char) pbr.read();
- assertTrue("Failed to read char: " + c, c == pbString.charAt(1));
- Reader reader = new PushbackReader(new CharArrayReader(
- new char[] { '\u8765' }));
- assertTrue("Wrong double byte character", reader.read() == '\u8765');
- } catch (IOException e) {
- fail("IOException during read test : " + e.getMessage());
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII() throws IOException {
- PushbackReader tobj;
- char[] buf = ("01234567890123456789").toCharArray();
-
- tobj = new PushbackReader(underlying);
- tobj.read(buf, 6, 5);
- assertEquals("Wrong value read!", "BEGIN", new String(buf, 6, 5));
- assertEquals("Too much read!", "012345BEGIN123456789", new String(buf));
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.read(buf, 6, 5);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method int java.io.PushbackReader.read(char [], int, int)
- try {
- char[] c = new char[5];
- pbr.read(c, 0, 5);
- assertTrue("Failed to read chars", new String(c).equals(pbString
- .substring(0, 5)));
-
- assertEquals(0, pbr.read(c, 0, 0));
- assertEquals(c.length, pbr.read(c, 0, c.length));
- assertEquals(0, pbr.read(c, c.length, 0));
- } catch (IOException e) {
- fail("IOException during read test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PushbackReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks exceptions.",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read_$CII_Exception() throws IOException {
- pbr = new PushbackReader(new StringReader(pbString), 10);
-
- char[] nullCharArray = null;
- char[] charArray = new char[10];
-
- try {
- pbr.read(nullCharArray, 0, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- pbr.read(charArray, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- pbr.read(charArray, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- pbr.read(charArray, charArray.length + 1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- pbr.read(charArray, charArray.length, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- pbr.read(charArray, 1, charArray.length);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- pbr.read(charArray, 0, charArray.length + 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- pbr.close();
-
- try {
- pbr.read(charArray, 0, 1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#ready()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Could also add tests where underlying says no but push back buffer has contents.",
- method = "ready",
- args = {}
- )
- public void test_ready() throws IOException {
- PushbackReader tobj;
-
- tobj = new PushbackReader(underlying);
- assertTrue("Should be ready!", tobj.ready());
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.ready();
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method boolean java.io.PushbackReader.ready()
- try {
- char[] c = new char[11];
- if (c.length > 0)
- ;// use c to avoid warning msg
- assertTrue("Ready stream returned false to ready()", pbr.ready());
- } catch (IOException e) {
- fail("IOException during ready() test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PushbackReader#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- )
- public void test_reset() {
- try {
- pbr.reset();
- } catch (IOException e) {
- // correct
- return;
- }
- fail("reset failed to throw expected IOException");
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#unread(char[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "unread",
- args = {char[].class}
- )
- public void test_unread$C() throws IOException {
- PushbackReader tobj;
- String str2 = "0123456789";
- char[] buf2 = str2.toCharArray();
- char[] readBuf = new char[10];
-
- tobj = new PushbackReader(underlying, 10);
- tobj.unread(buf2);
- try {
- tobj.unread(buf2);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
- tobj.read(readBuf);
- assertEquals("Incorrect bytes read", str2, new String(readBuf));
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.read(buf2);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method void java.io.PushbackReader.unread(char [])
- try {
- char[] c = new char[5];
- pbr.read(c, 0, 5);
- pbr.unread(c);
- pbr.read(c, 0, 5);
- assertTrue("Failed to unread chars", new String(c).equals(pbString
- .substring(0, 5)));
- } catch (IOException e) {
- fail("IOException during read test : " + e.getMessage());
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- )
- public void test_skip$J() throws IOException {
- PushbackReader tobj;
-
- tobj = new PushbackReader(underlying);
- tobj.skip(6);
- tobj.skip(1000000);
- tobj.skip(1000000);
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.skip(1);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- char chars[] = new char[] { 'h', 'e', 'l', 'l', 'o' };
- for (int i = 0; i < 3; i++) {
- Reader reader, reader2;
- switch (i) {
- case 0:
- reader = new StringReader(new String(chars));
- reader2 = new StringReader(new String(chars));
- break;
- case 1:
- reader = new FilterReader(new StringReader(new String(chars))) {
- };
- reader2 = new FilterReader(new StringReader(new String(chars))) {
- };
- break;
- default:
- reader = new CharArrayReader(chars);
- reader2 = new CharArrayReader(chars);
- }
- PushbackReader pReader = new PushbackReader(reader, 2);
- PushbackReader pReader2 = new PushbackReader(reader2, 2);
- boolean skipped = false;
- long numSkipped = 0;
- try {
- numSkipped = pReader2.skip(3);
- pReader2.unread('a');
- pReader2.unread('b');
- numSkipped += pReader2.skip(10);
- numSkipped += pReader2.skip(10);
- numSkipped += pReader2.skip(10);
- numSkipped += pReader2.skip(10);
- numSkipped += pReader2.skip(10);
- numSkipped += pReader2.skip(10);
- assertEquals("Did not skip correct number of characters",
- 7, numSkipped);
- numSkipped = 0;
- numSkipped += pReader.skip(2);
- pReader.unread('i');
- numSkipped += pReader.skip(2);
- numSkipped += pReader.skip(0);
- skipped = true;
- numSkipped += pReader.skip(-1);
- fail("Failed to throw "
- + new IllegalArgumentException().getClass().getName());
- } catch (IllegalArgumentException e) {
- assertTrue("Failed to skip characters" + e, skipped);
- } catch (IOException e) {
- fail("Failed to skip characters" + e);
- }
- try {
- numSkipped += pReader.skip(1);
- numSkipped += pReader.skip(1);
- numSkipped += pReader.skip(1);
- assertEquals("Failed to skip all characters", 6, numSkipped);
- long nextSkipped = pReader.skip(1);
- assertEquals("skipped empty reader", 0, nextSkipped);
- } catch (IOException e) {
- fail("Failed to skip more characters" + e);
- }
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#unread(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "unread",
- args = {char[].class, int.class, int.class}
- )
- public void test_unread$CII() throws IOException {
- PushbackReader tobj;
- String str2 = "0123456789";
- char[] buf2 = (str2 + str2 + str2).toCharArray();
- char[] readBuf = new char[10];
-
- tobj = new PushbackReader(underlying, 10);
- tobj.unread(buf2, 15, 10);
- try {
- tobj.unread(buf2, 15, 10);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
- tobj.read(readBuf);
- assertEquals("Incorrect bytes read", "5678901234", new String(readBuf));
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.read(buf2, 15, 10);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method void java.io.PushbackReader.unread(char [], int, int)
- try {
- char[] c = new char[5];
- pbr.read(c, 0, 5);
- pbr.unread(c, 0, 2);
- pbr.read(c, 0, 5);
- assertTrue("Failed to unread chars", new String(c).equals(pbString
- .substring(0, 2)
- + pbString.substring(5, 8)));
- } catch (IOException e) {
- fail("IOException during unread test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PushbackReader#unread(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "unread",
- args = {char[].class, int.class, int.class}
- )
- public void test_unread_$CII_NullPointerException() throws IOException {
- //a pushback reader with one character buffer
- pbr = new PushbackReader(new StringReader(pbString));
-
- try {
- pbr.unread(null, 0, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PushbackReader#unread(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "unread",
- args = {char[].class, int.class, int.class}
- )
- public void test_unread_$CII_Exception_InsufficientBuffer() throws IOException {
- //a pushback reader with one character buffer
- pbr = new PushbackReader(new StringReader(pbString));
-
- //if count > buffer's size , should throw IOException
- try {
- pbr.unread(new char[pbString.length()], 0, 2);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PushbackReader#unread(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "unread",
- args = {char[].class, int.class, int.class}
- )
- public void test_unread_$CII_ArrayIndexOutOfBoundsException() throws IOException {
- //a pushback reader with one character buffer
- pbr = new PushbackReader(new StringReader(pbString));
-
- try {
- pbr.unread(new char[pbString.length()], -1 , 1);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- pbr.unread(new char[pbString.length()], 0 , -1);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- pbr.unread(new char[10], 10 , 1);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#unread(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "unread",
- args = {int.class}
- )
- public void test_unreadI() throws IOException {
- PushbackReader tobj;
-
- tobj = new PushbackReader(underlying);
- tobj.unread(23); // Why does this work?!?
- tobj.skip(2);
- tobj.unread(23);
- assertEquals("Wrong value read!", 23, tobj.read());
- tobj.unread(13);
- try {
- tobj.unread(13);
- fail("IOException not thrown (ACTUALLY NOT SURE WHETHER IT REALLY MUST BE THROWN!).");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method void java.io.PushbackReader.unread(int)
- try {
- int c;
- pbr.read();
- c = pbr.read();
- pbr.unread(c);
- assertTrue("Failed to unread char", pbr.read() == c);
- } catch (IOException e) {
- fail("IOException during unread 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() {
- pbr = new PushbackReader(new StringReader(pbString), 10);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- pbr.close();
- } catch (IOException e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/SequenceInputStreamTest.java b/luni/src/test/java/tests/api/java/io/SequenceInputStreamTest.java
deleted file mode 100644
index 0b9d2a4..0000000
--- a/luni/src/test/java/tests/api/java/io/SequenceInputStreamTest.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.SequenceInputStream;
-import java.util.Enumeration;
-
-import tests.support.Support_ASimpleInputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(SequenceInputStream.class)
-public class SequenceInputStreamTest extends junit.framework.TestCase {
-
- Support_ASimpleInputStream simple1, simple2;
- SequenceInputStream si;
- String s1 = "Hello";
- String s2 = "World";
-
- /**
- * @tests SequenceInputStream#SequenceInputStream(java.io.InputStream,
- * java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Checks NullPointerException. A positive test of this " +
- "constructor is implicitely done in setUp(); if it would " +
- "fail, all other tests will also fail.",
- method = "SequenceInputStream",
- args = {java.io.InputStream.class, java.io.InputStream.class}
- )
- public void test_Constructor_LInputStreamLInputStream_Null() {
- try {
- si = new SequenceInputStream(null , null);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- //will not throw NullPointerException if the first InputStream is not null
- InputStream is = new ByteArrayInputStream(s1.getBytes());
- si = new SequenceInputStream(is , null);
- }
-
- /**
- * @tests java.io.SequenceInputStream#SequenceInputStream(java.util.Enumeration)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SequenceInputStream",
- args = {java.util.Enumeration.class}
- )
- public void test_ConstructorLjava_util_Enumeration() {
- // Test for method java.io.SequenceInputStream(java.util.Enumeration)
- class StreamEnumerator implements Enumeration<InputStream> {
- InputStream streams[] = new InputStream[2];
-
- int count = 0;
-
- public StreamEnumerator() {
- streams[0] = new ByteArrayInputStream(s1.getBytes());
- streams[1] = new ByteArrayInputStream(s2.getBytes());
- }
-
- public boolean hasMoreElements() {
- return count < streams.length;
- }
-
- public InputStream nextElement() {
- return streams[count++];
- }
- }
-
- try {
- si = new SequenceInputStream(new StreamEnumerator());
- byte buf[] = new byte[s1.length() + s2.length()];
- si.read(buf, 0, s1.length());
- si.read(buf, s1.length(), s2.length());
- assertTrue("Read incorrect bytes: " + new String(buf), new String(
- buf).equals(s1 + s2));
- } catch (IOException e) {
- fail("IOException during read test : " + e.getMessage());
- }
-
- }
-
- /**
- * @throws IOException
- * @tests java.io.SequenceInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "available",
- args = {}
- )
- public void test_available() throws IOException {
- assertEquals("Returned incorrect number of bytes!", s1.length(), si.available());
- simple2.throwExceptionOnNextUse = true;
- assertTrue("IOException on second stream should not affect at this time!",
- si.available() == s1.length());
- simple1.throwExceptionOnNextUse = true;
- try {
- si.available();
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.SequenceInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- assertTrue("Something is available!", si.available() > 0);
- si.close();
- //will not throw IOException to close a stream which is closed already
- si.close();
- assertTrue("Nothing is available, now!", si.available() <= 0);
-// assertEquals("And not on the underlying streams either!", 0, simple1.available());
-// assertTrue("And not on the underlying streams either!", simple1.available() <= 0);
-// assertTrue("And not on the underlying streams either!", simple2.available() <= 0);
- }
-
- /**
- * @tests java.io.SequenceInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- public void test_close2() throws IOException {
- simple1.throwExceptionOnNextUse = true;
- try {
- si.close();
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.SequenceInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- si.read();
- assertEquals("Test 1: Incorrect char read;",
- s1.charAt(1), (char) si.read());
-
- // We are still reading from the first input stream, should be ok.
- simple2.throwExceptionOnNextUse = true;
- try {
- assertEquals("Test 2: Incorrect char read;",
- s1.charAt(2), (char) si.read());
- } catch (IOException e) {
- fail("Test 3: Unexpected IOException.");
- }
-
- simple1.throwExceptionOnNextUse = true;
- try {
- si.read();
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- simple1.throwExceptionOnNextUse = false;
-
- // Reading bytes 4 and 5 of the first input stream should be ok again.
- si.read();
- si.read();
-
- // Reading the first byte of the second input stream should fail.
- try {
- si.read();
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- // Reading from the second input stream should be ok now.
- simple2.throwExceptionOnNextUse = false;
- try {
- assertEquals("Test 6: Incorrect char read;",
- s2.charAt(0), (char) si.read());
- } catch (IOException e) {
- fail("Test 7: Unexpected IOException.");
- }
-
- si.close();
- assertTrue("Test 8: -1 expected when reading from a closed " +
- "sequence input stream.", si.read() == -1);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read_exc() throws IOException {
- simple2.throwExceptionOnNextUse = true;
- assertEquals("IOException on second stream should not affect at this time!", 72, si.read());
- simple1.throwExceptionOnNextUse = true;
- try {
- si.read();
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.SequenceInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() throws IOException {
- // Test for method int java.io.SequenceInputStream.read(byte [], int,
- // int)
- try {
- byte buf[] = new byte[s1.length() + s2.length()];
- si.read(buf, 0, s1.length());
- si.read(buf, s1.length(), s2.length());
- assertTrue("Read incorrect bytes: " + new String(buf), new String(
- buf).equals(s1 + s2));
- } catch (IOException e) {
- fail("IOException during read test : " + e.getMessage());
- }
-
- ByteArrayInputStream bis1 = new ByteArrayInputStream(
- new byte[] { 1, 2, 3, 4 });
- ByteArrayInputStream bis2 = new ByteArrayInputStream(
- new byte[] { 5, 6, 7, 8 });
- SequenceInputStream sis = new SequenceInputStream(bis1, bis2);
-
- try {
- sis.read(null, 0, 2);
- fail("Expected NullPointerException exception");
- } catch (NullPointerException e) {
- // expected
- }
-
- assertEquals(4, sis.read(new byte[10], 0, 8));
- // The call to read will return after the end of the first substream is
- // reached. So the next call to read will close the first substream
- // because the read call to that substream will return -1, and
- // it will continue reading from the second substream.
- assertEquals(5, sis.read());
-
- //returns -1 if the stream is closed , do not throw IOException
- byte[] array = new byte[] { 1 , 2 , 3 ,4 };
- sis.close();
- int result = sis.read(array , 0 , 5);
- assertEquals(-1 , result);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Excpetion() throws IOException {
- byte[] buf = new byte[4];
- si.read(buf, 0, 2);
- si.read(buf, 2, 1);
- simple2.throwExceptionOnNextUse = true;
- si.read(buf, 3, 1);
- assertEquals("Wrong stuff read!", "Hell", new String(buf));
- simple1.throwExceptionOnNextUse = true;
- try {
- si.read(buf, 3, 1);
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
-
- buf = new byte[10];
- simple1 = new Support_ASimpleInputStream(s1);
- simple2 = new Support_ASimpleInputStream(s2);
- si = new SequenceInputStream(simple1, simple2);
- try {
- si.read(buf, -1, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- si.read(buf, 0, -1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- si.read(buf, 1, 10);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- simple1 = new Support_ASimpleInputStream(s1);
- simple2 = new Support_ASimpleInputStream(s2);
- si = new SequenceInputStream(simple1, simple2);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/SerializablePermissionTest.java b/luni/src/test/java/tests/api/java/io/SerializablePermissionTest.java
deleted file mode 100644
index 22b5998..0000000
--- a/luni/src/test/java/tests/api/java/io/SerializablePermissionTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.SerializablePermission;
-
-@TestTargetClass(SerializablePermission.class)
-public class SerializablePermissionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.SerializablePermission#SerializablePermission(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SerializablePermission",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.SerializablePermission(java.lang.String)
- assertEquals("permission ill-formed",
- "enableSubclassImplementation", new SerializablePermission(
- "enableSubclassImplementation").getName());
- }
-
- /**
- * @tests java.io.SerializablePermission#SerializablePermission(java.lang.String,
- * java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SerializablePermission",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_String() {
- // Test for method java.io.SerializablePermission(java.lang.String,
- // java.lang.String)
- assertEquals("permission ill-formed",
- "enableSubclassImplementation", new SerializablePermission(
- "enableSubclassImplementation", "").getName());
- }
-
- /**
- * 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() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/StreamCorruptedExceptionTest.java b/luni/src/test/java/tests/api/java/io/StreamCorruptedExceptionTest.java
deleted file mode 100644
index de062f3..0000000
--- a/luni/src/test/java/tests/api/java/io/StreamCorruptedExceptionTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.StreamCorruptedException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(StreamCorruptedException.class)
-public class StreamCorruptedExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.StreamCorruptedException#StreamCorruptedException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "StreamCorruptedException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new StreamCorruptedException();
- fail("Test 1: StreamCorruptedException expected.");
- } catch (StreamCorruptedException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.StreamCorruptedException#StreamCorruptedException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "StreamCorruptedException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new StreamCorruptedException("Something went wrong.");
- fail("Test 1: StreamCorruptedException expected.");
- } catch (StreamCorruptedException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java b/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java
deleted file mode 100644
index a91a97d..0000000
--- a/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java
+++ /dev/null
@@ -1,757 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.CharArrayReader;
-import java.io.IOException;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-import java.io.Reader;
-import java.io.StreamTokenizer;
-import java.io.StringBufferInputStream;
-import java.io.StringReader;
-
-import junit.framework.Assert;
-import tests.support.Support_StringReader;
-import tests.support.Support_ASimpleInputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-// TODO: most of the assertTrue calls in this test case should be
-// replaced with assertEquals (possibly two assertEquals) see
-// test_ConstructorLjava_io_InputStream for example.
-// This gives much more helpful error messages.
-
-@TestTargetClass(StreamTokenizer.class)
-public class StreamTokenizerTest extends junit.framework.TestCase {
- Support_StringReader r;
-
- StreamTokenizer st;
-
- String testString;
-
- /**
- * @tests java.io.StreamTokenizer#StreamTokenizer(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StreamTokenizer",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStream() throws IOException {
- st = new StreamTokenizer(new StringBufferInputStream(
- "/comments\n d 8 'h'"));
-
- assertEquals("the next token returned should be the letter d",
- StreamTokenizer.TT_WORD, st.nextToken());
- assertEquals("the next token returned should be the letter d",
- "d", st.sval);
-
- assertEquals("the next token returned should be the digit 8",
- StreamTokenizer.TT_NUMBER, st.nextToken());
- assertEquals("the next token returned should be the digit 8",
- 8.0, st.nval);
-
- assertEquals("the next token returned should be the quote character",
- 39, st.nextToken());
- assertEquals("the next token returned should be the quote character",
- "h", st.sval);
- }
-
- /**
- * @tests java.io.StreamTokenizer#StreamTokenizer(java.io.Reader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StreamTokenizer",
- args = {java.io.Reader.class}
- )
- public void test_ConstructorLjava_io_Reader() throws IOException {
- setTest("/testing\n d 8 'h' ");
- assertEquals("the next token returned should be the letter d skipping the comments",
- StreamTokenizer.TT_WORD, st.nextToken());
- assertEquals("the next token returned should be the letter d",
- "d", st.sval);
-
- assertEquals("the next token returned should be the digit 8",
- StreamTokenizer.TT_NUMBER, st.nextToken());
- assertEquals("the next token returned should be the digit 8",
- 8.0, st.nval);
-
- assertEquals("the next token returned should be the quote character",
- 39, st.nextToken());
- assertEquals("the next token returned should be the quote character",
- "h", st.sval);
- }
-
- /**
- * @tests java.io.StreamTokenizer#commentChar(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "commentChar",
- args = {int.class}
- )
- public void test_commentCharI() throws IOException {
- setTest("*comment \n / 8 'h' ");
- st.ordinaryChar('/');
- st.commentChar('*');
- assertEquals("nextToken() did not return the character / skiping the comments starting with *",
- 47, st.nextToken());
- assertTrue("the next token returned should be the digit 8", st
- .nextToken() == StreamTokenizer.TT_NUMBER
- && st.nval == 8.0);
- assertTrue("the next token returned should be the quote character",
- st.nextToken() == 39 && st.sval.equals("h"));
- }
-
- /**
- * @tests java.io.StreamTokenizer#eolIsSignificant(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "eolIsSignificant",
- args = {boolean.class}
- )
- public void test_eolIsSignificantZ() throws IOException {
- setTest("d 8\n");
- // by default end of line characters are not significant
- assertTrue("nextToken did not return d",
- st.nextToken() == StreamTokenizer.TT_WORD
- && st.sval.equals("d"));
- assertTrue("nextToken did not return 8",
- st.nextToken() == StreamTokenizer.TT_NUMBER
- && st.nval == 8.0);
- assertTrue("nextToken should be the end of file",
- st.nextToken() == StreamTokenizer.TT_EOF);
- setTest("d\n");
- st.eolIsSignificant(true);
- // end of line characters are significant
- assertTrue("nextToken did not return d",
- st.nextToken() == StreamTokenizer.TT_WORD
- && st.sval.equals("d"));
- assertTrue("nextToken is the end of line",
- st.nextToken() == StreamTokenizer.TT_EOL);
- }
-
- /**
- * @tests java.io.StreamTokenizer#lineno()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "lineno",
- args = {}
- )
- public void test_lineno() throws IOException {
- setTest("d\n 8\n");
- assertEquals("the lineno should be 1", 1, st.lineno());
- st.nextToken();
- st.nextToken();
- assertEquals("the lineno should be 2", 2, st.lineno());
- st.nextToken();
- assertEquals("the next line no should be 3", 3, st.lineno());
- }
-
- /**
- * @tests java.io.StreamTokenizer#lowerCaseMode(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "lowerCaseMode",
- args = {boolean.class}
- )
- public void test_lowerCaseModeZ() throws Exception {
- // SM.
- setTest("HELLOWORLD");
- st.lowerCaseMode(true);
-
- st.nextToken();
- assertEquals("sval not converted to lowercase.", "helloworld", st.sval
- );
- }
-
- /**
- * @tests java.io.StreamTokenizer#nextToken()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "nextToken",
- args = {}
- )
- public void test_nextToken() throws IOException {
- setTest("\r\n/* fje fje 43.4 f \r\n f g */ 456.459 \r\n"
- + "Hello / \r\n \r\n \n \r \257 Hi \'Hello World\'");
- st.ordinaryChar('/');
- st.slashStarComments(true);
- st.nextToken();
- assertTrue("Wrong Token type1: " + (char) st.ttype,
- st.ttype == StreamTokenizer.TT_NUMBER);
- st.nextToken();
- assertTrue("Wrong Token type2: " + st.ttype,
- st.ttype == StreamTokenizer.TT_WORD);
- st.nextToken();
- assertTrue("Wrong Token type3: " + st.ttype, st.ttype == '/');
- st.nextToken();
- assertTrue("Wrong Token type4: " + st.ttype,
- st.ttype == StreamTokenizer.TT_WORD);
- st.nextToken();
- assertTrue("Wrong Token type5: " + st.ttype,
- st.ttype == StreamTokenizer.TT_WORD);
- st.nextToken();
- assertTrue("Wrong Token type6: " + st.ttype, st.ttype == '\'');
- assertTrue("Wrong Token type7: " + st.ttype, st.sval
- .equals("Hello World"));
- st.nextToken();
- assertTrue("Wrong Token type8: " + st.ttype, st.ttype == -1);
-
- final PipedInputStream pin = new PipedInputStream();
- PipedOutputStream pout = new PipedOutputStream(pin);
- pout.write("hello\n\r\r".getBytes());
- st = new StreamTokenizer(pin);
- st.eolIsSignificant(true);
- assertTrue("Wrong token 1,1",
- st.nextToken() == StreamTokenizer.TT_WORD
- && st.sval.equals("hello"));
- assertTrue("Wrong token 1,2", st.nextToken() == '\n');
- assertTrue("Wrong token 1,3", st.nextToken() == '\n');
- assertTrue("Wrong token 1,4", st.nextToken() == '\n');
- pout.close();
- assertTrue("Wrong token 1,5",
- st.nextToken() == StreamTokenizer.TT_EOF);
-
- st = new StreamTokenizer(new Support_StringReader("\n \r\n#"));
- st.ordinaryChar('\n'); // make \n ordinary
- st.eolIsSignificant(true);
- assertTrue("Wrong token 2,1", st.nextToken() == '\n');
- assertTrue("Wrong token 2,2", st.nextToken() == '\n');
- assertEquals("Wrong token 2,3", '#', st.nextToken());
-
- Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
- sis.throwExceptionOnNextUse = true;
- st = new StreamTokenizer(sis);
- try {
- st.nextToken();
- fail("IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.StreamTokenizer#ordinaryChar(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "ordinaryChar",
- args = {int.class}
- )
- public void test_ordinaryCharI() throws IOException {
- // SM.
- setTest("Ffjein 893");
- st.ordinaryChar('F');
- st.nextToken();
- assertTrue("OrdinaryChar failed." + (char) st.ttype,
- st.ttype == 'F');
- }
-
- /**
- * @tests java.io.StreamTokenizer#ordinaryChars(int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "ordinaryChars",
- args = {int.class, int.class}
- )
- public void test_ordinaryCharsII() throws IOException {
- // SM.
- setTest("azbc iof z 893");
- st.ordinaryChars('a', 'z');
- assertEquals("OrdinaryChars failed.", 'a', st.nextToken());
- assertEquals("OrdinaryChars failed.", 'z', st.nextToken());
- }
-
- /**
- * @tests java.io.StreamTokenizer#parseNumbers()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "parseNumbers",
- args = {}
- )
- public void test_parseNumbers() throws IOException {
- // SM
- setTest("9.9 678");
- assertTrue("Base behavior failed.",
- st.nextToken() == StreamTokenizer.TT_NUMBER);
- st.ordinaryChars('0', '9');
- assertEquals("setOrdinary failed.", '6', st.nextToken());
- st.parseNumbers();
- assertTrue("parseNumbers failed.",
- st.nextToken() == StreamTokenizer.TT_NUMBER);
- }
-
- /**
- * @tests java.io.StreamTokenizer#pushBack()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "pushBack",
- args = {}
- )
- public void test_pushBack() throws IOException {
- // SM.
- setTest("Hello 897");
- st.nextToken();
- st.pushBack();
- assertTrue("PushBack failed.",
- st.nextToken() == StreamTokenizer.TT_WORD);
- }
-
- /**
- * @tests java.io.StreamTokenizer#quoteChar(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "quoteChar",
- args = {int.class}
- )
- public void test_quoteCharI() throws IOException {
- // SM
- setTest("<Hello World< HelloWorldH");
- st.quoteChar('<');
- assertEquals("QuoteChar failed.", '<', st.nextToken());
- assertEquals("QuoteChar failed.", "Hello World", st.sval);
- st.quoteChar('H');
- st.nextToken();
- assertEquals("QuoteChar failed for word.", "elloWorld", st.sval
- );
- }
-
- /**
- * @tests java.io.StreamTokenizer#resetSyntax()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "resetSyntax",
- args = {}
- )
- public void test_resetSyntax() throws IOException {
- // SM
- setTest("H 9\' ello World");
- st.resetSyntax();
- assertTrue("resetSyntax failed1." + (char) st.ttype,
- st.nextToken() == 'H');
- assertTrue("resetSyntax failed1." + (char) st.ttype,
- st.nextToken() == ' ');
- assertTrue("resetSyntax failed2." + (char) st.ttype,
- st.nextToken() == '9');
- assertTrue("resetSyntax failed3." + (char) st.ttype,
- st.nextToken() == '\'');
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashSlashComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "slashSlashComments",
- args = {boolean.class}
- )
- public void test_slashSlashCommentsZ() throws IOException {
- // SM.
- setTest("// foo \r\n /fiji \r\n -456");
- st.ordinaryChar('/');
- st.slashSlashComments(true);
- assertEquals("Test failed.", '/', st.nextToken());
- assertTrue("Test failed.",
- st.nextToken() == StreamTokenizer.TT_WORD);
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashSlashComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "slashSlashComments",
- args = {boolean.class}
- )
- public void test_slashSlashComments_withSSOpen() throws IOException {
- Reader reader = new CharArrayReader( "t // t t t".toCharArray());
-
- StreamTokenizer st = new StreamTokenizer(reader);
- st.slashSlashComments(true);
-
- assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
- assertEquals(StreamTokenizer.TT_EOF,st.nextToken());
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashSlashComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "slashSlashComments",
- args = {boolean.class}
- )
- public void test_slashSlashComments_withSSOpen_NoComment() throws IOException {
- Reader reader = new CharArrayReader( "// t".toCharArray());
-
- StreamTokenizer st = new StreamTokenizer(reader);
- st.slashSlashComments(true);
- st.ordinaryChar('/');
-
- assertEquals(StreamTokenizer.TT_EOF,st.nextToken());
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashSlashComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "slashSlashComments",
- args = {boolean.class}
- )
- public void test_slashSlashComments_withSSClosed() throws IOException {
- Reader reader = new CharArrayReader( "// t".toCharArray());
-
- StreamTokenizer st = new StreamTokenizer(reader);
- st.slashSlashComments(false);
- st.ordinaryChar('/');
-
- assertEquals('/',st.nextToken());
- assertEquals('/',st.nextToken());
- assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashStarComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "slashStarComments",
- args = {boolean.class}
- )
- public void test_slashStarCommentsZ() throws IOException {
- setTest("/* foo \r\n /fiji \r\n*/ -456");
- st.ordinaryChar('/');
- st.slashStarComments(true);
- assertTrue("Test failed.",
- st.nextToken() == StreamTokenizer.TT_NUMBER);
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashStarComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "slashStarComments",
- args = {boolean.class}
- )
- public void test_slashStarComments_withSTOpen() throws IOException {
- Reader reader = new CharArrayReader( "t /* t */ t".toCharArray());
-
- StreamTokenizer st = new StreamTokenizer(reader);
- st.slashStarComments(true);
-
- assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
- assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
- assertEquals(StreamTokenizer.TT_EOF,st.nextToken());
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashStarComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "slashStarComments",
- args = {boolean.class}
- )
- public void test_slashStarComments_withSTClosed() throws IOException {
- Reader reader = new CharArrayReader( "t /* t */ t".toCharArray());
-
- StreamTokenizer st = new StreamTokenizer(reader);
- st.slashStarComments(false);
-
- assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
- assertEquals(StreamTokenizer.TT_EOF,st.nextToken());
- }
-
- /**
- * @tests java.io.StreamTokenizer#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() throws IOException {
- setTest("ABC Hello World");
- st.nextToken();
- assertTrue("toString failed." + st.toString(),
- st.toString().equals(
- "Token[ABC], line 1"));
- }
-
- /**
- * @tests java.io.StreamTokenizer#whitespaceChars(int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "whitespaceChars",
- args = {int.class, int.class}
- )
- public void test_whitespaceCharsII() throws IOException {
- setTest("azbc iof z 893");
- st.whitespaceChars('a', 'z');
- assertTrue("OrdinaryChar failed.",
- st.nextToken() == StreamTokenizer.TT_NUMBER);
- }
-
- /**
- * @tests java.io.StreamTokenizer#wordChars(int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "wordChars",
- args = {int.class, int.class}
- )
- public void test_wordCharsII() throws IOException {
- setTest("A893 -9B87");
- st.wordChars('0', '9');
- assertTrue("WordChar failed1.",
- st.nextToken() == StreamTokenizer.TT_WORD);
- assertEquals("WordChar failed2.", "A893", st.sval);
- assertTrue("WordChar failed3.",
- st.nextToken() == StreamTokenizer.TT_NUMBER);
- st.nextToken();
- assertEquals("WordChar failed4.", "B87", st.sval);
-
- setTest(" Hello World");
- st.wordChars(' ', ' ');
- st.nextToken();
- assertEquals("WordChars failed for whitespace.", "Hello World", st.sval
- );
-
- setTest(" Hello World\r\n \'Hello World\' Hello\' World");
- st.wordChars(' ', ' ');
- st.wordChars('\'', '\'');
- st.nextToken();
- assertTrue("WordChars failed for whitespace: " + st.sval, st.sval
- .equals("Hello World"));
- st.nextToken();
- assertTrue("WordChars failed for quote1: " + st.sval, st.sval
- .equals("\'Hello World\' Hello\' World"));
- }
-
- private void setTest(String s) {
- testString = s;
- r = new Support_StringReader(testString);
- st = new StreamTokenizer(r);
- }
-
- protected void setUp() {
- }
-
- protected void tearDown() {
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "lineno",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "General functionality of these methods tested in separate tests.",
- method = "nextToken",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "toString",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "commentChar",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "eolIsSignificant",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "lowerCaseMode",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "ordinaryChar",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "slashStarComments",
- args = {boolean.class}
- )
- })
- public void test_basicStringTokenizerMethods()
- {
- String str = "Testing 12345 \n alpha \r\n omega";
- String strb = "-3.8 'BLIND mice' \r sEe /* how */ they run";
- StringReader aa = new StringReader(str);
- StringReader ba = new StringReader(strb);
- StreamTokenizer a = new StreamTokenizer(aa);
- StreamTokenizer b = new StreamTokenizer(ba);
-
- try {
- Assert.assertTrue(a.lineno() == 1);
- Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_WORD);
- Assert.assertTrue(a.toString().equals("Token[Testing], line 1"));
- Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_NUMBER);
- Assert.assertTrue(a.toString().equals("Token[n=12345.0], line 1"));
- Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_WORD);
- Assert.assertTrue(a.toString().equals("Token[alpha], line 2"));
- Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_WORD);
- Assert.assertTrue(a.toString().equals("Token[omega], line 3"));
- Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_EOF);
- Assert.assertTrue(a.toString().equals("Token[EOF], line 3"));
-
- b.commentChar('u');
- b.eolIsSignificant(true);
- b.lowerCaseMode(true);
- b.ordinaryChar('y');
- b.slashStarComments(true);
-
- Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_NUMBER);
- Assert.assertTrue(b.nval == -3.8);
- Assert.assertTrue(b.toString().equals("Token[n=-3.8], line 1"));
- Assert.assertTrue(b.nextToken() == 39); // '
- Assert.assertTrue(b.toString().equals("Token[BLIND mice], line 1"));
- Assert.assertTrue(b.nextToken() == 10); // \n
- Assert.assertTrue(b.toString().equals("Token[EOL], line 2"));
- Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_WORD);
- Assert.assertTrue(b.toString().equals("Token[see], line 2"));
- Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_WORD);
- Assert.assertTrue(b.toString().equals("Token[the], line 2"));
- Assert.assertTrue(b.nextToken() == 121); // y
- Assert.assertTrue(b.toString().equals("Token['y'], line 2"));
- Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_WORD);
- Assert.assertTrue(b.toString().equals("Token[r], line 2"));
- Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_EOF);
- Assert.assertTrue(b.toString().equals("Token[EOF], line 2"));
- }
- catch (Exception ex){
- System.out.println("Exception found in StreamTokenizer");
- ex.printStackTrace();
- throw new RuntimeException("error in test, see stdout");
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "nextToken",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "toString",
- args = {}
- )
- })
- public void test_harmonyRegressionTest() {
- byte[] data = new byte[] {(byte) '-'};
- StreamTokenizer tokenizer = new StreamTokenizer(new ByteArrayInputStream(data));
- try {
- tokenizer.nextToken();
- } catch(Exception e) {
- Assert.fail(e.getMessage());
- }
- String result = tokenizer.toString();
- Assert.assertEquals("Token['-'], line 1", result);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "nextToken",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "toString",
- args = {}
- )
- })
- public void test_harmonyRegressionTest2() {
- byte[] data = new byte[] {(byte) '"',
- (byte) 'H',
- (byte) 'e',
- (byte) 'l',
- (byte) 'l',
- (byte) 'o',
- (byte) '"'};
- StreamTokenizer tokenizer = new StreamTokenizer(new ByteArrayInputStream(data));
- try {
- tokenizer.nextToken();
- } catch (Exception e) {
- e.printStackTrace();
- }
- String result = tokenizer.toString();
- Assert.assertEquals("Token[Hello], line 1", result);
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/StringBufferInputStreamTest.java b/luni/src/test/java/tests/api/java/io/StringBufferInputStreamTest.java
deleted file mode 100644
index d82a497..0000000
--- a/luni/src/test/java/tests/api/java/io/StringBufferInputStreamTest.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.StringBufferInputStream;
-
-@TestTargetClass(StringBufferInputStream.class)
-public class StringBufferInputStreamTest extends junit.framework.TestCase {
-
- StringBufferInputStream sbis;
-
- /**
- * @tests java.io.StringBufferInputStream#StringBufferInputStream(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StringBufferInputStream",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- new StringBufferInputStream("");
- } catch (Exception ee) {
- fail("Exception " + ee.getMessage() + " does not expected in this case");
- }
- // Test for method java.io.StringBufferInputStream(java.lang.String)
- }
-
- /**
- * @tests java.io.StringBufferInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "available",
- args = {}
- )
- public void test_available() {
- // Test for method int java.io.StringBufferInputStream.available()
- assertEquals("Returned incorrect number of available bytes", 11, sbis
- .available());
- }
-
- /**
- * @tests java.io.StringBufferInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() {
- // Test for method int java.io.StringBufferInputStream.read()
- byte[] buf = new byte[5];
- sbis.skip(6);
- sbis.read(buf, 0, 5);
- assertEquals("Returned incorrect chars", "World", new String(buf));
- }
-
- /**
- * @tests java.io.StringBufferInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Exception() {
- // Test for method int java.io.StringBufferInputStream.read()
- byte[] buf = new byte[10];
- try {
- sbis.read(buf, 0, -1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- sbis.read(buf, -1, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- sbis.read(buf, 10, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.StringBufferInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
- public void test_read() {
- // Test for method int java.io.StringBufferInputStream.read(byte [],
- // int, int)
- assertEquals("Read returned incorrect char", 'H', sbis.read());
- }
-
- /**
- * @tests java.io.StringBufferInputStream#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reset",
- args = {}
- )
- public void test_reset() {
- // Test for method void java.io.StringBufferInputStream.reset()
- long s = sbis.skip(6);
- assertEquals("Unable to skip correct umber of chars", 6, s);
- sbis.reset();
- assertEquals("Failed to reset", 'H', sbis.read());
- }
-
- /**
- * @tests java.io.StringBufferInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() {
- // Test for method long java.io.StringBufferInputStream.skip(long)
- long s = sbis.skip(6);
- assertEquals("Unable to skip correct umber of chars", 6, s);
- assertEquals("Skip positioned at incorrect char", 'W', sbis.read());
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- sbis = new StringBufferInputStream("Hello World");
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/StringReaderTest.java b/luni/src/test/java/tests/api/java/io/StringReaderTest.java
deleted file mode 100644
index 4cb8e02..0000000
--- a/luni/src/test/java/tests/api/java/io/StringReaderTest.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.IOException;
-import java.io.StringReader;
-
-@TestTargetClass(StringReader.class)
-public class StringReaderTest extends junit.framework.TestCase {
-
- String testString = "This is a test string";
-
- StringReader sr;
-
- /**
- * @tests java.io.StringReader#StringReader(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StringReader",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.StringReader(java.lang.String)
- try {
- new StringReader("Test string");
- } catch (Exception ee) {
- fail ("Exception " + ee.getMessage() + " does not expected in this case");
- }
- }
-
- /**
- * @tests java.io.StringReader#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- public void test_close() {
- // Test for method void java.io.StringReader.close()
- try {
- sr = new StringReader(testString);
- sr.close();
- char[] buf = new char[10];
- sr.read(buf, 0, 2);
- fail("Close failed");
- } catch (java.io.IOException e) {
- return;
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.StringReader#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException will never be thrown for this implementation.",
- method = "mark",
- args = {int.class}
- )
- public void test_markI() throws IOException {
- sr = new StringReader(testString);
- sr.skip(5);
- sr.mark(0);
- sr.skip(5);
- sr.reset();
- char[] buf = new char[10];
- sr.read(buf, 0, 2);
- assertTrue("Failed to return to mark", new String(buf, 0, 2)
- .equals(testString.substring(5, 7)));
- try {
- sr.mark(-1);
- fail("IllegalArgumentException not thrown!");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.StringReader#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() {
- // Test for method boolean java.io.StringReader.markSupported()
-
- sr = new StringReader(testString);
- assertTrue("markSupported returned false", sr.markSupported());
- }
-
- /**
- * @tests java.io.StringReader#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException will never be thrown for this implementation.",
- method = "read",
- args = {}
- )
- public void test_read() {
- // Test for method int java.io.StringReader.read()
- try {
- sr = new StringReader(testString);
- int r = sr.read();
- assertEquals("Failed to read char", 'T', r);
- sr = new StringReader(new String(new char[] { '\u8765' }));
- assertTrue("Wrong double byte char", sr.read() == '\u8765');
- } catch (Exception e) {
- fail("Exception during read test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.StringReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException will never be thrown for this implementation.",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII() throws Exception {
- // Test for method int java.io.StringReader.read(char [], int, int)
- try {
- sr = new StringReader(testString);
- char[] buf = new char[testString.length()];
- int r = sr.read(buf, 0, testString.length());
- assertTrue("Failed to read chars", r == testString.length());
- assertTrue("Read chars incorrectly", new String(buf, 0, r)
- .equals(testString));
- } catch (Exception e) {
- fail("Exception during read test : " + e.getMessage());
- }
-
- char[] buf = new char[testString.length()];
- sr = new StringReader(testString);
- try {
- sr.read(buf, 0, -1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- sr.read(buf, -1, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- sr.read(buf, 1, testString.length());
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.StringReader#ready()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException will never be thrown for this implementation.",
- method = "ready",
- args = {}
- )
- public void test_ready() {
- // Test for method boolean java.io.StringReader.ready()
- try {
- sr = new StringReader(testString);
- assertTrue("Steam not ready", sr.ready());
- sr.close();
- int r = 0;
- try {
- sr.ready();
- } catch (IOException e) {
- r = 1;
- }
- assertEquals("Expected IOException not thrown in read()", 1, r);
- } catch (IOException e) {
- fail("IOException during ready test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.StringReader#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException will never be thrown for this implementation.",
- method = "reset",
- args = {}
- )
- public void test_reset() {
- // Test for method void java.io.StringReader.reset()
- try {
- sr = new StringReader(testString);
- sr.skip(5);
- sr.mark(0);
- sr.skip(5);
- sr.reset();
- char[] buf = new char[10];
- sr.read(buf, 0, 2);
- assertTrue("Failed to reset properly", new String(buf, 0, 2)
- .equals(testString.substring(5, 7)));
- } catch (Exception e) {
- fail("Exception during reset test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.StringReader#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException will never be thrown for this implementation.",
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() {
- // Test for method long java.io.StringReader.skip(long)
- try {
- sr = new StringReader(testString);
- sr.skip(5);
- char[] buf = new char[10];
- sr.read(buf, 0, 2);
- assertTrue("Failed to skip properly", new String(buf, 0, 2)
- .equals(testString.substring(5, 7)));
- } catch (Exception 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() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
-
- try {
- sr.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/StringWriterTest.java b/luni/src/test/java/tests/api/java/io/StringWriterTest.java
deleted file mode 100644
index aeb3934..0000000
--- a/luni/src/test/java/tests/api/java/io/StringWriterTest.java
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.IOException;
-import java.io.StringWriter;
-
-@TestTargetClass(StringWriter.class)
-public class StringWriterTest extends junit.framework.TestCase {
-
- StringWriter sw;
-
- /**
- * @tests java.io.StringWriter#StringWriter()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StringWriter",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StringWriter",
- args = {int.class}
- )
- })
- public void test_Constructor() {
- new StringWriter();
- new StringWriter(10);
- new StringWriter(10000);
- }
-
- /**
- * @tests java.io.StringWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "There won't be IOException, ever!",
- method = "close",
- args = {}
- )
- public void test_close() {
- // Test for method void java.io.StringWriter.close()
- try {
- sw.close();
- } catch (IOException e) {
- fail("IOException closing StringWriter : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.StringWriter#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "flush",
- args = {}
- )
- public void test_flush() {
- // Test for method void java.io.StringWriter.flush()
- sw.flush();
- sw.write('c');
- assertEquals("Failed to flush char", "c", sw.toString());
- }
-
- /**
- * @tests java.io.StringWriter#getBuffer()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getBuffer",
- args = {}
- )
- public void test_getBuffer() {
- // Test for method java.lang.StringBuffer
- // java.io.StringWriter.getBuffer()
-
- sw.write("This is a test string");
- StringBuffer sb = sw.getBuffer();
- assertEquals("Incorrect buffer returned",
- "This is a test string", sb.toString());
- }
-
- /**
- * @tests java.io.StringWriter#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.io.StringWriter.toString()
- sw.write("This is a test string");
- assertEquals("Incorrect string returned",
- "This is a test string", sw.toString());
- }
-
- /**
- * @tests java.io.StringWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII() {
- // Test for method void java.io.StringWriter.write(char [], int, int)
- char[] c = new char[1000];
- "This is a test string".getChars(0, 21, c, 0);
- sw.write(c, 4, 14);
- assertEquals("Chars not written properly",
- " is a test str", sw.toString());
- }
-
- /**
- * @tests java.io.StringWriter#write(char[], int, int)
- * Regression for HARMONY-387
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII_Exception() {
- StringWriter obj = new StringWriter();
- try {
- obj.write(new char[10], 0, -1);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- obj.write(new char[10], -1, 1);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- obj.write(new char[10], 2, 9);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.StringWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() {
- // Test for method void java.io.StringWriter.write(int)
- sw.write('c');
- assertEquals("Char not written properly", "c", sw.toString());
- }
-
- /**
- * @tests java.io.StringWriter#write(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {java.lang.String.class}
- )
- public void test_writeLjava_lang_String() {
- // Test for method void java.io.StringWriter.write(java.lang.String)
- sw.write("This is a test string");
- assertEquals("String not written properly",
- "This is a test string", sw.toString());
- }
-
- /**
- * @tests java.io.StringWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void test_writeLjava_lang_StringII() {
- // Test for method void java.io.StringWriter.write(java.lang.String,
- // int, int)
- sw.write("This is a test string", 2, 2);
- assertEquals("String not written properly", "is", sw.toString());
- }
-
- /**
- * @tests java.io.StringWriter#append(char)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {char.class}
- )
- public void test_appendChar() throws IOException {
- char testChar = ' ';
- StringWriter stringWriter = new StringWriter(20);
- stringWriter.append(testChar);
- assertEquals(String.valueOf(testChar), stringWriter.toString());
- stringWriter.close();
- }
-
- /**
- * @tests java.io.PrintWriter#append(CharSequence)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {java.lang.CharSequence.class}
- )
- public void test_appendCharSequence() throws IOException {
-
- String testString = "My Test String";
- StringWriter stringWriter = new StringWriter(20);
- stringWriter.append(testString);
- assertEquals(String.valueOf(testString), stringWriter.toString());
- stringWriter.close();
- }
-
- /**
- * @tests java.io.PrintWriter#append(CharSequence, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- public void test_appendCharSequenceIntInt() throws IOException {
- String testString = "My Test String";
- StringWriter stringWriter = new StringWriter(20);
- stringWriter.append(testString, 1, 3);
- assertEquals(testString.substring(1, 3), stringWriter.toString());
- stringWriter.close();
-
- try {
- StringWriter tobj = new StringWriter(9);
- tobj.append("01234567890123456789", 19, 2);
- fail("IndexOutOfBoundsException not thrown!");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- StringWriter tobj = new StringWriter(9);
- tobj.append("01234567890123456789", 29, 2);
- fail("IndexOutOfBoundsException not thrown!");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
-
- sw = new StringWriter();
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/SyncFailedExceptionTest.java b/luni/src/test/java/tests/api/java/io/SyncFailedExceptionTest.java
deleted file mode 100644
index 9ec7c86..0000000
--- a/luni/src/test/java/tests/api/java/io/SyncFailedExceptionTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.SyncFailedException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(SyncFailedException.class)
-public class SyncFailedExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.SyncFailedException#SyncFailedException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "SyncFailedException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new SyncFailedException("Something went wrong.");
- fail("Test 1: SyncFailedException expected.");
- } catch (SyncFailedException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/UTFDataFormatExceptionTest.java b/luni/src/test/java/tests/api/java/io/UTFDataFormatExceptionTest.java
deleted file mode 100644
index 8798785..0000000
--- a/luni/src/test/java/tests/api/java/io/UTFDataFormatExceptionTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.UTFDataFormatException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(UTFDataFormatException.class)
-public class UTFDataFormatExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.UTFDataFormatException#UTFDataFormatException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "UTFDataFormatException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new UTFDataFormatException();
- fail("Test 1: UTFDataFormatException expected.");
- } catch (UTFDataFormatException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.UTFDataFormatException#UTFDataFormatException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "UTFDataFormatException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new UTFDataFormatException("Something went wrong.");
- fail("Test 1: UTFDataFormatException expected.");
- } catch (UTFDataFormatException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/UnsupportedEncodingExceptionTest.java b/luni/src/test/java/tests/api/java/io/UnsupportedEncodingExceptionTest.java
deleted file mode 100644
index 7fe4d11..0000000
--- a/luni/src/test/java/tests/api/java/io/UnsupportedEncodingExceptionTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import java.io.UnsupportedEncodingException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(UnsupportedEncodingException.class)
-public class UnsupportedEncodingExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.UnsupportedEncodingException#UnsupportedEncodingException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "UnsupportedEncodingException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new UnsupportedEncodingException();
- fail("Test 1: UnsupportedEncodingException expected.");
- } catch (UnsupportedEncodingException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.UnsupportedEncodingException#UnsupportedEncodingException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "UnsupportedEncodingException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new UnsupportedEncodingException("Something went wrong.");
- fail("Test 1: UnsupportedEncodingException expected.");
- } catch (UnsupportedEncodingException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/WriteAbortedExceptionTest.java b/luni/src/test/java/tests/api/java/io/WriteAbortedExceptionTest.java
deleted file mode 100644
index 813b1e8..0000000
--- a/luni/src/test/java/tests/api/java/io/WriteAbortedExceptionTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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 tests.api.java.io;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.IOException;
-import java.io.WriteAbortedException;
-
-@TestTargetClass(WriteAbortedException.class)
-public class WriteAbortedExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.WriteAbortedException#WriteAbortedException(java.lang.String,
- * java.lang.Exception)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "WriteAbortedException",
- args = {java.lang.String.class, java.lang.Exception.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_Exception() {
- // Test for method java.io.WriteAbortedException(java.lang.String,
- // java.lang.Exception)
- try {
- if (true)
- throw new WriteAbortedException("HelloWorld",
- new WriteAbortedException("ByeWorld", null));
- } catch (WriteAbortedException e) {
- return;
- }
- fail("Failed to generate expected Exception");
- }
-
- /**
- * @tests java.io.WriteAbortedException#getMessage()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getCause",
- args = {}
- )
- public void test_getCause() {
- try {
- if (true) {
- throw new WriteAbortedException("HelloWorld",
- new IOException("Something went wrong."));
- }
- fail("Test 1: WriteAbortedException expected.");
- } catch (WriteAbortedException e) {
- Throwable cause = e.getCause();
- assertTrue("Test 2: Incorrect exception cause: " + cause,
- cause.getClass().equals(IOException.class) &&
- cause.getMessage().equals("Something went wrong."));
- }
- }
-
- /**
- * @tests java.io.WriteAbortedException#getMessage()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMessage",
- args = {}
- )
- public void test_getMessage() {
- // Test for method java.lang.String
- // java.io.WriteAbortedException.getMessage()
- try {
- if (true)
- throw new WriteAbortedException("HelloWorld",
- new WriteAbortedException("ByeWorld", null));
- } catch (WriteAbortedException e) {
- assertTrue("WriteAbortedException::getMessage() failed"
- + e.getMessage(), e.getMessage().equals(
- "HelloWorld; java.io.WriteAbortedException: ByeWorld"));
- return;
- }
- fail("Failed to generate expected Exception");
- }
-}