CLI: fix batch mode fopen() -> win_fopen() (Windows)

GUI: fix `save_to_file()` `filename.toLatin1()` -> `toUtf8()`
tests: `fopen()` -> `testUtilOpen()`, `remove()` -> `testUtilRemove()`
  ticket #288, props Marcel
This commit is contained in:
gitlost 2023-05-10 21:29:09 +01:00
parent 15fdca2a03
commit dff534140a
26 changed files with 172 additions and 132 deletions

View File

@ -461,7 +461,7 @@ static void test_perf(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}

View File

@ -108,11 +108,11 @@ static void test_pixel_plot(const testCtx *const p_ctx) {
assert_zero(ret, "i:%d identify %s ret %d != 0\n", i, symbol->outfile, ret);
}
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
} else {
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
(void) remove(symbol->outfile);
(void) testUtilRemove(symbol->outfile);
}
}
@ -220,7 +220,7 @@ static void test_print(const testCtx *const p_ctx) {
ret = testUtilCmpBins(symbol->outfile, expected_file);
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
ZBarcode_Delete(symbol);

View File

@ -587,7 +587,7 @@ static void test_perf(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}

View File

@ -1178,7 +1178,7 @@ static void test_perf(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}

View File

@ -6850,7 +6850,7 @@ static void test_perf(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}

View File

@ -167,7 +167,7 @@ static void test_print(const testCtx *const p_ctx) {
ret = testUtilCmpBins(symbol->outfile, expected_file);
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
if (p_ctx->index == -1) assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
if (p_ctx->index == -1) assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
ZBarcode_Delete(symbol);

View File

@ -104,11 +104,11 @@ static void test_pixel_plot(const testCtx *const p_ctx) {
assert_zero(ret, "i:%d identify %s ret %d != 0\n", i, symbol->outfile, ret);
}
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
} else {
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
(void) remove(symbol->outfile);
(void) testUtilRemove(symbol->outfile);
}
}
@ -263,7 +263,7 @@ static void test_print(const testCtx *const p_ctx) {
ret = testUtilCmpBins(symbol->outfile, expected_file);
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
ZBarcode_Delete(symbol);
@ -332,7 +332,7 @@ static void test_large_scale(const testCtx *const p_ctx) {
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) { /* -d 64 */
/* 129.1 kB file manually inspected and checked (1.1 MB file for scale 70.0f also checked) */
assert_zero(remove(symbol.outfile), "remove(%s) != 0\n", symbol.outfile);
assert_zero(testUtilRemove(symbol.outfile), "testUtilRemove(%s) != 0\n", symbol.outfile);
}
ZBarcode_Clear(&symbol);

View File

@ -78,8 +78,8 @@ static void test_csv(const testCtx *const p_ctx) {
"/backend/tests/data/imail/usps/", "uspsIMbEncoderTestCases.csv"), "testUtilDataPath == 0\n");
for (j = 0; j < perf_iterations; j++) {
fd = fopen(csvfile, "r");
assert_nonnull(fd, "fopen(%s) == NULL", csvfile);
fd = testUtilOpen(csvfile, "r");
assert_nonnull(fd, "testUtilOpen(%s) == NULL", csvfile);
while (fgets(buffer, sizeof(buffer), fd) != NULL) {
const char *b;

View File

@ -616,8 +616,8 @@ static void test_escape_char_process(const testCtx *const p_ctx) {
FILE *fp;
struct zint_symbol *symbol2;
fp = fopen(input_filename, "wb");
assert_nonnull(fp, "i:%d fopen(%s) failed\n", i, input_filename);
fp = testUtilOpen(input_filename, "wb");
assert_nonnull(fp, "i:%d testUtilOpen(%s) failed\n", i, input_filename);
assert_notequal(fputs(data[i].data, fp), EOF, "i%d fputs(%s) failed == EOF (%d)\n", i, data[i].data, ferror(fp));
assert_zero(fclose(fp), "i%d fclose() failed\n", i);
@ -635,7 +635,7 @@ static void test_escape_char_process(const testCtx *const p_ctx) {
ret = testUtilSymbolCmp(symbol2, symbol);
assert_zero(ret, "i:%d testUtilSymbolCmp symbol2 ret %d != 0\n", i, ret);
assert_zero(remove(input_filename), "i:%d remove(%s) != 0 (%d: %s)\n", i, input_filename, errno, strerror(errno));
assert_zero(testUtilRemove(input_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input_filename, errno, strerror(errno));
ZBarcode_Delete(symbol2);
}
@ -789,18 +789,18 @@ static void test_encode_file_empty(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
(void) remove(filename); /* In case junk hanging around */
(void) testUtilRemove(filename); /* In case junk hanging around */
fstream = fopen(filename, "w+");
assert_nonnull(fstream, "fopen(%s) failed (%d)\n", filename, ferror(fstream));
fstream = testUtilOpen(filename, "w+");
assert_nonnull(fstream, "testUtilOpen(%s) failed (%d)\n", filename, ferror(fstream));
ret = fclose(fstream);
assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret);
ret = ZBarcode_Encode_File(symbol, filename);
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File empty ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt);
ret = remove(filename);
assert_zero(ret, "remove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
ret = testUtilRemove(filename);
assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
ZBarcode_Delete(symbol);
@ -821,10 +821,10 @@ static void test_encode_file_too_large(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
(void) remove(filename); /* In case junk hanging around */
(void) testUtilRemove(filename); /* In case junk hanging around */
fstream = fopen(filename, "w+");
assert_nonnull(fstream, "fopen(%s) failed (%d)\n", filename, ferror(fstream));
fstream = testUtilOpen(filename, "w+");
assert_nonnull(fstream, "testUtilOpen(%s) failed (%d)\n", filename, ferror(fstream));
ret = (int) fwrite(buf, 1, sizeof(buf), fstream);
assert_equal(ret, sizeof(buf), "fwrite return value: %d != %d\n", ret, (int)sizeof(buf));
ret = fclose(fstream);
@ -833,8 +833,8 @@ static void test_encode_file_too_large(const testCtx *const p_ctx) {
ret = ZBarcode_Encode_File(symbol, filename);
assert_equal(ret, ZINT_ERROR_TOO_LONG, "ZBarcode_Encode_File too large ret %d != ZINT_ERROR_TOO_LONG (%s)\n", ret, symbol->errtxt);
ret = remove(filename);
assert_zero(ret, "remove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
ret = testUtilRemove(filename);
assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
ZBarcode_Delete(symbol);
@ -878,8 +878,8 @@ static void test_encode_file_unreadable(const testCtx *const p_ctx) {
ret = ZBarcode_Encode_File(symbol, filename);
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File unreadable ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt);
ret = remove(filename);
assert_zero(ret, "remove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
ret = testUtilRemove(filename);
assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
ZBarcode_Delete(symbol);
@ -927,11 +927,11 @@ static void test_encode_file(const testCtx *const p_ctx) {
testStart("test_encode_file");
(void) remove(filename); /* In case junk hanging around */
(void) remove(outfile); /* In case junk hanging around */
(void) testUtilRemove(filename); /* In case junk hanging around */
(void) testUtilRemove(outfile); /* In case junk hanging around */
fp = fopen(filename, "w+");
assert_nonnull(fp, "fopen(%s) failed (%d)\n", filename, ferror(fp));
fp = testUtilOpen(filename, "w+");
assert_nonnull(fp, "testUtilOpen(%s) failed (%d)\n", filename, ferror(fp));
assert_notequal(fputs(data, fp), EOF, "fputs(%s) failed == EOF (%d)\n", data, ferror(fp));
ret = fclose(fp);
assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret);
@ -944,8 +944,8 @@ static void test_encode_file(const testCtx *const p_ctx) {
ret = ZBarcode_Encode_File_and_Print(symbol, filename, 0);
assert_zero(ret, "ret %d != 0 (%s)\n", ret, symbol->errtxt);
ret = remove(outfile);
assert_zero(ret, "remove(%s) != 0 (%d: %s)\n", outfile, errno, strerror(errno));
ret = testUtilRemove(outfile);
assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", outfile, errno, strerror(errno));
ZBarcode_Delete(symbol);
}
@ -974,8 +974,8 @@ static void test_encode_file(const testCtx *const p_ctx) {
ZBarcode_Delete(symbol);
}
ret = remove(filename);
assert_zero(ret, "remove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
ret = testUtilRemove(filename);
assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
testFinish();
}

View File

@ -134,7 +134,7 @@ static void test_print(const testCtx *const p_ctx) {
ret = testUtilCmpBins(symbol->outfile, expected_file);
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
ZBarcode_Delete(symbol);

View File

@ -5618,7 +5618,7 @@ static void test_perf(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
@ -5678,7 +5678,7 @@ static void test_perf(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}

View File

@ -405,7 +405,7 @@ static void test_perf(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}

View File

@ -102,11 +102,11 @@ static void test_pixel_plot(const testCtx *const p_ctx) {
assert_zero(ret, "i:%d identify %s ret %d != 0\n", i, symbol->outfile, ret);
}
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
} else {
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
(void) remove(symbol->outfile);
(void) testUtilRemove(symbol->outfile);
}
}
@ -303,7 +303,7 @@ static void test_print(const testCtx *const p_ctx) {
assert_zero(ret, "i:%d %s testUtilCmpPngs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
ret = testUtilCmpBins(symbol->outfile, expected_file);
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
ZBarcode_Delete(symbol);
@ -374,15 +374,15 @@ static void test_wpng_error_handler(const testCtx *const p_ctx) {
wpng_error.symbol = &symbol;
/* Create empty file */
(void) remove(filename); /* In case junk hanging around */
fp = fopen(filename, "w+");
assert_nonnull(fp, "fopen(%s) failed\n", filename);
(void) testUtilRemove(filename); /* In case junk hanging around */
fp = testUtilOpen(filename, "w+");
assert_nonnull(fp, "testUtilOpen(%s) failed\n", filename);
ret = fclose(fp);
assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret);
/* Re-open for read, which will cause libpng to error */
fp = fopen(filename, "r");
assert_nonnull(fp, "fopen(%s) for read failed\n", filename);
fp = testUtilOpen(filename, "r");
assert_nonnull(fp, "testUtilOpen(%s) for read failed\n", filename);
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, &wpng_error, wpng_error_handler_test, NULL);
assert_nonnull(png_ptr, "png_create_write_struct failed\n");
@ -395,7 +395,7 @@ static void test_wpng_error_handler(const testCtx *const p_ctx) {
ret = fclose(fp);
assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret);
assert_nonnull(strstr(symbol.errtxt, "635: libpng error:"), "strstr(%s) NULL\n", symbol.errtxt);
assert_zero(remove(filename), "remove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
assert_zero(testUtilRemove(filename), "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
} else {
png_init_io(png_ptr, fp);
@ -429,7 +429,7 @@ static void test_large_compliant_height(const testCtx *const p_ctx) {
ret = ZBarcode_Encode_and_Print(symbol, (const unsigned char *) data_buf, codablockf_max, 0);
assert_zero(ret, "ZBarcode_Encode_and_Print ret %d != 0 (%s)\n", ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "remove(%s) != 0\n", symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "testUtilRemove(%s) != 0\n", symbol->outfile);
ZBarcode_Delete(symbol);

View File

@ -611,7 +611,7 @@ static void test_perf(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}

View File

@ -204,7 +204,7 @@ static void test_print(const testCtx *const p_ctx) {
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
}
if (p_ctx->index == -1) assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
if (p_ctx->index == -1) assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
ZBarcode_Delete(symbol);

View File

@ -173,7 +173,7 @@ static void test_print(const testCtx *const p_ctx) {
ret = testUtilCmpEpss(symbol->outfile, expected_file);
assert_zero(ret, "i:%d %s testUtilCmpEpss(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
ZBarcode_Delete(symbol);

View File

@ -1020,7 +1020,7 @@ static void test_draw_string_wrap(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d ZBarcode_Print(%d) ret %d != 0\n", i, data[i].symbology, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
text_bits_set = 0;
row = data[i].expected_no_text_row;
@ -1090,7 +1090,7 @@ static void test_code128_utf8(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d ZBarcode_Print(%d) ret %d != 0\n", i, BARCODE_CODE128, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
text_bits_set = 0;
row = data[i].expected_text_row;
@ -1271,7 +1271,7 @@ static void test_scale(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0);
assert_equal(ret, data[i].ret_raster, "i:%d ZBarcode_Print(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret_raster, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
assert_nonzero(symbol->bitmap_height >= data[i].expected_set_rows, "i:%d (%d) symbol->bitmap_height %d < expected_set_rows %d\n",
i, data[i].symbology, symbol->bitmap_height, data[i].expected_set_rows);
@ -1383,7 +1383,7 @@ static void test_guard_descent(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0);
assert_equal(ret, data[i].ret_raster, "i:%d ZBarcode_Print(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret_raster, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
assert_nonzero(symbol->bitmap_height >= data[i].expected_set_rows, "i:%d (%d) symbol->bitmap_height %d < expected_set_rows %d\n",
i, data[i].symbology, symbol->bitmap_height, data[i].expected_set_rows);
@ -1762,7 +1762,7 @@ static void test_quiet_zones(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0);
assert_equal(ret, data[i].ret_raster, "i:%d ZBarcode_Print(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret_raster, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
assert_nonzero(symbol->bitmap_height >= data[i].expected_set_rows, "i:%d (%d) symbol->bitmap_height %d < expected_set_rows %d\n",
i, data[i].symbology, symbol->bitmap_height, data[i].expected_set_rows);
@ -1917,7 +1917,7 @@ static void test_text_gap(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Print(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
assert_nonzero(symbol->bitmap_height >= data[i].expected_set_rows, "i:%d (%d) symbol->bitmap_height %d < expected_set_rows %d\n",
i, data[i].symbology, symbol->bitmap_height, data[i].expected_set_rows);
@ -3098,7 +3098,7 @@ static void test_perf_scale(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}

View File

@ -211,7 +211,7 @@ static void test_print(const testCtx *const p_ctx) {
ret = testUtilCmpSvgs(symbol->outfile, expected_file);
assert_zero(ret, "i:%d %s testUtilCmpSvgs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
ZBarcode_Delete(symbol);

View File

@ -141,11 +141,11 @@ static void test_pixel_plot(const testCtx *const p_ctx) {
}
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
} else {
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
(void) remove(symbol->outfile);
(void) testUtilRemove(symbol->outfile);
}
}
@ -299,7 +299,7 @@ static void test_print(const testCtx *const p_ctx) {
ret = testUtilCmpBins(symbol->outfile, expected_file);
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
ZBarcode_Delete(symbol);

View File

@ -184,7 +184,7 @@ static void test_upca_print(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
@ -1124,7 +1124,7 @@ static void test_perf(const testCtx *const p_ctx) {
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}

View File

@ -37,6 +37,7 @@
#ifdef _WIN32
#include <windows.h>
#include <direct.h>
#include <wchar.h>
#endif
#ifndef ZINT_NO_PNG
#include <png.h>
@ -1334,13 +1335,19 @@ int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const ch
return 1;
}
/* Open a file (Windows compatibility) */
FILE *testUtilOpen(const char *filename, const char *mode) {
#ifdef _WIN32
FILE *fp = out_win_fopen(filename, mode);
#else
FILE *fp = fopen(filename, mode);
#endif
return fp;
}
/* Does file exist? */
int testUtilExists(const char *filename) {
#ifdef _WIN32
FILE *fp = out_win_fopen(filename, "r");
#else
FILE *fp = fopen(filename, "r");
#endif
FILE *fp = testUtilOpen(filename, "r");
if (fp == NULL) {
return 0;
}
@ -1396,7 +1403,7 @@ int testUtilRmDir(const char *dirname) {
/* Rename a file (Windows compatibility) */
int testUtilRename(const char *oldpath, const char *newpath) {
#ifdef _MSVC
#ifdef _WIN32
wchar_t *oldpathW, *newpathW;
int ret = testUtilRemove(newpath);
if (ret != 0) return ret;
@ -1412,10 +1419,8 @@ int testUtilRename(const char *oldpath, const char *newpath) {
int testUtilCreateROFile(const char *filename) {
#ifdef _WIN32
wchar_t *filenameW;
FILE *fp = out_win_fopen(filename, "w+");
#else
FILE *fp = fopen(filename, "w+");
#endif
FILE *fp = testUtilOpen(filename, "w+");
if (fp == NULL) {
return 0;
}
@ -1464,11 +1469,11 @@ int testUtilCmpPngs(const char *png1, const char *png2) {
size_t rowbytes1, rowbytes2;
int r;
fp1 = fopen(png1, "rb");
fp1 = testUtilOpen(png1, "rb");
if (!fp1) {
return 2;
}
fp2 = fopen(png2, "rb");
fp2 = testUtilOpen(png2, "rb");
if (!fp2) {
fclose(fp1);
return 3;
@ -1654,11 +1659,11 @@ int testUtilCmpTxts(const char *txt1, const char *txt2) {
char buf2[1024];
size_t len1 = 0, len2 = 0;
fp1 = fopen(txt1, "r");
fp1 = testUtilOpen(txt1, "r");
if (!fp1) {
return 2;
}
fp2 = fopen(txt2, "r");
fp2 = testUtilOpen(txt2, "r");
if (!fp2) {
fclose(fp1);
return 3;
@ -1705,11 +1710,11 @@ int testUtilCmpBins(const char *bin1, const char *bin2) {
char buf2[1024];
size_t len1 = 0, len2 = 0;
fp1 = fopen(bin1, "rb");
fp1 = testUtilOpen(bin1, "rb");
if (!fp1) {
return 2;
}
fp2 = fopen(bin2, "rb");
fp2 = testUtilOpen(bin2, "rb");
if (!fp2) {
fclose(fp1);
return 3;
@ -1753,11 +1758,11 @@ int testUtilCmpEpss(const char *eps1, const char *eps2) {
static char first_line[] = "%!PS-Adobe-3.0 EPSF-3.0\n";
static char second_line_start[] = "%%Creator: Zint ";
fp1 = fopen(eps1, "r");
fp1 = testUtilOpen(eps1, "r");
if (!fp1) {
return 2;
}
fp2 = fopen(eps2, "r");
fp2 = testUtilOpen(eps2, "r");
if (!fp2) {
fclose(fp1);
return 3;
@ -1896,7 +1901,7 @@ int testUtilVerifyLibreOffice(const char *filename, int debug) {
return -1;
}
fp = fopen(svg, "r");
fp = testUtilOpen(svg, "r");
if (!fp) {
fprintf(stderr, "testUtilVerifyLibreOffice: failed to open '%s' (%s)\n", svg, cmd);
return -1;
@ -1923,7 +1928,7 @@ int testUtilVerifyLibreOffice(const char *filename, int debug) {
if (strstr(buf, "x=\"-32767\"") != NULL) {
return -1;
}
remove(svg);
testUtilRemove(svg);
return 0;
}

View File

@ -159,6 +159,7 @@ void testUtilBitmapPrint(const struct zint_symbol *symbol, const char *prefix, c
int testUtilBitmapCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *column);
int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const char *filename);
FILE *testUtilOpen(const char *filename, const char *mode);
int testUtilExists(const char *filename);
int testUtilRemove(const char *filename);
int testUtilDirExists(const char *dirname);

View File

@ -844,7 +844,7 @@ namespace Zint {
bool QZint::save_to_file(const QString& filename) {
if (resetSymbol()) {
strcpy(m_zintSymbol->outfile, filename.toLatin1().left(255));
strcpy(m_zintSymbol->outfile, filename.toUtf8().left(255));
if (m_segs.empty()) {
QByteArray bstr = m_text.toUtf8();
m_error = ZBarcode_Encode_and_Print(m_zintSymbol, (unsigned char *) bstr.data(), bstr.length(),

View File

@ -484,6 +484,10 @@ private slots:
QTest::newRow("BARCODE_DATAMATRIX gif") << BARCODE_DATAMATRIX << "1234" << "test_save_to_file.gif" << true;
QTest::newRow("BARCODE_DATAMATRIX unknown format") << BARCODE_DATAMATRIX << "1234" << "test_save_to_file.ext" << false;
QTest::newRow("BARCODE_DATAMATRIX UTF8 gif") << BARCODE_DATAMATRIX << "1234" << "test_save_to_file_τ.gif" << true;
QTest::newRow("BARCODE_DATAMATRIX too long (unknown format)") << BARCODE_DATAMATRIX << "1234"
<< "test_6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.gif" // 256 long so should be truncated to end in ".gi"
<< false;
}
void saveToFileTest()
@ -491,7 +495,6 @@ private slots:
Zint::QZint bc;
bool bRet;
int ret;
QFETCH(int, symbology);
QFETCH(QString, text);
@ -505,8 +508,8 @@ private slots:
QCOMPARE(bRet, expected_bRet);
if (bRet) {
ret = remove(fileName.toLatin1());
QCOMPARE(ret, 0);
bRet = QFile::remove(fileName);
QCOMPARE(bRet, true);
}
}

View File

@ -834,6 +834,10 @@ static int validate_seg(const char *optarg, const int N, struct zint_seg segs[10
return 1;
}
#ifdef _WIN32
static FILE *win_fopen(const char *filename, const char *mode); /* Forward ref */
#endif
/* Batch mode - output symbol for each line of text in `filename` */
static int batch_process(struct zint_symbol *symbol, const char *filename, const int mirror_mode,
const char *filetype, const int output_given, const int rotate_angle) {
@ -884,7 +888,11 @@ static int batch_process(struct zint_symbol *symbol, const char *filename, const
if (strcmp(filename, "-") == 0) {
file = stdin;
} else {
#ifdef _WIN32
file = win_fopen(filename, "rb");
#else
file = fopen(filename, "rb");
#endif
if (!file) {
fprintf(stderr, "Error 102: Unable to read input file '%s'\n", filename);
fflush(stderr);
@ -1120,6 +1128,25 @@ static void win_args(int *p_argc, char ***p_argv) {
}
}
}
/* Convert UTF-8 to Windows wide chars. Ticket #288, props Marcel */
#define utf8_to_wide(u, w, r) \
{ \
int lenW; /* Includes NUL terminator */ \
if ((lenW = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, u, -1, NULL, 0)) == 0) return r; \
w = (wchar_t *) z_alloca(sizeof(wchar_t) * lenW); \
if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, u, -1, w, lenW) == 0) return r; \
}
/* Do `fopen()` on Windows, assuming `filename` is UTF-8 encoded. Ticket #288, props Marcel */
static FILE *win_fopen(const char *filename, const char *mode) {
wchar_t *filenameW, *modeW;
utf8_to_wide(filename, filenameW, NULL);
utf8_to_wide(mode, modeW, NULL);
return _wfopen(filenameW, modeW);
}
#endif /* _WIN32 */
/* Helper to free Windows args on exit */

View File

@ -185,7 +185,7 @@ static int arg_input(char *cmd, const char *filename, const char *input) {
int cnt;
if (input != NULL) {
if (strcmp(input, "-") != 0) {
fp = fopen(filename, "wb");
fp = testUtilOpen(filename, "wb");
if (!fp) {
fprintf(stderr, "arg_input: failed to open '%s' for writing\n", filename);
return 0;
@ -398,10 +398,10 @@ static void test_dump_args(const testCtx *const p_ctx) {
assert_zero(strcmp(buf, data[i].expected), "i:%d buf (%s) != expected (%s) (%s)\n", i, buf, data[i].expected, cmd);
if (have_input1) {
assert_zero(remove(input1_filename), "i:%d remove(%s) != 0 (%d: %s)\n", i, input1_filename, errno, strerror(errno));
assert_zero(testUtilRemove(input1_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input1_filename, errno, strerror(errno));
}
if (have_input2) {
assert_zero(remove(input2_filename), "i:%d remove(%s) != 0 (%d: %s)\n", i, input2_filename, errno, strerror(errno));
assert_zero(testUtilRemove(input2_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input2_filename, errno, strerror(errno));
}
}
@ -500,6 +500,7 @@ static void test_input(const testCtx *const p_ctx) {
int input_mode;
int mirror;
char *filetype;
char *input_filename;
char *input;
char *outfile;
@ -508,33 +509,35 @@ static void test_input(const testCtx *const p_ctx) {
};
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = {
/* 0*/ { BARCODE_CODE128, 1, -1, 0, "gif", "123\n456\n", "", 2, "00001.gif\00000002.gif" },
/* 1*/ { BARCODE_CODE128, 1, -1, 0, "gif", "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", "~~~.gif", 10, "001.gif\000002.gif\000003.gif\000004.gif\000005.gif\000006.gif\000007.gif\000008.gif\000009.gif\000010.gif" },
/* 2*/ { BARCODE_CODE128, 1, -1, 0, "gif", "123\n456\n", "@@@@.gif", 2, TEST_INPUT_AMPERSAND_EXPECTED },
/* 3*/ { BARCODE_CODE128, 1, -1, 0, "gif", "123\n456\n789\n", "#####.gif", 3, " 1.gif\000 2.gif\000 3.gif" },
/* 4*/ { BARCODE_CODE128, 1, -1, 0, "gif", "123\n456\n", "test_batch~.gif", 2, "test_batch1.gif\000test_batch2.gif" },
/* 5*/ { BARCODE_CODE128, 1, -1, 1, "gif", "123\n456\n7890123456789\n", NULL, 3, "123.gif\000456.gif\0007890123456789.gif" },
/* 6*/ { BARCODE_CODE128, 1, -1, 1, "gif", "123\n456\n7890123456789\n", "test_input_dir/", 3, "test_input_dir/123.gif\000test_input_dir/456.gif\000test_input_dir/7890123456789.gif" },
/* 7*/ { BARCODE_CODE128, 1, -1, 1, "svg", "123\n456\n7890123456789\n", NULL, 3, "123.svg\000456.svg\0007890123456789.svg" },
/* 8*/ { BARCODE_CODE128, 1, -1, 1, "gif", "123\n456\n7890123456789\nA\\xA0B\n", NULL, 4, "123.gif\000456.gif\0007890123456789.gif\000A_xA0B.gif" },
/* 9*/ { BARCODE_CODE128, 1, ESCAPE_MODE, 1, "gif", "123\n456\n7890123456789\nA\\xA0B\n", NULL, 4, "123.gif\000456.gif\0007890123456789.gif\000A_B.gif" },
/* 10*/ { BARCODE_CODE128, 1, -1, 1, "gif", "123\n456\n7890123456789\nA\\u00A0B\n", NULL, 4, "123.gif\000456.gif\0007890123456789.gif\000A_u00A0B.gif" },
/* 11*/ { BARCODE_CODE128, 1, ESCAPE_MODE, 1, "gif", "123\n456\n7890123456789\nA\\u00A0B\n", NULL, 4, "123.gif\000456.gif\0007890123456789.gif\000A_B.gif" },
/* 12*/ { BARCODE_CODE128, 1, -1, 1, "gif", "1!2\"3*\n/:45<6>\n?7890\\\\12345|6789\177\nA\\U0000A0B\n", NULL, 4, "1_2_3_.gif\000__45_6_.gif\000_7890__12345_6789_.gif\000A_U0000A0B.gif" },
/* 13*/ { BARCODE_CODE128, 1, ESCAPE_MODE, 1, "gif", "!\"*\n/:45<6>\n?7890\\\\12345|6789\177\nA\\U0000A0B\n", NULL, 4, "___.gif\000__45_6_.gif\000_7890_12345_6789_.gif\000A_B.gif" },
/* 14*/ { BARCODE_CODE128, 1, -1, 1, "gif", "1\\d123*9\n\\o1234:5\n#$%&'()+,-.;=@[]^`{}\n", NULL, 3, "1_d123_9.gif\000_o1234_5.gif\000#$%&'()+,-.;=@[]^`{}.gif" },
/* 15*/ { BARCODE_CODE128, 1, ESCAPE_MODE, 1, "gif", "1\\d123*2\n\\o1234:5\n#$%&'()+,-.;=@[]^`{}\n", NULL, 3, "1__2.gif\000_4_5.gif\000#$%&'()+,-.;=@[]^`{}.gif" },
/* 16*/ { BARCODE_CODE128, 1, -1, 0, "gif", "\n", "test_batch.gif", 0, NULL },
/* 17*/ { BARCODE_CODE128, 1, -1, 0, "gif", "123\n456\n", TEST_INPUT_LONG "~.gif", 2, TEST_INPUT_LONG "1.gif\000" TEST_INPUT_LONG "2.gif" },
/* 18*/ { BARCODE_CODE128, 0, -1, 0, "svg", "123", TEST_INPUT_LONG "1.gif", 1, TEST_INPUT_LONG "1.svg" },
/* 19*/ { BARCODE_CODE128, 1, -1, 0, "svg", "123\n", TEST_INPUT_LONG "1.gif", 1, TEST_INPUT_LONG "1.svg" },
/* 20*/ { BARCODE_CODE128, 1, -1, 0, "gif", "123\n", "test_batch.jpeg", 1, "test_batch.jpeg.gif" },
/* 21*/ { BARCODE_CODE128, 1, -1, 0, "gif", "123\n", "test_batch.jpg", 1, "test_batch.gif" },
/* 22*/ { BARCODE_CODE128, 1, -1, 0, "emf", "123\n", "test_batch.jpeg", 1, "test_batch.jpeg.emf" },
/* 23*/ { BARCODE_CODE128, 1, -1, 0, "emf", "123\n", "test_batch.jpg", 1, "test_batch.emf" },
/* 24*/ { BARCODE_CODE128, 1, -1, 0, "eps", "123\n", "test_batch.ps", 1, "test_batch.eps" },
/* 25*/ { BARCODE_CODE128, 1, -1, 1, "gif", "1234567890123456789012345678901\n1234567890123456789012345678902\n", TEST_MIRRORED_DIR_LONG, 2, TEST_MIRRORED_DIR_LONG "1234567890123456789012345678901.gif\000" TEST_MIRRORED_DIR_LONG "1234567890123456789012345678902.gif" },
/* 26*/ { BARCODE_CODE128, 1, -1, 1, "gif", "123\n456\n", TEST_MIRRORED_DIR_TOO_LONG, 2, "123.gif\000456.gif" },
/* 0*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n456\n", "", 2, "00001.gif\00000002.gif" },
/* 1*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", "~~~.gif", 10, "001.gif\000002.gif\000003.gif\000004.gif\000005.gif\000006.gif\000007.gif\000008.gif\000009.gif\000010.gif" },
/* 2*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n456\n", "@@@@.gif", 2, TEST_INPUT_AMPERSAND_EXPECTED },
/* 3*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n456\n789\n", "#####.gif", 3, " 1.gif\000 2.gif\000 3.gif" },
/* 4*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n456\n", "test_batch~.gif", 2, "test_batch1.gif\000test_batch2.gif" },
/* 5*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "123\n456\n7890123456789\n", NULL, 3, "123.gif\000456.gif\0007890123456789.gif" },
/* 6*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "123\n456\n7890123456789\n", "test_input_dir/", 3, "test_input_dir/123.gif\000test_input_dir/456.gif\000test_input_dir/7890123456789.gif" },
/* 7*/ { BARCODE_CODE128, 1, -1, 1, "svg", NULL, "123\n456\n7890123456789\n", NULL, 3, "123.svg\000456.svg\0007890123456789.svg" },
/* 8*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "123\n456\n7890123456789\nA\\xA0B\n", NULL, 4, "123.gif\000456.gif\0007890123456789.gif\000A_xA0B.gif" },
/* 9*/ { BARCODE_CODE128, 1, ESCAPE_MODE, 1, "gif", NULL, "123\n456\n7890123456789\nA\\xA0B\n", NULL, 4, "123.gif\000456.gif\0007890123456789.gif\000A_B.gif" },
/* 10*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "123\n456\n7890123456789\nA\\u00A0B\n", NULL, 4, "123.gif\000456.gif\0007890123456789.gif\000A_u00A0B.gif" },
/* 11*/ { BARCODE_CODE128, 1, ESCAPE_MODE, 1, "gif", NULL, "123\n456\n7890123456789\nA\\u00A0B\n", NULL, 4, "123.gif\000456.gif\0007890123456789.gif\000A_B.gif" },
/* 12*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "1!2\"3*\n/:45<6>\n?7890\\\\12345|6789\177\nA\\U0000A0B\n", NULL, 4, "1_2_3_.gif\000__45_6_.gif\000_7890__12345_6789_.gif\000A_U0000A0B.gif" },
/* 13*/ { BARCODE_CODE128, 1, ESCAPE_MODE, 1, "gif", NULL, "!\"*\n/:45<6>\n?7890\\\\12345|6789\177\nA\\U0000A0B\n", NULL, 4, "___.gif\000__45_6_.gif\000_7890_12345_6789_.gif\000A_B.gif" },
/* 14*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "1\\d123*9\n\\o1234:5\n#$%&'()+,-.;=@[]^`{}\n", NULL, 3, "1_d123_9.gif\000_o1234_5.gif\000#$%&'()+,-.;=@[]^`{}.gif" },
/* 15*/ { BARCODE_CODE128, 1, ESCAPE_MODE, 1, "gif", NULL, "1\\d123*2\n\\o1234:5\n#$%&'()+,-.;=@[]^`{}\n", NULL, 3, "1__2.gif\000_4_5.gif\000#$%&'()+,-.;=@[]^`{}.gif" },
/* 16*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "\n", "test_batch.gif", 0, NULL },
/* 17*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n456\n", TEST_INPUT_LONG "~.gif", 2, TEST_INPUT_LONG "1.gif\000" TEST_INPUT_LONG "2.gif" },
/* 18*/ { BARCODE_CODE128, 0, -1, 0, "svg", NULL, "123", TEST_INPUT_LONG "1.gif", 1, TEST_INPUT_LONG "1.svg" },
/* 19*/ { BARCODE_CODE128, 1, -1, 0, "svg", NULL, "123\n", TEST_INPUT_LONG "1.gif", 1, TEST_INPUT_LONG "1.svg" },
/* 20*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n", "test_batch.jpeg", 1, "test_batch.jpeg.gif" },
/* 21*/ { BARCODE_CODE128, 1, -1, 0, "gif", NULL, "123\n", "test_batch.jpg", 1, "test_batch.gif" },
/* 22*/ { BARCODE_CODE128, 1, -1, 0, "emf", NULL, "123\n", "test_batch.jpeg", 1, "test_batch.jpeg.emf" },
/* 23*/ { BARCODE_CODE128, 1, -1, 0, "emf", NULL, "123\n", "test_batch.jpg", 1, "test_batch.emf" },
/* 24*/ { BARCODE_CODE128, 1, -1, 0, "eps", NULL, "123\n", "test_batch.ps", 1, "test_batch.eps" },
/* 25*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "1234567890123456789012345678901\n1234567890123456789012345678902\n", TEST_MIRRORED_DIR_LONG, 2, TEST_MIRRORED_DIR_LONG "1234567890123456789012345678901.gif\000" TEST_MIRRORED_DIR_LONG "1234567890123456789012345678902.gif" },
/* 26*/ { BARCODE_CODE128, 1, -1, 1, "gif", NULL, "123\n456\n", TEST_MIRRORED_DIR_TOO_LONG, 2, "123.gif\000456.gif" },
/* 27*/ { BARCODE_CODE128, 1, -1, 0, "gif", "testé_input.txt", "123\n456\n", "", 2, "00001.gif\00000002.gif" },
/* 28*/ { BARCODE_CODE128, 1, -1, 0, "gif", "testก_input.txt", "123\n456\n", "test_input_δir/testé~~~.gif", 2, "test_input_δir/testé001.gif\000test_input_δir/testé002.gif" },
};
int data_size = ARRAY_SIZE(data);
int i;
@ -542,7 +545,7 @@ static void test_input(const testCtx *const p_ctx) {
char cmd[4096];
char buf[4096];
char *input_filename = "test_input.txt";
char *input_filename;
char *outfile;
testStart("test_input");
@ -568,6 +571,7 @@ static void test_input(const testCtx *const p_ctx) {
arg_input_mode(cmd, data[i].input_mode);
arg_bool(cmd, "--mirror", data[i].mirror);
arg_data(cmd, "--filetype=", data[i].filetype);
input_filename = data[i].input_filename ? data[i].input_filename : "test_input.txt";
arg_input(cmd, input_filename, data[i].input);
arg_data(cmd, "-o ", data[i].outfile);
@ -581,11 +585,11 @@ static void test_input(const testCtx *const p_ctx) {
outfile = data[i].expected;
for (j = 0; j < data[i].num_expected; j++) {
assert_nonzero(testUtilExists(outfile), "i:%d j:%d testUtilExists(%s) != 1\n", i, j, outfile);
assert_zero(remove(outfile), "i:%d j:%d remove(%s) != 0 (%d: %s)\n", i, j, outfile, errno, strerror(errno));
assert_zero(testUtilRemove(outfile), "i:%d j:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, j, outfile, errno, strerror(errno));
outfile += strlen(outfile) + 1;
}
assert_zero(remove(input_filename), "i:%d remove(%s) != 0 (%d: %s)\n", i, input_filename, errno, strerror(errno));
assert_zero(testUtilRemove(input_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input_filename, errno, strerror(errno));
if (data[i].batch && data[i].mirror && data[i].outfile && data[i].outfile[0] && strcmp(data[i].outfile, TEST_MIRRORED_DIR_TOO_LONG) != 0) {
assert_zero(testUtilRmDir(data[i].outfile), "i:%d testUtilRmDir(%s) != 0 (%d: %s)\n", i, data[i].outfile, errno, strerror(errno));
}
@ -633,7 +637,7 @@ static void test_stdin_input(const testCtx *const p_ctx) {
assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
assert_nonzero(testUtilExists(data[i].outfile), "i:%d testUtilExists(%s) != 1\n", i, data[i].outfile);
assert_zero(remove(data[i].outfile), "i:%d remove(%s) != 0 (%d: %s)\n", i, data[i].outfile, errno, strerror(errno));
assert_zero(testUtilRemove(data[i].outfile), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, data[i].outfile, errno, strerror(errno));
}
testFinish();
@ -690,10 +694,10 @@ static void test_batch_input(const testCtx *const p_ctx) {
assert_zero(strcmp(buf, data[i].expected), "i:%d buf (%s) != expected (%s)\n", i, buf, data[i].expected);
if (have_input1) {
assert_zero(remove(input1_filename), "i:%d remove(%s) != 0 (%d: %s)\n", i, input1_filename, errno, strerror(errno));
assert_zero(testUtilRemove(input1_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input1_filename, errno, strerror(errno));
}
if (have_input2) {
assert_zero(remove(input2_filename), "i:%d remove(%s) != 0 (%d: %s)\n", i, input2_filename, errno, strerror(errno));
assert_zero(testUtilRemove(input2_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input2_filename, errno, strerror(errno));
}
}
@ -753,13 +757,13 @@ static void test_batch_large(const testCtx *const p_ctx) {
if (!data[i].expected) printf("++++ Following Error 541 expected, ignore\n");
assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
if (data[i].expected) {
assert_zero(remove(data[i].expected), "i:%d remove(%s) != 0 (%d: %s)\n", i, data[i].expected, errno, strerror(errno));
assert_zero(testUtilRemove(data[i].expected), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, data[i].expected, errno, strerror(errno));
} else {
assert_zero(testUtilExists("out.gif"), "i:%d testUtilExists(out.gif) != 0 (%d: %s) (%s)\n", i, errno, strerror(errno), cmd);
}
if (have_input) {
assert_zero(remove(input_filename), "i:%d remove(%s) != 0 (%d: %s)\n", i, input_filename, errno, strerror(errno));
assert_zero(testUtilRemove(input_filename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, input_filename, errno, strerror(errno));
}
}
@ -881,7 +885,7 @@ static void test_checks(const testCtx *const p_ctx) {
assert_zero(strcmp(buf, data[i].expected), "i:%d buf (%s) != expected (%s) (%s)\n", i, buf, data[i].expected, cmd);
if (strncmp(data[i].expected, "Warning", 7) == 0) {
assert_zero(remove(outfilename), "i:%d remove(%s) != 0 (%d: %s)\n", i, outfilename, errno, strerror(errno));
assert_zero(testUtilRemove(outfilename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, outfilename, errno, strerror(errno));
}
}
@ -1128,7 +1132,7 @@ static void test_barcode_symbology(const testCtx *const p_ctx) {
assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, NULL), "i:%d exec(%s) NULL\n", i, cmd);
if (!data[i].fail) {
assert_zero(remove(outfilename), "i:%d remove(%s) != 0 (%d: %s) (%s)\n", i, outfilename, errno, strerror(errno), cmd);
assert_zero(testUtilRemove(outfilename), "i:%d testUtilRemove(%s) != 0 (%d: %s) (%s)\n", i, outfilename, errno, strerror(errno), cmd);
}
assert_nonnull(strstr(buf, data[i].expected), "i:%d strstr(%s, %s) == NULL (%s)\n", i, buf, data[i].expected, cmd);
}
@ -1248,7 +1252,7 @@ static void test_other_opts(const testCtx *const p_ctx) {
} else {
assert_zero(strcmp(buf, data[i].expected), "i:%d strcmp buf (%s) != expected (%s) (%s)\n", i, buf, data[i].expected, cmd);
if (strstr(data[i].expected, "Error") == NULL) {
assert_zero(remove(outfilename), "i:%d remove(%s) != 0 (%d: %s)\n", i, outfilename, errno, strerror(errno));
assert_zero(testUtilRemove(outfilename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, outfilename, errno, strerror(errno));
}
}
}
@ -1310,7 +1314,7 @@ static void test_exit_status(const testCtx *const p_ctx) {
assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i, &exit_status), "i:%d exec(%s) NULL\n", i, cmd);
assert_equal(exit_status, data[i].expected, "i:%d exit_status %d != expected (%d) (%s), (cmd: %s)\n", i, exit_status, data[i].expected, buf, cmd);
if (data[i].expected < ZINT_ERROR) {
assert_zero(remove(outfilename), "i:%d remove(%s) != 0 (%d: %s)\n", i, outfilename, errno, strerror(errno));
assert_zero(testUtilRemove(outfilename), "i:%d testUtilRemove(%s) != 0 (%d: %s)\n", i, outfilename, errno, strerror(errno));
}
}