comparison mupdf-source/thirdparty/zint/backend/tests/test_channel.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 "testcommon.h"
33
34 static void test_hrt(const testCtx *const p_ctx) {
35 int debug = p_ctx->debug;
36
37 struct item {
38 int option_2;
39 char *data;
40 int length;
41
42 char *expected;
43 };
44 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
45 static const struct item data[] = {
46 /* 0*/ { -1, "1", -1, "01" },
47 /* 1*/ { 3, "1", -1, "01" },
48 /* 2*/ { 3, "12", -1, "12" },
49 /* 3*/ { 4, "123", -1, "123" },
50 /* 4*/ { 5, "123", -1, "0123" },
51 /* 5*/ { 5, "12", -1, "0012" },
52 /* 6*/ { 5, "1", -1, "0001" },
53 /* 7*/ { 5, "1234", -1, "1234" },
54 /* 8*/ { 6, "1234", -1, "01234" },
55 /* 9*/ { 6, "123", -1, "00123" },
56 /* 10*/ { 6, "12", -1, "00012" },
57 /* 11*/ { 6, "1", -1, "00001" },
58 /* 12*/ { 7, "1234", -1, "001234" },
59 /* 13*/ { 7, "12345", -1, "012345" },
60 /* 14*/ { 7, "123456", -1, "123456" },
61 /* 15*/ { 7, "1", -1, "000001" },
62 /* 16*/ { 8, "12345", -1, "0012345" },
63 /* 17*/ { 8, "123456", -1, "0123456" },
64 /* 18*/ { 8, "1234567", -1, "1234567" },
65 /* 19*/ { 8, "12", -1, "0000012" },
66 /* 20*/ { 8, "1", -1, "0000001" },
67 };
68 const int data_size = ARRAY_SIZE(data);
69 int i, length, ret;
70 struct zint_symbol *symbol = NULL;
71
72 testStartSymbol("test_hrt", &symbol);
73
74 for (i = 0; i < data_size; i++) {
75
76 if (testContinue(p_ctx, i)) continue;
77
78 symbol = ZBarcode_Create();
79 assert_nonnull(symbol, "Symbol not created\n");
80
81 length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
82
83 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
84 assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt);
85
86 assert_zero(strcmp((char *) symbol->text, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->text, data[i].expected);
87
88 ZBarcode_Delete(symbol);
89 }
90
91 testFinish();
92 }
93
94 static void test_input(const testCtx *const p_ctx) {
95 int debug = p_ctx->debug;
96
97 struct item {
98 int option_2;
99 char *data;
100 int ret;
101 int expected_rows;
102 int expected_width;
103 char *expected_errtxt;
104 };
105 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
106 static const struct item data[] = {
107 /* 0*/ { -1, "0", 0, 1, 19, "" }, /* < 3 ignored */
108 /* 1*/ { 0, "0", 0, 1, 19, "" },
109 /* 2*/ { 1, "0", 0, 1, 19, "" },
110 /* 3*/ { 2, "0", 0, 1, 19, "" },
111 /* 4*/ { 9, "0", 0, 1, 19, "" }, /* > 8 ignored */
112 /* 5*/ { -1, "00", 0, 1, 19, "" },
113 /* 6*/ { 3, "00", 0, 1, 19, "" },
114 /* 7*/ { -1, "26", 0, 1, 19, "" },
115 /* 8*/ { 3, "26", 0, 1, 19, "" },
116 /* 9*/ { 3, "27", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 335: Input value \"27\" out of range (0 to 26 for 3 channels)" },
117 /* 10*/ { 3, "027", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 335: Input value \"27\" out of range (0 to 26 for 3 channels)" },
118 /* 11*/ { 3, "000", 0, 1, 19, "" },
119 /* 12*/ { 3, "001", 0, 1, 19, "" },
120 /* 13*/ { 3, "026", 0, 1, 19, "" },
121 /* 14*/ { -1, "27", 0, 1, 23, "" }, /* Channel 4 */
122 /* 15*/ { -1, "026", 0, 1, 23, "" }, /* Defaults to channel 4 due to length */
123 /* 16*/ { 3, "0026", 0, 1, 19, "" },
124 /* 17*/ { 3, "1234", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 335: Input value \"1234\" out of range (0 to 26 for 3 channels)" },
125 /* 18*/ { 4, "000", 0, 1, 23, "" },
126 /* 19*/ { -1, "000", 0, 1, 23, "" }, /* Defaults to channel 4 due to length */
127 /* 20*/ { 4, "026", 0, 1, 23, "" },
128 /* 21*/ { 4, "0000026", 0, 1, 23, "" },
129 /* 22*/ { 4, "0000", 0, 1, 23, "" },
130 /* 23*/ { 4, "292", 0, 1, 23, "" },
131 /* 24*/ { 4, "293", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 335: Input value \"293\" out of range (0 to 292 for 4 channels)" },
132 /* 25*/ { 4, "000293", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 335: Input value \"293\" out of range (0 to 292 for 4 channels)" },
133 /* 26*/ { -1, "293", 0, 1, 27, "" }, /* Channel 5 */
134 /* 27*/ { 5, "0000", 0, 1, 27, "" },
135 /* 28*/ { -1, "0000", 0, 1, 27, "" }, /* Defaults to channel 5 due to length */
136 /* 29*/ { -1, "3493", 0, 1, 27, "" },
137 /* 30*/ { 5, "3493", 0, 1, 27, "" },
138 /* 31*/ { 5, "3494", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 335: Input value \"3494\" out of range (0 to 3493 for 5 channels)" },
139 /* 32*/ { -1, "3494", 0, 1, 31, "" }, /* Channel 6 */
140 /* 33*/ { 6, "00000", 0, 1, 31, "" },
141 /* 34*/ { -1, "00000", 0, 1, 31, "" }, /* Defaults to channel 5 due to length */
142 /* 35*/ { -1, "44072", 0, 1, 31, "" },
143 /* 36*/ { 6, "44072", 0, 1, 31, "" },
144 /* 37*/ { 6, "44073", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 335: Input value \"44073\" out of range (0 to 44072 for 6 channels)" },
145 /* 38*/ { -1, "44073", 0, 1, 35, "" }, /* Channel 7 */
146 /* 39*/ { 7, "000000", 0, 1, 35, "" },
147 /* 40*/ { -1, "000000", 0, 1, 35, "" }, /* Defaults to channel 7 due to length */
148 /* 41*/ { 7, "576688", 0, 1, 35, "" },
149 /* 42*/ { 7, "576689", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 335: Input value \"576689\" out of range (0 to 576688 for 7 channels)" },
150 /* 43*/ { 7, "0576688", 0, 1, 35, "" },
151 /* 44*/ { -1, "1234567", 0, 1, 39, "" },
152 /* 45*/ { -1, "576689", 0, 1, 39, "" }, /* Channel 8 */
153 /* 46*/ { 8, "0000000", 0, 1, 39, "" },
154 /* 47*/ { -1, "0000000", 0, 1, 39, "" }, /* Defaults to channel 8 due to length */
155 /* 48*/ { 8, "1234567", 0, 1, 39, "" },
156 /* 49*/ { 8, "7742863", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 318: Input value \"7742863\" out of range (0 to 7742862)" },
157 /* 50*/ { 8, "01234567", ZINT_ERROR_TOO_LONG, -1, -1, "Error 333: Input length 8 too long (maximum 7)" },
158 /* 51*/ { 8, "00000000", ZINT_ERROR_TOO_LONG, -1, -1, "Error 333: Input length 8 too long (maximum 7)" },
159 /* 52*/ { 9, "7742863", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 318: Input value \"7742863\" out of range (0 to 7742862)" },
160 /* 53*/ { -1, "A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 334: Invalid character at position 1 in input (digits only)" },
161 };
162 const int data_size = ARRAY_SIZE(data);
163 int i, length, ret;
164 struct zint_symbol *symbol = NULL;
165
166 testStartSymbol("test_input", &symbol);
167
168 for (i = 0; i < data_size; i++) {
169
170 if (testContinue(p_ctx, i)) continue;
171
172 symbol = ZBarcode_Create();
173 assert_nonnull(symbol, "Symbol not created\n");
174
175 length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
176
177 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
178 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
179 assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt);
180 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
181
182 if (ret < ZINT_ERROR) {
183 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
184 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);
185 }
186
187 ZBarcode_Delete(symbol);
188 }
189
190 testFinish();
191 }
192
193 static void test_encode(const testCtx *const p_ctx) {
194 int debug = p_ctx->debug;
195
196 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
197
198 struct item {
199 int option_2;
200 char *data;
201 int ret;
202
203 int expected_rows;
204 int expected_width;
205 char *comment;
206 char *expected;
207 };
208 static const struct item data[] = {
209 /* 0*/ { -1, "1234", 0, 1, 27, "ANSI/AIM BC12-1998 Figure 1",
210 "101010101001010010011110011"
211 },
212 /* 1*/ { -1, "00", 0, 1, 19, "ANSI/AIM BC12-1998 Figure F1 Channel 3 top",
213 "1010101010110100011"
214 },
215 /* 2*/ { -1, "02", 0, 1, 19, "ANSI/AIM BC12-1998 Figure F1 Channel 3 2nd",
216 "1010101010110010011"
217 },
218 /* 3*/ { -1, "05", 0, 1, 19, "ANSI/AIM BC12-1998 Figure F1 Channel 3 3rd",
219 "1010101010110001101"
220 },
221 /* 4*/ { -1, "08", 0, 1, 19, "ANSI/AIM BC12-1998 Figure F1 Channel 3 4th",
222 "1010101010111000101"
223 },
224 /* 5*/ { -1, "10", 0, 1, 19, "ANSI/AIM BC12-1998 Figure F1 Channel 3 5th",
225 "1010101010010110011"
226 },
227 /* 6*/ { -1, "26", 0, 1, 19, "ANSI/AIM BC12-1998 Figure F1 Channel 3 bottom",
228 "1010101010001110101"
229 },
230 /* 7*/ { -1, "000", 0, 1, 23, "ANSI/AIM BC12-1998 Figure F1 Channel 4 top",
231 "10101010101101010000111"
232 },
233 /* 8*/ { -1, "004", 0, 1, 23, "ANSI/AIM BC12-1998 Figure F1 Channel 4 2nd",
234 "10101010101101001100011"
235 },
236 /* 9*/ { -1, "007", 0, 1, 23, "ANSI/AIM BC12-1998 Figure F1 Channel 4 3rd",
237 "10101010101101000110011"
238 },
239 /* 10*/ { -1, "010", 0, 1, 23, "ANSI/AIM BC12-1998 Figure F1 Channel 4 4th",
240 "10101010101101000011011"
241 },
242 /* 11*/ { -1, "100", 0, 1, 23, "ANSI/AIM BC12-1998 Figure F1 Channel 4 5th",
243 "10101010100101011100011"
244 },
245 /* 12*/ { -1, "292", 0, 1, 23, "ANSI/AIM BC12-1998 Figure F1 Channel 4 bottom",
246 "10101010100001110110101"
247 },
248 /* 13*/ { -1, "0000", 0, 1, 27, "ANSI/AIM BC12-1998 Figure F1 Channel 5 top",
249 "101010101011010101100000111"
250 },
251 /* 14*/ { -1, "0005", 0, 1, 27, "ANSI/AIM BC12-1998 Figure F1 Channel 5 2nd",
252 "101010101011010100111000011"
253 },
254 /* 15*/ { -1, "0010", 0, 1, 27, "ANSI/AIM BC12-1998 Figure F1 Channel 5 3rd",
255 "101010101011010100011110001"
256 },
257 /* 16*/ { -1, "0100", 0, 1, 27, "ANSI/AIM BC12-1998 Figure F1 Channel 5 4th",
258 "101010101011010001000111101"
259 },
260 /* 17*/ { -1, "1000", 0, 1, 27, "ANSI/AIM BC12-1998 Figure F1 Channel 5 5th",
261 "101010101011100001011011001"
262 },
263 /* 18*/ { -1, "3493", 0, 1, 27, "ANSI/AIM BC12-1998 Figure F1 Channel 5 bottom",
264 "101010101000001111010110101"
265 },
266 /* 19*/ { -1, "00000", 0, 1, 31, "ANSI/AIM BC12-1998 Figure F1 Channel 6 top",
267 "1010101010110101011010000001111"
268 },
269 /* 20*/ { -1, "00010", 0, 1, 31, "ANSI/AIM BC12-1998 Figure F1 Channel 6 2nd",
270 "1010101010110101011000111000011"
271 },
272 /* 21*/ { -1, "00100", 0, 1, 31, "ANSI/AIM BC12-1998 Figure F1 Channel 6 3rd",
273 "1010101010110101001100001111001"
274 },
275 /* 22*/ { -1, "01000", 0, 1, 31, "ANSI/AIM BC12-1998 Figure F1 Channel 6 4th",
276 "1010101010110100110011000100111"
277 },
278 /* 23*/ { -1, "10000", 0, 1, 31, "ANSI/AIM BC12-1998 Figure F1 Channel 6 5th",
279 "1010101010111011000100010110011"
280 },
281 /* 24*/ { -1, "44072", 0, 1, 31, "ANSI/AIM BC12-1998 Figure F1 Channel 6 bottom",
282 "1010101010000001111101010110101"
283 },
284 /* 25*/ { -1, "000000", 0, 1, 35, "ANSI/AIM BC12-1998 Figure F1 Channel 7 top",
285 "10101010101101010110101000000011111"
286 },
287 /* 26*/ { -1, "000100", 0, 1, 35, "ANSI/AIM BC12-1998 Figure F1 Channel 7 2nd",
288 "10101010101101010110111110001000001"
289 },
290 /* 27*/ { -1, "001000", 0, 1, 35, "ANSI/AIM BC12-1998 Figure F1 Channel 7 3rd",
291 "10101010101101010010100001111100011"
292 },
293 /* 28*/ { -1, "010000", 0, 1, 35, "ANSI/AIM BC12-1998 Figure F1 Channel 7 4th",
294 "10101010101101001010111111000100001"
295 },
296 /* 29*/ { -1, "100000", 0, 1, 35, "ANSI/AIM BC12-1998 Figure F1 Channel 7 5th",
297 "10101010101100001001001111101101001"
298 },
299 /* 30*/ { -1, "576688", 0, 1, 35, "ANSI/AIM BC12-1998 Figure F1 Channel 7 bottom",
300 "10101010100000001111101101010110101"
301 },
302 /* 31*/ { -1, "0000000", 0, 1, 39, "ANSI/AIM BC12-1998 Figure F1 Channel 8 top",
303 "101010101011010101101010110000000011111"
304 },
305 /* 32*/ { -1, "0001000", 0, 1, 39, "ANSI/AIM BC12-1998 Figure F1 Channel 8 2nd",
306 "101010101011010101101100010000010011111"
307 },
308 /* 33*/ { -1, "0010000", 0, 1, 39, "ANSI/AIM BC12-1998 Figure F1 Channel 8 3rd",
309 "101010101011010101110000110001101100011"
310 },
311 /* 34*/ { -1, "0100000", 0, 1, 39, "ANSI/AIM BC12-1998 Figure F1 Channel 8 4th",
312 "101010101011010111010110101100000000111"
313 },
314 /* 35*/ { -1, "1000000", 0, 1, 39, "ANSI/AIM BC12-1998 Figure F1 Channel 8 5th",
315 "101010101011001110100100100001111001011"
316 },
317 /* 36*/ { -1, "7742862", 0, 1, 39, "ANSI/AIM BC12-1998 Figure F1 Channel 8 bottom",
318 "101010101000000001111110101101010110101"
319 },
320 /* 37*/ { -1, "01", 0, 1, 19, "Edge case for initial_precalcs table",
321 "1010101010110110001"
322 },
323 /* 38*/ { -1, "001", 0, 1, 23, "Edge case for initial_precalcs table",
324 "10101010101101011000011"
325 },
326 /* 39*/ { -1, "0001", 0, 1, 27, "Edge case for initial_precalcs table",
327 "101010101011010101110000011"
328 },
329 /* 40*/ { -1, "00001", 0, 1, 31, "Edge case for initial_precalcs table",
330 "1010101010110101011011000000111"
331 },
332 /* 41*/ { -1, "000001", 0, 1, 35, "Edge case for initial_precalcs table",
333 "10101010101101010110101100000001111"
334 },
335 /* 42*/ { -1, "0000001", 0, 1, 39, "Edge case for initial_precalcs table",
336 "101010101011010101101010111000000001111"
337 },
338 /* 43*/ { -1, "115337", 0, 1, 35, "Edge case for channel_precalcs7 table",
339 "10101010101110100101001000111100011"
340 },
341 /* 44*/ { -1, "115338", 0, 1, 35, "Edge case for channel_precalcs7 table",
342 "10101010101110100101001000111110001"
343 },
344 /* 45*/ { -1, "115339", 0, 1, 35, "Edge case for channel_precalcs7 table",
345 "10101010101110100101001000010011111"
346 },
347 /* 46*/ { -1, "230675", 0, 1, 35, "Edge case for channel_precalcs7 table",
348 "10101010100101100011001111010011001"
349 },
350 /* 47*/ { -1, "230676", 0, 1, 35, "Edge case for channel_precalcs7 table",
351 "10101010100101100011001111010001011"
352 },
353 /* 48*/ { -1, "230677", 0, 1, 35, "Edge case for channel_precalcs7 table",
354 "10101010100101100011001111010001101"
355 },
356 /* 49*/ { -1, "346013", 0, 1, 35, "Edge case for channel_precalcs7 table",
357 "10101010100110011101010001011000111"
358 },
359 /* 50*/ { -1, "346014", 0, 1, 35, "Edge case for channel_precalcs7 table",
360 "10101010100110011101010001011100011"
361 },
362 /* 51*/ { -1, "346015", 0, 1, 35, "Edge case for channel_precalcs7 table",
363 "10101010100110011101010001011110001"
364 },
365 /* 52*/ { -1, "0119120", 0, 1, 39, "Edge case for channel_precalcs8 table",
366 "101010101011010111000011000100111010011"
367 },
368 /* 53*/ { -1, "0119121", 0, 1, 39, "Edge case for channel_precalcs8 table",
369 "101010101011010111000011000100111011001"
370 },
371 /* 54*/ { -1, "0119122", 0, 1, 39, "Edge case for channel_precalcs8 table",
372 "101010101011010111000011000100111001011"
373 },
374 /* 55*/ { -1, "0238241", 0, 1, 39, "Edge case for channel_precalcs8 table",
375 "101010101011010001011011001100011110001"
376 },
377 /* 56*/ { -1, "0238242", 0, 1, 39, "Edge case for channel_precalcs8 table",
378 "101010101011010001011011001100001001111"
379 },
380 /* 57*/ { -1, "0238243", 0, 1, 39, "Edge case for channel_precalcs8 table",
381 "101010101011010001011011001100001100111"
382 },
383 /* 58*/ { -1, "1072088", 0, 1, 39, "Edge case for channel_precalcs8 table",
384 "101010101011001111101000101100011001001"
385 },
386 /* 59*/ { -1, "1072089", 0, 1, 39, "Edge case for channel_precalcs8 table",
387 "101010101011001111101000101100011000101"
388 },
389 /* 60*/ { -1, "1072090", 0, 1, 39, "Edge case for channel_precalcs8 table",
390 "101010101011001111101000101100001010011"
391 },
392 /* 61*/ { -1, "4169234", 0, 1, 39, "Edge case for channel_precalcs8 table",
393 "101010101001101001101101111011000100001"
394 },
395 /* 62*/ { -1, "4169235", 0, 1, 39, "Edge case for channel_precalcs8 table",
396 "101010101001101001101101111011000010001"
397 },
398 /* 63*/ { -1, "4169236", 0, 1, 39, "Edge case for channel_precalcs8 table",
399 "101010101001101001101101111011000001001"
400 },
401 /* 64*/ { -1, "6075170", 0, 1, 39, "Edge case for channel_precalcs8 table",
402 "101010101000100011101010001110111001011"
403 },
404 /* 65*/ { -1, "6075171", 0, 1, 39, "Edge case for channel_precalcs8 table",
405 "101010101000100011101010001110111001101"
406 },
407 /* 66*/ { -1, "6075172", 0, 1, 39, "Edge case for channel_precalcs8 table",
408 "101010101000100011101010001110111101001"
409 },
410 /* 67*/ { -1, "7623743", 0, 1, 39, "Edge case for channel_precalcs8 table",
411 "101010101000001110010101101100101001111"
412 },
413 /* 68*/ { -1, "7623744", 0, 1, 39, "Edge case for channel_precalcs8 table",
414 "101010101000001110010101101100101100111"
415 },
416 /* 69*/ { -1, "7623745", 0, 1, 39, "Edge case for channel_precalcs8 table",
417 "101010101000001110010101101100101110011"
418 },
419 };
420 const int data_size = ARRAY_SIZE(data);
421 int i, length, ret;
422 struct zint_symbol *symbol = NULL;
423
424 char escaped[1024];
425 char bwipp_buf[8192];
426 char bwipp_msg[1024];
427
428 testStartSymbol("test_encode", &symbol);
429
430 for (i = 0; i < data_size; i++) {
431
432 if (testContinue(p_ctx, i)) continue;
433
434 symbol = ZBarcode_Create();
435 assert_nonnull(symbol, "Symbol not created\n");
436
437 length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
438
439 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
440 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
441
442 if (p_ctx->generate) {
443 printf(" /*%3d*/ { %d, \"%s\", %s, %d, %d, \"%s\",\n",
444 i, data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
445 testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
446 testUtilModulesPrint(symbol, " ", "\n");
447 printf(" },\n");
448 } else {
449 if (ret < ZINT_ERROR) {
450 int width, row;
451
452 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
453 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);
454
455 ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
456 assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
457
458 if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) {
459 ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf), NULL);
460 assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
461
462 ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected);
463 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
464 i, testUtilBarcodeName(symbol->symbology), ret, bwipp_msg, bwipp_buf, data[i].expected);
465 }
466 }
467 }
468
469 ZBarcode_Delete(symbol);
470 }
471
472 testFinish();
473 }
474
475 /* Dummy to generate pre-calculated tables for channels 7/8 */
476 static void test_generate(const testCtx *const p_ctx) {
477
478 struct item {
479 char *data;
480 };
481 static const struct item data[] = { { "576688" }, { "7742862" } };
482 const int data_size = ARRAY_SIZE(data);
483 int i, length, ret;
484 struct zint_symbol *symbol;
485
486 if (!p_ctx->generate) {
487 return;
488 }
489
490 for (i = 0; i < data_size; i++) {
491 symbol = ZBarcode_Create();
492 assert_nonnull(symbol, "Symbol not created\n");
493
494 length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, 0);
495
496 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
497 assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
498
499 ZBarcode_Delete(symbol);
500 }
501 }
502
503 int main(int argc, char *argv[]) {
504
505 testFunction funcs[] = { /* name, func */
506 { "test_hrt", test_hrt },
507 { "test_input", test_input },
508 { "test_encode", test_encode },
509 { "test_generate", test_generate },
510 };
511
512 testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
513
514 testReport();
515
516 return 0;
517 }
518
519 /* vim: set ts=4 sw=4 et : */