Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tests/testcommon.h @ 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 /* | |
| 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 | |
| 41 extern "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 | |
| 51 #include <errno.h> | |
| 52 #include <stdio.h> | |
| 53 #include "../common.h" | |
| 54 | |
| 55 #ifdef _MSC_VER | |
| 56 #define testutil_popen(command, mode) _popen(command, mode) | |
| 57 #define testutil_pclose(stream) _pclose(stream) | |
| 58 #else | |
| 59 #include <unistd.h> | |
| 60 extern FILE *popen(const char *command, const char *type); | |
| 61 extern int pclose(FILE *stream); | |
| 62 #define testutil_popen(command, mode) popen(command, mode) | |
| 63 #define testutil_pclose(stream) pclose(stream) | |
| 64 #endif | |
| 65 | |
| 66 #if defined(__GNUC__) | |
| 67 # pragma GCC diagnostic ignored "-Wpedantic" | |
| 68 # pragma GCC diagnostic ignored "-Woverlength-strings" | |
| 69 #elif defined(_MSC_VER) | |
| 70 # pragma warning(disable: 4305) /* truncation from 'double' to 'float' */ | |
| 71 # pragma warning(disable: 4702) /* unreachable code */ | |
| 72 #endif | |
| 73 | |
| 74 extern int testAssertFailed; | |
| 75 extern int testAssertNum; | |
| 76 extern struct zint_symbol **testAssertPPSymbol; | |
| 77 extern const char *testAssertFilename; | |
| 78 | |
| 79 #if defined(_MSC_VER) && _MSC_VER < 1900 /* MSVC 2015 */ | |
| 80 #define testStart(name) (testStartReal("", name, NULL)) | |
| 81 #define testStartSymbol(name, pp_symbol) (testStartReal("", name, pp_symbol)) | |
| 82 #else | |
| 83 #define testStart(name) (testStartReal(__func__, name, NULL)) | |
| 84 #define testStartSymbol(name, pp_symbol) (testStartReal(__func__, name, pp_symbol)) | |
| 85 #endif | |
| 86 void testStartReal(const char *func, const char *name, struct zint_symbol **pp_symbol); | |
| 87 void testFinish(void); | |
| 88 void testSkip(const char *msg); | |
| 89 void testReport(void); | |
| 90 | |
| 91 #define ZINT_TEST_CTX_EXC_MAX 32 | |
| 92 typedef struct s_testCtx { | |
| 93 int index; | |
| 94 int index_end; | |
| 95 int exclude[ZINT_TEST_CTX_EXC_MAX]; | |
| 96 int exclude_end[ZINT_TEST_CTX_EXC_MAX]; | |
| 97 int generate; | |
| 98 int debug; | |
| 99 } testCtx; | |
| 100 typedef void (*testFunc_t)(const testCtx *const p_ctx); | |
| 101 typedef struct s_testFunction { | |
| 102 const char *name; testFunc_t func; | |
| 103 } testFunction; | |
| 104 void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size); | |
| 105 int testContinue(const testCtx *const p_ctx, const int i); | |
| 106 | |
| 107 #if (defined(_MSC_VER) &&_MSC_VER <= 1200) || defined(ZINT_IS_C89) /* VC6 or C89 */ | |
| 108 void assert_zero(int exp, const char *fmt, ...); | |
| 109 void assert_nonzero(int exp, const char *fmt, ...); | |
| 110 void assert_null(const void *exp, const char *fmt, ...); | |
| 111 void assert_nonnull(const void *exp, const char *fmt, ...); | |
| 112 void assert_equal(int e1, int e2, const char *fmt, ...); | |
| 113 void assert_equalu64(uint64_t e1, uint64_t e2, const char *fmt, ...); | |
| 114 void assert_notequal(int e1, int e2, const char *fmt, ...); | |
| 115 #else | |
| 116 #define assert_exp(exp, ...) \ | |
| 117 { testAssertNum++; if (!(exp)) { testAssertFailed++; printf("%s:%d ", testAssertFilename, __LINE__); \ | |
| 118 printf(__VA_ARGS__); testFinish(); \ | |
| 119 if (testAssertPPSymbol) { ZBarcode_Delete(*testAssertPPSymbol); testAssertPPSymbol = NULL; } return; } } | |
| 120 | |
| 121 #define assert_zero(exp, ...) assert_exp((exp) == 0, __VA_ARGS__) | |
| 122 #define assert_nonzero(exp, ...) assert_exp((exp) != 0, __VA_ARGS__) | |
| 123 #define assert_null(ptr, ...) assert_exp((ptr) == NULL, __VA_ARGS__) | |
| 124 #define assert_nonnull(ptr, ...) assert_exp((ptr) != NULL, __VA_ARGS__) | |
| 125 #define assert_equal(e1, e2, ...) assert_exp((e1) == (e2), __VA_ARGS__) | |
| 126 #define assert_equalu64 assert_equal | |
| 127 #define assert_notequal(e1, e2, ...) assert_exp((e1) != (e2), __VA_ARGS__) | |
| 128 #endif | |
| 129 | |
| 130 #define TU(p) ((unsigned char *) (p)) | |
| 131 | |
| 132 INTERNAL void vector_free(struct zint_symbol *symbol); /* Free vector structures */ | |
| 133 | |
| 134 int testUtilSetSymbol(struct zint_symbol *symbol, int symbology, int input_mode, int eci, | |
| 135 int option_1, int option_2, int option_3, int output_options, const char *data, int length, int debug); | |
| 136 | |
| 137 const char *testUtilBarcodeName(int symbology); | |
| 138 const char *testUtilErrorName(int error_number); | |
| 139 const char *testUtilInputModeName(int input_mode); | |
| 140 const char *testUtilOption3Name(int symbology, int option_3); | |
| 141 const char *testUtilOutputOptionsName(int output_options); | |
| 142 | |
| 143 int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, const int buffer_size); | |
| 144 int testUtilIsValidUTF8(const unsigned char str[], const int length); | |
| 145 char *testUtilEscape(const char *buffer, const int length, char *escaped, const int escaped_size); | |
| 146 const char *testUtilReadCSVField(const char *buffer, char *field, const int field_size); | |
| 147 void testUtilStrCpyRepeat(char *buffer, const char *repeat, const int size); | |
| 148 | |
| 149 int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b); | |
| 150 struct zint_vector *testUtilVectorCpy(const struct zint_vector *in); | |
| 151 int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b); | |
| 152 | |
| 153 int testUtilModulesDump(const struct zint_symbol *symbol, char dump[], int dump_size); | |
| 154 void testUtilModulesPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix); | |
| 155 void testUtilModulesPrintRow(const struct zint_symbol *symbol, int row, const char *prefix, const char *postfix); | |
| 156 int testUtilModulesCmp(const struct zint_symbol *symbol, const char *expected, int *width, int *row); | |
| 157 int testUtilModulesCmpRow(const struct zint_symbol *symbol, int row, const char *expected, int *width); | |
| 158 char *testUtilUIntArrayDump(unsigned int *array, int size, char *dump, int dump_size); | |
| 159 char *testUtilUCharArrayDump(unsigned char *array, int size, char *dump, int dump_size); | |
| 160 | |
| 161 void testUtilBitmapPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix); | |
| 162 int testUtilBitmapCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *column); | |
| 163 | |
| 164 void testUtilVectorPrint(const struct zint_symbol *symbol); | |
| 165 | |
| 166 int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const char *filename); | |
| 167 FILE *testUtilOpen(const char *filename, const char *mode); | |
| 168 int testUtilExists(const char *filename); | |
| 169 int testUtilRemove(const char *filename); | |
| 170 int testUtilDirExists(const char *dirname); | |
| 171 int testUtilMkDir(const char *dirname); | |
| 172 int testUtilRmDir(const char *dirname); | |
| 173 int testUtilRename(const char *oldpath, const char *newpath); | |
| 174 int testUtilCreateROFile(const char *filename); | |
| 175 int testUtilRmROFile(const char *filename); | |
| 176 int testUtilReadFile(const char *filename, unsigned char *buffer, int buffer_size, int *p_size); | |
| 177 int testUtilWriteFile(const char *filename, const unsigned char *buffer, const int buffer_size, const char *mode); | |
| 178 | |
| 179 int testUtilCmpPngs(const char *file1, const char *file2); | |
| 180 int testUtilCmpTxts(const char *txt1, const char *txt2); | |
| 181 int testUtilCmpBins(const char *bin1, const char *bin2); | |
| 182 int testUtilCmpSvgs(const char *svg1, const char *svg2); | |
| 183 int testUtilCmpEpss(const char *eps1, const char *eps2); | |
| 184 | |
| 185 const char *testUtilHaveIdentify(void); | |
| 186 int testUtilVerifyIdentify(const char *const prog, const char *filename, int debug); | |
| 187 int testUtilHaveLibreOffice(void); | |
| 188 int testUtilVerifyLibreOffice(const char *filename, int debug); | |
| 189 int testUtilHaveGhostscript(void); | |
| 190 int testUtilVerifyGhostscript(const char *filename, int debug); | |
| 191 int testUtilHaveVnu(void); | |
| 192 int testUtilVerifyVnu(const char *filename, int debug); | |
| 193 int testUtilHaveTiffInfo(void); | |
| 194 int testUtilVerifyTiffInfo(const char *filename, int debug); | |
| 195 | |
| 196 int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, | |
| 197 int debug); | |
| 198 int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, | |
| 199 const char *data, int length, const char *primary, char *buffer, int buffer_size, int *p_parsefnc); | |
| 200 int testUtilBwippSegs(int index, struct zint_symbol *symbol, int option_1, int option_2, int option_3, | |
| 201 const struct zint_seg segs[], const int seg_count, const char *primary, char *buffer, int buffer_size); | |
| 202 int testUtilBwippCmp(const struct zint_symbol *symbol, char *msg, char *cmp_buf, const char *expected); | |
| 203 int testUtilBwippCmpRow(const struct zint_symbol *symbol, int row, char *msg, const char *cmp_buf, | |
| 204 const char *expected); | |
| 205 | |
| 206 int testUtilHaveZXingCPPDecoder(void); | |
| 207 int testUtilCanZXingCPP(int index, const struct zint_symbol *symbol, const char *data, const int length, | |
| 208 const int debug); | |
| 209 int testUtilZXingCPP(int index, struct zint_symbol *symbol, const char *source, const int length, char *bits, | |
| 210 char *buffer, const int buffer_size, int *p_cmp_len); | |
| 211 int testUtilZXingCPPSegs(int index, struct zint_symbol *symbol, const struct zint_seg segs[], const int seg_count, char *bits, | |
| 212 char *buffer, const int buffer_size, int *p_cmp_len); | |
| 213 int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, int cmp_len, | |
| 214 const char *expected, int expected_len, const char *primary, char *ret_buf, int *p_ret_len); | |
| 215 int testUtilZXingCPPCmpSegs(struct zint_symbol *symbol, char *msg, char *cmp_buf, int cmp_len, | |
| 216 const struct zint_seg segs[], const int seg_count, const char *primary, char *ret_buf, int *p_ret_len); | |
| 217 | |
| 218 #ifdef __cplusplus | |
| 219 } | |
| 220 #endif | |
| 221 | |
| 222 /* vim: set ts=4 sw=4 et : */ | |
| 223 #endif /* Z_TESTCOMMON_H */ |
