Changed the black box tests to require an absolute number of images to decode successfully, instead of a percentage, and set the high water mark for each test.

git-svn-id: https://zxing.googlecode.com/svn/trunk@367 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dswitkin 2008-04-18 14:43:56 +00:00
parent a816d5d9b1
commit a2662ebb40
11 changed files with 24 additions and 22 deletions

View file

@ -49,8 +49,7 @@ public abstract class AbstractBlackBoxTestCase extends TestCase {
private static final FilenameFilter IMAGE_NAME_FILTER = new FilenameFilter() { private static final FilenameFilter IMAGE_NAME_FILTER = new FilenameFilter() {
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
String lowerCase = name.toLowerCase(); String lowerCase = name.toLowerCase();
return return lowerCase.endsWith(".jpg") || lowerCase.endsWith(".jpeg") ||
lowerCase.endsWith(".jpg") || lowerCase.endsWith(".jpeg") ||
lowerCase.endsWith(".gif") || lowerCase.endsWith(".png") || lowerCase.endsWith(".gif") || lowerCase.endsWith(".png") ||
lowerCase.endsWith(".url"); lowerCase.endsWith(".url");
} }
@ -58,16 +57,16 @@ public abstract class AbstractBlackBoxTestCase extends TestCase {
private final File testBase; private final File testBase;
private final Reader barcodeReader; private final Reader barcodeReader;
private final double passPercent; private final int mustPassCount;
private final BarcodeFormat expectedFormat; private final BarcodeFormat expectedFormat;
protected AbstractBlackBoxTestCase(File testBase, protected AbstractBlackBoxTestCase(File testBase,
Reader barcodeReader, Reader barcodeReader,
double passPercent, int mustPassCount,
BarcodeFormat expectedFormat) { BarcodeFormat expectedFormat) {
this.testBase = testBase; this.testBase = testBase;
this.barcodeReader = barcodeReader; this.barcodeReader = barcodeReader;
this.passPercent = passPercent; this.mustPassCount = mustPassCount;
this.expectedFormat = expectedFormat; this.expectedFormat = expectedFormat;
} }
@ -99,8 +98,8 @@ public abstract class AbstractBlackBoxTestCase extends TestCase {
assertEquals(expectedFormat, result.getBarcodeFormat()); assertEquals(expectedFormat, result.getBarcodeFormat());
String testImageFileName = testImage.getName(); String testImageFileName = testImage.getName();
File expectedTextFile = File expectedTextFile = new File(testBase,
new File(testBase, testImageFileName.substring(0, testImageFileName.indexOf('.')) + ".txt"); testImageFileName.substring(0, testImageFileName.indexOf('.')) + ".txt");
String expectedText = readFileAsString(expectedTextFile); String expectedText = readFileAsString(expectedTextFile);
String resultText = result.getText(); String resultText = result.getText();
@ -116,16 +115,19 @@ public abstract class AbstractBlackBoxTestCase extends TestCase {
result = barcodeReader.decode(source, TRY_HARDER_HINT); result = barcodeReader.decode(source, TRY_HARDER_HINT);
} catch (ReaderException re) { } catch (ReaderException re) {
if (passed) { if (passed) {
fail("Normal mode succeed but \"try harder\" failed"); fail("Normal mode succeeded but \"try harder\" failed");
} }
continue; continue;
} }
assertEquals("Normal mode succeed but \"try harder\" failed", expectedFormat, result.getBarcodeFormat()); assertEquals("Normal mode succeeded but \"try harder\" failed", expectedFormat,
assertEquals("Normal mode succeed but \"try harder\" failed", expectedText, result.getText()); result.getBarcodeFormat());
assertEquals("Normal mode succeeded but \"try harder\" failed", expectedText,
result.getText());
} }
System.out.println(passedCount + " of " + imageFiles.length + " images passed"); System.out.println(passedCount + " of " + imageFiles.length + " images passed (" +
assertTrue("Too many images failed", passedCount >= (int) (imageFiles.length * passPercent)); mustPassCount + " required)");
assertTrue("Too many images failed", passedCount >= mustPassCount);
} }
private static String readFileAsString(File file) throws IOException { private static String readFileAsString(File file) throws IOException {

View file

@ -29,7 +29,7 @@ public final class DataMatrixBlackBox1TestCase extends AbstractBlackBoxTestCase
public DataMatrixBlackBox1TestCase() { public DataMatrixBlackBox1TestCase() {
// TODO use MultiFormatReader here once Data Matrix decoder is done // TODO use MultiFormatReader here once Data Matrix decoder is done
super(new File("test/data/blackbox/datamatrix-1"), new DataMatrixReader(), 1.0, BarcodeFormat.DATAMATRIX); super(new File("test/data/blackbox/datamatrix-1"), new DataMatrixReader(), 7, BarcodeFormat.DATAMATRIX);
} }
} }

View file

@ -28,7 +28,7 @@ import java.io.File;
public final class Code128BlackBox1TestCase extends AbstractBlackBoxTestCase { public final class Code128BlackBox1TestCase extends AbstractBlackBoxTestCase {
public Code128BlackBox1TestCase() { public Code128BlackBox1TestCase() {
super(new File("test/data/blackbox/code128-1"), new MultiFormatReader(), 1.0, BarcodeFormat.CODE_128); super(new File("test/data/blackbox/code128-1"), new MultiFormatReader(), 5, BarcodeFormat.CODE_128);
} }
} }

View file

@ -28,7 +28,7 @@ import java.io.File;
public final class Code39BlackBox1TestCase extends AbstractBlackBoxTestCase { public final class Code39BlackBox1TestCase extends AbstractBlackBoxTestCase {
public Code39BlackBox1TestCase() { public Code39BlackBox1TestCase() {
super(new File("test/data/blackbox/code39-1"), new MultiFormatReader(), 1.0, BarcodeFormat.CODE_39); super(new File("test/data/blackbox/code39-1"), new MultiFormatReader(), 4, BarcodeFormat.CODE_39);
} }
} }

View file

@ -27,7 +27,7 @@ import java.io.File;
public final class Code39ExtendedBlackBox2TestCase extends AbstractBlackBoxTestCase { public final class Code39ExtendedBlackBox2TestCase extends AbstractBlackBoxTestCase {
public Code39ExtendedBlackBox2TestCase() { public Code39ExtendedBlackBox2TestCase() {
super(new File("test/data/blackbox/code39-2"), new Code39Reader(false, true), 1.0, BarcodeFormat.CODE_39); super(new File("test/data/blackbox/code39-2"), new Code39Reader(false, true), 2, BarcodeFormat.CODE_39);
} }
} }

View file

@ -28,7 +28,7 @@ import java.io.File;
public final class EAN13BlackBox1TestCase extends AbstractBlackBoxTestCase { public final class EAN13BlackBox1TestCase extends AbstractBlackBoxTestCase {
public EAN13BlackBox1TestCase() { public EAN13BlackBox1TestCase() {
super(new File("test/data/blackbox/ean13-1"), new MultiFormatReader(), 0.66, BarcodeFormat.EAN_13); super(new File("test/data/blackbox/ean13-1"), new MultiFormatReader(), 25, BarcodeFormat.EAN_13);
} }
} }

View file

@ -28,7 +28,7 @@ import java.io.File;
public final class EAN8BlackBox1TestCase extends AbstractBlackBoxTestCase { public final class EAN8BlackBox1TestCase extends AbstractBlackBoxTestCase {
public EAN8BlackBox1TestCase() { public EAN8BlackBox1TestCase() {
super(new File("test/data/blackbox/ean8-1"), new MultiFormatReader(), 1.0, BarcodeFormat.EAN_8); super(new File("test/data/blackbox/ean8-1"), new MultiFormatReader(), 8, BarcodeFormat.EAN_8);
} }
} }

View file

@ -28,7 +28,7 @@ import java.io.File;
public final class UPCABlackBox1TestCase extends AbstractBlackBoxTestCase { public final class UPCABlackBox1TestCase extends AbstractBlackBoxTestCase {
public UPCABlackBox1TestCase() { public UPCABlackBox1TestCase() {
super(new File("test/data/blackbox/upca-1"), new MultiFormatReader(), 0.5, BarcodeFormat.UPC_A); super(new File("test/data/blackbox/upca-1"), new MultiFormatReader(), 14, BarcodeFormat.UPC_A);
} }
} }

View file

@ -28,7 +28,7 @@ import java.io.File;
public final class UPCEBlackBox1TestCase extends AbstractBlackBoxTestCase { public final class UPCEBlackBox1TestCase extends AbstractBlackBoxTestCase {
public UPCEBlackBox1TestCase() { public UPCEBlackBox1TestCase() {
super(new File("test/data/blackbox/upce-1"), new MultiFormatReader(), 1.0, BarcodeFormat.UPC_E); super(new File("test/data/blackbox/upce-1"), new MultiFormatReader(), 3, BarcodeFormat.UPC_E);
} }
} }

View file

@ -28,7 +28,7 @@ import java.io.File;
public final class QRCodeBlackBox1TestCase extends AbstractBlackBoxTestCase { public final class QRCodeBlackBox1TestCase extends AbstractBlackBoxTestCase {
public QRCodeBlackBox1TestCase() { public QRCodeBlackBox1TestCase() {
super(new File("test/data/blackbox/qrcode-1"), new MultiFormatReader(), 0.5, BarcodeFormat.QR_CODE); super(new File("test/data/blackbox/qrcode-1"), new MultiFormatReader(), 16, BarcodeFormat.QR_CODE);
} }
} }

View file

@ -28,7 +28,7 @@ import java.io.File;
public final class QRCodeBlackBox2TestCase extends AbstractBlackBoxTestCase { public final class QRCodeBlackBox2TestCase extends AbstractBlackBoxTestCase {
public QRCodeBlackBox2TestCase() { public QRCodeBlackBox2TestCase() {
super(new File("test/data/blackbox/qrcode-2"), new MultiFormatReader(), 1.0, BarcodeFormat.QR_CODE); super(new File("test/data/blackbox/qrcode-2"), new MultiFormatReader(), 10, BarcodeFormat.QR_CODE);
} }
} }