Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,

GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
  better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
  namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
This commit is contained in:
gitlost
2022-05-09 19:50:50 +01:00
parent 3b9d989894
commit f58c80e290
81 changed files with 12026 additions and 4701 deletions

View File

@ -1692,7 +1692,7 @@ static void test_encode(int index, int generate, int 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, data[i].option_2, data[i].option_3, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf));
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected);
@ -1720,6 +1720,382 @@ static void test_encode(int index, int generate, int debug) {
testFinish();
}
static void test_encode_segs(int index, int generate, int debug) {
struct item {
int symbology;
int input_mode;
int option_1;
int option_2;
int option_3;
struct zint_structapp structapp;
struct zint_seg segs[3];
int ret;
int expected_rows;
int expected_width;
int bwipp_cmp;
char *comment;
char *expected;
};
struct item data[] = {
/* 0*/ { BARCODE_PDF417, UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, { { TU(""), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, 0, 8, 103, 1, "Standard example",
"1111111101010100011111010101111100110101000011000001111001111001010011110101011110000111111101000101001"
"1111111101010100011111101010001110101000011110010001001111110010110011110101001000000111111101000101001"
"1111111101010100011101010111111000111010100011111101001111110011101011101010001111110111111101000101001"
"1111111101010100011010111100111110110110100010000001000011000110010010101111001111000111111101000101001"
"1111111101010100011101011100001100101110100011111001111000001001001011110101110011100111111101000101001"
"1111111101010100011110101111010000111011111000101101001111100001101011101011111010000111111101000101001"
"1111111101010100011101001110111110101000111011100001000111011100100011010011101111000111111101000101001"
"1111111101010100011111010010110000111000101110110001101011100001000010101111110111000111111101000101001"
},
/* 1*/ { BARCODE_PDF417, UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, { { TU(""), -1, 0 }, { TU("Ж"), -1, 0 }, { TU(""), 0, 0 } }, ZINT_WARN_USES_ECI, 8, 103, 1, "Standard example auto-ECI",
"1111111101010100011111010101111100110101000011000001111001111001010011110101011110000111111101000101001"
"1111111101010100011111101010001110101000011110010001001111110010110011110101001000000111111101000101001"
"1111111101010100011101010111111000111010100011111101001111110011101011101010001111110111111101000101001"
"1111111101010100011010111100111110110110100010000001000011000110010010101111001111000111111101000101001"
"1111111101010100011101011100001100101110100011111001111000001001001011110101110011100111111101000101001"
"1111111101010100011110101111010000111011111000101101001111100001101011101011111010000111111101000101001"
"1111111101010100011101001110111110101000111011100001000111011100100011010011101111000111111101000101001"
"1111111101010100011111010010110000111000101110110001101011100001000010101111110111000111111101000101001"
},
/* 2*/ { BARCODE_PDF417, UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, { { TU("Ж"), -1, 7 }, { TU(""), -1, 0 }, { TU(""), 0, 0 } }, 0, 9, 103, 1, "Standard example inverted",
"1111111101010100011111010101111100110101000001100001100011100011001011110101011110000111111101000101001"
"1111111101010100011110101000010000111111010100011101011111100100011011110101001000000111111101000101001"
"1111111101010100011101010111111000110010010111110001000011111011001010101000011110000111111101000101001"
"1111111101010100011010111100111110111010100111000001111001111001010010101111001111000111111101000101001"
"1111111101010100011010111000001000101000011110010001011111101011000011110101110011100111111101000101001"
"1111111101010100011110101111010000111000111111010101100111110100010011110101111101100111111101000101001"
"1111111101010100011101001110111110111110111010111001111001100101110011010011101111000111111101000101001"
"1111111101010100011111101001011100111100100010100001001111101011100010101111110111000111111101000101001"
"1111111101010100011010011011111100100111010011000001100011010011110011111010011101000111111101000101001"
},
/* 3*/ { BARCODE_PDF417, UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, { { TU("Ж"), -1, 0 }, { TU(""), -1, 0 }, { TU(""), 0, 0 } }, ZINT_WARN_USES_ECI, 9, 103, 1, "Standard example inverted auto-ECI",
"1111111101010100011111010101111100110101000001100001100011100011001011110101011110000111111101000101001"
"1111111101010100011110101000010000111111010100011101011111100100011011110101001000000111111101000101001"
"1111111101010100011101010111111000110010010111110001000011111011001010101000011110000111111101000101001"
"1111111101010100011010111100111110111010100111000001111001111001010010101111001111000111111101000101001"
"1111111101010100011010111000001000101000011110010001011111101011000011110101110011100111111101000101001"
"1111111101010100011110101111010000111000111111010101100111110100010011110101111101100111111101000101001"
"1111111101010100011101001110111110111110111010111001111001100101110011010011101111000111111101000101001"
"1111111101010100011111101001011100111100100010100001001111101011100010101111110111000111111101000101001"
"1111111101010100011010011011111100100111010011000001100011010011110011111010011101000111111101000101001"
},
/* 4*/ { BARCODE_PDF417, UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, { { TU("product:Google Pixel 4a - 128 GB of Storage - Black;price:$439.97"), -1, 3 }, { TU("品名:Google 谷歌 Pixel 4a -128 GB的存储空间-黑色;零售价:¥3149.79"), -1, 29 }, { TU("Produkt:Google Pixel 4a - 128 GB Speicher - Schwarz;Preis:444,90 €"), -1, 17 } }, 0, 24, 188, 0, "AIM ITS/04-023:2022 Annex A example; BWIPP different encodation",
"11111111010101000111010100011100001001010000100000011000111000110010111010100111000001000011000110010011000001001011000100110001101000001101000010000110011010100011000000111111101000101001"
"11111111010101000111110101000001101111010011011000011110000011011010100000101111101101111011000011001011110100000100010110100011100001001110000110111010011111101010001110111111101000101001"
"11111111010101000110101000111110001101100010001111011100101011111100110011111011011001001011000111110011111101011100110100111110001100101100011110101100011111101011010000111111101000101001"
"11111111010101000111110100101111101101001111011111010000010100010000111110110100111101100000101001100010011011100001100110000010100110001110011000010011011110100101111000111111101000101001"
"11111111010101000110101111011000001110010000011001011111010100011000110100011100001001001111010001111011000001011101000101011111001100001001001111000001011101011100001100111111101000101001"
"11111111010101000111101011110000101010011101111110010000001100101110111100001011110101001000100001111010010110000111110100110000110111101101000001011111011101011111000100111111101000101001"
"11111111010101000101001111011110001111011000100111010010001110011100110001110001100101010111101111000010000010000100010111011011001110001110110100011000011010011100011110111111101000101001"
"11111111010101000111111010010011101110100000110001011100101111001110101111110101100001111000001101101011101000000110010111101100001100101111010000010001011111010010110000111111101000101001"
"11111111010101000101001100011111001111110010110001011001111110110010100100100111100001011011101111100010110110111100000101100100000111001100011111001001011111010011100100111111101000101001"
"11111111010101000110100011100111101111011110001001011000011010010000110000100011011101100010101100000010000110111101110100000101000001001000001010001000010100011100111000111111101000101001"
"11111111010101000110100111000000101000101111010000011111101001011100110000010111010001101000011110110011011111101011100110010011101000001111110111010010011101001110001100111111101000101001"
"11111111010101000101000110111110001000010100011110011111101011000100110011100010011101100110100111100010111000110011100110110000010111101001100110001111011111010001110100111111101000101001"
"11111111010101000101000001001000001100110000010001010001010000010000110011000001001001101111001110001010100000101000000110110011000011001100100000100011011101000001011100111111101000101001"
"11111111010101000111101000110110001101111101011110011111011001010000101110111111010001111001110011101011110100001001000101111110100110001111101011011100011111010001000110111111101000101001"
"11111111010101000101000001101111101001110011001110011000111110010010101111110011100101110110111111001010000111110110010111111010110001001100011111001001011100101011111100111111101000101001"
"11111111010101000111100101101111101001100110000100010011000110100000110100001000011001011000111000011011100111101100010100000101110011101110111010100000011100101101111000111111101000101001"
"11111111010101000101000111111011101111010000010001011010001110000100111000011011101001001011111101110011110100011011000110000010111010001101000111000001010100011111011000111111101000101001"
"11111111010101000111110010111101101111110101110011010011111000110010110001111010110001111101001110100011001111101101100100100101111000001000111101110111011100101111100100111111101000101001"
"11111111010101000111101101000011101100000100101100011010000010011000101001111011110001010000011000110010000010100010000111011100100000101000001000101000011101101000011000111111101000101001"
"11111111010101000111101000001000101000001011110100011100101100000100111101011001100001111001110011101011101011101100000111100010110011001111010001000010010100001111100110111111101000101001"
"11111111010101000110010010011111001011110010000010010111000100110000101000001001111001011100100011000011111101011100110100111111001110101110010111111011010010010000111100111111101000101001"
"11111111010101000101101110001100001000011000110010010000110001100100100001100011001001000011000110010010000110001100100110011000010010001101110110100000011101101110011110111111101000101001"
"11111111010101000111100101000000101111010000010001010100011110010000101110100111110001110000010110001011101000011000010110110001111001001100010111000100011111001010001100111111101000101001"
"11111111010101000111001001111101001011101100011100011001110010001110110000111110100101001111001100011010110011001111000101100100001110001101111001000011011001001111110010111111101000101001"
},
/* 5*/ { BARCODE_PDF417, DATA_MODE, -1, -1, -1, { 0, 0, "" }, { { TU("\357"), 1, 0 }, { TU("\357"), 1, 7 }, { TU("\357"), 1, 0 } }, 0, 10, 103, 1, "Standard example + extra seg, data mode",
"1111111101010100011101010011100000110101101110000001111001111001010011110101011110000111111101000101001"
"1111111101010100011111010100011000111100101110011101001111110010110011111010100110000111111101000101001"
"1111111101010100011101010111111000111010100011111101001111110011101011010100011111000111111101000101001"
"1111111101010100010101111101111100111011001000110001100011100011001010101111001111000111111101000101001"
"1111111101010100011010111000010000111110101001100001011111100100011011010111000100000111111101000101001"
"1111111101010100011110101111010000101100110011110001100011111001001011110101111000010111111101000101001"
"1111111101010100010100111001110000110101000011000001100100011001110011010011101111000111111101000101001"
"1111111101010100011110100101000000100001011110000101101011111101111011010111111011110111111101000101001"
"1111111101010100011010011011111100110100111111010001001011101111110010100110001111100111111101000101001"
"1111111101010100010100011000001100111100100100111101100011001010000011010001100011100111111101000101001"
},
/* 6*/ { BARCODE_PDF417, UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, { { TU("Τεχτ"), -1, 9 }, { TU("กขฯ"), -1, 0 }, { TU("貫やぐ禁"), -1, 20 } }, ZINT_WARN_USES_ECI, 11, 120, 1, "Auto-ECI",
"111111110101010001110101001110000011010111001111000110001110001100101010100000100000011111010101111100111111101000101001"
"111111110101010001111110101000111011011111101011100111111001010111001111001011000110011111010100110000111111101000101001"
"111111110101010001010100111100000010110011101111100111111001000110101000011111011001011101010001111110111111101000101001"
"111111110101010001010111110111110011101011011110000100000100001000101001011000110000011010111100111110111111101000101001"
"111111110101010001110101110000110011110100001010000111010000001100101001111110010110011010111000100000111111101000101001"
"111111110101010001111101011110110011111101011000010110011111101100101011001000001110011101011111010000111111101000101001"
"111111110101010001010011100111000011001100001100110101100011110011101100111001110011011101001110111110111111101000101001"
"111111110101010001111101001011000011111010001011000110100011101000001111100101001100011010111111011110111111101000101001"
"111111110101010001111110100110010011000111110010010100111010011000001110101111100010010100110000111110111111101000101001"
"111111110101010001010001100000110011001000010011000110011000110011001011110011110010010100011000011000111111101000101001"
"111111110101010001110100111000110011010001111011000110000110111100101101001111000011011010011100100000111111101000101001"
},
/* 7*/ { BARCODE_PDF417, UNICODE_MODE, -1, -1, -1, { 2, 4, "017053" }, { { TU("Τεχτ"), -1, 9 }, { TU("กขฯ"), -1, 13 }, { TU("貫やぐ禁"), -1, 20 } }, 0, 11, 120, 1, "Structured Append",
"111111110101010001110101001110000011010111001111000110001110001100101010100000100000011111010101111100111111101000101001"
"111111110101010001111110101000111011011111101011100111111001010111001111001011000110011111010100110000111111101000101001"
"111111110101010001010100111100000010110011101111100111111001000110101000011111011001011101010001111110111111101000101001"
"111111110101010001010111110111110011101011011110000100000100001000101001011000110000011010111100111110111111101000101001"
"111111110101010001110101110000110011110100001010000111010000001100101001111110010110011010111000100000111111101000101001"
"111111110101010001111101011110110011111101011000010110011111101100101011001000001110011101011111010000111111101000101001"
"111111110101010001010011100111000011001100001100110101100011110011101100111001110011011101001110111110111111101000101001"
"111111110101010001111101001011000011111010001011000110100011101000001111100101001100011010111111011110111111101000101001"
"111111110101010001111110100110010011000111110010010100111010011000001110101111100010010100110000111110111111101000101001"
"111111110101010001010001100000110011001000010011000110011000110011001011110011110010010100011000011000111111101000101001"
"111111110101010001110100111000110011010001111011000110000110111100101101001111000011011010011100100000111111101000101001"
},
/* 8*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 3, -1, { 0, 0, "" }, { { TU("¶¶"), -1, 0 }, { TU("ЖЖ"), -1, 7 }, { TU(""), 0, 0 } }, 0, 8, 82, 1, "Standard example (doubled to avoid Byte Shift)",
"1100111010100000100001000101000010110110110100010000001101101000100000011001110101"
"1110111010100111111001011001000010010111111010100011101101111110101110011101110101"
"1110011010110010010111110001000011010110010010111110001100011111001001011100110101"
"1111011010100001100011001001000111010100001011101110001100010000010011011110110101"
"1111001010111001000011010001000110010110111001111101001101000011101000011110010101"
"1110001010101101101111000001000100010100111100001101101011011100011111011100010101"
"1100001010111011100010100001001100010101110001110010001100100111011110011000010101"
"1100011010101111100100111001001110010111010001100010001111000101000001011000110101"
},
/* 9*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 3, -1, { 0, 0, "" }, { { TU("¶¶"), -1, 0 }, { TU("ЖЖ"), -1, 0 }, { TU(""), 0, 0 } }, ZINT_WARN_USES_ECI, 8, 82, 1, "Standard example auto-ECI",
"1100111010100000100001000101000010110110110100010000001101101000100000011001110101"
"1110111010100111111001011001000010010111111010100011101101111110101110011101110101"
"1110011010110010010111110001000011010110010010111110001100011111001001011100110101"
"1111011010100001100011001001000111010100001011101110001100010000010011011110110101"
"1111001010111001000011010001000110010110111001111101001101000011101000011110010101"
"1110001010101101101111000001000100010100111100001101101011011100011111011100010101"
"1100001010111011100010100001001100010101110001110010001100100111011110011000010101"
"1100011010101111100100111001001110010111010001100010001111000101000001011000110101"
},
/* 10*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 3, -1, { 0, 0, "" }, { { TU("ЖЖ"), -1, 7 }, { TU("¶¶"), -1, 0 }, { TU(""), 0, 0 } }, 0, 8, 82, 1, "Standard example inverted",
"1100111010110001110001100101000010110111010100011100001000001000010001011001110101"
"1110111010101000011110010001000010010101000011110010001001111110010110011101110101"
"1110011010110101001111100001000011010110011111101100101100100101111100011100110101"
"1111011010110110100010000001000111010100000100111011101010000010100000011110110101"
"1111001010110111001111101001000110010110111011111010001011111010011100011110010101"
"1110001010101100010001110001000100010110111110010000101000000110101110011100010101"
"1100001010110100001000110001001100010111010010000111001110001100010011011000010101"
"1100011010111110111011000101001110010111011000111000101110100111000110011000110101"
},
/* 11*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 3, -1, { 0, 0, "" }, { { TU("ЖЖ"), -1, 0 }, { TU("¶¶"), -1, 0 }, { TU(""), 0, 0 } }, ZINT_WARN_USES_ECI, 8, 82, 1, "Standard example inverted auto-ECI",
"1100111010110001110001100101000010110111010100011100001000001000010001011001110101"
"1110111010101000011110010001000010010101000011110010001001111110010110011101110101"
"1110011010110101001111100001000011010110011111101100101100100101111100011100110101"
"1111011010110110100010000001000111010100000100111011101010000010100000011110110101"
"1111001010110111001111101001000110010110111011111010001011111010011100011110010101"
"1110001010101100010001110001000100010110111110010000101000000110101110011100010101"
"1100001010110100001000110001001100010111010010000111001110001100010011011000010101"
"1100011010111110111011000101001110010111011000111000101110100111000110011000110101"
},
/* 12*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 4, -1, { 0, 0, "" }, { { TU("product:Google Pixel 4a 128 GB Black;price:$439.97"), -1, 3 }, { TU("品名:Google 谷歌 Pixel 4a 128 GB 黑色;零售价:¥3149.79"), -1, 29 }, { TU("Produkt:Google Pixel 4a 128 GB Schwarz;Preis:444,90 €"), -1, 17 } }, 0, 44, 99, 0, "AIM ITS/04-023:2022 Annex A example (shortened); BWIPP different encodation",
"110010001011000111000110010111010100111000001011000010100001100011001001100000100101100011010001001"
"111010001011000100111010000101001111000010001011100010111101001101100001111000001101101011010001101"
"111011001010001111001101100101110001100111001011100110100100100001111001111110010110001011010000101"
"110011001011000001001011000110010001101110001011100100110100000100011001000001010001000011011000101"
"110111001011010001110000010111010110000001001011101100111100000100010101111110100101110011001000101"
"110111101011001111101101100100100101111000001001101100110001111010110001110111111010100011101000101"
"110011101011111010101111100110110000100001001000101100110101100111000001101110011000010011101100101"
"111011101010101111110011100110011110101111101000101000100010011111011001110100111000011011001100101"
"111001101010111101001000000101100110011110001001101000100001111101100101010111000111111011011100101"
"111101101010000010000100010111011011001110001011101000111011010001100001110010010011100011011110101"
"111100101011100101111001110101111110101100001011001000111100000110110101110100000011001011001110101"
"111000101010111000110011100100100100001111001011001100111111001011000101100111111011001011101110101"
"110000101011011010000100000101101100010000001011000100111101101000111001110110010110000011100110101"
"110001101010111111010110000101111001000111101011000110100001101011111101000110100111111011110110101"
"110001001011011101001110000100111110011101101010000110100111110110010001100111110110110011110010101"
"111001001011010111100111110100100011001100001010001110111000111010010001101001100011100011100010101"
"111101001011011111101011100110110111100010001010001100111110100010110001100011001111001011000010101"
"111101011010011001000011100110001111000101101010011100110001000101111101000111001011000011000110101"
"111101010010100010000010000111101000101111001010011000111101110100110001001011000011000011000100101"
"111001010011110100001001000101111110100110001010111000111110101101110001011101011111000011100100101"
"111011010011000111110010010101111110011100101010110000111011011111100101000011111011001011110100101"
"111010010011110101100111110100001100011001001010010000100110011000010001001100011010000011110101101"
"111010011010100111100001000110010011110110001011010000111100000110110101000001011111011011110101001"
"111010111010111000110011100100100100001111001001010000111111001011000101100111110010100011100101001"
"111010110011001000110111000110100000100011001001011000100000101000100001110010100111000011101101001"
"111010100011101011000000100111100000100010101001011100111111010010111001100000101110100011101001001"
"110010100010010010111100000100011110111011101011011100100111110110001001011001000001110011101001101"
"110010110011110101100111110110111100111000101011011110101011100011100001110001000100111011101011101"
"110010111011110100010000100111100010001010001011001110100100001111000101111010001001000011101011001"
"110010011010111001000110000111111010111001101001001110100111111001110101110010111111011011101010001"
"110011011010000110001100100100001100011001001001101110100001100011001001000011000110010011001010001"
"111011011010111111010110000101111110101100001000101110111110101100011101101110011111010011001011001"
"111001011011011110010011000111111000101100101000100110101111011101110001000011010111000011001011101"
"110001011010011000110100000110000100011011101000110110111000110001001101001101111101111011001001101"
"110001010010011111010011100110110011110001001000010110111101100111001101111010000010100011001101101"
"110011010011111001000111010100010000101111001000010010111010001011111101001100001000111011101101101"
"110111010010001100110000010100001100110010001000011010100010001100001101100100000100011011100101101"
"110110010011101111011111010111111011010011001000111010111100010100100001110000110111010011000101101"
"110110011010011001001110000111001111101001101000110010101110010001100001000101100111110011000101001"
"110110111011101101100111000100110001110110001000100010110111100011100101000110110010000011001101001"
"110110110011111011100110100111001000001100101001100010111101100110000101100100000111001011011101001"
"110110100011101110010111100110001111010001101001110010110111111001101001011010000011100011011001001"
"110100100010110011110001110101100001100010001001111010111011000100110001010000011001100011011001101"
"110101100011111011000010100111110100001011001011111010111110111011000101011101111110001011011011101"
},
/* 13*/ { BARCODE_MICROPDF417, DATA_MODE, -1, 3, -1, { 0, 0, "" }, { { TU("\357\357"), 2, 0 }, { TU("\357\357"), 2, 7 }, { TU("\357\357"), 2, 0 } }, 0, 10, 82, 1, "Standard example (doubled) + extra seg, data mode",
"1100010010110011111101100101001111010101100110011110001011001100111100011000100101"
"1110010010110001110001100101011111010111010100011100001000001000010001011100100101"
"1111010010111100101110011101011110010111100101110011101001111110010110011110100101"
"1111010110110101001111100001011110110110011111101100101011001100111100011110101101"
"1111010100111011001000110001001110110100001100011001001100111011001000011110101001"
"1110010100110001000001110101001110100111111011101010001101110111110100011100101001"
"1110110100110100010011111001001100100110010100001111101110011111101010011101101001"
"1110100100110110000010000101001100110101001000001000001110100000100111011101001001"
"1110100110111101000011001101001000110111101001000100001100100111010000011101001101"
"1110101110100000101101111101001000010111010011111000101001110111001111011101011101"
},
/* 14*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, { { TU("Τεχτ"), -1, 9 }, { TU("กขฯ"), -1, 0 }, { TU("貫やぐ禁"), -1, 20 } }, ZINT_WARN_USES_ECI, 17, 55, 1, "Auto-ECI",
"1100110100100001111101100101101010000111110011001101001"
"1101110100100000100001000101100100110011100011011101001"
"1101100100111100101100011001100101111011000011011001001"
"1101100110111111001000110101000011111011001011011001101"
"1101101110111010110111100001000001000010001011011011101"
"1101101100101000111111011101111010000101000011011011001"
"1101101000100100111011111101000011111011001011011010001"
"1101001000101011000011000001000001000010001011010010001"
"1101011000111001011000001001111011101110100011010110001"
"1101011100110011010011110001101111100010001011010111001"
"1101011110110100001110111101110100000010111011010111101"
"1101001110111110010100110001011111101011000011010011101"
"1101001100101000011001111101000000110100111011010011001"
"1101000100110100110111000001000010000100100011010001001"
"1101000110111001011110011101101101111001000011010001101"
"1101000010110000011010111101100110010001111011010000101"
"1101100010100001001101100001001001110111000011011000101"
},
/* 15*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, -1, -1, { 3, 4, "017053" }, { { TU("Τεχτ"), -1, 9 }, { TU("กขฯ"), -1, 13 }, { TU("貫やぐ禁"), -1, 20 } }, 0, 17, 55, 1, "Structured Append",
"1100110100100001111101100101101010000111110011001101001"
"1101110100100000100001000101100100110011100011011101001"
"1101100100111100101100011001100101111011000011011001001"
"1101100110111111001000110101000011111011001011011001101"
"1101101110111010110111100001000001000010001011011011101"
"1101101100101000111111011101111010000101000011011011001"
"1101101000100100111011111101000011111011001011011010001"
"1101001000101011000011000001000001000010001011010010001"
"1101011000111001011000001001111011101110100011010110001"
"1101011100110011010011110001101111100010001011010111001"
"1101011110110100001110111101110100000010111011010111101"
"1101001110111110010100110001011111101011000011010011101"
"1101001100101000011001111101000000110100111011010011001"
"1101000100110100110111000001000010000100100011010001001"
"1101000110111001011110011101101101111001000011010001101"
"1101000010110000011010111101100110010001111011010000101"
"1101100010100001001101100001001001110111000011011000101"
},
/* 16*/ { BARCODE_PDF417COMP, UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, { { TU(""), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, 0, 8, 69, 1, "Standard example",
"111111110101010001111101010111110011010100001100000111100111100101001"
"111111110101010001111110101000111010100001111001000100111111001011001"
"111111110101010001110101011111100011101010001111110100111111001110101"
"111111110101010001101011110011111011011010001000000100001100011001001"
"111111110101010001110101110000110010111010001111100111100000100100101"
"111111110101010001111010111101000011101111100010110100111110000110101"
"111111110101010001110100111011111010100011101110000100011101110010001"
"111111110101010001111101001011000011100010111011000110101110000100001"
},
/* 17*/ { BARCODE_HIBC_PDF, UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, { { TU("H123ABC"), -1, 0 }, { TU("012345678"), -1, 0 }, { TU("90D"), -1, 20 } }, ZINT_ERROR_INVALID_OPTION, 0, 0, 1, "HIBC",
""
},
/* 18*/ { BARCODE_HIBC_MICPDF, UNICODE_MODE, -1, -1, -1, { 0, 0, "" }, { { TU("H123ABC"), -1, 0 }, { TU("012345678"), -1, 0 }, { TU("90D"), -1, 20 } }, ZINT_ERROR_INVALID_OPTION, 0, 0, 1, "HIBC",
""
},
};
int data_size = ARRAY_SIZE(data);
int i, j, seg_count, ret;
struct zint_symbol *symbol;
char escaped[1024];
char cmp_buf[32768];
char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise
testStart("test_encode_segs");
for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/,
data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, NULL, 0, debug);
for (j = 0, seg_count = 0; j < 3 && data[i].segs[j].length; j++, seg_count++);
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) {
char escaped1[4096];
char escaped2[4096];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length;
int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length;
printf(" /*%3d*/ { %s, %s, %d, %d, %d, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode),
data[i].option_1, data[i].option_2, data[i].option_3,
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
testUtilEscape((const char *) data[i].segs[0].source, length, escaped, sizeof(escaped)), data[i].segs[0].length, data[i].segs[0].eci,
testUtilEscape((const char *) data[i].segs[1].source, length1, escaped1, sizeof(escaped1)), data[i].segs[1].length, data[i].segs[1].eci,
testUtilEscape((const char *) data[i].segs[2].source, length2, escaped2, sizeof(escaped2)), data[i].segs[2].length, data[i].segs[2].eci,
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment);
if (data[i].ret < ZINT_ERROR) {
testUtilModulesPrint(symbol, " ", "\n");
} else {
printf(" \"\"\n");
}
printf(" },\n");
} else {
if (ret < ZINT_ERROR) {
int width, row;
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d\n", i, ret, width, row);
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
} else {
ret = testUtilBwippSegs(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3, data[i].segs, seg_count, NULL, cmp_buf, sizeof(cmp_buf));
assert_zero(ret, "i:%d %s testUtilBwippSegs ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, (const char *) data[i].segs[0].source, data[i].segs[0].length, debug)) {
if (data[i].input_mode == DATA_MODE) {
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d multiple segments in DATA_MODE not currently supported for ZXing-C++ testing (%s)\n",
i, testUtilBarcodeName(symbol->symbology));
}
} else {
int cmp_len, ret_len;
char modules_dump[2710 * 8 + 1];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilZXingCPP(i, symbol, (const char *) data[i].segs[0].source, data[i].segs[0].length,
modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len);
assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilZXingCPPCmpSegs(symbol, cmp_msg, cmp_buf, cmp_len, data[i].segs, seg_count,
NULL /*primary*/, escaped, &ret_len);
assert_zero(ret, "i:%d %s testUtilZXingCPPCmpSegs %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped);
}
}
}
}
ZBarcode_Delete(symbol);
}
testFinish();
}
// #181 Nico Gunkel OSS-Fuzz
static void test_fuzz(int index, int debug) {
@ -2161,6 +2537,7 @@ int main(int argc, char *argv[]) {
{ "test_reader_init", test_reader_init, 1, 1, 1 },
{ "test_input", test_input, 1, 1, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_encode_segs", test_encode_segs, 1, 1, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
{ "test_perf", test_perf, 1, 0, 1 },
};