- CODABLOCKF: fix misencodation of extended ASCII 0xB0-0xB9 when

followed by digit (ignore 2nd byte of FNC4 when categorizing
  Code C characters)
- New `ZBarcode_Cap()` flag `ZINT_CAP_BINDABLE`, differentiated
  from `ZINT_CAP_STACKABLE`, and new Qt Backend method
  `isBindable()`
- CLI: fix `separator` check to use new `ZINT_CAP_BINDABLE` instead
  of `ZINT_CAP_STACKABLE`
- ZBarcode_Cap: add missing symbologies to `ZINT_CAP_BINDABLE` (was
  `ZINT_CAP_STACKABLE`)
- DOTCODE: pad rows if given number of columns instead of failing
  if rows below min (5)
- DBAR/composites: ensure stacked symbologies and composites are
  not stacked (set `symbol->rows` to 0)
- test suite: move `test_perf` routines into single test
  "test_perf";
  new "test_random" (based on "test_bwipp") to test various
  symbologies with random binary - discovered CODABLOCKF bug;
  expand "test_bwipp"
manual: Feeback: mention AZTEC -1 meaning min & MICROPDF417:
  doc new `ZINT_CAP_BINDABLE`
general: various code fiddlings and re-formattings
This commit is contained in:
gitlost 2025-04-03 16:08:15 +01:00
parent 2370fbfbb7
commit a74871a7de
60 changed files with 3509 additions and 3267 deletions

View file

@ -1,4 +1,4 @@
Version 2.15.0.9 (dev) not released yet (2025-03-28)
Version 2.15.0.9 (dev) not released yet (2025-04-04)
====================================================
**Incompatible changes**
@ -8,6 +8,7 @@ Version 2.15.0.9 (dev) not released yet (2025-03-28)
- Symbol structure members `option_1`, `option_2` and `option_3` now updated
after `ZBarcode_Encode()` and variants are called, and there are three new
methods in the Qt Backend to access to them
- New Qt Backend method `isBindable()` for new flag `ZINT_CAP_BINDABLE`
- GS1 Composites now return warning if CC type upped from requested due to size
of composite data
@ -25,12 +26,22 @@ Changes
- composite: warn if CC type upped from requested
- gs1: csumalpha: improve warning, report both chars (ticket #332, props Harald
Oehlmann)
- New `ZBarcode_Cap()` flag `ZINT_CAP_BINDABLE`, differentiated from
`ZINT_CAP_STACKABLE`, and new Qt Backend method `isBindable()`
- DOTCODE: now pads rows if given number of columns instead of failing if rows
below min (5)
Bugs
----
- CODABLOCKF: fix misencodation of extended ASCII 0xB0-0xB9 when followed by
digit (ignore 2nd byte of FNC4 when categorizing Code C characters)
- AZTEC: fix GS1 mode with Structured Append (wasn't outputting initial FNC1)
- set_height: fix non-compliance false positives by using epsilon in checks
- UPU_S10: fix Service Indicator warning re "H" (ticket #331, props Milton Neal)
- CLI: fix `separator` check to use new `ZINT_CAP_BINDABLE` instead of
`ZINT_CAP_STACKABLE`
- ZBarcode_Cap: add missing symbologies to `ZINT_CAP_BINDABLE` (was
`ZINT_CAP_STACKABLE`)
- manual/man page: fix DATAMATRIX Sizes tables "28 12x26" -> "27 12x26"

View file

@ -171,12 +171,9 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len
}
} else {
switch (symbol->symbology) {
case BARCODE_AUSREPLY: memcpy(fcc, "45", 2);
break;
case BARCODE_AUSROUTE: memcpy(fcc, "87", 2);
break;
case BARCODE_AUSREDIRECT: memcpy(fcc, "92", 2);
break;
case BARCODE_AUSREPLY: memcpy(fcc, "45", 2); break;
case BARCODE_AUSROUTE: memcpy(fcc, "87", 2); break;
case BARCODE_AUSREDIRECT: memcpy(fcc, "92", 2); break;
}
/* Add leading zeros as required */

View file

@ -887,6 +887,7 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int
unsigned int *data_part;
unsigned int *ecc_part;
float ecc_ratio;
int dim;
if (gs1 && reader_init) {
return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 501, "Cannot use Reader Initialisation in GS1 mode");
@ -1283,9 +1284,7 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int
}
symbol->row_height[y - offset] = 1;
}
symbol->height = 27 - (2 * offset);
symbol->rows = 27 - (2 * offset);
symbol->width = 27 - (2 * offset);
dim = 27 - (2 * offset);
} else {
const int offset = AztecOffset[layers - 1];
const int end_offset = 151 - offset;
@ -1300,10 +1299,11 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int
}
symbol->row_height[y - offset] = 1;
}
symbol->height = 151 - (2 * offset);
symbol->rows = 151 - (2 * offset);
symbol->width = 151 - (2 * offset);
dim = 151 - (2 * offset);
}
symbol->height = dim;
symbol->rows = dim;
symbol->width = dim;
return error_number;
}

View file

