Performance improvements for linear encoding and raster output

- use fixed-length string tables (mostly) instead of (char *) pointer ones
   (saves ~40K)
 - re-use C128Table for CODABLOCKF and CODE16K
   (required removal of Stop character and extra CODE16K-only entry)
 - use pointer to destination and copy (memcpy/strcpy(), bin_append_posn())
   instead of concatenating (strcat()) (mostly)
 - replace last remaining bin_append()s with bin_append_posn();
   bin_append() removed
 - add length arg to toupper() and expand() (avoids strlen())
 - change is_sane() to use table-based flags (avoids an iteration)
 - rename lookup() to is_sane_lookup() and change to check and return posns
   and use in pointer to destination loops (avoids strcat()s)
 - remove special case PHARMA in expand() (dealt with in pharma())
 - make #define SILVER/CALCIUM/TECHNETIUM/KRSET etc static strings
 - replace strchr() -> posn()
 - CODE128: populate destination once in checksum loop; re-use and export
   some more routines (c128_set_a/b/c(), c128_put_in_set()) for sharing;
   prefix defines (SHIFTA -> C128_SHIFTA etc) and existing exported routines
 - use factor XOR toggle trick in checksum calcs (avoids branch)
 - raster.c: fill out single 1-pixel row and copy using new draw_bar_line(),
   copy_bar_line() routines; similarly in buffer_plot compare previous line &
   copy if same (same technique as used to improve non-half-integer scaling,
   significant performance increase, (c) codemonkey82);
   also done for PNG (BMP/GIF/PCX/TIFF not done)
 - raster/vector/output.c: shorten "output_" prefix -> "out_";
   sync vector to other raster changes to try to keep source files similar
 - 2of5.c: prefix "c25_"
JAPANPOST: return error if input data truncated (backward incompatible)
DAFT: max chars 50 -> 100
common.c: istwodigit() -> is_twodigit()
common.c/emf.c/output.c: use some further stripf()s (MSVC6 float variations)
library.c: new check_output_args() helper
zint.h: add BARCODE_LAST marker and use in library.c
QRCODE: remove a NOLINT (requires clang-tidy-13), one remaining
CMake: separate no-optimize from ZINT_DEBUG into new ZINT_NOOPT option
This commit is contained in:
gitlost 2021-10-20 23:05:30 +01:00
parent e8b59aa696
commit fab7435fac
72 changed files with 3501 additions and 2380 deletions

View file

