summaryrefslogtreecommitdiff
path: root/test/create-for-stream.c
diff options
context:
space:
mode:
authorUli Schlachter <psychon@znc.in>2021-07-23 17:22:16 +0200
committerUli Schlachter <psychon@znc.in>2021-07-23 17:22:16 +0200
commit2fbd53a6b33a90a08ef6eda9e5f88e8fb3b97c1e (patch)
treeb99bcdf4741e6473d77ddc0e2ea1e71e76381086 /test/create-for-stream.c
parentb408352d450bb8c1b1cc17b14e0d605dc40daaed (diff)
downloadcairo-2fbd53a6b33a90a08ef6eda9e5f88e8fb3b97c1e.tar.gz
pdf: Properly pass on stdio write errors
cairo-pdf was silently ignoring write errors in _cairo_pdf_surface_finish(). Any write errors that happened here ended up setting a "status" variable, but the value in this variable was then unused. This commit fixes this bug by passing this error on to the caller. Additionally, this also adds a test case for this behaviour based on writing to /dev/full. This file is non-standard and thus the test first checks that this file exists and is writable before trying to write to it. This bug was found based on a report from Knut Petersen [0]. [0]: https://lists.cairographics.org/archives/cairo/2021-July/029281.html Signed-off-by: Uli Schlachter <psychon@znc.in>
Diffstat (limited to 'test/create-for-stream.c')
-rw-r--r--test/create-for-stream.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/test/create-for-stream.c b/test/create-for-stream.c
index af1632f14..3e7577a6a 100644
--- a/test/create-for-stream.c
+++ b/test/create-for-stream.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <unistd.h>
#if CAIRO_HAS_PS_SURFACE
#include <cairo-ps.h>
@@ -165,11 +166,29 @@ test_surface (const cairo_test_context_t *ctx,
if (status != CAIRO_STATUS_WRITE_ERROR) {
cairo_test_log (ctx,
- "%s: Error: expected \"write error\", but received \"%s\".\n",
+ "%s: Error: expected \"write error\" from bad_write(), but received \"%s\".\n",
backend, cairo_status_to_string (status));
return CAIRO_TEST_FAILURE;
}
+ /* test propagation of file errors - for now this is unix-only */
+ if (access("/dev/full", W_OK) == 0) {
+ surface = file_constructor ("/dev/full", WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
+ cairo_surface_finish (surface);
+ status = cairo_surface_status (surface);
+ cairo_surface_destroy (surface);
+
+ if (status != CAIRO_STATUS_WRITE_ERROR) {
+ cairo_test_log (ctx,
+ "%s: Error: expected \"write error\" from /dev/full, but received \"%s\".\n",
+ backend, cairo_status_to_string (status));
+ return CAIRO_TEST_FAILURE;
+ }
+ } else {
+ cairo_test_log (ctx,
+ "/dev/full does not exist; skipping write test.\n");
+ }
+
/* construct the real surface */
wc.ctx = ctx;
wc.status = CAIRO_TEST_SUCCESS;