mirror of
https://git.code.sf.net/p/zint/code
synced 2026-01-09 21:15:57 +00:00
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION MAILMARK: fuller error messages CODABAR: add option to show check character in HRT zint.h: use 0xNNNN for OR-able defines GUI: add guard descent height reset button, add Zint version to window title, static get_zint_version() method, use QStringLiteral (QSL shorthand), use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons, add saveAs shortcut, add main menu, context menus and actions, add help, reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF, lessen triggering of update_preview(), shorten names of getters/setters, simplify/shorten some update_preview() logic in switch, CODEONE disable structapp for Version S qzint.cpp: add on_errored signal, add missing getters, add test
This commit is contained in:
@@ -21,6 +21,9 @@ target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/backend")
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} zint Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Gui)
|
||||
|
||||
if(ZINT_TEST AND NOT WIN32) # Fails with "Test not available without configuration" on Windows so skip
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
install(TARGETS ${PROJECT_NAME} ${INSTALL_TARGETS_DEFAULT_ARGS})
|
||||
install(FILES qzint.h DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel)
|
||||
|
||||
@@ -65,6 +65,7 @@ namespace Zint {
|
||||
m_gssep = false;
|
||||
m_quiet_zones = false;
|
||||
m_no_quiet_zones = false;
|
||||
m_compliant_height = false;
|
||||
m_reader_init = false;
|
||||
m_rotate_angle = 0;
|
||||
m_debug = false;
|
||||
@@ -95,6 +96,9 @@ namespace Zint {
|
||||
if (m_no_quiet_zones) {
|
||||
m_zintSymbol->output_options |= BARCODE_NO_QUIET_ZONES;
|
||||
}
|
||||
if (m_compliant_height) {
|
||||
m_zintSymbol->output_options |= COMPLIANT_HEIGHT;
|
||||
}
|
||||
m_zintSymbol->border_width = m_borderWidth;
|
||||
m_zintSymbol->option_1 = m_option_1;
|
||||
m_zintSymbol->option_2 = m_option_2;
|
||||
@@ -153,6 +157,8 @@ namespace Zint {
|
||||
m_whitespace = m_zintSymbol->whitespace_width;
|
||||
m_vwhitespace = m_zintSymbol->whitespace_height;
|
||||
emit encoded();
|
||||
} else {
|
||||
emit errored();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,8 +242,12 @@ namespace Zint {
|
||||
m_dotty = dotty;
|
||||
}
|
||||
|
||||
void QZint::setDotSize(float dot_size) {
|
||||
m_dot_size = dot_size;
|
||||
float QZint::dotSize() const {
|
||||
return m_dot_size;
|
||||
}
|
||||
|
||||
void QZint::setDotSize(float dotSize) {
|
||||
m_dot_size = dotSize;
|
||||
}
|
||||
|
||||
float QZint::guardDescent() const {
|
||||
@@ -248,6 +258,18 @@ namespace Zint {
|
||||
m_guardDescent = guardDescent;
|
||||
}
|
||||
|
||||
int QZint::structAppCount() const {
|
||||
return m_structapp.count;
|
||||
}
|
||||
|
||||
int QZint::structAppIndex() const {
|
||||
return m_structapp.index;
|
||||
}
|
||||
|
||||
QString QZint::structAppID() const {
|
||||
return m_structapp.id;
|
||||
}
|
||||
|
||||
void QZint::setStructApp(const int count, const int index, const QString& id) {
|
||||
if (count) {
|
||||
m_structapp.count = count;
|
||||
@@ -289,6 +311,10 @@ namespace Zint {
|
||||
m_bgColor = bgColor;
|
||||
}
|
||||
|
||||
bool QZint::cmyk() const {
|
||||
return m_cmyk;
|
||||
}
|
||||
|
||||
void QZint::setCMYK(bool cmyk) {
|
||||
m_cmyk = cmyk;
|
||||
}
|
||||
@@ -311,21 +337,33 @@ namespace Zint {
|
||||
return m_borderWidth;
|
||||
}
|
||||
|
||||
void QZint::setBorderWidth(int boderWidth) {
|
||||
if (boderWidth < 0 || boderWidth > 16)
|
||||
boderWidth = 0;
|
||||
m_borderWidth = boderWidth;
|
||||
void QZint::setBorderWidth(int borderWidth) {
|
||||
if (borderWidth < 0 || borderWidth > 16)
|
||||
borderWidth = 0;
|
||||
m_borderWidth = borderWidth;
|
||||
}
|
||||
|
||||
int QZint::whitespace() const {
|
||||
return m_whitespace;
|
||||
}
|
||||
|
||||
void QZint::setWhitespace(int whitespace) {
|
||||
m_whitespace = whitespace;
|
||||
}
|
||||
|
||||
void QZint::setVWhitespace(int vwhitespace) {
|
||||
m_vwhitespace = vwhitespace;
|
||||
int QZint::vWhitespace() const {
|
||||
return m_vwhitespace;
|
||||
}
|
||||
|
||||
void QZint::setFontSetting(int fontSettingIndex) {
|
||||
void QZint::setVWhitespace(int vWhitespace) {
|
||||
m_vwhitespace = vWhitespace;
|
||||
}
|
||||
|
||||
int QZint::fontSetting() const {
|
||||
return m_fontSetting;
|
||||
}
|
||||
|
||||
void QZint::setFontSetting(int fontSettingIndex) { // Sets from comboBox index
|
||||
if (fontSettingIndex == 1) {
|
||||
m_fontSetting = BOLD_TEXT;
|
||||
} else if (fontSettingIndex == 2) {
|
||||
@@ -337,27 +375,59 @@ namespace Zint {
|
||||
}
|
||||
}
|
||||
|
||||
void QZint::setShowText(bool show) {
|
||||
m_show_hrt = show;
|
||||
void QZint::setFontSettingValue(int fontSetting) { // Sets literal value
|
||||
if ((fontSetting & (BOLD_TEXT | SMALL_TEXT)) == fontSetting) {
|
||||
m_fontSetting = fontSetting;
|
||||
} else {
|
||||
m_fontSetting = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void QZint::setGSSep(bool gssep) {
|
||||
m_gssep = gssep;
|
||||
bool QZint::showText() const {
|
||||
return m_show_hrt;
|
||||
}
|
||||
|
||||
int QZint::rotateAngle() const {
|
||||
return m_rotate_angle;
|
||||
void QZint::setShowText(bool showText) {
|
||||
m_show_hrt = showText;
|
||||
}
|
||||
|
||||
bool QZint::gsSep() const {
|
||||
return m_gssep;
|
||||
}
|
||||
|
||||
void QZint::setGSSep(bool gsSep) {
|
||||
m_gssep = gsSep;
|
||||
}
|
||||
|
||||
bool QZint::quietZones() const {
|
||||
return m_quiet_zones;
|
||||
}
|
||||
|
||||
void QZint::setQuietZones(bool quietZones) {
|
||||
m_quiet_zones = quietZones;
|
||||
}
|
||||
|
||||
bool QZint::noQuietZones() const {
|
||||
return m_no_quiet_zones;
|
||||
}
|
||||
|
||||
void QZint::setNoQuietZones(bool noQuietZones) {
|
||||
m_no_quiet_zones = noQuietZones;
|
||||
}
|
||||
|
||||
void QZint::setRotateAngle(int rotateIndex) {
|
||||
bool QZint::compliantHeight() const {
|
||||
return m_compliant_height;
|
||||
}
|
||||
|
||||
void QZint::setCompliantHeight(bool compliantHeight) {
|
||||
m_compliant_height = compliantHeight;
|
||||
}
|
||||
|
||||
int QZint::rotateAngle() const {
|
||||
return m_rotate_angle;
|
||||
}
|
||||
|
||||
void QZint::setRotateAngle(int rotateIndex) { // Sets from comboBox index
|
||||
if (rotateIndex == 1) {
|
||||
m_rotate_angle = 90;
|
||||
} else if (rotateIndex == 2) {
|
||||
@@ -369,7 +439,23 @@ namespace Zint {
|
||||
}
|
||||
}
|
||||
|
||||
void QZint::setECI(int ECIIndex) {
|
||||
void QZint::setRotateAngleValue(int rotateAngle) { // Sets literal value
|
||||
if (rotateAngle == 90) {
|
||||
m_rotate_angle = 90;
|
||||
} else if (rotateAngle == 180) {
|
||||
m_rotate_angle = 180;
|
||||
} else if (rotateAngle == 270) {
|
||||
m_rotate_angle = 270;
|
||||
} else {
|
||||
m_rotate_angle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int QZint::eci() const {
|
||||
return m_eci;
|
||||
}
|
||||
|
||||
void QZint::setECI(int ECIIndex) { // Sets from comboBox index
|
||||
if (ECIIndex >= 1 && ECIIndex <= 11) {
|
||||
m_eci = ECIIndex + 2;
|
||||
} else if (ECIIndex >= 12 && ECIIndex <= 15) {
|
||||
@@ -383,16 +469,40 @@ namespace Zint {
|
||||
}
|
||||
}
|
||||
|
||||
void QZint::setGS1Parens(bool gs1parens) {
|
||||
m_gs1parens = gs1parens;
|
||||
void QZint::setECIValue(int eci) { // Sets literal value
|
||||
if (eci < 3 || (eci > 30 && eci != 899) || eci == 14 || eci == 19) {
|
||||
m_eci = 0;
|
||||
} else {
|
||||
m_eci = eci;
|
||||
}
|
||||
}
|
||||
|
||||
void QZint::setGS1NoCheck(bool gs1nocheck) {
|
||||
m_gs1nocheck = gs1nocheck;
|
||||
bool QZint::gs1Parens() const {
|
||||
return m_gs1parens;
|
||||
}
|
||||
|
||||
void QZint::setReaderInit(bool reader_init) {
|
||||
m_reader_init = reader_init;
|
||||
void QZint::setGS1Parens(bool gs1Parens) {
|
||||
m_gs1parens = gs1Parens;
|
||||
}
|
||||
|
||||
bool QZint::gs1NoCheck() const {
|
||||
return m_gs1nocheck;
|
||||
}
|
||||
|
||||
void QZint::setGS1NoCheck(bool gs1NoCheck) {
|
||||
m_gs1nocheck = gs1NoCheck;
|
||||
}
|
||||
|
||||
bool QZint::readerInit() const {
|
||||
return m_reader_init;
|
||||
}
|
||||
|
||||
void QZint::setReaderInit(bool readerInit) {
|
||||
m_reader_init = readerInit;
|
||||
}
|
||||
|
||||
bool QZint::debug() const {
|
||||
return m_debug;
|
||||
}
|
||||
|
||||
void QZint::setDebug(bool debug) {
|
||||
@@ -411,6 +521,7 @@ namespace Zint {
|
||||
target_size_horiz = width;
|
||||
target_size_vert = height;
|
||||
}
|
||||
QString QZint::error_message() const { return m_lastError; } /* Same as lastError() */
|
||||
|
||||
bool QZint::hasHRT(int symbology) const {
|
||||
return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_HRT);
|
||||
@@ -444,12 +555,12 @@ namespace Zint {
|
||||
return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_READER_INIT);
|
||||
}
|
||||
|
||||
int QZint::getError() const {
|
||||
return m_error;
|
||||
bool QZint::hasCompliantHeight(int symbology) const {
|
||||
return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_COMPLIANT_HEIGHT);
|
||||
}
|
||||
|
||||
QString QZint::error_message() const {
|
||||
return m_lastError;
|
||||
int QZint::getError() const {
|
||||
return m_error;
|
||||
}
|
||||
|
||||
const QString& QZint::lastError() const {
|
||||
@@ -472,6 +583,7 @@ namespace Zint {
|
||||
m_rotate_angle);
|
||||
if (m_error >= ZINT_ERROR) {
|
||||
m_lastError = m_zintSymbol->errtxt;
|
||||
emit errored();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
||||
@@ -67,11 +67,15 @@ public:
|
||||
bool dotty() const;
|
||||
void setDotty(bool botty);
|
||||
|
||||
float dotSize() const;
|
||||
void setDotSize(float dot_size);
|
||||
|
||||
float guardDescent() const;
|
||||
void setGuardDescent(float guardDescent);
|
||||
|
||||
int structAppCount() const;
|
||||
int structAppIndex() const;
|
||||
QString structAppID() const;
|
||||
void setStructApp(const int count, const int index, const QString& id);
|
||||
void clearStructApp();
|
||||
|
||||
@@ -81,38 +85,58 @@ public:
|
||||
QColor bgColor() const;
|
||||
void setBgColor(const QColor& bgColor);
|
||||
|
||||
bool cmyk() const;
|
||||
void setCMYK(bool cmyk);
|
||||
|
||||
int borderType() const;
|
||||
void setBorderType(int borderTypeIndex);
|
||||
|
||||
int borderWidth() const;
|
||||
void setBorderWidth(int boderWidth);
|
||||
void setBorderWidth(int borderWidth);
|
||||
|
||||
int whitespace() const;
|
||||
void setWhitespace(int whitespace);
|
||||
|
||||
void setVWhitespace(int vwhitespace);
|
||||
int vWhitespace() const;
|
||||
void setVWhitespace(int vWhitespace);
|
||||
|
||||
void setFontSetting(int fontSettingIndex);
|
||||
int fontSetting() const;
|
||||
void setFontSetting(int fontSettingIndex); // Sets from comboBox index
|
||||
void setFontSettingValue(int fontSetting); // Sets literal value
|
||||
|
||||
void setShowText(bool show);
|
||||
bool showText() const;
|
||||
void setShowText(bool showText);
|
||||
|
||||
void setGSSep(bool gssep);
|
||||
bool gsSep() const;
|
||||
void setGSSep(bool gsSep);
|
||||
|
||||
bool quietZones() const;
|
||||
void setQuietZones(bool quietZones);
|
||||
|
||||
bool noQuietZones() const;
|
||||
void setNoQuietZones(bool noQuietZones);
|
||||
|
||||
bool compliantHeight() const;
|
||||
void setCompliantHeight(bool compliantHeight);
|
||||
|
||||
int rotateAngle() const;
|
||||
void setRotateAngle(int rotateIndex);
|
||||
void setRotateAngle(int rotateIndex); // Sets from comboBox index
|
||||
void setRotateAngleValue(int rotateAngle); // Sets literal value
|
||||
|
||||
void setECI(int ECIIndex);
|
||||
int eci() const;
|
||||
void setECI(int ECIIndex); // Sets from comboBox index
|
||||
void setECIValue(int eci); // Sets literal value
|
||||
|
||||
void setGS1Parens(bool gs1parens);
|
||||
bool gs1Parens() const;
|
||||
void setGS1Parens(bool gs1Parens);
|
||||
|
||||
void setGS1NoCheck(bool gs1nocheck);
|
||||
bool gs1NoCheck() const;
|
||||
void setGS1NoCheck(bool gs1NoCheck);
|
||||
|
||||
void setReaderInit(bool reader_init);
|
||||
bool readerInit() const;
|
||||
void setReaderInit(bool readerInit);
|
||||
|
||||
bool debug() const;
|
||||
void setDebug(bool debug);
|
||||
|
||||
/* Legacy property getters/setters */
|
||||
@@ -120,10 +144,11 @@ public:
|
||||
int width() const;
|
||||
void setSecurityLevel(int securityLevel); /* option_2 */
|
||||
int securityLevel() const;
|
||||
void setPdf417CodeWords(int pdf417CodeWords); /* no op */
|
||||
void setPdf417CodeWords(int pdf417CodeWords); /* No-op */
|
||||
int pdf417CodeWords() const;
|
||||
void setHideText(bool hide); /* setShowText(!hide) */
|
||||
void setTargetSize(int width, int height);
|
||||
QString error_message() const; /* Same as lastError() */
|
||||
|
||||
/* Test capabilities - ZBarcode_Cap() */
|
||||
bool hasHRT(int symbology = 0) const;
|
||||
@@ -134,11 +159,10 @@ public:
|
||||
bool isFixedRatio(int symbology = 0) const;
|
||||
bool isDotty(int symbology = 0) const;
|
||||
bool supportsReaderInit(int symbology = 0) const;
|
||||
bool hasCompliantHeight(int symbology = 0) const;
|
||||
|
||||
int getError() const;
|
||||
|
||||
QString error_message() const;
|
||||
|
||||
const QString& lastError() const;
|
||||
bool hasErrors() const;
|
||||
|
||||
@@ -151,6 +175,7 @@ public:
|
||||
|
||||
signals:
|
||||
void encoded();
|
||||
void errored();
|
||||
|
||||
private:
|
||||
void resetSymbol();
|
||||
@@ -190,6 +215,7 @@ private:
|
||||
bool m_gssep;
|
||||
bool m_quiet_zones;
|
||||
bool m_no_quiet_zones;
|
||||
bool m_compliant_height;
|
||||
bool m_reader_init;
|
||||
bool m_debug;
|
||||
|
||||
|
||||
22
backend_qt/tests/CMakeLists.txt
Normal file
22
backend_qt/tests/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
# Copyright (C) 2021 Robin Stuart <rstuart114@gmail.com>
|
||||
# vim: set ts=4 sw=4 et :
|
||||
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(QZint_tests LANGUAGES CXX)
|
||||
|
||||
enable_testing()
|
||||
|
||||
if(USE_QT6)
|
||||
find_package(Qt6Test REQUIRED)
|
||||
else()
|
||||
find_package(Qt5Test REQUIRED)
|
||||
endif()
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
add_executable(test_qzint test_qzint.cpp)
|
||||
add_test(NAME qzint COMMAND test_qzint)
|
||||
|
||||
target_link_libraries(test_qzint PRIVATE QZint Qt${QT_VERSION_MAJOR}::Test)
|
||||
403
backend_qt/tests/test_qzint.cpp
Normal file
403
backend_qt/tests/test_qzint.cpp
Normal file
@@ -0,0 +1,403 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2021 by Robin Stuart <rstuart114@gmail.com> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
***************************************************************************/
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include "../qzint.h" /* Don't use <qzint.h> in case it's been changed */
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0])))
|
||||
#endif
|
||||
|
||||
class TestQZint : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestQZint() : m_skipIfFontUsed(false)
|
||||
{
|
||||
// Qt5 will trigger "detected memory leaks" if font used (libfontconfig) so skip if ASAN enabled
|
||||
#if QT_VERSION < 0x60000
|
||||
# if defined(__SANITIZE_ADDRESS__) || (defined(__has_feature) && __has_feature(address_sanitizer))
|
||||
m_skipIfFontUsed = true;
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual ~TestQZint() {} // Seems to be needed to generate vtable
|
||||
|
||||
private:
|
||||
bool m_skipIfFontUsed; // Hack to get around Qt5 ASAN leaks
|
||||
|
||||
private slots:
|
||||
|
||||
void setGetTest()
|
||||
{
|
||||
Zint::QZint bc;
|
||||
|
||||
int symbology = BARCODE_CODE11;
|
||||
bc.setSymbol(symbology);
|
||||
QCOMPARE(bc.symbol(), symbology);
|
||||
|
||||
int inputMode = UNICODE_MODE;
|
||||
bc.setInputMode(inputMode);
|
||||
QCOMPARE(bc.inputMode(), inputMode);
|
||||
|
||||
QString text("text");
|
||||
bc.setText(text);
|
||||
QCOMPARE(bc.text(), text);
|
||||
|
||||
QString primaryMessage("primary message");
|
||||
bc.setPrimaryMessage(primaryMessage);
|
||||
QCOMPARE(bc.primaryMessage(), primaryMessage);
|
||||
|
||||
float height = 12.345f;
|
||||
bc.setHeight(height);
|
||||
QCOMPARE(bc.height(), height);
|
||||
|
||||
int option1 = 1;
|
||||
bc.setOption1(option1);
|
||||
QCOMPARE(bc.option1(), option1);
|
||||
|
||||
int option2 = 2;
|
||||
bc.setOption2(option2);
|
||||
QCOMPARE(bc.option2(), option2);
|
||||
|
||||
int option3 = 3;
|
||||
bc.setOption3(option3);
|
||||
QCOMPARE(bc.option3(), option3);
|
||||
|
||||
float scale = 0.678f;
|
||||
bc.setScale(scale);
|
||||
QCOMPARE(bc.scale(), scale);
|
||||
|
||||
bool dotty = true;
|
||||
bc.setDotty(dotty);
|
||||
QCOMPARE(bc.dotty(), dotty);
|
||||
|
||||
float dotSize = 1.234f;
|
||||
bc.setDotSize(dotSize);
|
||||
QCOMPARE(bc.dotSize(), dotSize);
|
||||
|
||||
float guardDescent = 0.678f;
|
||||
bc.setGuardDescent(guardDescent);
|
||||
QCOMPARE(bc.guardDescent(), guardDescent);
|
||||
|
||||
struct zint_structapp structapp = { 2, 3, "ID" };
|
||||
bc.setStructApp(structapp.count, structapp.index, structapp.id);
|
||||
QCOMPARE(bc.structAppCount(), structapp.count);
|
||||
QCOMPARE(bc.structAppIndex(), structapp.index);
|
||||
QCOMPARE(bc.structAppID(), QString(structapp.id));
|
||||
|
||||
QColor fgColor(0x12, 0x34, 0x45, 0x67);
|
||||
bc.setFgColor(fgColor);
|
||||
QCOMPARE(bc.fgColor(), fgColor);
|
||||
|
||||
QColor bgColor(0x89, 0xAB, 0xCD, 0xEF);
|
||||
bc.setBgColor(bgColor);
|
||||
QCOMPARE(bc.bgColor(), bgColor);
|
||||
|
||||
bool cmyk = true;
|
||||
bc.setCMYK(cmyk);
|
||||
QCOMPARE(bc.cmyk(), cmyk);
|
||||
|
||||
int borderTypes[] = { 0, BARCODE_BIND, BARCODE_BOX };
|
||||
for (int i = 0; i < ARRAY_SIZE(borderTypes); i++) {
|
||||
bc.setBorderType(i);
|
||||
QCOMPARE(bc.borderType(), borderTypes[i]);
|
||||
}
|
||||
|
||||
int borderWidth = 4;
|
||||
bc.setBorderWidth(borderWidth);
|
||||
QCOMPARE(bc.borderWidth(), borderWidth);
|
||||
|
||||
int whitespace = 5;
|
||||
bc.setWhitespace(whitespace);
|
||||
QCOMPARE(bc.whitespace(), whitespace);
|
||||
|
||||
int vWhitespace = 6;
|
||||
bc.setVWhitespace(vWhitespace);
|
||||
QCOMPARE(bc.vWhitespace(), vWhitespace);
|
||||
|
||||
int fontSettings[] = { 0, BOLD_TEXT, SMALL_TEXT, SMALL_TEXT | BOLD_TEXT };
|
||||
for (int i = 0; i < ARRAY_SIZE(fontSettings); i++) {
|
||||
bc.setFontSetting(i);
|
||||
QCOMPARE(bc.fontSetting(), fontSettings[i]);
|
||||
|
||||
bc.setFontSettingValue(fontSettings[i]);
|
||||
QCOMPARE(bc.fontSetting(), fontSettings[i]);
|
||||
}
|
||||
bc.setFontSetting(ARRAY_SIZE(fontSettings));
|
||||
QCOMPARE(bc.fontSetting(), 0);
|
||||
bc.setFontSetting(-1);
|
||||
QCOMPARE(bc.fontSetting(), 0);
|
||||
|
||||
bc.setFontSettingValue(-1);
|
||||
QCOMPARE(bc.fontSetting(), 0);
|
||||
bc.setFontSettingValue(CMYK_COLOUR);
|
||||
QCOMPARE(bc.fontSetting(), 0);
|
||||
|
||||
bool showText = false;
|
||||
bc.setShowText(showText);
|
||||
QCOMPARE(bc.showText(), showText);
|
||||
|
||||
bool gsSep = true;
|
||||
bc.setGSSep(gsSep);
|
||||
QCOMPARE(bc.gsSep(), gsSep);
|
||||
|
||||
bool quietZones = true;
|
||||
bc.setQuietZones(quietZones);
|
||||
QCOMPARE(bc.quietZones(), quietZones);
|
||||
|
||||
bool noQuietZones = true;
|
||||
bc.setNoQuietZones(noQuietZones);
|
||||
QCOMPARE(bc.noQuietZones(), noQuietZones);
|
||||
|
||||
bool compliantHeight = true;
|
||||
bc.setCompliantHeight(compliantHeight);
|
||||
QCOMPARE(bc.compliantHeight(), compliantHeight);
|
||||
|
||||
int rotateAngles[] = { 0, 90, 180, 270 };
|
||||
for (int i = 0; i < ARRAY_SIZE(rotateAngles); i++) {
|
||||
bc.setRotateAngle(i);
|
||||
QCOMPARE(bc.rotateAngle(), rotateAngles[i]);
|
||||
|
||||
bc.setRotateAngleValue(rotateAngles[i]);
|
||||
QCOMPARE(bc.rotateAngle(), rotateAngles[i]);
|
||||
}
|
||||
bc.setRotateAngle(ARRAY_SIZE(rotateAngles));
|
||||
QCOMPARE(bc.rotateAngle(), 0);
|
||||
bc.setRotateAngle(-1);
|
||||
QCOMPARE(bc.rotateAngle(), 0);
|
||||
|
||||
bc.setRotateAngleValue(-1);
|
||||
QCOMPARE(bc.rotateAngle(), 0);
|
||||
bc.setRotateAngleValue(45);
|
||||
QCOMPARE(bc.rotateAngle(), 0);
|
||||
|
||||
int ecis[] = {
|
||||
0, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 15, 16, 17, 18, 20, 21, 22, 23,
|
||||
24, 25, 26, 27, 28, 29, 30, 899,
|
||||
};
|
||||
for (int i = 0; i < ARRAY_SIZE(ecis); i++) {
|
||||
bc.setECI(i);
|
||||
QCOMPARE(bc.eci(), ecis[i]);
|
||||
|
||||
bc.setECIValue(ecis[i]);
|
||||
QCOMPARE(bc.eci(), ecis[i]);
|
||||
}
|
||||
bc.setECI(ARRAY_SIZE(ecis));
|
||||
QCOMPARE(bc.eci(), 0);
|
||||
bc.setECI(-1);
|
||||
QCOMPARE(bc.eci(), 0);
|
||||
// See also setGetECIValueTest()
|
||||
|
||||
bool gs1Parens = true;
|
||||
bc.setGS1Parens(gs1Parens);
|
||||
QCOMPARE(bc.gs1Parens(), gs1Parens);
|
||||
|
||||
bool gs1NoCheck = true;
|
||||
bc.setGS1NoCheck(gs1NoCheck);
|
||||
QCOMPARE(bc.gs1NoCheck(), gs1NoCheck);
|
||||
|
||||
bool readerInit = true;
|
||||
bc.setReaderInit(readerInit);
|
||||
QCOMPARE(bc.readerInit(), readerInit);
|
||||
|
||||
bool debug = true;
|
||||
bc.setDebug(debug);
|
||||
QCOMPARE(bc.debug(), debug);
|
||||
}
|
||||
|
||||
void setGetECIValueTest_data()
|
||||
{
|
||||
QTest::addColumn<int>("value");
|
||||
QTest::addColumn<int>("eci");
|
||||
|
||||
QTest::newRow("-1") << -1 << 0;
|
||||
QTest::newRow("0") << 0 << 0;
|
||||
QTest::newRow("1") << 1 << 0;
|
||||
QTest::newRow("2") << 2 << 0;
|
||||
QTest::newRow("14") << 14 << 0;
|
||||
QTest::newRow("19") << 19 << 0;
|
||||
QTest::newRow("31") << 31 << 0;
|
||||
QTest::newRow("898") << 898 << 0;
|
||||
QTest::newRow("900") << 900 << 0;
|
||||
QTest::newRow("1000") << 1000 << 0;
|
||||
}
|
||||
|
||||
void setGetECIValueTest()
|
||||
{
|
||||
Zint::QZint bc;
|
||||
|
||||
QFETCH(int, value);
|
||||
QFETCH(int, eci);
|
||||
|
||||
bc.setECIValue(value);
|
||||
QCOMPARE(bc.eci(), eci);
|
||||
}
|
||||
|
||||
void legacyTest()
|
||||
{
|
||||
Zint::QZint bc;
|
||||
|
||||
int width = 12;
|
||||
bc.setWidth(width);
|
||||
QCOMPARE(bc.width(), width);
|
||||
QCOMPARE(bc.option1(), width);
|
||||
|
||||
int securityLevel = 2;
|
||||
bc.setSecurityLevel(securityLevel);
|
||||
QCOMPARE(bc.securityLevel(), securityLevel);
|
||||
QCOMPARE(bc.option2(), securityLevel);
|
||||
|
||||
int pdf417CodeWords = 123;
|
||||
bc.setPdf417CodeWords(pdf417CodeWords);
|
||||
QCOMPARE(bc.pdf417CodeWords(), 0); // No-op
|
||||
|
||||
bool hideText = true;
|
||||
bc.setHideText(hideText);
|
||||
QCOMPARE(bc.showText(), !hideText);
|
||||
|
||||
// No get for target size
|
||||
}
|
||||
|
||||
void capTest_data()
|
||||
{
|
||||
QTest::addColumn<int>("symbology");
|
||||
QTest::addColumn<int>("cap_flag");
|
||||
|
||||
QTest::newRow("BARCODE_CODE11") << BARCODE_CODE11 << (ZINT_CAP_HRT);
|
||||
QTest::newRow("BARCODE_CODE128") << BARCODE_CODE128 << (ZINT_CAP_HRT | ZINT_CAP_READER_INIT);
|
||||
QTest::newRow("BARCODE_EANX") << BARCODE_EANX << (ZINT_CAP_HRT | ZINT_CAP_EXTENDABLE | ZINT_CAP_QUIET_ZONES | ZINT_CAP_COMPLIANT_HEIGHT);
|
||||
QTest::newRow("BARCODE_QRCODE") << BARCODE_QRCODE << (ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO);
|
||||
}
|
||||
|
||||
void capTest()
|
||||
{
|
||||
Zint::QZint bc;
|
||||
|
||||
QFETCH(int, symbology);
|
||||
QFETCH(int, cap_flag);
|
||||
|
||||
bc.setSymbol(symbology);
|
||||
QCOMPARE(bc.hasHRT(), (cap_flag & ZINT_CAP_HRT) != 0);
|
||||
QCOMPARE(bc.isExtendable(), (cap_flag & ZINT_CAP_EXTENDABLE) != 0);
|
||||
QCOMPARE(bc.supportsECI(), (cap_flag & ZINT_CAP_ECI) != 0);
|
||||
QCOMPARE(bc.supportsGS1(), (cap_flag & ZINT_CAP_GS1) != 0);
|
||||
QCOMPARE(bc.hasDefaultQuietZones(), (cap_flag & ZINT_CAP_QUIET_ZONES) != 0);
|
||||
QCOMPARE(bc.isFixedRatio(), (cap_flag & ZINT_CAP_FIXED_RATIO) != 0);
|
||||
QCOMPARE(bc.isDotty(), (cap_flag & ZINT_CAP_DOTTY) != 0);
|
||||
QCOMPARE(bc.supportsReaderInit(), (cap_flag & ZINT_CAP_READER_INIT) != 0);
|
||||
QCOMPARE(bc.hasCompliantHeight(), (cap_flag & ZINT_CAP_COMPLIANT_HEIGHT) != 0);
|
||||
}
|
||||
|
||||
void renderTest_data()
|
||||
{
|
||||
QTest::addColumn<int>("symbology");
|
||||
QTest::addColumn<QString>("text");
|
||||
QTest::addColumn<int>("getError");
|
||||
QTest::addColumn<QString>("error_message");
|
||||
|
||||
QTest::newRow("BARCODE_QRCODE") << BARCODE_QRCODE << "1234" << 0 << "";
|
||||
if (!m_skipIfFontUsed) {
|
||||
QTest::newRow("BARCODE_QRCODE no text") << BARCODE_QRCODE << "" << ZINT_ERROR_INVALID_DATA << "Error 205: No input data";
|
||||
}
|
||||
}
|
||||
|
||||
void renderTest()
|
||||
{
|
||||
Zint::QZint bc;
|
||||
|
||||
bool bRet;
|
||||
QPainter painter;
|
||||
constexpr int width = 100, height = 100;
|
||||
QPixmap paintDevice(width, height);
|
||||
QRectF paintRect(0, 0, width, height);
|
||||
Zint::QZint::AspectRatioMode mode;
|
||||
QSignalSpy spyEncoded(&bc, SIGNAL(encoded()));
|
||||
QSignalSpy spyErrored(&bc, SIGNAL(errored()));
|
||||
|
||||
mode = Zint::QZint::AspectRatioMode::KeepAspectRatio; // Legacy - ignored
|
||||
|
||||
QFETCH(int, symbology);
|
||||
QFETCH(QString, text);
|
||||
QFETCH(int, getError);
|
||||
QFETCH(QString, error_message);
|
||||
|
||||
bc.setSymbol(symbology);
|
||||
bc.setText(text);
|
||||
|
||||
bRet = painter.begin(&paintDevice);
|
||||
QCOMPARE(bRet, true);
|
||||
|
||||
bc.render(painter, paintRect, mode);
|
||||
|
||||
bRet = painter.end();
|
||||
QCOMPARE(bRet, true);
|
||||
|
||||
QCOMPARE(bc.getError(), getError);
|
||||
QCOMPARE(bc.error_message(), error_message);
|
||||
QCOMPARE(bc.lastError(), error_message);
|
||||
QCOMPARE(bc.hasErrors(), getError != 0);
|
||||
|
||||
if (getError) {
|
||||
QCOMPARE(spyEncoded.count(), 0);
|
||||
QCOMPARE(spyErrored.count(), 1);
|
||||
} else {
|
||||
QCOMPARE(spyEncoded.count(), 1);
|
||||
QCOMPARE(spyErrored.count(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void saveToFileTest_data()
|
||||
{
|
||||
QTest::addColumn<int>("symbology");
|
||||
QTest::addColumn<QString>("text");
|
||||
QTest::addColumn<QString>("fileName");
|
||||
QTest::addColumn<bool>("expected_bRet");
|
||||
|
||||
QTest::newRow("BARCODE_DATAMATRIX gif") << BARCODE_DATAMATRIX << "1234" << "test_save_to_file.gif" << true;
|
||||
QTest::newRow("BARCODE_DATAMATRIX unknown format") << BARCODE_DATAMATRIX << "1234" << "test_save_to_file.ext" << false;
|
||||
}
|
||||
|
||||
void saveToFileTest()
|
||||
{
|
||||
Zint::QZint bc;
|
||||
|
||||
bool bRet;
|
||||
int ret;
|
||||
|
||||
QFETCH(int, symbology);
|
||||
QFETCH(QString, text);
|
||||
QFETCH(QString, fileName);
|
||||
QFETCH(bool, expected_bRet);
|
||||
|
||||
bc.setSymbol(symbology);
|
||||
bc.setText(text);
|
||||
|
||||
bRet = bc.save_to_file(fileName);
|
||||
QCOMPARE(bRet, expected_bRet);
|
||||
|
||||
if (bRet) {
|
||||
ret = remove(fileName.toLatin1());
|
||||
QCOMPARE(ret, 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(TestQZint)
|
||||
#include "test_qzint.moc"
|
||||
Reference in New Issue
Block a user