mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-17 00:24:35 -04:00
Add text_length
(length of text
) to zint_symbol
, and new
`BARCODE_PLAIN_HRT` option for `output_options` - for use primarily by ZXing-C++ but may be generally useful; centralize setting of HRT using new common `hrt_cpy_nochk()` etc. routines to ensure `text_length` always set PLESSEY: add show default check characters option CODE32: ignore `option_2` (check digit options) PZN: ignore `option_2` (check digit options) except when indicates PZN7 only DPD: exclude DEL from ident tag also out_maybe_mkdir: fix `utf8_to_wide()` return (Windows only) general: replace use of `strcpy()` etc. (except for test suite) with `memcpy()`, `hrt_()` etc. in lib & `cpy_str()` etc. in CLI & `cpy_bytearray_left()` in backend_qt clang-tidy: update README reflecting above backend_tcl: use sizeof(primary) to check length; tabs -> spaces general: various code fiddling docs: pandoc 3.6.2 -> 3.6.3
This commit is contained in:
parent
ddedd00d2d
commit
fef8b083b4
82 changed files with 2873 additions and 1671 deletions
|
@ -36,8 +36,7 @@ static void test_input(const testCtx *const p_ctx) {
|
|||
|
||||
struct item {
|
||||
int input_mode;
|
||||
int option_1;
|
||||
int option_2;
|
||||
int output_options;
|
||||
const char *data;
|
||||
int length;
|
||||
int ret;
|
||||
|
@ -48,32 +47,39 @@ static void test_input(const testCtx *const p_ctx) {
|
|||
};
|
||||
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
|
||||
static const struct item data[] = {
|
||||
/* 0*/ { UNICODE_MODE, -1, -1, "123456", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 792: Input length 6 too short (minimum 7)", "" },
|
||||
/* 1*/ { UNICODE_MODE, -1, -1, "1234567890123456789", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 790: Input length 19 too long (maximum 18)", "" },
|
||||
/* 2*/ { UNICODE_MODE, -1, -1, "1234567", -1, 0, 1, 102, "1U234567", "" },
|
||||
/* 3*/ { UNICODE_MODE, -1, -1, "1234567 ", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 791: Invalid character at position 8 in input (alphanumerics only, excluding \"O\")", "" },
|
||||
/* 4*/ { UNICODE_MODE, -1, -1, "ABCDEFGHIJKLMNOPQR", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 791: Invalid character at position 15 in input (alphanumerics only, excluding \"O\")", "" },
|
||||
/* 5*/ { UNICODE_MODE, -1, -1, "ABCDEFGHIJKLMNPQRS", -1, 0, 1, 234, "AQBCDEFGHIJKLMNPQRS", "" },
|
||||
/* 6*/ { UNICODE_MODE, -1, -1, "STUVWXYZ1234567890", -1, 0, 1, 234, "SCTUVWXYZ1234567890", "" },
|
||||
/* 7*/ { UNICODE_MODE, -1, -1, "abcdefghijklmnpqrs", -1, 0, 1, 234, "AQBCDEFGHIJKLMNPQRS", "" },
|
||||
/* 8*/ { UNICODE_MODE, -1, -1, "123456789012345678", -1, 0, 1, 234, "1223456789012345678", "" },
|
||||
/* 9*/ { UNICODE_MODE, -1, -1, "MMMMMMMMMMMMMMMMMM", -1, 0, 1, 234, "MTMMMMMMMMMMMMMMMMM", "" },
|
||||
/* 10*/ { UNICODE_MODE, -1, -1, "00000000", -1, 0, 1, 114, "000000000", "" },
|
||||
/* 11*/ { UNICODE_MODE, -1, -1, "000000000", -1, 0, 1, 126, "0000000000", "" },
|
||||
/* 12*/ { UNICODE_MODE, -1, -1, "000S0S000S", -1, 0, 1, 138, "0S00S0S000S", "" },
|
||||
/* 13*/ { UNICODE_MODE, -1, -1, "ZYXWVUTSRQP", -1, 0, 1, 150, "Z0YXWVUTSRQP", "" },
|
||||
/* 14*/ { UNICODE_MODE, -1, -1, "0R9GLVHA8EZ4", -1, 0, 1, 162, "0DR9GLVHA8EZ4", "" },
|
||||
/* 15*/ { UNICODE_MODE, -1, -1, "NTS1J2Q6C7DYK", -1, 0, 1, 174, "NRTS1J2Q6C7DYK", "" },
|
||||
/* 16*/ { UNICODE_MODE, -1, -1, "TS1J2Q6C7DYKBU", -1, 0, 1, 186, "TWS1J2Q6C7DYKBU", "" },
|
||||
/* 17*/ { UNICODE_MODE, -1, -1, "IX3FWP5M0R9GLVH", -1, 0, 1, 198, "IBX3FWP5M0R9GLVH", "" },
|
||||
/* 18*/ { UNICODE_MODE, -1, -1, "R9GLVHA8EZ4NTS1J", -1, 0, 1, 210, "RY9GLVHA8EZ4NTS1J", "" },
|
||||
/* 19*/ { UNICODE_MODE, -1, -1, "M5PWF3XIUBKYD7C6Q", -1, 0, 1, 222, "M35PWF3XIUBKYD7C6Q", "" },
|
||||
/* 20*/ { UNICODE_MODE, -1, -1, "2J1STN4ZE8AHVLG90R", -1, 0, 1, 234, "2PJ1STN4ZE8AHVLG90R", "" },
|
||||
/* 21*/ { UNICODE_MODE, -1, -1, "JJJJJJJJJJJJJJJJJJ", -1, 0, 1, 234, "J9JJJJJJJJJJJJJJJJJ", "" },
|
||||
/* 0*/ { UNICODE_MODE, -1, "123456", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 792: Input length 6 too short (minimum 7)", "" },
|
||||
/* 1*/ { UNICODE_MODE, -1, "1234567890123456789", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 790: Input length 19 too long (maximum 18)", "" },
|
||||
/* 2*/ { UNICODE_MODE, -1, "1234567", -1, 0, 1, 102, "1U234567", "" },
|
||||
/* 3*/ { UNICODE_MODE, BARCODE_PLAIN_HRT, "1234567", -1, 0, 1, 102, "1U234567", "" }, /* No difference */
|
||||
/* 4*/ { UNICODE_MODE, -1, "1234567 ", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 791: Invalid character at position 8 in input (alphanumerics only, excluding \"O\")", "" },
|
||||
/* 5*/ { UNICODE_MODE, -1, "ABCDEFGHIJKLMNOPQR", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 791: Invalid character at position 15 in input (alphanumerics only, excluding \"O\")", "" },
|
||||
/* 6*/ { UNICODE_MODE, -1, "ABCDEFGHIJKLMNPQRS", -1, 0, 1, 234, "AQBCDEFGHIJKLMNPQRS", "" },
|
||||
/* 7*/ { UNICODE_MODE, BARCODE_PLAIN_HRT, "ABCDEFGHIJKLMNPQRS", -1, 0, 1, 234, "AQBCDEFGHIJKLMNPQRS", "" }, /* No difference */
|
||||
/* 8*/ { UNICODE_MODE, -1, "STUVWXYZ1234567890", -1, 0, 1, 234, "SCTUVWXYZ1234567890", "" },
|
||||
/* 9*/ { UNICODE_MODE, -1, "abcdefghijklmnpqrs", -1, 0, 1, 234, "AQBCDEFGHIJKLMNPQRS", "" },
|
||||
/* 10*/ { UNICODE_MODE, BARCODE_PLAIN_HRT, "abcdefghijklmnpqrs", -1, 0, 1, 234, "AQBCDEFGHIJKLMNPQRS", "" }, /* No difference */
|
||||
/* 11*/ { UNICODE_MODE, -1, "123456789012345678", -1, 0, 1, 234, "1223456789012345678", "" },
|
||||
/* 12*/ { UNICODE_MODE, -1, "MMMMMMMMMMMMMMMMMM", -1, 0, 1, 234, "MTMMMMMMMMMMMMMMMMM", "" },
|
||||
/* 13*/ { UNICODE_MODE, -1, "00000000", -1, 0, 1, 114, "000000000", "" },
|
||||
/* 14*/ { UNICODE_MODE, BARCODE_PLAIN_HRT, "00000000", -1, 0, 1, 114, "000000000", "" }, /* No difference */
|
||||
/* 15*/ { UNICODE_MODE, -1, "000000000", -1, 0, 1, 126, "0000000000", "" },
|
||||
/* 16*/ { UNICODE_MODE, BARCODE_PLAIN_HRT, "000000000", -1, 0, 1, 126, "0000000000", "" }, /* No difference */
|
||||
/* 17*/ { UNICODE_MODE, -1, "000S0S000S", -1, 0, 1, 138, "0S00S0S000S", "" },
|
||||
/* 18*/ { UNICODE_MODE, -1, "ZYXWVUTSRQP", -1, 0, 1, 150, "Z0YXWVUTSRQP", "" },
|
||||
/* 19*/ { UNICODE_MODE, -1, "0R9GLVHA8EZ4", -1, 0, 1, 162, "0DR9GLVHA8EZ4", "" },
|
||||
/* 20*/ { UNICODE_MODE, -1, "NTS1J2Q6C7DYK", -1, 0, 1, 174, "NRTS1J2Q6C7DYK", "" },
|
||||
/* 21*/ { UNICODE_MODE, -1, "TS1J2Q6C7DYKBU", -1, 0, 1, 186, "TWS1J2Q6C7DYKBU", "" },
|
||||
/* 22*/ { UNICODE_MODE, -1, "IX3FWP5M0R9GLVH", -1, 0, 1, 198, "IBX3FWP5M0R9GLVH", "" },
|
||||
/* 23*/ { UNICODE_MODE, -1, "R9GLVHA8EZ4NTS1J", -1, 0, 1, 210, "RY9GLVHA8EZ4NTS1J", "" },
|
||||
/* 24*/ { UNICODE_MODE, -1, "M5PWF3XIUBKYD7C6Q", -1, 0, 1, 222, "M35PWF3XIUBKYD7C6Q", "" },
|
||||
/* 25*/ { UNICODE_MODE, -1, "2J1STN4ZE8AHVLG90R", -1, 0, 1, 234, "2PJ1STN4ZE8AHVLG90R", "" },
|
||||
/* 26*/ { UNICODE_MODE, -1, "JJJJJJJJJJJJJJJJJJ", -1, 0, 1, 234, "J9JJJJJJJJJJJJJJJJJ", "" },
|
||||
/* 27*/ { UNICODE_MODE, BARCODE_PLAIN_HRT, "JJJJJJJJJJJJJJJJJJ", -1, 0, 1, 234, "J9JJJJJJJJJJJJJJJJJ", "" }, /* No difference */
|
||||
};
|
||||
const int data_size = ARRAY_SIZE(data);
|
||||
int i, length, ret;
|
||||
struct zint_symbol *symbol = NULL;
|
||||
int expected_length;
|
||||
|
||||
char bwipp_buf[8192];
|
||||
char bwipp_msg[1024];
|
||||
|
@ -89,20 +95,28 @@ static void test_input(const testCtx *const p_ctx) {
|
|||
symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
length = testUtilSetSymbol(symbol, BARCODE_BC412, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
|
||||
length = testUtilSetSymbol(symbol, BARCODE_BC412, data[i].input_mode, -1 /*eci*/,
|
||||
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, data[i].output_options,
|
||||
data[i].data, data[i].length, debug);
|
||||
expected_length = (int) strlen(data[i].expected);
|
||||
|
||||
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
|
||||
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
|
||||
|
||||
if (ret < ZINT_ERROR) {
|
||||
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
|
||||
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
|
||||
assert_zero(strcmp((char *) symbol->text, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->text, data[i].expected);
|
||||
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
|
||||
i, symbol->rows, data[i].expected_rows, data[i].data);
|
||||
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
|
||||
i, symbol->width, data[i].expected_width, data[i].data);
|
||||
assert_equal(symbol->text_length, expected_length, "i:%d text_length %d != expected_length %d\n",
|
||||
i, symbol->text_length, expected_length);
|
||||
assert_zero(strcmp((char *) symbol->text, data[i].expected), "i:%d strcmp(%s, %s) != 0\n",
|
||||
i, symbol->text, data[i].expected);
|
||||
|
||||
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, -1, -1, debug)) {
|
||||
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) {
|
||||
char modules_dump[8192 + 1];
|
||||
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
|
||||
ret = testUtilBwipp(i, symbol, data[i].option_1, -1, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf), NULL);
|
||||
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf), NULL);
|
||||
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
|
||||
|
||||
ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, modules_dump);
|
||||
|
@ -124,8 +138,6 @@ static void test_encode(const testCtx *const p_ctx) {
|
|||
|
||||
struct item {
|
||||
int input_mode;
|
||||
int option_1;
|
||||
int option_2;
|
||||
const char *data;
|
||||
int ret;
|
||||
|
||||
|
@ -136,10 +148,10 @@ static void test_encode(const testCtx *const p_ctx) {
|
|||
const char *expected;
|
||||
};
|
||||
static const struct item data[] = {
|
||||
/* 0*/ { UNICODE_MODE, -1, -1, "AQ45670", 0, 1, 102, 1, "SEMI T1-95 Figure 2, same",
|
||||
/* 0*/ { UNICODE_MODE, "AQ45670", 0, 1, 102, 1, "SEMI T1-95 Figure 2, same",
|
||||
"100101000100100100010101000100010101000101010000010101001010000101001001000101001000100101010100000101"
|
||||
},
|
||||
/* 1*/ { UNICODE_MODE, -1, -1, "A6BC1234", 0, 1, 114, 1, "https://www.grapecity.co.jp, same",
|
||||
/* 1*/ { UNICODE_MODE, "A6BC1234", 0, 1, 114, 1, "https://www.grapecity.co.jp, same",
|
||||
"100101000100100100100010100101001001000101000100010101000010100101010010000101010001000101010000100101010000010101"
|
||||
},
|
||||
};
|
||||
|
@ -162,14 +174,14 @@ static void test_encode(const testCtx *const p_ctx) {
|
|||
symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
length = testUtilSetSymbol(symbol, BARCODE_BC412, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
|
||||
length = testUtilSetSymbol(symbol, BARCODE_BC412, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
|
||||
|
||||
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
|
||||
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
|
||||
|
||||
if (p_ctx->generate) {
|
||||
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\",\n",
|
||||
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2,
|
||||
printf(" /*%3d*/ { %s, \"%s\", %s, %d, %d, %d, \"%s\",\n",
|
||||
i, testUtilInputModeName(data[i].input_mode),
|
||||
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
|
||||
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment);
|
||||
testUtilModulesPrint(symbol, " ", "\n");
|
||||
|
@ -184,11 +196,11 @@ static void test_encode(const testCtx *const p_ctx) {
|
|||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
|
||||
|
||||
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, -1, -1, debug)) {
|
||||
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) {
|
||||
if (!data[i].bwipp_cmp) {
|
||||
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
|
||||
} else {
|
||||
ret = testUtilBwipp(i, symbol, data[i].option_1, -1, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf), NULL);
|
||||
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf), NULL);
|
||||
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
|
||||
|
||||
ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue