You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/12/30 22:17:30 UTC

[commons-codec] 03/05: Test for incremental XXHash32.

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git

commit 88e729ecddb4869b61c19f06623d19d347c4e42b
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Dec 30 21:51:25 2019 +0000

    Test for incremental XXHash32.
---
 .../org/apache/commons/codec/digest/XXHash32Test.java  | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/test/java/org/apache/commons/codec/digest/XXHash32Test.java b/src/test/java/org/apache/commons/codec/digest/XXHash32Test.java
index acae79b..07c5ce7 100644
--- a/src/test/java/org/apache/commons/codec/digest/XXHash32Test.java
+++ b/src/test/java/org/apache/commons/codec/digest/XXHash32Test.java
@@ -76,6 +76,24 @@ public class XXHash32Test {
         Assert.assertEquals("checksum for " + file.getName(), expectedChecksum, Long.toHexString(h.getValue()));
     }
 
+    @Test
+    public void verifyIncrementalChecksum() throws IOException {
+        final XXHash32 h = new XXHash32();
+        try (final FileInputStream s = new FileInputStream(file)) {
+            final byte[] b = toByteArray(s);
+            // Hit the case where the hash should be reset
+            h.update(b[0]);
+            h.reset();
+            // Pass in chunks
+            h.update(b[0]);
+            h.update(b, 1, b.length - 2);
+            h.update(b, b.length - 1, 1);
+            // Check the hash ignores negative length
+            h.update(b, 0, -1);
+        }
+        Assert.assertEquals("checksum for " + file.getName(), expectedChecksum, Long.toHexString(h.getValue()));
+    }
+
     private static byte[] toByteArray(final InputStream input) throws IOException {
         final ByteArrayOutputStream output = new ByteArrayOutputStream();
         copy(input, output, 10240);