summaryrefslogtreecommitdiff
path: root/core/src/test/java
diff options
context:
space:
mode:
authorgitlost <gitlost@users.noreply.github.com>2021-04-12 17:44:42 +0300
committerGitHub <noreply@github.com>2021-04-12 17:44:42 +0300
commitd4c3d73592e86aff480afef62ebc20ae70165e38 (patch)
treea328cebcd3a7ed2d07c4272286fba45976c82a59 /core/src/test/java
parent99e9b34f5afc21fdaeead283d5ed0bc1314cbec1 (diff)
downloadzxing-d4c3d73592e86aff480afef62ebc20ae70165e38.tar.xz
PDF417 Macro: fileId numeric decode; allow Macro only symbol (#1379)
* PDF417 Macro: fileId numeric decode; allow Macro only symbol * PDF417 Macro: additional FormatException unit tests
Diffstat (limited to 'core/src/test/java')
-rw-r--r--core/src/test/java/com/google/zxing/pdf417/decoder/PDF417DecoderTestCase.java85
1 files changed, 81 insertions, 4 deletions
diff --git a/core/src/test/java/com/google/zxing/pdf417/decoder/PDF417DecoderTestCase.java b/core/src/test/java/com/google/zxing/pdf417/decoder/PDF417DecoderTestCase.java
index cb70c0a9a..6494a9a24 100644
--- a/core/src/test/java/com/google/zxing/pdf417/decoder/PDF417DecoderTestCase.java
+++ b/core/src/test/java/com/google/zxing/pdf417/decoder/PDF417DecoderTestCase.java
@@ -18,6 +18,7 @@ package com.google.zxing.pdf417.decoder;
import com.google.zxing.FormatException;
import com.google.zxing.pdf417.PDF417ResultMetadata;
+import com.google.zxing.common.DecoderResult;
import org.junit.Assert;
import org.junit.Test;
@@ -39,7 +40,7 @@ public class PDF417DecoderTestCase extends Assert {
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 2, resultMetadata);
assertEquals(0, resultMetadata.getSegmentIndex());
- assertEquals("ARBX", resultMetadata.getFileId());
+ assertEquals("017053", resultMetadata.getFileId());
assertFalse(resultMetadata.isLastSegment());
assertEquals(4, resultMetadata.getSegmentCount());
assertEquals("CEN BE", resultMetadata.getSender());
@@ -66,7 +67,7 @@ public class PDF417DecoderTestCase extends Assert {
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 2, resultMetadata);
assertEquals(3, resultMetadata.getSegmentIndex());
- assertEquals("ARBX", resultMetadata.getFileId());
+ assertEquals("017053", resultMetadata.getFileId());
assertTrue(resultMetadata.isLastSegment());
assertEquals(4, resultMetadata.getSegmentCount());
assertNull(resultMetadata.getAddressee());
@@ -79,6 +80,32 @@ public class PDF417DecoderTestCase extends Assert {
104, optionalData[optionalData.length - 1]);
}
+
+ /**
+ * Tests the example given in ISO/IEC 15438:2015(E) - Annex H.6
+ */
+ @Test
+ public void testStandardSample3() throws FormatException {
+ PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
+ int[] sampleCodes = {7, 928, 111, 100, 100, 200, 300,
+ 0}; // Final dummy ECC codeword required to avoid ArrayIndexOutOfBounds
+
+ DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 2, resultMetadata);
+
+ assertEquals(0, resultMetadata.getSegmentIndex());
+ assertEquals("100200300", resultMetadata.getFileId());
+ assertFalse(resultMetadata.isLastSegment());
+ assertEquals(-1, resultMetadata.getSegmentCount());
+ assertNull(resultMetadata.getAddressee());
+ assertNull(resultMetadata.getSender());
+ assertNull(resultMetadata.getOptionalData());
+
+ // Check that symbol containing no data except Macro is accepted (see note in Annex H.2)
+ DecoderResult decoderResult = DecodedBitStreamParser.decode(sampleCodes, "0");
+ assertEquals("", decoderResult.getText());
+ assertNotNull(decoderResult.getOther());
+ }
+
@Test
public void testSampleWithFilename() throws FormatException {
int[] sampleCodes = {23, 477, 928, 111, 100, 0, 252, 21, 86, 923, 0, 815, 251, 133, 12, 148, 537, 593,
@@ -89,7 +116,7 @@ public class PDF417DecoderTestCase extends Assert {
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 3, resultMetadata);
assertEquals(0, resultMetadata.getSegmentIndex());
- assertEquals("AAIMAVC ", resultMetadata.getFileId());
+ assertEquals("000252021086", resultMetadata.getFileId());
assertFalse(resultMetadata.isLastSegment());
assertEquals(2, resultMetadata.getSegmentCount());
assertNull(resultMetadata.getAddressee());
@@ -106,7 +133,7 @@ public class PDF417DecoderTestCase extends Assert {
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 3, resultMetadata);
assertEquals(0, resultMetadata.getSegmentIndex());
- assertEquals("AAIMAVC ", resultMetadata.getFileId());
+ assertEquals("000252021086", resultMetadata.getFileId());
assertFalse(resultMetadata.isLastSegment());
assertEquals(180980729000000L, resultMetadata.getTimestamp());
@@ -114,4 +141,54 @@ public class PDF417DecoderTestCase extends Assert {
assertEquals(260013, resultMetadata.getChecksum());
}
+ @Test
+ public void testSampleWithMacroTerminatorOnly() throws FormatException {
+ int[] sampleCodes = {7, 477, 928, 222, 198, 0, 922};
+ PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
+
+ DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 3, resultMetadata);
+
+ assertEquals(99998, resultMetadata.getSegmentIndex());
+ assertEquals("000", resultMetadata.getFileId());
+ assertTrue(resultMetadata.isLastSegment());
+ assertEquals(-1, resultMetadata.getSegmentCount());
+ assertNull(resultMetadata.getOptionalData());
+ }
+
+ @Test
+ public void testSampleWithBadSequenceIndexMacro() throws FormatException {
+ int[] sampleCodes = {3, 928, 222, 0};
+ PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
+
+ try {
+ DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 2, resultMetadata);
+ } catch (FormatException expected) {
+ // continue
+ }
+ }
+
+ @Test
+ public void testSampleWithNoFileIdMacro() throws FormatException {
+ int[] sampleCodes = {4, 928, 222, 198, 0};
+ PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
+
+ try {
+ DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 2, resultMetadata);
+ } catch (FormatException expected) {
+ // continue
+ }
+ }
+
+ @Test
+ public void testSampleWithNoDataNoMacro() throws FormatException {
+ int[] sampleCodes = {3, 899, 899, 0};
+
+ try {
+ DecodedBitStreamParser.decode(sampleCodes, "0");
+ } catch (FormatException expected) {
+ // continue
+ }
+
+ }
+
}