mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Follow up on commit for issue #242
This commit is contained in:
parent
e0495aafd3
commit
d876b3e178
1
AUTHORS
1
AUTHORS
|
@ -53,6 +53,7 @@ Isaac Potoczny-Jones
|
|||
Ivan Poliakov
|
||||
Jacob Haynes (Google)
|
||||
Jeff Breidenbach (Google)
|
||||
jjYBdx4IL
|
||||
Joan Montané (Softcatalà.cat)
|
||||
John Connolly (Bug Labs)
|
||||
Jonas Petersson (Prisjakt)
|
||||
|
|
|
@ -33,7 +33,7 @@ public abstract class ReaderException extends Exception {
|
|||
}
|
||||
|
||||
ReaderException(Throwable cause) {
|
||||
super(cause);
|
||||
super(cause);
|
||||
}
|
||||
|
||||
// Prevent stack traces from being taken
|
||||
|
|
|
@ -63,7 +63,6 @@ public final class BitMatrix implements Cloneable {
|
|||
}
|
||||
|
||||
public static BitMatrix parse(String stringRepresentation, String setString, String unsetString) {
|
||||
int pos = 0;
|
||||
if (stringRepresentation == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
@ -73,8 +72,10 @@ public final class BitMatrix implements Cloneable {
|
|||
int rowStartPos = 0;
|
||||
int rowLength = -1;
|
||||
int nRows = 0;
|
||||
int pos = 0;
|
||||
while (pos < stringRepresentation.length()) {
|
||||
if (stringRepresentation.substring(pos, pos + 1).equals("\n") || stringRepresentation.substring(pos, pos + 1).equals("\r")) {
|
||||
if (stringRepresentation.charAt(pos) == '\n' ||
|
||||
stringRepresentation.charAt(pos) == '\r') {
|
||||
if (bitsPos > rowStartPos) {
|
||||
if(rowLength == -1) {
|
||||
rowLength = bitsPos - rowStartPos;
|
||||
|
@ -97,7 +98,8 @@ public final class BitMatrix implements Cloneable {
|
|||
bits[bitsPos] = false;
|
||||
bitsPos++;
|
||||
} else {
|
||||
throw new IllegalArgumentException("illegal character encountered: " + stringRepresentation.substring(pos));
|
||||
throw new IllegalArgumentException(
|
||||
"illegal character encountered: " + stringRepresentation.substring(pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,15 +107,14 @@ public final class BitMatrix implements Cloneable {
|
|||
if (bitsPos > rowStartPos) {
|
||||
if(rowLength == -1) {
|
||||
rowLength = bitsPos - rowStartPos;
|
||||
}
|
||||
else if (bitsPos - rowStartPos != rowLength) {
|
||||
} else if (bitsPos - rowStartPos != rowLength) {
|
||||
throw new IllegalArgumentException("row lengths do not match");
|
||||
}
|
||||
nRows++;
|
||||
}
|
||||
|
||||
BitMatrix matrix = new BitMatrix(rowLength, nRows);
|
||||
for (int i=0; i<bitsPos; i++) {
|
||||
for (int i = 0; i < bitsPos; i++) {
|
||||
if (bits[i]) {
|
||||
matrix.set(i % rowLength, i / rowLength);
|
||||
}
|
||||
|
@ -161,17 +162,17 @@ public final class BitMatrix implements Cloneable {
|
|||
}
|
||||
|
||||
/**
|
||||
* <p>XOR for {@link BitMatrix}.</p>
|
||||
* Flip the bit in this {@link BitMatrix} if the corresponding mask bit is set.
|
||||
* Exclusive-or (XOR): Flip the bit in this {@code BitMatrix} if the corresponding
|
||||
* mask bit is set.
|
||||
*
|
||||
* @param mask
|
||||
* @param mask XOR mask
|
||||
*/
|
||||
public void xor(BitMatrix mask) {
|
||||
if (width != mask.getWidth() || height != mask.getHeight()
|
||||
|| rowSize != mask.getRowSize()) {
|
||||
throw new IllegalArgumentException("input matrix dimensions do not match");
|
||||
}
|
||||
BitArray rowArray = new BitArray(width/32+1);
|
||||
BitArray rowArray = new BitArray(width / 32 + 1);
|
||||
for (int y = 0; y < height; y++) {
|
||||
int offset = y * rowSize;
|
||||
int[] row = mask.getRow(y, rowArray).getBitArray();
|
||||
|
|
|
@ -19,11 +19,9 @@ import com.google.zxing.FormatException;
|
|||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.aztec.AztecDetectorResult;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DecoderTest {
|
||||
public final class DecoderTest {
|
||||
|
||||
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
|
||||
|
||||
|
@ -36,8 +34,8 @@ public class DecoderTest {
|
|||
* at com.google.zxing.aztec.decoder.Decoder.decode(Decoder.java:77)
|
||||
* at com.google.zxing.aztec.decoder.DecoderTest.testDecodeBug1(DecoderTest.java:66)</pre>
|
||||
*/
|
||||
@Test
|
||||
public void testDecodeTooManyErrors() {
|
||||
@Test(expected = FormatException.class)
|
||||
public void testDecodeTooManyErrors() throws FormatException {
|
||||
BitMatrix matrix = BitMatrix.parse(""
|
||||
+ "X X . X . . . X X . . . X . . X X X . X . X X X X X . \n"
|
||||
+ "X X . . X X . . . . . X X . . . X X . . . X . X . . X \n"
|
||||
|
@ -68,15 +66,11 @@ public class DecoderTest {
|
|||
+ "X X . X . X . . . X . X . . . . X X . X . . X X . . . \n",
|
||||
"X ", ". ");
|
||||
AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, true, 16, 4);
|
||||
try {
|
||||
DecoderResult res = new Decoder().decode(r);
|
||||
fail();
|
||||
} catch (FormatException ex) {
|
||||
}
|
||||
new Decoder().decode(r);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeTooManyErrors2() {
|
||||
@Test(expected = FormatException.class)
|
||||
public void testDecodeTooManyErrors2() throws FormatException {
|
||||
BitMatrix matrix = BitMatrix.parse(""
|
||||
+ ". X X . . X . X X . . . X . . X X X . . . X X . X X . \n"
|
||||
+ "X X . X X . . X . . . X X . . . X X . X X X . X . X X \n"
|
||||
|
@ -107,11 +101,7 @@ public class DecoderTest {
|
|||
+ "X X . . . X X . . X . X . . . . X X . X . . X . X . X \n",
|
||||
"X ", ". ");
|
||||
AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, true, 16, 4);
|
||||
try {
|
||||
DecoderResult res = new Decoder().decode(r);
|
||||
fail();
|
||||
} catch (FormatException ex) {
|
||||
}
|
||||
new Decoder().decode(r);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,17 +27,14 @@ import com.google.zxing.common.BitArray;
|
|||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
import org.junit.Before;
|
||||
|
||||
/**
|
||||
* Aztec 2D generator unit tests.
|
||||
|
@ -49,12 +46,6 @@ public final class EncoderTest extends Assert {
|
|||
|
||||
private static final Pattern DOTX = Pattern.compile("[^.X]");
|
||||
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
|
||||
private static Random random;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
random = new Random(0);
|
||||
}
|
||||
|
||||
// real life tests
|
||||
|
||||
|
@ -513,7 +504,7 @@ public final class EncoderTest extends Assert {
|
|||
}
|
||||
|
||||
private static Random getPseudoRandom() {
|
||||
return random;
|
||||
return new Random(0xDEADBEEF);
|
||||
}
|
||||
|
||||
private static void testModeMessage(boolean compact, int layers, int words, String expected) {
|
||||
|
|
|
@ -101,7 +101,7 @@ public final class BitArrayTestCase extends Assert {
|
|||
|
||||
@Test
|
||||
public void testGetNextSet5() {
|
||||
Random r = new SecureRandom(new byte[] {(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF});
|
||||
Random r = new Random(0xDEADBEEF);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
BitArray array = new BitArray(1 + r.nextInt(100));
|
||||
int numSet = r.nextInt(20);
|
||||
|
|
|
@ -173,7 +173,9 @@ public final class BitMatrixTestCase extends Assert {
|
|||
try {
|
||||
assertEquals(centerMatrix, BitMatrix.parse(" \n xy\n \n", "x", " "));
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// good
|
||||
}
|
||||
|
||||
assertEquals(emptyMatrix24, BitMatrix.parse(" \n \n \n \n", "x", " "));
|
||||
|
||||
|
@ -222,12 +224,16 @@ public final class BitMatrixTestCase extends Assert {
|
|||
try {
|
||||
emptyMatrix.clone().xor(badMatrix);
|
||||
fail();
|
||||
} catch(IllegalArgumentException ex) {}
|
||||
} catch(IllegalArgumentException ex) {
|
||||
// good
|
||||
}
|
||||
|
||||
try {
|
||||
badMatrix.clone().xor(emptyMatrix);
|
||||
fail();
|
||||
} catch(IllegalArgumentException ex) {}
|
||||
} catch(IllegalArgumentException ex) {
|
||||
// good
|
||||
}
|
||||
}
|
||||
|
||||
private static void testXOR(BitMatrix dataMatrix, BitMatrix flipMatrix, BitMatrix expectedMatrix) {
|
||||
|
|
|
@ -501,7 +501,7 @@ public final class ReedSolomonTestCase extends Assert {
|
|||
}
|
||||
|
||||
private static Random getPseudoRandom() {
|
||||
return new SecureRandom(new byte[] {(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF});
|
||||
return new Random(0xDEADBEEF);
|
||||
}
|
||||
|
||||
}
|
|
@ -49,7 +49,7 @@ abstract class AbstractErrorCorrectionTestCase extends Assert {
|
|||
}
|
||||
|
||||
static Random getRandom() {
|
||||
return new Random(0);
|
||||
return new Random(0xDEADBEEF);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue