+ File expectedMetadataFile = new File(testBase, fileBaseName + ".metadata.txt");
+ Properties expectedMetadata = new Properties();
+ if (expectedMetadataFile.exists()) {
+ expectedMetadata.load(new FileInputStream(expectedMetadataFile));
+ }
+
+ for (int x = 0; x < testCount; x++) {
+ float rotation = testResults.get(x).getRotation();
+ BufferedImage rotatedImage = rotateImage(image, rotation);
+ LuminanceSource source = new BufferedImageLuminanceSource(rotatedImage);
+ BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
+ if (decode(bitmap, rotation, expectedText, expectedMetadata, false)) {
+ passedCounts[x]++;
+ }
+ if (decode(bitmap, rotation, expectedText, expectedMetadata, true)) {
+ tryHarderCounts[x]++;
+ }
+ }
+ }
+
+ // Print the results of all tests first
+ int totalFound = 0;
+ int totalMustPass = 0;
+ 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)");
+ totalFound += passedCounts[x];
+ totalFound += tryHarderCounts[x];
+ totalMustPass += testResults.get(x).getMustPassCount();
+ totalMustPass += testResults.get(x).getTryHarderCount();
+ }
+
+ int totalTests = imageFiles.length * testCount * 2;
+ System.out.println("TOTALS:\n Decoded " + totalFound + " images out of " + totalTests +
+ " (" + (totalFound * 100 / totalTests) + "%, " + totalMustPass + " required)");
+ if (totalFound > totalMustPass) {
+ System.out.println(" *** Test too lax by " + (totalFound - totalMustPass) + " images");
+ } else if (totalFound < totalMustPass) {
+ System.out.println(" *** Test failed by " + (totalMustPass - totalFound) + " images");
+ }
+
+ // Then run through again and assert if any failed
+ if (assertOnFailure) {
+ for (int x = 0; x < testCount; x++) {
+ 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());
+ }
+ }
+ return new SummaryResults(totalFound, totalMustPass, totalTests);
+ }
+
+ private boolean decode(BinaryBitmap source,
+ float rotation,
+ String expectedText,
+ Properties expectedMetadata,
+ boolean tryHarder) {
+ Result result;
+ String suffix = " (" + (tryHarder ? "try harder, " : "") + "rotation: " + rotation + ')';
+
+ try {
+ Hashtable<DecodeHintType, Object> hints = getHints();
+ if (tryHarder) {
+ if (hints == null) {
+ hints = TRY_HARDER_HINT;
+ } else {
+ hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
+ }