Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tests/test_ps.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 #include <sys/stat.h> | |
| 34 | |
| 35 static void test_print(const testCtx *const p_ctx) { | |
| 36 int debug = p_ctx->debug; | |
| 37 | |
| 38 struct item { | |
| 39 int symbology; | |
| 40 int input_mode; | |
| 41 int border_width; | |
| 42 int output_options; | |
| 43 int whitespace_width; | |
| 44 int whitespace_height; | |
| 45 int option_1; | |
| 46 int option_2; | |
| 47 float scale; | |
| 48 float dot_size; | |
| 49 char *fgcolour; | |
| 50 char *bgcolour; | |
| 51 int rotate_angle; | |
| 52 char *data; | |
| 53 char *expected_file; | |
| 54 }; | |
| 55 static const struct item data[] = { | |
| 56 /* 0*/ { BARCODE_CODE128, UNICODE_MODE, -1, BOLD_TEXT, -1, -1, -1, -1, 0, 0, "", "", 0, "Égjpqy", "code128_egrave_bold.eps" }, | |
| 57 /* 1*/ { BARCODE_CODE128, UNICODE_MODE, -1, BOLD_TEXT, -1, -1, -1, -1, 0, 0, "", "", 90, "Égjpqy", "code128_egrave_bold_rotate_90.eps" }, | |
| 58 /* 2*/ { BARCODE_CODE128, UNICODE_MODE, -1, BOLD_TEXT, -1, -1, -1, -1, 0, 0, "", "", 180, "Égjpqy", "code128_egrave_bold_rotate_180.eps" }, | |
| 59 /* 3*/ { BARCODE_CODE128, UNICODE_MODE, -1, BOLD_TEXT, -1, -1, -1, -1, 0, 0, "", "", 270, "Égjpqy", "code128_egrave_bold_rotate_270.eps" }, | |
| 60 /* 4*/ { BARCODE_CODE39, -1, -1, -1, -1, -1, -1, -1, 0, 0, "147AD0", "FC9630", 0, "123", "code39_fg_bg.eps" }, | |
| 61 /* 5*/ { BARCODE_CODE39, -1, -1, CMYK_COLOUR, -1, -1, -1, -1, 0, 0, "147AD0EE", "FC9630", 0, "123", "code39_fgalpha_bg_cmyk.eps" }, | |
| 62 /* 6*/ { BARCODE_CODE39, -1, -1, CMYK_COLOUR, -1, -1, -1, -1, 0, 0, "90,40,0,9", "FC963000", 0, "123", "code39_nobg_cmyk.eps" }, | |
| 63 /* 7*/ { BARCODE_CODE39, -1, -1, SMALL_TEXT, -1, -1, -1, -1, 0, 0, "", "", 0, "123", "code39_small.eps" }, | |
| 64 /* 8*/ { BARCODE_ULTRA, -1, -1, -1, -1, -1, -1, -1, 0, 0, "147AD0", "FC9630", 0, "123", "ultra_fg_bg.eps" }, | |
| 65 /* 9*/ { BARCODE_ULTRA, -1, 1, BARCODE_BOX, 2, -1, -1, -1, 0, 0, "0000FF", "FF0000", 0, "123", "ultra_fg_bg_box.eps" }, | |
| 66 /* 10*/ { BARCODE_ULTRA, -1, 2, BARCODE_BOX | CMYK_COLOUR, 1, 1, -1, -1, 0, 0, "0000FF", "FF0000", 0, "123", "ultra_fg_bg_box_cmyk.eps" }, | |
| 67 /* 11*/ { BARCODE_EANX, -1, -1, -1, -1, -1, -1, -1, 0, 0, "", "", 0, "9501101531000", "ean13_ggs_5.2.2.1-1.eps" }, | |
| 68 /* 12*/ { BARCODE_EANX, -1, -1, EANUPC_GUARD_WHITESPACE, -1, -1, -1, -1, 0, 0, "", "", 0, "9501101531000", "ean13_ggs_5.2.2.1-1_gws.eps" }, | |
| 69 /* 13*/ { BARCODE_EANX, -1, -1, -1, -1, -1, -1, -1, 0, 0, "", "", 0, "9771384524017+12", "ean13_2addon_ggs_5.2.2.5.1-2.eps" }, | |
| 70 /* 14*/ { BARCODE_EANX, -1, -1, EANUPC_GUARD_WHITESPACE, -1, -1, -1, -1, 0, 0, "", "", 0, "9771384524017+12", "ean13_2addon_ggs_5.2.2.5.1-2_gws.eps" }, | |
| 71 /* 15*/ { BARCODE_EANX, -1, -1, -1, -1, -1, -1, -1, 0, 0, "", "", 0, "9501234", "ean8_gss_5.2.2.2-1.eps" }, | |
| 72 /* 16*/ { BARCODE_EANX, -1, -1, EANUPC_GUARD_WHITESPACE, -1, -1, -1, -1, 0, 0, "", "", 0, "9501234", "ean8_gss_5.2.2.2-1_gws.eps" }, | |
| 73 /* 17*/ { BARCODE_EANX, -1, -1, EANUPC_GUARD_WHITESPACE, 3, -1, -1, -1, 0, 0, "", "", 0, "9501234", "ean8_gss_5.2.2.2-1_gws_wsw3.eps" }, | |
| 74 /* 18*/ { BARCODE_EANX, -1, -1, -1, -1, -1, -1, -1, 0, 0, "", "", 0, "98765", "ean5.eps" }, | |
| 75 /* 19*/ { BARCODE_EANX, -1, -1, EANUPC_GUARD_WHITESPACE, -1, -1, -1, -1, 0, 0, "", "", 0, "98765", "ean5_gws.eps" }, | |
| 76 /* 20*/ { BARCODE_UPCA, -1, -1, -1, -1, -1, -1, -1, 0, 0, "", "", 0, "012345678905+24", "upca_2addon_ggs_5.2.6.6-5.eps" }, | |
| 77 /* 21*/ { BARCODE_UPCA, -1, -1, EANUPC_GUARD_WHITESPACE, -1, -1, -1, -1, 0, 0, "", "", 0, "012345678905+24", "upca_2addon_ggs_5.2.6.6-5_gws.eps" }, | |
| 78 /* 22*/ { BARCODE_UPCA, -1, -1, EANUPC_GUARD_WHITESPACE, 1, 3, -1, -1, 0, 0, "", "", 0, "012345678905+24", "upca_2addon_ggs_5.2.6.6-5_gws_wsw1h3.eps" }, | |
| 79 /* 23*/ { BARCODE_UPCA, -1, -1, -1, -1, -1, -1, -1, 0, 0, "", "", 90, "012345678905+24", "upca_2addon_ggs_5.2.6.6-5_rotate_90.eps" }, | |
| 80 /* 24*/ { BARCODE_UPCA, -1, -1, EANUPC_GUARD_WHITESPACE, -1, -1, -1, -1, 0, 0, "", "", 180, "012345678905+24", "upca_2addon_ggs_5.2.6.6-5_gws_rotate_180.eps" }, | |
| 81 /* 25*/ { BARCODE_UPCA, -1, -1, EANUPC_GUARD_WHITESPACE, 4, -1, -1, -1, 0, 0, "", "", 270, "012345678905+24", "upca_2addon_ggs_5.2.6.6-5_gws_rotate_270_wsw4.eps" }, | |
| 82 /* 26*/ { BARCODE_UPCE, -1, -1, -1, -1, -1, -1, -1, 0, 0, "", "", 0, "0123456+12345", "upce_5addon.eps" }, | |
| 83 /* 27*/ { BARCODE_UPCE, -1, -1, EANUPC_GUARD_WHITESPACE, -1, -1, -1, -1, 0, 0, "", "", 0, "0123456+12345", "upce_5addon_gws.eps" }, | |
| 84 /* 28*/ { BARCODE_UPCE, -1, -1, -1, -1, -1, -1, -1, 0, 0, "", "", 270, "0123456+12345", "upce_5addon_rotate_270.eps" }, | |
| 85 /* 29*/ { BARCODE_UPCE, -1, -1, SMALL_TEXT | BOLD_TEXT, -1, -1, -1, -1, 0, 0, "", "", 0, "0123456+12345", "upce_5addon_small_bold.eps" }, | |
| 86 /* 30*/ { BARCODE_UPCE, -1, -1, SMALL_TEXT | BOLD_TEXT | EANUPC_GUARD_WHITESPACE, -1, -1, -1, -1, 0, 0, "", "", 0, "0123456+12345", "upce_5addon_small_bold_gws.eps" }, | |
| 87 /* 31*/ { BARCODE_CODE128, UNICODE_MODE, -1, -1, -1, -1, -1, -1, 0, 0, "", "", 0, "A\\B)ç(D", "code128_escape_latin1.eps" }, | |
| 88 /* 32*/ { BARCODE_DBAR_LTD, -1, -1, BOLD_TEXT, -1, -1, -1, -1, 0, 0, "", "", 0, "1501234567890", "dbar_ltd_24724_fig7_bold.eps" }, | |
| 89 /* 33*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 0.1, 0, "", "", 0, "12", "dotcode_0.1.eps" }, | |
| 90 /* 34*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 0.08, 0, "", "", 0, "12", "dotcode_0.1.eps" }, | |
| 91 /* 35*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 0, 0, "", "", 0, "12", "dotcode_1.0.eps" }, | |
| 92 /* 36*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 0, 0.1, "", "", 0, "12", "dotcode_1.0_ds0.1.eps" }, | |
| 93 /* 37*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 0, 1.1, "", "", 0, "12", "dotcode_1.0_ds1.1.eps" }, | |
| 94 /* 38*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 1.5, 0, "", "", 0, "12", "dotcode_1.5.eps" }, | |
| 95 /* 39*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 1.5, 0.4, "", "", 0, "12", "dotcode_1.5_ds0.4.eps" }, | |
| 96 /* 40*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 1.5, 1.1, "", "", 0, "12", "dotcode_1.5_ds1.1.eps" }, | |
| 97 /* 41*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 1.5, 2.1, "", "", 0, "12", "dotcode_1.5_ds2.1.eps" }, | |
| 98 /* 42*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 2, 0, "", "", 0, "12", "dotcode_2.0.eps" }, | |
| 99 /* 43*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 2, 0.9, "", "", 0, "12", "dotcode_2.0_ds0.9.eps" }, | |
| 100 /* 44*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 2, 1.1, "", "", 0, "12", "dotcode_2.0_ds1.1.eps" }, | |
| 101 /* 45*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 3, 0, "", "", 0, "12", "dotcode_3.0.eps" }, | |
| 102 /* 46*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 3, 0.4, "", "", 0, "12", "dotcode_3.0_ds0.4.eps" }, | |
| 103 /* 47*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 3, 1.1, "", "", 0, "12", "dotcode_3.0_ds1.1.eps" }, | |
| 104 /* 48*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 3.5, 0, "", "", 0, "12", "dotcode_3.5.eps" }, | |
| 105 /* 49*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 3.5, 0.4, "", "", 0, "12", "dotcode_3.5_ds0.4.eps" }, | |
| 106 /* 50*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 3.5, 1.1, "", "", 0, "12", "dotcode_3.5_ds1.1.eps" }, | |
| 107 /* 51*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 5, 0, "", "", 0, "12", "dotcode_5.0.eps" }, | |
| 108 /* 52*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 5, 0.2, "", "", 0, "12", "dotcode_5.0_ds0.2.eps" }, | |
| 109 /* 53*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 5, 1.1, "", "", 0, "12", "dotcode_5.0_ds1.1.eps" }, | |
| 110 /* 54*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 5, 1.7, "", "", 0, "12", "dotcode_5.0_ds1.7.eps" }, | |
| 111 /* 55*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, -1, -1, 0, 0, "FF0000", "0000FF00", 0, "12", "dotcode_no_bg.eps" }, | |
| 112 /* 56*/ { BARCODE_MAXICODE, -1, -1, CMYK_COLOUR, -1, -1, -1, -1, 0, 0, "", "", 270, "12", "maxicode_rotate_270_cmyk.eps" }, | |
| 113 /* 57*/ { BARCODE_MAXICODE, -1, -1, -1, 3, -1, -1, -1, 0, 0, "", "0000FF00", 180, "12", "maxicode_no_bg_hwsp3_rotate_180.eps" }, | |
| 114 /* 58*/ { BARCODE_MAXICODE, -1, -1, -1, -1, -1, -1, -1, 2.4, 0, "", "", 90, "12", "maxicode_2.4_rotate_90.eps" }, | |
| 115 }; | |
| 116 const int data_size = ARRAY_SIZE(data); | |
| 117 int i, length, ret; | |
| 118 struct zint_symbol *symbol = NULL; | |
| 119 | |
| 120 const char data_dir[] = "/backend/tests/data/eps"; | |
| 121 const char eps[] = "out.eps"; | |
| 122 const char memfile[] = "mem.eps"; | |
| 123 char expected_file[1024]; | |
| 124 char escaped[1024]; | |
| 125 int escaped_size = 1024; | |
| 126 | |
| 127 int have_ghostscript = testUtilHaveGhostscript(); | |
| 128 | |
| 129 testStartSymbol("test_print", &symbol); | |
| 130 | |
| 131 if (p_ctx->generate) { | |
| 132 char data_dir_path[1024]; | |
| 133 assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); | |
| 134 if (!testUtilDirExists(data_dir_path)) { | |
| 135 ret = testUtilMkDir(data_dir_path); | |
| 136 assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 for (i = 0; i < data_size; i++) { | |
| 141 | |
| 142 if (testContinue(p_ctx, i)) continue; | |
| 143 | |
| 144 symbol = ZBarcode_Create(); | |
| 145 assert_nonnull(symbol, "Symbol not created\n"); | |
| 146 | |
| 147 length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); | |
| 148 if (data[i].border_width != -1) { | |
| 149 symbol->border_width = data[i].border_width; | |
| 150 } | |
| 151 if (data[i].whitespace_width != -1) { | |
| 152 symbol->whitespace_width = data[i].whitespace_width; | |
| 153 } | |
| 154 if (data[i].whitespace_height != -1) { | |
| 155 symbol->whitespace_height = data[i].whitespace_height; | |
| 156 } | |
| 157 if (data[i].scale) { | |
| 158 symbol->scale = data[i].scale; | |
| 159 } | |
| 160 if (data[i].dot_size) { | |
| 161 symbol->dot_size = data[i].dot_size; | |
| 162 } | |
| 163 if (*data[i].fgcolour) { | |
| 164 strcpy(symbol->fgcolour, data[i].fgcolour); | |
| 165 } | |
| 166 if (*data[i].bgcolour) { | |
| 167 strcpy(symbol->bgcolour, data[i].bgcolour); | |
| 168 } | |
| 169 | |
| 170 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); | |
| 171 assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); | |
| 172 | |
| 173 strcpy(symbol->outfile, eps); | |
| 174 ret = ZBarcode_Print(symbol, data[i].rotate_angle); | |
| 175 assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret); | |
| 176 | |
| 177 assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); | |
| 178 | |
| 179 if (p_ctx->generate) { | |
| 180 printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, %d, %d, %.5g, %.5g, \"%s\", \"%s\", %d, \"%s\", \"%s\"},\n", | |
| 181 i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width, | |
| 182 testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, data[i].whitespace_height, data[i].option_1, data[i].option_2, | |
| 183 data[i].scale, data[i].dot_size, data[i].fgcolour, data[i].bgcolour, data[i].rotate_angle, | |
| 184 testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file); | |
| 185 ret = testUtilRename(symbol->outfile, expected_file); | |
| 186 assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); | |
| 187 if (have_ghostscript) { | |
| 188 ret = testUtilVerifyGhostscript(expected_file, debug); | |
| 189 assert_zero(ret, "i:%d %s ghostscript %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); | |
| 190 } | |
| 191 } else { | |
| 192 assert_nonzero(testUtilExists(symbol->outfile), "i:%d testUtilExists(%s) == 0\n", i, symbol->outfile); | |
| 193 assert_nonzero(testUtilExists(expected_file), "i:%d testUtilExists(%s) == 0\n", i, expected_file); | |
| 194 | |
| 195 ret = testUtilCmpEpss(symbol->outfile, expected_file); | |
| 196 assert_zero(ret, "i:%d %s testUtilCmpEpss(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); | |
| 197 | |
| 198 symbol->output_options |= BARCODE_MEMORY_FILE; | |
| 199 ret = ZBarcode_Print(symbol, data[i].rotate_angle); | |
| 200 assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n", | |
| 201 i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt); | |
| 202 assert_nonnull(symbol->memfile, "i:%d %s memfile NULL\n", i, testUtilBarcodeName(data[i].symbology)); | |
| 203 assert_nonzero(symbol->memfile_size, "i:%d %s memfile_size 0\n", i, testUtilBarcodeName(data[i].symbology)); | |
| 204 | |
| 205 ret = testUtilWriteFile(memfile, symbol->memfile, symbol->memfile_size, "wb"); | |
| 206 assert_zero(ret, "%d: testUtilWriteFile(%s) fail ret %d != 0\n", i, memfile, ret); | |
| 207 | |
| 208 ret = testUtilCmpEpss(symbol->outfile, memfile); | |
| 209 assert_zero(ret, "i:%d %s testUtilCmpEpss(%s, %s) %d != 0\n", | |
| 210 i, testUtilBarcodeName(data[i].symbology), symbol->outfile, memfile, ret); | |
| 211 | |
| 212 if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) { | |
| 213 assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile); | |
| 214 assert_zero(testUtilRemove(memfile), "i:%d testUtilRemove(%s) != 0\n", i, memfile); | |
| 215 } | |
| 216 } | |
| 217 | |
| 218 ZBarcode_Delete(symbol); | |
| 219 } | |
| 220 | |
| 221 testFinish(); | |
| 222 } | |
| 223 | |
| 224 INTERNAL void ps_convert_test(const unsigned char *string, unsigned char *ps_string); | |
| 225 | |
| 226 static void test_ps_convert(const testCtx *const p_ctx) { | |
| 227 | |
| 228 struct item { | |
| 229 char *data; | |
| 230 char *expected; | |
| 231 }; | |
| 232 static const struct item data[] = { | |
| 233 /* 0*/ { "1\\(é)2€3¿", "1\\\\\\(\351\\)23\277" }, | |
| 234 }; | |
| 235 const int data_size = ARRAY_SIZE(data); | |
| 236 int i; | |
| 237 | |
| 238 unsigned char converted[256]; | |
| 239 | |
| 240 testStart("test_ps_convert"); | |
| 241 | |
| 242 for (i = 0; i < data_size; i++) { | |
| 243 | |
| 244 if (testContinue(p_ctx, i)) continue; | |
| 245 | |
| 246 ps_convert_test((unsigned char *) data[i].data, converted); | |
| 247 assert_zero(strcmp((char *) converted, data[i].expected), "i:%d ps_convert(%s) %s != %s\n", i, data[i].data, converted, data[i].expected); | |
| 248 } | |
| 249 | |
| 250 testFinish(); | |
| 251 } | |
| 252 | |
| 253 INTERNAL int ps_plot(struct zint_symbol *symbol, int rotate_angle); | |
| 254 | |
| 255 static void test_outfile(const testCtx *const p_ctx) { | |
| 256 int ret; | |
| 257 int skip_readonly_test = 0; | |
| 258 struct zint_symbol symbol = {0}; | |
| 259 struct zint_vector vector = {0}; | |
| 260 | |
| 261 (void)p_ctx; | |
| 262 | |
| 263 testStart("test_outfile"); | |
| 264 | |
| 265 symbol.symbology = BARCODE_CODE128; | |
| 266 symbol.vector = &vector; | |
| 267 | |
| 268 strcpy(symbol.outfile, "test_ps_out.eps"); | |
| 269 #ifndef _WIN32 | |
| 270 skip_readonly_test = getuid() == 0; /* Skip if running as root on Unix as can't create read-only file */ | |
| 271 #endif | |
| 272 if (!skip_readonly_test) { | |
| 273 static char expected_errtxt[] = "645: Could not open EPS output file ("; /* Excluding OS-dependent `errno` stuff */ | |
| 274 | |
| 275 (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ | |
| 276 assert_nonzero(testUtilCreateROFile(symbol.outfile), "ps_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); | |
| 277 | |
| 278 ret = ps_plot(&symbol, 0); | |
| 279 assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "ps_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); | |
| 280 assert_zero(testUtilRmROFile(symbol.outfile), "ps_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); | |
| 281 assert_zero(strncmp(symbol.errtxt, expected_errtxt, sizeof(expected_errtxt) - 1), "strncmp(%s, %s) != 0\n", symbol.errtxt, expected_errtxt); | |
| 282 } | |
| 283 | |
| 284 symbol.output_options |= BARCODE_STDOUT; | |
| 285 | |
| 286 printf(">>>Begin ignore (EPS to stdout)\n"); fflush(stdout); | |
| 287 ret = ps_plot(&symbol, 0); | |
| 288 printf("<<<End ignore (EPS to stdout)\n"); fflush(stdout); | |
| 289 assert_zero(ret, "ps_plot ret %d != 0 (%s)\n", ret, symbol.errtxt); | |
| 290 | |
| 291 symbol.vector = NULL; | |
| 292 ret = ps_plot(&symbol, 0); | |
| 293 assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ps_plot ret %d != ZINT_ERROR_INVALID_DATA (%d) (%s)\n", ret, ZINT_ERROR_INVALID_DATA, symbol.errtxt); | |
| 294 | |
| 295 testFinish(); | |
| 296 } | |
| 297 | |
| 298 int main(int argc, char *argv[]) { | |
| 299 | |
| 300 testFunction funcs[] = { /* name, func */ | |
| 301 { "test_print", test_print }, | |
| 302 { "test_ps_convert", test_ps_convert }, | |
| 303 { "test_outfile", test_outfile }, | |
| 304 }; | |
| 305 | |
| 306 testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); | |
| 307 | |
| 308 testReport(); | |
| 309 | |
| 310 return 0; | |
| 311 } | |
| 312 | |
| 313 /* vim: set ts=4 sw=4 et : */ |
