mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-09 13:41:59 -04:00
EAN-8: specify in check digit error
test suite: deal with ZXing-C++ changes re DBAR and EAN/UPC with add-ons
This commit is contained in:
parent
26805338f8
commit
0b7103e21e
3 changed files with 111 additions and 118 deletions
|
@ -406,9 +406,9 @@ static void test_eanx_input(const testCtx *const p_ctx) {
|
|||
/* 67*/ { BARCODE_EANX_CHK, "12345678905", 0, "", "" },
|
||||
/* 68*/ { BARCODE_EANX_CHK, "1234567890", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '0', expecting '5'", "" },
|
||||
/* 69*/ { BARCODE_EANX_CHK, "123456789", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '9', expecting '4'", "" },
|
||||
/* 70*/ { BARCODE_EANX_CHK, "12345678", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '8', expecting '0'", "EAN-8" },
|
||||
/* 71*/ { BARCODE_EANX_CHK, "1234567", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '7', expecting '5'", "" },
|
||||
/* 72*/ { BARCODE_EANX_CHK, "123456", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '6', expecting '7'", "" },
|
||||
/* 70*/ { BARCODE_EANX_CHK, "12345678", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid EAN-8 check digit '8', expecting '0'", "EAN-8" },
|
||||
/* 71*/ { BARCODE_EANX_CHK, "1234567", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid EAN-8 check digit '7', expecting '5'", "" },
|
||||
/* 72*/ { BARCODE_EANX_CHK, "123456", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid EAN-8 check digit '6', expecting '7'", "" },
|
||||
/* 73*/ { BARCODE_EANX_CHK, "12345", 0, "", "EAN-5" },
|
||||
/* 74*/ { BARCODE_EANX_CHK, "1234", 0, "", "" },
|
||||
/* 75*/ { BARCODE_EANX_CHK, "123", 0, "", "" },
|
||||
|
@ -439,21 +439,21 @@ static void test_eanx_input(const testCtx *const p_ctx) {
|
|||
/*100*/ { BARCODE_EANX_CHK, "1234567890+12345", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '0', expecting '5'", "" },
|
||||
/*101*/ { BARCODE_EANX_CHK, "1234567890+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" },
|
||||
/*102*/ { BARCODE_EANX_CHK, "123456789+12345", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '9', expecting '4'", "" },
|
||||
/*103*/ { BARCODE_EANX_CHK, "12345678+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '8', expecting '0'", "EAN-8" },
|
||||
/*103*/ { BARCODE_EANX_CHK, "12345678+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid EAN-8 check digit '8', expecting '0'", "EAN-8" },
|
||||
/*104*/ { BARCODE_EANX_CHK, "12345670+12345", ZINT_WARN_NONCOMPLIANT, "Warning 292: EAN-8 with add-on is non-standard", "" },
|
||||
/*105*/ { BARCODE_EANX_CHK, "1234567+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '7', expecting '5'", "" },
|
||||
/*105*/ { BARCODE_EANX_CHK, "1234567+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid EAN-8 check digit '7', expecting '5'", "" },
|
||||
/*106*/ { BARCODE_EANX_CHK, "1234565+12345", ZINT_WARN_NONCOMPLIANT, "Warning 292: EAN-8 with add-on is non-standard", "" },
|
||||
/*107*/ { BARCODE_EANX_CHK, "123456+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '6', expecting '7'", "" },
|
||||
/*107*/ { BARCODE_EANX_CHK, "123456+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid EAN-8 check digit '6', expecting '7'", "" },
|
||||
/*108*/ { BARCODE_EANX_CHK, "123457+12345", ZINT_WARN_NONCOMPLIANT, "Warning 292: EAN-8 with add-on is non-standard", "" },
|
||||
/*109*/ { BARCODE_EANX_CHK, "12345+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '5', expecting '8'", "" },
|
||||
/*109*/ { BARCODE_EANX_CHK, "12345+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid EAN-8 check digit '5', expecting '8'", "" },
|
||||
/*110*/ { BARCODE_EANX_CHK, "12348+12345", ZINT_WARN_NONCOMPLIANT, "Warning 292: EAN-8 with add-on is non-standard", "" },
|
||||
/*111*/ { BARCODE_EANX_CHK, "1234+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '4', expecting '6'", "" },
|
||||
/*111*/ { BARCODE_EANX_CHK, "1234+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid EAN-8 check digit '4', expecting '6'", "" },
|
||||
/*112*/ { BARCODE_EANX_CHK, "1236+12345", ZINT_WARN_NONCOMPLIANT, "Warning 292: EAN-8 with add-on is non-standard", "" },
|
||||
/*113*/ { BARCODE_EANX_CHK, "123+12345", ZINT_WARN_NONCOMPLIANT, "Warning 292: EAN-8 with add-on is non-standard", "3 happens to be correct check digit" },
|
||||
/*114*/ { BARCODE_EANX_CHK, "124+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '4', expecting '3'", "" },
|
||||
/*115*/ { BARCODE_EANX_CHK, "12+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '2', expecting '7'", "" },
|
||||
/*114*/ { BARCODE_EANX_CHK, "124+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid EAN-8 check digit '4', expecting '3'", "" },
|
||||
/*115*/ { BARCODE_EANX_CHK, "12+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid EAN-8 check digit '2', expecting '7'", "" },
|
||||
/*116*/ { BARCODE_EANX_CHK, "17+12345", ZINT_WARN_NONCOMPLIANT, "Warning 292: EAN-8 with add-on is non-standard", "" },
|
||||
/*117*/ { BARCODE_EANX_CHK, "1+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '1', expecting '0'", "" },
|
||||
/*117*/ { BARCODE_EANX_CHK, "1+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid EAN-8 check digit '1', expecting '0'", "" },
|
||||
/*118*/ { BARCODE_EANX_CHK, "0+12345", ZINT_WARN_NONCOMPLIANT, "Warning 292: EAN-8 with add-on is non-standard", "" },
|
||||
/*119*/ { BARCODE_EANX_CHK, "0+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" },
|
||||
/*120*/ { BARCODE_EANX_CHK, "1+12345678901234", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 14 too long (maximum 5)", "" },
|
||||
|
@ -981,49 +981,52 @@ static void test_encode(const testCtx *const p_ctx) {
|
|||
/* 20*/ { BARCODE_UPCE_CHK, -1, "12345670+12345", 0, 1, 105, "Example of UPC-E with 5-digit add-on",
|
||||
"101001001101111010100011011100100001010010001010101000000010110110011010010011010100001010100011010110001"
|
||||
},
|
||||
/* 21*/ { BARCODE_EANX, -1, "1234567+12", ZINT_WARN_NONCOMPLIANT, 1, 94, "Example of EAN-8 with 2-digit add-on",
|
||||
/* 21*/ { BARCODE_EANX, -1, "2012345+12", ZINT_WARN_NONCOMPLIANT, 1, 94, "Example of EAN-8 with 2-digit add-on",
|
||||
"1010010011000110100110010010011010101000010101110010011101100110101000000010110011001010010011"
|
||||
},
|
||||
/* 22*/ { BARCODE_EANX, -1, "1234567+12", ZINT_WARN_NONCOMPLIANT, 1, 94, "Example of EAN-8 with 2-digit add-on",
|
||||
"1010011001001001101111010100011010101001110101000010001001110010101000000010110011001010010011"
|
||||
},
|
||||
/* 22*/ { BARCODE_EANX_CHK, -1, "12345670+12345", ZINT_WARN_NONCOMPLIANT, 1, 121, "Example of EAN-8 with 5-digit add-on",
|
||||
/* 23*/ { BARCODE_EANX_CHK, -1, "12345670+12345", ZINT_WARN_NONCOMPLIANT, 1, 121, "Example of EAN-8 with 5-digit add-on",
|
||||
"1010011001001001101111010100011010101001110101000010001001110010101000000010110110011010010011010100001010100011010110001"
|
||||
},
|
||||
/* 23*/ { BARCODE_EANX, -1, "54321", 0, 1, 47, "Example of EAN-5",
|
||||
/* 24*/ { BARCODE_EANX, -1, "54321", 0, 1, 47, "Example of EAN-5",
|
||||
"10110111001010100011010100001010010011010011001"
|
||||
},
|
||||
/* 24*/ { BARCODE_EANX, -1, "21", 0, 1, 20, "Example of EAN-2",
|
||||
/* 25*/ { BARCODE_EANX, -1, "21", 0, 1, 20, "Example of EAN-2",
|
||||
"10110010011010110011"
|
||||
},
|
||||
/* 25*/ { BARCODE_EANX_CHK, 9, "76543210+21", ZINT_WARN_NONCOMPLIANT, 1, 96, "Example of EAN-8 barcode with two-digit add-on, addon_gap 9",
|
||||
/* 26*/ { BARCODE_EANX_CHK, 9, "76543210+21", ZINT_WARN_NONCOMPLIANT, 1, 96, "Example of EAN-8 barcode with two-digit add-on, addon_gap 9",
|
||||
"101011101101011110110001010001101010100001011011001100110111001010100000000010110010011010110011"
|
||||
},
|
||||
/* 26*/ { BARCODE_EANX, 12, "7654321+54321", ZINT_WARN_NONCOMPLIANT, 1, 126, "Example of EAN-8 barcode with five-digit add-on, addon_gap 12",
|
||||
/* 27*/ { BARCODE_EANX, 12, "7654321+54321", ZINT_WARN_NONCOMPLIANT, 1, 126, "Example of EAN-8 barcode with five-digit add-on, addon_gap 12",
|
||||
"101011101101011110110001010001101010100001011011001100110111001010100000000000010110111001010100011010100001010010011010011001"
|
||||
},
|
||||
/* 27*/ { BARCODE_UPCA_CHK, 10, "210987654329+21", 0, 1, 125, "Example of UPC-A with 2-digit add-on, addon_gap 10",
|
||||
/* 28*/ { BARCODE_UPCA_CHK, 10, "210987654329+21", 0, 1, 125, "Example of UPC-A with 2-digit add-on, addon_gap 10",
|
||||
"10100100110011001000110100010110110111011101101010101000010011101011100100001011011001110100101000000000010110010011010110011"
|
||||
},
|
||||
/* 28*/ { BARCODE_UPCA, 12, "21098765432+12121", 0, 1, 154, "Example of UPC-A with 5-digit add-on, addon_gap 12",
|
||||
/* 29*/ { BARCODE_UPCA, 12, "21098765432+12121", 0, 1, 154, "Example of UPC-A with 5-digit add-on, addon_gap 12",
|
||||
"1010010011001100100011010001011011011101110110101010100001001110101110010000101101100111010010100000000000010110011001010010011010110011010011011010011001"
|
||||
},
|
||||
/* 29*/ { BARCODE_UPCE_CHK, 8, "06543217+21", 0, 1, 79, "Example of UPC-E with 2-digit add-on, addon_gap 8",
|
||||
/* 30*/ { BARCODE_UPCE_CHK, 8, "06543217+21", 0, 1, 79, "Example of UPC-E with 2-digit add-on, addon_gap 8",
|
||||
"1010000101011000100111010111101001101100110010101010000000010110010011010110011"
|
||||
},
|
||||
/* 30*/ { BARCODE_UPCE, 11, "1654321+12121", 0, 1, 109, "Example of UPC-E with 5-digit add-on, addon_gap 11",
|
||||
/* 31*/ { BARCODE_UPCE, 11, "1654321+12121", 0, 1, 109, "Example of UPC-E with 5-digit add-on, addon_gap 11",
|
||||
"1010101111011100101000110111101001101101100110101010000000000010110011001010010011010110011010011011010011001"
|
||||
},
|
||||
/* 31*/ { BARCODE_ISBNX, -1, "9789295055124", 0, 1, 95, "ISBN Users' Manual 7th Ed. 13.2",
|
||||
/* 32*/ { BARCODE_ISBNX, -1, "9789295055124", 0, 1, 95, "ISBN Users' Manual 7th Ed. 13.2",
|
||||
"10101110110001001001011100100110010111011000101010111001010011101001110110011011011001011100101"
|
||||
},
|
||||
/* 32*/ { BARCODE_ISBNX, -1, "9780123456786+50995", 0, 1, 149, "BISG BGUSBI Figure 1: Bookland EAN (with Price Add-On) (and Figures 4, 5, 6)",
|
||||
/* 33*/ { BARCODE_ISBNX, -1, "9780123456786+50995", 0, 1, 149, "BISG BGUSBI Figure 1: Bookland EAN (with Price Add-On) (and Figures 4, 5, 6)",
|
||||
"10101110110001001010011100110010011011011110101010101110010011101010000100010010010001010000101000000010110110001010100111010001011010001011010111001"
|
||||
},
|
||||
/* 33*/ { BARCODE_ISBNX, -1, "9781402894626+50495", 0, 1, 149, "BISG BGUSBI Figure 2",
|
||||
/* 34*/ { BARCODE_ISBNX, -1, "9781402894626+50495", 0, 1, 149, "BISG BGUSBI Figure 2",
|
||||
"10101110110001001011001101000110100111001001101010100100011101001011100101000011011001010000101000000010110111001010001101010100011010001011010111001"
|
||||
},
|
||||
/* 34*/ { BARCODE_ISBNX, 10, "9780940016644+50750", 0, 1, 152, "BISG BGUSBI Figure 3, addon_gap 10",
|
||||
/* 35*/ { BARCODE_ISBNX, 10, "9780940016644+50750", 0, 1, 152, "BISG BGUSBI Figure 3, addon_gap 10",
|
||||
"10101110110001001010011100010110011101000110101010111001011001101010000101000010111001011100101000000000010110111001010001101010010001010110001010001101"
|
||||
},
|
||||
/* 35*/ { BARCODE_ISBNX, -1, "9791234567896+12", 0, 1, 122, "Example of ISBN with 2-digit add-on",
|
||||
/* 36*/ { BARCODE_ISBNX, -1, "9791234567896+12", 0, 1, 122, "Example of ISBN with 2-digit add-on",
|
||||
"10101110110010111011001100100110100001010001101010100111010100001000100100100011101001010000101000000010110011001010010011"
|
||||
},
|
||||
};
|
||||
|
|
|
@ -4181,6 +4181,24 @@ static int textUtilZXingCPPDX(const char *expected, const int expected_len, cons
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Helper to append add-on if any to EAN-13, returning expected length */
|
||||
static int textUtilZXingCPPEAN13AddOn(const char *expected, const int expected_len, char *out) {
|
||||
char *plus;
|
||||
if ((plus = strchr(expected, '+')) != NULL) {
|
||||
const int addon_len = expected_len - (plus + 1 - expected);
|
||||
if (addon_len <= 2) {
|
||||
memset(out + 13, '0', 2 - addon_len);
|
||||
memcpy(out + 13 + (2 - addon_len), plus + 1, addon_len);
|
||||
return 15;
|
||||
}
|
||||
assert(addon_len <= 5);
|
||||
memset(out + 13, '0', 5 - addon_len);
|
||||
memcpy(out + 13 + (5 - addon_len), plus + 1, addon_len);
|
||||
return 18;
|
||||
}
|
||||
return 13;
|
||||
}
|
||||
|
||||
/* Massage result from "zxingcppdecoder" so as can compare to Zint input */
|
||||
int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, int cmp_len, const char *expected,
|
||||
int expected_len, const char *primary, char *ret_buf, int *p_ret_len) {
|
||||
|
@ -4188,6 +4206,8 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in
|
|||
|
||||
const int is_gs1_128_dbar_exp = symbology == BARCODE_GS1_128 || symbology == BARCODE_DBAR_EXP
|
||||
|| symbology == BARCODE_DBAR_EXPSTK;
|
||||
const int is_dbar_nonexp = symbology == BARCODE_DBAR_OMN || symbology == BARCODE_DBAR_LTD
|
||||
|| symbology == BARCODE_DBAR_OMNSTK || symbology == BARCODE_DBAR_STK;
|
||||
const int gs1 = (symbol->input_mode & 0x07) == GS1_MODE || is_gs1_128_dbar_exp;
|
||||
const int is_extra_escaped = (symbol->input_mode & EXTRA_ESCAPE_MODE) && symbol->symbology == BARCODE_CODE128;
|
||||
const int is_escaped = (symbol->input_mode & ESCAPE_MODE) || is_extra_escaped;
|
||||
|
@ -4207,7 +4227,8 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in
|
|||
? (char *) z_alloca(expected_len + strlen(primary) + 4 + 6 + 9 + 1) : NULL;
|
||||
char *vin = is_vin_international ? (char *) z_alloca(expected_len + 1 + 1) : NULL;
|
||||
char *c25inter = have_c25inter ? (char *) z_alloca(expected_len + 13 + 1 + 1) : NULL;
|
||||
char *upcean = is_upcean ? (char *) z_alloca(expected_len + 1 + 1) : NULL;
|
||||
char *dbar_nonexp = is_dbar_nonexp ? (char *) z_alloca(expected_len + 2 + 1) : NULL;
|
||||
char *upcean = is_upcean ? (char *) z_alloca(expected_len + 13 + 1) : NULL;
|
||||
char *ean14_nve18 = symbology == BARCODE_EAN14 || symbology == BARCODE_NVE18
|
||||
? (char *) z_alloca(expected_len + 3 + 19 + 1) : NULL;
|
||||
char *dpd = need_dpd_prefix ? (char *) z_alloca(28 + 1) : NULL;
|
||||
|
@ -4402,118 +4423,86 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in
|
|||
c25inter[++expected_len] = '\0';
|
||||
expected = c25inter;
|
||||
}
|
||||
} else if (symbology == BARCODE_DBAR_OMN || symbology == BARCODE_DBAR_LTD || symbology == BARCODE_DBAR_OMNSTK
|
||||
|| symbology == BARCODE_DBAR_STK) {
|
||||
} else if (is_dbar_nonexp) {
|
||||
if (expected_len == 13) {
|
||||
cmp_len--; /* Too messy to calc the check digit so ignore */
|
||||
}
|
||||
if (symbology == BARCODE_DBAR_LTD) {
|
||||
cmp_buf += 2; /* Ignore prefixed "01" */
|
||||
cmp_len -= 2;
|
||||
}
|
||||
dbar_nonexp[0] = '0';
|
||||
dbar_nonexp[1] = '1';
|
||||
memcpy(dbar_nonexp + 2, expected, expected_len);
|
||||
expected = dbar_nonexp;
|
||||
expected_len += 2;
|
||||
} else if (is_upcean) {
|
||||
if (symbology == BARCODE_UPCA && (expected_len == 11 || expected_len == 14 || expected_len == 17)) {
|
||||
memcpy(upcean, expected, 11);
|
||||
upcean[11] = gs1_check_digit((const unsigned char *) upcean, 11);
|
||||
if (expected_len == 14) {
|
||||
upcean[12] = ' ';
|
||||
memcpy(upcean + 13, expected + 12, 2);
|
||||
} else if (expected_len == 17) {
|
||||
upcean[12] = ' ';
|
||||
memcpy(upcean + 13, expected + 12, 5);
|
||||
}
|
||||
expected_len++;
|
||||
const char *plus;
|
||||
if (symbology == BARCODE_UPCA || symbology == BARCODE_UPCA_CHK) {
|
||||
assert(expected_len >= 11);
|
||||
upcean[0] = '0';
|
||||
memcpy(upcean + 1, expected, 11);
|
||||
upcean[12] = gs1_check_digit(ZCUCP(upcean), 12);
|
||||
expected_len = textUtilZXingCPPEAN13AddOn(expected, expected_len, upcean);
|
||||
upcean[expected_len] = '\0';
|
||||
expected = upcean;
|
||||
} else if (symbology == BARCODE_UPCA_CHK && (expected_len == 15 || expected_len == 18)) {
|
||||
memcpy(upcean, expected, expected_len);
|
||||
upcean[12] = ' ';
|
||||
expected = upcean;
|
||||
} else if (symbology == BARCODE_UPCE && (expected_len == 7 || expected_len == 10 || expected_len == 13)) {
|
||||
} else if (symbology == BARCODE_UPCE || symbology == BARCODE_UPCE_CHK) {
|
||||
char equivalent[11];
|
||||
memcpy(upcean, expected, 7);
|
||||
memcpy(equivalent, upcean, 3);
|
||||
assert(expected_len >= 7);
|
||||
memcpy(equivalent, expected, 3);
|
||||
memset(equivalent + 3, '0', 8);
|
||||
switch (upcean[6]) {
|
||||
switch (expected[6]) {
|
||||
case '0': case '1': case '2':
|
||||
equivalent[3] = upcean[6];
|
||||
equivalent[8] = upcean[3];
|
||||
equivalent[9] = upcean[4];
|
||||
equivalent[10] = upcean[5];
|
||||
equivalent[3] = expected[6];
|
||||
equivalent[8] = expected[3];
|
||||
equivalent[9] = expected[4];
|
||||
equivalent[10] = expected[5];
|
||||
break;
|
||||
case '3':
|
||||
equivalent[3] = upcean[3];
|
||||
equivalent[9] = upcean[4];
|
||||
equivalent[10] = upcean[5];
|
||||
equivalent[3] = expected[3];
|
||||
equivalent[9] = expected[4];
|
||||
equivalent[10] = expected[5];
|
||||
break;
|
||||
case '4':
|
||||
equivalent[3] = upcean[3];
|
||||
equivalent[4] = upcean[4];
|
||||
equivalent[10] = upcean[5];
|
||||
equivalent[3] = expected[3];
|
||||
equivalent[4] = expected[4];
|
||||
equivalent[10] = expected[5];
|
||||
break;
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
equivalent[3] = upcean[3];
|
||||
equivalent[4] = upcean[4];
|
||||
equivalent[5] = upcean[5];
|
||||
equivalent[10] = upcean[6];
|
||||
equivalent[3] = expected[3];
|
||||
equivalent[4] = expected[4];
|
||||
equivalent[5] = expected[5];
|
||||
equivalent[10] = expected[6];
|
||||
break;
|
||||
}
|
||||
upcean[7] = gs1_check_digit((const unsigned char *) equivalent, 11);
|
||||
if (expected_len == 10) {
|
||||
upcean[8] = ' ';
|
||||
memcpy(upcean + 9, expected + 8, 2);
|
||||
} else if (expected_len == 13) {
|
||||
upcean[8] = ' ';
|
||||
memcpy(upcean + 9, expected + 8, 5);
|
||||
}
|
||||
expected_len++;
|
||||
upcean[0] = '0';
|
||||
memcpy(upcean + 1, equivalent, 11);
|
||||
upcean[12] = gs1_check_digit(ZCUCP(upcean), 12);
|
||||
expected_len = textUtilZXingCPPEAN13AddOn(expected, expected_len, upcean);
|
||||
upcean[expected_len] = '\0';
|
||||
expected = upcean;
|
||||
} else if (symbology == BARCODE_UPCE_CHK && (expected_len == 11 || expected_len == 14)) {
|
||||
memcpy(upcean, expected, expected_len);
|
||||
upcean[8] = ' ';
|
||||
/* EAN-8 with add-on check must happen before other EANX checks */
|
||||
} else if ((symbology == BARCODE_EANX || symbology == BARCODE_EANX_CHK)
|
||||
&& (plus = strchr(expected, '+')) != NULL && (plus - expected) <= 8) {
|
||||
const int ean7_len = (int) (plus - expected) - (symbology == BARCODE_EANX_CHK);
|
||||
memset(upcean, '0', 12 - ean7_len);
|
||||
memcpy(upcean + (12 - ean7_len), expected, ean7_len);
|
||||
upcean[12] = gs1_check_digit(ZCUCP(upcean), 12);
|
||||
expected_len = textUtilZXingCPPEAN13AddOn(expected, expected_len, upcean);
|
||||
upcean[expected_len] = '\0';
|
||||
expected = upcean;
|
||||
} else if (symbology == BARCODE_EANX && (expected_len == 12 || expected_len == 15 || expected_len == 18)) {
|
||||
} else if ((symbology == BARCODE_EANX || symbology == BARCODE_EANX_CHK)
|
||||
&& (expected_len == 7 || expected_len == 8)) {
|
||||
if (expected_len == 7) {
|
||||
memcpy(upcean, expected, 7);
|
||||
upcean[7] = gs1_check_digit(ZCUCP(expected), 7);
|
||||
}
|
||||
expected_len = 8;
|
||||
upcean[expected_len] = '\0';
|
||||
expected = upcean;
|
||||
} else if ((symbology == BARCODE_EANX || symbology == BARCODE_EANX_CHK || symbology == BARCODE_ISBNX)
|
||||
&& expected_len >= 12) {
|
||||
memcpy(upcean, expected, 12);
|
||||
upcean[12] = gs1_check_digit((const unsigned char *) upcean, 12);
|
||||
if (expected_len == 15) {
|
||||
upcean[13] = ' ';
|
||||
memcpy(upcean + 14, expected + 13, 2);
|
||||
} else if (expected_len == 18) {
|
||||
upcean[13] = ' ';
|
||||
memcpy(upcean + 14, expected + 13, 5);
|
||||
}
|
||||
expected_len++;
|
||||
upcean[12] = gs1_check_digit(ZCUCP(upcean), 12);
|
||||
expected_len = textUtilZXingCPPEAN13AddOn(expected, expected_len, upcean);
|
||||
upcean[expected_len] = '\0';
|
||||
expected = upcean;
|
||||
} else if (symbology == BARCODE_EANX && (expected_len == 16 || expected_len == 19)) {
|
||||
memcpy(upcean, expected, expected_len);
|
||||
upcean[13] = ' ';
|
||||
expected = upcean;
|
||||
} else if (symbology == BARCODE_EANX && (expected_len == 7
|
||||
|| (strchr(expected, '+') != NULL && (expected_len == 10 || expected_len == 13)))) {
|
||||
memcpy(upcean, expected, 7);
|
||||
upcean[7] = gs1_check_digit((const unsigned char *) upcean, 7);
|
||||
if (expected_len == 10) {
|
||||
upcean[8] = ' ';
|
||||
memcpy(upcean + 9, expected + 8, 2);
|
||||
} else if (expected_len == 13) {
|
||||
upcean[8] = ' ';
|
||||
memcpy(upcean + 9, expected + 8, 5);
|
||||
}
|
||||
expected_len++;
|
||||
upcean[expected_len] = '\0';
|
||||
expected = upcean;
|
||||
} else if ((symbology == BARCODE_EANX_CHK || symbology == BARCODE_ISBNX)
|
||||
&& (expected_len == 16 || expected_len == 19)) {
|
||||
memcpy(upcean, expected, expected_len);
|
||||
upcean[13] = ' ';
|
||||
expected = upcean;
|
||||
} else if (symbology == BARCODE_EANX_CHK && strchr(expected, '+') != NULL
|
||||
&& (expected_len == 11 || expected_len == 14)) {
|
||||
memcpy(upcean, expected, expected_len);
|
||||
upcean[8] = ' ';
|
||||
expected = upcean;
|
||||
}
|
||||
|
||||
} else if (symbology == BARCODE_EAN14 || symbology == BARCODE_NVE18) {
|
||||
|
@ -4525,7 +4514,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in
|
|||
memcpy(ean14_nve18 + 2 + zeroes, expected, expected_len);
|
||||
ean14_nve18[len + 2] = gs1_check_digit((unsigned char *) (ean14_nve18 + 2), len);
|
||||
expected = ean14_nve18;
|
||||
expected_len += zeroes + 3;
|
||||
expected_len = len + 3;
|
||||
|
||||
} else if (need_dpd_prefix) {
|
||||
dpd[0] = '%';
|
||||
|
|
|
@ -473,7 +473,8 @@ static int ean8_cc(struct zint_symbol *symbol, const unsigned char source[], int
|
|||
hrt_cat_chr_nochk(symbol, gs1_check_digit(gtin, 7));
|
||||
} else {
|
||||
if (source[length - 1] != gs1_check_digit(gtin, 7)) {
|
||||
return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 276, "Invalid check digit '%1$c', expecting '%2$c'",
|
||||
return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 276,
|
||||
"Invalid EAN-8 check digit '%1$c', expecting '%2$c'",
|
||||
source[length - 1], gs1_check_digit(gtin, 7));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue