From 3af2bcb68b5a228149cdd6ac518bcb91891583d2 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 1 Nov 2012 11:18:11 +0000 Subject: [PATCH] LZ4: improve test coverage. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1404541 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractTestCompressionMode.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lucene/codecs/src/test/org/apache/lucene/codecs/compressing/AbstractTestCompressionMode.java b/lucene/codecs/src/test/org/apache/lucene/codecs/compressing/AbstractTestCompressionMode.java index 5904d50ef87..234d7727116 100644 --- a/lucene/codecs/src/test/org/apache/lucene/codecs/compressing/AbstractTestCompressionMode.java +++ b/lucene/codecs/src/test/org/apache/lucene/codecs/compressing/AbstractTestCompressionMode.java @@ -38,6 +38,10 @@ public abstract class AbstractTestCompressionMode extends LuceneTestCase { final int length = random().nextBoolean() ? random().nextInt(20) : random().nextInt(192 * 1024); + return randomArray(length, max); + } + + static byte[] randomArray(int length, int max) { final byte[] arr = new byte[length]; for (int i = 0; i < arr.length; ++i) { arr[i] = (byte) RandomInts.randomIntBetween(random(), 0, max); @@ -147,8 +151,8 @@ public abstract class AbstractTestCompressionMode extends LuceneTestCase { test(decompressed); } - public void testLongLiteralsAndMatchs() throws IOException { - // literals and matchs length > 16 + public void testLongMatchs() throws IOException { + // match length > 16 final byte[] decompressed = new byte[RandomInts.randomIntBetween(random(), 300, 1024)]; for (int i = 0; i < decompressed.length; ++i) { decompressed[i] = (byte) i; @@ -156,4 +160,14 @@ public abstract class AbstractTestCompressionMode extends LuceneTestCase { test(decompressed); } + public void testLongLiterals() throws IOException { + // long literals (length > 16) which are not the last literals + final byte[] decompressed = randomArray(RandomInts.randomIntBetween(random(), 400, 1024), 256); + final int matchRef = random().nextInt(30); + final int matchOff = RandomInts.randomIntBetween(random(), decompressed.length - 40, decompressed.length - 20); + final int matchLength = RandomInts.randomIntBetween(random(), 4, 10); + System.arraycopy(decompressed, matchRef, decompressed, matchOff, matchLength); + test(decompressed); + } + } \ No newline at end of file