2 * Copyright © Jeff Muizelaar
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Red Hat, Inc. makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * JEFF MUIZELAAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: Jeff Muizelaar <jeff@infidigm.net>
24 * Carl Worth <cworth@cworth.org>
27 #include "cairo-test.h"
32 static unsigned char mask[MASK_WIDTH * MASK_HEIGHT] = {
33 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
34 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
35 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
36 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
37 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
38 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
39 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
40 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
43 static cairo_test_status_t
44 check_status (const cairo_test_context_t *ctx,
45 cairo_status_t status,
46 cairo_status_t expected)
48 if (status == expected)
49 return CAIRO_TEST_SUCCESS;
52 "Error: Expected status value %d (%s), received %d (%s)\n",
54 cairo_status_to_string (expected),
56 cairo_status_to_string (status));
57 return CAIRO_TEST_FAILURE;
60 static cairo_test_status_t
61 test_surface_with_width_and_stride (const cairo_test_context_t *ctx,
62 int width, int stride,
63 cairo_status_t expected)
65 cairo_test_status_t status;
66 cairo_surface_t *surface;
72 "Creating surface with width %d and stride %d\n",
80 surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_A8,
82 cr = cairo_create (surface);
86 status = check_status (ctx, cairo_surface_status (surface), expected);
90 status = check_status (ctx, cairo_status (cr), expected);
96 cairo_surface_destroy (surface);
101 static cairo_test_status_t
102 draw (cairo_t *cr, int dst_width, int dst_height)
105 unsigned char *src, *dst, *mask_aligned;
106 cairo_surface_t *surface;
108 /* Now test actually drawing through our mask data, allocating and
109 * copying with the proper stride. */
110 stride = cairo_format_stride_for_width (CAIRO_FORMAT_A8,
113 mask_aligned = xmalloc (stride * MASK_HEIGHT);
117 for (row = 0; row < MASK_HEIGHT; row++) {
118 memcpy (dst, src, MASK_WIDTH);
123 surface = cairo_image_surface_create_for_data (mask_aligned,
129 /* Paint background blue */
130 cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
133 /* Then paint red through our mask */
134 cairo_set_source_rgb (cr, 1, 0, 0); /* red */
135 cairo_mask_surface (cr, surface, 0, 0);
136 cairo_surface_destroy (surface);
140 return CAIRO_TEST_SUCCESS;
143 static cairo_test_status_t
144 preamble (cairo_test_context_t *ctx)
146 cairo_test_status_t status = CAIRO_TEST_SUCCESS;
149 for (test_width = 0; test_width < 40; test_width++) {
150 int stride = cairo_format_stride_for_width (CAIRO_FORMAT_A8,
152 cairo_status_t expected;
154 /* First create a surface using the width as the stride,
155 * (most of these should fail).
157 expected = (stride == test_width) ?
158 CAIRO_STATUS_SUCCESS : CAIRO_STATUS_INVALID_STRIDE;
160 status = test_surface_with_width_and_stride (ctx,
167 status = test_surface_with_width_and_stride (ctx,
175 /* Then create a surface using the correct stride,
176 * (should always succeed).
178 status = test_surface_with_width_and_stride (ctx,
181 CAIRO_STATUS_SUCCESS);
185 status = test_surface_with_width_and_stride (ctx,
188 CAIRO_STATUS_SUCCESS);
197 "test masks of CAIRO_FORMAT_A8",
198 "alpha, mask", /* keywords */
199 NULL, /* requirements */