commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [4/6] commons-compress git commit: Adding a batch of decompression tests.
Date Wed, 24 Feb 2016 14:54:05 GMT
Adding a batch of decompression 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/617860eb
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/617860eb
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/617860eb

Branch: refs/heads/master
Commit: 617860eb422480c46f74b3c1fa6b1087f491db38
Parents: ebeb53d
Author: Dawid Weiss <dawid.weiss@carrotsearch.com>
Authored: Tue Feb 23 15:52:15 2016 +0100
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Wed Feb 24 15:42:19 2016 +0100

----------------------------------------------------------------------
 .../archivers/sevenz/SevenZFileTest.java        |  63 +++++++++++++++++++
 src/test/resources/COMPRESS-320/BZip2-solid.7z  | Bin 0 -> 66992 bytes
 src/test/resources/COMPRESS-320/BZip2.7z        | Bin 0 -> 98148 bytes
 src/test/resources/COMPRESS-320/Copy-solid.7z   | Bin 0 -> 325679 bytes
 src/test/resources/COMPRESS-320/Copy.7z         | Bin 0 -> 325669 bytes
 .../resources/COMPRESS-320/Deflate-solid.7z     | Bin 0 -> 73730 bytes
 src/test/resources/COMPRESS-320/Deflate.7z      | Bin 0 -> 97803 bytes
 src/test/resources/COMPRESS-320/LZMA-solid.7z   | Bin 0 -> 64813 bytes
 src/test/resources/COMPRESS-320/LZMA.7z         | Bin 0 -> 95391 bytes
 src/test/resources/COMPRESS-320/LZMA2-solid.7z  | Bin 0 -> 64845 bytes
 src/test/resources/COMPRESS-320/LZMA2.7z        | Bin 0 -> 95705 bytes
 src/test/resources/COMPRESS-320/PPMd-solid.7z   | Bin 0 -> 61452 bytes
 src/test/resources/COMPRESS-320/PPMd.7z         | Bin 0 -> 86170 bytes
 src/test/resources/COMPRESS-320/recreate.sh     |   9 +++
 14 files changed, 72 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
index 196d040..ce17218 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
@@ -19,10 +19,16 @@ package org.apache.commons.compress.archivers.sevenz;
 
 import static org.junit.Assert.*;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.IOException;
 import java.security.NoSuchAlgorithmException;
 import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.crypto.Cipher;
+
 import org.apache.commons.compress.AbstractTestCase;
 import org.apache.commons.compress.PasswordRequiredException;
 import org.junit.Test;
