diff options
author | Narayan Kamath <narayan@google.com> | 2014-02-19 14:25:08 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-02-19 14:25:08 +0000 |
commit | 5a95445260e22dcca730b582c881cc67b8de640e (patch) | |
tree | 1f40c36e0e83bdcfc92d455d087c05efbc916f38 /luni | |
parent | e68e325b5a7f73c6a6dc8bdfb92e76114e4f2b64 (diff) | |
parent | 2b7c83942a5e28c53698232182193d5118028e6c (diff) | |
download | libcore-5a95445260e22dcca730b582c881cc67b8de640e.zip libcore-5a95445260e22dcca730b582c881cc67b8de640e.tar.gz libcore-5a95445260e22dcca730b582c881cc67b8de640e.tar.bz2 |
Merge "Fix another set of file related tests."
Diffstat (limited to 'luni')
4 files changed, 20 insertions, 501 deletions
diff --git a/luni/src/test/java/libcore/java/io/OldBufferedInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldBufferedInputStreamTest.java deleted file mode 100644 index a3ef4e4..0000000 --- a/luni/src/test/java/libcore/java/io/OldBufferedInputStreamTest.java +++ /dev/null @@ -1,228 +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 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/libcore/java/io/OldFileInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldFileInputStreamTest.java deleted file mode 100644 index 894849a..0000000 --- a/luni/src/test/java/libcore/java/io/OldFileInputStreamTest.java +++ /dev/null @@ -1,209 +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 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/OldFilterInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldFilterInputStreamTest.java index 848b1bf..11c0279 100644 --- a/luni/src/test/java/libcore/java/io/OldFilterInputStreamTest.java +++ b/luni/src/test/java/libcore/java/io/OldFilterInputStreamTest.java @@ -18,11 +18,11 @@ package libcore.java.io; import java.io.BufferedInputStream; +import java.io.File; import java.io.FilterInputStream; import java.io.IOException; import java.util.Arrays; import tests.support.Support_ASimpleInputStream; -import tests.support.Support_PlatformFile; public class OldFilterInputStreamTest extends junit.framework.TestCase { @@ -36,13 +36,11 @@ public class OldFilterInputStreamTest extends junit.framework.TestCase { private FilterInputStream is; - byte[] ibuf = new byte[4096]; - - private static final String testString = "Lorem ipsum dolor sit amet,\n" + + private static final String INPUT = "Lorem ipsum dolor sit amet,\n" + "consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut" + "labore et dolore magna aliqua.\n"; - private static final int testLength = testString.length(); + private static final int INPUT_LENGTH = INPUT.length(); public void test_Constructor() { // The FilterInputStream object has already been created in setUp(). @@ -59,7 +57,7 @@ public class OldFilterInputStreamTest extends junit.framework.TestCase { public void test_available() throws IOException { assertEquals("Test 1: Returned incorrect number of available bytes;", - testLength, is.available()); + INPUT_LENGTH, is.available()); is.close(); try { @@ -144,7 +142,7 @@ public class OldFilterInputStreamTest extends junit.framework.TestCase { public void test_read() throws IOException { int c = is.read(); assertEquals("Test 1: Read returned incorrect char;", - testString.charAt(0), c); + INPUT.charAt(0), c); is.close(); try { @@ -161,7 +159,7 @@ public class OldFilterInputStreamTest extends junit.framework.TestCase { is.read(buf1); assertTrue("Test 1: Failed to read correct data.", new String(buf1, 0, buf1.length).equals( - testString.substring(0, 100))); + INPUT.substring(0, 100))); is.close(); try { @@ -281,7 +279,7 @@ public class OldFilterInputStreamTest extends junit.framework.TestCase { is.read(buf1, 0, buf1.length); assertTrue("Test 1: Failed to skip to the correct position.", new String(buf1, 0, buf1.length).equals( - testString.substring(10, 20))); + INPUT.substring(10, 20))); is.close(); try { @@ -292,32 +290,19 @@ public class OldFilterInputStreamTest extends junit.framework.TestCase { } } - 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 java.io.FileOutputStream(fileName); - fos.write(testString.getBytes()); - fos.close(); - is = new MyFilterInputStream(new java.io.FileInputStream(fileName)); - } catch (java.io.IOException e) { - System.out.println("Exception during setup"); - e.printStackTrace(); - } + protected void setUp() throws Exception { + File f = File.createTempFile("OldFilterInputStreamTest", "tst"); + fileName = f.getAbsolutePath(); + java.io.OutputStream fos = new java.io.FileOutputStream(fileName); + fos.write(INPUT.getBytes()); + fos.close(); + is = new MyFilterInputStream(new java.io.FileInputStream(fileName)); } protected void tearDown() { try { is.close(); - } catch (Exception e) { - System.out.println("Unexpected exception in tearDown()."); + } catch (Exception ignored) { } - new java.io.File(fileName).delete(); } } diff --git a/luni/src/test/java/libcore/java/util/zip/OldZipFileTest.java b/luni/src/test/java/libcore/java/util/zip/OldZipFileTest.java index 9f2864b..2104655 100644 --- a/luni/src/test/java/libcore/java/util/zip/OldZipFileTest.java +++ b/luni/src/test/java/libcore/java/util/zip/OldZipFileTest.java @@ -17,21 +17,14 @@ package libcore.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; -import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; -import java.security.Permission; -import java.util.Enumeration; import java.util.zip.ZipEntry; -import java.util.zip.ZipException; import java.util.zip.ZipFile; +import tests.support.resource.Support_Resources; public class OldZipFileTest extends junit.framework.TestCase { @@ -150,24 +143,15 @@ public class OldZipFileTest extends junit.framework.TestCase { @Override protected void setUp() throws IOException { // 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(); + File tempFile = File.createTempFile("OldZipFileTest", "zip"); + tempFileName = tempFile.getAbsolutePath(); InputStream is = Support_Resources.getStream("hyts_ZipFile.zip"); - FileOutputStream fos = new FileOutputStream(f); + FileOutputStream fos = new FileOutputStream(tempFile); byte[] rbuf = getAllBytesFromStream(is); fos.write(rbuf, 0, rbuf.length); is.close(); fos.close(); - zfile = new ZipFile(f); + zfile = new ZipFile(tempFile); } /** @@ -179,18 +163,5 @@ public class OldZipFileTest extends junit.framework.TestCase { // 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(); } } |