aboutsummaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorEugene Kliuchnikov <eustas@google.com>2016-10-31 14:33:59 +0100
committerGitHub <noreply@github.com>2016-10-31 14:33:59 +0100
commite9b278ac6e097beb763e8a46eeafcaa3f6f63f18 (patch)
tree15438c3a37a4df3d9bf8e782053d1e42daf44374 /java
parenta260b6ba73e0b0eab6d7e7385dbaa476d36f30ab (diff)
downloadbrotli-e9b278ac6e097beb763e8a46eeafcaa3f6f63f18.zip
brotli-e9b278ac6e097beb763e8a46eeafcaa3f6f63f18.tar.gz
brotli-e9b278ac6e097beb763e8a46eeafcaa3f6f63f18.tar.bz2
Update docs and add more java tests (#463)
* doxygenize and update API documentation * fix spelling * add "fuzz" corpus for java decoder to improve coverage * use upper-case-snake names for dictionary constant definitions * use `LDFLAGS` in conventional `Makefile`
Diffstat (limited to 'java')
-rwxr-xr-xjava/integration/BUILD14
-rwxr-xr-xjava/integration/BundleChecker.java38
-rwxr-xr-xjava/integration/fuzz_data.zipbin0 -> 23854 bytes
-rwxr-xr-xjava/integration/pom.xml16
4 files changed, 58 insertions, 10 deletions
diff --git a/java/integration/BUILD b/java/integration/BUILD
index bb6f501..9171e9e 100755
--- a/java/integration/BUILD
+++ b/java/integration/BUILD
@@ -14,10 +14,22 @@ java_binary(
)
java_test(
- name = "bundle_checker_test",
+ name = "bundle_checker_data_test",
args = ["java/integration/test_data.zip"],
data = ["test_data.zip"],
main_class = "org.brotli.integration.BundleChecker",
use_testrunner = 0,
runtime_deps = [":bundle_checker_lib"],
)
+
+java_test(
+ name = "bundle_checker_fuzz_test",
+ args = [
+ "-s",
+ "java/integration/fuzz_data.zip"
+ ],
+ data = ["fuzz_data.zip"],
+ main_class = "org.brotli.integration.BundleChecker",
+ use_testrunner = 0,
+ runtime_deps = [":bundle_checker_lib"],
+)
diff --git a/java/integration/BundleChecker.java b/java/integration/BundleChecker.java
index 4b2aad8..316f03c 100755
--- a/java/integration/BundleChecker.java
+++ b/java/integration/BundleChecker.java
@@ -18,7 +18,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
- * Decompress files and checks thier checksums.
+ * Decompress files and (optionally) checks their checksums.
*
* <p> File are read from ZIP archive passed as an array of bytes. Multiple checkers negotiate about
* task distribution via shared AtomicInteger counter.
@@ -28,10 +28,15 @@ import java.util.zip.ZipInputStream;
public class BundleChecker implements Runnable {
final AtomicInteger nextJob;
final InputStream input;
+ final boolean sanityCheck;
- public BundleChecker(InputStream input, AtomicInteger nextJob) {
+ /**
+ * @param sanityCheck do not calculate checksum and ignore {@link IOException}.
+ */
+ public BundleChecker(InputStream input, AtomicInteger nextJob, boolean sanityCheck) {
this.input = input;
this.nextJob = nextJob;
+ this.sanityCheck = sanityCheck;
}
/** ECMA CRC64 polynomial. */
@@ -93,10 +98,17 @@ public class BundleChecker implements Runnable {
continue;
}
entryName = entry.getName();
- String entryCrcString = entryName.substring(0, entryName.indexOf('.'));
+ int dotIndex = entryName.indexOf('.');
+ String entryCrcString = (dotIndex == -1) ? entryName : entryName.substring(0, dotIndex);
long entryCrc = new BigInteger(entryCrcString, 16).longValue();
- if (entryCrc != decompressAndCalculateCrc(zis)) {
- throw new RuntimeException("CRC mismatch");
+ try {
+ if (entryCrc != decompressAndCalculateCrc(zis) && !sanityCheck) {
+ throw new RuntimeException("CRC mismatch");
+ }
+ } catch (IOException iox) {
+ if (!sanityCheck) {
+ throw new RuntimeException("Decompression failed", iox);
+ }
}
zis.closeEntry();
entryName = "";
@@ -110,11 +122,19 @@ public class BundleChecker implements Runnable {
}
public static void main(String[] args) throws FileNotFoundException {
- if (args.length == 0) {
- throw new RuntimeException("Usage: BundleChecker <fileX.zip> ...");
+ int argsOffset = 0;
+ boolean sanityCheck = false;
+ if (args.length != 0) {
+ if (args[0].equals("-s")) {
+ sanityCheck = true;
+ argsOffset = 1;
+ }
+ }
+ if (args.length == argsOffset) {
+ throw new RuntimeException("Usage: BundleChecker [-s] <fileX.zip> ...");
}
- for (int i = 0; i < args.length; ++i) {
- new BundleChecker(new FileInputStream(args[i]), new AtomicInteger(0)).run();
+ for (int i = argsOffset; i < args.length; ++i) {
+ new BundleChecker(new FileInputStream(args[i]), new AtomicInteger(0), sanityCheck).run();
}
}
}
diff --git a/java/integration/fuzz_data.zip b/java/integration/fuzz_data.zip
new file mode 100755
index 0000000..7a7eeda
--- /dev/null
+++ b/java/integration/fuzz_data.zip
Binary files differ
diff --git a/java/integration/pom.xml b/java/integration/pom.xml
index 6625f69..5672df1 100755
--- a/java/integration/pom.xml
+++ b/java/integration/pom.xml
@@ -39,6 +39,7 @@
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
+ <id>data</id>
<phase>test</phase>
<goals>
<goal>java</goal>
@@ -51,6 +52,21 @@
</arguments>
</configuration>
</execution>
+ <execution>
+ <id>fuzz</id>
+ <phase>test</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ <configuration>
+ <executable>java</executable>
+ <mainClass>org.brotli.integration.BundleChecker</mainClass>
+ <arguments>
+ <argument>-s</argument>
+ <argument>fuzz_data.zip</argument>
+ </arguments>
+ </configuration>
+ </execution>
</executions>
</plugin>
</plugins>