Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tests/test_print.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 #ifndef ZINT_NO_PNG | |
| 34 #include <zlib.h> /* For ZLIBNG_VERSION define (if any) */ | |
| 35 #endif | |
| 36 #include <sys/stat.h> | |
| 37 | |
| 38 #define TEST_PRINT_OVERWRITE_EXPECTED "bmp,emf,eps,gif,pcx,png,svg,tif,txt" | |
| 39 | |
| 40 static void test_print(const testCtx *const p_ctx) { | |
| 41 int debug = p_ctx->debug; | |
| 42 | |
| 43 struct item { | |
| 44 int symbology; | |
| 45 int option_1; | |
| 46 int option_2; | |
| 47 float scale; | |
| 48 char *data; | |
| 49 char *expected_file; | |
| 50 }; | |
| 51 struct item data[] = { | |
| 52 /* 0*/ { BARCODE_CODE128, -1, -1, -1, "AIM", "code128_aim" }, | |
| 53 /* 1*/ { BARCODE_QRCODE, 2, 1, -1, "1234567890", "qr_v1_m" }, | |
| 54 /* 2*/ { BARCODE_DOTCODE, -1, -1, 5, "2741", "dotcode_aim_fig7" }, | |
| 55 /* 3*/ { BARCODE_ULTRA, -1, -1, -1, "A", "ultracode_a" }, | |
| 56 /* 4*/ { BARCODE_MAXICODE, -1, -1, -1, "THIS IS A 93 CHARACTER CODE SET A MESSAGE THAT FILLS A MODE 4, UNAPPENDED, MAXICODE SYMBOL...", "maxicode_fig_2" }, | |
| 57 }; | |
| 58 int data_size = ARRAY_SIZE(data); | |
| 59 int i, length, ret; | |
| 60 struct zint_symbol *symbol = NULL; | |
| 61 int j; | |
| 62 | |
| 63 char *exts[] = { "bmp", "emf", "eps", "gif", "pcx", "png", "svg", "tif", "txt" }; | |
| 64 int exts_size = ARRAY_SIZE(exts); | |
| 65 | |
| 66 char data_dir[1024]; | |
| 67 char data_subdir[1024]; | |
| 68 char expected_file[1024]; | |
| 69 | |
| 70 char escaped[1024]; | |
| 71 int escaped_size = 1024; | |
| 72 | |
| 73 const char *have_identify = NULL; | |
| 74 int have_libreoffice = 0; | |
| 75 int have_ghostscript = 0; | |
| 76 int have_vnu = 0; | |
| 77 int have_tiffinfo = 0; | |
| 78 | |
| 79 if (p_ctx->generate) { | |
| 80 have_identify = testUtilHaveIdentify(); | |
| 81 have_libreoffice = testUtilHaveLibreOffice(); | |
| 82 have_ghostscript = testUtilHaveGhostscript(); | |
| 83 have_vnu = testUtilHaveVnu(); | |
| 84 have_tiffinfo = testUtilHaveTiffInfo(); | |
| 85 } | |
| 86 | |
| 87 testStartSymbol("test_print", &symbol); | |
| 88 | |
| 89 assert_nonzero(testUtilDataPath(data_dir, sizeof(data_dir), "/backend/tests/data", NULL), "testUtilDataPath == 0\n"); | |
| 90 | |
| 91 if (p_ctx->generate) { | |
| 92 if (!testUtilDirExists(data_dir)) { | |
| 93 ret = testUtilMkDir(data_dir); | |
| 94 assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno)); | |
| 95 } | |
| 96 assert_nonzero(sizeof(data_dir) > strlen(data_dir) + 6, "sizeof(data_dir) %d <= strlen (%d) + 6\n", (int) sizeof(data_dir), (int) strlen(data_dir)); | |
| 97 strcat(data_dir, "/print"); | |
| 98 if (!testUtilDirExists(data_dir)) { | |
| 99 ret = testUtilMkDir(data_dir); | |
| 100 assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno)); | |
| 101 } | |
| 102 } else { | |
| 103 assert_nonzero(sizeof(data_dir) > strlen(data_dir) + 6, "sizeof(data_dir) %d <= strlen (%d) + 6\n", (int) sizeof(data_dir), (int) strlen(data_dir)); | |
| 104 strcat(data_dir, "/print"); | |
| 105 } | |
| 106 | |
| 107 for (j = 0; j < exts_size; j++) { | |
| 108 | |
| 109 if (ZBarcode_NoPng() && strcmp(exts[j], "png") == 0) continue; | |
| 110 | |
| 111 assert_nonzero(sizeof(data_subdir) > strlen(data_dir) + 1 + strlen(exts[j]), | |
| 112 "sizeof(data_subdir) (%d) <= strlen(data_dir) (%d) + 1 + strlen(%s) (%d)\n", | |
| 113 (int) sizeof(data_subdir), (int) strlen(data_dir), exts[j], (int) strlen(exts[j])); | |
| 114 strcpy(data_subdir, data_dir); | |
| 115 strcat(data_subdir, "/"); | |
| 116 strcat(data_subdir, exts[j]); | |
| 117 | |
| 118 if (p_ctx->generate) { | |
| 119 if (!testUtilDirExists(data_subdir)) { | |
| 120 ret = testUtilMkDir(data_subdir); | |
| 121 assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_subdir, ret, errno, strerror(errno)); | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 for (i = 0; i < data_size; i++) { | |
| 126 | |
| 127 if (testContinue(p_ctx, i)) continue; | |
| 128 | |
| 129 symbol = ZBarcode_Create(); | |
| 130 assert_nonnull(symbol, "Symbol not created\n"); | |
| 131 | |
| 132 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); | |
| 133 if (data[i].scale != -1) { | |
| 134 symbol->scale = data[i].scale; | |
| 135 } | |
| 136 | |
| 137 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 138 assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); | |
| 139 | |
| 140 strcpy(symbol->outfile, "out."); | |
| 141 strcat(symbol->outfile, exts[j]); | |
| 142 | |
| 143 assert_nonzero(sizeof(expected_file) > strlen(data_subdir) + 1 + strlen(data[i].expected_file) + 1 + strlen(exts[j]), | |
| 144 "i:%d sizeof(expected_file) (%d) > strlen(data_subdir) (%d) + 1 + strlen(%s) (%d) + 1 + strlen(%s) (%d),\n", | |
| 145 i, (int) sizeof(expected_file), (int) strlen(data_subdir), data[i].expected_file, (int) strlen(data[i].expected_file), exts[j], (int) strlen(exts[j])); | |
| 146 strcpy(expected_file, data_subdir); | |
| 147 strcat(expected_file, "/"); | |
| 148 strcat(expected_file, data[i].expected_file); | |
| 149 strcat(expected_file, "."); | |
| 150 strcat(expected_file, exts[j]); | |
| 151 | |
| 152 ret = ZBarcode_Print(symbol, 0); | |
| 153 assert_zero(ret, "i:%d j:%d %s %s ZBarcode_Print %s ret %d != 0\n", i, j, exts[j], testUtilBarcodeName(data[i].symbology), symbol->outfile, ret); | |
| 154 | |
| 155 if (p_ctx->generate) { | |
| 156 if (j == 0) { | |
| 157 printf(" /*%3d*/ { %s, %d, %d, %.8g, \"%s\", \"%s\" },\n", | |
| 158 i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, data[i].scale, | |
| 159 testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file); | |
| 160 } | |
| 161 if (strstr(TEST_PRINT_OVERWRITE_EXPECTED, exts[j])) { | |
| 162 ret = testUtilRename(symbol->outfile, expected_file); | |
| 163 assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); | |
| 164 if (strcmp(exts[j], "eps") == 0) { | |
| 165 if (have_ghostscript) { | |
| 166 ret = testUtilVerifyGhostscript(expected_file, debug); | |
| 167 assert_zero(ret, "i:%d %s ghostscript %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); | |
| 168 } | |
| 169 } else if (strcmp(exts[j], "svg") == 0 || strcmp(exts[j], "emf") == 0) { | |
| 170 if (have_libreoffice) { | |
| 171 ret = testUtilVerifyLibreOffice(expected_file, debug); /* Slow */ | |
| 172 assert_zero(ret, "i:%d %s libreoffice %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); | |
| 173 } | |
| 174 if (have_vnu && strcmp(exts[j], "svg") == 0) { | |
| 175 ret = testUtilVerifyVnu(expected_file, debug); /* Very slow */ | |
| 176 assert_zero(ret, "i:%d %s vnu %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); | |
| 177 } | |
| 178 } else if (strcmp(exts[j], "tif") == 0 && have_tiffinfo) { /* Much faster (and better) than identify */ | |
| 179 ret = testUtilVerifyTiffInfo(expected_file, debug); | |
| 180 assert_zero(ret, "i:%d %s tiffinfo %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); | |
| 181 } else if (strcmp(exts[j], "txt") != 0) { /* I.e. rasters */ | |
| 182 if (have_identify) { | |
| 183 ret = testUtilVerifyIdentify(have_identify, expected_file, debug); | |
| 184 assert_zero(ret, "i:%d %s identify %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); | |
| 185 } | |
| 186 } | |
| 187 } | |
| 188 } else { | |
| 189 assert_nonzero(testUtilExists(symbol->outfile), "i:%d j:%d %s testUtilExists(%s) == 0\n", i, j, exts[j], symbol->outfile); | |
| 190 | |
| 191 if (strcmp(exts[j], "eps") == 0) { | |
| 192 ret = testUtilCmpEpss(symbol->outfile, expected_file); | |
| 193 assert_zero(ret, "i:%d %s testUtilCmpEpss(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); | |
| 194 } else if (strcmp(exts[j], "png") == 0) { | |
| 195 ret = testUtilCmpPngs(symbol->outfile, expected_file); | |
| 196 assert_zero(ret, "i:%d %s testUtilCmpPngs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); | |
| 197 #ifndef ZLIBNG_VERSION /* zlib-ng (used by e.g. Fedora 40) may produce non-binary compat output */ | |
| 198 ret = testUtilCmpBins(symbol->outfile, expected_file); | |
| 199 assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); | |
| 200 #endif | |
| 201 } else if (strcmp(exts[j], "svg") == 0) { | |
| 202 ret = testUtilCmpSvgs(symbol->outfile, expected_file); | |
| 203 assert_zero(ret, "i:%d %s testUtilCmpSvgs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); | |
| 204 } else if (strcmp(exts[j], "txt") == 0) { | |
| 205 ret = testUtilCmpTxts(symbol->outfile, expected_file); | |
| 206 assert_zero(ret, "i:%d %s testUtilCmpTxts(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); | |
| 207 } else { | |
| 208 ret = testUtilCmpBins(symbol->outfile, expected_file); | |
| 209 assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); | |
| 210 } | |
| 211 | |
| 212 if (p_ctx->index == -1) assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile); | |
| 213 } | |
| 214 | |
| 215 ZBarcode_Delete(symbol); | |
| 216 } | |
| 217 } | |
| 218 | |
| 219 testFinish(); | |
| 220 } | |
| 221 | |
| 222 int main(int argc, char *argv[]) { | |
| 223 | |
| 224 testFunction funcs[] = { /* name, func */ | |
| 225 { "test_print", test_print }, | |
| 226 }; | |
| 227 | |
| 228 testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); | |
| 229 | |
| 230 testReport(); | |
| 231 | |
| 232 return 0; | |
| 233 } | |
| 234 | |
| 235 /* vim: set ts=4 sw=4 et : */ |