@ -236,61 +236,67 @@ static void test_encode(int index, int generate, int debug) {
/* 1*/ { BARCODE_C25STANDARD, 1, "87654321", 0, 1, 107, "With check digit",
"11110101011101000101010001110100011101011101110101011101110111000101010001011101110101110100010111011110101"
},
/* 2*/ { BARCODE_C25INTER, -1, "87654321", 0, 1, 81, "Interleaved Code 2 of 5, even; verified manually against tec-it",
/* 2*/ { BARCODE_C25STANDARD, -1, "1234567890", 0, 1, 117, "",
"111101010111010111010001011101110001010101110111011101110101000111010101000111011101000101000100010101110001011110101"
},
/* 3*/ { BARCODE_C25INTER, -1, "87654321", 0, 1, 81, "Interleaved Code 2 of 5, even; verified manually against tec-it",
"101011101010111000100010001110111000101010001000111010111010001110101011100011101"
},
/* 3*/ { BARCODE_C25INTER, 1, "87654321", 0, 1, 99, "With check digit",
/* 4*/ { BARCODE_C25INTER, 1, "87654321", 0, 1, 99, "With check digit",
"101010001011101110001010100010001110111011101011100010100011101110001010100011101000101011100011101"
},
/* 4*/ { BARCODE_C25INTER, -1, "7654321", 0, 1, 81, "Interleaved Code 2 of 5, odd",
/* 5*/ { BARCODE_C25INTER, -1, "7654321", 0, 1, 81, "Interleaved Code 2 of 5, odd",
"101010101110111000100010001110111000101010001000111010111010001110101011100011101"
},
/* 5*/ { BARCODE_C25INTER, 1, "7654321", 0, 1, 81, "With check digit",
/* 6*/ { BARCODE_C25INTER, 1, "7654321", 0, 1, 81, "With check digit",
"101010100010001110111011101011100010100011101110001010100011101010001000111011101"
},
/* 6*/ { BARCODE_C25INTER, -1, "602003", 0, 1, 63, "DX cartridge barcode https://en.wikipedia.org/wiki/Interleaved_2_of_5 example",
/* 7*/ { BARCODE_C25INTER, -1, "602003", 0, 1, 63, "DX cartridge barcode https://en.wikipedia.org/wiki/Interleaved_2_of_5 example",
"101010111011100010001010111010001000111010001000111011101011101"
},
/* 7*/ { BARCODE_C25IATA, -1, "87654321", 0, 1, 121, "IATA Code 2 of 5; verified manually against tec-it",
/* 8*/ { BARCODE_C25IATA, -1, "87654321", 0, 1, 121, "IATA Code 2 of 5; verified manually against tec-it",
"1010111010101110101010101110111010111011101010111010111010101010111010111011101110101010101110101011101110101010111011101"
},
/* 8*/ { BARCODE_C25IATA, 1, "87654321", 0, 1, 135, "With check digit",
/* 9*/ { BARCODE_C25IATA, 1, "87654321", 0, 1, 135, "With check digit",
"101011101010111010101010111011101011101110101011101011101010101011101011101110111010101010111010101110111010101011101011101010111011101"
},
/* 9*/ { BARCODE_C25LOGIC, -1, "87654321", 0, 1, 89, "Code 2 of 5 Data Logic; verified manually against tec-it",
/* 10*/ { BARCODE_C25LOGIC, -1, "87654321", 0, 1, 89, "Code 2 of 5 Data Logic; verified manually against tec-it",
"10101110100010101000111010001110101110111010101110111011100010101000101110111010111011101"
},
/* 10*/ { BARCODE_C25LOGIC, 1, "87654321", 0, 1, 99, "With check digit",
/* 11*/ { BARCODE_C25LOGIC, 1, "87654321", 0, 1, 99, "With check digit",
"101011101000101010001110100011101011101110101011101110111000101010001011101110101110100010111011101"
},
/* 11*/ { BARCODE_C25IND, -1, "87654321", 0, 1, 131, "Industrial Code 2 of 5; verified manually against tec-it",
/* 12*/ { BARCODE_C25IND, -1, "87654321", 0, 1, 131, "Industrial Code 2 of 5; verified manually against tec-it",
"11101110101110101011101010101011101110101110111010101110101110101010101110101110111011101010101011101010111011101010101110111010111"
},
/* 12*/ { BARCODE_C25IND, 1, "87654321", 0, 1, 145, "With check digit",
/* 13*/ { BARCODE_C25IND, 1, "87654321", 0, 1, 145, "With check digit",
"1110111010111010101110101010101110111010111011101010111010111010101010111010111011101110101010101110101011101110101010111010111010101110111010111"
},
/* 13*/ { BARCODE_DPLEIT, -1, "0000087654321", 0, 1, 135, "Deutsche Post Leitcode; verified manually against tec-it",
/* 14*/ { BARCODE_C25IND, -1, "1234567890", 0, 1, 159, "",
"111011101011101010101110101110101011101110111010101010101110101110111010111010101011101110101010101011101110111010101110101011101011101010101110111010111010111"
},
/* 15*/ { BARCODE_DPLEIT, -1, "0000087654321", 0, 1, 135, "Deutsche Post Leitcode; verified manually against tec-it",
"101010101110001110001010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000100010111011101"
},
/* 14*/ { BARCODE_DPLEIT, -1, "5082300702800", 0, 1, 135, "Deutsche Post Leitcode https://de.wikipedia.org/wiki/Leitcode example",
/* 16*/ { BARCODE_DPLEIT, -1, "5082300702800", 0, 1, 135, "Deutsche Post Leitcode https://de.wikipedia.org/wiki/Leitcode example",
"101011101011100010001011101000101110100011101110100010001010101110111000100010100011101110100011101010001110001010001011100011101011101"
},
/* 15*/ { BARCODE_DPIDENT, -1, "00087654321", 0, 1, 117, "Deutsche Post Identcode; verified manually against tec-it",
/* 17*/ { BARCODE_DPIDENT, -1, "00087654321", 0, 1, 117, "Deutsche Post Identcode; verified manually against tec-it",
"101010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000100010111011101"
},
/* 16*/ { BARCODE_DPIDENT, -1, "39601313414", 0, 1, 117, "Deutsche Post Identcode https://de.wikipedia.org/wiki/Leitcode example",
/* 18*/ { BARCODE_DPIDENT, -1, "39601313414", 0, 1, 117, "Deutsche Post Identcode https://de.wikipedia.org/wiki/Leitcode example",
"101011101110001010001010111011100010001011100010001010111011100010001010111010001011101011100010101110001000111011101"
},
/* 17*/ { BARCODE_ITF14, -1, "0000087654321", 0, 1, 135, "ITF-14; verified manually against tec-it",
/* 19*/ { BARCODE_ITF14, -1, "0000087654321", 0, 1, 135, "ITF-14; verified manually against tec-it",
"101010101110001110001010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000101011100011101"
},
/* 18*/ { BARCODE_ITF14, -1, "0950110153000", 0, 1, 135, "GS1 General Specifications Figure 5.1-2",
/* 20*/ { BARCODE_ITF14, -1, "0950110153000", 0, 1, 135, "GS1 General Specifications Figure 5.1-2",
"101010100011101110001011101011100010001011100010101011100010001011101110100011100010001110101010101110001110001010001000111011101011101"
},
/* 19*/ { BARCODE_ITF14, -1, "1540014128876", 0, 1, 135, "GS1 General Specifications Figure 5.3.2.4-1",
/* 21*/ { BARCODE_ITF14, -1, "1540014128876", 0, 1, 135, "GS1 General Specifications Figure 5.3.2.4-1",
"101011100010100010111010101110001000111010001011101110100010001011101011100010001110101000111011101010111000100010001110001110101011101"
},
/* 20*/ { BARCODE_ITF14, -1, "0950110153001", 0, 1, 135, "GS1 General Specifications Figure 5.3.6-1",
/* 22*/ { BARCODE_ITF14, -1, "0950110153001", 0, 1, 135, "GS1 General Specifications Figure 5.3.6-1",
"101010100011101110001011101011100010001011100010101011100010001011101110100011100010001110101010101110001110001011101010001000111011101"
},
};
@ -351,6 +357,107 @@ static void test_encode(int index, int generate, int debug) {
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(int index, int debug) {
struct item {
int symbology;
int option_2;
char *data;
int ret;
int expected_rows;
int expected_width;
char *comment;
};
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" },
};
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 (index != -1 && i != index) 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, (unsigned char *) 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(remove(symbol->outfile), "i:%d remove(%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 (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, has_index, has_generate, has_debug */
@ -358,6 +465,7 @@ int main(int argc, char *argv[]) {
{ "test_hrt", test_hrt, 1, 0, 1 },
{ "test_input", test_input, 1, 0, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_perf", test_perf, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -236,17 +236,42 @@ static void test_encode(int index, int generate, int debug) {
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"0000101010100010101010101000100000101010000010100010100010101010001010000010001010100000100010101000000000101000001010100000000010000"
},
/* 5*/ { BARCODE_AUSREPLY, "12345678", 0, 3, 73, "Verified manually against tec-it",
/* 5*/ { BARCODE_AUSPOST, "12345678DEGHJKLMNO", 0, 3, 133, "62 Custom 3 C encoding GDSET 1st part",
"1000001010001010100010101010100000100010000010101010101010001010001010101010101010100010101010101010100000001010000010000000000010100"
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"0000101010101000101000100000001010101000101010001010000010101010100000101000100000101000001000000000001000001010000010001010001010000"
},
/* 6*/ { BARCODE_AUSPOST, "23456789PQRSTUVWXY", 0, 3, 133, "62 Custom 3 C encoding GDSET 2nd part",
"1000001010001000101010101000001000100000001010001010001010000000101000101000100000101000101000100000001000101000101010101000101010100"
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"0000101010101010001000000010101010001010001000101000100000101010101010100010101010001010000010001010101000000010001000001010101000000"
},
/* 7*/ { BARCODE_AUSPOST, "34567890Zcefgijklm", 0, 3, 133, "62 Custom 3 C encoding GDSET 3rd part",
"1000001010001010101010000010001000000010101000001010001010000010100010100010001010001010000010000000100000101000100000001010001010100"
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"0000101010100010000000101010100010100010101010100010000010000000100000000000001000000000001000000010100000101000000010101010100010000"
},
/* 8*/ { BARCODE_AUSPOST, "12345678lnopqrstuv", 0, 3, 133, "62 Custom 3 C encoding GDSET 4th part",
"1000001010001010100010101010100000100010000010000000100000000000001000001000000000000000100000100000000000001010001010101000000010100"
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"0000101010101000101000100000001010101000101000000010000010100010001010000010001010000000100000000000100000100000001010001000100000000"
},
/* 9*/ { BARCODE_AUSPOST, "09876543wxy# ", 0, 3, 103, "59 Custom 2 C encoding GDSET 5th part",
"1000100000101010001000000010001010001010101000001000001000000010100010100000100010000000000010100010100"
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"0000001000101010001010101000101000100000001000001000000000001010000010100000001010001000001000100000000"
},
/* 10*/ { BARCODE_AUSREPLY, "12345678", 0, 3, 73, "Verified manually against tec-it",
"1000101010001010100010101010100000100010000000001000001000000000100010100"
"1010101010101010101010101010101010101010101010101010101010101010101010101"
"0000000000101000101000100000001010101000101000000000100010101000101000000"
},
/* 6*/ { BARCODE_AUSROUTE, "34567890", 0, 3, 73, "Verified manually against tec-it",
/* 11*/ { BARCODE_AUSROUTE, "34567890", 0, 3, 73, "Verified manually against tec-it",
"1000000000101010101010000010001000000010101000100010101010000000101000100"
"1010101010101010101010101010101010101010101010101010101010101010101010101"
"0000101010000010000000101010100010100010101000100010101010001010001000000"
},
/* 7*/ { BARCODE_AUSREDIRECT, "98765432", 0, 3, 73, "Verified manually against tec-it",
/* 12*/ { BARCODE_AUSREDIRECT, "98765432", 0, 3, 73, "Verified manually against tec-it",
"1000001010000010000000100010100010101010100000101010101000100010100010100"
"1010101010101010101010101010101010101010101010101010101010101010101010101"
"0000001010100010101010001010001000000010101000000000001010101000001010000"

View file

@ -31,6 +31,65 @@
#include "testcommon.h"
static void test_hrt(int index, int debug) {
struct item {
int option_2;
char *data;
int length;
char *expected;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { -1, "1", -1, "01" },
/* 1*/ { 3, "1", -1, "01" },
/* 2*/ { 3, "12", -1, "12" },
/* 3*/ { 4, "123", -1, "123" },
/* 4*/ { 5, "123", -1, "0123" },
/* 5*/ { 5, "12", -1, "0012" },
/* 6*/ { 5, "1", -1, "0001" },
/* 7*/ { 5, "1234", -1, "1234" },
/* 8*/ { 6, "1234", -1, "01234" },
/* 9*/ { 6, "123", -1, "00123" },
/* 10*/ { 6, "12", -1, "00012" },
/* 11*/ { 6, "1", -1, "00001" },
/* 12*/ { 7, "1234", -1, "001234" },
/* 13*/ { 7, "12345", -1, "012345" },
/* 14*/ { 7, "123456", -1, "123456" },
/* 15*/ { 7, "1", -1, "000001" },
/* 16*/ { 8, "12345", -1, "0012345" },
/* 17*/ { 8, "123456", -1, "0123456" },
/* 18*/ { 8, "1234567", -1, "1234567" },
/* 19*/ { 8, "12", -1, "0000012" },
/* 20*/ { 8, "1", -1, "0000001" },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
testStart("test_hrt");
for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt);
assert_zero(strcmp((char *) symbol->text, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->text, data[i].expected);
ZBarcode_Delete(symbol);
}
testFinish();
}
static void test_input(int index, int debug) {
struct item {
@ -436,6 +495,7 @@ static void test_generate(int generate) {
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_hrt", test_hrt, 1, 0, 1 },
{ "test_input", test_input, 1, 0, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_generate", test_generate, 0, 1, 0 },

View file

@ -428,12 +428,25 @@ static void test_encode(int index, int generate, int debug) {
"1101000010010111101110110001001001011000111011011001100100011000101101100110011011101000110110111101111011101010010000110100100111101100011101011"
"1101000010010111101110101100111001000111101011001010000100011110101001101000011011011110101110111101000011001011011101110101001111001100011101011"
},
/* 11*/ { 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)",
/* 11*/ { BARCODE_CODABLOCKF, -1, -1, " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", 0, 11, 156, 1, "Visible ASCII",
"110100001001011110111010000110100110110011001100110110011001100110100100110001001000110010001001100100110010001001100010010001100100101100011101100011101011"
"110100001001011110111011000100100110010010001100100010011000100100101100111001001101110010011001110101110011001001110110010011100110100001100101100011101011"
"110100001001011101111010001101110111011011101011101100010000101100110110111101011110111011100100110111011001001110011010011100110010100001001101100011101011"
"110100001001011110111010011011100110110110001101100011011000110110101000110001000101100010001000110101100010001000110100010001100010111100010101100011101011"
"110100001001011110111010011001110110100010001100010100011000100010101101110001011000111010001101110101110110001011100011010001110110100110111001100011101011"
"110100001001011110111010111001100111011101101101000111011000101110110111010001101110001011011101110111010110001110100011011100010110100001011001100011101011"
"110100001001011110111011100100110111011010001110110001011100011010111011110101100100001011110001010101001100001010000110010010110000100011000101100011101011"
"110100001001011110111011101100100100100001101000010110010000100110101100100001011000010010011010000100110000101000011010010000110010101011110001100011101011"
"110100001001011110111011100110100110000100101100101000011110111010110000101001000111101010100111100100101111001001001111010111100100101100011101100011101011"
"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)",
"110100001001011110111010010110000110001001001010001100010011100110110011100101100101110010001011000100100001101100011101011"
"110100001001011110111011000100100101101110001000100011011011100100101100010001100111010010001101000111001001101100011101011"
"110100001001011110111010110011100111011011101001110011011010001000101110111101011100011011001110100100100110001100011101011"
},
/* 12*/ { 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"

View file

@ -185,38 +185,64 @@ static void test_input(int index, int debug) {
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_CODE11, -1, "-", -1, 0, 1, 37 },
/* 1*/ { BARCODE_CODE11, -1, "A", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 2*/ { BARCODE_CODE11, 3, "1", -1, ZINT_ERROR_INVALID_OPTION, -1, -1 },
/* 3*/ { BARCODE_CODE39, -1, "a", -1, 0, 1, 38 }, // Converts to upper
/* 4*/ { BARCODE_CODE39, -1, ",", 1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 5*/ { BARCODE_CODE39, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 6*/ { BARCODE_CODE39, 0, "1", -1, 0, 1, 38 },
/* 7*/ { BARCODE_CODE39, 1, "1", -1, 0, 1, 51 }, // Check digit
/* 8*/ { BARCODE_CODE39, 2, "1", -1, 0, 1, 38 }, // option_2 > 1 gnored
/* 9*/ { BARCODE_EXCODE39, -1, "A", -1, 0, 1, 38 },
/* 10*/ { BARCODE_EXCODE39, -1, "a", -1, 0, 1, 51 },
/* 11*/ { BARCODE_EXCODE39, -1, ",", -1, 0, 1, 51 },
/* 12*/ { BARCODE_EXCODE39, -1, "\000", 1, 0, 1, 51 },
/* 13*/ { BARCODE_EXCODE39, -1, "é", -1, ZINT_ERROR_INVALID_DATA, -1, -1, },
/* 14*/ { BARCODE_LOGMARS, -1, "A", -1, 0, 1, 47 },
/* 15*/ { BARCODE_LOGMARS, -1, "a", -1, 0, 1, 47 },
/* 16*/ { BARCODE_LOGMARS, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1, },
/* 17*/ { BARCODE_LOGMARS, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1, },
/* 18*/ { BARCODE_CODE93, -1, "A", -1, 0, 1, 46 },
/* 19*/ { BARCODE_CODE93, -1, "a", -1, 0, 1, 55 },
/* 20*/ { BARCODE_CODE93, -1, ",", -1, 0, 1, 55 },
/* 21*/ { BARCODE_CODE93, -1, "\000", 1, 0, 1, 55 },
/* 22*/ { BARCODE_CODE93, -1, "é", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 23*/ { BARCODE_PZN, -1, "1", -1, 0, 1, 142 },
/* 24*/ { BARCODE_PZN, -1, "A", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 25*/ { BARCODE_PZN, -1, "1000006", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // Check digit == 10 so can't be used
/* 26*/ { BARCODE_VIN, -1, "5GZCZ43D13S812715", -1, 0, 1, 246 },
/* 27*/ { BARCODE_VIN, -1, "5GZCZ43D23S812715", -1, ZINT_ERROR_INVALID_CHECK, -1, -1 }, // North American with invalid check character
/* 28*/ { BARCODE_VIN, -1, "WP0ZZZ99ZTS392124", -1, 0, 1, 246 }, // Not North American so no check
/* 29*/ { BARCODE_VIN, -1, "WPOZZZ99ZTS392124", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // O not allowed
/* 30*/ { BARCODE_HIBC_39, -1, "a", -1, 0, 1, 79 }, // Converts to upper
/* 31*/ { BARCODE_HIBC_39, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 32*/ { BARCODE_HIBC_39, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 1*/ { BARCODE_CODE11, -1, "0123456789-", -1, 0, 1, 115 },
/* 2*/ { BARCODE_CODE11, -1, "A", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 3*/ { BARCODE_CODE11, -1, "12+", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 4*/ { BARCODE_CODE11, -1, "1.2", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 5*/ { BARCODE_CODE11, -1, "12!", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 6*/ { BARCODE_CODE11, -1, " ", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 7*/ { BARCODE_CODE11, 3, "1", -1, ZINT_ERROR_INVALID_OPTION, -1, -1 },
/* 8*/ { BARCODE_CODE39, -1, "a", -1, 0, 1, 38 }, // Converts to upper
/* 9*/ { BARCODE_CODE39, -1, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%", -1, 0, 1, 584 },
/* 10*/ { BARCODE_CODE39, -1, "AB!", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 11*/ { BARCODE_CODE39, -1, "A\"B", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 12*/ { BARCODE_CODE39, -1, "#AB", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 13*/ { BARCODE_CODE39, -1, "&", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 14*/ { BARCODE_CODE39, -1, "'", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 15*/ { BARCODE_CODE39, -1, "(", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 16*/ { BARCODE_CODE39, -1, ")", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 17*/ { BARCODE_CODE39, -1, "*", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 18*/ { BARCODE_CODE39, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 19*/ { BARCODE_CODE39, -1, ":", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 20*/ { BARCODE_CODE39, -1, "@", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 21*/ { BARCODE_CODE39, -1, "[", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 22*/ { BARCODE_CODE39, -1, "`", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 23*/ { BARCODE_CODE39, -1, "{", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 24*/ { BARCODE_CODE39, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 25*/ { BARCODE_CODE39, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 26*/ { BARCODE_CODE39, 0, "1", -1, 0, 1, 38 },
/* 27*/ { BARCODE_CODE39, 1, "1", -1, 0, 1, 51 }, // Check digit
/* 28*/ { BARCODE_CODE39, 2, "1", -1, 0, 1, 38 }, // option_2 > 1 gnored
/* 29*/ { BARCODE_EXCODE39, -1, "A", -1, 0, 1, 38 },
/* 30*/ { BARCODE_EXCODE39, -1, "a", -1, 0, 1, 51 },
/* 31*/ { BARCODE_EXCODE39, -1, ",", -1, 0, 1, 51 },
/* 32*/ { BARCODE_EXCODE39, -1, "\000", 1, 0, 1, 51 },
/* 33*/ { BARCODE_EXCODE39, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 34*/ { BARCODE_EXCODE39, -1, "é", -1, ZINT_ERROR_INVALID_DATA, -1, -1, },
/* 35*/ { BARCODE_LOGMARS, -1, "A", -1, 0, 1, 47 },
/* 36*/ { BARCODE_LOGMARS, -1, "a", -1, 0, 1, 47 },
/* 37*/ { BARCODE_LOGMARS, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1, },
/* 38*/ { BARCODE_LOGMARS, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1, },
/* 39*/ { BARCODE_LOGMARS, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1, },
/* 40*/ { BARCODE_CODE93, -1, "A", -1, 0, 1, 46 },
/* 41*/ { BARCODE_CODE93, -1, "a", -1, 0, 1, 55 },
/* 42*/ { BARCODE_CODE93, -1, ",", -1, 0, 1, 55 },
/* 43*/ { BARCODE_CODE93, -1, "\000", 1, 0, 1, 55 },
/* 44*/ { BARCODE_CODE93, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 45*/ { BARCODE_CODE93, -1, "é", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 46*/ { BARCODE_PZN, -1, "1", -1, 0, 1, 142 },
/* 47*/ { BARCODE_PZN, -1, "A", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 48*/ { BARCODE_PZN, -1, "1000006", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // Check digit == 10 so can't be used
/* 49*/ { BARCODE_VIN, -1, "5GZCZ43D13S812715", -1, 0, 1, 246 },
/* 50*/ { BARCODE_VIN, -1, "5GZCZ43D23S812715", -1, ZINT_ERROR_INVALID_CHECK, -1, -1 }, // North American with invalid check character
/* 51*/ { BARCODE_VIN, -1, "WP0ZZZ99ZTS392124", -1, 0, 1, 246 }, // Not North American so no check
/* 52*/ { BARCODE_VIN, -1, "WP0ZZZ99ZTS392I24", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // I not allowed
/* 53*/ { BARCODE_VIN, -1, "WPOZZZ99ZTS392124", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // O not allowed
/* 54*/ { BARCODE_VIN, -1, "WPQZZZ99ZTS392124", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // Q not allowed
/* 55*/ { BARCODE_HIBC_39, -1, "a", -1, 0, 1, 79 }, // Converts to upper
/* 56*/ { BARCODE_HIBC_39, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 57*/ { BARCODE_HIBC_39, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 58*/ { BARCODE_HIBC_39, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
@ -310,67 +336,82 @@ static void test_encode(int index, int generate, int debug) {
/* 15*/ { BARCODE_CODE39, -1, "+A/E%U$A/D%T+Z", -1, 0, 1, 207, "Same as BARCODE_EXCODE39 'a%\000\001$\177z' below",
"100101101101010010100100101101010010110100100101001011010110010101010010010010110010101011010010010010101101010010110100100101001010101100101101010010010010101011011001010010100100101001101101010100101101101"
},
/* 16*/ { BARCODE_EXCODE39, -1, "1A", -1, 0, 1, 51, "ISO/IEC 16388:2007 Figure 1",
/* 16*/ { BARCODE_CODE39, -1, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%", -1, 0, 1, 584, "Full CODE39 set",
"10010110110101010011011010110100101011010110010101101101100101010101001101011011010011010101011001101010101001011011011010010110101011001011010110101001011010110100101101101101001010101011001011011010110010101011011001010101010011011011010100110101011010011010101011001101011010101001101011010100110110110101001010101101001101101011010010101101101001010101011001101101010110010101101011001010101101100101100101010110100110101011011001101010101001011010110110010110101010011011010101001010110110110010101101010011010110101001001001010100100101001010010100100101010010010010100101101101"
},
/* 17*/ { BARCODE_EXCODE39, -1, "1A", -1, 0, 1, 51, "ISO/IEC 16388:2007 Figure 1",
"100101101101011010010101101101010010110100101101101"
},
/* 17*/ { BARCODE_EXCODE39, 1, "1A", -1, 0, 1, 64, "With check digit",
/* 18*/ { BARCODE_EXCODE39, 1, "1A", -1, 0, 1, 64, "With check digit",
"1001011011010110100101011011010100101101011010010110100101101101"
},
/* 18*/ { BARCODE_EXCODE39, 1, "Z4", -1, 0, 1, 64, "Check digit $",
/* 19*/ { BARCODE_EXCODE39, 1, "Z4", -1, 0, 1, 64, "Check digit $",
"1001011011010100110110101010100110101101001001001010100101101101"
},
/* 19*/ { BARCODE_EXCODE39, -1, "a%\000\001$\177z", 7, 0, 1, 207, "Verified manually against tec-it",
/* 20*/ { BARCODE_EXCODE39, -1, "a%\000\001$\177z", 7, 0, 1, 207, "Verified manually against tec-it",
"100101101101010010100100101101010010110100100101001011010110010101010010010010110010101011010010010010101101010010110100100101001010101100101101010010010010101011011001010010100100101001101101010100101101101"
},
/* 20*/ { BARCODE_EXCODE39, -1, "\033\037!+/\\@A~", -1, 0, 1, 246, "Verified manually against tec-it",
/* 21*/ { BARCODE_EXCODE39, -1, "\033\037!+/\\@A~", -1, 0, 1, 246, "Verified manually against tec-it",
"100101101101010100100100101101010010110101001001001011010110010101001001010010110101001011010010010100101101010100110100100101001011010110100101010010010010101101010011010100100100101001101010110110101001011010100100100101011010110010100101101101"
},
/* 21*/ { BARCODE_LOGMARS, -1, "1A", -1, 0, 1, 63, "Verified manually against tec-it",
/* 22*/ { BARCODE_EXCODE39, -1, " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]", -1, 0, 1, 1130, "Visible ASCII 1st 85 symbol chars",
"10010110110101001101011010100100101001011010100101101001001010010101101001011010010010100101101101001010100100101001010101100101101001001010010110101100101010010010100101011011001010100100101001010101001101101001001010010110101001101010010010100101011010011010100100101001010101100110101001001010010110101010011010010010100101011010100110100101011011011001010110101001001010010110101101001010100110110101101001010110101100101011011011001010101010011010110110100110101010110011010101010010110110110100101101010110010110101001001010010100110110101010100100100101011011001010101001001001010101001101101010010010010110101001101010100100100101011010011010101001001001010101100110101010010010010100110101011011010100101101011010010110110110100101010101100101101101011001010101101100101010101001101101101010011010101101001101010101100110101101010100110101101010011011011010100101010110100110110101101001010110110100101010101100110110101011001010110101100101010110110010110010101011010011010101101100110101010100101101011011001011010101001101101010101001001001011010101001101010010010010101101010011010100100100101101101010010100101101101"
},
/* 23*/ { BARCODE_EXCODE39, -1, "^_`abcdefghijklmnopqrstuvwxyz{|}~", -1, 0, 1, 883, "Visible ASCII last part",
"1001011011010101001001001010101101001101010010010010110101101001010100100100101100110101010100101001001011010100101101001010010010101101001011010010100100101101101001010100101001001010101100101101001010010010110101100101010010100100101011011001010100101001001010101001101101001010010010110101001101010010100100101011010011010100101001001010101100110101001010010010110101010011010010100100101011010100110100101001001011011010100101001010010010101011010011010010100100101101011010010100101001001010110110100101001010010010101010110011010010100100101101010110010100101001001010110101100101001010010010101011011001010010100100101100101010110100101001001010011010101101001010010010110011010101010010100100101001011010110100101001001011001011010101001010010010100110110101010100100100101011011010010101001001001010101011001101010010010010110101011001010100100100101011010110010100101101101"
},
/* 24*/ { BARCODE_LOGMARS, -1, "1A", -1, 0, 1, 63, "Verified manually against tec-it",
"100010111011101011101000101011101110101000101110100010111011101"
},
/* 22*/ { BARCODE_LOGMARS, 1, "1A", -1, 0, 1, 79, "With check digit; verified manually against tec-it",
/* 25*/ { BARCODE_LOGMARS, 1, "1A", -1, 0, 1, 79, "With check digit; verified manually against tec-it",
"1000101110111010111010001010111011101010001011101011101000101110100010111011101"
},
/* 23*/ { BARCODE_LOGMARS, -1, "ABC", -1, 0, 1, 79, "MIL-STD-1189 Rev. B Figure 1",
/* 26*/ { BARCODE_LOGMARS, -1, "ABC", -1, 0, 1, 79, "MIL-STD-1189 Rev. B Figure 1",
"1000101110111010111010100010111010111010001011101110111010001010100010111011101"
},
/* 24*/ { BARCODE_LOGMARS, -1, "SAMPLE 1", -1, 0, 1, 159, "MIL-STD-1189 Rev. B Figure 2 top",
/* 27*/ { BARCODE_LOGMARS, -1, "SAMPLE 1", -1, 0, 1, 159, "MIL-STD-1189 Rev. B Figure 2 top",
"100010111011101010111010111000101110101000101110111011101010001010111011101000101011101010001110111010111000101010001110101110101110100010101110100010111011101"
},
/* 25*/ { BARCODE_LOGMARS, 1, "12345/ABCDE", -1, 0, 1, 223, "MIL-STD-1189 Rev. B Section 6.2.1 check character example; verified manually against tec-it",
/* 28*/ { BARCODE_LOGMARS, 1, "12345/ABCDE", -1, 0, 1, 223, "MIL-STD-1189 Rev. B Section 6.2.1 check character example; verified manually against tec-it",
"1000101110111010111010001010111010111000101011101110111000101010101000111010111011101000111010101000100010100010111010100010111010111010001011101110111010001010101011100010111011101011100010101010111011100010100010111011101"
},
/* 26*/ { BARCODE_CODE93, -1, "C93", -1, 0, 1, 64, "ANSI/AIM BC5-1995 Figure 1; verified manually against tec-it",
/* 29*/ { BARCODE_CODE93, -1, "C93", -1, 0, 1, 64, "ANSI/AIM BC5-1995 Figure 1; verified manually against tec-it",
"1010111101101000101000010101010000101101010001110110101010111101"
},
/* 27*/ { BARCODE_CODE93, -1, "CODE\01593", -1, 0, 1, 109, "ANSI/AIM BC5-1995 Figure B1; verified manually against tec-it",
/* 30*/ { BARCODE_CODE93, -1, "CODE\01593", -1, 0, 1, 109, "ANSI/AIM BC5-1995 Figure B1; verified manually against tec-it",
"1010111101101000101001011001100101001100100101001001101010011001000010101010000101100101001000101101010111101"
},
/* 28*/ { BARCODE_CODE93, -1, "1A", -1, 0, 1, 55, "Verified manually against tec-it",
/* 31*/ { BARCODE_CODE93, -1, "1A", -1, 0, 1, 55, "Verified manually against tec-it",
"1010111101010010001101010001101000101001110101010111101"
},
/* 29*/ { BARCODE_CODE93, -1, "TEST93", -1, 0, 1, 91, "Verified manually against tec-it",
/* 32*/ { BARCODE_CODE93, -1, "TEST93", -1, 0, 1, 91, "Verified manually against tec-it",
"1010111101101001101100100101101011001101001101000010101010000101011101101001000101010111101"
},
/* 30*/ { BARCODE_CODE93, -1, "\000a\177", 3, 0, 1, 91, "Verified manually against tec-it",
/* 33*/ { BARCODE_CODE93, -1, "\000a\177", 3, 0, 1, 91, "Verified manually against tec-it",
"1010111101110110101100101101001100101101010001110110101101001101011011101010010001010111101"
},
/* 31*/ { BARCODE_PZN, -1, "1234567", -1, 0, 1, 142, "Example from IFA Info Code 39 EN V2.1; verified manually against tec-it",
/* 34*/ { BARCODE_CODE93, -1, " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghij", -1, 0, 1, 1000, "Visible ASCII 1st 107 symbol chars",
"1010111101110100101110101101101010001110101101101001001110101101101000101110010101101011101110101101100010101110101101011010001110101101011001001110101101011000101110101101001101001011101101110101101010110001001011101110101001011011101000101001010010001010001001010000101001010001001001001001000101010100001000100101000010101110101101001110101110110101100010101110110101011010001110110101011001001110110101011000101110110101001101001110110101100110101101010001101001001101000101100101001100100101100010101011010001011001001011000101001101001000110101010110001010011001010001101001011001000101101101101001101100101101011001101001101100101101100110101011011001011001101001101101001110101110110101000110101110110101010110001110110101010011001110110101010001101110110101001011001110110101011011001001100101101010001001100101101001001001100101101000101001100101100101001001100101100100101001100101100010101001100101011010001001100101011001001001100101011000101001100101001101001010001101101001101010111101"
},
/* 35*/ { BARCODE_CODE93, -1, "klmnopqrstuvwxyz{|}~", -1, 0, 1, 397, "Visible ASCII last part",
"1010111101001100101000110101001100101010110001001100101010011001001100101010001101001100101001011001001100101000101101001100101101101001001100101101100101001100101101011001001100101101001101001100101100101101001100101100110101001100101011011001001100101011001101001100101001101101001100101001110101110110101000101101110110101101101001110110101101100101110110101101011001101001001101100101010111101"
},
/* 36*/ { BARCODE_PZN, -1, "1234567", -1, 0, 1, 142, "Example from IFA Info Code 39 EN V2.1; verified manually against tec-it",
"1001011011010100101011011011010010101101011001010110110110010101010100110101101101001101010101100110101010100101101101101001011010100101101101"
},
/* 32*/ { BARCODE_PZN, -1, "2758089", -1, 0, 1, 142, "Example from IFA Info Check Digit Calculations EN 15 July 2019; verified manually against tec-it",
/* 37*/ { BARCODE_PZN, -1, "2758089", -1, 0, 1, 142, "Example from IFA Info Check Digit Calculations EN 15 July 2019; verified manually against tec-it",
"1001011011010100101011011010110010101101010010110110110100110101011010010110101010011011010110100101101010110010110101011001011010100101101101"
},
/* 33*/ { BARCODE_VIN, -1, "1FTCR10UXTPA78180", -1, 0, 1, 246, "https://www.vinquery.com/img/vinbarcode/vinbarcode4.jpg",
/* 38*/ { BARCODE_VIN, -1, "1FTCR10UXTPA78180", -1, 0, 1, 246, "https://www.vinquery.com/img/vinbarcode/vinbarcode4.jpg",
"100101101101011010010101101011011001010101011011001011011010010101101010110010110100101011010100110110101100101010110100101101011010101101100101011011010010110101001011010100101101101101001011010110100101011011010010110101010011011010100101101101"
},
/* 34*/ { BARCODE_VIN, 1, "2FTPX28L0XCA15511", -1, 0, 1, 259, "With Import 'I' prefix; https://www.vinquery.com/img/vinbarcode/vinbarcode1.jpg",
/* 39*/ { BARCODE_VIN, 1, "2FTPX28L0XCA15511", -1, 0, 1, 259, "With Import 'I' prefix; https://www.vinquery.com/img/vinbarcode/vinbarcode1.jpg",
"1001011011010101101001101010110010101101011011001010101011011001010110110100101001011010110101100101011011010010110101011010100110101001101101010010110101101101101001010110101001011011010010101101101001101010110100110101011010010101101101001010110100101101101"
},
/* 35*/ { BARCODE_HIBC_39, -1, "A123BJC5D6E71", -1, 0, 1, 271, "ANSI/HIBC 2.6 - 2016 Figure 2, same",
/* 40*/ { BARCODE_HIBC_39, -1, "A123BJC5D6E71", -1, 0, 1, 271, "ANSI/HIBC 2.6 - 2016 Figure 2, same",
"1000101110111010100010100010001011101010001011101110100010101110101110001010111011101110001010101011101000101110101011100011101011101110100010101110100011101010101011100010111010111000111010101110101110001010101000101110111011101000101011101010100011101110100010111011101"
},
/* 36*/ { BARCODE_HIBC_39, -1, "$$52001510X3G", -1, 0, 1, 271, "ANSI/HIBC 2.6 - 2016 Figure 6, same",
/* 41*/ { BARCODE_HIBC_39, -1, "$$52001510X3G", -1, 0, 1, 271, "ANSI/HIBC 2.6 - 2016 Figure 6, same",
"1000101110111010100010100010001010001000100010101000100010001010111010001110101010111000101011101010001110111010101000111011101011101000101011101110100011101010111010001010111010100011101110101000101110101110111011100010101010101000111011101010111000101110100010111011101"
},
};
@ -431,6 +472,111 @@ static void test_encode(int index, int generate, int debug) {
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(int index, int debug) {
struct item {
int symbology;
int option_2;
char *data;
int ret;
int expected_rows;
int expected_width;
char *comment;
};
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" },
/* 4*/ { BARCODE_CODE11, -1, "1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-", 0, 1, 966, "CODE11 121" },
/* 5*/ { BARCODE_CODE11, -1, "1234567890-", 0, 1, 116, "CODE11 5" },
};
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 (index != -1 && i != index) 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, (unsigned char *) 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(remove(symbol->outfile), "i:%d remove(%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 (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, has_index, has_generate, has_debug */
@ -438,6 +584,7 @@ int main(int argc, char *argv[]) {
{ "test_hrt", test_hrt, 1, 0, 1 },
{ "test_input", test_input, 1, 0, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_perf", test_perf, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -839,6 +839,105 @@ static void test_encode(int index, int generate, int debug) {
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(int index, int debug) {
struct item {
int symbology;
char *data;
int ret;
int expected_rows;
int expected_width;
char *comment;
};
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)" },
};
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 (index != -1 && i != index) 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, (unsigned char *) 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(remove(symbol->outfile), "i:%d remove(%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 (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, has_index, has_generate, has_debug */
@ -852,6 +951,7 @@ int main(int argc, char *argv[]) {
{ "test_ean14_input", test_ean14_input, 1, 1, 1 },
{ "test_dpd_input", test_dpd_input, 1, 1, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_perf", test_perf, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -31,6 +31,230 @@
#include "testcommon.h"
/* Original */
static int is_sane_orig(const char test_string[], const unsigned char source[], const int length) {
int i, j, lt = (int) strlen(test_string);
for (i = 0; i < length; i++) {
unsigned int latch = FALSE;
for (j = 0; j < lt; j++) {
if (source[i] == test_string[j]) {
latch = TRUE;
break;
}
}
if (!(latch)) {
return ZINT_ERROR_INVALID_DATA;
}
}
return 0;
}
static void test_is_sane(int index) {
struct item {
unsigned int flg;
char *data;
int length;
int ret;
char *orig_test;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { IS_SPC_F, " ", -1, 1, " " },
/* 1*/ { IS_SPC_F, "\000", 1, 0, " " },
/* 2*/ { IS_HSH_F, "#", -1, 1, "#" },
/* 3*/ { IS_HSH_F, " ", -1, 0, "#" },
/* 4*/ { IS_PLS_F, "+", -1, 1, "+" },
/* 5*/ { IS_PLS_F, " ", -1, 0, "+" },
/* 6*/ { IS_MNS_F, "-", -1, 1, "-" },
/* 7*/ { IS_MNS_F, " ", -1, 0, "-" },
/* 8*/ { IS_NUM_F, "0123456789", -1, 1, "0123456789" }, // NEON
/* 9*/ { IS_NUM_F, "0123456789 ", -1, 0, "0123456789" },
/* 10*/ { IS_NUM_F, "012345678A9", -1, 0, "0123456789" },
/* 11*/ { IS_UPO_F, "GHIJKLMNOPQRSTUVWYZ", -1, 1, "GHIJKLMNOPQRSTUVWYZ" },
/* 12*/ { IS_UPO_F, "FGHIJKLMNOPQRSTUVWYZ", -1, 0, "GHIJKLMNOPQRSTUVWYZ" },
/* 13*/ { IS_LWO_F, "ghijklmnopqrstuvwyz", -1, 1, "ghijklmnopqrstuvwyz" },
/* 14*/ { IS_LWO_F, "fghijklmnopqrstuvwyz", -1, 0, "ghijklmnopqrstuvwyz" },
/* 15*/ { IS_UHX_F, "ABCDEF", -1, 1, "ABCDEF" },
/* 16*/ { IS_UHX_F, "ABCDEf", -1, 0, "ABCDEF" },
/* 17*/ { IS_LHX_F, "abcdef", -1, 1, "abcdef" },
/* 18*/ { IS_LHX_F, "abcdeF", -1, 0, "abcdef" },
/* 19*/ { IS_UPR_F, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", -1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ" },
/* 20*/ { IS_UPR_F, "ABCDEFGHIJKLMNOPQRSTUVWXYZ ", -1, 0, "ABCDEFGHIJKLMNOPQRSTUVWXYZ" },
/* 21*/ { IS_UPR_F, "X", -1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ" },
/* 22*/ { IS_UPR_F, "x", -1, 0, "ABCDEFGHIJKLMNOPQRSTUVWXYZ" },
/* 23*/ { IS_LWR_F, "abcdefghijklmnopqrstuvwxyz", -1, 1, "abcdefghijklmnopqrstuvwxyz" },
/* 24*/ { IS_LWR_F, "abcdefghijklmnopqrstuvwxyz ", -1, 0, "abcdefghijklmnopqrstuvwxyz" },
/* 25*/ { IS_LWR_F, "x", -1, 1, "abcdefghijklmnopqrstuvwxyz" },
/* 26*/ { IS_LWR_F, "X", -1, 0, "abcdefghijklmnopqrstuvwxyz" },
/* 27*/ { IS_UX__F, "X", -1, 1, "X" },
/* 28*/ { IS_UX__F, "x", -1, 0, "X" },
/* 29*/ { IS_LX__F, "x", -1, 1, "x" },
/* 30*/ { IS_LX__F, "X", -1, 0, "x" },
/* 31*/ { IS_C82_F, "!\"%&'()*,./:;<=>?_", -1, 1, "!\"%&'()*,./:;<=>?_" }, // CSET82 punctuation less "-+"
/* 32*/ { IS_C82_F, "!\"%&'()*,./:;<=>?_ ", -1, 0, "!\"%&'()*,./:;<=>?_" },
/* 33*/ { IS_C82_F, "-", -1, 0, "!\"%&'()*,./:;<=>?_" },
/* 34*/ { IS_C82_F, "$", -1, 0, "!\"%&'()*,./:;<=>?_" },
/* 35*/ { IS_SIL_F, ".$/%", -1, 1, ".$/%" }, // SILVER punctuation less " -+"
/* 36*/ { IS_SIL_F, ".$/% " , -1, 0, ".$/%" },
/* 37*/ { IS_SIL_F, "-", -1, 0, ".$/%" },
/* 38*/ { IS_CLI_F, "$:/.", -1, 1, "$:/." }, // CALCIUM INNER punctuation less "-+"
/* 39*/ { IS_CLI_F, "$:/. ", -1, 0, "$:/." },
/* 40*/ { IS_CLI_F, "+", -1, 0, "$:/." },
/* 41*/ { IS_ARS_F, "ABCDEFGHJKLMNPRSTUVWXYZ", -1, 1, "ABCDEFGHJKLMNPRSTUVWXYZ" }, // ARSENIC uppercase
/* 42*/ { IS_ARS_F, "ABCDEFGHJKLMNPRSTUVWXYZ ", -1, 0, "ABCDEFGHJKLMNPRSTUVWXYZ" },
/* 43*/ { IS_ARS_F, "I", -1, 0, "ABCDEFGHJKLMNPRSTUVWXYZ" },
/* 44*/ { IS_ARS_F, "O", -1, 0, "ABCDEFGHJKLMNPRSTUVWXYZ" },
/* 45*/ { IS_NUM_F | IS_UHX_F, "0123456789ABCDEF", -1, 1, "0123456789ABCDEF" }, // SSET
/* 46*/ { IS_NUM_F | IS_UHX_F, "0123456789ABCDEf", -1, 0, "0123456789ABCDEF" },
/* 47*/ { IS_NUM_F | IS_PLS_F, "0123456789+", -1, 1, "0123456789+" }, // SODIUM_PLS
/* 48*/ { IS_NUM_F | IS_PLS_F, "0123456789+-", -1, 0, "0123456789+" },
/* 49*/ { IS_NUM_F | IS_UX__F, "0123456789X", -1, 1, "0123456789X" }, // ISBNX_SANE
/* 50*/ { IS_NUM_F | IS_UX__F, "0123456789x", -1, 0, "0123456789X" },
/* 51*/ { IS_NUM_F | IS_UX__F | IS_LX__F | IS_PLS_F, "0123456789Xx+", -1, 1, "0123456789Xx+" }, // ISBNX_ADDON_SANE
/* 52*/ { IS_NUM_F | IS_UX__F | IS_LX__F | IS_PLS_F, "0123456789Xx+Y", -1, 0, "0123456789Xx+" },
/* 53*/ { IS_NUM_F | IS_MNS_F, "0123456789-", -1, 1, "0123456789-" }, // SODIUM_MNS
/* 54*/ { IS_NUM_F | IS_MNS_F, "0123456789-+", -1, 0, "0123456789-" },
/* 55*/ { IS_C82_F | IS_MNS_F | IS_PLS_F | IS_NUM_F | IS_UPR_F | IS_LWR_F, "!\"%&'()*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz", -1, 1, "!\"%&'()*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" }, // CSET82
/* 56*/ { IS_C82_F | IS_MNS_F | IS_PLS_F | IS_NUM_F | IS_UPR_F | IS_LWR_F, " ", -1, 0, "!\"%&'()*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" },
/* 57*/ { IS_C82_F | IS_MNS_F | IS_PLS_F | IS_NUM_F | IS_UPR_F | IS_LWR_F, "#", -1, 0, "!\"%&'()*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" },
/* 58*/ { IS_C82_F | IS_MNS_F | IS_PLS_F | IS_NUM_F | IS_UPR_F | IS_LWR_F, "$", -1, 0, "!\"%&'()*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" },
/* 59*/ { IS_C82_F | IS_MNS_F | IS_PLS_F | IS_NUM_F | IS_UPR_F | IS_LWR_F, "@", -1, 0, "!\"%&'()*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" },
/* 60*/ { IS_LWR_F | IS_C82_F | IS_PLS_F | IS_MNS_F | IS_SPC_F, "abcdefghijklmnopqrstuvwxyz!\"%&'()*+,-./:;<=>?_ ", -1, 1, "abcdefghijklmnopqrstuvwxyz!\"%&'()*+,-./:;<=>?_ " }, // IS_ISOIEC_F
/* 61*/ { IS_LWR_F | IS_C82_F | IS_PLS_F | IS_MNS_F | IS_SPC_F, "abcdefghijklmnopqrstuvwxyz!\"%&'()*+,-./:;<=>?_ #", -1, 0, "abcdefghijklmnopqrstuvwxyz!\"%&'()*+,-./:;<=>?_ " },
/* 62*/ { IS_LWR_F | IS_C82_F | IS_PLS_F | IS_MNS_F | IS_SPC_F, "$", -1, 0, "abcdefghijklmnopqrstuvwxyz!\"%&'()*+,-./:;<=>?_ " },
/* 63*/ { IS_MNS_F | IS_SIL_F | IS_SPC_F | IS_PLS_F, "-. $/+%", -1, 1, "" },
/* 64*/ { IS_MNS_F | IS_SIL_F | IS_SPC_F | IS_PLS_F, "-. $/!+%", -1, 0, "" },
/* 65*/ { IS_NUM_F | IS_UPR_F | IS_MNS_F | IS_SIL_F | IS_SPC_F | IS_PLS_F, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%", -1, 1, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%" }, // SILVER
/* 66*/ { IS_NUM_F | IS_UPR_F | IS_MNS_F | IS_SIL_F | IS_SPC_F | IS_PLS_F, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%a", -1, 0, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%" },
/* 67*/ { IS_NUM_F | IS_ARS_F, "0123456789ABCDEFGHJKLMNPRSTUVWXYZ", -1, 1, "0123456789ABCDEFGHJKLMNPRSTUVWXYZ" }, // ARSENIC
/* 68*/ { IS_NUM_F | IS_ARS_F, "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ", -1, 0, "0123456789ABCDEFGHJKLMNPRSTUVWXYZ" },
/* 69*/ { IS_NUM_F | IS_ARS_F, "0123456789ABCDEFGHJKLMNPRSTUVWXYz", -1, 0, "0123456789ABCDEFGHJKLMNPRSTUVWXYZ" },
/* 70*/ { IS_NUM_F | IS_UPR_F | IS_LWR_F | IS_SPC_F | IS_HSH_F, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #", -1, 1, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #" }, // GDSET
/* 71*/ { IS_NUM_F | IS_UPR_F | IS_LWR_F | IS_SPC_F | IS_HSH_F, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #!", -1, 0, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #" },
/* 72*/ { IS_NUM_F | IS_MNS_F | IS_CLI_F | IS_PLS_F, "0123456789-$:/.+", -1, 1, "0123456789-$:/.+" }, // CALCIUM_INNER
/* 73*/ { IS_NUM_F | IS_MNS_F | IS_CLI_F | IS_PLS_F, "0123456789-$:/.+ ", -1, 0, "0123456789-$:/.+" },
/* 74*/ { IS_NUM_F | IS_MNS_F | IS_CLI_F | IS_PLS_F, "0123456789-$:/.+!", -1, 0, "0123456789-$:/.+" },
/* 75*/ { IS_NUM_F | IS_UPR_F, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", -1, 1, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, // KRSET
/* 76*/ { IS_NUM_F | IS_UPR_F, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYz", -1, 0, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" },
/* 77*/ { IS_NUM_F | IS_UPR_F | IS_SPC_F, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ ", -1, 1, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ " }, // RUBIDIUM
/* 78*/ { IS_NUM_F | IS_UPR_F | IS_SPC_F, "0123456789aBCDEFGHIJKLMNOPQRSTUVWXYZ ", -1, 0, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ " },
/* 79*/ { IS_NUM_F | IS_MNS_F | IS_UPR_F, "1234567890-ABCDEFGHIJKLMNOPQRSTUVWXYZ", -1, 1, "1234567890-ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, // SHKASUTSET
/* 80*/ { IS_NUM_F | IS_MNS_F | IS_UPR_F, "1234567890-ABCDEFGHIJKLMNOPQRSTUVWXYz", -1, 0, "1234567890-ABCDEFGHIJKLMNOPQRSTUVWXYZ" },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
testStart("test_is_sane");
for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = is_sane(data[i].flg, (const unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
if (data[i].orig_test[0]) {
int orig_ret = is_sane_orig(data[i].orig_test, (const unsigned char *) data[i].data, length);
if (orig_ret == 0) {
assert_nonzero(ret, "i:%d orig_ret %d, ret %d == 0\n", i, orig_ret, ret);
} else {
assert_zero(ret, "i:%d orig_ret %d, ret %d != 0\n", i, orig_ret, ret);
}
}
}
testFinish();
}
static void test_is_sane_lookup(int index) {
struct item {
char *test_string;
int test_length;
char *data;
int length;
int ret;
int posns[32];
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { "1234567", -1, "7654321357", -1, 1, { 6, 5, 4, 3, 2, 1, 0, 2, 4, 6 } },
/* 1*/ { "1234567", -1, "76543213578", -1, 0, {0} },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
int test_length;
int posns[32];
testStart("test_is_sane_lookup");
for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
test_length = data[i].test_length == -1 ? (int) strlen(data[i].test_string) : data[i].test_length;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = is_sane_lookup(data[i].test_string, test_length, (const unsigned char *) data[i].data, length, posns);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
if (ret) {
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]);
}
}
}
testFinish();
}
static void test_is_valid_utf8(int index) {
struct item {
char *data;
int length;
int ret;
char *comment;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { "", -1, 1, "" },
/* 1*/ { "abcdefghijklmnopqrstuvwxyz", -1, 1, "" },
/* 2*/ { "éa", -1, 1, "" },
/* 3*/ { "a\000b", 3, 1, "Embedded nul" },
/* 4*/ { "\357\273\277a", -1, 1, "Bom" },
/* 5*/ { "a\xC2", -1, 0, "Missing 2nd byte" },
/* 6*/ { "a\200b", -1, 0, "Orphan continuation 0x80" },
/* 7*/ { "\300\201", -1, 0, "Overlong 0xC081" },
/* 8*/ { "\355\240\200", -1, 0, "Surrogate 0xEDA080" },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
testStart("test_is_valid_utf8");
for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = is_valid_utf8((const unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
}
testFinish();
}
static void test_utf8_to_unicode(int index, int debug) {
struct item {
@ -142,45 +366,6 @@ static void test_set_height(int index, int debug) {
testFinish();
}
static void test_is_valid_utf8(int index) {
struct item {
char *data;
int length;
int ret;
char *comment;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { "", -1, 1, "" },
/* 1*/ { "abcdefghijklmnopqrstuvwxyz", -1, 1, "" },
/* 2*/ { "éa", -1, 1, "" },
/* 3*/ { "a\000b", 3, 1, "Embedded nul" },
/* 4*/ { "\357\273\277a", -1, 1, "Bom" },
/* 5*/ { "a\xC2", -1, 0, "Missing 2nd byte" },
/* 6*/ { "a\200b", -1, 0, "Orphan continuation 0x80" },
/* 7*/ { "\300\201", -1, 0, "Overlong 0xC081" },
/* 8*/ { "\355\240\200", -1, 0, "Surrogate 0xEDA080" },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
testStart("test_is_valid_utf8");
for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = is_valid_utf8((const unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
}
testFinish();
}
static void test_debug_test_codeword_dump_int(int index, int debug) {
struct item {
@ -217,9 +402,11 @@ static void test_debug_test_codeword_dump_int(int index, int debug) {
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_is_sane", test_is_sane, 1, 0, 0 },
{ "test_is_sane_lookup", test_is_sane_lookup, 1, 0, 0 },
{ "test_is_valid_utf8", test_is_valid_utf8, 1, 0, 0 },
{ "test_utf8_to_unicode", test_utf8_to_unicode, 1, 0, 1 },
{ "test_set_height", test_set_height, 1, 0, 1 },
{ "test_is_valid_utf8", test_is_valid_utf8, 1, 0, 0 },
{ "test_debug_test_codeword_dump_int", test_debug_test_codeword_dump_int, 1, 0, 1 },
};

View file

@ -146,7 +146,7 @@ static void test_print(int index, int generate, int debug) {
ret = testUtilCmpBins(symbol->outfile, expected_file);
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
if (index == -1) assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
}
ZBarcode_Delete(symbol);

View file

@ -62,7 +62,7 @@ static void test_csv(int index, int debug) {
assert_nonnull(fd, "fopen(%s) == NULL", csvfile);
while (fgets(buffer, sizeof(buffer), fd) != NULL) {
char *b;
const char *b;
struct zint_symbol *symbol;
lc++;

View file

@ -501,7 +501,7 @@ static void test_cap_compliant_height() {
testStart("test_cap_compliant_height");
for (symbol_id = 1; symbol_id <= BARCODE_RMQR; symbol_id++) {
for (symbol_id = 1; symbol_id <= BARCODE_LAST; symbol_id++) {
if (!ZBarcode_ValidID(symbol_id)) continue;
ret = ZBarcode_Cap(symbol_id, ZINT_CAP_COMPLIANT_HEIGHT);

View file

@ -31,7 +31,7 @@
#include "testcommon.h"
STATIC_UNLESS_ZINT_TEST int quiet_zones(const struct zint_symbol *symbol, const int hide_text,
STATIC_UNLESS_ZINT_TEST int out_quiet_zones(const struct zint_symbol *symbol, const int hide_text,
float *left, float *right, float *top, float *bottom);
static void test_quiet_zones(void) {
@ -42,11 +42,11 @@ static void test_quiet_zones(void) {
testStart("test_quiet_zones");
for (i = BARCODE_CODE11; i <= BARCODE_RMQR; i++) {
for (i = 1; i <= BARCODE_LAST; i++) {
if (!ZBarcode_ValidID(i)) continue;
symbol.symbology = i;
symbol.output_options = BARCODE_QUIET_ZONES;
ret = quiet_zones(&symbol, hide_text, &left, &right, &top, &bottom);
ret = out_quiet_zones(&symbol, hide_text, &left, &right, &top, &bottom);
if (i != BARCODE_FLAT) { // Only one which isn't marked as done
assert_nonzero(ret, "i:%d %s not done\n", i, testUtilBarcodeName(i));
}

View file

@ -319,6 +319,107 @@ static void test_encode(int index, int generate, int debug) {
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(int index, int debug) {
struct item {
int symbology;
int option_2;
char *data;
int ret;
int expected_rows;
int expected_width;
char *comment;
};
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" },
};
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 (index != -1 && i != index) 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, (unsigned char *) 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(remove(symbol->outfile), "i:%d remove(%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 (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, has_index, has_generate, has_debug */
@ -326,6 +427,7 @@ int main(int argc, char *argv[]) {
{ "test_hrt", test_hrt, 1, 0, 1 },
{ "test_input", test_input, 1, 0, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_perf", test_perf, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -385,6 +385,33 @@ static void test_wpng_error_handler(void) {
testFinish();
}
// Check compliant height printable for max CODABLOCKF with 44 rows * ((62 cols) * 0.55 + 3)) = 1632.4
static void test_large_compliant_height(void) {
int ret;
struct zint_symbol *symbol = NULL;
const char pattern[] = { "1" };
const int codablockf_max = 2726;
char data_buf[2726 + 1];
testStart("test_large_compliant_height");
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_CODABLOCKF;
symbol->output_options |= COMPLIANT_HEIGHT;
testUtilStrCpyRepeat(data_buf, pattern, codablockf_max);
assert_equal(codablockf_max, (int) strlen(data_buf), "length %d != strlen(data_buf) %d\n", codablockf_max, (int) strlen(data_buf));
ret = ZBarcode_Encode_and_Print(symbol, (const unsigned char *) data_buf, codablockf_max, 0);
assert_zero(ret, "ZBarcode_Encode_and_Print ret %d != 0 (%s)\n", ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "remove(%s) != 0\n", symbol->outfile);
ZBarcode_Delete(symbol);
testFinish();
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
@ -392,6 +419,7 @@ int main(int argc, char *argv[]) {
{ "test_print", test_print, 1, 1, 1 },
{ "test_outfile", test_outfile, 0, 0, 0 },
{ "test_wpng_error_handler", test_wpng_error_handler, 0, 0, 0 },
{ "test_large_compliant_height", test_large_compliant_height, 0, 0, 0 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -59,16 +59,18 @@ static void test_large(int index, int debug) {
/* 9*/ { BARCODE_RM4SCC, "1", 51, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 10*/ { BARCODE_JAPANPOST, "1", 20, 0, 3, 133 },
/* 11*/ { BARCODE_JAPANPOST, "1", 21, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 12*/ { BARCODE_KOREAPOST, "1", 6, 0, 1, 162 },
/* 13*/ { BARCODE_KOREAPOST, "1", 7, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 14*/ { BARCODE_PLANET, "1", 13, 0, 2, 143 },
/* 15*/ { BARCODE_PLANET, "1", 14, ZINT_WARN_NONCOMPLIANT, 2, 153 },
/* 16*/ { BARCODE_PLANET, "1", 38, ZINT_WARN_NONCOMPLIANT, 2, 393 },
/* 17*/ { BARCODE_PLANET, "1", 39, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 18*/ { BARCODE_KIX, "1", 18, 0, 3, 143 },
/* 19*/ { BARCODE_KIX, "1", 19, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 20*/ { BARCODE_DAFT, "D", 50, 0, 3, 99 },
/* 21*/ { BARCODE_DAFT, "D", 51, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 12*/ { BARCODE_JAPANPOST, "A", 10, 0, 3, 133 },
/* 13*/ { BARCODE_JAPANPOST, "A", 11, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 14*/ { BARCODE_KOREAPOST, "1", 6, 0, 1, 162 },
/* 15*/ { BARCODE_KOREAPOST, "1", 7, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 16*/ { BARCODE_PLANET, "1", 13, 0, 2, 143 },
/* 17*/ { BARCODE_PLANET, "1", 14, ZINT_WARN_NONCOMPLIANT, 2, 153 },
/* 18*/ { BARCODE_PLANET, "1", 38, ZINT_WARN_NONCOMPLIANT, 2, 393 },
/* 19*/ { BARCODE_PLANET, "1", 39, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 20*/ { BARCODE_KIX, "1", 18, 0, 3, 143 },
/* 21*/ { BARCODE_KIX, "1", 19, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 22*/ { BARCODE_DAFT, "D", 100, 0, 3, 199 },
/* 23*/ { BARCODE_DAFT, "D", 101, ZINT_ERROR_TOO_LONG, -1, -1 },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
@ -237,27 +239,31 @@ static void test_input(int index, int debug) {
/* 17*/ { BARCODE_RM4SCC, -1, 0, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, 3, 299, 8 },
/* 18*/ { BARCODE_RM4SCC, -1, 0, "a", 0, 3, 19, 8 }, // Converts to upper
/* 19*/ { BARCODE_RM4SCC, -1, 0, ",", ZINT_ERROR_INVALID_DATA, -1, -1, -1 },
/* 20*/ { BARCODE_JAPANPOST, -1, 0, "1234567890-ABCDEFGH", 0, 3, 133, 8 },
/* 21*/ { BARCODE_JAPANPOST, -1, 0, "a", 0, 3, 133, 8 }, // Converts to upper
/* 22*/ { BARCODE_JAPANPOST, -1, 0, ",", ZINT_ERROR_INVALID_DATA, -1, -1, -1 },
/* 23*/ { BARCODE_KOREAPOST, -1, 0, "123456", 0, 1, 167, 50 },
/* 24*/ { BARCODE_KOREAPOST, -1, 0, "A", ZINT_ERROR_INVALID_DATA, -1, -1, -1 },
/* 25*/ { BARCODE_PLANET, -1, 0, "12345678901", 0, 2, 123, 12 },
/* 26*/ { BARCODE_PLANET, -1, 0, "1234567890123", 0, 2, 143, 12 },
/* 27*/ { BARCODE_PLANET, -1, 0, "0", ZINT_WARN_NONCOMPLIANT, 2, 23, 12 },
/* 28*/ { BARCODE_PLANET, -1, 0, "1234567890", ZINT_WARN_NONCOMPLIANT, 2, 113, 12 },
/* 29*/ { BARCODE_PLANET, -1, 0, "123456789012", ZINT_WARN_NONCOMPLIANT, 2, 133, 12 },
/* 30*/ { BARCODE_PLANET, -1, 0, "12345678901234", ZINT_WARN_NONCOMPLIANT, 2, 153, 12 },
/* 31*/ { BARCODE_PLANET, -1, 0, "1234567890A", ZINT_ERROR_INVALID_DATA, -1, -1, -1 },
/* 32*/ { BARCODE_KIX, -1, 0, "0123456789ABCDEFGH", 0, 3, 143, 8 },
/* 33*/ { BARCODE_KIX, -1, 0, "a", 0, 3, 7, 8 }, // Converts to upper
/* 34*/ { BARCODE_KIX, -1, 0, ",", ZINT_ERROR_INVALID_DATA, -1, -1, -1 },
/* 35*/ { BARCODE_DAFT, -1, 0, "DAFT", 0, 3, 7, 8 },
/* 36*/ { BARCODE_DAFT, -1, 0, "a", 0, 3, 1, 8 }, // Converts to upper
/* 37*/ { BARCODE_DAFT, -1, 0, "B", ZINT_ERROR_INVALID_DATA, -1, -1, -1 },
/* 38*/ { BARCODE_DAFT, -1, 1.9, "DAFT", 0, 3, 7, 2 },
/* 39*/ { BARCODE_DAFT, 500, 0.9, "DAFT", 0, 3, 7, 2 }, // 50% ratio
/* 40*/ { BARCODE_DAFT, 500, 0.4, "DAFT", 0, 3, 7, 8 }, // 50% ratio
/* 20*/ { BARCODE_JAPANPOST, -1, 0, "1234567890-ABCD", 0, 3, 133, 8 }, // 19 symbol chars
/* 21*/ { BARCODE_JAPANPOST, -1, 0, "1234567890-ABCD1", 0, 3, 133, 8 }, // 20 symbol chars
/* 22*/ { BARCODE_JAPANPOST, -1, 0, "1234567890-ABCDE", ZINT_ERROR_TOO_LONG, -1, -1, -1 }, // 21 symbol chars
/* 23*/ { BARCODE_JAPANPOST, -1, 0, "1234567890-ABCD12", ZINT_ERROR_TOO_LONG, -1, -1, -1 }, // 21 symbol chars
/* 24*/ { BARCODE_JAPANPOST, -1, 0, "1234567890ABCDE", 0, 3, 133, 8 }, // 20 symbol chars
/* 25*/ { BARCODE_JAPANPOST, -1, 0, "a", 0, 3, 133, 8 }, // Converts to upper
/* 26*/ { BARCODE_JAPANPOST, -1, 0, ",", ZINT_ERROR_INVALID_DATA, -1, -1, -1 },
/* 27*/ { BARCODE_KOREAPOST, -1, 0, "123456", 0, 1, 167, 50 },
/* 28*/ { BARCODE_KOREAPOST, -1, 0, "A", ZINT_ERROR_INVALID_DATA, -1, -1, -1 },
/* 29*/ { BARCODE_PLANET, -1, 0, "12345678901", 0, 2, 123, 12 },
/* 30*/ { BARCODE_PLANET, -1, 0, "1234567890123", 0, 2, 143, 12 },
/* 31*/ { BARCODE_PLANET, -1, 0, "0", ZINT_WARN_NONCOMPLIANT, 2, 23, 12 },
/* 32*/ { BARCODE_PLANET, -1, 0, "1234567890", ZINT_WARN_NONCOMPLIANT, 2, 113, 12 },
/* 33*/ { BARCODE_PLANET, -1, 0, "123456789012", ZINT_WARN_NONCOMPLIANT, 2, 133, 12 },
/* 34*/ { BARCODE_PLANET, -1, 0, "12345678901234", ZINT_WARN_NONCOMPLIANT, 2, 153, 12 },
/* 35*/ { BARCODE_PLANET, -1, 0, "1234567890A", ZINT_ERROR_INVALID_DATA, -1, -1, -1 },
/* 36*/ { BARCODE_KIX, -1, 0, "0123456789ABCDEFGH", 0, 3, 143, 8 },
/* 37*/ { BARCODE_KIX, -1, 0, "a", 0, 3, 7, 8 }, // Converts to upper
/* 38*/ { BARCODE_KIX, -1, 0, ",", ZINT_ERROR_INVALID_DATA, -1, -1, -1 },
/* 39*/ { BARCODE_DAFT, -1, 0, "DAFT", 0, 3, 7, 8 },
/* 40*/ { BARCODE_DAFT, -1, 0, "a", 0, 3, 1, 8 }, // Converts to upper
/* 41*/ { BARCODE_DAFT, -1, 0, "B", ZINT_ERROR_INVALID_DATA, -1, -1, -1 },
/* 42*/ { BARCODE_DAFT, -1, 1.9, "DAFT", 0, 3, 7, 2 },
/* 43*/ { BARCODE_DAFT, 500, 0.9, "DAFT", 0, 3, 7, 2 }, // 50% ratio
/* 44*/ { BARCODE_DAFT, 500, 0.4, "DAFT", 0, 3, 7, 8 }, // 50% ratio
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
@ -329,60 +335,95 @@ static void test_encode(int index, int generate, int debug) {
"101010101010101010101010101010101010101010101010101010101010101010101010101"
"000010100000100010001000100000101010100000100000100000101000100010001010001"
},
/* 6*/ { BARCODE_JAPANPOST, "15400233-16-4-205", 0, 3, 133, "Zip/Barcode Manual p.6 1st example; verified manually against tec-it",
/* 6*/ { BARCODE_RM4SCC, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, 3, 299, "Verified manually against tec-it",
"10000010100000101000001010000010100000101000001010001000100010001000100010001000100010001000100010001010000010100000101000001010000010100000101000100000101000001010000010100000101000001010000010100010001000100010001000100010001000100010001000101000001010000010100000101000001010000010100000101000001"
"10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"00000010100010001000101000100000101000100010100000000010100010001000101000100000101000100010100000000010100010001000101000100000101000100010100000000010100010001000101000100000101000100010100000000010100010001000101000100000101000100010100000000010100010001000101000100000101000100010100000101000001"
},
/* 7*/ { BARCODE_JAPANPOST, "15400233-16-4-205", 0, 3, 133, "Zip/Barcode Manual p.6 1st example; verified manually against tec-it",
"1000101000100010101000100000100000100010001010001010001000101000001010001000101000001000100010100000100010000010000010000010001010001"
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"1010101000100010100010100000100000101000101000101000001000101000100010001000100010001000101000100000100010001000001000001000100010101"
},
/* 7*/ { BARCODE_JAPANPOST, "350110622-1A308", 0, 3, 133, "Zip/Barcode Manual p.6 2nd example; verified manually against tec-it",
/* 8*/ { BARCODE_JAPANPOST, "350110622-1A308", 0, 3, 133, "Zip/Barcode Manual p.6 2nd example; verified manually against tec-it",
"1000001010100010100000101000101000100000001010100010100010001000101000001000100000001010100000100010000010000010000010000010100010001"
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"1010101000100010100000101000101000100000100010101000101000001000101000100000100000101000100000001010001000001000001000001000100010101"
},
/* 8*/ { BARCODE_JAPANPOST, "12345671-2-3", 0, 3, 133, "Verified manually against tec-it",
/* 9*/ { BARCODE_JAPANPOST, "12345671-2-3", 0, 3, 133, "Verified manually against tec-it",
"1000101000100010001010101000100010001010101000101000001000100010001000001010000010000010000010000010000010000010000010000010100010001"
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"1010101000101000101000100010100010100010001010101000001000101000001000101000001000001000001000001000001000001000001000001000100010101"
},
/* 9*/ { BARCODE_KOREAPOST, "010230", 0, 1, 167, "Verified manually against tec-it",
/* 10*/ { BARCODE_JAPANPOST, "1234567BCDEFG", 0, 3, 133, "Verified manually against tec-it",
"1000101000100010001010101000100010001010101000001000101000001000100010001000001010001000101000001000100010001000001010000010101000001"
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"1010101000101000101000100010100010100010001010100000101000100000101000100000101000100000100010100000100010100000100010001000100010101"
},
/* 11*/ { BARCODE_JAPANPOST, "8901234HIJKLM", 0, 3, 133, "Verified manually against tec-it",
"1000100010001010100000101000100010001010101000001000101000001000100010001000001010000010100000000010101000000010100010000010100000001"
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"1010001010001010100000101000101000101000100010100000001010100000001010100000001010100000100000100000101000100000101000001000000010101"
},
/* 12*/ { BARCODE_JAPANPOST, "0987654NOPQRS", 0, 3, 133, "Verified manually against tec-it",
"1000100000001010100010101000001010100010101000000010001010000010101000000010100010000010001010000010101000000010100010000010100000001"
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"1010100000001010001010001010100010100010100010100000101000100000100010100000100010100000100010100000001010100000001010001000001000101"
},
/* 13*/ { BARCODE_JAPANPOST, "3210987TUVWXY", 0, 3, 133, "Verified manually against tec-it",
"1000001010100010101000100000001010100010101000000010001010100000100000100000101000100000100010100000001010100000101000000010000010001"
"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"1010101000101000101000100000001010001010001010100000001010001000100000001000101000001000101000001000101000001000100010001000100000101"
},
/* 14*/ { BARCODE_KOREAPOST, "010230", 0, 1, 167, "Verified manually against tec-it",
"10001000100000000000100010000000000010001000100000001000000010001000100010001000100000000000100000000001000100010001000100010001000000000001000000010001000000010001000"
},
/* 10*/ { BARCODE_KOREAPOST, "923457", 0, 1, 168, "Verified manually against tec-it",
/* 15*/ { BARCODE_KOREAPOST, "923457", 0, 1, 168, "Verified manually against tec-it",
"000010001000100000001000100000001000000010001000000010001000000010001000100000000000100010001000000010000000100010001000100010000000100000001000100010001000000000001000"
},
/* 11*/ { BARCODE_PLANET, "4012345235636", 0, 2, 143, "USPS Publication 197 (2004) Exhibit 4; verified manually against tec-it",
/* 16*/ { BARCODE_PLANET, "4012345235636", 0, 2, 143, "USPS Publication 197 (2004) Exhibit 4; verified manually against tec-it",
"10100010100000001010101010100000101000100010100000101000101000100010001010100010001010000010100010001010000010101010000010100000101010000010101"
"10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
/* 12*/ { BARCODE_PLANET, "40123452356", 0, 2, 123, "Verified manually against tec-it",
/* 17*/ { BARCODE_PLANET, "40123452356", 0, 2, 123, "Verified manually against tec-it",
"101000101000000010101010101000001010001000101000001010001010001000100010101000100010100000101000100010100000101010001000101"
"101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
/* 13*/ { BARCODE_PLANET, "5020140235635", 0, 2, 143, "USPS Publication 197 (2004) Exhibit 6; verified manually against tec-it",
/* 18*/ { BARCODE_PLANET, "5020140235635", 0, 2, 143, "USPS Publication 197 (2004) Exhibit 6; verified manually against tec-it",
"10100010001000001010101010001000000010101010101000001000101000000010101010100010001010000010100010001010000010101010000010100010001010001010001"
"10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
/* 14*/ { BARCODE_KIX, "2500GG30250", 0, 3, 87, "PostNL Handleiding KIX code Section 2.1 Example 1",
/* 19*/ { BARCODE_KIX, "2500GG30250", 0, 3, 87, "PostNL Handleiding KIX code Section 2.1 Example 1",
"000010100000101000001010000010100010100000101000000010100000101000001010000010100000101"
"101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"001010001010000000001010000010101000100010001000100000100000101000101000101000000000101"
},
/* 15*/ { BARCODE_KIX, "2130VA80430", 0, 3, 87, "PostNL Handleiding KIX code Section 2.1 Example 2",
/* 20*/ { BARCODE_KIX, "2130VA80430", 0, 3, 87, "PostNL Handleiding KIX code Section 2.1 Example 2",
"000010100000101000001010000010101010000000100010001000100000101000001010000010100000101"
"101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"001010000010001010000010000010100010001010001000001010000000101010001000100000100000101"
},
/* 16*/ { BARCODE_KIX, "1231GF156X2", 0, 3, 87, "PostNL Handleiding KIX code Section 2.1 Example 3",
/* 21*/ { BARCODE_KIX, "1231GF156X2", 0, 3, 87, "PostNL Handleiding KIX code Section 2.1 Example 3",
"000010100000101000001010000010100010100000101000000010100000101000100010101000000000101"
"101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"001000100010100010000010001000101000100010000010001000101010000000001010100000100010100"
},
/* 17*/ { BARCODE_KIX, "1231FZ13Xhs", 0, 3, 87, "PostNL Handleiding KIX code Section 2.1 Example 4",
/* 22*/ { BARCODE_KIX, "1231FZ13Xhs", 0, 3, 87, "PostNL Handleiding KIX code Section 2.1 Example 4",
"000010100000101000001010000010100010100010100000000010100000101010100000001010001000100"
"101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"001000100010100010000010001000101000001010100000001000101000001010000010101000001000100"
},
/* 18*/ { BARCODE_DAFT, "DAFTTFADFATDTATFT", 0, 3, 33, "Verified manually against tec-it",
/* 23*/ { BARCODE_KIX, "1234567890ABCDEFGH", 0, 3, 143, "Verified manually against tec-it",
"00001010000010100000101000001010000010100010001000100010001000100010001000001010001000100010001000101000001010000010100000101000001010000010100"
"10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"00100010001010001000001010001000101000000000101000100010001010001000001000001010100010001010000000001010001000100010100010000010100010001010000"
},
/* 24*/ { BARCODE_KIX, "IJKLMNOPQRSTUVWXYZ", 0, 3, 143, "Verified manually against tec-it",
"10000010100000101000001010000010100000101000001010001000100010001000100010001000100010001000100010100000101000001010000010100000101000001010000"
"10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
"00001010001000100010100010000010100010001010000000001010001000100010100010000010100010001010000000001010001000100010100010000010100010001010000"
},
/* 25*/ { BARCODE_DAFT, "DAFTTFADFATDTATFT", 0, 3, 33, "Verified manually against tec-it",
"001010000010100010100000001000100"
"101010101010101010101010101010101"
"100010000010001010000010000000100"
@ -445,6 +486,106 @@ static void test_encode(int index, int generate, int debug) {
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(int index, int debug) {
struct item {
int symbology;
int option_2;
char *data;
int ret;
int expected_rows;
int expected_width;
char *comment;
};
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" },
};
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 (index != -1 && i != index) 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, (unsigned char *) 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(remove(symbol->outfile), "i:%d remove(%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 (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, has_index, has_generate, has_debug */
@ -453,6 +594,7 @@ int main(int argc, char *argv[]) {
{ "test_japanpost", test_japanpost, 1, 0, 1 },
{ "test_input", test_input, 1, 0, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_perf", test_perf, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -2518,7 +2518,9 @@ static void test_height(int index, int generate, int debug) {
#include <time.h>
#define TEST_PERF_ITERATIONS 1000
#define TEST_PERF_ITER_MILLES 1
#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 for scaling
static void test_perf_scale(int index, int debug) {
@ -2547,28 +2549,38 @@ static void test_perf_scale(int index, int debug) {
"HIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567"
"890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcde"
"fghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
0, 40, 307, "960 chars, text/numeric" },
/* 1*/ { BARCODE_POSTNET, -1, -1, BARCODE_QUIET_ZONES, -1, -1, 0, 1.1, "12345", 0, 2, 63, "" },
/* 2*/ { BARCODE_ITF14, -1, 4, BARCODE_BIND, -1, -1, 61.8, 3.1, "12345", 0, 1, 135, "" },
0, 40, 307, "PDF417 960 chars, text/numeric, 1.3" },
/* 1*/ { BARCODE_POSTNET, -1, -1, BARCODE_QUIET_ZONES, -1, -1, 0, 1.1, "12345", 0, 2, 63, "POSTNET 5 chars, quiet zones, 1.1" },
/* 2*/ { BARCODE_ITF14, -1, 4, BARCODE_BIND, -1, -1, 61.8, 3.1, "12345", 0, 1, 135, "ITF14 bind 4, height 61.8, 3.1" },
};
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;
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 (index != -1 && i != index) continue;
diff_encode = diff_buffer = 0;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
struct zint_symbol *symbol = ZBarcode_Create();
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, data[i].output_options, data[i].data, -1, debug);
@ -2592,16 +2604,34 @@ static void test_perf_scale(int index, int debug) {
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(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
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);
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 (index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
if (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));
}
}

View file

@ -34,28 +34,28 @@
// Print out the log/alog tables for "backend/reedsol_logs.h"
static void print_logs(const char *name, int logmod, unsigned int *logt, unsigned int *alog, int u16, int last) {
int i;
int i;
const char *type = u16 ? "short" : "char";
const char *format = u16 ? " 0x%04X," : " 0x%02X,";
printf("static const unsigned %s logt_%s[%d] = {", type, name, logmod + 1);
for (i = 0; i < logmod + 1; i++) {
if (i % 16 == 0) printf("\n ");
printf(format, i ? logt[i] : 0);
}
printf("\n};\n");
printf("static const unsigned %s logt_%s[%d] = {", type, name, logmod + 1);
for (i = 0; i < logmod + 1; i++) {
if (i % 16 == 0) printf("\n ");
printf(format, i ? logt[i] : 0);
}
printf("\n};\n");
printf("static const unsigned %s alog_%s[%d] = {", type, name, logmod * 2);
for (i = 0; i < logmod; i++) {
if (i % 16 == 0) printf("\n ");
printf(format, alog[i]);
}
printf("static const unsigned %s alog_%s[%d] = {", type, name, logmod * 2);
for (i = 0; i < logmod; i++) {
if (i % 16 == 0) printf("\n ");
printf(format, alog[i]);
}
// Double antilog table
for (i = 0; i < logmod; i++) {
if (i % 16 == 0) printf("\n ");
printf(format, alog[i]);
}
printf("\n};\n");
printf("\n};\n");
if (!last) {
printf("\n");
}

View file

@ -330,6 +330,62 @@ static void test_fuzz(int index, int debug) {
testFinish();
}
static char TeleTable[128][16] = {
{ "31313131" }, { "1131313111" }, { "33313111" }, { "1111313131" },
{ "3111313111" }, { "11333131" }, { "13133131" }, { "111111313111" },
{ "31333111" }, { "1131113131" }, { "33113131" }, { "1111333111" },
{ "3111113131" }, { "1113133111" }, { "1311133111" }, { "111111113131" },
{ "3131113111" }, { "11313331" }, { "333331" }, { "111131113111" },
{ "31113331" }, { "1133113111" }, { "1313113111" }, { "1111113331" },
{ "31131331" }, { "113111113111" }, { "3311113111" }, { "1111131331" },
{ "311111113111" }, { "1113111331" }, { "1311111331" }, { "11111111113111" },
{ "31313311" }, { "1131311131" }, { "33311131" }, { "1111313311" },
{ "3111311131" }, { "11333311" }, { "13133311" }, { "111111311131" },
{ "31331131" }, { "1131113311" }, { "33113311" }, { "1111331131" },
{ "3111113311" }, { "1113131131" }, { "1311131131" }, { "111111113311" },
{ "3131111131" }, { "1131131311" }, { "33131311" }, { "111131111131" },
{ "3111131311" }, { "1133111131" }, { "1313111131" }, { "111111131311" },
{ "3113111311" }, { "113111111131" }, { "3311111131" }, { "111113111311" },
{ "311111111131" }, { "111311111311" }, { "131111111311" }, { "11111111111131" },
{ "3131311111" }, { "11313133" }, { "333133" }, { "111131311111" },
{ "31113133" }, { "1133311111" }, { "1313311111" }, { "1111113133" },
{ "313333" }, { "113111311111" }, { "3311311111" }, { "11113333" },
{ "311111311111" }, { "11131333" }, { "13111333" }, { "11111111311111" },
{ "31311133" }, { "1131331111" }, { "33331111" }, { "1111311133" },
{ "3111331111" }, { "11331133" }, { "13131133" }, { "111111331111" },
{ "3113131111" }, { "1131111133" }, { "33111133" }, { "111113131111" },
{ "3111111133" }, { "111311131111" }, { "131111131111" }, { "111111111133" },
{ "31311313" }, { "113131111111" }, { "3331111111" }, { "1111311313" },
{ "311131111111" }, { "11331313" }, { "13131313" }, { "11111131111111" },
{ "3133111111" }, { "1131111313" }, { "33111313" }, { "111133111111" },
{ "3111111313" }, { "111313111111" }, { "131113111111" }, { "111111111313" },
{ "313111111111" }, { "1131131113" }, { "33131113" }, { "11113111111111" },
{ "3111131113" }, { "113311111111" }, { "131311111111" }, { "111111131113" },
{ "3113111113" }, { "11311111111111" }, { "331111111111" }, { "111113111113" },
{ "31111111111111" }, { "111311111113" }, { "131111111113" },
{'1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'},
};
// Dummy to generate lengths table
static void test_generate_lens(int generate) {
int i;
if (!generate) {
return;
}
printf("static const char TeleLens[128] = {");
for (i = 0; i < 127; i++) {
if ((i % 16) == 0) {
printf("\n %2d,", (int) strlen(TeleTable[i]));
} else {
printf(" %2d,", (int) strlen(TeleTable[i]));
}
}
printf(" 16\n};\n");
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
@ -338,6 +394,7 @@ int main(int argc, char *argv[]) {
{ "test_input", test_input, 1, 0, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
{ "test_generate_lens", test_generate_lens, 0, 1, 0 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -92,7 +92,7 @@ static void test_pixel_plot(int index, int debug) {
char *tif = "out.tif";
char data_buf[65536];
char data_buf[ZINT_MAX_DATA_LEN * 2 + 1];
int have_tiffinfo = testUtilHaveTiffInfo();
int have_identify = testUtilHaveIdentify();

View file

@ -266,150 +266,154 @@ static void test_upca_input(int index, int debug) {
testFinish();
}
static void test_eanx_input(int index, int debug) {
static void test_eanx_input(int index, int generate, int debug) {
struct item {
int symbology;
char *data;
int ret;
char *ret_errtxt;
char *comment;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_EANX, "123456789012", 0 },
/* 1*/ { BARCODE_EANX, "12345678901A", ZINT_ERROR_INVALID_DATA },
/* 2*/ { BARCODE_EANX, "12345678901", 0 },
/* 3*/ { BARCODE_EANX, "1234567890128", 0 }, // EANX accepts CHK (treated as such if no leading zeroes required)
/* 4*/ { BARCODE_EANX, "1234567890120", ZINT_ERROR_INVALID_CHECK },
/* 5*/ { BARCODE_EANX, "123456789012+1", 0 },
/* 6*/ { BARCODE_EANX, "1234567890128+1", 0 },
/* 7*/ { BARCODE_EANX, "1234567890121+1", ZINT_ERROR_INVALID_CHECK },
/* 8*/ { BARCODE_EANX, "123456789012+12", 0 },
/* 9*/ { BARCODE_EANX, "1234567890128+12", 0 },
/* 10*/ { BARCODE_EANX, "1234567890122+12", ZINT_ERROR_INVALID_CHECK },
/* 11*/ { BARCODE_EANX, "12345678901234+12", ZINT_ERROR_TOO_LONG },
/* 12*/ { BARCODE_EANX, "123456789012345+12", ZINT_ERROR_TOO_LONG },
/* 13*/ { BARCODE_EANX, "1234567890123456+12", ZINT_ERROR_TOO_LONG },
/* 14*/ { BARCODE_EANX, "123456789012+123", 0 },
/* 15*/ { BARCODE_EANX, "1234567890128+123", 0 },
/* 16*/ { BARCODE_EANX, "1234567890123+123", ZINT_ERROR_INVALID_CHECK },
/* 17*/ { BARCODE_EANX, "12345678901234+123", ZINT_ERROR_TOO_LONG },
/* 18*/ { BARCODE_EANX, "123456789012345+123", ZINT_ERROR_TOO_LONG },
/* 19*/ { BARCODE_EANX, "123456789012+1234", 0 },
/* 20*/ { BARCODE_EANX, "1234567890128+1234", 0 },
/* 21*/ { BARCODE_EANX, "1234567890124+1234", ZINT_ERROR_INVALID_CHECK },
/* 22*/ { BARCODE_EANX, "12345678901234+1234", ZINT_ERROR_TOO_LONG },
/* 23*/ { BARCODE_EANX, "123456789012+12345", 0 },
/* 24*/ { BARCODE_EANX, "1234567890128+12345", 0 },
/* 25*/ { BARCODE_EANX, "12345678901234+12345", ZINT_ERROR_TOO_LONG },
/* 26*/ { BARCODE_EANX, "1234567890125+12345", ZINT_ERROR_INVALID_CHECK },
/* 27*/ { BARCODE_EANX, "123456789012+123456", ZINT_ERROR_TOO_LONG },
/* 28*/ { BARCODE_EANX, "1234567890128+123456", ZINT_ERROR_TOO_LONG },
/* 29*/ { BARCODE_EANX, "12345678901+123456", ZINT_ERROR_TOO_LONG },
/* 30*/ { BARCODE_EANX, "12345678901+1234567", ZINT_ERROR_TOO_LONG },
/* 31*/ { BARCODE_EANX, "1234567890+123456", ZINT_ERROR_TOO_LONG },
/* 32*/ { BARCODE_EANX, "1234567890+1234567", ZINT_ERROR_TOO_LONG },
/* 33*/ { BARCODE_EANX, "123456789+123456", ZINT_ERROR_TOO_LONG },
/* 34*/ { BARCODE_EANX, "123456789+1234567", ZINT_ERROR_TOO_LONG },
/* 35*/ { BARCODE_EANX, "12345678+123456", ZINT_ERROR_TOO_LONG },
/* 36*/ { BARCODE_EANX, "1234567+123456", ZINT_ERROR_TOO_LONG }, // EAN-8
/* 37*/ { BARCODE_EANX, "123456+123456", ZINT_ERROR_TOO_LONG },
/* 38*/ { BARCODE_EANX, "12345+123456", ZINT_ERROR_TOO_LONG },
/* 39*/ { BARCODE_EANX, "1234+123456", ZINT_ERROR_TOO_LONG },
/* 40*/ { BARCODE_EANX, "123+123456", ZINT_ERROR_TOO_LONG },
/* 41*/ { BARCODE_EANX, "12+123456", ZINT_ERROR_TOO_LONG },
/* 42*/ { BARCODE_EANX, "1+123456", ZINT_ERROR_TOO_LONG },
/* 43*/ { BARCODE_EANX, "1+12345678901234", ZINT_ERROR_TOO_LONG },
/* 44*/ { BARCODE_EANX, "1+12345", 0 },
/* 45*/ { BARCODE_EANX, "1+", 0 }, // EAN-2
/* 46*/ { BARCODE_EANX, "+1", 0 }, // EAN-8
/* 47*/ { BARCODE_EANX, "+", 0 }, // EAN-2
/* 48*/ { BARCODE_EANX, "1", 0 }, // EAN-2
/* 49*/ { BARCODE_EANX, "12", 0 }, // EAN-2
/* 50*/ { BARCODE_EANX, "123", 0 }, // EAN-5
/* 51*/ { BARCODE_EANX, "12345678901234", ZINT_ERROR_TOO_LONG },
/* 52*/ { BARCODE_EANX, "1234567890123A", ZINT_ERROR_INVALID_DATA },
/* 53*/ { BARCODE_EANX, "123456789012345", ZINT_ERROR_TOO_LONG },
/* 54*/ { BARCODE_EANX, "12345678901234A", ZINT_ERROR_INVALID_DATA },
/* 55*/ { BARCODE_EANX, "1234567890123456", ZINT_ERROR_TOO_LONG },
/* 56*/ { BARCODE_EANX, "12345678901234567", ZINT_ERROR_TOO_LONG },
/* 57*/ { BARCODE_EANX, "123456789012345678", ZINT_ERROR_TOO_LONG },
/* 58*/ { BARCODE_EANX, "1234567890123456789", ZINT_ERROR_TOO_LONG },
/* 59*/ { BARCODE_EANX_CHK, "1234567890128", 0 },
/* 60*/ { BARCODE_EANX_CHK, "1234567890126", ZINT_ERROR_INVALID_CHECK },
/* 61*/ { BARCODE_EANX_CHK, "123456789012A", ZINT_ERROR_INVALID_DATA },
/* 62*/ { BARCODE_EANX_CHK, "123456789012", 0 }, // Note: this is "0123456789012" with '2' happening to be the correct check digit
/* 63*/ { BARCODE_EANX_CHK, "123456789013", ZINT_ERROR_INVALID_CHECK },
/* 64*/ { BARCODE_EANX_CHK, "12345678901", ZINT_ERROR_INVALID_CHECK },
/* 65*/ { BARCODE_EANX_CHK, "12345678905", 0 },
/* 66*/ { BARCODE_EANX_CHK, "1234567890", ZINT_ERROR_INVALID_CHECK },
/* 67*/ { BARCODE_EANX_CHK, "123456789", ZINT_ERROR_INVALID_CHECK },
/* 68*/ { BARCODE_EANX_CHK, "12345678", ZINT_ERROR_INVALID_CHECK }, // EAN-8
/* 69*/ { BARCODE_EANX_CHK, "1234567", ZINT_ERROR_INVALID_CHECK },
/* 70*/ { BARCODE_EANX_CHK, "123456", ZINT_ERROR_INVALID_CHECK },
/* 71*/ { BARCODE_EANX_CHK, "12345", 0 }, // EAN-5
/* 72*/ { BARCODE_EANX_CHK, "1234", 0 },
/* 73*/ { BARCODE_EANX_CHK, "123", 0 },
/* 74*/ { BARCODE_EANX_CHK, "12", 0 }, // EAN-2
/* 75*/ { BARCODE_EANX_CHK, "1", 0 },
/* 76*/ { BARCODE_EANX_CHK, "123456789012+1", 0 },
/* 77*/ { BARCODE_EANX_CHK, "1234567890128+1", 0 },
/* 78*/ { BARCODE_EANX_CHK, "1234567890127+1", ZINT_ERROR_INVALID_CHECK },
/* 79*/ { BARCODE_EANX_CHK, "123456789012+12", 0 },
/* 80*/ { BARCODE_EANX_CHK, "1234567890128+12", 0 },
/* 81*/ { BARCODE_EANX_CHK, "1234567890129+12", ZINT_ERROR_INVALID_CHECK },
/* 82*/ { BARCODE_EANX_CHK, "123456789012+123", 0 },
/* 83*/ { BARCODE_EANX_CHK, "1234567890128+123", 0 },
/* 84*/ { BARCODE_EANX_CHK, "1234567890120+1234", ZINT_ERROR_INVALID_CHECK },
/* 85*/ { BARCODE_EANX_CHK, "123456789012+1234", 0 },
/* 86*/ { BARCODE_EANX_CHK, "1234567890128+1234", 0 },
/* 87*/ { BARCODE_EANX_CHK, "1234567890121+1234", ZINT_ERROR_INVALID_CHECK },
/* 88*/ { BARCODE_EANX_CHK, "123456789012+12345", 0 },
/* 89*/ { BARCODE_EANX_CHK, "1234567890128+12345", 0 },
/* 90*/ { BARCODE_EANX_CHK, "1234567890122+12345", ZINT_ERROR_INVALID_CHECK },
/* 91*/ { BARCODE_EANX_CHK, "1234567890122+1234A", ZINT_ERROR_INVALID_DATA },
/* 92*/ { BARCODE_EANX_CHK, "123456789012+123456", ZINT_ERROR_TOO_LONG },
/* 93*/ { BARCODE_EANX_CHK, "123456789012+12345A", ZINT_ERROR_INVALID_DATA },
/* 94*/ { BARCODE_EANX_CHK, "1234567890128+123456", ZINT_ERROR_TOO_LONG },
/* 95*/ { BARCODE_EANX_CHK, "12345678901+123456", ZINT_ERROR_TOO_LONG },
/* 96*/ { BARCODE_EANX_CHK, "12345678901+1234567", ZINT_ERROR_TOO_LONG },
/* 97*/ { BARCODE_EANX_CHK, "12345678901+12345", ZINT_ERROR_INVALID_CHECK },
/* 98*/ { BARCODE_EANX_CHK, "1234567890+12345", ZINT_ERROR_INVALID_CHECK },
/* 99*/ { BARCODE_EANX_CHK, "1234567890+123456", ZINT_ERROR_TOO_LONG },
/*100*/ { BARCODE_EANX_CHK, "123456789+12345", ZINT_ERROR_INVALID_CHECK },
/*101*/ { BARCODE_EANX_CHK, "12345678+12345", ZINT_ERROR_INVALID_CHECK }, // EAN-8
/*102*/ { BARCODE_EANX_CHK, "12345670+12345", 0 },
/*103*/ { BARCODE_EANX_CHK, "1234567+12345", ZINT_ERROR_INVALID_CHECK },
/*104*/ { BARCODE_EANX_CHK, "1234565+12345", 0 },
/*105*/ { BARCODE_EANX_CHK, "123456+12345", ZINT_ERROR_INVALID_CHECK },
/*106*/ { BARCODE_EANX_CHK, "123457+12345", 0 },
/*107*/ { BARCODE_EANX_CHK, "12345+12345", ZINT_ERROR_INVALID_CHECK },
/*108*/ { BARCODE_EANX_CHK, "12348+12345", 0 },
/*109*/ { BARCODE_EANX_CHK, "1234+12345", ZINT_ERROR_INVALID_CHECK },
/*110*/ { BARCODE_EANX_CHK, "1236+12345", 0 },
/*111*/ { BARCODE_EANX_CHK, "123+12345", 0 }, // 3 happens to be correct check digit
/*112*/ { BARCODE_EANX_CHK, "124+12345", ZINT_ERROR_INVALID_CHECK },
/*113*/ { BARCODE_EANX_CHK, "12+12345", ZINT_ERROR_INVALID_CHECK },
/*114*/ { BARCODE_EANX_CHK, "17+12345", 0 },
/*115*/ { BARCODE_EANX_CHK, "1+12345", ZINT_ERROR_INVALID_CHECK },
/*116*/ { BARCODE_EANX_CHK, "0+12345", 0 },
/*117*/ { BARCODE_EANX_CHK, "0+123456", ZINT_ERROR_TOO_LONG },
/*118*/ { BARCODE_EANX_CHK, "1+12345678901234", ZINT_ERROR_TOO_LONG },
/*119*/ { BARCODE_EANX_CHK, "0+12345678901234", ZINT_ERROR_TOO_LONG },
/*120*/ { BARCODE_EANX_CHK, "1+", 0 }, // EAN-2
/*121*/ { BARCODE_EANX_CHK, "+1", 0 }, // EAN-8
/*122*/ { BARCODE_EANX_CHK, "+", 0 }, // EAN-2
/*123*/ { BARCODE_EANX_CHK, "12345678901234", ZINT_ERROR_TOO_LONG },
/*124*/ { BARCODE_EANX_CHK, "1234567890123A", ZINT_ERROR_INVALID_DATA },
/*125*/ { BARCODE_EANX_CHK, "123456789012345", ZINT_ERROR_TOO_LONG },
/*126*/ { BARCODE_EANX_CHK, "1234567890123456", ZINT_ERROR_TOO_LONG },
/*127*/ { BARCODE_EANX_CHK, "12345678901234567", ZINT_ERROR_TOO_LONG },
/*128*/ { BARCODE_EANX_CHK, "123456789012345678", ZINT_ERROR_TOO_LONG },
/*129*/ { BARCODE_EANX_CHK, "1234567890123456789", ZINT_ERROR_TOO_LONG },
/* 0*/ { BARCODE_EANX, "123456789012", 0, "", "" },
/* 1*/ { BARCODE_EANX, "12345678901A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character in data (digits and \"+\" only)", "" },
/* 2*/ { BARCODE_EANX, "12345678901", 0, "", "" },
/* 3*/ { BARCODE_EANX, "1234567890128", 0, "", "EANX accepts CHK (treated as such if no leading zeroes required)" },
/* 4*/ { BARCODE_EANX, "1234567890120", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '0', expecting '8'", "" },
/* 5*/ { BARCODE_EANX, "123456789012+1", 0, "", "" },
/* 6*/ { BARCODE_EANX, "1234567890128+1", 0, "", "" },
/* 7*/ { BARCODE_EANX, "1234567890121+1", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '1', expecting '8'", "" },
/* 8*/ { BARCODE_EANX, "123456789012+12", 0, "", "" },
/* 9*/ { BARCODE_EANX, "1234567890128+12", 0, "", "" },
/* 10*/ { BARCODE_EANX, "1234567890122+12", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '2', expecting '8'", "" },
/* 11*/ { BARCODE_EANX, "12345678901234+12", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/* 12*/ { BARCODE_EANX, "123456789012345+12", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/* 13*/ { BARCODE_EANX, "1234567890123456+12", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/* 14*/ { BARCODE_EANX, "123456789012+123", 0, "", "" },
/* 15*/ { BARCODE_EANX, "1234567890128+123", 0, "", "" },
/* 16*/ { BARCODE_EANX, "1234567890123+123", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '3', expecting '8'", "" },
/* 17*/ { BARCODE_EANX, "12345678901234+123", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/* 18*/ { BARCODE_EANX, "123456789012345+123", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/* 19*/ { BARCODE_EANX, "123456789012+1234", 0, "", "" },
/* 20*/ { BARCODE_EANX, "1234567890128+1234", 0, "", "" },
/* 21*/ { BARCODE_EANX, "1234567890124+1234", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '4', expecting '8'", "" },
/* 22*/ { BARCODE_EANX, "12345678901234+1234", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/* 23*/ { BARCODE_EANX, "123456789012+12345", 0, "", "" },
/* 24*/ { BARCODE_EANX, "1234567890128+12345", 0, "", "" },
/* 25*/ { BARCODE_EANX, "12345678901234+12345", ZINT_ERROR_TOO_LONG, "Error 283: Input too long (19 character maximum)", "" },
/* 26*/ { BARCODE_EANX, "1234567890125+12345", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '5', expecting '8'", "" },
/* 27*/ { BARCODE_EANX, "123456789012+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 28*/ { BARCODE_EANX, "1234567890128+123456", ZINT_ERROR_TOO_LONG, "Error 283: Input too long (19 character maximum)", "" },
/* 29*/ { BARCODE_EANX, "12345678901+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 30*/ { BARCODE_EANX, "12345678901+1234567", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 31*/ { BARCODE_EANX, "1234567890+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 32*/ { BARCODE_EANX, "1234567890+1234567", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 33*/ { BARCODE_EANX, "123456789+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 34*/ { BARCODE_EANX, "123456789+1234567", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 35*/ { BARCODE_EANX, "12345678+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 36*/ { BARCODE_EANX, "1234567+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "EAN-8" },
/* 37*/ { BARCODE_EANX, "123456+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 38*/ { BARCODE_EANX, "12345+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 39*/ { BARCODE_EANX, "1234+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 40*/ { BARCODE_EANX, "123+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 41*/ { BARCODE_EANX, "12+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 42*/ { BARCODE_EANX, "1+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 43*/ { BARCODE_EANX, "1+12345678901234", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 44*/ { BARCODE_EANX, "1+12345", 0, "", "" },
/* 45*/ { BARCODE_EANX, "1+", 0, "", "EAN-2" },
/* 46*/ { BARCODE_EANX, "+1", 0, "", "EAN-8" },
/* 47*/ { BARCODE_EANX, "+", 0, "", "EAN-2" },
/* 48*/ { BARCODE_EANX, "1", 0, "", "EAN-2" },
/* 49*/ { BARCODE_EANX, "12", 0, "", "EAN-2" },
/* 50*/ { BARCODE_EANX, "123", 0, "", "EAN-5" },
/* 51*/ { BARCODE_EANX, "12345678901234", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/* 52*/ { BARCODE_EANX, "1234567890123A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character in data (digits and \"+\" only)", "" },
/* 53*/ { BARCODE_EANX, "123456789012345", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/* 54*/ { BARCODE_EANX, "12345678901234A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character in data (digits and \"+\" only)", "" },
/* 55*/ { BARCODE_EANX, "1234567890123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/* 56*/ { BARCODE_EANX, "12345678901234567", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/* 57*/ { BARCODE_EANX, "123456789012345678", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/* 58*/ { BARCODE_EANX, "1234567890123456789", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/* 59*/ { BARCODE_EANX_CHK, "1234567890128", 0, "", "" },
/* 60*/ { BARCODE_EANX_CHK, "1234567890126", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '6', expecting '8'", "" },
/* 61*/ { BARCODE_EANX_CHK, "123456789012A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character in data (digits and \"+\" only)", "" },
/* 62*/ { BARCODE_EANX_CHK, "123456789012", 0, "", "Note: this is '0123456789012' with '2' happening to be the correct check digit" },
/* 63*/ { BARCODE_EANX_CHK, "123456789013", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '3', expecting '2'", "" },
/* 64*/ { BARCODE_EANX_CHK, "12345678901", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '1', expecting '5'", "" },
/* 65*/ { BARCODE_EANX_CHK, "12345678905", 0, "", "" },
/* 66*/ { BARCODE_EANX_CHK, "1234567890", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '0', expecting '5'", "" },
/* 67*/ { BARCODE_EANX_CHK, "123456789", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '9', expecting '4'", "" },
/* 68*/ { BARCODE_EANX_CHK, "12345678", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '8', expecting '0'", "EAN-8" },
/* 69*/ { BARCODE_EANX_CHK, "1234567", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '7', expecting '5'", "" },
/* 70*/ { BARCODE_EANX_CHK, "123456", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '6', expecting '7'", "" },
/* 71*/ { BARCODE_EANX_CHK, "12345", 0, "", "EAN-5" },
/* 72*/ { BARCODE_EANX_CHK, "1234", 0, "", "" },
/* 73*/ { BARCODE_EANX_CHK, "123", 0, "", "" },
/* 74*/ { BARCODE_EANX_CHK, "12", 0, "", "EAN-2" },
/* 75*/ { BARCODE_EANX_CHK, "1", 0, "", "" },
/* 76*/ { BARCODE_EANX_CHK, "123456789012+1", 0, "", "" },
/* 77*/ { BARCODE_EANX_CHK, "1234567890128+1", 0, "", "" },
/* 78*/ { BARCODE_EANX_CHK, "1234567890127+1", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '7', expecting '8'", "" },
/* 79*/ { BARCODE_EANX_CHK, "123456789012+12", 0, "", "" },
/* 80*/ { BARCODE_EANX_CHK, "1234567890128+12", 0, "", "" },
/* 81*/ { BARCODE_EANX_CHK, "1234567890129+12", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '9', expecting '8'", "" },
/* 82*/ { BARCODE_EANX_CHK, "123456789012+123", 0, "", "" },
/* 83*/ { BARCODE_EANX_CHK, "1234567890128+123", 0, "", "" },
/* 84*/ { BARCODE_EANX_CHK, "1234567890120+1234", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '0', expecting '8'", "" },
/* 85*/ { BARCODE_EANX_CHK, "123456789012+1234", 0, "", "" },
/* 86*/ { BARCODE_EANX_CHK, "1234567890128+1234", 0, "", "" },
/* 87*/ { BARCODE_EANX_CHK, "1234567890121+1234", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '1', expecting '8'", "" },
/* 88*/ { BARCODE_EANX_CHK, "123456789012+12345", 0, "", "" },
/* 89*/ { BARCODE_EANX_CHK, "1234567890128+12345", 0, "", "" },
/* 90*/ { BARCODE_EANX_CHK, "1234567890122+12345", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '2', expecting '8'", "" },
/* 91*/ { BARCODE_EANX_CHK, "1234567890122+1234A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character in data (digits and \"+\" only)", "" },
/* 92*/ { BARCODE_EANX_CHK, "123456789012+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 93*/ { BARCODE_EANX_CHK, "123456789012+12345A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character in data (digits and \"+\" only)", "" },
/* 94*/ { BARCODE_EANX_CHK, "1234567890128+123456", ZINT_ERROR_TOO_LONG, "Error 283: Input too long (19 character maximum)", "" },
/* 95*/ { BARCODE_EANX_CHK, "12345678901+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 96*/ { BARCODE_EANX_CHK, "12345678901+1234567", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 97*/ { BARCODE_EANX_CHK, "12345678901+12345", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '1', expecting '5'", "" },
/* 98*/ { BARCODE_EANX_CHK, "1234567890+12345", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '0', expecting '5'", "" },
/* 99*/ { BARCODE_EANX_CHK, "1234567890+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/*100*/ { BARCODE_EANX_CHK, "123456789+12345", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '9', expecting '4'", "" },
/*101*/ { BARCODE_EANX_CHK, "12345678+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '8', expecting '0'", "EAN-8" },
/*102*/ { BARCODE_EANX_CHK, "12345670+12345", 0, "", "" },
/*103*/ { BARCODE_EANX_CHK, "1234567+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '7', expecting '5'", "" },
/*104*/ { BARCODE_EANX_CHK, "1234565+12345", 0, "", "" },
/*105*/ { BARCODE_EANX_CHK, "123456+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '6', expecting '7'", "" },
/*106*/ { BARCODE_EANX_CHK, "123457+12345", 0, "", "" },
/*107*/ { BARCODE_EANX_CHK, "12345+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '5', expecting '8'", "" },
/*108*/ { BARCODE_EANX_CHK, "12348+12345", 0, "", "" },
/*109*/ { BARCODE_EANX_CHK, "1234+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '4', expecting '6'", "" },
/*110*/ { BARCODE_EANX_CHK, "1236+12345", 0, "", "" },
/*111*/ { BARCODE_EANX_CHK, "123+12345", 0, "", "3 happens to be correct check digit" },
/*112*/ { BARCODE_EANX_CHK, "124+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '4', expecting '3'", "" },
/*113*/ { BARCODE_EANX_CHK, "12+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '2', expecting '7'", "" },
/*114*/ { BARCODE_EANX_CHK, "17+12345", 0, "", "" },
/*115*/ { BARCODE_EANX_CHK, "1+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '1', expecting '0'", "" },
/*116*/ { BARCODE_EANX_CHK, "0+12345", 0, "", "" },
/*117*/ { BARCODE_EANX_CHK, "0+123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/*118*/ { BARCODE_EANX_CHK, "1+12345678901234", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/*119*/ { BARCODE_EANX_CHK, "0+12345678901234", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (5 character maximum for add-on)", "" },
/*120*/ { BARCODE_EANX_CHK, "1+", 0, "", "EAN-2" },
/*121*/ { BARCODE_EANX_CHK, "+1", 0, "", "EAN-8" },
/*122*/ { BARCODE_EANX_CHK, "+", 0, "", "EAN-2" },
/*123*/ { BARCODE_EANX_CHK, "12345678901234", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/*124*/ { BARCODE_EANX_CHK, "1234567890123A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character in data (digits and \"+\" only)", "" },
/*125*/ { BARCODE_EANX_CHK, "123456789012345", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/*126*/ { BARCODE_EANX_CHK, "1234567890123456", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/*127*/ { BARCODE_EANX_CHK, "12345678901234567", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/*128*/ { BARCODE_EANX_CHK, "123456789012345678", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
/*129*/ { BARCODE_EANX_CHK, "1234567890123456789", ZINT_ERROR_TOO_LONG, "Error 294: Input too long (13 character maximum)", "" },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
char errtxt_escaped[256];
testStart("test_eanx_input");
for (i = 0; i < data_size; i++) {
@ -422,7 +426,16 @@ static void test_eanx_input(int index, int debug) {
length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) {
printf(" /*%3d*/ { %s, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), data[i].data, testUtilErrorName(data[i].ret),
testUtilEscape(symbol->errtxt, (int) strlen(symbol->errtxt), errtxt_escaped, sizeof(errtxt_escaped)),
data[i].comment);
} 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].ret_errtxt), "i:%d errtxt %s != %s\n", i, symbol->errtxt, data[i].ret_errtxt);
}
ZBarcode_Delete(symbol);
}
@ -430,125 +443,129 @@ static void test_eanx_input(int index, int debug) {
testFinish();
}
static void test_isbn_input(int index, int debug) {
static void test_isbn_input(int index, int generate, int debug) {
struct item {
char *data;
int ret_encode;
int ret_vector;
char *ret_errtxt;
char *comment;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { "0", 0, 0 }, // Left zero-padded if < 10 chars
/* 1*/ { "1", ZINT_ERROR_INVALID_CHECK, -1 },
/* 2*/ { "X", ZINT_ERROR_INVALID_CHECK, -1 },
/* 3*/ { "12", ZINT_ERROR_INVALID_CHECK, -1 },
/* 4*/ { "19", 0, 0, },
/* 5*/ { "X9", ZINT_ERROR_INVALID_DATA, -1 },
/* 6*/ { "123", ZINT_ERROR_INVALID_CHECK, -1 },
/* 7*/ { "124", 0, 0, },
/* 8*/ { "1X4", ZINT_ERROR_INVALID_DATA, -1 },
/* 9*/ { "1234", ZINT_ERROR_INVALID_CHECK, -1 },
/* 10*/ { "1236", 0, 0, },
/* 11*/ { "12X6", ZINT_ERROR_INVALID_DATA, -1 },
/* 12*/ { "12345", ZINT_ERROR_INVALID_CHECK, -1 },
/* 13*/ { "12343", 0, 0, },
/* 14*/ { "123X3", ZINT_ERROR_INVALID_DATA, -1 },
/* 15*/ { "123456", ZINT_ERROR_INVALID_CHECK, -1 },
/* 16*/ { "123455", 0, 0, },
/* 17*/ { "1234X5", ZINT_ERROR_INVALID_DATA, -1 },
/* 18*/ { "1234567", ZINT_ERROR_INVALID_CHECK, -1 },
/* 19*/ { "1234560", 0, 0, },
/* 20*/ { "12345X0", ZINT_ERROR_INVALID_DATA, -1 },
/* 21*/ { "12345678", ZINT_ERROR_INVALID_CHECK, -1 },
/* 22*/ { "12345679", 0, 0 }, // 9 is correct check digit
/* 23*/ { "98765434", 0, 0 }, // 4 is correct check digit
/* 24*/ { "123456X9", ZINT_ERROR_INVALID_DATA, -1 },
/* 25*/ { "123456789", 0, 0 },
/* 26*/ { "340013817", ZINT_ERROR_INVALID_CHECK, -1 },
/* 27*/ { "340013818", 0, 0 }, // 8 is correct check digit
/* 28*/ { "902888455", 0, 0 }, // 5 is correct check digit
/* 29*/ { "9028884X5", ZINT_ERROR_INVALID_DATA, -1 },
/* 30*/ { "0123456789", 0, 0 },
/* 31*/ { "1234567890", ZINT_ERROR_INVALID_CHECK, -1 },
/* 32*/ { "123456789X", 0, 0 }, // X is correct check digit
/* 33*/ { "123456789x", 0, 0 }, // x is correct check digit
/* 34*/ { "8175257660", 0, 0 }, // 0 is correct check digit
/* 35*/ { "0590764845", 0, 0 }, // 5 is correct check digit
/* 36*/ { "0906495741", 0, 0 }, // 1 is correct check digit
/* 37*/ { "0140430016", 0, 0 }, // 6 is correct check digit
/* 38*/ { "0571086187", 0, 0 }, // 7 is correct check digit
/* 39*/ { "0486600882", 0, 0 }, // 2 is correct check digit
/* 40*/ { "04866008X2", ZINT_ERROR_INVALID_DATA, -1 },
/* 41*/ { "123456789A", ZINT_ERROR_INVALID_DATA, -1 },
/* 42*/ { "12345678901", ZINT_ERROR_TOO_LONG, -1 },
/* 43*/ { "1234567890A", ZINT_ERROR_INVALID_DATA, -1 },
/* 44*/ { "123456789012", ZINT_ERROR_TOO_LONG, -1 },
/* 45*/ { "12345678901", ZINT_ERROR_TOO_LONG, -1 },
/* 46*/ { "123456789012", ZINT_ERROR_TOO_LONG, -1 },
/* 47*/ { "1234567890123", ZINT_ERROR_INVALID_DATA, -1 },
/* 48*/ { "9784567890123", ZINT_ERROR_INVALID_CHECK, -1 },
/* 49*/ { "9784567890120", 0, 0 }, // 0 is correct check digit
/* 50*/ { "9783161484100", 0, 0 }, // 0 is correct check digit
/* 51*/ { "9781846688225", 0, 0 }, // 5 is correct check digit
/* 52*/ { "9781847657954", 0, 0 }, // 4 is correct check digit
/* 53*/ { "9781846688188", 0, 0 }, // 8 is correct check digit
/* 54*/ { "9781847659293", 0, 0 }, // 3 is correct check digit
/* 55*/ { "97845678901201", ZINT_ERROR_TOO_LONG, -1 },
/* 56*/ { "978456789012012", ZINT_ERROR_TOO_LONG, -1 },
/* 57*/ { "3954994+12", 0, 0 },
/* 58*/ { "3954994+1X", ZINT_ERROR_INVALID_DATA, -1 },
/* 59*/ { "39549X4+12", ZINT_ERROR_INVALID_DATA, -1 },
/* 60*/ { "3954994+12345", 0, 0 },
/* 61*/ { "3954994+1234X", ZINT_ERROR_INVALID_DATA, -1 },
/* 62*/ { "39549X4+12345", ZINT_ERROR_INVALID_DATA, -1 },
/* 63*/ { "3954994+123456", ZINT_ERROR_TOO_LONG, -1 },
/* 64*/ { "3954994+", 0, 0 },
/* 65*/ { "3954X94+", ZINT_ERROR_INVALID_DATA, -1 },
/* 66*/ { "61954993+1", 0, 0 },
/* 67*/ { "61954993+X", ZINT_ERROR_INVALID_DATA, -1 },
/* 68*/ { "619549X3+1", ZINT_ERROR_INVALID_DATA, -1 },
/* 69*/ { "61954992+123", ZINT_ERROR_INVALID_CHECK, -1 },
/* 70*/ { "61954993+123", 0, 0 },
/* 71*/ { "61954993+12X", ZINT_ERROR_INVALID_DATA, -1 },
/* 72*/ { "619549X3+123", ZINT_ERROR_INVALID_DATA, -1 },
/* 73*/ { "361954990+12", ZINT_ERROR_INVALID_CHECK, -1 },
/* 74*/ { "361954999+12", 0, 0 },
/* 75*/ { "361954999+1X", ZINT_ERROR_INVALID_DATA, -1 },
/* 76*/ { "3619549X9+12", ZINT_ERROR_INVALID_DATA, -1 },
/* 77*/ { "361954999+1234", 0, 0 },
/* 78*/ { "361954999+123X", ZINT_ERROR_INVALID_DATA, -1 },
/* 79*/ { "3619549X9+1234", ZINT_ERROR_INVALID_DATA, -1 },
/* 80*/ { "1999000030+12", ZINT_ERROR_INVALID_CHECK, -1 },
/* 81*/ { "199900003X+12", 0, 0 },
/* 82*/ { "199900003x+12", 0, 0 },
/* 83*/ { "19990000XX+12", ZINT_ERROR_INVALID_DATA, -1 },
/* 84*/ { "199900003X+1X", ZINT_ERROR_INVALID_DATA, -1 },
/* 85*/ { "1999000031+12345", ZINT_ERROR_INVALID_CHECK, -1 },
/* 86*/ { "199900003X+12345", 0, 0 },
/* 87*/ { "199900003x+12345", 0, 0 },
/* 88*/ { "199900003X+1234X", ZINT_ERROR_INVALID_DATA, -1 },
/* 89*/ { "19990000XX+12345", ZINT_ERROR_INVALID_DATA, -1 },
/* 90*/ { "199900003X+1234A", ZINT_ERROR_INVALID_DATA, -1 },
/* 91*/ { "9791234567895+12", ZINT_ERROR_INVALID_CHECK, -1 },
/* 92*/ { "9791234567896+12", 0, 0 },
/* 93*/ { "9791234567896+1X", ZINT_ERROR_INVALID_DATA, -1 },
/* 94*/ { "97912345678X6+12", ZINT_ERROR_INVALID_DATA, -1 },
/* 95*/ { "9791234567897+12345", ZINT_ERROR_INVALID_CHECK, -1 },
/* 96*/ { "9791234567896+12345", 0, 0 },
/* 97*/ { "9791234567896+1234X", ZINT_ERROR_INVALID_DATA, -1 },
/* 98*/ { "979123456X896+12345", ZINT_ERROR_INVALID_DATA, -1 },
/* 99*/ { "9791234567892+", ZINT_ERROR_INVALID_CHECK, -1 },
/*100*/ { "9791234567896+", 0, 0 },
/*101*/ { "97912345678X6+", ZINT_ERROR_INVALID_DATA, -1 },
/*102*/ { "97912345678961+", ZINT_ERROR_TOO_LONG, -1 },
/*103*/ { "97912345678961+12345", ZINT_ERROR_TOO_LONG, -1 },
/*104*/ { "9791234567896+123456", ZINT_ERROR_TOO_LONG, -1 },
/* 0*/ { "0", 0, 0, "", "Left zero-padded if < 10 chars" },
/* 1*/ { "1", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '1', expecting '0'", "" },
/* 2*/ { "X", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit 'X', expecting '0'", "" },
/* 3*/ { "12", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '2', expecting '9'", "" },
/* 4*/ { "19", 0, 0, "", "" },
/* 5*/ { "X9", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 6*/ { "123", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '3', expecting '4'", "" },
/* 7*/ { "124", 0, 0, "", "" },
/* 8*/ { "1X4", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 9*/ { "1234", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '4', expecting '6'", "" },
/* 10*/ { "1236", 0, 0, "", "" },
/* 11*/ { "12X6", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 12*/ { "12345", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '5', expecting '3'", "" },
/* 13*/ { "12343", 0, 0, "", "" },
/* 14*/ { "123X3", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 15*/ { "123456", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '6', expecting '5'", "" },
/* 16*/ { "123455", 0, 0, "", "" },
/* 17*/ { "1234X5", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 18*/ { "1234567", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '7', expecting '0'", "" },
/* 19*/ { "1234560", 0, 0, "", "" },
/* 20*/ { "12345X0", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 21*/ { "12345678", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '8', expecting '9'", "" },
/* 22*/ { "12345679", 0, 0, "", "9 is correct check digit" },
/* 23*/ { "98765434", 0, 0, "", "4 is correct check digit" },
/* 24*/ { "123456X9", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 25*/ { "123456789", 0, 0, "", "" },
/* 26*/ { "340013817", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '7', expecting '8'", "" },
/* 27*/ { "340013818", 0, 0, "", "8 is correct check digit" },
/* 28*/ { "902888455", 0, 0, "", "5 is correct check digit" },
/* 29*/ { "9028884X5", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 30*/ { "0123456789", 0, 0, "", "" },
/* 31*/ { "1234567890", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid ISBN check digit '0', expecting 'X'", "" },
/* 32*/ { "123456789X", 0, 0, "", "X is correct check digit" },
/* 33*/ { "123456789x", 0, 0, "", "x is correct check digit" },
/* 34*/ { "8175257660", 0, 0, "", "0 is correct check digit" },
/* 35*/ { "0590764845", 0, 0, "", "5 is correct check digit" },
/* 36*/ { "0906495741", 0, 0, "", "1 is correct check digit" },
/* 37*/ { "0140430016", 0, 0, "", "6 is correct check digit" },
/* 38*/ { "0571086187", 0, 0, "", "7 is correct check digit" },
/* 39*/ { "0486600882", 0, 0, "", "2 is correct check digit" },
/* 40*/ { "04866008X2", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 41*/ { "123456789A", ZINT_ERROR_INVALID_DATA, -1, "Error 285: Invalid character in data (digits, \"X\" and \"+\" only)", "" },
/* 42*/ { "12345678901", ZINT_ERROR_TOO_LONG, -1, "Error 278: Input wrong length (9, 10, or 13 characters only)", "" },
/* 43*/ { "1234567890A", ZINT_ERROR_INVALID_DATA, -1, "Error 285: Invalid character in data (digits, \"X\" and \"+\" only)", "" },
/* 44*/ { "123456789012", ZINT_ERROR_TOO_LONG, -1, "Error 278: Input wrong length (9, 10, or 13 characters only)", "" },
/* 45*/ { "12345678901", ZINT_ERROR_TOO_LONG, -1, "Error 278: Input wrong length (9, 10, or 13 characters only)", "" },
/* 46*/ { "123456789012", ZINT_ERROR_TOO_LONG, -1, "Error 278: Input wrong length (9, 10, or 13 characters only)", "" },
/* 47*/ { "1234567890123", ZINT_ERROR_INVALID_DATA, -1, "Error 279: Invalid ISBN (must begin with \"978\" or \"979\")", "" },
/* 48*/ { "9784567890123", ZINT_ERROR_INVALID_CHECK, -1, "Error 280: Invalid ISBN check digit '3', expecting '0'", "" },
/* 49*/ { "9784567890120", 0, 0, "", "0 is correct check digit" },
/* 50*/ { "9783161484100", 0, 0, "", "0 is correct check digit" },
/* 51*/ { "9781846688225", 0, 0, "", "5 is correct check digit" },
/* 52*/ { "9781847657954", 0, 0, "", "4 is correct check digit" },
/* 53*/ { "9781846688188", 0, 0, "", "8 is correct check digit" },
/* 54*/ { "9781847659293", 0, 0, "", "3 is correct check digit" },
/* 55*/ { "97845678901201", ZINT_ERROR_TOO_LONG, -1, "Error 294: Input too long (13 character maximum)", "" },
/* 56*/ { "978456789012012", ZINT_ERROR_TOO_LONG, -1, "Error 294: Input too long (13 character maximum)", "" },
/* 57*/ { "3954994+12", 0, 0, "", "" },
/* 58*/ { "3954994+1X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" },
/* 59*/ { "39549X4+12", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 60*/ { "3954994+12345", 0, 0, "", "" },
/* 61*/ { "3954994+1234X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" },
/* 62*/ { "39549X4+12345", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 63*/ { "3954994+123456", ZINT_ERROR_TOO_LONG, -1, "Error 294: Input too long (5 character maximum for add-on)", "" },
/* 64*/ { "3954994+", 0, 0, "", "" },
/* 65*/ { "3954X94+", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 66*/ { "61954993+1", 0, 0, "", "" },
/* 67*/ { "61954993+X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" },
/* 68*/ { "619549X3+1", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 69*/ { "61954992+123", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '2', expecting '3'", "" },
/* 70*/ { "61954993+123", 0, 0, "", "" },
/* 71*/ { "61954993+12X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" },
/* 72*/ { "619549X3+123", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 73*/ { "361954990+12", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '0', expecting '9'", "" },
/* 74*/ { "361954999+12", 0, 0, "", "" },
/* 75*/ { "361954999+1X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" },
/* 76*/ { "3619549X9+12", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 77*/ { "361954999+1234", 0, 0, "", "" },
/* 78*/ { "361954999+123X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" },
/* 79*/ { "3619549X9+1234", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 80*/ { "1999000030+12", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid ISBN check digit '0', expecting 'X'", "" },
/* 81*/ { "199900003X+12", 0, 0, "", "" },
/* 82*/ { "199900003x+12", 0, 0, "", "" },
/* 83*/ { "19990000XX+12", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 84*/ { "199900003X+1X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" },
/* 85*/ { "1999000031+12345", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid ISBN check digit '1', expecting 'X'", "" },
/* 86*/ { "199900003X+12345", 0, 0, "", "" },
/* 87*/ { "199900003x+12345", 0, 0, "", "" },
/* 88*/ { "199900003X+1234X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" },
/* 89*/ { "19990000XX+12345", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in data, \"X\" allowed in last position only", "" },
/* 90*/ { "199900003X+1234A", ZINT_ERROR_INVALID_DATA, -1, "Error 285: Invalid character in data (digits, \"X\" and \"+\" only)", "" },
/* 91*/ { "9791234567895+12", ZINT_ERROR_INVALID_CHECK, -1, "Error 280: Invalid ISBN check digit '5', expecting '6'", "" },
/* 92*/ { "9791234567896+12", 0, 0, "", "" },
/* 93*/ { "9791234567896+1X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" },
/* 94*/ { "97912345678X6+12", ZINT_ERROR_INVALID_DATA, -1, "Error 282: Invalid character in data, \"X\" not allowed in ISBN-13", "" },
/* 95*/ { "9791234567897+12345", ZINT_ERROR_INVALID_CHECK, -1, "Error 280: Invalid ISBN check digit '7', expecting '6'", "" },
/* 96*/ { "9791234567896+12345", 0, 0, "", "" },
/* 97*/ { "9791234567896+1234X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" },
/* 98*/ { "979123456X896+12345", ZINT_ERROR_INVALID_DATA, -1, "Error 282: Invalid character in data, \"X\" not allowed in ISBN-13", "" },
/* 99*/ { "9791234567892+", ZINT_ERROR_INVALID_CHECK, -1, "Error 280: Invalid ISBN check digit '2', expecting '6'", "" },
/*100*/ { "9791234567896+", 0, 0, "", "" },
/*101*/ { "97912345678X6+", ZINT_ERROR_INVALID_DATA, -1, "Error 282: Invalid character in data, \"X\" not allowed in ISBN-13", "" },
/*102*/ { "97912345678961+", ZINT_ERROR_TOO_LONG, -1, "Error 294: Input too long (13 character maximum)", "" },
/*103*/ { "97912345678961+12345", ZINT_ERROR_TOO_LONG, -1, "Error 283: Input too long (19 character maximum)", "" },
/*104*/ { "9791234567896+123456", ZINT_ERROR_TOO_LONG, -1, "Error 283: Input too long (19 character maximum)", "" },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol;
char errtxt_escaped[256];
testStart("test_isbn_input");
for (i = 0; i < data_size; i++) {
@ -562,11 +579,20 @@ static void test_isbn_input(int index, int debug) {
length = testUtilSetSymbol(symbol, BARCODE_ISBNX, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt);
if (data[i].ret_vector != -1) {
ret = ZBarcode_Buffer_Vector(symbol, 0);
assert_equal(ret, data[i].ret_vector, "i:%d ZBarcode_Buffer_Vector ret %d != %d (%s)\n", i, ret, data[i].ret_vector, symbol->errtxt);
if (generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, \"%s\", \"%s\" },\n",
i, data[i].data, testUtilErrorName(data[i].ret_encode), data[i].ret_vector,
testUtilEscape(symbol->errtxt, (int) strlen(symbol->errtxt), errtxt_escaped, sizeof(errtxt_escaped)),
data[i].comment);
} else {
assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].ret_errtxt), "i:%d errtxt %s != %s\n", i, symbol->errtxt, data[i].ret_errtxt);
if (data[i].ret_vector != -1) {
ret = ZBarcode_Buffer_Vector(symbol, 0);
assert_equal(ret, data[i].ret_vector, "i:%d ZBarcode_Buffer_Vector ret %d != %d (%s)\n", i, ret, data[i].ret_vector, symbol->errtxt);
}
}
ZBarcode_Delete(symbol);
@ -955,18 +981,127 @@ static void test_fuzz(int index, int debug) {
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(int index, int debug) {
struct item {
int symbology;
int option_2;
char *data;
int ret;
int expected_rows;
int expected_width;
char *comment;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
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" },
};
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 (index != -1 && i != index) 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, (unsigned char *) 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(remove(symbol->outfile), "i:%d remove(%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 (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, has_index, has_generate, has_debug */
{ "test_upce_input", test_upce_input, 1, 0, 1 },
{ "test_upca_print", test_upca_print, 1, 0, 1 },
{ "test_upca_input", test_upca_input, 1, 0, 1 },
{ "test_eanx_input", test_eanx_input, 1, 0, 1 },
{ "test_isbn_input", test_isbn_input, 1, 0, 1 },
{ "test_eanx_input", test_eanx_input, 1, 1, 1 },
{ "test_isbn_input", test_isbn_input, 1, 1, 1 },
{ "test_hrt", test_hrt, 1, 0, 1 },
{ "test_vector_same", test_vector_same, 1, 0, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
{ "test_perf", test_perf, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View file

@ -84,13 +84,13 @@ void assert_nonzero(int exp, const char *fmt, ...) {
va_list args; assertionFailed++; va_start(args, fmt); vprintf(fmt, args); va_end(args); testFinish();
}
}
void assert_null(void *exp, const char *fmt, ...) {
void assert_null(const void *exp, const char *fmt, ...) {
assertionNum++;
if (exp != NULL) {
va_list args; assertionFailed++; va_start(args, fmt); vprintf(fmt, args); va_end(args); testFinish();
}
}
void assert_nonnull(void *exp, const char *fmt, ...) {
void assert_nonnull(const void *exp, const char *fmt, ...) {
assertionNum++;
if (exp == NULL) {
va_list args; assertionFailed++; va_start(args, fmt); vprintf(fmt, args); va_end(args); testFinish();
@ -683,7 +683,7 @@ const char *testUtilOutputOptionsName(int output_options) {
}
/* Convert modules spanning 3 rows to DAFT equivalents */
int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, int buffer_size) {
int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, const int buffer_size) {
int i;
char *b = buffer;
*b = '\0';
@ -720,7 +720,7 @@ int testUtilIsValidUTF8(const unsigned char str[], const int length) {
}
/* Escape data for printing on generate test. Has a number of issues, e.g. need to use octal escapes */
char *testUtilEscape(char *buffer, int length, char *escaped, int escaped_size) {
char *testUtilEscape(const char *buffer, const int length, char *escaped, const int escaped_size) {
int i;
unsigned char *b = (unsigned char *) buffer;
unsigned char *be = b + length;
@ -767,9 +767,9 @@ char *testUtilEscape(char *buffer, int length, char *escaped, int escaped_size)
}
/* Helper to read a CSV field */
char *testUtilReadCSVField(char *buffer, char *field, int field_size) {
const char *testUtilReadCSVField(const char *buffer, char *field, const int field_size) {
int i;
char *b = buffer;
const char *b = buffer;
for (i = 0; i < field_size && *b && *b != ',' && *b != '\n' && *b != '\r'; i++) {
field[i] = *b++;
}
@ -781,7 +781,7 @@ char *testUtilReadCSVField(char *buffer, char *field, int field_size) {
}
/* Helper to fill a buffer (for "large" tests) - single-byte filler only */
void testUtilStrCpyRepeat(char *buffer, char *repeat, int size) {
void testUtilStrCpyRepeat(char *buffer, const char *repeat, const int size) {
int i;
int len = (int) strlen(repeat);
int max = size - len;
@ -2046,7 +2046,7 @@ static const char *testUtilBwippName(int index, const struct zint_symbol *symbol
{ "identcode", BARCODE_DPIDENT, 22, 0, 0, 0, 0, 0, },
{ "code16k", BARCODE_CODE16K, 23, 0, 0, 0, 8 /*linear_row_height*/, 0, },
{ "code49", BARCODE_CODE49, 24, 0, 0, 0, 8 /*linear_row_height*/, 0, },
{ "code93", BARCODE_CODE93, 25, 0, 0, 0, 0, 0, },
{ "code93ext", BARCODE_CODE93, 25, 0, 0, 0, 0, 0, },
{ "", -1, 26, 0, 0, 0, 0, 0, },
{ "", -1, 27, 0, 0, 0, 0, 0, },
{ "flattermarken", BARCODE_FLAT, 28, 0, 0, 0, 0, 0, },
@ -2598,9 +2598,6 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
} else if (symbology == BARCODE_CODE93) {
sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sincludecheck",
strlen(bwipp_opts_buf) ? " " : "");
if (parse) {
bwipp_barcode = "code93ext";
}
bwipp_opts = bwipp_opts_buf;
} else if (symbology == BARCODE_PZN) {
sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%spzn8", strlen(bwipp_opts_buf) ? " " : "");
@ -2681,7 +2678,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
|| symbology == BARCODE_PHARMA_TWO) {
for (r = 0; r < symbol->rows; r++) bwipp_row_height[r] = 1; /* Zap */
if (symbology == BARCODE_KIX) {
to_upper((unsigned char *) bwipp_data);
to_upper((unsigned char *) bwipp_data, (int) strlen(bwipp_data));
} else if (symbology == BARCODE_USPS_IMAIL) {
char *dash = strchr(bwipp_data, '-');
if (dash) {

View file

@ -96,8 +96,8 @@ void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size);
#include "../ms_stdint.h"
void assert_zero(int exp, const char *fmt, ...);
void assert_nonzero(int exp, const char *fmt, ...);
void assert_null(void *exp, const char *fmt, ...);
void assert_nonnull(void *exp, const char *fmt, ...);
void assert_null(const void *exp, const char *fmt, ...);
void assert_nonnull(const void *exp, const char *fmt, ...);
void assert_equal(int e1, int e2, const char *fmt, ...);
void assert_equalu64(uint64_t e1, uint64_t e2, const char *fmt, ...);
void assert_notequal(int e1, int e2, ...);
@ -126,11 +126,11 @@ const char *testUtilInputModeName(int input_mode);
const char *testUtilOption3Name(int option_3);
const char *testUtilOutputOptionsName(int output_options);
int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, int buffer_size);
int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, const int buffer_size);
int testUtilIsValidUTF8(const unsigned char str[], const int length);
char *testUtilEscape(char *buffer, int length, char *escaped, int escaped_size);
char *testUtilReadCSVField(char *buffer, char *field, int field_size);
void testUtilStrCpyRepeat(char *buffer, char *repeat, int size);
char *testUtilEscape(const char *buffer, const int length, char *escaped, const int escaped_size);
const char *testUtilReadCSVField(const char *buffer, char *field, const int field_size);
void testUtilStrCpyRepeat(char *buffer, const char *repeat, const int size);
int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b);
struct zint_vector *testUtilVectorCpy(const struct zint_vector *in);