Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tests/test_library.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 #include <errno.h> | |
| 33 #include <fcntl.h> | |
| 34 #include <math.h> | |
| 35 #include <sys/stat.h> | |
| 36 #include "testcommon.h" | |
| 37 | |
| 38 static void test_checks(const testCtx *const p_ctx) { | |
| 39 int debug = p_ctx->debug; | |
| 40 | |
| 41 struct item { | |
| 42 int symbology; | |
| 43 int option_1; | |
| 44 char *data; | |
| 45 int length; | |
| 46 int input_mode; | |
| 47 int eci; | |
| 48 float height; | |
| 49 int whitespace_width; | |
| 50 int whitespace_height; | |
| 51 int border_width; | |
| 52 float scale; | |
| 53 float dot_size; | |
| 54 float text_gap; | |
| 55 float guard_descent; | |
| 56 int warn_level; | |
| 57 int ret; | |
| 58 | |
| 59 char *expected; | |
| 60 int expected_symbology; | |
| 61 }; | |
| 62 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 63 static const struct item data[] = { | |
| 64 /* 0*/ { BARCODE_CODE128, -1, "1234", -1, -1, 3, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 217: Symbology does not support ECI switching", -1 }, | |
| 65 /* 1*/ { BARCODE_CODE128, -1, "1234", -1, -1, 0, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", -1 }, | |
| 66 /* 2*/ { BARCODE_QRCODE, -1, "1234", -1, -1, 3, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", -1 }, | |
| 67 /* 3*/ { BARCODE_QRCODE, -1, "1234", -1, -1, 999999 + 1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 218: ECI code '1000000' out of range (0 to 999999, excluding 1, 2, 14 and 19)", -1 }, | |
| 68 /* 4*/ { BARCODE_CODE128, -1, "1234", -1, -1, -1, 0, 0, 0, 0, 0.009, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 227: Scale out of range (0.01 to 200)", -1 }, | |
| 69 /* 5*/ { BARCODE_CODE128, -1, "1234", -1, -1, -1, 0, 0, 0, 0, 200.01, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 227: Scale out of range (0.01 to 200)", -1 }, | |
| 70 /* 6*/ { BARCODE_CODE128, -1, "1234", -1, -1, -1, 0, 0, 0, 0, -1, 20.1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 221: Dot size out of range (0.01 to 20)", -1 }, | |
| 71 /* 7*/ { BARCODE_CODE128, -1, "1234", -1, -1, -1, 0, 0, 0, 0, 0.01, 0.009, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 221: Dot size out of range (0.01 to 20)", -1 }, | |
| 72 /* 8*/ { BARCODE_CODE128, -1, "1234", -1, -1, -1, -0.1, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 765: Height out of range (0 to 2000)", -1 }, | |
| 73 /* 9*/ { BARCODE_CODE128, -1, "1234", -1, -1, -1, 2000.01, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 765: Height out of range (0 to 2000)", -1 }, | |
| 74 /* 10*/ { BARCODE_CODE128, -1, "1234", -1, -1, -1, 0, -1, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 766: Whitespace width out of range (0 to 100)", -1 }, | |
| 75 /* 11*/ { BARCODE_CODE128, -1, "1234", -1, -1, -1, 0, 101, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 766: Whitespace width out of range (0 to 100)", -1 }, | |
| 76 /* 12*/ { BARCODE_CODE128, -1, "1234", -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 767: Whitespace height out of range (0 to 100)", -1 }, | |
| 77 /* 13*/ { BARCODE_CODE128, -1, "1234", -1, -1, -1, 0, 0, 101, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 767: Whitespace height out of range (0 to 100)", -1 }, | |
| 78 /* 14*/ { BARCODE_CODE128, -1, "1234", -1, -1, -1, 0, 0, 0, -1, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 768: Border width out of range (0 to 100)", -1 }, | |
| 79 /* 15*/ { BARCODE_CODE128, -1, "1234", -1, -1, -1, 0, 0, 0, 101, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 768: Border width out of range (0 to 100)", -1 }, | |
| 80 /* 16*/ { BARCODE_CODE128, -1, "1234", -1, GS1_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 220: Selected symbology does not support GS1 mode", -1 }, | |
| 81 /* 17*/ { BARCODE_EANX, -1, "123456789012", -1, -1, -1, 0, 0, 0, 101, -1, -1, -5.1, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 219: Text gap out of range (-5 to 10)", -1 }, | |
| 82 /* 18*/ { BARCODE_EANX, -1, "123456789012", -1, -1, -1, 0, 0, 0, 101, -1, -1, 10.1, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 219: Text gap out of range (-5 to 10)", -1 }, | |
| 83 /* 19*/ { BARCODE_EANX, -1, "123456789012", -1, -1, -1, 0, 0, 0, 101, -1, -1, 0, -0.5, -1, ZINT_ERROR_INVALID_OPTION, "Error 769: Guard bar descent out of range (0 to 50)", -1 }, | |
| 84 /* 20*/ { BARCODE_EANX, -1, "123456789012", -1, -1, -1, 0, 0, 0, 101, -1, -1, 0, 50.1, -1, ZINT_ERROR_INVALID_OPTION, "Error 769: Guard bar descent out of range (0 to 50)", -1 }, | |
| 85 /* 21*/ { BARCODE_GS1_128, -1, "[21]12\0004", 8, GS1_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 262: NUL characters not permitted in GS1 mode", -1 }, | |
| 86 /* 22*/ { BARCODE_GS1_128, -1, "[21]12é4", -1, GS1_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 250: Extended ASCII characters are not supported by GS1", -1 }, | |
| 87 /* 23*/ { BARCODE_GS1_128, -1, "[21]12\0074", -1, GS1_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 251: Control characters are not supported by GS1", -1 }, | |
| 88 /* 24*/ { BARCODE_GS1_128, -1, "[21]1234", -1, GS1_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", -1 }, | |
| 89 /* 25*/ { 0, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 90 /* 26*/ { 0, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 91 /* 27*/ { 0, -1, "1", -1, -1, 1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 217: Symbology does not support ECI switching", BARCODE_CODE128 }, /* Not supporting beats invalid ECI */ | |
| 92 /* 28*/ { 0, -1, "1", -1, -1, 1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 93 /* 29*/ { 0, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, 0.009, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 221: Dot size out of range (0.01 to 20)", BARCODE_CODE128 }, | |
| 94 /* 30*/ { 0, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, 0.009, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 95 /* 31*/ { 0, -1, "1", -1, -1, 1, 0, 0, 0, 0, -1, 0.009, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 217: Symbology does not support ECI switching", BARCODE_CODE128 }, /* Invalid dot size no longer beats invalid ECI */ | |
| 96 /* 32*/ { 0, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, 0.009, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 97 /* 33*/ { 5, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_C25STANDARD }, | |
| 98 /* 34*/ { 5, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_C25STANDARD }, | |
| 99 /* 35*/ { 10, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_EANX }, | |
| 100 /* 36*/ { 10, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_EANX }, | |
| 101 /* 37*/ { 11, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_EANX }, | |
| 102 /* 38*/ { 11, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_EANX }, | |
| 103 /* 39*/ { 12, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_EANX }, | |
| 104 /* 40*/ { 12, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_EANX }, | |
| 105 /* 41*/ { 15, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_EANX }, | |
| 106 /* 42*/ { 15, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_EANX }, | |
| 107 /* 43*/ { 17, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_UPCA }, | |
| 108 /* 44*/ { 17, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_UPCA }, | |
| 109 /* 45*/ { 19, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_TOO_LONG, "Error 362: Input length 1 too short (minimum 3)", BARCODE_CODABAR }, | |
| 110 /* 46*/ { 19, -1, "A1B", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 207: Codabar 18 not supported", BARCODE_CODABAR }, | |
| 111 /* 47*/ { 19, -1, "A1B", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 207: Codabar 18 not supported", -1 }, | |
| 112 /* 48*/ { 26, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_UPCA }, | |
| 113 /* 49*/ { 26, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_UPCA }, | |
| 114 /* 50*/ { 27, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 208: UPCD1 not supported", 27 }, | |
| 115 /* 51*/ { 33, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 252: Data does not start with an AI", BARCODE_GS1_128 }, | |
| 116 /* 52*/ { 33, -1, "[10]23", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_GS1_128 }, | |
| 117 /* 53*/ { 33, -1, "[10]23", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_GS1_128 }, | |
| 118 /* 54*/ { 36, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_UPCA }, | |
| 119 /* 55*/ { 36, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_UPCA }, | |
| 120 /* 56*/ { 39, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_UPCE }, | |
| 121 /* 57*/ { 39, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_UPCE }, | |
| 122 /* 58*/ { 41, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_NONCOMPLIANT, "Warning 479: Input length 1 is not standard (5, 9 or 11)", BARCODE_POSTNET }, | |
| 123 /* 59*/ { 41, -1, "12345", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_POSTNET }, | |
| 124 /* 60*/ { 41, -1, "12345", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_POSTNET }, | |
| 125 /* 61*/ { 42, -1, "12345", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_POSTNET }, | |
| 126 /* 62*/ { 42, -1, "12345", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_POSTNET }, | |
| 127 /* 63*/ { 43, -1, "12345", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_POSTNET }, | |
| 128 /* 64*/ { 43, -1, "12345", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_POSTNET }, | |
| 129 /* 65*/ { 44, -1, "12345", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_POSTNET }, | |
| 130 /* 66*/ { 44, -1, "12345", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_POSTNET }, | |
| 131 /* 67*/ { 45, -1, "12345", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_POSTNET }, | |
| 132 /* 68*/ { 45, -1, "12345", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_POSTNET }, | |
| 133 /* 69*/ { 46, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_PLESSEY }, | |
| 134 /* 70*/ { 46, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_PLESSEY }, | |
| 135 /* 71*/ { 48, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_NVE18 }, | |
| 136 /* 72*/ { 48, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_NVE18 }, | |
| 137 /* 73*/ { 59, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_CODE128 }, | |
| 138 /* 74*/ { 59, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_CODE128 }, | |
| 139 /* 75*/ { 61, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_CODE128 }, | |
| 140 /* 76*/ { 61, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_CODE128 }, | |
| 141 /* 77*/ { 62, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_CODE93 }, | |
| 142 /* 78*/ { 62, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_CODE93 }, | |
| 143 /* 79*/ { 64, -1, "12345678", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_AUSPOST }, | |
| 144 /* 80*/ { 64, -1, "12345678", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_AUSPOST }, | |
| 145 /* 81*/ { 65, -1, "12345678", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_AUSPOST }, | |
| 146 /* 82*/ { 65, -1, "12345678", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_AUSPOST }, | |
| 147 /* 83*/ { 78, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_DBAR_OMN }, | |
| 148 /* 84*/ { 78, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_DBAR_OMN }, | |
| 149 /* 85*/ { 83, -1, "12345678901", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_PLANET }, | |
| 150 /* 86*/ { 83, -1, "12345678901", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_PLANET }, | |
| 151 /* 87*/ { 88, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 252: Data does not start with an AI", BARCODE_GS1_128 }, | |
| 152 /* 88*/ { 88, -1, "[10]12", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_GS1_128 }, | |
| 153 /* 89*/ { 88, -1, "[10]12", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_GS1_128 }, | |
| 154 /* 90*/ { 91, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 155 /* 91*/ { 91, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 156 /* 92*/ { 94, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 157 /* 93*/ { 94, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 158 /* 94*/ { 95, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 159 /* 95*/ { 95, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 160 /* 96*/ { 100, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_128 }, | |
| 161 /* 97*/ { 100, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_128 }, | |
| 162 /* 98*/ { 101, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_39 }, | |
| 163 /* 99*/ { 101, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_39 }, | |
| 164 /*100*/ { 103, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_DM }, | |
| 165 /*101*/ { 103, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_DM }, | |
| 166 /*102*/ { 105, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_QR }, | |
| 167 /*103*/ { 105, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_QR }, | |
| 168 /*104*/ { 107, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_PDF }, | |
| 169 /*105*/ { 107, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_PDF }, | |
| 170 /*106*/ { 109, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_MICPDF }, | |
| 171 /*107*/ { 109, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_MICPDF }, | |
| 172 /*108*/ { 111, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_BLOCKF }, | |
| 173 /*109*/ { 111, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_BLOCKF }, | |
| 174 /*110*/ { 113, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 175 /*111*/ { 113, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 176 /*112*/ { 114, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 177 /*113*/ { 114, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 178 /*114*/ { 117, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 179 /*115*/ { 117, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 180 /*116*/ { 118, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 181 /*117*/ { 118, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 182 /*118*/ { 122, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 183 /*119*/ { 122, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 184 /*120*/ { 123, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 185 /*121*/ { 123, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 186 /*122*/ { 124, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 187 /*123*/ { 124, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 188 /*124*/ { 125, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 189 /*125*/ { 125, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 190 /*126*/ { 126, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 191 /*127*/ { 126, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 192 /*128*/ { 127, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 193 /*129*/ { 127, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 194 /*130*/ { 148, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 195 /*131*/ { 148, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 196 /*132*/ { BARCODE_LAST + 1, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 }, | |
| 197 /*133*/ { BARCODE_LAST + 1, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 }, | |
| 198 /*134*/ { BARCODE_CODE128, -1, "\200", -1, UNICODE_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 245: Invalid UTF-8 in input", -1 }, | |
| 199 /*135*/ { BARCODE_CODE128, -1, "\\o200", -1, UNICODE_MODE | ESCAPE_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 245: Invalid UTF-8 in input", -1 }, | |
| 200 /*136*/ { BARCODE_MAXICODE, -1, "\200", -1, UNICODE_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 245: Invalid UTF-8 in input", -1 }, | |
| 201 /*137*/ { BARCODE_MAXICODE, -1, "\\o200", -1, UNICODE_MODE | ESCAPE_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 245: Invalid UTF-8 in input", -1 }, | |
| 202 /*138*/ { BARCODE_GS1_128, -1, "[01]12345678901234", -1, GS1_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_NONCOMPLIANT, "Warning 261: AI (01) position 14: Bad checksum '4', expected '1'", -1 }, | |
| 203 /*139*/ { BARCODE_GS1_128, -1, "[01]12345678901234", -1, GS1_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_NONCOMPLIANT, "Error 261: AI (01) position 14: Bad checksum '4', expected '1'", -1 }, | |
| 204 /*140*/ { BARCODE_QRCODE, -1, "ก", -1, UNICODE_MODE, 13, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", -1 }, | |
| 205 /*141*/ { BARCODE_QRCODE, -1, "ก", -1, UNICODE_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_USES_ECI, "Warning 222: Encoded data includes ECI 13", -1 }, | |
| 206 /*142*/ { BARCODE_QRCODE, -1, "ก", -1, UNICODE_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_USES_ECI, "Error 222: Encoded data includes ECI 13", -1 }, | |
| 207 /*143*/ { BARCODE_CODEONE, -1, "[01]12345678901231", -1, GS1_MODE, 3, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 512: ECI ignored for GS1 mode", -1 }, | |
| 208 /*144*/ { BARCODE_CODEONE, -1, "[01]12345678901231", -1, GS1_MODE, 3, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 512: ECI ignored for GS1 mode", -1 }, | |
| 209 /*145*/ { BARCODE_CODEONE, -1, "[01]12345678901234", -1, GS1_MODE, 3, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 512: ECI ignored for GS1 mode", -1 }, /* Warning in encoder overrides library warnings */ | |
| 210 /*146*/ { BARCODE_CODEONE, -1, "[01]12345678901234", -1, GS1_MODE, 3, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_NONCOMPLIANT, "Error 261: AI (01) position 14: Bad checksum '4', expected '1'", -1 }, /* But not errors */ | |
| 211 /*147*/ { BARCODE_AZTEC, -1, "ก", -1, UNICODE_MODE, 13, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", -1 }, | |
| 212 /*148*/ { BARCODE_AZTEC, -1, "ก", -1, UNICODE_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_USES_ECI, "Warning 222: Encoded data includes ECI 13", -1 }, | |
| 213 /*149*/ { BARCODE_AZTEC, -1, "ก", -1, UNICODE_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_USES_ECI, "Error 222: Encoded data includes ECI 13", -1 }, | |
| 214 /*150*/ { BARCODE_AZTEC, 6, "ก", -1, UNICODE_MODE, 13, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 503: Error correction level '6' out of range (1 to 4), ignoring", -1 }, | |
| 215 /*151*/ { BARCODE_AZTEC, 6, "ก", -1, UNICODE_MODE, 13, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 503: Error correction level '6' out of range (1 to 4)", -1 }, | |
| 216 /*152*/ { BARCODE_AZTEC, 6, "ก", -1, UNICODE_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_USES_ECI, "Warning 222: Encoded data includes ECI 13", -1 }, /* ECI warning trumps all other warnings */ | |
| 217 /*153*/ { BARCODE_AZTEC, 6, "ก", -1, UNICODE_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 503: Error correction level '6' out of range (1 to 4)", -1 }, /* But not errors */ | |
| 218 }; | |
| 219 const int data_size = ARRAY_SIZE(data); | |
| 220 int i, length, ret; | |
| 221 struct zint_symbol *symbol = NULL; | |
| 222 | |
| 223 testStartSymbol("test_checks", &symbol); | |
| 224 | |
| 225 for (i = 0; i < data_size; i++) { | |
| 226 | |
| 227 if (testContinue(p_ctx, i)) continue; | |
| 228 | |
| 229 symbol = ZBarcode_Create(); | |
| 230 assert_nonnull(symbol, "Symbol not created\n"); | |
| 231 | |
| 232 length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); | |
| 233 if (data[i].height) { | |
| 234 symbol->height = data[i].height; | |
| 235 } | |
| 236 if (data[i].whitespace_width) { | |
| 237 symbol->whitespace_width = data[i].whitespace_width; | |
| 238 } | |
| 239 if (data[i].whitespace_height) { | |
| 240 symbol->whitespace_height = data[i].whitespace_height; | |
| 241 } | |
| 242 if (data[i].border_width) { | |
| 243 symbol->border_width = data[i].border_width; | |
| 244 } | |
| 245 if (data[i].scale != -1) { | |
| 246 symbol->scale = data[i].scale; | |
| 247 } | |
| 248 if (data[i].dot_size != -1) { | |
| 249 symbol->dot_size = data[i].dot_size; | |
| 250 } | |
| 251 if (data[i].text_gap) { | |
| 252 symbol->text_gap = data[i].text_gap; | |
| 253 } | |
| 254 if (data[i].guard_descent != -1) { | |
| 255 symbol->guard_descent = data[i].guard_descent; | |
| 256 } | |
| 257 if (data[i].warn_level != -1) { | |
| 258 symbol->warn_level = data[i].warn_level; | |
| 259 } | |
| 260 | |
| 261 ret = ZBarcode_Encode(symbol, TU(data[i].data), length); | |
| 262 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret, symbol->errtxt); | |
| 263 | |
| 264 ret = strcmp(symbol->errtxt, data[i].expected); | |
| 265 assert_zero(ret, "i:%d (%d) strcmp(%s, %s) %d != 0\n", i, data[i].symbology, symbol->errtxt, data[i].expected, ret); | |
| 266 | |
| 267 if (data[i].expected_symbology == -1) { | |
| 268 assert_equal(symbol->symbology, data[i].symbology, "i:%d symbol->symbology %d != original %d\n", i, symbol->symbology, data[i].symbology); | |
| 269 } else { | |
| 270 assert_equal(symbol->symbology, data[i].expected_symbology, "i:%d symbol->symbology %d != expected %d\n", i, symbol->symbology, data[i].expected_symbology); | |
| 271 } | |
| 272 | |
| 273 ZBarcode_Delete(symbol); | |
| 274 } | |
| 275 | |
| 276 testFinish(); | |
| 277 } | |
| 278 | |
| 279 static void test_checks_segs(const testCtx *const p_ctx) { | |
| 280 int debug = p_ctx->debug; | |
| 281 | |
| 282 struct item { | |
| 283 int symbology; | |
| 284 int option_1; | |
| 285 struct zint_seg segs[2]; | |
| 286 int seg_count; | |
| 287 int input_mode; | |
| 288 int eci; | |
| 289 int warn_level; | |
| 290 int ret; | |
| 291 | |
| 292 char *expected; | |
| 293 }; | |
| 294 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 295 static const struct item data[] = { | |
| 296 /* 0*/ { BARCODE_CODE128, -1, { { NULL, 0, 0 }, { NULL, 0, 0 } }, 0, -1, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 205: No input data" }, | |
| 297 /* 1*/ { BARCODE_CODE128, -1, { { NULL, 0, 0 }, { NULL, 0, 0 } }, 257, -1, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 771: Too many input segments (maximum 256)" }, | |
| 298 /* 2*/ { BARCODE_CODE128, -1, { { NULL, 0, 0 }, { NULL, 0, 0 } }, 1, -1, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 772: Input segment 0 source NULL" }, | |
| 299 /* 3*/ { BARCODE_CODE128, -1, { { TU(""), 0, 0 }, { NULL, 0, 0 } }, 1, -1, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 778: No input data" }, | |
| 300 /* 4*/ { BARCODE_CODE128, -1, { { TU("A"), 0, 0 }, { NULL, 0, 0 } }, 2, -1, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 772: Input segment 1 source NULL" }, | |
| 301 /* 5*/ { BARCODE_CODE128, -1, { { TU("A"), 0, 0 }, { TU(""), 0, 0 } }, 2, -1, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 773: Input segment 1 empty" }, | |
| 302 /* 6*/ { BARCODE_CODE128, -1, { { TU("A"), 0, 3 }, { TU("B"), 0, 0 } }, 2, -1, 4, -1, ZINT_ERROR_INVALID_OPTION, "Error 774: Symbol ECI '4' must match segment zero ECI '3'" }, | |
| 303 /* 7*/ { BARCODE_CODE128, -1, { { TU("A"), 0, 3 }, { TU("B"), 0, 4 } }, 2, -1, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 775: Symbology does not support multiple segments" }, | |
| 304 /* 8*/ { BARCODE_CODE128, -1, { { TU("A"), 0, 3 }, { NULL, 0, 0 } }, 1, -1, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 217: Symbology does not support ECI switching" }, | |
| 305 /* 9*/ { BARCODE_AZTEC, -1, { { TU("A"), 0, 3 }, { TU("B"), 0, 1 } }, 2, -1, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 218: ECI code '1' out of range (0 to 999999, excluding 1, 2, 14 and 19)" }, | |
| 306 /* 10*/ { BARCODE_AZTEC, -1, { { TU("A"), 0, 3 }, { TU("B"), 0, 4 } }, 2, GS1_MODE, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 776: GS1 mode not supported for multiple segments" }, | |
| 307 /* 11*/ { BARCODE_AZTEC, -1, { { TU("A"), 0, 3 }, { TU("\200"), 0, 4 } }, 2, UNICODE_MODE, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 245: Invalid UTF-8 in input" }, | |
| 308 /* 12*/ { BARCODE_AZTEC, -1, { { TU("A"), 0, 3 }, { TU("B"), 0, 4 } }, 2, -1, -1, -1, 0, "" }, | |
| 309 /* 13*/ { BARCODE_AZTEC, -1, { { TU("A"), 0, 0 }, { TU("B"), 0, 4 } }, 2, -1, 3, -1, 0, "" }, | |
| 310 /* 14*/ { BARCODE_AZTEC, -1, { { TU("A"), ZINT_MAX_DATA_LEN, 3 }, { TU("B"), 1, 4 } }, 2, -1, -1, -1, ZINT_ERROR_TOO_LONG, "Error 243: Input too long" }, | |
| 311 }; | |
| 312 const int data_size = ARRAY_SIZE(data); | |
| 313 int i, ret; | |
| 314 struct zint_symbol *symbol = NULL; | |
| 315 | |
| 316 testStartSymbol("test_checks_segs", &symbol); | |
| 317 | |
| 318 for (i = 0; i < data_size; i++) { | |
| 319 | |
| 320 if (testContinue(p_ctx, i)) continue; | |
| 321 | |
| 322 symbol = ZBarcode_Create(); | |
| 323 assert_nonnull(symbol, "Symbol not created\n"); | |
| 324 | |
| 325 testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].option_1, -1, -1, -1 /*output_options*/, NULL, 0, debug); | |
| 326 if (data[i].warn_level != -1) { | |
| 327 symbol->warn_level = data[i].warn_level; | |
| 328 } | |
| 329 | |
| 330 ret = ZBarcode_Encode_Segs(symbol, data[i].segs, data[i].seg_count); | |
| 331 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret, symbol->errtxt); | |
| 332 | |
| 333 ret = strcmp(symbol->errtxt, data[i].expected); | |
| 334 assert_zero(ret, "i:%d (%d) strcmp(%s, %s) %d != 0\n", i, data[i].symbology, symbol->errtxt, data[i].expected, ret); | |
| 335 | |
| 336 ZBarcode_Delete(symbol); | |
| 337 } | |
| 338 | |
| 339 testFinish(); | |
| 340 } | |
| 341 | |
| 342 static void test_input_data(const testCtx *const p_ctx) { | |
| 343 int debug = p_ctx->debug; | |
| 344 | |
| 345 struct item { | |
| 346 int symbology; | |
| 347 int input_mode; | |
| 348 char *data; | |
| 349 int length; | |
| 350 char *composite; | |
| 351 int ret; | |
| 352 | |
| 353 char *expected; | |
| 354 }; | |
| 355 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 356 static const struct item data[] = { | |
| 357 /* 0*/ { BARCODE_CODE128, -1, "1234", -1, "", 0, "" }, | |
| 358 /* 1*/ { BARCODE_GS1_128, -1, "[01]12345678901231", -1, "", 0, "" }, | |
| 359 /* 2*/ { BARCODE_GS1_128, -1, "", -1, "", ZINT_ERROR_INVALID_DATA, "Error 778: No input data" }, | |
| 360 /* 3*/ { BARCODE_GS1_128_CC, -1, "[01]12345678901231", -1, "[10]121212", 0, "" }, | |
| 361 /* 4*/ { BARCODE_GS1_128_CC, -1, "[01]12345678901231", -1, "", ZINT_ERROR_INVALID_DATA, "Error 779: No composite data (2D component)" }, | |
| 362 /* 5*/ { BARCODE_GS1_128_CC, -1, "", -1, "[10]121212", ZINT_ERROR_INVALID_OPTION, "Error 445: No primary (linear) message" }, | |
| 363 /* 6*/ { BARCODE_DATAMATRIX, -1, "", -1, "", ZINT_ERROR_INVALID_DATA, "Error 228: No input data (segment 0 empty)" }, | |
| 364 }; | |
| 365 const int data_size = ARRAY_SIZE(data); | |
| 366 int i, length, ret; | |
| 367 struct zint_symbol *symbol = NULL; | |
| 368 | |
| 369 char *text; | |
| 370 | |
| 371 testStartSymbol("test_input_data", &symbol); | |
| 372 | |
| 373 for (i = 0; i < data_size; i++) { | |
| 374 | |
| 375 if (testContinue(p_ctx, i)) continue; | |
| 376 | |
| 377 symbol = ZBarcode_Create(); | |
| 378 assert_nonnull(symbol, "Symbol not created\n"); | |
| 379 | |
| 380 if (is_composite(data[i].symbology)) { | |
| 381 text = data[i].composite; | |
| 382 strcpy(symbol->primary, data[i].data); | |
| 383 } else { | |
| 384 text = data[i].data; | |
| 385 } | |
| 386 length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, text, -1, debug); | |
| 387 | |
| 388 ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); | |
| 389 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret, symbol->errtxt); | |
| 390 | |
| 391 ret = strcmp(symbol->errtxt, data[i].expected); | |
| 392 assert_zero(ret, "i:%d (%d) strcmp(%s, %s) %d != 0\n", i, data[i].symbology, symbol->errtxt, data[i].expected, ret); | |
| 393 | |
| 394 ZBarcode_Delete(symbol); | |
| 395 } | |
| 396 | |
| 397 if (p_ctx->index == -1 && p_ctx->exclude[0] == -1) { | |
| 398 char data_buf[ZINT_MAX_DATA_LEN + 10]; | |
| 399 int expected_ret = ZINT_ERROR_TOO_LONG; | |
| 400 char *expected_errtxt[] = { "Error 797: Input too long", "Error 340: Input length 17399 too long (maximum 256)" }; | |
| 401 | |
| 402 symbol = ZBarcode_Create(); | |
| 403 assert_nonnull(symbol, "Symbol not created\n"); | |
| 404 | |
| 405 /* Caught by `ZBarcode_Encode_Segs()` de-escape loop */ | |
| 406 symbol->input_mode = ESCAPE_MODE; | |
| 407 testUtilStrCpyRepeat(data_buf, "A", ZINT_MAX_DATA_LEN); | |
| 408 data_buf[ZINT_MAX_DATA_LEN] = '\\'; | |
| 409 data_buf[ZINT_MAX_DATA_LEN + 1] = 'n'; | |
| 410 | |
| 411 ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, ZINT_MAX_DATA_LEN + 2); | |
| 412 assert_equal(ret, expected_ret, "ZBarcode_Encode(%d) ret %d != %d (%s)\n", symbol->symbology, ret, expected_ret, symbol->errtxt); | |
| 413 assert_zero(strcmp(symbol->errtxt, expected_errtxt[0]), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, expected_errtxt[0]); | |
| 414 | |
| 415 /* Passes de-escape loop, caught by `code128()` */ | |
| 416 symbol->errtxt[0] = '\0'; | |
| 417 data_buf[ZINT_MAX_DATA_LEN - 2] = '\\'; | |
| 418 data_buf[ZINT_MAX_DATA_LEN - 1] = 'n'; | |
| 419 | |
| 420 ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, ZINT_MAX_DATA_LEN); | |
| 421 assert_equal(ret, expected_ret, "ZBarcode_Encode(%d) ret %d != %d (%s)\n", symbol->symbology, ret, expected_ret, symbol->errtxt); | |
| 422 assert_zero(strcmp(symbol->errtxt, expected_errtxt[1]), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, expected_errtxt[1]); | |
| 423 | |
| 424 ZBarcode_Delete(symbol); | |
| 425 } | |
| 426 | |
| 427 testFinish(); | |
| 428 } | |
| 429 | |
| 430 static int test_prev_map_invalid_symbology(int *p_symbology) { | |
| 431 int symbology = *p_symbology; | |
| 432 int warn_number = 0; | |
| 433 | |
| 434 if (symbology < 1) { | |
| 435 warn_number = ZINT_WARN_INVALID_OPTION; | |
| 436 symbology = BARCODE_CODE128; | |
| 437 /* symbol->symbologys 1 to 126 are defined by tbarcode */ | |
| 438 } else if (symbology == 5) { | |
| 439 symbology = BARCODE_C25STANDARD; | |
| 440 } else if ((symbology >= 10) && (symbology <= 12)) { | |
| 441 symbology = BARCODE_EANX; | |
| 442 } else if (symbology == 15) { | |
| 443 symbology = BARCODE_EANX; | |
| 444 } else if (symbology == 17) { | |
| 445 symbology = BARCODE_UPCA; | |
| 446 } else if (symbology == 19) { | |
| 447 warn_number = ZINT_WARN_INVALID_OPTION; | |
| 448 symbology = BARCODE_CODABAR; | |
| 449 } else if (symbology == 26) { /* UPC-A up to tbarcode 9, ISSN for tbarcode 10+ */ | |
| 450 symbology = BARCODE_UPCA; | |
| 451 } else if (symbology == 27) { /* UPCD1 up to tbarcode 9, ISSN + 2 digit add-on for tbarcode 10+ */ | |
| 452 return ZINT_ERROR_INVALID_OPTION; | |
| 453 } else if (symbology == 33) { | |
| 454 symbology = BARCODE_GS1_128; | |
| 455 } else if (symbology == 36) { | |
| 456 symbology = BARCODE_UPCA; | |
| 457 } else if (symbology == 39) { | |
| 458 symbology = BARCODE_UPCE; | |
| 459 } else if ((symbology >= 41) && (symbology <= 45)) { | |
| 460 symbology = BARCODE_POSTNET; | |
| 461 } else if (symbology == 46) { | |
| 462 symbology = BARCODE_PLESSEY; | |
| 463 } else if (symbology == 48) { | |
| 464 symbology = BARCODE_NVE18; | |
| 465 } else if ((symbology == 59) || (symbology == 61)) { | |
| 466 symbology = BARCODE_CODE128; | |
| 467 } else if (symbology == 62) { | |
| 468 symbology = BARCODE_CODE93; | |
| 469 } else if ((symbology == 64) || (symbology == 65)) { | |
| 470 symbology = BARCODE_AUSPOST; | |
| 471 } else if (symbology == 78) { | |
| 472 symbology = BARCODE_DBAR_OMN; | |
| 473 } else if (symbology == 83) { | |
| 474 symbology = BARCODE_PLANET; | |
| 475 } else if (symbology == 88) { | |
| 476 symbology = BARCODE_GS1_128; | |
| 477 } else if (symbology == 91) { /* BC412 up to tbarcode 9, Code 32 for tbarcode 10+ */ | |
| 478 warn_number = ZINT_WARN_INVALID_OPTION; | |
| 479 symbology = BARCODE_CODE128; | |
| 480 } else if ((symbology >= 94) && (symbology <= 95)) { | |
| 481 warn_number = ZINT_WARN_INVALID_OPTION; | |
| 482 symbology = BARCODE_CODE128; | |
| 483 } else if (symbology == 100) { | |
| 484 symbology = BARCODE_HIBC_128; | |
| 485 } else if (symbology == 101) { | |
| 486 symbology = BARCODE_HIBC_39; | |
| 487 } else if (symbology == 103) { | |
| 488 symbology = BARCODE_HIBC_DM; | |
| 489 } else if (symbology == 105) { | |
| 490 symbology = BARCODE_HIBC_QR; | |
| 491 } else if (symbology == 107) { | |
| 492 symbology = BARCODE_HIBC_PDF; | |
| 493 } else if (symbology == 109) { | |
| 494 symbology = BARCODE_HIBC_MICPDF; | |
| 495 } else if (symbology == 111) { | |
| 496 symbology = BARCODE_HIBC_BLOCKF; | |
| 497 } else if ((symbology == 113) || (symbology == 114)) { | |
| 498 warn_number = ZINT_WARN_INVALID_OPTION; | |
| 499 symbology = BARCODE_CODE128; | |
| 500 } else if ((symbology >= 117) && (symbology <= 127)) { | |
| 501 if (symbology < 119 || symbology > 121) { /* BARCODE_MAILMARK_2D/4S/UPU_S10 */ | |
| 502 warn_number = ZINT_WARN_INVALID_OPTION; | |
| 503 symbology = BARCODE_CODE128; | |
| 504 } | |
| 505 /* Everything from 128 up is Zint-specific */ | |
| 506 } else if (symbology > BARCODE_LAST) { | |
| 507 warn_number = ZINT_WARN_INVALID_OPTION; | |
| 508 symbology = BARCODE_CODE128; | |
| 509 } | |
| 510 if (symbology == *p_symbology) { /* Should never happen */ | |
| 511 return ZINT_ERROR_ENCODING_PROBLEM; | |
| 512 } | |
| 513 | |
| 514 *p_symbology = symbology; | |
| 515 | |
| 516 return warn_number; | |
| 517 } | |
| 518 | |
| 519 static void test_symbologies(const testCtx *const p_ctx) { | |
| 520 int i, ret; | |
| 521 struct zint_symbol s_symbol = {0}; | |
| 522 struct zint_symbol *symbol = &s_symbol; | |
| 523 | |
| 524 testStart("test_symbologies"); | |
| 525 | |
| 526 for (i = -1; i < 148; i++) { | |
| 527 if (testContinue(p_ctx, i)) continue; | |
| 528 | |
| 529 symbol->symbology = i; | |
| 530 ret = ZBarcode_Encode(symbol, TU(""), 0); | |
| 531 assert_notequal(ret, ZINT_ERROR_ENCODING_PROBLEM, "i:%d Encoding problem (%s)\n", i, symbol->errtxt); | |
| 532 | |
| 533 if (!ZBarcode_ValidID(i)) { | |
| 534 int prev_symbology = i; | |
| 535 int prev_ret = test_prev_map_invalid_symbology(&prev_symbology); | |
| 536 if (ret != ZINT_ERROR_INVALID_DATA) { | |
| 537 assert_equal(prev_ret, ret, "i:%d prev_ret (%d) != ret (%d)\n", i, prev_ret, ret); | |
| 538 } | |
| 539 assert_equal(prev_symbology, symbol->symbology, "i:%d prev_symbology (%d) != symbol->symbology (%d)\n", | |
| 540 i, prev_symbology, symbol->symbology); | |
| 541 } else { | |
| 542 /* No input data */ | |
| 543 assert_equal(ret, ZINT_ERROR_INVALID_DATA, "i:%d ret (%d) != ZINT_ERROR_INVALID_DATA\n", i, ret); | |
| 544 } | |
| 545 } | |
| 546 | |
| 547 testFinish(); | |
| 548 } | |
| 549 | |
| 550 static void test_input_mode(const testCtx *const p_ctx) { | |
| 551 int debug = p_ctx->debug; | |
| 552 | |
| 553 struct item { | |
| 554 char *data; | |
| 555 int input_mode; | |
| 556 int ret; | |
| 557 | |
| 558 int expected_input_mode; | |
| 559 char *expected_errtxt; | |
| 560 }; | |
| 561 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 562 static const struct item data[] = { | |
| 563 /* 0*/ { "1234", DATA_MODE, 0, DATA_MODE, "" }, | |
| 564 /* 1*/ { "1234", DATA_MODE | ESCAPE_MODE, 0, DATA_MODE | ESCAPE_MODE, "" }, | |
| 565 /* 2*/ { "1234", UNICODE_MODE, 0, UNICODE_MODE, "" }, | |
| 566 /* 3*/ { "1234", UNICODE_MODE | ESCAPE_MODE, 0, UNICODE_MODE | ESCAPE_MODE, "" }, | |
| 567 /* 4*/ { "[01]12345678901231", GS1_MODE, 0, GS1_MODE, "" }, | |
| 568 /* 5*/ { "[01]12345678901231", GS1_MODE | ESCAPE_MODE, 0, GS1_MODE | ESCAPE_MODE, "" }, | |
| 569 /* 6*/ { "1234", 4 | ESCAPE_MODE, ZINT_WARN_INVALID_OPTION, DATA_MODE, "Warning 212: Invalid input mode - reset to DATA_MODE" }, /* Unknown mode reset to bare DATA_MODE. Note: now warns */ | |
| 570 /* 7*/ { "1234", -1, 0, DATA_MODE, "" }, | |
| 571 /* 8*/ { "1234", DATA_MODE | 0x10, 0, DATA_MODE | 0x10, "" }, /* Unknown flags kept (but ignored) */ | |
| 572 /* 9*/ { "1234", UNICODE_MODE | 0x10, 0, UNICODE_MODE | 0x10, "" }, | |
| 573 /* 10*/ { "[01]12345678901231", GS1_MODE | 0x20, 0, GS1_MODE | 0x20, "" }, | |
| 574 }; | |
| 575 const int data_size = ARRAY_SIZE(data); | |
| 576 int i, length, ret; | |
| 577 struct zint_symbol *symbol = NULL; | |
| 578 | |
| 579 testStartSymbol("test_input_mode", &symbol); | |
| 580 | |
| 581 for (i = 0; i < data_size; i++) { | |
| 582 | |
| 583 if (testContinue(p_ctx, i)) continue; | |
| 584 | |
| 585 symbol = ZBarcode_Create(); | |
| 586 assert_nonnull(symbol, "Symbol not created\n"); | |
| 587 | |
| 588 length = testUtilSetSymbol(symbol, BARCODE_CODE49 /*Supports GS1*/, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 589 | |
| 590 ret = ZBarcode_Encode(symbol, TU(data[i].data), length); | |
| 591 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 592 assert_equal(symbol->input_mode, data[i].expected_input_mode, "i:%d symbol->input_mode %d != %d\n", i, symbol->input_mode, data[i].expected_input_mode); | |
| 593 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d ZBarcode_Encode strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt); | |
| 594 | |
| 595 ZBarcode_Delete(symbol); | |
| 596 } | |
| 597 | |
| 598 testFinish(); | |
| 599 } | |
| 600 | |
| 601 static void test_escape_char_process(const testCtx *const p_ctx) { | |
| 602 int debug = p_ctx->debug; | |
| 603 | |
| 604 struct item { | |
| 605 int symbology; | |
| 606 int input_mode; | |
| 607 int eci; | |
| 608 char *data; | |
| 609 char *composite; | |
| 610 int ret; | |
| 611 int expected_width; | |
| 612 char *expected; | |
| 613 int compare_previous; | |
| 614 char *comment; | |
| 615 }; | |
| 616 static const struct item data[] = { | |
| 617 /* 0*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", "", 0, 26, "01 05 08 09 0A 0B 0C 0D 0E 1C 1E 1F EB 02 5D 81 21 0D 92 2E 3D FD B6 9A 37 2A CD 61 FB 95", 0, "" }, | |
| 618 /* 1*/ { BARCODE_CODABLOCKF, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", "", 0, 101, "(45) 67 62 43 40 44 47 48 29 6A 67 62 0B 49 4A 4B 4C 18 6A 67 62 0C 4D 5B 5D 5E 62 6A 67", 0, "" }, | |
| 619 /* 2*/ { BARCODE_CODE16K, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", "", 0, 70, "(20) 14 64 68 71 72 73 74 75 76 77 91 93 94 101 65 60 103 103 45 61", 0, "" }, | |
| 620 /* 3*/ { BARCODE_DOTCODE, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", "", 0, 28, "65 40 44 47 48 49 4A 4B 4C 4D 5B 5D 5E 6E 41 3C 6A", 0, "" }, | |
| 621 /* 4*/ { BARCODE_GRIDMATRIX, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", "", 0, 30, "30 1A 00 02 01 61 00 48 28 16 0C 06 46 63 51 74 05 38 00", 0, "" }, | |
| 622 /* 5*/ { BARCODE_HANXIN, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", "", 0, 23, "2F 80 10 72 09 28 B3 0D 6F F3 00 20 E8 F4 0A E0 00", 0, "" }, | |
| 623 /* 6*/ { BARCODE_MAXICODE, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", "", 0, 30, "(144) 04 3E 3E 00 04 07 08 09 0A 0B 03 3D 2C 24 19 1E 23 1B 18 0E 0C 0D 1E 3F 1D 1E 3C 31", 0, "" }, | |
| 624 /* 7*/ { BARCODE_PDF417, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", "", 0, 120, "(24) 16 901 0 23 655 318 98 18 461 639 893 122 129 92 900 900 872 438 359 646 522 773 831", 0, "" }, | |
| 625 /* 8*/ { BARCODE_ULTRA, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", "", 0, 20, "(15) 257 0 4 7 8 9 10 11 12 13 27 29 30 129 92", 0, "" }, | |
| 626 /* 9*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\d129\\o201\\\\", "", 0, 18, "(32) 01 05 08 09 0A 0B 0C 0D 0E 1C 1E 1F E7 32 45 DB 70 5D E3 16 7B 2B 44 60 E1 55 F7 08", 0, "" }, | |
| 627 /* 10*/ { BARCODE_HANXIN, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\d129\\o201\\\\", "", 0, 23, "2F 80 10 72 09 28 B3 0D 6F F3 00 30 E8 F4 0C 0C 0A E0 00 00 00", 0, "" }, | |
| 628 /* 11*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\c", "", ZINT_ERROR_INVALID_DATA, 0, "Error 234: Unrecognised escape character '\\c' in input", 0, "" }, | |
| 629 /* 12*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\", "", ZINT_ERROR_INVALID_DATA, 0, "Error 236: Incomplete escape character in input", 0, "" }, | |
| 630 /* 13*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\x", "", ZINT_ERROR_INVALID_DATA, 0, "Error 232: Incomplete '\\x' escape sequence in input", 0, "" }, | |
| 631 /* 14*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\x1", "", ZINT_ERROR_INVALID_DATA, 0, "Error 232: Incomplete '\\x' escape sequence in input", 0, "" }, | |
| 632 /* 15*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\x1g", "", ZINT_ERROR_INVALID_DATA, 0, "Error 238: Invalid character in escape sequence '\\x1g' in input (hexadecimal only)", 0, "" }, | |
| 633 /* 16*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\d", "", ZINT_ERROR_INVALID_DATA, 0, "Error 232: Incomplete '\\d' escape sequence in input", 0, "" }, | |
| 634 /* 17*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\d1", "", ZINT_ERROR_INVALID_DATA, 0, "Error 232: Incomplete '\\d' escape sequence in input", 0, "" }, | |
| 635 /* 18*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\d12", "", ZINT_ERROR_INVALID_DATA, 0, "Error 232: Incomplete '\\d' escape sequence in input", 0, "" }, | |
| 636 /* 19*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\d12a", "", ZINT_ERROR_INVALID_DATA, 0, "Error 238: Invalid character in escape sequence '\\d12a' in input (decimal only)", 0, "" }, | |
| 637 /* 20*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\d256", "", ZINT_ERROR_INVALID_DATA, 0, "Error 237: Value of escape sequence '\\d256' in input out of range (000 to 255)", 0, "" }, | |
| 638 /* 21*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\o", "", ZINT_ERROR_INVALID_DATA, 0, "Error 232: Incomplete '\\o' escape sequence in input", 0, "" }, | |
| 639 /* 22*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\o1", "", ZINT_ERROR_INVALID_DATA, 0, "Error 232: Incomplete '\\o' escape sequence in input", 0, "" }, | |
| 640 /* 23*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\o12", "", ZINT_ERROR_INVALID_DATA, 0, "Error 232: Incomplete '\\o' escape sequence in input", 0, "" }, | |
| 641 /* 24*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\o128", "", ZINT_ERROR_INVALID_DATA, 0, "Error 238: Invalid character in escape sequence '\\o128' in input (octal only)", 0, "" }, | |
| 642 /* 25*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\o400", "", ZINT_ERROR_INVALID_DATA, 0, "Error 237: Value of escape sequence '\\o400' in input out of range (000 to 377)", 0, "" }, | |
| 643 /* 26*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\xA01\\xFF", "", 0, 12, "EB 21 32 EB 80 D8 49 44 DC 7D 9E 3B", 0, "" }, | |
| 644 /* 27*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\d1601\\d255", "", 0, 12, "EB 21 32 EB 80 D8 49 44 DC 7D 9E 3B", 1, "" }, | |
| 645 /* 28*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\o2401\\o377", "", 0, 12, "EB 21 32 EB 80 D8 49 44 DC 7D 9E 3B", 1, "" }, | |
| 646 /* 29*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, "\\u00A01\\u00FF", "", 0, 12, "EB 21 32 EB 80 D8 49 44 DC 7D 9E 3B", 1, "" }, | |
| 647 /* 30*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, "\\U0000A01\\U0000FF", "", 0, 12, "EB 21 32 EB 80 D8 49 44 DC 7D 9E 3B", 1, "" }, | |
| 648 /* 31*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\xc3\\xbF", "", 0, 12, "EB 44 EB 40 81 30 87 17 C5 68 5C 91", 0, "" }, | |
| 649 /* 32*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\d195\\d191", "", 0, 12, "EB 44 EB 40 81 30 87 17 C5 68 5C 91", 1, "" }, | |
| 650 /* 33*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\o303\\o277", "", 0, 12, "EB 44 EB 40 81 30 87 17 C5 68 5C 91", 1, "" }, | |
| 651 /* 34*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\u00fF", "", 0, 12, "EB 44 EB 40 81 30 87 17 C5 68 5C 91", 1, "" }, | |
| 652 /* 35*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\U0000fF", "", 0, 12, "EB 44 EB 40 81 30 87 17 C5 68 5C 91", 1, "" }, | |
| 653 /* 36*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, "\\xc3\\xbF", "", 0, 10, "EB 80 81 47 1E 45 FC 93", 0, "" }, | |
| 654 /* 37*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, "\\d195\\d191", "", 0, 10, "EB 80 81 47 1E 45 FC 93", 1, "" }, | |
| 655 /* 38*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, "\\o303\\o277", "", 0, 10, "EB 80 81 47 1E 45 FC 93", 1, "" }, | |
| 656 /* 39*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, "\\u00fF", "", 0, 10, "EB 80 81 47 1E 45 FC 93", 1, "" }, | |
| 657 /* 40*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, "\\U0000fF", "", 0, 10, "EB 80 81 47 1E 45 FC 93", 1, "" }, | |
| 658 /* 41*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\u", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\u' escape sequence in input", 0, "" }, | |
| 659 /* 42*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\uF", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\u' escape sequence in input", 0, "" }, | |
| 660 /* 43*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\u0F", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\u' escape sequence in input", 0, "" }, | |
| 661 /* 44*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\uFG", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\u' escape sequence in input", 0, "" }, | |
| 662 /* 45*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\u00F", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\u' escape sequence in input", 0, "" }, | |
| 663 /* 46*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\u00FG", "", ZINT_ERROR_INVALID_DATA, 0, "Error 211: Invalid character for '\\u' escape sequence in input (hexadecimal only)", 0, "" }, | |
| 664 /* 47*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\ufffe", "", ZINT_ERROR_INVALID_DATA, 0, "Error 246: Value of escape sequence '\\ufffe' in input out of range", 0, "Reversed BOM" }, | |
| 665 /* 48*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\ud800", "", ZINT_ERROR_INVALID_DATA, 0, "Error 246: Value of escape sequence '\\ud800' in input out of range", 0, "Surrogate" }, | |
| 666 /* 49*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\udfff", "", ZINT_ERROR_INVALID_DATA, 0, "Error 246: Value of escape sequence '\\udfff' in input out of range", 0, "Surrogate" }, | |
| 667 /* 50*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\uffff", "", 0, 12, "E7 2C B0 16 AB A1 1F 85 EB 50 A1 4C", 0, "" }, | |
| 668 /* 51*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 17, "\\xE2\\x82\\xAC", "", 0, 12, "F1 12 EB 25 81 4A 0A 8C 31 AC E3 2E", 0, "Zint manual 4.10 Ex1" }, | |
| 669 /* 52*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 17, "\\u20AC", "", 0, 12, "F1 12 EB 25 81 4A 0A 8C 31 AC E3 2E", 1, "" }, | |
| 670 /* 53*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 17, "\\U0020AC", "", 0, 12, "F1 12 EB 25 81 4A 0A 8C 31 AC E3 2E", 1, "" }, | |
| 671 /* 54*/ { BARCODE_DATAMATRIX, DATA_MODE, 17, "\\xA4", "", 0, 12, "F1 12 EB 25 81 4A 0A 8C 31 AC E3 2E", 1, "" }, | |
| 672 /* 55*/ { BARCODE_DATAMATRIX, DATA_MODE, 28, "\\xB1\\x60", "", 0, 12, "F1 1D EB 32 61 D9 1C 0C C2 46 C3 B2", 0, "Zint manual 4.10 Ex2" }, | |
| 673 /* 56*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 28, "\\u5E38", "", 0, 12, "F1 1D EB 32 61 D9 1C 0C C2 46 C3 B2", 1, "" }, | |
| 674 /* 57*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 28, "\\U005E38", "", 0, 12, "F1 1D EB 32 61 D9 1C 0C C2 46 C3 B2", 1, "" }, | |
| 675 /* 58*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, "\\u007F", "", 0, 10, "80 81 46 73 64 88 6A 84", 0, "" }, | |
| 676 /* 59*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, "\\U00007F", "", 0, 10, "80 81 46 73 64 88 6A 84", 0, "" }, | |
| 677 /* 60*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\U", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\U' escape sequence in input", 0, "" }, | |
| 678 /* 61*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\UF", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\U' escape sequence in input", 0, "" }, | |
| 679 /* 62*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\U0F", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\U' escape sequence in input", 0, "" }, | |
| 680 /* 63*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\UFG", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\U' escape sequence in input", 0, "" }, | |
| 681 /* 64*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\U00F", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\U' escape sequence in input", 0, "" }, | |
| 682 /* 65*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\U00FG", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\U' escape sequence in input", 0, "" }, | |
| 683 /* 66*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\Ufffe", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\U' escape sequence in input", 0, "Reversed BOM" }, | |
| 684 /* 67*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\Ud800", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\U' escape sequence in input", 0, "Surrogate" }, | |
| 685 /* 68*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\Udfff", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\U' escape sequence in input", 0, "Surrogate" }, | |
| 686 /* 69*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\U000F", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\U' escape sequence in input", 0, "" }, | |
| 687 /* 70*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\U0000F", "", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete '\\U' escape sequence in input", 0, "" }, | |
| 688 /* 71*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\U110000", "", ZINT_ERROR_INVALID_DATA, 0, "Error 246: Value of escape sequence '\\U110000' in input out of range", 0, "" }, | |
| 689 /* 72*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 25, "\\U10FFFF", "", 0, 14, "F1 1A E7 57 C7 81 F7 AC 09 06 28 51 F3 00 E1 8C 2A 1C", 0, "" }, | |
| 690 /* 73*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 26, "\\U10FFFF", "", 0, 14, "F1 1B E7 57 E0 11 D7 6C 4F 45 E2 B3 FF F1 72 AB 54 9F", 0, "" }, | |
| 691 /* 74*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 32, "\\U10FFFF", "", 0, 14, "F1 21 EB 64 33 EB 1B 36 1D F7 B1 6D 8C A6 34 64 19 3A", 0, "" }, | |
| 692 /* 75*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 33, "\\U10FFFF", "", 0, 14, "F1 22 E7 57 EB 5D 17 8C C1 B0 B6 B2 53 78 E4 7D 61 CB", 0, "" }, | |
| 693 /* 76*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 34, "\\U10FFFF", "", 0, 14, "F1 23 01 11 EB 80 EB 80 90 33 51 1B FA AE 78 F7 05 44", 0, "" }, | |
| 694 /* 77*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 35, "\\U10FFFF", "", 0, 14, "F1 24 EB 80 EB 80 11 01 17 BA C6 05 9F 4C EA E5 18 31", 0, "" }, | |
| 695 /* 78*/ { BARCODE_GS1_128_CC, GS1_MODE, -1, "[20]10", "[10]A", 0, 99, "(7) 105 102 20 10 100 59 106", 0, "" }, | |
| 696 /* 79*/ { BARCODE_GS1_128_CC, GS1_MODE, -1, "[2\\x30]1\\d048", "[\\x310]\\x41", 0, 99, "(7) 105 102 20 10 100 59 106", 1, "" }, | |
| 697 /* 80*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\^A1", "", ZINT_ERROR_INVALID_DATA, 0, "Error 798: Escape '\\^' only valid for Code 128 in extra escape mode", 0, "" }, | |
| 698 /* 81*/ { BARCODE_CODE128, DATA_MODE | EXTRA_ESCAPE_MODE, -1, "\\^A1", "", 0, 46, "(4) 103 17 17 106", 0, "" }, | |
| 699 /* 82*/ { BARCODE_CODE128, EXTRA_ESCAPE_MODE, -1, "\\^", "", 0, 57, "(5) 104 60 62 82 106", 0, "Partial special escape '\\^' at end allowed" }, | |
| 700 /* 83*/ { BARCODE_CODE128, EXTRA_ESCAPE_MODE, -1, "\\^D1", "", 0, 79, "(7) 104 60 62 36 17 52 106", 0, "Unknown special escapes passed straight thu" }, | |
| 701 /* 84*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\w", "", ZINT_ERROR_INVALID_DATA, 0, "Error 234: Unrecognised escape character '\\w' in input", 0, "" }, | |
| 702 }; | |
| 703 const int data_size = ARRAY_SIZE(data); | |
| 704 int i, length, ret; | |
| 705 struct zint_symbol *symbol = NULL; | |
| 706 | |
| 707 char escaped[1024]; | |
| 708 char escaped_composite[1024]; | |
| 709 struct zint_symbol previous_symbol; | |
| 710 char *input_filename = "test_escape.txt"; | |
| 711 | |
| 712 char *text; | |
| 713 | |
| 714 testStartSymbol("test_escape_char_process", &symbol); | |
| 715 | |
| 716 for (i = 0; i < data_size; i++) { | |
| 717 | |
| 718 if (testContinue(p_ctx, i)) continue; | |
| 719 | |
| 720 symbol = ZBarcode_Create(); | |
| 721 assert_nonnull(symbol, "Symbol not created\n"); | |
| 722 | |
| 723 if (is_composite(data[i].symbology)) { | |
| 724 text = data[i].composite; | |
| 725 strcpy(symbol->primary, data[i].data); | |
| 726 } else { | |
| 727 text = data[i].data; | |
| 728 } | |
| 729 | |
| 730 debug |= ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */ | |
| 731 | |
| 732 length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode | ESCAPE_MODE, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, text, -1, debug); | |
| 733 | |
| 734 ret = ZBarcode_Encode(symbol, TU(text), length); | |
| 735 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 736 | |
| 737 if (p_ctx->generate) { | |
| 738 printf(" /*%3d*/ { %s, %s, %d, \"%s\", \"%s\", %s, %d, \"%s\", %d, \"%s\" },\n", | |
| 739 i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci, | |
| 740 testUtilEscape(data[i].data, length, escaped, ARRAY_SIZE(escaped)), | |
| 741 testUtilEscape(data[i].composite, (int) strlen(data[i].composite), escaped_composite, ARRAY_SIZE(escaped_composite)), | |
| 742 testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].compare_previous, data[i].comment); | |
| 743 } else { | |
| 744 assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected); | |
| 745 | |
| 746 if (ret < ZINT_ERROR) { | |
| 747 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); | |
| 748 if (p_ctx->index == -1 && data[i].compare_previous) { | |
| 749 ret = testUtilSymbolCmp(symbol, &previous_symbol); | |
| 750 assert_zero(ret, "i:%d testUtilSymbolCmp ret %d != 0\n", i, ret); | |
| 751 } | |
| 752 } | |
| 753 memcpy(&previous_symbol, symbol, sizeof(previous_symbol)); | |
| 754 | |
| 755 if (ret < ZINT_ERROR && !data[i].composite[0]) { | |
| 756 /* Test from input file */ | |
| 757 FILE *fp; | |
| 758 struct zint_symbol *symbol2; | |
| 759 | |
| 760 fp = testUtilOpen(input_filename, "wb"); | |
| 761 assert_nonnull(fp, "i:%d testUtilOpen(%s) failed\n", i, input_filename); | |
| 762 assert_notequal(fputs(data[i].data, fp), EOF, "i%d fputs(%s) failed == EOF (%d)\n", i, data[i].data, ferror(fp)); | |
| 763 assert_zero(fclose(fp), "i%d fclose() failed\n", i); | |
| 764 | |
| 765 symbol2 = ZBarcode_Create(); | |
| 766 assert_nonnull(symbol, "Symbol2 not created\n"); | |
| 767 | |
| 768 symbol2->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */ | |
| 769 | |
| 770 (void) testUtilSetSymbol(symbol2, data[i].symbology, data[i].input_mode | ESCAPE_MODE, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 771 | |
| 772 ret = ZBarcode_Encode_File(symbol2, input_filename); | |
| 773 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_File ret %d != %d (%s)\n", i, ret, data[i].ret, symbol2->errtxt); | |
| 774 assert_zero(strcmp(symbol2->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol2->errtxt, data[i].expected); | |
| 775 | |
| 776 ret = testUtilSymbolCmp(symbol2, symbol); | |
| 777 assert_zero(ret, "i:%d testUtilSymbolCmp symbol2 ret %d != 0\n", i, ret); | |
| 778 | |
| 779 assert_zero(testUtilRemove(input_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input_filename, errno, strerror(errno)); | |
| 780 | |
| 781 ZBarcode_Delete(symbol2); | |
| 782 } | |
| 783 } | |
| 784 | |
| 785 ZBarcode_Delete(symbol); | |
| 786 } | |
| 787 | |
| 788 testFinish(); | |
| 789 } | |
| 790 | |
| 791 INTERNAL int escape_char_process_test(struct zint_symbol *symbol, unsigned char *input_string, int *p_length, | |
| 792 unsigned char *escaped_string); | |
| 793 | |
| 794 static void test_escape_char_process_test(const testCtx *const p_ctx) { | |
| 795 | |
| 796 struct item { | |
| 797 int symbology; | |
| 798 int input_mode; | |
| 799 char *data; | |
| 800 int ret; | |
| 801 char *expected; | |
| 802 int expected_len; | |
| 803 }; | |
| 804 static const struct item data[] = { | |
| 805 /* 0*/ { 0, 0, "BLANK", 0, "BLANK", 5 }, | |
| 806 /* 1*/ { 0, 0, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\\\o201\\d255", 0, "\000\004\a\b\t\n\v\f\r\033\035\036\201\\\201\377", 16 }, | |
| 807 /* 2*/ { 0, 0, "\\U010283", 0, "\360\220\212\203", 4 }, | |
| 808 /* 3*/ { 0, 0, "\\u007F\\u0080\\u011E\\u13C9\\U010283", 0, "\177\302\200\304\236\341\217\211\360\220\212\203", 12 }, | |
| 809 /* 4*/ { BARCODE_CODE128, EXTRA_ESCAPE_MODE, "\\^A\\^^\\^B", 0, "\\^A\\^^\\^B", 9 }, | |
| 810 }; | |
| 811 const int data_size = ARRAY_SIZE(data); | |
| 812 int i, length, ret; | |
| 813 | |
| 814 | |
| 815 testStart("test_escape_char_process_test"); | |
| 816 | |
| 817 for (i = 0; i < data_size; i++) { | |
| 818 | |
| 819 struct zint_symbol s_symbol = {0}; | |
| 820 struct zint_symbol *symbol = &s_symbol; | |
| 821 int escaped_len; | |
| 822 char escaped[1024]; | |
| 823 | |
| 824 if (testContinue(p_ctx, i)) continue; | |
| 825 | |
| 826 symbol->symbology = data[i].symbology; | |
| 827 symbol->input_mode = data[i].input_mode; | |
| 828 length = (int) strlen(data[i].data); | |
| 829 | |
| 830 escaped_len = length; | |
| 831 ret = escape_char_process_test(symbol, (unsigned char *) data[i].data, &escaped_len, NULL); | |
| 832 assert_equal(ret, data[i].ret, "i:%d escape_char_process_test(NULL) ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 833 assert_equal(escaped_len, data[i].expected_len, "i:%d NULL escaped_len %d != %d\n", i, escaped_len, data[i].expected_len); | |
| 834 | |
| 835 memset(escaped, 0xDD, sizeof(escaped)); | |
| 836 | |
| 837 escaped_len = length; | |
| 838 ret = escape_char_process_test(symbol, (unsigned char *) data[i].data, &escaped_len, (unsigned char *) escaped); | |
| 839 assert_equal(ret, data[i].ret, "i:%d escape_char_process_test(escaped) ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 840 assert_equal(escaped_len, data[i].expected_len, "i:%d escaped escaped_len %d != %d\n", i, escaped_len, data[i].expected_len); | |
| 841 | |
| 842 assert_zero(memcmp(escaped, data[i].expected, escaped_len), "i:%d memcmp() != 0\n", i); | |
| 843 assert_zero(escaped[escaped_len], "i:%d escaped[%d] not NUL-terminated (0x%X)\n", i, escaped_len, escaped[escaped_len]); | |
| 844 } | |
| 845 | |
| 846 testFinish(); | |
| 847 } | |
| 848 | |
| 849 static void test_cap(const testCtx *const p_ctx) { | |
| 850 | |
| 851 struct item { | |
| 852 int symbology; | |
| 853 unsigned cap_flag; | |
| 854 unsigned int expected; | |
| 855 }; | |
| 856 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 857 static const struct item data[] = { | |
| 858 /* 0*/ { BARCODE_CODE128, ZINT_CAP_HRT, ZINT_CAP_HRT }, | |
| 859 /* 1*/ { BARCODE_CODE128, ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_GS1, ZINT_CAP_HRT | ZINT_CAP_STACKABLE }, | |
| 860 /* 2*/ { BARCODE_PDF417, ZINT_CAP_HRT | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE, ZINT_CAP_ECI | ZINT_CAP_READER_INIT }, | |
| 861 /* 3*/ { BARCODE_QRCODE, ZINT_CAP_HRT | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP | ZINT_CAP_COMPLIANT_HEIGHT, ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP }, | |
| 862 /* 4*/ { BARCODE_EANX_CC, ZINT_CAP_HRT | ZINT_CAP_COMPOSITE | ZINT_CAP_EXTENDABLE | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_QUIET_ZONES | ZINT_CAP_COMPLIANT_HEIGHT, ZINT_CAP_HRT | ZINT_CAP_COMPOSITE | ZINT_CAP_EXTENDABLE | ZINT_CAP_GS1 | ZINT_CAP_QUIET_ZONES | ZINT_CAP_COMPLIANT_HEIGHT }, | |
| 863 /* 5*/ { BARCODE_HANXIN, ZINT_CAP_DOTTY | ZINT_CAP_QUIET_ZONES | ZINT_CAP_FIXED_RATIO | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK, ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK }, | |
| 864 /* 6*/ { BARCODE_CODE11, ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_FIXED_RATIO | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_COMPLIANT_HEIGHT, 0 }, | |
| 865 /* 7*/ { BARCODE_POSTNET, ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_EXTENDABLE | ZINT_CAP_COMPOSITE | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP, 0 }, | |
| 866 /* 8*/ { 0, 0, 0 }, | |
| 867 }; | |
| 868 const int data_size = ARRAY_SIZE(data); | |
| 869 int i; | |
| 870 unsigned int uret; | |
| 871 | |
| 872 testStart("test_cap"); | |
| 873 | |
| 874 for (i = 0; i < data_size; i++) { | |
| 875 | |
| 876 if (testContinue(p_ctx, i)) continue; | |
| 877 | |
| 878 uret = ZBarcode_Cap(data[i].symbology, data[i].cap_flag); | |
| 879 assert_equal(uret, data[i].expected, "i:%d ZBarcode_Cap(%s, 0x%X) 0x%X != 0x%X\n", i, testUtilBarcodeName(data[i].symbology), data[i].cap_flag, uret, data[i].expected); | |
| 880 } | |
| 881 | |
| 882 testFinish(); | |
| 883 } | |
| 884 | |
| 885 static void test_cap_compliant_height(const testCtx *const p_ctx) { | |
| 886 int symbol_id; | |
| 887 unsigned int uret; | |
| 888 | |
| 889 testStart("test_cap_compliant_height"); | |
| 890 | |
| 891 for (symbol_id = 1; symbol_id <= BARCODE_LAST; symbol_id++) { | |
| 892 if (!ZBarcode_ValidID(symbol_id)) continue; | |
| 893 if (testContinue(p_ctx, symbol_id)) continue; | |
| 894 | |
| 895 uret = ZBarcode_Cap(symbol_id, ZINT_CAP_COMPLIANT_HEIGHT); | |
| 896 | |
| 897 switch (symbol_id) { | |
| 898 /*case BARCODE_CODE11: TODO: Find doc */ | |
| 899 case BARCODE_C25INTER: | |
| 900 case BARCODE_CODE39: | |
| 901 case BARCODE_EXCODE39: | |
| 902 case BARCODE_EANX: | |
| 903 case BARCODE_EANX_CHK: | |
| 904 case BARCODE_GS1_128: | |
| 905 case BARCODE_CODABAR: | |
| 906 /*case BARCODE_DPLEIT: TODO: Find doc */ | |
| 907 /*case BARCODE_DPIDENT: TODO: Find doc */ | |
| 908 case BARCODE_CODE16K: | |
| 909 case BARCODE_CODE49: | |
| 910 case BARCODE_CODE93: | |
| 911 /*case BARCODE_FLAT: TODO: Find doc */ | |
| 912 case BARCODE_DBAR_OMN: | |
| 913 case BARCODE_DBAR_LTD: | |
| 914 case BARCODE_DBAR_EXP: | |
| 915 case BARCODE_TELEPEN: | |
| 916 case BARCODE_UPCA: | |
| 917 case BARCODE_UPCA_CHK: | |
| 918 case BARCODE_UPCE: | |
| 919 case BARCODE_UPCE_CHK: | |
| 920 case BARCODE_POSTNET: | |
| 921 /*case BARCODE_MSI_PLESSEY: TODO: Find doc */ | |
| 922 case BARCODE_FIM: | |
| 923 case BARCODE_LOGMARS: | |
| 924 case BARCODE_PHARMA: | |
| 925 case BARCODE_PZN: | |
| 926 case BARCODE_PHARMA_TWO: | |
| 927 case BARCODE_CEPNET: | |
| 928 case BARCODE_AUSPOST: | |
| 929 case BARCODE_AUSREPLY: | |
| 930 case BARCODE_AUSROUTE: | |
| 931 case BARCODE_AUSREDIRECT: | |
| 932 case BARCODE_ISBNX: | |
| 933 case BARCODE_RM4SCC: | |
| 934 case BARCODE_EAN14: | |
| 935 /*case BARCODE_VIN: Spec unlikely */ | |
| 936 case BARCODE_CODABLOCKF: | |
| 937 case BARCODE_NVE18: | |
| 938 case BARCODE_JAPANPOST: | |
| 939 /*case BARCODE_KOREAPOST: TODO: Find doc */ | |
| 940 case BARCODE_DBAR_STK: | |
| 941 case BARCODE_DBAR_OMNSTK: | |
| 942 case BARCODE_DBAR_EXPSTK: | |
| 943 case BARCODE_PLANET: | |
| 944 case BARCODE_USPS_IMAIL: | |
| 945 /*case BARCODE_PLESSEY: TODO: Find doc */ | |
| 946 case BARCODE_TELEPEN_NUM: | |
| 947 case BARCODE_ITF14: | |
| 948 case BARCODE_KIX: | |
| 949 case BARCODE_DPD: | |
| 950 case BARCODE_HIBC_39: | |
| 951 case BARCODE_HIBC_BLOCKF: | |
| 952 case BARCODE_UPU_S10: | |
| 953 case BARCODE_MAILMARK_4S: | |
| 954 case BARCODE_CODE32: | |
| 955 case BARCODE_EANX_CC: | |
| 956 case BARCODE_GS1_128_CC: | |
| 957 case BARCODE_DBAR_OMN_CC: | |
| 958 case BARCODE_DBAR_LTD_CC: | |
| 959 case BARCODE_DBAR_EXP_CC: | |
| 960 case BARCODE_UPCA_CC: | |
| 961 case BARCODE_UPCE_CC: | |
| 962 case BARCODE_DBAR_STK_CC: | |
| 963 case BARCODE_DBAR_OMNSTK_CC: | |
| 964 case BARCODE_DBAR_EXPSTK_CC: | |
| 965 case BARCODE_CHANNEL: | |
| 966 case BARCODE_BC412: | |
| 967 case BARCODE_DXFILMEDGE: | |
| 968 /* Make sure ZINT_CAP_COMPLIANT_HEIGHT set for those that have it */ | |
| 969 assert_equal(uret, ZINT_CAP_COMPLIANT_HEIGHT, "symbol_id %d (%s) uret 0x%X != ZINT_CAP_COMPLIANT_HEIGHT\n", symbol_id, testUtilBarcodeName(symbol_id), uret); | |
| 970 break; | |
| 971 default: | |
| 972 /* And not set for those that don't */ | |
| 973 assert_zero(uret, "symbol_id %d (%s) uret 0x%X non-zero\n", symbol_id, testUtilBarcodeName(symbol_id), uret); | |
| 974 break; | |
| 975 } | |
| 976 } | |
| 977 | |
| 978 testFinish(); | |
| 979 } | |
| 980 | |
| 981 static void test_encode_file_empty(const testCtx *const p_ctx) { | |
| 982 int ret; | |
| 983 struct zint_symbol *symbol = NULL; | |
| 984 char filename[] = "in.bin"; | |
| 985 FILE *fstream; | |
| 986 | |
| 987 (void)p_ctx; | |
| 988 | |
| 989 testStartSymbol("test_encode_file_empty", &symbol); | |
| 990 | |
| 991 symbol = ZBarcode_Create(); | |
| 992 assert_nonnull(symbol, "Symbol not created\n"); | |
| 993 | |
| 994 (void) testUtilRemove(filename); /* In case junk hanging around */ | |
| 995 | |
| 996 fstream = testUtilOpen(filename, "w+"); | |
| 997 assert_nonnull(fstream, "testUtilOpen(%s) failed (%d)\n", filename, errno); | |
| 998 ret = fclose(fstream); | |
| 999 assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret); | |
| 1000 | |
| 1001 ret = ZBarcode_Encode_File(symbol, filename); | |
| 1002 assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File empty ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt); | |
| 1003 | |
| 1004 ret = testUtilRemove(filename); | |
| 1005 assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno)); | |
| 1006 | |
| 1007 ZBarcode_Delete(symbol); | |
| 1008 | |
| 1009 testFinish(); | |
| 1010 } | |
| 1011 | |
| 1012 static void test_encode_file_too_large(const testCtx *const p_ctx) { | |
| 1013 char filename[] = "in.bin"; | |
| 1014 FILE *fstream; | |
| 1015 int ret; | |
| 1016 struct zint_symbol *symbol = NULL; | |
| 1017 char buf[ZINT_MAX_DATA_LEN + 1] = {0}; | |
| 1018 | |
| 1019 (void)p_ctx; | |
| 1020 | |
| 1021 testStartSymbol("test_encode_file_too_large", &symbol); | |
| 1022 | |
| 1023 symbol = ZBarcode_Create(); | |
| 1024 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1025 | |
| 1026 (void) testUtilRemove(filename); /* In case junk hanging around */ | |
| 1027 | |
| 1028 fstream = testUtilOpen(filename, "w+"); | |
| 1029 assert_nonnull(fstream, "testUtilOpen(%s) failed (%d)\n", filename, errno); | |
| 1030 ret = (int) fwrite(buf, 1, sizeof(buf), fstream); | |
| 1031 assert_equal(ret, sizeof(buf), "fwrite return value: %d != %d\n", ret, (int)sizeof(buf)); | |
| 1032 ret = fclose(fstream); | |
| 1033 assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret); | |
| 1034 | |
| 1035 ret = ZBarcode_Encode_File(symbol, filename); | |
| 1036 assert_equal(ret, ZINT_ERROR_TOO_LONG, "ZBarcode_Encode_File too large ret %d != ZINT_ERROR_TOO_LONG (%s)\n", ret, symbol->errtxt); | |
| 1037 | |
| 1038 ret = testUtilRemove(filename); | |
| 1039 assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno)); | |
| 1040 | |
| 1041 ZBarcode_Delete(symbol); | |
| 1042 | |
| 1043 testFinish(); | |
| 1044 } | |
| 1045 | |
| 1046 /* #181 Nico Gunkel OSS-Fuzz */ | |
| 1047 static void test_encode_file_unreadable(const testCtx *const p_ctx) { | |
| 1048 #ifndef _WIN32 | |
| 1049 int ret; | |
| 1050 char filename[] = "in.bin"; | |
| 1051 | |
| 1052 char buf[ZINT_MAX_DATA_LEN + 1] = {0}; | |
| 1053 int fd; | |
| 1054 #endif | |
| 1055 struct zint_symbol *symbol = NULL; | |
| 1056 | |
| 1057 (void)p_ctx; | |
| 1058 | |
| 1059 testStartSymbol("test_encode_file_unreadable", &symbol); | |
| 1060 | |
| 1061 #ifdef _WIN32 | |
| 1062 testSkip("Test not implemented on Windows"); | |
| 1063 #else | |
| 1064 if (getuid() == 0) { | |
| 1065 testSkip("Test not available as root"); | |
| 1066 return; | |
| 1067 } | |
| 1068 | |
| 1069 symbol = ZBarcode_Create(); | |
| 1070 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1071 | |
| 1072 /* Unreadable file */ | |
| 1073 fd = creat(filename, S_IWUSR); | |
| 1074 assert_notequal(fd, -1, "Unreadable input file (%s) not created == -1 (%d: %s)\n", filename, errno, strerror(errno)); | |
| 1075 ret = write(fd, buf, 1); | |
| 1076 assert_equal(ret, 1, "Unreadable write ret %d != 1\n", ret); | |
| 1077 ret = close(fd); | |
| 1078 assert_zero(ret, "Unreadable close(%s) != 0(%d: %s)\n", filename, errno, strerror(errno)); | |
| 1079 | |
| 1080 ret = ZBarcode_Encode_File(symbol, filename); | |
| 1081 assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File unreadable ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt); | |
| 1082 | |
| 1083 ret = testUtilRemove(filename); | |
| 1084 assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno)); | |
| 1085 | |
| 1086 ZBarcode_Delete(symbol); | |
| 1087 | |
| 1088 testFinish(); | |
| 1089 #endif /* _WIN32 */ | |
| 1090 } | |
| 1091 | |
| 1092 /* #181 Nico Gunkel OSS-Fuzz (buffer not freed on fread() error) Note: unable to reproduce fread() error using this method */ | |
| 1093 static void test_encode_file_directory(const testCtx *const p_ctx) { | |
| 1094 int ret; | |
| 1095 struct zint_symbol *symbol = NULL; | |
| 1096 char dirname[] = "in_dir"; | |
| 1097 | |
| 1098 (void)p_ctx; | |
| 1099 | |
| 1100 testStartSymbol("test_encode_file_directory", &symbol); | |
| 1101 | |
| 1102 #if defined(__NetBSD__) || defined(_AIX) | |
| 1103 /* Reading a directory works on NetBSD, and get `code128()` ZINT_ERROR_TOO_LONG instead */ | |
| 1104 (void)ret; (void)symbol; (void)dirname; | |
| 1105 testSkip("Test not implemented on NetBSD or AIX"); | |
| 1106 #else | |
| 1107 symbol = ZBarcode_Create(); | |
| 1108 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1109 | |
| 1110 (void) testUtilRmDir(dirname); /* In case junk hanging around */ | |
| 1111 ret = testUtilMkDir(dirname); | |
| 1112 assert_zero(ret, "testUtilMkDir(%s) %d != 0 (%d: %s)\n", dirname, ret, errno, strerror(errno)); | |
| 1113 | |
| 1114 ret = ZBarcode_Encode_File(symbol, dirname); | |
| 1115 assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt); | |
| 1116 | |
| 1117 ret = testUtilRmDir(dirname); | |
| 1118 assert_zero(ret, "testUtilRmDir(%s) %d != 0 (%d: %s)\n", dirname, ret, errno, strerror(errno)); | |
| 1119 | |
| 1120 ZBarcode_Delete(symbol); | |
| 1121 | |
| 1122 testFinish(); | |
| 1123 #endif /* __NetBSD__ */ | |
| 1124 } | |
| 1125 | |
| 1126 static void test_encode_file(const testCtx *const p_ctx) { | |
| 1127 int ret; | |
| 1128 struct zint_symbol *symbol = NULL; | |
| 1129 char *data = "1"; | |
| 1130 char *filename = "test_encode_file_in.txt"; | |
| 1131 char *outfile = "test_encode_file_out.gif"; | |
| 1132 FILE *fp; | |
| 1133 | |
| 1134 (void)p_ctx; | |
| 1135 | |
| 1136 testStartSymbol("test_encode_file", &symbol); | |
| 1137 | |
| 1138 (void) testUtilRemove(filename); /* In case junk hanging around */ | |
| 1139 (void) testUtilRemove(outfile); /* In case junk hanging around */ | |
| 1140 | |
| 1141 fp = testUtilOpen(filename, "w+"); | |
| 1142 assert_nonnull(fp, "testUtilOpen(%s) failed (%d)\n", filename, errno); | |
| 1143 assert_notequal(fputs(data, fp), EOF, "fputs(%s) failed == EOF (%d)\n", data, ferror(fp)); | |
| 1144 ret = fclose(fp); | |
| 1145 assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret); | |
| 1146 | |
| 1147 { | |
| 1148 symbol = ZBarcode_Create(); | |
| 1149 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1150 | |
| 1151 strcpy(symbol->outfile, outfile); | |
| 1152 ret = ZBarcode_Encode_File_and_Print(symbol, filename, 0); | |
| 1153 assert_zero(ret, "ret %d != 0 (%s)\n", ret, symbol->errtxt); | |
| 1154 | |
| 1155 ret = testUtilRemove(outfile); | |
| 1156 assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", outfile, errno, strerror(errno)); | |
| 1157 | |
| 1158 ZBarcode_Delete(symbol); | |
| 1159 } | |
| 1160 | |
| 1161 { | |
| 1162 symbol = ZBarcode_Create(); | |
| 1163 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1164 | |
| 1165 strcpy(symbol->outfile, outfile); | |
| 1166 ret = ZBarcode_Encode_File_and_Buffer(symbol, filename, 0); | |
| 1167 assert_zero(ret, "ret %d != 0 (%s)\n", ret, symbol->errtxt); | |
| 1168 assert_nonnull(symbol->bitmap, "symbol->bitmap NULL (%s)\n", symbol->errtxt); | |
| 1169 | |
| 1170 ZBarcode_Delete(symbol); | |
| 1171 } | |
| 1172 | |
| 1173 { | |
| 1174 symbol = ZBarcode_Create(); | |
| 1175 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1176 | |
| 1177 strcpy(symbol->outfile, outfile); | |
| 1178 ret = ZBarcode_Encode_File_and_Buffer_Vector(symbol, filename, 0); | |
| 1179 assert_zero(ret, "ret %d != 0 (%s)\n", ret, symbol->errtxt); | |
| 1180 assert_nonnull(symbol->vector, "symbol->vector NULL (%s)\n", symbol->errtxt); | |
| 1181 | |
| 1182 ZBarcode_Delete(symbol); | |
| 1183 } | |
| 1184 | |
| 1185 ret = testUtilRemove(filename); | |
| 1186 assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno)); | |
| 1187 | |
| 1188 testFinish(); | |
| 1189 } | |
| 1190 | |
| 1191 static void test_encode_print_outfile_directory(const testCtx *const p_ctx) { | |
| 1192 int ret; | |
| 1193 struct zint_symbol *symbol = NULL; | |
| 1194 char dirname[] = "outdir.txt"; | |
| 1195 char expected[] = "Error 201: Could not open output file"; | |
| 1196 | |
| 1197 (void)p_ctx; | |
| 1198 | |
| 1199 testStartSymbol("test_encode_print_outfile_directory", &symbol); | |
| 1200 | |
| 1201 symbol = ZBarcode_Create(); | |
| 1202 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1203 | |
| 1204 (void) testUtilRmDir(dirname); /* In case junk hanging around */ | |
| 1205 ret = testUtilMkDir(dirname); | |
| 1206 assert_zero(ret, "testUtilMkDir(%s) %d != 0 (%d: %s)\n", dirname, ret, errno, strerror(errno)); | |
| 1207 | |
| 1208 strcpy(symbol->outfile, dirname); | |
| 1209 ret = ZBarcode_Encode_and_Print(symbol, TU("1"), 0, 0); | |
| 1210 assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "ret %d != ZINT_ERROR_FILE_ACCESS (%s)\n", ret, symbol->errtxt); | |
| 1211 assert_zero(strcmp(symbol->errtxt, expected), "strcmp(%s, %s) != 0\n", symbol->errtxt, expected); | |
| 1212 | |
| 1213 ret = testUtilRmDir(dirname); | |
| 1214 assert_zero(ret, "testUtilRmDir(%s) %d != 0 (%d: %s)\n", dirname, ret, errno, strerror(errno)); | |
| 1215 | |
| 1216 ZBarcode_Delete(symbol); | |
| 1217 | |
| 1218 testFinish(); | |
| 1219 } | |
| 1220 | |
| 1221 static void test_bad_args(const testCtx *const p_ctx) { | |
| 1222 int ret; | |
| 1223 unsigned int uret; | |
| 1224 struct zint_symbol *symbol = NULL; | |
| 1225 char *data = "1"; | |
| 1226 char *filename = "1.png"; | |
| 1227 char *empty = ""; | |
| 1228 struct zint_seg seg = { TU("1"), -1, 4 }; | |
| 1229 struct zint_seg seg_empty = { TU(""), -1, 4 }; | |
| 1230 struct zint_seg seg_too_long = { TU("1"), ZINT_MAX_DATA_LEN + 1, 4 }; | |
| 1231 const char *expected[] = { | |
| 1232 "Error 772: Input segment 0 source NULL", | |
| 1233 "Error 200: Input segments NULL", | |
| 1234 "Error 239: Filename NULL", | |
| 1235 "Error 778: No input data", | |
| 1236 "Error 229: Unable to read input file (", /* Excluding OS-dependent `errno` stuff */ | |
| 1237 "Error 771: Too many input segments (maximum 256)", | |
| 1238 "Error 205: No input data", | |
| 1239 "Error 777: Input too long", | |
| 1240 }; | |
| 1241 | |
| 1242 (void)p_ctx; | |
| 1243 | |
| 1244 testStartSymbol("test_bad_args", &symbol); | |
| 1245 | |
| 1246 /* These just return, no error */ | |
| 1247 ZBarcode_Clear(NULL); | |
| 1248 ZBarcode_Reset(NULL); | |
| 1249 ZBarcode_Delete(NULL); | |
| 1250 | |
| 1251 ret = ZBarcode_Version(); | |
| 1252 assert_nonzero(ret >= 20901, "ZBarcode_Version() %d <= 20901\n", ret); | |
| 1253 | |
| 1254 assert_zero(ZBarcode_ValidID(0), "ZBarcode_ValidID(0) non-zero\n"); | |
| 1255 assert_zero(ZBarcode_ValidID(10), "ZBarcode_ValidID(10) non-zero\n"); /* Note 10 remapped to BARCODE_EANX in ZBarcode_Encode() for tbarcode compat but not counted as valid */ | |
| 1256 | |
| 1257 uret = ZBarcode_Cap(0, ~0); | |
| 1258 assert_zero(uret, "ZBarcode_Cap(0, ~0) uret 0x%X != 0\n", uret); | |
| 1259 uret = ZBarcode_Cap(10, ~0); | |
| 1260 assert_zero(uret, "ZBarcode_Cap(10, ~0) uret 0x%X != 0\n", uret); | |
| 1261 | |
| 1262 /* NULL symbol */ | |
| 1263 assert_equal(ZBarcode_Encode(NULL, TU(data), 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode(NULL, data, 1) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1264 assert_equal(ZBarcode_Encode_Segs(NULL, &seg, 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs(NULL, &seg, 1) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1265 assert_equal(ZBarcode_Print(NULL, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Print(NULL, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1266 assert_equal(ZBarcode_Buffer(NULL, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Buffer(NULL, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1267 assert_equal(ZBarcode_Buffer_Vector(NULL, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Buffer_Vector(NULL, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1268 assert_equal(ZBarcode_Encode_and_Print(NULL, TU(data), 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Print(NULL, data, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1269 assert_equal(ZBarcode_Encode_Segs_and_Print(NULL, &seg, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Seg_and_Print(NULL, &seg, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1270 assert_equal(ZBarcode_Encode_and_Buffer(NULL, TU(data), 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Buffer(NULL, data, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1271 assert_equal(ZBarcode_Encode_Segs_and_Buffer(NULL, &seg, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs_and_Buffer(NULL, &seg, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1272 assert_equal(ZBarcode_Encode_and_Buffer_Vector(NULL, TU(data), 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Buffer_Vector(NULL, data, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1273 assert_equal(ZBarcode_Encode_Segs_and_Buffer_Vector(NULL, &seg, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs_and_Buffer_Vector(NULL, &seg, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1274 assert_equal(ZBarcode_Encode_File(NULL, filename), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File(NULL, filename) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1275 assert_equal(ZBarcode_Encode_File_and_Print(NULL, filename, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Print(NULL, filename, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1276 assert_equal(ZBarcode_Encode_File_and_Buffer(NULL, filename, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Buffer(NULL, filename, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1277 | |
| 1278 symbol = ZBarcode_Create(); | |
| 1279 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1280 | |
| 1281 /* NULL data/segs/filename */ | |
| 1282 symbol->errtxt[0] = '\0'; | |
| 1283 assert_equal(ZBarcode_Encode(symbol, NULL, 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode(symbol, NULL, 1) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1284 assert_zero(strcmp(expected[0], symbol->errtxt), "ZBarcode_Encode(symbol, NULL, 1) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt); | |
| 1285 symbol->errtxt[0] = '\0'; | |
| 1286 assert_equal(ZBarcode_Encode_Segs(symbol, NULL, 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs(symbol, NULL, 1) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1287 assert_zero(strcmp(expected[1], symbol->errtxt), "ZBarcode_Encode_Segs(symbol, NULL, 1) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt); | |
| 1288 symbol->errtxt[0] = '\0'; | |
| 1289 assert_equal(ZBarcode_Encode_and_Print(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Print(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1290 assert_zero(strcmp(expected[0], symbol->errtxt), "ZBarcode_Encode_and_Print(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt); | |
| 1291 symbol->errtxt[0] = '\0'; | |
| 1292 assert_equal(ZBarcode_Encode_and_Buffer(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Buffer(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1293 assert_zero(strcmp(expected[0], symbol->errtxt), "ZBarcode_Encode_and_Buffer(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt); | |
| 1294 symbol->errtxt[0] = '\0'; | |
| 1295 assert_equal(ZBarcode_Encode_Segs_and_Buffer(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs_and_Buffer(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1296 assert_zero(strcmp(expected[1], symbol->errtxt), "ZBarcode_Encode_Segs_and_Buffer(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt); | |
| 1297 symbol->errtxt[0] = '\0'; | |
| 1298 assert_equal(ZBarcode_Encode_and_Buffer_Vector(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Buffer_Vector(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1299 assert_zero(strcmp(expected[0], symbol->errtxt), "ZBarcode_Encode_and_Buffer_Vector(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt); | |
| 1300 symbol->errtxt[0] = '\0'; | |
| 1301 assert_equal(ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, NULL, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, NULL, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1302 assert_zero(strcmp(expected[1], symbol->errtxt), "ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, NULL, 1, 0) strcmp(%s, %s) != 0\n", expected[0], symbol->errtxt); | |
| 1303 symbol->errtxt[0] = '\0'; | |
| 1304 assert_equal(ZBarcode_Encode_File(symbol, NULL), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File(symbol, NULL) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1305 assert_zero(strcmp(expected[2], symbol->errtxt), "ZBarcode_Encode_File(symbol, NULL) strcmp(%s, %s) != 0\n", expected[2], symbol->errtxt); | |
| 1306 symbol->errtxt[0] = '\0'; | |
| 1307 assert_equal(ZBarcode_Encode_File_and_Print(symbol, NULL, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Print(symbol, NULL, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1308 assert_zero(strcmp(expected[2], symbol->errtxt), "ZBarcode_Encode_File_and_Print(symbol, NULL, 0) strcmp(%s, %s) != 0\n", expected[2], symbol->errtxt); | |
| 1309 symbol->errtxt[0] = '\0'; | |
| 1310 assert_equal(ZBarcode_Encode_File_and_Buffer(symbol, NULL, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Buffer(symbol, NULL, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1311 assert_zero(strcmp(expected[2], symbol->errtxt), "ZBarcode_Encode_File_and_Buffer(symbol, NULL, 0) strcmp(%s, %s) != 0\n", expected[2], symbol->errtxt); | |
| 1312 symbol->errtxt[0] = '\0'; | |
| 1313 assert_equal(ZBarcode_Encode_File_and_Buffer_Vector(symbol, NULL, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Buffer_Vector(symbol, NULL, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1314 assert_zero(strcmp(expected[2], symbol->errtxt), "ZBarcode_Encode_File_and_Buffer_Vector(symbol, NULL, 0) strcmp(%s, %s) != 0\n", expected[2], symbol->errtxt); | |
| 1315 | |
| 1316 /* Empty data/segs/filename */ | |
| 1317 symbol->errtxt[0] = '\0'; | |
| 1318 assert_equal(ZBarcode_Encode(symbol, TU(empty), 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode(symbol, empty, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1319 assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode(symbol, TU(empty), 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt); | |
| 1320 symbol->errtxt[0] = '\0'; | |
| 1321 assert_equal(ZBarcode_Encode_Segs(symbol, &seg_empty, 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs(symbol, &seg_empty, 1) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1322 assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode_Segs(symbol, &seg_empty, 1) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt); | |
| 1323 symbol->errtxt[0] = '\0'; | |
| 1324 assert_equal(ZBarcode_Encode_and_Print(symbol, TU(empty), 0, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Print(symbol, empty, 0, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1325 assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode_and_Print(symbol, TU(empty), 0, 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt); | |
| 1326 symbol->errtxt[0] = '\0'; | |
| 1327 assert_equal(ZBarcode_Encode_and_Buffer(symbol, TU(empty), 0, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Buffer(symbol, empty, 0, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1328 assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode_and_Buffer(symbol, TU(empty), 0, 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt); | |
| 1329 symbol->errtxt[0] = '\0'; | |
| 1330 assert_equal(ZBarcode_Encode_Segs_and_Buffer(symbol, &seg_empty, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs_and_Buffer(symbol, &seg_empty, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1331 assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode_Segs_and_Buffer(symbol, &seg_empty, 1, 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt); | |
| 1332 symbol->errtxt[0] = '\0'; | |
| 1333 assert_equal(ZBarcode_Encode_and_Buffer_Vector(symbol, TU(empty), 0, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_and_Buffer_Vector(symbol, empty, 0, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1334 assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode_and_Buffer_Vector(symbol, TU(empty), 0, 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt); | |
| 1335 symbol->errtxt[0] = '\0'; | |
| 1336 assert_equal(ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, &seg_empty, 1, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, &seg_empty, 1, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1337 assert_zero(strcmp(expected[3], symbol->errtxt), "ZBarcode_Encode_Segs_and_Buffer_Vector(symbol, &seg_empty, 1, 0) strcmp(%s, %s) != 0\n", expected[3], symbol->errtxt); | |
| 1338 symbol->errtxt[0] = '\0'; | |
| 1339 assert_equal(ZBarcode_Encode_File(symbol, empty), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File(symbol, empty) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1340 assert_zero(strncmp(expected[4], symbol->errtxt, strlen(expected[4])), "ZBarcode_Encode_File(symbol, empty) strncmp(%s, %s, %d) != 0\n", expected[4], symbol->errtxt, (int) strlen(expected[4])); | |
| 1341 symbol->errtxt[0] = '\0'; | |
| 1342 assert_equal(ZBarcode_Encode_File_and_Print(symbol, empty, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Print(symbol, empty, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1343 assert_zero(strncmp(expected[4], symbol->errtxt, strlen(expected[4])), "ZBarcode_Encode_File(symbol, empty) strncmp(%s, %s, %d) != 0\n", expected[4], symbol->errtxt, (int) strlen(expected[4])); | |
| 1344 symbol->errtxt[0] = '\0'; | |
| 1345 assert_equal(ZBarcode_Encode_File_and_Buffer(symbol, empty, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Buffer(symbol, empty, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1346 assert_zero(strncmp(expected[4], symbol->errtxt, strlen(expected[4])), "ZBarcode_Encode_File(symbol, empty) strncmp(%s, %s, %d) != 0\n", expected[4], symbol->errtxt, (int) strlen(expected[4])); | |
| 1347 symbol->errtxt[0] = '\0'; | |
| 1348 assert_equal(ZBarcode_Encode_File_and_Buffer_Vector(symbol, empty, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Buffer_Vector(symbol, empty, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1349 assert_zero(strncmp(expected[4], symbol->errtxt, strlen(expected[4])), "ZBarcode_Encode_File(symbol, empty) strncmp(%s, %s, %d) != 0\n", expected[4], symbol->errtxt, (int) strlen(expected[4])); | |
| 1350 | |
| 1351 /* Bad seg_count */ | |
| 1352 symbol->errtxt[0] = '\0'; | |
| 1353 assert_equal(ZBarcode_Encode_Segs(symbol, &seg_empty, ZINT_MAX_SEG_COUNT + 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs(symbol, &seg_empty, ZINT_MAX_SEG_COUNT + 1) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1354 assert_zero(strcmp(expected[5], symbol->errtxt), "ZBarcode_Encode_Segs(symbol, &seg_empty, ZINT_MAX_SEG_COUNT + 1) strcmp(%s, %s) != 0\n", expected[5], symbol->errtxt); | |
| 1355 symbol->errtxt[0] = '\0'; | |
| 1356 assert_equal(ZBarcode_Encode_Segs(symbol, &seg_empty, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs(symbol, &seg_empty, 0) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1357 assert_zero(strcmp(expected[6], symbol->errtxt), "ZBarcode_Encode_Segs(symbol, &seg_empty, 0) strcmp(%s, %s) != 0\n", expected[6], symbol->errtxt); | |
| 1358 symbol->errtxt[0] = '\0'; | |
| 1359 assert_equal(ZBarcode_Encode_Segs(symbol, &seg_empty, -1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_Segs(symbol, &seg_empty, -1) != ZINT_ERROR_INVALID_DATA\n"); | |
| 1360 assert_zero(strcmp(expected[6], symbol->errtxt), "ZBarcode_Encode_Segs(symbol, &seg_empty, -1) strcmp(%s, %s) != 0\n", expected[6], symbol->errtxt); | |
| 1361 | |
| 1362 /* Data/seg too big */ | |
| 1363 symbol->errtxt[0] = '\0'; | |
| 1364 assert_equal(ZBarcode_Encode(symbol, TU(empty), ZINT_MAX_DATA_LEN + 1), ZINT_ERROR_TOO_LONG, "ZBarcode_Encode(symbol, empty, ZINT_MAX_DATA_LEN + 1) != ZINT_ERROR_TOO_LONG\n"); | |
| 1365 assert_zero(strcmp(expected[7], symbol->errtxt), "ZBarcode_Encode(symbol, TU(empty), ZINT_MAX_DATA_LEN + 1) strcmp(%s, %s) != 0\n", expected[7], symbol->errtxt); | |
| 1366 symbol->errtxt[0] = '\0'; | |
| 1367 assert_equal(ZBarcode_Encode_Segs(symbol, &seg_too_long, 1), ZINT_ERROR_TOO_LONG, "ZBarcode_Encode_Segs(symbol, &seg_too_long, 1) != ZINT_ERROR_TOO_LONG\n"); | |
| 1368 assert_zero(strcmp(expected[7], symbol->errtxt), "ZBarcode_Encode_Segs(symbol, &seg_too_long, 1) strcmp(%s, %s) != 0\n", expected[7], symbol->errtxt); | |
| 1369 | |
| 1370 ZBarcode_Delete(symbol); | |
| 1371 | |
| 1372 testFinish(); | |
| 1373 } | |
| 1374 | |
| 1375 static void test_valid_id(const testCtx *const p_ctx) { | |
| 1376 | |
| 1377 int ret; | |
| 1378 const char *name; | |
| 1379 int symbol_id; | |
| 1380 | |
| 1381 (void)p_ctx; | |
| 1382 | |
| 1383 testStart("test_valid_id"); | |
| 1384 | |
| 1385 for (symbol_id = -1; symbol_id < 160; symbol_id++) { | |
| 1386 ret = ZBarcode_ValidID(symbol_id); | |
| 1387 name = testUtilBarcodeName(symbol_id); | |
| 1388 assert_nonnull((char *) name, "testUtilBarcodeName(%d) NULL\n", symbol_id); | |
| 1389 if (ret) { | |
| 1390 assert_equal(ret, 1, "ZBarcode_Valid(%d) != 1\n", symbol_id); | |
| 1391 assert_nonzero(*name != '\0', "testUtilBarcodeName(%d) empty when ZBarcode_Valid() true\n", symbol_id); | |
| 1392 } else { | |
| 1393 assert_zero(ret, "ZBarcode_Valid(%d) != 0\n", symbol_id); | |
| 1394 assert_zero(*name, "testUtilBarcodeName(%d) non-empty when ZBarcode_Valid() false\n", symbol_id); | |
| 1395 } | |
| 1396 } | |
| 1397 | |
| 1398 testFinish(); | |
| 1399 } | |
| 1400 | |
| 1401 static int test_prev_ZBarcode_BarcodeName(int symbol_id, char name[32]) { | |
| 1402 struct item { | |
| 1403 const char *name; | |
| 1404 int define; | |
| 1405 int val; | |
| 1406 }; | |
| 1407 static const struct item data[] = { | |
| 1408 { "", -1, 0 }, | |
| 1409 { "BARCODE_CODE11", BARCODE_CODE11, 1 }, | |
| 1410 { "BARCODE_C25STANDARD", BARCODE_C25STANDARD, 2 }, | |
| 1411 { "BARCODE_C25INTER", BARCODE_C25INTER, 3 }, | |
| 1412 { "BARCODE_C25IATA", BARCODE_C25IATA, 4 }, | |
| 1413 { "", -1, 5 }, | |
| 1414 { "BARCODE_C25LOGIC", BARCODE_C25LOGIC, 6 }, | |
| 1415 { "BARCODE_C25IND", BARCODE_C25IND, 7 }, | |
| 1416 { "BARCODE_CODE39", BARCODE_CODE39, 8 }, | |
| 1417 { "BARCODE_EXCODE39", BARCODE_EXCODE39, 9 }, | |
| 1418 { "", -1, 10 }, | |
| 1419 { "", -1, 11 }, | |
| 1420 { "", -1, 12 }, | |
| 1421 { "BARCODE_EANX", BARCODE_EANX, 13 }, | |
| 1422 { "BARCODE_EANX_CHK", BARCODE_EANX_CHK, 14 }, | |
| 1423 { "", -1, 15 }, | |
| 1424 { "BARCODE_GS1_128", BARCODE_GS1_128, 16 }, | |
| 1425 { "", -1, 17 }, | |
| 1426 { "BARCODE_CODABAR", BARCODE_CODABAR, 18 }, | |
| 1427 { "", -1, 19 }, | |
| 1428 { "BARCODE_CODE128", BARCODE_CODE128, 20 }, | |
| 1429 { "BARCODE_DPLEIT", BARCODE_DPLEIT, 21 }, | |
| 1430 { "BARCODE_DPIDENT", BARCODE_DPIDENT, 22 }, | |
| 1431 { "BARCODE_CODE16K", BARCODE_CODE16K, 23 }, | |
| 1432 { "BARCODE_CODE49", BARCODE_CODE49, 24 }, | |
| 1433 { "BARCODE_CODE93", BARCODE_CODE93, 25 }, | |
| 1434 { "", -1, 26 }, | |
| 1435 { "", -1, 27 }, | |
| 1436 { "BARCODE_FLAT", BARCODE_FLAT, 28 }, | |
| 1437 { "BARCODE_DBAR_OMN", BARCODE_DBAR_OMN, 29 }, | |
| 1438 { "BARCODE_DBAR_LTD", BARCODE_DBAR_LTD, 30 }, | |
| 1439 { "BARCODE_DBAR_EXP", BARCODE_DBAR_EXP, 31 }, | |
| 1440 { "BARCODE_TELEPEN", BARCODE_TELEPEN, 32 }, | |
| 1441 { "", -1, 33 }, | |
| 1442 { "BARCODE_UPCA", BARCODE_UPCA, 34 }, | |
| 1443 { "BARCODE_UPCA_CHK", BARCODE_UPCA_CHK, 35 }, | |
| 1444 { "", -1, 36 }, | |
| 1445 { "BARCODE_UPCE", BARCODE_UPCE, 37 }, | |
| 1446 { "BARCODE_UPCE_CHK", BARCODE_UPCE_CHK, 38 }, | |
| 1447 { "", -1, 39 }, | |
| 1448 { "BARCODE_POSTNET", BARCODE_POSTNET, 40 }, | |
| 1449 { "", -1, 41 }, | |
| 1450 { "", -1, 42 }, | |
| 1451 { "", -1, 43 }, | |
| 1452 { "", -1, 44 }, | |
| 1453 { "", -1, 45 }, | |
| 1454 { "", -1, 46 }, | |
| 1455 { "BARCODE_MSI_PLESSEY", BARCODE_MSI_PLESSEY, 47 }, | |
| 1456 { "", -1, 48 }, | |
| 1457 { "BARCODE_FIM", BARCODE_FIM, 49 }, | |
| 1458 { "BARCODE_LOGMARS", BARCODE_LOGMARS, 50 }, | |
| 1459 { "BARCODE_PHARMA", BARCODE_PHARMA, 51 }, | |
| 1460 { "BARCODE_PZN", BARCODE_PZN, 52 }, | |
| 1461 { "BARCODE_PHARMA_TWO", BARCODE_PHARMA_TWO, 53 }, | |
| 1462 { "BARCODE_CEPNET", BARCODE_CEPNET, 54 }, | |
| 1463 { "BARCODE_PDF417", BARCODE_PDF417, 55 }, | |
| 1464 { "BARCODE_PDF417COMP", BARCODE_PDF417COMP, 56 }, | |
| 1465 { "BARCODE_MAXICODE", BARCODE_MAXICODE, 57 }, | |
| 1466 { "BARCODE_QRCODE", BARCODE_QRCODE, 58 }, | |
| 1467 { "", -1, 59 }, | |
| 1468 { "BARCODE_CODE128AB", BARCODE_CODE128AB, 60 }, | |
| 1469 { "", -1, 61 }, | |
| 1470 { "", -1, 62 }, | |
| 1471 { "BARCODE_AUSPOST", BARCODE_AUSPOST, 63 }, | |
| 1472 { "", -1, 64 }, | |
| 1473 { "", -1, 65 }, | |
| 1474 { "BARCODE_AUSREPLY", BARCODE_AUSREPLY, 66 }, | |
| 1475 { "BARCODE_AUSROUTE", BARCODE_AUSROUTE, 67 }, | |
| 1476 { "BARCODE_AUSREDIRECT", BARCODE_AUSREDIRECT, 68 }, | |
| 1477 { "BARCODE_ISBNX", BARCODE_ISBNX, 69 }, | |
| 1478 { "BARCODE_RM4SCC", BARCODE_RM4SCC, 70 }, | |
| 1479 { "BARCODE_DATAMATRIX", BARCODE_DATAMATRIX, 71 }, | |
| 1480 { "BARCODE_EAN14", BARCODE_EAN14, 72 }, | |
| 1481 { "BARCODE_VIN", BARCODE_VIN, 73 }, | |
| 1482 { "BARCODE_CODABLOCKF", BARCODE_CODABLOCKF, 74 }, | |
| 1483 { "BARCODE_NVE18", BARCODE_NVE18, 75 }, | |
| 1484 { "BARCODE_JAPANPOST", BARCODE_JAPANPOST, 76 }, | |
| 1485 { "BARCODE_KOREAPOST", BARCODE_KOREAPOST, 77 }, | |
| 1486 { "", -1, 78 }, | |
| 1487 { "BARCODE_DBAR_STK", BARCODE_DBAR_STK, 79 }, | |
| 1488 { "BARCODE_DBAR_OMNSTK", BARCODE_DBAR_OMNSTK, 80 }, | |
| 1489 { "BARCODE_DBAR_EXPSTK", BARCODE_DBAR_EXPSTK, 81 }, | |
| 1490 { "BARCODE_PLANET", BARCODE_PLANET, 82 }, | |
| 1491 { "", -1, 83 }, | |
| 1492 { "BARCODE_MICROPDF417", BARCODE_MICROPDF417, 84 }, | |
| 1493 { "BARCODE_USPS_IMAIL", BARCODE_USPS_IMAIL, 85 }, | |
| 1494 { "BARCODE_PLESSEY", BARCODE_PLESSEY, 86 }, | |
| 1495 { "BARCODE_TELEPEN_NUM", BARCODE_TELEPEN_NUM, 87 }, | |
| 1496 { "", -1, 88 }, | |
| 1497 { "BARCODE_ITF14", BARCODE_ITF14, 89 }, | |
| 1498 { "BARCODE_KIX", BARCODE_KIX, 90 }, | |
| 1499 { "", -1, 91 }, | |
| 1500 { "BARCODE_AZTEC", BARCODE_AZTEC, 92 }, | |
| 1501 { "BARCODE_DAFT", BARCODE_DAFT, 93 }, | |
| 1502 { "", -1, 94 }, | |
| 1503 { "", -1, 95 }, | |
| 1504 { "BARCODE_DPD", BARCODE_DPD, 96 }, | |
| 1505 { "BARCODE_MICROQR", BARCODE_MICROQR, 97 }, | |
| 1506 { "BARCODE_HIBC_128", BARCODE_HIBC_128, 98 }, | |
| 1507 { "BARCODE_HIBC_39", BARCODE_HIBC_39, 99 }, | |
| 1508 { "", -1, 100 }, | |
| 1509 { "", -1, 101 }, | |
| 1510 { "BARCODE_HIBC_DM", BARCODE_HIBC_DM, 102 }, | |
| 1511 { "", -1, 103 }, | |
| 1512 { "BARCODE_HIBC_QR", BARCODE_HIBC_QR, 104 }, | |
| 1513 { "", -1, 105 }, | |
| 1514 { "BARCODE_HIBC_PDF", BARCODE_HIBC_PDF, 106 }, | |
| 1515 { "", -1, 107 }, | |
| 1516 { "BARCODE_HIBC_MICPDF", BARCODE_HIBC_MICPDF, 108 }, | |
| 1517 { "", -1, 109 }, | |
| 1518 { "BARCODE_HIBC_BLOCKF", BARCODE_HIBC_BLOCKF, 110 }, | |
| 1519 { "", -1, 111 }, | |
| 1520 { "BARCODE_HIBC_AZTEC", BARCODE_HIBC_AZTEC, 112 }, | |
| 1521 { "", -1, 113 }, | |
| 1522 { "", -1, 114 }, | |
| 1523 { "BARCODE_DOTCODE", BARCODE_DOTCODE, 115 }, | |
| 1524 { "BARCODE_HANXIN", BARCODE_HANXIN, 116 }, | |
| 1525 { "", -1, 117 }, | |
| 1526 { "", -1, 118 }, | |
| 1527 { "BARCODE_MAILMARK_2D", BARCODE_MAILMARK_2D, 119 }, | |
| 1528 { "BARCODE_UPU_S10", BARCODE_UPU_S10, 120 }, | |
| 1529 { "BARCODE_MAILMARK_4S", BARCODE_MAILMARK_4S, 121 }, | |
| 1530 { "", -1, 122 }, | |
| 1531 { "", -1, 123 }, | |
| 1532 { "", -1, 124 }, | |
| 1533 { "", -1, 125 }, | |
| 1534 { "", -1, 126 }, | |
| 1535 { "", -1, 127 }, | |
| 1536 { "BARCODE_AZRUNE", BARCODE_AZRUNE, 128 }, | |
| 1537 { "BARCODE_CODE32", BARCODE_CODE32, 129 }, | |
| 1538 { "BARCODE_EANX_CC", BARCODE_EANX_CC, 130 }, | |
| 1539 { "BARCODE_GS1_128_CC", BARCODE_GS1_128_CC, 131 }, | |
| 1540 { "BARCODE_DBAR_OMN_CC", BARCODE_DBAR_OMN_CC, 132 }, | |
| 1541 { "BARCODE_DBAR_LTD_CC", BARCODE_DBAR_LTD_CC, 133 }, | |
| 1542 { "BARCODE_DBAR_EXP_CC", BARCODE_DBAR_EXP_CC, 134 }, | |
| 1543 { "BARCODE_UPCA_CC", BARCODE_UPCA_CC, 135 }, | |
| 1544 { "BARCODE_UPCE_CC", BARCODE_UPCE_CC, 136 }, | |
| 1545 { "BARCODE_DBAR_STK_CC", BARCODE_DBAR_STK_CC, 137 }, | |
| 1546 { "BARCODE_DBAR_OMNSTK_CC", BARCODE_DBAR_OMNSTK_CC, 138 }, | |
| 1547 { "BARCODE_DBAR_EXPSTK_CC", BARCODE_DBAR_EXPSTK_CC, 139 }, | |
| 1548 { "BARCODE_CHANNEL", BARCODE_CHANNEL, 140 }, | |
| 1549 { "BARCODE_CODEONE", BARCODE_CODEONE, 141 }, | |
| 1550 { "BARCODE_GRIDMATRIX", BARCODE_GRIDMATRIX, 142 }, | |
| 1551 { "BARCODE_UPNQR", BARCODE_UPNQR, 143 }, | |
| 1552 { "BARCODE_ULTRA", BARCODE_ULTRA, 144 }, | |
| 1553 { "BARCODE_RMQR", BARCODE_RMQR, 145 }, | |
| 1554 { "BARCODE_BC412", BARCODE_BC412, 146 }, | |
| 1555 { "BARCODE_DXFILMEDGE", BARCODE_DXFILMEDGE, 147 }, | |
| 1556 }; | |
| 1557 | |
| 1558 name[0] = '\0'; | |
| 1559 | |
| 1560 if (!ZBarcode_ValidID(symbol_id)) { | |
| 1561 return 1; | |
| 1562 } | |
| 1563 if (!(symbol_id >= 0 && symbol_id < ARRAY_SIZE(data) && data[symbol_id].name[0])) { | |
| 1564 return -1; /* Shouldn't happen */ | |
| 1565 } | |
| 1566 | |
| 1567 /* Self-check, shouldn't happen */ | |
| 1568 if (data[symbol_id].val != symbol_id || (data[symbol_id].define != -1 && data[symbol_id].define != symbol_id)) { | |
| 1569 return -1; | |
| 1570 } | |
| 1571 | |
| 1572 strcpy(name, data[symbol_id].name); | |
| 1573 | |
| 1574 return 0; | |
| 1575 } | |
| 1576 | |
| 1577 static void test_barcode_name(const testCtx *const p_ctx) { | |
| 1578 | |
| 1579 int ret; | |
| 1580 char name[32]; | |
| 1581 int symbol_id; | |
| 1582 | |
| 1583 (void)p_ctx; | |
| 1584 | |
| 1585 testStart("test_barcode_name"); | |
| 1586 | |
| 1587 for (symbol_id = -1; symbol_id < 160; symbol_id++) { | |
| 1588 int prev_ret; | |
| 1589 char prev_name[32]; | |
| 1590 ret = ZBarcode_BarcodeName(symbol_id, name); | |
| 1591 if (ZBarcode_ValidID(symbol_id)) { | |
| 1592 assert_equal(ret, 0, "ZBarcode_BarcodeName(%d) != 0\n", symbol_id); | |
| 1593 assert_nonzero(*name != '\0', "ZBarcode_BarcodeName(%d) empty when ZBarcode_Valid() true\n", symbol_id); | |
| 1594 } else { | |
| 1595 assert_equal(ret, 1, "ZBarcode_BarcodeName(%d) != 1\n", symbol_id); | |
| 1596 assert_zero(*name, "ZBarcode_BarcodeName(%d) non-empty when ZBarcode_Valid() false\n", symbol_id); | |
| 1597 } | |
| 1598 prev_ret = test_prev_ZBarcode_BarcodeName(symbol_id, prev_name); | |
| 1599 assert_equal(ret, prev_ret, "ZBarcode_BarcodeName(%d) ret %d != prev_ret %d\n", symbol_id, ret, prev_ret); | |
| 1600 assert_zero(strcmp(name, prev_name), "ZBarcode_BarcodeName(%d) strcmp(%s, %s) != 0\n", symbol_id, name, prev_name); | |
| 1601 } | |
| 1602 | |
| 1603 testFinish(); | |
| 1604 } | |
| 1605 | |
| 1606 INTERNAL int error_tag_test(int error_number, struct zint_symbol *symbol, const int err_id, const char *error_string); | |
| 1607 | |
| 1608 static void test_error_tag(const testCtx *const p_ctx) { | |
| 1609 | |
| 1610 struct item { | |
| 1611 int debug_test; | |
| 1612 int error_number; | |
| 1613 int warn_level; | |
| 1614 char *data; | |
| 1615 int ret; | |
| 1616 char *expected; | |
| 1617 }; | |
| 1618 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 1619 struct item data[] = { | |
| 1620 /* 0*/ { 0, ZINT_WARN_INVALID_OPTION, -1, "", ZINT_WARN_INVALID_OPTION, "Warning " }, | |
| 1621 /* 1*/ { 0, ZINT_WARN_INVALID_OPTION, WARN_FAIL_ALL, "", ZINT_ERROR_INVALID_OPTION, "Error " }, | |
| 1622 /* 2*/ { 0, ZINT_WARN_USES_ECI, -1, "", ZINT_WARN_USES_ECI, "Warning " }, | |
| 1623 /* 3*/ { 0, ZINT_WARN_USES_ECI, WARN_FAIL_ALL, "", ZINT_ERROR_USES_ECI, "Error " }, | |
| 1624 /* 4*/ { 0, ZINT_WARN_NONCOMPLIANT, -1, "", ZINT_WARN_NONCOMPLIANT, "Warning " }, | |
| 1625 /* 5*/ { 0, ZINT_WARN_NONCOMPLIANT, WARN_FAIL_ALL, "", ZINT_ERROR_NONCOMPLIANT, "Error " }, | |
| 1626 /* 6*/ { 0, ZINT_WARN_HRT_TRUNCATED, -1, "", ZINT_WARN_HRT_TRUNCATED, "Warning " }, | |
| 1627 /* 7*/ { 0, ZINT_WARN_HRT_TRUNCATED, WARN_FAIL_ALL, "", ZINT_ERROR_HRT_TRUNCATED, "Error " }, | |
| 1628 /* 8*/ { 0, ZINT_ERROR_TOO_LONG, WARN_DEFAULT, "", ZINT_ERROR_TOO_LONG, "Error " }, | |
| 1629 /* 9*/ { 0, ZINT_ERROR_TOO_LONG, WARN_FAIL_ALL, "", ZINT_ERROR_TOO_LONG, "Error " }, | |
| 1630 /* 10*/ { 0, ZINT_WARN_USES_ECI, -1, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901", ZINT_WARN_USES_ECI, "Warning 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901" }, | |
| 1631 /* 11*/ { 1, ZINT_WARN_USES_ECI, -1, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012", ZINT_WARN_USES_ECI, "Warning 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901" }, | |
| 1632 /* 12*/ { 0, ZINT_WARN_USES_ECI, WARN_FAIL_ALL, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123", ZINT_ERROR_USES_ECI, "Error 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123" }, | |
| 1633 /* 13*/ { 1, ZINT_WARN_USES_ECI, WARN_FAIL_ALL, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", ZINT_ERROR_USES_ECI, "Error 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123" }, | |
| 1634 /* 14*/ { 0, ZINT_ERROR_INVALID_DATA, -1, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123", ZINT_ERROR_INVALID_DATA, "Error 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123" }, | |
| 1635 /* 15*/ { 1, ZINT_ERROR_INVALID_DATA, -1, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", ZINT_ERROR_INVALID_DATA, "Error 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123" }, | |
| 1636 /* 16*/ { 1, ZINT_ERROR_INVALID_DATA, WARN_FAIL_ALL, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", ZINT_ERROR_INVALID_DATA, "Error 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123" }, | |
| 1637 /* 17*/ { 1, ZINT_WARN_USES_ECI, -1, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", ZINT_WARN_USES_ECI, "Warning 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901" }, | |
| 1638 /* 18*/ { 1, ZINT_WARN_USES_ECI, WARN_FAIL_ALL, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", ZINT_ERROR_USES_ECI, "Error 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123" }, | |
| 1639 /* 19*/ { 1, ZINT_ERROR_INVALID_DATA, -1, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", ZINT_ERROR_INVALID_DATA, "Error 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123" }, | |
| 1640 }; | |
| 1641 const int data_size = ARRAY_SIZE(data); | |
| 1642 int i, ret; | |
| 1643 | |
| 1644 testStart("test_error_tag"); | |
| 1645 | |
| 1646 for (i = 0; i < data_size; i++) { | |
| 1647 struct zint_symbol s_symbol = {0}; | |
| 1648 struct zint_symbol *symbol = &s_symbol; | |
| 1649 | |
| 1650 if (testContinue(p_ctx, i)) continue; | |
| 1651 | |
| 1652 if (data[i].debug_test) symbol->debug |= ZINT_DEBUG_TEST; | |
| 1653 symbol->warn_level = data[i].warn_level; | |
| 1654 | |
| 1655 ret = error_tag_test(data[i].error_number, symbol, -1, data[i].data); | |
| 1656 assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); | |
| 1657 assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected); | |
| 1658 | |
| 1659 if ((int) strlen(data[i].data) < 100) { | |
| 1660 strcpy(symbol->errtxt, data[i].data); | |
| 1661 ret = error_tag_test(data[i].error_number, symbol, -1, NULL); | |
| 1662 assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); | |
| 1663 assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected); | |
| 1664 } | |
| 1665 } | |
| 1666 | |
| 1667 testFinish(); | |
| 1668 } | |
| 1669 | |
| 1670 INTERNAL void strip_bom_test(unsigned char *source, int *input_length); | |
| 1671 | |
| 1672 static void test_strip_bom(const testCtx *const p_ctx) { | |
| 1673 | |
| 1674 int length, ret; | |
| 1675 char data[] = "\357\273\277A"; /* U+FEFF BOM, with "A" */ | |
| 1676 char bom_only[] = "\357\273\277"; /* U+FEFF BOM only */ | |
| 1677 char buf[6]; | |
| 1678 | |
| 1679 (void)p_ctx; | |
| 1680 | |
| 1681 testStart("test_strip_bom"); | |
| 1682 | |
| 1683 strcpy(buf, data); | |
| 1684 length = (int) strlen(buf); | |
| 1685 strip_bom_test(TU(buf), &length); | |
| 1686 assert_equal(length, 1, "length %d != 1\n", length); | |
| 1687 assert_zero(buf[1], "buf[1] %d != 0\n", buf[1]); | |
| 1688 | |
| 1689 /* BOM not stripped if only data */ | |
| 1690 | |
| 1691 strcpy(buf, bom_only); | |
| 1692 length = (int) strlen(buf); | |
| 1693 strip_bom_test(TU(buf), &length); | |
| 1694 assert_equal(length, 3, "BOM only length %d != 3\n", length); | |
| 1695 ret = strcmp(buf, bom_only); | |
| 1696 assert_zero(ret, "BOM only strcmp ret %d != 0\n", ret); | |
| 1697 | |
| 1698 testFinish(); | |
| 1699 } | |
| 1700 | |
| 1701 static void test_zero_outfile(const testCtx *const p_ctx) { | |
| 1702 | |
| 1703 int ret; | |
| 1704 struct zint_symbol *symbol = NULL; | |
| 1705 char *data = "1234"; | |
| 1706 | |
| 1707 (void)p_ctx; | |
| 1708 | |
| 1709 testStartSymbol("test_zero_outfile", &symbol); | |
| 1710 | |
| 1711 symbol = ZBarcode_Create(); | |
| 1712 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1713 | |
| 1714 assert_nonzero(symbol->outfile[0], "ZBarcode_Create() outfile zero\n"); | |
| 1715 symbol->outfile[0] = '\0'; | |
| 1716 | |
| 1717 ret = ZBarcode_Encode(symbol, TU(data), 0); | |
| 1718 assert_zero(ret, "ZBarcode_Encode(%s) ret %d != 0 (%s)\n", data, ret, symbol->errtxt); | |
| 1719 assert_zero(symbol->outfile[0], "ZBarcode_Encode() outfile non-zero\n"); | |
| 1720 | |
| 1721 ret = ZBarcode_Print(symbol, 0); | |
| 1722 assert_equal(ret, ZINT_ERROR_INVALID_OPTION, "ZBarcode_Print() ret %d != ZINT_ERROR_INVALID_OPTION (%s)\n", ret, symbol->errtxt); | |
| 1723 assert_zero(symbol->outfile[0], "ZBarcode_Print() outfile non-zero\n"); | |
| 1724 | |
| 1725 ret = ZBarcode_Buffer(symbol, 0); | |
| 1726 assert_zero(ret, "ZBarcode_Buffer() ret %d != 0 (%s)\n", ret, symbol->errtxt); | |
| 1727 assert_zero(symbol->outfile[0], "ZBarcode_Buffer() outfile non-zero\n"); | |
| 1728 | |
| 1729 ZBarcode_Delete(symbol); | |
| 1730 | |
| 1731 testFinish(); | |
| 1732 } | |
| 1733 | |
| 1734 static void test_clear(const testCtx *const p_ctx) { | |
| 1735 | |
| 1736 int ret; | |
| 1737 struct zint_symbol *symbol = NULL; | |
| 1738 char *data = "1234"; | |
| 1739 | |
| 1740 (void)p_ctx; | |
| 1741 | |
| 1742 testStartSymbol("test_clear", &symbol); | |
| 1743 | |
| 1744 symbol = ZBarcode_Create(); | |
| 1745 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1746 | |
| 1747 symbol->symbology = BARCODE_MAXICODE; | |
| 1748 symbol->whitespace_width = 5; | |
| 1749 symbol->whitespace_height = 5; | |
| 1750 symbol->border_width = 2; | |
| 1751 symbol->output_options = BARCODE_BOX; | |
| 1752 strcpy(symbol->fgcolour, "000000AA"); | |
| 1753 strcpy(symbol->bgcolour, "FFFFFFAA"); | |
| 1754 | |
| 1755 /* Raster */ | |
| 1756 | |
| 1757 ret = ZBarcode_Encode(symbol, TU(data), 0); | |
| 1758 assert_zero(ret, "ZBarcode_Encode() ret %d != 0 (%s)\n", ret, symbol->errtxt); | |
| 1759 | |
| 1760 assert_nonzero(symbol->rows, "ZBarcode_Encode() rows 0\n"); | |
| 1761 assert_nonzero(symbol->width, "ZBarcode_Encode() width 0\n"); | |
| 1762 | |
| 1763 ret = ZBarcode_Buffer(symbol, 0); | |
| 1764 assert_zero(ret, "ZBarcode_Buffer() ret %d != 0 (%s)\n", ret, symbol->errtxt); | |
| 1765 | |
| 1766 assert_nonnull(symbol->bitmap, "ZBarcode_Buffer() bitmap NULL\n"); | |
| 1767 assert_nonnull(symbol->alphamap, "ZBarcode_Buffer() alphamap NULL\n"); | |
| 1768 assert_nonzero(symbol->bitmap_width, "ZBarcode_Buffer() bitmap_width 0\n"); | |
| 1769 assert_nonzero(symbol->bitmap_height, "ZBarcode_Buffer() bitmap_height 0\n"); | |
| 1770 | |
| 1771 assert_nonzero(symbol->rows, "ZBarcode_Buffer() rows 0\n"); | |
| 1772 assert_nonzero(symbol->width, "ZBarcode_Buffer() width 0\n"); | |
| 1773 assert_null(symbol->vector, "ZBarcode_Buffer() vector != NULL\n"); | |
| 1774 | |
| 1775 ZBarcode_Clear(symbol); | |
| 1776 | |
| 1777 assert_null(symbol->bitmap, "ZBarcode_Buffer() bitmap != NULL\n"); | |
| 1778 assert_null(symbol->alphamap, "ZBarcode_Buffer() alphamap != NULL\n"); | |
| 1779 assert_zero(symbol->bitmap_width, "ZBarcode_Buffer() bitmap_width %d != 0\n", symbol->bitmap_width); | |
| 1780 assert_zero(symbol->bitmap_height, "ZBarcode_Buffer() bitmap_height %d != 0\n", symbol->bitmap_height); | |
| 1781 | |
| 1782 assert_zero(symbol->rows, "ZBarcode_Buffer() rows %d != 0\n", symbol->rows); | |
| 1783 assert_zero(symbol->width, "ZBarcode_Buffer() width %d != 0\n", symbol->width); | |
| 1784 assert_null(symbol->vector, "ZBarcode_Buffer() vector != NULL\n"); | |
| 1785 | |
| 1786 /* Vector */ | |
| 1787 | |
| 1788 ret = ZBarcode_Encode(symbol, TU(data), 0); | |
| 1789 assert_zero(ret, "ZBarcode_Encode() ret %d != 0 (%s)\n", ret, symbol->errtxt); | |
| 1790 | |
| 1791 assert_nonzero(symbol->rows, "ZBarcode_Encode() rows 0\n"); | |
| 1792 assert_nonzero(symbol->width, "ZBarcode_Encode() width 0\n"); | |
| 1793 | |
| 1794 ret = ZBarcode_Buffer_Vector(symbol, 0); | |
| 1795 assert_zero(ret, "ZBarcode_Buffer_Vector() ret %d != 0 (%s)\n", ret, symbol->errtxt); | |
| 1796 | |
| 1797 assert_nonnull(symbol->vector, "ZBarcode_Buffer_Vector() vector NULL\n"); | |
| 1798 assert_nonnull(symbol->vector->rectangles, "ZBarcode_Buffer_Vector() vector->rectangles NULL\n"); | |
| 1799 assert_nonnull(symbol->vector->hexagons, "ZBarcode_Buffer_Vector() vector->hexagons NULL\n"); | |
| 1800 assert_null(symbol->vector->strings, "ZBarcode_Buffer_Vector() vector->strings != NULL\n"); /* MAXICODE no text */ | |
| 1801 assert_nonnull(symbol->vector->circles, "ZBarcode_Buffer_Vector() vector->circles NULL\n"); | |
| 1802 | |
| 1803 assert_nonzero(symbol->rows, "ZBarcode_Buffer_Vector() rows 0\n"); | |
| 1804 assert_nonzero(symbol->width, "ZBarcode_Buffer_Vector() width 0\n"); | |
| 1805 assert_null(symbol->bitmap, "ZBarcode_Buffer_Vector() bitmap != NULL\n"); | |
| 1806 assert_null(symbol->alphamap, "ZBarcode_Buffer_Vector() alphamap != NULL\n"); | |
| 1807 | |
| 1808 ZBarcode_Clear(symbol); | |
| 1809 | |
| 1810 assert_null(symbol->vector, "ZBarcode_Buffer_Vector() vector != NULL\n"); | |
| 1811 | |
| 1812 assert_zero(symbol->rows, "ZBarcode_Buffer_Vector() rows %d != 0\n", symbol->rows); | |
| 1813 assert_zero(symbol->width, "ZBarcode_Buffer_Vector() width %d != 0\n", symbol->width); | |
| 1814 assert_null(symbol->bitmap, "ZBarcode_Buffer_Vector() bitmap != NULL\n"); | |
| 1815 assert_null(symbol->alphamap, "ZBarcode_Buffer_Vector() alphamap != NULL\n"); | |
| 1816 assert_zero(symbol->bitmap_width, "ZBarcode_Buffer_Vector() bitmap_width %d != 0\n", symbol->bitmap_width); | |
| 1817 assert_zero(symbol->bitmap_height, "ZBarcode_Buffer_Vector() bitmap_height %d != 0\n", symbol->bitmap_height); | |
| 1818 | |
| 1819 ZBarcode_Delete(symbol); | |
| 1820 | |
| 1821 testFinish(); | |
| 1822 } | |
| 1823 | |
| 1824 /* Helper to set various `zint_symbol` fields */ | |
| 1825 static void set_symbol_fields(struct zint_symbol *symbol) { | |
| 1826 symbol->symbology = BARCODE_MAXICODE; | |
| 1827 symbol->height = 2.3f; | |
| 1828 symbol->scale = 1.1f; | |
| 1829 symbol->whitespace_width = 5; | |
| 1830 symbol->whitespace_height = 5; | |
| 1831 symbol->border_width = 2; | |
| 1832 symbol->output_options = BARCODE_BOX; | |
| 1833 strcpy(symbol->fgcolour, "000000AA"); | |
| 1834 strcpy(symbol->bgcolour, "FFFFFFAA"); | |
| 1835 strcpy(symbol->outfile, "gosh.png"); | |
| 1836 strcpy(symbol->primary, "1234567"); | |
| 1837 symbol->option_1 = 2; | |
| 1838 symbol->option_2 = 3; | |
| 1839 symbol->option_3 = 4; | |
| 1840 symbol->show_hrt = 0; | |
| 1841 symbol->input_mode = UNICODE_MODE | ESCAPE_MODE; | |
| 1842 symbol->eci = 3; | |
| 1843 symbol->dpmm = 24.0f; | |
| 1844 symbol->dot_size = 1.6f; | |
| 1845 symbol->text_gap = 0.5f; | |
| 1846 symbol->guard_descent = 4.5f; | |
| 1847 symbol->structapp.index = 1; | |
| 1848 symbol->structapp.count = 2; | |
| 1849 /*strcpy(symbol->structapp.id, "ID1");*/ /* Not available for MAXICODE */ | |
| 1850 symbol->warn_level = WARN_FAIL_ALL; | |
| 1851 } | |
| 1852 | |
| 1853 static void test_reset(const testCtx *const p_ctx) { | |
| 1854 | |
| 1855 int ret; | |
| 1856 struct zint_symbol *symbol; | |
| 1857 struct zint_symbol *symbol_def; | |
| 1858 char *data = "1234"; | |
| 1859 | |
| 1860 (void)p_ctx; | |
| 1861 | |
| 1862 testStart("test_reset"); | |
| 1863 | |
| 1864 symbol_def = ZBarcode_Create(); | |
| 1865 assert_nonnull(symbol_def, "Default symbol not created\n"); | |
| 1866 | |
| 1867 symbol = ZBarcode_Create(); | |
| 1868 assert_nonnull(symbol, "Symbol not created\n"); | |
| 1869 | |
| 1870 set_symbol_fields(symbol); | |
| 1871 | |
| 1872 /* Raster */ | |
| 1873 | |
| 1874 ret = ZBarcode_Encode(symbol, TU(data), 0); | |
| 1875 assert_zero(ret, "ZBarcode_Encode() ret %d != 0 (%s)\n", ret, symbol->errtxt); | |
| 1876 | |
| 1877 assert_nonzero(symbol->rows, "ZBarcode_Encode() rows 0\n"); | |
| 1878 assert_nonzero(symbol->width, "ZBarcode_Encode() width 0\n"); | |
| 1879 | |
| 1880 ret = ZBarcode_Buffer(symbol, 0); | |
| 1881 assert_zero(ret, "ZBarcode_Buffer() ret %d != 0 (%s)\n", ret, symbol->errtxt); | |
| 1882 | |
| 1883 assert_nonnull(symbol->bitmap, "ZBarcode_Buffer() bitmap NULL\n"); | |
| 1884 assert_nonnull(symbol->alphamap, "ZBarcode_Buffer() alphamap NULL\n"); | |
| 1885 assert_nonzero(symbol->bitmap_width, "ZBarcode_Buffer() bitmap_width 0\n"); | |
| 1886 assert_nonzero(symbol->bitmap_height, "ZBarcode_Buffer() bitmap_height 0\n"); | |
| 1887 | |
| 1888 assert_nonzero(symbol->rows, "ZBarcode_Buffer() rows 0\n"); | |
| 1889 assert_nonzero(symbol->width, "ZBarcode_Buffer() width 0\n"); | |
| 1890 assert_null(symbol->vector, "ZBarcode_Buffer() vector != NULL\n"); | |
| 1891 | |
| 1892 ZBarcode_Reset(symbol); | |
| 1893 | |
| 1894 assert_nonzero(symbol->symbology == symbol_def->symbology, "ZBarcodeBuffer symbology != symbol_def\n"); | |
| 1895 assert_nonzero(symbol->height == symbol_def->height, "ZBarcodeBuffer height != symbol_def\n"); | |
| 1896 assert_nonzero(symbol->scale == symbol_def->scale, "ZBarcodeBuffer scale != symbol_def\n"); | |
| 1897 assert_nonzero(symbol->whitespace_width == symbol_def->whitespace_width, "ZBarcodeBuffer whitespace_width != symbol_def\n"); | |
| 1898 assert_nonzero(symbol->whitespace_height == symbol_def->whitespace_height, "ZBarcodeBuffer whitespace_height != symbol_def\n"); | |
| 1899 assert_nonzero(symbol->border_width == symbol_def->border_width, "ZBarcodeBuffer border_width != symbol_def\n"); | |
| 1900 assert_nonzero(symbol->output_options == symbol_def->output_options, "ZBarcodeBuffer output_options != symbol_def\n"); | |
| 1901 assert_zero(strcmp(symbol->fgcolour, symbol_def->fgcolour), "ZBarcodeBuffer fgcolour != symbol_def\n"); | |
| 1902 assert_zero(strcmp(symbol->bgcolour, symbol_def->bgcolour), "ZBarcodeBuffer bgcolour != symbol_def\n"); | |
| 1903 assert_zero(strcmp(symbol->fgcolor, symbol_def->fgcolor), "ZBarcodeBuffer fgcolor != symbol_def\n"); | |
| 1904 assert_zero(strcmp(symbol->bgcolor, symbol_def->bgcolor), "ZBarcodeBuffer bgcolor != symbol_def\n"); | |
| 1905 assert_zero(strcmp(symbol->outfile, symbol_def->outfile), "ZBarcodeBuffer outfile != symbol_def\n"); | |
| 1906 assert_zero(strcmp(symbol->primary, symbol_def->primary), "ZBarcodeBuffer primary != symbol_def\n"); | |
| 1907 assert_nonzero(symbol->option_1 == symbol_def->option_1, "ZBarcodeBuffer option_1 != symbol_def\n"); | |
| 1908 assert_nonzero(symbol->option_2 == symbol_def->option_2, "ZBarcodeBuffer option_2 != symbol_def\n"); | |
| 1909 assert_nonzero(symbol->option_3 == symbol_def->option_3, "ZBarcodeBuffer option_3 != symbol_def\n"); | |
| 1910 assert_nonzero(symbol->show_hrt == symbol_def->show_hrt, "ZBarcodeBuffer show_hrt != symbol_def\n"); | |
| 1911 assert_nonzero(symbol->input_mode == symbol_def->input_mode, "ZBarcodeBuffer input_mode != symbol_def\n"); | |
| 1912 assert_nonzero(symbol->eci == symbol_def->eci, "ZBarcodeBuffer eci != symbol_def\n"); | |
| 1913 assert_nonzero(symbol->dpmm == symbol_def->dpmm, "ZBarcodeBuffer dpmm != symbol_def\n"); | |
| 1914 assert_nonzero(symbol->dot_size == symbol_def->dot_size, "ZBarcodeBuffer dot_size != symbol_def\n"); | |
| 1915 assert_nonzero(symbol->text_gap == symbol_def->text_gap, "ZBarcodeBuffer text_gap != symbol_def\n"); | |
| 1916 assert_nonzero(symbol->guard_descent == symbol_def->guard_descent, "ZBarcodeBuffer guard_descent != symbol_def\n"); | |
| 1917 assert_nonzero(symbol->structapp.index == symbol_def->structapp.index, "ZBarcodeBuffer structapp.index != symbol_def\n"); | |
| 1918 assert_nonzero(symbol->structapp.count == symbol_def->structapp.count, "ZBarcodeBuffer structapp.count != symbol_def\n"); | |
| 1919 assert_nonzero(symbol->warn_level == symbol_def->warn_level, "ZBarcodeBuffer warn_level != symbol_def\n"); | |
| 1920 | |
| 1921 /* Vector */ | |
| 1922 | |
| 1923 set_symbol_fields(symbol); | |
| 1924 | |
| 1925 ret = ZBarcode_Encode(symbol, TU(data), 0); | |
| 1926 assert_zero(ret, "ZBarcode_Encode() ret %d != 0 (%s)\n", ret, symbol->errtxt); | |
| 1927 | |
| 1928 assert_nonzero(symbol->rows, "ZBarcode_Encode() rows 0\n"); | |
| 1929 assert_nonzero(symbol->width, "ZBarcode_Encode() width 0\n"); | |
| 1930 | |
| 1931 ret = ZBarcode_Buffer_Vector(symbol, 0); | |
| 1932 assert_zero(ret, "ZBarcode_Buffer_Vector() ret %d != 0 (%s)\n", ret, symbol->errtxt); | |
| 1933 | |
| 1934 assert_nonnull(symbol->vector, "ZBarcode_Buffer_Vector() vector NULL\n"); | |
| 1935 assert_nonnull(symbol->vector->rectangles, "ZBarcode_Buffer_Vector() vector->rectangles NULL\n"); | |
| 1936 assert_nonnull(symbol->vector->hexagons, "ZBarcode_Buffer_Vector() vector->hexagons NULL\n"); | |
| 1937 assert_null(symbol->vector->strings, "ZBarcode_Buffer_Vector() vector->strings != NULL\n"); /* MAXICODE no text */ | |
| 1938 assert_nonnull(symbol->vector->circles, "ZBarcode_Buffer_Vector() vector->circles NULL\n"); | |
| 1939 | |
| 1940 assert_nonzero(symbol->rows, "ZBarcode_Buffer_Vector() rows 0\n"); | |
| 1941 assert_nonzero(symbol->width, "ZBarcode_Buffer_Vector() width 0\n"); | |
| 1942 assert_null(symbol->bitmap, "ZBarcode_Buffer_Vector() bitmap != NULL\n"); | |
| 1943 assert_null(symbol->alphamap, "ZBarcode_Buffer_Vector() alphamap != NULL\n"); | |
| 1944 | |
| 1945 ZBarcode_Reset(symbol); | |
| 1946 | |
| 1947 assert_nonzero(symbol->symbology == symbol_def->symbology, "ZBarcodeBuffer symbology != symbol_def\n"); | |
| 1948 assert_nonzero(symbol->height == symbol_def->height, "ZBarcodeBuffer height != symbol_def\n"); | |
| 1949 assert_nonzero(symbol->scale == symbol_def->scale, "ZBarcodeBuffer scale != symbol_def\n"); | |
| 1950 assert_nonzero(symbol->whitespace_width == symbol_def->whitespace_width, "ZBarcodeBuffer whitespace_width != symbol_def\n"); | |
| 1951 assert_nonzero(symbol->whitespace_height == symbol_def->whitespace_height, "ZBarcodeBuffer whitespace_height != symbol_def\n"); | |
| 1952 assert_nonzero(symbol->border_width == symbol_def->border_width, "ZBarcodeBuffer border_width != symbol_def\n"); | |
| 1953 assert_nonzero(symbol->output_options == symbol_def->output_options, "ZBarcodeBuffer output_options != symbol_def\n"); | |
| 1954 assert_zero(strcmp(symbol->fgcolour, symbol_def->fgcolour), "ZBarcodeBuffer fgcolour != symbol_def\n"); | |
| 1955 assert_zero(strcmp(symbol->bgcolour, symbol_def->bgcolour), "ZBarcodeBuffer bgcolour != symbol_def\n"); | |
| 1956 assert_zero(strcmp(symbol->fgcolor, symbol_def->fgcolor), "ZBarcodeBuffer fgcolor != symbol_def\n"); | |
| 1957 assert_zero(strcmp(symbol->bgcolor, symbol_def->bgcolor), "ZBarcodeBuffer bgcolor != symbol_def\n"); | |
| 1958 assert_zero(strcmp(symbol->outfile, symbol_def->outfile), "ZBarcodeBuffer outfile != symbol_def\n"); | |
| 1959 assert_zero(strcmp(symbol->primary, symbol_def->primary), "ZBarcodeBuffer primary != symbol_def\n"); | |
| 1960 assert_nonzero(symbol->option_1 == symbol_def->option_1, "ZBarcodeBuffer option_1 != symbol_def\n"); | |
| 1961 assert_nonzero(symbol->option_2 == symbol_def->option_2, "ZBarcodeBuffer option_2 != symbol_def\n"); | |
| 1962 assert_nonzero(symbol->option_3 == symbol_def->option_3, "ZBarcodeBuffer option_3 != symbol_def\n"); | |
| 1963 assert_nonzero(symbol->show_hrt == symbol_def->show_hrt, "ZBarcodeBuffer show_hrt != symbol_def\n"); | |
| 1964 assert_nonzero(symbol->input_mode == symbol_def->input_mode, "ZBarcodeBuffer input_mode != symbol_def\n"); | |
| 1965 assert_nonzero(symbol->eci == symbol_def->eci, "ZBarcodeBuffer eci != symbol_def\n"); | |
| 1966 assert_nonzero(symbol->dpmm == symbol_def->dpmm, "ZBarcodeBuffer dpmm != symbol_def\n"); | |
| 1967 assert_nonzero(symbol->dot_size == symbol_def->dot_size, "ZBarcodeBuffer dot_size != symbol_def\n"); | |
| 1968 assert_nonzero(symbol->text_gap == symbol_def->text_gap, "ZBarcodeBuffer text_gap != symbol_def\n"); | |
| 1969 assert_nonzero(symbol->guard_descent == symbol_def->guard_descent, "ZBarcodeBuffer guard_descent != symbol_def\n"); | |
| 1970 assert_nonzero(symbol->structapp.index == symbol_def->structapp.index, "ZBarcodeBuffer structapp.index != symbol_def\n"); | |
| 1971 assert_nonzero(symbol->structapp.count == symbol_def->structapp.count, "ZBarcodeBuffer structapp.count != symbol_def\n"); | |
| 1972 assert_nonzero(symbol->warn_level == symbol_def->warn_level, "ZBarcodeBuffer warn_level != symbol_def\n"); | |
| 1973 | |
| 1974 ZBarcode_Delete(symbol); | |
| 1975 ZBarcode_Delete(symbol_def); | |
| 1976 | |
| 1977 testFinish(); | |
| 1978 } | |
| 1979 | |
| 1980 static void test_scale_from_xdimdp(const testCtx *const p_ctx) { | |
| 1981 | |
| 1982 struct item { | |
| 1983 int symbology; | |
| 1984 float x_dim; | |
| 1985 float dpmm; | |
| 1986 int dpi; | |
| 1987 char *filetype; | |
| 1988 float expected; | |
| 1989 }; | |
| 1990 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 1991 static const struct item data[] = { | |
| 1992 /* 0*/ { BARCODE_EANX, 0.33f, 2, 50, "gif", 0.5f }, | |
| 1993 /* 1*/ { BARCODE_EANX, 0.33f, 2, 50, "emf", 0.33000001f }, | |
| 1994 /* 2*/ { BARCODE_EANX, 0.33f, 2, 50, "svg", 0.33000001f }, | |
| 1995 /* 3*/ { BARCODE_EANX, 0.33f, 3, 76, "gif", 0.5f }, | |
| 1996 /* 4*/ { BARCODE_EANX, 0.33f, 3, 76, "svg", 0.495f }, | |
| 1997 /* 5*/ { BARCODE_EANX, 0.33f, 4, 100, "gif", 0.5f }, | |
| 1998 /* 6*/ { BARCODE_EANX, 0.33f, 4, 100, "svg", 0.66000003f }, | |
| 1999 /* 7*/ { BARCODE_EANX, 0.33f, 6, 150, "gif", 1 }, | |
| 2000 /* 8*/ { BARCODE_EANX, 0.33f, 6, 150, "svg", 0.99f }, | |
| 2001 /* 9*/ { BARCODE_EANX, 0.33f, 8, 200, "gif", 1.5f }, | |
| 2002 /* 10*/ { BARCODE_EANX, 0.33f, 8, 200, "svg", 1.32f }, | |
| 2003 /* 11*/ { BARCODE_EANX, 0.33f, 12, 300, "gif", 2 }, | |
| 2004 /* 12*/ { BARCODE_EANX, 0.33f, 12, 300, "svg", 1.98f }, | |
| 2005 /* 13*/ { BARCODE_EANX, 0.33f, 16, 400, "gif", 2.5f }, /* NOTE: scale previously documented as 3.0f */ | |
| 2006 /* 14*/ { BARCODE_EANX, 0.33f, 16, 400, "svg", 2.64f }, | |
| 2007 /* 15*/ { BARCODE_EANX, 0.33f, 24, 600, "gif", 4 }, | |
| 2008 /* 16*/ { BARCODE_EANX, 0.33f, 24, 600, "svg", 3.96f }, | |
| 2009 /* 17*/ { BARCODE_EANX, 0.33f, 47, 1200, "gif", 8 }, | |
| 2010 /* 18*/ { BARCODE_EANX, 0.33f, 47, 1200, "emf", 7.755f }, | |
| 2011 /* 19*/ { BARCODE_EANX, 0.33f, 47, 1200, "svg", 7.755f }, | |
| 2012 /* 20*/ { BARCODE_EANX, 0.33f, 94, 2400, "gif", 15.5f }, /* NOTE dpmm previously documented as 95 */ | |
| 2013 /* 21*/ { BARCODE_EANX, 0.33f, 94, 2400, "svg", 15.51f }, | |
| 2014 /* 22*/ { BARCODE_EANX, 0.33f, 189, 4800, "gif", 31 }, | |
| 2015 /* 23*/ { BARCODE_EANX, 0.33f, 189, 4800, "svg", 31.185001f }, | |
| 2016 /* 24*/ { BARCODE_EANX, 0.33f, 378, 9600, "gif", 62.5f }, | |
| 2017 /* 25*/ { BARCODE_EANX, 0.33f, 378, 9600, "svg", 62.370003f }, | |
| 2018 /* 26*/ { BARCODE_MAXICODE, 0.88f, 4, 100, "gif", 0.352f }, | |
| 2019 /* 27*/ { BARCODE_MAXICODE, 0.88f, 4, 100, "emf", 0.1f }, /* NOTE scale rounded up to min 0.1 so doesn't round trip */ | |
| 2020 /* 28*/ { BARCODE_MAXICODE, 0.88f, 4, 100, "svg", 1.76f }, | |
| 2021 /* 29*/ { BARCODE_MAXICODE, 0.88f, 6, 150, "gif", 0.528f }, /* NOTE scale previously documented as 0.5f */ | |
| 2022 /* 30*/ { BARCODE_MAXICODE, 0.88f, 6, 150, "emf", 0.132f }, | |
| 2023 /* 31*/ { BARCODE_MAXICODE, 0.88f, 6, 150, "svg", 2.6399999 }, | |
| 2024 /* 32*/ { BARCODE_MAXICODE, 0.88f, 8, 200, "gif", 0.704f }, /* NOTE scale previously documented as 0.7f */ | |
| 2025 /* 33*/ { BARCODE_MAXICODE, 0.88f, 8, 200, "emf", 0.176f }, | |
| 2026 /* 34*/ { BARCODE_MAXICODE, 0.88f, 8, 200, "svg", 3.52f }, | |
| 2027 /* 35*/ { BARCODE_MAXICODE, 0.88f, 12, 300, "gif", 1.056f }, /* NOTE scale previously documented as 1.0f */ | |
| 2028 /* 36*/ { BARCODE_MAXICODE, 0.88f, 12, 300, "emf", 0.264f }, | |
| 2029 /* 37*/ { BARCODE_MAXICODE, 0.88f, 12, 300, "svg", 5.2799997f }, | |
| 2030 /* 38*/ { BARCODE_MAXICODE, 0.88f, 16, 400, "gif", 1.408f }, /* NOTE scale previously documented as 1.4f */ | |
| 2031 /* 39*/ { BARCODE_MAXICODE, 0.88f, 16, 400, "emf", 0.352f }, | |
| 2032 /* 40*/ { BARCODE_MAXICODE, 0.88f, 16, 400, "gif", 1.408f }, | |
| 2033 /* 41*/ { BARCODE_MAXICODE, 0.88f, 24, 600, "gif", 2.112f }, /* NOTE scale previously documented as 2.1f */ | |
| 2034 /* 42*/ { BARCODE_MAXICODE, 0.88f, 24, 600, "emf", 0.528f }, | |
| 2035 /* 43*/ { BARCODE_MAXICODE, 0.88f, 24, 600, "svg", 10.559999f }, | |
| 2036 /* 44*/ { BARCODE_MAXICODE, 0.88f, 47, 1200, "gif", 4.136f }, /* NOTE scale previously documented as 4.1f */ | |
| 2037 /* 45*/ { BARCODE_MAXICODE, 0.88f, 47, 1200, "emf", 1.034f }, | |
| 2038 /* 46*/ { BARCODE_MAXICODE, 0.88f, 47, 1200, "svg", 20.68f }, | |
| 2039 /* 47*/ { BARCODE_MAXICODE, 0.88f, 94, 2400, "gif", 8.272f }, /* NOTE dpmm previously documented as 95, scale as 8.2f */ | |
| 2040 /* 48*/ { BARCODE_MAXICODE, 0.88f, 94, 2400, "emf", 2.0680001f }, | |
| 2041 /* 49*/ { BARCODE_MAXICODE, 0.88f, 94, 2400, "svg", 41.360001f }, | |
| 2042 /* 50*/ { BARCODE_MAXICODE, 0.88f, 189, 4800, "gif", 16.632f }, /* NOTE scale previously documented as 16.4f */ | |
| 2043 /* 51*/ { BARCODE_MAXICODE, 0.88f, 189, 4800, "emf", 4.158f }, | |
| 2044 /* 52*/ { BARCODE_MAXICODE, 0.88f, 189, 4800, "svg", 83.159996f }, | |
| 2045 /* 53*/ { BARCODE_MAXICODE, 0.88f, 378, 9600, "gif", 33.264f }, | |
| 2046 /* 54*/ { BARCODE_MAXICODE, 0.88f, 378, 9600, "emf", 8.316f }, | |
| 2047 /* 55*/ { BARCODE_MAXICODE, 0.88f, 378, 9600, "svg", 166.31999f }, | |
| 2048 /* 56*/ { BARCODE_PDF417, 0.27f, 2, 50, "gif", 0.5f }, | |
| 2049 /* 57*/ { BARCODE_PDF417, 0.27f, 2, 50, "svg", 0.27000001f }, | |
| 2050 /* 58*/ { BARCODE_PDF417, 0.27f, 6, 150, "gif", 1 }, | |
| 2051 /* 59*/ { BARCODE_PDF417, 0.27f, 6, 150, "svg", 0.81000006f }, | |
| 2052 /* 60*/ { BARCODE_PDF417, 0.27f, 12, 300, "gif", 1.5 }, | |
| 2053 /* 61*/ { BARCODE_PDF417, 0.27f, 12, 300, "svg", 1.6200001f }, | |
| 2054 /* 62*/ { BARCODE_PDF417, 0.27f, 24, 600, "gif", 3 }, | |
| 2055 /* 63*/ { BARCODE_PDF417, 0.27f, 24, 600, "emf", 3.2400002f }, | |
| 2056 /* 64*/ { BARCODE_PDF417, 0.27f, 24, 600, "svg", 3.2400002f }, | |
| 2057 /* 65*/ { BARCODE_PHARMA_TWO, 1, 2, 50, "gif", 1 }, | |
| 2058 /* 66*/ { BARCODE_PHARMA_TWO, 1, 2, 50, "svg", 1 }, | |
| 2059 /* 67*/ { BARCODE_PHARMA_TWO, 1, 6, 150, "gif", 3 }, | |
| 2060 /* 68*/ { BARCODE_PHARMA_TWO, 1, 6, 150, "svg", 3 }, | |
| 2061 /* 69*/ { BARCODE_PHARMA_TWO, 1, 8, 200, "gif", 4 }, | |
| 2062 /* 70*/ { BARCODE_PHARMA_TWO, 1, 8, 200, "svg", 4 }, | |
| 2063 /* 71*/ { BARCODE_PHARMA_TWO, 1, 189, 4800, "gif", 94.5f }, | |
| 2064 /* 72*/ { BARCODE_PHARMA_TWO, 1, 189, 4800, "svg", 94.5f }, | |
| 2065 /* 73*/ { BARCODE_PHARMA_TWO, 1, 378, 9600, "gif", 189 }, | |
| 2066 /* 74*/ { BARCODE_PHARMA_TWO, 1, 378, 9600, "svg", 189 }, | |
| 2067 /* 75*/ { BARCODE_PHARMA_TWO, 1, 401, 10200, "gif", 200 }, /* NOTE scale capped to 200 so doesn't round trip */ | |
| 2068 /* 76*/ { BARCODE_PHARMA_TWO, 1, 401, 10200, "svg", 200 }, | |
| 2069 /* 77*/ { BARCODE_CODE128, 0.5, 12, 300, "gif", 3 }, | |
| 2070 /* 78*/ { BARCODE_CODE128, 0, 12, -1, "gif", 0 }, /* x_dim zero */ | |
| 2071 /* 79*/ { BARCODE_CODE128, 200.1f, 12, -1, "gif", 0 }, /* x_dim > 200 */ | |
| 2072 /* 80*/ { BARCODE_CODE128, 0.5f, -0.1f, -1, "gif", 0 }, /* dpmm neg */ | |
| 2073 /* 81*/ { BARCODE_CODE128, 0.5f, 1000.1, -1, "gif", 0 }, /* dpmm > 1000 */ | |
| 2074 /* 82*/ { BARCODE_CODE128, 0.5f, 300, -1, "abcd", 0 }, /* filetype unknown */ | |
| 2075 /* 83*/ { BARCODE_QRCODE, 10, 31, 800, "gif", 155 }, | |
| 2076 }; | |
| 2077 const int data_size = ARRAY_SIZE(data); | |
| 2078 int i; | |
| 2079 float ret; | |
| 2080 float x_dim_from_scale; | |
| 2081 float dpmm_from_dpi; | |
| 2082 | |
| 2083 testStart("test_scale_from_xdimdp"); | |
| 2084 | |
| 2085 for (i = 0; i < data_size; i++) { | |
| 2086 | |
| 2087 if (testContinue(p_ctx, i)) continue; | |
| 2088 | |
| 2089 ret = ZBarcode_Scale_From_XdimDp(data[i].symbology, data[i].x_dim, data[i].dpmm, data[i].filetype); | |
| 2090 assert_equal(ret, data[i].expected, "i:%d ZBarcode_Scale_From_XdimDp(%s, %g, %g, %s) %.8g != %.8g\n", | |
| 2091 i, testUtilBarcodeName(data[i].symbology), data[i].dpmm, data[i].x_dim, data[i].filetype, ret, data[i].expected); | |
| 2092 | |
| 2093 if (ret) { | |
| 2094 dpmm_from_dpi = stripf(roundf(data[i].dpi / 25.4f)); | |
| 2095 ret = ZBarcode_Scale_From_XdimDp(data[i].symbology, data[i].x_dim, dpmm_from_dpi, data[i].filetype); | |
| 2096 assert_equal(ret, data[i].expected, "i:%d ZBarcode_Scale_From_XdimDp(%s, %g (dpi %d), %g, %s) %.8g != %.8g\n", | |
| 2097 i, testUtilBarcodeName(data[i].symbology), dpmm_from_dpi, data[i].dpi, data[i].x_dim, data[i].filetype, ret, data[i].expected); | |
| 2098 | |
| 2099 if (data[i].expected > 0.1f && data[i].expected < 200.0f /* Can't round trip scales <= 0.1 or >= 200.0 */ | |
| 2100 && (data[i].symbology == BARCODE_MAXICODE || strcmp(data[i].filetype, "gif") != 0)) { /* Non-MAXICODE raster rounds to half-increments */ | |
| 2101 x_dim_from_scale = ZBarcode_XdimDp_From_Scale(data[i].symbology, ret, data[i].dpmm, data[i].filetype); | |
| 2102 x_dim_from_scale = stripf(stripf(roundf(x_dim_from_scale * 100.0f)) / 100.0f); | |
| 2103 assert_equal(x_dim_from_scale, data[i].x_dim, "i:%d ZBarcode_XdimDp_From_Scale(%s, %g, %g, %s) %.8g != x_dim %.8g\n", | |
| 2104 i, testUtilBarcodeName(data[i].symbology), ret, data[i].x_dim, data[i].filetype, x_dim_from_scale, data[i].x_dim); | |
| 2105 } | |
| 2106 } | |
| 2107 } | |
| 2108 | |
| 2109 testFinish(); | |
| 2110 } | |
| 2111 | |
| 2112 static void test_xdimdp_from_scale(const testCtx *const p_ctx) { | |
| 2113 | |
| 2114 struct item { | |
| 2115 int symbology; | |
| 2116 float scale; | |
| 2117 float dpmm; /* Note testing "normal" case that want X-dim, not dpmm */ | |
| 2118 int dpi; | |
| 2119 char *filetype; | |
| 2120 float expected; | |
| 2121 }; | |
| 2122 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 2123 static const struct item data[] = { | |
| 2124 /* 0*/ { BARCODE_EANX, 1, 6, 150, "gif", 0.33333334f }, | |
| 2125 /* 1*/ { BARCODE_EANX, 1.32f, 8, 200, "gif", 0.33000001f }, | |
| 2126 /* 2*/ { BARCODE_EANX, 1.5f, 8, 200, "gif", 0.375f }, | |
| 2127 /* 3*/ { BARCODE_EANX, 1.98f, 12, 300, "gif", 0.33f }, | |
| 2128 /* 4*/ { BARCODE_EANX, 2, 12, 300, "gif", 0.33333334f }, | |
| 2129 /* 5*/ { BARCODE_EANX, 2, 12, 300, "svg", 0.33333334f }, | |
| 2130 /* 6*/ { BARCODE_EANX, 2.64f, 16, 400, "gif", 0.33f }, | |
| 2131 /* 7*/ { BARCODE_EANX, 2.5f, 16, 400, "gif", 0.3125f }, | |
| 2132 /* 8*/ { BARCODE_EANX, 3.96f, 24, 600, "gif", 0.33f }, | |
| 2133 /* 9*/ { BARCODE_EANX, 3.96f, 24, 600, "svg", 0.33f }, | |
| 2134 /* 10*/ { BARCODE_EANX, 4, 24, 600, "gif", 0.33333334f }, | |
| 2135 /* 11*/ { BARCODE_EANX, 7.755f, 47, 1200, "gif", 0.33f }, | |
| 2136 /* 12*/ { BARCODE_EANX, 8, 47, 1200, "gif", 0.34042552f }, | |
| 2137 /* 13*/ { BARCODE_EANX, 15.51f, 94, 2400, "gif", 0.33f }, | |
| 2138 /* 14*/ { BARCODE_EANX, 15.5f, 94, 2400, "gif", 0.32978722f }, | |
| 2139 /* 15*/ { BARCODE_EANX, 31.185001f, 189, 4800, "gif", 0.33f }, | |
| 2140 /* 16*/ { BARCODE_EANX, 31, 189, 4800, "gif", 0.32804233f }, | |
| 2141 /* 17*/ { BARCODE_MAXICODE, 1, 12, 300, "gif", 0.83333331f }, | |
| 2142 /* 18*/ { BARCODE_MAXICODE, 0.264f, 12, 300, "emf", 0.87999994f }, | |
| 2143 /* 19*/ { BARCODE_MAXICODE, 5.2799997f, 12, 300, "svg", 0.87999994f }, | |
| 2144 /* 20*/ { BARCODE_MAXICODE, 2, 24, 600, "gif", 0.83333331f }, | |
| 2145 /* 21*/ { BARCODE_MAXICODE, 0.528f, 24, 600, "emf", 0.87999994f }, | |
| 2146 /* 22*/ { BARCODE_MAXICODE, 10.559999f, 24, 600, "svg", 0.87999994f }, | |
| 2147 /* 23*/ { BARCODE_CODE128, 0, 12, -1, "gif", 0 }, /* scale zero */ | |
| 2148 /* 24*/ { BARCODE_CODE128, 200.01f, 12, -1, "gif", 0 }, /* scale > 200 */ | |
| 2149 /* 25*/ { BARCODE_CODE128, 0.5f, 0, -1, "gif", 0 }, /* xdim_mm_or_dpmm zero */ | |
| 2150 /* 26*/ { BARCODE_CODE128, 0.5f, 1000.1f, -1, "gif", 0 }, /* xdim_mm_or_dpmm > 1000 */ | |
| 2151 }; | |
| 2152 const int data_size = ARRAY_SIZE(data); | |
| 2153 int i; | |
| 2154 float ret; | |
| 2155 float dpmm_from_dpi; | |
| 2156 | |
| 2157 testStart("test_xdimdp_from_scale"); | |
| 2158 | |
| 2159 for (i = 0; i < data_size; i++) { | |
| 2160 | |
| 2161 if (testContinue(p_ctx, i)) continue; | |
| 2162 | |
| 2163 ret = ZBarcode_XdimDp_From_Scale(data[i].symbology, data[i].scale, data[i].dpmm, data[i].filetype); | |
| 2164 assert_equal(ret, data[i].expected, "i:%d ZBarcode_XdimDp_From_Scale(%s, %g, %g, %s) %.8g != %.8g\n", | |
| 2165 i, testUtilBarcodeName(data[i].symbology), data[i].dpmm, data[i].scale, data[i].filetype, ret, data[i].expected); | |
| 2166 | |
| 2167 if (ret) { | |
| 2168 dpmm_from_dpi = stripf(roundf(data[i].dpi / 25.4f)); | |
| 2169 ret = ZBarcode_XdimDp_From_Scale(data[i].symbology, data[i].scale, dpmm_from_dpi, data[i].filetype); | |
| 2170 assert_equal(ret, data[i].expected, "i:%d ZBarcode_XdimDp_From_Scale(%s, %g (dpi %d), %g, %s) %.8g != %.8g\n", | |
| 2171 i, testUtilBarcodeName(data[i].symbology), dpmm_from_dpi, data[i].dpi, data[i].scale, data[i].filetype, ret, data[i].expected); | |
| 2172 } | |
| 2173 } | |
| 2174 | |
| 2175 testFinish(); | |
| 2176 } | |
| 2177 | |
| 2178 int main(int argc, char *argv[]) { | |
| 2179 | |
| 2180 testFunction funcs[] = { /* name, func */ | |
| 2181 { "test_checks", test_checks }, | |
| 2182 { "test_checks_segs", test_checks_segs }, | |
| 2183 { "test_input_data", test_input_data }, | |
| 2184 { "test_symbologies", test_symbologies }, | |
| 2185 { "test_input_mode", test_input_mode }, | |
| 2186 { "test_escape_char_process", test_escape_char_process }, | |
| 2187 { "test_escape_char_process_test", test_escape_char_process_test }, | |
| 2188 { "test_cap", test_cap }, | |
| 2189 { "test_cap_compliant_height", test_cap_compliant_height }, | |
| 2190 { "test_encode_file_empty", test_encode_file_empty }, | |
| 2191 { "test_encode_file_too_large", test_encode_file_too_large }, | |
| 2192 { "test_encode_file_unreadable", test_encode_file_unreadable }, | |
| 2193 { "test_encode_file_directory", test_encode_file_directory }, | |
| 2194 { "test_encode_file", test_encode_file }, | |
| 2195 { "test_encode_print_outfile_directory", test_encode_print_outfile_directory }, | |
| 2196 { "test_bad_args", test_bad_args }, | |
| 2197 { "test_valid_id", test_valid_id }, | |
| 2198 { "test_barcode_name", test_barcode_name }, | |
| 2199 { "test_error_tag", test_error_tag }, | |
| 2200 { "test_strip_bom", test_strip_bom }, | |
| 2201 { "test_zero_outfile", test_zero_outfile }, | |
| 2202 { "test_clear", test_clear }, | |
| 2203 { "test_reset", test_reset }, | |
| 2204 { "test_scale_from_xdimdp", test_scale_from_xdimdp }, | |
| 2205 { "test_xdimdp_from_scale", test_xdimdp_from_scale }, | |
| 2206 }; | |
| 2207 | |
| 2208 testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); | |
| 2209 | |
| 2210 testReport(); | |
| 2211 | |
| 2212 return 0; | |
| 2213 } | |
| 2214 | |
| 2215 /* vim: set ts=4 sw=4 et : */ |
