Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tests/test_code.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) 2020-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_large(const testCtx *const p_ctx) { | |
| 35 int debug = p_ctx->debug; | |
| 36 | |
| 37 struct item { | |
| 38 int symbology; | |
| 39 int option_2; | |
| 40 char *pattern; | |
| 41 int length; | |
| 42 int ret; | |
| 43 int expected_rows; | |
| 44 int expected_width; | |
| 45 char *expected_errtxt; | |
| 46 }; | |
| 47 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 48 static const struct item data[] = { | |
| 49 /* 0*/ { BARCODE_CODE11, -1, "13", 140, 0, 1, 1151, "" }, /* 8 (Start) + 140*8 + 2*8 (Checks) + 7 (Stop) == 1151 */ | |
| 50 /* 1*/ { BARCODE_CODE11, -1, "13", 141, ZINT_ERROR_TOO_LONG, -1, -1, "Error 320: Input length 141 too long (maximum 140)" }, | |
| 51 /* 2*/ { BARCODE_CODE39, -1, "1", 86, 0, 1, 1143, "" }, /* 13 (Start) + 86*13 + 12 (Stop) == 1143 */ | |
| 52 /* 3*/ { BARCODE_CODE39, -1, "1", 87, ZINT_ERROR_TOO_LONG, -1, -1, "Error 323: Input length 87 too long (maximum 86)" }, | |
| 53 /* 4*/ { BARCODE_EXCODE39, -1, "1", 86, 0, 1, 1143, "" }, | |
| 54 /* 5*/ { BARCODE_EXCODE39, -1, "1", 87, ZINT_ERROR_TOO_LONG, -1, -1, "Error 328: Input length 87 too long (maximum 86)" }, | |
| 55 /* 6*/ { BARCODE_EXCODE39, -1, "a", 43, 0, 1, 1143, "" }, /* Takes 2 encoding chars per char */ | |
| 56 /* 7*/ { BARCODE_EXCODE39, -1, "a", 44, ZINT_ERROR_TOO_LONG, -1, -1, "Error 317: Input too long, requires 88 symbol characters (maximum 86)" }, | |
| 57 /* 8*/ { BARCODE_EXCODE39, -1, "a", 86, ZINT_ERROR_TOO_LONG, -1, -1, "Error 317: Input too long, requires 172 symbol characters (maximum 86)" }, | |
| 58 /* 9*/ { BARCODE_LOGMARS, -1, "1", 30, 0, 1, 511, "" }, /* 16 (Start) + 30*16 + 15 (Stop) == 511 */ | |
| 59 /* 10*/ { BARCODE_LOGMARS, -1, "1", 31, ZINT_ERROR_TOO_LONG, -1, -1, "Error 322: Input length 31 too long (maximum 30)" }, | |
| 60 /* 11*/ { BARCODE_CODE93, -1, "1", 123, 0, 1, 1144, "" }, /* 9 (Start) + 123*9 + 2*9 (Checks) + 10 (Stop) == 1144 */ | |
| 61 /* 12*/ { BARCODE_CODE93, -1, "1", 124, ZINT_ERROR_TOO_LONG, -1, -1, "Error 330: Input length 124 too long (maximum 123)" }, | |
| 62 /* 13*/ { BARCODE_CODE93, -1, "a", 61, 0, 1, 1135, "" }, /* Takes 2 encoding chars per char */ | |
| 63 /* 14*/ { BARCODE_CODE93, -1, "a", 62, ZINT_ERROR_TOO_LONG, -1, -1, "Error 332: Input too long, requires 124 symbol characters (maximum 123)" }, | |
| 64 /* 15*/ { BARCODE_CODE93, -1, "a", 124, ZINT_ERROR_TOO_LONG, -1, -1, "Error 330: Input length 124 too long (maximum 123)" }, | |
| 65 /* 16*/ { BARCODE_CODE93, -1, "a1", 82, 0, 1, 1144, "" }, /* Takes 1.5 encoding chars (1.5*82 == 123) */ | |
| 66 /* 17*/ { BARCODE_CODE93, -1, "a1", 83, ZINT_ERROR_TOO_LONG, -1, -1, "Error 332: Input too long, requires 125 symbol characters (maximum 123)" }, | |
| 67 /* 18*/ { BARCODE_PZN, -1, "1", 7, 0, 1, 142, "" }, /* Takes 8 with correct check digit */ | |
| 68 /* 19*/ { BARCODE_PZN, -1, "1", 9, ZINT_ERROR_TOO_LONG, -1, -1, "Error 325: Input length 9 too long (maximum 8)" }, | |
| 69 /* 20*/ { BARCODE_PZN, 1, "1", 6, 0, 1, 129, "" }, /* PZN7 takes 7 with correct check digit */ | |
| 70 /* 21*/ { BARCODE_PZN, 1, "1", 8, ZINT_ERROR_TOO_LONG, -1, -1, "Error 325: Input length 8 too long (maximum 7)" }, | |
| 71 /* 22*/ { BARCODE_VIN, -1, "1", 17, 0, 1, 246, "" }, | |
| 72 /* 23*/ { BARCODE_VIN, -1, "1", 18, ZINT_ERROR_TOO_LONG, -1, -1, "Error 336: Input length 18 wrong (17 only)" }, | |
| 73 /* 24*/ { BARCODE_VIN, -1, "1", 16, ZINT_ERROR_TOO_LONG, -1, -1, "Error 336: Input length 16 wrong (17 only)" }, | |
| 74 /* 25*/ { BARCODE_VIN, 1, "1", 17, 0, 1, 259, "" }, | |
| 75 /* 26*/ { BARCODE_HIBC_39, -1, "1", 68, 0, 1, 1151, "" }, /* 70 - 2 ('+' and check digit) */ | |
| 76 /* 27*/ { BARCODE_HIBC_39, -1, "1", 69, ZINT_ERROR_TOO_LONG, -1, -1, "Error 319: Input length 69 too long (maximum 68)" }, | |
| 77 }; | |
| 78 const int data_size = ARRAY_SIZE(data); | |
| 79 int i, length, ret; | |
| 80 struct zint_symbol *symbol = NULL; | |
| 81 | |
| 82 char data_buf[4096]; | |
| 83 | |
| 84 testStartSymbol("test_large", &symbol); | |
| 85 | |
| 86 for (i = 0; i < data_size; i++) { | |
| 87 | |
| 88 if (testContinue(p_ctx, i)) continue; | |
| 89 | |
| 90 symbol = ZBarcode_Create(); | |
| 91 assert_nonnull(symbol, "Symbol not created\n"); | |
| 92 | |
| 93 testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); | |
| 94 assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); | |
| 95 | |
| 96 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); | |
| 97 | |
| 98 ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); | |
| 99 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 100 assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt); | |
| 101 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt); | |
| 102 | |
| 103 if (ret < ZINT_ERROR) { | |
| 104 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); | |
| 105 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); | |
| 106 } | |
| 107 | |
| 108 ZBarcode_Delete(symbol); | |
| 109 } | |
| 110 | |
| 111 testFinish(); | |
| 112 } | |
| 113 | |
| 114 static void test_hrt(const testCtx *const p_ctx) { | |
| 115 int debug = p_ctx->debug; | |
| 116 | |
| 117 struct item { | |
| 118 int symbology; | |
| 119 int option_2; | |
| 120 char *data; | |
| 121 int length; | |
| 122 | |
| 123 char *expected; | |
| 124 }; | |
| 125 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 126 static const struct item data[] = { | |
| 127 /* 0*/ { BARCODE_CODE11, -1, "123-45", -1, "123-4552" }, /* 2 checksums */ | |
| 128 /* 1*/ { BARCODE_CODE11, 1, "123-45", -1, "123-455" }, /* 1 check digit */ | |
| 129 /* 2*/ { BARCODE_CODE11, 2, "123-45", -1, "123-45" }, /* No checksums */ | |
| 130 /* 3*/ { BARCODE_CODE11, -1, "123456789012", -1, "123456789012-8" }, /* First check digit 10 (A) goes to hyphen */ | |
| 131 /* 4*/ { BARCODE_CODE39, -1, "ABC1234", -1, "*ABC1234*" }, | |
| 132 /* 5*/ { BARCODE_CODE39, 1, "ABC1234", -1, "*ABC12340*" }, /* With visible check digit */ | |
| 133 /* 6*/ { BARCODE_CODE39, -1, "abc1234", -1, "*ABC1234*" }, /* Converts to upper */ | |
| 134 /* 7*/ { BARCODE_CODE39, 1, "abc1234", -1, "*ABC12340*" }, /* Converts to upper */ | |
| 135 /* 8*/ { BARCODE_CODE39, -1, "123456789", -1, "*123456789*" }, | |
| 136 /* 9*/ { BARCODE_CODE39, 1, "123456789", -1, "*1234567892*" }, /* With visible check digit */ | |
| 137 /* 10*/ { BARCODE_CODE39, 2, "123456789", -1, "*123456789*" }, /* With hidden check digit */ | |
| 138 /* 11*/ { BARCODE_EXCODE39, -1, "ABC1234", -1, "ABC1234" }, | |
| 139 /* 12*/ { BARCODE_EXCODE39, 1, "ABC1234", -1, "ABC12340" }, /* With visible check digit */ | |
| 140 /* 13*/ { BARCODE_EXCODE39, -1, "abc1234", -1, "abc1234" }, | |
| 141 /* 14*/ { BARCODE_EXCODE39, 1, "abc1234", -1, "abc1234." }, /* With visible check digit (previously was hidden) */ | |
| 142 /* 15*/ { BARCODE_EXCODE39, 2, "abc1234", -1, "abc1234" }, /* With hidden check digit */ | |
| 143 /* 16*/ { BARCODE_EXCODE39, -1, "a%\000\001$\177z\033\037!+/\\@A~", 16, "a% $ z !+/\\@A~" }, /* NUL, ctrls and DEL replaced with spaces */ | |
| 144 /* 17*/ { BARCODE_EXCODE39, 1, "a%\000\001$\177z\033\037!+/\\@A~", 16, "a% $ z !+/\\@A~L" }, /* With visible check digit */ | |
| 145 /* 18*/ { BARCODE_EXCODE39, 2, "a%\000\001$\177z\033\037!+/\\@A~", 16, "a% $ z !+/\\@A~" }, /* With hidden check digit */ | |
| 146 /* 19*/ { BARCODE_LOGMARS, -1, "ABC1234", -1, "ABC1234" }, | |
| 147 /* 20*/ { BARCODE_LOGMARS, -1, "abc1234", -1, "ABC1234" }, /* Converts to upper */ | |
| 148 /* 21*/ { BARCODE_LOGMARS, 1, "abc1234", -1, "ABC12340" }, /* With check digit */ | |
| 149 /* 22*/ { BARCODE_LOGMARS, 1, "12345/ABCDE", -1, "12345/ABCDET" }, /* With visible check digit */ | |
| 150 /* 23*/ { BARCODE_LOGMARS, 2, "12345/ABCDE", -1, "12345/ABCDE" }, /* With hidden check digit */ | |
| 151 /* 24*/ { BARCODE_CODE93, -1, "ABC1234", -1, "ABC1234" }, /* No longer shows 2 check chars added (same as BWIPP and TEC-IT) */ | |
| 152 /* 25*/ { BARCODE_CODE93, 1, "ABC1234", -1, "ABC1234S5" }, /* Unless requested */ | |
| 153 /* 26*/ { BARCODE_CODE93, -1, "abc1234", -1, "abc1234" }, | |
| 154 /* 27*/ { BARCODE_CODE93, 1, "abc1234", -1, "abc1234ZG" }, | |
| 155 /* 28*/ { BARCODE_CODE93, -1, "A\001a\000b\177d\037e", 9, "A a b d e" }, /* NUL, ctrls and DEL replaced with spaces */ | |
| 156 /* 29*/ { BARCODE_PZN, -1, "12345", -1, "PZN - 00123458" }, /* Pads with zeroes if length < 7 */ | |
| 157 /* 30*/ { BARCODE_PZN, -1, "123456", -1, "PZN - 01234562" }, | |
| 158 /* 31*/ { BARCODE_PZN, -1, "1234567", -1, "PZN - 12345678" }, | |
| 159 /* 32*/ { BARCODE_PZN, -1, "12345678", -1, "PZN - 12345678" }, | |
| 160 /* 33*/ { BARCODE_PZN, 1, "1234", -1, "PZN - 0012345" }, /* PZN7, pads with zeroes if length < 6 */ | |
| 161 /* 34*/ { BARCODE_PZN, 1, "12345", -1, "PZN - 0123458" }, | |
| 162 /* 35*/ { BARCODE_PZN, 1, "123456", -1, "PZN - 1234562" }, | |
| 163 /* 36*/ { BARCODE_PZN, 1, "1234562", -1, "PZN - 1234562" }, | |
| 164 /* 37*/ { BARCODE_VIN, -1, "1FTCR10UXTPA78180", -1, "1FTCR10UXTPA78180" }, | |
| 165 /* 38*/ { BARCODE_VIN, 1, "2FTPX28L0XCA15511", -1, "2FTPX28L0XCA15511" }, /* Include Import char - no change */ | |
| 166 /* 39*/ { BARCODE_HIBC_39, -1, "ABC1234", -1, "*+ABC1234+*" }, | |
| 167 /* 40*/ { BARCODE_HIBC_39, -1, "abc1234", -1, "*+ABC1234+*" }, /* Converts to upper */ | |
| 168 /* 41*/ { BARCODE_HIBC_39, -1, "123456789", -1, "*+1234567890*" }, | |
| 169 }; | |
| 170 const int data_size = ARRAY_SIZE(data); | |
| 171 int i, length, ret; | |
| 172 struct zint_symbol *symbol = NULL; | |
| 173 | |
| 174 testStartSymbol("test_hrt", &symbol); | |
| 175 | |
| 176 for (i = 0; i < data_size; i++) { | |
| 177 | |
| 178 if (testContinue(p_ctx, i)) continue; | |
| 179 | |
| 180 symbol = ZBarcode_Create(); | |
| 181 assert_nonnull(symbol, "Symbol not created\n"); | |
| 182 | |
| 183 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, data[i].length, debug); | |
| 184 | |
| 185 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 186 assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); | |
| 187 | |
| 188 assert_zero(strcmp((char *) symbol->text, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->text, data[i].expected); | |
| 189 | |
| 190 ZBarcode_Delete(symbol); | |
| 191 } | |
| 192 | |
| 193 testFinish(); | |
| 194 } | |
| 195 | |
| 196 static void test_input(const testCtx *const p_ctx) { | |
| 197 int debug = p_ctx->debug; | |
| 198 | |
| 199 struct item { | |
| 200 int symbology; | |
| 201 int input_mode; | |
| 202 int option_2; | |
| 203 char *data; | |
| 204 int length; | |
| 205 int ret; | |
| 206 int expected_rows; | |
| 207 int expected_width; | |
| 208 char *expected_errtxt; | |
| 209 }; | |
| 210 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 211 static const struct item data[] = { | |
| 212 /* 0*/ { BARCODE_CODE11, -1, -1, "-", -1, 0, 1, 37, "" }, | |
| 213 /* 1*/ { BARCODE_CODE11, -1, -1, "0123456789-", -1, 0, 1, 115, "" }, | |
| 214 /* 2*/ { BARCODE_CODE11, -1, -1, "A", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 321: Invalid character at position 1 in input (digits and \"-\" only)" }, | |
| 215 /* 3*/ { BARCODE_CODE11, -1, -1, "12+", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 321: Invalid character at position 3 in input (digits and \"-\" only)" }, | |
| 216 /* 4*/ { BARCODE_CODE11, -1, -1, "1.2", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 321: Invalid character at position 2 in input (digits and \"-\" only)" }, | |
| 217 /* 5*/ { BARCODE_CODE11, -1, -1, "12!", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 321: Invalid character at position 3 in input (digits and \"-\" only)" }, | |
| 218 /* 6*/ { BARCODE_CODE11, -1, -1, " ", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 321: Invalid character at position 1 in input (digits and \"-\" only)" }, | |
| 219 /* 7*/ { BARCODE_CODE11, ESCAPE_MODE, -1, "\\d048 ", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 321: Invalid character at position 2 in input (digits and \"-\" only)" }, /* Note position doesn't account for escape sequences */ | |
| 220 /* 8*/ { BARCODE_CODE11, -1, 3, "1", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 339: Invalid check digit version '3' (1 or 2 only)" }, | |
| 221 /* 9*/ { BARCODE_CODE39, -1, -1, "a", -1, 0, 1, 38, "" }, /* Converts to upper */ | |
| 222 /* 10*/ { BARCODE_CODE39, -1, -1, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%", -1, 0, 1, 584, "" }, | |
| 223 /* 11*/ { BARCODE_CODE39, -1, -1, "AB!", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 3 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 224 /* 12*/ { BARCODE_CODE39, -1, -1, "A\"B", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 2 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 225 /* 13*/ { BARCODE_CODE39, -1, -1, "#AB", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 226 /* 14*/ { BARCODE_CODE39, -1, -1, "&", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 227 /* 15*/ { BARCODE_CODE39, -1, -1, "'", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 228 /* 16*/ { BARCODE_CODE39, -1, -1, "(", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 229 /* 17*/ { BARCODE_CODE39, -1, -1, ")", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 230 /* 18*/ { BARCODE_CODE39, -1, -1, "*", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 231 /* 19*/ { BARCODE_CODE39, -1, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 232 /* 20*/ { BARCODE_CODE39, -1, -1, ":", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 233 /* 21*/ { BARCODE_CODE39, -1, -1, "@", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 234 /* 22*/ { BARCODE_CODE39, -1, -1, "[", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 235 /* 23*/ { BARCODE_CODE39, -1, -1, "`", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 236 /* 24*/ { BARCODE_CODE39, -1, -1, "{", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 237 /* 25*/ { BARCODE_CODE39, -1, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 238 /* 26*/ { BARCODE_CODE39, -1, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 239 /* 27*/ { BARCODE_CODE39, -1, 0, "1", -1, 0, 1, 38, "" }, | |
| 240 /* 28*/ { BARCODE_CODE39, -1, 1, "1", -1, 0, 1, 51, "" }, /* Check digit */ | |
| 241 /* 29*/ { BARCODE_CODE39, -1, 2, "1", -1, 0, 1, 51, "" }, /* Hidden check digit */ | |
| 242 /* 30*/ { BARCODE_CODE39, -1, 3, "1", -1, 0, 1, 38, "" }, /* option_2 > 2 ignored */ | |
| 243 /* 31*/ { BARCODE_EXCODE39, -1, -1, "A", -1, 0, 1, 38, "" }, | |
| 244 /* 32*/ { BARCODE_EXCODE39, -1, 3, "A", -1, 0, 1, 38, "" }, /* option_2 > 2 ignored */ | |
| 245 /* 33*/ { BARCODE_EXCODE39, -1, -1, "a", -1, 0, 1, 51, "" }, | |
| 246 /* 34*/ { BARCODE_EXCODE39, -1, -1, ",", -1, 0, 1, 51, "" }, | |
| 247 /* 35*/ { BARCODE_EXCODE39, -1, -1, "\000", 1, 0, 1, 51, "" }, | |
| 248 /* 36*/ { BARCODE_EXCODE39, -1, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 329: Invalid character at position 1 in input, extended ASCII not allowed" }, | |
| 249 /* 37*/ { BARCODE_EXCODE39, -1, -1, "ABCDé", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 329: Invalid character at position 5 in input, extended ASCII not allowed" }, | |
| 250 /* 38*/ { BARCODE_LOGMARS, -1, -1, "A", -1, 0, 1, 47, "" }, | |
| 251 /* 39*/ { BARCODE_LOGMARS, -1, -1, "a", -1, 0, 1, 47, "" }, | |
| 252 /* 40*/ { BARCODE_LOGMARS, -1, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 253 /* 41*/ { BARCODE_LOGMARS, -1, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 254 /* 42*/ { BARCODE_LOGMARS, -1, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 324: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 255 /* 43*/ { BARCODE_LOGMARS, -1, 3, "A", -1, 0, 1, 47, "" }, /* option_2 > 2 ignored */ | |
| 256 /* 44*/ { BARCODE_CODE93, -1, -1, "A", -1, 0, 1, 46, "" }, | |
| 257 /* 45*/ { BARCODE_CODE93, -1, -1, "a", -1, 0, 1, 55, "" }, | |
| 258 /* 46*/ { BARCODE_CODE93, -1, -1, ",", -1, 0, 1, 55, "" }, | |
| 259 /* 47*/ { BARCODE_CODE93, -1, -1, "\000", 1, 0, 1, 55, "" }, | |
| 260 /* 48*/ { BARCODE_CODE93, -1, -1, "12\3004", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 331: Invalid character at position 3 in input, extended ASCII not allowed" }, | |
| 261 /* 49*/ { BARCODE_CODE93, -1, -1, "é", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 331: Invalid character at position 1 in input, extended ASCII not allowed" }, | |
| 262 /* 50*/ { BARCODE_PZN, -1, -1, "1", -1, 0, 1, 142, "" }, | |
| 263 /* 51*/ { BARCODE_PZN, -1, -1, "A", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 326: Invalid character at position 1 in input (digits only)" }, | |
| 264 /* 52*/ { BARCODE_PZN, -1, -1, "1000006", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 327: Invalid PZN, check digit is '10'" }, /* Check digit == 10 so can't be used */ | |
| 265 /* 53*/ { BARCODE_PZN, -1, -1, "00000011", -1, ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 890: Invalid check digit '1', expecting '7'" }, | |
| 266 /* 54*/ { BARCODE_PZN, -1, 1, "100009", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 327: Invalid PZN, check digit is '10'" }, /* Check digit == 10 so can't be used */ | |
| 267 /* 55*/ { BARCODE_PZN, -1, 1, "0000011", -1, ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 890: Invalid check digit '1', expecting '7'" }, | |
| 268 /* 56*/ { BARCODE_VIN, -1, -1, "5GZCZ43D13S812715", -1, 0, 1, 246, "" }, | |
| 269 /* 57*/ { BARCODE_VIN, -1, -1, "5GZCZ43D23S812715", -1, ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 338: Invalid check digit '2' (position 9), expecting '1'" }, /* North American with invalid check character */ | |
| 270 /* 58*/ { BARCODE_VIN, -1, -1, "WP0ZZZ99ZTS392124", -1, 0, 1, 246, "" }, /* Not North American so no check */ | |
| 271 /* 59*/ { BARCODE_VIN, -1, -1, "WP0ZZZ99ZTS392I24", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 337: Invalid character at position 15 in input (alphanumerics only, excluding \"IOQ\")" }, /* I not allowed */ | |
| 272 /* 60*/ { BARCODE_VIN, -1, -1, "WPOZZZ99ZTS392124", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 337: Invalid character at position 3 in input (alphanumerics only, excluding \"IOQ\")" }, /* O not allowed */ | |
| 273 /* 61*/ { BARCODE_VIN, -1, -1, "WPQZZZ99ZTS392124", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 337: Invalid character at position 3 in input (alphanumerics only, excluding \"IOQ\")" }, /* Q not allowed */ | |
| 274 /* 62*/ { BARCODE_HIBC_39, -1, -1, "a", -1, 0, 1, 79, "" }, /* Converts to upper */ | |
| 275 /* 63*/ { BARCODE_HIBC_39, -1, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 203: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 276 /* 64*/ { BARCODE_HIBC_39, -1, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 203: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 277 /* 65*/ { BARCODE_HIBC_39, -1, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 203: Invalid character at position 1 in input (alphanumerics, space and \"-.$/+%\" only)" }, | |
| 278 /* 66*/ { BARCODE_HIBC_39, -1, 1, "a", -1, 0, 1, 79, "" }, /* option_2 ignored */ | |
| 279 /* 67*/ { BARCODE_HIBC_39, -1, 2, "a", -1, 0, 1, 79, "" }, /* option_2 ignored */ | |
| 280 }; | |
| 281 const int data_size = ARRAY_SIZE(data); | |
| 282 int i, length, ret; | |
| 283 struct zint_symbol *symbol = NULL; | |
| 284 | |
| 285 testStartSymbol("test_input", &symbol); | |
| 286 | |
| 287 for (i = 0; i < data_size; i++) { | |
| 288 | |
| 289 if (testContinue(p_ctx, i)) continue; | |
| 290 | |
| 291 symbol = ZBarcode_Create(); | |
| 292 assert_nonnull(symbol, "Symbol not created\n"); | |
| 293 | |
| 294 length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); | |
| 295 | |
| 296 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 297 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 298 assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt); | |
| 299 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt); | |
| 300 | |
| 301 if (ret < ZINT_ERROR) { | |
| 302 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); | |
| 303 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); | |
| 304 } | |
| 305 | |
| 306 ZBarcode_Delete(symbol); | |
| 307 } | |
| 308 | |
| 309 testFinish(); | |
| 310 } | |
| 311 | |
| 312 static void test_encode(const testCtx *const p_ctx) { | |
| 313 int debug = p_ctx->debug; | |
| 314 | |
| 315 struct item { | |
| 316 int symbology; | |
| 317 int option_2; | |
| 318 char *data; | |
| 319 int length; | |
| 320 int ret; | |
| 321 | |
| 322 int expected_rows; | |
| 323 int expected_width; | |
| 324 char *comment; | |
| 325 char *expected; | |
| 326 }; | |
| 327 static const struct item data[] = { | |
| 328 /* 0*/ { BARCODE_CODE11, -1, "123-45", -1, 0, 1, 78, "2 check digits (52); verified manually against TEC-IT", | |
| 329 "101100101101011010010110110010101011010101101101101101011011010100101101011001" | |
| 330 }, | |
| 331 /* 1*/ { BARCODE_CODE11, -1, "93", -1, 0, 1, 44, "2 check digits (--); verified manually against TEC-IT", | |
| 332 "10110010110101011001010101101010110101011001" | |
| 333 }, | |
| 334 /* 2*/ { BARCODE_CODE11, 1, "123-455", -1, 0, 1, 78, "1 check digit (2); verified manually against TEC-IT", | |
| 335 "101100101101011010010110110010101011010101101101101101011011010100101101011001" | |
| 336 }, | |
| 337 /* 3*/ { BARCODE_CODE11, 2, "123-4552", -1, 0, 1, 78, "0 check digits; verified manually against TEC-IT", | |
| 338 "101100101101011010010110110010101011010101101101101101011011010100101101011001" | |
| 339 }, | |
| 340 /* 4*/ { BARCODE_CODE11, 1, "123-45", -1, 0, 1, 70, "1 check digit; verified manually against TEC-IT", | |
| 341 "1011001011010110100101101100101010110101011011011011010110110101011001" | |
| 342 }, | |
| 343 /* 5*/ { BARCODE_CODE11, 2, "123-45", -1, 0, 1, 62, "0 check digits; verified manually against TEC-IT", | |
| 344 "10110010110101101001011011001010101101010110110110110101011001" | |
| 345 }, | |
| 346 /* 6*/ { BARCODE_CODE39, -1, "1A", -1, 0, 1, 51, "ISO/IEC 16388:2007 Figure 1", | |
| 347 "100101101101011010010101101101010010110100101101101" | |
| 348 }, | |
| 349 /* 7*/ { BARCODE_CODE39, 1, "1A", -1, 0, 1, 64, "With check digit (B)", | |
| 350 "1001011011010110100101011011010100101101011010010110100101101101" | |
| 351 }, | |
| 352 /* 8*/ { BARCODE_CODE39, 1, "Z1", -1, 0, 1, 64, "Check digit '-'", | |
| 353 "1001011011010100110110101011010010101101001010110110100101101101" | |
| 354 }, | |
| 355 /* 9*/ { BARCODE_CODE39, 1, "Z2", -1, 0, 1, 64, "Check digit '.'", | |
| 356 "1001011011010100110110101010110010101101100101011010100101101101" | |
| 357 }, | |
| 358 /* 10*/ { BARCODE_CODE39, 1, "Z3", -1, 0, 1, 64, "Check digit space, displayed as underscore", | |
| 359 "1001011011010100110110101011011001010101001101011010100101101101" | |
| 360 }, | |
| 361 /* 11*/ { BARCODE_CODE39, 1, "Z4", -1, 0, 1, 64, "Check digit '$'", | |
| 362 "1001011011010100110110101010100110101101001001001010100101101101" | |
| 363 }, | |
| 364 /* 12*/ { BARCODE_CODE39, 1, "Z5", -1, 0, 1, 64, "Check digit '/'", | |
| 365 "1001011011010100110110101011010011010101001001010010100101101101" | |
| 366 }, | |
| 367 /* 13*/ { BARCODE_CODE39, 1, "Z6", -1, 0, 1, 64, "Check digit '+'", | |
| 368 "1001011011010100110110101010110011010101001010010010100101101101" | |
| 369 }, | |
| 370 /* 14*/ { BARCODE_CODE39, 1, "Z7", -1, 0, 1, 64, "Check digit '%'", | |
| 371 "1001011011010100110110101010100101101101010010010010100101101101" | |
| 372 }, | |
| 373 /* 15*/ { BARCODE_CODE39, -1, "+A/E%U$A/D%T+Z", -1, 0, 1, 207, "Same as BARCODE_EXCODE39 'a%\000\001$\177z' below", | |
| 374 "100101101101010010100100101101010010110100100101001011010110010101010010010010110010101011010010010010101101010010110100100101001010101100101101010010010010101011011001010010100100101001101101010100101101101" | |
| 375 }, | |
| 376 /* 16*/ { BARCODE_CODE39, -1, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%", -1, 0, 1, 584, "Full CODE39 set", | |
| 377 "10010110110101010011011010110100101011010110010101101101100101010101001101011011010011010101011001101010101001011011011010010110101011001011010110101001011010110100101101101101001010101011001011011010110010101011011001010101010011011011010100110101011010011010101011001101011010101001101011010100110110110101001010101101001101101011010010101101101001010101011001101101010110010101101011001010101101100101100101010110100110101011011001101010101001011010110110010110101010011011010101001010110110110010101101010011010110101001001001010100100101001010010100100101010010010010100101101101" | |
| 378 }, | |
| 379 /* 17*/ { BARCODE_EXCODE39, -1, "1A", -1, 0, 1, 51, "ISO/IEC 16388:2007 Figure 1", | |
| 380 "100101101101011010010101101101010010110100101101101" | |
| 381 }, | |
| 382 /* 18*/ { BARCODE_EXCODE39, 1, "1A", -1, 0, 1, 64, "With check digit", | |
| 383 "1001011011010110100101011011010100101101011010010110100101101101" | |
| 384 }, | |
| 385 /* 19*/ { BARCODE_EXCODE39, 1, "Z4", -1, 0, 1, 64, "Check digit $", | |
| 386 "1001011011010100110110101010100110101101001001001010100101101101" | |
| 387 }, | |
| 388 /* 20*/ { BARCODE_EXCODE39, -1, "a%\000\001$\177z", 7, 0, 1, 207, "Verified manually against TEC-IT", | |
| 389 "100101101101010010100100101101010010110100100101001011010110010101010010010010110010101011010010010010101101010010110100100101001010101100101101010010010010101011011001010010100100101001101101010100101101101" | |
| 390 }, | |
| 391 /* 21*/ { BARCODE_EXCODE39, -1, "\033\037!+/\\@A~", -1, 0, 1, 246, "Verified manually against TEC-IT", | |
| 392 "100101101101010100100100101101010010110101001001001011010110010101001001010010110101001011010010010100101101010100110100100101001011010110100101010010010010101101010011010100100100101001101010110110101001011010100100100101011010110010100101101101" | |
| 393 }, | |
| 394 /* 22*/ { BARCODE_EXCODE39, -1, " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]", -1, 0, 1, 1130, "Visible ASCII 1st 85 symbol chars", | |
| 395 "10010110110101001101011010100100101001011010100101101001001010010101101001011010010010100101101101001010100100101001010101100101101001001010010110101100101010010010100101011011001010100100101001010101001101101001001010010110101001101010010010100101011010011010100100101001010101100110101001001010010110101010011010010010100101011010100110100101011011011001010110101001001010010110101101001010100110110101101001010110101100101011011011001010101010011010110110100110101010110011010101010010110110110100101101010110010110101001001010010100110110101010100100100101011011001010101001001001010101001101101010010010010110101001101010100100100101011010011010101001001001010101100110101010010010010100110101011011010100101101011010010110110110100101010101100101101101011001010101101100101010101001101101101010011010101101001101010101100110101101010100110101101010011011011010100101010110100110110101101001010110110100101010101100110110101011001010110101100101010110110010110010101011010011010101101100110101010100101101011011001011010101001101101010101001001001011010101001101010010010010101101010011010100100100101101101010010100101101101" | |
| 396 }, | |
| 397 /* 23*/ { BARCODE_EXCODE39, -1, "^_`abcdefghijklmnopqrstuvwxyz{|}~", -1, 0, 1, 883, "Visible ASCII last part", | |
| 398 "1001011011010101001001001010101101001101010010010010110101101001010100100100101100110101010100101001001011010100101101001010010010101101001011010010100100101101101001010100101001001010101100101101001010010010110101100101010010100100101011011001010100101001001010101001101101001010010010110101001101010010100100101011010011010100101001001010101100110101001010010010110101010011010010100100101011010100110100101001001011011010100101001010010010101011010011010010100100101101011010010100101001001010110110100101001010010010101010110011010010100100101101010110010100101001001010110101100101001010010010101011011001010010100100101100101010110100101001001010011010101101001010010010110011010101010010100100101001011010110100101001001011001011010101001010010010100110110101010100100100101011011010010101001001001010101011001101010010010010110101011001010100100100101011010110010100101101101" | |
| 399 }, | |
| 400 /* 24*/ { BARCODE_LOGMARS, -1, "1A", -1, 0, 1, 63, "Verified manually against TEC-IT", | |
| 401 "100010111011101011101000101011101110101000101110100010111011101" | |
| 402 }, | |
| 403 /* 25*/ { BARCODE_LOGMARS, 1, "1A", -1, 0, 1, 79, "With check digit; verified manually against TEC-IT", | |
| 404 "1000101110111010111010001010111011101010001011101011101000101110100010111011101" | |
| 405 }, | |
| 406 /* 26*/ { BARCODE_LOGMARS, -1, "ABC", -1, 0, 1, 79, "MIL-STD-1189 Rev. B Figure 1", | |
| 407 "1000101110111010111010100010111010111010001011101110111010001010100010111011101" | |
| 408 }, | |
| 409 /* 27*/ { BARCODE_LOGMARS, -1, "SAMPLE 1", -1, 0, 1, 159, "MIL-STD-1189 Rev. B Figure 2 top", | |
| 410 "100010111011101010111010111000101110101000101110111011101010001010111011101000101011101010001110111010111000101010001110101110101110100010101110100010111011101" | |
| 411 }, | |
| 412 /* 28*/ { BARCODE_LOGMARS, 1, "12345/ABCDE", -1, 0, 1, 223, "MIL-STD-1189 Rev. B Section 6.2.1 check character example; verified manually against TEC-IT", | |
| 413 "1000101110111010111010001010111010111000101011101110111000101010101000111010111011101000111010101000100010100010111010100010111010111010001011101110111010001010101011100010111011101011100010101010111011100010100010111011101" | |
| 414 }, | |
| 415 /* 29*/ { BARCODE_CODE93, -1, "C93", -1, 0, 1, 64, "ANSI/AIM BC5-1995 Figure 1; verified manually against TEC-IT", | |
| 416 "1010111101101000101000010101010000101101010001110110101010111101" | |
| 417 }, | |
| 418 /* 30*/ { BARCODE_CODE93, -1, "CODE\01593", -1, 0, 1, 109, "ANSI/AIM BC5-1995 Figure B1; verified manually against TEC-IT", | |
| 419 "1010111101101000101001011001100101001100100101001001101010011001000010101010000101100101001000101101010111101" | |
| 420 }, | |
| 421 /* 31*/ { BARCODE_CODE93, -1, "1A", -1, 0, 1, 55, "Verified manually against TEC-IT", | |
| 422 "1010111101010010001101010001101000101001110101010111101" | |
| 423 }, | |
| 424 /* 32*/ { BARCODE_CODE93, -1, "TEST93", -1, 0, 1, 91, "Verified manually against TEC-IT", | |
| 425 "1010111101101001101100100101101011001101001101000010101010000101011101101001000101010111101" | |
| 426 }, | |
| 427 /* 33*/ { BARCODE_CODE93, -1, "\000a\177", 3, 0, 1, 91, "Verified manually against TEC-IT", | |
| 428 "1010111101110110101100101101001100101101010001110110101101001101011011101010010001010111101" | |
| 429 }, | |
| 430 /* 34*/ { BARCODE_CODE93, -1, " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghij", -1, 0, 1, 1000, "Visible ASCII 1st 107 symbol chars", | |
| 431 "1010111101110100101110101101101010001110101101101001001110101101101000101110010101101011101110101101100010101110101101011010001110101101011001001110101101011000101110101101001101001011101101110101101010110001001011101110101001011011101000101001010010001010001001010000101001010001001001001001000101010100001000100101000010101110101101001110101110110101100010101110110101011010001110110101011001001110110101011000101110110101001101001110110101100110101101010001101001001101000101100101001100100101100010101011010001011001001011000101001101001000110101010110001010011001010001101001011001000101101101101001101100101101011001101001101100101101100110101011011001011001101001101101001110101110110101000110101110110101010110001110110101010011001110110101010001101110110101001011001110110101011011001001100101101010001001100101101001001001100101101000101001100101100101001001100101100100101001100101100010101001100101011010001001100101011001001001100101011000101001100101001101001010001101101001101010111101" | |
| 432 }, | |
| 433 /* 35*/ { BARCODE_CODE93, -1, "klmnopqrstuvwxyz{|}~", -1, 0, 1, 397, "Visible ASCII last part", | |
| 434 "1010111101001100101000110101001100101010110001001100101010011001001100101010001101001100101001011001001100101000101101001100101101101001001100101101100101001100101101011001001100101101001101001100101100101101001100101100110101001100101011011001001100101011001101001100101001101101001100101001110101110110101000101101110110101101101001110110101101100101110110101101011001101001001101100101010111101" | |
| 435 }, | |
| 436 /* 36*/ { BARCODE_PZN, -1, "1234567", -1, 0, 1, 142, "Example from IFA Info Code 39 EN V2.1; verified manually against TEC-IT", | |
| 437 "1001011011010100101011011011010010101101011001010110110110010101010100110101101101001101010101100110101010100101101101101001011010100101101101" | |
| 438 }, | |
| 439 /* 37*/ { BARCODE_PZN, -1, "2758089", -1, 0, 1, 142, "Example from IFA Info Check Digit Calculations EN 15 July 2019; verified manually against TEC-IT", | |
| 440 "1001011011010100101011011010110010101101010010110110110100110101011010010110101010011011010110100101101010110010110101011001011010100101101101" | |
| 441 }, | |
| 442 /* 38*/ { BARCODE_PZN, 1, "123456", -1, 0, 1, 129, "Example from BWIPP; verified manually against TEC-IT", | |
| 443 "100101101101010010101101101101001010110101100101011011011001010101010011010110110100110101010110011010101011001010110100101101101" | |
| 444 }, | |
| 445 /* 39*/ { BARCODE_VIN, -1, "1FTCR10UXTPA78180", -1, 0, 1, 246, "https://www.vinquery.com/img/vinbarcode/vinbarcode4.jpg", | |
| 446 "100101101101011010010101101011011001010101011011001011011010010101101010110010110100101011010100110110101100101010110100101101011010101101100101011011010010110101001011010100101101101101001011010110100101011011010010110101010011011010100101101101" | |
| 447 }, | |
| 448 /* 40*/ { BARCODE_VIN, 1, "2FTPX28L0XCA15511", -1, 0, 1, 259, "With Import 'I' prefix; https://www.vinquery.com/img/vinbarcode/vinbarcode1.jpg", | |
| 449 "1001011011010101101001101010110010101101011011001010101011011001010110110100101001011010110101100101011011010010110101011010100110101001101101010010110101101101101001010110101001011011010010101101101001101010110100110101011010010101101101001010110100101101101" | |
| 450 }, | |
| 451 /* 41*/ { BARCODE_HIBC_39, -1, "A123BJC5D6E71", -1, 0, 1, 271, "ANSI/HIBC 2.6 - 2016 Figure 2, same", | |
| 452 "1000101110111010100010100010001011101010001011101110100010101110101110001010111011101110001010101011101000101110101011100011101011101110100010101110100011101010101011100010111010111000111010101110101110001010101000101110111011101000101011101010100011101110100010111011101" | |
| 453 }, | |
| 454 /* 42*/ { BARCODE_HIBC_39, -1, "$$52001510X3G", -1, 0, 1, 271, "ANSI/HIBC 2.6 - 2016 Figure 6, same", | |
| 455 "1000101110111010100010100010001010001000100010101000100010001010111010001110101010111000101011101010001110111010101000111011101011101000101011101110100011101010111010001010111010100011101110101000101110101110111011100010101010101000111011101010111000101110100010111011101" | |
| 456 }, | |
| 457 }; | |
| 458 const int data_size = ARRAY_SIZE(data); | |
| 459 int i, length, ret; | |
| 460 struct zint_symbol *symbol = NULL; | |
| 461 | |
| 462 char escaped[1024]; | |
| 463 char cmp_buf[8192]; | |
| 464 char cmp_msg[1024]; | |
| 465 | |
| 466 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */ | |
| 467 int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */ | |
| 468 | |
| 469 testStartSymbol("test_encode", &symbol); | |
| 470 | |
| 471 for (i = 0; i < data_size; i++) { | |
| 472 | |
| 473 if (testContinue(p_ctx, i)) continue; | |
| 474 | |
| 475 symbol = ZBarcode_Create(); | |
| 476 assert_nonnull(symbol, "Symbol not created\n"); | |
| 477 | |
| 478 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, data[i].length, debug); | |
| 479 | |
| 480 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 481 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 482 | |
| 483 if (p_ctx->generate) { | |
| 484 printf(" /*%3d*/ { %s, %d, \"%s\", %d, %s, %d, %d, \"%s\",\n", | |
| 485 i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length, | |
| 486 testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); | |
| 487 testUtilModulesPrint(symbol, " ", "\n"); | |
| 488 printf(" },\n"); | |
| 489 } else { | |
| 490 if (ret < ZINT_ERROR) { | |
| 491 int width, row; | |
| 492 | |
| 493 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); | |
| 494 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); | |
| 495 | |
| 496 ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); | |
| 497 assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data); | |
| 498 | |
| 499 if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) { | |
| 500 ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL); | |
| 501 assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 502 | |
| 503 ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected); | |
| 504 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", | |
| 505 i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected); | |
| 506 } | |
| 507 if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) { | |
| 508 int cmp_len, ret_len; | |
| 509 char modules_dump[8192 + 1]; | |
| 510 assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i); | |
| 511 ret = testUtilZXingCPP(i, symbol, data[i].data, length, modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len); | |
| 512 assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 513 | |
| 514 ret = testUtilZXingCPPCmp(symbol, cmp_msg, cmp_buf, cmp_len, data[i].data, length, NULL /*primary*/, escaped, &ret_len); | |
| 515 assert_zero(ret, "i:%d %s testUtilZXingCPPCmp %d != 0 %s\n actual: %.*s\nexpected: %.*s\n", | |
| 516 i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped); | |
| 517 } | |
| 518 } | |
| 519 } | |
| 520 | |
| 521 ZBarcode_Delete(symbol); | |
| 522 } | |
| 523 | |
| 524 testFinish(); | |
| 525 } | |
| 526 | |
| 527 #include <time.h> | |
| 528 | |
| 529 #define TEST_PERF_ITER_MILLES 5 | |
| 530 #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000) | |
| 531 #define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC) | |
| 532 | |
| 533 /* Not a real test, just performance indicator */ | |
| 534 static void test_perf(const testCtx *const p_ctx) { | |
| 535 int debug = p_ctx->debug; | |
| 536 | |
| 537 struct item { | |
| 538 int symbology; | |
| 539 int option_2; | |
| 540 char *data; | |
| 541 int ret; | |
| 542 | |
| 543 int expected_rows; | |
| 544 int expected_width; | |
| 545 char *comment; | |
| 546 }; | |
| 547 static const struct item data[] = { | |
| 548 /* 0*/ { BARCODE_CODE39, -1, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+", 0, 1, 1130, "CODE39 85" }, | |
| 549 /* 1*/ { BARCODE_CODE39, -1, "123456ABCD", 0, 1, 155, "CODE39 10" }, | |
| 550 /* 2*/ { BARCODE_CODE93, -1, | |
| 551 "\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !\"#$%&'()*+,-./0123456789ABCDEFGHIJ", | |
| 552 0, 1, 1000, "CODE93 107 symbol chars" }, | |
| 553 /* 3*/ { BARCODE_CODE93, -1, "123456ABCD", 0, 1, 127, "CODE93 10" }, | |
| 554 /* 4*/ { BARCODE_CODE11, -1, "1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-", 0, 1, 966, "CODE11 121" }, | |
| 555 /* 5*/ { BARCODE_CODE11, -1, "1234567890-", 0, 1, 116, "CODE11 5" }, | |
| 556 }; | |
| 557 const int data_size = ARRAY_SIZE(data); | |
| 558 int i, length, ret; | |
| 559 struct zint_symbol *symbol; | |
| 560 | |
| 561 clock_t start; | |
| 562 clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0; | |
| 563 clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print; | |
| 564 int comment_max = 0; | |
| 565 | |
| 566 if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ | |
| 567 return; | |
| 568 } | |
| 569 | |
| 570 for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment); | |
| 571 | |
| 572 printf("Iterations %d\n", TEST_PERF_ITERATIONS); | |
| 573 | |
| 574 for (i = 0; i < data_size; i++) { | |
| 575 int j; | |
| 576 | |
| 577 if (testContinue(p_ctx, i)) continue; | |
| 578 | |
| 579 diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0; | |
| 580 | |
| 581 for (j = 0; j < TEST_PERF_ITERATIONS; j++) { | |
| 582 start = clock(); | |
| 583 symbol = ZBarcode_Create(); | |
| 584 diff_create += clock() - start; | |
| 585 assert_nonnull(symbol, "Symbol not created\n"); | |
| 586 | |
| 587 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); | |
| 588 | |
| 589 start = clock(); | |
| 590 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 591 diff_encode += clock() - start; | |
| 592 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 593 | |
| 594 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); | |
| 595 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); | |
| 596 | |
| 597 start = clock(); | |
| 598 ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/); | |
| 599 diff_buffer += clock() - start; | |
| 600 assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt); | |
| 601 | |
| 602 symbol->output_options |= OUT_BUFFER_INTERMEDIATE; | |
| 603 start = clock(); | |
| 604 ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/); | |
| 605 diff_buf_inter += clock() - start; | |
| 606 assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt); | |
| 607 symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */ | |
| 608 | |
| 609 start = clock(); | |
| 610 ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/); | |
| 611 diff_print += clock() - start; | |
| 612 assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt); | |
| 613 assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile); | |
| 614 | |
| 615 ZBarcode_Delete(symbol); | |
| 616 } | |
| 617 | |
| 618 printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment, | |
| 619 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)); | |
| 620 | |
| 621 total_create += diff_create; | |
| 622 total_encode += diff_encode; | |
| 623 total_buffer += diff_buffer; | |
| 624 total_buf_inter += diff_buf_inter; | |
| 625 total_print += diff_print; | |
| 626 } | |
| 627 if (p_ctx->index == -1) { | |
| 628 printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals", | |
| 629 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)); | |
| 630 } | |
| 631 } | |
| 632 | |
| 633 int main(int argc, char *argv[]) { | |
| 634 | |
| 635 testFunction funcs[] = { /* name, func */ | |
| 636 { "test_large", test_large }, | |
| 637 { "test_hrt", test_hrt }, | |
| 638 { "test_input", test_input }, | |
| 639 { "test_encode", test_encode }, | |
| 640 { "test_perf", test_perf }, | |
| 641 }; | |
| 642 | |
| 643 testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); | |
| 644 | |
| 645 testReport(); | |
| 646 | |
| 647 return 0; | |
| 648 } | |
| 649 | |
| 650 /* vim: set ts=4 sw=4 et : */ |
