comparison mupdf-source/thirdparty/zint/backend/tests/test_dxfilmedge.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) 2024 Antoine Merino <antoine.merino.dev@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_encode(const testCtx *const p_ctx) {
35 int debug = p_ctx->debug;
36
37 struct item {
38 int symbology;
39 int option_2;
40 char *data;
41 int ret;
42
43 int expected_rows;
44 int expected_width;
45 char *comment;
46 char *expected;
47 };
48 static const struct item data[] = {
49 /* 0*/ { BARCODE_DXFILMEDGE, -1, "79-7", 0, 2, 23, "DX code 1: 79, DX code 2: 7. DX Extract = 1271. DX Full: X1271X (X is any digit)",
50 "1111101010101010101011110101010011110011100101"
51 },
52 /* 1*/ { BARCODE_DXFILMEDGE, -1, "1271", 0, 2, 23, "",
53 "1111101010101010101011110101010011110011100101"
54 },
55 /* 2*/ { BARCODE_DXFILMEDGE, -1, "012710", 0, 2, 23, "",
56 "1111101010101010101011110101010011110011100101"
57 },
58 /* 3*/ { BARCODE_DXFILMEDGE, -1, "112712", 0, 2, 23, "",
59 "1111101010101010101011110101010011110011100101"
60 },
61 /* 4*/ { BARCODE_DXFILMEDGE, -1, "1-0", 0, 2, 23, "Lower limit: DX part 1 = 1, DX part 2 = 0",
62 "1111101010101010101011110101000000010000010101"
63 },
64 /* 5*/ { BARCODE_DXFILMEDGE, -1, "000160", 0, 2, 23, "",
65 "1111101010101010101011110101000000010000010101"
66 },
67 /* 6*/ { BARCODE_DXFILMEDGE, -1, "16", 0, 2, 23, "",
68 "1111101010101010101011110101000000010000010101"
69 },
70 /* 7*/ { BARCODE_DXFILMEDGE, -1, "920479/63A", 0, 2, 31, "Upper limit: DX part 1 = 127, DX part 2 = 15",
71 "11111010101010101010101010101111010101111111011111111111000101"
72 },
73 /* 8*/ { BARCODE_DXFILMEDGE, -1, "127-15/00A", 0, 2, 31, "",
74 "11111010101010101010101010101111010101111111011111111111000101"
75 },
76 /* 9*/ { BARCODE_DXFILMEDGE, -1, "79-7/1", 0, 2, 31, "",
77 "11111010101010101010101010101111010101001111001110000010010101"
78 },
79 /* 10*/ { BARCODE_DXFILMEDGE, -1, "0079-7/001", 0, 2, 31, "Optional behaviour: leading zeros are accepted",
80 "11111010101010101010101010101111010101001111001110000010010101"
81 },
82 /* 11*/ { BARCODE_DXFILMEDGE, -1, "79-7/1", 0, 2, 31, "Frame number",
83 "11111010101010101010101010101111010101001111001110000010010101"
84 },
85 /* 12*/ { BARCODE_DXFILMEDGE, -1, "1271/1", 0, 2, 31, "",
86 "11111010101010101010101010101111010101001111001110000010010101"
87 },
88 /* 13*/ { BARCODE_DXFILMEDGE, -1, "912718/1", 0, 2, 31, "",
89 "11111010101010101010101010101111010101001111001110000010010101"
90 },
91 /* 14*/ { BARCODE_DXFILMEDGE, -1, "79-7/1A", 0, 2, 31, "",
92 "11111010101010101010101010101111010101001111001110000011000101"
93 },
94 /* 15*/ { BARCODE_DXFILMEDGE, -1, "1271/1a", 0, 2, 31, "",
95 "11111010101010101010101010101111010101001111001110000011000101"
96 },
97 /* 16*/ { BARCODE_DXFILMEDGE, -1, "212715/1A", 0, 2, 31, "",
98 "11111010101010101010101010101111010101001111001110000011000101"
99 },
100 /* 17*/ { BARCODE_DXFILMEDGE, -1, "79-7/62", 0, 2, 31, "Special frame numbers",
101 "11111010101010101010101010101111010101001111001111111100010101"
102 },
103 /* 18*/ { BARCODE_DXFILMEDGE, -1, "79-7/S", 0, 2, 31, "",
104 "11111010101010101010101010101111010101001111001111111100010101"
105 },
106 /* 19*/ { BARCODE_DXFILMEDGE, -1, "79-7/x", 0, 2, 31, "",
107 "11111010101010101010101010101111010101001111001111111100010101"
108 },
109 /* 20*/ { BARCODE_DXFILMEDGE, -1, "79-7/62a", 0, 2, 31, "",
110 "11111010101010101010101010101111010101001111001111111101000101"
111 },
112 /* 21*/ { BARCODE_DXFILMEDGE, -1, "79-7/sA", 0, 2, 31, "",
113 "11111010101010101010101010101111010101001111001111111101000101"
114 },
115 /* 22*/ { BARCODE_DXFILMEDGE, -1, "79-7/Xa", 0, 2, 31, "",
116 "11111010101010101010101010101111010101001111001111111101000101"
117 },
118 /* 23*/ { BARCODE_DXFILMEDGE, -1, "79-7/63", 0, 2, 31, "",
119 "11111010101010101010101010101111010101001111001111111110000101"
120 },
121 /* 24*/ { BARCODE_DXFILMEDGE, -1, "79-7/k", 0, 2, 31, "",
122 "11111010101010101010101010101111010101001111001111111110000101"
123 },
124 /* 25*/ { BARCODE_DXFILMEDGE, -1, "79-7/00", 0, 2, 31, "",
125 "11111010101010101010101010101111010101001111001111111110000101"
126 },
127 /* 26*/ { BARCODE_DXFILMEDGE, -1, "79-7/63a", 0, 2, 31, "",
128 "11111010101010101010101010101111010101001111001111111111010101"
129 },
130 /* 27*/ { BARCODE_DXFILMEDGE, -1, "79-7/kA", 0, 2, 31, "",
131 "11111010101010101010101010101111010101001111001111111111010101"
132 },
133 /* 28*/ { BARCODE_DXFILMEDGE, -1, "79-7/00a", 0, 2, 31, "",
134 "11111010101010101010101010101111010101001111001111111111010101"
135 },
136 /* 29*/ { BARCODE_DXFILMEDGE, -1, "79-7/0", 0, 2, 31, "",
137 "11111010101010101010101010101111010101001111001110000000000101"
138 },
139 /* 30*/ { BARCODE_DXFILMEDGE, -1, "79-7/F", 0, 2, 31, "",
140 "11111010101010101010101010101111010101001111001110000000000101"
141 },
142 /* 31*/ { BARCODE_DXFILMEDGE, -1, "79-7/0a", 0, 2, 31, "",
143 "11111010101010101010101010101111010101001111001110000001010101"
144 },
145 /* 32*/ { BARCODE_DXFILMEDGE, -1, "79-7/fA", 0, 2, 31, "",
146 "11111010101010101010101010101111010101001111001110000001010101"
147 },
148 };
149 const int data_size = ARRAY_SIZE(data);
150 int i, length, ret;
151 struct zint_symbol *symbol = NULL;
152
153 char escaped[1024];
154 char cmp_buf[4096];
155 char cmp_msg[1024];
156
157 int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
158
159 testStartSymbol("test_encode", &symbol);
160
161 for (i = 0; i < data_size; i++) {
162
163 if (testContinue(p_ctx, i)) continue;
164
165 symbol = ZBarcode_Create();
166 assert_nonnull(symbol, "Symbol not created\n");
167
168 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
169
170 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
171 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
172
173 if (p_ctx->generate) {
174 printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n",
175 i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
176 testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
177 testUtilModulesPrint(symbol, " ", "\n");
178 printf(" },\n");
179 } else {
180 if (ret < ZINT_ERROR) {
181 int width, row;
182
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 ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
187 assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
188
189 if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
190 int cmp_len, ret_len;
191 char modules_dump[8192 + 1];
192 assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
193 ret = testUtilZXingCPP(i, symbol, data[i].data, length, modules_dump, cmp_buf, sizeof(cmp_buf), &cmp_len);
194 assert_zero(ret, "i:%d %s testUtilZXingCPP ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
195
196 ret = testUtilZXingCPPCmp(symbol, cmp_msg, cmp_buf, cmp_len, data[i].data, length, NULL /*primary*/, escaped, &ret_len);
197 assert_zero(ret, "i:%d %s testUtilZXingCPPCmp %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
198 i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf, ret_len, escaped);
199 }
200 }
201 }
202
203 ZBarcode_Delete(symbol);
204 }
205
206 testFinish();
207 }
208
209 static void test_input(const testCtx *const p_ctx) {
210 int debug = p_ctx->debug;
211
212 struct item {
213 int symbology;
214 int input_mode;
215 char *data;
216 int ret;
217 int expected_rows;
218 int expected_width;
219 char *expected_errtxt;
220 };
221 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
222 static const struct item data[] = {
223 /* 0*/ { BARCODE_DXFILMEDGE, -1, "79-1/123A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 972: Frame number part length 4 too long (maximum 3)" },
224 /* 1*/ { BARCODE_DXFILMEDGE, -1, "79-1/1@A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 973: Frame number \"1@A\" is invalid (expected digits, optionally followed by a single \"A\")" },
225 /* 2*/ { BARCODE_DXFILMEDGE, -1, "012312365", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 974: DX information length 9 too long (maximum 6)" },
226 /* 3*/ { BARCODE_DXFILMEDGE, -1, "12-", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 977: Wrong format for DX parts 1 and 2 (expected format: XXX-XX, digits)" },
227 /* 4*/ { BARCODE_DXFILMEDGE, -1, "01234/00A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 980: DX number \"01234\" is incorrect; expected 4 digits (DX extract) or 6 digits (DX full)" },
228 /* 5*/ { BARCODE_DXFILMEDGE, -1, "0123/0AA", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 983: Frame number \"0AA\" is invalid (expected digits, optionally followed by a single \"A\")" },
229 /* 6*/ { BARCODE_DXFILMEDGE, -1, "128-0/24", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 978: DX part 1 \"128\" out of range (1 to 127)" },
230 /* 7*/ { BARCODE_DXFILMEDGE, -1, "127-16", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 979: DX part 2 \"16\" out of range (0 to 15)" },
231 /* 8*/ { BARCODE_DXFILMEDGE, -1, "79-2/A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 983: Frame number \"A\" is invalid (expected digits, optionally followed by a single \"A\")" },
232 /* 9*/ { BARCODE_DXFILMEDGE, -1, "79-2/-1", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 984: Frame number \"-1\" out of range (0 to 63)" },
233 /* 10*/ { BARCODE_DXFILMEDGE, -1, "79-2/64", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 984: Frame number \"64\" out of range (0 to 63)" },
234 /* 11*/ { BARCODE_DXFILMEDGE, -1, "79-2-1", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 976: The \"-\" is used to separate DX parts 1 and 2, and should be used no more than once" },
235 /* 12*/ { BARCODE_DXFILMEDGE, -1, "110-2/2B", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 985: Frame number \"2B\" is invalid (expected digits, optionally followed by a single \"A\")" },
236 /* 13*/ { BARCODE_DXFILMEDGE, -1, "099990/123A", ZINT_ERROR_TOO_LONG, -1, -1, "Error 986: Input length 11 too long (maximum 10)" },
237 /* 14*/ { BARCODE_DXFILMEDGE, -1, "0123123/1", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 971: DX information length 7 too long (maximum 6)" },
238 /* 15*/ { BARCODE_DXFILMEDGE, -1, "120481", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 981: DX extract \"2048\" out of range (16 to 2047)" },
239 /* 16*/ { BARCODE_DXFILMEDGE, -1, "100151", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 981: DX extract \"15\" out of range (16 to 2047)" },
240 /* 17*/ { BARCODE_DXFILMEDGE, -1, "15", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 981: DX extract \"15\" out of range (16 to 2047)" },
241 /* 18*/ { BARCODE_DXFILMEDGE, -1, "12-12A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 975: Invalid character at position 6 in DX info (digits and \"-\" character only)" },
242 /* 19*/ { BARCODE_DXFILMEDGE, -1, "012X", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 975: Invalid character at position 4 in DX info (digits and \"-\" character only)" },
243 /* 20*/ { BARCODE_DXFILMEDGE, -1, "110-2/", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 982: Frame number indicator \"/\" at position 6, but frame number is empty" },
244 /* 21*/ { BARCODE_DXFILMEDGE, -1, "/", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 970: Invalid first character \"/\", DX code should start with a number" },
245 /* 22*/ { BARCODE_DXFILMEDGE, -1, "-12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 970: Invalid first character \"-\", DX code should start with a number" },
246 /* 23*/ { BARCODE_DXFILMEDGE, -1, "X1234X", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 970: Invalid first character \"X\", DX code should start with a number" },
247 };
248 const int data_size = ARRAY_SIZE(data);
249 int i, length, ret;
250 struct zint_symbol *symbol = NULL;
251
252 testStartSymbol("test_input", &symbol);
253
254 for (i = 0; i < data_size; i++) {
255
256 if (testContinue(p_ctx, i)) continue;
257
258 symbol = ZBarcode_Create();
259 assert_nonnull(symbol, "Symbol not created\n");
260
261 length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, -1 /*output_options*/, data[i].data, -1, debug);
262
263 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
264 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
265 assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt);
266 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
267
268 if (ret < ZINT_ERROR) {
269 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
270 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
271 }
272
273 ZBarcode_Delete(symbol);
274 }
275
276 testFinish();
277 }
278
279 int main(int argc, char *argv[]) {
280
281 testFunction funcs[] = { /* name, func */
282 { "test_input", test_input },
283 { "test_encode", test_encode },
284 };
285
286 testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
287
288 testReport();
289
290 return 0;
291 }
292
293 /* vim: set ts=4 sw=4 et : */