diff --git a/backend/tests/test_bmp.c b/backend/tests/test_bmp.c index 6cd6fd43..76508479 100644 --- a/backend/tests/test_bmp.c +++ b/backend/tests/test_bmp.c @@ -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; diff --git a/backend/tests/test_emf.c b/backend/tests/test_emf.c index be931d74..43b6b49e 100644 --- a/backend/tests/test_emf.c +++ b/backend/tests/test_emf.c @@ -178,6 +178,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle); static void test_outfile(const testCtx *const p_ctx) { int ret; + int skip_readonly_test = 0; struct zint_symbol symbol = {0}; struct zint_vector vector = {0}; @@ -189,12 +190,17 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.vector = &vector; strcpy(symbol.outfile, "test_emf_out.emf"); - (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ - assert_nonzero(testUtilCreateROFile(symbol.outfile), "emf_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), "emf_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = emf_plot(&symbol, 0); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "emf_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "emf_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + ret = emf_plot(&symbol, 0); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "emf_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); + assert_zero(testUtilRmROFile(symbol.outfile), "emf_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + } symbol.output_options |= BARCODE_STDOUT; diff --git a/backend/tests/test_gif.c b/backend/tests/test_gif.c index e990f9f1..d4033da2 100644 --- a/backend/tests/test_gif.c +++ b/backend/tests/test_gif.c @@ -271,6 +271,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" }; @@ -283,12 +284,17 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.bitmap_width = symbol.bitmap_height = 1; strcpy(symbol.outfile, "test_gif_out.gif"); - (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ - assert_nonzero(testUtilCreateROFile(symbol.outfile), "gif_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), "gif_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = gif_pixel_plot(&symbol, data); - 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); - assert_zero(testUtilRmROFile(symbol.outfile), "gif_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + ret = gif_pixel_plot(&symbol, data); + 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); + assert_zero(testUtilRmROFile(symbol.outfile), "gif_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + } symbol.output_options |= BARCODE_STDOUT; diff --git a/backend/tests/test_pcx.c b/backend/tests/test_pcx.c index 60032db8..d382233f 100644 --- a/backend/tests/test_pcx.c +++ b/backend/tests/test_pcx.c @@ -146,6 +146,7 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) 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" }; @@ -158,12 +159,17 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.bitmap_width = symbol.bitmap_height = 1; strcpy(symbol.outfile, "test_pcx_out.pcx"); - (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ - assert_nonzero(testUtilCreateROFile(symbol.outfile), "pcx_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), "pcx_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = pcx_pixel_plot(&symbol, data); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "pcx_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "pcx_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + ret = pcx_pixel_plot(&symbol, data); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "pcx_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); + assert_zero(testUtilRmROFile(symbol.outfile), "pcx_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + } symbol.output_options |= BARCODE_STDOUT; diff --git a/backend/tests/test_png.c b/backend/tests/test_png.c index 390d8bb3..5eb8bedf 100644 --- a/backend/tests/test_png.c +++ b/backend/tests/test_png.c @@ -310,6 +310,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" }; @@ -322,12 +323,17 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.bitmap_width = symbol.bitmap_height = 1; strcpy(symbol.outfile, "test_png_out.png"); - (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ - assert_nonzero(testUtilCreateROFile(symbol.outfile), "png_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), "png_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = png_pixel_plot(&symbol, data); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "png_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "png_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + ret = png_pixel_plot(&symbol, data); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "png_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); + assert_zero(testUtilRmROFile(symbol.outfile), "png_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + } symbol.output_options |= BARCODE_STDOUT; diff --git a/backend/tests/test_ps.c b/backend/tests/test_ps.c index a9154bc1..c5d114bd 100644 --- a/backend/tests/test_ps.c +++ b/backend/tests/test_ps.c @@ -214,6 +214,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol, int rotate_angle); static void test_outfile(const testCtx *const p_ctx) { int ret; + int skip_readonly_test = 0; struct zint_symbol symbol = {0}; struct zint_vector vector = {0}; @@ -225,12 +226,17 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.vector = &vector; strcpy(symbol.outfile, "test_ps_out.eps"); - (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ - assert_nonzero(testUtilCreateROFile(symbol.outfile), "ps_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), "ps_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = ps_plot(&symbol, 0); - 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); - assert_zero(testUtilRmROFile(symbol.outfile), "ps_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + ret = ps_plot(&symbol, 0); + 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); + assert_zero(testUtilRmROFile(symbol.outfile), "ps_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + } symbol.output_options |= BARCODE_STDOUT; diff --git a/backend/tests/test_svg.c b/backend/tests/test_svg.c index 9ba33b43..f794798c 100644 --- a/backend/tests/test_svg.c +++ b/backend/tests/test_svg.c @@ -222,6 +222,7 @@ INTERNAL int svg_plot(struct zint_symbol *symbol, int rotate_angle); static void test_outfile(const testCtx *const p_ctx) { int ret; + int skip_readonly_test = 0; struct zint_symbol symbol = {0}; struct zint_vector vector = {0}; @@ -233,12 +234,17 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.vector = &vector; strcpy(symbol.outfile, "test_svg_out.svg"); - (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ - assert_nonzero(testUtilCreateROFile(symbol.outfile), "svg_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), "svg_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = svg_plot(&symbol, 0); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "svg_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "svg_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + ret = svg_plot(&symbol, 0); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "svg_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); + assert_zero(testUtilRmROFile(symbol.outfile), "svg_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + } symbol.output_options |= BARCODE_STDOUT; diff --git a/backend/tests/test_tif.c b/backend/tests/test_tif.c index 9bdf81c6..a9426c95 100644 --- a/backend/tests/test_tif.c +++ b/backend/tests/test_tif.c @@ -309,6 +309,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" }; @@ -321,12 +322,17 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.bitmap_width = symbol.bitmap_height = 1; strcpy(symbol.outfile, "test_tif_out.tif"); - (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ - assert_nonzero(testUtilCreateROFile(symbol.outfile), "tif_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), "tif_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = tif_pixel_plot(&symbol, data); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "tif_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "tif_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + ret = tif_pixel_plot(&symbol, data); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "tif_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); + assert_zero(testUtilRmROFile(symbol.outfile), "tif_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + } symbol.output_options |= BARCODE_STDOUT;