summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-05-14 13:01:07 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-05-14 13:01:08 +0000
commit0284e2e886667de13f70ac971dee18f4b3bde887 (patch)
tree500a318063370005d827292f5d62c7f1936bd511
parent6af7a264e5bfb24ff9d0681c0a5b09cae741672c (diff)
parent96905cbea69f50b8bab0e3d6e9d25fcae151bdb4 (diff)
downloadlibcore-0284e2e886667de13f70ac971dee18f4b3bde887.zip
libcore-0284e2e886667de13f70ac971dee18f4b3bde887.tar.gz
libcore-0284e2e886667de13f70ac971dee18f4b3bde887.tar.bz2
Merge "Fix remaining file related CTS Test failures." into klp-modular-dev
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileOutputStreamTest.java14
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileTest.java6
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/CheckedInputStreamTest.java21
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/CheckedOutputStreamTest.java27
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/DeflaterOutputStreamTest.java22
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/GZIPOutputStreamTest.java37
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/ZipEntryTest.java111
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/ZipFileTest.java56
-rw-r--r--luni/src/test/java/libcore/java/io/FileTest.java6
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/io/ObjectInputStreamTest.java3
10 files changed, 90 insertions, 213 deletions
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 8c5e91f..6263cc5 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
@@ -91,8 +91,9 @@ public class FileOutputStreamTest extends TestCase {
String fileName = f.getAbsolutePath();
fos = new FileOutputStream(fileName);
- // Regression test for HARMONY-4012
- new FileOutputStream("nul");
+ // Harmony 4012.
+ fos = new FileOutputStream("/dev/null");
+ fos.close();
}
/**
@@ -196,14 +197,13 @@ public class FileOutputStreamTest extends TestCase {
.length()).equals(fileString));
// Regression test for HARMONY-285
- File file = new File("FileOutputStream.tmp");
- file.deleteOnExit();
+ File file = File.createTempFile("FileOutputStreamTest", ".tmp");
FileOutputStream out = new FileOutputStream(file);
try {
out.write(null, 0, 0);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
+ fail();
+ } catch (NullPointerException expected) {
+
} finally {
out.close();
file.delete();
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 affe913..ea7b2ea 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
@@ -2009,7 +2009,11 @@ public class FileTest extends TestCase {
* java.io.File#toString()
*/
public void test_toString() {
- String fileName = System.getProperty("user.home") + File.separator + "input.tst";
+ String fileName = System.getProperty("user.home");
+ if (!fileName.endsWith(File.separator)) {
+ fileName += File.separator;
+ }
+ fileName += "input.tst";
File f = new File(fileName);
assertEquals("Incorrect string returned", fileName, f.toString());
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/CheckedInputStreamTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/CheckedInputStreamTest.java
index 1c8cc93..903f60b 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/CheckedInputStreamTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/CheckedInputStreamTest.java
@@ -18,28 +18,15 @@ package org.apache.harmony.tests.java.util.zip;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
-
import junit.framework.TestCase;
import tests.support.resource.Support_Resources;
public class CheckedInputStreamTest extends TestCase {
- @Override
- protected void tearDown() {
- try {
- File deletedFile = new File("empty.txt");
- deletedFile.delete();
- } catch (SecurityException e) {
- fail("Cannot delete file for security reasons");
- }
-
- }
-
/**
* java.util.zip.CheckedInputStream#CheckedInputStream(java.io.InputStream,
*java.util.zip.Checksum)
@@ -57,10 +44,8 @@ public class CheckedInputStreamTest extends TestCase {
*/
public void test_getChecksum() throws Exception {
byte outBuf[] = new byte[100];
- // testing getChecksum for an empty file
- FileOutputStream outEmp = new FileOutputStream("empty.txt");
- outEmp.close();
- InputStream inEmp = new FileInputStream("empty.txt");
+ File f = File.createTempFile("CheckedInputStreamTest", ".txt");
+ InputStream inEmp = new FileInputStream(f);
CheckedInputStream checkEmpty = new CheckedInputStream(inEmp, new CRC32());
while (checkEmpty.read() >= 0) {
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/CheckedOutputStreamTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/CheckedOutputStreamTest.java
index e354872..09d5756 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/CheckedOutputStreamTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/CheckedOutputStreamTest.java
@@ -32,7 +32,8 @@ public class CheckedOutputStreamTest extends junit.framework.TestCase {
public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Checksum() {
// test method java.util.zip.checkedOutputStream.constructor
try {
- FileOutputStream outFile = new FileOutputStream("chkOut.txt");
+ FileOutputStream outFile = new FileOutputStream(
+ File.createTempFile("CheckedOutputStreamTest", ".txt"));
CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
new CRC32());
assertEquals("the checkSum value of the constructor is not 0", 0, chkOut
@@ -53,7 +54,8 @@ public class CheckedOutputStreamTest extends junit.framework.TestCase {
// test method java.util.zip.checkedOutputStream.getChecksum()
byte byteArray[] = { 1, 2, 3, 'e', 'r', 't', 'g', 3, 6 };
try {
- FileOutputStream outFile = new FileOutputStream("chkOut.txt");
+ FileOutputStream outFile = new FileOutputStream(
+ File.createTempFile("CheckedOutputStreamTest", ".txt"));
CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
new Adler32());
chkOut.write(byteArray[4]);
@@ -85,7 +87,8 @@ public class CheckedOutputStreamTest extends junit.framework.TestCase {
// test method java.util.zip.checkedOutputStream.writeI()
byte byteArray[] = { 1, 2, 3, 'e', 'r', 't', 'g', 3, 6 };
try {
- FileOutputStream outFile = new FileOutputStream("chkOut.txt");
+ FileOutputStream outFile = new FileOutputStream(
+ File.createTempFile("CheckedOutputStreamTest", ".txt"));
CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
new CRC32());
for (byte element : byteArray) {
@@ -109,7 +112,8 @@ public class CheckedOutputStreamTest extends junit.framework.TestCase {
// test method java.util.zip.checkOutputStream.writeBII()
byte byteArray[] = { 1, 2, 3, 'e', 'r', 't', 'g', 3, 6 };
try {
- FileOutputStream outFile = new FileOutputStream("chkOut.txt");
+ FileOutputStream outFile = new FileOutputStream(
+ File.createTempFile("CheckedOutputStreamTest", ".txt"));
CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
new CRC32());
chkOut.write(byteArray, 4, 5);
@@ -133,19 +137,4 @@ public class CheckedOutputStreamTest extends junit.framework.TestCase {
fail("Index for write is out of bounds");
}
}
-
- @Override
- protected void setUp() {
- }
-
- @Override
- protected void tearDown() {
- try {
- File deletedFile = new File("chkOut.txt");
- deletedFile.delete();
- } catch (SecurityException e) {
- fail("Cannot delete file for security reasons");
- }
- }
-
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/DeflaterOutputStreamTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/DeflaterOutputStreamTest.java
index 185f7b2..e4be198 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/DeflaterOutputStreamTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/DeflaterOutputStreamTest.java
@@ -60,7 +60,7 @@ public class DeflaterOutputStreamTest extends TestCase {
}
}
- private byte outPutBuf[] = new byte[500];
+ private final byte outputBuf[] = new byte[500];
@Override
protected void setUp() {
@@ -70,11 +70,11 @@ public class DeflaterOutputStreamTest extends TestCase {
Deflater deflate = new Deflater(1);
deflate.setInput(byteArray);
while (!(deflate.needsInput())) {
- x += deflate.deflate(outPutBuf, x, outPutBuf.length - x);
+ x += deflate.deflate(outputBuf, x, outputBuf.length - x);
}
deflate.finish();
while (!(deflate.finished())) {
- x = x + deflate.deflate(outPutBuf, x, outPutBuf.length - x);
+ x = x + deflate.deflate(outputBuf, x, outputBuf.length - x);
}
deflate.end();
}
@@ -85,7 +85,7 @@ public class DeflaterOutputStreamTest extends TestCase {
*/
public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Deflater() throws Exception {
byte byteArray[] = { 1, 3, 4, 7, 8 };
- File f1 = new File("hyts_ConstruOD.tst");
+ File f1 = File.createTempFile("hyts_ConstruOD", ".tst");
FileOutputStream fos = new FileOutputStream(f1);
Deflater defl = null;
MyDeflaterOutputStream dos;
@@ -111,7 +111,7 @@ public class DeflaterOutputStreamTest extends TestCase {
* java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream)
*/
public void test_ConstructorLjava_io_OutputStream() throws Exception {
- File f1 = new File("hyts_ConstruO.tst");
+ File f1 = File.createTempFile("hyts_ConstruO", ".tst");
FileOutputStream fos = new FileOutputStream(f1);
MyDeflaterOutputStream dos = new MyDeflaterOutputStream(fos);
@@ -119,7 +119,7 @@ public class DeflaterOutputStreamTest extends TestCase {
// buffer.
assertEquals("Incorrect Buffer Size", 512, dos.getProtectedBuf().length);
- dos.write(outPutBuf);
+ dos.write(outputBuf);
dos.close();
f1.delete();
}
@@ -134,7 +134,7 @@ public class DeflaterOutputStreamTest extends TestCase {
int negBuf = -5;
int zeroBuf = 0;
byte byteArray[] = { 1, 3, 4, 7, 8, 3, 6 };
- File f1 = new File("hyts_ConstruODI.tst");
+ File f1 = File.createTempFile("hyts_ConstruODI", ".tst");
FileOutputStream fos = new FileOutputStream(f1);
Deflater defl = null;
MyDeflaterOutputStream dos;
@@ -237,7 +237,7 @@ public class DeflaterOutputStreamTest extends TestCase {
// Need test to see if method finish() actually finishes
// Only testing possible errors, not if it actually works
- File f1 = new File("finish.tst");
+ File f1 = File.createTempFile("finish", ".tst");
FileOutputStream fos1 = new FileOutputStream(f1);
DeflaterOutputStream dos = new DeflaterOutputStream(fos1);
byte byteArray[] = { 1, 3, 4, 6 };
@@ -285,7 +285,7 @@ public class DeflaterOutputStreamTest extends TestCase {
* java.util.zip.DeflaterOutputStream#write(int)
*/
public void test_writeI() throws Exception {
- File f1 = new File("writeI1.tst");
+ File f1 = File.createTempFile("writeIL", ".tst");
FileOutputStream fos = new FileOutputStream(f1);
DeflaterOutputStream dos = new DeflaterOutputStream(fos);
for (int i = 0; i < 3; i++) {
@@ -324,7 +324,7 @@ public class DeflaterOutputStreamTest extends TestCase {
byte byteArray[] = { 1, 3, 4, 7, 8, 3, 6 };
// Test to see if the correct bytes are saved.
- File f1 = new File("writeBII.tst");
+ File f1 = File.createTempFile("writeBII", ".tst");
FileOutputStream fos1 = new FileOutputStream(f1);
DeflaterOutputStream dos1 = new DeflaterOutputStream(fos1);
dos1.write(byteArray, 2, 3);
@@ -340,7 +340,7 @@ public class DeflaterOutputStreamTest extends TestCase {
f1.delete();
// Test for trying to write more bytes than available from the array
- File f2 = new File("writeBII2.tst");
+ File f2 = File.createTempFile("writeBII2", ".tst");
FileOutputStream fos2 = new FileOutputStream(f2);
DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
try {
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/GZIPOutputStreamTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/GZIPOutputStreamTest.java
index de54d5a..30a94f0 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/GZIPOutputStreamTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/GZIPOutputStreamTest.java
@@ -47,7 +47,8 @@ public class GZIPOutputStreamTest extends junit.framework.TestCase {
*/
public void test_ConstructorLjava_io_OutputStream() {
try {
- FileOutputStream outFile = new FileOutputStream("GZIPOutCon.txt");
+ FileOutputStream outFile = new FileOutputStream(
+ File.createTempFile("GZIPCon", ".txt"));
TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile);
assertNotNull("the constructor for GZIPOutputStream is null",
outGZIP);
@@ -66,7 +67,8 @@ public class GZIPOutputStreamTest extends junit.framework.TestCase {
*/
public void test_ConstructorLjava_io_OutputStreamI() {
try {
- FileOutputStream outFile = new FileOutputStream("GZIPOutCon.txt");
+ FileOutputStream outFile = new FileOutputStream(
+ File.createTempFile("GZIPOutCon", ".txt"));
TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile,
100);
assertNotNull("the constructor for GZIPOutputStream is null",
@@ -87,7 +89,8 @@ public class GZIPOutputStreamTest extends junit.framework.TestCase {
// test method java.util.zip.GZIPOutputStream.finish()
byte byteArray[] = { 3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
try {
- FileOutputStream outFile = new FileOutputStream("GZIPOutFinish.txt");
+ FileOutputStream outFile = new FileOutputStream(
+ File.createTempFile("GZIPOutFinish", ".txt"));
TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile);
outGZIP.finish();
@@ -114,7 +117,8 @@ public class GZIPOutputStreamTest extends junit.framework.TestCase {
// test method java.util.zip.GZIPOutputStream.close()
byte byteArray[] = { 3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
try {
- FileOutputStream outFile = new FileOutputStream("GZIPOutClose2.txt");
+ FileOutputStream outFile = new FileOutputStream(
+ File.createTempFile("GZIPOutClose2", ".txt"));
TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile);
outGZIP.close();
int r = 0;
@@ -138,7 +142,8 @@ public class GZIPOutputStreamTest extends junit.framework.TestCase {
// test method java.util.zip.GZIPOutputStream.writeBII
byte byteArray[] = { 3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
try {
- FileOutputStream outFile = new FileOutputStream("GZIPOutWrite.txt");
+ FileOutputStream outFile = new FileOutputStream(
+ File.createTempFile("GZIPOutWrite", ".txt"));
TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile);
outGZIP.write(byteArray, 0, 10);
// ran JDK and found this CRC32 value is 3097700292
@@ -179,26 +184,4 @@ public class GZIPOutputStreamTest extends junit.framework.TestCase {
assertEquals(2, in.read());
assertEquals(3, in.read());
}
-
- @Override
- protected void setUp() {
- }
-
- @Override
- protected void tearDown() {
-
- try {
- File dFile = new File("GZIPOutCon.txt");
- dFile.delete();
- File dFile2 = new File("GZIPOutFinish.txt");
- dFile2.delete();
- File dFile3 = new File("GZIPOutWrite.txt");
- dFile3.delete();
- File dFile4 = new File("GZIPOutClose2.txt");
- dFile4.delete();
- } catch (SecurityException e) {
- fail("Cannot delete file for security reasons");
- }
- }
-
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/ZipEntryTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/ZipEntryTest.java
index 3b3d7d5..f034639 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/ZipEntryTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/ZipEntryTest.java
@@ -16,48 +16,25 @@
*/
package org.apache.harmony.tests.java.util.zip;
-import java.util.TimeZone;
-import java.util.zip.ZipEntry;
-import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-
+import java.util.TimeZone;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import libcore.io.Streams;
import tests.support.resource.Support_Resources;
public class ZipEntryTest extends junit.framework.TestCase {
-
- public byte[] getAllBytesFromStream(InputStream is) throws IOException {
- ByteArrayOutputStream bs = new ByteArrayOutputStream();
- byte[] buf = new byte[512];
- int iRead;
- int off;
- while (is.available() > 0) {
- iRead = is.read(buf, 0, buf.length);
- if (iRead > 0) bs.write(buf, 0, iRead);
- }
- return bs.toByteArray();
- }
-
// zip file hyts_ZipFile.zip must be included as a resource
- java.util.zip.ZipEntry zentry;
-
- java.util.zip.ZipFile zfile;
-
- private static final String platformId = System.getProperty(
- "com.ibm.oti.configuration", "JDK")
- + System.getProperty("java.vm.version");
-
- static final String tempFileName = platformId + "zfzezi.zip";
-
- long orgSize;
-
- long orgCompressedSize;
+ private ZipEntry zentry;
+ private ZipFile zfile;
- long orgCrc;
-
- long orgTime;
-
- String orgComment;
+ private long orgSize;
+ private long orgCompressedSize;
+ private long orgCrc;
+ private long orgTime;
/**
* java.util.zip.ZipEntry#ZipEntry(java.lang.String)
@@ -442,47 +419,26 @@ public class ZipEntryTest extends junit.framework.TestCase {
assertEquals(extraB.length, zeOutput.getExtra().length);
}
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
-
@Override
- protected void setUp() {
- java.io.File f = null;
- try {
- // Create a local copy of the file since some tests want to alter
- // information.
- f = new java.io.File(tempFileName);
- // Create absolute filename as ZipFile does not resolve using
- // user.dir
- f = new java.io.File(f.getAbsolutePath());
- f.delete();
- java.io.InputStream is = Support_Resources
- .getStream("hyts_ZipFile.zip");
- java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
- byte[] rbuf = getAllBytesFromStream(is);
- fos.write(rbuf, 0, rbuf.length);
- is.close();
- fos.close();
- zfile = new java.util.zip.ZipFile(f);
- zentry = zfile.getEntry("File1.txt");
- orgSize = zentry.getSize();
- orgCompressedSize = zentry.getCompressedSize();
- orgCrc = zentry.getCrc();
- orgTime = zentry.getTime();
- orgComment = zentry.getComment();
- } catch (Exception e) {
- System.out.println("Exception during ZipFile setup <"
- + f.getAbsolutePath() + ">: ");
- e.printStackTrace();
- }
- }
+ protected void setUp() throws Exception {
+ // Create a local copy of the file since some tests want to alter
+ // information.
+ final File f = File.createTempFile("ZipEntryTest", ".zip");
+ InputStream is = Support_Resources.getStream("hyts_ZipFile.zip");
+
+ FileOutputStream fos = new java.io.FileOutputStream(f);
+ Streams.copy(is, fos);
+ is.close();
+ fos.close();
+
+ zfile = new ZipFile(f);
+ zentry = zfile.getEntry("File1.txt");
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
+ orgSize = zentry.getSize();
+ orgCompressedSize = zentry.getCompressedSize();
+ orgCrc = zentry.getCrc();
+ orgTime = zentry.getTime();
+ }
@Override
protected void tearDown() {
@@ -490,11 +446,8 @@ public class ZipEntryTest extends junit.framework.TestCase {
if (zfile != null) {
zfile.close();
}
- java.io.File f = new java.io.File(tempFileName);
- f.delete();
- } catch (java.io.IOException e) {
- System.out.println("Exception during tearDown");
+ } catch (IOException ignored) {
}
}
-
}
+
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 0c3a4d5..5b96633 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,75 +17,37 @@
package org.apache.harmony.tests.java.util.zip;
-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 libcore.io.Streams;
import libcore.java.lang.ref.FinalizationTester;
import tests.support.resource.Support_Resources;
public class ZipFileTest extends junit.framework.TestCase {
- public byte[] getAllBytesFromStream(InputStream is) throws IOException {
- ByteArrayOutputStream bs = new ByteArrayOutputStream();
- byte[] buf = new byte[512];
- int iRead;
- int off;
- while (is.available() > 0) {
- iRead = is.read(buf, 0, buf.length);
- if (iRead > 0) bs.write(buf, 0, iRead);
- }
- return bs.toByteArray();
- }
-
// the file hyts_zipFile.zip in setup must be included as a resource
private String tempFileName;
-
private ZipFile zfile;
- // custom security manager
- SecurityManager sm = new SecurityManager() {
- final String forbidenPermissionAction = "read";
-
-
-
- public void checkPermission(Permission perm) {
- // only check if it's a FilePermission because Locale checks
- // for a PropertyPermission with action"read" to get system props.
- if (perm instanceof FilePermission
- && perm.getActions().equals(forbidenPermissionAction)) {
- throw new SecurityException();
- }
- }
- };
-
- /**
- * java.util.zip.ZipFile#ZipFile(java.io.File)
- */
- public void test_ConstructorLjava_io_File() {
- // Test for method java.util.zip.ZipFile(java.io.File)
- assertTrue("Used to test", true);
- }
-
/**
* java.util.zip.ZipFile#ZipFile(java.io.File, int)
*/
public void test_ConstructorLjava_io_FileI() throws IOException {
zfile.close(); // about to reopen the same temp file
+
File file = new File(tempFileName);
ZipFile zip = new ZipFile(file, ZipFile.OPEN_DELETE | ZipFile.OPEN_READ);
zip.close();
assertTrue("Zip should not exist", !file.exists());
+
file = new File(tempFileName);
- file.delete();
try {
zip = new ZipFile(file, ZipFile.OPEN_READ);
fail("IOException expected");
@@ -106,14 +68,12 @@ public class ZipFileTest extends junit.framework.TestCase {
* java.util.zip.ZipFile#ZipFile(java.lang.String)
*/
public void test_ConstructorLjava_lang_String() throws IOException {
- System.setProperty("user.dir", System.getProperty("java.io.tmpdir"));
-
zfile.close(); // about to reopen the same temp file
ZipFile zip = new ZipFile(tempFileName);
zip.close();
File file = File.createTempFile("zip", "tmp");
try {
- zip = new ZipFile(file.getName());
+ zip = new ZipFile(file.getAbsolutePath());
fail("ZipException expected");
} catch (ZipException ee) {
// expected
@@ -441,10 +401,12 @@ public class ZipFileTest extends junit.framework.TestCase {
// 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);
+ Streams.copy(is, fos);
+
is.close();
fos.close();
zfile = new ZipFile(tempFile);
@@ -452,8 +414,6 @@ public class ZipFileTest extends junit.framework.TestCase {
@Override
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();
}
diff --git a/luni/src/test/java/libcore/java/io/FileTest.java b/luni/src/test/java/libcore/java/io/FileTest.java
index 4135ae4..b4101f9 100644
--- a/luni/src/test/java/libcore/java/io/FileTest.java
+++ b/luni/src/test/java/libcore/java/io/FileTest.java
@@ -217,8 +217,12 @@ public class FileTest extends junit.framework.TestCase {
public void test_getAbsolutePath() throws Exception {
String userDir = System.getProperty("user.dir");
+ if (!userDir.endsWith(File.separator)) {
+ userDir = userDir + File.separator;
+ }
+
File f = new File("poop");
- assertEquals(userDir + File.separator + "poop", f.getAbsolutePath());
+ assertEquals(userDir + "poop", f.getAbsolutePath());
}
public void test_getSpace() throws Exception {
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ObjectInputStreamTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ObjectInputStreamTest.java
index 5b89172..d1f92ec 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ObjectInputStreamTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ObjectInputStreamTest.java
@@ -1001,8 +1001,7 @@ public class ObjectInputStreamTest extends TestCase implements
// Regression Test for JIRA 2192
public void test_readObject_withPrimitiveClass() throws Exception {
- File file = new File("test.ser");
- file.deleteOnExit();
+ File file = File.createTempFile("ObjectInputStreamTest", ".ser");
Test test = new Test();
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
file));