summaryrefslogtreecommitdiffstats
path: root/harmony-tests
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-02-19 14:25:08 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-02-19 14:25:08 +0000
commit5a95445260e22dcca730b582c881cc67b8de640e (patch)
tree1f40c36e0e83bdcfc92d455d087c05efbc916f38 /harmony-tests
parente68e325b5a7f73c6a6dc8bdfb92e76114e4f2b64 (diff)
parent2b7c83942a5e28c53698232182193d5118028e6c (diff)
downloadlibcore-5a95445260e22dcca730b582c881cc67b8de640e.zip
libcore-5a95445260e22dcca730b582c881cc67b8de640e.tar.gz
libcore-5a95445260e22dcca730b582c881cc67b8de640e.tar.bz2
Merge "Fix another set of file related tests."
Diffstat (limited to 'harmony-tests')
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/io/BufferedInputStreamTest.java110
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileDescriptorTest.java110
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileInputStreamTest.java124
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileOutputStreamTest.java89
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileReaderTest.java9
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileTest.java49
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileWriterTest.java26
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FilterInputStreamTest.java134
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/io/SyncFailedExceptionTest.java18
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/net/JarURLConnectionTest.java20
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/util/jar/JarFileTest.java11
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/ZipFileTest.java78
12 files changed, 377 insertions, 401 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/BufferedInputStreamTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/BufferedInputStreamTest.java
index aea5196..a5ba9e1 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/BufferedInputStreamTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/BufferedInputStreamTest.java
@@ -17,8 +17,6 @@
package org.apache.harmony.tests.java.io;
-import junit.framework.TestCase;
-import tests.support.Support_PlatformFile;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -27,17 +25,68 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import junit.framework.TestCase;
public class BufferedInputStreamTest extends TestCase {
- public String fileName;
+ private static final String INPUT =
+ "Test_All_Tests\n" +
+ "Test_BufferedInputStream\n" +
+ "Test_java_io_BufferedOutputStream\n" +
+ "Test_java_io_ByteArrayInputStream\n" +
+ "Test_java_io_ByteArrayOutputStream\n" +
+ "Test_java_io_DataInputStream\n" +
+ "Test_java_io_File\n" +
+ "Test_java_io_FileDescriptor\n" +
+ "Test_java_io_FileInputStream\n" +
+ "Test_java_io_FileNotFoundException\n" +
+ "Test_java_io_FileOutputStream\n" +
+ "Test_java_io_FilterInputStream\n" +
+ "Test_java_io_FilterOutputStream\n" +
+ "Test_java_io_InputStream\n" +
+ "Test_java_io_IOException\n" +
+ "Test_java_io_OutputStream\n" +
+ "Test_java_io_PrintStream\n" +
+ "Test_java_io_RandomAccessFile\n" +
+ "Test_java_io_SyncFailedException\n" +
+ "Test_java_lang_AbstractMethodError\n" +
+ "Test_java_lang_ArithmeticException\n" +
+ "Test_java_lang_ArrayIndexOutOfBoundsException\n" +
+ "Test_java_lang_ArrayStoreException\n" +
+ "Test_java_lang_Boolean\n" +
+ "Test_java_lang_Byte\n" +
+ "Test_java_lang_Character\n" +
+ "Test_All_Tests\n" +
+ "Test_BufferedInputStream\n" +
+ "Test_java_io_BufferedOutputStream\n" +
+ "Test_java_io_ByteArrayInputStream\n" +
+ "Test_java_io_ByteArrayOutputStream\n" +
+ "Test_java_io_DataInputStream\n" +
+ "Test_java_io_File\n" +
+ "Test_java_io_FileDescriptor\n" +
+ "Test_java_io_FileInputStream\n" +
+ "Test_java_io_FileNotFoundException\n" +
+ "Test_java_io_FileOutputStream\n" +
+ "Test_java_io_FilterInputStream\n" +
+ "Test_java_io_FilterOutputStream\n" +
+ "Test_java_io_InputStream\n" +
+ "Test_java_io_IOException\n" +
+ "Test_java_io_OutputStream\n" +
+ "Test_java_io_PrintStream\n" +
+ "Test_java_io_RandomAccessFile\n" +
+ "Test_java_io_SyncFailedException\n" +
+ "Test_java_lang_AbstractMethodError\n" +
+ "Test_java_lang_ArithmeticException\n" +
+ "Test_java_lang_ArrayIndexOutOfBoundsException\n" +
+ "Test_java_lang_ArrayStoreException\n" +
+ "Test_java_lang_Boolean\n" +
+ "Test_java_lang_Byte\n" +
+ "Test_java_lang_Character\n";
private BufferedInputStream is;
+ private InputStream isBytes;
- private FileInputStream isFile;
-
- private static final String INPUT = "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";
/*
* java.io.BufferedInputStream(InputStream)
@@ -66,16 +115,17 @@ public class BufferedInputStreamTest extends TestCase {
// Test for method java.io.BufferedInputStream(java.io.InputStream, int)
- // Create buffer with exact size of file
- is = new BufferedInputStream(isFile, this.INPUT.length());
+ // Create buffer with hald size of file and fill it.
+ int bufferSize = INPUT.length() / 2;
+ is = new BufferedInputStream(isBytes, bufferSize);
// Ensure buffer gets filled by evaluating one read
is.read();
// Close underlying FileInputStream, all but 1 buffered bytes should
// still be available.
- isFile.close();
+ isBytes.close();
// Read the remaining buffered characters, no IOException should
// occur.
- is.skip(this.INPUT.length() - 2);
+ is.skip(bufferSize - 2);
is.read();
try {
// is.read should now throw an exception because it will have to
@@ -135,7 +185,7 @@ public class BufferedInputStreamTest extends TestCase {
* java.io.BufferedInputStream#close()
*/
public void test_close() throws IOException {
- new BufferedInputStream(isFile).close();
+ new BufferedInputStream(isBytes).close();
// regression for HARMONY-667
BufferedInputStream buf = new BufferedInputStream(null, 5);
@@ -194,8 +244,8 @@ public class BufferedInputStreamTest extends TestCase {
public void test_markI() throws IOException {
byte[] buf1 = new byte[100];
byte[] buf2 = new byte[100];
- is.skip(3000);
- is.mark(1000);
+ is.skip(50);
+ is.mark(500);
is.read(buf1, 0, buf1.length);
is.reset();
is.read(buf2, 0, buf2.length);
@@ -266,7 +316,7 @@ public class BufferedInputStreamTest extends TestCase {
public void test_read() throws IOException {
InputStreamReader isr = new InputStreamReader(is);
int c = isr.read();
- assertTrue("read returned incorrect char", c == INPUT.charAt(0));
+ assertEquals(INPUT.charAt(0), c);
byte[] bytes = new byte[256];
for (int i = 0; i < 256; i++) {
@@ -331,11 +381,11 @@ public class BufferedInputStreamTest extends TestCase {
*/
public void test_read$BII() throws IOException {
byte[] buf1 = new byte[100];
- is.skip(3000);
- is.mark(1000);
+ is.skip(500);
+ is.mark(500);
is.read(buf1, 0, buf1.length);
assertTrue("Failed to read correct data", new String(buf1, 0,
- buf1.length).equals(INPUT.substring(3000, 3100)));
+ buf1.length).equals(INPUT.substring(500, 600)));
BufferedInputStream bufin = new BufferedInputStream(new InputStream() {
int size = 2
@@ -489,20 +539,13 @@ public class BufferedInputStreamTest extends TestCase {
*/
@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(INPUT.getBytes());
+ File f = File.createTempFile("BufferedInputStreamTest", "tst");
+ FileOutputStream fos = new FileOutputStream(f);
+ fos.write(INPUT.getBytes(StandardCharsets.US_ASCII));
fos.close();
- isFile = new FileInputStream(fileName);
- is = new BufferedInputStream(isFile);
+
+ isBytes = new FileInputStream(f.getAbsolutePath());
+ is = new BufferedInputStream(isBytes, INPUT.length() / 2);
}
/**
@@ -515,10 +558,5 @@ public class BufferedInputStreamTest extends TestCase {
is.close();
} catch (Exception e) {
}
- try {
- File f = new File(fileName);
- f.delete();
- } catch (Exception e) {
- }
}
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileDescriptorTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileDescriptorTest.java
index b4bb180..5c18de3 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileDescriptorTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileDescriptorTest.java
@@ -17,99 +17,73 @@
package org.apache.harmony.tests.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.IOException;
import java.io.RandomAccessFile;
-
+import java.nio.charset.StandardCharsets;
import junit.framework.TestCase;
public class FileDescriptorTest extends TestCase {
- private static String platformId = "JDK"
- + System.getProperty("java.vm.version").replace('.', '-');
-
- FileOutputStream fos;
+ public void test_sync() throws IOException {
+ File f = File.createTempFile("FileDescriptorText", "txt");
- BufferedOutputStream os;
+ FileOutputStream fos = null;
+ FileInputStream fis = null;
+ RandomAccessFile raf = null;
- FileInputStream fis;
+ try {
+ fos = new FileOutputStream(f.getAbsolutePath());
+ fos.write("Test String".getBytes(StandardCharsets.US_ASCII));
- File f;
+ fis = new FileInputStream(f.getPath());
+ FileDescriptor fd = fos.getFD();
+ fd.sync();
- /**
- * java.io.FileDescriptor#FileDescriptor()
- */
- public void test_Constructor() {
- FileDescriptor fd = new FileDescriptor();
- assertTrue("Failed to create FileDescriptor",
- fd instanceof FileDescriptor);
- }
-
- /**
- * java.io.FileDescriptor#sync()
- */
- public void test_sync() throws IOException {
- f = new File(System.getProperty("user.dir"), "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());
+ int length = "Test String".length();
+ assertEquals(length, fis.available());
- // Regression test for Harmony-1494
- fd = fis.getFD();
- fd.sync();
- assertEquals("Bytes were not written after sync", length, fis
- .available());
+ // Regression test for Harmony-1494
+ fd = fis.getFD();
+ fd.sync();
+ assertEquals(length, fis.available());
- RandomAccessFile raf = new RandomAccessFile(f, "r");
- fd = raf.getFD();
- fd.sync();
- raf.close();
+ raf = new RandomAccessFile(f, "r");
+ fd = raf.getFD();
+ fd.sync();
+ } finally {
+ if (fos != null) {
+ fos.close();
+ }
+ if (fis != null) {
+ fis.close();
+ }
+ if (raf != null) {
+ raf.close();
+ }
+ }
}
/**
* java.io.FileDescriptor#valid()
*/
public void test_valid() throws IOException {
- f = new File(System.getProperty("user.dir"), "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());
- }
+ File f = File.createTempFile("FileDescriptorText", "txt");
- /**
- * 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) {
- }
+ FileOutputStream fos = null;
try {
+ fos = new FileOutputStream(f.getAbsolutePath());
+ FileDescriptor fd = fos.getFD();
+ assertTrue(fd.valid());
fos.close();
- } catch (Exception e) {
- }
- try {
- f.delete();
- } catch (Exception e) {
+ assertFalse(fd.valid());
+ } finally {
+ if (fos != null) {
+ fos.close();
+ }
}
}
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileInputStreamTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileInputStreamTest.java
index 2da82f4..af54d4b 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileInputStreamTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileInputStreamTest.java
@@ -17,25 +17,89 @@
package org.apache.harmony.tests.java.io;
-import junit.framework.TestCase;
-import tests.support.Support_PlatformFile;
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.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import junit.framework.TestCase;
public class FileInputStreamTest extends TestCase {
- public String fileName;
+ private String fileName;
private java.io.InputStream is;
- byte[] ibuf = new byte[4096];
+ private static final String INPUT =
+ "Test_All_Tests\n" +
+ "Test_BufferedInputStream\n" +
+ "Test_java_io_BufferedOutputStream\n" +
+ "Test_java_io_ByteArrayInputStream\n" +
+ "Test_java_io_ByteArrayOutputStream\n" +
+ "Test_java_io_DataInputStream\n" +
+ "Test_java_io_File\n" +
+ "Test_java_io_FileDescriptor\n" +
+ "Test_java_io_FileInputStream\n" +
+ "Test_java_io_FileNotFoundException\n" +
+ "Test_java_io_FileOutputStream\n" +
+ "Test_java_io_FilterInputStream\n" +
+ "Test_java_io_FilterOutputStream\n" +
+ "Test_java_io_InputStream\n" +
+ "Test_java_io_IOException\n" +
+ "Test_java_io_OutputStream\n" +
+ "Test_java_io_PrintStream\n" +
+ "Test_java_io_RandomAccessFile\n" +
+ "Test_java_io_SyncFailedException\n" +
+ "Test_java_lang_AbstractMethodError\n" +
+ "Test_java_lang_ArithmeticException\n" +
+ "Test_java_lang_ArrayIndexOutOfBoundsException\n" +
+ "Test_java_lang_ArrayStoreException\n" +
+ "Test_java_lang_Boolean\n" +
+ "Test_java_lang_Byte\n" +
+ "Test_java_lang_Character\n" +
+ "Test_All_Tests\n" +
+ "Test_BufferedInputStream\n" +
+ "Test_java_io_BufferedOutputStream\n" +
+ "Test_java_io_ByteArrayInputStream\n" +
+ "Test_java_io_ByteArrayOutputStream\n" +
+ "Test_java_io_DataInputStream\n" +
+ "Test_java_io_File\n" +
+ "Test_java_io_FileDescriptor\n" +
+ "Test_java_io_FileInputStream\n" +
+ "Test_java_io_FileNotFoundException\n" +
+ "Test_java_io_FileOutputStream\n" +
+ "Test_java_io_FilterInputStream\n" +
+ "Test_java_io_FilterOutputStream\n" +
+ "Test_java_io_InputStream\n" +
+ "Test_java_io_IOException\n" +
+ "Test_java_io_OutputStream\n" +
+ "Test_java_io_PrintStream\n" +
+ "Test_java_io_RandomAccessFile\n" +
+ "Test_java_io_SyncFailedException\n" +
+ "Test_java_lang_AbstractMethodError\n" +
+ "Test_java_lang_ArithmeticException\n" +
+ "Test_java_lang_ArrayIndexOutOfBoundsException\n" +
+ "Test_java_lang_ArrayStoreException\n" +
+ "Test_java_lang_Boolean\n" +
+ "Test_java_lang_Byte\n" +
+ "Test_java_lang_Character\n";
+
+ @Override
+ protected void setUp() throws IOException {
+ File f = File.createTempFile("FileInputStreamTest", "tst");
+
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(f.getAbsolutePath());
+ fos.write(INPUT.getBytes(StandardCharsets.US_ASCII));
+ } finally {
+ fos.close();
+ }
- 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";
+ fileName = f.getAbsolutePath();
+ }
/**
* java.io.FileInputStream#FileInputStream(java.io.File)
@@ -96,8 +160,7 @@ public class FileInputStreamTest extends TestCase {
public void test_available() throws IOException {
try {
is = new FileInputStream(fileName);
- assertTrue("Returned incorrect number of available bytes", is
- .available() == fileString.length());
+ assertTrue(is.available() == INPUT.length());
} finally {
try {
is.close();
@@ -150,7 +213,7 @@ public class FileInputStreamTest extends TestCase {
InputStreamReader isr = new InputStreamReader(new FileInputStream(fileName));
int c = isr.read();
isr.close();
- assertTrue("read returned incorrect char", c == fileString.charAt(0));
+ assertEquals(INPUT.charAt(0), c);
}
/**
@@ -159,11 +222,11 @@ public class FileInputStreamTest extends TestCase {
public void test_read$B() throws IOException {
byte[] buf1 = new byte[100];
is = new FileInputStream(fileName);
- is.skip(3000);
+ is.skip(500);
is.read(buf1);
is.close();
- assertTrue("Failed to read correct data", new String(buf1, 0,
- buf1.length).equals(fileString.substring(3000, 3100)));
+ assertEquals(INPUT.substring(500, 600),
+ new String(buf1, 0, buf1.length, StandardCharsets.US_ASCII));
}
/**
@@ -172,11 +235,11 @@ public class FileInputStreamTest extends TestCase {
public void test_read$BII() throws IOException {
byte[] buf1 = new byte[100];
is = new FileInputStream(fileName);
- is.skip(3000);
+ is.skip(500);
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)));
+ assertEquals(INPUT.substring(500, 600),
+ new String(buf1, 0, buf1.length, StandardCharsets.US_ASCII));
// Regression test for HARMONY-285
File tmpFile = File.createTempFile("FileOutputStream", "tmp");
@@ -319,8 +382,9 @@ public class FileInputStreamTest extends TestCase {
is.skip(1000);
is.read(buf1, 0, buf1.length);
is.close();
- assertTrue("Failed to skip to correct position", new String(buf1, 0,
- buf1.length).equals(fileString.substring(1000, 1010)));
+ assertEquals(INPUT.substring(1000, 1010),
+ new String(buf1, 0, buf1.length, StandardCharsets.US_ASCII));
+
}
/**
@@ -415,30 +479,4 @@ public class FileInputStreamTest extends TestCase {
assertEquals(110, fis.getChannel().position());
fis.close();
}
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- 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");
- java.io.OutputStream fos = new java.io.FileOutputStream(fileName);
- fos.write(fileString.getBytes());
- fos.close();
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- new File(fileName).delete();
- }
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileOutputStreamTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileOutputStreamTest.java
index 1d13f76..8c5e91f 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileOutputStreamTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileOutputStreamTest.java
@@ -28,25 +28,43 @@ import junit.framework.TestCase;
public class FileOutputStreamTest extends TestCase {
- public String fileName;
-
- FileOutputStream fos;
-
- FileInputStream fis;
-
- File f;
-
- byte[] ibuf = new byte[4096];
+ private FileOutputStream fos;
+ private FileInputStream fis;
+ private File f;
+ private byte[] bytes;
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";
- byte[] bytes;
+ protected void setUp() {
+ bytes = new byte[10];
+ for (int i = 0; i < bytes.length; i++) {
+ bytes[i] = (byte) i;
+ }
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (f != null) {
+ f.delete();
+ }
+ if (fis != null) {
+ fis.close();
+ }
+ if (fos != null) {
+ fos.close();
+ }
+ }
/**
* java.io.FileOutputStream#FileOutputStream(java.io.File)
*/
public void test_ConstructorLjava_io_File() throws IOException {
- f = new File(fileName = System.getProperty("user.home"), "fos.tst");
+ f = File.createTempFile("FileOutputStreamTest", "tst");
fos = new FileOutputStream(f);
}
@@ -54,8 +72,8 @@ public class FileOutputStreamTest extends TestCase {
* java.io.FileOutputStream#FileOutputStream(java.io.FileDescriptor)
*/
public void test_ConstructorLjava_io_FileDescriptor() throws IOException {
- f = new File(fileName = System.getProperty("user.home"), "fos.tst");
- fileName = f.getAbsolutePath();
+ f = File.createTempFile("FileOutputStreamTest", "tst");
+ String fileName = f.getAbsolutePath();
fos = new FileOutputStream(fileName);
fos.write('l');
fos.close();
@@ -69,8 +87,8 @@ public class FileOutputStreamTest extends TestCase {
* java.io.FileOutputStream#FileOutputStream(java.lang.String)
*/
public void test_ConstructorLjava_lang_String() throws IOException {
- f = new File(fileName = System.getProperty("user.home"), "fos.tst");
- fileName = f.getAbsolutePath();
+ f = File.createTempFile("FileOutputStreamTest", "tst");
+ String fileName = f.getAbsolutePath();
fos = new FileOutputStream(fileName);
// Regression test for HARMONY-4012
@@ -82,7 +100,7 @@ public class FileOutputStreamTest extends TestCase {
*boolean)
*/
public void test_ConstructorLjava_lang_StringZ() throws IOException {
- f = new File(System.getProperty("user.home"), "fos.tst");
+ f = File.createTempFile("FileOutputStreamTest", "tst");
fos = new FileOutputStream(f.getPath(), false);
fos.write("HI".getBytes(), 0, 2);
fos.close();
@@ -126,7 +144,7 @@ public class FileOutputStreamTest extends TestCase {
* java.io.FileOutputStream#close()
*/
public void test_close() throws IOException {
- f = new File(System.getProperty("user.home"), "output.tst");
+ f = File.createTempFile("FileOutputStreamTest", "tst");
fos = new FileOutputStream(f.getPath());
fos.close();
@@ -142,8 +160,8 @@ public class FileOutputStreamTest extends TestCase {
* java.io.FileOutputStream#getFD()
*/
public void test_getFD() throws IOException {
- f = new File(fileName = System.getProperty("user.home"), "testfd");
- fileName = f.getAbsolutePath();
+ f = File.createTempFile("FileOutputStreamTest", "tst");
+ String fileName = f.getAbsolutePath();
fos = new FileOutputStream(f);
assertTrue("Returned invalid fd", fos.getFD().valid());
fos.close();
@@ -154,7 +172,7 @@ public class FileOutputStreamTest extends TestCase {
* java.io.FileOutputStream#write(byte[])
*/
public void test_write$B() throws IOException {
- f = new File(System.getProperty("user.home"), "output.tst");
+ f = File.createTempFile("FileOutputStreamTest", "tst");
fos = new FileOutputStream(f.getPath());
fos.write(fileString.getBytes());
fis = new FileInputStream(f.getPath());
@@ -168,7 +186,7 @@ public class FileOutputStreamTest extends TestCase {
* java.io.FileOutputStream#write(byte[], int, int)
*/
public void test_write$BII() throws IOException {
- f = new File(System.getProperty("user.home"), "output.tst");
+ f = File.createTempFile("FileOutputStreamTest", "tst");
fos = new FileOutputStream(f.getPath());
fos.write(fileString.getBytes(), 0, fileString.length());
fis = new FileInputStream(f.getPath());
@@ -196,7 +214,7 @@ public class FileOutputStreamTest extends TestCase {
* java.io.FileOutputStream#write(int)
*/
public void test_writeI() throws IOException {
- f = new File(System.getProperty("user.home"), "output.tst");
+ f = File.createTempFile("FileOutputStreamTest", "tst");
fos = new FileOutputStream(f.getPath());
fos.write('t');
fis = new FileInputStream(f.getPath());
@@ -208,7 +226,7 @@ public class FileOutputStreamTest extends TestCase {
*/
public void test_write$BII2() throws IOException {
// Regression for HARMONY-437
- f = new File(System.getProperty("user.home"), "output.tst");
+ f = File.createTempFile("FileOutputStreamTest", "tst");
fos = new FileOutputStream(f.getPath());
try {
@@ -373,29 +391,4 @@ public class FileOutputStreamTest extends TestCase {
assertEquals(0, fos.getChannel().position());
fos.close();
}
-
- protected void setUp() {
- bytes = new byte[10];
- for (int i = 0; i < bytes.length; i++) {
- bytes[i] = (byte) i;
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- @Override
- 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/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileReaderTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileReaderTest.java
index bbe20fa..7f7c02c 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileReaderTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileReaderTest.java
@@ -87,13 +87,8 @@ public class FileReaderTest extends TestCase {
* 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("user.home"), "reader.tst");
- if (f.exists()) {
- if (!f.delete()) {
- fail("Unable to delete test file");
- }
- }
+ protected void setUp() throws IOException {
+ f = File.createTempFile("FileReaderTest", "tst");
}
/**
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileTest.java
index eed9841..affe913 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileTest.java
@@ -17,9 +17,6 @@
package org.apache.harmony.tests.java.io;
-import junit.framework.TestCase;
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import tests.support.Support_PlatformFile;
import java.io.File;
import java.io.FileFilter;
import java.io.FileOutputStream;
@@ -32,7 +29,9 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import junit.framework.TestCase;
import libcore.io.Libcore;
+import org.apache.harmony.testframework.serialization.SerializationTest;
public class FileTest extends TestCase {
@@ -1873,9 +1872,7 @@ public class FileTest extends TestCase {
public void test_setLastModifiedJ() throws IOException {
File f1 = null;
try {
- f1 = new File(Support_PlatformFile.getNewPlatformFile(
- "harmony-test-FileTest_setLastModified", ".tmp"));
- f1.createNewFile();
+ f1 = File.createTempFile("harmony-test-FileTest_setLastModified", ".tmp");
long orgTime = f1.lastModified();
// Subtracting 100 000 milliseconds from the orgTime of File f1
f1.setLastModified(orgTime - 100000);
@@ -1930,7 +1927,7 @@ public class FileTest extends TestCase {
/**
* java.io.File#setReadOnly()
*/
- public void test_setReadOnly() throws IOException, InterruptedException {
+ public void test_setReadOnly() throws Exception {
File f1 = null;
File f2 = null;
if (Libcore.os.getuid() == 0) {
@@ -1954,23 +1951,16 @@ public class FileTest extends TestCase {
} catch (IOException e) {
// Expected
}
- Runtime r = Runtime.getRuntime();
- Process p;
- boolean onUnix = File.separatorChar == '/';
- if (onUnix) {
- p = r.exec("chmod +w " + f1.getAbsolutePath());
- } else {
- p = r.exec("attrib -r \"" + f1.getAbsolutePath() + "\"");
- }
- p.waitFor();
+
+ Libcore.os.chmod(f1.getAbsolutePath(), 666);
+
// Assert is flawed because canWrite does not work.
// assertTrue("File f1 Is Set To ReadOnly." , f1.canWrite());
FileOutputStream fos = new FileOutputStream(f1);
fos.write(fileString.getBytes());
fos.close();
- assertTrue("File Was Not Able To Be Written To.",
- f1.length() == fileString.length());
- assertTrue("File f1 Did Not Delete", f1.delete());
+ assertEquals(fileString.length(), f1.length());
+ assertTrue(f1.delete());
// Assert is flawed because canWrite does not work.
// assertTrue("File f2 Is Set To ReadOnly." , f2.canWrite());
@@ -1990,19 +1980,15 @@ public class FileTest extends TestCase {
} catch (IOException e) {
// Expected
}
- r = Runtime.getRuntime();
- if (onUnix) {
- p = r.exec("chmod +w " + f2.getAbsolutePath());
- } else {
- p = r.exec("attrib -r \"" + f2.getAbsolutePath() + "\"");
- }
- p.waitFor();
- assertTrue("File f2 Is Set To ReadOnly.", f2.canWrite());
+
+ Libcore.os.chmod(f2.getAbsolutePath(), 666);
+ assertTrue(f2.canWrite());
fos = new FileOutputStream(f2);
fos.write(fileString.getBytes());
fos.close();
f2.setReadOnly();
- assertTrue("File f2 Did Not Delete", f2.delete());
+ assertTrue(f2.delete());
+
// Similarly, trying to delete a read-only directory should succeed
f2 = new File(tempDirectory, "deltestdir");
f2.mkdir();
@@ -2166,12 +2152,7 @@ public class FileTest extends TestCase {
// Regression test for HARMONY-4493
public void test_list_withUnicodeFileName() throws Exception {
- File rootDir = new File("P");
- if (!rootDir.exists()) {
- rootDir.mkdir();
- rootDir.deleteOnExit();
- }
-
+ File rootDir = new File(System.getProperty("java.io.tmpdir")).getAbsoluteFile();
String dirName = new String("src\u3400");
File dir = new File(rootDir, dirName);
if (!dir.exists()) {
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileWriterTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileWriterTest.java
index f8f0d4f..a3640b0 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileWriterTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileWriterTest.java
@@ -29,18 +29,11 @@ import java.io.IOException;
import junit.framework.TestCase;
public class FileWriterTest extends TestCase {
-
- FileWriter fw;
-
- FileInputStream fis;
-
- BufferedWriter bw;
-
- File f;
-
- FileOutputStream fos;
-
- BufferedReader br;
+ private FileInputStream fis;
+ private BufferedWriter bw;
+ private File f;
+ private FileOutputStream fos;
+ private BufferedReader br;
/**
* java.io.FileWriter#FileWriter(java.io.File)
@@ -169,13 +162,8 @@ public class FileWriterTest extends TestCase {
* is called before a test is executed.
*/
@Override
- protected void setUp() {
- f = new File(System.getProperty("user.home"), "writer.tst");
- if (f.exists()) {
- if (!f.delete()) {
- fail("Unable to delete test file");
- }
- }
+ protected void setUp() throws Exception {
+ f = File.createTempFile("FileWriterTest", "tst");
}
/**
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FilterInputStreamTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FilterInputStreamTest.java
index 600b145..1e42770 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FilterInputStreamTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FilterInputStreamTest.java
@@ -18,12 +18,13 @@
package org.apache.harmony.tests.java.io;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
-
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import junit.framework.TestCase;
-import tests.support.Support_PlatformFile;
public class FilterInputStreamTest extends TestCase {
@@ -34,19 +35,95 @@ public class FilterInputStreamTest extends TestCase {
}
private String fileName;
-
private InputStream is;
+ private static final String INPUT =
+ "Test_All_Tests\n" +
+ "Test_BufferedInputStream\n" +
+ "Test_java_io_BufferedOutputStream\n" +
+ "Test_java_io_ByteArrayInputStream\n" +
+ "Test_java_io_ByteArrayOutputStream\n" +
+ "Test_java_io_DataInputStream\n" +
+ "Test_java_io_File\n" +
+ "Test_java_io_FileDescriptor\n" +
+ "Test_java_io_FileInputStream\n" +
+ "Test_java_io_FileNotFoundException\n" +
+ "Test_java_io_FileOutputStream\n" +
+ "Test_java_io_FilterInputStream\n" +
+ "Test_java_io_FilterOutputStream\n" +
+ "Test_java_io_InputStream\n" +
+ "Test_java_io_IOException\n" +
+ "Test_java_io_OutputStream\n" +
+ "Test_java_io_PrintStream\n" +
+ "Test_java_io_RandomAccessFile\n" +
+ "Test_java_io_SyncFailedException\n" +
+ "Test_java_lang_AbstractMethodError\n" +
+ "Test_java_lang_ArithmeticException\n" +
+ "Test_java_lang_ArrayIndexOutOfBoundsException\n" +
+ "Test_java_lang_ArrayStoreException\n" +
+ "Test_java_lang_Boolean\n" +
+ "Test_java_lang_Byte\n" +
+ "Test_java_lang_Character\n" +
+ "Test_All_Tests\n" +
+ "Test_BufferedInputStream\n" +
+ "Test_java_io_BufferedOutputStream\n" +
+ "Test_java_io_ByteArrayInputStream\n" +
+ "Test_java_io_ByteArrayOutputStream\n" +
+ "Test_java_io_DataInputStream\n" +
+ "Test_java_io_File\n" +
+ "Test_java_io_FileDescriptor\n" +
+ "Test_java_io_FileInputStream\n" +
+ "Test_java_io_FileNotFoundException\n" +
+ "Test_java_io_FileOutputStream\n" +
+ "Test_java_io_FilterInputStream\n" +
+ "Test_java_io_FilterOutputStream\n" +
+ "Test_java_io_InputStream\n" +
+ "Test_java_io_IOException\n" +
+ "Test_java_io_OutputStream\n" +
+ "Test_java_io_PrintStream\n" +
+ "Test_java_io_RandomAccessFile\n" +
+ "Test_java_io_SyncFailedException\n" +
+ "Test_java_lang_AbstractMethodError\n" +
+ "Test_java_lang_ArithmeticException\n" +
+ "Test_java_lang_ArrayIndexOutOfBoundsException\n" +
+ "Test_java_lang_ArrayStoreException\n" +
+ "Test_java_lang_Boolean\n" +
+ "Test_java_lang_Byte\n" +
+ "Test_java_lang_Character\n";
- byte[] ibuf = new byte[4096];
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ @Override
+ protected void setUp() throws IOException {
+ File temp = File.createTempFile("FilterInputStreamTest", "tst");
+ fileName = temp.getAbsolutePath();
+ OutputStream fos = new FileOutputStream(temp.getAbsolutePath());
+ fos.write(INPUT.getBytes(StandardCharsets.US_ASCII));
+ fos.close();
+ is = new MyFilterInputStream(new java.io.FileInputStream(fileName));
+ }
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_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";
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ @Override
+ protected void tearDown() {
+ try {
+ is.close();
+ } catch (Exception e) {
+ // Ignored
+ }
+ new File(fileName).delete();
+ }
/**
* java.io.FilterInputStream#available()
*/
public void test_available() throws IOException {
assertTrue("Returned incorrect number of available bytes", is
- .available() == fileString.length());
+ .available() == INPUT.length());
}
/**
@@ -82,7 +159,7 @@ public class FilterInputStreamTest extends TestCase {
*/
public void test_read() throws Exception {
int c = is.read();
- assertTrue("read returned incorrect char", c == fileString.charAt(0));
+ assertTrue("read returned incorrect char", c == INPUT.charAt(0));
}
/**
@@ -92,7 +169,7 @@ public class FilterInputStreamTest extends TestCase {
byte[] buf1 = new byte[100];
is.read(buf1);
assertTrue("Failed to read correct data", new String(buf1, 0,
- buf1.length, "UTF-8").equals(fileString.substring(0, 100)));
+ buf1.length, "UTF-8").equals(INPUT.substring(0, 100)));
}
/**
@@ -100,11 +177,11 @@ public class FilterInputStreamTest extends TestCase {
*/
public void test_read$BII() throws Exception {
byte[] buf1 = new byte[100];
- is.skip(3000);
+ is.skip(500);
is.mark(1000);
is.read(buf1, 0, buf1.length);
assertTrue("Failed to read correct data", new String(buf1, 0,
- buf1.length, "UTF-8").equals(fileString.substring(3000, 3100)));
+ buf1.length, "UTF-8").equals(INPUT.substring(500, 600)));
}
/**
@@ -127,41 +204,6 @@ public class FilterInputStreamTest extends TestCase {
is.skip(1000);
is.read(buf1, 0, buf1.length);
assertTrue("Failed to skip to correct position", new String(buf1, 0,
- buf1.length, "UTF-8").equals(fileString.substring(1000, 1010)));
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- @Override
- protected void setUp() throws IOException {
- fileName = System.getProperty("user.dir");
- String separator = System.getProperty("file.separator");
- if (fileName.charAt(fileName.length() - 1) == separator.charAt(0)) {
- fileName = Support_PlatformFile.getNewPlatformFile(fileName,
- "input.tst");
- } else {
- fileName = Support_PlatformFile.getNewPlatformFile(fileName
- + separator, "input.tst");
- }
- java.io.OutputStream fos = new java.io.FileOutputStream(fileName);
- fos.write(fileString.getBytes("UTF-8"));
- fos.close();
- is = new MyFilterInputStream(new java.io.FileInputStream(fileName));
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- @Override
- protected void tearDown() {
- try {
- is.close();
- } catch (Exception e) {
- // Ignored
- }
- new File(fileName).delete();
+ buf1.length, "UTF-8").equals(INPUT.substring(1000, 1010)));
}
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/SyncFailedExceptionTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/SyncFailedExceptionTest.java
index 409561a..d1772a3 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/SyncFailedExceptionTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/SyncFailedExceptionTest.java
@@ -31,8 +31,8 @@ public class SyncFailedExceptionTest extends junit.framework.TestCase {
// Test for method java.io.SyncFailedException(java.lang.String)
File f = null;
try {
- f = new File(System.getProperty("user.dir"), "synfail.tst");
- FileOutputStream fos = new FileOutputStream(f.getPath());
+ f = File.createTempFile("SyncFailedExceptionTest", "tst");
+ FileOutputStream fos = new FileOutputStream(f.getAbsolutePath());
FileDescriptor fd = fos.getFD();
fos.close();
fd.sync();
@@ -43,18 +43,4 @@ public class SyncFailedExceptionTest extends junit.framework.TestCase {
fail("Failed to generate expected Exception");
}
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/JarURLConnectionTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/JarURLConnectionTest.java
index 0b946c1..c938785 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/JarURLConnectionTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/JarURLConnectionTest.java
@@ -36,9 +36,7 @@ import java.util.zip.ZipFile;
public class JarURLConnectionTest extends junit.framework.TestCase {
- JarURLConnection juc;
-
- URLConnection uc;
+ private JarURLConnection juc;
private URL copyAndOpenResourceStream(String jarFile, String inFile)
throws MalformedURLException {
@@ -209,18 +207,16 @@ public class JarURLConnectionTest extends junit.framework.TestCase {
*/
public void test_getInputStream_DeleteJarFileUsingURLConnection()
throws Exception {
- String jarFileName = "file.jar";
- String entry = "text.txt";
- File file = new File(jarFileName);
- FileOutputStream jarFile = new FileOutputStream(jarFileName);
+ File file = File.createTempFile("JarUrlConnectionTest", "jar");
+ FileOutputStream jarFile = new FileOutputStream(file);
JarOutputStream out = new JarOutputStream(new BufferedOutputStream(
jarFile));
- JarEntry jarEntry = new JarEntry(entry);
+ JarEntry jarEntry = new JarEntry("entry.txt");
out.putNextEntry(jarEntry);
out.write(new byte[] { 'a', 'b', 'c' });
out.close();
- URL url = new URL("jar:file:" + jarFileName + "!/" + entry);
+ URL url = new URL("jar:file:" + file.getAbsolutePath() + "!/entry.txt");
URLConnection conn = url.openConnection();
conn.setUseCaches(false);
InputStream is = conn.getInputStream();
@@ -313,10 +309,4 @@ public class JarURLConnectionTest extends junit.framework.TestCase {
is.close();
}
}
-
- protected void setUp() {
- }
-
- protected void tearDown() {
- }
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/jar/JarFileTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/jar/JarFileTest.java
index a42d748..49e7868 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/jar/JarFileTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/jar/JarFileTest.java
@@ -17,11 +17,6 @@
package org.apache.harmony.tests.java.util.jar;
-import junit.framework.TestCase;
-
-import tests.support.Support_PlatformFile;
-import tests.support.resource.Support_Resources;
-
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -40,6 +35,8 @@ import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
+import junit.framework.TestCase;
+import tests.support.resource.Support_Resources;
public class JarFileTest extends TestCase {
@@ -476,9 +473,7 @@ public class JarFileTest extends TestCase {
ByteArrayOutputStream manOut = new ByteArrayOutputStream();
manifest.write(manOut);
byte[] manBytes = manOut.toByteArray();
- File file = File.createTempFile(
- Support_PlatformFile.getNewPlatformFile("hyts_manifest1",
- ""), ".jar");
+ File file = File.createTempFile("hyts_manifest1", ".jar");
JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(
file.getAbsolutePath()));
ZipEntry entry = new ZipEntry("META-INF/");
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/ZipFileTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/ZipFileTest.java
index 79f60d9..0c3a4d5 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/ZipFileTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/ZipFileTest.java
@@ -17,9 +17,6 @@
package org.apache.harmony.tests.java.util.zip;
-import tests.support.Support_PlatformFile;
-import tests.support.resource.Support_Resources;
-
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -33,6 +30,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import libcore.java.lang.ref.FinalizationTester;
+import tests.support.resource.Support_Resources;
public class ZipFileTest extends junit.framework.TestCase {
@@ -438,68 +436,26 @@ public class ZipFileTest extends junit.framework.TestCase {
is.close();
}
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
@Override
- protected void setUp() {
- try {
- // Create a local copy of the file since some tests want to alter
- // information.
- tempFileName = System.getProperty("java.io.tmpdir");
- String separator = System.getProperty("file.separator");
- if (tempFileName.charAt(tempFileName.length() - 1) == separator
- .charAt(0)) {
- tempFileName = Support_PlatformFile.getNewPlatformFile(
- tempFileName, "gabba.zip");
- } else {
- tempFileName = Support_PlatformFile.getNewPlatformFile(
- tempFileName + separator, "gabba.zip");
- }
-
- File f = new File(tempFileName);
- f.delete();
- InputStream is = Support_Resources.getStream("hyts_ZipFile.zip");
- FileOutputStream fos = new FileOutputStream(f);
- byte[] rbuf = getAllBytesFromStream(is);
- fos.write(rbuf, 0, rbuf.length);
- is.close();
- fos.close();
- zfile = new ZipFile(f);
- } catch (Exception e) {
- System.out.println("Exception during ZipFile setup:");
- e.printStackTrace();
- }
+ protected void setUp() throws IOException {
+ // Create a local copy of the file since some tests want to alter information.
+ File tempFile = File.createTempFile("OldZipFileTest", "zip");
+ tempFileName = tempFile.getAbsolutePath();
+ InputStream is = Support_Resources.getStream("hyts_ZipFile.zip");
+ FileOutputStream fos = new FileOutputStream(tempFile);
+ byte[] rbuf = getAllBytesFromStream(is);
+ fos.write(rbuf, 0, rbuf.length);
+ is.close();
+ fos.close();
+ zfile = new ZipFile(tempFile);
}
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
@Override
- protected void tearDown() {
- try {
- if (zfile != null) {
- // Note zfile is a user-defined zip file used by other tests and
- // should not be deleted
- zfile.close();
- tempFileName = System.getProperty("java.io.tmpdir");
- String separator = System.getProperty("file.separator");
- if (tempFileName.charAt(tempFileName.length() - 1) == separator
- .charAt(0)) {
- tempFileName = Support_PlatformFile.getNewPlatformFile(
- tempFileName, "gabba.zip");
- } else {
- tempFileName = Support_PlatformFile.getNewPlatformFile(
- tempFileName + separator, "gabba.zip");
- }
-
- File f = new File(tempFileName);
- f.delete();
- }
- } catch (Exception e) {
+ protected void tearDown() throws IOException {
+ // Note zfile is a user-defined zip file used by other tests and
+ // should not be deleted
+ if (zfile != null) {
+ zfile.close();
}
}
-
}