Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tests/test_postal.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* | |
| 2 libzint - the open source barcode library | |
| 3 Copyright (C) 2019-2024 Robin Stuart <rstuart114@gmail.com> | |
| 4 | |
| 5 Redistribution and use in source and binary forms, with or without | |
| 6 modification, are permitted provided that the following conditions | |
| 7 are met: | |
| 8 | |
| 9 1. Redistributions of source code must retain the above copyright | |
| 10 notice, this list of conditions and the following disclaimer. | |
| 11 2. Redistributions in binary form must reproduce the above copyright | |
| 12 notice, this list of conditions and the following disclaimer in the | |
| 13 documentation and/or other materials provided with the distribution. | |
| 14 3. Neither the name of the project nor the names of its contributors | |
| 15 may be used to endorse or promote products derived from this software | |
| 16 without specific prior written permission. | |
| 17 | |
| 18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| 19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | |
| 22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
| 24 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
| 27 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 28 SUCH DAMAGE. | |
| 29 */ | |
| 30 /* SPDX-License-Identifier: BSD-3-Clause */ | |
| 31 | |
| 32 /* USPS Publication 25 (July 2003) Designing Letter and Reply Mail https://web.archive.org/web/20050118015758/http://www.siemons.com/forms/pdf/designing_letter_reply_mail.pdf */ | |
| 33 /* USPS DMM Domestic Mail Manual https://pe.usps.com/DMM300 */ | |
| 34 /* USPS Publication 197 (Sept 2004) Confirm User Guide https://web.archive.org/web/20060505214851/https://mailtracking.usps.com/mtr/resources/documents/Guide.pdf */ | |
| 35 | |
| 36 #include "testcommon.h" | |
| 37 | |
| 38 static void test_large(const testCtx *const p_ctx) { | |
| 39 int debug = p_ctx->debug; | |
| 40 | |
| 41 struct item { | |
| 42 int symbology; | |
| 43 char *pattern; | |
| 44 int length; | |
| 45 int ret; | |
| 46 int expected_rows; | |
| 47 int expected_width; | |
| 48 char *expected_errtxt; | |
| 49 }; | |
| 50 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 51 static const struct item data[] = { | |
| 52 /* 0*/ { BARCODE_FLAT, "1", 128, 0, 1, 1152, "" }, | |
| 53 /* 1*/ { BARCODE_FLAT, "1", 129, ZINT_ERROR_TOO_LONG, -1, -1, "Error 494: Input length 129 too long (maximum 128)" }, | |
| 54 /* 2*/ { BARCODE_POSTNET, "1", 11, 0, 2, 123, "" }, | |
| 55 /* 3*/ { BARCODE_POSTNET, "1", 12, ZINT_WARN_NONCOMPLIANT, 2, 133, "Warning 479: Input length 12 is not standard (5, 9 or 11)" }, | |
| 56 /* 4*/ { BARCODE_POSTNET, "1", 38, ZINT_WARN_NONCOMPLIANT, 2, 393, "Warning 479: Input length 38 is not standard (5, 9 or 11)" }, | |
| 57 /* 5*/ { BARCODE_POSTNET, "1", 39, ZINT_ERROR_TOO_LONG, -1, -1, "Error 480: Input length 39 too long (maximum 38)" }, | |
| 58 /* 6*/ { BARCODE_FIM, "D", 1, 0, 1, 17, "" }, | |
| 59 /* 7*/ { BARCODE_FIM, "D", 2, ZINT_ERROR_TOO_LONG, -1, -1, "Error 486: Input length 2 too long (maximum 1)" }, | |
| 60 /* 8*/ { BARCODE_CEPNET, "1", 8, 0, 2, 93, "" }, | |
| 61 /* 9*/ { BARCODE_CEPNET, "1", 7, ZINT_WARN_NONCOMPLIANT, 2, 83, "Warning 780: Input length 7 wrong (should be 8 digits)" }, | |
| 62 /* 10*/ { BARCODE_CEPNET, "1", 9, ZINT_WARN_NONCOMPLIANT, 2, 103, "Warning 780: Input length 9 wrong (should be 8 digits)" }, | |
| 63 /* 11*/ { BARCODE_CEPNET, "1", 39, ZINT_ERROR_TOO_LONG, -1, -1, "Error 480: Input length 39 too long (maximum 38)" }, | |
| 64 /* 12*/ { BARCODE_RM4SCC, "1", 50, 0, 3, 411, "" }, | |
| 65 /* 13*/ { BARCODE_RM4SCC, "1", 51, ZINT_ERROR_TOO_LONG, -1, -1, "Error 488: Input length 51 too long (maximum 50)" }, | |
| 66 /* 14*/ { BARCODE_JAPANPOST, "1", 20, 0, 3, 133, "" }, | |
| 67 /* 15*/ { BARCODE_JAPANPOST, "1", 21, ZINT_ERROR_TOO_LONG, -1, -1, "Error 496: Input length 21 too long (maximum 20)" }, | |
| 68 /* 16*/ { BARCODE_JAPANPOST, "A", 10, 0, 3, 133, "" }, | |
| 69 /* 17*/ { BARCODE_JAPANPOST, "A", 11, ZINT_ERROR_TOO_LONG, -1, -1, "Error 477: Input too long, requires too many symbol characters (maximum 20)" }, | |
| 70 /* 18*/ { BARCODE_KOREAPOST, "1", 6, 0, 1, 162, "" }, | |
| 71 /* 19*/ { BARCODE_KOREAPOST, "1", 7, ZINT_ERROR_TOO_LONG, -1, -1, "Error 484: Input length 7 too long (maximum 6)" }, | |
| 72 /* 20*/ { BARCODE_PLANET, "1", 13, 0, 2, 143, "" }, | |
| 73 /* 21*/ { BARCODE_PLANET, "1", 14, ZINT_WARN_NONCOMPLIANT, 2, 153, "Warning 478: Input length 14 is not standard (11 or 13)" }, | |
| 74 /* 22*/ { BARCODE_PLANET, "1", 38, ZINT_WARN_NONCOMPLIANT, 2, 393, "Warning 478: Input length 38 is not standard (11 or 13)" }, | |
| 75 /* 23*/ { BARCODE_PLANET, "1", 39, ZINT_ERROR_TOO_LONG, -1, -1, "Error 482: Input length 39 too long (maximum 38)" }, | |
| 76 /* 24*/ { BARCODE_KIX, "1", 18, 0, 3, 143, "" }, | |
| 77 /* 25*/ { BARCODE_KIX, "1", 19, ZINT_ERROR_TOO_LONG, -1, -1, "Error 490: Input length 19 too long (maximum 18)" }, | |
| 78 /* 26*/ { BARCODE_DAFT, "D", 576, 0, 3, 1151, "" }, | |
| 79 /* 27*/ { BARCODE_DAFT, "D", 577, ZINT_ERROR_TOO_LONG, -1, -1, "Error 492: Input length 577 too long (maximum 576)" }, | |
| 80 }; | |
| 81 const int data_size = ARRAY_SIZE(data); | |
| 82 int i, length, ret; | |
| 83 struct zint_symbol *symbol = NULL; | |
| 84 | |
| 85 char data_buf[4096]; | |
| 86 | |
| 87 testStartSymbol("test_large", &symbol); | |
| 88 | |
| 89 for (i = 0; i < data_size; i++) { | |
| 90 | |
| 91 if (testContinue(p_ctx, i)) continue; | |
| 92 | |
| 93 symbol = ZBarcode_Create(); | |
| 94 assert_nonnull(symbol, "Symbol not created\n"); | |
| 95 | |
| 96 testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); | |
| 97 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)); | |
| 98 | |
| 99 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); | |
| 100 | |
| 101 ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); | |
| 102 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 103 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt); | |
| 104 | |
| 105 if (ret < ZINT_ERROR) { | |
| 106 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); | |
| 107 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); | |
| 108 } | |
| 109 | |
| 110 ZBarcode_Delete(symbol); | |
| 111 } | |
| 112 | |
| 113 testFinish(); | |
| 114 } | |
| 115 | |
| 116 static void test_koreapost(const testCtx *const p_ctx) { | |
| 117 int debug = p_ctx->debug; | |
| 118 | |
| 119 struct item { | |
| 120 char *data; | |
| 121 int ret_encode; | |
| 122 int ret_vector; | |
| 123 | |
| 124 float expected_height; | |
| 125 int expected_rows; | |
| 126 int expected_width; | |
| 127 }; | |
| 128 static const struct item data[] = { | |
| 129 /* 0*/ { "123456", 0, 0, 50, 1, 167 }, | |
| 130 }; | |
| 131 const int data_size = ARRAY_SIZE(data); | |
| 132 int i, length, ret; | |
| 133 struct zint_symbol *symbol = NULL; | |
| 134 | |
| 135 testStartSymbol("test_koreapost", &symbol); | |
| 136 | |
| 137 for (i = 0; i < data_size; i++) { | |
| 138 | |
| 139 if (testContinue(p_ctx, i)) continue; | |
| 140 | |
| 141 symbol = ZBarcode_Create(); | |
| 142 assert_nonnull(symbol, "Symbol not created\n"); | |
| 143 | |
| 144 length = testUtilSetSymbol(symbol, BARCODE_KOREAPOST, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 145 | |
| 146 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 147 assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret_encode); | |
| 148 | |
| 149 if (ret < ZINT_ERROR) { | |
| 150 assert_equal(symbol->height, data[i].expected_height, "i:%d symbol->height %.8g != %.8g\n", i, symbol->height, data[i].expected_height); | |
| 151 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); | |
| 152 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); | |
| 153 | |
| 154 ret = ZBarcode_Buffer_Vector(symbol, 0); | |
| 155 assert_equal(ret, data[i].ret_vector, "i:%d ZBarcode_Buffer_Vector ret %d != %d\n", i, ret, data[i].ret_vector); | |
| 156 } | |
| 157 | |
| 158 ZBarcode_Delete(symbol); | |
| 159 } | |
| 160 | |
| 161 testFinish(); | |
| 162 } | |
| 163 | |
| 164 static void test_japanpost(const testCtx *const p_ctx) { | |
| 165 int debug = p_ctx->debug; | |
| 166 | |
| 167 struct item { | |
| 168 char *data; | |
| 169 int ret_encode; | |
| 170 int ret_vector; | |
| 171 | |
| 172 float expected_height; | |
| 173 int expected_rows; | |
| 174 int expected_width; | |
| 175 char *comment; | |
| 176 }; | |
| 177 static const struct item data[] = { | |
| 178 /* 0*/ { "123", 0, 0, 8, 3, 133, "Check 3" }, | |
| 179 /* 1*/ { "123456-AB", 0, 0, 8, 3, 133, "Check 10" }, | |
| 180 /* 2*/ { "123456", 0, 0, 8, 3, 133, "Check 11" }, | |
| 181 /* 3*/ { "999980-KZ", 0, 0, 8, 3, 133, "Check 18" }, | |
| 182 /* 4*/ { "987654-TU", 0, 0, 8, 3, 133, "Check 0" }, | |
| 183 }; | |
| 184 const int data_size = ARRAY_SIZE(data); | |
| 185 int i, length, ret; | |
| 186 struct zint_symbol *symbol = NULL; | |
| 187 | |
| 188 testStartSymbol("test_japanpost", &symbol); | |
| 189 | |
| 190 for (i = 0; i < data_size; i++) { | |
| 191 | |
| 192 if (testContinue(p_ctx, i)) continue; | |
| 193 | |
| 194 symbol = ZBarcode_Create(); | |
| 195 assert_nonnull(symbol, "Symbol not created\n"); | |
| 196 | |
| 197 length = testUtilSetSymbol(symbol, BARCODE_JAPANPOST, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 198 | |
| 199 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 200 assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret_encode); | |
| 201 | |
| 202 if (ret < ZINT_ERROR) { | |
| 203 assert_equal(symbol->height, data[i].expected_height, "i:%d symbol->height %.8g != %.8g\n", i, symbol->height, data[i].expected_height); | |
| 204 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); | |
| 205 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); | |
| 206 | |
| 207 ret = ZBarcode_Buffer_Vector(symbol, 0); | |
| 208 assert_equal(ret, data[i].ret_vector, "i:%d ZBarcode_Buffer_Vector ret %d != %d\n", i, ret, data[i].ret_vector); | |
| 209 } | |
| 210 | |
| 211 ZBarcode_Delete(symbol); | |
| 212 } | |
| 213 | |
| 214 testFinish(); | |
| 215 } | |
| 216 | |
| 217 static void test_input(const testCtx *const p_ctx) { | |
| 218 int debug = p_ctx->debug; | |
| 219 | |
| 220 struct item { | |
| 221 int symbology; | |
| 222 int option_2; | |
| 223 float height; | |
| 224 char *data; | |
| 225 int ret; | |
| 226 int expected_rows; | |
| 227 int expected_width; | |
| 228 float expected_height; | |
| 229 char *expected_errtxt; | |
| 230 int bwipp_cmp; | |
| 231 char *comment; | |
| 232 }; | |
| 233 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 234 static const struct item data[] = { | |
| 235 /* 0*/ { BARCODE_FLAT, -1, 0, "1234567890", 0, 1, 90, 50, "", 1, "" }, | |
| 236 /* 1*/ { BARCODE_FLAT, -1, 0, "A", ZINT_ERROR_INVALID_DATA, -1, -1, -1, "Error 495: Invalid character at position 1 in input (digits only)", 1, "" }, | |
| 237 /* 2*/ { BARCODE_POSTNET, -1, 0, "12345", 0, 2, 63, 12, "", 1, "" }, | |
| 238 /* 3*/ { BARCODE_POSTNET, -1, 0, "123457689", 0, 2, 103, 12, "", 1, "" }, | |
| 239 /* 4*/ { BARCODE_POSTNET, -1, 0, "12345768901", 0, 2, 123, 12, "", 1, "" }, | |
| 240 /* 5*/ { BARCODE_POSTNET, -1, 0, "0", ZINT_WARN_NONCOMPLIANT, 2, 23, 12, "Warning 479: Input length 1 is not standard (5, 9 or 11)", 0, "BWIPP requires standard lengths" }, | |
| 241 /* 6*/ { BARCODE_POSTNET, -1, 0, "1234", ZINT_WARN_NONCOMPLIANT, 2, 53, 12, "Warning 479: Input length 4 is not standard (5, 9 or 11)", 0, "BWIPP requires standard lengths" }, | |
| 242 /* 7*/ { BARCODE_POSTNET, -1, 0, "123456", ZINT_WARN_NONCOMPLIANT, 2, 73, 12, "Warning 479: Input length 6 is not standard (5, 9 or 11)", 0, "BWIPP requires standard lengths" }, | |
| 243 /* 8*/ { BARCODE_POSTNET, -1, 0, "123456789012", ZINT_WARN_NONCOMPLIANT, 2, 133, 12, "Warning 479: Input length 12 is not standard (5, 9 or 11)", 0, "BWIPP requires standard lengths" }, | |
| 244 /* 9*/ { BARCODE_POSTNET, -1, 0, "1234A", ZINT_ERROR_INVALID_DATA, -1, -1, -1, "Error 481: Invalid character at position 5 in input (digits only)", 1, "" }, | |
| 245 /* 10*/ { BARCODE_POSTNET, -1, 0.9, "12345", 0, 2, 63, 1, "", 1, "" }, | |
| 246 /* 11*/ { BARCODE_FIM, -1, 0, "a", 0, 1, 17, 50, "", 1, "" }, | |
| 247 /* 12*/ { BARCODE_FIM, -1, 0, "b", 0, 1, 17, 50, "", 1, "" }, | |
| 248 /* 13*/ { BARCODE_FIM, -1, 0, "c", 0, 1, 17, 50, "", 1, "" }, | |
| 249 /* 14*/ { BARCODE_FIM, -1, 0, "d", 0, 1, 17, 50, "", 1, "" }, | |
| 250 /* 15*/ { BARCODE_FIM, -1, 0, "ad", ZINT_ERROR_TOO_LONG, -1, -1, -1, "Error 486: Input length 2 too long (maximum 1)", 1, "" }, | |
| 251 /* 16*/ { BARCODE_FIM, -1, 0, "e", 0, 1, 17, 50, "", 1, "" }, | |
| 252 /* 17*/ { BARCODE_FIM, -1, 0, "f", ZINT_ERROR_INVALID_DATA, -1, -1, -1, "Error 487: Invalid character in input (\"A\", \"B\", \"C\", \"D\" or \"E\" only)", 1, "" }, | |
| 253 /* 18*/ { BARCODE_CEPNET, -1, 0, "1234567A", ZINT_ERROR_INVALID_DATA, -1, -1, -1, "Error 481: Invalid character at position 8 in input (digits only)", 1, "" }, | |
| 254 /* 19*/ { BARCODE_RM4SCC, -1, 0, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, 3, 299, 8, "", 1, "" }, | |
| 255 /* 20*/ { BARCODE_RM4SCC, -1, 0, "a", 0, 3, 19, 8, "", 1, "" }, /* Converts to upper */ | |
| 256 /* 21*/ { BARCODE_RM4SCC, -1, 0, ",", ZINT_ERROR_INVALID_DATA, -1, -1, -1, "Error 489: Invalid character at position 1 in input (alphanumerics only)", 1, "" }, | |
| 257 /* 22*/ { BARCODE_JAPANPOST, -1, 0, "1234567890-ABCD", 0, 3, 133, 8, "", 1, "" }, /* 19 symbol chars */ | |
| 258 /* 23*/ { BARCODE_JAPANPOST, -1, 0, "1234567890-ABCD1", 0, 3, 133, 8, "", 1, "" }, /* 20 symbol chars */ | |
| 259 /* 24*/ { BARCODE_JAPANPOST, -1, 0, "1234567890-ABCDE", ZINT_ERROR_TOO_LONG, -1, -1, -1, "Error 477: Input too long, requires too many symbol characters (maximum 20)", 1, "" }, /* 21 symbol chars */ | |
| 260 /* 25*/ { BARCODE_JAPANPOST, -1, 0, "1234567890-ABCD12", ZINT_ERROR_TOO_LONG, -1, -1, -1, "Error 477: Input too long, requires too many symbol characters (maximum 20)", 1, "" }, /* 21 symbol chars */ | |
| 261 /* 26*/ { BARCODE_JAPANPOST, -1, 0, "1234567890ABCDE", 0, 3, 133, 8, "", 1, "" }, /* 20 symbol chars */ | |
| 262 /* 27*/ { BARCODE_JAPANPOST, -1, 0, "a", 0, 3, 133, 8, "", 1, "" }, /* Converts to upper */ | |
| 263 /* 28*/ { BARCODE_JAPANPOST, -1, 0, ",", ZINT_ERROR_INVALID_DATA, -1, -1, -1, "Error 497: Invalid character at position 1 in input (alphanumerics and \"-\" only)", 1, "" }, | |
| 264 /* 29*/ { BARCODE_KOREAPOST, -1, 0, "123456", 0, 1, 167, 50, "", 1, "" }, | |
| 265 /* 30*/ { BARCODE_KOREAPOST, -1, 0, "A", ZINT_ERROR_INVALID_DATA, -1, -1, -1, "Error 485: Invalid character at position 1 in input (digits only)", 1, "" }, | |
| 266 /* 31*/ { BARCODE_PLANET, -1, 0, "12345678901", 0, 2, 123, 12, "", 1, "" }, | |
| 267 /* 32*/ { BARCODE_PLANET, -1, 0, "1234567890123", 0, 2, 143, 12, "", 1, "" }, | |
| 268 /* 33*/ { BARCODE_PLANET, -1, 0, "0", ZINT_WARN_NONCOMPLIANT, 2, 23, 12, "Warning 478: Input length 1 is not standard (11 or 13)", 0, "BWIPP requires standard lengths" }, | |
| 269 /* 34*/ { BARCODE_PLANET, -1, 0, "1234567890", ZINT_WARN_NONCOMPLIANT, 2, 113, 12, "Warning 478: Input length 10 is not standard (11 or 13)", 0, "BWIPP requires standard lengths" }, | |
| 270 /* 35*/ { BARCODE_PLANET, -1, 0, "123456789012", ZINT_WARN_NONCOMPLIANT, 2, 133, 12, "Warning 478: Input length 12 is not standard (11 or 13)", 0, "BWIPP requires standard lengths" }, | |
| 271 /* 36*/ { BARCODE_PLANET, -1, 0, "12345678901234", ZINT_WARN_NONCOMPLIANT, 2, 153, 12, "Warning 478: Input length 14 is not standard (11 or 13)", 0, "BWIPP requires standard lengths" }, | |
| 272 /* 37*/ { BARCODE_PLANET, -1, 0, "1234567890A", ZINT_ERROR_INVALID_DATA, -1, -1, -1, "Error 483: Invalid character at position 11 in input (digits only)", 1, "" }, | |
| 273 /* 38*/ { BARCODE_KIX, -1, 0, "0123456789ABCDEFGH", 0, 3, 143, 8, "", 1, "" }, | |
| 274 /* 39*/ { BARCODE_KIX, -1, 0, "a", 0, 3, 7, 8, "", 1, "" }, /* Converts to upper */ | |
| 275 /* 40*/ { BARCODE_KIX, -1, 0, ",", ZINT_ERROR_INVALID_DATA, -1, -1, -1, "Error 491: Invalid character at position 1 in input (alphanumerics only)", 1, "" }, | |
| 276 /* 41*/ { BARCODE_DAFT, -1, 0, "DAFT", 0, 3, 7, 8, "", 1, "" }, | |
| 277 /* 42*/ { BARCODE_DAFT, -1, 0, "a", 0, 3, 1, 8, "", 1, "" }, /* Converts to upper */ | |
| 278 /* 43*/ { BARCODE_DAFT, -1, 0, "B", ZINT_ERROR_INVALID_DATA, -1, -1, -1, "Error 493: Invalid character at position 1 in input (\"D\", \"A\", \"F\" and \"T\" only)", 1, "" }, | |
| 279 /* 44*/ { BARCODE_DAFT, -1, 1.9, "DAFT", 0, 3, 7, 2, "", 1, "" }, | |
| 280 /* 45*/ { BARCODE_DAFT, 500, 0.9, "DAFT", 0, 3, 7, 2, "", 1, "" }, /* 50% ratio */ | |
| 281 /* 46*/ { BARCODE_DAFT, 500, 0.4, "DAFT", 0, 3, 7, 8, "", 1, "" }, /* 50% ratio */ | |
| 282 }; | |
| 283 const int data_size = ARRAY_SIZE(data); | |
| 284 int i, length, ret; | |
| 285 struct zint_symbol *symbol = NULL; | |
| 286 | |
| 287 char cmp_buf[8192]; | |
| 288 char cmp_msg[1024]; | |
| 289 | |
| 290 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */ | |
| 291 | |
| 292 testStartSymbol("test_input", &symbol); | |
| 293 | |
| 294 for (i = 0; i < data_size; i++) { | |
| 295 | |
| 296 if (testContinue(p_ctx, i)) continue; | |
| 297 | |
| 298 symbol = ZBarcode_Create(); | |
| 299 assert_nonnull(symbol, "Symbol not created\n"); | |
| 300 | |
| 301 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); | |
| 302 if (data[i].height) { | |
| 303 symbol->height = data[i].height; | |
| 304 } | |
| 305 | |
| 306 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 307 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 308 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt); | |
| 309 | |
| 310 if (ret < ZINT_ERROR) { | |
| 311 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); | |
| 312 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); | |
| 313 assert_equal(symbol->height, data[i].expected_height, "i:%d symbol->height %g != %g\n", i, symbol->height, data[i].expected_height); | |
| 314 | |
| 315 if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { | |
| 316 if (!data[i].bwipp_cmp) { | |
| 317 if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment); | |
| 318 } else { | |
| 319 char modules_dump[4096]; | |
| 320 assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i); | |
| 321 ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL); | |
| 322 assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 323 | |
| 324 ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump); | |
| 325 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", | |
| 326 i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, modules_dump); | |
| 327 } | |
| 328 } | |
| 329 } | |
| 330 | |
| 331 ZBarcode_Delete(symbol); | |
| 332 } | |
| 333 | |
| 334 testFinish(); | |
| 335 } | |
| 336 | |
| 337 static void test_encode(const testCtx *const p_ctx) { | |
| 338 int debug = p_ctx->debug; | |
| 339 | |
| 340 struct item { | |
| 341 int symbology; | |
| 342 char *data; | |
| 343 int ret; | |
| 344 | |
| 345 int expected_rows; | |
| 346 int expected_width; | |
| 347 char *comment; | |
| 348 char *expected; | |
| 349 }; | |
| 350 static const struct item data[] = { | |
| 351 /* 0*/ { BARCODE_FLAT, "1304056", 0, 1, 63, "Verified manually against tec-it", | |
| 352 "100000000001000000000000000000100000000000000000010000000001000" | |
| 353 }, | |
| 354 /* 1*/ { BARCODE_POSTNET, "12345678901", 0, 2, 123, "USPS Publication 25 (2003) Exhibit 4-1", | |
| 355 "100000001010000010001000001010000010000010001000100000101000001000000010100000100010001000001010000000000000101000100000101" | |
| 356 "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 357 }, | |
| 358 /* 2*/ { BARCODE_POSTNET, "555551237", 0, 2, 103, "Verified manually against tec-it", | |
| 359 "1000100010000010001000001000100000100010000010001000000000101000001000100000101000100000001000001000101" | |
| 360 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 361 }, | |
| 362 /* 3*/ { BARCODE_FIM, "C", 0, 1, 17, "USPS DMM Exhibit 8.2.0 FIM C", | |
| 363 "10100010001000101" | |
| 364 }, | |
| 365 /* 4*/ { BARCODE_FIM, "E", 0, 1, 17, "", | |
| 366 "10001000000010001" | |
| 367 }, | |
| 368 /* 5*/ { BARCODE_CEPNET, "12345678", 0, 2, 93, "CEPNet e Código Bidimensional Datamatrix 2D (26/05/2021) Figura 8", | |
| 369 "100000001010000010001000001010000010000010001000100000101000001000000010100000100000100000101" | |
| 370 "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 371 }, | |
| 372 /* 6*/ { BARCODE_CEPNET, "36400000", 0, 2, 93, "CEPNet e Código Bidimensional Datamatrix 2D (26/05/2021) Figura 10", | |
| 373 "100000101000001010000000100000101010000000101000000010100000001010000000101000000010000000101" | |
| 374 "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 375 }, | |
| 376 /* 7*/ { BARCODE_RM4SCC, "BX11LT1A", 0, 3, 75, "Verified manually against tec-it", | |
| 377 "100010001010100000000010100000101010000010100010000000101000100010100000101" | |
| 378 "101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 379 "001010000010000010001000100010001010000010101000000010001010001000000010101" | |
| 380 }, | |
| 381 /* 8*/ { BARCODE_RM4SCC, "W1J0TR01", 0, 3, 75, "Verified manually against tec-it", | |
| 382 "101010000000001010100000100000101010001000100010000000101000001010101000001" | |
| 383 "101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 384 "000010100000100010001000100000101010100000100000100000101000100010001010001" | |
| 385 }, | |
| 386 /* 9*/ { BARCODE_RM4SCC, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, 3, 299, "Verified manually against tec-it", | |
| 387 "10000010100000101000001010000010100000101000001010001000100010001000100010001000100010001000100010001010000010100000101000001010000010100000101000100000101000001010000010100000101000001010000010100010001000100010001000100010001000100010001000101000001010000010100000101000001010000010100000101000001" | |
| 388 "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 389 "00000010100010001000101000100000101000100010100000000010100010001000101000100000101000100010100000000010100010001000101000100000101000100010100000000010100010001000101000100000101000100010100000000010100010001000101000100000101000100010100000000010100010001000101000100000101000100010100000101000001" | |
| 390 }, | |
| 391 /* 10*/ { BARCODE_JAPANPOST, "15400233-16-4-205", 0, 3, 133, "Zip/Barcode Manual p.6 1st example; verified manually against tec-it", | |
| 392 "1000101000100010101000100000100000100010001010001010001000101000001010001000101000001000100010100000100010000010000010000010001010001" | |
| 393 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 394 "1010101000100010100010100000100000101000101000101000001000101000100010001000100010001000101000100000100010001000001000001000100010101" | |
| 395 }, | |
| 396 /* 11*/ { BARCODE_JAPANPOST, "350110622-1A308", 0, 3, 133, "Zip/Barcode Manual p.6 2nd example; verified manually against tec-it", | |
| 397 "1000001010100010100000101000101000100000001010100010100010001000101000001000100000001010100000100010000010000010000010000010100010001" | |
| 398 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 399 "1010101000100010100000101000101000100000100010101000101000001000101000100000100000101000100000001010001000001000001000001000100010101" | |
| 400 }, | |
| 401 /* 12*/ { BARCODE_JAPANPOST, "12345671-2-3", 0, 3, 133, "Verified manually against tec-it", | |
| 402 "1000101000100010001010101000100010001010101000101000001000100010001000001010000010000010000010000010000010000010000010000010100010001" | |
| 403 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 404 "1010101000101000101000100010100010100010001010101000001000101000001000101000001000001000001000001000001000001000001000001000100010101" | |
| 405 }, | |
| 406 /* 13*/ { BARCODE_JAPANPOST, "1234567BCDEFG", 0, 3, 133, "Verified manually against tec-it", | |
| 407 "1000101000100010001010101000100010001010101000001000101000001000100010001000001010001000101000001000100010001000001010000010101000001" | |
| 408 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 409 "1010101000101000101000100010100010100010001010100000101000100000101000100000101000100000100010100000100010100000100010001000100010101" | |
| 410 }, | |
| 411 /* 14*/ { BARCODE_JAPANPOST, "8901234HIJKLM", 0, 3, 133, "Verified manually against tec-it", | |
| 412 "1000100010001010100000101000100010001010101000001000101000001000100010001000001010000010100000000010101000000010100010000010100000001" | |
| 413 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 414 "1010001010001010100000101000101000101000100010100000001010100000001010100000001010100000100000100000101000100000101000001000000010101" | |
| 415 }, | |
| 416 /* 15*/ { BARCODE_JAPANPOST, "0987654NOPQRS", 0, 3, 133, "Verified manually against tec-it", | |
| 417 "1000100000001010100010101000001010100010101000000010001010000010101000000010100010000010001010000010101000000010100010000010100000001" | |
| 418 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 419 "1010100000001010001010001010100010100010100010100000101000100000100010100000100010100000100010100000001010100000001010001000001000101" | |
| 420 }, | |
| 421 /* 16*/ { BARCODE_JAPANPOST, "3210987TUVWXY", 0, 3, 133, "Verified manually against tec-it", | |
| 422 "1000001010100010101000100000001010100010101000000010001010100000100000100000101000100000100010100000001010100000101000000010000010001" | |
| 423 "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 424 "1010101000101000101000100000001010001010001010100000001010001000100000001000101000001000101000001000101000001000100010001000100000101" | |
| 425 }, | |
| 426 /* 17*/ { BARCODE_KOREAPOST, "010230", 0, 1, 167, "Verified manually against tec-it", | |
| 427 "10001000100000000000100010000000000010001000100000001000000010001000100010001000100000000000100000000001000100010001000100010001000000000001000000010001000000010001000" | |
| 428 }, | |
| 429 /* 18*/ { BARCODE_KOREAPOST, "923457", 0, 1, 168, "Verified manually against tec-it", | |
| 430 "000010001000100000001000100000001000000010001000000010001000000010001000100000000000100010001000000010000000100010001000100010000000100000001000100010001000000000001000" | |
| 431 }, | |
| 432 /* 19*/ { BARCODE_PLANET, "4012345235636", 0, 2, 143, "USPS Publication 197 (2004) Exhibit 4; verified manually against tec-it", | |
| 433 "10100010100000001010101010100000101000100010100000101000101000100010001010100010001010000010100010001010000010101010000010100000101010000010101" | |
| 434 "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 435 }, | |
| 436 /* 20*/ { BARCODE_PLANET, "40123452356", 0, 2, 123, "Verified manually against tec-it", | |
| 437 "101000101000000010101010101000001010001000101000001010001010001000100010101000100010100000101000100010100000101010001000101" | |
| 438 "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 439 }, | |
| 440 /* 21*/ { BARCODE_PLANET, "5020140235635", 0, 2, 143, "USPS Publication 197 (2004) Exhibit 6; verified manually against tec-it", | |
| 441 "10100010001000001010101010001000000010101010101000001000101000000010101010100010001010000010100010001010000010101010000010100010001010001010001" | |
| 442 "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 443 }, | |
| 444 /* 22*/ { BARCODE_KIX, "2500GG30250", 0, 3, 87, "PostNL Handleiding KIX code Section 2.1 Example 1", | |
| 445 "000010100000101000001010000010100010100000101000000010100000101000001010000010100000101" | |
| 446 "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 447 "001010001010000000001010000010101000100010001000100000100000101000101000101000000000101" | |
| 448 }, | |
| 449 /* 23*/ { BARCODE_KIX, "2130VA80430", 0, 3, 87, "PostNL Handleiding KIX code Section 2.1 Example 2", | |
| 450 "000010100000101000001010000010101010000000100010001000100000101000001010000010100000101" | |
| 451 "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 452 "001010000010001010000010000010100010001010001000001010000000101010001000100000100000101" | |
| 453 }, | |
| 454 /* 24*/ { BARCODE_KIX, "1231GF156X2", 0, 3, 87, "PostNL Handleiding KIX code Section 2.1 Example 3", | |
| 455 "000010100000101000001010000010100010100000101000000010100000101000100010101000000000101" | |
| 456 "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 457 "001000100010100010000010001000101000100010000010001000101010000000001010100000100010100" | |
| 458 }, | |
| 459 /* 25*/ { BARCODE_KIX, "1231FZ13Xhs", 0, 3, 87, "PostNL Handleiding KIX code Section 2.1 Example 4", | |
| 460 "000010100000101000001010000010100010100010100000000010100000101010100000001010001000100" | |
| 461 "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 462 "001000100010100010000010001000101000001010100000001000101000001010000010101000001000100" | |
| 463 }, | |
| 464 /* 26*/ { BARCODE_KIX, "1234567890ABCDEFGH", 0, 3, 143, "Verified manually against tec-it", | |
| 465 "00001010000010100000101000001010000010100010001000100010001000100010001000001010001000100010001000101000001010000010100000101000001010000010100" | |
| 466 "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 467 "00100010001010001000001010001000101000000000101000100010001010001000001000001010100010001010000000001010001000100010100010000010100010001010000" | |
| 468 }, | |
| 469 /* 27*/ { BARCODE_KIX, "IJKLMNOPQRSTUVWXYZ", 0, 3, 143, "Verified manually against tec-it", | |
| 470 "10000010100000101000001010000010100000101000001010001000100010001000100010001000100010001000100010100000101000001010000010100000101000001010000" | |
| 471 "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" | |
| 472 "00001010001000100010100010000010100010001010000000001010001000100010100010000010100010001010000000001010001000100010100010000010100010001010000" | |
| 473 }, | |
| 474 /* 28*/ { BARCODE_DAFT, "DAFTTFADFATDTATFT", 0, 3, 33, "Verified manually against tec-it", | |
| 475 "001010000010100010100000001000100" | |
| 476 "101010101010101010101010101010101" | |
| 477 "100010000010001010000010000000100" | |
| 478 }, | |
| 479 }; | |
| 480 const int data_size = ARRAY_SIZE(data); | |
| 481 int i, length, ret; | |
| 482 struct zint_symbol *symbol = NULL; | |
| 483 | |
| 484 char escaped[1024]; | |
| 485 char bwipp_buf[8192]; | |
| 486 char bwipp_msg[1024]; | |
| 487 | |
| 488 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */ | |
| 489 | |
| 490 testStartSymbol("test_encode", &symbol); | |
| 491 | |
| 492 for (i = 0; i < data_size; i++) { | |
| 493 | |
| 494 if (testContinue(p_ctx, i)) continue; | |
| 495 | |
| 496 symbol = ZBarcode_Create(); | |
| 497 assert_nonnull(symbol, "Symbol not created\n"); | |
| 498 | |
| 499 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 500 | |
| 501 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 502 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 503 | |
| 504 if (p_ctx->generate) { | |
| 505 printf(" /*%3d*/ { %s, \"%s\", %s, %d, %d, \"%s\",\n", | |
| 506 i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), | |
| 507 testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); | |
| 508 testUtilModulesPrint(symbol, " ", "\n"); | |
| 509 printf(" },\n"); | |
| 510 } else { | |
| 511 if (ret < ZINT_ERROR) { | |
| 512 int width, row; | |
| 513 | |
| 514 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); | |
| 515 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); | |
| 516 | |
| 517 ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); | |
| 518 assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data); | |
| 519 | |
| 520 if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { | |
| 521 ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf), NULL); | |
| 522 assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 523 | |
| 524 ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected); | |
| 525 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", | |
| 526 i, testUtilBarcodeName(symbol->symbology), ret, bwipp_msg, bwipp_buf, data[i].expected); | |
| 527 } | |
| 528 } | |
| 529 } | |
| 530 | |
| 531 ZBarcode_Delete(symbol); | |
| 532 } | |
| 533 | |
| 534 testFinish(); | |
| 535 } | |
| 536 | |
| 537 #include <time.h> | |
| 538 | |
| 539 #define TEST_PERF_ITER_MILLES 10 | |
| 540 #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000) | |
| 541 #define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC) | |
| 542 | |
| 543 /* Not a real test, just performance indicator */ | |
| 544 static void test_perf(const testCtx *const p_ctx) { | |
| 545 int debug = p_ctx->debug; | |
| 546 | |
| 547 struct item { | |
| 548 int symbology; | |
| 549 int option_2; | |
| 550 char *data; | |
| 551 int ret; | |
| 552 | |
| 553 int expected_rows; | |
| 554 int expected_width; | |
| 555 char *comment; | |
| 556 }; | |
| 557 static const struct item data[] = { | |
| 558 /* 0*/ { BARCODE_POSTNET, -1, "12345678901", 0, 2, 123, "POSTNET 11" }, | |
| 559 /* 1*/ { BARCODE_PLANET, -1, "1234567890123", 0, 2, 143, "PLANET 13" }, | |
| 560 /* 2*/ { BARCODE_KOREAPOST, -1, "123456", 0, 1, 167, "KOREAPOST 6" }, | |
| 561 }; | |
| 562 const int data_size = ARRAY_SIZE(data); | |
| 563 int i, length, ret; | |
| 564 struct zint_symbol *symbol; | |
| 565 | |
| 566 clock_t start; | |
| 567 clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0; | |
| 568 clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print; | |
| 569 int comment_max = 0; | |
| 570 | |
| 571 if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ | |
| 572 return; | |
| 573 } | |
| 574 | |
| 575 for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment); | |
| 576 | |
| 577 printf("Iterations %d\n", TEST_PERF_ITERATIONS); | |
| 578 | |
| 579 for (i = 0; i < data_size; i++) { | |
| 580 int j; | |
| 581 | |
| 582 if (testContinue(p_ctx, i)) continue; | |
| 583 | |
| 584 diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0; | |
| 585 | |
| 586 for (j = 0; j < TEST_PERF_ITERATIONS; j++) { | |
| 587 start = clock(); | |
| 588 symbol = ZBarcode_Create(); | |
| 589 diff_create += clock() - start; | |
| 590 assert_nonnull(symbol, "Symbol not created\n"); | |
| 591 | |
| 592 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); | |
| 593 | |
| 594 start = clock(); | |
| 595 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 596 diff_encode += clock() - start; | |
| 597 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 598 | |
| 599 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); | |
| 600 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); | |
| 601 | |
| 602 start = clock(); | |
| 603 ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/); | |
| 604 diff_buffer += clock() - start; | |
| 605 assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt); | |
| 606 | |
| 607 symbol->output_options |= OUT_BUFFER_INTERMEDIATE; | |
| 608 start = clock(); | |
| 609 ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/); | |
| 610 diff_buf_inter += clock() - start; | |
| 611 assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt); | |
| 612 symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */ | |
| 613 | |
| 614 start = clock(); | |
| 615 ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/); | |
| 616 diff_print += clock() - start; | |
| 617 assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt); | |
| 618 assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile); | |
| 619 | |
| 620 ZBarcode_Delete(symbol); | |
| 621 } | |
| 622 | |
| 623 printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment, | |
| 624 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)); | |
| 625 | |
| 626 total_create += diff_create; | |
| 627 total_encode += diff_encode; | |
| 628 total_buffer += diff_buffer; | |
| 629 total_buf_inter += diff_buf_inter; | |
| 630 total_print += diff_print; | |
| 631 } | |
| 632 if (p_ctx->index == -1) { | |
| 633 printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals", | |
| 634 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)); | |
| 635 } | |
| 636 } | |
| 637 | |
| 638 int main(int argc, char *argv[]) { | |
| 639 | |
| 640 testFunction funcs[] = { /* name, func */ | |
| 641 { "test_large", test_large }, | |
| 642 { "test_koreapost", test_koreapost }, | |
| 643 { "test_japanpost", test_japanpost }, | |
| 644 { "test_input", test_input }, | |
| 645 { "test_encode", test_encode }, | |
| 646 { "test_perf", test_perf }, | |
| 647 }; | |
| 648 | |
| 649 testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); | |
| 650 | |
| 651 testReport(); | |
| 652 | |
| 653 return 0; | |
| 654 } | |
| 655 | |
| 656 /* vim: set ts=4 sw=4 et : */ |
