aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core.test
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2016-04-17 09:34:29 +0200
committerEvgeny Mandrikov <mandrikov@gmail.com>2016-04-17 10:20:59 +0200
commitdb8374395a39202642f564295c5370a043c852ef (patch)
tree01cf3edbeb7a42ab4d11438d41c1e93febabbf4b /org.jacoco.core.test
parentc36649b49f41dfaa6aff07f1da36e718e2416a30 (diff)
downloadjacoco-db8374395a39202642f564295c5370a043c852ef.tar.gz
GitHub #397: Improve EOF handling for exec files.
A EOFException should be reported for truncated exec files.
Diffstat (limited to 'org.jacoco.core.test')
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java21
1 files changed, 16 insertions, 5 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java b/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java
index d5db8ec0..cbf52902 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java
@@ -19,6 +19,7 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
@@ -87,17 +88,17 @@ public class ExecutionDataReaderWriterTest {
@Test
public void testCustomBlocks() throws IOException {
- buffer.write(-22);
- buffer.write(-33);
+ buffer.write(0x55);
+ buffer.write(0x66);
final ExecutionDataReader reader = new ExecutionDataReader(
new ByteArrayInputStream(buffer.toByteArray())) {
@Override
protected boolean readBlock(byte blocktype) throws IOException {
switch (blocktype) {
- case -22:
+ case 0x55:
return true;
- case -33:
+ case 0x66:
return false;
}
return super.readBlock(blocktype);
@@ -161,9 +162,19 @@ public class ExecutionDataReaderWriterTest {
createReader().read();
}
+ @Test(expected = EOFException.class)
+ public void testTruncatedFile() throws IOException {
+ writer.visitClassExecution(new ExecutionData(Long.MIN_VALUE, "Sample",
+ createData(8)));
+ final byte[] content = buffer.toByteArray();
+ buffer.reset();
+ buffer.write(content, 0, content.length - 1);
+ createReaderWithVisitors().read();
+ }
+
@Test
public void testEmptyFile() throws IOException {
- buffer = new ByteArrayOutputStream();
+ buffer.reset();
createReader().read();
}