File indexing completed on 2024-05-05 16:21:36

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #include <prison.h>
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         std::unique_ptr<Prison::AbstractBarcode> code(Prison::createBarcode(Prison::QRCode));
0032         code->setData(input);
0033         const auto img = code->toImage(code->preferredSize(1));
0034         img.save(refName);
0035 
0036         QImage ref(QStringLiteral(":/qr/") + refName);
0037         ref = ref.convertToFormat(img.format());
0038         QCOMPARE(img, ref);
0039     }
0040 
0041     void testRenderBinary_data()
0042     {
0043         QTest::addColumn<QByteArray>("input");
0044         QTest::addColumn<QString>("refName");
0045 
0046         QTest::newRow("text") << QByteArray("KF5::Prison") << "qr-text.png";
0047         QTest::newRow("binary") << QByteArray("KDE\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9kde", 16) << "qr-binary.png";
0048     }
0049 
0050     void testRenderBinary()
0051     {
0052         QFETCH(QByteArray, input);
0053         QFETCH(QString, refName);
0054 
0055         std::unique_ptr<Prison::AbstractBarcode> code(Prison::createBarcode(Prison::QRCode));
0056         code->setData(input);
0057         const auto img = code->toImage(code->preferredSize(1));
0058         img.save(refName);
0059 
0060         QImage ref(QStringLiteral(":/qr/") + refName);
0061         ref = ref.convertToFormat(img.format());
0062         QCOMPARE(img, ref);
0063     }
0064 };
0065 
0066 QTEST_APPLESS_MAIN(QrTest)
0067 
0068 #include "qrtest.moc"