diff --git a/autotests/barcodedecodertest.cpp b/autotests/barcodedecodertest.cpp --- a/autotests/barcodedecodertest.cpp +++ b/autotests/barcodedecodertest.cpp @@ -72,6 +72,29 @@ QVERIFY(b.startsWith("OTI010080000020")); #endif } + + void testQRCode_data() + { + QTest::addColumn("fileName"); + QTest::addColumn("result"); + + QTest::newRow("1") << QStringLiteral("qrcode1.png") << QStringLiteral("M$K0YGV0G"); + QTest::newRow("2") << QStringLiteral("qrcode2.png") << QStringLiteral("KZEXO4HRE"); + } + + void testQRCode() + { + QFETCH(QString, fileName); + QFETCH(QString, result); + + QImage img(QStringLiteral(SOURCE_DIR "/barcodes/") + fileName); + QVERIFY(!img.isNull()); + +#ifdef HAVE_ZXING + QCOMPARE(BarcodeDecoder::decodeQRCode(img), result); +#endif + + } }; QTEST_APPLESS_MAIN(BarcodeDecoderTest) diff --git a/autotests/barcodes/qrcode1.png b/autotests/barcodes/qrcode1.png new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ source(new QImageLuminanceSource(img)); + + const zxing::Ref binarizer(new zxing::HybridBinarizer(source)); + const zxing::Ref binary(new zxing::BinaryBitmap(binarizer)); + const zxing::DecodeHints hints(zxing::DecodeHints::QR_CODE_HINT); + + zxing::MultiFormatReader reader; + const auto result = reader.decode(binary, hints); + return QString::fromStdString(result->getText()->getText()); + } catch (const std::exception &e) { + //qCDebug(Log) << e.what(); + } +#else + Q_UNUSED(img); +#endif + return {}; +}