diff options
-rw-r--r-- | boilerplate/cairo-boilerplate-svg.c | 2 | ||||
-rw-r--r-- | test/cairo-test.c | 21 | ||||
-rw-r--r-- | test/png.c | 34 | ||||
-rw-r--r-- | test/pthread-same-source.c | 7 | ||||
-rw-r--r-- | test/surface-source.c | 11 | ||||
-rw-r--r-- | test/toy-font-face.c | 16 | ||||
-rw-r--r-- | test/user-data.c | 51 | ||||
-rw-r--r-- | test/xlib-surface-source.c | 7 |
8 files changed, 112 insertions, 37 deletions
diff --git a/boilerplate/cairo-boilerplate-svg.c b/boilerplate/cairo-boilerplate-svg.c index 583f9a16..dbfa0d6d 100644 --- a/boilerplate/cairo-boilerplate-svg.c +++ b/boilerplate/cairo-boilerplate-svg.c @@ -242,7 +242,7 @@ static void _cairo_boilerplate_svg_cleanup (void *closure) { svg_target_closure_t *ptc = closure; - if (ptc->target) { + if (ptc->target != NULL) { cairo_surface_finish (ptc->target); cairo_surface_destroy (ptc->target); } diff --git a/test/cairo-test.c b/test/cairo-test.c index f78519f1..aa8dd3a6 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -917,10 +917,23 @@ REPEAT: goto UNWIND_SURFACE; } - cairo_surface_set_user_data (surface, - &cairo_boilerplate_output_basename_key, - base_path, - NULL); + if (cairo_surface_set_user_data (surface, + &cairo_boilerplate_output_basename_key, + base_path, + NULL)) + { +#if HAVE_MEMFAULT + cairo_surface_destroy (surface); + + if (target->cleanup) + target->cleanup (closure); + + goto REPEAT; +#else + ret = CAIRO_TEST_FAILURE; + goto UNWIND_SURFACE; +#endif + } cairo_surface_set_device_offset (surface, dev_offset, dev_offset); @@ -55,6 +55,7 @@ format_to_string (cairo_format_t format) switch (format) { case CAIRO_FORMAT_A1: return "a1"; case CAIRO_FORMAT_A8: return "a8"; + case CAIRO_FORMAT_RGB16_565: return "rgb16"; case CAIRO_FORMAT_RGB24: return "rgb24"; case CAIRO_FORMAT_ARGB32: return "argb32"; case CAIRO_FORMAT_INVALID: @@ -79,61 +80,72 @@ preamble (cairo_test_context_t *ctx) cairo_surface_t *surface0, *surface1; cairo_status_t status; uint32_t argb32 = 0xdeadbede; - cairo_test_status_t result = CAIRO_TEST_SUCCESS; surface0 = cairo_image_surface_create_for_data ((unsigned char *) &argb32, CAIRO_FORMAT_ARGB32, 1, 1, 4); - assert (cairo_surface_status (surface0) == CAIRO_STATUS_SUCCESS); status = cairo_surface_write_to_png (surface0, filename); if (status) { cairo_test_log (ctx, "Error writing '%s': %s\n", filename, cairo_status_to_string (status)); - result = CAIRO_TEST_FAILURE; + + cairo_surface_destroy (surface0); + return cairo_test_status_from_status (ctx, status); } surface1 = cairo_image_surface_create_from_png (filename); status = cairo_surface_status (surface1); if (status) { cairo_test_log (ctx, "Error reading '%s': %s\n", filename, cairo_status_to_string (status)); - result = CAIRO_TEST_FAILURE; + + cairo_surface_destroy (surface1); + cairo_surface_destroy (surface0); + return cairo_test_status_from_status (ctx, status); } if (! image_surface_equals (surface0, surface1)) { cairo_test_log (ctx, "Error surface mismatch.\n"); cairo_test_log (ctx, "to png: "); print_surface (ctx, surface0); cairo_test_log (ctx, "from png: "); print_surface (ctx, surface1); - result = CAIRO_TEST_FAILURE; + + cairo_surface_destroy (surface0); + cairo_surface_destroy (surface1); + return CAIRO_TEST_FAILURE; } assert (*(uint32_t *) cairo_image_surface_get_data (surface1) == argb32); cairo_surface_destroy (surface0); cairo_surface_destroy (surface1); - surface0 = cairo_image_surface_create_for_data ((unsigned char *) &argb32, CAIRO_FORMAT_RGB24, 1, 1, 4); - assert (cairo_surface_status (surface0) == CAIRO_STATUS_SUCCESS); status = cairo_surface_write_to_png (surface0, filename); if (status) { cairo_test_log (ctx, "Error writing '%s': %s\n", filename, cairo_status_to_string (status)); - result = CAIRO_TEST_FAILURE; + cairo_surface_destroy (surface0); + return cairo_test_status_from_status (ctx, status); } surface1 = cairo_image_surface_create_from_png (filename); status = cairo_surface_status (surface1); if (status) { cairo_test_log (ctx, "Error reading '%s': %s\n", filename, cairo_status_to_string (status)); - result = CAIRO_TEST_FAILURE; + + cairo_surface_destroy (surface1); + cairo_surface_destroy (surface0); + return cairo_test_status_from_status (ctx, status); } if (! image_surface_equals (surface0, surface1)) { cairo_test_log (ctx, "Error surface mismatch.\n"); cairo_test_log (ctx, "to png: "); print_surface (ctx, surface0); cairo_test_log (ctx, "from png: "); print_surface (ctx, surface1); - result = CAIRO_TEST_FAILURE; + + cairo_surface_destroy (surface0); + cairo_surface_destroy (surface1); + return CAIRO_TEST_FAILURE; } assert ((*(uint32_t *) cairo_image_surface_get_data (surface1) & RGB_MASK) == (argb32 & RGB_MASK)); @@ -141,7 +153,7 @@ preamble (cairo_test_context_t *ctx) cairo_surface_destroy (surface0); cairo_surface_destroy (surface1); - return result; + return CAIRO_TEST_SUCCESS; } CAIRO_TEST (png, diff --git a/test/pthread-same-source.c b/test/pthread-same-source.c index 50102d98..49123b43 100644 --- a/test/pthread-same-source.c +++ b/test/pthread-same-source.c @@ -113,9 +113,16 @@ draw (cairo_t *cr, int width, int height) thread_data_t thread_data[N_THREADS]; cairo_test_status_t test_status = CAIRO_TEST_SUCCESS; cairo_surface_t *source; + cairo_status_t status; int i; source = create_source (cairo_get_target (cr)); + status = cairo_surface_status (source); + if (status) { + cairo_surface_destroy (source); + return cairo_test_status_from_status (cairo_test_get_context (cr), + status); + } for (i = 0; i < N_THREADS; i++) { thread_data[i].target = cairo_surface_create_similar (cairo_get_target (cr), diff --git a/test/surface-source.c b/test/surface-source.c index eb8be194..657a0c88 100644 --- a/test/surface-source.c +++ b/test/surface-source.c @@ -111,6 +111,7 @@ draw (cairo_t *cr, int width, int height) { cairo_surface_t *surface; cairo_surface_t *similar; + cairo_status_t status; cairo_t *cr2; cairo_set_source_rgb (cr, 0, 0, 0); @@ -143,21 +144,27 @@ draw (cairo_t *cr, int width, int height) cairo_fill (cr); /* destroy the surface last, as this triggers XCloseDisplay */ + cairo_surface_finish (surface); + status = cairo_surface_status (surface); cairo_surface_destroy (surface); - return CAIRO_TEST_SUCCESS; + return cairo_test_status_from_status (cairo_test_get_context (cr), + status); } static cairo_test_status_t preamble (cairo_test_context_t *ctx) { cairo_surface_t *surface; + cairo_status_t status; surface = create_source_surface (SOURCE_SIZE); if (surface == NULL) /* can't create the source so skip the test */ return CAIRO_TEST_UNTESTED; + cairo_surface_finish (surface); + status = cairo_surface_status (surface); cairo_surface_destroy (surface); - return CAIRO_TEST_SUCCESS; + return cairo_test_status_from_status (ctx, status); } diff --git a/test/toy-font-face.c b/test/toy-font-face.c index 147c43b7..cbebf840 100644 --- a/test/toy-font-face.c +++ b/test/toy-font-face.c @@ -51,6 +51,7 @@ preamble (cairo_test_context_t *ctx) cairo_t *cr; cairo_surface_t *surface; cairo_font_face_t *font_face; + cairo_status_t status; surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 0, 0); cr = cairo_create (surface); @@ -61,9 +62,12 @@ preamble (cairo_test_context_t *ctx) assert (cairo_toy_font_face_get_family (font_face) != NULL); assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL); assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL); - assert (cairo_font_face_status(font_face) == CAIRO_STATUS_SUCCESS); + status = cairo_font_face_status(font_face); cairo_font_face_destroy (font_face); + if (status) + return cairo_test_status_from_status (ctx, status); + cairo_select_font_face (cr, "bizarre", CAIRO_FONT_SLANT_OBLIQUE, @@ -73,9 +77,12 @@ preamble (cairo_test_context_t *ctx) assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "bizarre")); assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_OBLIQUE); assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_BOLD); - assert (cairo_font_face_status(font_face) == CAIRO_STATUS_SUCCESS); + status = cairo_font_face_status(font_face); cairo_font_face_destroy (font_face); + if (status) + return cairo_test_status_from_status (ctx, status); + font_face = cairo_toy_font_face_create ("bozarre", CAIRO_FONT_SLANT_OBLIQUE, CAIRO_FONT_WEIGHT_BOLD); @@ -83,9 +90,12 @@ preamble (cairo_test_context_t *ctx) assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "bozarre")); assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_OBLIQUE); assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_BOLD); - assert (cairo_font_face_status(font_face) == CAIRO_STATUS_SUCCESS); + status = cairo_font_face_status(font_face); cairo_font_face_destroy (font_face); + if (status) + return cairo_test_status_from_status (ctx, status); + font_face = cairo_toy_font_face_create (NULL, CAIRO_FONT_SLANT_OBLIQUE, CAIRO_FONT_WEIGHT_BOLD); diff --git a/test/user-data.c b/test/user-data.c index f0e62d1a..532107aa 100644 --- a/test/user-data.c +++ b/test/user-data.c @@ -42,43 +42,64 @@ destroy_data2 (void *p) static cairo_test_status_t preamble (cairo_test_context_t *ctx) { - cairo_surface_t *surface; static const cairo_user_data_key_t key1, key2; + cairo_surface_t *surface; + cairo_status_t status; int data1, data2; data1 = 0; data2 = 0; + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); - assert (cairo_surface_set_user_data (surface, &key1, &data1, destroy_data1) - == CAIRO_STATUS_SUCCESS); - assert (cairo_surface_set_user_data (surface, &key2, &data2, destroy_data2) - == CAIRO_STATUS_SUCCESS); + status = cairo_surface_set_user_data (surface, &key1, &data1, destroy_data1); + if (status) + goto error; + + status = cairo_surface_set_user_data (surface, &key2, &data2, destroy_data2); + if (status) + goto error; + assert (cairo_surface_get_user_data (surface, &key1) == &data1); - assert (cairo_surface_set_user_data (surface, &key1, NULL, NULL) - == CAIRO_STATUS_SUCCESS); + status = cairo_surface_set_user_data (surface, &key1, NULL, NULL); + if (status) + goto error; + assert (cairo_surface_get_user_data (surface, &key1) == NULL); assert (data1 == 1); assert (data2 == 0); - assert (cairo_surface_set_user_data (surface, &key2, NULL, NULL) - == CAIRO_STATUS_SUCCESS); + status = cairo_surface_set_user_data (surface, &key2, NULL, NULL); + if (status) + goto error; + assert (data2 == 2); data1 = 0; - assert (cairo_surface_set_user_data (surface, &key1, &data1, NULL) - == CAIRO_STATUS_SUCCESS); - assert (cairo_surface_set_user_data (surface, &key1, NULL, NULL) - == CAIRO_STATUS_SUCCESS); + status = cairo_surface_set_user_data (surface, &key1, &data1, NULL); + if (status) + goto error; + + status = cairo_surface_set_user_data (surface, &key1, NULL, NULL); + if (status) + goto error; + assert (data1 == 0); assert (cairo_surface_get_user_data (surface, &key1) == NULL); - assert (cairo_surface_set_user_data (surface, &key1, &data1, destroy_data1) - == CAIRO_STATUS_SUCCESS); + status = cairo_surface_set_user_data (surface, &key1, &data1, destroy_data1); + if (status) + goto error; + cairo_surface_destroy (surface); + assert (data1 == 1); assert (data2 == 2); return CAIRO_TEST_SUCCESS; + +error: + cairo_surface_destroy (surface); + return cairo_test_status_from_status (ctx, status); } CAIRO_TEST (user_data, diff --git a/test/xlib-surface-source.c b/test/xlib-surface-source.c index 65a9fdfe..7d2ed71c 100644 --- a/test/xlib-surface-source.c +++ b/test/xlib-surface-source.c @@ -79,7 +79,12 @@ create_source_surface (int size) xrender_format, size, size); data->device = cairo_device_reference (cairo_surface_get_device (surface)); - cairo_surface_set_user_data (surface, &closure_key, data, cleanup); + if (cairo_surface_set_user_data (surface, &closure_key, data, cleanup)) { + cairo_surface_finish (surface); + cairo_surface_destroy (surface); + cleanup (data); + return NULL; + } return surface; #else |