summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2009-09-30 17:50:09 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2009-09-30 17:50:35 +0100
commit8e4e0aa7ee5b4e0963409cda825705a09aae61e1 (patch)
tree345272105cf8b5827026238c39ec552d7d10f1bb
parent395555b116a497c99b9e8365a202377c344c0c45 (diff)
[boilerplate/xcb] Check for connection errors during test
-rw-r--r--boilerplate/cairo-boilerplate-xcb.c51
-rw-r--r--test/cairo-test.c86
2 files changed, 83 insertions, 54 deletions
diff --git a/boilerplate/cairo-boilerplate-xcb.c b/boilerplate/cairo-boilerplate-xcb.c
index e8996fae..de71fa6f 100644
--- a/boilerplate/cairo-boilerplate-xcb.c
+++ b/boilerplate/cairo-boilerplate-xcb.c
@@ -30,12 +30,24 @@
#include <xcb/xcb_renderutil.h>
+static const cairo_user_data_key_t xcb_closure_key;
+
typedef struct _xcb_target_closure {
xcb_connection_t *c;
xcb_pixmap_t pixmap;
} xcb_target_closure_t;
static void
+_cairo_boilerplate_xcb_cleanup (void *closure)
+{
+ xcb_target_closure_t *xtc = closure;
+
+ xcb_free_pixmap (xtc->c, xtc->pixmap);
+ xcb_disconnect (xtc->c);
+ free (xtc);
+}
+
+static void
_cairo_boilerplate_xcb_synchronize (void *closure)
{
xcb_target_closure_t *xtc = closure;
@@ -61,6 +73,8 @@ _cairo_boilerplate_xcb_create_surface (const char *name,
xcb_connection_t *c;
xcb_render_pictforminfo_t *render_format;
xcb_pict_standard_t format;
+ cairo_surface_t *surface;
+ cairo_status_t status;
*closure = xtc = xmalloc (sizeof (xcb_target_closure_t));
@@ -98,19 +112,32 @@ _cairo_boilerplate_xcb_create_surface (const char *name,
if (render_format->id == 0)
return NULL;
- return cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root,
- render_format,
- width, height);
+ surface = cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root,
+ render_format,
+ width, height);
+
+ status = cairo_surface_set_user_data (surface, &xcb_closure_key, xtc, NULL);
+ if (status == CAIRO_STATUS_SUCCESS)
+ return surface;
+
+ cairo_surface_destroy (surface);
+ surface = cairo_boilerplate_surface_create_in_error (status);
+
+ _cairo_boilerplate_xcb_cleanup (xtc);
+
+ return surface;
}
-static void
-_cairo_boilerplate_xcb_cleanup (void *closure)
+static cairo_status_t
+_cairo_boilerplate_xcb_finish_surface (cairo_surface_t *surface)
{
- xcb_target_closure_t *xtc = closure;
+ xcb_target_closure_t *xtc = cairo_surface_get_user_data (surface,
+ &xcb_closure_key);
- xcb_free_pixmap (xtc->c, xtc->pixmap);
- xcb_disconnect (xtc->c);
- free (xtc);
+ if (xcb_connection_has_error (xtc->c))
+ return CAIRO_STATUS_WRITE_ERROR;
+
+ return CAIRO_STATUS_SUCCESS;
}
static const cairo_boilerplate_target_t targets[] = {
@@ -121,7 +148,8 @@ static const cairo_boilerplate_target_t targets[] = {
CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR_ALPHA, 1,
"cairo_xcb_surface_create_with_xrender_format",
_cairo_boilerplate_xcb_create_surface,
- NULL, NULL,
+ NULL,
+ _cairo_boilerplate_xcb_finish_surface,
_cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_xcb_cleanup,
@@ -132,7 +160,8 @@ static const cairo_boilerplate_target_t targets[] = {
CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR, 1,
"cairo_xcb_surface_create_with_xrender_format",
_cairo_boilerplate_xcb_create_surface,
- NULL, NULL,
+ NULL,
+ _cairo_boilerplate_xcb_finish_surface,
_cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_xcb_cleanup,
diff --git a/test/cairo-test.c b/test/cairo-test.c
index 1f495af6..72288656 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -1014,61 +1014,61 @@ REPEAT:
}
#endif
- /* Skip image check for tests with no image (width,height == 0,0) */
- if (ctx->test->width != 0 && ctx->test->height != 0) {
- cairo_surface_t *ref_image;
- cairo_surface_t *test_image;
- cairo_surface_t *diff_image;
- buffer_diff_result_t result;
- cairo_status_t diff_status;
-
- if (target->finish_surface != NULL) {
+ if (target->finish_surface != NULL) {
#if HAVE_MEMFAULT
- /* We need to re-enable faults as most meta-surface processing
- * is done during cairo_surface_finish().
- */
- MEMFAULT_CLEAR_FAULTS ();
- last_fault_count = MEMFAULT_COUNT_FAULTS ();
- MEMFAULT_ENABLE_FAULTS ();
+ /* We need to re-enable faults as most meta-surface processing
+ * is done during cairo_surface_finish().
+ */
+ MEMFAULT_CLEAR_FAULTS ();
+ last_fault_count = MEMFAULT_COUNT_FAULTS ();
+ MEMFAULT_ENABLE_FAULTS ();
#endif
- /* also check for infinite loops whilst replaying */
- alarm (ctx->timeout);
- diff_status = target->finish_surface (surface);
- alarm (0);
+ /* also check for infinite loops whilst replaying */
+ alarm (ctx->timeout);
+ status = target->finish_surface (surface);
+ alarm (0);
#if HAVE_MEMFAULT
- MEMFAULT_DISABLE_FAULTS ();
+ MEMFAULT_DISABLE_FAULTS ();
- if (ctx->malloc_failure &&
- MEMFAULT_COUNT_FAULTS () - last_fault_count > 0 &&
- diff_status == CAIRO_STATUS_NO_MEMORY)
- {
- cairo_destroy (cr);
- cairo_surface_destroy (surface);
- if (target->cleanup)
- target->cleanup (closure);
- if (ctx->thread == 0) {
- cairo_debug_reset_static_data ();
+ if (ctx->malloc_failure &&
+ MEMFAULT_COUNT_FAULTS () - last_fault_count > 0 &&
+ status == CAIRO_STATUS_NO_MEMORY)
+ {
+ cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+ if (target->cleanup)
+ target->cleanup (closure);
+ if (ctx->thread == 0) {
+ cairo_debug_reset_static_data ();
#if HAVE_FCFINI
- FcFini ();
+ FcFini ();
#endif
- if (MEMFAULT_COUNT_LEAKS () > 0) {
- MEMFAULT_PRINT_FAULTS ();
- MEMFAULT_PRINT_LEAKS ();
- }
+ if (MEMFAULT_COUNT_LEAKS () > 0) {
+ MEMFAULT_PRINT_FAULTS ();
+ MEMFAULT_PRINT_LEAKS ();
}
-
- goto REPEAT;
}
+
+ goto REPEAT;
+ }
#endif
- if (diff_status) {
- cairo_test_log (ctx, "Error: Failed to finish surface: %s\n",
- cairo_status_to_string (diff_status));
- ret = CAIRO_TEST_FAILURE;
- goto UNWIND_CAIRO;
- }
+ if (status) {
+ cairo_test_log (ctx, "Error: Failed to finish surface: %s\n",
+ cairo_status_to_string (status));
+ ret = CAIRO_TEST_FAILURE;
+ goto UNWIND_CAIRO;
}
+ }
+
+ /* Skip image check for tests with no image (width,height == 0,0) */
+ if (ctx->test->width != 0 && ctx->test->height != 0) {
+ cairo_surface_t *ref_image;
+ cairo_surface_t *test_image;
+ cairo_surface_t *diff_image;
+ buffer_diff_result_t result;
+ cairo_status_t diff_status;
if (ref_png_path == NULL) {
cairo_test_log (ctx, "Error: Cannot find reference image for %s\n",