mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
Deprecate MonochromeRectangleDetector and more coverage-related improvements
This commit is contained in:
parent
0895b3cefa
commit
b639d5748d
|
@ -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>
|
* black. It returns the four corners of the region, as best it can determine.</p>
|
||||||
*
|
*
|
||||||
* @author Sean Owen
|
* @author Sean Owen
|
||||||
|
* @deprecated without replacement since 3.3.0
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public final class MonochromeRectangleDetector {
|
public final class MonochromeRectangleDetector {
|
||||||
|
|
||||||
private static final int MAX_MODULES = 32;
|
private static final int MAX_MODULES = 32;
|
||||||
|
|
|
@ -49,10 +49,24 @@ public final class PlanarYUVLuminanceSourceTestCase extends Assert {
|
||||||
@Test
|
@Test
|
||||||
public void testCrop() {
|
public void testCrop() {
|
||||||
PlanarYUVLuminanceSource source =
|
PlanarYUVLuminanceSource source =
|
||||||
new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 1, 1, COLS-2, ROWS-2, false);
|
new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 1, 1, COLS - 2, ROWS - 2, false);
|
||||||
for (int r = 0; r < ROWS-2; r++) {
|
assertTrue(source.isCropSupported());
|
||||||
assertEquals(Y, (r + 1) * COLS + 1, source.getRow(r, null), 0, COLS-2);
|
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,
|
private static void assertEquals(byte[] expected, int expectedFrom,
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package com.google.zxing.client.result;
|
package com.google.zxing.client.result;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.Result;
|
import com.google.zxing.Result;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -32,18 +34,19 @@ public final class GeoParsedResultTestCase extends Assert {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGeo() {
|
public void testGeo() {
|
||||||
doTest("geo:1,2", 1.0, 2.0, 0.0, null);
|
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);
|
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);
|
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");
|
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");
|
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,
|
private static void doTest(String contents,
|
||||||
double latitude,
|
double latitude,
|
||||||
double longitude,
|
double longitude,
|
||||||
double altitude,
|
double altitude,
|
||||||
String query) {
|
String query,
|
||||||
|
String uri) {
|
||||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||||
assertSame(ParsedResultType.GEO, result.getType());
|
assertSame(ParsedResultType.GEO, result.getType());
|
||||||
|
@ -52,6 +55,7 @@ public final class GeoParsedResultTestCase extends Assert {
|
||||||
assertEquals(longitude, geoResult.getLongitude(), EPSILON);
|
assertEquals(longitude, geoResult.getLongitude(), EPSILON);
|
||||||
assertEquals(altitude, geoResult.getAltitude(), EPSILON);
|
assertEquals(altitude, geoResult.getAltitude(), EPSILON);
|
||||||
assertEquals(query, geoResult.getQuery());
|
assertEquals(query, geoResult.getQuery());
|
||||||
|
assertEquals(uri == null ? contents.toLowerCase(Locale.ENGLISH) : uri, geoResult.getGeoURI());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -30,39 +30,37 @@ public final class SMSMMSParsedResultTestCase extends Assert {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSMS() {
|
public void testSMS() {
|
||||||
doTest("sms:+15551212", "+15551212", null, null, null);
|
doTest("sms:+15551212", "+15551212", null, null, null, "sms:+15551212");
|
||||||
doTest("sms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null);
|
doTest("sms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null,
|
||||||
doTest("sms:+15551212;via=999333", "+15551212", null, null, "999333");
|
"sms:+15551212?body=bar&subject=foo");
|
||||||
|
doTest("sms:+15551212;via=999333", "+15551212", null, null, "999333",
|
||||||
|
"sms:+15551212;via=999333");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMMS() {
|
public void testMMS() {
|
||||||
doTest("mms:+15551212", "+15551212", null, null, null);
|
doTest("mms:+15551212", "+15551212", null, null, null, "sms:+15551212");
|
||||||
doTest("mms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null);
|
doTest("mms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null,
|
||||||
doTest("mms:+15551212;via=999333", "+15551212", null, null, "999333");
|
"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,
|
private static void doTest(String contents,
|
||||||
String number,
|
String number,
|
||||||
String subject,
|
String subject,
|
||||||
String body,
|
String body,
|
||||||
String via) {
|
String via,
|
||||||
doTest(contents, new String[] {number}, subject, body, new String[] {via});
|
String parsedURI) {
|
||||||
}
|
|
||||||
|
|
||||||
private static void doTest(String contents,
|
|
||||||
String[] numbers,
|
|
||||||
String subject,
|
|
||||||
String body,
|
|
||||||
String[] vias) {
|
|
||||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||||
assertSame(ParsedResultType.SMS, result.getType());
|
assertSame(ParsedResultType.SMS, result.getType());
|
||||||
SMSParsedResult smsResult = (SMSParsedResult) result;
|
SMSParsedResult smsResult = (SMSParsedResult) result;
|
||||||
assertArrayEquals(numbers, smsResult.getNumbers());
|
assertArrayEquals(new String[] { number }, smsResult.getNumbers());
|
||||||
assertEquals(subject, smsResult.getSubject());
|
assertEquals(subject, smsResult.getSubject());
|
||||||
assertEquals(body, smsResult.getBody());
|
assertEquals(body, smsResult.getBody());
|
||||||
assertArrayEquals(vias, smsResult.getVias());
|
assertArrayEquals(new String[] { via }, smsResult.getVias());
|
||||||
|
assertEquals(parsedURI, smsResult.getSMSURI());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,7 +261,20 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||||
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
|
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()) {
|
if (expectedFormat != result.getBarcodeFormat()) {
|
||||||
log.info(String.format("Format mismatch: expected '%s' but got '%s'%s",
|
log.info(String.format("Format mismatch: expected '%s' but got '%s'%s",
|
||||||
|
|
Loading…
Reference in a new issue