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 DataMatrixTest : public QObject 0015 { 0016 Q_OBJECT 0017 private Q_SLOTS: 0018 void testRender_data() 0019 { 0020 QTest::addColumn<QByteArray>("input"); 0021 QTest::addColumn<QString>("refName"); 0022 0023 QTest::newRow("text") << QByteArray("KF5::Prison") << "datamatrix-text.png"; 0024 QTest::newRow("binary") << QByteArray("KDE\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9kde", 16) << "datamatrix-binary.png"; 0025 } 0026 0027 void testRender() 0028 { 0029 QFETCH(QByteArray, input); 0030 QFETCH(QString, refName); 0031 0032 { 0033 std::unique_ptr<Prison::AbstractBarcode> code(Prison::createBarcode(Prison::DataMatrix)); 0034 code->setData(QString::fromLatin1(input.constData(), input.size())); 0035 const auto img = code->toImage(code->preferredSize(1)); 0036 img.save(refName); 0037 0038 QImage ref(QStringLiteral(":/datamatrix/") + refName); 0039 ref = ref.convertToFormat(img.format()); 0040 QCOMPARE(img, ref); 0041 } 0042 { 0043 std::unique_ptr<Prison::AbstractBarcode> code(Prison::createBarcode(Prison::DataMatrix)); 0044 code->setData(input); 0045 const auto img = code->toImage(code->preferredSize(1)); 0046 img.save(refName); 0047 0048 QImage ref(QStringLiteral(":/datamatrix/") + refName); 0049 ref = ref.convertToFormat(img.format()); 0050 QCOMPARE(img, ref); 0051 } 0052 } 0053 }; 0054 0055 QTEST_APPLESS_MAIN(DataMatrixTest) 0056 0057 #include "datamatrixtest.moc"