Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tests/test_auspost.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 char *pattern; | |
| 40 int length; | |
| 41 int ret; | |
| 42 int expected_rows; | |
| 43 int expected_width; | |
| 44 }; | |
| 45 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 46 static const struct item data[] = { | |
| 47 /* 0*/ { BARCODE_AUSPOST, "1", 23, 0, 3, 133 }, | |
| 48 /* 1*/ { BARCODE_AUSPOST, "1", 24, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 49 /* 2*/ { BARCODE_AUSPOST, "1", 18, 0, 3, 133 }, | |
| 50 /* 3*/ { BARCODE_AUSPOST, "1", 19, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 51 /* 4*/ { BARCODE_AUSPOST, "1", 16, 0, 3, 103 }, | |
| 52 /* 5*/ { BARCODE_AUSPOST, "1", 17, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 53 /* 6*/ { BARCODE_AUSPOST, "1", 13, 0, 3, 103 }, | |
| 54 /* 7*/ { BARCODE_AUSPOST, "1", 14, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 55 /* 8*/ { BARCODE_AUSPOST, "1", 8, 0, 3, 73 }, | |
| 56 /* 9*/ { BARCODE_AUSPOST, "1", 9, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 57 /* 10*/ { BARCODE_AUSREPLY, "1", 8, 0, 3, 73 }, | |
| 58 /* 11*/ { BARCODE_AUSREPLY, "1", 9, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 59 /* 12*/ { BARCODE_AUSROUTE, "1", 8, 0, 3, 73 }, | |
| 60 /* 13*/ { BARCODE_AUSROUTE, "1", 9, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 61 /* 14*/ { BARCODE_AUSREDIRECT, "1", 8, 0, 3, 73 }, | |
| 62 /* 15*/ { BARCODE_AUSREDIRECT, "1", 9, ZINT_ERROR_TOO_LONG, -1, -1 }, | |
| 63 }; | |
| 64 const int data_size = ARRAY_SIZE(data); | |
| 65 int i, length, ret; | |
| 66 struct zint_symbol *symbol = NULL; | |
| 67 | |
| 68 char data_buf[64]; | |
| 69 | |
| 70 testStartSymbol("test_large", &symbol); | |
| 71 | |
| 72 for (i = 0; i < data_size; i++) { | |
| 73 | |
| 74 if (testContinue(p_ctx, i)) continue; | |
| 75 | |
| 76 symbol = ZBarcode_Create(); | |
| 77 assert_nonnull(symbol, "Symbol not created\n"); | |
| 78 | |
| 79 testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); | |
| 80 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)); | |
| 81 | |
| 82 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); | |
| 83 | |
| 84 ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); | |
| 85 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 86 | |
| 87 if (ret < ZINT_ERROR) { | |
| 88 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); | |
| 89 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); | |
| 90 } | |
| 91 | |
| 92 ZBarcode_Delete(symbol); | |
| 93 } | |
| 94 | |
| 95 testFinish(); | |
| 96 } | |
| 97 | |
| 98 static void test_hrt(const testCtx *const p_ctx) { | |
| 99 int debug = p_ctx->debug; | |
| 100 | |
| 101 struct item { | |
| 102 int symbology; | |
| 103 char *data; | |
| 104 | |
| 105 char *expected; | |
| 106 }; | |
| 107 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 108 static const struct item data[] = { | |
| 109 /* 0*/ { BARCODE_AUSPOST, "12345678901234567890123", "" }, /* None */ | |
| 110 }; | |
| 111 const int data_size = ARRAY_SIZE(data); | |
| 112 int i, length, ret; | |
| 113 struct zint_symbol *symbol = NULL; | |
| 114 | |
| 115 testStartSymbol("test_hrt", &symbol); | |
| 116 | |
| 117 for (i = 0; i < data_size; i++) { | |
| 118 | |
| 119 if (testContinue(p_ctx, i)) continue; | |
| 120 | |
| 121 symbol = ZBarcode_Create(); | |
| 122 assert_nonnull(symbol, "Symbol not created\n"); | |
| 123 | |
| 124 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 125 | |
| 126 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 127 assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); | |
| 128 | |
| 129 assert_zero(strcmp((char *) symbol->text, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->text, data[i].expected); | |
| 130 | |
| 131 ZBarcode_Delete(symbol); | |
| 132 } | |
| 133 | |
| 134 testFinish(); | |
| 135 } | |
| 136 | |
| 137 static void test_input(const testCtx *const p_ctx) { | |
| 138 int debug = p_ctx->debug; | |
| 139 | |
| 140 struct item { | |
| 141 int symbology; | |
| 142 char *data; | |
| 143 int ret; | |
| 144 int expected_rows; | |
| 145 int expected_width; | |
| 146 char *expected_errtxt; | |
| 147 }; | |
| 148 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 149 static const struct item data[] = { | |
| 150 /* 0*/ { BARCODE_AUSPOST, "12345678", 0, 3, 73, "" }, | |
| 151 /* 1*/ { BARCODE_AUSPOST, "1234567A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 405: Invalid character at position 8 in DPID (first 8 characters) (digits only)" }, | |
| 152 /* 2*/ { BARCODE_AUSPOST, "12345678ABcd#", 0, 3, 103, "" }, | |
| 153 /* 3*/ { BARCODE_AUSPOST, "12345678ABcd!", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 404: Invalid character at position 13 in input (alphanumerics, space and \"#\" only)" }, | |
| 154 /* 4*/ { BARCODE_AUSPOST, "12345678ABcd#", 0, 3, 103, "" }, | |
| 155 /* 5*/ { BARCODE_AUSPOST, "1234567890123456", 0, 3, 103, "" }, | |
| 156 /* 6*/ { BARCODE_AUSPOST, "123456789012345A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 402: Invalid character at position 16 in input (digits only for FCC 59 length 16)" }, | |
| 157 /* 7*/ { BARCODE_AUSPOST, "12345678ABCDefgh #", 0, 3, 133, "" }, /* Length 18 */ | |
| 158 /* 8*/ { BARCODE_AUSPOST, "12345678901234567890123", 0, 3, 133, "" }, | |
| 159 /* 9*/ { BARCODE_AUSPOST, "1234567890123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 406: Invalid character at position 23 in input (digits only for FCC 62 length 23)" }, | |
| 160 /* 10*/ { BARCODE_AUSPOST, "1234567", ZINT_ERROR_TOO_LONG, -1, -1, "Error 401: Input length 7 wrong (8, 13, 16, 18 or 23 only)" }, /* No leading zeroes added */ | |
| 161 /* 11*/ { BARCODE_AUSREPLY, "12345678", 0, 3, 73, "" }, | |
| 162 /* 12*/ { BARCODE_AUSREPLY, "1234567", 0, 3, 73, "" }, /* Leading zeroes added */ | |
| 163 /* 13*/ { BARCODE_AUSREPLY, "123456789", ZINT_ERROR_TOO_LONG, -1, -1, "Error 403: Input length 9 too long (maximum 8)" }, | |
| 164 /* 14*/ { BARCODE_AUSROUTE, "123456", 0, 3, 73, "" }, | |
| 165 /* 15*/ { BARCODE_AUSROUTE, "12345", 0, 3, 73, "" }, | |
| 166 /* 16*/ { BARCODE_AUSROUTE, "123456789", ZINT_ERROR_TOO_LONG, -1, -1, "Error 403: Input length 9 too long (maximum 8)" }, | |
| 167 /* 17*/ { BARCODE_AUSREDIRECT, "1234", 0, 3, 73, "" }, | |
| 168 /* 18*/ { BARCODE_AUSREDIRECT, "123", 0, 3, 73, "" }, | |
| 169 /* 19*/ { BARCODE_AUSREDIRECT, "0", 0, 3, 73, "" }, | |
| 170 /* 20*/ { BARCODE_AUSREDIRECT, "123456789", ZINT_ERROR_TOO_LONG, -1, -1, "Error 403: Input length 9 too long (maximum 8)" }, | |
| 171 }; | |
| 172 const int data_size = ARRAY_SIZE(data); | |
| 173 int i, length, ret; | |
| 174 struct zint_symbol *symbol = NULL; | |
| 175 | |
| 176 char cmp_buf[8192]; | |
| 177 char cmp_msg[1024]; | |
| 178 | |
| 179 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */ | |
| 180 | |
| 181 testStartSymbol("test_input", &symbol); | |
| 182 | |
| 183 for (i = 0; i < data_size; i++) { | |
| 184 | |
| 185 if (testContinue(p_ctx, i)) continue; | |
| 186 | |
| 187 symbol = ZBarcode_Create(); | |
| 188 assert_nonnull(symbol, "Symbol not created\n"); | |
| 189 | |
| 190 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 191 | |
| 192 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 193 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 194 assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt); | |
| 195 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt); | |
| 196 | |
| 197 if (ret < ZINT_ERROR) { | |
| 198 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); | |
| 199 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); | |
| 200 | |
| 201 if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { | |
| 202 char modules_dump[4096]; | |
| 203 assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i); | |
| 204 ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL); | |
| 205 assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 206 | |
| 207 ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump); | |
| 208 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", | |
| 209 i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump); | |
| 210 } | |
| 211 } | |
| 212 | |
| 213 ZBarcode_Delete(symbol); | |
| 214 } | |
| 215 | |
| 216 testFinish(); | |
| 217 } | |
| 218 | |
| 219 /* Australia Post Customer Barcoding Technical Specifications (Revised 3 Aug 2012) "AusPost Tech Specs" | |
| 220 https://auspost.com.au/content/dam/auspost_corp/media/documents/customer-barcode-technical-specifications-aug2012.pdf | |
| 221 Australia Post A Guide To Printing the 4-State Barcode (Revised 16 March 2012) "AusPost Guide" | |
| 222 https://auspost.com.au/content/dam/auspost_corp/media/documents/a-guide-to-printing-the-4state-barcode-v31-mar2012.pdf | |
| 223 */ | |
| 224 static void test_encode(const testCtx *const p_ctx) { | |
| 225 int debug = p_ctx->debug; | |
| 226 | |
| 227 struct item { | |
| 228 int symbology; | |
| 229 char *data; | |
| 230 int ret; | |
| 231 | |
| 232 int expected_rows; | |
| 233 int expected_width; | |
| 234 char *comment; | |
| 235 char *expected; | |
| 236 }; | |
| 237 static const struct item data[] = { | |
| 238 /* 0*/ { BARCODE_AUSPOST, "96184209", 0, 3, 73, "AusPost Tech Specs Diagram 1; verified manually against TEC-IT", | |
| 239 "1000101010100010001010100000101010001010001000001010000010001000001000100" | |
| 240 "1010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 241 "0000100010000010101010001010000010101010001000101010001000100010000010000" | |
| 242 }, | |
| 243 /* 1*/ { BARCODE_AUSPOST, "39549554", 0, 3, 73, "AusPost Guide Figure 3, same; verified manually against TEC-IT", | |
| 244 "1000101010101010001010001010001010001000101000001000101010001010000000100" | |
| 245 "1010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 246 "0000100010000010001000100000001000100010000000000010001000000000001010000" | |
| 247 }, | |
| 248 /* 2*/ { BARCODE_AUSPOST, "56439111ABA 9", 0, 3, 103, "AusPost Guide Figure 4, same; verified manually against TEC-IT", | |
| 249 "1000100000101000001010101010001010101010101010101010101010101010100000000000001010100010101010000010100" | |
| 250 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 251 "0000001000100010101000000010001010001000100010101010100010101010100000101000000010001000101010000000000" | |
| 252 }, | |
| 253 /* 3*/ { BARCODE_AUSPOST, "3221132412345678", 0, 3, 103, "59 Custom 2 N encoding", | |
| 254 "1000100000101010100010001010101010101000101010101000101010101000001000100000101000000000001000000000100" | |
| 255 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 256 "0000001000100010101010101000100000101010000010001010001000000010101010001010000010001010101000100000000" | |
| 257 }, | |
| 258 /* 4*/ { BARCODE_AUSPOST, "32211324Ab #2", 0, 3, 103, "59 Custom 2 C encoding", | |
| 259 "1000100000101010100010001010101010101000101010101010001010100010100000101000100000000010100000100010100" | |
| 260 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 261 "0000001000100010101010101000100000101010000010101010001010100010000000100000001000101010000010000000000" | |
| 262 }, | |
| 263 /* 5*/ { BARCODE_AUSPOST, "32211324123456789012345", 0, 3, 133, "62 Custom 3 N encoding", | |
| 264 "1000001010001010100010001010101010101000101010101000101010101000001000100000001010101010100010101010100000100000100010101010100010100" | |
| 265 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 266 "0000101010100010101010101000100000101010000010001010001000000010101010001010001010101000101000100000001000001010000010001010100010000" | |
| 267 }, | |
| 268 /* 6*/ { BARCODE_AUSPOST, "32211324aBCd#F hIz", 0, 3, 133, "62 Custom 3 C encoding", | |
| 269 "1000001010001010100010001010101010101000101010000010101010100010000010100010100010100010000010000000000000100010100010101010000000100" | |
| 270 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 271 "0000101010100010101010101000100000101010000010100010100010101010001010000010001010100000100010101000000000101000001010100000000010000" | |
| 272 }, | |
| 273 /* 7*/ { BARCODE_AUSPOST, "12345678DEGHJKLMNO", 0, 3, 133, "62 Custom 3 C encoding GDSET 1st part", | |
| 274 "1000001010001010100010101010100000100010000010101010101010001010001010101010101010100010101010101010100000001010000010000000000010100" | |
| 275 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 276 "0000101010101000101000100000001010101000101010001010000010101010100000101000100000101000001000000000001000001010000010001010001010000" | |
| 277 }, | |
| 278 /* 8*/ { BARCODE_AUSPOST, "23456789PQRSTUVWXY", 0, 3, 133, "62 Custom 3 C encoding GDSET 2nd part", | |
| 279 "1000001010001000101010101000001000100000001010001010001010000000101000101000100000101000101000100000001000101000101010101000101010100" | |
| 280 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 281 "0000101010101010001000000010101010001010001000101000100000101010101010100010101010001010000010001010101000000010001000001010101000000" | |
| 282 }, | |
| 283 /* 9*/ { BARCODE_AUSPOST, "34567890Zcefgijklm", 0, 3, 133, "62 Custom 3 C encoding GDSET 3rd part", | |
| 284 "1000001010001010101010000010001000000010101000001010001010000010100010100010001010001010000010000000100000101000100000001010001010100" | |
| 285 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 286 "0000101010100010000000101010100010100010101010100010000010000000100000000000001000000000001000000010100000101000000010101010100010000" | |
| 287 }, | |
| 288 /* 10*/ { BARCODE_AUSPOST, "12345678lnopqrstuv", 0, 3, 133, "62 Custom 3 C encoding GDSET 4th part", | |
| 289 "1000001010001010100010101010100000100010000010000000100000000000001000001000000000000000100000100000000000001010001010101000000010100" | |
| 290 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 291 "0000101010101000101000100000001010101000101000000010000010100010001010000010001010000000100000000000100000100000001010001000100000000" | |
| 292 }, | |
| 293 /* 11*/ { BARCODE_AUSPOST, "09876543wxy# ", 0, 3, 103, "59 Custom 2 C encoding GDSET 5th part", | |
| 294 "1000100000101010001000000010001010001010101000001000001000000010100010100000100010000000000010100010100" | |
| 295 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 296 "0000001000101010001010101000101000100000001000001000000000001010000010100000001010001000001000100000000" | |
| 297 }, | |
| 298 /* 12*/ { BARCODE_AUSREPLY, "12345678", 0, 3, 73, "Verified manually against tec-it", | |
| 299 "1000101010001010100010101010100000100010000000001000001000000000100010100" | |
| 300 "1010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 301 "0000000000101000101000100000001010101000101000000000100010101000101000000" | |
| 302 }, | |
| 303 /* 13*/ { BARCODE_AUSROUTE, "34567890", 0, 3, 73, "Verified manually against tec-it", | |
| 304 "1000000000101010101010000010001000000010101000100010101010000000101000100" | |
| 305 "1010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 306 "0000101010000010000000101010100010100010101000100010101010001010001000000" | |
| 307 }, | |
| 308 /* 14*/ { BARCODE_AUSREDIRECT, "98765432", 0, 3, 73, "Verified manually against tec-it", | |
| 309 "1000001010000010000000100010100010101010100000101010101000100010100010100" | |
| 310 "1010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 311 "0000001010100010101010001010001000000010101000000000001010101000001010000" | |
| 312 }, | |
| 313 }; | |
| 314 const int data_size = ARRAY_SIZE(data); | |
| 315 int i, length, ret; | |
| 316 struct zint_symbol *symbol = NULL; | |
| 317 | |
| 318 char escaped[1024]; | |
| 319 char bwipp_buf[8192]; | |
| 320 char bwipp_msg[1024]; | |
| 321 | |
| 322 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */ | |
| 323 | |
| 324 testStartSymbol("test_encode", &symbol); | |
| 325 | |
| 326 for (i = 0; i < data_size; i++) { | |
| 327 | |
| 328 if (testContinue(p_ctx, i)) continue; | |
| 329 | |
| 330 symbol = ZBarcode_Create(); | |
| 331 assert_nonnull(symbol, "Symbol not created\n"); | |
| 332 | |
| 333 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 334 | |
| 335 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 336 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 337 | |
| 338 if (p_ctx->generate) { | |
| 339 printf(" /*%3d*/ { %s, \"%s\", %s, %d, %d, \"%s\",\n", | |
| 340 i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), | |
| 341 testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); | |
| 342 testUtilModulesPrint(symbol, " ", "\n"); | |
| 343 printf(" },\n"); | |
| 344 } else { | |
| 345 if (ret < ZINT_ERROR) { | |
| 346 int width, row; | |
| 347 | |
| 348 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); | |
| 349 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); | |
| 350 | |
| 351 ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); | |
| 352 assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data); | |
| 353 | |
| 354 if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { | |
| 355 ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf), NULL); | |
| 356 assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 357 | |
| 358 ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected); | |
| 359 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", | |
| 360 i, testUtilBarcodeName(symbol->symbology), ret, bwipp_msg, bwipp_buf, data[i].expected); | |
| 361 } | |
| 362 } | |
| 363 } | |
| 364 | |
| 365 ZBarcode_Delete(symbol); | |
| 366 } | |
| 367 | |
| 368 testFinish(); | |
| 369 } | |
| 370 | |
| 371 /* #181 Christian Hartlage OSS-Fuzz */ | |
| 372 static void test_fuzz(const testCtx *const p_ctx) { | |
| 373 int debug = p_ctx->debug; | |
| 374 | |
| 375 struct item { | |
| 376 int symbology; | |
| 377 char *data; | |
| 378 int length; | |
| 379 int ret; | |
| 380 }; | |
| 381 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 382 static const struct item data[] = { | |
| 383 /* 0*/ { BARCODE_AUSROUTE, "A\000\000\000", 4, ZINT_ERROR_INVALID_DATA }, | |
| 384 /* 1*/ { BARCODE_AUSROUTE, "1\000\000\000", 4, ZINT_ERROR_INVALID_DATA }, | |
| 385 /* 2*/ { BARCODE_AUSREPLY, "A\000\000\000", 4, ZINT_ERROR_INVALID_DATA }, | |
| 386 /* 3*/ { BARCODE_AUSREPLY, "1\000\000\000", 4, ZINT_ERROR_INVALID_DATA }, | |
| 387 /* 4*/ { BARCODE_AUSREDIRECT, "A\000\000\000", 4, ZINT_ERROR_INVALID_DATA }, | |
| 388 /* 5*/ { BARCODE_AUSREDIRECT, "1\000\000\000", 4, ZINT_ERROR_INVALID_DATA }, | |
| 389 }; | |
| 390 const int data_size = ARRAY_SIZE(data); | |
| 391 int i, length, ret; | |
| 392 struct zint_symbol *symbol = NULL; | |
| 393 | |
| 394 testStartSymbol("test_fuzz", &symbol); | |
| 395 | |
| 396 for (i = 0; i < data_size; i++) { | |
| 397 | |
| 398 if (testContinue(p_ctx, i)) continue; | |
| 399 | |
| 400 symbol = ZBarcode_Create(); | |
| 401 assert_nonnull(symbol, "Symbol not created\n"); | |
| 402 | |
| 403 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); | |
| 404 | |
| 405 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 406 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 407 | |
| 408 ZBarcode_Delete(symbol); | |
| 409 } | |
| 410 | |
| 411 testFinish(); | |
| 412 } | |
| 413 | |
| 414 int main(int argc, char *argv[]) { | |
| 415 | |
| 416 testFunction funcs[] = { /* name, func */ | |
| 417 { "test_large", test_large }, | |
| 418 { "test_hrt", test_hrt }, | |
| 419 { "test_input", test_input }, | |
| 420 { "test_encode", test_encode }, | |
| 421 { "test_fuzz", test_fuzz }, | |
| 422 }; | |
| 423 | |
| 424 testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); | |
| 425 | |
| 426 testReport(); | |
| 427 | |
| 428 return 0; | |
| 429 } | |
| 430 | |
| 431 /* vim: set ts=4 sw=4 et : */ |
