From f5f363b22fbebbb95eefecf0aadf092c9a129140 Mon Sep 17 00:00:00 2001 From: gitlost Date: Fri, 26 Nov 2021 12:20:54 +0000 Subject: [PATCH] Add a test that checks the qZint generated barcodes are equal to those generated by libzint. Whether or not those barcodes are correct should be validated in the test suite for libzint, for qZint it's good enough to produce the same printouts that libzint does, which isn't trivial, especially as some API names have different meanings, such as qZint ```text``` is libzint ```data```. Props Alonso Schaich --- backend_qt/tests/test_qzint.cpp | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/backend_qt/tests/test_qzint.cpp b/backend_qt/tests/test_qzint.cpp index 9d58c993..40d8653b 100644 --- a/backend_qt/tests/test_qzint.cpp +++ b/backend_qt/tests/test_qzint.cpp @@ -910,6 +910,54 @@ private slots: QCOMPARE(cmd, expected_barcodeNames); } } + + void qZintAndLibZintEqual_data() + { + QTest::addColumn("symbology"); + QTest::addColumn("rotateAngles"); + QTest::addColumn("text"); + + QTest::newRow("symbology=BARCODE_DATAMATRIX rotateAngles=0 text=1234") << BARCODE_DATAMATRIX << 0 << "1234"; + QTest::newRow("symbology=BARCODE_QRCODE rotateAngles=0 text=Hello%20World") << BARCODE_QRCODE << 0 << "Hello%20World"; + QTest::newRow("symbology=BARCODE_QRCODE rotateAngles=90 text=Hello%20World") << BARCODE_QRCODE << 90 << "Hello%20World"; + QTest::newRow("symbology=BARCODE_QRCODE rotateAngles=180 text=Hello%20World") << BARCODE_QRCODE << 180 << "Hello%20World"; + QTest::newRow("symbology=BARCODE_QRCODE rotateAngles=270 text=Hello%20World") << BARCODE_QRCODE << 270 << "Hello%20World"; + } + + void qZintAndLibZintEqual() + { + QFETCH(int, symbology); + QFETCH(int, rotateAngles); + QFETCH(QString, text); + QString fileName("test_qZintAndLibZintEqual_%1.gif"); + QString fileNameForLibZint(fileName.arg("libZint")); + QString fileNameForQZint(fileName.arg("qZint")); + + Zint::QZint bc; + QSharedPointer symbol(ZBarcode_Create(), ZBarcode_Delete); + + bc.setSymbol(symbology); + symbol->symbology = symbology; + + bc.setText(text); + bc.setRotateAngleValue(rotateAngles); + + qstrcpy(symbol->outfile, qUtf8Printable(fileNameForLibZint)); + + bc.save_to_file(fileNameForQZint); + ZBarcode_Encode_and_Print(symbol.data(), reinterpret_cast(qUtf8Printable(text)), 0, rotateAngles); + + QImage imageWrittenByVanilla(fileNameForLibZint); + QImage imageWrittenByQZint(fileNameForQZint); + + QCOMPARE(imageWrittenByQZint.isNull(), false); + QCOMPARE(imageWrittenByVanilla.isNull(), false); + + QCOMPARE(imageWrittenByQZint == imageWrittenByVanilla, true); + + QFile::remove(fileNameForLibZint); + QFile::remove(fileNameForQZint); + } }; QTEST_MAIN(TestQZint)