diff --git a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java index e2b56311e..eaa246309 100644 --- a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java +++ b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java @@ -60,14 +60,20 @@ public abstract class AbstractBlackBoxTestCase extends TestCase { private static class TestResult { private final int mustPassCount; + private final int tryHarderCount; private final float rotation; - TestResult(int mustPassCount, float rotation) { + + TestResult(int mustPassCount, int tryHarderCount, float rotation) { this.mustPassCount = mustPassCount; + this.tryHarderCount = tryHarderCount; this.rotation = rotation; } public int getMustPassCount() { return mustPassCount; } + public int getTryHarderCount() { + return tryHarderCount; + } public float getRotation() { return rotation; } @@ -91,10 +97,11 @@ public abstract class AbstractBlackBoxTestCase extends TestCase { * Adds a new test for the current directory of images. * * @param mustPassCount The number of images which must decode for the test to pass. + * @param tryHarderCount The number of images which must pass using the try harder flag. * @param rotation The rotation in degrees clockwise to use for this test. */ - protected void addTest(int mustPassCount, float rotation) { - testResults.add(new TestResult(mustPassCount, rotation)); + protected void addTest(int mustPassCount, int tryHarderCount, float rotation) { + testResults.add(new TestResult(mustPassCount, tryHarderCount, rotation)); } protected File[] getImageFiles() { @@ -110,7 +117,9 @@ public abstract class AbstractBlackBoxTestCase extends TestCase { assertFalse(testResults.isEmpty()); File[] imageFiles = getImageFiles(); - int[] passedCounts = new int[testResults.size()]; + int testCount = testResults.size(); + int[] passedCounts = new int[testCount]; + int[] tryHarderCounts = new int[testCount]; for (File testImage : imageFiles) { System.out.println("Starting " + testImage.getAbsolutePath()); @@ -121,60 +130,59 @@ public abstract class AbstractBlackBoxTestCase extends TestCase { testImageFileName.substring(0, testImageFileName.indexOf('.')) + ".txt"); String expectedText = readFileAsString(expectedTextFile); - for (int x = 0; x < testResults.size(); x++) { - if (doTestOneImage(image, testResults.get(x).getRotation(), expectedText)) { + for (int x = 0; x < testCount; x++) { + float rotation = testResults.get(x).getRotation(); + BufferedImage rotatedImage = rotateImage(image, rotation); + MonochromeBitmapSource source = new BufferedImageMonochromeBitmapSource(rotatedImage); + if (decode(source, rotation, expectedText, false)) { passedCounts[x]++; } + if (decode(source, rotation, expectedText, true)) { + tryHarderCounts[x]++; + } } } - for (int x = 0; x < testResults.size(); x++) { - System.out.println("Rotation " + testResults.get(x).getRotation() + " degrees: " + passedCounts[x] + - " of " + imageFiles.length + " images passed (" + testResults.get(x).getMustPassCount() + + for (int x = 0; x < testCount; x++) { + System.out.println("Rotation " + testResults.get(x).getRotation() + " degrees:"); + System.out.println(" " + passedCounts[x] + " of " + imageFiles.length + " images passed (" + + testResults.get(x).getMustPassCount() + " required)"); + System.out.println(" " + tryHarderCounts[x] + " of " + imageFiles.length + + " images passed with try harder (" + testResults.get(x).getTryHarderCount() + " required)"); - assertTrue("Rotation " + testResults.get(x).getRotation() + " degrees: Too many images failed", + assertTrue("Rotation " + testResults.get(x).getRotation() + + " degrees: Too many images failed", passedCounts[x] >= testResults.get(x).getMustPassCount()); + assertTrue("Try harder, Rotation " + testResults.get(x).getRotation() + + " degrees: Too many images failed", + tryHarderCounts[x] >= testResults.get(x).getTryHarderCount()); } } - private boolean doTestOneImage(BufferedImage image, float rotationInDegrees, String expectedText) { - BufferedImage rotatedImage = rotateImage(image, rotationInDegrees); - MonochromeBitmapSource source = new BufferedImageMonochromeBitmapSource(rotatedImage); + private boolean decode(MonochromeBitmapSource source, float rotation, String expectedText, + boolean tryHarder) { Result result; + String suffix = " (" + (tryHarder ? "try harder, " : "") + "rotation: " + rotation + ')'; + try { - result = barcodeReader.decode(source); + result = barcodeReader.decode(source, tryHarder ? TRY_HARDER_HINT : null); } catch (ReaderException re) { - System.out.println(re + " (rotation: " + rotationInDegrees + ')'); + System.out.println(re + suffix); return false; } if (!expectedFormat.equals(result.getBarcodeFormat())) { System.out.println("Format mismatch: expected '" + expectedFormat + "' but got '" + - result.getBarcodeFormat() + "' (rotation: " + rotationInDegrees + ')'); + result.getBarcodeFormat() + "'" + suffix); return false; } String resultText = result.getText(); if (!expectedText.equals(resultText)) { System.out.println("Mismatch: expected '" + expectedText + "' but got '" + resultText + - "' (rotation: " + rotationInDegrees + ')'); + "'" + suffix); return false; } - - // Try "try harder" mode - try { - result = barcodeReader.decode(source, TRY_HARDER_HINT); - } catch (ReaderException re) { - fail("Normal mode succeeded but \"try harder\" failed (rotation: " + rotationInDegrees + ')'); - return false; - } - if (!expectedFormat.equals(result.getBarcodeFormat())) { - System.out.println("Try Harder Format mismatch: expected '" + expectedFormat + "' but got '" + - result.getBarcodeFormat() + "' (rotation: " + rotationInDegrees + ')'); - } else if (!expectedText.equals(resultText)) { - System.out.println("Try Harder Mismatch: expected '" + expectedText + "' but got '" + - resultText + "' (rotation: " + rotationInDegrees + ')'); - } return true; } diff --git a/core/test/src/com/google/zxing/datamatrix/DataMatrixBlackBox1TestCase.java b/core/test/src/com/google/zxing/datamatrix/DataMatrixBlackBox1TestCase.java index a8f289a67..2214374a3 100644 --- a/core/test/src/com/google/zxing/datamatrix/DataMatrixBlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/datamatrix/DataMatrixBlackBox1TestCase.java @@ -30,7 +30,7 @@ public final class DataMatrixBlackBox1TestCase extends AbstractBlackBoxTestCase public DataMatrixBlackBox1TestCase() { // TODO use MultiFormatReader here once Data Matrix decoder is done super(new File("test/data/blackbox/datamatrix-1"), new DataMatrixReader(), BarcodeFormat.DATAMATRIX); - addTest(7, 0.0f); + addTest(7, 7, 0.0f); } } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/oned/Code128BlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/Code128BlackBox1TestCase.java index 907967d7b..bb115aaf6 100644 --- a/core/test/src/com/google/zxing/oned/Code128BlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/Code128BlackBox1TestCase.java @@ -29,8 +29,8 @@ public final class Code128BlackBox1TestCase extends AbstractBlackBoxTestCase { public Code128BlackBox1TestCase() { super(new File("test/data/blackbox/code128-1"), new MultiFormatReader(), BarcodeFormat.CODE_128); - addTest(5, 0.0f); - addTest(5, 180.0f); + addTest(5, 5, 0.0f); + addTest(5, 5, 180.0f); } } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/oned/Code128BlackBox2TestCase.java b/core/test/src/com/google/zxing/oned/Code128BlackBox2TestCase.java index 3c04ff3ff..a42338a86 100644 --- a/core/test/src/com/google/zxing/oned/Code128BlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/oned/Code128BlackBox2TestCase.java @@ -29,8 +29,8 @@ public final class Code128BlackBox2TestCase extends AbstractBlackBoxTestCase { public Code128BlackBox2TestCase() { super(new File("test/data/blackbox/code128-2"), new MultiFormatReader(), BarcodeFormat.CODE_128); - addTest(33, 0.0f); - addTest(34, 180.0f); + addTest(33, 39, 0.0f); + addTest(34, 37, 180.0f); } } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/oned/Code39BlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/Code39BlackBox1TestCase.java index b120935fb..0800e73be 100644 --- a/core/test/src/com/google/zxing/oned/Code39BlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/Code39BlackBox1TestCase.java @@ -29,8 +29,8 @@ public final class Code39BlackBox1TestCase extends AbstractBlackBoxTestCase { public Code39BlackBox1TestCase() { super(new File("test/data/blackbox/code39-1"), new MultiFormatReader(), BarcodeFormat.CODE_39); - addTest(4, 0.0f); - addTest(4, 180.0f); + addTest(4, 4, 0.0f); + addTest(4, 4, 180.0f); } } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/oned/Code39BlackBox3TestCase.java b/core/test/src/com/google/zxing/oned/Code39BlackBox3TestCase.java index d898413a7..b60497f9a 100644 --- a/core/test/src/com/google/zxing/oned/Code39BlackBox3TestCase.java +++ b/core/test/src/com/google/zxing/oned/Code39BlackBox3TestCase.java @@ -29,8 +29,8 @@ public final class Code39BlackBox3TestCase extends AbstractBlackBoxTestCase { public Code39BlackBox3TestCase() { super(new File("test/data/blackbox/code39-3"), new MultiFormatReader(), BarcodeFormat.CODE_39); - addTest(17, 0.0f); - addTest(17, 180.0f); + addTest(17, 17, 0.0f); + addTest(17, 17, 180.0f); } } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/oned/Code39ExtendedBlackBox2TestCase.java b/core/test/src/com/google/zxing/oned/Code39ExtendedBlackBox2TestCase.java index a2a474f3d..f5656ad55 100644 --- a/core/test/src/com/google/zxing/oned/Code39ExtendedBlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/oned/Code39ExtendedBlackBox2TestCase.java @@ -28,8 +28,8 @@ public final class Code39ExtendedBlackBox2TestCase extends AbstractBlackBoxTestC public Code39ExtendedBlackBox2TestCase() { super(new File("test/data/blackbox/code39-2"), new Code39Reader(false, true), BarcodeFormat.CODE_39); - addTest(2, 0.0f); - addTest(2, 180.0f); + addTest(2, 2, 0.0f); + addTest(2, 2, 180.0f); } } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java index 3c02c0282..1113c16aa 100644 --- a/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java @@ -29,8 +29,8 @@ public final class EAN13BlackBox1TestCase extends AbstractBlackBoxTestCase { public EAN13BlackBox1TestCase() { super(new File("test/data/blackbox/ean13-1"), new MultiFormatReader(), BarcodeFormat.EAN_13); - addTest(26, 0.0f); - addTest(24, 180.0f); + addTest(26, 29, 0.0f); + addTest(24, 29, 180.0f); } } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/oned/EAN13BlackBox2TestCase.java b/core/test/src/com/google/zxing/oned/EAN13BlackBox2TestCase.java index 89844ddff..a96646e67 100644 --- a/core/test/src/com/google/zxing/oned/EAN13BlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/oned/EAN13BlackBox2TestCase.java @@ -29,8 +29,8 @@ public final class EAN13BlackBox2TestCase extends AbstractBlackBoxTestCase { public EAN13BlackBox2TestCase() { super(new File("test/data/blackbox/ean13-2"), new MultiFormatReader(), BarcodeFormat.EAN_13); - addTest(1, 0.0f); - addTest(1, 180.0f); + addTest(1, 1, 0.0f); + addTest(1, 1, 180.0f); } } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/oned/EAN8BlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/EAN8BlackBox1TestCase.java index e8e2b993f..f018dea12 100644 --- a/core/test/src/com/google/zxing/oned/EAN8BlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/EAN8BlackBox1TestCase.java @@ -29,8 +29,8 @@ public final class EAN8BlackBox1TestCase extends AbstractBlackBoxTestCase { public EAN8BlackBox1TestCase() { super(new File("test/data/blackbox/ean8-1"), new MultiFormatReader(), BarcodeFormat.EAN_8); - addTest(8, 0.0f); - addTest(8, 180.0f); + addTest(8, 8, 0.0f); + addTest(8, 8, 180.0f); } } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/oned/UPCABlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/UPCABlackBox1TestCase.java index 1414f574f..48663bd6b 100644 --- a/core/test/src/com/google/zxing/oned/UPCABlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/UPCABlackBox1TestCase.java @@ -29,8 +29,8 @@ public final class UPCABlackBox1TestCase extends AbstractBlackBoxTestCase { public UPCABlackBox1TestCase() { super(new File("test/data/blackbox/upca-1"), new MultiFormatReader(), BarcodeFormat.UPC_A); - addTest(15, 0.0f); - addTest(16, 180.0f); + addTest(15, 17, 0.0f); + addTest(16, 19, 180.0f); } } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/oned/UPCABlackBox2TestCase.java b/core/test/src/com/google/zxing/oned/UPCABlackBox2TestCase.java index 502d12087..60c387b8a 100644 --- a/core/test/src/com/google/zxing/oned/UPCABlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/oned/UPCABlackBox2TestCase.java @@ -29,8 +29,8 @@ public final class UPCABlackBox2TestCase extends AbstractBlackBoxTestCase { public UPCABlackBox2TestCase() { super(new File("test/data/blackbox/upca-2"), new MultiFormatReader(), BarcodeFormat.UPC_A); - addTest(26, 0.0f); - addTest(25, 180.0f); + addTest(26, 35, 0.0f); + addTest(25, 35, 180.0f); } } diff --git a/core/test/src/com/google/zxing/oned/UPCEBlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/UPCEBlackBox1TestCase.java index fb5ccb5bd..7d78e0533 100644 --- a/core/test/src/com/google/zxing/oned/UPCEBlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/UPCEBlackBox1TestCase.java @@ -29,8 +29,8 @@ public final class UPCEBlackBox1TestCase extends AbstractBlackBoxTestCase { public UPCEBlackBox1TestCase() { super(new File("test/data/blackbox/upce-1"), new MultiFormatReader(), BarcodeFormat.UPC_E); - addTest(3, 0.0f); - addTest(3, 180.0f); + addTest(3, 3, 0.0f); + addTest(3, 3, 180.0f); } } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox1TestCase.java b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox1TestCase.java index 3a2786762..c181453aa 100644 --- a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox1TestCase.java @@ -29,10 +29,10 @@ public final class QRCodeBlackBox1TestCase extends AbstractBlackBoxTestCase { public QRCodeBlackBox1TestCase() { super(new File("test/data/blackbox/qrcode-1"), new MultiFormatReader(), BarcodeFormat.QR_CODE); - addTest(18, 0.0f); - addTest(14, 90.0f); - addTest(18, 180.0f); - addTest(14, 270.0f); + addTest(18, 18, 0.0f); + addTest(14, 14, 90.0f); + addTest(18, 18, 180.0f); + addTest(14, 14, 270.0f); } } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java index ffe3485bb..ae99176ab 100644 --- a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java @@ -29,10 +29,10 @@ public final class QRCodeBlackBox2TestCase extends AbstractBlackBoxTestCase { public QRCodeBlackBox2TestCase() { super(new File("test/data/blackbox/qrcode-2"), new MultiFormatReader(), BarcodeFormat.QR_CODE); - addTest(10, 0.0f); - addTest(6, 90.0f); - addTest(9, 180.0f); - addTest(7, 270.0f); + addTest(10, 10, 0.0f); + addTest(6, 6, 90.0f); + addTest(9, 9, 180.0f); + addTest(7, 7, 270.0f); } } \ No newline at end of file