test_output BMP/EMF/EPS/GIF/PCX/PNG/SVG/TIF: skip read-only test if root (ticket #274)

This commit is contained in:
gitlost 2022-12-06 15:09:06 +00:00
parent 831c704b7b
commit 2230c3a2ec
8 changed files with 88 additions and 40 deletions

View file

@ -231,6 +231,7 @@ static void test_print(const testCtx *const p_ctx) {
static void test_outfile(const testCtx *const p_ctx) {
int ret;
int skip_readonly_test = 0;
struct zint_symbol symbol = {0};
unsigned char data[] = { "1" };
@ -243,12 +244,17 @@ static void test_outfile(const testCtx *const p_ctx) {
symbol.bitmap_width = symbol.bitmap_height = 1;
strcpy(symbol.outfile, "test_bmp_out.bmp");
(void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */
assert_nonzero(testUtilCreateROFile(symbol.outfile), "bmp_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno));
#ifndef _WIN32
skip_readonly_test = getuid() == 0; /* Skip if running as root on Unix as can't create read-only file */
#endif
if (!skip_readonly_test) {
(void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */
assert_nonzero(testUtilCreateROFile(symbol.outfile), "bmp_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno));
ret = bmp_pixel_plot(&symbol, data);
assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "bmp_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt);
assert_zero(testUtilRmROFile(symbol.outfile), "bmp_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno));
ret = bmp_pixel_plot(&symbol, data);
assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "bmp_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt);
assert_zero(testUtilRmROFile(symbol.outfile), "bmp_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno));
}
symbol.output_options |= BARCODE_STDOUT;