X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=core%2Ftest%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fcommon%2Freedsolomon%2FReedSolomonDecoderQRCodeTestCase.java;h=15964bcacd3d3a78dc3300e5d227dbf96437dd2f;hp=18a5b4cb014c69cdcd48f7b84f5573a5873a758d;hb=e5d03a79a458340b69a57914a352f0a8841cdf69;hpb=d420554bc509d08feb59ac81cd48a10d3b5e6042 diff --git a/core/test/src/com/google/zxing/common/reedsolomon/ReedSolomonDecoderQRCodeTestCase.java b/core/test/src/com/google/zxing/common/reedsolomon/ReedSolomonDecoderQRCodeTestCase.java index 18a5b4cb..15964bca 100644 --- a/core/test/src/com/google/zxing/common/reedsolomon/ReedSolomonDecoderQRCodeTestCase.java +++ b/core/test/src/com/google/zxing/common/reedsolomon/ReedSolomonDecoderQRCodeTestCase.java @@ -16,25 +16,29 @@ package com.google.zxing.common.reedsolomon; +import org.junit.Test; + import java.util.Random; /** - * @author srowen@google.com (Sean Owen) + * @author Sean Owen */ public final class ReedSolomonDecoderQRCodeTestCase extends AbstractReedSolomonTestCase { /** See ISO 18004, Appendix I, from which this example is taken. */ private static final int[] QR_CODE_TEST = { 0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11, 0xEC, - 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xA5 }; + 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11 }; private static final int[] QR_CODE_TEST_WITH_EC = { 0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xA5, 0x24, 0xD4, 0xC1, 0xED, 0x36, 0xC7, 0x87, 0x2C, 0x55 }; - private static final int QR_CODE_CORRECTABLE = (QR_CODE_TEST_WITH_EC.length - QR_CODE_TEST.length) / 2; + private static final int QR_CODE_ECC_BYTES = QR_CODE_TEST_WITH_EC.length - QR_CODE_TEST.length; + private static final int QR_CODE_CORRECTABLE = QR_CODE_ECC_BYTES / 2; private final ReedSolomonDecoder qrRSDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD); + @Test public void testNoError() throws ReedSolomonException { int[] received = new int[QR_CODE_TEST_WITH_EC.length]; System.arraycopy(QR_CODE_TEST_WITH_EC, 0, received, 0, received.length); @@ -42,9 +46,10 @@ public final class ReedSolomonDecoderQRCodeTestCase extends AbstractReedSolomonT checkQRRSDecode(received); } + @Test public void testOneError() throws ReedSolomonException { int[] received = new int[QR_CODE_TEST_WITH_EC.length]; - Random random = new Random(0xDEADBEEFL); + Random random = getRandom(); for (int i = 0; i < received.length; i++) { System.arraycopy(QR_CODE_TEST_WITH_EC, 0, received, 0, received.length); received[i] = random.nextInt(256); @@ -52,20 +57,22 @@ public final class ReedSolomonDecoderQRCodeTestCase extends AbstractReedSolomonT } } + @Test public void testMaxErrors() throws ReedSolomonException { int[] received = new int[QR_CODE_TEST_WITH_EC.length]; - Random random = new Random(0xDEADBEEFL); - for (int i = 0; i < QR_CODE_TEST.length; i++) { // # iterations is kind of arbitrary + Random random = getRandom(); + for (int test : QR_CODE_TEST) { // # iterations is kind of arbitrary System.arraycopy(QR_CODE_TEST_WITH_EC, 0, received, 0, received.length); corrupt(received, QR_CODE_CORRECTABLE, random); checkQRRSDecode(received); } } + @Test public void testTooManyErrors() { int[] received = new int[QR_CODE_TEST_WITH_EC.length]; System.arraycopy(QR_CODE_TEST_WITH_EC, 0, received, 0, received.length); - Random random = new Random(0xDEADBEEFL); + Random random = getRandom(); corrupt(received, QR_CODE_CORRECTABLE + 1, random); try { checkQRRSDecode(received); @@ -76,7 +83,7 @@ public final class ReedSolomonDecoderQRCodeTestCase extends AbstractReedSolomonT } private void checkQRRSDecode(int[] received) throws ReedSolomonException { - qrRSDecoder.decode(received, 2*QR_CODE_CORRECTABLE); + qrRSDecoder.decode(received, QR_CODE_ECC_BYTES); for (int i = 0; i < QR_CODE_TEST.length; i++) { assertEquals(received[i], QR_CODE_TEST[i]); }