@@ -31,6 +37,63 @@ public class SevenZFileTest extends AbstractTestCase {
     private static final String TEST2_CONTENT = "<?xml version = '1.0'?>\r\n<!DOCTYPE"
         + " connections>\r\n<meinxml>\r\n\t<leer />\r\n</meinxml>\n";
 
+    // https://issues.apache.org/jira/browse/COMPRESS-320
+    @Test
+    public void testRandomlySkippingEntries() throws Exception {
+    	// Read sequential reference.
+    	Map<String, byte[]> entriesByName = new HashMap<String, byte[]>();
+	    SevenZFile archive = new SevenZFile(getFile("COMPRESS-320/Copy.7z"));
+	    SevenZArchiveEntry entry;
+	    while ((entry = archive.getNextEntry()) != null) {
+	    	if (entry.hasStream()) {
+	    		entriesByName.put(entry.getName(), readFully(archive));
+	    	}
+	    }
+	    archive.close();
+
+		String[] variants = {
+			"BZip2-solid.7z", 
+			"BZip2.7z", 
+			"Copy-solid.7z", 
+			"Copy.7z", 
+			"Deflate-solid.7z", 
+			"Deflate.7z",
+			"LZMA-solid.7z", 
+			"LZMA.7z", 
+			"LZMA2-solid.7z", 
+			"LZMA2.7z", 
+			// TODO: unsupported compression method.
+			// "PPMd-solid.7z", 
+			// "PPMd.7z", 
+		};
+
+		for (String fileName : variants) {
+		    archive = new SevenZFile(getFile("COMPRESS-320/" + fileName));
+
+		    while ((entry = archive.getNextEntry()) != null) {
+				// TODO: randomly skip reading entries.
+
+				if (entry.hasStream()) {
+				    assertTrue(entriesByName.containsKey(entry.getName()));
+				    byte [] content = readFully(archive);
+				    assertTrue("Content mismatch on: " + fileName + "!" + entry.getName(), 
+				    		Arrays.equals(content, entriesByName.get(entry.getName())));
+				}
+		    }
+	
+		    archive.close();
+		}
+    }
+
+	private byte [] readFully(SevenZFile archive) throws IOException {
+	    byte [] buf = new byte [1024];
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		for (int len = 0; (len = archive.read(buf)) > 0;) {
+		    baos.write(buf, 0, len);
+		}
+		return baos.toByteArray();
+	}
+
     @Test
     public void testAllEmptyFilesArchive() throws Exception {
         SevenZFile archive = new SevenZFile(getFile("7z-empty-mhc-off.7z"));

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/BZip2-solid.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/BZip2-solid.7z b/src/test/resources/COMPRESS-320/BZip2-solid.7z
new file mode 100644
index 0000000..a1ff11b
Binary files /dev/null and b/src/test/resources/COMPRESS-320/BZip2-solid.7z differ

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/BZip2.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/BZip2.7z b/src/test/resources/COMPRESS-320/BZip2.7z
new file mode 100644
index 0000000..3272ecd
Binary files /dev/null and b/src/test/resources/COMPRESS-320/BZip2.7z differ

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/Copy-solid.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/Copy-solid.7z b/src/test/resources/COMPRESS-320/Copy-solid.7z
new file mode 100644
index 0000000..008564d
Binary files /dev/null and b/src/test/resources/COMPRESS-320/Copy-solid.7z differ

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/Copy.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/Copy.7z b/src/test/resources/COMPRESS-320/Copy.7z
new file mode 100644
index 0000000..958cd8f
Binary files /dev/null and b/src/test/resources/COMPRESS-320/Copy.7z differ

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/Deflate-solid.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/Deflate-solid.7z b/src/test/resources/COMPRESS-320/Deflate-solid.7z
new file mode 100644
index 0000000..00eb84d
Binary files /dev/null and b/src/test/resources/COMPRESS-320/Deflate-solid.7z differ

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/Deflate.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/Deflate.7z b/src/test/resources/COMPRESS-320/Deflate.7z
new file mode 100644
index 0000000..b5e3570
Binary files /dev/null and b/src/test/resources/COMPRESS-320/Deflate.7z differ

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/LZMA-solid.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/LZMA-solid.7z b/src/test/resources/COMPRESS-320/LZMA-solid.7z
new file mode 100644
index 0000000..5f55993
Binary files /dev/null and b/src/test/resources/COMPRESS-320/LZMA-solid.7z differ

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/LZMA.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/LZMA.7z b/src/test/resources/COMPRESS-320/LZMA.7z
new file mode 100644
index 0000000..3416d11
Binary files /dev/null and b/src/test/resources/COMPRESS-320/LZMA.7z differ

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/LZMA2-solid.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/LZMA2-solid.7z b/src/test/resources/COMPRESS-320/LZMA2-solid.7z
new file mode 100644
index 0000000..5a9f807
Binary files /dev/null and b/src/test/resources/COMPRESS-320/LZMA2-solid.7z differ

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/LZMA2.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/LZMA2.7z b/src/test/resources/COMPRESS-320/LZMA2.7z
new file mode 100644
index 0000000..c6c8347
Binary files /dev/null and b/src/test/resources/COMPRESS-320/LZMA2.7z differ

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/PPMd-solid.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/PPMd-solid.7z b/src/test/resources/COMPRESS-320/PPMd-solid.7z
new file mode 100644
index 0000000..5a3ee0a
Binary files /dev/null and b/src/test/resources/COMPRESS-320/PPMd-solid.7z differ

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/PPMd.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/PPMd.7z b/src/test/resources/COMPRESS-320/PPMd.7z
new file mode 100644
index 0000000..237396a
Binary files /dev/null and b/src/test/resources/COMPRESS-320/PPMd.7z differ

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/617860eb/src/test/resources/COMPRESS-320/recreate.sh
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-320/recreate.sh b/src/test/resources/COMPRESS-320/recreate.sh
new file mode 100644
index 0000000..09bd0dc
--- /dev/null
+++ b/src/test/resources/COMPRESS-320/recreate.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+rm *.7z
+for COMPRESSION in "LZMA" "LZMA2" "PPMd" "BZip2" "Deflate" "Copy"; do
+  # New solid block every 10 files.
+  7za a -m0=$COMPRESSION -ms10f  $COMPRESSION-solid.7z ../../../../src/main/java/org/apache/commons/compress/compressors
+  # Each file in isolation
+  7za a -m0=$COMPRESSION -ms=off $COMPRESSION.7z       ../../../../src/main/java/org/apache/commons/compress/compressors
+done


Mime
View raw message