[cairo-commit] 4 commits - src/cairo-pattern.c test/pattern-getters.c test/rel-path.c test/show-glyphs-many.c
Chris Wilson
ickle at kemper.freedesktop.org
Wed Mar 18 02:44:59 PDT 2009
src/cairo-pattern.c | 18 ++++++++++++++++++
test/pattern-getters.c | 29 +++++++++++++++++++++++++----
test/rel-path.c | 19 ++++++++++++++++---
test/show-glyphs-many.c | 11 ++++++-----
4 files changed, 65 insertions(+), 12 deletions(-)
New commits:
commit c932a809d6484503d7ee267d934bbc87c8d44092
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Mar 17 12:01:13 2009 +0000
[test] Propagate allocation failure.
Check for memfaults during rel-path test.
diff --git a/test/rel-path.c b/test/rel-path.c
index 1544001..d1ef259 100644
--- a/test/rel-path.c
+++ b/test/rel-path.c
@@ -74,24 +74,37 @@ draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
cairo_status_t status;
+ cairo_test_status_t result;
/* first test that a relative move without a current point fails... */
status = invalid_rel_move_to (cairo_get_target (cr));
if (status != CAIRO_STATUS_NO_CURRENT_POINT) {
+ result = cairo_test_status_from_status (ctx, status);
+ if (result == CAIRO_TEST_NO_MEMORY)
+ return result;
+
cairo_test_log (ctx, "Error: invalid cairo_rel_move_to() did not raise NO_CURRENT_POINT\n");
- return CAIRO_TEST_FAILURE;
+ return result;
}
status = invalid_rel_line_to (cairo_get_target (cr));
if (status != CAIRO_STATUS_NO_CURRENT_POINT) {
+ result = cairo_test_status_from_status (ctx, status);
+ if (result == CAIRO_TEST_NO_MEMORY)
+ return result;
+
cairo_test_log (ctx, "Error: invalid cairo_rel_line_to() did not raise NO_CURRENT_POINT\n");
- return CAIRO_TEST_FAILURE;
+ return result;
}
status = invalid_rel_curve_to (cairo_get_target (cr));
if (status != CAIRO_STATUS_NO_CURRENT_POINT) {
+ result = cairo_test_status_from_status (ctx, status);
+ if (result == CAIRO_TEST_NO_MEMORY)
+ return result;
+
cairo_test_log (ctx, "Error: invalid cairo_rel_curve_to() did not raise NO_CURRENT_POINT\n");
- return CAIRO_TEST_FAILURE;
+ return result;
}
cairo_set_source_rgb (cr, 1, 1, 1);
commit 7db55b37d4aef188e04771b45076f6735507c209
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Mar 17 11:58:16 2009 +0000
[test] Destroy pattern on error paths.
Destroy the pattern after encountering an error in pattern-getters test.
diff --git a/test/pattern-getters.c b/test/pattern-getters.c
index 0b9c86b..657159c 100644
--- a/test/pattern-getters.c
+++ b/test/pattern-getters.c
@@ -27,7 +27,12 @@
#include <stdlib.h>
#include "cairo-test.h"
-#define CHECK_SUCCESS do { if (status) return CAIRO_TEST_FAILURE; } while (0)
+#define CHECK_SUCCESS do { \
+ if (status) { \
+ cairo_pattern_destroy (pat); \
+ return cairo_test_status_from_status (ctx, status); \
+ } \
+} while (0)
static int
double_buf_equal (const cairo_test_context_t *ctx, double *a, double *b, int nc)
@@ -64,6 +69,7 @@ draw (cairo_t *cr, int width, int height)
!CAIRO_TEST_DOUBLE_EQUALS(a,0.5)) {
cairo_test_log (ctx, "Error: cairo_pattern_get_rgba returned unexepcted results: %g, %g, %g, %g\n",
r, g, b, a);
+ cairo_pattern_destroy (pat);
return CAIRO_TEST_FAILURE;
}
@@ -81,6 +87,7 @@ draw (cairo_t *cr, int width, int height)
if (surf != cairo_get_target (cr)) {
cairo_test_log (ctx, "Error: cairo_pattern_get_resurface returned wrong surface\n");
+ cairo_pattern_destroy (pat);
return CAIRO_TEST_FAILURE;
}
@@ -114,13 +121,18 @@ draw (cairo_t *cr, int width, int height)
!CAIRO_TEST_DOUBLE_EQUALS(y0,2.0) ||
!CAIRO_TEST_DOUBLE_EQUALS(x1,3.0) ||
!CAIRO_TEST_DOUBLE_EQUALS(y1,4.0))
+ {
+ cairo_pattern_destroy (pat);
return CAIRO_TEST_FAILURE;
+ }
status = cairo_pattern_get_color_stop_count (pat, &i);
CHECK_SUCCESS;
- if (i != 3)
+ if (i != 3) {
+ cairo_pattern_destroy (pat);
return CAIRO_TEST_FAILURE;
+ }
for (i = 0; i < 3; i++) {
status = cairo_pattern_get_color_stop_rgba (pat, i,
@@ -133,11 +145,17 @@ draw (cairo_t *cr, int width, int height)
}
status = cairo_pattern_get_color_stop_rgba (pat, 5, NULL, NULL, NULL, NULL, NULL);
- if (status != CAIRO_STATUS_INVALID_INDEX)
+ if (status != CAIRO_STATUS_INVALID_INDEX) {
+ cairo_pattern_destroy (pat);
return CAIRO_TEST_FAILURE;
+ }
- if (!double_buf_equal (ctx, new_buf, expected_values, sizeof(expected_values)/sizeof(double)) != 0)
+ if (!double_buf_equal (ctx, new_buf, expected_values,
+ sizeof(expected_values)/sizeof(double)) != 0)
+ {
+ cairo_pattern_destroy (pat);
return CAIRO_TEST_FAILURE;
+ }
cairo_pattern_destroy (pat);
}
@@ -157,7 +175,10 @@ draw (cairo_t *cr, int width, int height)
!CAIRO_TEST_DOUBLE_EQUALS(d,4.0) ||
!CAIRO_TEST_DOUBLE_EQUALS(e,5.0) ||
!CAIRO_TEST_DOUBLE_EQUALS(f,6.0))
+ {
+ cairo_pattern_destroy (pat);
return CAIRO_TEST_FAILURE;
+ }
cairo_pattern_destroy (pat);
}
commit dc176d88ac03ae71fc32abb27329a35650801d99
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Mar 17 10:42:37 2009 +0000
[test] Trivial leak on error in show-glyphs-many.
Free the allocated glyph array after failure.
diff --git a/test/show-glyphs-many.c b/test/show-glyphs-many.c
index 497db58..9657e28 100644
--- a/test/show-glyphs-many.c
+++ b/test/show-glyphs-many.c
@@ -130,7 +130,7 @@ draw (cairo_t *cr, int width, int height)
for (utf8 = characters; *utf8 != NULL; utf8++) {
status = get_glyph (cr, *utf8, &glyphs[0]);
if (status)
- return status;
+ goto BAIL;
if (glyphs[0].index) {
glyphs[0].x = 1.0;
@@ -145,21 +145,22 @@ draw (cairo_t *cr, int width, int height)
/* we can pack ~21k 1-byte glyphs into a single XRenderCompositeGlyphs8 */
status = get_glyph (cr, "m", &glyphs[0]);
if (status)
- return status;
+ goto BAIL;
for (i=1; i < 21500; i++)
glyphs[i] = glyphs[0];
/* so check expanding the current 1-byte request for 2-byte glyphs */
status = get_glyph (cr, "μ", &glyphs[i]);
if (status)
- return status;
+ goto BAIL;
for (j=i+1; j < NUM_GLYPHS; j++)
glyphs[j] = glyphs[i];
cairo_show_glyphs (cr, glyphs, NUM_GLYPHS);
-
+
+ BAIL:
free(glyphs);
- return CAIRO_TEST_SUCCESS;
+ return status;
}
CAIRO_TEST (show_glyphs_many,
commit a4b44ca89eb9975e6af2913e50ec3c3eb566cfdd
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Mar 17 14:56:42 2009 +0000
[pattern] Report the true error status from getters.
As the getters actually return an error status, use it to report any
pre-existing error status on the pattern.
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index e8b1b23..bd7e07a 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -2597,6 +2597,9 @@ cairo_pattern_get_rgba (cairo_pattern_t *pattern,
cairo_solid_pattern_t *solid = (cairo_solid_pattern_t*) pattern;
double r0, g0, b0, a0;
+ if (pattern->status)
+ return pattern->status;
+
if (pattern->type != CAIRO_PATTERN_TYPE_SOLID)
return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
@@ -2635,6 +2638,9 @@ cairo_pattern_get_surface (cairo_pattern_t *pattern,
{
cairo_surface_pattern_t *spat = (cairo_surface_pattern_t*) pattern;
+ if (pattern->status)
+ return pattern->status;
+
if (pattern->type != CAIRO_PATTERN_TYPE_SURFACE)
return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
@@ -2673,6 +2679,9 @@ cairo_pattern_get_color_stop_rgba (cairo_pattern_t *pattern,
{
cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t*) pattern;
+ if (pattern->status)
+ return pattern->status;
+
if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR &&
pattern->type != CAIRO_PATTERN_TYPE_RADIAL)
return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
@@ -2714,6 +2723,9 @@ cairo_pattern_get_color_stop_count (cairo_pattern_t *pattern,
{
cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t*) pattern;
+ if (pattern->status)
+ return pattern->status;
+
if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR &&
pattern->type != CAIRO_PATTERN_TYPE_RADIAL)
return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
@@ -2747,6 +2759,9 @@ cairo_pattern_get_linear_points (cairo_pattern_t *pattern,
{
cairo_linear_pattern_t *linear = (cairo_linear_pattern_t*) pattern;
+ if (pattern->status)
+ return pattern->status;
+
if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR)
return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
@@ -2788,6 +2803,9 @@ cairo_pattern_get_radial_circles (cairo_pattern_t *pattern,
{
cairo_radial_pattern_t *radial = (cairo_radial_pattern_t*) pattern;
+ if (pattern->status)
+ return pattern->status;
+
if (pattern->type != CAIRO_PATTERN_TYPE_RADIAL)
return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
More information about the cairo-commit
mailing list