@ -72,10 +72,10 @@ typedef struct sCharacterSetTable {
* The result is an OR of CodeA, CodeB, CodeC, CodeFNC1, CodeFNC4 depending on the
* possible Code 128 character sets.
*/
static int GetPossibleCharacterSet(unsigned char C) {
static int GetPossibleCharacterSet(const unsigned char C, const int prevNotFNC4) {
if (C <= '\x1f') /* Control chars */
return CodeA;
if (z_isdigit(C))
if (z_isdigit(C) && prevNotFNC4)
return ZTNum; /* ZTNum = CodeA | CodeB | CodeC */
if (C == aFNC1) /* FNC1s (GS1) not used */
return ZTFNC1; /* ZTFNC1 = CodeA | CodeB | CodeC | CodeFNC1 */ /* Not reached */
@ -93,37 +93,37 @@ static int GetPossibleCharacterSet(unsigned char C) {
* int AFollowing, BFollowing The number of source characters you still may encode in this character set.
* int CFollowing The number of characters encodable in CodeC if we start here.
*/
static void CreateCharacterSetTable(CharacterSetTable T[], unsigned char *data, const int dataLength) {
static void CreateCharacterSetTable(CharacterSetTable T[], const unsigned char *data, const int dataLength) {
int charCur;
int runChar;
int prevNotFNC4;
/* Treat the Data backwards */
charCur = dataLength - 1;
T[charCur].CharacterSet = GetPossibleCharacterSet(data[charCur]);
T[charCur].AFollowing = ((T[charCur].CharacterSet & CodeA) == 0) ? 0 : 1;
T[charCur].BFollowing = ((T[charCur].CharacterSet & CodeB) == 0) ? 0 : 1;
T[charCur].CFollowing = 0;
prevNotFNC4 = charCur > 0 ? data[charCur - 1] != aFNC4 : 1;
T[charCur].CharacterSet = GetPossibleCharacterSet(data[charCur], prevNotFNC4);
T[charCur].AFollowing = T[charCur].CharacterSet & CodeA ? 1 : 0;
T[charCur].BFollowing = T[charCur].CharacterSet & CodeB ? 1 : 0;
for (charCur--; charCur >= 0; charCur--) {
T[charCur].CharacterSet = GetPossibleCharacterSet(data[charCur]);
T[charCur].AFollowing = ((T[charCur].CharacterSet & CodeA) == 0) ? 0 : T[charCur + 1].AFollowing + 1;
T[charCur].BFollowing = ((T[charCur].CharacterSet & CodeB) == 0) ? 0 : T[charCur + 1].BFollowing + 1;
T[charCur].CFollowing = 0;
prevNotFNC4 = charCur > 0 ? data[charCur - 1] != aFNC4 : 1;
T[charCur].CharacterSet = GetPossibleCharacterSet(data[charCur], prevNotFNC4);
T[charCur].AFollowing = T[charCur].CharacterSet & CodeA ? T[charCur + 1].AFollowing + 1 : 0;
T[charCur].BFollowing = T[charCur].CharacterSet & CodeB ? T[charCur + 1].BFollowing + 1 : 0;
}
/* Find the CodeC-chains */
for (charCur = 0; charCur < dataLength; charCur++) {
T[charCur].CFollowing = 0;
if ((T[charCur].CharacterSet & CodeC) != 0) {
if (T[charCur].CharacterSet & CodeC) {
/* CodeC possible */
runChar = charCur;
do {
/* Whether this is FNC1, whether next is */
/* numeric */
if (T[runChar].CharacterSet == ZTFNC1) /* FNC1s (GS1) not used */
++(T[charCur].CFollowing); /* Not reached */
T[charCur].CFollowing++; /* Not reached */
else {
++runChar;
if (runChar >= dataLength)
if (++runChar >= dataLength)
break;
/* Only a Number may follow */
if (T[runChar].CharacterSet == ZTNum)
@ -141,11 +141,9 @@ static void CreateCharacterSetTable(CharacterSetTable T[], unsigned char *data,
* one bundle into the line (up to here). This is calculated online because
* it depends on the space in the line.
*/
static int RemainingDigits(CharacterSetTable *T, int charCur, int emptyColumns) {
int digitCount; /* Numerical digits fitting in the line */
int runChar;
runChar = charCur;
digitCount = 0;
static int RemainingDigits(const CharacterSetTable T[], const int charCur, int emptyColumns) {
int digitCount = 0; /* Numerical digits fitting in the line */
int runChar = charCur;
while (emptyColumns > 0 && runChar < charCur + T[charCur].CFollowing) {
if (T[runChar].CharacterSet != ZTFNC1) {
/* NOT FNC1 */
@ -168,8 +166,8 @@ static int RemainingDigits(CharacterSetTable *T, int charCur, int emptyColumns)
* pSet Output of the character sets used, allocated by me.
* Return value Resulting row count
*/
static int Columns2Rows(struct zint_symbol *symbol, CharacterSetTable *T, const int dataLength, int *pRows,
int *pUseColumns, int *pSet, int *pFillings) {
static int Columns2Rows(const CharacterSetTable T[], const int dataLength, int *pRows, int *pUseColumns, int *pSet,
int *pFillings, const int debug) {
int useColumns; /* Usable Characters per line */
int fillings = 0; /* Number of filling characters */
int rowsCur;
@ -191,7 +189,7 @@ static int Columns2Rows(struct zint_symbol *symbol, CharacterSetTable *T, const
/* >>> Line Loop */
do {
/* >> Start Character */
emptyColumns = useColumns; /* Remained place in Line */
emptyColumns = useColumns; /* Remaining space in line */
/* >>Choose in Set A or B */
/* (C is changed as an option later on) */
@ -226,7 +224,7 @@ static int Columns2Rows(struct zint_symbol *symbol, CharacterSetTable *T, const
/* >> Following characters */
while (emptyColumns > 0 && charCur < dataLength) {
isFNC4 = (T[charCur].CharacterSet & CodeFNC4);
isFNC4 = T[charCur].CharacterSet & CodeFNC4;
switch (characterSetCur) {
case CodeA:
case CodeB:
@ -342,13 +340,18 @@ static int Columns2Rows(struct zint_symbol *symbol, CharacterSetTable *T, const
switch (emptyColumns) {
case 1:
pSet[charCur - 1] |= CFill;
/* fall through */
/* [[fallthrough]] */
case 0:
++rowsCur;
fillings = useColumns - 2 + emptyColumns;
break;
case 2: fillings = 0; break;
default: pSet[charCur - 1] |= CFill; fillings = emptyColumns - 2;
case 2:
fillings = 0;
break;
default:
pSet[charCur - 1] |= CFill;
fillings = emptyColumns - 2;
break;
}
if (rowsCur > 44) {
@ -361,7 +364,7 @@ static int Columns2Rows(struct zint_symbol *symbol, CharacterSetTable *T, const
fillings += useColumns;
}
} while (rowsCur > 44);
if (symbol->debug & ZINT_DEBUG_PRINT) {
if (debug) {
printf(" -> out: rowsCur <%d>, useColumns <%d>, fillings <%d>\n", rowsCur, useColumns, fillings);
}
*pUseColumns = useColumns;
@ -372,8 +375,8 @@ static int Columns2Rows(struct zint_symbol *symbol, CharacterSetTable *T, const
/* Find columns if row count is given.
*/
static int Rows2Columns(struct zint_symbol *symbol, CharacterSetTable *T, const int dataLength, int *pRows,
int *pUseColumns, int *pSet, int *pFillings) {
static int Rows2Columns(const CharacterSetTable T[], const int dataLength, int *pRows, int *pUseColumns, int *pSet,
int *pFillings, const int debug) {
int rowsCur;
int rowsRequested; /* Number of requested rows */
int columnsRequested; /* Number of requested columns (if any) */
@ -387,7 +390,7 @@ static int Rows2Columns(struct zint_symbol *symbol, CharacterSetTable *T, const
rowsRequested = *pRows;
columnsRequested = *pUseColumns >= 4 ? *pUseColumns : 0;
if (symbol->debug & ZINT_DEBUG_PRINT) {
if (debug) {
printf("Optimizer : Searching <%d> rows\n", rowsRequested);
}
@ -407,7 +410,7 @@ static int Rows2Columns(struct zint_symbol *symbol, CharacterSetTable *T, const
pTestList[testListSize] = testColumns;
testListSize++;
useColumns = testColumns; /* Make a copy because it may be modified */
errorCur = Columns2Rows(symbol, T, dataLength, &rowsCur, &useColumns, pSet, &fillings);
errorCur = Columns2Rows(T, dataLength, &rowsCur, &useColumns, pSet, &fillings, debug);
if (errorCur != 0)
return errorCur;
if (rowsCur <= rowsRequested) {
@ -448,7 +451,7 @@ static int Rows2Columns(struct zint_symbol *symbol, CharacterSetTable *T, const
/* Print a character in character set A
*/
static void A2C128_A(uchar **ppOutPos, uchar c) {
static void A2C128_A(uchar **ppOutPos, const uchar c) {
uchar *pOutPos = *ppOutPos;
switch (c) {
case aCodeB: *pOutPos = 100; break;
@ -471,7 +474,7 @@ static void A2C128_A(uchar **ppOutPos, uchar c) {
/* Output c in Set B
*/
static void A2C128_B(uchar **ppOutPos, uchar c) {
static void A2C128_B(uchar **ppOutPos, const uchar c) {
uchar *pOutPos = *ppOutPos;
switch (c) {
case aFNC1: *pOutPos = 102; break; /* FNC1s (GS1) not used */ /* Not reached */
@ -483,12 +486,12 @@ static void A2C128_B(uchar **ppOutPos, uchar c) {
case aShift: *pOutPos = 98; break;
default: *pOutPos = (uchar) (c - ' '); break;
}
++(*ppOutPos);
(*ppOutPos)++;
}
/* Output c1, c2 in Set C
*/
static void A2C128_C(uchar **ppOutPos, uchar c1, uchar c2) {
static void A2C128_C(uchar **ppOutPos, const uchar c1, const uchar c2) {
uchar *pOutPos = *ppOutPos;
switch (c1) {
case aFNC1: *pOutPos = 102; break; /* FNC1s (GS1) not used */ /* Not reached */
@ -501,7 +504,7 @@ static void A2C128_C(uchar **ppOutPos, uchar c1, uchar c2) {
/* Output a character in Characterset
*/
static void ASCIIZ128(uchar **ppOutPos, int CharacterSet, uchar c1, uchar c2) {
static void ASCIIZ128(uchar **ppOutPos, const int CharacterSet, const uchar c1, const uchar c2) {
if (CharacterSet == CodeA)
A2C128_A(ppOutPos, c1);
else if (CharacterSet == CodeB)
@ -512,7 +515,7 @@ static void ASCIIZ128(uchar **ppOutPos, int CharacterSet, uchar c1, uchar c2) {
/* XLate Tables D.2, D.3 and F.1 of Codablock-F Specification and call output
*/
static void SumASCII(uchar **ppOutPos, int Sum, int CharacterSet) {
static void SumASCII(uchar **ppOutPos, const int Sum, const int CharacterSet) {
switch (CharacterSet) {
case CodeA: /* Row # Indicators and Data Check Characters K1/K2 for CodeA and CodeB are the same */
case CodeB:
@ -548,6 +551,7 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int
int *pSet;
uchar *pOutput;
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT;
const int debug = symbol->debug & ZINT_DEBUG_PRINT;
/* Suppresses clang-analyzer-core.VLASize warning */
assert(length > 0);
@ -595,18 +599,15 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int
dataLength = 0;
if (symbol->output_options & READER_INIT) {
data[dataLength] = aFNC3;
dataLength++;
data[dataLength++] = aFNC3;
}
/* Replace all Codes>127 with <fnc4>Code-128 */
for (charCur = 0; charCur < length; charCur++) {
if (source[charCur] > 127) {
data[dataLength] = aFNC4;
dataLength++;
data[dataLength] = (unsigned char) (source[charCur] & 127);
data[dataLength++] = aFNC4;
data[dataLength++] = (unsigned char) (source[charCur] & 127);
} else
data[dataLength] = source[charCur];
dataLength++;
data[dataLength++] = source[charCur];
}
/* Build character set table */
@ -625,7 +626,7 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int
} else if (columns < 9) {
columns = 9;
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
if (debug) {
printf("Auto column count for %d characters:%d\n", dataLength, columns);
}
}
@ -633,10 +634,10 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int
useColumns = columns - 5;
if (rows > 0) {
/* Row count given */
error_number = Rows2Columns(symbol, T, dataLength, &rows, &useColumns, pSet, &fillings);
error_number = Rows2Columns(T, dataLength, &rows, &useColumns, pSet, &fillings, debug);
} else {
/* Column count given */
error_number = Columns2Rows(symbol, T, dataLength, &rows, &useColumns, pSet, &fillings);
error_number = Columns2Rows(T, dataLength, &rows, &useColumns, pSet, &fillings, debug);
}
if (error_number != 0) {
return errtxt(error_number, symbol, 413,
@ -652,7 +653,7 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int
Sum2 = (Sum2 + charCur * source[charCur]) % 86;
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
if (debug) {
int DPos;
fputs("\nData:", stdout);
for (DPos = 0; DPos < dataLength; DPos++)
@ -745,24 +746,24 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int
while (emptyColumns > 0 && charCur < dataLength) {
/* ? Change character set */
if (emptyColumns < useColumns) {
if ((pSet[charCur] & CodeA) != 0) {
if (pSet[charCur] & CodeA) {
/* Change to A */
ASCIIZ128(&pOutPos, characterSetCur, aCodeA, '\0');
--emptyColumns;
characterSetCur = CodeA;
} else if ((pSet[charCur] & CodeB) != 0) {
} else if (pSet[charCur] & CodeB) {
/* Change to B */
ASCIIZ128(&pOutPos, characterSetCur, aCodeB, '\0');
--emptyColumns;
characterSetCur = CodeB;
} else if ((pSet[charCur] & CodeC) != 0) {
} else if (pSet[charCur] & CodeC) {
/* Change to C */
ASCIIZ128(&pOutPos, characterSetCur, aCodeC, '\0');
--emptyColumns;
characterSetCur = CodeC;
}
}
if ((pSet[charCur] & CShift) != 0) {
if (pSet[charCur] & CShift) {
/* >> Shift it and put out the shifted character */
ASCIIZ128(&pOutPos, characterSetCur, aShift, '\0');
emptyColumns -= 2;
@ -832,7 +833,7 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int
*pOutPos++ = 106;
} /* End Lineloop */
if (symbol->debug & ZINT_DEBUG_PRINT) {
if (debug) {
int DPos, DPos2;
fputs("\nCode 128 Code Numbers:\n", stdout);
for (DPos = 0; DPos < rows; DPos++) {

View file

@ -195,14 +195,10 @@ static int c1_look_ahead_test(const unsigned char source[], const int length, co
}
switch (current_mode) {
case C1_C40: c40_count = 0; /* Step J2 */
break;
case C1_TEXT: text_count = 0; /* Step J3 */
break;
case C1_EDI: edi_count = 0; /* Missing in spec */
break;
case C1_BYTE: byte_count = 0; /* Step J4 */
break;
case C1_C40: c40_count = 0; break; /* Step J2 */
case C1_TEXT: text_count = 0; break; /* Step J3 */
case C1_EDI: edi_count = 0; break; /* Missing in spec */
case C1_BYTE: byte_count = 0; break; /* Step J4 */
}
for (sp = position; sp < length; sp++) {
@ -579,16 +575,20 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len
if (current_mode != next_mode) {
/* Change mode */
switch (next_mode) {
case C1_C40: target[tp++] = 230;
case C1_C40:
target[tp++] = 230;
if (debug_print) fputs("->C40 ", stdout);
break;
case C1_TEXT: target[tp++] = 239;
case C1_TEXT:
target[tp++] = 239;
if (debug_print) fputs("->Text ", stdout);
break;
case C1_EDI: target[tp++] = 238;
case C1_EDI:
target[tp++] = 238;
if (debug_print) fputs("->EDI ", stdout);
break;
case C1_BYTE: target[tp++] = 231;
case C1_BYTE:
target[tp++] = 231;
if (debug_print) fputs("->Byte ", stdout);
byte_start = tp;
target[tp++] = 0; /* Byte count holder (may be expanded to 2 codewords) */

View file

@ -525,9 +525,8 @@ INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int
/* If part of a composite symbol make room for the separator pattern */
if (symbol->symbology == BARCODE_GS1_128_CC) {
separator_row = symbol->rows;
symbol->row_height[symbol->rows] = 1;
symbol->rows += 1;
separator_row = symbol->rows++;
symbol->row_height[separator_row] = 1;
}
error_number = gs1_verify(symbol, source, length, reduced, &reduced_length);

View file

@ -134,7 +134,7 @@ static void c16k_dxsmooth(int list[2][C128_MAX], int *p_indexliste) {
}
}
if (i == 0) { /* first block */
if (i == 0) { /* First block */
if (current == C16K_ABORC) {
if ((indexliste == 1) && (length == 2)) {
/* Rule 1a */
@ -383,16 +383,8 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len
printf("FSet: %.*s\n", length, fset);
}
/* start with the mode character - Table 2 */
m = 0;
switch (set[0]) {
case 'A': m = 0;
break;
case 'B': m = 1;
break;
case 'C': m = 2;
break;
}
/* Start with the mode character - Table 2 */
m = set[0] - 'A';
if (symbol->output_options & READER_INIT) {
if (gs1) {
@ -409,10 +401,8 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len
if (gs1) {
/* Integrate FNC1 */
switch (set[0]) {
case 'B': m = 3;
break;
case 'C': m = 4;
break;
case 'B': m = 3; break;
case 'C': m = 4; break;
}
} else {
if ((set[0] == 'B') && (set[1] == 'C')) {
@ -472,14 +462,17 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len
if (!gs1 || source[read] != '\x1D') {
switch (set[read]) { /* Encode data characters */
case 'A':
case 'a': c16k_set_a(source[read], values, &bar_characters);
case 'a':
c16k_set_a(source[read], values, &bar_characters);
read++;
break;
case 'B':
case 'b': (void) c16k_set_b(source[read], values, &bar_characters);
case 'b':
(void) c16k_set_b(source[read], values, &bar_characters);
read++;
break;
case 'C': c16k_set_c(source[read], source[read + 1], values, &bar_characters);
case 'C':
c16k_set_c(source[read], source[read + 1], values, &bar_characters);
read += 2;
break;
}

View file

@ -201,14 +201,10 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng
switch (codewords[0]) {
/* Set starting mode value */
case 48: M = 2;
break;
case 43: M = 4;
break;
case 44: M = 5;
break;
default: M = 0;
break;
case 48: M = 2; break;
case 43: M = 4; break;
case 44: M = 5; break;
default: M = 0; break;
}
if (M != 0) {

View file

@ -535,7 +535,7 @@ INTERNAL int errtxt_adj(const int error_number, struct zint_symbol *symbol, cons
}
/* Whether `symbology` can have row binding */
INTERNAL int is_stackable(const int symbology) {
INTERNAL int is_bindable(const int symbology) {
if (symbology < BARCODE_PHARMA_TWO && symbology != BARCODE_POSTNET) {
return 1;
}
@ -544,6 +544,7 @@ INTERNAL int is_stackable(const int symbology) {
case BARCODE_CODE128AB:
case BARCODE_ISBNX:
case BARCODE_EAN14:
case BARCODE_VIN:
case BARCODE_NVE18:
case BARCODE_KOREAPOST:
case BARCODE_PLESSEY:
@ -551,7 +552,13 @@ INTERNAL int is_stackable(const int symbology) {
case BARCODE_ITF14:
case BARCODE_CODE32:
case BARCODE_CODABLOCKF:
case BARCODE_DPD:
case BARCODE_HIBC_128:
case BARCODE_HIBC_39:
case BARCODE_HIBC_BLOCKF:
case BARCODE_UPU_S10:
case BARCODE_CHANNEL:
case BARCODE_BC412:
return 1;
break;
}

View file

@ -206,7 +206,6 @@ INTERNAL int posn(const char set_string[], const char data);
`bin_posn`. Returns `bin_posn` + `length` */
INTERNAL int bin_append_posn(const int arg, const int length, char *binary, const int bin_posn);
#define Z_COMMON_INLINE 1
#ifdef Z_COMMON_INLINE
@ -267,7 +266,7 @@ INTERNAL int errtxt_adj(const int error_number, struct zint_symbol *symbol, cons
/* Whether `symbology` can have row binding */
INTERNAL int is_stackable(const int symbology);
INTERNAL int is_bindable(const int symbology);
/* Whether `symbology` is EAN/UPC */
INTERNAL int is_upcean(const int symbology);

View file

@ -80,12 +80,12 @@ static int cc_min(const int first, const int second) {
return second;
}
/* gets bit in bitString at bitPos */
/* Gets bit in bitString at bitPos */
static int cc_getBit(const unsigned short *bitStr, const int bitPos) {
return !!(bitStr[bitPos >> 4] & (0x8000 >> (bitPos & 15)));
}
/* converts bit string to base 928 values, codeWords[0] is highest order */
/* Converts bit string to base 928 values, codeWords[0] is highest order */
static int cc_encode928(const unsigned short bitString[], unsigned short codeWords[], const int bitLng) {
int i, j, b, cwNdx, cwLng;
for (cwNdx = cwLng = b = 0; b < bitLng; b += 69, cwNdx += 7) {
@ -101,7 +101,7 @@ static int cc_encode928(const unsigned short bitString[], unsigned short codeWor
}
}
for (i = cwCnt - 1; i > 0; i--) {
/* add "carries" */
/* Add "carries" */
codeWords[cwNdx + i - 1] += codeWords[cwNdx + i] / 928;
codeWords[cwNdx + i] %= 928;
}
@ -111,7 +111,7 @@ static int cc_encode928(const unsigned short bitString[], unsigned short codeWor
/* CC-A 2D component */
static void cc_a(struct zint_symbol *symbol, const char source[], const int cc_width) {
int i, segment, bitlen, cwCnt, variant, rows;
int i, segment, bitlen, cwCnt, variant;
int k, offset, j, total, rsCodeWords[8] = {0};
int LeftRAPStart, RightRAPStart, CentreRAPStart, StartCluster;
int LeftRAP, RightRAP, CentreRAP, Cluster;
@ -138,59 +138,42 @@ static void cc_a(struct zint_symbol *symbol, const char source[], const int cc_w
}
}
/* encode codeWords from bitStr */
/* Encode codeWords from bitStr */
cwCnt = cc_encode928(bitStr, codeWords, bitlen);
switch (cc_width) {
case 2:
switch (cwCnt) {
case 6: variant = 0;
break;
case 8: variant = 1;
break;
case 9: variant = 2;
break;
case 11: variant = 3;
break;
case 12: variant = 4;
break;
case 14: variant = 5;
break;
case 17: variant = 6;
break;
case 6: variant = 0; break;
case 8: variant = 1; break;
case 9: variant = 2; break;
case 11: variant = 3; break;
case 12: variant = 4; break;
case 14: variant = 5; break;
case 17: variant = 6; break;
}
break;
case 3:
switch (cwCnt) {
case 8: variant = 7;
break;
case 10: variant = 8;
break;
case 12: variant = 9;
break;
case 14: variant = 10;
break;
case 17: variant = 11;
break;
case 8: variant = 7; break;
case 10: variant = 8; break;
case 12: variant = 9; break;
case 14: variant = 10; break;
case 17: variant = 11; break;
}
break;
case 4:
switch (cwCnt) {
case 8: variant = 12;
break;
case 11: variant = 13;
break;
case 14: variant = 14;
break;
case 17: variant = 15;
break;
case 20: variant = 16;
break;
case 8: variant = 12; break;
case 11: variant = 13; break;
case 14: variant = 14; break;
case 17: variant = 15; break;
case 20: variant = 16; break;
}
break;
}
rows = cc_aVariants[variant];
symbol->rows = cc_aVariants[variant];
k = cc_aVariants[17 + variant];
offset = cc_aVariants[34 + variant];
@ -229,7 +212,7 @@ static void cc_a(struct zint_symbol *symbol, const char source[], const int cc_w
RightRAP = RightRAPStart;
Cluster = StartCluster; /* Cluster can be 0, 1 or 2 for Cluster(0), Cluster(3) and Cluster(6) */
for (i = 0; i < rows; i++) {
for (i = 0; i < symbol->rows; i++) {
bp = 0;
offset = 929 * Cluster;
k = i * cc_width;
@ -258,16 +241,15 @@ static void cc_a(struct zint_symbol *symbol, const char source[], const int cc_w
}
}
bp = bin_append_posn(pdf_rap_side[RightRAP - 1], 10, pattern, bp);
pattern[bp++] = '1'; /* stop */
pattern[bp++] = '1'; /* Stop */
/* so now pattern[] holds the string of '1's and '0's. - copy this to the symbol */
/* So now pattern[] holds the string of '1's and '0's. - copy this to the symbol */
for (loop = 0; loop < bp; loop++) {
if (pattern[loop] == '1') {
set_module(symbol, i, loop);
}
}
symbol->row_height[i] = 2;
symbol->rows++;
/* Set up RAPs and Cluster for next row */
LeftRAP++;
@ -400,10 +382,10 @@ static void cc_b(struct zint_symbol *symbol, const char source[], const int cc_w
assert(variant >= 0);
columns = pdf_MicroVariants[variant]; /* columns */
symbol->rows = pdf_MicroVariants[variant + 34]; /* rows */
k = pdf_MicroVariants[variant + 68]; /* number of EC CWs */
longueur = (columns * symbol->rows) - k; /* number of non-EC CWs */
i = longueur - mclength; /* amount of padding required */
offset = pdf_MicroVariants[variant + 102]; /* coefficient offset */
k = pdf_MicroVariants[variant + 68]; /* Number of EC CWs */
longueur = (columns * symbol->rows) - k; /* Number of non-EC CWs */
i = longueur - mclength; /* Amount of padding required */
offset = pdf_MicroVariants[variant + 102]; /* Coefficient offset */
/* Binary input padded to target length so no padding should be necessary */
while (i > 0) {
@ -429,7 +411,7 @@ static void cc_b(struct zint_symbol *symbol, const char source[], const int cc_w
mccorrection[j] = 929 - mccorrection[j];
}
}
/* we add these codes to the string */
/* We add these codes to the string */
for (i = k - 1; i >= 0; i--) {
chainemc[mclength++] = mccorrection[i];
}
@ -475,9 +457,9 @@ static void cc_b(struct zint_symbol *symbol, const char source[], const int cc_w
}
}
bp = bin_append_posn(pdf_rap_side[RightRAP - 1], 10, pattern, bp);
pattern[bp++] = '1'; /* stop */
pattern[bp++] = '1'; /* Stop */
/* so now pattern[] holds the string of '1's and '0's. - copy this to the symbol */
/* So now pattern[] holds the string of '1's and '0's. - copy this to the symbol */
for (loop = 0; loop < bp; loop++) {
if (pattern[loop] == '1') {
set_module(symbol, i, loop);
@ -536,7 +518,7 @@ static void cc_c(struct zint_symbol *symbol, const char source[], const int cc_w
}
}
chainemc[mclength++] = 0; /* space for length descriptor */
chainemc[mclength++] = 0; /* Space for length descriptor */
chainemc[mclength++] = 920; /* CC-C identifier */
pdf_byteprocess(chainemc, &mclength, data_string, 0, length, 0);
@ -556,24 +538,15 @@ static void cc_c(struct zint_symbol *symbol, const char source[], const int cc_w
/* 796 - we now take care of the Reed Solomon codes */
switch (ecc_level) {
case 1: offset = 2; /* Not reached */
break;
case 2: offset = 6; /* Min ECC currently used is 2 */
break;
case 3: offset = 14;
break;
case 4: offset = 30;
break;
case 5: offset = 62; /* Max ECC currently used is 5 */
break;
case 6: offset = 126; /* Not reached */
break;
case 7: offset = 254; /* Not reached */
break;
case 8: offset = 510; /* Not reached */
break;
default: offset = 0; /* Not reached */
break;
case 1: offset = 2; break; /* Not reached */
case 2: offset = 6; break; /* Min ECC currently used is 2 */
case 3: offset = 14; break;
case 4: offset = 30; break;
case 5: offset = 62; break; /* Max ECC currently used is 5 */
case 6: offset = 126; break; /* Not reached */
case 7: offset = 254; break; /* Not reached */
case 8: offset = 510; break; /* Not reached */
default: offset = 0; break; /* Not reached */
}
longueur = mclength;
@ -593,7 +566,7 @@ static void cc_c(struct zint_symbol *symbol, const char source[], const int cc_w
mccorrection[j] = 929 - mccorrection[j];
}
}
/* we add these codes to the string */
/* We add these codes to the string */
for (i = k - 1; i >= 0; i--) {
chainemc[mclength++] = mccorrection[i];
}
@ -604,7 +577,7 @@ static void cc_c(struct zint_symbol *symbol, const char source[], const int cc_w
c2 = ecc_level * 3 + (symbol->rows - 1) % 3;
c3 = cc_width - 1;
/* we now encode each row */
/* We now encode each row */
for (i = 0; i <= symbol->rows - 1; i++) {
for (j = 0; j < cc_width; j++) {
dummy[j + 1] = chainemc[i * cc_width + j];
@ -652,126 +625,40 @@ static void cc_c(struct zint_symbol *symbol, const char source[], const int cc_w
}
static int cc_a_calc_padding(const int binary_length, const int cc_width) {
static const short bin_lens[3][7] = {
{ 59, 78, 88, 108, 118, 138, 167 },
{ 78, 98, 118, 138, 167, 0, 0 },
{ 78, 108, 138, 167, 197, 0, 0 },
};
const short *bin_len = bin_lens[cc_width - 2];
int target_bitsize = 0;
int i;
switch (cc_width) {
case 2:
if (binary_length <= 59) {
target_bitsize = 59;
} else if (binary_length <= 78) {
target_bitsize = 78;
} else if (binary_length <= 88) {
target_bitsize = 88;
} else if (binary_length <= 108) {
target_bitsize = 108;
} else if (binary_length <= 118) {
target_bitsize = 118;
} else if (binary_length <= 138) {
target_bitsize = 138;
} else if (binary_length <= 167) {
target_bitsize = 167;
}
break;
case 3:
if (binary_length <= 78) {
target_bitsize = 78;
} else if (binary_length <= 98) {
target_bitsize = 98;
} else if (binary_length <= 118) {
target_bitsize = 118;
} else if (binary_length <= 138) {
target_bitsize = 138;
} else if (binary_length <= 167) {
target_bitsize = 167;
}
break;
case 4:
if (binary_length <= 78) {
target_bitsize = 78;
} else if (binary_length <= 108) {
target_bitsize = 108;
} else if (binary_length <= 138) {
target_bitsize = 138;
} else if (binary_length <= 167) {
target_bitsize = 167;
} else if (binary_length <= 197) {
target_bitsize = 197;
}
for (i = 0; i < ARRAY_SIZE(bin_lens[0]) && bin_len[i]; i++) {
if (binary_length <= bin_len[i]) {
target_bitsize = bin_len[i];
break;
}
}
return target_bitsize;
}
static int cc_b_calc_padding(const int binary_length, const int cc_width) {
static const short bin_lens[3][11] = {
{ 56, 104, 160, 208, 256, 296, 336, 0, 0, 0, 0 },
{ 32, 72, 112, 152, 208, 304, 416, 536, 648, 768, 0 },
{ 56, 96, 152, 208, 264, 352, 496, 672, 840, 1016, 1184 },
};
const short *bin_len = bin_lens[cc_width - 2];
int target_bitsize = 0;
int i;
switch (cc_width) {
case 2:
if (binary_length <= 56) {
target_bitsize = 56;
} else if (binary_length <= 104) {
target_bitsize = 104;
} else if (binary_length <= 160) {
target_bitsize = 160;
} else if (binary_length <= 208) {
target_bitsize = 208;
} else if (binary_length <= 256) {
target_bitsize = 256;
} else if (binary_length <= 296) {
target_bitsize = 296;
} else if (binary_length <= 336) {
target_bitsize = 336;
}
break;
case 3:
if (binary_length <= 32) {
target_bitsize = 32;
} else if (binary_length <= 72) {
target_bitsize = 72;
} else if (binary_length <= 112) {
target_bitsize = 112;
} else if (binary_length <= 152) {
target_bitsize = 152;
} else if (binary_length <= 208) {
target_bitsize = 208;
} else if (binary_length <= 304) {
target_bitsize = 304;
} else if (binary_length <= 416) {
target_bitsize = 416;
} else if (binary_length <= 536) {
target_bitsize = 536;
} else if (binary_length <= 648) {
target_bitsize = 648;
} else if (binary_length <= 768) {
target_bitsize = 768;
}
break;
case 4:
if (binary_length <= 56) {
target_bitsize = 56;
} else if (binary_length <= 96) {
target_bitsize = 96;
} else if (binary_length <= 152) {
target_bitsize = 152;
} else if (binary_length <= 208) {
target_bitsize = 208;
} else if (binary_length <= 264) {
target_bitsize = 264;
} else if (binary_length <= 352) {
target_bitsize = 352;
} else if (binary_length <= 496) {
target_bitsize = 496;
} else if (binary_length <= 672) {
target_bitsize = 672;
} else if (binary_length <= 840) {
target_bitsize = 840;
} else if (binary_length <= 1016) {
target_bitsize = 1016;
} else if (binary_length <= 1184) {
target_bitsize = 1184;
}
for (i = 0; i < ARRAY_SIZE(bin_lens[0]) && bin_len[i]; i++) {
if (binary_length <= bin_len[i]) {
target_bitsize = bin_len[i];
break;
}
}
return target_bitsize;
@ -820,7 +707,7 @@ static int cc_c_calc_padding(const int binary_length, int *p_cc_width, const int
}
assert(*p_cc_width > 0);
rows = (int) ceil((double) codewords_used / *p_cc_width);
/* stop the symbol from becoming too high */
/* Stop the symbol from becoming too high */
while (rows > 30 && *p_cc_width < 30) {
(*p_cc_width)++;
rows = (int) ceil((double) codewords_used / *p_cc_width);
@ -967,7 +854,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour
}
}
/* must start with 0, 1, 2 or 3 digits followed by an uppercase character */
/* Must start with 0, 1, 2 or 3 digits followed by an uppercase character */
alpha_posn = -1;
if (ninety_len && ninety[0] != '0') { /* Leading zeros are not permitted */
for (i = 0; i < ninety_len && i < 4; i++) {
@ -1028,12 +915,15 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour
}
switch (ai_crop) {
case 0: binary_string[bp++] = '0';
case 0:
binary_string[bp++] = '0';
break;
case 1: bp = bin_append_posn(2, 2, binary_string, bp); /* "10" */
case 1:
bp = bin_append_posn(2, 2, binary_string, bp); /* "10" */
ai_crop_posn = next_ai_posn + 1;
break;
case 3: bp = bin_append_posn(3, 2, binary_string, bp); /* "11" */
case 3:
bp = bin_append_posn(3, 2, binary_string, bp); /* "11" */
ai_crop_posn = next_ai_posn + 1;
break;
}
@ -1050,7 +940,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour
/* five bit binary string representing value before letter */
bp = bin_append_posn(numeric_value, 5, binary_string, bp);
/* followed by four bit representation of letter from Table 3 */
/* Followed by four bit representation of letter from Table 3 */
bp = bin_append_posn(table3_letter, 4, binary_string, bp);
} else {
/* Encoding is done according to 5.3.2 c) 3) */
@ -1169,15 +1059,9 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour
}
switch (cc_mode) {
case 1:
target_bitsize = cc_a_calc_padding(bp, *p_cc_width);
break;
case 2:
target_bitsize = cc_b_calc_padding(bp, *p_cc_width);
break;
case 3:
target_bitsize = cc_c_calc_padding(bp, p_cc_width, linear_width, p_ecc_level);
break;
case 1: target_bitsize = cc_a_calc_padding(bp, *p_cc_width); break;
case 2: target_bitsize = cc_b_calc_padding(bp, *p_cc_width); break;
case 3: target_bitsize = cc_c_calc_padding(bp, p_cc_width, linear_width, p_ecc_level); break;
}
if (target_bitsize == 0) {
@ -1313,24 +1197,15 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 449, "Input length %d wrong (linear component)", pri_len);
}
break;
case BARCODE_GS1_128_CC: cc_width = 4;
break;
case BARCODE_DBAR_OMN_CC: cc_width = 4;
break;
case BARCODE_DBAR_LTD_CC: cc_width = 3;
break;
case BARCODE_DBAR_EXP_CC: cc_width = 4;
break;
case BARCODE_UPCA_CC: cc_width = 4;
break;
case BARCODE_UPCE_CC: cc_width = 2;
break;
case BARCODE_DBAR_STK_CC: cc_width = 2;
break;
case BARCODE_DBAR_OMNSTK_CC: cc_width = 2;
break;
case BARCODE_DBAR_EXPSTK_CC: cc_width = 4;
break;
case BARCODE_GS1_128_CC: cc_width = 4; break;
case BARCODE_DBAR_OMN_CC: cc_width = 4; break;
case BARCODE_DBAR_LTD_CC: cc_width = 3; break;
case BARCODE_DBAR_EXP_CC: cc_width = 4; break;
case BARCODE_UPCA_CC: cc_width = 4; break;
case BARCODE_UPCE_CC: cc_width = 2; break;
case BARCODE_DBAR_STK_CC: cc_width = 2; break;
case BARCODE_DBAR_OMNSTK_CC: cc_width = 2; break;
case BARCODE_DBAR_EXPSTK_CC: cc_width = 4; break;
}
if (cc_mode < 1 || cc_mode > 3) {
@ -1369,14 +1244,14 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
}
}
symbol->rows = 0; /* Composites are not stackable */
switch (cc_mode) {
/* Note that ecc_level is only relevant to CC-C */
case 1: cc_a(symbol, binary_string, cc_width);
break;
case 2: cc_b(symbol, binary_string, cc_width);
break;
case 3: cc_c(symbol, binary_string, cc_width, ecc_level);
break;
/* Note that ecc_level is only relevant to CC-C */
case 1: cc_a(symbol, binary_string, cc_width); break;
case 2: cc_b(symbol, binary_string, cc_width); break;
case 3: cc_c(symbol, binary_string, cc_width, ecc_level); break;
default: assert(0); break; /* Not reached */
}
if (symbol->option_1 >= 1 && symbol->option_1 <= 3 && symbol->option_1 != cc_mode) {
@ -1497,7 +1372,8 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
}
}
break;
case BARCODE_DBAR_OMN_CC: bottom_shift = 4;
case BARCODE_DBAR_OMN_CC:
bottom_shift = 4;
break;
case BARCODE_DBAR_LTD_CC:
if (cc_mode == 1) {
@ -1510,13 +1386,17 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
for (k = 1; !module_is_set(linear, 1, k - 1) && module_is_set(linear, 1, k); k++);
top_shift = k;
break;
case BARCODE_UPCA_CC: bottom_shift = 2;
case BARCODE_UPCA_CC:
bottom_shift = 2;
break;
case BARCODE_UPCE_CC: bottom_shift = 2;
case BARCODE_UPCE_CC:
bottom_shift = 2;
break;
case BARCODE_DBAR_STK_CC: top_shift = 1;
case BARCODE_DBAR_STK_CC:
top_shift = 1;
break;
case BARCODE_DBAR_OMNSTK_CC: top_shift = 1;
case BARCODE_DBAR_OMNSTK_CC:
top_shift = 1;
break;
case BARCODE_DBAR_EXPSTK_CC:
for (k = 1; !module_is_set(linear, 1, k - 1) && module_is_set(linear, 1, k); k++);
@ -1530,7 +1410,7 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
if (top_shift != 0) {
/* Move the 2D component of the symbol horizontally */
for (i = 0; i <= symbol->rows; i++) {
for (i = 0; i < symbol->rows; i++) {
for (j = (symbol->width + top_shift); j >= top_shift; j--) {
if (module_is_set(symbol, i, j - top_shift)) {
set_module(symbol, i, j);
@ -1545,7 +1425,7 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
}
/* Merge linear and 2D components into one structure */
for (i = 0; i <= linear->rows; i++) {
for (i = 0; i < linear->rows; i++) {
symbol->row_height[symbol->rows + i] = linear->row_height[i];
for (j = 0; j <= linear->width; j++) {
if (module_is_set(linear, i, j)) {
@ -1569,15 +1449,15 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
/* If symbol->height given then min row height was returned, else default height */
if (error_number == 0) { /* Avoid overwriting any `gs1_verify()` warning */
error_number = set_height(symbol, symbol->height ? linear->height : 0.0f,
symbol->height ? 0.0f : linear->height, 0.0f, 0 /*no_errtxt*/);
symbol->height ? 0.0f : linear->height, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, symbol->height ? linear->height : 0.0f,
symbol->height ? 0.0f : linear->height, 0.0f, 1 /*no_errtxt*/);
symbol->height ? 0.0f : linear->height, 0.0f, 1 /*no_errtxt*/);
}
} else {
/* If symbol->height given then min row height was returned, else default height */
error_number = set_height(symbol, symbol->height ? linear->height : 0.0f,
symbol->height ? 0.0f : linear->height, 0.0f, 0 /*no_errtxt*/);
symbol->height ? 0.0f : linear->height, 0.0f, 0 /*no_errtxt*/);
}
} else {
if (symbol->symbology == BARCODE_DBAR_STK_CC) {

View file

@ -306,14 +306,10 @@ static int dm_look_ahead_test(const unsigned char source[], const int length, co
}
switch (current_mode) {
case DM_C40: c40_count = 0;
break;
case DM_TEXT: text_count = 0;
break;
case DM_X12: x12_count = 0;
break;
case DM_EDIFACT: edf_count = 0;
break;
case DM_C40: c40_count = 0; break;
case DM_TEXT: text_count = 0; break;
case DM_X12: x12_count = 0; break;
case DM_EDIFACT: edf_count = 0; break;
case DM_BASE256:
b256_count = mode_arg == 249 ? DM_MULT_1 : 0; /* Adjusted to use no. of bytes written */
break;
@ -656,19 +652,24 @@ static int dm_switch_mode(const int next_mode, unsigned char target[], int tp, i
case DM_ASCII:
if (debug_print) fputs("ASC ", stdout);
break;
case DM_C40: target[tp++] = 230;
case DM_C40:
target[tp++] = 230;
if (debug_print) fputs("C40 ", stdout);
break;
case DM_TEXT: target[tp++] = 239;
case DM_TEXT:
target[tp++] = 239;
if (debug_print) fputs("TEX ", stdout);
break;
case DM_X12: target[tp++] = 238;
case DM_X12:
target[tp++] = 238;
if (debug_print) fputs("X12 ", stdout);
break;
case DM_EDIFACT: target[tp++] = 240;
case DM_EDIFACT:
target[tp++] = 240;
if (debug_print) fputs("EDI ", stdout);
break;
case DM_BASE256: target[tp++] = 231;
case DM_BASE256:
target[tp++] = 231;
*p_b256_start = tp;
target[tp++] = 0; /* Byte count holder (may be expanded to 2 codewords) */
if (debug_print) fputs("BAS ", stdout);

View file

@ -1219,7 +1219,7 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i
int jc, n_dots;
int data_length, ecc_length;
int min_dots, min_area;
int height, width;
int height, width = 0;
int mask_score[8];
int user_mask;
int dot_stream_length;
@ -1243,6 +1243,14 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i
symbol->eci);
}
if (symbol->option_2 > 0) {
if (symbol->option_2 < 5 || symbol->option_2 > 200) {
return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 527,
"Number of columns '%d' is out of range (5 to 200)", symbol->option_2);
}
width = symbol->option_2;
}
user_mask = (symbol->option_3 >> 8) & 0x0F; /* User mask is mask + 1, so >= 1 and <= 8 */
if (user_mask > 8) {
user_mask = 0; /* Ignore */
@ -1293,7 +1301,7 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i
min_dots = 9 * (data_length + 3 + (data_length / 2)) + 2;
min_area = min_dots * 2;
if (symbol->option_2 == 0) {
if (width == 0) {
/* Automatic sizing */
/* Following Rule 3 (Section 5.2.2) and applying a recommended width to height ratio 3:2 */
/* Eliminates undersized symbols */
@ -1334,8 +1342,9 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i
} else {
/* User defined width */
width = symbol->option_2;
height = (min_area + (width - 1)) / width;
if ((height = (min_area + (width - 1)) / width) < 5) {
height = 5;
}
if (!((width + height) & 1)) {
height++;
@ -1359,9 +1368,9 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i
if ((height < 5) || (width < 5)) {
assert(height >= 5 || width >= 5); /* If width < 5, min height is 19 */
ZEXT errtxtf(0, symbol, 529, "Resulting symbol %1$s '%2$d' is too small (minimum 5)",
width < 5 ? "width" : "height", width < 5 ? width : height);
return ZINT_ERROR_INVALID_OPTION;
return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 529,
"Resulting symbol %1$s '%2$d' is too small (minimum 5)",
width < 5 ? "width" : "height", width < 5 ? width : height);
}
n_dots = (height * width) / 2;

View file

@ -363,88 +363,67 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
switch (current_mode) {
case 0:
switch (next_mode) {
case GM_CHINESE: bp = bin_append_posn(1, 4, binary, bp);
break;
case GM_NUMBER: bp = bin_append_posn(2, 4, binary, bp);
break;
case GM_LOWER: bp = bin_append_posn(3, 4, binary, bp);
break;
case GM_UPPER: bp = bin_append_posn(4, 4, binary, bp);
break;
case GM_MIXED: bp = bin_append_posn(5, 4, binary, bp);
break;
case GM_BYTE: bp = bin_append_posn(6, 4, binary, bp);
break;
case GM_CHINESE: bp = bin_append_posn(1, 4, binary, bp); break;
case GM_NUMBER: bp = bin_append_posn(2, 4, binary, bp); break;
case GM_LOWER: bp = bin_append_posn(3, 4, binary, bp); break;
case GM_UPPER: bp = bin_append_posn(4, 4, binary, bp); break;
case GM_MIXED: bp = bin_append_posn(5, 4, binary, bp); break;
case GM_BYTE: bp = bin_append_posn(6, 4, binary, bp); break;
}
break;
case GM_CHINESE:
switch (next_mode) {
case GM_NUMBER: bp = bin_append_posn(8161, 13, binary, bp);
break;
case GM_LOWER: bp = bin_append_posn(8162, 13, binary, bp);
break;
case GM_UPPER: bp = bin_append_posn(8163, 13, binary, bp);
break;
case GM_MIXED: bp = bin_append_posn(8164, 13, binary, bp);
break;
case GM_BYTE: bp = bin_append_posn(8165, 13, binary, bp);
break;
case GM_NUMBER: bp = bin_append_posn(8161, 13, binary, bp); break;
case GM_LOWER: bp = bin_append_posn(8162, 13, binary, bp); break;
case GM_UPPER: bp = bin_append_posn(8163, 13, binary, bp); break;
case GM_MIXED: bp = bin_append_posn(8164, 13, binary, bp); break;
case GM_BYTE: bp = bin_append_posn(8165, 13, binary, bp); break;
}
break;
case GM_NUMBER:
/* add numeric block padding value */
switch (p) {
case 1: binary[number_pad_posn] = '1';
case 1:
binary[number_pad_posn] = '1';
binary[number_pad_posn + 1] = '0';
break; /* 2 pad digits */
case 2: binary[number_pad_posn] = '0';
case 2:
binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '1';
break; /* 1 pad digits */
case 3: binary[number_pad_posn] = '0';
case 3:
binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '0';
break; /* 0 pad digits */
}
switch (next_mode) {
case GM_CHINESE: bp = bin_append_posn(1019, 10, binary, bp);
break;
case GM_LOWER: bp = bin_append_posn(1020, 10, binary, bp);
break;
case GM_UPPER: bp = bin_append_posn(1021, 10, binary, bp);
break;
case GM_MIXED: bp = bin_append_posn(1022, 10, binary, bp);
break;
case GM_BYTE: bp = bin_append_posn(1023, 10, binary, bp);
break;
case GM_CHINESE: bp = bin_append_posn(1019, 10, binary, bp); break;
case GM_LOWER: bp = bin_append_posn(1020, 10, binary, bp); break;
case GM_UPPER: bp = bin_append_posn(1021, 10, binary, bp); break;
case GM_MIXED: bp = bin_append_posn(1022, 10, binary, bp); break;
case GM_BYTE: bp = bin_append_posn(1023, 10, binary, bp); break;
}
break;
case GM_LOWER:
case GM_UPPER:
switch (next_mode) {
case GM_CHINESE: bp = bin_append_posn(28, 5, binary, bp);
break;
case GM_NUMBER: bp = bin_append_posn(29, 5, binary, bp);
break;
case GM_CHINESE: bp = bin_append_posn(28, 5, binary, bp); break;
case GM_NUMBER: bp = bin_append_posn(29, 5, binary, bp); break;
case GM_LOWER:
case GM_UPPER: bp = bin_append_posn(30, 5, binary, bp);
break;
case GM_MIXED: bp = bin_append_posn(124, 7, binary, bp);
break;
case GM_BYTE: bp = bin_append_posn(126, 7, binary, bp);
case GM_UPPER:
bp = bin_append_posn(30, 5, binary, bp);
break;
case GM_MIXED: bp = bin_append_posn(124, 7, binary, bp); break;
case GM_BYTE: bp = bin_append_posn(126, 7, binary, bp); break;
}
break;
case GM_MIXED:
switch (next_mode) {
case GM_CHINESE: bp = bin_append_posn(1009, 10, binary, bp);
break;
case GM_NUMBER: bp = bin_append_posn(1010, 10, binary, bp);
break;
case GM_LOWER: bp = bin_append_posn(1011, 10, binary, bp);
break;
case GM_UPPER: bp = bin_append_posn(1012, 10, binary, bp);
break;
case GM_BYTE: bp = bin_append_posn(1015, 10, binary, bp);
break;
case GM_CHINESE: bp = bin_append_posn(1009, 10, binary, bp); break;
case GM_NUMBER: bp = bin_append_posn(1010, 10, binary, bp); break;
case GM_LOWER: bp = bin_append_posn(1011, 10, binary, bp); break;
case GM_UPPER: bp = bin_append_posn(1012, 10, binary, bp); break;
case GM_BYTE: bp = bin_append_posn(1015, 10, binary, bp); break;
}
break;
case GM_BYTE:
@ -452,33 +431,22 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
gm_add_byte_count(binary, byte_count_posn, byte_count);
byte_count = 0;
switch (next_mode) {
case GM_CHINESE: bp = bin_append_posn(1, 4, binary, bp);
break;
case GM_NUMBER: bp = bin_append_posn(2, 4, binary, bp);
break;
case GM_LOWER: bp = bin_append_posn(3, 4, binary, bp);
break;
case GM_UPPER: bp = bin_append_posn(4, 4, binary, bp);
break;
case GM_MIXED: bp = bin_append_posn(5, 4, binary, bp);
break;
case GM_CHINESE: bp = bin_append_posn(1, 4, binary, bp); break;
case GM_NUMBER: bp = bin_append_posn(2, 4, binary, bp); break;
case GM_LOWER: bp = bin_append_posn(3, 4, binary, bp); break;
case GM_UPPER: bp = bin_append_posn(4, 4, binary, bp); break;
case GM_MIXED: bp = bin_append_posn(5, 4, binary, bp); break;
}
break;
}
if (debug_print) {
switch (next_mode) {
case GM_CHINESE: fputs("CHIN ", stdout);
break;
case GM_NUMBER: fputs("NUMB ", stdout);
break;
case GM_LOWER: fputs("LOWR ", stdout);
break;
case GM_UPPER: fputs("UPPR ", stdout);
break;
case GM_MIXED: fputs("MIXD ", stdout);
break;
case GM_BYTE: fputs("BYTE ", stdout);
break;
case GM_CHINESE: fputs("CHIN ", stdout); break;
case GM_NUMBER: fputs("NUMB ", stdout); break;
case GM_LOWER: fputs("LOWR ", stdout); break;
case GM_UPPER: fputs("UPPR ", stdout); break;
case GM_MIXED: fputs("MIXD ", stdout); break;
case GM_BYTE: fputs("BYTE ", stdout); break;
}
}
}
@ -575,18 +543,12 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
if (ppos != -1) {
switch (punt) {
case ' ': glyph = 0;
break;
case '+': glyph = 3;
break;
case '-': glyph = 6;
break;
case '.': glyph = 9;
break;
case ',': glyph = 12;
break;
case 13: glyph = 15;
break;
case ' ': glyph = 0; break;
case '+': glyph = 3; break;
case '-': glyph = 6; break;
case '.': glyph = 9; break;
case ',': glyph = 12; break;
case 13: glyph = 15; break;
}
glyph += ppos;
glyph += 1000;
@ -726,13 +688,16 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
if (current_mode == GM_NUMBER) {
/* add numeric block padding value */
switch (p) {
case 1: binary[number_pad_posn] = '1';
case 1:
binary[number_pad_posn] = '1';
binary[number_pad_posn + 1] = '0';
break; /* 2 pad digits */
case 2: binary[number_pad_posn] = '0';
case 2:
binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '1';
break; /* 1 pad digit */
case 3: binary[number_pad_posn] = '0';
case 3:
binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '0';
break; /* 0 pad digits */
}
@ -745,17 +710,14 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
/* Add "end of data" character */
switch (current_mode) {
case GM_CHINESE: bp = bin_append_posn(8160, 13, binary, bp);
break;
case GM_NUMBER: bp = bin_append_posn(1018, 10, binary, bp);
break;
case GM_CHINESE: bp = bin_append_posn(8160, 13, binary, bp); break;
case GM_NUMBER: bp = bin_append_posn(1018, 10, binary, bp); break;
case GM_LOWER:
case GM_UPPER: bp = bin_append_posn(27, 5, binary, bp);
break;
case GM_MIXED: bp = bin_append_posn(1008, 10, binary, bp);
break;
case GM_BYTE: bp = bin_append_posn(0, 4, binary, bp);
case GM_UPPER:
bp = bin_append_posn(27, 5, binary, bp);
break;
case GM_MIXED: bp = bin_append_posn(1008, 10, binary, bp); break;
case GM_BYTE: bp = bin_append_posn(0, 4, binary, bp); break;
}
if (bp > 9191) {
@ -1187,14 +1149,10 @@ INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], cons
data_max = 1313;
switch (ecc_level) {
case 2: data_max = 1167;
break;
case 3: data_max = 1021;
break;
case 4: data_max = 875;
break;
case 5: data_max = 729;
break;
case 2: data_max = 1167; break;
case 3: data_max = 1021; break;
case 4: data_max = 875; break;
case 5: data_max = 729; break;
}
if (data_cw > data_max) {

View file

@ -324,7 +324,7 @@ static int dump_plot(struct zint_symbol *symbol) {
byt += 1;
}
}
if (((i + 1) % 4) == 0) {
if ((i + 1) % 4 == 0) {
fputc(hex[byt], f);
space++;
byt = 0;
@ -335,7 +335,7 @@ static int dump_plot(struct zint_symbol *symbol) {
}
}
if ((symbol->width % 4) != 0) {
if (symbol->width % 4 != 0) {
byt = byt << (4 - (symbol->width % 4));
fputc(hex[byt], f);
}
@ -740,7 +740,7 @@ static int esc_base(struct zint_symbol *symbol, const unsigned char *input_strin
val = (c1 << 6) | (c2 << 3) | c3;
}
} else {
if ((c1 >= 0) && (c2 >= 0)) {
if (c1 >= 0 && c2 >= 0) {
val = (c1 << 4) | c2;
}
}
@ -1138,29 +1138,29 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[
}
/* Check other symbol fields */
if ((symbol->scale < 0.01f) || (symbol->scale > 200.0f)) {
if (symbol->scale < 0.01f || symbol->scale > 200.0f) {
return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, 227, "Scale out of range (0.01 to 200)");
}
if ((symbol->dot_size < 0.01f) || (symbol->dot_size > 20.0f)) {
if (symbol->dot_size < 0.01f || symbol->dot_size > 20.0f) {
return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, 221, "Dot size out of range (0.01 to 20)");
}
if ((symbol->height < 0.0f) || (symbol->height > 2000.0f)) { /* Allow for 44 row CODABLOCKF at 45X each */
if (symbol->height < 0.0f || symbol->height > 2000.0f) { /* Allow for 44 row CODABLOCKF at 45X each */
return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, 765, "Height out of range (0 to 2000)");
}
if ((symbol->guard_descent < 0.0f) || (symbol->guard_descent > 50.0f)) {
if (symbol->guard_descent < 0.0f || symbol->guard_descent > 50.0f) {
return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, 769, "Guard bar descent out of range (0 to 50)");
}
if ((symbol->text_gap < -5.0f) || (symbol->text_gap > 10.0f)) {
if (symbol->text_gap < -5.0f || symbol->text_gap > 10.0f) {
return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, 219, "Text gap out of range (-5 to 10)");
}
if ((symbol->whitespace_width < 0) || (symbol->whitespace_width > 100)) {
if (symbol->whitespace_width < 0 || symbol->whitespace_width > 100) {
return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, 766, "Whitespace width out of range (0 to 100)");
}
if ((symbol->whitespace_height < 0) || (symbol->whitespace_height > 100)) {
if (symbol->whitespace_height < 0 || symbol->whitespace_height > 100) {
return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, 767, "Whitespace height out of range (0 to 100)");
}
if ((symbol->border_width < 0) || (symbol->border_width > 100)) {
if (symbol->border_width < 0 || symbol->border_width > 100) {
return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, 768, "Border width out of range (0 to 100)");
}
@ -1687,8 +1687,15 @@ unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag) {
if ((cap_flag & ZINT_CAP_HRT) && has_hrt(symbol_id)) {
result |= ZINT_CAP_HRT;
}
if ((cap_flag & ZINT_CAP_STACKABLE) && is_stackable(symbol_id)) {
result |= ZINT_CAP_STACKABLE;
if ((cap_flag & ZINT_CAP_STACKABLE) && is_bindable(symbol_id)) {
switch (symbol_id) {
case BARCODE_CODE16K: /* Stacked are not stackable */
case BARCODE_CODE49:
break;
default:
result |= ZINT_CAP_STACKABLE;
break;
}
}
if ((cap_flag & ZINT_CAP_EANUPC) && is_upcean(symbol_id)) {
result |= ZINT_CAP_EANUPC;
@ -1824,6 +1831,9 @@ unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag) {
break;
}
}
if ((cap_flag & ZINT_CAP_BINDABLE) && is_bindable(symbol_id)) {
result |= ZINT_CAP_BINDABLE;
}
return result;
}

View file

@ -173,45 +173,57 @@ static int pdf_textprocess_switch(const int curtable, const int newtable, unsign
switch (curtable) {
case T_ALPHA:
switch (newtable) {
case T_LOWER: chainet[wnet++] = 27; /* LL */
case T_LOWER:
chainet[wnet++] = 27; /* LL */
break;
case T_MIXED: chainet[wnet++] = 28; /* ML */
case T_MIXED:
chainet[wnet++] = 28; /* ML */
break;
case T_PUNCT: chainet[wnet++] = 28; /* ML+PL */
case T_PUNCT:
chainet[wnet++] = 28; /* ML+PL */
chainet[wnet++] = 25;
break;
}
break;
case T_LOWER:
switch (newtable) {
case T_ALPHA: chainet[wnet++] = 28; /* ML+AL */
case T_ALPHA:
chainet[wnet++] = 28; /* ML+AL */
chainet[wnet++] = 28;
break;
case T_MIXED: chainet[wnet++] = 28; /* ML */
case T_MIXED:
chainet[wnet++] = 28; /* ML */
break;
case T_PUNCT: chainet[wnet++] = 28; /* ML+PL */
case T_PUNCT:
chainet[wnet++] = 28; /* ML+PL */
chainet[wnet++] = 25;
break;
}
break;
case T_MIXED:
switch (newtable) {
case T_ALPHA: chainet[wnet++] = 28; /* AL */
case T_ALPHA:
chainet[wnet++] = 28; /* AL */
break;
case T_LOWER: chainet[wnet++] = 27; /* LL */
case T_LOWER:
chainet[wnet++] = 27; /* LL */
break;
case T_PUNCT: chainet[wnet++] = 25; /* PL */
case T_PUNCT:
chainet[wnet++] = 25; /* PL */
break;
}
break;
case T_PUNCT:
switch (newtable) {
case T_ALPHA: chainet[wnet++] = 29; /* AL */
case T_ALPHA:
chainet[wnet++] = 29; /* AL */
break;
case T_LOWER: chainet[wnet++] = 29; /* AL+LL */
case T_LOWER:
chainet[wnet++] = 29; /* AL+LL */
chainet[wnet++] = 27;
break;
case T_MIXED: chainet[wnet++] = 29; /* AL+ML */
case T_MIXED:
chainet[wnet++] = 29; /* AL+ML */
chainet[wnet++] = 28;
break;
}
@ -1345,24 +1357,15 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int
/* 796 - we now take care of the Reed Solomon codes */
switch (ecc) {
case 1: offset = 2;
break;
case 2: offset = 6;
break;
case 3: offset = 14;
break;
case 4: offset = 30;
break;
case 5: offset = 62;
break;
case 6: offset = 126;
break;
case 7: offset = 254;
break;
case 8: offset = 510;
break;
default: offset = 0;
break;
case 1: offset = 2; break;
case 2: offset = 6; break;
case 3: offset = 14; break;
case 4: offset = 30; break;
case 5: offset = 62; break;
case 6: offset = 126; break;
case 7: offset = 254; break;
case 8: offset = 510; break;
default: offset = 0; break;
}
for (i = 0; i < mclength; i++) {
@ -1744,6 +1747,7 @@ INTERNAL int micropdf417(struct zint_symbol *symbol, struct zint_seg segs[], con
/* Cluster can be 0, 1 or 2 for Cluster(0), Cluster(3) and Cluster(6) */
if (debug_print) fputs("\nInternal row representation:\n", stdout);
for (i = 0; i < symbol->rows; i++) {
if (debug_print) printf("row %d: ", i);
bp = 0;

View file

@ -99,10 +99,12 @@ INTERNAL int plessey(struct zint_symbol *symbol, unsigned char source[], int len
for (i = 0; i < 8; i++) {
switch (checkptr[length * 4 + i]) {
case 0: memcpy(d, "13", 2);
case 0:
memcpy(d, "13", 2);
d += 2;
break;
case 1: memcpy(d, "31", 2);
case 1:
memcpy(d, "31", 2);
d += 2;
check_digits |= (1 << i);
break;
@ -352,20 +354,13 @@ INTERNAL int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int
d += 2;
switch (check_option) {
case 0: d = msi_plessey_nomod(symbol, source, length, raw_text, d);
break;
case 1: d = msi_plessey_mod10(symbol, source, length, no_checktext, raw_text, d);
break;
case 2: d = msi_plessey_mod1010(symbol, source, length, no_checktext, raw_text, d);
break;
case 3: d = msi_plessey_mod11(symbol, source, length, no_checktext, 7 /*IBM wrap*/, raw_text, d);
break;
case 4: d = msi_plessey_mod1110(symbol, source, length, no_checktext, 7 /*IBM wrap*/, raw_text, d);
break;
case 5: d = msi_plessey_mod11(symbol, source, length, no_checktext, 9 /*NCR wrap*/, raw_text, d);
break;
case 6: d = msi_plessey_mod1110(symbol, source, length, no_checktext, 9 /*NCR wrap*/, raw_text, d);
break;
case 0: d = msi_plessey_nomod(symbol, source, length, raw_text, d); break;
case 1: d = msi_plessey_mod10(symbol, source, length, no_checktext, raw_text, d); break;
case 2: d = msi_plessey_mod1010(symbol, source, length, no_checktext, raw_text, d); break;
case 3: d = msi_plessey_mod11(symbol, source, length, no_checktext, 7 /*IBM wrap*/, raw_text, d); break;
case 4: d = msi_plessey_mod1110(symbol, source, length, no_checktext, 7 /*IBM wrap*/, raw_text, d); break;
case 5: d = msi_plessey_mod11(symbol, source, length, no_checktext, 9 /*NCR wrap*/, raw_text, d); break;
case 6: d = msi_plessey_mod1110(symbol, source, length, no_checktext, 9 /*NCR wrap*/, raw_text, d); break;
}
if (!d) {

View file

@ -1293,12 +1293,9 @@ static void qr_add_format_info(unsigned char *grid, const int size, const int ec
int i;
switch (ecc_level) {
case QR_LEVEL_L: format |= 0x08;
break;
case QR_LEVEL_Q: format |= 0x18;
break;
case QR_LEVEL_H: format |= 0x10;
break;
case QR_LEVEL_L: format |= 0x08; break;
case QR_LEVEL_Q: format |= 0x18; break;
case QR_LEVEL_H: format |= 0x10; break;
}
seq = qr_annex_c[format];
@ -2067,14 +2064,10 @@ static int microqr_evaluate(const unsigned char *grid, const int size, const int
int sum1, sum2, i, filter = 0, retval;
switch (pattern) {
case 0: filter = 0x01;
break;
case 1: filter = 0x02;
break;
case 2: filter = 0x04;
break;
case 3: filter = 0x08;
break;
case 0: filter = 0x01; break;
case 1: filter = 0x02; break;
case 2: filter = 0x04; break;
case 3: filter = 0x08; break;
}
sum1 = 0;
@ -2418,8 +2411,6 @@ INTERNAL int upnqr(struct zint_symbol *symbol, unsigned char source[], int lengt
char *mode = (char *) z_alloca(length + 1);
unsigned char *preprocessed = (unsigned char *) z_alloca(length + 1);
symbol->eci = 4; /* Set before any processing */
user_mask = (symbol->option_3 >> 8) & 0x0F; /* User mask is pattern + 1, so >= 1 and <= 8 */
if (user_mask > 8) {
user_mask = 0; /* Ignore */

View file

@ -1341,7 +1341,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
}
/* Separator binding for stacked barcodes */
if ((symbol->output_options & BARCODE_BIND) && (symbol->rows > 1) && is_stackable(symbol->symbology)) {
if ((symbol->output_options & BARCODE_BIND) && symbol->rows > 1 && is_bindable(symbol->symbology)) {
int sep_xoffset_si = xoffset_si;
int sep_width_si = symbol->width * si;
int sep_height_si, sep_yoffset_si;

View file

@ -127,7 +127,7 @@ static void getRSSwidths(int widths[], int val, int n, const int elements, const
/* Get all combinations */
subVal = rss_combins(n - elmWidth - 1, elements - bar - 2);
/* Less combinations with no single-module element */
if ((!noNarrow) && (!narrowMask)
if (!noNarrow && !narrowMask
&& (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) {
subVal -= rss_combins(n - elmWidth - (elements - bar), elements - bar - 2);
}
@ -295,12 +295,10 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
int data_character[4] = {0}, data_group[4] = {0}, v_odd[4], v_even[4];
int data_widths[8][4], checksum, c_left, c_right, total_widths[46], writer;
int latch;
int separator_row;
int separator_row = 0;
int widths[4];
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT;
separator_row = 0;
if (length > 14) { /* Allow check digit to be specified (will be verified and ignored) */
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 380, "Input length %d too long (maximum 14)", length);
}
@ -317,14 +315,17 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
length--; /* Ignore */
}
if (symbol->symbology != BARCODE_DBAR_OMN) {
symbol->rows = 0; /* Stacked (and composites) are not stackable */
}
/* Make some room for a separator row for composite symbols */
switch (symbol->symbology) {
case BARCODE_DBAR_OMN_CC:
case BARCODE_DBAR_STK_CC:
case BARCODE_DBAR_OMNSTK_CC:
separator_row = symbol->rows;
separator_row = symbol->rows++;
symbol->row_height[separator_row] = 1;
symbol->rows += 1;
break;
}
@ -405,7 +406,7 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
/* Use DataBar subset width algorithm */
for (i = 0; i < 4; i++) {
if ((i == 0) || (i == 2)) {
if (i == 0 || i == 2) {
getRSSwidths(widths, v_odd[i], dbar_modules_odd[data_group[i]], 4, dbar_widest_odd[data_group[i]], 1);
data_widths[0][i] = widths[0];
data_widths[2][i] = widths[1];
@ -471,7 +472,7 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
}
/* Put this data into the symbol */
if ((symbol->symbology == BARCODE_DBAR_OMN) || (symbol->symbology == BARCODE_DBAR_OMN_CC)) {
if (symbol->symbology == BARCODE_DBAR_OMN || symbol->symbology == BARCODE_DBAR_OMN_CC) {
writer = 0;
latch = 0;
for (i = 0; i < 46; i++) {
@ -484,7 +485,7 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
/* Separator pattern for composite symbol */
dbar_omn_separator(symbol, 96, separator_row, 1 /*above*/, 18, 63, 0 /*bottom_finder_value_3*/);
}
symbol->rows = symbol->rows + 1;
symbol->rows++;
/* Set human readable text */
dbar_set_gtin14_hrt(symbol, source, length);
@ -505,7 +506,7 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
}
}
} else if ((symbol->symbology == BARCODE_DBAR_STK) || (symbol->symbology == BARCODE_DBAR_STK_CC)) {
} else if (symbol->symbology == BARCODE_DBAR_STK || symbol->symbology == BARCODE_DBAR_STK_CC) {
/* Top row */
writer = 0;
latch = 0;
@ -517,7 +518,7 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
symbol->row_height[symbol->rows] = 5.0f; /* ISO/IEC 24724:2011 5.3.2.1 set to 5X */
/* Bottom row */
symbol->rows = symbol->rows + 2;
symbol->rows += 2;
set_module(symbol, symbol->rows, 0);
unset_module(symbol, symbol->rows, 1);
writer = 2;
@ -549,7 +550,7 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
/* Separator pattern for composite symbol */
dbar_omn_separator(symbol, 50, separator_row, 1 /*above*/, 18, 0, 0 /*bottom_finder_value_3*/);
}
symbol->rows = symbol->rows + 1;
symbol->rows++;
if (symbol->width < 50) {
symbol->width = 50;
}
@ -558,7 +559,7 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
error_number = dbar_omnstk_set_height(symbol, 0 /*first_row*/);
}
} else if ((symbol->symbology == BARCODE_DBAR_OMNSTK) || (symbol->symbology == BARCODE_DBAR_OMNSTK_CC)) {
} else if (symbol->symbology == BARCODE_DBAR_OMNSTK || symbol->symbology == BARCODE_DBAR_OMNSTK_CC) {
/* Top row */
writer = 0;
latch = 0;
@ -569,7 +570,7 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
unset_module(symbol, symbol->rows, writer + 1);
/* Bottom row */
symbol->rows = symbol->rows + 4;
symbol->rows += 4;
set_module(symbol, symbol->rows, 0);
unset_module(symbol, symbol->rows, 1);
writer = 2;
@ -600,7 +601,7 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
/* Separator pattern for composite symbol */
dbar_omn_separator(symbol, 50, separator_row, 1 /*above*/, 18, 0, 0 /*bottom_finder_value_3*/);
}
symbol->rows = symbol->rows + 1;
symbol->rows++;
/* ISO/IEC 24724:2011 5.3.2.2 minimum 33X height per row */
if (symbol->symbology == BARCODE_DBAR_OMNSTK_CC) {
@ -638,12 +639,10 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int
int left_widths[14], right_widths[14];
int checksum, check_elements[14], total_widths[47], writer;
int latch;
int separator_row;
int separator_row = 0;
int widths[7];
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT;
separator_row = 0;
if (length > 14) { /* Allow check digit to be specified (will be verified and ignored) */
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 382, "Input length %d too long (maximum 14)", length);
}
@ -661,16 +660,15 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int
}
if (length == 13) {
if ((source[0] != '0') && (source[0] != '1')) {
if (source[0] != '0' && source[0] != '1') {
return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 384, "Input value out of range (0 to 1999999999999)");
}
}
/* Make some room for a separator row for composite symbols */
if (symbol->symbology == BARCODE_DBAR_LTD_CC) {
separator_row = symbol->rows;
separator_row = symbol->rows++;
symbol->row_height[separator_row] = 1;
symbol->rows += 1;
}
large_load_str_u64(&accum, source, length);
@ -785,7 +783,7 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int
if (symbol->width < writer) {
symbol->width = writer;
}
symbol->rows = symbol->rows + 1;
symbol->rows++;
/* Add separator pattern if composite symbol */
if (symbol->symbology == BARCODE_DBAR_LTD_CC) {
@ -865,7 +863,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
/* Decide whether a compressed data field is required and if so what
method to use - method 2 = no compressed data field */
if ((length >= 16) && ((source[0] == '0') && (source[1] == '1'))) {
if (length >= 16 && source[0] == '0' && source[1] == '1') {
/* (01) and other AIs */
encoding_method = 1;
if (debug_print) fputs("Choosing Method 1\n", stdout);
@ -875,12 +873,12 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
if (debug_print) fputs("Choosing Method 2\n", stdout);
}
if (((length >= 20) && (encoding_method == 1)) && ((source[2] == '9') && (source[16] == '3'))) {
if (length >= 20 && encoding_method == 1 && source[2] == '9' && source[16] == '3') {
/* Possibly encoding method > 2 */
if (debug_print) fputs("Checking for other methods\n", stdout);
if ((length >= 26) && (source[17] == '1') && (source[18] == '0')) {
if (length >= 26 && source[17] == '1' && source[18] == '0') {
/* Methods 3, 7, 9, 11 and 13 */
/* (01) and (310x) */
@ -890,7 +888,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
if (weight >= 0 && weight <= 99999) {
if (length == 26) {
if ((source[19] == '3') && weight <= 32767) { /* In grams, max 32.767 kilos */
if (source[19] == '3' && weight <= 32767) { /* In grams, max 32.767 kilos */
/* (01) and (3103) */
encoding_method = 3;
} else {
@ -898,7 +896,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
encoding_method = 7;
}
} else if ((length == 34) && (source[26] == '1')
} else if (length == 34 && source[26] == '1'
&& (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7')
&& dbar_date(source, length, 28) >= 0) {
@ -910,7 +908,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
}
}
} else if ((length >= 26) && (source[17] == '2') && (source[18] == '0')) {
} else if (length >= 26 && source[17] == '2' && source[18] == '0') {
/* Methods 4, 8, 10, 12 and 14 */
/* (01) and (320x) */
@ -929,7 +927,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
encoding_method = 8;
}
} else if ((length == 34) && (source[26] == '1')
} else if (length == 34 && source[26] == '1'
&& (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7')
&& dbar_date(source, length, 28) >= 0) {
@ -941,7 +939,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
}
}
} else if ((source[17] == '9') && ((source[19] >= '0') && (source[19] <= '3'))) {
} else if (source[17] == '9' && (source[19] >= '0' && source[19] <= '3')) {
/* Methods 5 and 6 */
if (source[18] == '2') {
/* (01) and (392x) */
@ -956,10 +954,12 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
}
switch (encoding_method) { /* Encoding method - Table 10 */
case 1: bp = bin_append_posn(4, 3, binary_string, bp); /* "1XX" */
case 1:
bp = bin_append_posn(4, 3, binary_string, bp); /* "1XX" */
read_posn = 16;
break;
case 2: bp = bin_append_posn(0, 4, binary_string, bp); /* "00XX" */
case 2:
bp = bin_append_posn(0, 4, binary_string, bp); /* "00XX" */
read_posn = 0;
break;
case 3: /* 0100 */
@ -967,10 +967,12 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
bp = bin_append_posn(4 + (encoding_method - 3), 4, binary_string, bp);
read_posn = 26;
break;
case 5: bp = bin_append_posn(0x30, 7, binary_string, bp); /* "01100XX" */
case 5:
bp = bin_append_posn(0x30, 7, binary_string, bp); /* "01100XX" */
read_posn = 20;
break;
case 6: bp = bin_append_posn(0x34, 7, binary_string, bp); /* "01101XX" */
case 6:
bp = bin_append_posn(0x34, 7, binary_string, bp); /* "01101XX" */
read_posn = 23;
break;
default: /* Modes 7 to 14 */
@ -1008,7 +1010,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
bp = bin_append_posn(to_int(source + i, 3), 10, binary_string, bp);
}
} else if ((encoding_method == 3) || (encoding_method == 4)) {
} else if (encoding_method == 3 || encoding_method == 4) {
/* Encoding method field "0100" - variable weight item (0,001 kilogram increments) */
/* Encoding method field "0101" - variable weight item (0,01 or 0,001 pound increment) */
@ -1016,13 +1018,13 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
bp = bin_append_posn(to_int(source + i, 3), 10, binary_string, bp);
}
if ((encoding_method == 4) && (source[19] == '3')) {
if (encoding_method == 4 && source[19] == '3') {
bp = bin_append_posn(to_int(source + 20, 6) + 10000, 15, binary_string, bp);
} else {
bp = bin_append_posn(to_int(source + 20, 6), 15, binary_string, bp);
}
} else if ((encoding_method == 5) || (encoding_method == 6)) {
} else if (encoding_method == 5 || encoding_method == 6) {
/* Encoding method "01100" - variable measure item and price */
/* Encoding method "01101" - variable measure item and price with ISO 4217 Currency Code */
@ -1036,7 +1038,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
bp = bin_append_posn(to_int(source + 20, 3), 10, binary_string, bp); /* 3-digit currency */
}
} else if ((encoding_method >= 7) && (encoding_method <= 14)) {
} else if (encoding_method >= 7 && encoding_method <= 14) {
/* Encoding method fields "0111000" through "0111111" - variable weight item plus date */
int group_val;
unsigned char weight_str[7];
@ -1117,7 +1119,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
/* There is still one more numeric digit to encode */
if (debug_print) fputs("Adding extra (odd) numeric digit\n", stdout);
if ((remainder >= 4) && (remainder <= 6)) {
if (remainder >= 4 && remainder <= 6) {
bp = bin_append_posn(ctoi(last_digit) + 1, 4, binary_string, bp);
} else {
d1 = ctoi(last_digit);
@ -1186,7 +1188,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
} else if (encoding_method == 2) {
binary_string[3] = d1 ? '1' : '0';
binary_string[4] = d2 ? '1' : '0';
} else if ((encoding_method == 5) || (encoding_method == 6)) {
} else if (encoding_method == 5 || encoding_method == 6) {
binary_string[6] = d1 ? '1' : '0';
binary_string[7] = d2 ? '1' : '0';
}
@ -1285,7 +1287,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
int latch;
int char_widths[21][8], checksum, check_widths[8], c_group;
int check_char, c_odd, c_even, elements[235], pattern_width, reader, writer;
int separator_row;
int separator_row = 0;
/* Allow for 8 bits + 5-bit latch per char + 200 bits overhead/padding */
unsigned int bin_len = 13 * length + 200 + 1;
int widths[4];
@ -1299,8 +1301,6 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
char *binary_string = (char *) z_alloca(bin_len);
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT;
separator_row = 0;
error_number = gs1_verify(symbol, source, length, reduced, &reduced_length);
if (error_number >= ZINT_ERROR) {
return error_number;
@ -1311,11 +1311,14 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
printf("Reduced (%d): %s\n", reduced_length, reduced);
}
if ((symbol->symbology == BARCODE_DBAR_EXP_CC) || (symbol->symbology == BARCODE_DBAR_EXPSTK_CC)) {
if (symbol->symbology != BARCODE_DBAR_EXP) {
symbol->rows = 0; /* Stacked (and composites) are not stackable */
}
if (symbol->symbology == BARCODE_DBAR_EXP_CC || symbol->symbology == BARCODE_DBAR_EXPSTK_CC) {
/* Make space for a composite separator pattern */
separator_row = symbol->rows;
separator_row = symbol->rows++;
symbol->row_height[separator_row] = 1;
symbol->rows += 1;
}
if (cc_rows) { /* The "component linkage" flag */
@ -1324,7 +1327,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
binary_string[bp++] = '0';
}
if ((symbol->symbology == BARCODE_DBAR_EXPSTK) || (symbol->symbology == BARCODE_DBAR_EXPSTK_CC)) {
if (symbol->symbology == BARCODE_DBAR_EXPSTK || symbol->symbology == BARCODE_DBAR_EXPSTK_CC) {
cols_per_row = 2; /* Default */
if (symbol->option_2 >= 1 && symbol->option_2 <= 11) {
cols_per_row = symbol->option_2;
@ -1345,7 +1348,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
return error_number;
}
if ((symbol->symbology == BARCODE_DBAR_EXPSTK) || (symbol->symbology == BARCODE_DBAR_EXPSTK_CC)) {
if (symbol->symbology == BARCODE_DBAR_EXPSTK || symbol->symbology == BARCODE_DBAR_EXPSTK_CC) {
/* Feedback options */
symbol->option_2 = cols_per_row;
symbol->option_3 = max_rows;
@ -1470,7 +1473,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
}
}
if ((symbol->symbology == BARCODE_DBAR_EXP) || (symbol->symbology == BARCODE_DBAR_EXP_CC)) {
if (symbol->symbology == BARCODE_DBAR_EXP || symbol->symbology == BARCODE_DBAR_EXP_CC) {
/* Copy elements into symbol */
elements[0] = 1; /* Left guard */
@ -1487,7 +1490,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
if (symbol->width < writer) {
symbol->width = writer;
}
symbol->rows = symbol->rows + 1;
symbol->rows++;
dbar_exp_hrt(symbol, source, length);
@ -1496,9 +1499,9 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
}
} else {
/* BARCODE_DBAR_EXPSTK || BARCODE_DBAR_EXPSTK_CC */
int current_row, current_block, left_to_right;
int v2_latch = 0;
/* RSS Expanded Stacked */
/* Bug corrected: Character missing for message
* [01]90614141999996[10]1234222222222221
@ -1531,7 +1534,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
/* If last row and is partial and even-numbered, and have even columns (segment pairs),
and odd number of finders (== odd number of columns) */
if ((current_row == stack_rows) && (num_columns != cols_per_row) && !(current_row & 1)
if (current_row == stack_rows && num_columns != cols_per_row && !(current_row & 1)
&& !(cols_per_row & 1) && (num_columns & 1)) {
/* Special case bottom row */
special_case_row = 1;
@ -1558,7 +1561,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
do {
i = 2 + (current_block * 21);
for (j = 0; j < 21; j++) {
if ((i + j) < pattern_width) {
if (i + j < pattern_width) {
if (left_to_right) {
sub_elements[j + (reader * 21) + 2] = elements[i + j];
} else {
@ -1608,9 +1611,9 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
symbol->row_height[symbol->rows + 1] = 1;
}
symbol->rows = symbol->rows + 4;
symbol->rows += 4;
}
symbol->rows = symbol->rows - 3;
symbol->rows -= 3;
if (raw_text && rt_cpy(symbol, reduced, reduced_length)) {
return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */

View file

@ -81,6 +81,7 @@ zint_add_test(medical test_medical)
zint_add_test(output test_output)
zint_add_test(pcx test_pcx)
zint_add_test(pdf417 test_pdf417)
zint_add_test(perf test_perf)
zint_add_test(plessey test_plessey)
if(ZINT_USE_PNG AND PNG_FOUND)
zint_add_test(png test_png)
@ -89,6 +90,7 @@ zint_add_test(postal test_postal)
zint_add_test(print test_print)
zint_add_test(ps test_ps)
zint_add_test(qr test_qr)
zint_add_test(random test_random)
zint_add_test(raster test_raster)
zint_add_test(reedsol test_reedsol)
zint_add_test(rss test_rss)

View file

@ -1,4 +1,4 @@
% backend/tests/README 2024-11-18
% backend/tests/README 2025-04-03
Zint backend test suite
-----------------------
@ -125,6 +125,18 @@ To run a test against ZXing-C++ (if any), use '-d 512':
backend/tests/test_rss -d 512
------------------------------------------------------------------------
For testing against ZXing-C++, the "diagnostics2" branch from
https://github.com/gitlost/zxing-cpp is required, built with
ZXING_EXAMPLE_DECODER defined, and "zxingcppdecoder" placed in PATH,
e.g.:
git clone --branch diagnostics2 https://github.com/gitlost/zxing-cpp \
zxing-cpp-diagnostics2
cd zxing-cpp-diagnostics2 && mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DZXING_EXAMPLE_DECODER=ON ..
make && sudo make install
------------------------------------------------------------------------
(see also <project-dir>/backend/tests/tools/run_zxingcpp_tests.sh)
To generate test data (if available), use '-g':

View file

@ -459,108 +459,6 @@ static void test_encode(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITER_MILLES 5
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int option_2;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_C25INTER, -1, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, 1, 819, "C25INTER 90" },
/* 1*/ { BARCODE_C25INTER, -1, "1234567890", 0, 1, 99, "C25INTER 10" },
/* 2*/ { BARCODE_C25STANDARD, -1, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, 1, 817, "C25STANDARD 80" },
/* 3*/ { BARCODE_C25STANDARD, -1, "1234567890", 0, 1, 117, "C25STANDARD 10" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
clock_t start;
clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print;
int comment_max = 0;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
printf("Iterations %d\n", TEST_PERF_ITERATIONS);
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, DATA_MODE, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter), TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
total_buf_inter += diff_buf_inter;
total_print += diff_print;
}
if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -568,7 +466,6 @@ int main(int argc, char *argv[]) {
{ "test_hrt", test_hrt },
{ "test_input", test_input },
{ "test_encode", test_encode },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -4161,122 +4161,6 @@ static void test_fuzz(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITERATIONS 1000
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int input_mode;
int option_1;
int option_2;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_AZTEC, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
0, 49, 49, "286 chars, 8-bit words, upper" },
/* 1*/ { BARCODE_AZTEC, -1, -1, -1,
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
0, 79, 79, "900 chars, 10-bit words, numeric" },
/* 2*/ { BARCODE_AZTEC, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377",
0, 91, 91, "980 chars, 10-bit words, mixed" },
/* 3*/ { BARCODE_AZTEC, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377",
0, 113, 113, "1540 chars, 12-bit words, mixed" },
/* 4*/ { BARCODE_AZRUNE, -1, -1, -1,
"255",
0, 11, 11, "3 chars, AZRUNE" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
data[i].option_1, data[i].option_2, -1 /*option_3*/, -1 /*output_options*/,
data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
ZBarcode_Delete(symbol);
}
printf("%s: diff_encode %gms, diff_buffer %gms\n",
data[i].comment, diff_encode * 1000.0 / CLOCKS_PER_SEC, diff_buffer * 1000.0 / CLOCKS_PER_SEC);
total_encode += diff_encode;
total_buffer += diff_buffer;
}
if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n",
total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -4287,7 +4171,6 @@ int main(int argc, char *argv[]) {
{ "test_rt", test_rt },
{ "test_rt_segs", test_rt_segs },
{ "test_fuzz", test_fuzz },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -1,3 +1,4 @@
/* Test BWIPP against ZXing-C++ (no zint involved) */
/*
libzint - the open source barcode library
Copyright (C) 2025 Robin Stuart <rstuart114@gmail.com>
@ -29,45 +30,29 @@
*/
/* SPDX-License-Identifier: BSD-3-Clause */
#include <math.h>
#include "testcommon.h"
static int aztec_width(const int bwipp_len) {
static const int width_lens[33] = {
15 * 15, 19 * 19, 23 * 23, 27 * 27, 31 * 31, 37 * 37, 41 * 41, 45 * 45, 49 * 49, 53 * 53,
57 * 57, 61 * 61, 67 * 67, 71 * 71, 75 * 75, 79 * 79, 83 * 83, 87 * 87, 91 * 91, 95 * 95,
101 * 101, 105 * 105, 109 * 109, 113 * 113, 117 * 117, 121 * 121, 125 * 125, 131 * 131, 135 * 135, 139 * 139,
143 * 143, 147 * 147, 151 * 151,
};
static const int widths[33] = {
15, 19, 23, 27, 31, 37, 41, 45, 49, 53,
57, 61, 67, 71, 75, 79, 83, 87, 91, 95,
101, 105, 109, 113, 117, 121, 125, 131, 135, 139,
143, 147, 151,
};
int i;
#define FLAG_FULL_8BIT 0
#define FLAG_LATIN_1 1
#define FLAG_ASCII 2
for (i = ARRAY_SIZE(width_lens) - 1; i >= 0 && width_lens[i] != bwipp_len; i--);
return i >= 0 ? widths[i] : 0;
}
struct random_item {
int data_flag;
int symbology;
int input_mode;
int eci;
int option_1;
int option_2;
int option_3;
int output_options;
int max_len;
};
static int cnv_hex_data(const char *hex, char *buf, const int buf_size) {
const char *h = hex;
const char *const he = hex + strlen(hex);
char *str_end;
int i;
typedef int (*random_width_func_t)(const struct random_item *, const int);
for (i = 0; i < buf_size && h < he; i++) {
buf[i] = (char) strtol(h, &str_end, 16);
if (str_end == h) {
return -1;
}
h = str_end + 1;
}
if (i < buf_size) buf[i] = '\0';
return i == buf_size ? -1 : i;
}
static void test_aztec_random(const testCtx *const p_ctx) {
static void test_bwipp_random(const testCtx *const p_ctx, const struct random_item *rdata,
random_width_func_t width_func) {
#ifndef _WIN32
int debug = p_ctx->debug;
@ -76,23 +61,15 @@ static void test_aztec_random(const testCtx *const p_ctx) {
struct zint_symbol *symbol = NULL;
#ifndef _WIN32
int symbology = BARCODE_AZTEC;
int input_mode = DATA_MODE;
int eci = 899;
int option_1 = 1;
int option_2 = -1;
int option_3 = -1;
int output_options = -1;
char data_buf[4096];
char bwipp_buf[32768];
char escaped[8192];
char escaped2[8192];
char cmp_buf[8192];
char cmp_msg[8192];
char ret_buf[8192] = {0}; /* Suppress clang -fsanitize=memory false positive */
char bwipp_buf[0x100000]; /* Megabyte */
char escaped[40960];
char escaped2[40960];
char cmp_buf[0x100000];
char cmp_msg[40960];
char ret_buf[40960] = {0}; /* Suppress clang -fsanitize=memory false positive */
const int iterations = p_ctx->arg ? p_ctx->arg : 10000; /* Use "-a N" to set iterations */
const int iterations = p_ctx->arg ? p_ctx->arg : 10000; /* Use "-a N" to set iterations */
/* Requires to be run with "-d 1024" (see ZINT_DEBUG_TEST_BWIPP_ZXINGCPP in "testcommon.h") */
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP_ZXINGCPP) && testUtilHaveGhostscript();
@ -117,31 +94,30 @@ static void test_aztec_random(const testCtx *const p_ctx) {
for (i = 0; i < iterations; i++) {
int bwipp_len, cmp_len, ret_len;
length = arc4random_uniform(1800) + 1;
length = arc4random_uniform(rdata->max_len) + 1;
arc4random_buf(data_buf, length);
testUtilSetSymbol(symbol, symbology, input_mode, eci, option_1, option_2, option_3,
output_options, data_buf, length, debug);
testUtilSetSymbol(symbol, rdata->symbology, rdata->input_mode, rdata->eci,
rdata->option_1, rdata->option_2, rdata->option_3, rdata->output_options,
data_buf, length, debug);
assert_nonzero(testUtilCanBwipp(i, symbol, option_1, option_2, option_3, debug),
assert_nonzero(testUtilCanBwipp(i, symbol, rdata->option_1, rdata->option_2, rdata->option_3, debug),
"i:%d testUtilCanBwipp != 0\n", i);
assert_nonzero(testUtilCanZXingCPP(i, symbol, data_buf, length, debug), "i:%d testUtilCanZXingCPP != 0\n", i);
symbol->rows = 0;
ret = testUtilBwipp(i, symbol, option_1, option_2, option_3, data_buf, length, NULL, bwipp_buf,
sizeof(bwipp_buf), NULL);
ret = testUtilBwipp(i, symbol, rdata->option_1, rdata->option_2, rdata->option_3, data_buf, length, NULL,
bwipp_buf, sizeof(bwipp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
bwipp_len = strlen(bwipp_buf);
assert_nonzero(bwipp_len, "i:%d bwipp_len %d = 0\n", i, bwipp_len);
symbol->width = aztec_width(bwipp_len);
assert_equal(symbol->width * symbol->width, bwipp_len,
"i:%d symbol->width^2 %d != bwipp_len %d (symbol->width %d)\n",
i, symbol->width * symbol->width, bwipp_len, symbol->width);
symbol->width = width_func ? width_func(rdata, bwipp_len) : bwipp_len;
assert_nonzero(symbol->width, "i:%d symbol->width zero\n", i);
ret = testUtilZXingCPP(i, symbol, data_buf, length, bwipp_buf, 1 /*zxingcpp_cmp*/, cmp_buf, sizeof(cmp_buf),
ret = testUtilZXingCPP(i, symbol, data_buf, length, bwipp_buf, 899 /*zxingcpp_cmp*/, cmp_buf, sizeof(cmp_buf),
&cmp_len);
assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
/*fprintf(stderr, "cmp_len %d\n", cmp_len);*/
@ -160,6 +136,162 @@ static void test_aztec_random(const testCtx *const p_ctx) {
#endif /* _WIN32 */
}
static int sqrt_width_func(const struct random_item *rdata, const int bwipp_len) {
const int width = (int) sqrt(bwipp_len);
const int sq = width * width;
(void)rdata;
if (sq != bwipp_len) {
fprintf(stderr, "sqrt_width_func: width %d, bwipp_len %d, sq %d\n", width, bwipp_len, sq);
}
return sq == bwipp_len? width : 0;
}
static void test_aztec(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_AZTEC, DATA_MODE, 899, -1, -1, -1, -1, 1600
};
test_bwipp_random(p_ctx, &rdata, sqrt_width_func);
}
static int codablockf_width_func(const struct random_item *rdata, const int bwipp_len) {
const int row_bits = rdata->option_2 * 11 + 2;
const int mod = bwipp_len % row_bits;
if (mod) {
fprintf(stderr, "codablockf_width_func: row_bits %d, bwipp_len %d, mod %d\n", row_bits, bwipp_len, mod);
}
return mod == 0 ? row_bits : 0;
}
static void test_codablockf(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_LATIN_1, BARCODE_CODABLOCKF, DATA_MODE, 0, -1, 30 + 5, -1, -1, 500
};
test_bwipp_random(p_ctx, &rdata, codablockf_width_func);
}
static void test_code128(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_LATIN_1, BARCODE_CODE128, DATA_MODE, 0, -1, -1, -1, -1, 80
};
test_bwipp_random(p_ctx, &rdata, NULL /*width_func*/);
}
static void test_datamatrix(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_DATAMATRIX, DATA_MODE, 0, -1, 21, DM_SQUARE, -1, 800
};
test_bwipp_random(p_ctx, &rdata, sqrt_width_func);
}
/* TODO: explore why "zxingcppdecoder" fails */
#if 0
static int dotcode_width_func(const struct random_item *rdata, const int bwipp_len) {
const int row_bits = rdata->option_2 >= 1 ? bwipp_len / rdata->option_2 : 0;
const int mod = row_bits ? bwipp_len % row_bits : -1;
if (mod) {
fprintf(stderr, "dotcode_width_func: row_bits %d, bwipp_len %d, mod %d\n", row_bits, bwipp_len, mod);
}
return mod == 0 ? row_bits : 0;
}
static void test_dotcode(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_DOTCODE, DATA_MODE, 0, -1, 50, -1, -1, 200
};
test_bwipp_random(p_ctx, &rdata, dotcode_width_func);
}
#endif
static int micropdf417_width_func(const struct random_item *rdata, const int bwipp_len) {
static const short widths[4] = { 38, 55, 82, 99 };
const int row_bits = rdata->option_2 >= 1 && rdata->option_2 <= 4 ? widths[rdata->option_2 - 1] : 0;
const int mod = row_bits ? bwipp_len % row_bits : -1;
if (mod) {
fprintf(stderr, "micropdf417_width_func: row_bits %d, bwipp_len %d, mod %d\n", row_bits, bwipp_len, mod);
}
return mod == 0 ? row_bits : 0;
}
static void test_micropdf417(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_MICROPDF417, DATA_MODE, 0, -1, 4, -1, -1, 120
};
test_bwipp_random(p_ctx, &rdata, micropdf417_width_func);
}
static int pdf417_width_func(const struct random_item *rdata, const int bwipp_len) {
const int row_bits = (rdata->option_2 + 4) * 17 + 1;
const int mod = bwipp_len % row_bits;
if (mod) {
fprintf(stderr, "pdf417_width_func: row_bits %d, bwipp_len %d, mod %d\n", row_bits, bwipp_len, mod);
}
return mod == 0 ? row_bits : 0;
}
static void test_pdf417(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_PDF417, DATA_MODE, 0, -1, 20, -1, -1, 800
};
test_bwipp_random(p_ctx, &rdata, pdf417_width_func);
}
static void test_qr(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_QRCODE, DATA_MODE, 0, 1, 21, -1, -1, 800
};
test_bwipp_random(p_ctx, &rdata, sqrt_width_func);
}
static int rmqr_width_func(const struct random_item *rdata, const int bwipp_len) {
static const short vers[32] = {
43, 59, 77, 99, 139,
43, 59, 77, 99, 139,
27, 43, 59, 77, 99, 139,
27, 43, 59, 77, 99, 139,
43, 59, 77, 99, 139,
43, 59, 77, 99, 139,
};
const int row_bits = rdata->option_2 >= 1 && rdata->option_2 <= ARRAY_SIZE(vers) ? vers[rdata->option_2 - 1] : 0;
if (row_bits == 0) {
fprintf(stderr, "rmqr_width_func: row_bits %d, bwipp_len %d, option_2 %d\n", row_bits, bwipp_len,
rdata->option_2);
}
return row_bits;
}
static void test_rmqr(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_RMQR, DATA_MODE, 0, 2, 32, -1, -1, 140
};
test_bwipp_random(p_ctx, &rdata, rmqr_width_func);
}
static int cnv_hex_data(const char *hex, char *buf, const int buf_size) {
const char *h = hex;
const char *const he = hex + strlen(hex);
char *str_end;
int i;
for (i = 0; i < buf_size && h < he; i++) {
buf[i] = (char) strtol(h, &str_end, 16);
if (str_end == h) {
return -1;
}
h = str_end + 1;
}
if (i < buf_size) buf[i] = '\0';
return i == buf_size ? -1 : i;
}
static void test_aztec_bwipjs_354(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
@ -281,7 +413,7 @@ static void test_aztec_bwipjs_354(const testCtx *const p_ctx) {
bwipp_len = strlen(bwipp_buf);
assert_nonzero(bwipp_len, "i:%d bwipp_len %d = 0\n", i, bwipp_len);
symbol->width = aztec_width(bwipp_len);
symbol->width = sqrt_width_func(NULL /*rdata*/, bwipp_len);
assert_equal(symbol->width * symbol->width, bwipp_len,
"i:%d symbol->width^2 %d != bwipp_len %d (symbol->width %d)\n",
i, symbol->width * symbol->width, bwipp_len, symbol->width);
@ -304,11 +436,111 @@ static void test_aztec_bwipjs_354(const testCtx *const p_ctx) {
testFinish();
}
static void test_codablockf_fnc4_digit(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
const char *data;
};
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
static const struct item data[] = {
/* 0*/ { "EE 9F 56 C8 B6 37 36 37" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol = NULL;
struct random_item s_rdata = { 0, BARCODE_CODABLOCKF, DATA_MODE, 0, -1, 8 + 5, -1, -1, 0 };
struct random_item *rdata = &s_rdata;
char data_buf[4096];
char bwipp_buf[32768];
char escaped[8192];
char escaped2[8192];
char cmp_buf[8192];
char cmp_msg[8192];
char ret_buf[8192] = {0}; /* Suppress clang -fsanitize=memory false positive */
/* Requires to be run with "-d 1024" (see ZINT_DEBUG_TEST_BWIPP_ZXINGCPP in "testcommon.h") */
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP_ZXINGCPP) && testUtilHaveGhostscript();
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_BWIPP_ZXINGCPP) && testUtilHaveZXingCPPDecoder();
testStartSymbol(p_ctx->func_name, &symbol);
if (!do_bwipp || !do_zxingcpp) {
testSkip("Test requires BWIPP and ZXing-C++");
return;
}
for (i = 0; i < data_size; i++) {
int bwipp_len, cmp_len, ret_len;
if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = cnv_hex_data(data[i].data, data_buf, ARRAY_SIZE(data_buf));
assert_nonzero(length, "i:%d cnv_hex_data length zero\n", i);
#if 0
debug_print_escape(TCU(data_buf), length, NULL);
printf("\n");
#endif
testUtilSetSymbol(symbol, rdata->symbology, rdata->input_mode, rdata->eci,
rdata->option_1, rdata->option_2, rdata->option_3, rdata->output_options,
data_buf, length, debug);
assert_nonzero(testUtilCanBwipp(i, symbol, rdata->option_1, rdata->option_2, rdata->option_3, debug),
"i:%d testUtilCanBwipp != 0\n", i);
assert_nonzero(testUtilCanZXingCPP(i, symbol, data_buf, length, debug), "i:%d testUtilCanZXingCPP != 0\n", i);
symbol->rows = 0;
ret = testUtilBwipp(i, symbol, rdata->option_1, rdata->option_2, rdata->option_3, data_buf, length, NULL,
bwipp_buf, sizeof(bwipp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
bwipp_len = strlen(bwipp_buf);
assert_nonzero(bwipp_len, "i:%d bwipp_len %d = 0\n", i, bwipp_len);
symbol->width = codablockf_width_func(rdata, bwipp_len);
assert_nonzero(symbol->width, "i:%d symbol->width == 0\n", i);
ret = testUtilZXingCPP(i, symbol, data_buf, length, bwipp_buf, 899 /*zxingcpp_cmp*/, cmp_buf, sizeof(cmp_buf),
&cmp_len);
assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
/*fprintf(stderr, "cmp_len %d\n", cmp_len);*/
ret = testUtilZXingCPPCmp(symbol, cmp_msg, cmp_buf, cmp_len, data_buf, length, NULL /*primary*/,
ret_buf, &ret_len);
assert_zero(ret, "i:%d %s testUtilZXingCPPCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg,
testUtilEscape(cmp_buf, cmp_len, escaped, sizeof(escaped)),
testUtilEscape(ret_buf, ret_len, escaped2, sizeof(escaped2)));
ZBarcode_Delete(symbol);
}
testFinish();
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
{ "test_aztec_random", test_aztec_random },
{ "test_aztec", test_aztec },
{ "test_codablockf", test_codablockf },
{ "test_code128", test_code128 },
{ "test_datamatrix", test_datamatrix },
#if 0
{ "test_dotcode", test_dotcode },
#endif
{ "test_micropdf417", test_micropdf417 },
{ "test_pdf417", test_pdf417 },
{ "test_qr", test_qr },
{ "test_rmqr", test_rmqr },
{ "test_aztec_bwipjs_354", test_aztec_bwipjs_354 },
{ "test_codablockf_fnc4_digit", test_codablockf_fnc4_digit },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -102,18 +102,26 @@ static void test_large(const testCtx *const p_ctx) {
assert_nonnull(symbol, "Symbol not created\n");
testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length);
assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf));
assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n",
i, data[i].length, (int) strlen(data_buf));
length = testUtilSetSymbol(symbol, BARCODE_CODABLOCKF, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug);
length = testUtilSetSymbol(symbol, BARCODE_CODABLOCKF, -1 /*input_mode*/, -1 /*eci*/,
data[i].option_1, data[i].option_2, -1 /*option_3*/, -1 /*output_options*/,
data_buf, data[i].length, debug);
ret = ZBarcode_Encode(symbol, TCU(data_buf), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n",
i, ret ? "set" : "empty", symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected_errtxt);
if (ret < ZINT_ERROR) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n",
i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n",
i, symbol->width, data[i].expected_width);
}
ZBarcode_Delete(symbol);
@ -183,13 +191,18 @@ static void test_options(const testCtx *const p_ctx) {
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected_errtxt);
assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n",
i, ret ? "set" : "empty", symbol->errtxt);
if (ret < ZINT_ERROR) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
}
assert_equal(symbol->option_1, data[i].expected_option_1, "i:%d symbol->option_1 %d != %d (option_2 %d)\n",
i, symbol->option_1, data[i].expected_option_1, symbol->option_2);
@ -238,21 +251,28 @@ static void test_reader_init(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, data[i].output_options,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options),
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode),
testUtilOutputOptionsName(data[i].output_options),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, symbol->errtxt, data[i].comment);
} else {
if (ret < ZINT_ERROR) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
assert_zero(strcmp((char *) symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
assert_zero(strcmp((char *) symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected);
}
}
@ -312,10 +332,11 @@ static void test_hrt(const testCtx *const p_ctx) {
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
data[i].option_1, data[i].option_2, -1 /*option_3*/, data[i].output_options,
data[i].data, data[i].length, debug);
data[i].option_1, data[i].option_2, -1 /*option_3*/, data[i].output_options,
data[i].data, data[i].length, debug);
expected_length = (int) strlen(data[i].expected);
expected_raw_length = data[i].expected_raw_length == -1 ? (int) strlen(data[i].expected_raw) : data[i].expected_raw_length;
expected_raw_length = data[i].expected_raw_length == -1 ? (int) strlen(data[i].expected_raw)
: data[i].expected_raw_length;
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt);
@ -429,8 +450,10 @@ static void test_input(const testCtx *const p_ctx) {
/* 48*/ { BARCODE_CODABLOCKF, UNICODE_MODE | ESCAPE_MODE, -1, -1, "2610\\u00F2", -1, 0, 2, 101, 1, 1, "67 63 00 1A 0A 64 63 4B 6A 67 64 0B 64 52 33 26 64 6A", "Okapi data-fuzz-19.png" },
/* 49*/ { BARCODE_CODABLOCKF, DATA_MODE | ESCAPE_MODE, 7, -1, "*\\r\\xF2\\x82\\x82(\\x982\\x82\\x82*\\r\\xF2\\x82\\xA8\\x82\\x82\\x82\\x82", -1, 0, 7, 123, 0, 899, "(77) 67 62 45 0A 4D 64 64 52 63 35 6A 67 62 0B 65 42 65 42 08 63 43 6A 67 62 0C 65 58 12", "Okapi data-fuzz-20.png; BWIPP different encodation" },
/* 50*/ { BARCODE_CODABLOCKF, UNICODE_MODE | ESCAPE_MODE, -1, -1, "\\u0018\\u00F2", -1, 0, 2, 101, 0, 1, "67 62 40 58 65 62 52 16 6A 67 64 0B 63 64 38 30 30 6A", "Okapi data-fuzz-21.png; BWIPP different encodation" },
/* 51*/ { BARCODE_HIBC_BLOCKF, UNICODE_MODE, -1, -1, "A99912345/$$52001510X3", -1, 0, 6, 101, 1, 1, "(54) 67 64 44 0B 21 19 19 3A 6A 67 63 2B 5B 17 2D 64 24 6A 67 64 0C 0F 04 04 15 16 6A 67", "" },
/* 52*/ { BARCODE_HIBC_BLOCKF, UNICODE_MODE, -1, -1, "A99912345/$$520:1510X3", -1, ZINT_ERROR_INVALID_DATA, -1, -1, 1, 1, "Error 203: Invalid character at position 16 in input (alphanumerics, space and \"-.$/+%\" only)", "" },
/* 51*/ { BARCODE_CODABLOCKF, DATA_MODE, -1, -1, "\256^a\357\033\270\017,\274u$B\305\311\006\011]\273\025u\315\2638\263\333", -1, 0, 7, 123, 1, 899, "(77) 67 64 45 64 0E 3E 41 64 4F 33 6A 67 62 0B 5B 65 18 4F 0C 63 01 6A 67 64 0C 64 1C 55", "Misencodation of 0xB0-B9 (\260-\271) as FNC4 digit followed by digit as CodeC (found with 'test_random'" },
/* 52*/ { BARCODE_CODABLOCKF, DATA_MODE, -1, -1, "\356\237V\310\266767", -1, 0, 5, 101, 0, 899, "(45) 67 64 43 64 4E 63 64 57 6A 67 62 0B 65 5F 36 63 13 6A 67 64 0C 64 28 64 16 53 6A 67", "BWIPP example of above; BWIPP different encodation" },
/* 53*/ { BARCODE_HIBC_BLOCKF, UNICODE_MODE, -1, -1, "A99912345/$$52001510X3", -1, 0, 6, 101, 1, 1, "(54) 67 64 44 0B 21 19 19 3A 6A 67 63 2B 5B 17 2D 64 24 6A 67 64 0C 0F 04 04 15 16 6A 67", "" },
/* 54*/ { BARCODE_HIBC_BLOCKF, UNICODE_MODE, -1, -1, "A99912345/$$520:1510X3", -1, ZINT_ERROR_INVALID_DATA, -1, -1, 1, 1, "Error 203: Invalid character at position 16 in input (alphanumerics, space and \"-.$/+%\" only)", "" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
@ -460,7 +483,8 @@ static void test_input(const testCtx *const p_ctx) {
data[i].data, data[i].length, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %d, \"%s\", %d, %s, %d, %d, %d, %d, \"%s\", \"%s\" },\n",
@ -470,23 +494,33 @@ static void test_input(const testCtx *const p_ctx) {
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp,
data[i].zxingcpp_cmp, symbol->errtxt, data[i].comment);
} else {
assert_zero(strcmp((char *) symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
assert_zero(strcmp((char *) symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected);
if (ret < ZINT_ERROR) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
char modules_dump[32768];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].data, length,
NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf,
modules_dump);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
@ -535,47 +569,47 @@ static void test_encode(const testCtx *const p_ctx) {
/* 0*/ { BARCODE_CODABLOCKF, 1, -1, "AIM", 0, 1, 68, 1, "Same as CODE128 (not supported by BWIPP or ZXing-C++)",
"11010010000101000110001100010001010111011000101110110001100011101011"
},
/* 1*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAA", 0, 3, 101, 1, "Defaults to rows 3, columns 9 (4 data); verified manually against tec-it",
/* 1*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAA", 0, 3, 101, 1, "Defaults to rows 3, columns 9 (4 data); verified manually against TEC-IT",
"11010000100101111011101001011000010100011000101000110001010001100010100011000110110011001100011101011"
"11010000100101111011101100010010010100011000101000110001010001100010111011110100100111101100011101011"
"11010000100101111011101011001110010111011110101111011101100001010011011101110111100101001100011101011"
},
/* 2*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAAAAA", 0, 3, 101, 1, "Defaults to rows 3, columns 9 (4 data); verified manually against tec-it",
/* 2*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAAAAA", 0, 3, 101, 1, "Defaults to rows 3, columns 9 (4 data); verified manually against TEC-IT",
"11010000100101111011101001011000010100011000101000110001010001100010100011000110110011001100011101011"
"11010000100101111011101100010010010100011000101000110001010001100010100011000111101000101100011101011"
"11010000100101111011101011001110010100011000101000110001110110010010010110000111000101101100011101011"
},
/* 3*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAAAAAA", 0, 4, 101, 1, "Defaults to rows 4, columns 9 (4 data); verified manually against tec-it",
/* 3*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAAAAAA", 0, 4, 101, 1, "Defaults to rows 4, columns 9 (4 data); verified manually against TEC-IT",
"11010000100101111011101001000011010100011000101000110001010001100010100011000110011001101100011101011"
"11010000100101111011101100010010010100011000101000110001010001100010100011000111101000101100011101011"
"11010000100101111011101011001110010100011000101000110001010001100010111011110100111101001100011101011"
"11010000100101111011101001101110010111011110101111011101110101100011101100100110010111001100011101011"
},
/* 4*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAAAAAAAAA", 0, 4, 101, 1, "Defaults to rows 4, columns 9 (4 data); verified manually against tec-it",
/* 4*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAAAAAAAAA", 0, 4, 101, 1, "Defaults to rows 4, columns 9 (4 data); verified manually against TEC-IT",
"11010000100101111011101001000011010100011000101000110001010001100010100011000110011001101100011101011"
"11010000100101111011101100010010010100011000101000110001010001100010100011000111101000101100011101011"
"11010000100101111011101011001110010100011000101000110001010001100010100011000101111011101100011101011"
"11010000100101111011101001101110010100011000101000110001011110100010111011000100110000101100011101011"
},
/* 5*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAAAAAAAAAA", 0, 5, 101, 1, "Defaults to rows 5, columns 9 (4 data); verified manually against tec-it",
/* 5*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAAAAAAAAAA", 0, 5, 101, 1, "Defaults to rows 5, columns 9 (4 data); verified manually against TEC-IT",
"11010000100101111011101000010110010100011000101000110001010001100010100011000100100011001100011101011"
"11010000100101111011101100010010010100011000101000110001010001100010100011000111101000101100011101011"
"11010000100101111011101011001110010100011000101000110001010001100010100011000101111011101100011101011"
"11010000100101111011101001101110010100011000101000110001010001100010111011110111101001001100011101011"
"11010000100101111011101001100111010111011110101111011101000110001010111101000110001010001100011101011"
},
/* 6*/ { BARCODE_CODABLOCKF, -1, 14, "AAAAAAAAAAAAAAA", 0, 2, 156, 1, "Rows 2, columns 14 (9 data); verified manually against tec-it",
/* 6*/ { BARCODE_CODABLOCKF, -1, 14, "AAAAAAAAAAAAAAA", 0, 2, 156, 1, "Rows 2, columns 14 (9 data); verified manually against TEC-IT",
"110100001001011110111010100001100101000110001010001100010100011000101000110001010001100010100011000101000110001010001100010100011000110001000101100011101011"
"110100001001011110111011000100100101000110001010001100010100011000101000110001010001100010100011000101110111101110111101011011000110111000101101100011101011"
},
/* 7*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAAAAAAAAAAA", 0, 5, 101, 1, "Defaults to rows 5, columns 9 (4 data); verified manually against tec-it",
/* 7*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAAAAAAAAAAA", 0, 5, 101, 1, "Defaults to rows 5, columns 9 (4 data); verified manually against TEC-IT",
"11010000100101111011101000010110010100011000101000110001010001100010100011000100100011001100011101011"
"11010000100101111011101100010010010100011000101000110001010001100010100011000111101000101100011101011"
"11010000100101111011101011001110010100011000101000110001010001100010100011000101111011101100011101011"
"11010000100101111011101001101110010100011000101000110001010001100010100011000111101011101100011101011"
"11010000100101111011101001100111010111011110101111011101011100011010001100010100011101101100011101011"
},
/* 8*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAAAAAAAAAAAAAAAAAAAA", 0, 6, 112, 1, "Defaults to rows 6, columns 10 (5 data); verified manually against tec-it",
/* 8*/ { BARCODE_CODABLOCKF, -1, -1, "AAAAAAAAAAAAAAAAAAAAAAAAA", 0, 6, 112, 1, "Defaults to rows 6, columns 10 (5 data); verified manually against TEC-IT",
"1101000010010111101110100001001101010001100010100011000101000110001010001100010100011000110110001101100011101011"
"1101000010010111101110110001001001010001100010100011000101000110001010001100010100011000110010011101100011101011"
"1101000010010111101110101100111001010001100010100011000101000110001010001100010100011000110011101001100011101011"
@ -607,12 +641,12 @@ static void test_encode(const testCtx *const p_ctx) {
"110100001001011110111011100110010100111101001001111001011110100100111100101001111001001011011011110110111101101111011011010101111000111101010001100011101011"
"110100001001011110111011011011000101000111101000101111010111011110101111011101011101111010111101110101110111101011100011011101101110101001100001100011101011"
},
/* 12*/ { BARCODE_HIBC_BLOCKF, 3, -1, "A123BJC5D6E71", 0, 3, 123, 0, "Verified manually against tec-it; differs from BWIPP (columns=6) which uses Code C for final 71 (same no. of codewords)",
/* 12*/ { BARCODE_HIBC_BLOCKF, 3, -1, "A123BJC5D6E71", 0, 3, 123, 0, "Verified manually against TEC-IT; differs from BWIPP (columns=6) which uses Code C for final 71 (same no. of codewords)",
"110100001001011110111010010110000110001001001010001100010011100110110011100101100101110010001011000100100001101100011101011"
"110100001001011110111011000100100101101110001000100011011011100100101100010001100111010010001101000111001001101100011101011"
"110100001001011110111010110011100111011011101001110011011010001000101110111101011100011011001110100100100110001100011101011"
},
/* 13*/ { BARCODE_HIBC_BLOCKF, -1, -1, "$$52001510X3G", 0, 4, 101, 1, "tec-it differs as adds unnecessary Code C at end of 1st line",
/* 13*/ { BARCODE_HIBC_BLOCKF, -1, -1, "$$52001510X3G", 0, 4, 101, 1, "TEC-IT differs as adds unnecessary Code C at end of 1st line",
"11010000100101111011101001000011011000100100100100011001001000110011011100100101110011001100011101011"
"11010000100101110111101011000111011001001110110011011001101110100010111101110100001100101100011101011"
"11010000100101111011101011001110010011101100111000101101100101110011010001000100100011001100011101011"
@ -758,21 +792,30 @@ static void test_fuzz(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, BARCODE_CODABLOCKF, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
length = testUtilSetSymbol(symbol, BARCODE_CODABLOCKF, -1 /*input_mode*/, -1 /*eci*/,
data[i].option_1, data[i].option_2, -1 /*option_3*/, -1 /*output_options*/,
data[i].data, data[i].length, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (ret < ZINT_ERROR) {
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
char modules_dump[32768];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].data, length, NULL,
cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",

View file

@ -536,110 +536,6 @@ static void test_encode(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITER_MILLES 5
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int option_2;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_CODE39, -1, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+", 0, 1, 1130, "CODE39 85" },
/* 1*/ { BARCODE_CODE39, -1, "123456ABCD", 0, 1, 155, "CODE39 10" },
/* 2*/ { BARCODE_CODE93, -1,
"\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !\"#$%&'()*+,-./0123456789ABCDEFGHIJ",
0, 1, 1000, "CODE93 107 symbol chars" },
/* 3*/ { BARCODE_CODE93, -1, "123456ABCD", 0, 1, 127, "CODE93 10" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
clock_t start;
clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print;
int comment_max = 0;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
printf("Iterations %d\n", TEST_PERF_ITERATIONS);
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, DATA_MODE, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter), TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
total_buf_inter += diff_buf_inter;
total_print += diff_print;
}
if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -647,7 +543,6 @@ int main(int argc, char *argv[]) {
{ "test_hrt", test_hrt },
{ "test_input", test_input },
{ "test_encode", test_encode },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -320,106 +320,6 @@ static void test_encode(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITER_MILLES 5
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int option_2;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_CODE11, -1, "1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-", 0, 1, 966, "CODE11 121" },
/* 1*/ { BARCODE_CODE11, -1, "1234567890-", 0, 1, 116, "CODE11 5" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
clock_t start;
clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print;
int comment_max = 0;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
printf("Iterations %d\n", TEST_PERF_ITERATIONS);
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, DATA_MODE, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter), TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
total_buf_inter += diff_buf_inter;
total_print += diff_print;
}
if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -427,7 +327,6 @@ int main(int argc, char *argv[]) {
{ "test_hrt", test_hrt },
{ "test_input", test_input },
{ "test_encode", test_encode },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -121,29 +121,42 @@ static void test_large(const testCtx *const p_ctx) {
if (data[i].length != -1) {
testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length);
assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf));
assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n",
i, data[i].length, (int) strlen(data_buf));
} else {
strcpy(data_buf, data[i].pattern);
}
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, data[i].output_options, data_buf, data[i].length, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, data[i].output_options,
data_buf, data[i].length, debug);
ret = ZBarcode_Encode(symbol, TCU(data_buf), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n",
i, ret ? "set" : "empty", symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected_errtxt);
if (ret < ZINT_ERROR) {
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n",
i, symbol->width, data[i].expected_width);
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) {
if (data[i].output_options != -1 && (data[i].output_options & READER_INIT)) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), "READER_INIT not supported");
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), "READER_INIT not supported");
}
} else {
char modules_dump[4096];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, -1, -1, data_buf, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, -1, -1, data_buf, length, NULL, cmp_buf, sizeof(cmp_buf),
NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
@ -297,10 +310,11 @@ static void test_hrt(const testCtx *const p_ctx) {
memset(symbol->text, 0xDD, sizeof(symbol->text)); /* Detect non-NUL terminated HRT */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, data[i].option_2, -1 /*option_3*/, data[i].output_options,
data[i].data, data[i].length, debug);
-1 /*option_1*/, data[i].option_2, -1 /*option_3*/, data[i].output_options,
data[i].data, data[i].length, debug);
expected_length = data[i].expected_length == -1 ? (int) strlen(data[i].expected) : data[i].expected_length;
expected_raw_length = data[i].expected_raw_length == -1 ? (int) strlen(data[i].expected_raw) : data[i].expected_raw_length;
expected_raw_length = data[i].expected_raw_length == -1 ? (int) strlen(data[i].expected_raw)
: data[i].expected_raw_length;
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt);
@ -328,12 +342,18 @@ static void test_hrt(const testCtx *const p_ctx) {
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) {
if (data[i].symbology == BARCODE_HIBC_128
&& not_sane(IS_NUM_F | IS_UPR_F | IS_SPC_F | IS_PLS_F | IS_MNS_F | IS_SIL_F, (const unsigned char *) data[i].data, length)) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), "BWIPP does not uppercase input");
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), "BWIPP does not uppercase input");
}
} else {
char modules_dump[4096];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, cmp_buf,
sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
@ -413,21 +433,28 @@ static void test_reader_init(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, data[i].output_options,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options),
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode),
testUtilOutputOptionsName(data[i].output_options),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, symbol->errtxt, data[i].comment);
} else {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected);
if (ret < ZINT_ERROR) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
int cmp_len, ret_len;
@ -621,6 +648,7 @@ static void test_input(const testCtx *const p_ctx) {
/*138*/ { DATA_MODE, "1234\200", -1, 0, 90, 1, 899, "(8) 105 12 34 101 101 64 79 106", "StartC 12 34 CodeA FNC4 PAD" },
/*139*/ { UNICODE_MODE, "12é12é", -1, 0, 123, 0, 1, "(11) 105 12 100 100 73 17 18 100 73 17 106", "StartC 12 CodeB FNC4 é 1 2 FNC4 é; BWIPP different encodation (StartB)" },
/*140*/ { UNICODE_MODE, "1234é123456é", -1, 0, 167, 1, 1, "(15) 105 12 34 100 100 73 99 12 34 56 100 100 73 15 106", "StartC 12 34 CodeB FNC4 é CodeC 12 34 56 CodeB FNC4 é" },
/*141*/ { DATA_MODE, "\256^a\357\033\270\017,\274u$B\305\311\006\011]\273\025u\315\2638\263\333", -1, 0, 453, 1, 899, "(41) 104 100 14 62 65 100 79 101 91 101 24 79 12 101 28 98 85 4 34 101 37 101 41 70 73 61", "" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
@ -647,7 +675,9 @@ static void test_input(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_CODE128, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
length = testUtilSetSymbol(symbol, BARCODE_CODE128, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, -1 /*output_options*/,
data[i].data, data[i].length, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
@ -658,8 +688,10 @@ static void test_input(const testCtx *const p_ctx) {
testUtilErrorName(ret), symbol->width, data[i].bwipp_cmp, data[i].zxingcpp_cmp, symbol->errtxt,
data[i].comment);
} else {
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0 (width %d)\n", i, symbol->errtxt, data[i].expected, symbol->width);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0 (width %d)\n",
i, symbol->errtxt, data[i].expected, symbol->width);
if (ret < ZINT_ERROR) {
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width,
@ -667,16 +699,23 @@ static void test_input(const testCtx *const p_ctx) {
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
char modules_dump[4096];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf,
sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf,
modules_dump);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
@ -776,39 +815,56 @@ static void test_gs1_128_input(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_GS1_128, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, BARCODE_GS1_128, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, -1 /*output_options*/,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->width, data[i].bwipp_cmp, symbol->errtxt, data[i].comment);
i, testUtilInputModeName(data[i].input_mode),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret),
symbol->width, data[i].bwipp_cmp, symbol->errtxt, data[i].comment);
} else {
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0 (width %d)\n", i, symbol->errtxt, data[i].expected, symbol->width);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0 (width %d)\n",
i, symbol->errtxt, data[i].expected, symbol->width);
if (ret < ZINT_ERROR) {
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
if (ret == ZINT_WARN_HRT_TRUNCATED) {
assert_nonzero((int) ustrlen(symbol->text) < (int) strlen(data[i].data), "i:%d len symbol->text(%s) %d >= %d (%s) (%s)\n",
i, symbol->text, (int) ustrlen(symbol->text), (int) strlen(data[i].data), data[i].data, symbol->errtxt);
assert_nonzero((int) ustrlen(symbol->text) < (int) strlen(data[i].data),
"i:%d len symbol->text(%s) %d >= %d (%s) (%s)\n",
i, symbol->text, (int) ustrlen(symbol->text), (int) strlen(data[i].data), data[i].data,
symbol->errtxt);
} else {
assert_equal((int) ustrlen(symbol->text), (int) strlen(data[i].data), "i:%d len symbol->text(%s) %d != %d (%s, %s) (%s)\n",
i, symbol->text, (int) ustrlen(symbol->text), (int) strlen(data[i].data), testUtilErrorName(ret), data[i].data, symbol->errtxt);
assert_equal((int) ustrlen(symbol->text), (int) strlen(data[i].data),
"i:%d len symbol->text(%s) %d != %d (%s, %s) (%s)\n",
i, symbol->text, (int) ustrlen(symbol->text), (int) strlen(data[i].data),
testUtilErrorName(ret), data[i].data, symbol->errtxt);
}
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
char modules_dump[4096];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf,
sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf,
modules_dump);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
@ -883,32 +939,45 @@ static void test_hibc_input(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_HIBC_128, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, BARCODE_HIBC_128, UNICODE_MODE, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, -1 /*output_options*/,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->width, data[i].bwipp_cmp, symbol->errtxt, data[i].comment);
testUtilErrorName(data[i].ret), symbol->width, data[i].bwipp_cmp, symbol->errtxt,
data[i].comment);
} else {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0 (width %d)\n", i, symbol->errtxt, data[i].expected, symbol->width);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0 (width %d)\n",
i, symbol->errtxt, data[i].expected, symbol->width);
if (ret < ZINT_ERROR) {
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
char modules_dump[4096];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf,
sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf,
modules_dump);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
@ -970,7 +1039,9 @@ static void test_nve18_input(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_NVE18, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, BARCODE_NVE18, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, -1 /*output_options*/,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
@ -1024,7 +1095,9 @@ static void test_ean14_input(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_EAN14, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, BARCODE_EAN14, UNICODE_MODE, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_2*/, -1 /*output_options*/,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
@ -1119,7 +1192,9 @@ static void test_dpd_input(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_DPD, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, BARCODE_DPD, UNICODE_MODE, -1 /*eci*/,
-1 /*option_1*/, data[i].option_2, -1 /*option_3*/, data[i].output_options,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
@ -1240,7 +1315,9 @@ static void test_upu_s10_input(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, BARCODE_UPU_S10, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, BARCODE_UPU_S10, UNICODE_MODE, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, -1 /*output_options*/,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
@ -1490,12 +1567,13 @@ static void test_encode(const testCtx *const p_ctx) {
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, \"%s\", %s, %d, %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].option_2,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode),
data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp,
data[i].zxingcpp_cmp, data[i].comment);
testUtilModulesPrint(symbol, " ", "\n");
@ -1504,22 +1582,31 @@ static void test_encode(const testCtx *const p_ctx) {
if (ret < ZINT_ERROR) {
int width, row;
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n",
i, ret, width, row, data[i].data);
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, cmp_buf,
sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf,
data[i].expected);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
@ -1548,112 +1635,6 @@ static void test_encode(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITER_MILLES 10
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_CODE128, "123456ABCD123456ABCD123456ABCD123456ABCD123456ABCD123456ABCD", 0, 1, 618, "CODE128 60" },
/* 1*/ { BARCODE_CODE128, "123456ABCD", 0, 1, 123, "CODE128 10" },
/* 2*/ { BARCODE_GS1_128, "[01]09501101530003", 0, 1, 134, "GS1_128 (01)" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
clock_t start;
clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print;
int comment_max = 0;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
printf("Iterations %d\n", TEST_PERF_ITERATIONS);
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, DATA_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
#if 0
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
#endif
ZBarcode_Delete(symbol);
}
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n",
comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter),
TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
total_buf_inter += diff_buf_inter;
total_print += diff_print;
}
if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n",
comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter),
TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -1668,7 +1649,6 @@ int main(int argc, char *argv[]) {
{ "test_dpd_input", test_dpd_input },
{ "test_upu_s10_input", test_upu_s10_input },
{ "test_encode", test_encode },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -117,7 +117,8 @@ static void test_to_upper(const testCtx *const p_ctx) {
buf[length] = '\0';
to_upper(buf, length);
assert_zero(strcmp((const char *) buf, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, buf, data[i].expected);
assert_zero(strcmp((const char *) buf, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
i, buf, data[i].expected);
}
testFinish();
@ -359,7 +360,8 @@ static void test_not_sane_lookup(const testCtx *const p_ctx) {
if (ret == 0) {
int j;
for (j = 0; j < length; j++) {
assert_equal(posns[j], data[i].posns[j], "i:%d posns[%d] %d != expected posns[%d] %d\n", i, j, posns[j], j, data[i].posns[j]);
assert_equal(posns[j], data[i].posns[j], "i:%d posns[%d] %d != expected posns[%d] %d\n",
i, j, posns[j], j, data[i].posns[j]);
}
}
}
@ -407,7 +409,8 @@ static void test_errtxt(const testCtx *const p_ctx) {
ret = errtxt(data[i].error_number, symbol, data[i].err_id, data[i].msg);
assert_equal(ret, data[i].error_number, "i:%d ret %d != %d\n", i, ret, data[i].error_number);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected);
}
testFinish();
@ -539,7 +542,8 @@ static void test_errtxtf(const testCtx *const p_ctx) {
if (data[i].debug_test) symbol->debug |= ZINT_DEBUG_TEST;
if (data[i].num_args == 0) {
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, NULL /*suppress -Wformat-security*/);
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt,
NULL /*suppress -Wformat-security*/);
} else if (data[i].num_args == 1) {
if (data[i].i_arg != -1) {
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg);
@ -551,29 +555,36 @@ static void test_errtxtf(const testCtx *const p_ctx) {
} else if (data[i].num_args == 2) {
if (data[i].i_arg != -1) {
if (data[i].s_arg != NULL) {
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg, data[i].s_arg);
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg,
data[i].s_arg);
} else {
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg, data[i].f_arg);
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg,
data[i].f_arg);
}
} else {
assert_nonnull(data[i].s_arg, "i:%d num_args:%d data[i].s_arg NULL", i, data[i].num_args);
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].s_arg, data[i].f_arg);
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].s_arg,
data[i].f_arg);
}
} else if (data[i].num_args == 3) {
assert_nonnull(data[i].s_arg, "i:%d num_args:%d data[i].s_arg NULL", i, data[i].num_args);
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg, data[i].s_arg, data[i].f_arg);
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg, data[i].s_arg,
data[i].f_arg);
} else if (data[i].num_args == 9) { /* Special case max, assuming 4th arg "%d", 5th arg "%s" */
assert_nonnull(data[i].s_arg, "i:%d num_args:%d data[i].s_arg NULL", i, data[i].num_args);
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, 2100000001, 2100000002, 3333, data[i].i_arg, data[i].s_arg, 2100000006, 2100000007, 2100000008, 2100000009);
ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, 2100000001, 2100000002, 3333,
data[i].i_arg, data[i].s_arg, 2100000006, 2100000007, 2100000008, 2100000009);
} else {
assert_nonnull(NULL, "i:%d num_args:%d > 3 && != 9\n", i, data[i].num_args);
}
if (data[i].ret == -1) {
assert_equal(ret, data[i].error_number, "i:%d ret %d != %d (%s)\n", i, ret, data[i].error_number, symbol->errtxt);
assert_equal(ret, data[i].error_number, "i:%d ret %d != %d (%s)\n",
i, ret, data[i].error_number, symbol->errtxt);
} else {
assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
}
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected);
}
testFinish();
@ -700,9 +711,11 @@ static void test_utf8_to_unicode(const testCtx *const p_ctx) {
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
if (ret == 0) {
int j;
assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length);
assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n",
i, ret_length, data[i].ret_length);
for (j = 0; j < ret_length; j++) {
assert_equal(vals[j], data[i].expected_vals[j], "i:%d vals[%d] %04X != %04X\n", i, j, vals[j], data[i].expected_vals[j]);
assert_equal(vals[j], data[i].expected_vals[j], "i:%d vals[%d] %04X != %04X\n",
i, j, vals[j], data[i].expected_vals[j]);
}
}
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n",
@ -920,7 +933,8 @@ static void test_hrt_cpy_cat_nochk(const testCtx *const p_ctx) {
expected_length = data[i].expected_length == -1 ? (int) strlen(data[i].expected) : data[i].expected_length;
hrt_cpy_cat_nochk(symbol, TCU(data[i].source), data[i].length, data[i].separator, TCU(data[i].cat), data[i].cat_length);
hrt_cpy_cat_nochk(symbol, TCU(data[i].source), data[i].length, data[i].separator, TCU(data[i].cat),
data[i].cat_length);
if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) {
for (j = 0; j < symbol->text_length; j++) {
@ -1243,8 +1257,10 @@ static void test_rt_printf_256(const testCtx *const p_ctx) {
if (data[i].num_args == 1) {
ret = rt_printf_256(symbol, data[i].fmt, data[i].data1);
assert_zero(ret, "i:%d rt_printf_256 1 arg ret %d != 0\n", i, ret);
} else if (data[i].num_args == 2) {
ret = rt_printf_256(symbol, data[i].fmt, data[i].data1, data[i].data2);
assert_zero(ret, "i:%d rt_printf_256 2 args ret %d != 0\n", i, ret);
} else {
assert_zero(1, "i:%d, bad num_args\n", i);
}
@ -1323,10 +1339,13 @@ static void test_set_height(const testCtx *const p_ctx) {
}
symbol->height = data[i].height;
ret = set_height(symbol, data[i].min_row_height, data[i].default_height, data[i].max_height, data[i].no_errtxt);
ret = set_height(symbol, data[i].min_row_height, data[i].default_height, data[i].max_height,
data[i].no_errtxt);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
assert_equal(symbol->height, data[i].expected_height, "i:%d symbol->height %g != %g\n", i, symbol->height, data[i].expected_height);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d errtxt %s != %s\n", i, symbol->errtxt, data[i].expected_errtxt);
assert_equal(symbol->height, data[i].expected_height, "i:%d symbol->height %g != %g\n",
i, symbol->height, data[i].expected_height);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d errtxt %s != %s\n",
i, symbol->errtxt, data[i].expected_errtxt);
}
testFinish();
@ -1350,7 +1369,7 @@ static void test_debug_test_codeword_dump_int(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
int i;
struct zint_symbol s_symbol;
struct zint_symbol s_symbol = {0};
struct zint_symbol *symbol = &s_symbol;
testStart(p_ctx->func_name);
@ -1362,8 +1381,11 @@ static void test_debug_test_codeword_dump_int(const testCtx *const p_ctx) {
if (testContinue(p_ctx, i)) continue;
debug_test_codeword_dump_int(symbol, data[i].codewords, data[i].length);
assert_nonzero(strlen(symbol->errtxt) < 92, "i:%d strlen(%s) >= 92 (%d)\n", i, symbol->errtxt, (int) strlen(symbol->errtxt));
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0 (%d, %d)\n", i, symbol->errtxt, data[i].expected, (int) strlen(symbol->errtxt), (int) strlen(data[i].expected));
assert_nonzero(strlen(symbol->errtxt) < 92, "i:%d strlen(%s) >= 92 (%d)\n",
i, symbol->errtxt, (int) strlen(symbol->errtxt));
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0 (%d, %d)\n",
i, symbol->errtxt, data[i].expected, (int) strlen(symbol->errtxt),
(int) strlen(data[i].expected));
}
testFinish();

View file

@ -3599,96 +3599,6 @@ static void test_fuzz(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITERATIONS 1000
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int option_1;
const char *data;
const char *composite;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_EANX_CC, 1, "123456789012",
"[91]123456789012345678901234567890123456789012345678901234",
0, 11, 99, "58 chars CC-A" },
/* 1*/ { BARCODE_UPCA_CC, 2, "12345678901",
"[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[94]12345678901234567890123456789012345678901234567890",
0, 48, 99, "336 chars CC-B" },
/* 2*/ { BARCODE_GS1_128_CC, 3, "[01]12345678901231",
"[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
0, 32, 205, "564 chars CC-C" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, composite_length, ret;
clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data);
composite_length = (int) strlen(data[i].composite);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].composite), composite_length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
ZBarcode_Delete(symbol);
}
printf("%s: diff_encode %gms, diff_buffer %gms\n", data[i].comment, diff_encode * 1000.0 / CLOCKS_PER_SEC, diff_buffer * 1000.0 / CLOCKS_PER_SEC);
total_encode += diff_encode;
total_buffer += diff_buffer;
}
if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -3705,7 +3615,6 @@ int main(int argc, char *argv[]) {
{ "test_hrt", test_hrt },
{ "test_input", test_input },
{ "test_fuzz", test_fuzz },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -398,10 +398,18 @@ static void test_large(const testCtx *const p_ctx) {
testUtilEscape(data[i].pattern, (int) strlen(data[i].pattern), escaped, sizeof(escaped)),
data[i].length, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].zxingcpp_cmp,
errtxt);
ZBarcode_Clear(symbol);
symbol->input_mode |= FAST_MODE;
length = testUtilSetSymbol(symbol, data[i].symbology, FAST_MODE /*input_mode*/, -1 /*eci*/,
-1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/,
data_buf, data[i].length, debug);
if (data[i].structapp.count) {
symbol->structapp = data[i].structapp;
}
(void) ZBarcode_Encode(symbol, TCU(data_buf), length);
printf(" \"%s\", \"%s\" },\n", strcmp(errtxt, symbol->errtxt) != 0 ? symbol->errtxt : "", data[i].comment);
printf(" \"%s\", \"%s\" },\n",
strcmp(errtxt, symbol->errtxt) != 0 ? symbol->errtxt : "", data[i].comment);
} else {
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
@ -435,7 +443,13 @@ static void test_large(const testCtx *const p_ctx) {
}
ZBarcode_Clear(symbol);
symbol->input_mode |= FAST_MODE;
length = testUtilSetSymbol(symbol, data[i].symbology, FAST_MODE /*input_mode*/, -1 /*eci*/,
-1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/,
data_buf, data[i].length, debug);
if (data[i].structapp.count) {
symbol->structapp = data[i].structapp;
}
ret = ZBarcode_Encode(symbol, TCU(data_buf), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
@ -519,18 +533,26 @@ static void test_buffer(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, data[i].output_options, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode, data[i].eci,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, data[i].output_options,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
char modules_dump[144 * 144 + 1];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf),
NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
@ -705,13 +727,16 @@ static void test_options(const testCtx *const p_ctx) {
assert_nonnull(symbol, "Symbol not created\n");
debug &= ~ZINT_DEBUG_TEST; /* Want real errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, data[i].output_options, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
data[i].option_1, data[i].option_2, data[i].option_3, data[i].output_options,
data[i].data, -1, debug);
if (data[i].structapp.count) {
symbol->structapp = data[i].structapp;
}
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (ret < ZINT_ERROR) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (width %d) (%s)\n",
@ -720,12 +745,18 @@ static void test_options(const testCtx *const p_ctx) {
i, symbol->width, data[i].expected_width, symbol->errtxt);
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
char modules_dump[144 * 144 + 1];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, data[i].data, length, NULL,
cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
@ -760,15 +791,26 @@ static void test_options(const testCtx *const p_ctx) {
assert_zero(symbol->option_3, "i:%d symbol->option_3 %d != 0\n", i, symbol->option_3); /* Unchanged */
}
symbol->input_mode |= FAST_MODE;
ZBarcode_Clear(symbol);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode | FAST_MODE, -1 /*eci*/,
data[i].option_1, data[i].option_2, data[i].option_3, data[i].output_options,
data[i].data, -1, debug);
if (data[i].structapp.count) {
symbol->structapp = data[i].structapp;
}
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode FAST_MODE ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode FAST_MODE ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (ret < ZINT_ERROR) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n",
i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n",
i, symbol->width, data[i].expected_width);
}
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d symbol->errtxt %s != %s\n", i, symbol->errtxt, data[i].expected_errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d symbol->errtxt %s != %s\n",
i, symbol->errtxt, data[i].expected_errtxt);
ZBarcode_Delete(symbol);
}
@ -817,10 +859,13 @@ static void test_reader_init(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
@ -838,8 +883,10 @@ static void test_reader_init(const testCtx *const p_ctx) {
char modules_dump[144 * 144 + 1];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf),
NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
@ -862,7 +909,8 @@ static void test_reader_init(const testCtx *const p_ctx) {
escaped);
}
}
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected);
}
ZBarcode_Delete(symbol);
@ -1180,7 +1228,8 @@ static void test_input(const testCtx *const p_ctx) {
}
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %s, %s, { %d, %d, \"%s\" }, \"%s\", %s, %d, %d, %d, %d, %d, \"%s\", \"%s\", %d },\n",
@ -1193,25 +1242,35 @@ static void test_input(const testCtx *const p_ctx) {
data[i].bwipp_cmp, data[i].zxingcpp_cmp, symbol->errtxt, data[i].comment, data[i].expected_diff);
} else {
if (ret < ZINT_ERROR) {
assert_equal(symbol->eci, data[i].expected_eci, "i:%d eci %d != %d\n", i, symbol->eci, data[i].expected_eci);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d width %d != %d\n", i, symbol->width, data[i].expected_width);
assert_equal(symbol->eci, data[i].expected_eci, "i:%d eci %d != %d\n",
i, symbol->eci, data[i].expected_eci);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d rows %d != %d\n",
i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d width %d != %d\n",
i, symbol->width, data[i].expected_width);
}
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected);
if (ret < ZINT_ERROR) {
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
char modules_dump[144 * 144 + 1];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, data[i].data, length,
NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
@ -1235,9 +1294,11 @@ static void test_input(const testCtx *const p_ctx) {
#ifdef ZINT_TEST_ENCODING
if (ret < ZINT_ERROR) {
if (i && (data[i].input_mode & 0x07) == (data[i - 1].input_mode & 0x07) && !(data[i].input_mode & FAST_MODE) && (data[i - 1].input_mode & FAST_MODE)
if (i && (data[i].input_mode & 0x07) == (data[i - 1].input_mode & 0x07)
&& !(data[i].input_mode & FAST_MODE) && (data[i - 1].input_mode & FAST_MODE)
&& data[i].eci == data[i - 1].eci && data[i].option_2 == data[i - 1].option_2
&& data[i].option_3 == data[i - 1].option_3 && data[i].output_options == data[i - 1].output_options
&& data[i].option_3 == data[i - 1].option_3
&& data[i].output_options == data[i - 1].output_options
&& strcmp(data[i].data, data[i - 1].data) == 0) {
unsigned char binary[2][2200];
int gs1;
@ -1246,10 +1307,12 @@ static void test_input(const testCtx *const p_ctx) {
unsigned char reduced[1000];
unsigned char *text;
const int last_seg = 1;
const int expected_rows_width = data[i].expected_rows * data[i].expected_width;
const int prev_expected_rows_width = data[i - 1].expected_rows * data[i - 1].expected_width;
assert_equal(data[i].expected_rows * data[i].expected_width <= data[i - 1].expected_rows * data[i - 1].expected_width, 1,
"i:%d data[i].expected_rows * data[i].expected_width %d > data[i - 1].expected_rows * data[i - 1].expected_width %d\n", i,
data[i].expected_rows * data[i].expected_width, data[i - 1].expected_rows * data[i - 1].expected_width);
assert_equal(expected_rows_width <= prev_expected_rows_width, 1,
"i:%d expected_rows_width %d > prev_expected_rows_width %d\n",
i, expected_rows_width, prev_expected_rows_width);
if ((data[i].input_mode & 0x07) == GS1_MODE) {
ret = gs1_verify(symbol, (unsigned char *) data[i].data, length, reduced, &length);
@ -1261,7 +1324,8 @@ static void test_input(const testCtx *const p_ctx) {
binlen = 0;
symbol->input_mode = data[i - 1].input_mode;
symbol->option_2 = data[i].option_2 != -1 ? data[i].option_2 : 0; /* Restore option_2 */
gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 : (symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1;
gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 :
(symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1;
ret = dm_encode_test(symbol, text, length, symbol->eci, last_seg, gs1, binary[0], &binlen);
assert_zero(ret, "i:%d dm_encode() FAST_MODE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
@ -1269,17 +1333,20 @@ static void test_input(const testCtx *const p_ctx) {
binlen = 0;
symbol->input_mode = data[i].input_mode;
gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 : (symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1;
gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 :
(symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1;
symbol->option_2 = data[i].option_2 != -1 ? data[i].option_2 : 0; /* Restore option_2 */
ret = dm_encode_test(symbol, text, length, symbol->eci, last_seg, gs1, binary[1], &binlen);
assert_zero(ret, "i:%d dm_encode() minimal ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
binlens[1] = binlen;
assert_equal(binlens[0], binlens[1] + data[i].expected_diff, "i:%d binlens[0] %d != %d binlens[1] (%d) + expected_diff (%d)\n",
assert_equal(binlens[0], binlens[1] + data[i].expected_diff,
"i:%d binlens[0] %d != %d binlens[1] (%d) + expected_diff (%d)\n",
i, binlens[0], binlens[1] + data[i].expected_diff, binlens[1], data[i].expected_diff);
if (data[i].expected_diff >= 0) {
assert_equal(binlens[1] <= binlens[0], 1, "i:%d binlens[1] %d > binlens[0] %d\n", i, binlens[1], binlens[0]);
assert_equal(binlens[1] <= binlens[0], 1, "i:%d binlens[1] %d > binlens[0] %d\n",
i, binlens[1], binlens[0]);
}
}
}
@ -5777,22 +5844,31 @@ static void test_encode(const testCtx *const p_ctx) {
if (ret < ZINT_ERROR) {
int width, row;
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n",
i, ret, width, row, data[i].data);
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, data[i].data, length,
NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf,
data[i].expected);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
@ -5814,23 +5890,28 @@ static void test_encode(const testCtx *const p_ctx) {
}
#ifdef ZINT_TEST_ENCODING
if (i && (data[i].input_mode & 0x07) == (data[i - 1].input_mode & 0x07) && !(data[i].input_mode & FAST_MODE) && (data[i - 1].input_mode & FAST_MODE)
if (i && (data[i].input_mode & 0x07) == (data[i - 1].input_mode & 0x07)
&& !(data[i].input_mode & FAST_MODE) && (data[i - 1].input_mode & FAST_MODE)
&& data[i].eci == data[i - 1].eci && data[i].option_2 == data[i - 1].option_2
&& data[i].option_3 == data[i - 1].option_3 && data[i].output_options == data[i - 1].output_options
&& data[i].option_3 == data[i - 1].option_3
&& data[i].output_options == data[i - 1].output_options
&& strcmp(data[i].data, data[i - 1].data) == 0) {
unsigned char binary[2][2200];
int gs1;
int binlen;
int binlens[2] = {0};
const int last_seg = 1;
const int expected_rows_width = data[i].expected_rows * data[i].expected_width;
const int prev_expected_rows_width = data[i - 1].expected_rows * data[i - 1].expected_width;
assert_equal(data[i].expected_rows * data[i].expected_width <= data[i - 1].expected_rows * data[i - 1].expected_width, 1,
"i:%d data[i].expected_rows * data[i].expected_width %d > data[i - 1].expected_rows * data[i - 1].expected_width %d\n", i,
data[i].expected_rows * data[i].expected_width, data[i - 1].expected_rows * data[i - 1].expected_width);
assert_equal(expected_rows_width <= prev_expected_rows_width, 1,
"i:%d expected_rows_width %d > prev_expected_rows_width %d\n", i,
expected_rows_width, prev_expected_rows_width);
binlen = 0;
symbol->input_mode = data[i - 1].input_mode;
gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 : (symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1;
gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 :
(symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1;
ret = dm_encode_test(symbol, (unsigned char *) data[i].data, length, symbol->eci, last_seg, gs1,
binary[0], &binlen);
assert_zero(ret, "i:%d dm_encode() FAST_MODE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
@ -5839,14 +5920,16 @@ static void test_encode(const testCtx *const p_ctx) {
binlen = 0;
symbol->input_mode = data[i].input_mode;
gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 : (symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1;
gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 :
(symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1;
ret = dm_encode_test(symbol, (unsigned char *) data[i].data, length, symbol->eci, last_seg, gs1,
binary[1], &binlen);
assert_zero(ret, "i:%d dm_encode() minimal ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
binlens[1] = binlen;
assert_equal(binlens[1] <= binlens[0], 1, "i:%d binlens[1] %d > binlens[0] %d\n", i, binlens[1], binlens[0]);
assert_equal(binlens[1] <= binlens[0], 1, "i:%d binlens[1] %d > binlens[0] %d\n",
i, binlens[1], binlens[0]);
assert_equal(binlens[0], binlens[1] + data[i].expected_diff,
"i:%d binlens[0] %d != %d binlens[1] (%d) + expected_diff (%d)\n",
i, binlens[0], binlens[1] + data[i].expected_diff, binlens[1], data[i].expected_diff);
@ -6198,8 +6281,9 @@ static void test_encode_segs(const testCtx *const p_ctx) {
char cmp_buf[32768];
char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
/* Only do BWIPP/ZXing-C++ tests if asked, too slow otherwise */
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript();
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder();
testStartSymbol(p_ctx->func_name, &symbol);
@ -6211,15 +6295,16 @@ static void test_encode_segs(const testCtx *const p_ctx) {
assert_nonnull(symbol, "Symbol not created\n");
testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, data[i].option_2, data[i].option_3, data[i].output_options,
NULL, 0, debug);
-1 /*option_1*/, data[i].option_2, data[i].option_3, data[i].output_options,
NULL, 0, debug);
if (data[i].structapp.count) {
symbol->structapp = data[i].structapp;
}
for (j = 0, seg_count = 0; j < 3 && data[i].segs[j].length; j++, seg_count++);
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
char escaped1[4096];
@ -6232,9 +6317,12 @@ static void test_encode_segs(const testCtx *const p_ctx) {
testUtilOutputOptionsName(data[i].output_options),
data[i].option_2, testUtilOption3Name(data[i].symbology, data[i].option_3),
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
testUtilEscape((const char *) data[i].segs[0].source, length, escaped, sizeof(escaped)), data[i].segs[0].length, data[i].segs[0].eci,
testUtilEscape((const char *) data[i].segs[1].source, length1, escaped1, sizeof(escaped1)), data[i].segs[1].length, data[i].segs[1].eci,
testUtilEscape((const char *) data[i].segs[2].source, length2, escaped2, sizeof(escaped2)), data[i].segs[2].length, data[i].segs[2].eci,
testUtilEscape((const char *) data[i].segs[0].source, length, escaped, sizeof(escaped)),
data[i].segs[0].length, data[i].segs[0].eci,
testUtilEscape((const char *) data[i].segs[1].source, length1, escaped1, sizeof(escaped1)),
data[i].segs[1].length, data[i].segs[1].eci,
testUtilEscape((const char *) data[i].segs[2].source, length2, escaped2, sizeof(escaped2)),
data[i].segs[2].length, data[i].segs[2].eci,
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment);
testUtilModulesPrint(symbol, " ", "\n");
printf(" },\n");
@ -6242,25 +6330,34 @@ static void test_encode_segs(const testCtx *const p_ctx) {
if (ret < ZINT_ERROR) {
int width, row;
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n",
i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n",
i, symbol->width, data[i].expected_width);
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d\n", i, ret, width, row);
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
ret = testUtilBwippSegs(i, symbol, -1, data[i].option_2, data[i].option_3, data[i].segs, seg_count, NULL, cmp_buf, sizeof(cmp_buf));
assert_zero(ret, "i:%d %s testUtilBwippSegs ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippSegs(i, symbol, -1, data[i].option_2, data[i].option_3, data[i].segs,
seg_count, NULL, cmp_buf, sizeof(cmp_buf));
assert_zero(ret, "i:%d %s testUtilBwippSegs ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf,
data[i].expected);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, (const char *) data[i].segs[0].source, data[i].segs[0].length, debug)) {
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, (const char *) data[i].segs[0].source,
data[i].segs[0].length, debug)) {
if (data[i].input_mode == DATA_MODE) {
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s multiple segments in DATA_MODE not currently supported for ZXing-C++ testing\n",
@ -6269,14 +6366,18 @@ static void test_encode_segs(const testCtx *const p_ctx) {
} else {
int cmp_len, ret_len;
char modules_dump[144 * 144 + 1];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilZXingCPP(i, symbol, (const char *) data[i].segs[0].source, data[i].segs[0].length,
modules_dump, 1 /*zxingcpp_cmp*/, cmp_buf, sizeof(cmp_buf), &cmp_len);
assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilZXingCPP(i, symbol, (const char *) data[i].segs[0].source,
data[i].segs[0].length, modules_dump, 1 /*zxingcpp_cmp*/, cmp_buf, sizeof(cmp_buf),
&cmp_len);
assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilZXingCPPCmpSegs(symbol, cmp_msg, cmp_buf, cmp_len, data[i].segs, seg_count,
NULL /*primary*/, escaped, &ret_len);
assert_zero(ret, "i:%d %s testUtilZXingCPPCmpSegs %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
assert_zero(ret,
"i:%d %s testUtilZXingCPPCmpSegs %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len,
escaped);
}
@ -7524,26 +7625,33 @@ static void test_minimalenc(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, data[i].output_options, data[i].data, data[i].length, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, data[i].option_2, -1, data[i].output_options,
data[i].data, data[i].length, debug);
binlen = 0;
symbol->input_mode |= FAST_MODE;
gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 : (symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1;
ret = dm_encode_test(symbol, (unsigned char *) data[i].data, length, symbol->eci, last_seg, gs1, binary[0], &binlen);
assert_equal(ret, data[i].ret, "i:%d dm_encode() FAST_MODE ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
ret = dm_encode_test(symbol, (unsigned char *) data[i].data, length, symbol->eci, last_seg, gs1, binary[0],
&binlen);
assert_equal(ret, data[i].ret, "i:%d dm_encode() FAST_MODE ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
binlens[0] = binlen;
binlen = 0;
symbol->input_mode &= ~FAST_MODE;
gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 : (symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1;
ret = dm_encode_test(symbol, (unsigned char *) data[i].data, length, symbol->eci, last_seg, gs1, binary[1], &binlen);
assert_equal(ret, data[i].ret, "i:%d dm_encode() minimal ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
ret = dm_encode_test(symbol, (unsigned char *) data[i].data, length, symbol->eci, last_seg, gs1, binary[1],
&binlen);
assert_equal(ret, data[i].ret, "i:%d dm_encode() minimal ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
binlens[1] = binlen;
fflush(stdout);
assert_equal(binlens[0], binlens[1] + data[i].expected_diff, "i:%d binlens[0] %d != %d binlens[1] (%d) + expected_diff (%d)\n",
assert_equal(binlens[0], binlens[1] + data[i].expected_diff,
"i:%d binlens[0] %d != %d binlens[1] (%d) + expected_diff (%d)\n",
i, binlens[0], binlens[1] + data[i].expected_diff, binlens[1], data[i].expected_diff);
if (debug & ZINT_DEBUG_TEST_PRINT) {
@ -7563,180 +7671,6 @@ static void test_minimalenc(const testCtx *const p_ctx) {
}
#endif
#include <time.h>
#if 1
#define TEST_PERF_ITER_MILLES 5
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#else
#define TEST_PERF_ITERATIONS 100 /* For valgrind */
#endif
#define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int input_mode;
int option_2;
int option_3;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_DATAMATRIX, FAST_MODE, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz&,:#-.$/+%*=^ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM"
"NOPQRSTUVWXYZ;<>@[]_`~!||()?{}'123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJK"
"LMNOPQRSTUVWXYZ12345678912345678912345678912345678900001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFG"
"HIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567"
"890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcde"
"fghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
0, 96, 96, "960 chars, text/numeric" },
/* 1*/ { BARCODE_DATAMATRIX, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz&,:#-.$/+%*=^ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM"
"NOPQRSTUVWXYZ;<>@[]_`~!||()?{}'123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJK"
"LMNOPQRSTUVWXYZ12345678912345678912345678912345678900001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFG"
"HIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567"
"890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcde"
"fghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
0, 96, 96, "960 chars, text/numeric" },
/* 2*/ { BARCODE_DATAMATRIX, DATA_MODE | FAST_MODE, -1, -1,
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240",
0, 120, 120, "960 chars, byte" },
/* 3*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, -1,
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240",
0, 120, 120, "960 chars, byte" },
/* 4*/ { BARCODE_DATAMATRIX, FAST_MODE, -1, -1, "https://example.com/01/09506000134369", 0, 22, 22, "37 chars, text/numeric" },
/* 5*/ { BARCODE_DATAMATRIX, -1, -1, -1, "https://example.com/01/09506000134369", 0, 22, 22, "37 chars, text/numeric" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
clock_t start;
clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print;
int comment_max = 0;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
printf("Iterations %d\n", TEST_PERF_ITERATIONS);
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter), TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
total_buf_inter += diff_buf_inter;
total_print += diff_print;
}
if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -7752,7 +7686,6 @@ int main(int argc, char *argv[]) {
#ifdef ZINT_TEST_ENCODING
{ "test_minimalenc", test_minimalenc },
#endif
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -46,9 +46,12 @@ static void test_large(const testCtx *const p_ctx) {
/* 0*/ { 200, '0', 2940, 0, "" }, /* 2940 largest Code Set C data that fits in 200x199 HxW */
/* 1*/ { 200, '0', 2941, ZINT_ERROR_INVALID_OPTION, "Error 528: Resulting symbol height '201' is too large (maximum 200)" },
/* 2*/ { 200, '9', 200, 0, "" }, /* Changes a number of mask scores re pre-Rev. 4 version, but best score still the same (7) */
/* 3*/ { 201, '0', 2940, ZINT_ERROR_INVALID_OPTION, "Error 528: Resulting symbol width '201' is too large (maximum 200)" },
/* 4*/ { 201, '0', 2974, ZINT_ERROR_INVALID_OPTION, "Error 526: Resulting symbol size '202x201' (HxW) is too large (maximum 200x200)" }, /* Height > 200 also */
/* 5*/ { 30, '\001', 71, 0, "" }, /* Codeword length 72, ECC length 39, for ND + 1 == 112 */
/* 3*/ { 200, '0', 2974, ZINT_ERROR_INVALID_OPTION, "Error 528: Resulting symbol height '203' is too large (maximum 200)" }, /* Width > 200 also */
/* 4*/ { 200, 'A', 1470, 0, "" },
/* 5*/ { 200, 'A', 1471, ZINT_ERROR_INVALID_OPTION, "Error 528: Resulting symbol height '201' is too large (maximum 200)" },
/* 6*/ { 200, '\240', 1225, 0, "" },
/* 7*/ { 200, '\240', 1226, ZINT_ERROR_INVALID_OPTION, "Error 528: Resulting symbol height '201' is too large (maximum 200)" },
/* 8*/ { 30, '\001', 71, 0, "" }, /* Codeword length 72, ECC length 39, for ND + 1 == 112 */
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
@ -105,11 +108,11 @@ static void test_options(const testCtx *const p_ctx) {
/* 2*/ { -1, -1, -1, 19, -1, { 0, 0, "" }, "1234567890", 0, 12, 19, "", 19, 2 << 8 },
/* 3*/ { -1, -1, -1, 12, -1, { 0, 0, "" }, "1234567890", 0, 19, 12, "", 12, 2 << 8 },
/* 4*/ { -1, -1, -1, 5, -1, { 0, 0, "" }, "1234567890", 0, 44, 5, "", 5, 6 << 8 },
/* 5*/ { -1, -1, -1, 4, -1, { 0, 0, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 529: Resulting symbol width '4' is too small (minimum 5)", 4, 0 }, /* Cols < 5 */
/* 6*/ { -1, -1, -1, 200, -1, { 0, 0, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 529: Resulting symbol height '3' is too small (minimum 5)", 200, 0 }, /* Not enough data - height 3 too small */
/* 5*/ { -1, -1, -1, 4, -1, { 0, 0, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 527: Number of columns '4' is out of range (5 to 200)", 4, 0 }, /* Cols < 5 */
/* 6*/ { -1, -1, -1, 200, -1, { 0, 0, "" }, "1234567890", 0, 5, 200, "", 200, 7 << 8 }, /* Note used to fail - now sets height to at least 5 */
/* 7*/ { -1, -1, -1, 200, -1, { 0, 0, "" }, "1234567890123456789012345678901234567890", 0, 5, 200, "", 200, 7 << 8 }, /* Cols 200 max */
/* 8*/ { -1, -1, -1, 200, -1, { 0, 0, "" }, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, 7, 200, "", 200, 4 << 8 },
/* 9*/ { -1, -1, -1, 201, -1, { 0, 0, "" }, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 528: Resulting symbol width '201' is too large (maximum 200)", 201, 0 },
/* 9*/ { -1, -1, -1, 201, -1, { 0, 0, "" }, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 527: Number of columns '201' is out of range (5 to 200)", 201, 0 },
/* 10*/ { -1, -1, -1, -1, 10 << 8, { 0, 0, "" }, "1", 0, 9, 14, "", 14, 1 << 8 }, /* Mask > 8 + 1 ignored */
/* 11*/ { -1, -1, -1, -1, 8 << 8, { 0, 0, "" }, "1", 0, 9, 14, "", 14, 8 << 8 },
/* 12*/ { -1, -1, -1, 19, -1, { 0, 0, "" }, "ABCDE", 0, 12, 19, "", 19, 3 << 8 },
@ -1879,84 +1882,6 @@ static void test_generate(const testCtx *const p_ctx) {
printf("\n };\n");
}
#include <time.h>
#define TEST_PERF_ITERATIONS 1000
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int input_mode;
int option_1;
int option_2;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_DOTCODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz&,:#-.$/+%*=^ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM"
"NOPQRSTUVWXYZ;<>@[]_`~!||()?{}'123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJK"
"LMNOPQRSTUVWXYZ12345678912345678912345678912345678900001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFG"
"HIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567"
"890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcde"
"fghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
0, 124, 185, "960 chars, text/numeric" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
ZBarcode_Delete(symbol);
}
printf("%s: diff_encode %gms, diff_buffer %gms\n", data[i].comment, diff_encode * 1000.0 / CLOCKS_PER_SEC, diff_buffer * 1000.0 / CLOCKS_PER_SEC);
total_encode += diff_encode;
total_buffer += diff_buffer;
}
if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -1969,7 +1894,6 @@ int main(int argc, char *argv[]) {
{ "test_rt_segs", test_rt_segs },
{ "test_fuzz", test_fuzz },
{ "test_generate", test_generate },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -1091,92 +1091,6 @@ static void test_rt_segs(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITERATIONS 1000
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int input_mode;
int option_1;
int option_2;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_GRIDMATRIX, UNICODE_MODE, -1, -1,
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738",
0, 66, 66, "97 chars, mixed modes" },
/* 1*/ { BARCODE_GRIDMATRIX, UNICODE_MODE, -1, -1,
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738",
0, 162, 162, "970 chars, mixed modes" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
ZBarcode_Delete(symbol);
}
printf("%s: diff_encode %gms, diff_buffer %gms\n", data[i].comment, diff_encode * 1000.0 / CLOCKS_PER_SEC, diff_buffer * 1000.0 / CLOCKS_PER_SEC);
total_encode += diff_encode;
total_buffer += diff_buffer;
}
if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -1187,7 +1101,6 @@ int main(int argc, char *argv[]) {
{ "test_encode_segs", test_encode_segs },
{ "test_rt", test_rt },
{ "test_rt_segs", test_rt_segs },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -2346,7 +2346,7 @@ static void test_input_mode(const testCtx *const p_ctx) {
int i, length, ret;
struct zint_symbol *symbol = NULL;
struct zint_symbol previous_symbol;
struct zint_symbol *previous_symbol = NULL;
testStartSymbol(p_ctx->func_name, &symbol);
@ -2357,18 +2357,21 @@ static void test_input_mode(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, data[i].output_options, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, data[i].output_options,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->index == -1 && data[i].compare_previous) {
ret = testUtilSymbolCmp(symbol, &previous_symbol);
ret = testUtilSymbolCmp(symbol, previous_symbol);
assert_zero(ret, "i:%d testUtilSymbolCmp ret %d != 0\n", i, ret);
}
memcpy(&previous_symbol, symbol, sizeof(previous_symbol));
ZBarcode_Delete(symbol);
ZBarcode_Delete(previous_symbol);
previous_symbol = symbol;
}
ZBarcode_Delete(previous_symbol);
testFinish();
}

View file

@ -3839,108 +3839,6 @@ static void test_fuzz(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITERATIONS 1000
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int input_mode;
int option_1;
int option_2;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_HANXIN, UNICODE_MODE, -1, -1,
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。",
ZINT_WARN_NONCOMPLIANT, 43, 43, "98 chars, Region One and Text" },
/* 1*/ { BARCODE_HANXIN, UNICODE_MODE, -1, -1,
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。",
ZINT_WARN_NONCOMPLIANT, 121, 121, "980 chars, Region One and Text" },
/* 2*/ { BARCODE_HANXIN, UNICODE_MODE, -1, -1,
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。",
ZINT_WARN_NONCOMPLIANT, 147, 147, "1470 chars, Region One and Text" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
ZBarcode_Delete(symbol);
}
printf("%s: diff_encode %gms, diff_buffer %gms\n", data[i].comment, diff_encode * 1000.0 / CLOCKS_PER_SEC, diff_buffer * 1000.0 / CLOCKS_PER_SEC);
total_encode += diff_encode;
total_buffer += diff_buffer;
}
if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -3952,7 +3850,6 @@ int main(int argc, char *argv[]) {
{ "test_rt", test_rt },
{ "test_rt_segs", test_rt_segs },
{ "test_fuzz", test_fuzz },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -229,7 +229,9 @@ static void test_checks(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci,
data[i].option_1, -1, -1, -1 /*output_options*/,
data[i].data, data[i].length, debug);
if (data[i].height) {
symbol->height = data[i].height;
}
@ -259,15 +261,19 @@ static void test_checks(const testCtx *const p_ctx) {
}
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode(%d) ret %d != %d (%s)\n",
i, data[i].symbology, ret, data[i].ret, symbol->errtxt);
ret = strcmp(symbol->errtxt, data[i].expected);
assert_zero(ret, "i:%d (%d) strcmp(%s, %s) %d != 0\n", i, data[i].symbology, symbol->errtxt, data[i].expected, ret);
assert_zero(ret, "i:%d (%d) strcmp(%s, %s) %d != 0\n",
i, data[i].symbology, symbol->errtxt, data[i].expected, ret);
if (data[i].expected_symbology == -1) {
assert_equal(symbol->symbology, data[i].symbology, "i:%d symbol->symbology %d != original %d\n", i, symbol->symbology, data[i].symbology);
assert_equal(symbol->symbology, data[i].symbology, "i:%d symbol->symbology %d != original %d\n",
i, symbol->symbology, data[i].symbology);
} else {
assert_equal(symbol->symbology, data[i].expected_symbology, "i:%d symbol->symbology %d != expected %d\n", i, symbol->symbology, data[i].expected_symbology);
assert_equal(symbol->symbology, data[i].expected_symbology, "i:%d symbol->symbology %d != expected %d\n",
i, symbol->symbology, data[i].expected_symbology);
}
ZBarcode_Delete(symbol);
@ -322,16 +328,20 @@ static void test_checks_segs(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].option_1, -1, -1, -1 /*output_options*/, NULL, 0, debug);
testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci,
data[i].option_1, -1, -1, -1 /*output_options*/,
NULL, 0, debug);
if (data[i].warn_level != -1) {
symbol->warn_level = data[i].warn_level;
}
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, data[i].seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs(%d) ret %d != %d (%s)\n",
i, data[i].symbology, ret, data[i].ret, symbol->errtxt);
ret = strcmp(symbol->errtxt, data[i].expected);
assert_zero(ret, "i:%d (%d) strcmp(%s, %s) %d != 0\n", i, data[i].symbology, symbol->errtxt, data[i].expected, ret);
assert_zero(ret, "i:%d (%d) strcmp(%s, %s) %d != 0\n",
i, data[i].symbology, symbol->errtxt, data[i].expected, ret);
ZBarcode_Delete(symbol);
}
@ -383,13 +393,17 @@ static void test_input_data(const testCtx *const p_ctx) {
} else {
text = data[i].data;
}
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, text, -1, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, -1, -1, -1 /*output_options*/,
text, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(text), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode(%d) ret %d != %d (%s)\n",
i, data[i].symbology, ret, data[i].ret, symbol->errtxt);
ret = strcmp(symbol->errtxt, data[i].expected);
assert_zero(ret, "i:%d (%d) strcmp(%s, %s) %d != 0\n", i, data[i].symbology, symbol->errtxt, data[i].expected, ret);
assert_zero(ret, "i:%d (%d) strcmp(%s, %s) %d != 0\n",
i, data[i].symbology, symbol->errtxt, data[i].expected, ret);
ZBarcode_Delete(symbol);
}
@ -409,8 +423,10 @@ static void test_input_data(const testCtx *const p_ctx) {
data_buf[ZINT_MAX_DATA_LEN + 1] = 'n';
ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, ZINT_MAX_DATA_LEN + 2);
assert_equal(ret, expected_ret, "ZBarcode_Encode(%d) ret %d != %d (%s)\n", symbol->symbology, ret, expected_ret, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, expected_errtxt[0]), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, expected_errtxt[0]);
assert_equal(ret, expected_ret, "ZBarcode_Encode(%d) ret %d != %d (%s)\n",
symbol->symbology, ret, expected_ret, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, expected_errtxt[0]), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, expected_errtxt[0]);
/* Passes de-escape loop, caught by `code128()` */
symbol->errtxt[0] = '\0';
@ -418,8 +434,10 @@ static void test_input_data(const testCtx *const p_ctx) {
data_buf[ZINT_MAX_DATA_LEN - 1] = 'n';
ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, ZINT_MAX_DATA_LEN);
assert_equal(ret, expected_ret, "ZBarcode_Encode(%d) ret %d != %d (%s)\n", symbol->symbology, ret, expected_ret, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, expected_errtxt[1]), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, expected_errtxt[1]);
assert_equal(ret, expected_ret, "ZBarcode_Encode(%d) ret %d != %d (%s)\n",
symbol->symbology, ret, expected_ret, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, expected_errtxt[1]), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, expected_errtxt[1]);
ZBarcode_Delete(symbol);
}
@ -585,12 +603,17 @@ static void test_input_mode(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, BARCODE_CODE49 /*Supports GS1*/, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, BARCODE_CODE49 /*Supports GS1*/, data[i].input_mode,
-1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->input_mode, data[i].expected_input_mode, "i:%d symbol->input_mode %d != %d\n", i, symbol->input_mode, data[i].expected_input_mode);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d ZBarcode_Encode strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->input_mode, data[i].expected_input_mode, "i:%d symbol->input_mode %d != %d\n",
i, symbol->input_mode, data[i].expected_input_mode);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d ZBarcode_Encode strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected_errtxt);
ZBarcode_Delete(symbol);
}
@ -706,7 +729,7 @@ static void test_escape_char_process(const testCtx *const p_ctx) {
char escaped[1024];
char escaped_composite[1024];
struct zint_symbol previous_symbol;
struct zint_symbol *previous_symbol = NULL;
const char *input_filename = "test_escape.txt";
const char *text;
@ -729,28 +752,34 @@ static void test_escape_char_process(const testCtx *const p_ctx) {
debug |= ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode | ESCAPE_MODE, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, text, -1, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode | ESCAPE_MODE, data[i].eci,
-1 /*option_1*/, -1, -1, -1 /*output_options*/,
text, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(text), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, \"%s\", \"%s\", %s, %d, \"%s\", %d, \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci,
testUtilEscape(data[i].data, length, escaped, ARRAY_SIZE(escaped)),
testUtilEscape(data[i].composite, (int) strlen(data[i].composite), escaped_composite, ARRAY_SIZE(escaped_composite)),
testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].compare_previous, data[i].comment);
testUtilEscape(data[i].composite, (int) strlen(data[i].composite), escaped_composite,
ARRAY_SIZE(escaped_composite)),
testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].compare_previous,
data[i].comment);
} else {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected);
if (ret < ZINT_ERROR) {
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
if (p_ctx->index == -1 && data[i].compare_previous) {
ret = testUtilSymbolCmp(symbol, &previous_symbol);
ret = testUtilSymbolCmp(symbol, previous_symbol);
assert_zero(ret, "i:%d testUtilSymbolCmp ret %d != 0\n", i, ret);
}
}
memcpy(&previous_symbol, symbol, sizeof(previous_symbol));
if (ret < ZINT_ERROR && !data[i].composite[0]) {
/* Test from input file */
@ -759,7 +788,8 @@ static void test_escape_char_process(const testCtx *const p_ctx) {
fp = testUtilOpen(input_filename, "wb");
assert_nonnull(fp, "i:%d testUtilOpen(%s) failed\n", i, input_filename);
assert_notequal(fputs(data[i].data, fp), EOF, "i%d fputs(%s) failed == EOF (%d)\n", i, data[i].data, ferror(fp));
assert_notequal(fputs(data[i].data, fp), EOF, "i%d fputs(%s) failed == EOF (%d)\n",
i, data[i].data, ferror(fp));
assert_zero(fclose(fp), "i%d fclose() failed\n", i);
symbol2 = ZBarcode_Create();
@ -767,23 +797,30 @@ static void test_escape_char_process(const testCtx *const p_ctx) {
symbol2->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
(void) testUtilSetSymbol(symbol2, data[i].symbology, data[i].input_mode | ESCAPE_MODE, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
(void) testUtilSetSymbol(symbol2, data[i].symbology, data[i].input_mode | ESCAPE_MODE, data[i].eci,
-1 /*option_1*/, -1, -1, -1 /*output_options*/,
data[i].data, -1, debug);
ret = ZBarcode_Encode_File(symbol2, input_filename);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_File ret %d != %d (%s)\n", i, ret, data[i].ret, symbol2->errtxt);
assert_zero(strcmp(symbol2->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol2->errtxt, data[i].expected);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_File ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol2->errtxt);
assert_zero(strcmp(symbol2->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
i, symbol2->errtxt, data[i].expected);
ret = testUtilSymbolCmp(symbol2, symbol);
assert_zero(ret, "i:%d testUtilSymbolCmp symbol2 ret %d != 0\n", i, ret);
assert_zero(testUtilRemove(input_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input_filename, errno, strerror(errno));
assert_zero(testUtilRemove(input_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n",
i, input_filename, errno, strerror(errno));
ZBarcode_Delete(symbol2);
}
}
ZBarcode_Delete(symbol);
ZBarcode_Delete(previous_symbol);
previous_symbol = symbol;
}
ZBarcode_Delete(previous_symbol);
testFinish();
}
@ -829,18 +866,24 @@ static void test_escape_char_process_test(const testCtx *const p_ctx) {
escaped_len = length;
ret = escape_char_process_test(symbol, (unsigned char *) data[i].data, &escaped_len, NULL);
assert_equal(ret, data[i].ret, "i:%d escape_char_process_test(NULL) ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(escaped_len, data[i].expected_len, "i:%d NULL escaped_len %d != %d\n", i, escaped_len, data[i].expected_len);
assert_equal(ret, data[i].ret, "i:%d escape_char_process_test(NULL) ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
assert_equal(escaped_len, data[i].expected_len, "i:%d NULL escaped_len %d != %d\n",
i, escaped_len, data[i].expected_len);
memset(escaped, 0xDD, sizeof(escaped));
escaped_len = length;
ret = escape_char_process_test(symbol, (unsigned char *) data[i].data, &escaped_len, (unsigned char *) escaped);
assert_equal(ret, data[i].ret, "i:%d escape_char_process_test(escaped) ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(escaped_len, data[i].expected_len, "i:%d escaped escaped_len %d != %d\n", i, escaped_len, data[i].expected_len);
ret = escape_char_process_test(symbol, (unsigned char *) data[i].data, &escaped_len,
(unsigned char *) escaped);
assert_equal(ret, data[i].ret, "i:%d escape_char_process_test(escaped) ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
assert_equal(escaped_len, data[i].expected_len, "i:%d escaped escaped_len %d != %d\n",
i, escaped_len, data[i].expected_len);
assert_zero(memcmp(escaped, data[i].expected, escaped_len), "i:%d memcmp() != 0\n", i);
assert_zero(escaped[escaped_len], "i:%d escaped[%d] not NUL-terminated (0x%X)\n", i, escaped_len, escaped[escaped_len]);
assert_zero(escaped[escaped_len], "i:%d escaped[%d] not NUL-terminated (0x%X)\n",
i, escaped_len, escaped[escaped_len]);
}
testFinish();
@ -856,13 +899,13 @@ static void test_cap(const testCtx *const p_ctx) {
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
static const struct item data[] = {
/* 0*/ { BARCODE_CODE128, ZINT_CAP_HRT, ZINT_CAP_HRT },
/* 1*/ { BARCODE_CODE128, ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_GS1, ZINT_CAP_HRT | ZINT_CAP_STACKABLE },
/* 2*/ { BARCODE_PDF417, ZINT_CAP_HRT | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE, ZINT_CAP_ECI | ZINT_CAP_READER_INIT },
/* 1*/ { BARCODE_CODE128, ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_GS1 | ZINT_CAP_BINDABLE, ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_BINDABLE },
/* 2*/ { BARCODE_PDF417, ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_BINDABLE, ZINT_CAP_ECI | ZINT_CAP_READER_INIT },
/* 3*/ { BARCODE_QRCODE, ZINT_CAP_HRT | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP | ZINT_CAP_COMPLIANT_HEIGHT, ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP },
/* 4*/ { BARCODE_EANX_CC, ZINT_CAP_HRT | ZINT_CAP_COMPOSITE | ZINT_CAP_EXTENDABLE | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_QUIET_ZONES | ZINT_CAP_COMPLIANT_HEIGHT, ZINT_CAP_HRT | ZINT_CAP_COMPOSITE | ZINT_CAP_EXTENDABLE | ZINT_CAP_GS1 | ZINT_CAP_QUIET_ZONES | ZINT_CAP_COMPLIANT_HEIGHT },
/* 5*/ { BARCODE_HANXIN, ZINT_CAP_DOTTY | ZINT_CAP_QUIET_ZONES | ZINT_CAP_FIXED_RATIO | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK, ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK },
/* 6*/ { BARCODE_CODE11, ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_FIXED_RATIO | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_COMPLIANT_HEIGHT, 0 },
/* 7*/ { BARCODE_POSTNET, ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_EXTENDABLE | ZINT_CAP_COMPOSITE | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP, 0 },
/* 7*/ { BARCODE_POSTNET, ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_EXTENDABLE | ZINT_CAP_COMPOSITE | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP | ZINT_CAP_BINDABLE, 0 },
/* 8*/ { 0, 0, 0 },
};
const int data_size = ARRAY_SIZE(data);
@ -876,7 +919,8 @@ static void test_cap(const testCtx *const p_ctx) {
if (testContinue(p_ctx, i)) continue;
uret = ZBarcode_Cap(data[i].symbology, data[i].cap_flag);
assert_equal(uret, data[i].expected, "i:%d ZBarcode_Cap(%s, 0x%X) 0x%X != 0x%X\n", i, testUtilBarcodeName(data[i].symbology), data[i].cap_flag, uret, data[i].expected);
assert_equal(uret, data[i].expected, "i:%d ZBarcode_Cap(%s, 0x%X) 0x%X != 0x%X\n",
i, testUtilBarcodeName(data[i].symbology), data[i].cap_flag, uret, data[i].expected);
}
testFinish();
@ -966,11 +1010,14 @@ static void test_cap_compliant_height(const testCtx *const p_ctx) {
case BARCODE_BC412:
case BARCODE_DXFILMEDGE:
/* Make sure ZINT_CAP_COMPLIANT_HEIGHT set for those that have it */
assert_equal(uret, ZINT_CAP_COMPLIANT_HEIGHT, "symbol_id %d (%s) uret 0x%X != ZINT_CAP_COMPLIANT_HEIGHT\n", symbol_id, testUtilBarcodeName(symbol_id), uret);
assert_equal(uret, ZINT_CAP_COMPLIANT_HEIGHT,
"symbol_id %d (%s) uret 0x%X != ZINT_CAP_COMPLIANT_HEIGHT\n",
symbol_id, testUtilBarcodeName(symbol_id), uret);
break;
default:
/* And not set for those that don't */
assert_zero(uret, "symbol_id %d (%s) uret 0x%X non-zero\n", symbol_id, testUtilBarcodeName(symbol_id), uret);
assert_zero(uret, "symbol_id %d (%s) uret 0x%X non-zero\n",
symbol_id, testUtilBarcodeName(symbol_id), uret);
break;
}
}
@ -978,6 +1025,290 @@ static void test_cap_compliant_height(const testCtx *const p_ctx) {
testFinish();
}
struct min_item {
int symbology;
const char *data;
};
static const struct min_item min_data[] = {
/* 0*/ { BARCODE_CODE11, "1" },
/* 1*/ { BARCODE_C25STANDARD, "1" },
/* 2*/ { BARCODE_C25INTER, "1" },
/* 3*/ { BARCODE_C25IATA, "1" },
/* 4*/ { BARCODE_C25LOGIC, "1" },
/* 5*/ { BARCODE_C25IND, "1" },
/* 6*/ { BARCODE_CODE39, "1" },
/* 7*/ { BARCODE_EXCODE39, "1" },
/* 8*/ { BARCODE_EANX, "1" },
/* 9*/ { BARCODE_EANX_CHK, "1" },
/* 10*/ { BARCODE_GS1_128, "[01]12345678901231" },
/* 11*/ { BARCODE_CODABAR, "A0B" },
/* 12*/ { BARCODE_CODE128, "1" },
/* 13*/ { BARCODE_DPLEIT, "1" },
/* 14*/ { BARCODE_DPIDENT, "1" },
/* 15*/ { BARCODE_CODE16K, "1" },
/* 16*/ { BARCODE_CODE49, "1" },
/* 17*/ { BARCODE_CODE93, "1" },
/* 18*/ { BARCODE_FLAT, "1" },
/* 19*/ { BARCODE_DBAR_OMN, "1" },
/* 20*/ { BARCODE_DBAR_LTD, "1" },
/* 21*/ { BARCODE_DBAR_EXP, "[01]12345678901231" },
/* 22*/ { BARCODE_TELEPEN, "1" },
/* 23*/ { BARCODE_UPCA, "1" },
/* 24*/ { BARCODE_UPCE, "1" },
/* 25*/ { BARCODE_POSTNET, "12345678901" },
/* 26*/ { BARCODE_MSI_PLESSEY, "1" },
/* 27*/ { BARCODE_FIM, "A" },
/* 28*/ { BARCODE_LOGMARS, "1" },
/* 29*/ { BARCODE_PHARMA, "3" },
/* 30*/ { BARCODE_PZN, "1" },
/* 31*/ { BARCODE_PHARMA_TWO, "4" },
/* 32*/ { BARCODE_CEPNET, "12345678" },
/* 33*/ { BARCODE_PDF417, "1" },
/* 34*/ { BARCODE_PDF417COMP, "1" },
/* 35*/ { BARCODE_MAXICODE, "1" },
/* 36*/ { BARCODE_QRCODE, "1" },
/* 37*/ { BARCODE_CODE128AB, "1" },
/* 38*/ { BARCODE_AUSPOST, "12345678901234567890123" },
/* 39*/ { BARCODE_AUSREPLY, "12345678" },
/* 40*/ { BARCODE_AUSROUTE, "12345678" },
/* 41*/ { BARCODE_AUSREDIRECT, "12345678" },
/* 42*/ { BARCODE_ISBNX, "123456789" },
/* 43*/ { BARCODE_RM4SCC, "1" },
/* 44*/ { BARCODE_DATAMATRIX, "1" },
/* 45*/ { BARCODE_EAN14, "1" },
/* 46*/ { BARCODE_VIN, "12345678701234567" },
/* 47*/ { BARCODE_CODABLOCKF, "1" },
/* 48*/ { BARCODE_NVE18, "1" },
/* 49*/ { BARCODE_JAPANPOST, "1" },
/* 50*/ { BARCODE_KOREAPOST, "1" },
/* 51*/ { BARCODE_DBAR_STK, "1" },
/* 52*/ { BARCODE_DBAR_OMNSTK, "1" },
/* 53*/ { BARCODE_DBAR_EXPSTK, "[01]12345678901231" },
/* 54*/ { BARCODE_PLANET, "12345678901" },
/* 55*/ { BARCODE_MICROPDF417, "1" },
/* 56*/ { BARCODE_USPS_IMAIL, "12345678901234567890" },
/* 57*/ { BARCODE_PLESSEY, "1" },
/* 58*/ { BARCODE_TELEPEN_NUM, "1" },
/* 59*/ { BARCODE_ITF14, "1" },
/* 60*/ { BARCODE_KIX, "1" },
/* 61*/ { BARCODE_AZTEC, "1" },
/* 62*/ { BARCODE_DAFT, "D" },
/* 63*/ { BARCODE_DPD, "0123456789012345678901234567" },
/* 64*/ { BARCODE_MICROQR, "1" },
/* 65*/ { BARCODE_HIBC_128, "1" },
/* 66*/ { BARCODE_HIBC_39, "1" },
/* 67*/ { BARCODE_HIBC_DM, "1" },
/* 68*/ { BARCODE_HIBC_QR, "1" },
/* 69*/ { BARCODE_HIBC_PDF, "1" },
/* 70*/ { BARCODE_HIBC_MICPDF, "1" },
/* 71*/ { BARCODE_HIBC_BLOCKF, "1" },
/* 72*/ { BARCODE_HIBC_AZTEC, "1" },
/* 73*/ { BARCODE_DOTCODE, "1" },
/* 74*/ { BARCODE_HANXIN, "1" },
/* 75*/ { BARCODE_MAILMARK_2D, "012100123412345678AB19XY1A 0" },
/* 76*/ { BARCODE_UPU_S10, "EE876543216CA" },
/* 77*/ { BARCODE_MAILMARK_4S, "01000000000000000AA00AA0A" },
/* 78*/ { BARCODE_AZRUNE, "1" },
/* 79*/ { BARCODE_CODE32, "1" },
/* 80*/ { BARCODE_EANX_CC, "1" },
/* 81*/ { BARCODE_GS1_128_CC, "[01]12345678901231" },
/* 82*/ { BARCODE_DBAR_OMN_CC, "1" },
/* 83*/ { BARCODE_DBAR_LTD_CC, "1" },
/* 84*/ { BARCODE_DBAR_EXP_CC, "[01]12345678901231" },
/* 85*/ { BARCODE_UPCA_CC, "1" },
/* 86*/ { BARCODE_UPCE_CC, "1" },
/* 87*/ { BARCODE_DBAR_STK_CC, "1" },
/* 88*/ { BARCODE_DBAR_OMNSTK_CC, "1" },
/* 89*/ { BARCODE_DBAR_EXPSTK_CC, "[01]12345678901231" },
/* 90*/ { BARCODE_CHANNEL, "01" },
/* 91*/ { BARCODE_CODEONE, "1" },
/* 92*/ { BARCODE_GRIDMATRIX, "1" },
/* 93*/ { BARCODE_UPNQR, "1" },
/* 94*/ { BARCODE_ULTRA, "1" },
/* 95*/ { BARCODE_RMQR, "1" },
/* 96*/ { BARCODE_BC412, "1234567" },
};
static void test_cap_stackable(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
const int data_size = ARRAY_SIZE(min_data);
const struct min_item *data = min_data;
int i, length, ret;
struct zint_symbol *symbol = NULL;
const char *text;
int prestacked_rows;
int stacked_rows;
testStartSymbol(p_ctx->func_name, &symbol);
for (i = 0; i < data_size; i++) {
if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
if (is_composite(data[i].symbology)) {
text = "[20]01";
strcpy(symbol->primary, data[i].data);
} else {
text = data[i].data;
}
length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, -1 /*output_options*/,
text, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(text), length);
assert_zero(ret, "i:%d ZBarcode_Encode prestacked ret %d != 0 %s\n", i, ret, symbol->errtxt);
prestacked_rows = symbol->rows;
assert_nonzero(prestacked_rows, "i:%d prestacked_rows 0\n", i);
symbol->eci = 0;
symbol->option_1 = -1;
symbol->option_2 = symbol->option_3 = 0;
ret = ZBarcode_Encode(symbol, TCU(text), length);
assert_zero(ret, "i:%d ZBarcode_Encode stacked ret %d != 0 %s\n", i, ret, symbol->errtxt);
stacked_rows = symbol->rows;
assert_nonzero(stacked_rows, "i:%d stacked_rows 0\n", i);
assert_nonzero(stacked_rows >= prestacked_rows, "i:%d stacked_rows %d < prestacked_rows %d\n",
i, stacked_rows, prestacked_rows);
if (ZBarcode_Cap(symbol->symbology, ZINT_CAP_STACKABLE) & ZINT_CAP_STACKABLE) {
assert_nonzero(stacked_rows > prestacked_rows, "i:%d stacked_rows %d <= prestacked_rows %d\n",
i, stacked_rows, prestacked_rows);
} else {
assert_equal(stacked_rows, prestacked_rows, "i:%d stacked_rows %d != prestacked_rows %d\n",
i, stacked_rows, prestacked_rows);
}
ZBarcode_Delete(symbol);
}
testFinish();
}
static void test_bindable(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
const int data_size = ARRAY_SIZE(min_data);
const struct min_item *data = min_data;
int i, length, ret;
struct zint_symbol *symbol = NULL;
int stackable;
int diff, nodiff;
int option_3;
char prebind[32768];
char bind[32768];
const char *text;
testStartSymbol(p_ctx->func_name, &symbol);
for (i = 0; i < data_size; i++) {
if (testContinue(p_ctx, i)) continue;
/* This test can't differentiate these as always have bindings */
nodiff = data[i].symbology == BARCODE_CODABLOCKF || data[i].symbology == BARCODE_CODE16K
|| data[i].symbology == BARCODE_CODE49 || data[i].symbology == BARCODE_HIBC_BLOCKF;
diff = ZBarcode_Cap(data[i].symbology, ZINT_CAP_STACKABLE | ZINT_CAP_BINDABLE);
option_3 = diff ? 3 : 0;
stackable = diff & ZINT_CAP_STACKABLE;
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
if (is_composite(data[i].symbology)) {
text = "[20]01";
strcpy(symbol->primary, data[i].data);
} else {
text = data[i].data;
}
strcpy(symbol->outfile, "mem.svg");
length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, option_3, BARCODE_MEMORY_FILE,
text, -1, debug);
if (stackable) {
ret = ZBarcode_Encode(symbol, TCU(text), length);
assert_zero(ret, "i:%d ZBarcode_Encode prebind ret %d != 0 %s\n", i, ret, symbol->errtxt);
symbol->option_1 = -1;
symbol->option_2 = 0;
symbol->option_3 = option_3;
}
ret = ZBarcode_Encode_and_Print(symbol, TCU(text), length, 0 /*rotate*/);
assert_zero(ret, "i:%d ZBarcode_Encode_and_Print prebind ret %d != 0 %s\n", i, ret, symbol->errtxt);
assert_nonzero(symbol->memfile_size, "i:%d prebind memfile_size zero\n", i);
assert_nonzero(symbol->memfile_size + 1 < ARRAY_SIZE(prebind),
"i:%d prebind memfile_size + 1 %d >= ARRAY_SIZE(prebind) %d\n",
i, symbol->memfile_size, ARRAY_SIZE(prebind));
memcpy(prebind, symbol->memfile, symbol->memfile_size);
prebind[symbol->memfile_size] = '\0';
ZBarcode_Reset(symbol);
if (is_composite(data[i].symbology)) {
text = "[20]01";
strcpy(symbol->primary, data[i].data);
} else {
text = data[i].data;
}
strcpy(symbol->outfile, "mem.svg");
length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, option_3, BARCODE_BIND | BARCODE_MEMORY_FILE,
text, -1, debug);
if (stackable) {
ret = ZBarcode_Encode(symbol, TCU(text), length);
assert_zero(ret, "i:%d ZBarcode_Encode bind ret %d != 0 %s\n", i, ret, symbol->errtxt);
symbol->option_1 = -1;
symbol->option_2 = 0;
symbol->option_3 = option_3;
}
ret = ZBarcode_Encode_and_Print(symbol, TCU(text), length, 0 /*rotate*/);
assert_zero(ret, "i:%d ZBarcode_Encode_and_Print bind ret %d != 0 %s\n", i, ret, symbol->errtxt);
assert_nonzero(symbol->memfile_size, "i:%d bind memfile_size zero\n", i);
assert_nonzero(symbol->memfile_size + 1 < ARRAY_SIZE(bind),
"i:%d bind memfile_size + 1 %d >= ARRAY_SIZE(bind) %d\n",
i, symbol->memfile_size, ARRAY_SIZE(bind));
memcpy(bind, symbol->memfile, symbol->memfile_size);
bind[symbol->memfile_size] = '\0';
if (diff && !nodiff) {
assert_nonzero(strlen(prebind) < strlen(bind),
"i:%d length prebind %d >= bind %d (prebind %s, bind %s)\n",
i, (int) strlen(prebind), (int) strlen(bind), prebind, bind);
assert_nonzero(strcmp(prebind, bind), "i:%d strcmp(%s, %s) == 0", i, prebind, bind);
} else {
assert_equal((int) strlen(prebind), (int) strlen(bind),
"i:%d length prebind %d >= bind %d (prebind %s, bind %s)\n",
i, (int) strlen(prebind), (int) strlen(bind), prebind, bind);
}
ZBarcode_Delete(symbol);
}
testFinish();
}
static void test_encode_file_empty(const testCtx *const p_ctx) {
int ret;
struct zint_symbol *symbol = NULL;
@ -999,7 +1330,8 @@ static void test_encode_file_empty(const testCtx *const p_ctx) {
assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret);
ret = ZBarcode_Encode_File(symbol, filename);
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File empty ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt);
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File empty ret %d != ZINT_ERROR_INVALID_DATA (%s)\n",
ret, symbol->errtxt);
ret = testUtilRemove(filename);
assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
@ -1033,7 +1365,8 @@ static void test_encode_file_too_large(const testCtx *const p_ctx) {
assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret);
ret = ZBarcode_Encode_File(symbol, filename);
assert_equal(ret, ZINT_ERROR_TOO_LONG, "ZBarcode_Encode_File too large ret %d != ZINT_ERROR_TOO_LONG (%s)\n", ret, symbol->errtxt);
assert_equal(ret, ZINT_ERROR_TOO_LONG, "ZBarcode_Encode_File too large ret %d != ZINT_ERROR_TOO_LONG (%s)\n",
ret, symbol->errtxt);
ret = testUtilRemove(filename);
assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
@ -1071,14 +1404,16 @@ static void test_encode_file_unreadable(const testCtx *const p_ctx) {
/* Unreadable file */
fd = creat(filename, S_IWUSR);
assert_notequal(fd, -1, "Unreadable input file (%s) not created == -1 (%d: %s)\n", filename, errno, strerror(errno));
assert_notequal(fd, -1, "Unreadable input file (%s) not created == -1 (%d: %s)\n",
filename, errno, strerror(errno));
ret = write(fd, buf, 1);
assert_equal(ret, 1, "Unreadable write ret %d != 1\n", ret);
ret = close(fd);
assert_zero(ret, "Unreadable close(%s) != 0(%d: %s)\n", filename, errno, strerror(errno));
ret = ZBarcode_Encode_File(symbol, filename);
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File unreadable ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt);
assert_equal(ret, ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_File unreadable ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt);
ret = testUtilRemove(filename);
assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
@ -1089,7 +1424,8 @@ static void test_encode_file_unreadable(const testCtx *const p_ctx) {
#endif /* _WIN32 */
}
/* #181 Nico Gunkel OSS-Fuzz (buffer not freed on fread() error) Note: unable to reproduce fread() error using this method */
/* #181 Nico Gunkel OSS-Fuzz (buffer not freed on fread() error)
Note: unable to reproduce fread() error using this method */
static void test_encode_file_directory(const testCtx *const p_ctx) {
int ret;
struct zint_symbol *symbol = NULL;
@ -1252,7 +1588,8 @@ static void test_bad_args(const testCtx *const p_ctx) {
assert_nonzero(ret >= 20901, "ZBarcode_Version() %d <= 20901\n", ret);
assert_zero(ZBarcode_ValidID(0), "ZBarcode_ValidID(0) non-zero\n");
assert_zero(ZBarcode_ValidID(10), "ZBarcode_ValidID(10) non-zero\n"); /* Note 10 remapped to BARCODE_EANX in ZBarcode_Encode() for tbarcode compat but not counted as valid */
/* Note 10 remapped to BARCODE_EANX in ZBarcode_Encode() for tbarcode compat but not counted as valid */
assert_zero(ZBarcode_ValidID(10), "ZBarcode_ValidID(10) non-zero\n");
uret = ZBarcode_Cap(0, ~0);
assert_zero(uret, "ZBarcode_Cap(0, ~0) uret 0x%X != 0\n", uret);
@ -1260,112 +1597,225 @@ static void test_bad_args(const testCtx *const p_ctx) {
assert_zero(uret, "ZBarcode_Cap(10, ~0) uret 0x%X != 0\n", uret);
/* NULL symbol */
assert_equal(ZBarcode_Encode(NULL, TCU(data), 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode(NULL, data, 1) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_Segs(NULL, &seg, 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs(NULL, &seg, 1) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Print(NULL, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Print(NULL, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Buffer(NULL, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Buffer(NULL, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Buffer_Vector(NULL, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Buffer_Vector(NULL, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_and_Print(NULL, TCU(data), 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Print(NULL, data, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_Segs_and_Print(NULL, &seg, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Seg_and_Print(NULL, &seg, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_and_Buffer(NULL, TCU(data), 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Buffer(NULL, data, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_Segs_and_Buffer(NULL, &seg, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs_and_Buffer(NULL, &seg, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_and_Buffer_Vector(NULL, TCU(data), 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Buffer_Vector(NULL, data, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_Segs_and_Buffer_Vector(NULL, &seg, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs_and_Buffer_Vector(NULL, &seg, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_File(NULL, filename), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File(NULL, filename) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_File_and_Print(NULL, filename, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Print(NULL, filename, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_File_and_Buffer(NULL, filename, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Buffer(NULL, filename, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode(NULL, TCU(data), 1), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode(NULL, data, 1) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_Segs(NULL, &seg, 1), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Segs(NULL, &seg, 1) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Print(NULL, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Print(NULL, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Buffer(NULL, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Buffer(NULL, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Buffer_Vector(NULL, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Buffer_Vector(NULL, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_and_Print(NULL, TCU(data), 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_and_Print(NULL, data, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_Segs_and_Print(NULL, &seg, 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Seg_and_Print(NULL, &seg, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_and_Buffer(NULL, TCU(data), 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_and_Buffer(NULL, data, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_Segs_and_Buffer(NULL, &seg, 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Segs_and_Buffer(NULL, &seg, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_and_Buffer_Vector(NULL, TCU(data), 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_and_Buffer_Vector(NULL, data, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_Segs_and_Buffer_Vector(NULL, &seg, 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Segs_and_Buffer_Vector(NULL, &seg, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_File(NULL, filename), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_File(NULL, filename) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_File_and_Print(NULL, filename, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_File_and_Print(NULL, filename, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_equal(ZBarcode_Encode_File_and_Buffer(NULL, filename, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_File_and_Buffer(NULL, filename, 0) != ZINT_ERROR_INVALID_DATA\n");
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
/* NULL data/segs/filename */
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode(symbol, NULL, 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode(symbol, NULL, 1) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[0], symbol->errtxt), "ZBarcode_Encode(symbol, NULL, 1) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt);
assert_equal(ZBarcode_Encode(symbol, NULL, 1), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode(symbol, NULL, 1) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[0], symbol->errtxt),
"ZBarcode_Encode(symbol, NULL, 1) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_Segs(symbol, NULL, 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs(symbol, NULL, 1) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[1], symbol->errtxt), "ZBarcode_Encode_Segs(symbol, NULL, 1) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt);
assert_equal(ZBarcode_Encode_Segs(symbol, NULL, 1), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Segs(symbol, NULL, 1) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[1], symbol->errtxt),
"ZBarcode_Encode_Segs(symbol, NULL, 1) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_and_Print(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Print(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[0], symbol->errtxt), "ZBarcode_Encode_and_Print(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt);
assert_equal(ZBarcode_Encode_and_Print(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_and_Print(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[0], symbol->errtxt),
"ZBarcode_Encode_and_Print(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_and_Buffer(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Buffer(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[0], symbol->errtxt), "ZBarcode_Encode_and_Buffer(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt);
assert_equal(ZBarcode_Encode_and_Buffer(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_and_Buffer(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[0], symbol->errtxt),
"ZBarcode_Encode_and_Buffer(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_Segs_and_Buffer(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs_and_Buffer(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[1], symbol->errtxt), "ZBarcode_Encode_Segs_and_Buffer(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt);
assert_equal(ZBarcode_Encode_Segs_and_Buffer(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Segs_and_Buffer(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[1], symbol->errtxt),
"ZBarcode_Encode_Segs_and_Buffer(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n",
expected[0], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_and_Buffer_Vector(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Buffer_Vector(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[0], symbol->errtxt), "ZBarcode_Encode_and_Buffer_Vector(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt);
assert_equal(ZBarcode_Encode_and_Buffer_Vector(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_and_Buffer_Vector(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[0], symbol->errtxt),
"ZBarcode_Encode_and_Buffer_Vector(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n",
expected[0], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[1], symbol->errtxt), "ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt);
assert_equal(ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[1], symbol->errtxt),
"ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n",
expected[0], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_File(symbol, NULL), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File(symbol, NULL) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[2], symbol->errtxt), "ZBarcode_Encode_File(symbol, NULL) strcmp(%s, %s) != 0\n", expected[2], symbol->errtxt);
assert_equal(ZBarcode_Encode_File(symbol, NULL), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_File(symbol, NULL) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[2], symbol->errtxt),
"ZBarcode_Encode_File(symbol, NULL) strcmp(%s, %s) != 0\n", expected[2], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_File_and_Print(symbol, NULL, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Print(symbol, NULL, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[2], symbol->errtxt), "ZBarcode_Encode_File_and_Print(symbol, NULL, 0) strcmp(%s, %s) != 0\n", expected[2], symbol->errtxt);
assert_equal(ZBarcode_Encode_File_and_Print(symbol, NULL, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_File_and_Print(symbol, NULL, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[2], symbol->errtxt),
"ZBarcode_Encode_File_and_Print(symbol, NULL, 0) strcmp(%s, %s) != 0\n", expected[2], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_File_and_Buffer(symbol, NULL, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Buffer(symbol, NULL, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[2], symbol->errtxt), "ZBarcode_Encode_File_and_Buffer(symbol, NULL, 0) strcmp(%s, %s) != 0\n", expected[2], symbol->errtxt);
assert_equal(ZBarcode_Encode_File_and_Buffer(symbol, NULL, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_File_and_Buffer(symbol, NULL, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[2], symbol->errtxt),
"ZBarcode_Encode_File_and_Buffer(symbol, NULL, 0) strcmp(%s, %s) != 0\n",
expected[2], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_File_and_Buffer_Vector(symbol, NULL, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Buffer_Vector(symbol, NULL, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[2], symbol->errtxt), "ZBarcode_Encode_File_and_Buffer_Vector(symbol, NULL, 0) strcmp(%s, %s) != 0\n", expected[2], symbol->errtxt);
assert_equal(ZBarcode_Encode_File_and_Buffer_Vector(symbol, NULL, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_File_and_Buffer_Vector(symbol, NULL, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[2], symbol->errtxt),
"ZBarcode_Encode_File_and_Buffer_Vector(symbol, NULL, 0) strcmp(%s, %s) != 0\n",
expected[2], symbol->errtxt);
/* Empty data/segs/filename */
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode(symbol, TCU(empty), 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode(symbol, empty, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode(symbol, TCU(empty), 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt);
assert_equal(ZBarcode_Encode(symbol, TCU(empty), 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode(symbol, empty, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt),
"ZBarcode_Encode(symbol, TCU(empty), 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_Segs(symbol, &seg_empty, 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs(symbol, &seg_empty, 1) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode_Segs(symbol, &seg_empty, 1) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt);
assert_equal(ZBarcode_Encode_Segs(symbol, &seg_empty, 1), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Segs(symbol, &seg_empty, 1) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt),
"ZBarcode_Encode_Segs(symbol, &seg_empty, 1) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_and_Print(symbol, TCU(empty), 0, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Print(symbol, empty, 0, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode_and_Print(symbol, TCU(empty), 0, 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt);
assert_equal(ZBarcode_Encode_and_Print(symbol, TCU(empty), 0, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_and_Print(symbol, empty, 0, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt),
"ZBarcode_Encode_and_Print(symbol, TCU(empty), 0, 0) strcmp(%s, %s) != 0\n",
expected[3], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_and_Buffer(symbol, TCU(empty), 0, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Buffer(symbol, empty, 0, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode_and_Buffer(symbol, TCU(empty), 0, 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt);
assert_equal(ZBarcode_Encode_and_Buffer(symbol, TCU(empty), 0, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_and_Buffer(symbol, empty, 0, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt),
"ZBarcode_Encode_and_Buffer(symbol, TCU(empty), 0, 0) strcmp(%s, %s) != 0\n",
expected[3], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_Segs_and_Buffer(symbol, &seg_empty, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs_and_Buffer(symbol, &seg_empty, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode_Segs_and_Buffer(symbol, &seg_empty, 1, 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt);
assert_equal(ZBarcode_Encode_Segs_and_Buffer(symbol, &seg_empty, 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Segs_and_Buffer(symbol, &seg_empty, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt),
"ZBarcode_Encode_Segs_and_Buffer(symbol, &seg_empty, 1, 0) strcmp(%s, %s) != 0\n",
expected[3], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_and_Buffer_Vector(symbol, TCU(empty), 0, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Buffer_Vector(symbol, empty, 0, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode_and_Buffer_Vector(symbol, TCU(empty), 0, 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt);
assert_equal(ZBarcode_Encode_and_Buffer_Vector(symbol, TCU(empty), 0, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_and_Buffer_Vector(symbol, empty, 0, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt),
"ZBarcode_Encode_and_Buffer_Vector(symbol, TCU(empty), 0, 0) strcmp(%s, %s) != 0\n",
expected[3], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, &seg_empty, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, &seg_empty, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, &seg_empty, 1, 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt);
assert_equal(ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, &seg_empty, 1, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, &seg_empty, 1, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[3], symbol->errtxt),
"ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, &seg_empty, 1, 0) strcmp(%s, %s) != 0\n",
expected[3], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_File(symbol, empty), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File(symbol, empty) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strncmp(expected[4], symbol->errtxt, strlen(expected[4])), "ZBarcode_Encode_File(symbol, empty) strncmp(%s, %s, %d) != 0\n", expected[4], symbol->errtxt, (int) strlen(expected[4]));
assert_equal(ZBarcode_Encode_File(symbol, empty), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_File(symbol, empty) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strncmp(expected[4], symbol->errtxt, strlen(expected[4])),
"ZBarcode_Encode_File(symbol, empty) strncmp(%s, %s, %d) != 0\n",
expected[4], symbol->errtxt, (int) strlen(expected[4]));
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_File_and_Print(symbol, empty, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Print(symbol, empty, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strncmp(expected[4], symbol->errtxt, strlen(expected[4])), "ZBarcode_Encode_File(symbol, empty) strncmp(%s, %s, %d) != 0\n", expected[4], symbol->errtxt, (int) strlen(expected[4]));
assert_equal(ZBarcode_Encode_File_and_Print(symbol, empty, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_File_and_Print(symbol, empty, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strncmp(expected[4], symbol->errtxt, strlen(expected[4])),
"ZBarcode_Encode_File(symbol, empty) strncmp(%s, %s, %d) != 0\n",
expected[4], symbol->errtxt, (int) strlen(expected[4]));
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_File_and_Buffer(symbol, empty, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Buffer(symbol, empty, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strncmp(expected[4], symbol->errtxt, strlen(expected[4])), "ZBarcode_Encode_File(symbol, empty) strncmp(%s, %s, %d) != 0\n", expected[4], symbol->errtxt, (int) strlen(expected[4]));
assert_equal(ZBarcode_Encode_File_and_Buffer(symbol, empty, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_File_and_Buffer(symbol, empty, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strncmp(expected[4], symbol->errtxt, strlen(expected[4])),
"ZBarcode_Encode_File(symbol, empty) strncmp(%s, %s, %d) != 0\n",
expected[4], symbol->errtxt, (int) strlen(expected[4]));
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_File_and_Buffer_Vector(symbol, empty, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Buffer_Vector(symbol, empty, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strncmp(expected[4], symbol->errtxt, strlen(expected[4])), "ZBarcode_Encode_File(symbol, empty) strncmp(%s, %s, %d) != 0\n", expected[4], symbol->errtxt, (int) strlen(expected[4]));
assert_equal(ZBarcode_Encode_File_and_Buffer_Vector(symbol, empty, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_File_and_Buffer_Vector(symbol, empty, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strncmp(expected[4], symbol->errtxt, strlen(expected[4])),
"ZBarcode_Encode_File(symbol, empty) strncmp(%s, %s, %d) != 0\n",
expected[4], symbol->errtxt, (int) strlen(expected[4]));
/* Bad seg_count */
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_Segs(symbol, &seg_empty, ZINT_MAX_SEG_COUNT + 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs(symbol, &seg_empty, ZINT_MAX_SEG_COUNT + 1) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[5], symbol->errtxt), "ZBarcode_Encode_Segs(symbol, &seg_empty, ZINT_MAX_SEG_COUNT + 1) strcmp(%s, %s) != 0\n", expected[5], symbol->errtxt);
assert_equal(ZBarcode_Encode_Segs(symbol, &seg_empty, ZINT_MAX_SEG_COUNT + 1), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Segs(symbol, &seg_empty, ZINT_MAX_SEG_COUNT + 1) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[5], symbol->errtxt),
"ZBarcode_Encode_Segs(symbol, &seg_empty, ZINT_MAX_SEG_COUNT + 1) strcmp(%s, %s) != 0\n",
expected[5], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_Segs(symbol, &seg_empty, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs(symbol, &seg_empty, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[6], symbol->errtxt), "ZBarcode_Encode_Segs(symbol, &seg_empty, 0) strcmp(%s, %s) != 0\n", expected[6], symbol->errtxt);
assert_equal(ZBarcode_Encode_Segs(symbol, &seg_empty, 0), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Segs(symbol, &seg_empty, 0) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[6], symbol->errtxt),
"ZBarcode_Encode_Segs(symbol, &seg_empty, 0) strcmp(%s, %s) != 0\n", expected[6], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_Segs(symbol, &seg_empty, -1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs(symbol, &seg_empty, -1) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[6], symbol->errtxt), "ZBarcode_Encode_Segs(symbol, &seg_empty, -1) strcmp(%s, %s) != 0\n", expected[6], symbol->errtxt);
assert_equal(ZBarcode_Encode_Segs(symbol, &seg_empty, -1), ZINT_ERROR_INVALID_DATA,
"ZBarcode_Encode_Segs(symbol, &seg_empty, -1) != ZINT_ERROR_INVALID_DATA\n");
assert_zero(strcmp(expected[6], symbol->errtxt),
"ZBarcode_Encode_Segs(symbol, &seg_empty, -1) strcmp(%s, %s) != 0\n", expected[6], symbol->errtxt);
/* Data/seg too big */
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode(symbol, TCU(empty), ZINT_MAX_DATA_LEN + 1), ZINT_ERROR_TOO_LONG, "ZBarcode_Encode(symbol, empty, ZINT_MAX_DATA_LEN + 1) != ZINT_ERROR_TOO_LONG\n");
assert_zero(strcmp(expected[7], symbol->errtxt), "ZBarcode_Encode(symbol, TCU(empty), ZINT_MAX_DATA_LEN + 1) strcmp(%s, %s) != 0\n", expected[7], symbol->errtxt);
assert_equal(ZBarcode_Encode(symbol, TCU(empty), ZINT_MAX_DATA_LEN + 1), ZINT_ERROR_TOO_LONG,
"ZBarcode_Encode(symbol, empty, ZINT_MAX_DATA_LEN + 1) != ZINT_ERROR_TOO_LONG\n");
assert_zero(strcmp(expected[7], symbol->errtxt),
"ZBarcode_Encode(symbol, TCU(empty), ZINT_MAX_DATA_LEN + 1) strcmp(%s, %s) != 0\n",
expected[7], symbol->errtxt);
symbol->errtxt[0] = '\0';
assert_equal(ZBarcode_Encode_Segs(symbol, &seg_too_long, 1), ZINT_ERROR_TOO_LONG, "ZBarcode_Encode_Segs(symbol, &seg_too_long, 1) != ZINT_ERROR_TOO_LONG\n");
assert_zero(strcmp(expected[7], symbol->errtxt), "ZBarcode_Encode_Segs(symbol, &seg_too_long, 1) strcmp(%s, %s) != 0\n", expected[7], symbol->errtxt);
assert_equal(ZBarcode_Encode_Segs(symbol, &seg_too_long, 1), ZINT_ERROR_TOO_LONG,
"ZBarcode_Encode_Segs(symbol, &seg_too_long, 1) != ZINT_ERROR_TOO_LONG\n");
assert_zero(strcmp(expected[7], symbol->errtxt),
"ZBarcode_Encode_Segs(symbol, &seg_too_long, 1) strcmp(%s, %s) != 0\n", expected[7], symbol->errtxt);
ZBarcode_Delete(symbol);
testFinish();
}
static void test_stacking(const testCtx *const p_ctx) {
int ret;
struct zint_symbol *symbol = NULL;
const char *data = "1";
const char *expected_error = "Error 770: Too many stacked symbols";
int i;
(void)p_ctx;
testStartSymbol(p_ctx->func_name, &symbol);
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
for (i = 0; i < ARRAY_SIZE(symbol->row_height); i++) {
ret = ZBarcode_Encode(symbol, TCU(data), 0);
assert_zero(ret, "i:%d ZBarcode_Encode(%s) ret %d != 0 (%s)\n", i, data, ret, symbol->errtxt);
}
ret = ZBarcode_Encode(symbol, TCU(data), 0);
assert_equal(ret, ZINT_ERROR_TOO_LONG, "i:%d ZBarcode_Encode ret %d != ZINT_ERROR_TOO_LONG (%s)\n",
i, ret, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, expected_error), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, expected_error);
ZBarcode_Delete(symbol);
@ -2468,6 +2918,8 @@ int main(int argc, char *argv[]) {
{ "test_escape_char_process_test", test_escape_char_process_test },
{ "test_cap", test_cap },
{ "test_cap_compliant_height", test_cap_compliant_height },
{ "test_cap_stackable", test_cap_stackable },
{ "test_bindable", test_bindable },
{ "test_encode_file_empty", test_encode_file_empty },
{ "test_encode_file_too_large", test_encode_file_too_large },
{ "test_encode_file_unreadable", test_encode_file_unreadable },
@ -2475,6 +2927,7 @@ int main(int argc, char *argv[]) {
{ "test_encode_file", test_encode_file },
{ "test_encode_print_outfile_directory", test_encode_print_outfile_directory },
{ "test_bad_args", test_bad_args },
{ "test_stacking", test_stacking },
{ "test_valid_id", test_valid_id },
{ "test_barcode_name", test_barcode_name },
{ "test_error_tag", test_error_tag },

View file

@ -2126,108 +2126,6 @@ static void test_fuzz(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITER_MILLES 10
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int input_mode;
int option_1;
int option_2;
const char *data;
const char *primary;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_MAXICODE, UNICODE_MODE | ESCAPE_MODE, -1, -1,
"1Z34567890\\GUPSN\\G102562\\G034\\G\\G1/1\\G\\GY\\G2201 Second St\\GFt Myers\\GFL\\R\\E",
"339010000840001", 0, 33, 30, "Mode 2" },
/* 1*/ { BARCODE_MAXICODE, UNICODE_MODE, 4, -1, "MaxiCode (19 chars)", "", 0, 33, 30, "Mode 4 small" },
/* 2*/ { BARCODE_MAXICODE, DATA_MODE | ESCAPE_MODE, 4, -1, "ABCDabcdAabcABabcABCabcABCDaABCabABCabcABC\\d233a", "", 0, 33, 30, "Mode 4 medium" },
/* 3*/ { BARCODE_MAXICODE, DATA_MODE | ESCAPE_MODE, 4, -1,
"ABabcdeAabcdABCabcdABabc\\d192\\d192 \\d192\\d224\\d224\\d028\\d224\\d001\\d001\\d001\\d029\\d00112345678a123456789aABCDa\\d192\\d224\\d001\\d192\\d001\\d224\\d030\\d004",
"", 0, 33, 30, "Mode 4 latches" },
/* 4*/ { BARCODE_MAXICODE, UNICODE_MODE, 4, -1,
"THIS IS A 93 CHARACTER CODE SET A MESSAGE THAT FILLS A MODE 4, UNAPPENDED, MAXICODE SYMBOL...", "", 0, 33, 30, "Mode 4 txt max" },
/* 5*/ { BARCODE_MAXICODE, UNICODE_MODE, 4, -1,
"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
"", 0, 33, 30, "Mode 4 num max" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
clock_t start;
clock_t total_create = 0, total_encode = 0, total_buffer = 0;
clock_t diff_create, diff_encode, diff_buffer;
int comment_max = 0;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
printf("Iterations %d\n", TEST_PERF_ITERATIONS);
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
strcpy(symbol->primary, data[i].primary);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
#if 0
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
#endif
ZBarcode_Delete(symbol);
}
printf("%*s: encode % 8gms, buffer % 8gms, create % 8gms\n", comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
}
if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_create));
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -2238,7 +2136,6 @@ int main(int argc, char *argv[]) {
{ "test_rt", test_rt },
{ "test_rt_segs", test_rt_segs },
{ "test_fuzz", test_fuzz },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -209,7 +209,8 @@ INTERNAL int out_quiet_zones_test(const struct zint_symbol *symbol, const int hi
static void test_quiet_zones(const testCtx *const p_ctx) {
int i, ret;
struct zint_symbol symbol = {0};
struct zint_symbol s_symbol = {0};
struct zint_symbol *symbol = &s_symbol;
int hide_text = 0;
int comp_xoffset = 0;
float left, right, top, bottom;
@ -220,9 +221,9 @@ static void test_quiet_zones(const testCtx *const p_ctx) {
if (!ZBarcode_ValidID(i)) continue;
if (testContinue(p_ctx, i)) continue;
symbol.symbology = i;
symbol.output_options = BARCODE_QUIET_ZONES;
ret = out_quiet_zones_test(&symbol, hide_text, comp_xoffset, &left, &right, &top, &bottom);
symbol->symbology = i;
symbol->output_options = BARCODE_QUIET_ZONES;
ret = out_quiet_zones_test(symbol, hide_text, comp_xoffset, &left, &right, &top, &bottom);
if (i != BARCODE_FLAT && i != BARCODE_BC412) { /* Only two which aren't marked as done */
assert_nonzero(ret, "i:%d %s not done\n", i, testUtilBarcodeName(i));
}

View file

@ -78,34 +78,48 @@ static void test_large(const testCtx *const p_ctx) {
if (data[i].length != -1) {
testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length);
assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf));
assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n",
i, data[i].length, (int) strlen(data_buf));
} else {
strcpy(data_buf, data[i].pattern);
}
length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data_buf, data[i].length, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/,
data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/,
data_buf, data[i].length, debug);
ret = ZBarcode_Encode(symbol, TCU(data_buf), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (ret < ZINT_ERROR) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, symbol->errtxt);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, symbol->errtxt);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n",
i, symbol->width, data[i].expected_width);
}
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected_errtxt);
/* FAST_MODE */
length = testUtilSetSymbol(symbol, data[i].symbology, FAST_MODE, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data_buf, data[i].length, debug);
ZBarcode_Clear(symbol);
length = testUtilSetSymbol(symbol, data[i].symbology, FAST_MODE /*input_mode*/, -1 /*eci*/,
data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/,
data_buf, data[i].length, debug);
ret = ZBarcode_Encode(symbol, TCU(data_buf), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (ret < ZINT_ERROR) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, symbol->errtxt);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, symbol->errtxt);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n",
i, symbol->width, data[i].expected_width);
}
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected_errtxt);
ZBarcode_Delete(symbol);
}
@ -193,7 +207,7 @@ static void test_options(const testCtx *const p_ctx) {
int i, length, ret;
struct zint_symbol *symbol = NULL;
struct zint_symbol previous_symbol;
struct zint_symbol *previous_symbol = NULL;
testStartSymbol(p_ctx->func_name, &symbol);
@ -233,11 +247,10 @@ static void test_options(const testCtx *const p_ctx) {
i, symbol->option_3, data[i].expected_option_3);
if (p_ctx->index == -1 && data[i].compare_previous != -1) {
ret = testUtilSymbolCmp(symbol, &previous_symbol);
ret = testUtilSymbolCmp(symbol, previous_symbol);
assert_equal(!ret, !data[i].compare_previous, "i:%d testUtilSymbolCmp !ret %d != %d\n",
i, ret, data[i].compare_previous);
}
memcpy(&previous_symbol, symbol, sizeof(previous_symbol));
if (data[i].ret_vector != -1) {
ret = ZBarcode_Buffer_Vector(symbol, 0);
@ -245,8 +258,10 @@ static void test_options(const testCtx *const p_ctx) {
i, ret, data[i].ret_vector);
}
ZBarcode_Delete(symbol);
ZBarcode_Delete(previous_symbol);
previous_symbol = symbol;
}
ZBarcode_Delete(previous_symbol);
testFinish();
}
@ -291,10 +306,13 @@ static void test_reader_init(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
@ -303,10 +321,13 @@ static void test_reader_init(const testCtx *const p_ctx) {
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, symbol->errtxt, data[i].comment);
} else {
if (ret < ZINT_ERROR) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
}
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected);
if (ret < ZINT_ERROR) {
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
@ -465,55 +486,75 @@ static void test_input(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci,
data[i].option_1, data[i].option_2, -1 /*option_3*/, -1 /*output_options*/,
data[i].data, -1, debug);
if (data[i].structapp.count) {
symbol->structapp = data[i].structapp;
}
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %d, %d, { %d, %d, \"%s\" }, \"%s\", %s, %d, %d, %d, \"%s\", %d, \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2,
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci,
data[i].option_1, data[i].option_2,
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret),
symbol->eci, symbol->rows, symbol->width, symbol->errtxt, data[i].bwipp_cmp, data[i].comment);
} else {
if (ret < ZINT_ERROR) {
assert_equal(symbol->eci, data[i].expected_eci, "i:%d symbol->eci %d != %d (%s)\n", i, symbol->eci, data[i].expected_eci, data[i].data);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
assert_equal(symbol->eci, data[i].expected_eci, "i:%d symbol->eci %d != %d (%s)\n",
i, symbol->eci, data[i].expected_eci, data[i].data);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
}
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, data[i].expected);
if (ret < ZINT_ERROR) {
if (ret == 0 && p_ctx->index == -1) {
if (i && (data[i - 1].input_mode & FAST_MODE) && !(data[i].input_mode & FAST_MODE)
&& strcmp(data[i - 1].data, data[i].data) == 0) {
int num_cwds;
assert_equal(sscanf(symbol->errtxt, "(%d)", &num_cwds), 1, "i:%d num_cwds sscanf != 1 (%s)\n", i, symbol->errtxt);
assert_nonzero(last_fast_num_cwds >= num_cwds, "i:%d last_fast_num_cwds %d < num_cwds %d\n", i, last_fast_num_cwds, num_cwds);
if (num_cwds < last_fast_num_cwds && (debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) {
assert_equal(sscanf(symbol->errtxt, "(%d)", &num_cwds), 1, "i:%d num_cwds sscanf != 1 (%s)\n",
i, symbol->errtxt);
assert_nonzero(last_fast_num_cwds >= num_cwds, "i:%d last_fast_num_cwds %d < num_cwds %d\n",
i, last_fast_num_cwds, num_cwds);
if (num_cwds < last_fast_num_cwds && (debug & ZINT_DEBUG_TEST_PRINT)
&& !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) {
printf("i:%d diff %d\n", i, num_cwds - last_fast_num_cwds);
}
}
if (data[i].input_mode & FAST_MODE) {
assert_equal(sscanf(symbol->errtxt, "(%d)", &last_fast_num_cwds), 1, "i:%d last_fast sscanf != 1 (%s)\n", i, symbol->errtxt);
assert_equal(sscanf(symbol->errtxt, "(%d)", &last_fast_num_cwds), 1,
"i:%d last_fast sscanf != 1 (%s)\n", i, symbol->errtxt);
}
}
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
char modules_dump[32768];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].data, length,
NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf,
modules_dump);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
@ -3973,10 +4014,13 @@ static void test_encode(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci,
data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %s, %d, %d, %d, \"%s\", %s, %d, %d, %d, %d, \"%s\",\n",
@ -3992,37 +4036,51 @@ static void test_encode(const testCtx *const p_ctx) {
testUtilEscape(data[i].data, length, escaped, sizeof(escaped));
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, escaped);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, escaped);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, escaped);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, escaped);
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, escaped);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n",
i, ret, width, row, escaped);
if (ret == 0 && p_ctx->index == -1) {
if (i && (data[i - 1].input_mode & FAST_MODE) && !(data[i].input_mode & FAST_MODE)
&& strcmp(data[i - 1].data, data[i].data) == 0) {
int num_cwds;
assert_equal(sscanf(symbol->errtxt, "(%d)", &num_cwds), 1, "i:%d num_cwds sscanf != 1 (%s)\n", i, symbol->errtxt);
assert_nonzero(last_fast_num_cwds >= num_cwds, "i:%d last_fast_num_cwds %d < num_cwds %d\n", i, last_fast_num_cwds, num_cwds);
if (num_cwds < last_fast_num_cwds && (debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) {
assert_equal(sscanf(symbol->errtxt, "(%d)", &num_cwds), 1, "i:%d num_cwds sscanf != 1 (%s)\n",
i, symbol->errtxt);
assert_nonzero(last_fast_num_cwds >= num_cwds, "i:%d last_fast_num_cwds %d < num_cwds %d\n",
i, last_fast_num_cwds, num_cwds);
if (num_cwds < last_fast_num_cwds && (debug & ZINT_DEBUG_TEST_PRINT)
&& !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) {
printf("i:%d diff %d\n", i, num_cwds - last_fast_num_cwds);
}
}
if (data[i].input_mode & FAST_MODE) {
assert_equal(sscanf(symbol->errtxt, "(%d)", &last_fast_num_cwds), 1, "i:%d last_fast sscanf != 1 (%s)\n", i, symbol->errtxt);
assert_equal(sscanf(symbol->errtxt, "(%d)", &last_fast_num_cwds), 1,
"i:%d last_fast sscanf != 1 (%s)\n", i, symbol->errtxt);
}
}
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3, debug)) {
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3,
debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3,
data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf,
data[i].expected);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
@ -4719,11 +4777,13 @@ static void test_encode_segs(const testCtx *const p_ctx) {
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, NULL, 0, debug);
data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/,
NULL, 0, debug);
for (j = 0, seg_count = 0; j < 3 && data[i].segs[j].length; j++, seg_count++);
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
char escaped1[4096];
@ -4735,9 +4795,12 @@ static void test_encode_segs(const testCtx *const p_ctx) {
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode),
data[i].option_1, data[i].option_2, data[i].option_3,
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
testUtilEscape((const char *) data[i].segs[0].source, length, escaped, sizeof(escaped)), data[i].segs[0].length, data[i].segs[0].eci,
testUtilEscape((const char *) data[i].segs[1].source, length1, escaped1, sizeof(escaped1)), data[i].segs[1].length, data[i].segs[1].eci,
testUtilEscape((const char *) data[i].segs[2].source, length2, escaped2, sizeof(escaped2)), data[i].segs[2].length, data[i].segs[2].eci,
testUtilEscape((const char *) data[i].segs[0].source, length, escaped, sizeof(escaped)),
data[i].segs[0].length, data[i].segs[0].eci,
testUtilEscape((const char *) data[i].segs[1].source, length1, escaped1, sizeof(escaped1)),
data[i].segs[1].length, data[i].segs[1].eci,
testUtilEscape((const char *) data[i].segs[2].source, length2, escaped2, sizeof(escaped2)),
data[i].segs[2].length, data[i].segs[2].eci,
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment);
if (data[i].ret < ZINT_ERROR) {
testUtilModulesPrint(symbol, " ", "\n");
@ -4749,8 +4812,10 @@ static void test_encode_segs(const testCtx *const p_ctx) {
if (ret < ZINT_ERROR) {
int width, row;
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n",
i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n",
i, symbol->width, data[i].expected_width);
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d\n", i, ret, width, row);
@ -4758,30 +4823,42 @@ static void test_encode_segs(const testCtx *const p_ctx) {
if (data[i].ret == 0 && p_ctx->index == -1) {
if (i && (data[i - 1].input_mode & FAST_MODE) && !(data[i].input_mode & FAST_MODE)) {
int num_cwds;
assert_equal(sscanf(symbol->errtxt, "(%d)", &num_cwds), 1, "i:%d num_cwds sscanf != 1 (%s)\n", i, symbol->errtxt);
assert_nonzero(last_fast_num_cwds >= num_cwds, "i:%d last_fast_num_cwds %d < num_cwds %d\n", i, last_fast_num_cwds, num_cwds);
if (num_cwds < last_fast_num_cwds && (debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) {
assert_equal(sscanf(symbol->errtxt, "(%d)", &num_cwds), 1, "i:%d num_cwds sscanf != 1 (%s)\n",
i, symbol->errtxt);
assert_nonzero(last_fast_num_cwds >= num_cwds, "i:%d last_fast_num_cwds %d < num_cwds %d\n",
i, last_fast_num_cwds, num_cwds);
if (num_cwds < last_fast_num_cwds && (debug & ZINT_DEBUG_TEST_PRINT)
&& !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) {
printf("i:%d diff %d\n", i, num_cwds - last_fast_num_cwds);
}
}
if (data[i].input_mode & FAST_MODE) {
assert_equal(sscanf(symbol->errtxt, "(%d)", &last_fast_num_cwds), 1, "i:%d last_fast sscanf != 1 (%s)\n", i, symbol->errtxt);
assert_equal(sscanf(symbol->errtxt, "(%d)", &last_fast_num_cwds), 1,
"i:%d last_fast sscanf != 1 (%s)\n", i, symbol->errtxt);
}
}
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3, debug)) {
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3,
debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
ret = testUtilBwippSegs(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3, data[i].segs, seg_count, NULL, cmp_buf, sizeof(cmp_buf));
assert_zero(ret, "i:%d %s testUtilBwippSegs ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippSegs(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3,
data[i].segs, seg_count, NULL, cmp_buf, sizeof(cmp_buf));
assert_zero(ret, "i:%d %s testUtilBwippSegs ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf,
data[i].expected);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, (const char *) data[i].segs[0].source, data[i].segs[0].length, debug)) {
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, (const char *) data[i].segs[0].source,
data[i].segs[0].length, debug)) {
if ((data[i].input_mode & 0x07) == DATA_MODE) {
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s multiple segments in DATA_MODE not currently supported for ZXing-C++ testing\n",
@ -5826,25 +5903,34 @@ static void test_fuzz(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
data[i].option_1, data[i].option_2, -1, -1 /*output_options*/,
data[i].data, data[i].length, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (ret < ZINT_ERROR) {
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
char modules_dump[32768];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].data, length, NULL,
cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
@ -6018,17 +6104,21 @@ static void test_numbprocess(const testCtx *const p_ctx) {
length = (int) ustrlen(data[i].chaine);
mclength = 0;
pdf_numbprocess_test(chainemc, &mclength, data[i].chaine, 0, length);
assert_nonzero(mclength < ARRAY_SIZE(chainemc), "i:%d mclength %d >= ARRAY_SIZE(chainemc) %d\n", i, mclength, ARRAY_SIZE(chainemc));
assert_nonzero(mclength < ARRAY_SIZE(chainemc), "i:%d mclength %d >= ARRAY_SIZE(chainemc) %d\n",
i, mclength, ARRAY_SIZE(chainemc));
#if 0
for (j = 0; j < mclength; j++) { printf(" %d", chainemc[j]); } printf("\n");
#endif
assert_equal(mclength, data[i].expected_len, "i:%d mclength %d != expected_len %d\n", i, mclength, data[i].expected_len);
assert_equal(mclength, data[i].expected_len, "i:%d mclength %d != expected_len %d\n",
i, mclength, data[i].expected_len);
for (j = 0; j < mclength; j++) {
assert_equal(chainemc[j], data[i].expected[j], "i:%d chainemc[%d] %d != %d\n", i, j, chainemc[j], data[i].expected[j]);
assert_equal(chainemc[j], data[i].expected[j], "i:%d chainemc[%d] %d != %d\n",
i, j, chainemc[j], data[i].expected[j]);
}
if (length < 20) {
char buf1[64], buf2[64];
assert_zero(annex_d_decode_dump(chainemc, mclength, data[i].chaine, length, buf1, buf2), "i:%d annex_d_decode_dump() fail\n", i);
assert_zero(annex_d_decode_dump(chainemc, mclength, data[i].chaine, length, buf1, buf2),
"i:%d annex_d_decode_dump() fail\n", i);
assert_zero(strcmp(buf1, buf2), "i:%d, strcmp(%s, %s) != 0\n", i, buf1, buf2);
}
}
@ -6036,208 +6126,6 @@ static void test_numbprocess(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITER_MILLES 5
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int input_mode;
int option_1;
int option_2;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_PDF417, -1, -1, -1, "1234567890", 0, 7, 103, "10 numerics" },
/* 1*/ { BARCODE_PDF417, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz&,:#-.$/+%*=^ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM"
"NOPQRSTUVWXYZ;<>@[]_`~!||()?{}'123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJK"
"LMNOPQRSTUVWXYZ12345678912345678912345678912345678900001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFG"
"HIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567"
"890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcde"
"fghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
0, 43, 290, "960 chars, text/numeric" },
/* 2*/ { BARCODE_PDF417, DATA_MODE, -1, -1,
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240",
0, 51, 358, "960 chars, byte" },
/* 3*/ { BARCODE_PDF417, -1, -1, -1,
"BP2D+1.00+0005+FLE ESC BV+1.00+3.60*BX2D+1.00+0001+Casual shoes & apparel+90044030118100801265*D_2D+1.02+31351440315981+C910332+02032018+KXXXX CXXXX+UNIT 4 HXXX"
"XXXXX BUSINESS PARK++ST ALBANS+ST ALBANS++AL2 3TA+0001+000001+001+00000000+00++N+N+N+0000++++++N+++N*DS2D+1.01+0001+0001+90044030118100801265+++++07852389322+"
"+E*F_2D+1.00+0005*",
0, 26, 222, "338 chars, text/numeric/byte" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
clock_t start;
clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print;
int comment_max = 0;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
printf("Iterations %d\n", TEST_PERF_ITERATIONS);
printf("FAST_MODE\n");
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
int input_mode = data[i].input_mode == -1 ? FAST_MODE : (data[i].input_mode | FAST_MODE);
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter), TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
total_buf_inter += diff_buf_inter;
total_print += diff_print;
}
if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
}
printf("OPTIMIZED\n");
total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter), TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
total_buf_inter += diff_buf_inter;
total_print += diff_print;
}
if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -6251,7 +6139,6 @@ int main(int argc, char *argv[]) {
{ "test_rt_segs", test_rt_segs },
{ "test_fuzz", test_fuzz },
{ "test_numbprocess", test_numbprocess },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

718
backend/tests/test_perf.c Normal file
View file

@ -0,0 +1,718 @@
/* These are not real tests, just performance indicators */
/*
libzint - the open source barcode library
Copyright (C) 2025 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
#include <time.h>
#include "testcommon.h"
#define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC)
struct perf_item {
int symbology;
int input_mode;
int option_1;
int option_2;
int option_3;
const char *data;
const char *composite_primary;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static void test_perf(const testCtx *const p_ctx, const int default_iterations, const struct perf_item *data,
const int data_size) {
int debug = p_ctx->debug;
int i, length, ret;
struct zint_symbol *symbol = NULL;
clock_t start;
clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print;
int comment_max = 0;
const int iterations = p_ctx->arg ? p_ctx->arg : default_iterations; /* Use "-a N" to set iterations */
const char *text;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
testStartSymbol(p_ctx->func_name, &symbol);
for (i = 0; i < data_size; i++) {
if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
}
printf(" Iterations %d\n", iterations);
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
for (j = 0; j < iterations; j++) {
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
assert_nonnull(symbol, "Symbol not created\n");
if (strlen(data[i].composite_primary)) {
if (is_composite(data[i].symbology)) {
text = data[i].composite_primary;
assert_nonzero((int) strlen(data[i].data) < ARRAY_SIZE(symbol->primary),
"i:%d composite length %d >= %d\n",
i, (int) strlen(data[i].data), ARRAY_SIZE(symbol->primary));
strcpy(symbol->primary, data[i].data);
} else {
text = data[i].data;
assert_nonzero((int) strlen(data[i].composite_primary) < ARRAY_SIZE(symbol->primary),
"i:%d primary length %d >= %d\n",
i, (int) strlen(data[i].composite_primary), ARRAY_SIZE(symbol->primary));
strcpy(symbol->primary, data[i].composite_primary);
}
} else {
text = data[i].data;
}
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/,
text, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(text), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n",
i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
printf(" %*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n",
comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter),
TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
total_buf_inter += diff_buf_inter;
total_print += diff_print;
}
if (p_ctx->index == -1) {
printf(" %*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n",
comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter),
TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
}
testFinish();
}
static void test_2of5(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_C25INTER, -1, -1, -1, -1, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "", 0, 1, 819, "C25INTER 90" },
/* 1*/ { BARCODE_C25INTER, -1, -1, -1, -1, "1234567890", "", 0, 1, 99, "C25INTER 10" },
/* 2*/ { BARCODE_C25STANDARD, -1, -1, -1, -1, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", "", 0, 1, 817, "C25STANDARD 80" },
/* 3*/ { BARCODE_C25STANDARD, -1, -1, -1, -1, "1234567890", "", 0, 1, 117, "C25STANDARD 10" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_aztec(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_AZTEC, -1, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"", 0, 49, 49, "286 chars, 8-bit words, upper" },
/* 1*/ { BARCODE_AZTEC, -1, -1, -1, -1,
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
"", 0, 79, 79, "900 chars, 10-bit words, numeric" },
/* 2*/ { BARCODE_AZTEC, -1, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377",
"", 0, 91, 91, "980 chars, 10-bit words, mixed" },
/* 3*/ { BARCODE_AZTEC, -1, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377",
"", 0, 113, 113, "1540 chars, 12-bit words, mixed" },
/* 4*/ { BARCODE_AZRUNE, -1, -1, -1, -1,
"255",
"", 0, 11, 11, "3 chars, AZRUNE" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 1 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_code11(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_CODE11, -1, -1, -1, -1, "1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-", "", 0, 1, 966, "CODE11 121" },
/* 1*/ { BARCODE_CODE11, -1, -1, -1, -1, "1234567890-", "", 0, 1, 116, "CODE11 5" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_code128(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_CODE128, -1, -1, -1, -1, "123456ABCD123456ABCD123456ABCD123456ABCD123456ABCD123456ABCD", "", 0, 1, 618, "CODE128 60" },
/* 1*/ { BARCODE_CODE128, -1, -1, -1, -1, "123456ABCD", "", 0, 1, 123, "CODE128 10" },
/* 2*/ { BARCODE_GS1_128, -1, -1, -1, -1, "[01]09501101530003", "", 0, 1, 134, "GS1_128 (01)" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_composite(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_EANX_CC, -1, 1, -1, -1, "123456789012",
"[91]123456789012345678901234567890123456789012345678901234",
0, 11, 99, "58 chars CC-A" },
/* 1*/ { BARCODE_UPCA_CC, -1, 2, -1, -1, "12345678901",
"[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[94]12345678901234567890123456789012345678901234567890",
0, 48, 99, "336 chars CC-B" },
/* 2*/ { BARCODE_GS1_128_CC, -1, 3, -1, -1, "[01]12345678901231",
"[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
0, 32, 205, "564 chars CC-C" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 1 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_dmatrix(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_DATAMATRIX, FAST_MODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz&,:#-.$/+%*=^ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM"
"NOPQRSTUVWXYZ;<>@[]_`~!||()?{}'123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJK"
"LMNOPQRSTUVWXYZ12345678912345678912345678912345678900001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFG"
"HIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567"
"890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcde"
"fghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
"", 0, 96, 96, "960 chars, text/numeric" },
/* 1*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz&,:#-.$/+%*=^ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM"
"NOPQRSTUVWXYZ;<>@[]_`~!||()?{}'123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJK"
"LMNOPQRSTUVWXYZ12345678912345678912345678912345678900001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFG"
"HIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567"
"890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcde"
"fghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
"", 0, 96, 96, "960 chars, text/numeric" },
/* 2*/ { BARCODE_DATAMATRIX, DATA_MODE | FAST_MODE, -1, -1, -1,
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240",
"", 0, 120, 120, "960 chars, byte" },
/* 3*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, -1, -1,
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240",
"", 0, 120, 120, "960 chars, byte" },
/* 4*/ { BARCODE_DATAMATRIX, FAST_MODE, -1, -1, -1, "https://example.com/01/09506000134369", "", 0, 22, 22, "37 chars, text/numeric" },
/* 5*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, "https://example.com/01/09506000134369", "", 0, 22, 22, "37 chars, text/numeric" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_dotcode(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_DOTCODE, -1, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz&,:#-.$/+%*=^ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM"
"NOPQRSTUVWXYZ;<>@[]_`~!||()?{}'123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJK"
"LMNOPQRSTUVWXYZ12345678912345678912345678912345678900001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFG"
"HIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567"
"890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcde"
"fghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
"", 0, 124, 185, "960 chars, text/numeric" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 1 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_gridmtx(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_GRIDMATRIX, UNICODE_MODE, -1, -1, -1,
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738",
"", 0, 66, 66, "97 chars, mixed modes" },
/* 1*/ { BARCODE_GRIDMATRIX, UNICODE_MODE, -1, -1, -1,
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738"
"AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738 AAT2556 电池充电器+降压转换器 200mA至2A tel:86 019 82512738",
"", 0, 162, 162, "970 chars, mixed modes" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 1 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_hanxin(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_HANXIN, UNICODE_MODE, -1, -1, -1,
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。",
"", ZINT_WARN_NONCOMPLIANT, 43, 43, "98 chars, Region One and Text" },
/* 1*/ { BARCODE_HANXIN, UNICODE_MODE, -1, -1, -1,
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。",
"", ZINT_WARN_NONCOMPLIANT, 121, 121, "980 chars, Region One and Text" },
/* 2*/ { BARCODE_HANXIN, UNICODE_MODE, -1, -1, -1,
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。"
"汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。汉信码(Chinese-Sensible Code)是一种能够有效表示汉字、图像等信息的二维条码。",
"", ZINT_WARN_NONCOMPLIANT, 147, 147, "1470 chars, Region One and Text" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 1 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_maxicode(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_MAXICODE, UNICODE_MODE | ESCAPE_MODE, -1, -1, -1,
"1Z34567890\\GUPSN\\G102562\\G034\\G\\G1/1\\G\\GY\\G2201 Second St\\GFt Myers\\GFL\\R\\E",
"339010000840001", 0, 33, 30, "Mode 2" },
/* 1*/ { BARCODE_MAXICODE, UNICODE_MODE, 4, -1, -1, "MaxiCode (19 chars)", "", 0, 33, 30, "Mode 4 small" },
/* 2*/ { BARCODE_MAXICODE, DATA_MODE | ESCAPE_MODE, 4, -1, -1, "ABCDabcdAabcABabcABCabcABCDaABCabABCabcABC\\d233a", "", 0, 33, 30, "Mode 4 medium" },
/* 3*/ { BARCODE_MAXICODE, DATA_MODE | ESCAPE_MODE, 4, -1, -1,
"ABabcdeAabcdABCabcdABabc\\d192\\d192 \\d192\\d224\\d224\\d028\\d224\\d001\\d001\\d001\\d029\\d00112345678a123456789aABCDa\\d192\\d224\\d001\\d192\\d001\\d224\\d030\\d004",
"", 0, 33, 30, "Mode 4 latches" },
/* 4*/ { BARCODE_MAXICODE, UNICODE_MODE, 4, -1, -1,
"THIS IS A 93 CHARACTER CODE SET A MESSAGE THAT FILLS A MODE 4, UNAPPENDED, MAXICODE SYMBOL...", "", 0, 33, 30, "Mode 4 txt max" },
/* 5*/ { BARCODE_MAXICODE, UNICODE_MODE, 4, -1, -1,
"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
"", 0, 33, 30, "Mode 4 num max" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 10 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_pdf417(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_PDF417, -1, -1, -1, -1, "1234567890", "", 0, 7, 103, "10 numerics" },
/* 1*/ { BARCODE_PDF417, -1, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz&,:#-.$/+%*=^ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM"
"NOPQRSTUVWXYZ;<>@[]_`~!||()?{}'123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJK"
"LMNOPQRSTUVWXYZ12345678912345678912345678912345678900001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFG"
"HIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567"
"890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcde"
"fghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
"", 0, 43, 290, "960 chars, text/numeric" },
/* 2*/ { BARCODE_PDF417, DATA_MODE, -1, -1, -1,
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240",
"", 0, 51, 358, "960 chars, byte" },
/* 3*/ { BARCODE_PDF417, -1, -1, -1, -1,
"BP2D+1.00+0005+FLE ESC BV+1.00+3.60*BX2D+1.00+0001+Casual shoes & apparel+90044030118100801265*D_2D+1.02+31351440315981+C910332+02032018+KXXXX CXXXX+UNIT 4 HXXX"
"XXXXX BUSINESS PARK++ST ALBANS+ST ALBANS++AL2 3TA+0001+000001+001+00000000+00++N+N+N+0000++++++N+++N*DS2D+1.01+0001+0001+90044030118100801265+++++07852389322+"
"+E*F_2D+1.00+0005*",
"", 0, 26, 222, "338 chars, text/numeric/byte" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_plessey(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_PLESSEY, -1, -1, -1, -1, "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1", "", 0, 1, 1107, "PLESSEY 65" },
/* 1*/ { BARCODE_PLESSEY, -1, -1, -1, -1, "123456ABCD", "", 0, 1, 227, "PLESSEY 10" },
/* 2*/ { BARCODE_MSI_PLESSEY, -1, -1, -1, -1, "12345678901234567890123456789012345678901234567890123456789012345", "", 0, 1, 787, "MSI_PLESSEY 65" },
/* 3*/ { BARCODE_MSI_PLESSEY, -1, -1, -1, -1, "1234567890", "", 0, 1, 127, "MSI_PLESSEY 10" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_postal(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_POSTNET, -1, -1, -1, -1, "12345678901", "", 0, 2, 123, "POSTNET 11" },
/* 1*/ { BARCODE_PLANET, -1, -1, -1, -1, "1234567890123", "", 0, 2, 143, "PLANET 13" },
/* 2*/ { BARCODE_KOREAPOST, -1, -1, -1, -1, "123456", "", 0, 1, 167, "KOREAPOST 6" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 10 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_qr(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_QRCODE, UNICODE_MODE, -1, -1, -1, "12345678901234", "", 0, 21, 21, "14 chars, Numeric mode" },
/* 1*/ { BARCODE_QRCODE, UNICODE_MODE, -1, -1, -1, "ABC 123 ABC 123 ABCD", "", 0, 21, 21, "20 chars, Alphanumeric" },
/* 2*/ { BARCODE_QRCODE, UNICODE_MODE, -1, -1, -1, "ABCde fG H 123456 IJKlmn, 1234567890 opQ Rst uvwxyz. 1234", "", 0, 29, 29, "57 chars, Alphanumeric" },
/* 3*/ { BARCODE_QRCODE, UNICODE_MODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点",
"", ZINT_WARN_NONCOMPLIANT, 37, 37, "107 chars, Mixed modes" },
/* 4*/ { BARCODE_QRCODE, UNICODE_MODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点",
"", ZINT_WARN_NONCOMPLIANT, 53, 53, "214 chars, Mixed modes" },
/* 5*/ { BARCODE_QRCODE, UNICODE_MODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点",
"", ZINT_WARN_NONCOMPLIANT, 73, 73, "428 chars, Mixed modes" },
/* 6*/ { BARCODE_QRCODE, UNICODE_MODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点",
"", ZINT_WARN_NONCOMPLIANT, 105, 105, "963 chars, Mixed modes" },
/* 7*/ { BARCODE_QRCODE, UNICODE_MODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点",
"", ZINT_WARN_NONCOMPLIANT, 133, 133, "1498 chars, Mixed modes" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_qr_fast(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_QRCODE, UNICODE_MODE | FAST_MODE, -1, -1, -1, "12345678901234", "", 0, 21, 21, "14 chars, Numeric mode" },
/* 1*/ { BARCODE_QRCODE, UNICODE_MODE | FAST_MODE, -1, -1, -1, "ABC 123 ABC 123 ABCD", "", 0, 21, 21, "20 chars, Alphanumeric" },
/* 2*/ { BARCODE_QRCODE, UNICODE_MODE | FAST_MODE, -1, -1, -1, "ABCde fG H 123456 IJKlmn, 1234567890 opQ Rst uvwxyz. 1234", "", 0, 29, 29, "57 chars, Alphanumeric" },
/* 3*/ { BARCODE_QRCODE, UNICODE_MODE | FAST_MODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点",
"", ZINT_WARN_NONCOMPLIANT, 37, 37, "107 chars, Mixed modes" },
/* 4*/ { BARCODE_QRCODE, UNICODE_MODE | FAST_MODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点",
"", ZINT_WARN_NONCOMPLIANT, 53, 53, "214 chars, Mixed modes" },
/* 5*/ { BARCODE_QRCODE, UNICODE_MODE | FAST_MODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点",
"", ZINT_WARN_NONCOMPLIANT, 73, 73, "428 chars, Mixed modes" },
/* 6*/ { BARCODE_QRCODE, UNICODE_MODE | FAST_MODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点",
"", ZINT_WARN_NONCOMPLIANT, 105, 105, "963 chars, Mixed modes" },
/* 7*/ { BARCODE_QRCODE, UNICODE_MODE | FAST_MODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 12345678901234567890123456 点点点点点点点点点点点点点点点点点点点点点点点点点点",
"", ZINT_WARN_NONCOMPLIANT, 133, 133, "1498 chars, Mixed modes" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_microqr(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_MICROQR, UNICODE_MODE, 1, 1, -1, "12345", "", 0, 11, 11, "Max 5 numbers, M1" },
/* 1*/ { BARCODE_MICROQR, UNICODE_MODE, 1, 2, -1, "1234567890", "", 0, 13, 13, "Max 10 numbers, M2-L" },
/* 2*/ { BARCODE_MICROQR, UNICODE_MODE, 1, 3, -1, "123456789012345", "", 0, 15, 15, "Max 15 numbers, M3-L" },
/* 3*/ { BARCODE_MICROQR, UNICODE_MODE, 1, 4, -1, "12345678901234567890123456789012345", "", 0, 17, 17, "Max 35 numbers, M4-L" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
static void test_upcean(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_EANX, -1, -1, -1, -1, "123456789012+12345", "", 0, 1, 149, "EAN-13 add-on 5" },
/* 1*/ { BARCODE_EANX, -1, -1, -1, -1, "123456789012", "", 0, 1, 95, "EAN-13 no add-on" },
/* 2*/ { BARCODE_UPCA, -1, -1, -1, -1, "12345678901+12345", "", 0, 1, 151, "UPC-A add-on 5" },
/* 3*/ { BARCODE_UPCA, -1, -1, -1, -1, "12345678901", "", 0, 1, 95, "UPC-A no add-on" },
/* 4*/ { BARCODE_EANX, -1, -1, -1, -1, "1234567+12345", "", 0, 1, 121, "EAN-8 add-on 5" },
/* 5*/ { BARCODE_EANX, -1, -1, -1, -1, "1234567", "", 0, 1, 67, "EAN-8 no add-on" },
/* 6*/ { BARCODE_UPCE, -1, -1, -1, -1, "1234567+12", "", 0, 1, 78, "UPC-E add-on 2" },
/* 7*/ { BARCODE_UPCE, -1, -1, -1, -1, "1234567", "", 0, 1, 51, "UPC-E no add-on" },
/* 8*/ { BARCODE_EANX, -1, -1, -1, -1, "12345", "", 0, 1, 47, "EAN-5" },
/* 9*/ { BARCODE_EANX, -1, -1, -1, -1, "12", "", 0, 1, 20, "EAN-2" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 10 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
{ "test_2of5", test_2of5 },
{ "test_aztec", test_aztec },
{ "test_code11", test_code11 },
{ "test_code128", test_code128 },
{ "test_composite", test_composite },
{ "test_dmatrix", test_dmatrix },
{ "test_dotcode", test_dotcode },
{ "test_gridmtx", test_gridmtx },
{ "test_hanxin", test_hanxin },
{ "test_maxicode", test_maxicode },
{ "test_pdf417", test_pdf417 },
{ "test_plessey", test_plessey },
{ "test_postal", test_postal },
{ "test_qr", test_qr },
{ "test_qr_fast", test_qr_fast },
{ "test_microqr", test_microqr },
{ "test_upcean", test_upcean },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();
return 0;
}
/* vim: set ts=4 sw=4 et : */

View file

@ -398,108 +398,6 @@ static void test_encode(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITER_MILLES 5
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int option_2;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_PLESSEY, -1, "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1", 0, 1, 1107, "PLESSEY 65" },
/* 1*/ { BARCODE_PLESSEY, -1, "123456ABCD", 0, 1, 227, "PLESSEY 10" },
/* 2*/ { BARCODE_MSI_PLESSEY, -1, "12345678901234567890123456789012345678901234567890123456789012345", 0, 1, 787, "MSI_PLESSEY 65" },
/* 3*/ { BARCODE_MSI_PLESSEY, -1, "1234567890", 0, 1, 127, "MSI_PLESSEY 10" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
clock_t start;
clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print;
int comment_max = 0;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
printf("Iterations %d\n", TEST_PERF_ITERATIONS);
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, DATA_MODE, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter), TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
total_buf_inter += diff_buf_inter;
total_print += diff_print;
}
if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -507,7 +405,6 @@ int main(int argc, char *argv[]) {
{ "test_hrt", test_hrt },
{ "test_input", test_input },
{ "test_encode", test_encode },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -616,107 +616,6 @@ static void test_encode(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITER_MILLES 10
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int option_2;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
static const struct item data[] = {
/* 0*/ { BARCODE_POSTNET, -1, "12345678901", 0, 2, 123, "POSTNET 11" },
/* 1*/ { BARCODE_PLANET, -1, "1234567890123", 0, 2, 143, "PLANET 13" },
/* 2*/ { BARCODE_KOREAPOST, -1, "123456", 0, 1, 167, "KOREAPOST 6" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
clock_t start;
clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print;
int comment_max = 0;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
printf("Iterations %d\n", TEST_PERF_ITERATIONS);
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, DATA_MODE, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter), TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
total_buf_inter += diff_buf_inter;
total_print += diff_print;
}
if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -726,7 +625,6 @@ int main(int argc, char *argv[]) {
{ "test_hrt", test_hrt },
{ "test_input", test_input },
{ "test_encode", test_encode },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

File diff suppressed because it is too large Load diff

301
backend/tests/test_random.c Normal file
View file

@ -0,0 +1,301 @@
/* Test zint against ZXing-C++ */
/*
libzint - the open source barcode library
Copyright (C) 2025 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h"
#define FLAG_FULL_8BIT 0
#define FLAG_LATIN_1 1
#define FLAG_ASCII 2
struct random_item {
int data_flag;
int symbology;
int input_mode;
int eci;
int option_1;
int option_2;
int option_3;
int output_options;
int max_len;
};
static void test_random(const testCtx *const p_ctx, const struct random_item *rdata) {
#ifndef _WIN32
int debug = p_ctx->debug;
int i, length, ret;
#endif
struct zint_symbol *symbol = NULL;
#ifndef _WIN32
unsigned char data_buf[4096];
char modules_dump[40960];
char escaped[40960];
char escaped2[40960];
char cmp_buf[40960];
char cmp_msg[40960];
char ret_buf[40960] = {0}; /* Suppress clang -fsanitize=memory false positive */
const int iterations = p_ctx->arg ? p_ctx->arg : 10000; /* Use "-a N" to set iterations */
/* Requires to be run with "-d 512" (see ZINT_DEBUG_TEST_ZXINGCPP in "testcommon.h") */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder();
#endif
testStartSymbol(p_ctx->func_name, &symbol);
#ifdef _WIN32
testSkip("Test not implemented on Windows");
#else
if (!do_zxingcpp) {
testSkip("Test requires ZXing-C++");
return;
}
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
printf(" iterations %d\n", iterations);
for (i = 0; i < iterations; i++) {
int j;
int cmp_len, ret_len;
length = arc4random_uniform(rdata->max_len) + 1;
arc4random_buf(data_buf, length);
switch (rdata->data_flag) {
case FLAG_FULL_8BIT: /* Full 8-bit */
break;
case FLAG_LATIN_1: /* ASCII + Latin-1 only */
for (j = 0; j < length; j++) {
if (data_buf[j] >= 0x80) {
if (data_buf[j] < 0x90) {
data_buf[j] = (unsigned char) ((data_buf[j] - 0x80) + 0x70);
} else if (data_buf[j] < 0xA0) {
data_buf[j] = (unsigned char) ((data_buf[j] - 0x90) + 0xA0);
}
}
}
break;
case FLAG_ASCII: /* ASCII only */
for (j = 0; j < length; j++) {
data_buf[j] &= 0x7F;
}
break;
default:
assert_nonzero(0, "i:%d invalid data_flag %d\n", i, rdata->data_flag);
break;
}
(void) testUtilSetSymbol(symbol, rdata->symbology, rdata->input_mode, rdata->eci,
rdata->option_1, rdata->option_2, rdata->option_3, rdata->output_options,
(const char *) data_buf, length, debug);
ret = ZBarcode_Encode(symbol, data_buf, length);
assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_nonzero(testUtilCanZXingCPP(i, symbol, (const char *) data_buf, length, debug), "i:%d testUtilCanZXingCPP != 0\n", i);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilZXingCPP(i, symbol, (const char *) data_buf, length, modules_dump, 899 /*zxingcpp_cmp*/, cmp_buf,
sizeof(cmp_buf), &cmp_len);
assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
/*fprintf(stderr, "cmp_len %d\n", cmp_len);*/
ret = testUtilZXingCPPCmp(symbol, cmp_msg, cmp_buf, cmp_len, (const char *) data_buf, length,
NULL /*primary*/, ret_buf, &ret_len);
assert_zero(ret, "i:%d %s testUtilZXingCPPCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg,
testUtilUCharArrayDump(TCU(cmp_buf), cmp_len, escaped, sizeof(escaped)),
testUtilUCharArrayDump(TCU(ret_buf), ret_len, escaped2, sizeof(escaped2)));
ZBarcode_Reset(symbol);
}
ZBarcode_Delete(symbol);
testFinish();
#endif
}
static void test_aztec(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_AZTEC, DATA_MODE, 899, 1, 0, 0, -1, 1600
};
test_random(p_ctx, &rdata);
}
static void test_codablockf(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_LATIN_1, BARCODE_CODABLOCKF, DATA_MODE, 0, -1, 0, 0, -1, 1300
};
test_random(p_ctx, &rdata);
}
static void test_codablockf_ascii(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_ASCII, BARCODE_CODABLOCKF, DATA_MODE, 0, -1, 0, 0, -1, 2200
};
test_random(p_ctx, &rdata);
}
static void test_code128(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_LATIN_1, BARCODE_CODE128, DATA_MODE, 0, -1, 0, 0, -1, 61
};
test_random(p_ctx, &rdata);
}
static void test_code128_ascii(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_ASCII, BARCODE_CODE128, DATA_MODE, 0, -1, 0, 0, -1, 82
};
test_random(p_ctx, &rdata);
}
static void test_datamatrix(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_DATAMATRIX, DATA_MODE, 899, 1, 0, 0, -1, 1550
};
test_random(p_ctx, &rdata);
}
static void test_datamatrix_fast(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_DATAMATRIX, DATA_MODE | FAST_MODE, 899, 1, 0, 0, -1, 1550
};
test_random(p_ctx, &rdata);
}
static void test_dotcode(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_DOTCODE, DATA_MODE, 899, 1, 0, 0, -1, 620
};
test_random(p_ctx, &rdata);
}
static void test_hanxin(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_HANXIN, DATA_MODE, 899, 1, 0, 0, -1, 3261
};
test_random(p_ctx, &rdata);
}
static void test_maxicode(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_MAXICODE, DATA_MODE, 899, 4, 0, 0, -1, 49
};
test_random(p_ctx, &rdata);
}
static void test_micropdf417(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_MICROPDF417, DATA_MODE, 899, 1, 0, 0, -1, 140
};
test_random(p_ctx, &rdata);
}
static void test_pdf417(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_PDF417, DATA_MODE, 899, 1, 0, 0, -1, 1100
};
test_random(p_ctx, &rdata);
}
static void test_pdf417_fast(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_PDF417, DATA_MODE | FAST_MODE, 899, 1, 0, 0, -1, 1000
};
test_random(p_ctx, &rdata);
}
static void test_qr(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_QRCODE, DATA_MODE, 899, 1, 0, 0, -1, 2920
};
test_random(p_ctx, &rdata);
}
static void test_rmqr(const testCtx *const p_ctx) {
struct random_item rdata = {
FLAG_FULL_8BIT, BARCODE_RMQR, DATA_MODE, 899, 2, 0, 0, -1, 140
};
test_random(p_ctx, &rdata);
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
{ "test_aztec", test_aztec },
{ "test_codablockf", test_codablockf },
{ "test_codablockf_ascii", test_codablockf_ascii },
{ "test_code128", test_code128 },
{ "test_code128_ascii", test_code128_ascii },
{ "test_datamatrix", test_datamatrix },
{ "test_datamatrix_fast", test_datamatrix_fast },
{ "test_dotcode", test_dotcode },
{ "test_hanxin", test_hanxin },
{ "test_maxicode", test_maxicode },
{ "test_micropdf417", test_micropdf417 },
{ "test_pdf417", test_pdf417 },
{ "test_pdf417_fast", test_pdf417_fast },
{ "test_qr", test_qr },
{ "test_rmqr", test_rmqr },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();
return 0;
}
/* vim: set ts=4 sw=4 et : */

View file

@ -1091,115 +1091,6 @@ static void test_fuzz(const testCtx *const p_ctx) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITER_MILLES 10
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator */
static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int symbology;
int option_2;
const char *data;
int ret;
int expected_rows;
int expected_width;
const char *comment;
};
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
static const struct item data[] = {
/* 0*/ { BARCODE_EANX, -1, "123456789012+12345", 0, 1, 149, "EAN-13 add-on 5" },
/* 1*/ { BARCODE_EANX, -1, "123456789012", 0, 1, 95, "EAN-13 no add-on" },
/* 2*/ { BARCODE_UPCA, -1, "12345678901+12345", 0, 1, 151, "UPC-A add-on 5" },
/* 3*/ { BARCODE_UPCA, -1, "12345678901", 0, 1, 95, "UPC-A no add-on" },
/* 4*/ { BARCODE_EANX, -1, "1234567+12345", 0, 1, 121, "EAN-8 add-on 5" },
/* 5*/ { BARCODE_EANX, -1, "1234567", 0, 1, 67, "EAN-8 no add-on" },
/* 6*/ { BARCODE_UPCE, -1, "1234567+12", 0, 1, 78, "UPC-E add-on 2" },
/* 7*/ { BARCODE_UPCE, -1, "1234567", 0, 1, 51, "UPC-E no add-on" },
/* 8*/ { BARCODE_EANX, -1, "12345", 0, 1, 47, "EAN-5" },
/* 9*/ { BARCODE_EANX, -1, "12", 0, 1, 20, "EAN-2" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
clock_t start;
clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print;
int comment_max = 0;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
printf("Iterations %d\n", TEST_PERF_ITERATIONS);
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, DATA_MODE, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter), TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
total_buf_inter += diff_buf_inter;
total_print += diff_print;
}
if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
@ -1212,7 +1103,6 @@ int main(int argc, char *argv[]) {
{ "test_vector_same", test_vector_same },
{ "test_encode", test_encode },
{ "test_fuzz", test_fuzz },
{ "test_perf", test_perf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -793,6 +793,12 @@ char *testUtilEscape(const char *buffer, const int length, char *escaped, const
sprintf(escaped + i, "\\%.3o", *b);
}
i += 4;
} else if (*b == '\\' || *b == '"') {
if (i + 2 < escaped_size) {
escaped[i] = '\\';
escaped[i + 1] = *b;
}
i += 2;
} else {
escaped[i++] = *b;
}
@ -1260,7 +1266,7 @@ int testUtilModulesCmpRow(const struct zint_symbol *symbol, int row, const char
}
/* Dump an unsigned int array as hex */
char *testUtilUIntArrayDump(unsigned int *array, int size, char *dump, int dump_size) {
char *testUtilUIntArrayDump(const unsigned int *array, const int size, char *dump, const int dump_size) {
int i, cnt_len = 0;
for (i = 0; i < size; i++) {
@ -1274,7 +1280,7 @@ char *testUtilUIntArrayDump(unsigned int *array, int size, char *dump, int dump_
}
/* Dump an unsigned char array as hex */
char *testUtilUCharArrayDump(unsigned char *array, int size, char *dump, int dump_size) {
char *testUtilUCharArrayDump(const unsigned char *array, const int size, char *dump, const int dump_size) {
int i, cnt_len = 0;
for (i = 0; i < size; i++) {

View file

@ -133,6 +133,7 @@ void assert_notequal(int e1, int e2, const char *fmt, ...);
#define TU(p) ((unsigned char *) (p))
#define TCU(p) ((const unsigned char *) (p))
#define TCC(p) ((const char *) (p))
INTERNAL void vector_free(struct zint_symbol *symbol); /* Free vector structures */
@ -160,8 +161,8 @@ void testUtilModulesPrint(const struct zint_symbol *symbol, const char *prefix,
void testUtilModulesPrintRow(const struct zint_symbol *symbol, int row, const char *prefix, const char *postfix);
int testUtilModulesCmp(const struct zint_symbol *symbol, const char *expected, int *width, int *row);
int testUtilModulesCmpRow(const struct zint_symbol *symbol, int row, const char *expected, int *width);
char *testUtilUIntArrayDump(unsigned int *array, int size, char *dump, int dump_size);
char *testUtilUCharArrayDump(unsigned char *array, int size, char *dump, int dump_size);
char *testUtilUIntArrayDump(const unsigned int *array, const int size, char *dump, const int dump_size);
char *testUtilUCharArrayDump(const unsigned char *array, const int size, char *dump, const int dump_size);
void testUtilBitmapPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix);
int testUtilBitmapCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *column);

View file

@ -921,7 +921,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_
}
/* Separator binding for stacked barcodes */
if ((symbol->output_options & BARCODE_BIND) && (symbol->rows > 1) && is_stackable(symbol->symbology)) {
if ((symbol->output_options & BARCODE_BIND) && symbol->rows > 1 && is_bindable(symbol->symbology)) {
float sep_xoffset = xoffset;
float sep_width = symbol->width;
float sep_height = 1.0f, sep_yoffset, sep_half_height;

View file

@ -33,7 +33,10 @@
/*
* Version: 2.15.0.9 (dev) (see "zintconfig.h")
*
* For documentation, see "../docs/manual.txt" or "../docs/manual.html" or online at
* For documentation, see "../docs/manual.txt" or "../docs/manual.html" or the
* PDF manual for 2.15.0 at
* https://sourceforge.net/projects/zint/files/zint/2.15.0/manual.pdf/download
* or online at
* https://zint.org.uk/manual/
*/
@ -366,6 +369,7 @@ extern "C" {
#define ZINT_CAP_MASK 0x0800 /* Is mask selectable? */
#define ZINT_CAP_STRUCTAPP 0x1000 /* Supports Structured Append? */
#define ZINT_CAP_COMPLIANT_HEIGHT 0x2000 /* Has compliant height? */
#define ZINT_CAP_BINDABLE 0x4000 /* Can set row separators? */
/* The largest amount of data that can be encoded is 4350 4-byte UTF-8 chars in Han Xin Code */
#define ZINT_MAX_DATA_LEN 17400

View file

@ -894,6 +894,10 @@ namespace Zint {
return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_COMPLIANT_HEIGHT);
}
bool QZint::isBindable(int symbology) const {
return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_BINDABLE);
}
/* Whether takes GS1 AI-delimited data */
bool QZint::takesGS1AIData(int symbology) const {
if (symbology == 0) {

View file

@ -268,6 +268,7 @@ public:
bool hasMask(int symbology = 0) const;
bool supportsStructApp(int symbology = 0) const;
bool hasCompliantHeight(int symbology = 0) const;
bool isBindable(int symbology = 0) const;
/* Whether takes GS1 AI-delimited data */
bool takesGS1AIData(int symbology = 0) const;

View file

@ -384,12 +384,12 @@ private slots:
QTest::addColumn<int>("cap_flag");
QTest::newRow("BARCODE_CODE11") << BARCODE_CODE11
<< (ZINT_CAP_HRT | ZINT_CAP_STACKABLE);
<< (ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_BINDABLE);
QTest::newRow("BARCODE_CODE128") << BARCODE_CODE128
<< (ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_READER_INIT);
<< (ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_READER_INIT | ZINT_CAP_BINDABLE);
QTest::newRow("BARCODE_EANX") << BARCODE_EANX
<< (ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_EXTENDABLE | ZINT_CAP_QUIET_ZONES
| ZINT_CAP_COMPLIANT_HEIGHT);
| ZINT_CAP_COMPLIANT_HEIGHT | ZINT_CAP_BINDABLE);
QTest::newRow("BARCODE_EANX_CC") << BARCODE_EANX_CC
<< (ZINT_CAP_HRT | ZINT_CAP_EXTENDABLE | ZINT_CAP_COMPOSITE | ZINT_CAP_GS1 | ZINT_CAP_QUIET_ZONES
| ZINT_CAP_COMPLIANT_HEIGHT);
@ -420,6 +420,7 @@ private slots:
QCOMPARE(bc.hasMask(), (cap_flag & ZINT_CAP_MASK) != 0);
QCOMPARE(bc.supportsStructApp(), (cap_flag & ZINT_CAP_STRUCTAPP) != 0);
QCOMPARE(bc.hasCompliantHeight(), (cap_flag & ZINT_CAP_COMPLIANT_HEIGHT) != 0);
QCOMPARE(bc.isBindable(), (cap_flag & ZINT_CAP_BINDABLE) != 0);
}
void renderTest_data()

View file

@ -333,7 +333,7 @@
<h1 class="title">Zint Barcode Generator and Zint Barcode Studio User
Manual</h1>
<p class="author">Version 2.15.0.9</p>
<p class="date">March 2025</p>
<p class="date">April 2025</p>
</header>
<nav id="TOC" role="doc-toc">
<ul>
@ -4224,7 +4224,8 @@ Text?</td>
</tr>
<tr>
<td style="text-align: left;"><code>ZINT_CAP_STACKABLE</code></td>
<td style="text-align: left;">Is the symbology stackable?</td>
<td style="text-align: left;">Is the symbology stackable? Note that
stacked symbologies are not stackable.</td>
</tr>
<tr>
<td style="text-align: left;"><code>ZINT_CAP_EANUPC</code><a
@ -4255,7 +4256,7 @@ dots?</td>
<tr>
<td style="text-align: left;"><code>ZINT_CAP_QUIET_ZONES</code></td>
<td style="text-align: left;">Does the symbology have default quiet
zones?</td>
zones? Note that default quiet zones may be zero.</td>
</tr>
<tr>
<td style="text-align: left;"><code>ZINT_CAP_FIXED_RATIO</code></td>
@ -4287,6 +4288,12 @@ style="text-align: left;"><code>ZINT_CAP_COMPLIANT_HEIGHT</code></td>
<td style="text-align: left;">Does the symbology have a compliant height
defined?</td>
</tr>
<tr>
<td style="text-align: left;"><code>ZINT_CAP_BINDABLE</code></td>
<td style="text-align: left;">Does the symbology have row separators
that can be set? Includes stacked symbologies and stackable linear
symbologies.</td>
</tr>
</tbody>
</table>
</div>
@ -4317,9 +4324,9 @@ return the actual ECC percentage used in <code>option_1</code> as
<code>P &lt;&lt; 8</code>, where P is the integer percentage, the low
byte containing the values given in Table <a href="#tbl:aztec_eccs">:
Aztec Code Error Correction Modes</a> (with the addition of
<code>0</code> meaning less than 5% + 3 codewords). Micro PDF417 also
will return the ECC percentage in <code>option_1</code> as
<code>P &lt;&lt; 8</code>.</p>
<code>0</code> meaning less than 5% + 3 codewords and <code>-1</code>
meaning minimum 3 codewords). Micro PDF417 also will return the ECC
percentage in <code>option_1</code> as <code>P &lt;&lt; 8</code>.</p>
<p>Detailed feedback on the data encoded may be requested by specifying
the <code>BARCODE_RAW_TEXT</code> option in the
<code>output_options</code> member, which will populate the
@ -4392,7 +4399,7 @@ default. To add just one check digit, set <code>--vers=1</code> (API
<h3 id="code-2-of-5">6.1.2 Code 2 of 5</h3>
<p>Code 2 of 5 is a family of one-dimensional self-checking symbols, 8
of which are supported by Zint. Note that the names given to these
standards alters from one source to another so you should take care to
standards alter from one source to another so you should take care to
ensure that you have the right barcode type before using them.</p>
<h4 id="standard-code-2-of-5">6.1.2.1 Standard Code 2 of 5</h4>
<figure>
@ -7656,7 +7663,7 @@ alt="zint -b DOTCODE -d &quot;[01]00012345678905[17]201231[10]ABC123456&quot; --
aria-hidden="true"><code>zint -b DOTCODE -d "[01]00012345678905[17]201231[10]ABC123456" --gs1</code></figcaption>
</figure>
<p>DotCode uses a grid of dots in a rectangular formation to encode
characters up to a maximum of approximately 450 characters (or 900
characters up to a maximum of approximately 1220 characters (or 2940
numeric digits). The symbology supports ECI encoding and GS1 data
encoding. By default Zint will produce a symbol which is approximately
square, however the width of the symbol can be adjusted by using the

View file

@ -1,6 +1,6 @@
% Zint Barcode Generator and Zint Barcode Studio User Manual
% Version 2.15.0.9
% March 2025
% April 2025
# 1. Introduction
@ -2607,7 +2607,8 @@ Value Meaning
------------------------- --------------------------------------------------
`ZINT_CAP_HRT` Can the symbology print Human Readable Text?
`ZINT_CAP_STACKABLE` Is the symbology stackable?
`ZINT_CAP_STACKABLE` Is the symbology stackable? Note that stacked
symbologies are not stackable.
`ZINT_CAP_EANUPC`[^14] Is the symbology EAN/UPC?
@ -2622,6 +2623,7 @@ Value Meaning
`ZINT_CAP_DOTTY` Can the symbology be outputted as dots?
`ZINT_CAP_QUIET_ZONES` Does the symbology have default quiet zones?
Note that default quiet zones may be zero.
`ZINT_CAP_FIXED_RATIO` Does the symbology have a fixed width-to-height
(aspect) ratio?
@ -2636,6 +2638,10 @@ Value Meaning
`ZINT_CAP_COMPLIANT_HEIGHT` Does the symbology have a compliant height
defined?
`ZINT_CAP_BINDABLE` Does the symbology have row separators that can be
set? Includes stacked symbologies and stackable
linear symbologies.
------------------------------------------------------------------------------
Table: {#tbl:api_cap tag=": API Capability Flags"}
@ -2671,8 +2677,9 @@ In particular for symbologies that have masks,[^15] `option_3` will contain the
mask used as `(N + 1) << 8`, N being the mask. Also Aztec Code will return the
actual ECC percentage used in `option_1` as `P << 8`, where P is the integer
percentage, the low byte containing the values given in Table {@tbl:aztec_eccs}
(with the addition of `0` meaning less than 5% + 3 codewords). Micro PDF417 also
will return the ECC percentage in `option_1` as `P << 8`.
(with the addition of `0` meaning less than 5% + 3 codewords and `-1` meaning
minimum 3 codewords). Micro PDF417 also will return the ECC percentage in
`option_1` as `P << 8`.
Detailed feedback on the data encoded may be requested by specifying the
`BARCODE_RAW_TEXT` option in the `output_options` member, which will populate
@ -2765,7 +2772,7 @@ check digits are added by default. To add just one check digit, set `--vers=1`
### 6.1.2 Code 2 of 5
Code 2 of 5 is a family of one-dimensional self-checking symbols, 8 of which are
supported by Zint. Note that the names given to these standards alters from one
supported by Zint. Note that the names given to these standards alter from one
source to another so you should take care to ensure that you have the right
barcode type before using them.
@ -4674,7 +4681,7 @@ Structured Append]) (API `structapp`). The ID ranges from 0 (default) to 255.
--gs1`](images/dotcode.svg){.i2d}
DotCode uses a grid of dots in a rectangular formation to encode characters up
to a maximum of approximately 450 characters (or 900 numeric digits). The
to a maximum of approximately 1220 characters (or 2940 numeric digits). The
symbology supports ECI encoding and GS1 data encoding. By default Zint will
produce a symbol which is approximately square, however the width of the symbol
can be adjusted by using the `--cols` option (API `option_2`) (maximum 200).

View file

@ -1,6 +1,6 @@
Zint Barcode Generator and Zint Barcode Studio User Manual
Version 2.15.0.9
March 2025
April 2025
*******************************************************************************
* For reference the following is a text-only version of the Zint manual, *
@ -2553,7 +2553,8 @@ see which are set.
--------------------------- --------------------------------------------------
ZINT_CAP_HRT Can the symbology print Human Readable Text?
ZINT_CAP_STACKABLE Is the symbology stackable?
ZINT_CAP_STACKABLE Is the symbology stackable? Note that stacked
symbologies are not stackable.
ZINT_CAP_EANUPC[14] Is the symbology EAN/UPC?
@ -2567,7 +2568,8 @@ see which are set.
ZINT_CAP_DOTTY Can the symbology be outputted as dots?
ZINT_CAP_QUIET_ZONES Does the symbology have default quiet zones?
ZINT_CAP_QUIET_ZONES Does the symbology have default quiet zones? Note
that default quiet zones may be zero.
ZINT_CAP_FIXED_RATIO Does the symbology have a fixed width-to-height
(aspect) ratio?
@ -2582,6 +2584,10 @@ see which are set.
ZINT_CAP_COMPLIANT_HEIGHT Does the symbology have a compliant height
defined?
ZINT_CAP_BINDABLE Does the symbology have row separators that can be
set? Includes stacked symbologies and stackable
linear symbologies.
------------------------------------------------------------------------------
Table : API Capability Flags
@ -2613,8 +2619,8 @@ mask used as (N + 1) << 8, N being the mask. Also Aztec Code will return the
actual ECC percentage used in option_1 as P << 8, where P is the integer
percentage, the low byte containing the values given in Table
: Aztec Code Error Correction Modes (with the addition of 0 meaning less than
5% + 3 codewords). Micro PDF417 also will return the ECC percentage in option_1
as P << 8.
5% + 3 codewords and -1 meaning minimum 3 codewords). Micro PDF417 also will
return the ECC percentage in option_1 as P << 8.
Detailed feedback on the data encoded may be requested by specifying the
BARCODE_RAW_TEXT option in the output_options member, which will populate the
@ -2687,7 +2693,7 @@ check digits are added by default. To add just one check digit, set --vers=1
6.1.2 Code 2 of 5
Code 2 of 5 is a family of one-dimensional self-checking symbols, 8 of which are
supported by Zint. Note that the names given to these standards alters from one
supported by Zint. Note that the names given to these standards alter from one
source to another so you should take care to ensure that you have the right
barcode type before using them.
@ -4469,7 +4475,7 @@ Structured Append) (API structapp). The ID ranges from 0 (default) to 255.
[zint -b DOTCODE -d "[01]00012345678905[17]201231[10]ABC123456" --gs1]
DotCode uses a grid of dots in a rectangular formation to encode characters up
to a maximum of approximately 450 characters (or 900 numeric digits). The
to a maximum of approximately 1220 characters (or 2940 numeric digits). The
symbology supports ECI encoding and GS1 data encoding. By default Zint will
produce a symbol which is approximately square, however the width of the symbol
can be adjusted by using the --cols option (API option_2) (maximum 200).
@ -4930,7 +4936,7 @@ configured barcode is displayed once the "Generate" button is pressed.
Annex D. Man Page ZINT(1)
% ZINT(1) Version 2.15.0.9 % % March 2025
% ZINT(1) Version 2.15.0.9 % % April 2025
NAME

View file

@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 3.6.4
.\"
.TH "ZINT" "1" "March 2025" "Version 2.15.0.9"
.TH "ZINT" "1" "April 2025" "Version 2.15.0.9"
.SH NAME
\f[CR]zint\f[R] \- encode data as a barcode image
.SH SYNOPSIS

View file

@ -1,6 +1,6 @@
% ZINT(1) Version 2.15.0.9
%
% March 2025
% April 2025
# NAME

View file

@ -2129,15 +2129,15 @@ int main(int argc, char **argv) {
if (data_arg_num) {
const int symbology = my_symbol->symbology;
const unsigned int cap = ZBarcode_Cap(symbology, ZINT_CAP_STACKABLE | ZINT_CAP_EXTENDABLE |
ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK);
const unsigned int cap = ZBarcode_Cap(symbology, ZINT_CAP_EXTENDABLE | ZINT_CAP_FULL_MULTIBYTE
| ZINT_CAP_MASK | ZINT_CAP_BINDABLE);
if (fullmultibyte && (cap & ZINT_CAP_FULL_MULTIBYTE)) {
my_symbol->option_3 = ZINT_FULL_MULTIBYTE;
}
if (mask && (cap & ZINT_CAP_MASK)) {
my_symbol->option_3 |= mask << 8;
}
if (separator && (cap & ZINT_CAP_STACKABLE)) {
if (separator && (cap & ZINT_CAP_BINDABLE)) {
my_symbol->option_3 = separator;
}
if (addon_gap && (cap & ZINT_CAP_EXTENDABLE)) {