Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tests/test_medical.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 }; | |
| 46 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 47 static const struct item data[] = { | |
| 48 /* 0*/ { BARCODE_CODABAR, -1, "A+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++B", 103, 0, 1, 1133 }, | |
| 49 /* 1*/ { BARCODE_CODABAR, -1, "A++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++B", 104, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 50 /* 2*/ { BARCODE_CODABAR, 1, "A+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++B", 103, 0, 1, 1143 }, | |
| 51 /* 3*/ { BARCODE_CODABAR, 1, "A++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++B", 104, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 52 /* 4*/ { BARCODE_PHARMA, -1, "131070", 6, 0, 1, 78 }, | |
| 53 /* 5*/ { BARCODE_PHARMA, -1, "1", 7, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 54 /* 6*/ { BARCODE_PHARMA_TWO, -1, "64570080", 8, 0, 2, 31 }, | |
| 55 /* 7*/ { BARCODE_PHARMA_TWO, -1, "1", 9, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 56 /* 8*/ { BARCODE_CODE32, -1, "1", 8, 0, 1, 103 }, | |
| 57 /* 9*/ { BARCODE_CODE32, -1, "1", 9, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 58 }; | |
| 59 const int data_size = ARRAY_SIZE(data); | |
| 60 int i, length, ret; | |
| 61 struct zint_symbol *symbol = NULL; | |
| 62 | |
| 63 char data_buf[128]; | |
| 64 | |
| 65 testStartSymbol("test_large", &symbol); | |
| 66 | |
| 67 for (i = 0; i < data_size; i++) { | |
| 68 | |
| 69 if (testContinue(p_ctx, i)) continue; | |
| 70 | |
| 71 symbol = ZBarcode_Create(); | |
| 72 assert_nonnull(symbol, "Symbol not created\n"); | |
| 73 | |
| 74 testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); | |
| 75 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)); | |
| 76 | |
| 77 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); | |
| 78 | |
| 79 ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); | |
| 80 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 81 | |
| 82 if (ret < ZINT_ERROR) { | |
| 83 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); | |
| 84 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); | |
| 85 } | |
| 86 | |
| 87 ZBarcode_Delete(symbol); | |
| 88 } | |
| 89 | |
| 90 testFinish(); | |
| 91 } | |
| 92 | |
| 93 static void test_hrt(const testCtx *const p_ctx) { | |
| 94 int debug = p_ctx->debug; | |
| 95 | |
| 96 struct item { | |
| 97 int symbology; | |
| 98 int option_2; | |
| 99 char *data; | |
| 100 | |
| 101 char *expected; | |
| 102 }; | |
| 103 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 104 static const struct item data[] = { | |
| 105 /* 0*/ { BARCODE_CODABAR, -1, "A1234B", "A1234B" }, | |
| 106 /* 1*/ { BARCODE_CODABAR, -1, "a1234c", "A1234C" }, /* Converts to upper */ | |
| 107 /* 2*/ { BARCODE_CODABAR, 1, "A1234B", "A1234B" }, /* Check not included */ | |
| 108 /* 3*/ { BARCODE_CODABAR, 2, "A1234B", "A12345B" }, /* Check included */ | |
| 109 /* 4*/ { BARCODE_CODABAR, 1, "A123456A", "A123456A" }, /* Check not included */ | |
| 110 /* 5*/ { BARCODE_CODABAR, 2, "A123456A", "A123456$A" }, /* Check included */ | |
| 111 /* 6*/ { BARCODE_PHARMA, -1, "123456", "" }, /* None */ | |
| 112 /* 7*/ { BARCODE_PHARMA_TWO, -1, "123456", "" }, /* None */ | |
| 113 /* 8*/ { BARCODE_CODE32, -1, "123456", "A001234564" }, | |
| 114 /* 9*/ { BARCODE_CODE32, -1, "12345678", "A123456788" }, | |
| 115 }; | |
| 116 const int data_size = ARRAY_SIZE(data); | |
| 117 int i, length, ret; | |
| 118 struct zint_symbol *symbol = NULL; | |
| 119 | |
| 120 testStartSymbol("test_hrt", &symbol); | |
| 121 | |
| 122 for (i = 0; i < data_size; i++) { | |
| 123 | |
| 124 if (testContinue(p_ctx, i)) continue; | |
| 125 | |
| 126 symbol = ZBarcode_Create(); | |
| 127 assert_nonnull(symbol, "Symbol not created\n"); | |
| 128 | |
| 129 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); | |
| 130 | |
| 131 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 132 assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); | |
| 133 | |
| 134 assert_zero(strcmp((char *) symbol->text, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->text, data[i].expected); | |
| 135 | |
| 136 ZBarcode_Delete(symbol); | |
| 137 } | |
| 138 | |
| 139 testFinish(); | |
| 140 } | |
| 141 | |
| 142 static void test_input(const testCtx *const p_ctx) { | |
| 143 int debug = p_ctx->debug; | |
| 144 | |
| 145 struct item { | |
| 146 int symbology; | |
| 147 char *data; | |
| 148 int ret; | |
| 149 int expected_rows; | |
| 150 int expected_width; | |
| 151 const char *expected_errtxt; | |
| 152 int bwipp_cmp; | |
| 153 const char *comment; | |
| 154 }; | |
| 155 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 156 static const struct item data[] = { | |
| 157 /* 0*/ { BARCODE_CODABAR, "A1234B", 0, 1, 62, "", 1, "" }, | |
| 158 /* 1*/ { BARCODE_CODABAR, "1234B", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 358: Does not begin with \"A\", \"B\", \"C\" or \"D\"", 1, "" }, | |
| 159 /* 2*/ { BARCODE_CODABAR, "A1234", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 359: Does not end with \"A\", \"B\", \"C\" or \"D\"", 1, "" }, | |
| 160 /* 3*/ { BARCODE_CODABAR, "A1234E", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 359: Does not end with \"A\", \"B\", \"C\" or \"D\"", 1, "" }, | |
| 161 /* 4*/ { BARCODE_CODABAR, "C123.D", 0, 1, 63, "", 1, "" }, | |
| 162 /* 5*/ { BARCODE_CODABAR, "C123,D", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 357: Invalid character at position 5 in input (\"0123456789-$:/.+ABCD\" only)", 1, "" }, | |
| 163 /* 6*/ { BARCODE_CODABAR, "D:C", 0, 1, 33, "", 1, "" }, | |
| 164 /* 7*/ { BARCODE_CODABAR, "DCC", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 363: Invalid character at position 1 in input (cannot contain \"A\", \"B\", \"C\" or \"D\")", 1, "" }, | |
| 165 /* 8*/ { BARCODE_CODABAR, "A234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123B", ZINT_ERROR_TOO_LONG, -1, -1, "Error 356: Input length 104 too long (maximum 103)", 1, "" }, | |
| 166 /* 9*/ { BARCODE_CODABAR, "AB", ZINT_ERROR_TOO_LONG, -1, -1, "Error 362: Input length 2 too short (minimum 3)", 1, "" }, | |
| 167 /* 10*/ { BARCODE_PHARMA, "131070", 0, 1, 78, "", 1, "" }, | |
| 168 /* 11*/ { BARCODE_PHARMA, "1310700", ZINT_ERROR_TOO_LONG, -1, -1, "Error 350: Input length 7 too long (maximum 6)", 1, "" }, | |
| 169 /* 12*/ { BARCODE_PHARMA, "131071", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 352: Input value '131071' out of range (3 to 131070)", 1, "" }, | |
| 170 /* 13*/ { BARCODE_PHARMA, "3", 0, 1, 4, "", 1, "" }, | |
| 171 /* 14*/ { BARCODE_PHARMA, "2", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 352: Input value '2' out of range (3 to 131070)", 1, "" }, | |
| 172 /* 15*/ { BARCODE_PHARMA, "1", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 352: Input value '1' out of range (3 to 131070)", 1, "" }, | |
| 173 /* 16*/ { BARCODE_PHARMA, "12A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 351: Invalid character at position 3 in input (digits only)", 1, "" }, | |
| 174 /* 17*/ { BARCODE_PHARMA_TWO, "64570080", 0, 2, 31, "", 1, "" }, | |
| 175 /* 18*/ { BARCODE_PHARMA_TWO, "64570081", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 353: Input value '64570081' out of range (4 to 64570080)", 1, "" }, | |
| 176 /* 19*/ { BARCODE_PHARMA_TWO, "064570080", ZINT_ERROR_TOO_LONG, -1, -1, "Error 354: Input length 9 too long (maximum 8)", 1, "" }, | |
| 177 /* 20*/ { BARCODE_PHARMA_TWO, "4", 0, 2, 3, "", 1, "" }, | |
| 178 /* 21*/ { BARCODE_PHARMA_TWO, "3", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 353: Input value '3' out of range (4 to 64570080)", 1, "" }, | |
| 179 /* 22*/ { BARCODE_PHARMA_TWO, "2", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 353: Input value '2' out of range (4 to 64570080)", 1, "" }, | |
| 180 /* 23*/ { BARCODE_PHARMA_TWO, "1", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 353: Input value '1' out of range (4 to 64570080)", 1, "" }, | |
| 181 /* 24*/ { BARCODE_PHARMA_TWO, "123A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 355: Invalid character at position 4 in input (digits only)", 1, "" }, | |
| 182 /* 25*/ { BARCODE_CODE32, "12345678", 0, 1, 103, "", 1, "" }, | |
| 183 /* 26*/ { BARCODE_CODE32, "9", 0, 1, 103, "", 0, "BWIPP requires length 8 or 9" }, | |
| 184 /* 27*/ { BARCODE_CODE32, "0", 0, 1, 103, "", 0, "BWIPP requires length 8 or 9" }, | |
| 185 /* 28*/ { BARCODE_CODE32, "123456789", ZINT_ERROR_TOO_LONG, -1, -1, "Error 360: Input length 9 too long (maximum 8)", 1, "" }, | |
| 186 /* 29*/ { BARCODE_CODE32, "A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 361: Invalid character at position 1 in input (digits only)", 1, "" }, | |
| 187 /* 30*/ { BARCODE_CODE32, "99999999", 0, 1, 103, "", 1, "" }, | |
| 188 }; | |
| 189 const int data_size = ARRAY_SIZE(data); | |
| 190 int i, length, ret; | |
| 191 struct zint_symbol *symbol = NULL; | |
| 192 | |
| 193 char cmp_buf[8192]; | |
| 194 char cmp_msg[1024]; | |
| 195 | |
| 196 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */ | |
| 197 | |
| 198 testStartSymbol("test_input", &symbol); | |
| 199 | |
| 200 for (i = 0; i < data_size; i++) { | |
| 201 | |
| 202 if (testContinue(p_ctx, i)) continue; | |
| 203 | |
| 204 symbol = ZBarcode_Create(); | |
| 205 assert_nonnull(symbol, "Symbol not created\n"); | |
| 206 | |
| 207 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 208 | |
| 209 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 210 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 211 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d symbol->errtxt %s != %s\n", i, symbol->errtxt, data[i].expected_errtxt); | |
| 212 | |
| 213 if (ret < ZINT_ERROR) { | |
| 214 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); | |
| 215 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); | |
| 216 | |
| 217 if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { | |
| 218 if (!data[i].bwipp_cmp) { | |
| 219 if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment); | |
| 220 } else { | |
| 221 char modules_dump[4096]; | |
| 222 assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i); | |
| 223 ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL); | |
| 224 assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 225 | |
| 226 ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump); | |
| 227 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", | |
| 228 i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump); | |
| 229 } | |
| 230 } | |
| 231 } | |
| 232 | |
| 233 ZBarcode_Delete(symbol); | |
| 234 } | |
| 235 | |
| 236 testFinish(); | |
| 237 } | |
| 238 | |
| 239 static void test_encode(const testCtx *const p_ctx) { | |
| 240 int debug = p_ctx->debug; | |
| 241 | |
| 242 struct item { | |
| 243 int symbology; | |
| 244 int option_2; | |
| 245 char *data; | |
| 246 int ret; | |
| 247 | |
| 248 int expected_rows; | |
| 249 int expected_width; | |
| 250 char *comment; | |
| 251 char *expected; | |
| 252 }; | |
| 253 static const struct item data[] = { | |
| 254 /* 0*/ { BARCODE_CODABAR, -1, "A37859B", 0, 1, 72, "BS EN 798:1995 Figure 1", | |
| 255 "101100100101100101010100101101010011010101101010010110100101010010010110" | |
| 256 }, | |
| 257 /* 1*/ { BARCODE_CODABAR, -1, "A0123456789-$:/.+D", 0, 1, 186, "Verified manually against tec-it", | |
| 258 "101100100101010100110101011001010100101101100101010101101001011010100101001010110100101101010011010101101001010101001101010110010101101011011011011010110110110110101011011011010100110010" | |
| 259 }, | |
| 260 /* 2*/ { BARCODE_CODABAR, 1, "A1B", 0, 1, 43, "Verified manually against tec-it", | |
| 261 "1011001001010101100101101101101010010010110" | |
| 262 }, | |
| 263 /* 3*/ { BARCODE_CODABAR, 1, "A+B", 0, 1, 43, "Verified manually against tec-it", | |
| 264 "1011001001010110110110101010011010010010110" | |
| 265 }, | |
| 266 /* 4*/ { BARCODE_CODABAR, 1, "B0123456789-$:/.+B", 0, 1, 196, "Verified manually against tec-it", | |
| 267 "1001001011010101001101010110010101001011011001010101011010010110101001010010101101001011010100110101011010010101010011010101100101011010110110110110101101101101101010110110110100101011010010010110" | |
| 268 }, | |
| 269 /* 5*/ { BARCODE_PHARMA, -1, "131070", 0, 1, 78, "", | |
| 270 "111001110011100111001110011100111001110011100111001110011100111001110011100111" | |
| 271 }, | |
| 272 /* 6*/ { BARCODE_PHARMA, -1, "123456", 0, 1, 58, "", | |
| 273 "1110011100111001001001001110010010011100100100100100100111" | |
| 274 }, | |
| 275 /* 7*/ { BARCODE_PHARMA_TWO, -1, "64570080", 0, 2, 31, "Verified manually against tec-it", | |
| 276 "1010101010101010101010101010101" | |
| 277 "1010101010101010101010101010101" | |
| 278 }, | |
| 279 /* 8*/ { BARCODE_PHARMA_TWO, -1, "29876543", 0, 2, 31, "Verified manually against tec-it", | |
| 280 "0010100010001010001010001000101" | |
| 281 "1000101010100000100000101010000" | |
| 282 }, | |
| 283 /* 9*/ { BARCODE_CODE32, -1, "34567890", 0, 1, 103, "Verified manually against tec-it", | |
| 284 "1001011011010101101001011010110010110101011011010010101100101101011010010101101010101100110100101101101" | |
| 285 }, | |
| 286 }; | |
| 287 const int data_size = ARRAY_SIZE(data); | |
| 288 int i, length, ret; | |
| 289 struct zint_symbol *symbol = NULL; | |
| 290 | |
| 291 char escaped[1024]; | |
| 292 char cmp_buf[8192]; | |
| 293 char cmp_msg[1024]; | |
| 294 | |
| 295 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */ | |
| 296 int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */ | |
| 297 | |
| 298 testStartSymbol("test_encode", &symbol); | |
| 299 | |
| 300 for (i = 0; i < data_size; i++) { | |
| 301 | |
| 302 if (testContinue(p_ctx, i)) continue; | |
| 303 | |
| 304 symbol = ZBarcode_Create(); | |
| 305 assert_nonnull(symbol, "Symbol not created\n"); | |
| 306 | |
| 307 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); | |
| 308 | |
| 309 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 310 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 311 | |
| 312 if (p_ctx->generate) { | |
| 313 printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n", | |
| 314 i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), | |
| 315 testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); | |
| 316 testUtilModulesPrint(symbol, " ", "\n"); | |
| 317 printf(" },\n"); | |
| 318 } else { | |
| 319 if (ret < ZINT_ERROR) { | |
| 320 int width, row; | |
| 321 | |
| 322 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); | |
| 323 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); | |
| 324 | |
| 325 ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); | |
| 326 assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data); | |
| 327 | |
| 328 if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) { | |
| 329 ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL); | |
| 330 assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 331 | |
| 332 ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected); | |
| 333 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", | |
| 334 i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected); | |
| 335 } | |
| 336 if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) { | |
| 337 int cmp_len, ret_len; | |
| 338 char modules_dump[8192 + 1]; | |
| 339 assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i); | |
| 340 ret = testUtilZXingCPP(i, symbol, data[i].data, length, modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len); | |
| 341 assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 342 | |
| 343 ret = testUtilZXingCPPCmp(symbol, cmp_msg, cmp_buf, cmp_len, data[i].data, length, NULL /*primary*/, escaped, &ret_len); | |
| 344 assert_zero(ret, "i:%d %s testUtilZXingCPPCmp %d != 0 %s\n actual: %.*s\nexpected: %.*s\n", | |
| 345 i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped); | |
| 346 } | |
| 347 } | |
| 348 } | |
| 349 | |
| 350 ZBarcode_Delete(symbol); | |
| 351 } | |
| 352 | |
| 353 testFinish(); | |
| 354 } | |
| 355 | |
| 356 int main(int argc, char *argv[]) { | |
| 357 | |
| 358 testFunction funcs[] = { /* name, func */ | |
| 359 { "test_large", test_large }, | |
| 360 { "test_hrt", test_hrt }, | |
| 361 { "test_input", test_input }, | |
| 362 { "test_encode", test_encode }, | |
| 363 }; | |
| 364 | |
| 365 testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); | |
| 366 | |
| 367 testReport(); | |
| 368 | |
| 369 return 0; | |
| 370 } | |
| 371 | |
| 372 /* vim: set ts=4 sw=4 et : */ |
