use of com.google.zxing.Result in project zxing by zxing.
the class RSSExpandedStackedInternalTestCase method testCompleteDecode.
@Test
public void testCompleteDecode() throws Exception {
OneDReader rssExpandedReader = new RSSExpandedReader();
BinaryBitmap binaryMap = TestCaseUtil.getBinaryBitmap("src/test/resources/blackbox/rssexpandedstacked-2/1000.png");
Result result = rssExpandedReader.decode(binaryMap);
assertEquals("(01)98898765432106(3202)012345(15)991231", result.getText());
}
use of com.google.zxing.Result in project zxing by zxing.
the class DecodeWorker method dumpResult.
private static void dumpResult(URI input, Result... results) throws IOException {
Collection<String> resultTexts = new ArrayList<>();
for (Result result : results) {
resultTexts.add(result.getText());
}
Files.write(buildOutputPath(input, ".txt"), resultTexts, StandardCharsets.UTF_8);
}
use of com.google.zxing.Result in project zxing by zxing.
the class URIParsedResultTestCase method doTestNotUri.
private static void doTestNotUri(String text) {
Result fakeResult = new Result(text, null, null, BarcodeFormat.QR_CODE);
ParsedResult result = ResultParser.parseResult(fakeResult);
assertSame(ParsedResultType.TEXT, result.getType());
assertEquals(text, result.getDisplayResult());
}
use of com.google.zxing.Result in project zxing by zxing.
the class WifiParsedResultTestCase method doTest.
/**
* Given the string contents for the barcode, check that it matches our expectations
*/
private static void doTest(String contents, String ssid, String password, String type) {
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
ParsedResult result = ResultParser.parseResult(fakeResult);
// Ensure it is a wifi code
assertSame(ParsedResultType.WIFI, result.getType());
WifiParsedResult wifiResult = (WifiParsedResult) result;
assertEquals(ssid, wifiResult.getSsid());
assertEquals(password, wifiResult.getPassword());
assertEquals(type, wifiResult.getNetworkEncryption());
}
use of com.google.zxing.Result in project zxing by zxing.
the class AbstractBlackBoxTestCase method decode.
private boolean decode(BinaryBitmap source, float rotation, String expectedText, Map<?, ?> expectedMetadata, boolean tryHarder) throws ReaderException {
String suffix = String.format(" (%srotation: %d)", tryHarder ? "try harder, " : "", (int) rotation);
Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
if (tryHarder) {
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
}
// 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", expectedFormat, result.getBarcodeFormat(), suffix));
return false;
}
String resultText = result.getText();
if (!expectedText.equals(resultText)) {
log.info(String.format("Content mismatch: expected '%s' but got '%s'%s", expectedText, resultText, suffix));
return false;
}
Map<ResultMetadataType, ?> resultMetadata = result.getResultMetadata();
for (Map.Entry<?, ?> metadatum : expectedMetadata.entrySet()) {
ResultMetadataType key = ResultMetadataType.valueOf(metadatum.getKey().toString());
Object expectedValue = metadatum.getValue();
Object actualValue = resultMetadata == null ? null : resultMetadata.get(key);
if (!expectedValue.equals(actualValue)) {
log.info(String.format("Metadata mismatch for key '%s': expected '%s' but got '%s'", key, expectedValue, actualValue));
return false;
}
}
return true;
}
Aggregations