File indexing completed on 2024-05-05 04:00:57
0001 /* 0002 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #include <Prison/Barcode> 0008 0009 #include <QObject> 0010 #include <QTest> 0011 0012 using namespace Prison; 0013 0014 class QrTest : public QObject 0015 { 0016 Q_OBJECT 0017 private Q_SLOTS: 0018 void testRenderText_data() 0019 { 0020 QTest::addColumn<QString>("input"); 0021 QTest::addColumn<QString>("refName"); 0022 0023 QTest::newRow("text") << QStringLiteral("KF5::Prison") << "qr-text.png"; 0024 } 0025 0026 void testRenderText() 0027 { 0028 QFETCH(QString, input); 0029 QFETCH(QString, refName); 0030 0031 auto code = Prison::Barcode::create(Prison::QRCode); 0032 QVERIFY(code); 0033 code->setData(input); 0034 const auto img = code->toImage(code->preferredSize(1)); 0035 img.save(refName); 0036 0037 QImage ref(QStringLiteral(":/qr/") + refName); 0038 ref = ref.convertToFormat(img.format()); 0039 QCOMPARE(img, ref); 0040 } 0041 0042 void testRenderBinary_data() 0043 { 0044 QTest::addColumn<QByteArray>("input"); 0045 QTest::addColumn<QString>("refName"); 0046 0047 QTest::newRow("text") << QByteArray("KF5::Prison") << "qr-text.png"; 0048 QTest::newRow("binary") << QByteArray("KDE\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9kde", 16) << "qr-binary.png"; 0049 } 0050 0051 void testRenderBinary() 0052 { 0053 QFETCH(QByteArray, input); 0054 QFETCH(QString, refName); 0055 0056 auto code = Prison::Barcode::create(Prison::QRCode); 0057 QVERIFY(code); 0058 code->setData(input); 0059 const auto img = code->toImage(code->preferredSize(1)); 0060 img.save(refName); 0061 0062 QImage ref(QStringLiteral(":/qr/") + refName); 0063 ref = ref.convertToFormat(img.format()); 0064 QCOMPARE(img, ref); 0065 } 0066 }; 0067 0068 QTEST_APPLESS_MAIN(QrTest) 0069 0070 #include "qrtest.moc"