From e9896d03a65b96c9f7db3ba9f294e62d2f7aa168 Mon Sep 17 00:00:00 2001 From: Taneli Huuskonen Date: Thu, 5 May 2016 15:10:44 +0300 Subject: Aztec decoder returns raw bytes The Aztec decoder now packs the code bits into bytes and returns them as "raw bytes", even though the error correction codes and stuffing have been already removed. Also added a couple of tests for the byte-packing function. --- .../google/zxing/aztec/decoder/DecoderTest.java | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'core/src/test/java') diff --git a/core/src/test/java/com/google/zxing/aztec/decoder/DecoderTest.java b/core/src/test/java/com/google/zxing/aztec/decoder/DecoderTest.java index ce5b8a441..95f7e69a1 100644 --- a/core/src/test/java/com/google/zxing/aztec/decoder/DecoderTest.java +++ b/core/src/test/java/com/google/zxing/aztec/decoder/DecoderTest.java @@ -20,8 +20,9 @@ import com.google.zxing.ResultPoint; import com.google.zxing.aztec.AztecDetectorResult; import com.google.zxing.common.BitMatrix; import org.junit.Test; +import org.junit.Assert; -public final class DecoderTest { +public final class DecoderTest extends Assert { private static final ResultPoint[] NO_POINTS = new ResultPoint[0]; @@ -105,4 +106,35 @@ public final class DecoderTest { new Decoder().decode(r); } + private static void assertEqualByteArrays(byte[] b1, byte[] b2) { + assertEquals(b1.length, b2.length); + for (int i = 0; i < b1.length; i++) { + assertEquals(b1[i], b2[i]); + } + } + + @Test + public void testRawBytes() { + boolean bool0[] = {}; + boolean bool1[] = { true }; + boolean bool7[] = { true, false, true, false, true, false, true }; + boolean bool8[] = { true, false, true, false, true, false, true, false }; + boolean bool9[] = { true, false, true, false, true, false, true, false, + true }; + boolean bool16[] = { false, true, true, false, false, false, true, true, + true, true, false, false, false, false, false, true }; + byte byte0[] = {}; + byte byte1[] = { -128 }; + byte byte7[] = { -86 }; + byte byte8[] = { -86 }; + byte byte9[] = { -86, -128 }; + byte byte16[] = { 99, -63 }; + + assertEqualByteArrays(byte0, Decoder.convertBoolArrayToByteArray(bool0)); + assertEqualByteArrays(byte1, Decoder.convertBoolArrayToByteArray(bool1)); + assertEqualByteArrays(byte7, Decoder.convertBoolArrayToByteArray(bool7)); + assertEqualByteArrays(byte8, Decoder.convertBoolArrayToByteArray(bool8)); + assertEqualByteArrays(byte9, Decoder.convertBoolArrayToByteArray(bool9)); + assertEqualByteArrays(byte16, Decoder.convertBoolArrayToByteArray(bool16)); + } } -- cgit v1.2.3 From ee48b3e5d384fa81d928f647a1e463f780223be5 Mon Sep 17 00:00:00 2001 From: Taneli Huuskonen Date: Thu, 5 May 2016 21:58:37 +0300 Subject: Cleaned up previous commit Following Sean Owen's suggestions, I cleaned up my code in the Aztec decoder and its tests as follows: 1. Made convertBoolArrayToByteArray() package-private. 2. Replaced my own assertEqualByteArrays() with existing assertArrayEquals(). 3. Replaced C-style array declarations with more Javaish ones. --- .../com/google/zxing/aztec/decoder/Decoder.java | 2 +- .../google/zxing/aztec/decoder/DecoderTest.java | 43 +++++++++------------- 2 files changed, 19 insertions(+), 26 deletions(-) (limited to 'core/src/test/java') diff --git a/core/src/main/java/com/google/zxing/aztec/decoder/Decoder.java b/core/src/main/java/com/google/zxing/aztec/decoder/Decoder.java index a72b87520..20affb58f 100644 --- a/core/src/main/java/com/google/zxing/aztec/decoder/Decoder.java +++ b/core/src/main/java/com/google/zxing/aztec/decoder/Decoder.java @@ -347,7 +347,7 @@ public final class Decoder { /** * Packs a bit array into bytes, most significant bit first */ - public static byte[] convertBoolArrayToByteArray(boolean[] boolArr) { + static byte[] convertBoolArrayToByteArray(boolean[] boolArr) { byte[] byteArr = new byte[(boolArr.length + 7) / 8]; for (int i = 0; i < byteArr.length; i++) { byteArr[i] = readByte(boolArr, 8 * i); diff --git a/core/src/test/java/com/google/zxing/aztec/decoder/DecoderTest.java b/core/src/test/java/com/google/zxing/aztec/decoder/DecoderTest.java index 95f7e69a1..5bab590fd 100644 --- a/core/src/test/java/com/google/zxing/aztec/decoder/DecoderTest.java +++ b/core/src/test/java/com/google/zxing/aztec/decoder/DecoderTest.java @@ -106,35 +106,28 @@ public final class DecoderTest extends Assert { new Decoder().decode(r); } - private static void assertEqualByteArrays(byte[] b1, byte[] b2) { - assertEquals(b1.length, b2.length); - for (int i = 0; i < b1.length; i++) { - assertEquals(b1[i], b2[i]); - } - } - @Test public void testRawBytes() { - boolean bool0[] = {}; - boolean bool1[] = { true }; - boolean bool7[] = { true, false, true, false, true, false, true }; - boolean bool8[] = { true, false, true, false, true, false, true, false }; - boolean bool9[] = { true, false, true, false, true, false, true, false, + boolean[] bool0 = {}; + boolean[] bool1 = { true }; + boolean[] bool7 = { true, false, true, false, true, false, true }; + boolean[] bool8 = { true, false, true, false, true, false, true, false }; + boolean[] bool9 = { true, false, true, false, true, false, true, false, true }; - boolean bool16[] = { false, true, true, false, false, false, true, true, + boolean[] bool16 = { false, true, true, false, false, false, true, true, true, true, false, false, false, false, false, true }; - byte byte0[] = {}; - byte byte1[] = { -128 }; - byte byte7[] = { -86 }; - byte byte8[] = { -86 }; - byte byte9[] = { -86, -128 }; - byte byte16[] = { 99, -63 }; + byte[] byte0 = {}; + byte[] byte1 = { -128 }; + byte[] byte7 = { -86 }; + byte[] byte8 = { -86 }; + byte[] byte9 = { -86, -128 }; + byte[] byte16 = { 99, -63 }; - assertEqualByteArrays(byte0, Decoder.convertBoolArrayToByteArray(bool0)); - assertEqualByteArrays(byte1, Decoder.convertBoolArrayToByteArray(bool1)); - assertEqualByteArrays(byte7, Decoder.convertBoolArrayToByteArray(bool7)); - assertEqualByteArrays(byte8, Decoder.convertBoolArrayToByteArray(bool8)); - assertEqualByteArrays(byte9, Decoder.convertBoolArrayToByteArray(bool9)); - assertEqualByteArrays(byte16, Decoder.convertBoolArrayToByteArray(bool16)); + assertArrayEquals(byte0, Decoder.convertBoolArrayToByteArray(bool0)); + assertArrayEquals(byte1, Decoder.convertBoolArrayToByteArray(bool1)); + assertArrayEquals(byte7, Decoder.convertBoolArrayToByteArray(bool7)); + assertArrayEquals(byte8, Decoder.convertBoolArrayToByteArray(bool8)); + assertArrayEquals(byte9, Decoder.convertBoolArrayToByteArray(bool9)); + assertArrayEquals(byte16, Decoder.convertBoolArrayToByteArray(bool16)); } } -- cgit v1.2.3