aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core.test/src/org/jacoco/core
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2020-02-11 11:33:25 +0100
committerGitHub <noreply@github.com>2020-02-11 12:33:25 +0200
commit23c2ca75261ee3d39a00b7080664ebd0e9b9f6c8 (patch)
tree143020bcf41554e146e1c3f991f18f7fe59ae5cb /org.jacoco.core.test/src/org/jacoco/core
parent71f9341e088bb3347ecfea2f114e5e40bdc4326b (diff)
downloadjacoco-23c2ca75261ee3d39a00b7080664ebd0e9b9f6c8.tar.gz
Preserve compression method when instrumenting zip entries (#1018)
Diffstat (limited to 'org.jacoco.core.test/src/org/jacoco/core')
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java27
1 files changed, 24 insertions, 3 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java b/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java
index e0bdf861..9a4a1c10 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java
@@ -26,6 +26,7 @@ import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Arrays;
+import java.util.zip.CRC32;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipEntry;
@@ -250,18 +251,38 @@ public class InstrumenterTest {
public void testInstrumentAll_Zip() throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ZipOutputStream zipout = new ZipOutputStream(buffer);
- zipout.putNextEntry(new ZipEntry("Test.class"));
+
+ // Compressed Entry
+ ZipEntry entry = new ZipEntry("TestCompressed.class");
+ entry.setMethod(ZipEntry.DEFLATED);
+ zipout.putNextEntry(entry);
+ zipout.write(TargetLoader.getClassDataAsBytes(getClass()));
+
+ // Uncompressed Entry
+ entry = new ZipEntry("TestUncompressed.class");
+ entry.setMethod(ZipEntry.STORED);
+ entry.setSize(TargetLoader.getClassDataAsBytes(getClass()).length);
+ CRC32 crc = new CRC32();
+ crc.update(TargetLoader.getClassDataAsBytes(getClass()));
+ entry.setCrc(crc.getValue());
+ zipout.putNextEntry(entry);
zipout.write(TargetLoader.getClassDataAsBytes(getClass()));
+
zipout.finish();
ByteArrayOutputStream out = new ByteArrayOutputStream();
int count = instrumenter.instrumentAll(
new ByteArrayInputStream(buffer.toByteArray()), out, "Test");
- assertEquals(1, count);
+ assertEquals(2, count);
ZipInputStream zipin = new ZipInputStream(
new ByteArrayInputStream(out.toByteArray()));
- assertEquals("Test.class", zipin.getNextEntry().getName());
+ entry = zipin.getNextEntry();
+ assertEquals("TestCompressed.class", entry.getName());
+ assertEquals(ZipEntry.DEFLATED, entry.getMethod());
+ entry = zipin.getNextEntry();
+ assertEquals("TestUncompressed.class", entry.getName());
+ assertEquals(ZipEntry.STORED, entry.getMethod());
assertNull(zipin.getNextEntry());
}