Skip to content

Commit 86fb8a1

Browse files
author
Ioana Leontiuc
authored
Missing Test Case for negative offset value
The method copyLarge(InputStream input, InputStream output, int offset, buffer) copies the content of input into output. If offset is a positive number, it will skip a number of bytes from input equal to offset value. By performing mutation testing analysis we noticed that the copyLarge method was never tested for a negative value for offset. The added test call copyLarge with a negative value and check that the behavior is the same as for offset = 0, where no bytes are skipped from input.
1 parent 9990c66 commit 86fb8a1

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/test/java/org/apache/commons/io/IOUtilsTestCase.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,4 +1493,32 @@ public void close() throws IOException { }
14931493
assertSame(bw, IOUtils.buffer(bw));
14941494
assertSame(bw, IOUtils.buffer(bw, 1024));
14951495
}
1496+
1497+
1498+
@Test
1499+
public void testCopyLarge_SkipWithInvalidOffset() throws IOException {
1500+
ByteArrayInputStream is = null;
1501+
ByteArrayOutputStream os = null;
1502+
try {
1503+
// Create streams
1504+
is = new ByteArrayInputStream(iarr);
1505+
os = new ByteArrayOutputStream();
1506+
1507+
// Test our copy method
1508+
assertEquals(100, IOUtils.copyLarge(is, os, -10, 100));
1509+
final byte[] oarr = os.toByteArray();
1510+
1511+
// check that output length is correct
1512+
assertEquals(100, oarr.length);
1513+
// check that output data corresponds to input data
1514+
assertEquals(1, oarr[1]);
1515+
assertEquals(79, oarr[79]);
1516+
assertEquals(-1, oarr[80]);
1517+
1518+
} finally {
1519+
IOUtils.closeQuietly(is);
1520+
IOUtils.closeQuietly(os);
1521+
}
1522+
}
1523+
14961524
}

0 commit comments

Comments
 (0)