comparison mupdf-source/thirdparty/zint/frontend/tests/test_args.c @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /*
2 libzint - the open source barcode library
3 Copyright (C) 2020-2024 Robin Stuart <rstuart114@gmail.com>
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 3. Neither the name of the project nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 SUCH DAMAGE.
29 */
30 /* SPDX-License-Identifier: BSD-3-Clause */
31
32 #ifndef _WIN32
33 #include <sys/wait.h>
34 #endif
35
36 #include "testcommon.h"
37
38 #ifdef _WIN32
39 /* Hacks to stop popen() mangling input on Windows */
40 static int utf8_to_wchar(const char *str, wchar_t *out) {
41 unsigned int codepoint, state = 0;
42
43 while (*str) {
44 do {
45 decode_utf8(&state, &codepoint, *str++);
46 } while (*str && state != 0 && state != 12);
47 if (state != 0) {
48 return 0;
49 }
50 *out++ = codepoint;
51 }
52 *out = L'\0';
53
54 return 1;
55 }
56
57 static int escape_cmd(const char *str, char *buf) {
58 int ret = 0;
59 char *out = buf;
60 const unsigned char *ustr;
61
62 for (ustr = (const unsigned char *) str; *ustr; ustr++) {
63 if (*ustr >= 0x80 || *ustr < 0x20 || *ustr == '\\') {
64 sprintf(out, "\\x%02X", *ustr);
65 out += 4;
66 ret = 1;
67 } else {
68 *out++ = *ustr;
69 }
70 }
71 *out = '\0';
72 if (ret) {
73 if (out - buf > 5 && strcmp(out - 5, " 2>&1") == 0) {
74 strcpy(out - 5, " --esc 2>&1");
75 } else {
76 strcpy(out, " --esc");
77 }
78 }
79
80 return ret;
81 }
82 #endif
83
84 static char *exec(const char *cmd, char *buf, int buf_size, int debug, int index, int *p_exit_status) {
85 FILE *fp;
86 int cnt;
87 int exit_status;
88 #ifdef _WIN32
89 wchar_t wchar_cmd[8192];
90 char esc_cmd[16384];
91 int is_binary = strstr(cmd, " --binary") != NULL;
92 int is_escaped = strstr(cmd, " --esc") != NULL;
93 #endif
94
95 if (debug & ZINT_DEBUG_TEST_PRINT) printf("%d: %s\n", index, cmd);
96
97 *buf = '\0';
98
99 #ifdef _WIN32
100 if (!is_binary && utf8_to_wchar(cmd, wchar_cmd)) {
101 fp = _wpopen(wchar_cmd, L"r");
102 } else if (!is_escaped && is_binary && escape_cmd(cmd, esc_cmd)) {
103 fp = testutil_popen(esc_cmd, "r");
104 } else {
105 fp = testutil_popen(cmd, "r");
106 }
107 #else
108 fp = testutil_popen(cmd, "r");
109 #endif
110 if (!fp) {
111 fprintf(stderr, "exec: failed to run '%s'\n", cmd);
112 return NULL;
113 }
114 cnt = (int) fread(buf, 1, buf_size, fp);
115 if (fgetc(fp) != EOF) {
116 fprintf(stderr, "exec: failed to read full stream (%s)\n", cmd);
117 exit_status = testutil_pclose(fp);
118 if (p_exit_status) {
119 #ifndef _WIN32
120 if (WIFEXITED(exit_status)) {
121 exit_status = WEXITSTATUS(exit_status);
122 }
123 #endif
124 *p_exit_status = exit_status;
125 }
126 return NULL;
127 }
128 exit_status = testutil_pclose(fp);
129 if (p_exit_status) {
130 #ifndef _WIN32
131 if (WIFEXITED(exit_status)) {
132 exit_status = WEXITSTATUS(exit_status);
133 }
134 #endif
135 *p_exit_status = exit_status;
136 }
137
138 if (cnt) {
139 if (buf[cnt - 1] == '\r' || buf[cnt - 1] == '\n') {
140 buf[cnt - 1] = '\0';
141 if (cnt > 1 && (buf[cnt - 2] == '\r' || buf[cnt - 2] == '\n')) {
142 buf[cnt - 2] = '\0';
143 }
144 }
145 }
146
147 return buf;
148 }
149
150 static void arg_int(char *cmd, const char *opt, int val) {
151 if (val != -1) {
152 sprintf(cmd + strlen(cmd), "%s%s%d", strlen(cmd) ? " " : "", opt, val);
153 }
154 }
155
156 static void arg_bool(char *cmd, const char *opt, int val) {
157 if (val == 1) {
158 sprintf(cmd + strlen(cmd), "%s%s", strlen(cmd) ? " " : "", opt);
159 }
160 }
161
162 static void arg_double(char *cmd, const char *opt, double val) {
163 if (val != -1) {
164 sprintf(cmd + strlen(cmd), "%s%s%.8f", strlen(cmd) ? " " : "", opt, val);
165 }
166 }
167
168 static void arg_data(char *cmd, const char *opt, const char *data) {
169 if (data != NULL) {
170 sprintf(cmd + strlen(cmd), "%s%s\"%s\"", strlen(cmd) ? " " : "", opt, data);
171 }
172 }
173
174 static void arg_seg(char *cmd, const char *opt, const char *data, const int eci) {
175 if (data != NULL) {
176 sprintf(cmd + strlen(cmd), "%s%s%d,\"%s\"", strlen(cmd) ? " " : "", opt, eci, data);
177 } else {
178 sprintf(cmd + strlen(cmd), "%s%s%d", strlen(cmd) ? " " : "", opt, eci);
179 }
180 }
181
182 static int arg_input(char *cmd, const char *filename, const char *input) {
183 FILE *fp;
184 int cnt;
185 if (input != NULL) {
186 if (strcmp(input, "-") != 0) {
187 fp = testUtilOpen(filename, "wb");
188 if (!fp) {
189 fprintf(stderr, "arg_input: failed to open '%s' for writing\n", filename);
190 return 0;
191 }
192 cnt = (int) fwrite(input, 1, strlen(input), fp);
193 if (cnt != (int) strlen(input)) {
194 fprintf(stderr, "arg_input: failed to write %d bytes, cnt %d written (%s)\n", (int) strlen(input), cnt, filename);
195 fclose(fp);
196 return 0;
197 }
198 fclose(fp);
199 }
200 sprintf(cmd + strlen(cmd), "%s-i \"%s\"", strlen(cmd) ? " " : "", filename);
201 return 1;
202 }
203 return 0;
204 }
205
206 static void arg_input_mode(char *cmd, int input_mode) {
207 if (input_mode != -1) {
208 if ((input_mode & 0x07) == DATA_MODE) {
209 sprintf(cmd + strlen(cmd), "%s--binary", strlen(cmd) ? " " : "");
210 } else if ((input_mode & 0x07) == GS1_MODE) {
211 sprintf(cmd + strlen(cmd), "%s--gs1", strlen(cmd) ? " " : "");
212 }
213 if (input_mode & ESCAPE_MODE) {
214 sprintf(cmd + strlen(cmd), "%s--esc", strlen(cmd) ? " " : "");
215 }
216 if (input_mode & EXTRA_ESCAPE_MODE) {
217 sprintf(cmd + strlen(cmd), "%s--extraesc", strlen(cmd) ? " " : "");
218 }
219 if (input_mode & FAST_MODE) {
220 sprintf(cmd + strlen(cmd), "%s--fast", strlen(cmd) ? " " : "");
221 }
222 if (input_mode & GS1PARENS_MODE) {
223 sprintf(cmd + strlen(cmd), "%s--gs1parens", strlen(cmd) ? " " : "");
224 }
225 if (input_mode & GS1NOCHECK_MODE) {
226 sprintf(cmd + strlen(cmd), "%s--gs1nocheck", strlen(cmd) ? " " : "");
227 }
228 if (input_mode & HEIGHTPERROW_MODE) {
229 sprintf(cmd + strlen(cmd), "%s--heightperrow", strlen(cmd) ? " " : "");
230 }
231 }
232 }
233
234 static void arg_output_options(char *cmd, int output_options) {
235 if (output_options != -1) {
236 if (output_options & BARCODE_BIND) {
237 sprintf(cmd + strlen(cmd), "%s--bind", strlen(cmd) ? " " : "");
238 }
239 if (output_options & BARCODE_BIND_TOP) {
240 sprintf(cmd + strlen(cmd), "%s--bindtop", strlen(cmd) ? " " : "");
241 }
242 if (output_options & BARCODE_BOX) {
243 sprintf(cmd + strlen(cmd), "%s--box", strlen(cmd) ? " " : "");
244 }
245 if (output_options & BARCODE_STDOUT) {
246 sprintf(cmd + strlen(cmd), "%s--direct", strlen(cmd) ? " " : "");
247 }
248 if (output_options & READER_INIT) {
249 sprintf(cmd + strlen(cmd), "%s--init", strlen(cmd) ? " " : "");
250 }
251 if (output_options & SMALL_TEXT) {
252 sprintf(cmd + strlen(cmd), "%s--small", strlen(cmd) ? " " : "");
253 }
254 if (output_options & BOLD_TEXT) {
255 sprintf(cmd + strlen(cmd), "%s--bold", strlen(cmd) ? " " : "");
256 }
257 if (output_options & CMYK_COLOUR) {
258 sprintf(cmd + strlen(cmd), "%s--cmyk", strlen(cmd) ? " " : "");
259 }
260 if (output_options & BARCODE_DOTTY_MODE) {
261 sprintf(cmd + strlen(cmd), "%s--dotty", strlen(cmd) ? " " : "");
262 }
263 if (output_options & GS1_GS_SEPARATOR) {
264 sprintf(cmd + strlen(cmd), "%s--gssep", strlen(cmd) ? " " : "");
265 }
266 if (output_options & BARCODE_QUIET_ZONES) {
267 sprintf(cmd + strlen(cmd), "%s--quietzones", strlen(cmd) ? " " : "");
268 }
269 if (output_options & BARCODE_NO_QUIET_ZONES) {
270 sprintf(cmd + strlen(cmd), "%s--noquietzones", strlen(cmd) ? " " : "");
271 }
272 if (output_options & COMPLIANT_HEIGHT) {
273 sprintf(cmd + strlen(cmd), "%s--compliantheight", strlen(cmd) ? " " : "");
274 }
275 }
276 }
277
278 /* Tests args that can be detected with `--dump` */
279 static void test_dump_args(const testCtx *const p_ctx) {
280 int debug = p_ctx->debug;
281
282 struct item {
283 int b;
284 char *data;
285 char *data2;
286 char *input;
287 char *input2;
288 int input_mode;
289 int output_options;
290 int batch;
291 int cols;
292 int dmre;
293 int eci;
294 int fullmultibyte;
295 int mask;
296 int mode;
297 char *primary;
298 int rows;
299 int secure;
300 int square;
301 int vers;
302
303 char *expected;
304 };
305 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
306 struct item data[] = {
307 /* 0*/ { -1, "123", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "D3 96 72 F7 65 C9 61 8E B" },
308 /* 1*/ { BARCODE_CODE128, "123", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "D3 96 72 F7 65 C9 61 8E B" },
309 /* 2*/ { BARCODE_CODE128, "123", "456", NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "D3 96 72 F7 65 C9 61 8E B\nD3 97 62 F7 67 49 19 8E B" },
310 /* 3*/ { BARCODE_CODE128, "123", NULL, NULL, NULL, -1, -1, 1, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "Warning 141: Can't use batch mode if data given, ignoring\nD3 96 72 F7 65 C9 61 8E B" },
311 /* 4*/ { BARCODE_CODE128, NULL, NULL, "123\n45\n", NULL, -1, -1, 1, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "D3 96 72 F7 65 C9 61 8E B\nD3 97 62 3B 63 AC" },
312 /* 5*/ { BARCODE_CODE128, NULL, NULL, "123\n45\n", "7\n",-1, -1, 1, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "Warning 144: Processing first input file 'test_dump_args1.txt' only\nD3 96 72 F7 65 C9 61 8E B\nD3 97 62 3B 63 AC" },
313 /* 6*/ { BARCODE_CODE128, "\t", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "D0 90 D2 1A 63 AC" },
314 /* 7*/ { BARCODE_CODE128, "\\t", NULL, NULL, NULL, ESCAPE_MODE, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "D0 90 D2 1A 63 AC" },
315 /* 8*/ { BARCODE_CODE128, "\\^Ab\011", NULL, NULL, NULL, EXTRA_ESCAPE_MODE, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "D0 9E 8A 43 43 48 D1 8E B" },
316 /* 9*/ { BARCODE_CODE128, "\\^Ab\\t", NULL, NULL, NULL, ESCAPE_MODE | EXTRA_ESCAPE_MODE, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "D0 9E 8A 43 43 48 D1 8E B" },
317 /* 10*/ { BARCODE_CODE128, "123", NULL, NULL, NULL, -1, BARCODE_BIND | BARCODE_BOX | BARCODE_BIND_TOP | SMALL_TEXT | BOLD_TEXT | CMYK_COLOUR, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "D3 96 72 F7 65 C9 61 8E B" },
318 /* 11*/ { BARCODE_CODE128, "123", NULL, NULL, NULL, -1, BARCODE_DOTTY_MODE, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "Error 224: Selected symbology cannot be rendered as dots" },
319 /* 12*/ { BARCODE_CODABLOCKF, "ABCDEF", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "D0 97 BA 86 51 88 B1 11 AC 46 D8 C7 58\nD0 97 BB 12 46 88 C5 1A 3C 55 CC C7 58" },
320 /* 13*/ { BARCODE_CODABLOCKF, "ABCDEF", NULL, NULL, NULL, -1, -1, 0, 10, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "D0 97 BA 86 51 88 B1 11 AC 44 68 BC 98 EB\nD0 97 BB 12 46 2B BD 7B A3 47 8A 8D 18 EB" },
321 /* 14*/ { BARCODE_CODABLOCKF, "ABCDEF", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, 3, -1, 0, -1, "D0 97 BA 58 51 88 B1 11 AC 46 36 C7 58\nD0 97 BB 12 46 88 C5 77 AF 74 62 C7 58\nD0 97 BA CE 5D EB DD 1A 3C 56 88 C7 58" },
322 /* 15*/ { BARCODE_CODE11, NULL, NULL, "123", NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "B2 D6 96 CA B5 6D 64" },
323 /* 16*/ { BARCODE_CODE11, NULL, NULL, "123", NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, 1, "B2 D6 96 CA B5 64" },
324 /* 17*/ { BARCODE_CODE11, "123", NULL, "456", NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, 2, "B2 D6 96 CA B2\nB2 B6 DA 9A B2" },
325 /* 18*/ { BARCODE_CODE11, "123", "456", "789", "012", -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, 2, "B2 D6 96 CA B2\nB2 B6 DA 9A B2\nB2 A6 D2 D5 64\nB2 AD AD 2D 64" },
326 /* 19*/ { BARCODE_PDF417, "123", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, 0, 0, -1, "FF 54 7A BC 3A 9C 1D 5C 0F E8 A4\nFF 54 7E AE 3C 11 5F AB 8F E8 A4\nFF 54 6A F8 29 9F 1D 5F 8F E8 A4\nFF 54 57 9E 37 BA 1A F7 CF E8 A4\nFF 54 75 CC 36 F0 5D 73 0F E8 A4" },
327 /* 20*/ { BARCODE_DATAMATRIX, "ABC", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "AA 8\nB3 4\n8F 0\nB2 C\nA6 0\nBA C\nD6 0\nEB 4\nE2 8\nFF C" },
328 /* 21*/ { BARCODE_DATAMATRIX, "ABC", NULL, NULL, NULL, -1, READER_INIT, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "AA A\nAC 7\n8A 4\nA0 3\nC2 2\nB5 1\n82 2\nBA 7\n8C C\nA0 5\n86 A\nFF F" },
329 /* 22*/ { BARCODE_DATAMATRIX, "ABCDEFGH", NULL, NULL, NULL, FAST_MODE, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "AA A8\nA6 8C\nB2 F0\n98 B4\nB9 A8\nB8 CC\nF0 78\nA0 3C\n99 70\n85 1C\nDA B0\nE5 94\nA7 50\nFF FC" },
330 /* 23*/ { BARCODE_DATAMATRIX, "ABCDEFGH", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "AA A8\n80 04\n82 60\nC5 24\n98 A8\nA3 9C\nCB B8\nAF DC\n86 58\nF6 44\nAC 18\n90 54\nCF 30\nFF FC" },
331 /* 24*/ { BARCODE_DATAMATRIX, "ABCDEFGHIJK", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "AA AA AA AA\n80 09 F9 BD\n82 4A E2 58\nC5 CD C9 A5\nD8 5C A5 FC\nE0 35 88 69\nCC FC B3 E6\nFF FF FF FF" },
332 /* 25*/ { BARCODE_DATAMATRIX, "ABCDEFGHIJK", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 1, -1, "AA AA\n80 25\n82 24\nC5 5D\n98 90\nA4 C7\nC8 A6\nB9 E9\n8E 02\nDE 91\nCD 6C\nA0 BB\n85 80\n98 2D\nE4 CA\nFF FF" },
333 /* 26*/ { BARCODE_DATAMATRIX, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "AA AA A8\nBA 5A 44\n8B 4D 28\nBF 77 64\n97 85 50\nBA D8 AC\nCD ED B8\nD4 B5 2C\nD1 A8 00\n81 FB 2C\nE4 75 78\n96 E8 2C\nF3 75 78\nEE 1D 04\nCA BA 98\nB1 8F B4\nA0 4F 00\nE4 A7 74\nF1 D3 90\nEF E1 BC\n91 10 38\nFF FF FC" },
334 /* 27*/ { BARCODE_DATAMATRIX, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF", NULL, NULL, NULL, -1, -1, 0, -1, 1, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "AA AA AA AA AA AA AA AA\nBA 03 BA 7D E5 31 B0 0D\n8B 6A 93 B6 E0 0A B8 3C\nBF 1D EA A7 EB ED A1 FB\n96 66 86 B6 C9 AE 92 40\nBF 65 E7 95 BC B7 FA E3\nCC 7C 90 CC D1 24 AB 5A\nFF FF FF FF FF FF FF FF" },
335 /* 28*/ { BARCODE_DATAMATRIX, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF", NULL, NULL, NULL, -1, -1, 0, -1, 1, -1, 0, -1, -1, NULL, -1, -1, 1, -1, "AA AA A8\nBA 5A 44\n8B 4D 28\nBF 77 64\n97 85 50\nBA D8 AC\nCD ED B8\nD4 B5 2C\nD1 A8 00\n81 FB 2C\nE4 75 78\n96 E8 2C\nF3 75 78\nEE 1D 04\nCA BA 98\nB1 8F B4\nA0 4F 00\nE4 A7 74\nF1 D3 90\nEF E1 BC\n91 10 38\nFF FF FC" },
336 /* 29*/ { BARCODE_DATAMATRIX, "[91]12[92]34", NULL, NULL, NULL, GS1_MODE, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "AA A8\nFA 9C\nBC 00\nD7 84\nED E0\nA4 E4\nA7 40\n9D 3C\nBF 50\nFA 24\nB1 68\nE5 04\n92 70\nFF FC" },
337 /* 30*/ { BARCODE_DATAMATRIX, "[91]12[92]34", NULL, NULL, NULL, GS1_MODE, GS1_GS_SEPARATOR, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "AA A8\nF9 DC\nBF 20\nD6 C4\nED 10\nA0 0C\nA7 C0\n96 5C\nBA 70\nBB A4\nE2 18\nDD 14\n9C 40\nFF FC" },
338 /* 31*/ { BARCODE_DATAMATRIX, "[9\\x31]12[92]34", NULL, NULL, NULL, GS1_MODE | ESCAPE_MODE, GS1_GS_SEPARATOR, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "AA A8\nF9 DC\nBF 20\nD6 C4\nED 10\nA0 0C\nA7 C0\n96 5C\nBA 70\nBB A4\nE2 18\nDD 14\n9C 40\nFF FC" },
339 /* 32*/ { BARCODE_DATAMATRIX, "(9\\x31)12(92)34", NULL, NULL, NULL, GS1_MODE | ESCAPE_MODE | GS1PARENS_MODE, GS1_GS_SEPARATOR, 0, -1, 0, -1, 0, -1, -1, NULL, -1, -1, 0, -1, "AA A8\nF9 DC\nBF 20\nD6 C4\nED 10\nA0 0C\nA7 C0\n96 5C\nBA 70\nBB A4\nE2 18\nDD 14\n9C 40\nFF FC" },
340 /* 33*/ { BARCODE_EANX_CC, "[91]12", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, "12345678+12", -1, -1, 0, -1, "DB BC D3 9C 44 E9 D2 2C 19 E7 A2 D8 A0 00 00 00\nDB 31 1C 9C C7 29 92 47 D9 E9 40 C8 A0 00 00 00\nDA 3B EB 10 AF 09 9A 18 9D 7D 82 E8 A0 00 00 00\n10 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00\n20 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00\n10 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00\n14 68 D1 A6 49 BD 55 C9 D4 22 48 B9 40 59 94 98" },
341 /* 34*/ { BARCODE_EANX_CC, "[91]12", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, 2, "12345678+12", -1, -1, 0, -1, "D3 A3 E9 DB F5 C9 DB 43 D9 CB 98 D2 20 00 00 00\nD3 25 0F 11 E4 49 D3 51 F1 AC FC D6 20 00 00 00\nD1 33 48 19 39 E9 93 18 49 D8 98 D7 20 00 00 00\nD1 A6 FC DA 1C 49 9B C5 05 E2 84 D7 A0 00 00 00\n10 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00\n20 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00\n10 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00\n14 68 D1 A6 49 BD 55 C9 D4 22 48 B9 40 59 94 98" },
342 /* 35*/ { BARCODE_QRCODE, "点", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, 1, 0, -1, "Warning 760: Converted to Shift JIS but no ECI specified\nFE 2B F8\n82 AA 08\nBA B2 E8\nBA 0A E8\nBA FA E8\n82 E2 08\nFE AB F8\n00 80 00\nD3 3B B0\n60 95 68\n7A B3 A0\n1D 0F 98\nAA D7 30\n00 E6 A8\nFE DA D0\n82 42 20\nBA 0E 38\nBA C7 18\nBA 17 68\n82 B9 40\nFE C5 28" },
343 /* 36*/ { BARCODE_QRCODE, "点", NULL, NULL, NULL, -1, -1, 0, -1, 0, 26, 0, -1, -1, NULL, -1, 1, 0, -1, "FE 5B F8\n82 72 08\nBA DA E8\nBA 52 E8\nBA 2A E8\n82 0A 08\nFE AB F8\n00 D8 00\nEF F6 20\nB5 C2 28\n36 28 88\nFD 42 10\n62 2A C8\n00 95 70\nFE B7 38\n82 FD D8\nBA 97 00\nBA 43 60\nBA C8 C8\n82 C3 68\nFE EA F8" },
344 /* 37*/ { BARCODE_QRCODE, "\223\137", NULL, NULL, NULL, DATA_MODE, -1, 0, -1, 0, -1, 0, -1, -1, NULL, -1, 1, 0, -1, "FE 2B F8\n82 0A 08\nBA A2 E8\nBA 0A E8\nBA 5A E8\n82 72 08\nFE AB F8\n00 A0 00\nEF AE 20\n75 B5 20\n82 F7 58\nF4 9D C8\n5E 17 28\n00 C2 20\nFE 88 80\n82 82 38\nBA EA A8\nBA 55 50\nBA D7 68\n82 BD D0\nFE B7 78" },
345 /* 38*/ { BARCODE_QRCODE, "\223\137", NULL, NULL, NULL, DATA_MODE, -1, 0, -1, 0, -1, 1, -1, -1, NULL, -1, 1, 0, -1, "FE 2B F8\n82 AA 08\nBA B2 E8\nBA 0A E8\nBA FA E8\n82 E2 08\nFE AB F8\n00 80 00\nD3 3B B0\n60 95 68\n7A B3 A0\n1D 0F 98\nAA D7 30\n00 E6 A8\nFE DA D0\n82 42 20\nBA 0E 38\nBA C7 18\nBA 17 68\n82 B9 40\nFE C5 28" },
346 /* 39*/ { BARCODE_QRCODE, "\\x93\\x5F", NULL, NULL, NULL, DATA_MODE | ESCAPE_MODE, -1, 0, -1, 0, -1, 1, -1, -1, NULL, -1, 1, 0, -1, "FE 2B F8\n82 AA 08\nBA B2 E8\nBA 0A E8\nBA FA E8\n82 E2 08\nFE AB F8\n00 80 00\nD3 3B B0\n60 95 68\n7A B3 A0\n1D 0F 98\nAA D7 30\n00 E6 A8\nFE DA D0\n82 42 20\nBA 0E 38\nBA C7 18\nBA 17 68\n82 B9 40\nFE C5 28" },
347 /* 40*/ { BARCODE_QRCODE, "点", NULL, NULL, NULL, -1, -1, 0, -1, 0, -1, 0, 2, -1, NULL, -1, 1, 0, -1, "Warning 760: Converted to Shift JIS but no ECI specified\nFE 4B F8\n82 92 08\nBA 42 E8\nBA 92 E8\nBA 3A E8\n82 EA 08\nFE AB F8\n00 38 00\nFB CD 50\nA5 89 18\n0B 74 B8\nFC 81 A0\n92 34 B8\n00 DE 48\nFE AB 10\n82 5E 50\nBA C9 20\nBA C9 20\nBA F4 E0\n82 81 A0\nFE B4 E8" },
348 /* 41*/ { BARCODE_HANXIN, "é", NULL, NULL, NULL, DATA_MODE, -1, 0, -1, 0, -1, 1, -1, -1, NULL, -1, -1, 0, -1, "FE 8A FE\n80 28 02\nBE E8 FA\nA0 94 0A\nAE 3E EA\nAE D2 EA\nAE 74 EA\n00 AA 00\n15 B4 80\n0B 48 74\nA2 4A A4\nB5 56 2C\nA8 5A A8\n9F 18 50\n02 07 50\n00 A6 00\nFE 20 EA\n02 C2 EA\nFA C4 EA\n0A 42 0A\nEA 52 FA\nEA 24 02\nEA AA FE" },
349 /* 42*/ { BARCODE_HANXIN, "é", NULL, NULL, NULL, DATA_MODE, -1, 0, -1, 0, -1, 1, 3, -1, NULL, -1, -1, 0, -1, "FE 16 FE\n80 E2 02\nBE C2 FA\nA0 A0 0A\nAE F6 EA\nAE 98 EA\nAE BA EA\n00 E0 00\n15 83 80\n44 7E AE\n92 9C 78\n25 BF 08\n47 4B 8C\n0D F9 74\n03 E7 50\n00 3A 00\nFE C2 EA\n02 22 EA\nFA DA EA\n0A 22 0A\nEA B2 FA\nEA 9A 02\nEA E8 FE" },
350 /* 43*/ { BARCODE_HANXIN, "é", NULL, NULL, NULL, DATA_MODE, -1, 0, -1, 0, -1, 1, 4, -1, NULL, -1, -1, 0, -1, "FE 8A FE\n80 28 02\nBE E8 FA\nA0 94 0A\nAE 3E EA\nAE D2 EA\nAE 74 EA\n00 AA 00\n15 B4 80\n0B 48 74\nA2 4A A4\nB5 56 2C\nA8 5A A8\n9F 18 50\n02 07 50\n00 A6 00\nFE 20 EA\n02 C2 EA\nFA C4 EA\n0A 42 0A\nEA 52 FA\nEA 24 02\nEA AA FE" },
351 };
352 int data_size = ARRAY_SIZE(data);
353 int i;
354
355 char cmd[4096];
356 char buf[4096];
357
358 char *input1_filename = "test_dump_args1.txt";
359 char *input2_filename = "test_dump_args2.txt";
360 int have_input1;
361 int have_input2;
362
363 testStart("test_dump_args");
364
365 for (i = 0; i < data_size; i++) {
366
367 if (testContinue(p_ctx, i)) continue;
368
369 strcpy(cmd, "zint --dump");
370 if (debug & ZINT_DEBUG_PRINT) {
371 strcat(cmd, " --verbose");
372 }
373
374 arg_int(cmd, "-b ", data[i].b);
375 arg_data(cmd, "-d ", data[i].data);
376 arg_data(cmd, "-d ", data[i].data2);
377 have_input1 = arg_input(cmd, input1_filename, data[i].input);
378 have_input2 = arg_input(cmd, input2_filename, data[i].input2);
379 arg_input_mode(cmd, data[i].input_mode);
380 arg_output_options(cmd, data[i].output_options);
381 arg_bool(cmd, "--batch", data[i].batch);
382 arg_int(cmd, "--cols=", data[i].cols);
383 arg_bool(cmd, "--dmre", data[i].dmre);
384 arg_int(cmd, "--eci=", data[i].eci);
385 arg_bool(cmd, "--fullmultibyte", data[i].fullmultibyte);
386 arg_int(cmd, "--mask=", data[i].mask);
387 arg_int(cmd, "--mode=", data[i].mode);
388 arg_data(cmd, "--primary=", data[i].primary);
389 arg_int(cmd, "--rows=", data[i].rows);
390 arg_int(cmd, "--secure=", data[i].secure);
391 arg_bool(cmd, "--square", data[i].square);
392 arg_int(cmd, "--vers=", data[i].vers);
393
394 strcat(cmd, " 2>&1");
395
396 assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
397 assert_zero(strcmp(buf, data[i].expected), "i:%d buf (%s) != expected (%s) (%s)\n", i, buf, data[i].expected, cmd);
398
399 if (have_input1) {
400 assert_zero(testUtilRemove(input1_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input1_filename, errno, strerror(errno));
401 }
402 if (have_input2) {
403 assert_zero(testUtilRemove(input2_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input2_filename, errno, strerror(errno));
404 }
405 }
406
407 testFinish();
408 }
409
410 /* Tests segs */
411 static void test_dump_segs(const testCtx *const p_ctx) {
412 int debug = p_ctx->debug;
413
414 struct item {
415 int b;
416 char *data;
417 char *data_seg1;
418 char *data_seg2;
419 int eci;
420 int eci_seg1;
421 int eci_seg2;
422
423 char *expected;
424 };
425 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
426 struct item data[] = {
427 /* 0*/ { -1, "123", NULL, NULL, -1, -1, -1, "D3 96 72 F7 65 C9 61 8E B" },
428 /* 1*/ { -1, "123", NULL, NULL, -1, 3, -1, "Error 166: Invalid segment argument, expect \"ECI,DATA\"" },
429 /* 2*/ { -1, "123", "456", NULL, -1, -1, -1, "Error 167: Invalid segment ECI (digits only)" },
430 /* 3*/ { -1, "123", "456", NULL, -1, 1000000, -1, "Error 168: Segment ECI code '1000000' out of range (0 to 999999)" },
431 /* 4*/ { -1, "123", "456", NULL, -1, 3, -1, "Error 775: Symbology does not support multiple segments" },
432 /* 5*/ { BARCODE_AZTEC, "123", "456", NULL, -1, 3, -1, "2B 7A\nC7 02\nF0 6E\n3F FE\n70 1C\nB7 D6\nB4 58\n15 54\n94 56\nB7 DC\n30 1A\n1F FC\n4C 66\n22 DA\n1E C6" },
433 /* 6*/ { BARCODE_AZTEC, "123", NULL, "789", -1, -1, 3, "Error 172: Segments must be consecutive - segment 1 missing" },
434 };
435 int data_size = ARRAY_SIZE(data);
436 int i;
437
438 char cmd[4096];
439 char buf[4096];
440
441 testStart("test_dump_segs");
442
443 for (i = 0; i < data_size; i++) {
444
445 if (testContinue(p_ctx, i)) continue;
446
447 strcpy(cmd, "zint --dump");
448 if (debug & ZINT_DEBUG_PRINT) {
449 strcat(cmd, " --verbose");
450 }
451
452 arg_int(cmd, "-b ", data[i].b);
453
454 if (data[i].data && data[i].data[0]) {
455 arg_data(cmd, "-d ", data[i].data);
456 }
457 if (data[i].eci > 0) {
458 arg_int(cmd, "--eci=", data[i].eci);
459 }
460
461 if (data[i].data_seg1 && data[i].data_seg1[0]) {
462 arg_seg(cmd, "--seg1=", data[i].data_seg1, data[i].eci_seg1);
463 } else if (data[i].eci_seg1 >= 0) {
464 arg_seg(cmd, "--seg1=", NULL, data[i].eci_seg1);
465 }
466
467 if (data[i].data_seg2 && data[i].data_seg2[0]) {
468 arg_seg(cmd, "--seg2=", data[i].data_seg2, data[i].eci_seg2);
469 } else if (data[i].eci_seg2 >= 0) {
470 arg_seg(cmd, "--seg2=", NULL, data[i].eci_seg2);
471 }
472
473 strcat(cmd, " 2>&1");
474
475 assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
476 assert_zero(strcmp(buf, data[i].expected), "i:%d buf (%s) != expected (%s) (%s)\n", i, buf, data[i].expected, cmd);
477 }
478
479 testFinish();
480 }
481
482 static void test_input(const testCtx *const p_ctx) {
483 int debug = p_ctx->debug;
484
485 #define TEST_INPUT_LONG "test_67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
486
487 #define TEST_MIRRORED_DIR_LONG "testdir_9012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/"
488 #define TEST_MIRRORED_DIR_TOO_LONG "testdir_901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901/"
489
490 #ifndef _WIN32
491 #define TEST_INPUT_AMPERSAND_EXPECTED "***1.gif\000***2.gif"
492 #else
493 #define TEST_INPUT_AMPERSAND_EXPECTED "+++1.gif\000+++2.gif"
494 #endif
495
496 struct item {
497 int b;
498 int batch;
499 int input_mode;
500 int mirror;
501 char *filetype;
502 char *input_filename;
503 char *input;
504 char *outfile;
505
506 int num_expected;
507 char *expected;
508 };
509 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
510 struct item data[] = {
511 /* 0*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n456\n", "", 2, "00001.gif\00000002.gif" },
512 /* 1*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", "~~~.gif", 10, "001.gif\000002.gif\000003.gif\000004.gif\000005.gif\000006.gif\000007.gif\000008.gif\000009.gif\000010.gif" },
513 /* 2*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n456\n", "@@@@.gif", 2, TEST_INPUT_AMPERSAND_EXPECTED },
514 /* 3*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n456\n789\n", "#####.gif", 3, " 1.gif\000 2.gif\000 3.gif" },
515 /* 4*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n456\n", "test_batch~.gif", 2, "test_batch1.gif\000test_batch2.gif" },
516 /* 5*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "123\n456\n7890123456789\n", NULL, 3, "123.gif\000456.gif\0007890123456789.gif" },
517 /* 6*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "123\n456\n7890123456789\n", "test_input_dir/", 3, "test_input_dir/123.gif\000test_input_dir/456.gif\000test_input_dir/7890123456789.gif" },
518 /* 7*/ { BARCODE_CODE128, 1, -1, 1, "svg", NULL, "123\n456\n7890123456789\n", NULL, 3, "123.svg\000456.svg\0007890123456789.svg" },
519 /* 8*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "123\n456\n7890123456789\nA\\xA0B\n", NULL, 4, "123.gif\000456.gif\0007890123456789.gif\000A_xA0B.gif" },
520 /* 9*/ { BARCODE_CODE128, 1, ESCAPE_MODE, 1, "gif", NULL, "123\n456\n7890123456789\nA\\xA0B\n", NULL, 4, "123.gif\000456.gif\0007890123456789.gif\000A_B.gif" },
521 /* 10*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "123\n456\n7890123456789\nA\\u00A0B\n", NULL, 4, "123.gif\000456.gif\0007890123456789.gif\000A_u00A0B.gif" },
522 /* 11*/ { BARCODE_CODE128, 1, ESCAPE_MODE, 1, "gif", NULL, "123\n456\n7890123456789\nA\\u00A0B\n", NULL, 4, "123.gif\000456.gif\0007890123456789.gif\000A_B.gif" },
523 /* 12*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "1!2\"3*\n/:45<6>\n?7890\\\\12345|6789\177\nA\\U0000A0B\n", NULL, 4, "1_2_3_.gif\000__45_6_.gif\000_7890__12345_6789_.gif\000A_U0000A0B.gif" },
524 /* 13*/ { BARCODE_CODE128, 1, ESCAPE_MODE, 1, "gif", NULL, "!\"*\n/:45<6>\n?7890\\\\12345|6789\177\nA\\U0000A0B\n", NULL, 4, "___.gif\000__45_6_.gif\000_7890_12345_6789_.gif\000A_B.gif" },
525 /* 14*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "1\\d123*9\n\\o1234:5\n#$%&'()+,-.;=@[]^`{}\n", NULL, 3, "1_d123_9.gif\000_o1234_5.gif\000#$%&'()+,-.;=@[]^`{}.gif" },
526 /* 15*/ { BARCODE_CODE128, 1, ESCAPE_MODE, 1, "gif", NULL, "1\\d123*2\n\\o1234:5\n#$%&'()+,-.;=@[]^`{}\n", NULL, 3, "1__2.gif\000_4_5.gif\000#$%&'()+,-.;=@[]^`{}.gif" },
527 /* 16*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "\n", "test_batch.gif", 0, NULL },
528 /* 17*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n456\n", TEST_INPUT_LONG "~.gif", 2, TEST_INPUT_LONG "1.gif\000" TEST_INPUT_LONG "2.gif" },
529 /* 18*/ { BARCODE_CODE128, 0, -1, 0, "svg", NULL, "123", TEST_INPUT_LONG "1.gif", 1, TEST_INPUT_LONG "1.svg" },
530 /* 19*/ { BARCODE_CODE128, 1, -1, 0, "svg", NULL, "123\n", TEST_INPUT_LONG "1.gif", 1, TEST_INPUT_LONG "1.svg" },
531 /* 20*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n", "test_batch.jpeg", 1, "test_batch.jpeg.gif" },
532 /* 21*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n", "test_batch.jpg", 1, "test_batch.gif" },
533 /* 22*/ { BARCODE_CODE128, 1, -1, 0, "emf", NULL, "123\n", "test_batch.jpeg", 1, "test_batch.jpeg.emf" },
534 /* 23*/ { BARCODE_CODE128, 1, -1, 0, "emf", NULL, "123\n", "test_batch.jpg", 1, "test_batch.emf" },
535 /* 24*/ { BARCODE_CODE128, 1, -1, 0, "eps", NULL, "123\n", "test_batch.ps", 1, "test_batch.eps" },
536 /* 25*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "1234567890123456789012345678901\n1234567890123456789012345678902\n", TEST_MIRRORED_DIR_LONG, 2, TEST_MIRRORED_DIR_LONG "1234567890123456789012345678901.gif\000" TEST_MIRRORED_DIR_LONG "1234567890123456789012345678902.gif" },
537 /* 26*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "123\n456\n", TEST_MIRRORED_DIR_TOO_LONG, 2, "123.gif\000456.gif" },
538 /* 27*/ { BARCODE_CODE128, 1, -1, 0, "gif", "testé_input.txt", "123\n456\n", "", 2, "00001.gif\00000002.gif" },
539 /* 28*/ { BARCODE_CODE128, 1, -1, 0, "gif", "testก_input.txt", "123\n456\n", "test_input_δir/testé~~~.gif", 2, "test_input_δir/testé001.gif\000test_input_δir/testé002.gif" },
540 };
541 int data_size = ARRAY_SIZE(data);
542 int i;
543
544 char cmd[4096];
545 char buf[4096];
546
547 char *input_filename;
548 char *outfile;
549
550 testStart("test_input");
551
552 for (i = 0; i < data_size; i++) {
553 int j;
554 char *slash;
555
556 if (testContinue(p_ctx, i)) continue;
557 #ifdef _WIN32
558 if (data[i].outfile && (int) strlen(data[i].outfile) > 50) {
559 if (debug & ZINT_DEBUG_TEST_PRINT) printf("%d not Windows compatible (outfile length %d > 50)\n", i, (int) strlen(data[i].outfile));
560 continue;
561 }
562 #endif
563
564 strcpy(cmd, "zint");
565 if (debug & ZINT_DEBUG_PRINT) {
566 strcat(cmd, " --verbose");
567 }
568
569 arg_int(cmd, "-b ", data[i].b);
570 arg_bool(cmd, "--batch", data[i].batch);
571 arg_input_mode(cmd, data[i].input_mode);
572 arg_bool(cmd, "--mirror", data[i].mirror);
573 arg_data(cmd, "--filetype=", data[i].filetype);
574 input_filename = data[i].input_filename ? data[i].input_filename : "test_input.txt";
575 arg_input(cmd, input_filename, data[i].input);
576 arg_data(cmd, "-o ", data[i].outfile);
577
578 if (!data[i].expected
579 || (data[i].batch && data[i].mirror && data[i].outfile && data[i].outfile[0]
580 && strcmp(data[i].outfile, TEST_MIRRORED_DIR_LONG) == 0)) {
581 printf("++++ Following %s expected, ignore: ", data[i].expected ? "warning" : "error");
582 fflush(stdout);
583 }
584 assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
585
586 outfile = data[i].expected;
587 for (j = 0; j < data[i].num_expected; j++) {
588 assert_nonzero(testUtilExists(outfile), "i:%d j:%d testUtilExists(%s) != 1\n", i, j, outfile);
589 assert_zero(testUtilRemove(outfile), "i:%d j:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, j, outfile, errno, strerror(errno));
590 outfile += strlen(outfile) + 1;
591 }
592
593 assert_zero(testUtilRemove(input_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input_filename, errno, strerror(errno));
594
595 /* Remove directory if any */
596 if (data[i].outfile && (slash = strrchr(data[i].outfile, '/')) != NULL && strcmp(data[i].outfile, TEST_MIRRORED_DIR_TOO_LONG) != 0) {
597 char dirpath[256];
598 assert_nonzero((size_t) (slash - data[i].outfile) < sizeof(dirpath), "i: %d output directory too long\n", i);
599 strncpy(dirpath, data[i].outfile, slash - data[i].outfile);
600 dirpath[slash - data[i].outfile] = '\0';
601 assert_zero(testUtilRmDir(dirpath), "i:%d testUtilRmDir(%s) != 0 (%d: %s)\n", i, dirpath, errno, strerror(errno));
602 }
603 }
604
605 testFinish();
606 }
607
608 static void test_stdin_input(const testCtx *const p_ctx) {
609 int debug = p_ctx->debug;
610
611 struct item {
612 int b;
613 char *data;
614 char *input;
615 char *outfile;
616 };
617 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
618 struct item data[] = {
619 /* 0*/ { BARCODE_CODE128, "123", "-", "test_stdin_input.gif" },
620 };
621 int data_size = ARRAY_SIZE(data);
622 int i;
623
624 char cmd[4096];
625 char buf[4096];
626
627 char *input_filename = "-";
628
629 testStart("test_stdin_input");
630
631 for (i = 0; i < data_size; i++) {
632
633 if (testContinue(p_ctx, i)) continue;
634
635 sprintf(cmd, "echo '%s' | zint", data[i].data);
636 if (debug & ZINT_DEBUG_PRINT) {
637 strcat(cmd, " --verbose");
638 }
639
640 arg_int(cmd, "-b ", data[i].b);
641 arg_input(cmd, input_filename, data[i].input);
642 arg_data(cmd, "-o ", data[i].outfile);
643
644 assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
645
646 assert_nonzero(testUtilExists(data[i].outfile), "i:%d testUtilExists(%s) != 1\n", i, data[i].outfile);
647 assert_zero(testUtilRemove(data[i].outfile), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, data[i].outfile, errno, strerror(errno));
648 }
649
650 testFinish();
651 }
652
653 /* Note ordering of `--batch` before/after data/input args affects error messages */
654 static void test_batch_input(const testCtx *const p_ctx) {
655 int debug = p_ctx->debug;
656
657 struct item {
658 int b;
659 char *data;
660 char *input;
661 char *input2;
662
663 char *expected;
664 };
665 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
666 struct item data[] = {
667 /* 0*/ { BARCODE_CODE128, "123", NULL, NULL, "Warning 122: Can't define data in batch mode, ignoring '123'\nWarning 124: No data received, no symbol generated" },
668 /* 1*/ { BARCODE_CODE128, "123", "123\n456\n", NULL, "Warning 122: Can't define data in batch mode, ignoring '123'\nD3 96 72 F7 65 C9 61 8E B\nD3 97 62 F7 67 49 19 8E B" },
669 /* 2*/ { BARCODE_CODE128, NULL, "123\n456\n", "789\n", "Warning 143: Can only define one input file in batch mode, ignoring 'test_batch_input2.txt'\nD3 96 72 F7 65 C9 61 8E B\nD3 97 62 F7 67 49 19 8E B" },
670 };
671 int data_size = ARRAY_SIZE(data);
672 int i;
673
674 char cmd[4096];
675 char buf[4096];
676
677 char *input1_filename = "test_batch_input1.txt";
678 char *input2_filename = "test_batch_input2.txt";
679 int have_input1;
680 int have_input2;
681
682 testStart("test_batch_input");
683
684 for (i = 0; i < data_size; i++) {
685
686 if (testContinue(p_ctx, i)) continue;
687
688 strcpy(cmd, "zint --dump --batch");
689 if (debug & ZINT_DEBUG_PRINT) {
690 strcat(cmd, " --verbose");
691 }
692
693 arg_int(cmd, "-b ", data[i].b);
694 arg_data(cmd, "-d ", data[i].data);
695 have_input1 = arg_input(cmd, input1_filename, data[i].input);
696 have_input2 = arg_input(cmd, input2_filename, data[i].input2);
697
698 strcat(cmd, " 2>&1");
699
700 assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
701 assert_zero(strcmp(buf, data[i].expected), "i:%d buf (%s) != expected (%s)\n", i, buf, data[i].expected);
702
703 if (have_input1) {
704 assert_zero(testUtilRemove(input1_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input1_filename, errno, strerror(errno));
705 }
706 if (have_input2) {
707 assert_zero(testUtilRemove(input2_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input2_filename, errno, strerror(errno));
708 }
709 }
710
711 testFinish();
712 }
713
714 static void test_batch_large(const testCtx *const p_ctx) {
715 int debug = p_ctx->debug;
716
717 struct item {
718 int b;
719 int mirror;
720 char *pattern;
721 int length;
722
723 char *expected;
724 };
725 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
726 struct item data[] = {
727 /* 0*/ { BARCODE_HANXIN, 0, "1", 7827, "00001.gif" },
728 /* 1*/ { BARCODE_HANXIN, 1, "1", 7827, "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.gif" },
729 /* 2*/ { BARCODE_HANXIN, 0, "1", 7828, NULL },
730 };
731 int data_size = ARRAY_SIZE(data);
732 int i;
733
734 char cmd[16384];
735 char data_buf[8192];
736 char buf[16384];
737
738 char *input_filename = "test_batch_large.txt";
739 int have_input;
740
741 testStart("test_batch_large");
742
743 #ifdef _WIN32
744 testSkip("Test not compatible with Windows");
745 return;
746 #endif
747
748 for (i = 0; i < data_size; i++) {
749
750 if (testContinue(p_ctx, i)) continue;
751
752 strcpy(cmd, "zint --batch --filetype=gif");
753 if (debug & ZINT_DEBUG_PRINT) {
754 strcat(cmd, " --verbose");
755 }
756
757 arg_int(cmd, "-b ", data[i].b);
758 arg_bool(cmd, "--mirror", data[i].mirror);
759
760 testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length);
761 strcat(data_buf, "\n");
762 have_input = arg_input(cmd, input_filename, data_buf);
763
764 if (!data[i].expected) {
765 printf("++++ Following error expected, ignore: ");
766 fflush(stdout);
767 }
768 assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
769 if (data[i].expected) {
770 assert_zero(testUtilRemove(data[i].expected), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, data[i].expected, errno, strerror(errno));
771 } else {
772 assert_zero(testUtilExists("out.gif"), "i:%d testUtilExists(out.gif) != 0 (%d: %s) (%s)\n", i, errno, strerror(errno), cmd);
773 }
774
775 if (have_input) {
776 assert_zero(testUtilRemove(input_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input_filename, errno, strerror(errno));
777 }
778 }
779
780 testFinish();
781 }
782
783 static void test_checks(const testCtx *const p_ctx) {
784 int debug = p_ctx->debug;
785
786 struct item {
787 int addongap;
788 int border;
789 int cols;
790 double dotsize;
791 double textgap;
792 int eci;
793 char *filetype;
794 double height;
795 double guard_descent;
796 int mask;
797 int mode;
798 int rotate;
799 int rows;
800 double scale;
801 int scmvv;
802 int secure;
803 int separator;
804 int vers;
805 int vwhitesp;
806 int w;
807
808 char *expected;
809 };
810 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
811 struct item data[] = {
812 /* 0*/ { -2, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 139: Invalid add-on gap value (digits only)" },
813 /* 1*/ { 6, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 140: Add-on gap '6' out of range (7 to 12), ignoring" },
814 /* 2*/ { 13, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 140: Add-on gap '13' out of range (7 to 12), ignoring" },
815 /* 3*/ { -1, -2, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 107: Invalid border width value (digits only)" },
816 /* 4*/ { -1, 1001, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 108: Border width '1001' out of range (0 to 1000), ignoring" },
817 /* 5*/ { -1, -1, -1, -1, -5.1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 195: Text gap '-5.1' out of range (-5 to 10), ignoring" },
818 /* 6*/ { -1, -1, -1, -1, 10.01, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 195: Text gap '10.01' out of range (-5 to 10), ignoring" },
819 /* 7*/ { -1, -1, -1, 12345678, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 181: Invalid dot radius floating point (integer part must be 7 digits maximum)" },
820 /* 8*/ { -1, -1, -1, 0.009, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 106: Invalid dot radius value (less than 0.01), ignoring" },
821 /* 9*/ { -1, -1, -2, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 131: Invalid columns value (digits only)" },
822 /* 10*/ { -1, -1, 201, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 111: Number of columns '201' out of range (1 to 200), ignoring" },
823 /* 11*/ { -1, -1, -1, -1, -1, -2, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 138: Invalid ECI code (digits only)" },
824 /* 12*/ { -1, -1, -1, -1, -1, 1000000, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 118: ECI code '1000000' out of range (0 to 999999), ignoring" },
825 /* 13*/ { -1, -1, -1, -1, -1, -1, "jpg", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 142: File type 'jpg' not supported, ignoring" },
826 /* 14*/ { -1, -1, -1, -1, -1, -1, NULL, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 183: Invalid symbol height floating point (negative value not permitted)" },
827 /* 15*/ { -1, -1, -1, -1, -1, -1, NULL, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 110: Symbol height '0' out of range (0.5 to 2000), ignoring" },
828 /* 16*/ { -1, -1, -1, -1, -1, -1, NULL, 2001, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 110: Symbol height '2001' out of range (0.5 to 2000), ignoring" },
829 /* 17*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 182: Invalid guard bar descent floating point (negative value not permitted)" },
830 /* 18*/ { -1, -1, -1, -1, -1, -1, NULL, -1, 50.1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 135: Guard bar descent '50.1' out of range (0 to 50), ignoring" },
831 /* 19*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 148: Invalid mask value (digits only)" },
832 /* 20*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 147: Mask value '8' out of range (0 to 7), ignoring" },
833 /* 21*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 116: Mode value '7' out of range (0 to 6), ignoring" },
834 /* 22*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, "Error 117: Invalid rotation value (digits only)" },
835 /* 23*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 137: Rotation value '45' out of range (0, 90, 180 or 270 only), ignoring" },
836 /* 24*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, "Error 132: Invalid rows value (digits only)" },
837 /* 25*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, 91, -1, -1, -1, -1, -1, -1, -1, "Warning 112: Number of rows '91' out of range (1 to 90), ignoring" },
838 /* 26*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, "Error 184: Invalid scale floating point (negative value not permitted)" },
839 /* 27*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, 0.49, -1, -1, -1, -1, -1, -1, "Warning 146: Scaling less than 0.5 will be set to 0.5 for 'gif' output" },
840 /* 28*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, "Error 149: Invalid Structured Carrier Message version value (digits only)" },
841 /* 29*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, 100, -1, -1, -1, -1, -1, "Warning 150: Structured Carrier Message version '100' out of range (0 to 99), ignoring" },
842 /* 30*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, "Error 134: Invalid ECC value (digits only)" },
843 /* 31*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, 9, -1, -1, -1, -1, "Warning 114: ECC level '9' out of range (0 to 8), ignoring" },
844 /* 32*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, "Error 128: Invalid separator value (digits only)" },
845 /* 33*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, 5, -1, -1, -1, "Warning 127: Separator value '5' out of range (0 to 4), ignoring" },
846 /* 34*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, "Error 133: Invalid version value (digits only)" },
847 /* 35*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1000, -1, -1, "Warning 113: Version value '1000' out of range (1 to 999), ignoring" },
848 /* 36*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, "Error 153: Invalid vertical whitespace value '-2' (digits only)" },
849 /* 37*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1001, -1, "Warning 154: Vertical whitespace value '1001' out of range (0 to 1000), ignoring" },
850 /* 38*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, "Error 120: Invalid horizontal whitespace value '-2' (digits only)" },
851 /* 39*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1001, "Warning 121: Horizontal whitespace value '1001' out of range (0 to 1000), ignoring" },
852 };
853 int data_size = ARRAY_SIZE(data);
854 int i;
855
856 char cmd[4096];
857 char buf[4096];
858 const char *outfilename = "out.gif";
859
860 testStart("test_checks");
861
862 for (i = 0; i < data_size; i++) {
863
864 if (testContinue(p_ctx, i)) continue;
865
866 strcpy(cmd, "zint -d 1 --filetype=gif");
867 if (debug & ZINT_DEBUG_PRINT) {
868 strcat(cmd, " --verbose");
869 }
870
871 arg_int(cmd, "--addongap=", data[i].addongap);
872 arg_int(cmd, "--border=", data[i].border);
873 arg_int(cmd, "--cols=", data[i].cols);
874 arg_double(cmd, "--dotsize=", data[i].dotsize);
875 arg_double(cmd, "--textgap=", data[i].textgap);
876 arg_int(cmd, "--eci=", data[i].eci);
877 arg_data(cmd, "--filetype=", data[i].filetype);
878 arg_double(cmd, "--height=", data[i].height);
879 arg_double(cmd, "--guarddescent=", data[i].guard_descent);
880 arg_int(cmd, "--mask=", data[i].mask);
881 arg_int(cmd, "--mode=", data[i].mode);
882 arg_int(cmd, "--rotate=", data[i].rotate);
883 arg_int(cmd, "--rows=", data[i].rows);
884 arg_double(cmd, "--scale=", data[i].scale);
885 arg_int(cmd, "--scmvv=", data[i].scmvv);
886 arg_int(cmd, "--secure=", data[i].secure);
887 arg_int(cmd, "--separator=", data[i].separator);
888 arg_int(cmd, "--vers=", data[i].vers);
889 arg_int(cmd, "--vwhitesp=", data[i].vwhitesp);
890 arg_int(cmd, "-w ", data[i].w);
891
892 strcat(cmd, " 2>&1");
893
894 assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
895 assert_zero(strcmp(buf, data[i].expected), "i:%d buf (%s) != expected (%s) (%s)\n", i, buf, data[i].expected, cmd);
896
897 if (strncmp(data[i].expected, "Warning", 7) == 0) {
898 assert_zero(testUtilRemove(outfilename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, outfilename, errno, strerror(errno));
899 }
900 }
901
902 testFinish();
903 }
904
905 static void test_barcode_symbology(const testCtx *const p_ctx) {
906 int debug = p_ctx->debug;
907
908 struct item {
909 const char *bname;
910 const char *data;
911 const char *primary;
912 int fail;
913 const char *expected;
914 };
915 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
916 static const struct item data[] = {
917 /* 0*/ { "_", "1", NULL, 1, "Error 119: Invalid barcode type '_'" },
918 /* 1*/ { "a", "1", NULL, 1, "Error 119: Invalid barcode type 'a'" },
919 /* 2*/ { "code128", "1", NULL, 0, "BARCODE_CODE128 (20)," },
920 /* 3*/ { "code218", "1", NULL, 1, "Error 119: Invalid barcode type 'code218'" },
921 /* 4*/ { "code12", "1", NULL, 1, "Error 119: Invalid barcode type 'code12'" },
922 /* 5*/ { "BARCODE_CODE11", "1", NULL, 0, "BARCODE_CODE11 (1)," },
923 /* 6*/ { "C25 Standard", "1", NULL, 0, "BARCODE_C25STANDARD (2)," },
924 /* 7*/ { "c25matrix", "1", NULL, 0, "BARCODE_C25STANDARD (2)," }, /* Legacy now supported */
925 /* 8*/ { "2 of 5 Standard", "1", NULL, 0, "BARCODE_C25STANDARD (2)," }, /* Synonym */
926 /* 9*/ { "2 of 5 Matrix", "1", NULL, 0, "BARCODE_C25STANDARD (2)," }, /* Synonym */
927 /* 10*/ { "Code 2 of 5 Standard", "1", NULL, 0, "BARCODE_C25STANDARD (2)," }, /* Synonym */
928 /* 11*/ { "Code 2 of 5 Matrix", "1", NULL, 0, "BARCODE_C25STANDARD (2)," }, /* Synonym */
929 /* 12*/ { "Standard Code 2 of 5", "1", NULL, 0, "BARCODE_C25STANDARD (2)," }, /* Synonym */
930 /* 13*/ { "C25INTER", "1", NULL, 0, "BARCODE_C25INTER (3)," },
931 /* 14*/ { "c25 interleaved", "1", NULL, 0, "BARCODE_C25INTER (3)," }, /* Synonym */
932 /* 15*/ { "code 2 of 5 inter", "1", NULL, 0, "BARCODE_C25INTER (3)," }, /* Synonym */
933 /* 16*/ { "code 2 of 5 interleaved", "1", NULL, 0, "BARCODE_C25INTER (3)," }, /* Synonym */
934 /* 17*/ { "2 of 5 inter", "1", NULL, 0, "BARCODE_C25INTER (3)," }, /* Synonym */
935 /* 18*/ { "2 of 5 interleaved", "1", NULL, 0, "BARCODE_C25INTER (3)," }, /* Synonym */
936 /* 19*/ { "interleaved 2 of 5", "1", NULL, 0, "BARCODE_C25INTER (3)," }, /* Synonym */
937 /* 20*/ { "interleaved code 2 of 5", "1", NULL, 0, "BARCODE_C25INTER (3)," }, /* Synonym */
938 /* 21*/ { "c25IATA", "1", NULL, 0, "BARCODE_C25IATA (4)," },
939 /* 22*/ { "2of5IATA", "1", NULL, 0, "BARCODE_C25IATA (4)," }, /* Synonym */
940 /* 23*/ { "code2of5IATA", "1", NULL, 0, "BARCODE_C25IATA (4)," }, /* Synonym */
941 /* 24*/ { "IATA2of5", "1", NULL, 0, "BARCODE_C25IATA (4)," }, /* Synonym */
942 /* 25*/ { "IATAcode2of5", "1", NULL, 0, "BARCODE_C25IATA (4)," }, /* Synonym */
943 /* 26*/ { "c25 Logic", "1", NULL, 0, "BARCODE_C25LOGIC (6)," },
944 /* 27*/ { "c25 Data Logic", "1", NULL, 0, "BARCODE_C25LOGIC (6)," }, /* Synonym */
945 /* 28*/ { "Code 2 of 5 Logic", "1", NULL, 0, "BARCODE_C25LOGIC (6)," }, /* Synonym */
946 /* 29*/ { "Code 2 of 5 Data Logic", "1", NULL, 0, "BARCODE_C25LOGIC (6)," }, /* Synonym */
947 /* 30*/ { "2 of 5 Logic", "1", NULL, 0, "BARCODE_C25LOGIC (6)," }, /* Synonym */
948 /* 31*/ { "2 of 5 Data Logic", "1", NULL, 0, "BARCODE_C25LOGIC (6)," }, /* Synonym */
949 /* 32*/ { "c25 Ind", "1", NULL, 0, "BARCODE_C25IND (7)," },
950 /* 33*/ { "c25 Industrial", "1", NULL, 0, "BARCODE_C25IND (7)," }, /* Synonym */
951 /* 34*/ { "code 2 of 5 Ind", "1", NULL, 0, "BARCODE_C25IND (7)," }, /* Synonym */
952 /* 35*/ { "code 2 of 5 Industrial", "1", NULL, 0, "BARCODE_C25IND (7)," }, /* Synonym */
953 /* 36*/ { "2 of 5 Ind", "1", NULL, 0, "BARCODE_C25IND (7)," }, /* Synonym */
954 /* 37*/ { "2 of 5 Industrial", "1", NULL, 0, "BARCODE_C25IND (7)," }, /* Synonym */
955 /* 38*/ { "Industrial 2 of 5", "1", NULL, 0, "BARCODE_C25IND (7)," }, /* Synonym */
956 /* 39*/ { "Industrial code 2 of 5", "1", NULL, 0, "BARCODE_C25IND (7)," }, /* Synonym */
957 /* 40*/ { "code39", "1", NULL, 0, "BARCODE_CODE39 (8)," },
958 /* 41*/ { "excode 39", "1", NULL, 0, "BARCODE_EXCODE39 (9)," },
959 /* 42*/ { "Extended Code 39", "1", NULL, 0, "BARCODE_EXCODE39 (9)," },
960 /* 43*/ { "eanx", "1", NULL, 0, "BARCODE_EANX (13)," },
961 /* 44*/ { "ean", "1", NULL, 0, "BARCODE_EANX (13)," },
962 /* 45*/ { "eanx chk", "1", NULL, 0, "BARCODE_EANX_CHK (14)," },
963 /* 46*/ { "eanxchk", "1", NULL, 0, "BARCODE_EANX_CHK (14)," },
964 /* 47*/ { "eanchk", "1", NULL, 0, "BARCODE_EANX_CHK (14)," },
965 /* 48*/ { "GS1128", "[01]12345678901231", NULL, 0, "BARCODE_GS1_128 (16)," },
966 /* 49*/ { "ean 128", "[01]12345678901231", NULL, 0, "BARCODE_GS1_128 (16)," },
967 /* 50*/ { "coda bar", "A1B", NULL, 0, "BARCODE_CODABAR (18)," },
968 /* 51*/ { "DPLEIT", "1", NULL, 0, "BARCODE_DPLEIT (21)," },
969 /* 52*/ { "DPIDENT", "1", NULL, 0, "BARCODE_DPIDENT (22)," },
970 /* 53*/ { "code16k", "1", NULL, 0, "BARCODE_CODE16K (23)," },
971 /* 54*/ { "CODE49", "1", NULL, 0, "BARCODE_CODE49 (24)," },
972 /* 55*/ { "CODE93", "1", NULL, 0, "BARCODE_CODE93 (25)," },
973 /* 56*/ { "flat", "1", NULL, 0, "BARCODE_FLAT (28)," },
974 /* 57*/ { "dbar omn", "1", NULL, 0, "BARCODE_DBAR_OMN (29)," },
975 /* 58*/ { "dbar omni", "1", NULL, 0, "BARCODE_DBAR_OMN (29)," },
976 /* 59*/ { "rss14", "1", NULL, 0, "BARCODE_DBAR_OMN (29)," },
977 /* 60*/ { "databar omn", "1", NULL, 0, "BARCODE_DBAR_OMN (29)," },
978 /* 61*/ { "databar omni", "1", NULL, 0, "BARCODE_DBAR_OMN (29)," },
979 /* 62*/ { "dbar ltd", "1", NULL, 0, "BARCODE_DBAR_LTD (30)," },
980 /* 63*/ { "dbar limited", "1", NULL, 0, "BARCODE_DBAR_LTD (30)," },
981 /* 64*/ { "rss ltd", "1", NULL, 0, "BARCODE_DBAR_LTD (30)," },
982 /* 65*/ { "databar ltd", "1", NULL, 0, "BARCODE_DBAR_LTD (30)," },
983 /* 66*/ { "databar limited", "1", NULL, 0, "BARCODE_DBAR_LTD (30)," },
984 /* 67*/ { "dbarexp", "[10]12", NULL, 0, "BARCODE_DBAR_EXP (31)," },
985 /* 68*/ { "dbarexpanded", "[10]12", NULL, 0, "BARCODE_DBAR_EXP (31)," },
986 /* 69*/ { "rss exp", "[10]12", NULL, 0, "BARCODE_DBAR_EXP (31)," },
987 /* 70*/ { "databarexp", "[10]12", NULL, 0, "BARCODE_DBAR_EXP (31)," },
988 /* 71*/ { "databarexpanded", "[10]12", NULL, 0, "BARCODE_DBAR_EXP (31)," },
989 /* 72*/ { "telepen", "1", NULL, 0, "BARCODE_TELEPEN (32)," },
990 /* 73*/ { "upc", "1", NULL, 1, "Error 119: Invalid barcode type 'upc'" },
991 /* 74*/ { "upca", "1", NULL, 0, "BARCODE_UPCA (34)," },
992 /* 75*/ { "upca_chk", "123456789012", NULL, 0, "BARCODE_UPCA_CHK (35)," },
993 /* 76*/ { "upce", "1", NULL, 0, "BARCODE_UPCE (37)," },
994 /* 77*/ { "upce chk", "12345670", NULL, 0, "BARCODE_UPCE_CHK (38)," },
995 /* 78*/ { "POSTNET ", "12345678901", NULL, 0, "BARCODE_POSTNET (40)," },
996 /* 79*/ { "msi", "1", NULL, 0, "BARCODE_MSI_PLESSEY (47)," },
997 /* 80*/ { "MSI Plessey ", "1", NULL, 0, "BARCODE_MSI_PLESSEY (47)," },
998 /* 81*/ { "fim ", "A", NULL, 0, "BARCODE_FIM (49)," },
999 /* 82*/ { "LOGMARS", "123456", NULL, 0, "BARCODE_LOGMARS (50)," },
1000 /* 83*/ { " pharma", "123456", NULL, 0, "BARCODE_PHARMA (51)," },
1001 /* 84*/ { " pzn ", "1", NULL, 0, "BARCODE_PZN (52)," },
1002 /* 85*/ { "pharma two", "4", NULL, 0, "BARCODE_PHARMA_TWO (53)," },
1003 /* 86*/ { "cepnet", "12345678", NULL, 0, "BARCODE_CEPNET (54)," },
1004 /* 87*/ { "BARCODE_PDF417", "1", NULL, 0, "BARCODE_PDF417 (55)," },
1005 /* 88*/ { "pdf", "1", NULL, 1, "Error 119: Invalid barcode type 'pdf'" },
1006 /* 89*/ { "barcodepdf417comp", "1", NULL, 0, "BARCODE_PDF417COMP (56)," },
1007 /* 90*/ { "pdf417trunc", "1", NULL, 0, "BARCODE_PDF417COMP (56)," },
1008 /* 91*/ { "MaxiCode", "1", NULL, 0, "BARCODE_MAXICODE (57)," },
1009 /* 92*/ { "QR CODE", "1", NULL, 0, "BARCODE_QRCODE (58)," },
1010 /* 93*/ { "qr", "1", NULL, 0, "BARCODE_QRCODE (58)," }, /* Synonym */
1011 /* 94*/ { "Code 128 B", "1", NULL, 0, "BARCODE_CODE128AB (60)," },
1012 /* 95*/ { "Code 128 aB", "1", NULL, 0, "BARCODE_CODE128AB (60)," },
1013 /* 96*/ { "AUS POST", "12345678901234567890123", NULL, 0, "BARCODE_AUSPOST (63)," },
1014 /* 97*/ { "AusReply", "12345678", NULL, 0, "BARCODE_AUSREPLY (66)," },
1015 /* 98*/ { "AUSROUTE", "12345678", NULL, 0, "BARCODE_AUSROUTE (67)," },
1016 /* 99*/ { "AUS REDIRECT", "12345678", NULL, 0, "BARCODE_AUSREDIRECT (68)," },
1017 /*100*/ { "isbnx", "123456789", NULL, 0, "BARCODE_ISBNX (69)," },
1018 /*101*/ { "rm4scc", "1", NULL, 0, "BARCODE_RM4SCC (70)," },
1019 /*102*/ { "DataMatrix", "1", NULL, 0, "BARCODE_DATAMATRIX (71)," },
1020 /*103*/ { "EAN14", "1", NULL, 0, "BARCODE_EAN14 (72)," },
1021 /*104*/ { "vin", "12345678701234567", NULL, 0, "BARCODE_VIN (73)" },
1022 /*105*/ { "CodaBlock-F", "1", NULL, 0, "BARCODE_CODABLOCKF (74)," },
1023 /*106*/ { "NVE18", "1", NULL, 0, "BARCODE_NVE18 (75)," },
1024 /*107*/ { "Japan Post", "1", NULL, 0, "BARCODE_JAPANPOST (76)," },
1025 /*108*/ { "Korea Post", "1", NULL, 0, "BARCODE_KOREAPOST (77)," },
1026 /*109*/ { "DBar Stk", "1", NULL, 0, "BARCODE_DBAR_STK (79)," },
1027 /*110*/ { "DBar Stacked", "1", NULL, 0, "BARCODE_DBAR_STK (79)," },
1028 /*111*/ { "rss14stack", "1", NULL, 0, "BARCODE_DBAR_STK (79)," },
1029 /*112*/ { "DataBar Stk", "1", NULL, 0, "BARCODE_DBAR_STK (79)," },
1030 /*113*/ { "DataBar Stacked", "1", NULL, 0, "BARCODE_DBAR_STK (79)," },
1031 /*114*/ { "DBar Omn Stk", "1", NULL, 0, "BARCODE_DBAR_OMNSTK (80)," },
1032 /*115*/ { "DBar Stacked Omni", "1", NULL, 0, "BARCODE_DBAR_OMNSTK (80)," },
1033 /*116*/ { "RSS14STACK OMNI", "1", NULL, 0, "BARCODE_DBAR_OMNSTK (80)," },
1034 /*117*/ { "DataBar Omn Stk", "1", NULL, 0, "BARCODE_DBAR_OMNSTK (80)," },
1035 /*118*/ { "DataBar Stacked Omn", "1", NULL, 0, "BARCODE_DBAR_OMNSTK (80)," },
1036 /*119*/ { "DataBar Stacked Omni", "1", NULL, 0, "BARCODE_DBAR_OMNSTK (80)," },
1037 /*120*/ { "DBar Exp Stk", "[20]01", NULL, 0, "BARCODE_DBAR_EXPSTK (81)," },
1038 /*121*/ { "DBar Expanded Stacked", "[20]01", NULL, 0, "BARCODE_DBAR_EXPSTK (81)," },
1039 /*122*/ { "rss_expstack", "[20]01", NULL, 0, "BARCODE_DBAR_EXPSTK (81)," },
1040 /*123*/ { "DataBar Exp Stk", "[20]01", NULL, 0, "BARCODE_DBAR_EXPSTK (81)," },
1041 /*124*/ { "DataBar Expanded Stk", "[20]01", NULL, 0, "BARCODE_DBAR_EXPSTK (81)," },
1042 /*125*/ { "DataBar Expanded Stacked", "[20]01", NULL, 0, "BARCODE_DBAR_EXPSTK (81)," },
1043 /*126*/ { "planet", "12345678901", NULL, 0, "BARCODE_PLANET (82)," },
1044 /*127*/ { "MicroPDF417", "1", NULL, 0, "BARCODE_MICROPDF417 (84)," },
1045 /*128*/ { "USPS IMail", "12345678901234567890", NULL, 0, "BARCODE_USPS_IMAIL (85)," },
1046 /*129*/ { "OneCode", "12345678901234567890", NULL, 0, "BARCODE_USPS_IMAIL (85)," },
1047 /*130*/ { "plessey", "1", NULL, 0, "BARCODE_PLESSEY (86)," },
1048 /*131*/ { "telepen num", "1", NULL, 0, "BARCODE_TELEPEN_NUM (87)," },
1049 /*132*/ { "ITF14", "1", NULL, 0, "BARCODE_ITF14 (89)," },
1050 /*133*/ { "KIX", "1", NULL, 0, "BARCODE_KIX (90)," },
1051 /*134*/ { "Aztec", "1", NULL, 0, "BARCODE_AZTEC (92)," },
1052 /*135*/ { "Aztec Code", "1", NULL, 0, "BARCODE_AZTEC (92)," }, /* Synonym */
1053 /*136*/ { "daft", "D", NULL, 0, "BARCODE_DAFT (93)," },
1054 /*137*/ { "DPD", "0123456789012345678901234567", NULL, 0, "BARCODE_DPD (96)," },
1055 /*138*/ { "Micro QR", "1", NULL, 0, "BARCODE_MICROQR (97)," },
1056 /*139*/ { "Micro QR Code", "1", NULL, 0, "BARCODE_MICROQR (97)," },
1057 /*140*/ { "hibc128", "1", NULL, 0, "BARCODE_HIBC_128 (98)," },
1058 /*141*/ { "hibccode128", "1", NULL, 0, "BARCODE_HIBC_128 (98)," }, /* Synonym */
1059 /*142*/ { "hibc39", "1", NULL, 0, "BARCODE_HIBC_39 (99)," },
1060 /*143*/ { "hibccode39", "1", NULL, 0, "BARCODE_HIBC_39 (99)," }, /* Synonym */
1061 /*144*/ { "hibcdatamatrix", "1", NULL, 0, "BARCODE_HIBC_DM (102)," }, /* Synonym */
1062 /*145*/ { "hibcdm", "1", NULL, 0, "BARCODE_HIBC_DM (102)," },
1063 /*146*/ { "HIBC qr", "1", NULL, 0, "BARCODE_HIBC_QR (104)," },
1064 /*147*/ { "HIBC QR Code", "1", NULL, 0, "BARCODE_HIBC_QR (104)," }, /* Synonym */
1065 /*148*/ { "HIBCPDF", "1", NULL, 0, "BARCODE_HIBC_PDF (106)," },
1066 /*149*/ { "HIBCPDF417", "1", NULL, 0, "BARCODE_HIBC_PDF (106)," }, /* Synonym */
1067 /*150*/ { "HIBCMICPDF", "1", NULL, 0, "BARCODE_HIBC_MICPDF (108)," },
1068 /*151*/ { "HIBC Micro PDF", "1", NULL, 0, "BARCODE_HIBC_MICPDF (108)," }, /* Synonym */
1069 /*152*/ { "HIBC Micro PDF417", "1", NULL, 0, "BARCODE_HIBC_MICPDF (108)," }, /* Synonym */
1070 /*153*/ { "HIBC BlockF", "1", NULL, 0, "BARCODE_HIBC_BLOCKF (110)," },
1071 /*154*/ { "HIBC CodaBlock-F", "1", NULL, 0, "BARCODE_HIBC_BLOCKF (110)," }, /* Synonym */
1072 /*155*/ { "HIBC Aztec", "1", NULL, 0, "BARCODE_HIBC_AZTEC (112)," },
1073 /*156*/ { "DotCode", "1", NULL, 0, "BARCODE_DOTCODE (115)," },
1074 /*157*/ { "Han Xin", "1", NULL, 0, "BARCODE_HANXIN (116)," },
1075 /*158*/ { "Mailmark", "01000000000000000AA00AA0A", NULL, 0, "BARCODE_MAILMARK_4S (121)," },
1076 /*159*/ { "Mailmark 4-state", "01000000000000000AA00AA0A", NULL, 0, "BARCODE_MAILMARK_4S (121)," },
1077 /*160*/ { "Mailmark 2D", "012100123412345678AB19XY1A 0", NULL, 0, "BARCODE_MAILMARK_2D (119)," },
1078 /*161*/ { "azrune", "1", NULL, 0, "BARCODE_AZRUNE (128)," },
1079 /*162*/ { "aztecrune", "1", NULL, 0, "BARCODE_AZRUNE (128)," }, /* Synonym */
1080 /*163*/ { "aztecrunes", "1", NULL, 0, "BARCODE_AZRUNE (128)," }, /* Synonym */
1081 /*164*/ { "code32", "1", NULL, 0, "BARCODE_CODE32 (129)," },
1082 /*165*/ { "eanx cc", "[20]01", "1234567890128", 0, "BARCODE_EANX_CC (130)," },
1083 /*166*/ { "eancc", "[20]01", "1234567890128", 0, "BARCODE_EANX_CC (130)," },
1084 /*167*/ { "GS1 128 CC", "[01]12345678901231", "[20]01", 0, "BARCODE_GS1_128_CC (131)," },
1085 /*168*/ { "EAN128 CC", "[01]12345678901231", "[20]01", 0, "BARCODE_GS1_128_CC (131)," },
1086 /*169*/ { "dbaromncc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_OMN_CC (132)," },
1087 /*170*/ { "dbaromnicc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_OMN_CC (132)," },
1088 /*171*/ { "rss14 cc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_OMN_CC (132)," },
1089 /*172*/ { "databaromncc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_OMN_CC (132)," },
1090 /*173*/ { "databaromnicc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_OMN_CC (132)," },
1091 /*174*/ { "dbarltdcc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_LTD_CC (133)," },
1092 /*175*/ { "dbarlimitedcc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_LTD_CC (133)," },
1093 /*176*/ { "rss ltd cc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_LTD_CC (133)," },
1094 /*177*/ { "databarltdcc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_LTD_CC (133)," },
1095 /*178*/ { "databarlimitedcc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_LTD_CC (133)," },
1096 /*179*/ { "dbarexpcc", "[20]01", "[01]12345678901231", 0, "BARCODE_DBAR_EXP_CC (134)," },
1097 /*180*/ { "rss exp cc", "[20]01", "[01]12345678901231", 0, "BARCODE_DBAR_EXP_CC (134)," },
1098 /*181*/ { "databarexpcc", "[20]01", "[01]12345678901231", 0, "BARCODE_DBAR_EXP_CC (134)," },
1099 /*182*/ { "databar expanded cc", "[20]01", "[01]12345678901231", 0, "BARCODE_DBAR_EXP_CC (134)," },
1100 /*183*/ { "upcacc", "[20]01", "12345678901", 0, "BARCODE_UPCA_CC (135)," },
1101 /*184*/ { "upcecc", "[20]01", "1234567", 0, "BARCODE_UPCE_CC (136)," },
1102 /*185*/ { "dbar stk cc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_STK_CC (137)," },
1103 /*186*/ { "rss14stackcc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_STK_CC (137)," },
1104 /*187*/ { "databar stk cc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_STK_CC (137)," },
1105 /*188*/ { "databar stacked cc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_STK_CC (137)," },
1106 /*189*/ { "dbaromnstkcc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_OMNSTK_CC (138)," },
1107 /*190*/ { "BARCODE_RSS14_OMNI_CC", "[20]01", "1234567890123", 0, "BARCODE_DBAR_OMNSTK_CC (138)," },
1108 /*191*/ { "databaromnstkcc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_OMNSTK_CC (138)," },
1109 /*192*/ { "databar stacked omncc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_OMNSTK_CC (138)," },
1110 /*193*/ { "databar stacked omni cc", "[20]01", "1234567890123", 0, "BARCODE_DBAR_OMNSTK_CC (138)," },
1111 /*194*/ { "dbarexpstkcc", "[20]01", "[01]12345678901231", 0, "BARCODE_DBAR_EXPSTK_CC (139)," },
1112 /*195*/ { "RSS EXPSTACK CC", "[20]01", "[01]12345678901231", 0, "BARCODE_DBAR_EXPSTK_CC (139)," },
1113 /*196*/ { "databarexpstkcc", "[20]01", "[01]12345678901231", 0, "BARCODE_DBAR_EXPSTK_CC (139)," },
1114 /*197*/ { "databar expanded stkcc", "[20]01", "[01]12345678901231", 0, "BARCODE_DBAR_EXPSTK_CC (139)," },
1115 /*198*/ { "databar expanded stacked cc", "[20]01", "[01]12345678901231", 0, "BARCODE_DBAR_EXPSTK_CC (139)," },
1116 /*199*/ { "Channel", "1", NULL, 0, "BARCODE_CHANNEL (140)," },
1117 /*200*/ { "Channel Code", "1", NULL, 0, "BARCODE_CHANNEL (140)," },
1118 /*201*/ { "CodeOne", "1", NULL, 0, "BARCODE_CODEONE (141)," },
1119 /*202*/ { "Grid Matrix", "1", NULL, 0, "BARCODE_GRIDMATRIX (142)," },
1120 /*203*/ { "UPN QR", "1", NULL, 0, "BARCODE_UPNQR (143)," },
1121 /*204*/ { "UPN QR Code", "1", NULL, 0, "BARCODE_UPNQR (143)," }, /* Synonym */
1122 /*205*/ { "ultra", "1", NULL, 0, "BARCODE_ULTRA (144)," },
1123 /*206*/ { "ultracode", "1", NULL, 0, "BARCODE_ULTRA (144)," }, /* Synonym */
1124 /*207*/ { "rMQR", "1", NULL, 0, "BARCODE_RMQR (145)," },
1125 /*208*/ { "bc412", "1234567", NULL, 0, "BARCODE_BC412 (146)," },
1126 /*209*/ { "x", "1", NULL, 1, "Error 119: Invalid barcode type 'x'" },
1127 /*210*/ { "\177", "1", NULL, 1, "Error 119: Invalid barcode type '\177'" },
1128 };
1129 int data_size = ARRAY_SIZE(data);
1130 int i;
1131
1132 char cmd[4096];
1133 char buf[8192];
1134 const char *outfilename = "out.gif";
1135
1136 testStart("test_barcode_symbology");
1137
1138 for (i = 0; i < data_size; i++) {
1139
1140 if (testContinue(p_ctx, i)) continue;
1141
1142 strcpy(cmd, "zint --filetype=gif");
1143 strcat(cmd, " --verbose");
1144
1145 arg_data(cmd, "-b ", data[i].bname);
1146 arg_data(cmd, "-d ", data[i].data);
1147 arg_data(cmd, "--primary=", data[i].primary);
1148
1149 strcat(cmd, " 2>&1");
1150
1151 assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
1152 if (!data[i].fail) {
1153 assert_zero(testUtilRemove(outfilename), "i:%d testUtilRemove(%s) != 0 (%d: %s) (%s)\n", i, outfilename, errno, strerror(errno), cmd);
1154 }
1155 assert_nonnull(strstr(buf, data[i].expected), "i:%d strstr(%s, %s) == NULL (%s)\n", i, buf, data[i].expected, cmd);
1156 }
1157
1158 testFinish();
1159 }
1160
1161 static void test_other_opts(const testCtx *const p_ctx) {
1162 int debug = p_ctx->debug;
1163
1164 struct item {
1165 int b;
1166 char *data;
1167 int input_mode;
1168 char *opt;
1169 char *opt_data;
1170
1171 char *expected;
1172 int strstr_cmp;
1173 };
1174 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
1175 struct item data[] = {
1176 /* 0*/ { BARCODE_CODE128, "1", -1, " --bg=", "EF9900", "", 0 },
1177 /* 1*/ { BARCODE_CODE128, "1", -1, " -bg=", "EF9900", "", 0 },
1178 /* 2*/ { BARCODE_CODE128, "1", -1, " --bg=", "EF9900AA", "", 0 },
1179 /* 3*/ { BARCODE_CODE128, "1", -1, " --bg=", "GF9900", "Error 881: Malformed background RGB colour 'GF9900' (hexadecimal only)", 0 },
1180 /* 4*/ { BARCODE_CODE128, "1", -1, " --bgcolor=", "EF9900", "", 0 },
1181 /* 5*/ { BARCODE_CODE128, "1", -1, " --bgcolour=", "EF9900", "", 0 },
1182 /* 6*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000", "", 0 },
1183 /* 7*/ { BARCODE_CODE128, "1", -1, " --fg=", "00000000", "", 0 },
1184 /* 8*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000F", "Error 880: Malformed foreground RGB colour (6 or 8 characters only)", 0 },
1185 /* 9*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000FG", "Error 881: Malformed foreground RGB colour '000000FG' (hexadecimal only)", 0 },
1186 /* 10*/ { BARCODE_CODE128, "1", -1, " --fg=", "0,0,0,100", "", 0 },
1187 /* 11*/ { BARCODE_CODE128, "1", -1, " --fgcolor=", "111111", "", 0 },
1188 /* 12*/ { BARCODE_CODE128, "1", -1, " --fgcolour=", "111111", "", 0 },
1189 /* 13*/ { BARCODE_CODE128, "1", -1, " --compliantheight", "", "", 0 },
1190 /* 14*/ { BARCODE_DATAMATRIX, "1", -1, " --dmiso144", "", "", 0 },
1191 /* 15*/ { BARCODE_EANX, "123456", -1, " --guardwhitespace", "", "", 0 },
1192 /* 16*/ { BARCODE_EANX, "123456", -1, " --embedfont", "", "", 0 },
1193 /* 17*/ { BARCODE_CODE128, "1", -1, " --nobackground", "", "", 0 },
1194 /* 18*/ { BARCODE_CODE128, "1", -1, " --noquietzones", "", "", 0 },
1195 /* 19*/ { BARCODE_CODE128, "1", -1, " --notext", "", "", 0 },
1196 /* 20*/ { BARCODE_CODE128, "1", -1, " --quietzones", "", "", 0 },
1197 /* 21*/ { BARCODE_CODE128, "1", -1, " --reverse", "", "", 0 },
1198 /* 22*/ { BARCODE_CODE128, "1", -1, " --werror", NULL, "", 0 },
1199 /* 23*/ { 19, "1", -1, " --werror", NULL, "Error 207: Codabar 18 not supported", 0 },
1200 /* 24*/ { BARCODE_GS1_128, "[01]12345678901231", -1, "", NULL, "", 0 },
1201 /* 25*/ { BARCODE_GS1_128, "0112345678901231", -1, "", NULL, "Error 252: Data does not start with an AI", 0 },
1202 /* 26*/ { BARCODE_GS1_128, "0112345678901231", -1, " --gs1nocheck", NULL, "Error 252: Data does not start with an AI", 0 },
1203 /* 27*/ { BARCODE_GS1_128, "[00]376104250021234569", -1, "", NULL, "", 0 },
1204 /* 28*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, "", NULL, "Warning 261: AI (00) position 18: Bad checksum '8', expected '9'", 0 },
1205 /* 29*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, " --gs1nocheck", NULL, "", 0 },
1206 /* 30*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, " --werror", NULL, "Error 261: AI (00) position 18: Bad checksum '8', expected '9'", 0 },
1207 /* 31*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "1", "Error 155: Invalid Structured Append argument, expect \"index,count[,ID]\"", 0 },
1208 /* 32*/ { BARCODE_AZTEC, "1", -1, " --structapp=", ",", "Error 156: Structured Append index too short", 0 },
1209 /* 33*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "1234567890,", "Error 156: Structured Append index too long", 0 },
1210 /* 34*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,", "Error 159: Structured Append count too short", 0 },
1211 /* 35*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,1234567890", "Error 159: Structured Append count too long", 0 },
1212 /* 36*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,123456789,", "Error 158: Structured Append ID too short", 0 },
1213 /* 37*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,1234567890,", "Error 157: Structured Append count too long", 0 },
1214 /* 38*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,123456789,123456789012345678901234567890123", "Error 158: Structured Append ID too long", 0 },
1215 /* 39*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,123456789,12345678901234567890123456789012", "Error 701: Structured Append count '123456789' out of range (2 to 26)", 0 },
1216 /* 40*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "26,26,12345678901234567890123456789012", "", 0 },
1217 /* 41*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "A,26,12345678901234567890123456789012", "Error 160: Invalid Structured Append index (digits only)", 0 },
1218 /* 42*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "26,A,12345678901234567890123456789012", "Error 161: Invalid Structured Append count (digits only)", 0 },
1219 /* 43*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "26,1,12345678901234567890123456789012", "Error 162: Invalid Structured Append count '1', must be greater than or equal to 2", 0 },
1220 /* 44*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "0,2,12345678901234567890123456789012", "Error 163: Structured Append index '0' out of range (1 to count '2')", 0 },
1221 /* 45*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "3,2,12345678901234567890123456789012", "Error 163: Structured Append index '3' out of range (1 to count '2')", 0 },
1222 /* 46*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "2,3,12345678901234567890123456789012", "", 0 },
1223 /* 47*/ { BARCODE_PDF417, "1", -1, " --heightperrow", "", "", 0 },
1224 /* 48*/ { -1, NULL, -1, " -v", NULL, "Zint version ", 1 },
1225 /* 49*/ { -1, NULL, -1, " --version", NULL, "Zint version ", 1 },
1226 /* 50*/ { -1, NULL, -1, " -h", NULL, "Encode input data in a barcode ", 1 },
1227 /* 51*/ { -1, NULL, -1, " -e", NULL, "3: ISO/IEC 8859-1 ", 1 },
1228 /* 52*/ { -1, NULL, -1, " -t", NULL, "1 CODE11 ", 1 },
1229 /* 53*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12345678", "Error 178: scalexdimdp X-dim invalid floating point (integer part must be 7 digits maximum)", 0 },
1230 /* 54*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "1234567890123", "Error 176: scalexdimdp X-dim too long", 0 },
1231 /* 55*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "123456.12", "Error 178: scalexdimdp X-dim invalid floating point (7 significant digits maximum)", 0 },
1232 /* 56*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", ",12.34", "Error 174: scalexdimdp X-dim too short", 0 },
1233 /* 57*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12.34,", "Error 175: scalexdimdp resolution too short", 0 },
1234 /* 58*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12mm1", "Error 177: scalexdimdp X-dim units must occur at end", 0 },
1235 /* 59*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "1inc", "Error 177: scalexdimdp X-dim units must occur at end", 0 },
1236 /* 60*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "1234x", "Error 178: scalexdimdp X-dim invalid floating point (integer part must be digits only)", 0 },
1237 /* 61*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12.34in,123x", "Error 180: scalexdimdp resolution invalid floating point (integer part must be digits only)", 0 },
1238 /* 62*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12,123.45678", "Error 180: scalexdimdp resolution invalid floating point (7 significant digits maximum)", 0 },
1239 /* 63*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "10.1,1000", "Warning 185: scalexdimdp X-dim '10.1' out of range (greater than 10), ignoring", 0 },
1240 /* 64*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "10,1000.1", "Warning 186: scalexdimdp resolution '1000.1' out of range (greater than 1000), ignoring", 0 },
1241 };
1242 int data_size = ARRAY_SIZE(data);
1243 int i;
1244
1245 char cmd[4096];
1246 char buf[8192];
1247 const char *outfilename = ZBarcode_NoPng() ? "out.gif" : "out.png";
1248
1249 testStart("test_other_opts");
1250
1251 for (i = 0; i < data_size; i++) {
1252
1253 if (testContinue(p_ctx, i)) continue;
1254
1255 strcpy(cmd, "zint");
1256
1257 arg_int(cmd, "-b ", data[i].b);
1258 arg_input_mode(cmd, data[i].input_mode);
1259 arg_data(cmd, "-d ", data[i].data);
1260 if (data[i].opt_data != NULL) {
1261 arg_data(cmd, data[i].opt, data[i].opt_data);
1262 } else {
1263 strcat(cmd, data[i].opt);
1264 }
1265
1266 strcat(cmd, " 2>&1");
1267
1268 assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
1269 if (data[i].strstr_cmp) {
1270 assert_nonnull(strstr(buf, data[i].expected), "i:%d strstr buf (%s) != expected (%s) (%s)\n", i, buf, data[i].expected, cmd);
1271 } else {
1272 assert_zero(strcmp(buf, data[i].expected), "i:%d strcmp buf (%s) != expected (%s) (%s)\n", i, buf, data[i].expected, cmd);
1273 if (strstr(data[i].expected, "Error") == NULL) {
1274 assert_zero(testUtilRemove(outfilename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, outfilename, errno, strerror(errno));
1275 }
1276 }
1277 }
1278
1279 testFinish();
1280 }
1281
1282 static void test_combos(const testCtx *const p_ctx) {
1283 int debug = p_ctx->debug;
1284
1285 struct item {
1286 int b;
1287 char *data;
1288 char *opts;
1289
1290 char *expected;
1291 char *outfilename;
1292 int strstr_cmp;
1293 };
1294 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
1295 struct item data[] = {
1296 /* 0*/ { -1, "1", " --direct -o direct.gif", "Warning 193: Output file given, ignoring '--direct' option", "direct.gif", 0 },
1297 };
1298 int data_size = ARRAY_SIZE(data);
1299 int i;
1300
1301 char cmd[4096];
1302 char buf[8192];
1303
1304 testStart("test_combos");
1305
1306 for (i = 0; i < data_size; i++) {
1307
1308 if (testContinue(p_ctx, i)) continue;
1309
1310 strcpy(cmd, "zint");
1311
1312 arg_int(cmd, "-b ", data[i].b);
1313 arg_data(cmd, "-d ", data[i].data);
1314 strcat(cmd, data[i].opts);
1315
1316 strcat(cmd, " 2>&1");
1317
1318 assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
1319 if (data[i].strstr_cmp) {
1320 assert_nonnull(strstr(buf, data[i].expected), "i:%d strstr buf (%s) != expected (%s) (%s)\n", i, buf, data[i].expected, cmd);
1321 } else {
1322 assert_zero(strcmp(buf, data[i].expected), "i:%d strcmp buf (%s) != expected (%s) (%s)\n", i, buf, data[i].expected, cmd);
1323 }
1324 if (data[i].outfilename != NULL) {
1325 assert_zero(remove(data[i].outfilename), "i:%d remove(%s) != 0 (%d: %s)\n", i, data[i].outfilename, errno, strerror(errno));
1326 }
1327 }
1328
1329 testFinish();
1330 }
1331
1332 static void test_exit_status(const testCtx *const p_ctx) {
1333 int debug = p_ctx->debug;
1334
1335 struct item {
1336 int b;
1337 char *data;
1338 int input_mode;
1339 char *opt;
1340 char *opt_data;
1341
1342 int expected;
1343 };
1344 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
1345 struct item data[] = {
1346 /* 0*/ { BARCODE_CODE128, "1", -1, " --bg=", "EF9900", 0 },
1347 /* 1*/ { BARCODE_CODE128, "1", -1, " --bg=", "GF9900", ZINT_ERROR_INVALID_OPTION }, /* Caught by libzint */
1348 /* 2*/ { BARCODE_CODE128, "1", -1, " --border=", "1001", ZINT_WARN_INVALID_OPTION }, /* Caught by CLI */
1349 /* 3*/ { BARCODE_CODE128, "1", -1, " --data=", "\200", ZINT_ERROR_INVALID_DATA }, /* Caught by libzint */
1350 /* 4*/ { BARCODE_CODE128, "1", -1, " --separator=", "-1", ZINT_ERROR_INVALID_OPTION }, /* Caught by CLI */
1351 /* 5*/ { BARCODE_CODE128, "1", -1, " --separator", NULL, ZINT_ERROR_INVALID_OPTION },
1352 /* 6*/ { BARCODE_CODE128, "1", -1, " --separator=", NULL, 0 }, /* Separator arg treated as 0 */
1353 /* 7*/ { BARCODE_CODE128, "1", -1, " --unknown", NULL, ZINT_ERROR_INVALID_OPTION },
1354 };
1355 int data_size = ARRAY_SIZE(data);
1356 int i;
1357 int exit_status;
1358
1359 char cmd[4096];
1360 char buf[8192];
1361 const char *outfilename = ZBarcode_NoPng() ? "out.gif" : "out.png";
1362
1363 testStart("test_exit_status");
1364
1365 for (i = 0; i < data_size; i++) {
1366
1367 if (testContinue(p_ctx, i)) continue;
1368
1369 strcpy(cmd, "zint");
1370 *buf = '\0';
1371
1372 arg_int(cmd, "-b ", data[i].b);
1373 arg_input_mode(cmd, data[i].input_mode);
1374 arg_data(cmd, "-d ", data[i].data);
1375 if (data[i].opt_data != NULL) {
1376 arg_data(cmd, data[i].opt, data[i].opt_data);
1377 } else {
1378 strcat(cmd, data[i].opt);
1379 }
1380
1381 strcat(cmd, " 2>&1");
1382
1383 assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, &exit_status), "i:%d exec(%s) NULL\n", i, cmd);
1384 assert_equal(exit_status, data[i].expected, "i:%d exit_status %d != expected (%d) (%s), (cmd: %s)\n", i, exit_status, data[i].expected, buf, cmd);
1385 if (data[i].expected < ZINT_ERROR) {
1386 assert_zero(testUtilRemove(outfilename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, outfilename, errno, strerror(errno));
1387 }
1388 }
1389
1390 testFinish();
1391 }
1392
1393 int main(int argc, char *argv[]) {
1394
1395 testFunction funcs[] = { /* name, func */
1396 { "test_dump_args", test_dump_args },
1397 { "test_dump_segs", test_dump_segs },
1398 { "test_input", test_input },
1399 { "test_stdin_input", test_stdin_input },
1400 { "test_batch_input", test_batch_input },
1401 { "test_batch_large", test_batch_large },
1402 { "test_checks", test_checks },
1403 { "test_barcode_symbology", test_barcode_symbology },
1404 { "test_other_opts", test_other_opts },
1405 { "test_combos", test_combos },
1406 { "test_exit_status", test_exit_status },
1407 };
1408
1409 testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
1410
1411 testReport();
1412
1413 return 0;
1414 }
1415
1416 /* vim: set ts=4 sw=4 et : */