move all Result to RXingResult

This commit is contained in:
Henry Schimke
2022-08-20 12:12:30 -05:00
parent 9f72478dc8
commit 90ace738b7
149 changed files with 1658 additions and 1658 deletions

View File

@@ -22,11 +22,11 @@ import com.google.zxing.BufferedImageLuminanceSource;
import com.google.zxing.DecodeHintType;
import com.google.zxing.LuminanceSource;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
import com.google.zxing.RXingResult;
import com.google.zxing.RXingResultMetadataType;
import com.google.zxing.common.AbstractBlackBoxTestCase;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.common.TestResult;
import com.google.zxing.common.TestRXingResult;
import com.google.zxing.multi.MultipleBarcodeReader;
import org.junit.Test;
@@ -59,20 +59,20 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
private final MultipleBarcodeReader barcodeReader = new PDF417Reader();
private final List<TestResult> testResults = new ArrayList<>();
private final List<TestRXingResult> testRXingResults = new ArrayList<>();
public PDF417BlackBox4TestCase() {
super("src/test/resources/blackbox/pdf417-4", null, BarcodeFormat.PDF_417);
testResults.add(new TestResult(3, 3, 0, 0, 0.0f));
testRXingResults.add(new TestRXingResult(3, 3, 0, 0, 0.0f));
}
@Test
@Override
public void testBlackBox() throws IOException {
assertFalse(testResults.isEmpty());
assertFalse(testRXingResults.isEmpty());
Map<String,List<Path>> imageFiles = getImageFileLists();
int testCount = testResults.size();
int testCount = testRXingResults.size();
int[] passedCounts = new int[testCount];
int[] tryHarderCounts = new int[testCount];
@@ -94,10 +94,10 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
}
for (int x = 0; x < testCount; x++) {
List<Result> results = new ArrayList<>();
List<RXingResult> results = new ArrayList<>();
for (Path imageFile : testImageGroup.getValue()) {
BufferedImage image = ImageIO.read(imageFile.toFile());
float rotation = testResults.get(x).getRotation();
float rotation = testRXingResults.get(x).getRotation();
BufferedImage rotatedImage = rotateImage(image, rotation);
LuminanceSource source = new BufferedImageLuminanceSource(rotatedImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
@@ -108,11 +108,11 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
// ignore
}
}
results.sort(Comparator.comparingInt((Result r) -> getMeta(r).getSegmentIndex()));
results.sort(Comparator.comparingInt((RXingResult r) -> getMeta(r).getSegmentIndex()));
StringBuilder resultText = new StringBuilder();
String fileId = null;
for (Result result : results) {
PDF417ResultMetadata resultMetadata = getMeta(result);
for (RXingResult result : results) {
PDF417RXingResultMetadata resultMetadata = getMeta(result);
assertNotNull("resultMetadata", resultMetadata);
if (fileId == null) {
fileId = resultMetadata.getFileId();
@@ -131,15 +131,15 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
int totalMustPass = 0;
int numberOfTests = imageFiles.keySet().size();
for (int x = 0; x < testResults.size(); x++) {
TestResult testResult = testResults.get(x);
log.info(String.format("Rotation %d degrees:", (int) testResult.getRotation()));
for (int x = 0; x < testRXingResults.size(); x++) {
TestRXingResult testRXingResult = testRXingResults.get(x);
log.info(String.format("Rotation %d degrees:", (int) testRXingResult.getRotation()));
log.info(String.format(" %d of %d images passed (%d required)", passedCounts[x], numberOfTests,
testResult.getMustPassCount()));
testRXingResult.getMustPassCount()));
log.info(String.format(" %d of %d images passed with try harder (%d required)", tryHarderCounts[x],
numberOfTests, testResult.getTryHarderCount()));
numberOfTests, testRXingResult.getTryHarderCount()));
totalFound += passedCounts[x] + tryHarderCounts[x];
totalMustPass += testResult.getMustPassCount() + testResult.getTryHarderCount();
totalMustPass += testRXingResult.getMustPassCount() + testRXingResult.getTryHarderCount();
}
int totalTests = numberOfTests * testCount * 2;
@@ -154,19 +154,19 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
// Then run through again and assert if any failed
for (int x = 0; x < testCount; x++) {
TestResult testResult = testResults.get(x);
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
assertTrue(label, passedCounts[x] >= testResult.getMustPassCount());
assertTrue("Try harder, " + label, tryHarderCounts[x] >= testResult.getTryHarderCount());
TestRXingResult testRXingResult = testRXingResults.get(x);
String label = "Rotation " + testRXingResult.getRotation() + " degrees: Too many images failed";
assertTrue(label, passedCounts[x] >= testRXingResult.getMustPassCount());
assertTrue("Try harder, " + label, tryHarderCounts[x] >= testRXingResult.getTryHarderCount());
}
}
private static PDF417ResultMetadata getMeta(Result result) {
return result.getResultMetadata() == null ? null : (PDF417ResultMetadata) result.getResultMetadata().get(
ResultMetadataType.PDF417_EXTRA_METADATA);
private static PDF417RXingResultMetadata getMeta(RXingResult result) {
return result.getRXingResultMetadata() == null ? null : (PDF417RXingResultMetadata) result.getRXingResultMetadata().get(
RXingResultMetadataType.PDF417_EXTRA_METADATA);
}
private Result[] decode(BinaryBitmap source, boolean tryHarder) throws ReaderException {
private RXingResult[] decode(BinaryBitmap source, boolean tryHarder) throws ReaderException {
Map<DecodeHintType,Object> hints = new EnumMap<>(DecodeHintType.class);
if (tryHarder) {
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);

View File

@@ -18,8 +18,8 @@ package com.google.zxing.pdf417.decoder;
import com.google.zxing.FormatException;
import com.google.zxing.WriterException;
import com.google.zxing.pdf417.PDF417ResultMetadata;
import com.google.zxing.common.DecoderResult;
import com.google.zxing.pdf417.PDF417RXingResultMetadata;
import com.google.zxing.common.DecoderRXingResult;
import com.google.zxing.pdf417.encoder.Compaction;
import com.google.zxing.pdf417.encoder.PDF417HighLevelEncoderTestAdapter;
@@ -39,7 +39,7 @@ public class PDF417DecoderTestCase extends Assert {
*/
@Test
public void testStandardSample1() throws FormatException {
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
int[] sampleCodes = {20, 928, 111, 100, 17, 53, 923, 1, 111, 104, 923, 3, 64, 416, 34, 923, 4, 258, 446, 67,
// we should never reach these
1000, 1000, 1000};
@@ -66,7 +66,7 @@ public class PDF417DecoderTestCase extends Assert {
*/
@Test
public void testStandardSample2() throws FormatException {
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
int[] sampleCodes = {11, 928, 111, 103, 17, 53, 923, 1, 111, 104, 922,
// we should never reach these
1000, 1000, 1000};
@@ -93,7 +93,7 @@ public class PDF417DecoderTestCase extends Assert {
*/
@Test
public void testStandardSample3() throws FormatException {
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
int[] sampleCodes = {7, 928, 111, 100, 100, 200, 300,
0}; // Final dummy ECC codeword required to avoid ArrayIndexOutOfBounds
@@ -108,9 +108,9 @@ public class PDF417DecoderTestCase extends Assert {
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());
DecoderRXingResult decoderRXingResult = DecodedBitStreamParser.decode(sampleCodes, "0");
assertEquals("", decoderRXingResult.getText());
assertNotNull(decoderRXingResult.getOther());
}
@Test
@@ -118,7 +118,7 @@ public class PDF417DecoderTestCase extends Assert {
int[] sampleCodes = {23, 477, 928, 111, 100, 0, 252, 21, 86, 923, 0, 815, 251, 133, 12, 148, 537, 593,
599, 923, 1, 111, 102, 98, 311, 355, 522, 920, 779, 40, 628, 33, 749, 267, 506, 213, 928, 465, 248,
493, 72, 780, 699, 780, 493, 755, 84, 198, 628, 368, 156, 198, 809, 19, 113};
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 3, resultMetadata);
@@ -135,7 +135,7 @@ public class PDF417DecoderTestCase extends Assert {
public void testSampleWithNumericValues() throws FormatException {
int[] sampleCodes = {25, 477, 928, 111, 100, 0, 252, 21, 86, 923, 2, 2, 0, 1, 0, 0, 0, 923, 5, 130, 923,
6, 1, 500, 13, 0};
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 3, resultMetadata);
@@ -151,7 +151,7 @@ public class PDF417DecoderTestCase extends Assert {
@Test
public void testSampleWithMacroTerminatorOnly() throws FormatException {
int[] sampleCodes = {7, 477, 928, 222, 198, 0, 922};
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 3, resultMetadata);
@@ -165,14 +165,14 @@ public class PDF417DecoderTestCase extends Assert {
@Test(expected = FormatException.class)
public void testSampleWithBadSequenceIndexMacro() throws FormatException {
int[] sampleCodes = {3, 928, 222, 0};
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 2, resultMetadata);
}
@Test(expected = FormatException.class)
public void testSampleWithNoFileIdMacro() throws FormatException {
int[] sampleCodes = {4, 928, 222, 198, 0};
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 2, resultMetadata);
}
@@ -405,9 +405,9 @@ public class PDF417DecoderTestCase extends Assert {
}
}
private static void performDecodeTest(int[] codewords, String expectedResult) throws FormatException {
DecoderResult result = DecodedBitStreamParser.decode(codewords, "0");
assertEquals(expectedResult, result.getText());
private static void performDecodeTest(int[] codewords, String expectedRXingResult) throws FormatException {
DecoderRXingResult result = DecodedBitStreamParser.decode(codewords, "0");
assertEquals(expectedRXingResult, result.getText());
}
private static void performECITest(char[] chars,