wxMaxima
Loading...
Searching...
No Matches
testcommon.h
1/*
2 libzint - the open source barcode library
3 Copyright (C) 2019-2026 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/*
31 * Adapted from qrencode/tests/common.h
32 * Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
33 */
34/* Due to above: */
35/* SPDX-License-Identifier: LGPL-2.1+ */
36
37#ifndef Z_TESTCOMMON_H
38#define Z_TESTCOMMON_H
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44#define ZINT_DEBUG_TEST_PRINT 16
45#define ZINT_DEBUG_TEST_LESS_NOISY 32
46#define ZINT_DEBUG_TEST_KEEP_OUTFILE 64
47#define ZINT_DEBUG_TEST_BWIPP 128
48#define ZINT_DEBUG_TEST_PERFORMANCE 256
49#define ZINT_DEBUG_TEST_ZXINGCPP 512
50#define ZINT_DEBUG_TEST_BWIPP_ZXINGCPP 1024
51#define ZINT_DEBUG_TEST_AZTEC_SKIP_ALL 2048
52
53#ifdef ZINT_SANITIZEM /* Suppress clang -fsanitize=memory false positives */
54#define ZINT_TESTUTIL_SANITIZEM_INIT = {0}
55#define ZINT_TESTUTIL_SANITIZEM_INIT_2D = {{0}}
56#else
57#define ZINT_TESTUTIL_SANITIZEM_INIT
58#define ZINT_TESTUTIL_SANITIZEM_INIT_2D
59#endif
60
61/* Hack `option_3` flag to indicate GS1 Syntax Engine caret input */
62#define ZINT_TESTUTIL_GS1CARET (1 << 24)
63
64#include <errno.h>
65#include <stdio.h>
66#include "../common.h"
67
68#ifdef _MSC_VER
69#define testutil_popen(command, mode) _popen(command, mode)
70#define testutil_pclose(stream) _pclose(stream)
71#else
72#include <unistd.h>
73# ifndef _WIN32
74extern FILE *popen(const char *command, const char *type);
75extern int pclose(FILE *stream);
76# endif
77#define testutil_popen(command, mode) popen(command, mode)
78#define testutil_pclose(stream) pclose(stream)
79#endif
80
81#if defined(__GNUC__)
82# pragma GCC diagnostic ignored "-Woverlength-strings"
83#elif defined(_MSC_VER)
84# pragma warning(disable: 4305) /* truncation from 'double' to 'float' */
85# pragma warning(disable: 4702) /* unreachable code */
86#endif
87
88extern int testAssertFailed;
89extern int testAssertNum;
90extern struct zint_symbol **testAssertPPSymbol;
91extern const char *testAssertFilename;
92
93#if defined(_MSC_VER) && _MSC_VER < 1900 /* MSVC 2015 */
94#define testStart(name) (testStartReal("", name, NULL))
95#define testStartSymbol(name, pp_symbol) (testStartReal("", name, pp_symbol))
96#else
97#define testStart(name) (ZEXT testStartReal(__func__, name, NULL))
98#define testStartSymbol(name, pp_symbol) (ZEXT testStartReal(__func__, name, pp_symbol))
99#endif
100void testStartReal(const char *func, const char *name, struct zint_symbol **pp_symbol);
101void testFinish(void);
102void testSkip(const char *msg);
103void testReport(void);
104
105#define ZINT_TEST_CTX_EXC_MAX 32
106typedef struct s_testCtx {
107 const char *func_name;
108 int index;
109 int index_end;
110 int exclude[ZINT_TEST_CTX_EXC_MAX];
111 int exclude_end[ZINT_TEST_CTX_EXC_MAX];
112 int arg;
113 int generate;
114 int debug;
115} testCtx;
116typedef void (*testFunc_t)(const testCtx *const p_ctx);
117typedef struct s_testFunction {
118 const char *name; testFunc_t func;
120void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size);
121int testContinue(const testCtx *const p_ctx, const int i);
122
123#if (defined(_MSC_VER) &&_MSC_VER <= 1200) || defined(ZINT_IS_C89) /* VC6 or C89 */
124void assert_zero(int exp, const char *fmt, ...);
125void assert_nonzero(int exp, const char *fmt, ...);
126void assert_null(const void *exp, const char *fmt, ...);
127void assert_nonnull(const void *exp, const char *fmt, ...);
128void assert_equal(int e1, int e2, const char *fmt, ...);
129void assert_equalu64(uint64_t e1, uint64_t e2, const char *fmt, ...);
130void assert_notequal(int e1, int e2, const char *fmt, ...);
131#else
132#define assert_exp(exp, ...) \
133 { testAssertNum++; if (!(exp)) { testAssertFailed++; printf("%s:%d ", testAssertFilename, __LINE__); \
134 printf(__VA_ARGS__); testFinish(); \
135 if (testAssertPPSymbol) { ZBarcode_Delete(*testAssertPPSymbol); testAssertPPSymbol = NULL; } return; } }
136
137#define assert_zero(exp, ...) assert_exp((exp) == 0, __VA_ARGS__)
138#define assert_nonzero(exp, ...) assert_exp((exp) != 0, __VA_ARGS__)
139#define assert_null(ptr, ...) assert_exp((ptr) == NULL, __VA_ARGS__)
140#define assert_nonnull(ptr, ...) assert_exp((ptr) != NULL, __VA_ARGS__)
141#define assert_equal(e1, e2, ...) assert_exp((e1) == (e2), __VA_ARGS__)
142#define assert_equalu64 assert_equal
143#define assert_notequal(e1, e2, ...) assert_exp((e1) != (e2), __VA_ARGS__)
144#endif
145
146/* TODO: replace these with `ZUCP()`, `ZCUCP()` & `ZCCP()` resp. */
147#define TU(p) ((unsigned char *) (p))
148#define TCU(p) ((const unsigned char *) (p))
149#define TCC(p) ((const char *) (p))
150
151INTERNAL void vector_free(struct zint_symbol *symbol); /* Free vector structures */
152
153int testUtilSetSymbol(struct zint_symbol *symbol, int symbology, int input_mode, int eci,
154 int option_1, int option_2, int option_3, int output_options, const char *data, int length, int debug);
155
156const char *testUtilBarcodeName(int symbology);
157const char *testUtilErrorName(int error_number);
158const char *testUtilInputModeName(int input_mode);
159const char *testUtilOption3Name(int symbology, int option_3);
160const char *testUtilOutputOptionsName(int output_options);
161
162int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, const int buffer_size);
163int testUtilIsValidUTF8(const unsigned char str[], const int length);
164char *testUtilEscape(const char *buffer, const int length, char *escaped, const int escaped_size);
165const char *testUtilReadCSVField(const char *buffer, char *field, const int field_size);
166void testUtilStrCpyRepeat(char *buffer, const char *repeat, const int size);
167
168int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b);
169struct zint_vector *testUtilVectorCpy(const struct zint_vector *in);
170int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b);
171
172int testUtilModulesDump(const struct zint_symbol *symbol, char dump[], int dump_size);
173void testUtilModulesPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix);
174void testUtilModulesPrintRow(const struct zint_symbol *symbol, int row, const char *prefix, const char *postfix);
175int testUtilModulesCmp(const struct zint_symbol *symbol, const char *expected, int *width, int *row);
176int testUtilModulesCmpRow(const struct zint_symbol *symbol, int row, const char *expected, int *width);
177char *testUtilUIntArrayDump(const unsigned int *array, const int size, char *dump, const int dump_size);
178char *testUtilUCharArrayDump(const unsigned char *array, const int size, char *dump, const int dump_size);
179
180void testUtilBitmapPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix);
181int testUtilBitmapCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *column);
182
183void testUtilVectorPrint(const struct zint_symbol *symbol);
184
185int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const char *filename);
186FILE *testUtilOpen(const char *filename, const char *mode);
187int testUtilExists(const char *filename);
188int testUtilRemove(const char *filename);
189int testUtilDirExists(const char *dirname);
190int testUtilMkDir(const char *dirname);
191int testUtilRmDir(const char *dirname);
192int testUtilRename(const char *oldpath, const char *newpath);
193int testUtilCreateROFile(const char *filename);
194int testUtilRmROFile(const char *filename);
195int testUtilReadFile(const char *filename, unsigned char *buffer, int buffer_size, int *p_size);
196int testUtilWriteFile(const char *filename, const unsigned char *buffer, const int buffer_size, const char *mode);
197
198int testUtilCmpPngs(const char *file1, const char *file2);
199int testUtilCmpTxts(const char *txt1, const char *txt2);
200int testUtilCmpBins(const char *bin1, const char *bin2);
201int testUtilCmpSvgs(const char *svg1, const char *svg2);
202int testUtilCmpEpss(const char *eps1, const char *eps2);
203
204const char *testUtilHaveIdentify(void);
205int testUtilVerifyIdentify(const char *const prog, const char *filename, int debug);
206int testUtilHaveLibreOffice(void);
207int testUtilVerifyLibreOffice(const char *filename, int debug);
208int testUtilHaveGhostscript(void);
209int testUtilVerifyGhostscript(const char *filename, int debug);
210int testUtilHaveVnu(void);
211int testUtilVerifyVnu(const char *filename, int debug);
212int testUtilHaveTiffInfo(void);
213int testUtilVerifyTiffInfo(const char *filename, int debug);
214
215int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3,
216 int debug);
217int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3,
218 const char *data, int length, const char *primary, char *buffer, int buffer_size, const int *p_parsefnc);
219int testUtilBwippSegs(int index, struct zint_symbol *symbol, int option_1, int option_2, int option_3,
220 const struct zint_seg segs[], const int seg_count, const char *primary, char *buffer, int buffer_size);
221int testUtilBwippCmp(const struct zint_symbol *symbol, char *msg, char *cmp_buf, const char *expected);
222int testUtilBwippCmpRow(const struct zint_symbol *symbol, int row, char *msg, const char *cmp_buf,
223 const char *expected);
224
225int testUtilHaveZXingCPPDecoder(void);
226int testUtilCanZXingCPP(int index, const struct zint_symbol *symbol, const char *data, const int length,
227 const int debug);
228int testUtilZXingCPP(int index, struct zint_symbol *symbol, const char *source, const int length, const char *bits,
229 const int zxingcpp_cmp, char *buffer, const int buffer_size, int *p_cmp_len);
230int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, int cmp_len, const char *expected,
231 int expected_len, const char *primary, char *ret_buf, int *p_ret_len);
232int testUtilZXingCPPCmpSegs(struct zint_symbol *symbol, char *msg, char *cmp_buf, int cmp_len,
233 const struct zint_seg segs[], const int seg_count, const char *primary, char *ret_buf, int *p_ret_len);
234
235#ifdef __cplusplus
236}
237#endif
238
239/* vim: set ts=4 sw=4 et : */
240#endif /* Z_TESTCOMMON_H */
void func()
function in group 1
Definition: group.cpp:13
Definition: testcommon.h:106
Definition: testcommon.h:117
Definition: zint.h:101
Definition: zint.h:108
Definition: zint.h:85