You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2018/01/05 16:54:47 UTC
[6/6] commons-compress git commit: COMPRESS-429 tests
COMPRESS-429 tests
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/0517c7f2
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/0517c7f2
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/0517c7f2
Branch: refs/heads/COMPRESS-429
Commit: 0517c7f2e4ea6806098453b295f230dd42a8f510
Parents: 8392343
Author: Stefan Bodewig <bo...@apache.org>
Authored: Fri Jan 5 17:54:15 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Fri Jan 5 17:54:15 2018 +0100
----------------------------------------------------------------------
.../zip/ZipArchiveInputStreamTest.java | 33 ++++++++++++++++++++
.../compress/archivers/zip/ZipFileTest.java | 25 +++++++++++++++
2 files changed, 58 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0517c7f2/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
index a0a5c50..4c654c0 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
@@ -272,6 +272,23 @@ public class ZipArchiveInputStreamTest {
}
}
+ @Test
+ public void nameSourceDefaultsToName() throws Exception {
+ nameSource("bla.zip", "test1.xml", ZipArchiveEntry.NameSource.NAME);
+ }
+
+ @Test
+ public void nameSourceIsSetToUnicodeExtraField() throws Exception {
+ nameSource("utf8-winzip-test.zip", "\u20AC_for_Dollar.txt",
+ ZipArchiveEntry.NameSource.UNICODE_EXTRA_FIELD);
+ }
+
+ @Test
+ public void nameSourceIsSetToEFS() throws Exception {
+ nameSource("utf8-7zip-test.zip", "\u20AC_for_Dollar.txt", 3,
+ ZipArchiveEntry.NameSource.NAME_WITH_EFS_FLAG);
+ }
+
private static byte[] readEntry(ZipArchiveInputStream zip, ZipArchiveEntry zae) throws IOException {
final int len = (int)zae.getSize();
final byte[] buff = new byte[len];
@@ -279,4 +296,20 @@ public class ZipArchiveInputStreamTest {
return buff;
}
+
+ private static void nameSource(String archive, String entry, ZipArchiveEntry.NameSource expected) throws Exception {
+ nameSource(archive, entry, 1, expected);
+ }
+
+ private static void nameSource(String archive, String entry, int entryNo, ZipArchiveEntry.NameSource expected)
+ throws Exception {
+ try (ZipArchiveInputStream zis = new ZipArchiveInputStream(new FileInputStream(getFile(archive)))) {
+ ZipArchiveEntry ze;
+ do {
+ ze = zis.getNextZipEntry();
+ } while (--entryNo > 0);
+ assertEquals(entry, ze.getName());
+ assertEquals(expected, ze.getNameSource());
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0517c7f2/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
index 87a3ded..a6170b1 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
@@ -581,6 +581,23 @@ public class ZipFileTest {
entry.setAlignment(3);
}
+ @Test
+ public void nameSourceDefaultsToName() throws Exception {
+ nameSource("bla.zip", "test1.xml", ZipArchiveEntry.NameSource.NAME);
+ }
+
+ @Test
+ public void nameSourceIsSetToUnicodeExtraField() throws Exception {
+ nameSource("utf8-winzip-test.zip", "\u20AC_for_Dollar.txt",
+ ZipArchiveEntry.NameSource.UNICODE_EXTRA_FIELD);
+ }
+
+ @Test
+ public void nameSourceIsSetToEFS() throws Exception {
+ nameSource("utf8-7zip-test.zip", "\u20AC_for_Dollar.txt",
+ ZipArchiveEntry.NameSource.NAME_WITH_EFS_FLAG);
+ }
+
private void assertAllReadMethods(byte[] expected, ZipFile zipFile, ZipArchiveEntry entry) {
// simple IOUtil read
try (InputStream stream = zf.getInputStream(entry)) {
@@ -673,4 +690,12 @@ public class ZipFileTest {
+ expectedName + ".java",
ze.getName());
}
+
+ private static void nameSource(String archive, String entry, ZipArchiveEntry.NameSource expected) throws Exception {
+ try (ZipFile zf = new ZipFile(getFile(archive))) {
+ ZipArchiveEntry ze = zf.getEntry(entry);
+ assertEquals(entry, ze.getName());
+ assertEquals(expected, ze.getNameSource());
+ }
+ }
}