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 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 auto code = Prison::Barcode::create(Prison::DataMatrix); 0034 QVERIFY(code); 0035 code->setData(QString::fromLatin1(input.constData(), input.size())); 0036 const auto img = code->toImage(code->preferredSize(1)); 0037 img.save(refName); 0038 0039 QImage ref(QStringLiteral(":/datamatrix/") + refName); 0040 ref = ref.convertToFormat(img.format()); 0041 QCOMPARE(img, ref); 0042 } 0043 { 0044 auto code = Prison::Barcode::create(Prison::DataMatrix); 0045 QVERIFY(code); 0046 code->setData(input); 0047 const auto img = code->toImage(code->preferredSize(1)); 0048 img.save(refName); 0049 0050 QImage ref(QStringLiteral(":/datamatrix/") + refName); 0051 ref = ref.convertToFormat(img.format()); 0052 QCOMPARE(img, ref); 0053 } 0054 } 0055 }; 0056 0057 QTEST_APPLESS_MAIN(DataMatrixTest) 0058 0059 #include "datamatrixtest.moc"