comparison mupdf-source/thirdparty/zint/backend/tests/test_plessey.c @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /*
2 libzint - the open source barcode library
3 Copyright (C) 2020-2024 Robin Stuart <rstuart114@gmail.com>
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 3. Neither the name of the project nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 SUCH DAMAGE.
29 */
30 /* SPDX-License-Identifier: BSD-3-Clause */
31
32 #include "testcommon.h"
33
34 static void test_large(const testCtx *const p_ctx) {
35 int debug = p_ctx->debug;
36
37 struct item {
38 int symbology;
39 int option_2;
40 char *pattern;
41 int length;
42 int ret;
43 int expected_rows;
44 int expected_width;
45 char *expected_errtxt;
46 };
47 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
48 static const struct item data[] = {
49 /* 0*/ { BARCODE_MSI_PLESSEY, -1, "9", 92, 0, 1, 1111, "" },
50 /* 1*/ { BARCODE_MSI_PLESSEY, -1, "9", 93, ZINT_ERROR_TOO_LONG, -1, -1, "Error 372: Input length 93 too long (maximum 92)" },
51 /* 2*/ { BARCODE_MSI_PLESSEY, 1, "9", 92, 0, 1, 1123, "" }, /* 1 mod-10 check digit */
52 /* 3*/ { BARCODE_MSI_PLESSEY, 1, "9", 93, ZINT_ERROR_TOO_LONG, -1, -1, "Error 372: Input length 93 too long (maximum 92)" },
53 /* 4*/ { BARCODE_MSI_PLESSEY, 2, "9", 92, 0, 1, 1135, "" }, /* 2 mod-10 check digits */
54 /* 5*/ { BARCODE_MSI_PLESSEY, 2, "9", 93, ZINT_ERROR_TOO_LONG, -1, -1, "Error 372: Input length 93 too long (maximum 92)" },
55 /* 6*/ { BARCODE_MSI_PLESSEY, 3, "9", 92, 0, 1, 1123, "" }, /* 1 mod-11 check digit */
56 /* 7*/ { BARCODE_MSI_PLESSEY, 3, "9", 93, ZINT_ERROR_TOO_LONG, -1, -1, "Error 372: Input length 93 too long (maximum 92)" },
57 /* 8*/ { BARCODE_MSI_PLESSEY, 3, "4", 92, 0, 1, 1135, "" }, /* 1 mod-11 double check digit "10" */
58 /* 9*/ { BARCODE_MSI_PLESSEY, 3, "4", 93, ZINT_ERROR_TOO_LONG, -1, -1, "Error 372: Input length 93 too long (maximum 92)" },
59 /* 10*/ { BARCODE_MSI_PLESSEY, 4, "9", 92, 0, 1, 1135, "" }, /* 1 mod-11 and 1 mod-10 check digit */
60 /* 11*/ { BARCODE_MSI_PLESSEY, 4, "9", 93, ZINT_ERROR_TOO_LONG, -1, -1, "Error 372: Input length 93 too long (maximum 92)" },
61 /* 12*/ { BARCODE_MSI_PLESSEY, 4, "4", 92, 0, 1, 1147, "" }, /* 1 mod-11 double check digit "10" and 1 mod-10 check digit */
62 /* 13*/ { BARCODE_MSI_PLESSEY, 4, "4", 93, ZINT_ERROR_TOO_LONG, -1, -1, "Error 372: Input length 93 too long (maximum 92)" },
63 /* 14*/ { BARCODE_MSI_PLESSEY, 5, "9", 92, 0, 1, 1123, "" }, /* 1 NCR mod-11 check digit */
64 /* 15*/ { BARCODE_MSI_PLESSEY, 5, "9", 93, ZINT_ERROR_TOO_LONG, -1, -1, "Error 372: Input length 93 too long (maximum 92)" },
65 /* 16*/ { BARCODE_MSI_PLESSEY, 6, "9", 92, 0, 1, 1135, "" }, /* 1 NCR mod-11 and 1 mod-10 check digit */
66 /* 17*/ { BARCODE_MSI_PLESSEY, 6, "9", 93, ZINT_ERROR_TOO_LONG, -1, -1, "Error 372: Input length 93 too long (maximum 92)" },
67 /* 18*/ { BARCODE_PLESSEY, -1, "A", 67, 0, 1, 1139, "" },
68 /* 19*/ { BARCODE_PLESSEY, -1, "A", 68, ZINT_ERROR_TOO_LONG, -1, -1, "Error 370: Input length 68 too long (maximum 67)" },
69 };
70 const int data_size = ARRAY_SIZE(data);
71 int i, length, ret;
72 struct zint_symbol *symbol = NULL;
73
74 char data_buf[4096];
75
76 testStartSymbol("test_large", &symbol);
77
78 for (i = 0; i < data_size; i++) {
79
80 if (testContinue(p_ctx, i)) continue;
81
82 symbol = ZBarcode_Create();
83 assert_nonnull(symbol, "Symbol not created\n");
84
85 testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length);
86 assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf));
87
88 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug);
89
90 ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length);
91 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
92 assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt);
93 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
94
95 if (ret < ZINT_ERROR) {
96 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
97 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
98 }
99
100 ZBarcode_Delete(symbol);
101 }
102
103 testFinish();
104 }
105
106 static void test_hrt(const testCtx *const p_ctx) {
107 int debug = p_ctx->debug;
108
109 struct item {
110 int symbology;
111 int option_2;
112 char *data;
113
114 char *expected;
115 };
116 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
117 static const struct item data[] = {
118 /* 0*/ { BARCODE_MSI_PLESSEY, -1, "1234567", "1234567" },
119 /* 1*/ { BARCODE_MSI_PLESSEY, 0, "1234567", "1234567" },
120 /* 2*/ { BARCODE_MSI_PLESSEY, 1, "1234567", "12345674" },
121 /* 3*/ { BARCODE_MSI_PLESSEY, 1 + 10, "1234567", "1234567" },
122 /* 4*/ { BARCODE_MSI_PLESSEY, 1, "9999999999", "99999999990" },
123 /* 5*/ { BARCODE_MSI_PLESSEY, 2, "1234567", "123456741" },
124 /* 6*/ { BARCODE_MSI_PLESSEY, 2 + 10, "1234567", "1234567" },
125 /* 7*/ { BARCODE_MSI_PLESSEY, 2, "9999999999", "999999999900" },
126 /* 8*/ { BARCODE_MSI_PLESSEY, 3, "1234567", "12345674" },
127 /* 9*/ { BARCODE_MSI_PLESSEY, 3 + 10, "1234567", "1234567" },
128 /* 10*/ { BARCODE_MSI_PLESSEY, 3, "9999999999", "99999999995" },
129 /* 11*/ { BARCODE_MSI_PLESSEY, 4, "1234567", "123456741" },
130 /* 12*/ { BARCODE_MSI_PLESSEY, 4 + 10, "1234567", "1234567" },
131 /* 13*/ { BARCODE_MSI_PLESSEY, 4, "9999999999", "999999999959" },
132 /* 14*/ { BARCODE_MSI_PLESSEY, 5, "1234567", "12345679" },
133 /* 15*/ { BARCODE_MSI_PLESSEY, 5 + 10, "1234567", "1234567" },
134 /* 16*/ { BARCODE_MSI_PLESSEY, 5, "9999999999", "999999999910" },
135 /* 17*/ { BARCODE_MSI_PLESSEY, 6, "1234567", "123456790" },
136 /* 18*/ { BARCODE_MSI_PLESSEY, 6 + 10, "1234567", "1234567" },
137 /* 19*/ { BARCODE_MSI_PLESSEY, 6, "9999999999", "9999999999109" },
138 /* 20*/ { BARCODE_MSI_PLESSEY, 1, "123456", "1234566" },
139 /* 21*/ { BARCODE_MSI_PLESSEY, 2, "123456", "12345666" },
140 /* 22*/ { BARCODE_MSI_PLESSEY, 3, "123456", "1234560" },
141 /* 23*/ { BARCODE_MSI_PLESSEY, 4, "123456", "12345609" },
142 /* 24*/ { BARCODE_MSI_PLESSEY, 3, "2211", "221110" }, /* Mod-11 check digit '10' */
143 /* 25*/ { BARCODE_MSI_PLESSEY, 3 + 10, "2211", "2211" }, /* Mod-11 check digit '10' */
144 /* 26*/ { BARCODE_MSI_PLESSEY, 4, "2211", "2211100" },
145 /* 27*/ { BARCODE_MSI_PLESSEY, 4 + 10, "2211", "2211" },
146 /* 28*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", "0123456789ABCDEF" },
147 };
148 const int data_size = ARRAY_SIZE(data);
149 int i, length, ret;
150 struct zint_symbol *symbol = NULL;
151
152 testStartSymbol("test_hrt", &symbol);
153
154 for (i = 0; i < data_size; i++) {
155
156 if (testContinue(p_ctx, i)) continue;
157
158 symbol = ZBarcode_Create();
159 assert_nonnull(symbol, "Symbol not created\n");
160
161 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);
162
163 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
164 assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt);
165
166 assert_zero(strcmp((char *) symbol->text, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->text, data[i].expected);
167
168 ZBarcode_Delete(symbol);
169 }
170
171 testFinish();
172 }
173
174 static void test_input(const testCtx *const p_ctx) {
175 int debug = p_ctx->debug;
176
177 struct item {
178 int symbology;
179 int option_2;
180 char *data;
181 int ret;
182 int expected_rows;
183 int expected_width;
184 char *expected_errtxt;
185 };
186 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
187 static const struct item data[] = {
188 /* 0*/ { BARCODE_MSI_PLESSEY, -1, "1", 0, 1, 19, "" },
189 /* 1*/ { BARCODE_MSI_PLESSEY, -1, "A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 377: Invalid character at position 1 in input (digits only)" },
190 /* 2*/ { BARCODE_MSI_PLESSEY, -2, "1", 0, 1, 19, "" }, /* < 0 ignored */
191 /* 3*/ { BARCODE_MSI_PLESSEY, 7, "1", 0, 1, 19, "" }, /* > 6 ignored */
192 /* 4*/ { BARCODE_PLESSEY, -1, "A", 0, 1, 83, "" },
193 /* 5*/ { BARCODE_PLESSEY, -1, "G", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 371: Invalid character at position 1 in input (digits and \"ABCDEF\" only)" },
194 };
195 const int data_size = ARRAY_SIZE(data);
196 int i, length, ret;
197 struct zint_symbol *symbol = NULL;
198
199 testStartSymbol("test_input", &symbol);
200
201 for (i = 0; i < data_size; i++) {
202
203 if (testContinue(p_ctx, i)) continue;
204
205 symbol = ZBarcode_Create();
206 assert_nonnull(symbol, "Symbol not created\n");
207
208 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);
209
210 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
211 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
212 assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
213 assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt);
214
215 if (ret < ZINT_ERROR) {
216 assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
217 assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
218 }
219
220 ZBarcode_Delete(symbol);
221 }
222
223 testFinish();
224 }
225
226 static void test_encode(const testCtx *const p_ctx) {
227 int debug = p_ctx->debug;
228
229 struct item {
230 int symbology;
231 int option_2;
232 char *data;
233 int ret;
234
235 int expected_rows;
236 int expected_width;
237 char *comment;
238 char *expected;
239 };
240 static const struct item data[] = {
241 /* 0*/ { BARCODE_MSI_PLESSEY, -1, "1234567890", 0, 1, 127, "Verified manually against tec-it",
242 "1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001"
243 },
244 /* 1*/ { BARCODE_MSI_PLESSEY, 1, "1234567890", 0, 1, 139, "Verified manually against tec-it",
245 "1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001101101001"
246 },
247 /* 2*/ { BARCODE_MSI_PLESSEY, 2, "1234567890", 0, 1, 151, "Verified manually against tec-it",
248 "1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001101101001001001101001"
249 },
250 /* 3*/ { BARCODE_MSI_PLESSEY, 3, "1234567890", 0, 1, 139, "",
251 "1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001101101001"
252 },
253 /* 4*/ { BARCODE_MSI_PLESSEY, 4, "1234567890", 0, 1, 151, "",
254 "1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001101101001001001101001"
255 },
256 /* 5*/ { BARCODE_MSI_PLESSEY, 5, "1234567890", 0, 1, 139, "",
257 "1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001001001001"
258 },
259 /* 6*/ { BARCODE_MSI_PLESSEY, 6, "1234567890", 0, 1, 151, "",
260 "1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001001001001101101101001"
261 },
262 /* 7*/ { BARCODE_MSI_PLESSEY, 3, "2211", 0, 1, 79, "Produces mod-11 '10' check digit; BWIPP (badmod11)",
263 "1101001001101001001001101001001001001101001001001101001001001101001001001001001"
264 },
265 /* 8*/ { BARCODE_MSI_PLESSEY, 4, "2211", 0, 1, 91, "BWIPP (badmod11)",
266 "1101001001101001001001101001001001001101001001001101001001001101001001001001001001001001001"
267 },
268 /* 9*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", 0, 1, 323, "",
269 "11101110100011101000100010001000111010001000100010001110100010001110111010001000100010001110100011101000111010001000111011101000111011101110100010001000100011101110100010001110100011101000111011101110100011101000100011101110111010001110111010001110111011101110111011101110111010001000111010001000100010001110001000101110111"
270 },
271 /* 10*/ { BARCODE_MSI_PLESSEY, 4, "999999999999999999", 0, 1, 247, "Max value (previously); #209 check buffer not overrun",
272 "1101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001001001001001101001"
273 },
274 };
275 const int data_size = ARRAY_SIZE(data);
276 int i, length, ret;
277 struct zint_symbol *symbol = NULL;
278
279 char escaped[1024];
280 char bwipp_buf[4096];
281 char bwipp_msg[1024];
282
283 int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
284
285 testStartSymbol("test_encode", &symbol);
286
287 for (i = 0; i < data_size; i++) {
288
289 if (testContinue(p_ctx, i)) continue;
290
291 symbol = ZBarcode_Create();
292 assert_nonnull(symbol, "Symbol not created\n");
293
294 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);
295
296 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
297 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
298
299 if (p_ctx->generate) {
300 printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n",
301 i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
302 testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
303 testUtilModulesPrint(symbol, " ", "\n");
304 printf(" },\n");
305 } else {
306 if (ret < ZINT_ERROR) {
307 int width, row;
308
309 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);
310 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);
311
312 ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
313 assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
314
315 if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) {
316 ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf), NULL);
317 assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
318
319 ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected);
320 assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
321 i, testUtilBarcodeName(symbol->symbology), ret, bwipp_msg, bwipp_buf, data[i].expected);
322 }
323 }
324 }
325
326 ZBarcode_Delete(symbol);
327 }
328
329 testFinish();
330 }
331
332 #include <time.h>
333
334 #define TEST_PERF_ITER_MILLES 5
335 #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
336 #define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC)
337
338 /* Not a real test, just performance indicator */
339 static void test_perf(const testCtx *const p_ctx) {
340 int debug = p_ctx->debug;
341
342 struct item {
343 int symbology;
344 int option_2;
345 char *data;
346 int ret;
347
348 int expected_rows;
349 int expected_width;
350 char *comment;
351 };
352 static const struct item data[] = {
353 /* 0*/ { BARCODE_PLESSEY, -1, "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1", 0, 1, 1107, "PLESSEY 65" },
354 /* 1*/ { BARCODE_PLESSEY, -1, "123456ABCD", 0, 1, 227, "PLESSEY 10" },
355 /* 2*/ { BARCODE_MSI_PLESSEY, -1, "12345678901234567890123456789012345678901234567890123456789012345", 0, 1, 787, "MSI_PLESSEY 65" },
356 /* 3*/ { BARCODE_MSI_PLESSEY, -1, "1234567890", 0, 1, 127, "MSI_PLESSEY 10" },
357 };
358 const int data_size = ARRAY_SIZE(data);
359 int i, length, ret;
360 struct zint_symbol *symbol;
361
362 clock_t start;
363 clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
364 clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print;
365 int comment_max = 0;
366
367 if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
368 return;
369 }
370
371 for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
372
373 printf("Iterations %d\n", TEST_PERF_ITERATIONS);
374
375 for (i = 0; i < data_size; i++) {
376 int j;
377
378 if (testContinue(p_ctx, i)) continue;
379
380 diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
381
382 for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
383 start = clock();
384 symbol = ZBarcode_Create();
385 diff_create += clock() - start;
386 assert_nonnull(symbol, "Symbol not created\n");
387
388 length = testUtilSetSymbol(symbol, data[i].symbology, DATA_MODE, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
389
390 start = clock();
391 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
392 diff_encode += clock() - start;
393 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
394
395 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);
396 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);
397
398 start = clock();
399 ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
400 diff_buffer += clock() - start;
401 assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
402
403 symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
404 start = clock();
405 ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
406 diff_buf_inter += clock() - start;
407 assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
408 symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
409
410 start = clock();
411 ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
412 diff_print += clock() - start;
413 assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
414 assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
415
416 ZBarcode_Delete(symbol);
417 }
418
419 printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, data[i].comment,
420 TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter), TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
421
422 total_create += diff_create;
423 total_encode += diff_encode;
424 total_buffer += diff_buffer;
425 total_buf_inter += diff_buf_inter;
426 total_print += diff_print;
427 }
428 if (p_ctx->index == -1) {
429 printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
430 TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
431 }
432 }
433
434 int main(int argc, char *argv[]) {
435
436 testFunction funcs[] = { /* name, func */
437 { "test_large", test_large },
438 { "test_hrt", test_hrt },
439 { "test_input", test_input },
440 { "test_encode", test_encode },
441 { "test_perf", test_perf },
442 };
443
444 testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
445
446 testReport();
447
448 return 0;
449 }
450
451 /* vim: set ts=4 sw=4 et : */