Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tests/test_gif.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 INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); | |
| 35 | |
| 36 static void test_pixel_plot(const testCtx *const p_ctx) { | |
| 37 int debug = p_ctx->debug; | |
| 38 | |
| 39 struct item { | |
| 40 int symbology; | |
| 41 int width; | |
| 42 int height; | |
| 43 char *pattern; | |
| 44 int repeat; | |
| 45 int ret; | |
| 46 }; | |
| 47 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 48 static const struct item data[] = { | |
| 49 /* 0*/ { BARCODE_CODE128, 1, 1, "1", 0, 0 }, | |
| 50 /* 1*/ { BARCODE_CODE128, 2, 1, "11", 0, 0 }, | |
| 51 /* 2*/ { BARCODE_CODE128, 3, 1, "101", 0, 0 }, | |
| 52 /* 3*/ { BARCODE_CODE128, 4, 1, "1010", 0, 0 }, | |
| 53 /* 4*/ { BARCODE_CODE128, 5, 1, "10101", 0, 0 }, | |
| 54 /* 5*/ { BARCODE_CODE128, 3, 2, "101010", 0, 0 }, | |
| 55 /* 6*/ { BARCODE_CODE128, 3, 3, "101010101", 0, 0 }, | |
| 56 /* 7*/ { BARCODE_ULTRA, 8, 2, "CBMWKRYGGYRKWMBC", 0, 0 }, | |
| 57 /* 8*/ { BARCODE_ULTRA, 20, 30, "WWCWBWMWRWYWGWKCCWCMCRCYCGCKBWBCBBMBRBYBGBKMWMCMBMMRMYMGMKRWRCRBRMRRYRGRKYWYCYBYMYRYYGYKGWGCGBGMGRGYGGKKWKCKBKMKRKYKGKK", 1, 0 }, /* Single LZW block, size 255 */ | |
| 58 /* 9*/ { BARCODE_ULTRA, 19, 32, "WWCWBWMWRWYWGWKCCWCMCRCYCGCKBWBCBBMBRBYBGBKMWMCMBMMRMYMGMKRWRCRBRMRRYRGRKYWYCYBYMYRYYGYKGWGCGBGMGRGYGGKKWK", 1, 0 }, /* Two LZW blocks, last size 1 */ | |
| 59 /* 10*/ { BARCODE_ULTRA, 1, 1, "D", 0, 0 }, /* This used to fail, now just maps unknown codes to 0 (1st colour index) */ | |
| 60 }; | |
| 61 const int data_size = ARRAY_SIZE(data); | |
| 62 int i, ret; | |
| 63 struct zint_symbol *symbol = NULL; | |
| 64 | |
| 65 char *gif = "out.gif"; | |
| 66 | |
| 67 char data_buf[19 * 32 + 1]; /* 19 * 32 == 608 */ | |
| 68 | |
| 69 const char *const have_identify = testUtilHaveIdentify(); | |
| 70 | |
| 71 testStart("test_pixel_plot"); | |
| 72 | |
| 73 for (i = 0; i < data_size; i++) { | |
| 74 int size; | |
| 75 | |
| 76 if (testContinue(p_ctx, i)) continue; | |
| 77 | |
| 78 symbol = ZBarcode_Create(); | |
| 79 assert_nonnull(symbol, "Symbol not created\n"); | |
| 80 | |
| 81 strcpy(symbol->outfile, gif); | |
| 82 | |
| 83 symbol->symbology = data[i].symbology; | |
| 84 symbol->bitmap_width = data[i].width; | |
| 85 symbol->bitmap_height = data[i].height; | |
| 86 symbol->debug |= debug; | |
| 87 | |
| 88 size = data[i].width * data[i].height; | |
| 89 assert_nonzero(size < (int) sizeof(data_buf), "i:%d gif_pixel_plot size %d < sizeof(data_buf) %d\n", i, size, (int) sizeof(data_buf)); | |
| 90 | |
| 91 if (data[i].repeat) { | |
| 92 testUtilStrCpyRepeat(data_buf, data[i].pattern, size); | |
| 93 } else { | |
| 94 strcpy(data_buf, data[i].pattern); | |
| 95 } | |
| 96 assert_equal(size, (int) strlen(data_buf), "i:%d gif_pixel_plot size %d != strlen(data_buf) %d\n", i, size, (int) strlen(data_buf)); | |
| 97 | |
| 98 symbol->bitmap = (unsigned char *) data_buf; | |
| 99 | |
| 100 ret = gif_pixel_plot(symbol, (unsigned char *) data_buf); | |
| 101 assert_equal(ret, data[i].ret, "i:%d gif_pixel_plot ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); | |
| 102 | |
| 103 if (ret < ZINT_ERROR) { | |
| 104 if (have_identify) { | |
| 105 ret = testUtilVerifyIdentify(have_identify, symbol->outfile, debug); | |
| 106 assert_zero(ret, "i:%d identify %s ret %d != 0\n", i, symbol->outfile, ret); | |
| 107 } | |
| 108 if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) { /* -d 64 */ | |
| 109 assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile); | |
| 110 } | |
| 111 } else { | |
| 112 if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) { | |
| 113 (void) testUtilRemove(symbol->outfile); | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 symbol->bitmap = NULL; | |
| 118 | |
| 119 ZBarcode_Delete(symbol); | |
| 120 } | |
| 121 | |
| 122 testFinish(); | |
| 123 } | |
| 124 | |
| 125 static void test_print(const testCtx *const p_ctx) { | |
| 126 int debug = p_ctx->debug; | |
| 127 | |
| 128 struct item { | |
| 129 int symbology; | |
| 130 int border_width; | |
| 131 int output_options; | |
| 132 int whitespace_width; | |
| 133 int whitespace_height; | |
| 134 int option_1; | |
| 135 int option_2; | |
| 136 float height; | |
| 137 float scale; | |
| 138 float dot_size; | |
| 139 struct zint_structapp structapp; | |
| 140 char *fgcolour; | |
| 141 char *bgcolour; | |
| 142 char *data; | |
| 143 char *expected_file; | |
| 144 char *comment; | |
| 145 }; | |
| 146 static const struct item data[] = { | |
| 147 /* 0*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "", "", "12", "dotcode_1.0.gif", "" }, | |
| 148 /* 1*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 0, 0.1, { 0, 0, "" }, "", "", "12", "dotcode_1.0_ds0.1.gif", "" }, | |
| 149 /* 2*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 0, 1.1, { 0, 0, "" }, "", "", "12", "dotcode_1.0_ds1.1.gif", "" }, | |
| 150 /* 3*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 1.5, 0, { 0, 0, "" }, "", "", "12", "dotcode_1.5.gif", "" }, | |
| 151 /* 4*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 1.5, 0.4, { 0, 0, "" }, "", "", "12", "dotcode_1.5_ds0.4.gif", "" }, | |
| 152 /* 5*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 1.5, 1.1, { 0, 0, "" }, "", "", "12", "dotcode_1.5_ds1.1.gif", "" }, | |
| 153 /* 6*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 1.5, 2.1, { 0, 0, "" }, "", "", "12", "dotcode_1.5_ds2.1.gif", "" }, | |
| 154 /* 7*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 2, 0, { 0, 0, "" }, "", "", "12", "dotcode_2.0.gif", "" }, | |
| 155 /* 8*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 2, 0.9, { 0, 0, "" }, "", "", "12", "dotcode_2.0_ds0.9.gif", "" }, | |
| 156 /* 9*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 2, 1.1, { 0, 0, "" }, "", "", "12", "dotcode_2.0_ds1.1.gif", "" }, | |
| 157 /* 10*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 3, 0, { 0, 0, "" }, "", "", "12", "dotcode_3.0.gif", "" }, | |
| 158 /* 11*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 3, 0.4, { 0, 0, "" }, "", "", "12", "dotcode_3.0_ds0.4.gif", "" }, | |
| 159 /* 12*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 3, 1.1, { 0, 0, "" }, "", "", "12", "dotcode_3.0_ds1.1.gif", "" }, | |
| 160 /* 13*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 3.5, 0, { 0, 0, "" }, "", "", "12", "dotcode_3.5.gif", "" }, | |
| 161 /* 14*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 3.5, 0.4, { 0, 0, "" }, "", "", "12", "dotcode_3.5_ds0.4.gif", "" }, | |
| 162 /* 15*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 3.5, 1.1, { 0, 0, "" }, "", "", "12", "dotcode_3.5_ds1.1.gif", "" }, | |
| 163 /* 16*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 5, 0, { 0, 0, "" }, "", "", "12", "dotcode_5.0.gif", "" }, | |
| 164 /* 17*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 5, 0.2, { 0, 0, "" }, "", "", "12", "dotcode_5.0_ds0.2.gif", "" }, | |
| 165 /* 18*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 5, 1.1, { 0, 0, "" }, "", "", "12", "dotcode_5.0_ds1.1.gif", "" }, | |
| 166 /* 19*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 5, 1.7, { 0, 0, "" }, "", "", "12", "dotcode_5.0_ds1.7.gif", "" }, | |
| 167 /* 20*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "2674C344", "FDFFC2CC", "12", "dotcode_bgfgalpha.gif", "" }, | |
| 168 /* 21*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "00000000", "FFFFFF00", "12", "dotcode_bgfgtrans.gif", "" }, | |
| 169 /* 22*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "00000000", "FFFFFF", "12", "dotcode_fgtrans.gif", "" }, | |
| 170 /* 23*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "000000", "FFFFFF00", "12", "dotcode_bgtrans.gif", "" }, | |
| 171 /* 24*/ { BARCODE_DOTCODE, -1, CMYK_COLOUR, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "71,0,40,44", "", "12", "dotcode_cmyk_fg.gif", "" }, | |
| 172 /* 25*/ { BARCODE_ULTRA, 1, BARCODE_BOX, 1, 1, -1, -1, 0, 0, 0, { 0, 0, "" }, "0000FF", "FF0000", "12", "ultra_fgbg_hvwsp1_box1.gif", "" }, | |
| 173 /* 26*/ { BARCODE_ULTRA, 1, BARCODE_BOX, 1, 1, -1, -1, 0, 0, 0, { 0, 0, "" }, "0000FF00", "FF000000", "12", "ultra_fgbg_hvwsp1_box1_bgfgtrans.gif", "" }, | |
| 174 /* 27*/ { BARCODE_ULTRA, 1, BARCODE_BOX, 1, 1, -1, -1, 0, 0, 0, { 0, 0, "" }, "0000FF", "FF000000", "12", "ultra_fgbg_hvwsp1_box1_bgtrans.gif", "" }, | |
| 175 /* 28*/ { BARCODE_ULTRA, 1, BARCODE_BOX, 1, 1, -1, -1, 0, 0, 0, { 0, 0, "" }, "0000FF00", "FF0000", "12", "ultra_fgbg_hvwsp1_box1_fgtrans.gif", "" }, | |
| 176 /* 29*/ { BARCODE_ITF14, 4, BARCODE_BIND, 24, -1, -1, -1, 61.8, 3, 0, { 0, 0, "" }, "", "", "0501054800395", "itf14_height61.8_bind4_wsp24_3.gif", "#204 ARM-Cortex crash" }, | |
| 177 /* 30*/ { BARCODE_ITF14, 0, BARCODE_BIND, -1, -1, -1, -1, 0.5, 0.5, 0, { 0, 0, "" }, "", "", "0501054800395", "itf14_height0.5_box0_0.5.gif", "No box, no text" }, | |
| 178 /* 31*/ { BARCODE_ITF14, -1, -1, -1, -1, -1, -1, 0.5, 1.1, 0, { 0, 0, "" }, "", "", "0501054800395", "itf14_height0.5_1.1.gif", "" }, | |
| 179 /* 32*/ { BARCODE_CODE16K, -1, -1, 3, 5, -1, -1, 0.5, 0, 0, { 0, 0, "" }, "", "", "1234567890", "code16k_height0.5_wsp3_vwsp5.gif", "Separator covers bars" }, | |
| 180 /* 33*/ { BARCODE_CODE16K, -1, -1, 3, 5, -1, -1, 1.5, 0, 0, { 0, 0, "" }, "", "", "1234567890", "code16k_height1.5_wsp3_vwsp5.gif", "" }, | |
| 181 /* 34*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, -1, 0, 0, 0, { 2, 9, "001002" }, "", "", "1234567890", "datamatrix_seq2of9.gif", "" }, | |
| 182 /* 35*/ { BARCODE_ULTRA, -1, -1, 1, -1, -1, 2, 0, 0, 0, { 0, 0, "" }, "", "", "12", "ultra_rev2.gif", "Revision 2" }, | |
| 183 /* 36*/ { BARCODE_DPD, -1, BARCODE_QUIET_ZONES | COMPLIANT_HEIGHT, -1, -1, -1, -1, 0, 0, 0, { 0, 0, "" }, "", "", "008182709980000020028101276", "dpd_compliant.gif", "Now with bind top 3X default" }, | |
| 184 }; | |
| 185 const int data_size = ARRAY_SIZE(data); | |
| 186 int i, length, ret; | |
| 187 struct zint_symbol *symbol = NULL; | |
| 188 | |
| 189 const char *data_dir = "/backend/tests/data/gif"; | |
| 190 const char *gif = "out.gif"; | |
| 191 char expected_file[4096]; | |
| 192 char escaped[1024]; | |
| 193 int escaped_size = 1024; | |
| 194 unsigned char filebuf[32768]; | |
| 195 int filebuf_size; | |
| 196 | |
| 197 const char *const have_identify = testUtilHaveIdentify(); | |
| 198 | |
| 199 testStartSymbol("test_print", &symbol); | |
| 200 | |
| 201 if (p_ctx->generate) { | |
| 202 char data_dir_path[1024]; | |
| 203 assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); | |
| 204 if (!testUtilDirExists(data_dir_path)) { | |
| 205 ret = testUtilMkDir(data_dir_path); | |
| 206 assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); | |
| 207 } | |
| 208 } | |
| 209 | |
| 210 for (i = 0; i < data_size; i++) { | |
| 211 | |
| 212 if (testContinue(p_ctx, i)) continue; | |
| 213 | |
| 214 symbol = ZBarcode_Create(); | |
| 215 assert_nonnull(symbol, "Symbol not created\n"); | |
| 216 | |
| 217 length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); | |
| 218 if (data[i].border_width != -1) { | |
| 219 symbol->border_width = data[i].border_width; | |
| 220 } | |
| 221 if (data[i].whitespace_width != -1) { | |
| 222 symbol->whitespace_width = data[i].whitespace_width; | |
| 223 } | |
| 224 if (data[i].whitespace_height != -1) { | |
| 225 symbol->whitespace_height = data[i].whitespace_height; | |
| 226 } | |
| 227 if (data[i].height) { | |
| 228 symbol->height = data[i].height; | |
| 229 } | |
| 230 if (data[i].scale) { | |
| 231 symbol->scale = data[i].scale; | |
| 232 } | |
| 233 if (data[i].dot_size) { | |
| 234 symbol->dot_size = data[i].dot_size; | |
| 235 } | |
| 236 if (data[i].structapp.count) { | |
| 237 symbol->structapp = data[i].structapp; | |
| 238 } | |
| 239 if (*data[i].fgcolour) { | |
| 240 strcpy(symbol->fgcolour, data[i].fgcolour); | |
| 241 } | |
| 242 if (*data[i].bgcolour) { | |
| 243 strcpy(symbol->bgcolour, data[i].bgcolour); | |
| 244 } | |
| 245 | |
| 246 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 247 assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); | |
| 248 | |
| 249 strcpy(symbol->outfile, gif); | |
| 250 ret = ZBarcode_Print(symbol, 0); | |
| 251 assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret); | |
| 252 | |
| 253 assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); | |
| 254 | |
| 255 if (p_ctx->generate) { | |
| 256 printf(" /*%3d*/ { %s, %d, %s, %d, %d, %d, %d, %.5g, %.5g, %.5g, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\" },\n", | |
| 257 i, testUtilBarcodeName(data[i].symbology), data[i].border_width, testUtilOutputOptionsName(data[i].output_options), | |
| 258 data[i].whitespace_width, data[i].whitespace_height, | |
| 259 data[i].option_1, data[i].option_2, data[i].height, data[i].scale, data[i].dot_size, data[i].fgcolour, data[i].bgcolour, | |
| 260 testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file, data[i].comment); | |
| 261 ret = testUtilRename(symbol->outfile, expected_file); | |
| 262 assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); | |
| 263 if (have_identify) { | |
| 264 ret = testUtilVerifyIdentify(have_identify, expected_file, debug); | |
| 265 assert_zero(ret, "i:%d %s identify %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); | |
| 266 } | |
| 267 } else { | |
| 268 assert_nonzero(testUtilExists(symbol->outfile), "i:%d testUtilExists(%s) == 0\n", i, symbol->outfile); | |
| 269 assert_nonzero(testUtilExists(expected_file), "i:%d testUtilExists(%s) == 0\n", i, expected_file); | |
| 270 | |
| 271 ret = testUtilCmpBins(symbol->outfile, expected_file); | |
| 272 assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); | |
| 273 | |
| 274 ret = testUtilReadFile(symbol->outfile, filebuf, sizeof(filebuf), &filebuf_size); /* For BARCODE_MEMORY_FILE */ | |
| 275 assert_zero(ret, "i:%d %s testUtilReadFile(%s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret); | |
| 276 | |
| 277 if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) { | |
| 278 assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile); | |
| 279 } | |
| 280 | |
| 281 symbol->output_options |= BARCODE_MEMORY_FILE; | |
| 282 ret = ZBarcode_Print(symbol, 0); | |
| 283 assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n", | |
| 284 i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt); | |
| 285 assert_nonnull(symbol->memfile, "i:%d %s memfile NULL\n", i, testUtilBarcodeName(data[i].symbology)); | |
| 286 assert_equal(symbol->memfile_size, filebuf_size, "i:%d %s memfile_size %d != %d\n", | |
| 287 i, testUtilBarcodeName(data[i].symbology), symbol->memfile_size, filebuf_size); | |
| 288 assert_zero(memcmp(symbol->memfile, filebuf, symbol->memfile_size), "i:%d %s memcmp(memfile, filebuf) != 0\n", | |
| 289 i, testUtilBarcodeName(data[i].symbology)); | |
| 290 } | |
| 291 | |
| 292 ZBarcode_Delete(symbol); | |
| 293 } | |
| 294 | |
| 295 testFinish(); | |
| 296 } | |
| 297 | |
| 298 static void test_outfile(const testCtx *const p_ctx) { | |
| 299 int ret; | |
| 300 int skip_readonly_test = 0; | |
| 301 struct zint_symbol symbol = {0}; | |
| 302 unsigned char data[] = { "1" }; | |
| 303 | |
| 304 (void)p_ctx; | |
| 305 | |
| 306 testStart("test_outfile"); | |
| 307 | |
| 308 symbol.symbology = BARCODE_CODE128; | |
| 309 symbol.bitmap = data; | |
| 310 symbol.bitmap_width = symbol.bitmap_height = 1; | |
| 311 | |
| 312 strcpy(symbol.outfile, "test_gif_out.gif"); | |
| 313 #ifndef _WIN32 | |
| 314 skip_readonly_test = getuid() == 0; /* Skip if running as root on Unix as can't create read-only file */ | |
| 315 #endif | |
| 316 if (!skip_readonly_test) { | |
| 317 static char expected_errtxt[] = "611: Could not open GIF output file ("; /* Excluding OS-dependent `errno` stuff */ | |
| 318 | |
| 319 (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ | |
| 320 assert_nonzero(testUtilCreateROFile(symbol.outfile), "gif_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); | |
| 321 | |
| 322 ret = gif_pixel_plot(&symbol, data); | |
| 323 assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "gif_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); | |
| 324 assert_zero(testUtilRmROFile(symbol.outfile), "gif_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); | |
| 325 assert_zero(strncmp(symbol.errtxt, expected_errtxt, sizeof(expected_errtxt) - 1), "strncmp(%s, %s) != 0\n", symbol.errtxt, expected_errtxt); | |
| 326 } | |
| 327 | |
| 328 symbol.output_options |= BARCODE_STDOUT; | |
| 329 | |
| 330 ret = gif_pixel_plot(&symbol, data); | |
| 331 printf(" - ignore (GIF to stdout)\n"); fflush(stdout); | |
| 332 assert_zero(ret, "gif_pixel_plot ret %d != 0 (%s)\n", ret, symbol.errtxt); | |
| 333 | |
| 334 testFinish(); | |
| 335 } | |
| 336 | |
| 337 static void test_large_scale(const testCtx *const p_ctx) { | |
| 338 int debug = p_ctx->debug; | |
| 339 | |
| 340 int length, ret; | |
| 341 struct zint_symbol symbol = {0}; | |
| 342 char data[] = "1"; | |
| 343 | |
| 344 testStart("test_large_scale"); | |
| 345 | |
| 346 length = (int) strlen(data); | |
| 347 | |
| 348 ZBarcode_Reset(&symbol); | |
| 349 symbol.symbology = BARCODE_ITF14; | |
| 350 strcpy(symbol.outfile, "out.gif"); | |
| 351 /* X-dimension 0.27mm * 95 = 25.65 ~ 25 pixels so 12.5 gives 95 dpmm (2400 dpi) */ | |
| 352 symbol.scale = 12.5f; /* 70.0f would cause paging as LZW > 1MB but very slow */ | |
| 353 | |
| 354 ret = ZBarcode_Encode_and_Print(&symbol, (unsigned char *) data, length, 0 /*rotate_angle*/); | |
| 355 assert_zero(ret, "%s ZBarcode_Encode_and_Print ret %d != 0 %s\n", testUtilBarcodeName(symbol.symbology), ret, symbol.errtxt); | |
| 356 | |
| 357 if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) { /* -d 64 */ | |
| 358 /* 129.1 kB file manually inspected and checked (1.1 MB file for scale 70.0f also checked) */ | |
| 359 assert_zero(testUtilRemove(symbol.outfile), "testUtilRemove(%s) != 0\n", symbol.outfile); | |
| 360 } | |
| 361 | |
| 362 ZBarcode_Clear(&symbol); | |
| 363 | |
| 364 testFinish(); | |
| 365 } | |
| 366 | |
| 367 static void test_too_big(const testCtx *const p_ctx) { | |
| 368 int debug = p_ctx->debug; | |
| 369 | |
| 370 int length, ret; | |
| 371 struct zint_symbol symbol = {0}; | |
| 372 char data[] = "12345"; | |
| 373 | |
| 374 (void)debug; | |
| 375 | |
| 376 testStart("test_too_big"); | |
| 377 | |
| 378 length = (int) strlen(data); | |
| 379 | |
| 380 ZBarcode_Reset(&symbol); | |
| 381 symbol.symbology = BARCODE_EANX; | |
| 382 strcpy(symbol.outfile, "out.gif"); | |
| 383 symbol.scale = 200.0f; | |
| 384 symbol.whitespace_width = 32; | |
| 385 | |
| 386 /* Fails in `plot_raster_default()` with `image_size` 0x4029C800 > 1GB */ | |
| 387 ret = ZBarcode_Encode_and_Print(&symbol, (unsigned char *) data, length, 0 /*rotate_angle*/); | |
| 388 assert_equal(ret, ZINT_ERROR_MEMORY, "%s ZBarcode_Encode_and_Print ret %d != ZINT_ERROR_MEMORY %s\n", | |
| 389 testUtilBarcodeName(symbol.symbology), ret, symbol.errtxt); | |
| 390 | |
| 391 ZBarcode_Clear(&symbol); | |
| 392 | |
| 393 testFinish(); | |
| 394 } | |
| 395 | |
| 396 int main(int argc, char *argv[]) { | |
| 397 | |
| 398 testFunction funcs[] = { /* name, func */ | |
| 399 { "test_pixel_plot", test_pixel_plot }, | |
| 400 { "test_print", test_print }, | |
| 401 { "test_outfile", test_outfile }, | |
| 402 { "test_large_scale", test_large_scale }, | |
| 403 { "test_too_big", test_too_big }, | |
| 404 }; | |
| 405 | |
| 406 testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); | |
| 407 | |
| 408 testReport(); | |
| 409 | |
| 410 return 0; | |
| 411 } | |
| 412 | |
| 413 /* vim: set ts=4 sw=4 et : */ |
