Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tests/test_ultra.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 option_1; | |
| 39 int option_3; | |
| 40 struct zint_structapp structapp; | |
| 41 char *pattern; | |
| 42 int length; | |
| 43 int ret; | |
| 44 int expected_rows; | |
| 45 int expected_width; | |
| 46 char *expected_errtxt; | |
| 47 }; | |
| 48 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 49 static const struct item data[] = { | |
| 50 /* 0*/ { -1, -1, { 0, 0, "" }, "1", 252, 0, 31, 66, "" }, /* Default EC2 */ | |
| 51 /* 1*/ { -1, -1, { 0, 0, "" }, "1", 253, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC2, requires 256 codewords (maximum 255)" }, | |
| 52 /* 2*/ { -1, -1, { 0, 0, "" }, "1", ZINT_MAX_DATA_LEN, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC2, requires 17403 codewords (maximum 255)" }, | |
| 53 /* 3*/ { -1, -1, { 1, 2, "" }, "1", 251, 0, 31, 66, "" }, /* Structured Append no File Number 1 codeword overhead */ | |
| 54 /* 4*/ { -1, -1, { 1, 2, "" }, "1", 252, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC2, requires 256 codewords (maximum 255)" }, | |
| 55 /* 5*/ { -1, -1, { 1, 2, "1" }, "1", 249, 0, 31, 66, "" }, /* Structured Append with File Number 3 codewords overhead */ | |
| 56 /* 6*/ { -1, -1, { 1, 2, "1" }, "1", 250, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC2, requires 256 codewords (maximum 255)" }, | |
| 57 /* 7*/ { -1, -1, { 0, 0, "" }, "A", 252, 0, 31, 66, "" }, | |
| 58 /* 8*/ { -1, -1, { 0, 0, "" }, "A", 253, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC2, requires 256 codewords (maximum 255)" }, | |
| 59 /* 9*/ { -1, -1, { 0, 0, "" }, "\200", 252, 0, 31, 66, "" }, | |
| 60 /* 10*/ { -1, -1, { 0, 0, "" }, "\200", 253, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC2, requires 256 codewords (maximum 255)" }, | |
| 61 /* 11*/ { -1, -1, { 0, 0, "" }, "\001", 252, 0, 31, 66, "" }, | |
| 62 /* 12*/ { -1, -1, { 0, 0, "" }, "\001", 253, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC2, requires 256 codewords (maximum 255)" }, | |
| 63 /* 13*/ { -1, ULTRA_COMPRESSION, { 0, 0, "" }, "1", 504, 0, 31, 66, "" }, | |
| 64 /* 14*/ { -1, ULTRA_COMPRESSION, { 0, 0, "" }, "1", 505, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC2, requires 256 codewords (maximum 255)" }, | |
| 65 /* 15*/ { -1, ULTRA_COMPRESSION, { 0, 0, "" }, "A", 375, 0, 31, 66, "" }, | |
| 66 /* 16*/ { -1, ULTRA_COMPRESSION, { 0, 0, "" }, "A", 376, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC2, requires 256 codewords (maximum 255)" }, | |
| 67 /* 17*/ { -1, ULTRA_COMPRESSION, { 0, 0, "" }, "\200", 252, 0, 31, 66, "" }, | |
| 68 /* 18*/ { -1, ULTRA_COMPRESSION, { 0, 0, "" }, "\200", 253, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC2, requires 256 codewords (maximum 255)" }, | |
| 69 /* 19*/ { -1, ULTRA_COMPRESSION, { 0, 0, "" }, "\001", 252, 0, 31, 66, "" }, | |
| 70 /* 20*/ { -1, ULTRA_COMPRESSION, { 0, 0, "" }, "\001", 253, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC2, requires 256 codewords (maximum 255)" }, | |
| 71 /* 21*/ { 1, -1, { 0, 0, "" }, "1", 276, 0, 31, 66, "" }, | |
| 72 /* 22*/ { 1, -1, { 0, 0, "" }, "1", 277, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC0, requires 280 codewords (maximum 279)" }, | |
| 73 /* 23*/ { 1, -1, { 1, 2, "" }, "1", 275, 0, 31, 66, "" }, | |
| 74 /* 24*/ { 1, -1, { 1, 2, "" }, "1", 276, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC0, requires 280 codewords (maximum 279)" }, | |
| 75 /* 25*/ { 1, -1, { 1, 2, "1" }, "1", 273, 0, 31, 66, "" }, | |
| 76 /* 26*/ { 1, -1, { 1, 2, "1" }, "1", 274, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC0, requires 280 codewords (maximum 279)" }, | |
| 77 /* 27*/ { 2, -1, { 0, 0, "" }, "1", 263, 0, 31, 66, "" }, | |
| 78 /* 28*/ { 2, -1, { 0, 0, "" }, "1", 264, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC1, requires 267 codewords (maximum 266)" }, | |
| 79 /* 29*/ { 3, -1, { 0, 0, "" }, "1", 252, 0, 31, 66, "" }, | |
| 80 /* 30*/ { 3, -1, { 0, 0, "" }, "1", 253, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC2, requires 256 codewords (maximum 255)" }, | |
| 81 /* 31*/ { 4, -1, { 0, 0, "" }, "1", 234, 0, 31, 66, "" }, | |
| 82 /* 32*/ { 4, -1, { 0, 0, "" }, "1", 235, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC3, requires 238 codewords (maximum 237)" }, | |
| 83 /* 33*/ { 5, -1, { 0, 0, "" }, "1", 220, 0, 31, 66, "" }, | |
| 84 /* 34*/ { 5, -1, { 0, 0, "" }, "1", 221, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC4, requires 224 codewords (maximum 223)" }, | |
| 85 /* 35*/ { 6, -1, { 0, 0, "" }, "1", 202, 0, 31, 66, "" }, | |
| 86 /* 36*/ { 6, -1, { 0, 0, "" }, "1", 203, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC5, requires 206 codewords (maximum 205)" }, | |
| 87 /* 37*/ { 6, -1, { 0, 0, "" }, "A", ZINT_MAX_DATA_LEN / 2, ZINT_ERROR_TOO_LONG, -1, -1, "Error 591: Input too long for ECC level EC5, requires 8703 codewords (maximum 205)" }, | |
| 88 }; | |
| 89 const int data_size = ARRAY_SIZE(data); | |
| 90 int i, length, ret; | |
| 91 struct zint_symbol *symbol = NULL; | |
| 92 | |
| 93 char data_buf[ZINT_MAX_DATA_LEN + 1]; | |
| 94 | |
| 95 testStartSymbol("test_large", &symbol); | |
| 96 | |
| 97 for (i = 0; i < data_size; i++) { | |
| 98 | |
| 99 if (testContinue(p_ctx, i)) continue; | |
| 100 | |
| 101 symbol = ZBarcode_Create(); | |
| 102 assert_nonnull(symbol, "Symbol not created\n"); | |
| 103 | |
| 104 testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); | |
| 105 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)); | |
| 106 | |
| 107 length = testUtilSetSymbol(symbol, BARCODE_ULTRA, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, data[i].option_3, -1 /*output_options*/, data_buf, data[i].length, debug); | |
| 108 if (data[i].structapp.count) { | |
| 109 symbol->structapp = data[i].structapp; | |
| 110 } | |
| 111 | |
| 112 ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); | |
| 113 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 114 assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt); | |
| 115 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt); | |
| 116 | |
| 117 if (ret < ZINT_ERROR) { | |
| 118 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); | |
| 119 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); | |
| 120 } | |
| 121 | |
| 122 ZBarcode_Delete(symbol); | |
| 123 } | |
| 124 | |
| 125 testFinish(); | |
| 126 } | |
| 127 | |
| 128 static void test_reader_init(const testCtx *const p_ctx) { | |
| 129 int debug = p_ctx->debug; | |
| 130 | |
| 131 struct item { | |
| 132 int input_mode; | |
| 133 int output_options; | |
| 134 int option_3; | |
| 135 char *data; | |
| 136 int ret; | |
| 137 int expected_rows; | |
| 138 int expected_width; | |
| 139 char *expected; | |
| 140 char *comment; | |
| 141 }; | |
| 142 static const struct item data[] = { | |
| 143 /* 0*/ { UNICODE_MODE, READER_INIT, 0, "A", 0, 13, 14, "(3) 257 269 65", "8-bit FNC3 A" }, | |
| 144 /* 1*/ { UNICODE_MODE, READER_INIT, ULTRA_COMPRESSION, "A", 0, 13, 14, "(3) 272 271 65", "ASCII FNC3 A Note: draft spec inconsistent and FNC3 may be 272 in ASCII mode (and FNC1 271)" }, | |
| 145 }; | |
| 146 const int data_size = ARRAY_SIZE(data); | |
| 147 int i, length, ret; | |
| 148 struct zint_symbol *symbol = NULL; | |
| 149 | |
| 150 char escaped[1024]; | |
| 151 | |
| 152 testStartSymbol("test_reader_init", &symbol); | |
| 153 | |
| 154 for (i = 0; i < data_size; i++) { | |
| 155 | |
| 156 if (testContinue(p_ctx, i)) continue; | |
| 157 | |
| 158 symbol = ZBarcode_Create(); | |
| 159 assert_nonnull(symbol, "Symbol not created\n"); | |
| 160 | |
| 161 symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */ | |
| 162 | |
| 163 length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, data[i].option_3, data[i].output_options, data[i].data, -1, debug); | |
| 164 | |
| 165 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 166 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 167 | |
| 168 if (p_ctx->generate) { | |
| 169 printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n", | |
| 170 i, testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), | |
| 171 testUtilOption3Name(BARCODE_ULTRA, data[i].option_3), | |
| 172 testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), | |
| 173 testUtilErrorName(data[i].ret), symbol->rows, symbol->width, symbol->errtxt, data[i].comment); | |
| 174 } else { | |
| 175 if (ret < ZINT_ERROR) { | |
| 176 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); | |
| 177 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); | |
| 178 } | |
| 179 assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected); | |
| 180 } | |
| 181 | |
| 182 ZBarcode_Delete(symbol); | |
| 183 } | |
| 184 | |
| 185 testFinish(); | |
| 186 } | |
| 187 | |
| 188 static void test_input(const testCtx *const p_ctx) { | |
| 189 int debug = p_ctx->debug; | |
| 190 | |
| 191 struct item { | |
| 192 int input_mode; | |
| 193 int eci; | |
| 194 int option_1; | |
| 195 int option_2; | |
| 196 int option_3; | |
| 197 struct zint_structapp structapp; | |
| 198 char *data; | |
| 199 int ret; | |
| 200 char *expected; | |
| 201 char *comment; | |
| 202 }; | |
| 203 static const struct item data[] = { | |
| 204 /* 0*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "A", 0, "(2) 257 65", "Default (Revision 1)" }, | |
| 205 /* 1*/ { UNICODE_MODE, 0, -1, 1, -1, { 0, 0, "" }, "A", 0, "(2) 257 65", "Revision 1" }, | |
| 206 /* 2*/ { UNICODE_MODE, 0, -1, 2, -1, { 0, 0, "" }, "A", 0, "(2) 257 65", "Revision 2 (no codeword changes)" }, | |
| 207 /* 3*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "A", 0, "(2) 272 65", "" }, | |
| 208 /* 4*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "12", 0, "(3) 257 49 50", "" }, | |
| 209 /* 5*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "12", 0, "(2) 272 140", "" }, | |
| 210 /* 6*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "123", 0, "(4) 257 49 50 51", "" }, | |
| 211 /* 7*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "123", 0, "(3) 272 140 51", "" }, | |
| 212 /* 8*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "ABC", 0, "(4) 257 65 66 67", "" }, | |
| 213 /* 9*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "ABC", 0, "(4) 272 65 66 67", "" }, | |
| 214 /* 10*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "ULTRACODE_123456789!", 0, "(17) 272 85 76 84 82 65 67 79 68 69 95 140 162 184 206 57 33", "" }, | |
| 215 /* 11*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, "(253) 257 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65", "252 chars EC2" }, | |
| 216 /* 12*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", ZINT_ERROR_TOO_LONG, "Error 591: Input too long for ECC level EC2, requires 256 codewords (maximum 255)", "253 chars EC2" }, | |
| 217 /* 13*/ { UNICODE_MODE, 0, 1, -1, -1, { 0, 0, "" }, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, "(277) 257 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65", "276 chars EC0" }, | |
| 218 /* 14*/ { UNICODE_MODE, 0, 1, -1, -1, { 0, 0, "" }, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", ZINT_ERROR_TOO_LONG, "Error 591: Input too long for ECC level EC0, requires 280 codewords (maximum 279)", "277 chars EC0" }, | |
| 219 /* 15*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "é", 0, "(2) 257 233", "" }, | |
| 220 /* 16*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "β", ZINT_WARN_USES_ECI, "Warning (2) 263 226", "" }, | |
| 221 /* 17*/ { UNICODE_MODE, 9, -1, -1, -1, { 0, 0, "" }, "β", 0, "(2) 263 226", "" }, | |
| 222 /* 18*/ { UNICODE_MODE, 9, -1, -1, -1, { 0, 0, "" }, "βAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, "(253) 263 226 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65", "249 chars EC2" }, | |
| 223 /* 19*/ { UNICODE_MODE, 9, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "A", 0, "(2) 263 65", "Note previously ECI ignored and not outputted if ULTRA_COMPRESSION and all ASCII" }, | |
| 224 /* 20*/ { UNICODE_MODE, 15, -1, -1, -1, { 0, 0, "" }, "Ŗ", 0, "(2) 268 170", "" }, | |
| 225 /* 21*/ { DATA_MODE, 898, -1, -1, -1, { 0, 0, "" }, "\001\002\003\004\377", 0, "(7) 278 130 1 2 3 4 255", "" }, | |
| 226 /* 22*/ { DATA_MODE, 899, -1, -1, -1, { 0, 0, "" }, "\001\002\003\004\377", 0, "(6) 280 1 2 3 4 255", "" }, | |
| 227 /* 23*/ { DATA_MODE, 900, -1, -1, -1, { 0, 0, "" }, "\001\002\003\004\377", 0, "(9) 257 274 137 128 1 2 3 4 255", "" }, | |
| 228 /* 24*/ { DATA_MODE, 9999, -1, -1, -1, { 0, 0, "" }, "\001\002\003\004\377", 0, "(9) 257 274 227 227 1 2 3 4 255", "" }, | |
| 229 /* 25*/ { DATA_MODE, 10000, -1, -1, -1, { 0, 0, "" }, "\001\002\003\004\377", 0, "(10) 257 275 129 128 128 1 2 3 4 255", "" }, | |
| 230 /* 26*/ { DATA_MODE, 811799, -1, -1, -1, { 0, 0, "" }, "\001\002\003\004\377", 0, "(10) 257 275 209 145 227 1 2 3 4 255", "" }, | |
| 231 /* 27*/ { DATA_MODE, 811800, -1, -1, -1, { 0, 0, "" }, "\001\002\003\004\377", ZINT_ERROR_INVALID_OPTION, "Error 590: ECI code '811800' out of range (0 to 811799)", "" }, | |
| 232 /* 28*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "123,456,789/12,/3,4,/5//", 0, "(15) 272 140 231 173 234 206 257 140 44 262 242 44 264 47 47", "Mode: a (24)" }, | |
| 233 /* 29*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "HEIMASÍÐA KENNARAHÁSKÓLA ÍSLANDS", 0, "(32) 257 256 46 151 78 210 205 208 258 5 148 28 72 2 167 52 127 193 83 75 211 267 76 65 32", "Mode: cccccc88cccccccccc8888aaa8cccccc (32)" }, | |
| 234 /* 30*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "HEIMASÍÐA KENNARAHÁSKÓLA ÍSLANDS", 0, "(33) 257 72 69 73 77 65 83 205 208 65 32 75 69 78 78 65 82 65 72 193 83 75 211 76 65 32 205", "" }, | |
| 235 /* 31*/ { UNICODE_MODE, 10, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "אולטרה-קוד1234", 0, "(14) 264 224 229 236 232 248 228 45 247 229 227 267 140 162", "Mode: 8888888888aaaa (14); Figure G.3" }, | |
| 236 /* 32*/ { UNICODE_MODE, 10, -1, -1, -1, { 0, 0, "" }, "אולטרה-קוד1234", 0, "(15) 264 224 229 236 232 248 228 45 247 229 227 49 50 51 52", "" }, | |
| 237 /* 33*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "https://aimglobal.org/jcrv3tX", 0, "(16) 282 266 1 74 41 19 6 168 270 212 59 106 144 56 265 70", "Mode: c (21); Figure G.4a" }, | |
| 238 /* 34*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "https://aimglobal.org/jcrv3tX", 0, "(22) 282 97 105 109 103 108 111 98 97 108 46 111 114 103 47 106 99 114 118 51 116 88", "" }, | |
| 239 /* 35*/ { GS1_MODE, 0, -1, -1, -1, { 0, 0, "" }, "[01]03453120000011[17]121125[10]ABCD1234", 0, "(20) 273 129 131 173 159 148 128 128 139 145 140 139 153 138 65 66 67 68 140 162", "Mode: a (34); Figure G.6 uses C43 for 6 of last 7 chars (same codeword count)" }, | |
| 240 /* 36*/ { GS1_MODE, 0, -1, -1, -1, { 0, 0, "" }, "[17]120508[10]ABCD1234[410]9501101020917", 0, "(21) 273 145 140 133 136 138 65 66 67 68 140 162 272 169 137 178 139 129 130 137 145", "Mode: a (35)" }, | |
| 241 /* 37*/ { GS1_MODE, 0, -1, -1, -1, { 0, 0, "" }, "[17]120508[10]ABCDEFGHI[410]9501101020917", 0, "(24) 273 145 140 133 136 138 65 66 67 68 69 70 71 72 73 272 169 137 178 139 129 130 137 145", "Mode: a (36)" }, | |
| 242 /* 38*/ { GS1_MODE | GS1PARENS_MODE, 0, -1, -1, -1, { 0, 0, "" }, "(17)120508(10)ABCDEFGHI(410)9501101020917", 0, "(24) 273 145 140 133 136 138 65 66 67 68 69 70 71 72 73 272 169 137 178 139 129 130 137 145", "Mode: a (36)" }, | |
| 243 /* 39*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "ftp://", 0, "(4) 272 278 269 165", "Mode: c (6)" }, | |
| 244 /* 40*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, ".cgi", 0, "(4) 272 278 274 131", "Mode: c (4)" }, | |
| 245 /* 41*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "ftp://a.cgi", 0, "(6) 272 280 269 123 274 131", "Mode: c (11)" }, | |
| 246 /* 42*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "e: file:f.shtml !", 0, "(12) 272 280 30 94 236 235 72 233 39 52 267 250", "Mode: c (17)" }, | |
| 247 /* 43*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "Aaatel:", 0, "(6) 272 280 262 76 6 89", "Mode: c (7)" }, | |
| 248 /* 44*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "Aatel:a", 0, "(6) 272 280 262 76 271 161", "Mode: c (7)" }, | |
| 249 /* 45*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "Atel:aAa", 0, "(8) 272 275 6 89 275 148 0 42", "Mode: c (8)" }, | |
| 250 /* 46*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "tel:AAaa", 0, "(8) 272 275 271 161 6 28 262 118", "Mode: c (8)" }, | |
| 251 /* 47*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "AAaatel:aA", 0, "(10) 272 276 0 42 0 41 118 46 6 156", "Mode: c (10)" }, | |
| 252 /* 48*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "émailto:étel:éfile:éhttp://éhttps://éftp://", 0, "(18) 257 233 276 282 233 277 282 233 278 282 233 279 282 233 280 282 233 281", "Mode: 8ccccccc8cccc8ccccc8ccccccc8cccccccc8cccccc (43)" }, | |
| 253 /* 49*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "éhttp://www.url.com", 0, "(9) 257 233 279 269 186 113 81 45 252", "Mode: 8cccccccccccccccccc (19)" }, | |
| 254 /* 50*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "éhttps://www.url.com", 0, "(9) 257 233 280 269 186 113 81 45 252", "Mode: 8ccccccccccccccccccc (20)" }, | |
| 255 /* 51*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "http://url.com", 0, "(8) 281 117 114 108 46 99 111 109", "Mode: 8888888 (7)" }, | |
| 256 /* 52*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "https://url.com", 0, "(8) 282 117 114 108 46 99 111 109", "Mode: 8888888 (7)" }, | |
| 257 /* 53*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "http://url.com", 0, "(6) 281 262 133 216 269 251", "Mode: ccccccc (7)" }, | |
| 258 /* 54*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "https://url.com", 0, "(6) 282 262 133 216 269 251", "Mode: ccccccc (7)" }, | |
| 259 /* 55*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "{", 0, "(2) 272 123", "Mode: a (1)" }, | |
| 260 /* 56*/ { UNICODE_MODE, 0, -1, -1, -1, { 2, 3, "" }, "A", 0, "(2) 257 65", "" }, | |
| 261 /* 57*/ { UNICODE_MODE, 0, -1, -1, -1, { 1, 1, "" }, "A", ZINT_ERROR_INVALID_OPTION, "Error 596: Structured Append count '1' out of range (2 to 8)", "" }, | |
| 262 /* 58*/ { UNICODE_MODE, 0, -1, -1, -1, { 1, 9, "" }, "A", ZINT_ERROR_INVALID_OPTION, "Error 596: Structured Append count '9' out of range (2 to 8)", "" }, | |
| 263 /* 59*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 3, "" }, "A", ZINT_ERROR_INVALID_OPTION, "Error 597: Structured Append index '0' out of range (1 to count 3)", "" }, | |
| 264 /* 60*/ { UNICODE_MODE, 0, -1, -1, -1, { 4, 3, "" }, "A", ZINT_ERROR_INVALID_OPTION, "Error 597: Structured Append index '4' out of range (1 to count 3)", "" }, | |
| 265 /* 61*/ { UNICODE_MODE, 0, -1, -1, -1, { 8, 8, "0" }, "A", 0, "(2) 257 65", "" }, | |
| 266 /* 62*/ { UNICODE_MODE, 0, -1, -1, -1, { 8, 8, "80088" }, "A", 0, "(2) 257 65", "" }, | |
| 267 /* 63*/ { UNICODE_MODE, 0, -1, -1, -1, { 8, 8, "123456" }, "A", ZINT_ERROR_INVALID_OPTION, "Error 593: Structured Append ID length 6 too long (5 digit maximum)", "" }, | |
| 268 /* 64*/ { UNICODE_MODE, 0, -1, -1, -1, { 8, 8, "A" }, "A", ZINT_ERROR_INVALID_OPTION, "Error 594: Invalid Structured Append ID (digits only)", "" }, | |
| 269 /* 65*/ { UNICODE_MODE, 0, -1, -1, -1, { 8, 8, "80089" }, "A", ZINT_ERROR_INVALID_OPTION, "Error 595: Structured Append ID value '80089' out of range (1 to 80088)", "" }, | |
| 270 /* 66*/ { UNICODE_MODE, 0, -1, 3, -1, { 0, 0, "" }, "A", ZINT_ERROR_INVALID_OPTION, "Error 592: Revision '3' out of range (1 or 2 only)", "" }, | |
| 271 }; | |
| 272 const int data_size = ARRAY_SIZE(data); | |
| 273 int i, length, ret; | |
| 274 struct zint_symbol *symbol = NULL; | |
| 275 | |
| 276 char escaped[1024]; | |
| 277 | |
| 278 testStartSymbol("test_input", &symbol); | |
| 279 | |
| 280 for (i = 0; i < data_size; i++) { | |
| 281 | |
| 282 if (testContinue(p_ctx, i)) continue; | |
| 283 | |
| 284 symbol = ZBarcode_Create(); | |
| 285 assert_nonnull(symbol, "Symbol not created\n"); | |
| 286 | |
| 287 symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */ | |
| 288 | |
| 289 length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, data[i].eci, | |
| 290 data[i].option_1, data[i].option_2, data[i].option_3, | |
| 291 -1 /*output_options*/, data[i].data, -1, debug); | |
| 292 if (data[i].structapp.count) { | |
| 293 symbol->structapp = data[i].structapp; | |
| 294 } | |
| 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 | |
| 299 if (p_ctx->generate) { | |
| 300 printf(" /*%3d*/ { %s, %d, %d, %d, %s, { %d, %d, \"%s\" }, \"%s\", %s, \"%s\", \"%s\" },\n", | |
| 301 i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2, | |
| 302 testUtilOption3Name(BARCODE_ULTRA, data[i].option_3), | |
| 303 data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, | |
| 304 testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment); | |
| 305 } else { | |
| 306 assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected); | |
| 307 } | |
| 308 | |
| 309 ZBarcode_Delete(symbol); | |
| 310 } | |
| 311 | |
| 312 testFinish(); | |
| 313 } | |
| 314 | |
| 315 static void test_encode(const testCtx *const p_ctx) { | |
| 316 int debug = p_ctx->debug; | |
| 317 | |
| 318 struct item { | |
| 319 int input_mode; | |
| 320 int eci; | |
| 321 int option_1; | |
| 322 int option_2; | |
| 323 int option_3; | |
| 324 struct zint_structapp structapp; | |
| 325 char *data; | |
| 326 int ret; | |
| 327 | |
| 328 int expected_rows; | |
| 329 int expected_width; | |
| 330 int bwipp_cmp; | |
| 331 char *comment; | |
| 332 char *expected; | |
| 333 }; | |
| 334 /* Based on AIMD/TSC15032-43 (v 0.99c), with values updated from BWIPP update 2021-07-14 | |
| 335 https://github.com/bwipp/postscriptbarcode/commit/4255810845fa8d45c6192dd30aee1fdad1aaf0cc | |
| 336 */ | |
| 337 static const struct item data[] = { | |
| 338 /* 0*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "ULTRACODE_123456789!", 0, 13, 22, 1, "AIMD/TSC15032-43 Figure G.1 **NOT SAME** different compression", | |
| 339 "7777777777777777777777" | |
| 340 "7857865353533131551857" | |
| 341 "7767853515611616136717" | |
| 342 "7837836661565555363857" | |
| 343 "7717855333616336135717" | |
| 344 "7837836515535515366857" | |
| 345 "7787878787878787878787" | |
| 346 "7867816561133113551817" | |
| 347 "7737835155311665165737" | |
| 348 "7867866561155551653857" | |
| 349 "7737833315616663515717" | |
| 350 "7817851653331136333857" | |
| 351 "7777777777777777777777" | |
| 352 }, | |
| 353 /* 1*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "ULTRACODE_123456789!", 0, 13, 24, 1, "AIMD/TSC15032-43 Figure G.1 **NOT SAME** no compression", | |
| 354 "777777777777777777777777" | |
| 355 "785786533153313111181157" | |
| 356 "776783361661161666676617" | |
| 357 "783786115156555511383357" | |
| 358 "776785556561633656175517" | |
| 359 "783781311653551535581657" | |
| 360 "778787878787878787878787" | |
| 361 "786781656113311311181117" | |
| 362 "775783333531166566676537" | |
| 363 "781786651315555113383357" | |
| 364 "776785515161666351175517" | |
| 365 "781786166533113663683357" | |
| 366 "777777777777777777777777" | |
| 367 }, | |
| 368 /* 2*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "HEIMASÍÐA KENNARAHÁSKÓLA ÍSLANDS", 0, 19, 23, 1, "AIMD/TSC15032-43 Figure G.2 **NOT SAME** different compression", | |
| 369 "77777777777777777777777" | |
| 370 "78878663151561555158557" | |
| 371 "77878315565635366667617" | |
| 372 "78878666656561115538357" | |
| 373 "77578535365656556367117" | |
| 374 "78378153656135163558357" | |
| 375 "77178787878787878787877" | |
| 376 "78678156315513136168357" | |
| 377 "77378533531631615537117" | |
| 378 "78878361155313351368657" | |
| 379 "77678515613665166537117" | |
| 380 "78178651131551335158357" | |
| 381 "77678787878787878787877" | |
| 382 "78378535163551333638617" | |
| 383 "77178111531613611567137" | |
| 384 "78878566665531335618357" | |
| 385 "77878151331365561537137" | |
| 386 "78878333656153153368617" | |
| 387 "77777777777777777777777" | |
| 388 }, | |
| 389 /* 3*/ { DATA_MODE, 0, -1, -1, -1, { 0, 0, "" }, "\110\105\111\115\101\123\315\320\101\040\113\105\116\116\101\122\101\110\301\123\113\323\114\101\040\315\123\114\101\116\104\123", 0, 19, 23, 1, "AIMD/TSC15032-43 Figure G.2 **NOT SAME** no compression", | |
| 390 "77777777777777777777777" | |
| 391 "78878633151153313358137" | |
| 392 "77878315666661161167617" | |
| 393 "78878663155553555538557" | |
| 394 "77578531366336136167367" | |
| 395 "78378155555515653358537" | |
| 396 "77178787878787878787877" | |
| 397 "78678135513311133138357" | |
| 398 "77378513331166611617117" | |
| 399 "78878351153555533558557" | |
| 400 "77678613615636356367117" | |
| 401 "78178156336355515538657" | |
| 402 "77678787878787878787877" | |
| 403 "78378615133513355138117" | |
| 404 "77178136511651166517637" | |
| 405 "78878365635335515358557" | |
| 406 "77878613551651656517637" | |
| 407 "78878361115516163138317" | |
| 408 "77777777777777777777777" | |
| 409 }, | |
| 410 /* 4*/ { UNICODE_MODE, 10, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "אולטרה-קוד1234", 0, 13, 19, 1, "AIMD/TSC15032-43 Figure G.3 Same except DCC correct whereas DCC in Figure G.3 is incorrent", | |
| 411 "7777777777777777777" | |
| 412 "7857865565566616657" | |
| 413 "7737853333613351517" | |
| 414 "7867815155551565167" | |
| 415 "7757853333633356657" | |
| 416 "7837866561515535537" | |
| 417 "7787878787878787877" | |
| 418 "7867813561166666517" | |
| 419 "7737831653311131137" | |
| 420 "7817865336156555357" | |
| 421 "7767816565663636117" | |
| 422 "7817851316355311357" | |
| 423 "7777777777777777777" | |
| 424 }, | |
| 425 /* 5*/ { DATA_MODE, 0, -1, -1, -1, { 0, 0, "" }, "\340\345\354\350\370\344\055\367\345\343\061\062\063\064", 0, 13, 20, 1, "AIMD/TSC15032-43 Figure G.3 **NOT SAME** no compression", | |
| 426 "77777777777777777777" | |
| 427 "78578611115666161157" | |
| 428 "77678333656133516617" | |
| 429 "78178655165515651157" | |
| 430 "77578516516333565617" | |
| 431 "78378163335155353557" | |
| 432 "77878787878787878787" | |
| 433 "78678153311666661117" | |
| 434 "77378315553111316637" | |
| 435 "78578631611565551357" | |
| 436 "77378166136636365117" | |
| 437 "78178613653553116357" | |
| 438 "77777777777777777777" | |
| 439 }, | |
| 440 /* 6*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "https://aimglobal.org/jcrv3tX", 0, 13, 20, 1, "AIMD/TSC15032-43 Figure G.4a **NOT SAME** different compression; also DCC incorrect in figure", | |
| 441 "77777777777777777777" | |
| 442 "78578655115631563137" | |
| 443 "77678563356513315617" | |
| 444 "78178611665136133337" | |
| 445 "77578565116663516517" | |
| 446 "78378311355315331357" | |
| 447 "77878787878787878787" | |
| 448 "78678113111111615617" | |
| 449 "77378331553353561537" | |
| 450 "78578655311165333157" | |
| 451 "77378311136331165617" | |
| 452 "78178163363613633157" | |
| 453 "77777777777777777777" | |
| 454 }, | |
| 455 /* 7*/ { GS1_MODE, 0, -1, -1, -1, { 0, 0, "" }, "[01]03453120000011[17]121125[10]ABCD1234", 0, 13, 23, 1, "AIMD/TSC15032-43 Figure G.6 **NOT SAME** different compression and ECC; also DCC incorrect in figure", | |
| 456 "77777777777777777777777" | |
| 457 "78578616535355353318157" | |
| 458 "77678553116631616667617" | |
| 459 "78378331365353335558567" | |
| 460 "77578563516616556637657" | |
| 461 "78378656335135665368337" | |
| 462 "77878787878787878787877" | |
| 463 "78678161311353355118517" | |
| 464 "77578313153616611667137" | |
| 465 "78178635531563535558357" | |
| 466 "77378516316135616367117" | |
| 467 "78178335533356531518357" | |
| 468 "77777777777777777777777" | |
| 469 }, | |
| 470 /* 8*/ { UNICODE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "A", 0, 13, 13, 1, "", | |
| 471 "7777777777777" | |
| 472 "7857863335517" | |
| 473 "7717835163667" | |
| 474 "7867861551557" | |
| 475 "7757856115637" | |
| 476 "7837813636557" | |
| 477 "7787878787877" | |
| 478 "7867811361117" | |
| 479 "7717833133337" | |
| 480 "7857811355157" | |
| 481 "7737865163617" | |
| 482 "7817833536357" | |
| 483 "7777777777777" | |
| 484 }, | |
| 485 /* 9*/ { UNICODE_MODE, 0, 2, -1, -1, { 0, 0, "" }, "1234567890123456789012", 0, 13, 24, 1, "Length 22 == 25 MCC (C) with EC1 so 6 ECC by Table 12", | |
| 486 "777777777777777777777777" | |
| 487 "785786663111111111181117" | |
| 488 "776783555536666666676667" | |
| 489 "783786113311333113383117" | |
| 490 "776785365155115351175357" | |
| 491 "783781136666363663683667" | |
| 492 "778787878787878787878787" | |
| 493 "786781313511111111181117" | |
| 494 "775785135666666666676637" | |
| 495 "781781666511333113383157" | |
| 496 "776783531656155561575517" | |
| 497 "781786155535516355186337" | |
| 498 "777777777777777777777777" | |
| 499 }, | |
| 500 /* 10*/ { UNICODE_MODE, 0, 2, -1, -1, { 0, 0, "" }, "12345678901234567890123", 0, 13, 25, 1, "Length 23 == 26 MCC (C) with EC1 so 7 ECC by Table 12", | |
| 501 "7777777777777777777777777" | |
| 502 "7857863655511111111811117" | |
| 503 "7767831563666666666766667" | |
| 504 "7857863315511333113833117" | |
| 505 "7717855133656155561755567" | |
| 506 "7837811366535516355816357" | |
| 507 "7787878787878787878787877" | |
| 508 "7867813331111111111811117" | |
| 509 "7757851515366666666766637" | |
| 510 "7837816363113331133831157" | |
| 511 "7757851535651153511753517" | |
| 512 "7817835653363636636836657" | |
| 513 "7777777777777777777777777" | |
| 514 }, | |
| 515 /* 11*/ { UNICODE_MODE, 0, 1, -1, -1, { 0, 0, "" }, "1", 0, 13, 11, 1, "Figure 3a min 2-row, EC0", | |
| 516 "77777777777" | |
| 517 "78578661517" | |
| 518 "77178355667" | |
| 519 "78378666517" | |
| 520 "77678551657" | |
| 521 "78378135537" | |
| 522 "77878787877" | |
| 523 "78678151117" | |
| 524 "77178333337" | |
| 525 "78378115117" | |
| 526 "77578631357" | |
| 527 "78178365567" | |
| 528 "77777777777" | |
| 529 }, | |
| 530 /* 12*/ { UNICODE_MODE, 0, 6, -1, -1, { 0, 0, "" }, "1234567890123456789012", 0, 13, 28, 0, "Figure 3a max 2-row, EC5 **NOT SAME** extra col due to BWIPP update 2021-07-14; BWIPP chooses 3 rows instead", | |
| 531 "7777777777777777777777777777" | |
| 532 "7857863331131511111811111157" | |
| 533 "7717835613316666666766666617" | |
| 534 "7837866555153511333811333157" | |
| 535 "7757853333361656155756155517" | |
| 536 "7867816166656535516835516357" | |
| 537 "7787878787878787878787878787" | |
| 538 "7837816551551111111811111117" | |
| 539 "7717855165135366666766666637" | |
| 540 "7837813613616513331813331157" | |
| 541 "7767836165151351153751153567" | |
| 542 "7817863633563563636863636637" | |
| 543 "7777777777777777777777777777" | |
| 544 }, | |
| 545 /* 13*/ { UNICODE_MODE, 0, 1, -1, -1, { 0, 0, "" }, "12345678901234567890123456789012345", 0, 19, 22, 1, "Figure 3b min 3-row, EC0 **NOT SAME** Zint min not same as real min as chooses lower rows first (would need row option)", | |
| 546 "7777777777777777777777" | |
| 547 "7887866511111111111817" | |
| 548 "7787833666666666666767" | |
| 549 "7887861513313311331837" | |
| 550 "7757855651551536155717" | |
| 551 "7837811565333165666857" | |
| 552 "7717878787878787878787" | |
| 553 "7857811111111111111857" | |
| 554 "7737855366666666666717" | |
| 555 "7887863113313313311857" | |
| 556 "7767816361551551536717" | |
| 557 "7817831556665333165857" | |
| 558 "7757878787878787878787" | |
| 559 "7867811111111111111817" | |
| 560 "7717855666666666666737" | |
| 561 "7887816133113313313817" | |
| 562 "7787863515361551551757" | |
| 563 "7887831331656665333867" | |
| 564 "7777777777777777777777" | |
| 565 }, | |
| 566 /* 14*/ { UNICODE_MODE, 0, 6, -1, -1, { 0, 0, "" }, "1234567890123456789012345678901234567890123456789012345", 0, 19, 38, 0, "Figure 3b max 3-row, EC5 **NOT SAME** extra col due to BWIPP update 2021-07-14; BWIPP chooses 4 rows instead", | |
| 567 "77777777777777777777777777777777777777" | |
| 568 "78878611311563611118111111111111111817" | |
| 569 "77878366156351555667666666666666666767" | |
| 570 "78878633333136131138313313311331331837" | |
| 571 "77578551555353555617551551536155155717" | |
| 572 "78178136611516613568665333165666533837" | |
| 573 "77678787878787878787878787878787878787" | |
| 574 "78178111165636331118111111111111111817" | |
| 575 "77678663533553616667666666666666666767" | |
| 576 "78878336161116361338113313313311331837" | |
| 577 "77378611355661535157361551551536155717" | |
| 578 "78178166536313613318656665333165666857" | |
| 579 "77578787878787878787878787878787878787" | |
| 580 "78678313563533551118111111111111111817" | |
| 581 "77178535616651666667666666666666666757" | |
| 582 "78878153331316151338133113313313311837" | |
| 583 "77878611116665665157515361551551536717" | |
| 584 "78878166553313356538331656665333165837" | |
| 585 "77777777777777777777777777777777777777" | |
| 586 }, | |
| 587 /* 15*/ { UNICODE_MODE, 0, 1, -1, -1, { 0, 0, "" }, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012", 0, 25, 30, 1, "Figure 3c min 4-row, EC0 **NOT SAME** Zint min not same as real min as chooses lower rows first (would need row option)", | |
| 588 "777777777777777777777777777777" | |
| 589 "788786511111111111181111111117" | |
| 590 "778783166666666666676666666667" | |
| 591 "788786513313133131383131331317" | |
| 592 "778785351565515655175655156557" | |
| 593 "788781135651356513586513565137" | |
| 594 "778787878787878787878787878787" | |
| 595 "785783311111111111181111111117" | |
| 596 "771781166666666666676666666667" | |
| 597 "786786613133131331381331313317" | |
| 598 "775781351315513155173155131557" | |
| 599 "783783566633666336686336663367" | |
| 600 "778787878787878787878787878787" | |
| 601 "786783511111111111181111111157" | |
| 602 "771786666666666666676666666617" | |
| 603 "785785513133131331381331313357" | |
| 604 "773781665515655156575156551517" | |
| 605 "781785551356513565183565135657" | |
| 606 "778787878787878787878787878787" | |
| 607 "788781111111111111181111111117" | |
| 608 "778785366666666666676666666637" | |
| 609 "788781133131331313381313313117" | |
| 610 "778786315513155131575131551357" | |
| 611 "788785533666336663386663366667" | |
| 612 "777777777777777777777777777777" | |
| 613 }, | |
| 614 /* 16*/ { UNICODE_MODE, 0, 6, -1, -1, { 0, 0, "" }, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456", 0, 25, 50, 0, "Figure 3c max 4-row **NOT SAME** extra col due to BWIPP update 2021-07-14; BWIPP chooses 5 rows instead", | |
| 615 "77777777777777777777777777777777777777777777777777" | |
| 616 "78878631533313135518111111111111111811111111111117" | |
| 617 "77878315116161313667666666666666666766666666666667" | |
| 618 "78878656365333166518313313133131331831331313313137" | |
| 619 "77878561133666533667551565515655156755156551565517" | |
| 620 "78878156661531351558135651356513565813565135651357" | |
| 621 "77878787878787878787878787878787878787878787878787" | |
| 622 "78578313331353336118111111111111111811111111111117" | |
| 623 "77378661116566653567666666666666666766666666666667" | |
| 624 "78578136563115335638313133131331313831313313133137" | |
| 625 "77378311656551166317551315513155131755131551315517" | |
| 626 "78678653535336613538366633666336663836663366633667" | |
| 627 "77878787878787878787878787878787878787878787878787" | |
| 628 "78378336656556111118111111111111111811111111111157" | |
| 629 "77578153161313353667666666666666666766666666666617" | |
| 630 "78178566535655535138313133131331313831313313133157" | |
| 631 "77378635316136611517565515655156551756551565515617" | |
| 632 "78178551133613153358651356513565135865135651356557" | |
| 633 "77878787878787878787878787878787878787878787878787" | |
| 634 "78878655635551355118111111111111111811111111111117" | |
| 635 "77878313113333563667666666666666666766666666666657" | |
| 636 "78878161551515631138133131331313313813313133131367" | |
| 637 "77878316165363313517315513155131551731551315513157" | |
| 638 "78878633351651561668633666336663366863366633666337" | |
| 639 "77777777777777777777777777777777777777777777777777" | |
| 640 }, | |
| 641 /* 17*/ { UNICODE_MODE, 0, 1, -1, -1, { 0, 0, "" }, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", 0, 31, 42, 1, "Figure 3d min 5-row, EC0 **NOT SAME** Zint min not same as real min as chooses lower rows first (would need row option)", | |
| 642 "777777777777777777777777777777777777777777" | |
| 643 "788786511111111111181111111111111118111117" | |
| 644 "778783366666666666676666666666666667666667" | |
| 645 "788786113131313131381313131313131318313137" | |
| 646 "778785365656565656576565656565656567565657" | |
| 647 "788781553535353535385353535353535358353537" | |
| 648 "778787878787878787878787878787878787878787" | |
| 649 "788785511111111111181111111111111118111117" | |
| 650 "778781666666666666676666666666666667666667" | |
| 651 "788786533333333333383333333333333338333337" | |
| 652 "775785615151515151571515151515151517515157" | |
| 653 "783783536363636363683636363636363638636367" | |
| 654 "776787878787878787878787878787878787878787" | |
| 655 "781781111111111111181111111111111118111157" | |
| 656 "773785366666666666676666666666666667666617" | |
| 657 "788783131313131313183131313131313138131357" | |
| 658 "776786313131313131371313131313131317313117" | |
| 659 "783785556565656565685656565656565658656557" | |
| 660 "771787878787878787878787878787878787878787" | |
| 661 "785781111111111111181111111111111118111157" | |
| 662 "771783666666666666676666666666666667666617" | |
| 663 "788785131313131313183131313131313138131357" | |
| 664 "778781515151515151571515151515151517515117" | |
| 665 "788786363636363636386363636363636368363657" | |
| 666 "778787878787878787878787878787878787878787" | |
| 667 "788781111111111111181111111111111118111117" | |
| 668 "778786666666666666676666666666666667666637" | |
| 669 "788783131313131313183131313131313138131317" | |
| 670 "778785555555555555575555555555555557555557" | |
| 671 "788783616161616161681616161616161618616167" | |
| 672 "777777777777777777777777777777777777777777" | |
| 673 }, | |
| 674 /* 18*/ { UNICODE_MODE, 0, 6, -1, -1, { 0, 0, "" }, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012", 0, 31, 66, 1, "Figure 3d max 5-row, EC5 **NOT SAME** Max columns due to 282 limit is 60 not 61 as shown", | |
| 675 "777777777777777777777777777777777777777777777777777777777777777777" | |
| 676 "788786563656553165385551111111111118111111111111111811111111111117" | |
| 677 "778783136511335313673366666666666667666666666666666766666666666667" | |
| 678 "788786315633661531381153333333333338333333333333333833333333333337" | |
| 679 "778785666366116365673661515151515157151515151515151751515151515157" | |
| 680 "788781333151633111586553636363636368363636363636363863636363636367" | |
| 681 "778787878787878787878787878787878787878787878787878787878787878787" | |
| 682 "788785511663631513386131111111111118111111111111111811111111111117" | |
| 683 "778786665351353656571616666666666667666666666666666766666666666667" | |
| 684 "788783551116166363183533131313131318313131313131313813131313131317" | |
| 685 "775786313333613536571361313131313137131313131313131731313131313137" | |
| 686 "786785666615135615686615656565656568565656565656565865656565656567" | |
| 687 "775787878787878787878787878787878787878787878787878787878787878787" | |
| 688 "783785665636551563586511111111111118111111111111111811111111111117" | |
| 689 "776781516115365616671166666666666667666666666666666766666666666667" | |
| 690 "788785631666611363586313131313131318313131313131313813131313131317" | |
| 691 "773786116553355536673151515151515157151515151515151751515151515157" | |
| 692 "786783553131613115381536363636363638636363636363636836363636363637" | |
| 693 "775787878787878787878787878787878787878787878787878787878787878787" | |
| 694 "783786611351531316585111111111111118111111111111111811111111111117" | |
| 695 "771783536663313553371666666666666667666666666666666766666666666667" | |
| 696 "788785665115635111683313131313131318313131313131313813131313131317" | |
| 697 "778783133333563566376155555555555557555555555555555755555555555557" | |
| 698 "788785356111611131583661616161616168161616161616161861616161616167" | |
| 699 "778787878787878787878787878787878787878787878787878787878787878787" | |
| 700 "788785665536116356681611111111111118111111111111111811111111111137" | |
| 701 "778786511361333635576566666666666667666666666666666766666666666617" | |
| 702 "788783666116561361181613131313131318313131313131313813131313131357" | |
| 703 "778785533633353533375565656565656567565656565656565765656565656517" | |
| 704 "788786316551515665186353535353535358353535353535353853535353535357" | |
| 705 "777777777777777777777777777777777777777777777777777777777777777777" | |
| 706 }, | |
| 707 /* 19*/ { UNICODE_MODE | ESCAPE_MODE, 0, -1, -1, -1, { 0, 0, "" }, "[)>\\R06\\G17V12345\\G1P234TYU\\GS6789\\R\\E", 0, 13, 27, 0, "06 Macro; not supported by BWIPP", | |
| 708 "777777777777777777777777777" | |
| 709 "785786311655611111181311157" | |
| 710 "771783153516566666676156617" | |
| 711 "783786565165331131183633357" | |
| 712 "771785613316555615571311517" | |
| 713 "786781336155113553683636357" | |
| 714 "778787878787878787878787877" | |
| 715 "783781136511131113183331117" | |
| 716 "771785651653616651671116637" | |
| 717 "783781163535161335185653357" | |
| 718 "775786355661515113676165537" | |
| 719 "781783531133356335585331617" | |
| 720 "777777777777777777777777777" | |
| 721 }, | |
| 722 /* 20*/ { UNICODE_MODE | ESCAPE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "[)>\\R06\\G17V12345\\G1P234TYU\\GS6789\\R\\E", 0, 13, 23, 0, "06 Macro; not supported by BWIPP", | |
| 723 "77777777777777777777777" | |
| 724 "78578613335635131318557" | |
| 725 "77678536566511516157617" | |
| 726 "78378311615366353638157" | |
| 727 "77578533166515131317617" | |
| 728 "78378356655653353638357" | |
| 729 "77878787878787878787877" | |
| 730 "78678151311551153338617" | |
| 731 "77578333653116611117137" | |
| 732 "78178611511333155658357" | |
| 733 "77378555366511536167517" | |
| 734 "78178116153635315338657" | |
| 735 "77777777777777777777777" | |
| 736 }, | |
| 737 /* 21*/ { UNICODE_MODE, 0, -1, -1, -1, { 1, 2, "" }, "A", 0, 13, 14, 1, "Structured Append without File Number", | |
| 738 "77777777777777" | |
| 739 "78578633165557" | |
| 740 "77378351336117" | |
| 741 "78178666115357" | |
| 742 "77578533636617" | |
| 743 "78378156565557" | |
| 744 "77878787878787" | |
| 745 "78678153513117" | |
| 746 "77178365631637" | |
| 747 "78578133353557" | |
| 748 "77678651566317" | |
| 749 "78178535111557" | |
| 750 "77777777777777" | |
| 751 }, | |
| 752 /* 22*/ { UNICODE_MODE, 0, -1, -1, -1, { 8, 8, "283" }, "A", 0, 13, 15, 1, "Structured Append with File Number", | |
| 753 "777777777777777" | |
| 754 "785786353356157" | |
| 755 "773783115665317" | |
| 756 "781786661553157" | |
| 757 "776785535165317" | |
| 758 "783781613656557" | |
| 759 "778787878787877" | |
| 760 "786781563131117" | |
| 761 "771783651313637" | |
| 762 "786785336531557" | |
| 763 "773781115663317" | |
| 764 "781785653516557" | |
| 765 "777777777777777" | |
| 766 }, | |
| 767 /* 23*/ { UNICODE_MODE, 0, -1, 2, -1, { 0, 0, "" }, "ULTRACODE_123456789!", 0, 13, 24, 1, "Revision 2", | |
| 768 "777777777777777777777777" | |
| 769 "781786533153313111181157" | |
| 770 "776783361661161666676617" | |
| 771 "781786115156555511383357" | |
| 772 "775785556561633656175517" | |
| 773 "786781311653551535581657" | |
| 774 "778787878787878787878787" | |
| 775 "783781656113311311181117" | |
| 776 "776783333531166566676537" | |
| 777 "783786651315555113383357" | |
| 778 "776785515161666351175517" | |
| 779 "785786166533113663683357" | |
| 780 "777777777777777777777777" | |
| 781 }, | |
| 782 }; | |
| 783 const int data_size = ARRAY_SIZE(data); | |
| 784 int i, length, ret; | |
| 785 struct zint_symbol *symbol = NULL; | |
| 786 | |
| 787 char escaped[1024]; | |
| 788 char bwipp_buf[32768]; | |
| 789 char bwipp_msg[1024]; | |
| 790 | |
| 791 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */ | |
| 792 | |
| 793 testStartSymbol("test_encode", &symbol); | |
| 794 | |
| 795 for (i = 0; i < data_size; i++) { | |
| 796 | |
| 797 if (testContinue(p_ctx, i)) continue; | |
| 798 | |
| 799 symbol = ZBarcode_Create(); | |
| 800 assert_nonnull(symbol, "Symbol not created\n"); | |
| 801 | |
| 802 length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); | |
| 803 if (data[i].structapp.count) { | |
| 804 symbol->structapp = data[i].structapp; | |
| 805 } | |
| 806 | |
| 807 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 808 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 809 | |
| 810 if (p_ctx->generate) { | |
| 811 printf(" /*%3d*/ { %s, %d, %d, %d, %s, { %d, %d, \"%s\" }, \"%s\", %s, %d, %d, %d, \"%s\",\n", | |
| 812 i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2, | |
| 813 testUtilOption3Name(BARCODE_ULTRA, data[i].option_3), | |
| 814 data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, | |
| 815 testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), | |
| 816 symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment); | |
| 817 testUtilModulesPrint(symbol, " ", "\n"); | |
| 818 printf(" },\n"); | |
| 819 } else { | |
| 820 if (ret < ZINT_ERROR) { | |
| 821 int width, row; | |
| 822 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); | |
| 823 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); | |
| 824 | |
| 825 ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); | |
| 826 assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data); | |
| 827 | |
| 828 if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3, debug)) { | |
| 829 if (!data[i].bwipp_cmp) { | |
| 830 if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment); | |
| 831 } else { | |
| 832 ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf), NULL); | |
| 833 assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 834 | |
| 835 ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected); | |
| 836 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", | |
| 837 i, testUtilBarcodeName(symbol->symbology), ret, bwipp_msg, bwipp_buf, data[i].expected); | |
| 838 } | |
| 839 } | |
| 840 } | |
| 841 } | |
| 842 | |
| 843 ZBarcode_Delete(symbol); | |
| 844 } | |
| 845 | |
| 846 testFinish(); | |
| 847 } | |
| 848 | |
| 849 static void test_encode_segs(const testCtx *const p_ctx) { | |
| 850 int debug = p_ctx->debug; | |
| 851 | |
| 852 struct item { | |
| 853 int input_mode; | |
| 854 int option_1; | |
| 855 int option_2; | |
| 856 int option_3; | |
| 857 struct zint_structapp structapp; | |
| 858 struct zint_seg segs[3]; | |
| 859 int ret; | |
| 860 | |
| 861 int expected_rows; | |
| 862 int expected_width; | |
| 863 int bwipp_cmp; | |
| 864 char *comment; | |
| 865 char *expected; | |
| 866 }; | |
| 867 /* Based on AIMD/TSC15032-43 (v 0.99c), with values updated from BWIPP update 2021-07-14 | |
| 868 https://github.com/bwipp/postscriptbarcode/commit/4255810845fa8d45c6192dd30aee1fdad1aaf0cc | |
| 869 */ | |
| 870 static const struct item data[] = { | |
| 871 /* 0*/ { UNICODE_MODE, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, { { TU("¶"), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, 0, 13, 15, 0, "Standard example; BWIPP no ECI support for Ultracode", | |
| 872 "777777777777777" | |
| 873 "785786131155157" | |
| 874 "773783613563337" | |
| 875 "781786355656167" | |
| 876 "776785561363337" | |
| 877 "783781355651517" | |
| 878 "778787878787877" | |
| 879 "786781665116117" | |
| 880 "771783136335337" | |
| 881 "786785653613557" | |
| 882 "773781536165117" | |
| 883 "781786115333557" | |
| 884 "777777777777777" | |
| 885 }, | |
| 886 /* 1*/ { UNICODE_MODE, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, { { TU("¶"), -1, 0 }, { TU("Ж"), -1, 0 }, { TU(""), 0, 0 } }, ZINT_WARN_USES_ECI, 13, 15, 0, "Standard example auto-ECI; BWIPP no ECI support for Ultracode", | |
| 887 "777777777777777" | |
| 888 "785786131155157" | |
| 889 "773783613563337" | |
| 890 "781786355656167" | |
| 891 "776785561363337" | |
| 892 "783781355651517" | |
| 893 "778787878787877" | |
| 894 "786781665116117" | |
| 895 "771783136335337" | |
| 896 "786785653613557" | |
| 897 "773781536165117" | |
| 898 "781786115333557" | |
| 899 "777777777777777" | |
| 900 }, | |
| 901 /* 2*/ { UNICODE_MODE, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, { { TU("Ж"), -1, 7 }, { TU("¶"), -1, 0 }, { TU(""), 0, 0 } }, 0, 13, 15, 0, "Standard example inverted; BWIPP no ECI support for Ultracode", | |
| 902 "777777777777777" | |
| 903 "785786351355157" | |
| 904 "773785113663337" | |
| 905 "781781365356167" | |
| 906 "776783136163337" | |
| 907 "783786555651517" | |
| 908 "778787878787877" | |
| 909 "786781356116117" | |
| 910 "771783663335337" | |
| 911 "786785531613157" | |
| 912 "773781353165517" | |
| 913 "781786565333657" | |
| 914 "777777777777777" | |
| 915 }, | |
| 916 /* 3*/ { UNICODE_MODE, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, { { TU("Ж"), -1, 0 }, { TU("¶"), -1, 0 }, { TU(""), 0, 0 } }, ZINT_WARN_USES_ECI, 13, 15, 0, "Standard example inverted auto-ECI; BWIPP no ECI support for Ultracode", | |
| 917 "777777777777777" | |
| 918 "785786351355157" | |
| 919 "773785113663337" | |
| 920 "781781365356167" | |
| 921 "776783136163337" | |
| 922 "783786555651517" | |
| 923 "778787878787877" | |
| 924 "786781356116117" | |
| 925 "771783663335337" | |
| 926 "786785531613157" | |
| 927 "773781353165517" | |
| 928 "781786565333657" | |
| 929 "777777777777777" | |
| 930 }, | |
| 931 /* 4*/ { UNICODE_MODE, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, { { TU("product:Google Pixel 4a - 128 GB of Storage - Black;price:$439.97"), -1, 3 }, { TU("品名:Google 谷歌 Pixel 4a -128 GB的存储空间-黑色;零售价:¥3149.79"), -1, 29 }, { TU("Produkt:Google Pixel 4a - 128 GB Speicher - Schwarz;Preis:444,90 €"), -1, 17 } }, 0, 31, 51, 0, "AIM ITS/04-023:2022 Annex A example; BWIPP no ECI support for Ultracode", | |
| 932 "777777777777777777777777777777777777777777777777777" | |
| 933 "788786553615151313686615635315656568556155565633167" | |
| 934 "778783131336563655375536556151531317365661116315357" | |
| 935 "788786366163615166181363163533665138151555551131667" | |
| 936 "778785631636351311375511615351516667316663165656357" | |
| 937 "788781563115163655581635531513353338163331636363137" | |
| 938 "778787878787878787878787878787878787878787878787877" | |
| 939 "788785515563115631383565335311551158666513631316557" | |
| 940 "778786651356351315575153153566315667555156366135637" | |
| 941 "788781363513515166181666316333666318161633113513317" | |
| 942 "775783635365361331576153163515155637655155661351537" | |
| 943 "781785353136156566383335656633633318536616353136617" | |
| 944 "773787878787878787878787878787878787878787878787877" | |
| 945 "781781331535616631386565316331555568565666316651557" | |
| 946 "776786666356535565175656551655663617153515131366317" | |
| 947 "788783355511663311383331636113116138635136555113557" | |
| 948 "773785516665311566576556353555655567351513361555317" | |
| 949 "781783633336533155181333115131513638536365113131157" | |
| 950 "773787878787878787878787878787878787878787878787877" | |
| 951 "785786636561663636181316366313566618513136611663557" | |
| 952 "771781563655535363573133555551311167331655355551317" | |
| 953 "788783155566111151385315661133633538516533131135557" | |
| 954 "778786516633355666676136356651116667635356516556317" | |
| 955 "788785133151663353583553135516551118156615665661657" | |
| 956 "778787878787878787878787878787878787878787878787877" | |
| 957 "788781353515665533386611351311655558113366366156117" | |
| 958 "778783616631513151171356535556166617531115155365537" | |
| 959 "788785555563336315386533363665613368666653363516367" | |
| 960 "778781366656651133171316155153135557515516515663557" | |
| 961 "788786635535536351685531611336513668663633636555117" | |
| 962 "777777777777777777777777777777777777777777777777777" | |
| 963 }, | |
| 964 /* 5*/ { DATA_MODE, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, { { TU("\266"), 1, 0 }, { TU("\266"), 1, 7 }, { TU("\266"), 1, 0 } }, 0, 13, 17, 0, "Standard example + extra seg, data mode; BWIPP no ECI support for Ultracode", | |
| 965 "77777777777777777" | |
| 966 "78578616315515157" | |
| 967 "77378361566333337" | |
| 968 "78578633115616167" | |
| 969 "77678566656333337" | |
| 970 "78378131365151517" | |
| 971 "77878787878787877" | |
| 972 "78678136111616117" | |
| 973 "77378361633535337" | |
| 974 "78178513161353157" | |
| 975 "77378656536515517" | |
| 976 "78178135353353657" | |
| 977 "77777777777777777" | |
| 978 }, | |
| 979 /* 6*/ { UNICODE_MODE, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, { { TU("¿é"), -1, 0 }, { TU("กขฯ"), -1, 0 }, { TU("φχψω"), -1, 0 } }, ZINT_WARN_USES_ECI, 13, 20, 0, "Auto-ECI; BWIPP no ECI support for Ultracode", | |
| 980 "77777777777777777777" | |
| 981 "78578651555561561667" | |
| 982 "77678333166653153337" | |
| 983 "78178655335135635557" | |
| 984 "77578563166556553337" | |
| 985 "78378131655133331167" | |
| 986 "77878787878787878787" | |
| 987 "78678166111615516617" | |
| 988 "77378351653131633337" | |
| 989 "78578663311616515557" | |
| 990 "77378315636535131317" | |
| 991 "78178131363151656557" | |
| 992 "77777777777777777777" | |
| 993 }, | |
| 994 /* 7*/ { UNICODE_MODE, -1, -1, ULTRA_COMPRESSION, { 2, 3, "4" }, { { TU("¿é"), -1, 3 }, { TU("กขฯ"), -1, 13 }, { TU("φχψω"), -1, 9 } }, 0, 13, 23, 0, "Structured Append; BWIPP no ECI support for Ultracode", | |
| 995 "77777777777777777777777" | |
| 996 "78578613615616155168657" | |
| 997 "77678335366131316337317" | |
| 998 "78378666635516165158557" | |
| 999 "77578515156665351317317" | |
| 1000 "78378163515131516568557" | |
| 1001 "77878787878787878787877" | |
| 1002 "78678151513156156168617" | |
| 1003 "77578366351365315337337" | |
| 1004 "78178633513113563558557" | |
| 1005 "77378516666355655337317" | |
| 1006 "78178133151513333118657" | |
| 1007 "77777777777777777777777" | |
| 1008 }, | |
| 1009 /* 8*/ { UNICODE_MODE, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, { { TU("çèéêëì"), -1, 0 }, { TU("òóô"), -1, 899 }, { TU("òóô"), -1, 10000 } }, 0, 13, 27, 0, "ECIs >= 899; BWIPP no ECI support for Ultracode", | |
| 1010 "777777777777777777777777777" | |
| 1011 "785786353555666665585335557" | |
| 1012 "771783161616113513373663337" | |
| 1013 "783786335335661355686335667" | |
| 1014 "771785511666353666171656117" | |
| 1015 "786781655535111113385163357" | |
| 1016 "778787878787878787878787877" | |
| 1017 "783781151511666355586355517" | |
| 1018 "771785616353113666675666637" | |
| 1019 "783781363635661511183311157" | |
| 1020 "775786615561353366676566637" | |
| 1021 "781785551653535633383633317" | |
| 1022 "777777777777777777777777777" | |
| 1023 }, | |
| 1024 }; | |
| 1025 const int data_size = ARRAY_SIZE(data); | |
| 1026 int i, j, seg_count, ret; | |
| 1027 struct zint_symbol *symbol = NULL; | |
| 1028 | |
| 1029 char escaped[1024]; | |
| 1030 char bwipp_buf[32768]; | |
| 1031 char bwipp_msg[1024]; | |
| 1032 | |
| 1033 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */ | |
| 1034 | |
| 1035 testStartSymbol("test_encode_segs", &symbol); | |
| 1036 | |
| 1037 for (i = 0; i < data_size; i++) { | |
| 1038 | |
| 1039 if (testContinue(p_ctx, i)) continue; | |
| 1040 | |
| 1041 symbol = ZBarcode_Create(); | |
| 1042 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1043 | |
| 1044 testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, -1 /*eci*/, | |
| 1045 data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, NULL, 0, debug); | |
| 1046 if (data[i].structapp.count) { | |
| 1047 symbol->structapp = data[i].structapp; | |
| 1048 } | |
| 1049 for (j = 0, seg_count = 0; j < 3 && data[i].segs[j].length; j++, seg_count++); | |
| 1050 | |
| 1051 ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count); | |
| 1052 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 1053 | |
| 1054 if (p_ctx->generate) { | |
| 1055 char escaped1[4096]; | |
| 1056 char escaped2[4096]; | |
| 1057 int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; | |
| 1058 int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length; | |
| 1059 int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length; | |
| 1060 printf(" /*%3d*/ { %s, %d, %d, %s, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, %d, \"%s\",\n", | |
| 1061 i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, | |
| 1062 testUtilOption3Name(BARCODE_ULTRA, data[i].option_3), | |
| 1063 data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, | |
| 1064 testUtilEscape((const char *) data[i].segs[0].source, length, escaped, sizeof(escaped)), data[i].segs[0].length, data[i].segs[0].eci, | |
| 1065 testUtilEscape((const char *) data[i].segs[1].source, length1, escaped1, sizeof(escaped1)), data[i].segs[1].length, data[i].segs[1].eci, | |
| 1066 testUtilEscape((const char *) data[i].segs[2].source, length2, escaped2, sizeof(escaped2)), data[i].segs[2].length, data[i].segs[2].eci, | |
| 1067 testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment); | |
| 1068 testUtilModulesPrint(symbol, " ", "\n"); | |
| 1069 printf(" },\n"); | |
| 1070 } else { | |
| 1071 if (ret < ZINT_ERROR) { | |
| 1072 int width, row; | |
| 1073 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); | |
| 1074 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); | |
| 1075 | |
| 1076 ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); | |
| 1077 assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d\n", i, ret, width, row); | |
| 1078 | |
| 1079 if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3, debug)) { | |
| 1080 if (!data[i].bwipp_cmp) { | |
| 1081 if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment); | |
| 1082 } else { | |
| 1083 ret = testUtilBwippSegs(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3, data[i].segs, seg_count, NULL, bwipp_buf, sizeof(bwipp_buf)); | |
| 1084 assert_zero(ret, "i:%d %s testUtilBwippSegs ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); | |
| 1085 | |
| 1086 ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected); | |
| 1087 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", | |
| 1088 i, testUtilBarcodeName(symbol->symbology), ret, bwipp_msg, bwipp_buf, data[i].expected); | |
| 1089 } | |
| 1090 } | |
| 1091 } | |
| 1092 } | |
| 1093 | |
| 1094 ZBarcode_Delete(symbol); | |
| 1095 } | |
| 1096 | |
| 1097 testFinish(); | |
| 1098 } | |
| 1099 | |
| 1100 int main(int argc, char *argv[]) { | |
| 1101 | |
| 1102 testFunction funcs[] = { /* name, func */ | |
| 1103 { "test_large", test_large }, | |
| 1104 { "test_reader_init", test_reader_init }, | |
| 1105 { "test_input", test_input }, | |
| 1106 { "test_encode", test_encode }, | |
| 1107 { "test_encode_segs", test_encode_segs }, | |
| 1108 }; | |
| 1109 | |
| 1110 testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); | |
| 1111 | |
| 1112 testReport(); | |
| 1113 | |
| 1114 return 0; | |
| 1115 } | |
| 1116 | |
| 1117 /* vim: set ts=4 sw=4 et : */ |
