Skip to content

Commit 88e729e

Browse files
committed
Test for incremental XXHash32.
1 parent bc82d82 commit 88e729e

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/test/java/org/apache/commons/codec/digest/XXHash32Test.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ public void verifyChecksum() throws IOException {
7676
Assert.assertEquals("checksum for " + file.getName(), expectedChecksum, Long.toHexString(h.getValue()));
7777
}
7878

79+
@Test
80+
public void verifyIncrementalChecksum() throws IOException {
81+
final XXHash32 h = new XXHash32();
82+
try (final FileInputStream s = new FileInputStream(file)) {
83+
final byte[] b = toByteArray(s);
84+
// Hit the case where the hash should be reset
85+
h.update(b[0]);
86+
h.reset();
87+
// Pass in chunks
88+
h.update(b[0]);
89+
h.update(b, 1, b.length - 2);
90+
h.update(b, b.length - 1, 1);
91+
// Check the hash ignores negative length
92+
h.update(b, 0, -1);
93+
}
94+
Assert.assertEquals("checksum for " + file.getName(), expectedChecksum, Long.toHexString(h.getValue()));
95+
}
96+
7997
private static byte[] toByteArray(final InputStream input) throws IOException {
8098
final ByteArrayOutputStream output = new ByteArrayOutputStream();
8199
copy(input, output, 10240);

0 commit comments

Comments
 (0)