Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tests/test_upcean.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* | |
| 2 libzint - the open source barcode library | |
| 3 Copyright (C) 2019-2024 Robin Stuart <rstuart114@gmail.com> | |
| 4 | |
| 5 Redistribution and use in source and binary forms, with or without | |
| 6 modification, are permitted provided that the following conditions | |
| 7 are met: | |
| 8 | |
| 9 1. Redistributions of source code must retain the above copyright | |
| 10 notice, this list of conditions and the following disclaimer. | |
| 11 2. Redistributions in binary form must reproduce the above copyright | |
| 12 notice, this list of conditions and the following disclaimer in the | |
| 13 documentation and/or other materials provided with the distribution. | |
| 14 3. Neither the name of the project nor the names of its contributors | |
| 15 may be used to endorse or promote products derived from this software | |
| 16 without specific prior written permission. | |
| 17 | |
| 18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| 19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | |
| 22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
| 24 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
| 27 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 28 SUCH DAMAGE. | |
| 29 */ | |
| 30 /* SPDX-License-Identifier: BSD-3-Clause */ | |
| 31 | |
| 32 #include "testcommon.h" | |
| 33 | |
| 34 static void test_upce_input(const testCtx *const p_ctx) { | |
| 35 int debug = p_ctx->debug; | |
| 36 | |
| 37 struct item { | |
| 38 int symbology; | |
| 39 char *data; | |
| 40 int ret; | |
| 41 | |
| 42 char *hrt; | |
| 43 }; | |
| 44 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 45 static const struct item data[] = { | |
| 46 /* 0*/ { BARCODE_UPCE, "12345", 0, "00123457" }, /* equivalent: 00123400005, Check digit: 7 */ | |
| 47 /* 1*/ { BARCODE_UPCE_CHK, "12345", ZINT_ERROR_INVALID_CHECK, "" }, | |
| 48 /* 2*/ { BARCODE_UPCE_CHK, "12344", 0, "00012344" }, /* equivalent: 00012000003, Check digit: 4 */ | |
| 49 /* 3*/ { BARCODE_UPCE, "123456", 0, "01234565" }, /* equivalent: 01234500006, Check digit: 5 */ | |
| 50 /* 4*/ { BARCODE_UPCE_CHK, "123456", ZINT_ERROR_INVALID_CHECK, "" }, | |
| 51 /* 5*/ { BARCODE_UPCE_CHK, "123457", 0, "00123457" }, /* equivalent: 00123400005, Check digit: 7 */ | |
| 52 /* 6*/ { BARCODE_UPCE, "1234567", 0, "12345670" }, /* equivalent: 12345600007, Check digit: 0 */ | |
| 53 /* 7*/ { BARCODE_UPCE_CHK, "1234567", ZINT_ERROR_INVALID_CHECK, "" }, | |
| 54 /* 8*/ { BARCODE_UPCE_CHK, "1234565", 0, "01234565" }, /* equivalent: 01234500006, Check digit: 5 */ | |
| 55 /* 9*/ { BARCODE_UPCE, "12345678", ZINT_ERROR_INVALID_CHECK, "" }, | |
| 56 /* 10*/ { BARCODE_UPCE, "12345670", 0, "12345670" }, /* equivalent: 12345600007, Check digit: 0 */ | |
| 57 /* 11*/ { BARCODE_UPCE_CHK, "12345678", ZINT_ERROR_INVALID_CHECK, "" }, | |
| 58 /* 12*/ { BARCODE_UPCE_CHK, "12345670", 0, "12345670" }, /* equivalent: 12345600007, Check digit: 0 */ | |
| 59 /* 13*/ { BARCODE_UPCE, "123456789", ZINT_ERROR_TOO_LONG, "" }, | |
| 60 /* 14*/ { BARCODE_UPCE_CHK, "123456789", ZINT_ERROR_TOO_LONG, "" }, | |
| 61 /* 15*/ { BARCODE_UPCE, "123456A", ZINT_ERROR_INVALID_DATA, "" }, | |
| 62 /* 16*/ { BARCODE_UPCE, "1234567A", ZINT_ERROR_INVALID_DATA, "" }, | |
| 63 /* 17*/ { BARCODE_UPCE, "12345678A", ZINT_ERROR_INVALID_DATA, "" }, | |
| 64 /* 18*/ { BARCODE_UPCE_CHK, "123456A", ZINT_ERROR_INVALID_DATA, "" }, | |
| 65 /* 19*/ { BARCODE_UPCE_CHK, "1234567A", ZINT_ERROR_INVALID_DATA, "" }, | |
| 66 /* 20*/ { BARCODE_UPCE_CHK, "12345678A", ZINT_ERROR_INVALID_DATA, "" }, | |
| 67 /* 21*/ { BARCODE_UPCE, "2345678", 0, "03456781" }, /* 2 ignored, equivalent: 03456700008, Check digit: 1 */ | |
| 68 /* 22*/ { BARCODE_UPCE_CHK, "23456781", 0, "03456781" }, /* 2 ignored, equivalent: 03456700008, Check digit: 1 */ | |
| 69 /* 23*/ { BARCODE_UPCE, "123455", 0, "01234558" }, /* equivalent: 01234500005, Check digit: 8 (BS 797 Rule 3 (a)) */ | |
| 70 /* 24*/ { BARCODE_UPCE_CHK, "1234558", 0, "01234558" }, /* equivalent: 01234500005, Check digit: 8 (BS 797 Rule 3 (a)) */ | |
| 71 /* 25*/ { BARCODE_UPCE, "456784", 0, "04567840" }, /* equivalent: 04567000008, Check digit: 0 (BS 797 Rule 3 (b)) */ | |
| 72 /* 26*/ { BARCODE_UPCE_CHK, "4567840", 0, "04567840" }, /* equivalent: 04567000008, Check digit: 0 (BS 797 Rule 3 (b)) */ | |
| 73 /* 27*/ { BARCODE_UPCE, "345670", 0, "03456703" }, /* equivalent: 03400000567, Check digit: 3 (BS 797 Rule 3 (c)) */ | |
| 74 /* 28*/ { BARCODE_UPCE_CHK, "3456703", 0, "03456703" }, /* equivalent: 03400000567, Check digit: 3 (BS 797 Rule 3 (c)) */ | |
| 75 /* 29*/ { BARCODE_UPCE, "984753", 0, "09847531" }, /* equivalent: 09840000075, Check digit: 1 (BS 797 Rule 3 (d)) */ | |
| 76 /* 30*/ { BARCODE_UPCE_CHK, "9847531", 0, "09847531" }, /* equivalent: 09840000075, Check digit: 1 (BS 797 Rule 3 (d)) */ | |
| 77 /* 31*/ { BARCODE_UPCE, "120453", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 3, 3rd can't be 0, 1 or 2 (BS 787 Table 5 NOTE 1) */ | |
| 78 /* 32*/ { BARCODE_UPCE, "121453", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 3, 3rd can't be 0, 1 or 2 (BS 787 Table 5 NOTE 1) */ | |
| 79 /* 33*/ { BARCODE_UPCE, "122453", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 3, 3rd can't be 0, 1 or 2 (BS 787 Table 5 NOTE 1) */ | |
| 80 /* 34*/ { BARCODE_UPCE, "123453", 0, "01234531" }, | |
| 81 /* 35*/ { BARCODE_UPCE, "123054", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 4, 4th can't be 0 (BS 787 Table 5 NOTE 2) */ | |
| 82 /* 36*/ { BARCODE_UPCE, "123154", 0, "01231542" }, | |
| 83 /* 37*/ { BARCODE_UPCE, "123405", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 5, 5th can't be 0 (BS 787 Table 5 NOTE 3) */ | |
| 84 /* 38*/ { BARCODE_UPCE, "123455", 0, "01234558" }, | |
| 85 /* 39*/ { BARCODE_UPCE, "123406", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 6, 5th can't be 0 (BS 787 Table 5 NOTE 3) */ | |
| 86 /* 40*/ { BARCODE_UPCE, "123456", 0, "01234565" }, | |
| 87 /* 41*/ { BARCODE_UPCE, "123407", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 7, 5th can't be 0 (BS 787 Table 5 NOTE 3) */ | |
| 88 /* 42*/ { BARCODE_UPCE, "123457", 0, "01234572" }, | |
| 89 /* 43*/ { BARCODE_UPCE, "123408", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 8, 5th can't be 0 (BS 787 Table 5 NOTE 3) */ | |
| 90 /* 44*/ { BARCODE_UPCE, "123458", 0, "01234589" }, | |
| 91 /* 45*/ { BARCODE_UPCE, "123409", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 9, 5th can't be 0 (BS 787 Table 5 NOTE 3) */ | |
| 92 /* 46*/ { BARCODE_UPCE, "123459", 0, "01234596" }, | |
| 93 /* 47*/ { BARCODE_UPCE, "000000", 0, "00000000" }, | |
| 94 /* 48*/ { BARCODE_UPCE, "000001", 0, "00000019" }, | |
| 95 /* 49*/ { BARCODE_UPCE, "000002", 0, "00000028" }, | |
| 96 }; | |
| 97 const int data_size = ARRAY_SIZE(data); | |
| 98 int i, length, ret; | |
| 99 struct zint_symbol *symbol = NULL; | |
| 100 | |
| 101 char escaped[4096]; | |
| 102 char cmp_buf[4096]; | |
| 103 char cmp_msg[1024]; | |
| 104 | |
| 105 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */ | |
| 106 int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */ | |
| 107 | |
| 108 testStartSymbol("test_upce_input", &symbol); | |
| 109 | |
| 110 for (i = 0; i < data_size; i++) { | |
| 111 | |
| 112 if (testContinue(p_ctx, i)) continue; | |
| 113 | |
| 114 symbol = ZBarcode_Create(); | |
| 115 assert_nonnull(symbol, "Symbol not created\n"); | |
| 116 | |
| 117 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 118 | |
| 119 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 120 assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 121 | |
| 122 if (ret < ZINT_ERROR) { | |
| 123 if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { | |
| 124 char modules_dump[8192 + 1]; | |
| 125 assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i); | |
| 126 ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].hrt, (int) strlen(data[i].hrt), NULL, cmp_buf, sizeof(cmp_buf), NULL); | |
| 127 assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 128 | |
| 129 ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump); | |
| 130 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", | |
| 131 i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump); | |
| 132 } | |
| 133 if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) { | |
| 134 int cmp_len, ret_len; | |
| 135 char modules_dump[8192 + 1]; | |
| 136 assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i); | |
| 137 ret = testUtilZXingCPP(i, symbol, data[i].data, length, modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len); | |
| 138 assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 139 | |
| 140 ret = testUtilZXingCPPCmp(symbol, cmp_msg, cmp_buf, cmp_len, data[i].hrt, (int) strlen(data[i].hrt), NULL /*primary*/, escaped, &ret_len); | |
| 141 assert_zero(ret, "i:%d %s testUtilZXingCPPCmp %d != 0 %s\n actual: %.*s\nexpected: %.*s\n", | |
| 142 i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped); | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 ZBarcode_Delete(symbol); | |
| 147 } | |
| 148 | |
| 149 testFinish(); | |
| 150 } | |
| 151 | |
| 152 /* Note requires ZINT_SANITIZE to be set */ | |
| 153 static void test_upca_print(const testCtx *const p_ctx) { | |
| 154 int debug = p_ctx->debug; | |
| 155 | |
| 156 struct item { | |
| 157 int symbology; | |
| 158 char *data; | |
| 159 int ret; | |
| 160 }; | |
| 161 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 162 static const struct item data[] = { | |
| 163 /* 0*/ { BARCODE_UPCA, "01234567890", 0 }, | |
| 164 }; | |
| 165 const int data_size = ARRAY_SIZE(data); | |
| 166 int i, length, ret; | |
| 167 struct zint_symbol *symbol = NULL; | |
| 168 | |
| 169 testStartSymbol("test_upca_print", &symbol); | |
| 170 | |
| 171 for (i = 0; i < data_size; i++) { | |
| 172 | |
| 173 if (testContinue(p_ctx, i)) continue; | |
| 174 | |
| 175 symbol = ZBarcode_Create(); | |
| 176 assert_nonnull(symbol, "Symbol not created\n"); | |
| 177 | |
| 178 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 179 | |
| 180 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 181 assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 182 | |
| 183 strcpy(symbol->outfile, "out.gif"); | |
| 184 ret = ZBarcode_Print(symbol, 0); | |
| 185 assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt); | |
| 186 | |
| 187 assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile); | |
| 188 | |
| 189 ZBarcode_Delete(symbol); | |
| 190 } | |
| 191 | |
| 192 testFinish(); | |
| 193 } | |
| 194 | |
| 195 static void test_upca_input(const testCtx *const p_ctx) { | |
| 196 int debug = p_ctx->debug; | |
| 197 | |
| 198 struct item { | |
| 199 int symbology; | |
| 200 char *data; | |
| 201 int ret; | |
| 202 char *expected_errtxt; | |
| 203 }; | |
| 204 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 205 static const struct item data[] = { | |
| 206 /* 0*/ { BARCODE_UPCA, "12345678901", 0, "" }, | |
| 207 /* 1*/ { BARCODE_UPCA, "1234567890", 0, "" }, | |
| 208 /* 2*/ { BARCODE_UPCA, "123456789012", 0, "" }, /* UPC-A accepts CHK */ | |
| 209 /* 3*/ { BARCODE_UPCA, "123456789011", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '1', expecting '2'" }, | |
| 210 /* 4*/ { BARCODE_UPCA, "1234567890123", ZINT_ERROR_TOO_LONG, "Error 288: Input length 13 wrong (11 or 12 only)" }, | |
| 211 /* 5*/ { BARCODE_UPCA, "123456789012A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 13 in input (digits and \"+\" only)" }, | |
| 212 /* 6*/ { BARCODE_UPCA, "12345678901A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 12 in input (digits and \"+\" only)" }, | |
| 213 /* 7*/ { BARCODE_UPCA, "12345", 0, "" }, | |
| 214 /* 8*/ { BARCODE_UPCA, "1X345", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 2 in input (digits and \"+\" only)" }, | |
| 215 /* 9*/ { BARCODE_UPCA, "01A345", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 3 in input (digits and \"+\" only)" }, | |
| 216 /* 10*/ { BARCODE_UPCA, "12345678901+1", 0, "" }, | |
| 217 /* 11*/ { BARCODE_UPCA, "123456789012+1", 0, "" }, | |
| 218 /* 12*/ { BARCODE_UPCA, "123456789013+1", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '3', expecting '2'" }, | |
| 219 /* 13*/ { BARCODE_UPCA, "12345678901+12", 0, "" }, | |
| 220 /* 14*/ { BARCODE_UPCA, "123456789012+12", 0, "" }, | |
| 221 /* 15*/ { BARCODE_UPCA, "123456789014+12", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '4', expecting '2'" }, | |
| 222 /* 16*/ { BARCODE_UPCA, "12345678901+123", 0, "" }, | |
| 223 /* 17*/ { BARCODE_UPCA, "123456789012+123", 0, "" }, | |
| 224 /* 18*/ { BARCODE_UPCA, "123456789015+123", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '5', expecting '2'" }, | |
| 225 /* 19*/ { BARCODE_UPCA, "123456789012+1234", 0, "" }, | |
| 226 /* 20*/ { BARCODE_UPCA, "123456789016+1234", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '6', expecting '2'" }, | |
| 227 /* 21*/ { BARCODE_UPCA, "123456789012+12345", 0, "" }, | |
| 228 /* 22*/ { BARCODE_UPCA, "123456789017+12345", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '7', expecting '2'" }, | |
| 229 /* 23*/ { BARCODE_UPCA, "123456789012+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)" }, | |
| 230 /* 24*/ { BARCODE_UPCA, "123456789017+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)" }, | |
| 231 /* 25*/ { BARCODE_UPCA, "123456789017+12345A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 19 in input (digits and \"+\" only)" }, | |
| 232 /* 26*/ { BARCODE_UPCA_CHK, "123456789012", 0, "" }, | |
| 233 /* 27*/ { BARCODE_UPCA_CHK, "123456789011", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '1', expecting '2'" }, | |
| 234 /* 28*/ { BARCODE_UPCA_CHK, "1234567890123", ZINT_ERROR_TOO_LONG, "Error 288: Input length 13 wrong (11 or 12 only)" }, | |
| 235 /* 29*/ { BARCODE_UPCA_CHK, "123456789012A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 13 in input (digits and \"+\" only)" }, | |
| 236 /* 30*/ { BARCODE_UPCA_CHK, "12345678901A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 12 in input (digits and \"+\" only)" }, | |
| 237 /* 31*/ { BARCODE_UPCA_CHK, "12345678901", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '1', expecting '5'" }, | |
| 238 /* 32*/ { BARCODE_UPCA_CHK, "12345678905", 0, "" }, | |
| 239 /* 33*/ { BARCODE_UPCA_CHK, "1234567890", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '0', expecting '5'" }, | |
| 240 /* 34*/ { BARCODE_UPCA_CHK, "1234567895", 0, "" }, | |
| 241 /* 35*/ { BARCODE_UPCA_CHK, "123456789", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '9', expecting '4'" }, | |
| 242 /* 36*/ { BARCODE_UPCA_CHK, "123456784", 0, "" }, | |
| 243 /* 37*/ { BARCODE_UPCA_CHK, "12345678", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '8', expecting '0'" }, | |
| 244 /* 38*/ { BARCODE_UPCA_CHK, "12345670", 0, "" }, | |
| 245 /* 39*/ { BARCODE_UPCA_CHK, "1234567", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '7', expecting '5'" }, | |
| 246 /* 40*/ { BARCODE_UPCA_CHK, "1234565", 0, "" }, | |
| 247 /* 41*/ { BARCODE_UPCA_CHK, "123456", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '6', expecting '7'" }, | |
| 248 /* 42*/ { BARCODE_UPCA_CHK, "123457", 0, "" }, | |
| 249 /* 43*/ { BARCODE_UPCA_CHK, "12345", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '5', expecting '8'" }, | |
| 250 /* 44*/ { BARCODE_UPCA_CHK, "12348", 0, "" }, | |
| 251 /* 45*/ { BARCODE_UPCA_CHK, "1234", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '4', expecting '6'" }, | |
| 252 /* 46*/ { BARCODE_UPCA_CHK, "1236", 0, "" }, | |
| 253 /* 47*/ { BARCODE_UPCA_CHK, "123", 0, "" }, /* Happens to be correct check digit */ | |
| 254 /* 48*/ { BARCODE_UPCA_CHK, "124", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '4', expecting '3'" }, | |
| 255 /* 49*/ { BARCODE_UPCA_CHK, "12", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '2', expecting '7'" }, | |
| 256 /* 50*/ { BARCODE_UPCA_CHK, "17", 0, "" }, | |
| 257 /* 51*/ { BARCODE_UPCA_CHK, "1", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '1', expecting '0'" }, | |
| 258 /* 52*/ { BARCODE_UPCA_CHK, "0", 0, "" }, | |
| 259 /* 53*/ { BARCODE_UPCA_CHK, "12345678905+12", 0, "" }, | |
| 260 /* 54*/ { BARCODE_UPCA_CHK, "12345678905+12345", 0, "" }, | |
| 261 /* 55*/ { BARCODE_UPCA_CHK, "12345678905+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)" }, | |
| 262 /* 56*/ { BARCODE_UPCA_CHK, "12345678905+12345A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 18 in input (digits and \"+\" only)" }, | |
| 263 /* 57*/ { BARCODE_UPCA_CHK, "12345678905+1234A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 17 in input (digits and \"+\" only)" }, | |
| 264 /* 58*/ { BARCODE_UPCA_CHK, "1234567895+12345", 0, "" }, | |
| 265 /* 59*/ { BARCODE_UPCA_CHK, "1234567891+12345", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '1', expecting '5'" }, | |
| 266 /* 60*/ { BARCODE_UPCA_CHK, "123456784+12345", 0, "" }, | |
| 267 /* 61*/ { BARCODE_UPCA_CHK, "123456782+12345", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '2', expecting '4'" }, | |
| 268 /* 62*/ { BARCODE_UPCA_CHK, "12345670+12345", 0, "" }, | |
| 269 /* 63*/ { BARCODE_UPCA_CHK, "12345673+12345", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '3', expecting '0'" }, | |
| 270 /* 64*/ { BARCODE_UPCA_CHK, "1234565+12345", 0, "" }, | |
| 271 /* 65*/ { BARCODE_UPCA_CHK, "1234564+12345", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '4', expecting '5'" }, | |
| 272 /* 66*/ { BARCODE_UPCA_CHK, "123457+12345", 0, "" }, | |
| 273 /* 67*/ { BARCODE_UPCA_CHK, "123455+12345", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '5', expecting '7'" }, | |
| 274 /* 68*/ { BARCODE_UPCA_CHK, "12348+12345", 0, "" }, | |
| 275 /* 69*/ { BARCODE_UPCA_CHK, "12346+12345", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '6', expecting '8'" }, | |
| 276 /* 70*/ { BARCODE_UPCA_CHK, "1236+12345", 0, "" }, | |
| 277 /* 71*/ { BARCODE_UPCA_CHK, "1237+12345", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '7', expecting '6'" }, | |
| 278 /* 72*/ { BARCODE_UPCA_CHK, "123+12345", 0, "" }, | |
| 279 /* 73*/ { BARCODE_UPCA_CHK, "128+12345", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '8', expecting '3'" }, | |
| 280 /* 74*/ { BARCODE_UPCA_CHK, "17+12345", 0, "" }, | |
| 281 /* 75*/ { BARCODE_UPCA_CHK, "19+12345", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '9', expecting '7'" }, | |
| 282 /* 76*/ { BARCODE_UPCA_CHK, "1+12345", ZINT_ERROR_INVALID_CHECK, "Error 270: Invalid check digit '1', expecting '0'" }, | |
| 283 /* 77*/ { BARCODE_UPCA_CHK, "0+12345", 0, "" }, | |
| 284 }; | |
| 285 const int data_size = ARRAY_SIZE(data); | |
| 286 int i, length, ret; | |
| 287 struct zint_symbol *symbol = NULL; | |
| 288 | |
| 289 testStartSymbol("test_upca_input", &symbol); | |
| 290 | |
| 291 for (i = 0; i < data_size; i++) { | |
| 292 | |
| 293 if (testContinue(p_ctx, i)) continue; | |
| 294 | |
| 295 symbol = ZBarcode_Create(); | |
| 296 assert_nonnull(symbol, "Symbol not created\n"); | |
| 297 | |
| 298 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 299 | |
| 300 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 301 assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 302 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt); | |
| 303 | |
| 304 ZBarcode_Delete(symbol); | |
| 305 } | |
| 306 | |
| 307 testFinish(); | |
| 308 } | |
| 309 | |
| 310 static void test_eanx_input(const testCtx *const p_ctx) { | |
| 311 int debug = p_ctx->debug; | |
| 312 | |
| 313 struct item { | |
| 314 int symbology; | |
| 315 char *data; | |
| 316 int ret; | |
| 317 char *ret_errtxt; | |
| 318 char *comment; | |
| 319 }; | |
| 320 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 321 static const struct item data[] = { | |
| 322 /* 0*/ { BARCODE_EANX, "123456789012", 0, "", "" }, | |
| 323 /* 1*/ { BARCODE_EANX, "12345678901A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 12 in input (digits and \"+\" only)", "" }, | |
| 324 /* 2*/ { BARCODE_EANX, "12345A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 6 in input (digits and \"+\" only)", "" }, | |
| 325 /* 3*/ { BARCODE_EANX, "123A56", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 4 in input (digits and \"+\" only)", "" }, | |
| 326 /* 4*/ { BARCODE_EANX, "12345678901", 0, "", "" }, | |
| 327 /* 5*/ { BARCODE_EANX, "1234567890128", 0, "", "EANX accepts CHK (treated as such if no leading zeroes required)" }, | |
| 328 /* 6*/ { BARCODE_EANX, "1234567890120", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '0', expecting '8'", "" }, | |
| 329 /* 7*/ { BARCODE_EANX, "123456789012+1", 0, "", "" }, | |
| 330 /* 8*/ { BARCODE_EANX, "1234567890128+1", 0, "", "" }, | |
| 331 /* 9*/ { BARCODE_EANX, "1234567890121+1", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '1', expecting '8'", "" }, | |
| 332 /* 10*/ { BARCODE_EANX, "123456789012+12", 0, "", "" }, | |
| 333 /* 11*/ { BARCODE_EANX, "1234567890128+12", 0, "", "" }, | |
| 334 /* 12*/ { BARCODE_EANX, "1234567890122+12", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '2', expecting '8'", "" }, | |
| 335 /* 13*/ { BARCODE_EANX, "12345678901234+12", ZINT_ERROR_TOO_LONG, "Error 298: Input EAN length 14 too long (maximum 13)", "" }, | |
| 336 /* 14*/ { BARCODE_EANX, "123456789012345+12", ZINT_ERROR_TOO_LONG, "Error 298: Input EAN length 15 too long (maximum 13)", "" }, | |
| 337 /* 15*/ { BARCODE_EANX, "1234567890123456+12", ZINT_ERROR_TOO_LONG, "Error 298: Input EAN length 16 too long (maximum 13)", "" }, | |
| 338 /* 16*/ { BARCODE_EANX, "123456789012+123", 0, "", "" }, | |
| 339 /* 17*/ { BARCODE_EANX, "1234567890128+123", 0, "", "" }, | |
| 340 /* 18*/ { BARCODE_EANX, "1234567890123+123", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '3', expecting '8'", "" }, | |
| 341 /* 19*/ { BARCODE_EANX, "12345678901234+123", ZINT_ERROR_TOO_LONG, "Error 298: Input EAN length 14 too long (maximum 13)", "" }, | |
| 342 /* 20*/ { BARCODE_EANX, "123456789012345+123", ZINT_ERROR_TOO_LONG, "Error 298: Input EAN length 15 too long (maximum 13)", "" }, | |
| 343 /* 21*/ { BARCODE_EANX, "123456789012+1234", 0, "", "" }, | |
| 344 /* 22*/ { BARCODE_EANX, "1234567890128+1234", 0, "", "" }, | |
| 345 /* 23*/ { BARCODE_EANX, "1234567890124+1234", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '4', expecting '8'", "" }, | |
| 346 /* 24*/ { BARCODE_EANX, "12345678901234+1234", ZINT_ERROR_TOO_LONG, "Error 298: Input EAN length 14 too long (maximum 13)", "" }, | |
| 347 /* 25*/ { BARCODE_EANX, "123456789012+12345", 0, "", "" }, | |
| 348 /* 26*/ { BARCODE_EANX, "1234567890128+12345", 0, "", "" }, | |
| 349 /* 27*/ { BARCODE_EANX, "12345678901234+12345", ZINT_ERROR_TOO_LONG, "Error 283: Input length 20 too long (maximum 19)", "" }, | |
| 350 /* 28*/ { BARCODE_EANX, "1234567890125+12345", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '5', expecting '8'", "" }, | |
| 351 /* 29*/ { BARCODE_EANX, "123456789012+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 352 /* 30*/ { BARCODE_EANX, "1234567890128+123456", ZINT_ERROR_TOO_LONG, "Error 283: Input length 20 too long (maximum 19)", "" }, | |
| 353 /* 31*/ { BARCODE_EANX, "12345678901+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 354 /* 32*/ { BARCODE_EANX, "12345678901+1234567", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 7 too long (maximum 5)", "" }, | |
| 355 /* 33*/ { BARCODE_EANX, "1234567890+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 356 /* 34*/ { BARCODE_EANX, "1234567890+1234567", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 7 too long (maximum 5)", "" }, | |
| 357 /* 35*/ { BARCODE_EANX, "123456789+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 358 /* 36*/ { BARCODE_EANX, "123456789+1234567", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 7 too long (maximum 5)", "" }, | |
| 359 /* 37*/ { BARCODE_EANX, "12345678+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 360 /* 38*/ { BARCODE_EANX, "1234567+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "EAN-8" }, | |
| 361 /* 39*/ { BARCODE_EANX, "123456+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 362 /* 40*/ { BARCODE_EANX, "12345+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 363 /* 41*/ { BARCODE_EANX, "1234+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 364 /* 42*/ { BARCODE_EANX, "123+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 365 /* 43*/ { BARCODE_EANX, "12+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 366 /* 44*/ { BARCODE_EANX, "1+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 367 /* 45*/ { BARCODE_EANX, "1+12345678901234", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 14 too long (maximum 5)", "" }, | |
| 368 /* 46*/ { BARCODE_EANX, "1+12345", 0, "", "" }, | |
| 369 /* 47*/ { BARCODE_EANX, "1+", 0, "", "EAN-2" }, | |
| 370 /* 48*/ { BARCODE_EANX, "+1", 0, "", "EAN-8" }, | |
| 371 /* 49*/ { BARCODE_EANX, "+", 0, "", "EAN-2" }, | |
| 372 /* 50*/ { BARCODE_EANX, "1", 0, "", "EAN-2" }, | |
| 373 /* 51*/ { BARCODE_EANX, "12", 0, "", "EAN-2" }, | |
| 374 /* 52*/ { BARCODE_EANX, "123", 0, "", "EAN-5" }, | |
| 375 /* 53*/ { BARCODE_EANX, "12345678901234", ZINT_ERROR_TOO_LONG, "Error 294: Input length 14 too long (maximum 13)", "" }, | |
| 376 /* 54*/ { BARCODE_EANX, "1234567890123A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 14 in input (digits and \"+\" only)", "" }, | |
| 377 /* 55*/ { BARCODE_EANX, "123456789012345", ZINT_ERROR_TOO_LONG, "Error 294: Input length 15 too long (maximum 13)", "" }, | |
| 378 /* 56*/ { BARCODE_EANX, "12345678901234A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 15 in input (digits and \"+\" only)", "" }, | |
| 379 /* 57*/ { BARCODE_EANX, "1234567890123456", ZINT_ERROR_TOO_LONG, "Error 294: Input length 16 too long (maximum 13)", "" }, | |
| 380 /* 58*/ { BARCODE_EANX, "12345678901234567", ZINT_ERROR_TOO_LONG, "Error 294: Input length 17 too long (maximum 13)", "" }, | |
| 381 /* 59*/ { BARCODE_EANX, "123456789012345678", ZINT_ERROR_TOO_LONG, "Error 294: Input length 18 too long (maximum 13)", "" }, | |
| 382 /* 60*/ { BARCODE_EANX, "1234567890123456789", ZINT_ERROR_TOO_LONG, "Error 294: Input length 19 too long (maximum 13)", "" }, | |
| 383 /* 61*/ { BARCODE_EANX_CHK, "1234567890128", 0, "", "" }, | |
| 384 /* 62*/ { BARCODE_EANX_CHK, "1234567890126", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '6', expecting '8'", "" }, | |
| 385 /* 63*/ { BARCODE_EANX_CHK, "123456789012A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 13 in input (digits and \"+\" only)", "" }, | |
| 386 /* 64*/ { BARCODE_EANX_CHK, "123456789012", 0, "", "Note: this is '0123456789012' with '2' happening to be the correct check digit" }, | |
| 387 /* 65*/ { BARCODE_EANX_CHK, "123456789013", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '3', expecting '2'", "" }, | |
| 388 /* 66*/ { BARCODE_EANX_CHK, "12345678901", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '1', expecting '5'", "" }, | |
| 389 /* 67*/ { BARCODE_EANX_CHK, "12345678905", 0, "", "" }, | |
| 390 /* 68*/ { BARCODE_EANX_CHK, "1234567890", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '0', expecting '5'", "" }, | |
| 391 /* 69*/ { BARCODE_EANX_CHK, "123456789", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '9', expecting '4'", "" }, | |
| 392 /* 70*/ { BARCODE_EANX_CHK, "12345678", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '8', expecting '0'", "EAN-8" }, | |
| 393 /* 71*/ { BARCODE_EANX_CHK, "1234567", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '7', expecting '5'", "" }, | |
| 394 /* 72*/ { BARCODE_EANX_CHK, "123456", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '6', expecting '7'", "" }, | |
| 395 /* 73*/ { BARCODE_EANX_CHK, "12345", 0, "", "EAN-5" }, | |
| 396 /* 74*/ { BARCODE_EANX_CHK, "1234", 0, "", "" }, | |
| 397 /* 75*/ { BARCODE_EANX_CHK, "123", 0, "", "" }, | |
| 398 /* 76*/ { BARCODE_EANX_CHK, "12", 0, "", "EAN-2" }, | |
| 399 /* 77*/ { BARCODE_EANX_CHK, "1", 0, "", "" }, | |
| 400 /* 78*/ { BARCODE_EANX_CHK, "123456789012+1", 0, "", "" }, | |
| 401 /* 79*/ { BARCODE_EANX_CHK, "1234567890128+1", 0, "", "" }, | |
| 402 /* 80*/ { BARCODE_EANX_CHK, "1234567890127+1", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '7', expecting '8'", "" }, | |
| 403 /* 81*/ { BARCODE_EANX_CHK, "123456789012+12", 0, "", "" }, | |
| 404 /* 82*/ { BARCODE_EANX_CHK, "1234567890128+12", 0, "", "" }, | |
| 405 /* 83*/ { BARCODE_EANX_CHK, "1234567890129+12", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '9', expecting '8'", "" }, | |
| 406 /* 84*/ { BARCODE_EANX_CHK, "123456789012+123", 0, "", "" }, | |
| 407 /* 85*/ { BARCODE_EANX_CHK, "1234567890128+123", 0, "", "" }, | |
| 408 /* 86*/ { BARCODE_EANX_CHK, "1234567890120+1234", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '0', expecting '8'", "" }, | |
| 409 /* 87*/ { BARCODE_EANX_CHK, "123456789012+1234", 0, "", "" }, | |
| 410 /* 88*/ { BARCODE_EANX_CHK, "1234567890128+1234", 0, "", "" }, | |
| 411 /* 89*/ { BARCODE_EANX_CHK, "1234567890121+1234", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '1', expecting '8'", "" }, | |
| 412 /* 90*/ { BARCODE_EANX_CHK, "123456789012+12345", 0, "", "" }, | |
| 413 /* 91*/ { BARCODE_EANX_CHK, "1234567890128+12345", 0, "", "" }, | |
| 414 /* 92*/ { BARCODE_EANX_CHK, "1234567890122+12345", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '2', expecting '8'", "" }, | |
| 415 /* 93*/ { BARCODE_EANX_CHK, "1234567890122+1234A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 19 in input (digits and \"+\" only)", "" }, | |
| 416 /* 94*/ { BARCODE_EANX_CHK, "123456789012+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 417 /* 95*/ { BARCODE_EANX_CHK, "123456789012+12345A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 19 in input (digits and \"+\" only)", "" }, | |
| 418 /* 96*/ { BARCODE_EANX_CHK, "1234567890128+123456", ZINT_ERROR_TOO_LONG, "Error 283: Input length 20 too long (maximum 19)", "" }, | |
| 419 /* 97*/ { BARCODE_EANX_CHK, "12345678901+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 420 /* 98*/ { BARCODE_EANX_CHK, "12345678901+1234567", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 7 too long (maximum 5)", "" }, | |
| 421 /* 99*/ { BARCODE_EANX_CHK, "12345678901+12345", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '1', expecting '5'", "" }, | |
| 422 /*100*/ { BARCODE_EANX_CHK, "1234567890+12345", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '0', expecting '5'", "" }, | |
| 423 /*101*/ { BARCODE_EANX_CHK, "1234567890+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 424 /*102*/ { BARCODE_EANX_CHK, "123456789+12345", ZINT_ERROR_INVALID_CHECK, "Error 275: Invalid check digit '9', expecting '4'", "" }, | |
| 425 /*103*/ { BARCODE_EANX_CHK, "12345678+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '8', expecting '0'", "EAN-8" }, | |
| 426 /*104*/ { BARCODE_EANX_CHK, "12345670+12345", 0, "", "" }, | |
| 427 /*105*/ { BARCODE_EANX_CHK, "1234567+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '7', expecting '5'", "" }, | |
| 428 /*106*/ { BARCODE_EANX_CHK, "1234565+12345", 0, "", "" }, | |
| 429 /*107*/ { BARCODE_EANX_CHK, "123456+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '6', expecting '7'", "" }, | |
| 430 /*108*/ { BARCODE_EANX_CHK, "123457+12345", 0, "", "" }, | |
| 431 /*109*/ { BARCODE_EANX_CHK, "12345+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '5', expecting '8'", "" }, | |
| 432 /*110*/ { BARCODE_EANX_CHK, "12348+12345", 0, "", "" }, | |
| 433 /*111*/ { BARCODE_EANX_CHK, "1234+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '4', expecting '6'", "" }, | |
| 434 /*112*/ { BARCODE_EANX_CHK, "1236+12345", 0, "", "" }, | |
| 435 /*113*/ { BARCODE_EANX_CHK, "123+12345", 0, "", "3 happens to be correct check digit" }, | |
| 436 /*114*/ { BARCODE_EANX_CHK, "124+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '4', expecting '3'", "" }, | |
| 437 /*115*/ { BARCODE_EANX_CHK, "12+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '2', expecting '7'", "" }, | |
| 438 /*116*/ { BARCODE_EANX_CHK, "17+12345", 0, "", "" }, | |
| 439 /*117*/ { BARCODE_EANX_CHK, "1+12345", ZINT_ERROR_INVALID_CHECK, "Error 276: Invalid check digit '1', expecting '0'", "" }, | |
| 440 /*118*/ { BARCODE_EANX_CHK, "0+12345", 0, "", "" }, | |
| 441 /*119*/ { BARCODE_EANX_CHK, "0+123456", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 442 /*120*/ { BARCODE_EANX_CHK, "1+12345678901234", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 14 too long (maximum 5)", "" }, | |
| 443 /*121*/ { BARCODE_EANX_CHK, "0+12345678901234", ZINT_ERROR_TOO_LONG, "Error 297: Input add-on length 14 too long (maximum 5)", "" }, | |
| 444 /*122*/ { BARCODE_EANX_CHK, "1+", 0, "", "EAN-2" }, | |
| 445 /*123*/ { BARCODE_EANX_CHK, "+1", 0, "", "EAN-8" }, | |
| 446 /*124*/ { BARCODE_EANX_CHK, "+", 0, "", "EAN-2" }, | |
| 447 /*125*/ { BARCODE_EANX_CHK, "12345678901234", ZINT_ERROR_TOO_LONG, "Error 294: Input length 14 too long (maximum 13)", "" }, | |
| 448 /*126*/ { BARCODE_EANX_CHK, "1234567890123A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character at position 14 in input (digits and \"+\" only)", "" }, | |
| 449 /*127*/ { BARCODE_EANX_CHK, "123456789012345", ZINT_ERROR_TOO_LONG, "Error 294: Input length 15 too long (maximum 13)", "" }, | |
| 450 /*128*/ { BARCODE_EANX_CHK, "1234567890123456", ZINT_ERROR_TOO_LONG, "Error 294: Input length 16 too long (maximum 13)", "" }, | |
| 451 /*129*/ { BARCODE_EANX_CHK, "12345678901234567", ZINT_ERROR_TOO_LONG, "Error 294: Input length 17 too long (maximum 13)", "" }, | |
| 452 /*130*/ { BARCODE_EANX_CHK, "123456789012345678", ZINT_ERROR_TOO_LONG, "Error 294: Input length 18 too long (maximum 13)", "" }, | |
| 453 /*131*/ { BARCODE_EANX_CHK, "1234567890123456789", ZINT_ERROR_TOO_LONG, "Error 294: Input length 19 too long (maximum 13)", "" }, | |
| 454 }; | |
| 455 const int data_size = ARRAY_SIZE(data); | |
| 456 int i, length, ret; | |
| 457 struct zint_symbol *symbol = NULL; | |
| 458 | |
| 459 char errtxt_escaped[256]; | |
| 460 | |
| 461 testStartSymbol("test_eanx_input", &symbol); | |
| 462 | |
| 463 for (i = 0; i < data_size; i++) { | |
| 464 | |
| 465 if (testContinue(p_ctx, i)) continue; | |
| 466 | |
| 467 symbol = ZBarcode_Create(); | |
| 468 assert_nonnull(symbol, "Symbol not created\n"); | |
| 469 | |
| 470 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 471 | |
| 472 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 473 | |
| 474 if (p_ctx->generate) { | |
| 475 printf(" /*%3d*/ { %s, \"%s\", %s, \"%s\", \"%s\" },\n", | |
| 476 i, testUtilBarcodeName(data[i].symbology), data[i].data, testUtilErrorName(data[i].ret), | |
| 477 testUtilEscape(symbol->errtxt, (int) strlen(symbol->errtxt), errtxt_escaped, sizeof(errtxt_escaped)), | |
| 478 data[i].comment); | |
| 479 } else { | |
| 480 assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 481 assert_zero(strcmp(symbol->errtxt, data[i].ret_errtxt), "i:%d errtxt %s != %s\n", i, symbol->errtxt, data[i].ret_errtxt); | |
| 482 } | |
| 483 | |
| 484 ZBarcode_Delete(symbol); | |
| 485 } | |
| 486 | |
| 487 testFinish(); | |
| 488 } | |
| 489 | |
| 490 static void test_isbn_input(const testCtx *const p_ctx) { | |
| 491 int debug = p_ctx->debug; | |
| 492 | |
| 493 struct item { | |
| 494 char *data; | |
| 495 int ret_encode; | |
| 496 int ret_vector; | |
| 497 char *ret_errtxt; | |
| 498 char *comment; | |
| 499 }; | |
| 500 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 501 static const struct item data[] = { | |
| 502 /* 0*/ { "0", 0, 0, "", "Left zero-padded if < 10 chars" }, | |
| 503 /* 1*/ { "1", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '1', expecting '0'", "" }, | |
| 504 /* 2*/ { "X", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit 'X', expecting '0'", "" }, | |
| 505 /* 3*/ { "12", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '2', expecting '9'", "" }, | |
| 506 /* 4*/ { "19", 0, 0, "", "" }, | |
| 507 /* 5*/ { "X9", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 508 /* 6*/ { "123", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '3', expecting '4'", "" }, | |
| 509 /* 7*/ { "124", 0, 0, "", "" }, | |
| 510 /* 8*/ { "1X4", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 511 /* 9*/ { "1234", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '4', expecting '6'", "" }, | |
| 512 /* 10*/ { "1236", 0, 0, "", "" }, | |
| 513 /* 11*/ { "12X6", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 514 /* 12*/ { "12345", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '5', expecting '3'", "" }, | |
| 515 /* 13*/ { "12343", 0, 0, "", "" }, | |
| 516 /* 14*/ { "123X3", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 517 /* 15*/ { "123456", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '6', expecting '5'", "" }, | |
| 518 /* 16*/ { "123455", 0, 0, "", "" }, | |
| 519 /* 17*/ { "1234X5", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 520 /* 18*/ { "1234567", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '7', expecting '0'", "" }, | |
| 521 /* 19*/ { "1234560", 0, 0, "", "" }, | |
| 522 /* 20*/ { "12345X0", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 523 /* 21*/ { "12345678", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '8', expecting '9'", "" }, | |
| 524 /* 22*/ { "12345679", 0, 0, "", "9 is correct check digit" }, | |
| 525 /* 23*/ { "98765434", 0, 0, "", "4 is correct check digit" }, | |
| 526 /* 24*/ { "123456X9", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 527 /* 25*/ { "123456789", 0, 0, "", "" }, | |
| 528 /* 26*/ { "340013817", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '7', expecting '8'", "" }, | |
| 529 /* 27*/ { "340013818", 0, 0, "", "8 is correct check digit" }, | |
| 530 /* 28*/ { "902888455", 0, 0, "", "5 is correct check digit" }, | |
| 531 /* 29*/ { "9028884X5", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 532 /* 30*/ { "0123456789", 0, 0, "", "" }, | |
| 533 /* 31*/ { "1234567890", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid ISBN check digit '0', expecting 'X'", "" }, | |
| 534 /* 32*/ { "123456789X", 0, 0, "", "X is correct check digit" }, | |
| 535 /* 33*/ { "123456789x", 0, 0, "", "x is correct check digit" }, | |
| 536 /* 34*/ { "8175257660", 0, 0, "", "0 is correct check digit" }, | |
| 537 /* 35*/ { "0590764845", 0, 0, "", "5 is correct check digit" }, | |
| 538 /* 36*/ { "0906495741", 0, 0, "", "1 is correct check digit" }, | |
| 539 /* 37*/ { "0140430016", 0, 0, "", "6 is correct check digit" }, | |
| 540 /* 38*/ { "0571086187", 0, 0, "", "7 is correct check digit" }, | |
| 541 /* 39*/ { "0486600882", 0, 0, "", "2 is correct check digit" }, | |
| 542 /* 40*/ { "04866008X2", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 543 /* 41*/ { "123456789A", ZINT_ERROR_INVALID_DATA, -1, "Error 285: Invalid character at position 10 in input (digits, \"X\" and \"+\" only)", "" }, | |
| 544 /* 42*/ { "12345678901", ZINT_ERROR_TOO_LONG, -1, "Error 278: Input length 11 wrong (9, 10, or 13 only)", "" }, | |
| 545 /* 43*/ { "1234567890A", ZINT_ERROR_INVALID_DATA, -1, "Error 285: Invalid character at position 11 in input (digits, \"X\" and \"+\" only)", "" }, | |
| 546 /* 44*/ { "123456789012", ZINT_ERROR_TOO_LONG, -1, "Error 278: Input length 12 wrong (9, 10, or 13 only)", "" }, | |
| 547 /* 45*/ { "12345678901", ZINT_ERROR_TOO_LONG, -1, "Error 278: Input length 11 wrong (9, 10, or 13 only)", "" }, | |
| 548 /* 46*/ { "123456789012", ZINT_ERROR_TOO_LONG, -1, "Error 278: Input length 12 wrong (9, 10, or 13 only)", "" }, | |
| 549 /* 47*/ { "1234567890123", ZINT_ERROR_INVALID_DATA, -1, "Error 279: Invalid ISBN (must begin with \"978\" or \"979\")", "" }, | |
| 550 /* 48*/ { "9784567890123", ZINT_ERROR_INVALID_CHECK, -1, "Error 280: Invalid ISBN check digit '3', expecting '0'", "" }, | |
| 551 /* 49*/ { "9784567890120", 0, 0, "", "0 is correct check digit" }, | |
| 552 /* 50*/ { "9783161484100", 0, 0, "", "0 is correct check digit" }, | |
| 553 /* 51*/ { "9781846688225", 0, 0, "", "5 is correct check digit" }, | |
| 554 /* 52*/ { "9781847657954", 0, 0, "", "4 is correct check digit" }, | |
| 555 /* 53*/ { "9781846688188", 0, 0, "", "8 is correct check digit" }, | |
| 556 /* 54*/ { "9781847659293", 0, 0, "", "3 is correct check digit" }, | |
| 557 /* 55*/ { "97845678901201", ZINT_ERROR_TOO_LONG, -1, "Error 294: Input length 14 too long (maximum 13)", "" }, | |
| 558 /* 56*/ { "978456789012012", ZINT_ERROR_TOO_LONG, -1, "Error 294: Input length 15 too long (maximum 13)", "" }, | |
| 559 /* 57*/ { "3954994+12", 0, 0, "", "" }, | |
| 560 /* 58*/ { "3954994+1X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" }, | |
| 561 /* 59*/ { "39549X4+12", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 562 /* 60*/ { "3954994+12345", 0, 0, "", "" }, | |
| 563 /* 61*/ { "3954994+1234X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" }, | |
| 564 /* 62*/ { "39549X4+12345", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 565 /* 63*/ { "3954994+123456", ZINT_ERROR_TOO_LONG, -1, "Error 297: Input add-on length 6 too long (maximum 5)", "" }, | |
| 566 /* 64*/ { "3954994+", 0, 0, "", "" }, | |
| 567 /* 65*/ { "3954X94+", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 568 /* 66*/ { "61954993+1", 0, 0, "", "" }, | |
| 569 /* 67*/ { "61954993+X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" }, | |
| 570 /* 68*/ { "619549X3+1", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 571 /* 69*/ { "61954992+123", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '2', expecting '3'", "" }, | |
| 572 /* 70*/ { "61954993+123", 0, 0, "", "" }, | |
| 573 /* 71*/ { "61954993+12X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" }, | |
| 574 /* 72*/ { "619549X3+123", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 575 /* 73*/ { "361954990+12", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '0', expecting '9'", "" }, | |
| 576 /* 74*/ { "361954999+12", 0, 0, "", "" }, | |
| 577 /* 75*/ { "361954999+1X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" }, | |
| 578 /* 76*/ { "3619549X9+12", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 579 /* 77*/ { "361954999+1234", 0, 0, "", "" }, | |
| 580 /* 78*/ { "361954999+123X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" }, | |
| 581 /* 79*/ { "3619549X9+1234", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 582 /* 80*/ { "1999000030+12", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid ISBN check digit '0', expecting 'X'", "" }, | |
| 583 /* 81*/ { "199900003X+12", 0, 0, "", "" }, | |
| 584 /* 82*/ { "199900003x+12", 0, 0, "", "" }, | |
| 585 /* 83*/ { "19990000XX+12", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 586 /* 84*/ { "199900003X+1X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" }, | |
| 587 /* 85*/ { "1999000031+12345", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid ISBN check digit '1', expecting 'X'", "" }, | |
| 588 /* 86*/ { "199900003X+12345", 0, 0, "", "" }, | |
| 589 /* 87*/ { "199900003x+12345", 0, 0, "", "" }, | |
| 590 /* 88*/ { "199900003X+1234X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" }, | |
| 591 /* 89*/ { "19990000XX+12345", ZINT_ERROR_INVALID_DATA, -1, "Error 296: Invalid character in input, \"X\" allowed in last position only", "" }, | |
| 592 /* 90*/ { "199900003X+1234A", ZINT_ERROR_INVALID_DATA, -1, "Error 285: Invalid character at position 16 in input (digits, \"X\" and \"+\" only)", "" }, | |
| 593 /* 91*/ { "9791234567895+12", ZINT_ERROR_INVALID_CHECK, -1, "Error 280: Invalid ISBN check digit '5', expecting '6'", "" }, | |
| 594 /* 92*/ { "9791234567896+12", 0, 0, "", "" }, | |
| 595 /* 93*/ { "9791234567896+1X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" }, | |
| 596 /* 94*/ { "97912345678X6+12", ZINT_ERROR_INVALID_DATA, -1, "Error 282: Invalid character in input, \"X\" not allowed in ISBN-13", "" }, | |
| 597 /* 95*/ { "9791234567897+12345", ZINT_ERROR_INVALID_CHECK, -1, "Error 280: Invalid ISBN check digit '7', expecting '6'", "" }, | |
| 598 /* 96*/ { "9791234567896+12345", 0, 0, "", "" }, | |
| 599 /* 97*/ { "9791234567896+1234X", ZINT_ERROR_INVALID_DATA, -1, "Error 295: Invalid add-on data (digits only)", "" }, | |
| 600 /* 98*/ { "979123456X896+12345", ZINT_ERROR_INVALID_DATA, -1, "Error 282: Invalid character in input, \"X\" not allowed in ISBN-13", "" }, | |
| 601 /* 99*/ { "9791234567892+", ZINT_ERROR_INVALID_CHECK, -1, "Error 280: Invalid ISBN check digit '2', expecting '6'", "" }, | |
| 602 /*100*/ { "9791234567896+", 0, 0, "", "" }, | |
| 603 /*101*/ { "97912345678X6+", ZINT_ERROR_INVALID_DATA, -1, "Error 282: Invalid character in input, \"X\" not allowed in ISBN-13", "" }, | |
| 604 /*102*/ { "97912345678961+", ZINT_ERROR_TOO_LONG, -1, "Error 294: Input length 14 too long (maximum 13)", "" }, | |
| 605 /*103*/ { "97912345678961+12345", ZINT_ERROR_TOO_LONG, -1, "Error 283: Input length 20 too long (maximum 19)", "" }, | |
| 606 /*104*/ { "9791234567896+123456", ZINT_ERROR_TOO_LONG, -1, "Error 283: Input length 20 too long (maximum 19)", "" }, | |
| 607 }; | |
| 608 const int data_size = ARRAY_SIZE(data); | |
| 609 int i, length, ret; | |
| 610 struct zint_symbol *symbol = NULL; | |
| 611 | |
| 612 char errtxt_escaped[256]; | |
| 613 | |
| 614 testStartSymbol("test_isbn_input", &symbol); | |
| 615 | |
| 616 for (i = 0; i < data_size; i++) { | |
| 617 | |
| 618 if (testContinue(p_ctx, i)) continue; | |
| 619 | |
| 620 symbol = ZBarcode_Create(); | |
| 621 assert_nonnull(symbol, "Symbol not created\n"); | |
| 622 | |
| 623 length = testUtilSetSymbol(symbol, BARCODE_ISBNX, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 624 | |
| 625 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 626 | |
| 627 if (p_ctx->generate) { | |
| 628 printf(" /*%3d*/ { \"%s\", %s, %d, \"%s\", \"%s\" },\n", | |
| 629 i, data[i].data, testUtilErrorName(data[i].ret_encode), data[i].ret_vector, | |
| 630 testUtilEscape(symbol->errtxt, (int) strlen(symbol->errtxt), errtxt_escaped, sizeof(errtxt_escaped)), | |
| 631 data[i].comment); | |
| 632 } else { | |
| 633 assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); | |
| 634 assert_zero(strcmp(symbol->errtxt, data[i].ret_errtxt), "i:%d errtxt %s != %s\n", i, symbol->errtxt, data[i].ret_errtxt); | |
| 635 | |
| 636 if (data[i].ret_vector != -1) { | |
| 637 ret = ZBarcode_Buffer_Vector(symbol, 0); | |
| 638 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); | |
| 639 } | |
| 640 } | |
| 641 | |
| 642 ZBarcode_Delete(symbol); | |
| 643 } | |
| 644 | |
| 645 testFinish(); | |
| 646 } | |
| 647 | |
| 648 static void test_hrt(const testCtx *const p_ctx) { | |
| 649 int debug = p_ctx->debug; | |
| 650 | |
| 651 struct item { | |
| 652 int symbology; | |
| 653 char *data; | |
| 654 int ret; | |
| 655 char *expected; | |
| 656 }; | |
| 657 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 658 static const struct item data[] = { | |
| 659 /* 0*/ { BARCODE_EANX, "12345678901", 0, "0123456789012" }, | |
| 660 /* 1*/ { BARCODE_EANX, "123456789012", 0, "1234567890128" }, | |
| 661 /* 2*/ { BARCODE_EANX, "1234567890128", 0, "1234567890128" }, /* EANX accepts CHK (treated as such if no leading zeroes required) */ | |
| 662 /* 3*/ { BARCODE_EANX_CHK, "1234567890128", 0, "1234567890128" }, | |
| 663 /* 4*/ { BARCODE_EANX_CHK, "123456789012", 0, "0123456789012" }, /* '2' happens to be correct check digit for "012345678901" */ | |
| 664 /* 5*/ { BARCODE_EANX, "1234567890128+1", 0, "1234567890128+01" }, | |
| 665 /* 6*/ { BARCODE_EANX_CHK, "1234567890128+1", 0, "1234567890128+01" }, | |
| 666 /* 7*/ { BARCODE_EANX, "12345678", 0, "0000123456784" }, | |
| 667 /* 8*/ { BARCODE_EANX, "1234567", 0, "12345670" }, /* EAN-8 */ | |
| 668 /* 9*/ { BARCODE_EANX_CHK, "12345670", 0, "12345670" }, /* EAN-8 */ | |
| 669 /* 10*/ { BARCODE_EANX, "123456", 0, "01234565" }, /* EAN-8 */ | |
| 670 /* 11*/ { BARCODE_EANX_CHK, "123457", 0, "00123457" }, /* EAN-8 */ | |
| 671 /* 12*/ { BARCODE_EANX, "12345", 0, "12345" }, /* EAN-5 */ | |
| 672 /* 13*/ { BARCODE_EANX, "123", 0, "00123" }, /* EAN-5 */ | |
| 673 /* 14*/ { BARCODE_EANX, "12", 0, "12" }, /* EAN-2 */ | |
| 674 /* 15*/ { BARCODE_EANX, "1", 0, "01" }, /* EAN-2 */ | |
| 675 /* 16*/ { BARCODE_EANX, "0", 0, "00" }, /* EAN-2 */ | |
| 676 /* 17*/ { BARCODE_ISBNX, "0", 0, "9780000000002" }, | |
| 677 /* 18*/ { BARCODE_ISBNX, "123456789X", 0, "9781234567897" }, | |
| 678 /* 19*/ { BARCODE_ISBNX, "9781234567897", 0, "9781234567897" }, | |
| 679 /* 20*/ { BARCODE_ISBNX, "9791234567896+12", 0, "9791234567896+12" }, | |
| 680 /* 21*/ { BARCODE_UPCA, "12345678901", 0, "123456789012" }, | |
| 681 /* 22*/ { BARCODE_UPCA, "123456789012", 0, "123456789012" }, | |
| 682 /* 23*/ { BARCODE_UPCA_CHK, "123456789012", 0, "123456789012" }, | |
| 683 /* 24*/ { BARCODE_UPCA, "12345678905+1", 0, "123456789050+01" }, | |
| 684 /* 25*/ { BARCODE_UPCA_CHK, "123456789050+1", 0, "123456789050+01" }, | |
| 685 /* 26*/ { BARCODE_UPCA, "123456789050+123", 0, "123456789050+00123" }, | |
| 686 /* 27*/ { BARCODE_UPCA_CHK, "123456789050+123", 0, "123456789050+00123" }, | |
| 687 /* 28*/ { BARCODE_UPCE, "12345", 0, "00123457" }, /* equivalent: 00123400005, hrt: 00123457, Check digit: 7 */ | |
| 688 /* 29*/ { BARCODE_UPCE_CHK, "12344", 0, "00012344" }, /* equivalent: 00012000003, hrt: 00012344, Check digit: 4 */ | |
| 689 /* 30*/ { BARCODE_UPCE, "123456", 0, "01234565" }, /* equivalent: 01234500006, hrt: 01234565, Check digit: 5 */ | |
| 690 /* 31*/ { BARCODE_UPCE_CHK, "123457", 0, "00123457" }, /* equivalent: 00123400005, hrt: 00123457, Check digit: 7 */ | |
| 691 /* 32*/ { BARCODE_UPCE, "1234567", 0, "12345670" }, /* equivalent: 12345600007, hrt: 12345670, Check digit: 0 */ | |
| 692 /* 33*/ { BARCODE_UPCE_CHK, "1234565", 0, "01234565" }, /* equivalent: 01234500006, hrt: 01234565, Check digit: 5 */ | |
| 693 /* 34*/ { BARCODE_UPCE_CHK, "12345670", 0, "12345670" }, /* equivalent: 12345600007, hrt: 12345670, Check digit: 0 */ | |
| 694 /* 35*/ { BARCODE_UPCE, "2345678", 0, "03456781" }, /* 2 ignored, equivalent: 03456700008, hrt: 03456781, Check digit: 1 */ | |
| 695 /* 36*/ { BARCODE_UPCE_CHK, "23456781", 0, "03456781" }, /* 2 ignored, equivalent: 03456700008, hrt: 03456781, Check digit: 1 */ | |
| 696 /* 37*/ { BARCODE_UPCE, "123455", 0, "01234558" }, /* equivalent: 01234500005, hrt: 01234558, Check digit: 8 (BS 797 Rule 3 (a)) */ | |
| 697 /* 38*/ { BARCODE_UPCE_CHK, "1234558", 0, "01234558" }, /* equivalent: 01234500005, hrt: 01234558, Check digit: 8 (BS 797 Rule 3 (a)) */ | |
| 698 /* 39*/ { BARCODE_UPCE, "456784", 0, "04567840" }, /* equivalent: 04567000008, hrt: 04567840, Check digit: 0 (BS 797 Rule 3 (b)) */ | |
| 699 /* 40*/ { BARCODE_UPCE_CHK, "4567840", 0, "04567840" }, /* equivalent: 04567000008, hrt: 04567840, Check digit: 0 (BS 797 Rule 3 (b)) */ | |
| 700 /* 41*/ { BARCODE_UPCE, "345670", 0, "03456703" }, /* equivalent: 03400000567, hrt: 03456703, Check digit: 3 (BS 797 Rule 3 (c)) */ | |
| 701 /* 42*/ { BARCODE_UPCE_CHK, "3456703", 0, "03456703" }, /* equivalent: 03400000567, hrt: 03456703, Check digit: 3 (BS 797 Rule 3 (c)) */ | |
| 702 /* 43*/ { BARCODE_UPCE, "984753", 0, "09847531" }, /* equivalent: 09840000075, hrt: 09847531, Check digit: 1 (BS 797 Rule 3 (d)) */ | |
| 703 /* 44*/ { BARCODE_UPCE_CHK, "9847531", 0, "09847531" }, /* equivalent: 09840000075, hrt: 09847531, Check digit: 1 (BS 797 Rule 3 (d)) */ | |
| 704 /* 45*/ { BARCODE_UPCE, "123453", 0, "01234531" }, | |
| 705 /* 46*/ { BARCODE_UPCE, "000000", 0, "00000000" }, | |
| 706 /* 47*/ { BARCODE_UPCE, "0000000", 0, "00000000" }, | |
| 707 /* 48*/ { BARCODE_UPCE, "1000000", 0, "10000007" }, | |
| 708 /* 49*/ { BARCODE_UPCE, "2000000", 0, "00000000" }, /* First char 2-9 ignored, replaced with 0 */ | |
| 709 /* 50*/ { BARCODE_UPCE, "3000000", 0, "00000000" }, | |
| 710 /* 51*/ { BARCODE_UPCE, "8000000", 0, "00000000" }, | |
| 711 /* 52*/ { BARCODE_UPCE, "9000000", 0, "00000000" }, | |
| 712 /* 53*/ { BARCODE_UPCE, "1234567+1", 0, "12345670+01" }, | |
| 713 /* 54*/ { BARCODE_UPCE, "12345670+1", 0, "12345670+01" }, | |
| 714 /* 55*/ { BARCODE_UPCE_CHK, "12345670+1", 0, "12345670+01" }, | |
| 715 /* 56*/ { BARCODE_UPCE_CHK, "1234565+1", 0, "01234565+01" }, | |
| 716 }; | |
| 717 const int data_size = ARRAY_SIZE(data); | |
| 718 int i, length, ret; | |
| 719 struct zint_symbol *symbol = NULL; | |
| 720 | |
| 721 testStartSymbol("test_hrt", &symbol); | |
| 722 | |
| 723 for (i = 0; i < data_size; i++) { | |
| 724 | |
| 725 if (testContinue(p_ctx, i)) continue; | |
| 726 | |
| 727 symbol = ZBarcode_Create(); | |
| 728 assert_nonnull(symbol, "Symbol not created\n"); | |
| 729 | |
| 730 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 731 | |
| 732 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 733 assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 734 | |
| 735 assert_zero(strcmp((const char *) symbol->text, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->text, data[i].expected); | |
| 736 | |
| 737 ZBarcode_Delete(symbol); | |
| 738 } | |
| 739 | |
| 740 testFinish(); | |
| 741 } | |
| 742 | |
| 743 static void test_vector_same(const testCtx *const p_ctx) { | |
| 744 int debug = p_ctx->debug; | |
| 745 | |
| 746 struct item { | |
| 747 int symbology; | |
| 748 char *data; | |
| 749 int ret_encode; | |
| 750 int ret_vector; | |
| 751 }; | |
| 752 static const struct item data[] = { | |
| 753 /* 0*/ { BARCODE_UPCE, "123456", 0, 0 }, | |
| 754 /* 1*/ { BARCODE_UPCE_CHK, "1234565", 0, 0 }, /* 5 is correct check digit */ | |
| 755 /* 2*/ { BARCODE_ISBNX, "0195049969", 0, 0 }, /* 9 is correct check digit */ | |
| 756 }; | |
| 757 const int data_size = ARRAY_SIZE(data); | |
| 758 int i, length, ret; | |
| 759 struct zint_symbol *symbol = NULL; | |
| 760 | |
| 761 testStartSymbol("test_vector_same", &symbol); | |
| 762 | |
| 763 for (i = 0; i < data_size; i++) { | |
| 764 struct zint_vector *vectors[4]; | |
| 765 int vectors_size = ARRAY_SIZE(vectors); | |
| 766 int j; | |
| 767 | |
| 768 if (testContinue(p_ctx, i)) continue; | |
| 769 | |
| 770 for (j = 0; j < vectors_size; j++) { | |
| 771 symbol = ZBarcode_Create(); | |
| 772 assert_nonnull(symbol, "Symbol not created\n"); | |
| 773 | |
| 774 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 775 | |
| 776 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 777 assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); | |
| 778 | |
| 779 ret = ZBarcode_Buffer_Vector(symbol, 0); | |
| 780 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); | |
| 781 | |
| 782 assert_nonnull(symbol->vector, "i:%d symbol->vector NULL\n", i); | |
| 783 vectors[j] = testUtilVectorCpy(symbol->vector); | |
| 784 | |
| 785 ZBarcode_Delete(symbol); | |
| 786 } | |
| 787 | |
| 788 for (j = 1; j < vectors_size; j++) { | |
| 789 ret = testUtilVectorCmp(vectors[j - 1], vectors[j]); | |
| 790 assert_zero(ret, "i:%d testUtilVectorCmp ret %d != 0\n", i, ret); | |
| 791 } | |
| 792 | |
| 793 for (j = 0; j < vectors_size; j++) { | |
| 794 struct zint_symbol symbol_vector; | |
| 795 symbol_vector.vector = vectors[j]; | |
| 796 vector_free(&symbol_vector); | |
| 797 } | |
| 798 } | |
| 799 | |
| 800 testFinish(); | |
| 801 } | |
| 802 | |
| 803 /* https://www.isbn-international.org/content/isbn-users-manual ISBN Users' Manual */ | |
| 804 /* https://bisg.org/page/BarcodingGuidelines BISG Barcode Guidelines for the US Book Industry (BISG BGUSBI) */ | |
| 805 static void test_encode(const testCtx *const p_ctx) { | |
| 806 int debug = p_ctx->debug; | |
| 807 | |
| 808 struct item { | |
| 809 int symbology; | |
| 810 int option_2; | |
| 811 char *data; | |
| 812 int ret; | |
| 813 | |
| 814 int expected_rows; | |
| 815 int expected_width; | |
| 816 char *comment; | |
| 817 char *expected; | |
| 818 }; | |
| 819 static const struct item data[] = { | |
| 820 /* 0*/ { BARCODE_UPCA, -1, "01234567890", 0, 1, 95, "GGS Figure 5.1-1 UPC-A (also Figure 5.2.2.3-1., 5.2.6.6-2., 6.4.9-1. and BS EN 797:1996 Figure 3)", | |
| 821 "10100011010011001001001101111010100011011000101010101000010001001001000111010011100101001110101" | |
| 822 }, | |
| 823 /* 1*/ { BARCODE_EANX, -1, "4512345678906", 0, 1, 95, "GGS Figure 5.1-1 EAN-13", | |
| 824 "10101100010110011001001101111010011101011100101010101000010001001001000111010011100101010000101" | |
| 825 }, | |
| 826 /* 2*/ { BARCODE_EANX_CHK, -1, "9501101531000", 0, 1, 95, "GGS Figure 5.2.2.1-2. EAN-13 (also Figure 6.5.2.2-1., 6.5.3.2-1., 6.5.3.2-2., 6.5.6.4-1.)", | |
| 827 "10101100010100111011001100110010100111001100101010100111010000101100110111001011100101110010101" | |
| 828 }, | |
| 829 /* 3*/ { BARCODE_EANX, -1, "9501234", 0, 1, 67, "GGS Figure 5.2.2.2-1. EAN-8", | |
| 830 "1010001011011000100011010011001010101101100100001010111001010000101" | |
| 831 }, | |
| 832 /* 4*/ { BARCODE_UPCE, -1, "0012345", 0, 1, 51, "GGS Figure 5.2.2.4-1. UPC-E (also BS EN 797:1996 Figure 4)", | |
| 833 "101010011100110010011011011110100111010110001010101" | |
| 834 }, | |
| 835 /* 5*/ { BARCODE_EANX, -1, "9771384524017+12", 0, 1, 122, "GGS Figure 5.2.2.5.1-2. EAN-13 barcode with two-digit add-on", | |
| 836 "10101110110010001011001101111010001001010001101010100111011011001011100111001011001101000100101000000010110011001010010011" | |
| 837 }, | |
| 838 /* 6*/ { BARCODE_EANX, -1, "9780877799306+54321", 0, 1, 149, "GGS Figure 5.2.2.5.2-2. EAN-13 barcode with five-digit add-on", | |
| 839 "10101110110001001010011101101110010001011101101010100010011101001110100100001011100101010000101000000010110111001010100011010100001010010011010011001" | |
| 840 }, | |
| 841 /* 7*/ { BARCODE_EANX, -1, "501234567890", 0, 1, 95, "GGS Figure 5.2.6.6-1. EAN-13 (also BS EN 797:1996 Figure 1)", | |
| 842 "10100011010110011001101101111010100011011100101010101000010001001001000111010011100101110010101" | |
| 843 }, | |
| 844 /* 8*/ { BARCODE_EANX, -1, "2012345", 0, 1, 67, "GGS Figure 5.2.6.6-3. EAN-8", | |
| 845 "1010010011000110100110010010011010101000010101110010011101100110101" | |
| 846 }, | |
| 847 /* 9*/ { BARCODE_UPCE_CHK, -1, "00783491", 0, 1, 51, "GGS Figure 5.2.6.6-4. UPC-E", | |
| 848 "101010011100100010110111010000101000110001011010101" | |
| 849 }, | |
| 850 /* 10*/ { BARCODE_UPCA, -1, "01234567890+24", 0, 1, 124, "GGS Figure 5.2.6.6-5. UPC-A barcode with two-digit add-on", | |
| 851 "1010001101001100100100110111101010001101100010101010100001000100100100011101001110010100111010100000000010110010011010100011" | |
| 852 }, | |
| 853 /* 11*/ { BARCODE_EANX, -1, "1234567891019+45678", 0, 1, 149, "GGS Figure 5.2.6.6-6. EAN-13 barcode with five-digit add-on", | |
| 854 "10100100110111101001110101100010000101001000101010100100011101001100110111001011001101110100101000000010110011101010110001010101111010010001010110111" | |
| 855 }, | |
| 856 /* 12*/ { BARCODE_EANX, -1, "5024425377399", 0, 1, 95, "GGS Figure 5.10.5.12-1. EAN-13", | |
| 857 "10100011010011011001110101000110010011011100101010100001010001001000100100001011101001110100101" | |
| 858 }, | |
| 859 /* 13*/ { BARCODE_UPCA_CHK, -1, "614141000302", 0, 1, 95, "GGS Figure 5.10.6.3-1. UPC-A", | |
| 860 "10101011110011001010001100110010100011001100101010111001011100101110010100001011100101101100101" | |
| 861 }, | |
| 862 /* 14*/ { BARCODE_UPCA, -1, "61414123440", 0, 1, 95, "GGS Figure 6.4.17-2. UPC-A Daisy 5pc Set", | |
| 863 "10101011110011001010001100110010100011001100101010110110010000101011100101110011100101110010101" | |
| 864 }, | |
| 865 /* 15*/ { BARCODE_EANX, -1, "5410038302178", 0, 1, 95, "GGS Figure 6.5.5.3-1. EAN-13", | |
| 866 "10101000110110011010011100011010111101000100101010100001011100101101100110011010001001001000101" | |
| 867 }, | |
| 868 /* 16*/ { BARCODE_EANX, -1, "501234567890+12", 0, 1, 122, "BS EN 797:1996 Figure 5 EAN-13 with 2-digit add-on", | |
| 869 "10100011010110011001101101111010100011011100101010101000010001001001000111010011100101110010101000000010110011001010010011" | |
| 870 }, | |
| 871 /* 17*/ { BARCODE_EANX, -1, "501234567890+86104", 0, 1, 149, "BS EN 797:1996 Figure 6 EAN-13 with 5-digit add-on", | |
| 872 "10100011010110011001101101111010100011011100101010101000010001001001000111010011100101110010101000000010110001001010101111010011001010001101010011101" | |
| 873 }, | |
| 874 /* 18*/ { BARCODE_UPCA_CHK, -1, "614141234417+12345", 0, 1, 151, "Example of UPC-A with 5-digit add-on", | |
| 875 "1010101111001100101000110011001010001100110010101011011001000010101110010111001100110100010010100000000010110110011010010011010100001010100011010110001" | |
| 876 }, | |
| 877 /* 19*/ { BARCODE_UPCE, -1, "1234567+12", 0, 1, 78, "Example of UPC-E with 2-digit add-on", | |
| 878 "101001001101111010100011011100100001010010001010101000000010110011001010010011" | |
| 879 }, | |
| 880 /* 20*/ { BARCODE_UPCE_CHK, -1, "12345670+12345", 0, 1, 105, "Example of UPC-E with 5-digit add-on", | |
| 881 "101001001101111010100011011100100001010010001010101000000010110110011010010011010100001010100011010110001" | |
| 882 }, | |
| 883 /* 21*/ { BARCODE_EANX, -1, "1234567+12", 0, 1, 94, "Example of EAN-8 with 2-digit add-on", | |
| 884 "1010011001001001101111010100011010101001110101000010001001110010101000000010110011001010010011" | |
| 885 }, | |
| 886 /* 22*/ { BARCODE_EANX_CHK, -1, "12345670+12345", 0, 1, 121, "Example of EAN-8 with 5-digit add-on", | |
| 887 "1010011001001001101111010100011010101001110101000010001001110010101000000010110110011010010011010100001010100011010110001" | |
| 888 }, | |
| 889 /* 23*/ { BARCODE_EANX, -1, "54321", 0, 1, 47, "Example of EAN-5", | |
| 890 "10110111001010100011010100001010010011010011001" | |
| 891 }, | |
| 892 /* 24*/ { BARCODE_EANX, -1, "21", 0, 1, 20, "Example of EAN-2", | |
| 893 "10110010011010110011" | |
| 894 }, | |
| 895 /* 25*/ { BARCODE_EANX_CHK, 9, "76543210+21", 0, 1, 96, "Example of EAN-8 barcode with two-digit add-on, addon_gap 9", | |
| 896 "101011101101011110110001010001101010100001011011001100110111001010100000000010110010011010110011" | |
| 897 }, | |
| 898 /* 26*/ { BARCODE_EANX, 12, "7654321+54321", 0, 1, 126, "Example of EAN-8 barcode with five-digit add-on, addon_gap 12", | |
| 899 "101011101101011110110001010001101010100001011011001100110111001010100000000000010110111001010100011010100001010010011010011001" | |
| 900 }, | |
| 901 /* 27*/ { BARCODE_UPCA_CHK, 10, "210987654329+21", 0, 1, 125, "Example of UPC-A with 2-digit add-on, addon_gap 10", | |
| 902 "10100100110011001000110100010110110111011101101010101000010011101011100100001011011001110100101000000000010110010011010110011" | |
| 903 }, | |
| 904 /* 28*/ { BARCODE_UPCA, 12, "21098765432+12121", 0, 1, 154, "Example of UPC-A with 5-digit add-on, addon_gap 12", | |
| 905 "1010010011001100100011010001011011011101110110101010100001001110101110010000101101100111010010100000000000010110011001010010011010110011010011011010011001" | |
| 906 }, | |
| 907 /* 29*/ { BARCODE_UPCE_CHK, 8, "06543217+21", 0, 1, 79, "Example of UPC-E with 2-digit add-on, addon_gap 8", | |
| 908 "1010000101011000100111010111101001101100110010101010000000010110010011010110011" | |
| 909 }, | |
| 910 /* 30*/ { BARCODE_UPCE, 11, "1654321+12121", 0, 1, 109, "Example of UPC-E with 5-digit add-on, addon_gap 11", | |
| 911 "1010101111011100101000110111101001101101100110101010000000000010110011001010010011010110011010011011010011001" | |
| 912 }, | |
| 913 /* 31*/ { BARCODE_ISBNX, -1, "9789295055124", 0, 1, 95, "ISBN Users' Manual 7th Ed. 13.2", | |
| 914 "10101110110001001001011100100110010111011000101010111001010011101001110110011011011001011100101" | |
| 915 }, | |
| 916 /* 32*/ { BARCODE_ISBNX, -1, "9780123456786+50995", 0, 1, 149, "BISG BGUSBI Figure 1: Bookland EAN (with Price Add-On) (and Figures 4, 5, 6)", | |
| 917 "10101110110001001010011100110010011011011110101010101110010011101010000100010010010001010000101000000010110110001010100111010001011010001011010111001" | |
| 918 }, | |
| 919 /* 33*/ { BARCODE_ISBNX, -1, "9781402894626+50495", 0, 1, 149, "BISG BGUSBI Figure 2", | |
| 920 "10101110110001001011001101000110100111001001101010100100011101001011100101000011011001010000101000000010110111001010001101010100011010001011010111001" | |
| 921 }, | |
| 922 /* 34*/ { BARCODE_ISBNX, 10, "9780940016644+50750", 0, 1, 152, "BISG BGUSBI Figure 3, addon_gap 10", | |
| 923 "10101110110001001010011100010110011101000110101010111001011001101010000101000010111001011100101000000000010110111001010001101010010001010110001010001101" | |
| 924 }, | |
| 925 /* 35*/ { BARCODE_ISBNX, -1, "9791234567896+12", 0, 1, 122, "Example of ISBN with 2-digit add-on", | |
| 926 "10101110110010111011001100100110100001010001101010100111010100001000100100100011101001010000101000000010110011001010010011" | |
| 927 }, | |
| 928 }; | |
| 929 const int data_size = ARRAY_SIZE(data); | |
| 930 int i, length, ret; | |
| 931 struct zint_symbol *symbol = NULL; | |
| 932 | |
| 933 char escaped[4096]; | |
| 934 char cmp_buf[4096]; | |
| 935 char cmp_msg[1024]; | |
| 936 | |
| 937 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */ | |
| 938 int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */ | |
| 939 | |
| 940 testStartSymbol("test_encode", &symbol); | |
| 941 | |
| 942 for (i = 0; i < data_size; i++) { | |
| 943 | |
| 944 if (testContinue(p_ctx, i)) continue; | |
| 945 | |
| 946 symbol = ZBarcode_Create(); | |
| 947 assert_nonnull(symbol, "Symbol not created\n"); | |
| 948 | |
| 949 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 950 | |
| 951 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 952 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 953 | |
| 954 if (p_ctx->generate) { | |
| 955 printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n", | |
| 956 i, testUtilBarcodeName(data[i].symbology), data[i].option_2, data[i].data, testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); | |
| 957 testUtilModulesPrint(symbol, " ", "\n"); | |
| 958 printf(" },\n"); | |
| 959 } else { | |
| 960 if (ret < ZINT_ERROR) { | |
| 961 int width, row; | |
| 962 | |
| 963 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); | |
| 964 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); | |
| 965 | |
| 966 ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); | |
| 967 assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data); | |
| 968 | |
| 969 if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) { | |
| 970 ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL); | |
| 971 assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 972 | |
| 973 ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected); | |
| 974 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", | |
| 975 i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected); | |
| 976 } | |
| 977 if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) { | |
| 978 int cmp_len, ret_len; | |
| 979 char modules_dump[8192 + 1]; | |
| 980 assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i); | |
| 981 ret = testUtilZXingCPP(i, symbol, data[i].data, length, modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len); | |
| 982 assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 983 | |
| 984 ret = testUtilZXingCPPCmp(symbol, cmp_msg, cmp_buf, cmp_len, data[i].data, length, NULL /*primary*/, escaped, &ret_len); | |
| 985 assert_zero(ret, "i:%d %s testUtilZXingCPPCmp %d != 0 %s\n actual: %.*s\nexpected: %.*s\n", | |
| 986 i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped); | |
| 987 } | |
| 988 } | |
| 989 } | |
| 990 | |
| 991 ZBarcode_Delete(symbol); | |
| 992 } | |
| 993 | |
| 994 testFinish(); | |
| 995 } | |
| 996 | |
| 997 /* #181 Christian Hartlage OSS-Fuzz */ | |
| 998 static void test_fuzz(const testCtx *const p_ctx) { | |
| 999 int debug = p_ctx->debug; | |
| 1000 | |
| 1001 struct item { | |
| 1002 int symbology; | |
| 1003 char *data; | |
| 1004 int length; | |
| 1005 int ret; | |
| 1006 }; | |
| 1007 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 1008 static const struct item data[] = { | |
| 1009 /* 0*/ { BARCODE_EANX, "55++15", -1, ZINT_ERROR_INVALID_DATA }, | |
| 1010 /* 1*/ { BARCODE_EANX, "+123456789012345678", -1, ZINT_ERROR_TOO_LONG }, | |
| 1011 /* 2*/ { BARCODE_EANX_CHK, "+123456789012345678", -1, ZINT_ERROR_TOO_LONG }, | |
| 1012 /* 3*/ { BARCODE_UPCA, "+123456789012345678", -1, ZINT_ERROR_TOO_LONG }, | |
| 1013 /* 4*/ { BARCODE_UPCA_CHK, "+123456789012345678", -1, ZINT_ERROR_TOO_LONG }, | |
| 1014 /* 5*/ { BARCODE_UPCE, "+123456789012345678", -1, ZINT_ERROR_TOO_LONG }, | |
| 1015 /* 6*/ { BARCODE_UPCE_CHK, "+123456789012345678", -1, ZINT_ERROR_TOO_LONG }, | |
| 1016 /* 7*/ { BARCODE_ISBNX, "+123456789012345678", -1, ZINT_ERROR_TOO_LONG }, | |
| 1017 /* 8*/ { BARCODE_EANX, "+12345", -1, 0 }, | |
| 1018 /* 9*/ { BARCODE_EANX, "+123456", -1, ZINT_ERROR_TOO_LONG }, | |
| 1019 /*10*/ { BARCODE_EANX, "000002000000200+203", -1, ZINT_ERROR_TOO_LONG }, /* #218 Jan Schrewe CI-Fuzz */ | |
| 1020 }; | |
| 1021 const int data_size = ARRAY_SIZE(data); | |
| 1022 int i, length, ret; | |
| 1023 struct zint_symbol *symbol = NULL; | |
| 1024 | |
| 1025 testStartSymbol("test_fuzz", &symbol); | |
| 1026 | |
| 1027 for (i = 0; i < data_size; i++) { | |
| 1028 | |
| 1029 if (testContinue(p_ctx, i)) continue; | |
| 1030 | |
| 1031 symbol = ZBarcode_Create(); | |
| 1032 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1033 | |
| 1034 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); | |
| 1035 | |
| 1036 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 1037 assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 1038 | |
| 1039 ZBarcode_Delete(symbol); | |
| 1040 } | |
| 1041 | |
| 1042 testFinish(); | |
| 1043 } | |
| 1044 | |
| 1045 #include <time.h> | |
| 1046 | |
| 1047 #define TEST_PERF_ITER_MILLES 10 | |
| 1048 #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000) | |
| 1049 #define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC) | |
| 1050 | |
| 1051 /* Not a real test, just performance indicator */ | |
| 1052 static void test_perf(const testCtx *const p_ctx) { | |
| 1053 int debug = p_ctx->debug; | |
| 1054 | |
| 1055 struct item { | |
| 1056 int symbology; | |
| 1057 int option_2; | |
| 1058 char *data; | |
| 1059 int ret; | |
| 1060 | |
| 1061 int expected_rows; | |
| 1062 int expected_width; | |
| 1063 char *comment; | |
| 1064 }; | |
| 1065 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 1066 static const struct item data[] = { | |
| 1067 /* 0*/ { BARCODE_EANX, -1, "123456789012+12345", 0, 1, 149, "EAN-13 add-on 5" }, | |
| 1068 /* 1*/ { BARCODE_EANX, -1, "123456789012", 0, 1, 95, "EAN-13 no add-on" }, | |
| 1069 /* 2*/ { BARCODE_UPCA, -1, "12345678901+12345", 0, 1, 151, "UPC-A add-on 5" }, | |
| 1070 /* 3*/ { BARCODE_UPCA, -1, "12345678901", 0, 1, 95, "UPC-A no add-on" }, | |
| 1071 /* 4*/ { BARCODE_EANX, -1, "1234567+12345", 0, 1, 121, "EAN-8 add-on 5" }, | |
| 1072 /* 5*/ { BARCODE_EANX, -1, "1234567", 0, 1, 67, "EAN-8 no add-on" }, | |
| 1073 /* 6*/ { BARCODE_UPCE, -1, "1234567+12", 0, 1, 78, "UPC-E add-on 2" }, | |
| 1074 /* 7*/ { BARCODE_UPCE, -1, "1234567", 0, 1, 51, "UPC-E no add-on" }, | |
| 1075 /* 8*/ { BARCODE_EANX, -1, "12345", 0, 1, 47, "EAN-5" }, | |
| 1076 /* 9*/ { BARCODE_EANX, -1, "12", 0, 1, 20, "EAN-2" }, | |
| 1077 }; | |
| 1078 const int data_size = ARRAY_SIZE(data); | |
| 1079 int i, length, ret; | |
| 1080 struct zint_symbol *symbol; | |
| 1081 | |
| 1082 clock_t start; | |
| 1083 clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0; | |
| 1084 clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print; | |
| 1085 int comment_max = 0; | |
| 1086 | |
| 1087 if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ | |
| 1088 return; | |
| 1089 } | |
| 1090 | |
| 1091 for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment); | |
| 1092 | |
| 1093 printf("Iterations %d\n", TEST_PERF_ITERATIONS); | |
| 1094 | |
| 1095 for (i = 0; i < data_size; i++) { | |
| 1096 int j; | |
| 1097 | |
| 1098 if (testContinue(p_ctx, i)) continue; | |
| 1099 | |
| 1100 diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0; | |
| 1101 | |
| 1102 for (j = 0; j < TEST_PERF_ITERATIONS; j++) { | |
| 1103 start = clock(); | |
| 1104 symbol = ZBarcode_Create(); | |
| 1105 diff_create += clock() - start; | |
| 1106 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1107 | |
| 1108 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); | |
| 1109 | |
| 1110 start = clock(); | |
| 1111 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 1112 diff_encode += clock() - start; | |
| 1113 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 1114 | |
| 1115 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); | |
| 1116 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); | |
| 1117 | |
| 1118 start = clock(); | |
| 1119 ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/); | |
| 1120 diff_buffer += clock() - start; | |
| 1121 assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt); | |
| 1122 | |
| 1123 symbol->output_options |= OUT_BUFFER_INTERMEDIATE; | |
| 1124 start = clock(); | |
| 1125 ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/); | |
| 1126 diff_buf_inter += clock() - start; | |
| 1127 assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt); | |
| 1128 symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */ | |
| 1129 | |
| 1130 start = clock(); | |
| 1131 ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/); | |
| 1132 diff_print += clock() - start; | |
| 1133 assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt); | |
| 1134 assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile); | |
| 1135 | |
| 1136 ZBarcode_Delete(symbol); | |
| 1137 } | |
| 1138 | |
| 1139 printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment, | |
| 1140 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)); | |
| 1141 | |
| 1142 total_create += diff_create; | |
| 1143 total_encode += diff_encode; | |
| 1144 total_buffer += diff_buffer; | |
| 1145 total_buf_inter += diff_buf_inter; | |
| 1146 total_print += diff_print; | |
| 1147 } | |
| 1148 if (p_ctx->index == -1) { | |
| 1149 printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals", | |
| 1150 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)); | |
| 1151 } | |
| 1152 } | |
| 1153 | |
| 1154 int main(int argc, char *argv[]) { | |
| 1155 | |
| 1156 testFunction funcs[] = { /* name, func */ | |
| 1157 { "test_upce_input", test_upce_input }, | |
| 1158 { "test_upca_print", test_upca_print }, | |
| 1159 { "test_upca_input", test_upca_input }, | |
| 1160 { "test_eanx_input", test_eanx_input }, | |
| 1161 { "test_isbn_input", test_isbn_input }, | |
| 1162 { "test_hrt", test_hrt }, | |
| 1163 { "test_vector_same", test_vector_same }, | |
| 1164 { "test_encode", test_encode }, | |
| 1165 { "test_fuzz", test_fuzz }, | |
| 1166 { "test_perf", test_perf }, | |
| 1167 }; | |
| 1168 | |
| 1169 testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); | |
| 1170 | |
| 1171 testReport(); | |
| 1172 | |
| 1173 return 0; | |
| 1174 } | |
| 1175 | |
| 1176 /* vim: set ts=4 sw=4 et : */ |
