[cairo-commit] 3 commits - test/a1-mask.c test/a8-mask.c test/cairo-test.c

Chris Wilson ickle at kemper.freedesktop.org
Tue Apr 15 08:03:22 PDT 2008


 test/a1-mask.c    |   99 +++++++++++++++++++++++++++---------------------------
 test/a8-mask.c    |   97 +++++++++++++++++++++++++++-------------------------
 test/cairo-test.c |    7 +--
 3 files changed, 103 insertions(+), 100 deletions(-)

New commits:
commit 0e315b1e6092d7ba44a89076567257d68ab3e1f9
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 14 20:32:29 2008 +0100

    [test/a8-mask] Perform the stride API checking once.
    
    The stride API is independent of the surface and does not need to be
    repeated for every surface.

diff --git a/test/a8-mask.c b/test/a8-mask.c
index 2e5efad..fdf4fef 100644
--- a/test/a8-mask.c
+++ b/test/a8-mask.c
@@ -105,49 +105,9 @@ test_surface_with_width_and_stride (int width, int stride,
 static cairo_test_status_t
 draw (cairo_t *cr, int dst_width, int dst_height)
 {
-    int test_width, stride, row;
+    int stride, row;
     unsigned char *src, *dst, *mask_aligned;
     cairo_surface_t *surface;
-    cairo_pattern_t *pattern;
-    cairo_test_status_t status;
-    cairo_status_t expected;
-
-    for (test_width = 0; test_width < 40; test_width++) {
-	stride = cairo_format_stride_for_width (CAIRO_FORMAT_A8,
-						test_width);
-
-	/* First create a surface using the width as the stride, (most
-	 * of these should fail). */
-	expected = (stride == test_width) ?
-	    CAIRO_STATUS_SUCCESS : CAIRO_STATUS_INVALID_STRIDE;
-
-	status = test_surface_with_width_and_stride (test_width,
-						     test_width,
-						     expected);
-	if (status)
-	    return status;
-
-	status = test_surface_with_width_and_stride (test_width,
-						     -test_width,
-						     expected);
-	if (status)
-	    return status;
-
-
-	/* Then create a surface using the correct stride, (should
-	   always succeed).*/
-	status = test_surface_with_width_and_stride (test_width,
-						     stride,
-						     CAIRO_STATUS_SUCCESS);
-	if (status)
-	    return status;
-
-	status = test_surface_with_width_and_stride (test_width,
-						     -stride,
-						     CAIRO_STATUS_SUCCESS);
-	if (status)
-	    return status;
-    }
 
     /* Now test actually drawing through our mask data, allocating and
      * copying with the proper stride. */
@@ -164,7 +124,7 @@ draw (cairo_t *cr, int dst_width, int dst_height)
 	dst += stride;
     }
 
-    surface = cairo_image_surface_create_for_data (mask,
+    surface = cairo_image_surface_create_for_data (mask_aligned,
 						   CAIRO_FORMAT_A8,
 						   MASK_WIDTH,
 						   MASK_HEIGHT,
@@ -175,12 +135,8 @@ draw (cairo_t *cr, int dst_width, int dst_height)
     cairo_paint (cr);
 
     /* Then paint red through our mask */
-    pattern = cairo_pattern_create_for_surface (surface);
-
     cairo_set_source_rgb (cr, 1, 0, 0); /* red */
-    cairo_mask (cr, pattern);
-
-    cairo_pattern_destroy (pattern);
+    cairo_mask_surface (cr, surface, 0, 0);
     cairo_surface_destroy (surface);
 
     free (mask_aligned);
@@ -191,5 +147,52 @@ draw (cairo_t *cr, int dst_width, int dst_height)
 int
 main (void)
 {
+    int test_width;
+
+    cairo_test_init ("a8-mask");
+
+    for (test_width = 0; test_width < 40; test_width++) {
+	int stride = cairo_format_stride_for_width (CAIRO_FORMAT_A8,
+						test_width);
+	cairo_test_status_t status;
+	cairo_status_t expected;
+
+	/* First create a surface using the width as the stride,
+	 * (most of these should fail).
+	 */
+	expected = (stride == test_width) ?
+	    CAIRO_STATUS_SUCCESS : CAIRO_STATUS_INVALID_STRIDE;
+
+	status = test_surface_with_width_and_stride (test_width,
+						     test_width,
+						     expected);
+	if (status)
+	    return status;
+
+	status = test_surface_with_width_and_stride (test_width,
+						     -test_width,
+						     expected);
+	if (status)
+	    return status;
+
+
+	/* Then create a surface using the correct stride,
+	 * (should always succeed).
+	 */
+	status = test_surface_with_width_and_stride (test_width,
+						     stride,
+						     CAIRO_STATUS_SUCCESS);
+	if (status)
+	    return status;
+
+	status = test_surface_with_width_and_stride (test_width,
+						     -stride,
+						     CAIRO_STATUS_SUCCESS);
+	if (status)
+	    return status;
+    }
+
+    cairo_test_fini ();
+
     return cairo_test (&test);
 }
commit 8b36ca085844ada8f13d0164719772b6bb78dff6
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 14 20:32:29 2008 +0100

    [test/a1-mask] Perform the stride API checking once.
    
    The stride API is independent of the surface and does not need to be
    repeated for every surface.

diff --git a/test/a1-mask.c b/test/a1-mask.c
index cbc64b0..946b622 100644
--- a/test/a1-mask.c
+++ b/test/a1-mask.c
@@ -112,20 +112,55 @@ test_surface_with_width_and_stride (int width, int stride,
 static cairo_test_status_t
 draw (cairo_t *cr, int dst_width, int dst_height)
 {
-    int test_width, test_stride, stride, row;
-    unsigned char *src, *dst, *mask_aligned;
+    unsigned char *mask_aligned;
     cairo_surface_t *surface;
-    cairo_pattern_t *pattern;
-    cairo_test_status_t status;
-    cairo_status_t expected;
 
-    for (test_width = 0; test_width < 40; test_width++) {
-	test_stride = (test_width + 7) / 8;
-	stride = cairo_format_stride_for_width (CAIRO_FORMAT_A1,
-						test_width);
+    surface = cairo_image_surface_create (CAIRO_FORMAT_A1,
+					  MASK_WIDTH,
+					  MASK_HEIGHT);
+
+    mask_aligned = cairo_image_surface_get_data (surface);
+    if (mask_aligned != NULL) {
+	int stride = cairo_image_surface_get_stride (surface), row;
+	const unsigned char *src = mask;
+	unsigned char *dst = mask_aligned;
+	for (row = 0; row < MASK_HEIGHT; row++) {
+	    memcpy (dst, src, (MASK_WIDTH + 7) / 8);
+	    src += (MASK_WIDTH + 7) / 8;
+	    dst += stride;
+	}
+    }
+
+    /* Paint background blue */
+    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
+    cairo_paint (cr);
+
+    /* Then paint red through our mask */
+    cairo_set_source_rgb (cr, 1, 0, 0); /* red */
+    cairo_mask_surface (cr, surface, 0, 0);
+    cairo_surface_destroy (surface);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    int test_width;
+
+    cairo_test_init ("a1-mask");
 
-	/* First create a surface using the width as the stride, (most
-	 * of these should fail). */
+    /* first check the API strictness */
+    for (test_width = 0; test_width < 40; test_width++) {
+	int test_stride = (test_width + 7) / 8;
+	int stride = cairo_format_stride_for_width (CAIRO_FORMAT_A1,
+						    test_width);
+	cairo_test_status_t status;
+	cairo_status_t expected;
+
+	/* First create a surface using the width as the stride,
+	 * (most of these should fail).
+	 */
 	expected = (stride == test_stride) ?
 	    CAIRO_STATUS_SUCCESS : CAIRO_STATUS_INVALID_STRIDE;
 
@@ -142,8 +177,9 @@ draw (cairo_t *cr, int dst_width, int dst_height)
 	    return status;
 
 
-	/* Then create a surface using the correct stride, (should
-	   always succeed).*/
+	/* Then create a surface using the correct stride,
+	 * (should always succeed).
+	 */
 	status = test_surface_with_width_and_stride (test_width,
 						     stride,
 						     CAIRO_STATUS_SUCCESS);
@@ -157,42 +193,7 @@ draw (cairo_t *cr, int dst_width, int dst_height)
 	    return status;
     }
 
-    /* Now test actually drawing through our mask data, allocating and
-     * copying with the proper stride. */
-    surface = cairo_image_surface_create (CAIRO_FORMAT_A1,
-					  MASK_WIDTH,
-					  MASK_HEIGHT);
+    cairo_test_fini ();
 
-    mask_aligned = cairo_image_surface_get_data (surface);
-    if (mask_aligned != NULL) {
-	stride = cairo_image_surface_get_stride (surface);
-	src = mask;
-	dst = mask_aligned;
-	for (row = 0; row < MASK_HEIGHT; row++) {
-	    memcpy (dst, src, (MASK_WIDTH + 7) / 8);
-	    src += (MASK_WIDTH + 7) / 8;
-	    dst += stride;
-	}
-    }
-
-    /* Paint background blue */
-    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
-    cairo_paint (cr);
-
-    /* Then paint red through our mask */
-    pattern = cairo_pattern_create_for_surface (surface);
-
-    cairo_set_source_rgb (cr, 1, 0, 0); /* red */
-    cairo_mask (cr, pattern);
-
-    cairo_pattern_destroy (pattern);
-    cairo_surface_destroy (surface);
-
-    return CAIRO_TEST_SUCCESS;
-}
-
-int
-main (void)
-{
     return cairo_test (&test);
 }
commit fa5e87ad230db18be26b971dc0351abd342c7894
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 14 20:11:44 2008 +0100

    [cairo-test] Spelling fixes in comments.
    
    Skim through the comments fixing trivial smelling pistakes.

diff --git a/test/cairo-test.c b/test/cairo-test.c
index 5608f40..8ed5889 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -185,7 +185,7 @@ cairo_ref_name_for_test_target_format (const char *test_name,
     else
 	goto done;
 
-    /* Next, look for taget-specifc reference image. */
+    /* Next, look for target-specific reference image. */
     xasprintf (&ref_name, "%s/%s-%s%s", srcdir,
 	       test_name,
 	       target_name,
@@ -195,7 +195,7 @@ cairo_ref_name_for_test_target_format (const char *test_name,
     else
 	goto done;
 
-    /* Next, look for format-specifc reference image. */
+    /* Next, look for format-specific reference image. */
     xasprintf (&ref_name, "%s/%s-%s%s", srcdir,
 	       test_name,
 	       format,
@@ -339,8 +339,7 @@ cairo_test_for_target (cairo_test_t			 *test,
     }
 
     /* Check that we created a surface of the expected content,
-     * (ignore the articifical
-     * CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED value).
+     * (ignore the artificial CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED value).
      */
     expected_content = cairo_boilerplate_content (target->content);
 


More information about the cairo-commit mailing list