View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.commons.compress.compressors.lz4;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  
23  import java.io.File;
24  import java.io.IOException;
25  import java.io.InputStream;
26  import java.nio.file.Files;
27  import java.util.stream.Stream;
28  
29  import org.apache.commons.compress.AbstractTest;
30  import org.apache.commons.io.IOUtils;
31  import org.junit.jupiter.params.ParameterizedTest;
32  import org.junit.jupiter.params.provider.Arguments;
33  import org.junit.jupiter.params.provider.MethodSource;
34  
35  public class XXHash32Test {
36  
37      public static Stream<Arguments> factory() {
38          return Stream.of(
39                  // reference checksums created with xxh32sum
40                  Arguments.of("bla.tar", "fbb5c8d1"), Arguments.of("bla.tar.xz", "4106a208"), Arguments.of("8.posix.tar.gz", "9fce116a"));
41      }
42  
43      @ParameterizedTest
44      @MethodSource("factory")
45      public void verifyChecksum(final String fileName, final String expectedChecksum) throws IOException {
46          final XXHash32 h = new XXHash32();
47          final File file = AbstractTest.getFile(fileName);
48          try (InputStream s = Files.newInputStream(file.toPath())) {
49              final byte[] b = IOUtils.toByteArray(s);
50              h.update(b, 0, b.length);
51          }
52          assertEquals(expectedChecksum, Long.toHexString(h.getValue()), "checksum for " + file.getName());
53      }
54  }