Deprecate MonochromeRectangleDetector and more coverage-related improvements

This commit is contained in:
Sean Owen 2016-09-05 21:00:59 +01:00
parent 0895b3cefa
commit b639d5748d
5 changed files with 58 additions and 27 deletions

View file

@ -26,7 +26,9 @@ import com.google.zxing.common.BitMatrix;
* black. It returns the four corners of the region, as best it can determine.</p>
*
* @author Sean Owen
* @deprecated without replacement since 3.3.0
*/
@Deprecated
public final class MonochromeRectangleDetector {
private static final int MAX_MODULES = 32;

View file

@ -50,11 +50,25 @@ public final class PlanarYUVLuminanceSourceTestCase extends Assert {
public void testCrop() {
PlanarYUVLuminanceSource source =
new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 1, 1, COLS - 2, ROWS - 2, false);
assertTrue(source.isCropSupported());
byte[] cropMatrix = source.getMatrix();
for (int r = 0; r < ROWS - 2; r++) {
assertEquals(Y, (r + 1) * COLS + 1, cropMatrix, r * (COLS - 2), COLS - 2);
}
for (int r = 0; r < ROWS - 2; r++) {
assertEquals(Y, (r + 1) * COLS + 1, source.getRow(r, null), 0, COLS - 2);
}
}
@Test
public void testThumbnail() {
PlanarYUVLuminanceSource source =
new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 0, 0, COLS, ROWS, false);
assertArrayEquals(
new int[] { 0xFF000000, 0xFF010101, 0xFF030303, 0xFF000000, 0xFFFFFFFF, 0xFFFDFDFD },
source.renderThumbnail());
}
private static void assertEquals(byte[] expected, int expectedFrom,
byte[] actual, int actualFrom,
int length) {

View file

@ -16,6 +16,8 @@
package com.google.zxing.client.result;
import java.util.Locale;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Result;
import org.junit.Assert;
@ -32,18 +34,19 @@ public final class GeoParsedResultTestCase extends Assert {
@Test
public void testGeo() {
doTest("geo:1,2", 1.0, 2.0, 0.0, null);
doTest("geo:80.33,-32.3344,3.35", 80.33, -32.3344, 3.35, null);
doTest("geo:-20.33,132.3344,0.01", -20.33, 132.3344, 0.01, null);
doTest("geo:-20.33,132.3344,0.01?q=foobar", -20.33, 132.3344, 0.01, "q=foobar");
doTest("GEO:-20.33,132.3344,0.01?q=foobar", -20.33, 132.3344, 0.01, "q=foobar");
doTest("geo:1,2", 1.0, 2.0, 0.0, null, "geo:1.0,2.0");
doTest("geo:80.33,-32.3344,3.35", 80.33, -32.3344, 3.35, null, null);
doTest("geo:-20.33,132.3344,0.01", -20.33, 132.3344, 0.01, null, null);
doTest("geo:-20.33,132.3344,0.01?q=foobar", -20.33, 132.3344, 0.01, "q=foobar", null);
doTest("GEO:-20.33,132.3344,0.01?q=foobar", -20.33, 132.3344, 0.01, "q=foobar", null);
}
private static void doTest(String contents,
double latitude,
double longitude,
double altitude,
String query) {
String query,
String uri) {
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
ParsedResult result = ResultParser.parseResult(fakeResult);
assertSame(ParsedResultType.GEO, result.getType());
@ -52,6 +55,7 @@ public final class GeoParsedResultTestCase extends Assert {
assertEquals(longitude, geoResult.getLongitude(), EPSILON);
assertEquals(altitude, geoResult.getAltitude(), EPSILON);
assertEquals(query, geoResult.getQuery());
assertEquals(uri == null ? contents.toLowerCase(Locale.ENGLISH) : uri, geoResult.getGeoURI());
}
}

View file

@ -30,39 +30,37 @@ public final class SMSMMSParsedResultTestCase extends Assert {
@Test
public void testSMS() {
doTest("sms:+15551212", "+15551212", null, null, null);
doTest("sms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null);
doTest("sms:+15551212;via=999333", "+15551212", null, null, "999333");
doTest("sms:+15551212", "+15551212", null, null, null, "sms:+15551212");
doTest("sms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null,
"sms:+15551212?body=bar&subject=foo");
doTest("sms:+15551212;via=999333", "+15551212", null, null, "999333",
"sms:+15551212;via=999333");
}
@Test
public void testMMS() {
doTest("mms:+15551212", "+15551212", null, null, null);
doTest("mms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null);
doTest("mms:+15551212;via=999333", "+15551212", null, null, "999333");
doTest("mms:+15551212", "+15551212", null, null, null, "sms:+15551212");
doTest("mms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null,
"sms:+15551212?body=bar&subject=foo");
doTest("mms:+15551212;via=999333", "+15551212", null, null, "999333",
"sms:+15551212;via=999333");
}
private static void doTest(String contents,
String number,
String subject,
String body,
String via) {
doTest(contents, new String[] {number}, subject, body, new String[] {via});
}
private static void doTest(String contents,
String[] numbers,
String subject,
String body,
String[] vias) {
String via,
String parsedURI) {
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
ParsedResult result = ResultParser.parseResult(fakeResult);
assertSame(ParsedResultType.SMS, result.getType());
SMSParsedResult smsResult = (SMSParsedResult) result;
assertArrayEquals(numbers, smsResult.getNumbers());
assertArrayEquals(new String[] { number }, smsResult.getNumbers());
assertEquals(subject, smsResult.getSubject());
assertEquals(body, smsResult.getBody());
assertArrayEquals(vias, smsResult.getVias());
assertArrayEquals(new String[] { via }, smsResult.getVias());
assertEquals(parsedURI, smsResult.getSMSURI());
}
}

View file

@ -261,7 +261,20 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
}
Result result = barcodeReader.decode(source, hints);
// Try in 'pure' mode mostly to exercise PURE_BARCODE code paths for exceptions;
// not expected to pass, generally
Result result = null;
try {
Map<DecodeHintType,Object> pureHints = new EnumMap<>(hints);
pureHints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
result = barcodeReader.decode(source, pureHints);
} catch (ReaderException re) {
// continue
}
if (result == null) {
result = barcodeReader.decode(source, hints);
}
if (expectedFormat != result.getBarcodeFormat()) {
log.info(String.format("Format mismatch: expected '%s' but got '%s'%s",