2 * Copyright © 2008 Chris Wilson
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 * Chris Wilson not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Chris Wilson 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 * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL CHRIS WILSON 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 * Author: Chris Wilson <chris@chris-wilson.co.uk>
25 * Based on an example by Dirk "krit" Schulze found during WebKit integration.
28 #include "cairo-test.h"
30 /* we know that this is an inherent limitation in cairo */
31 #define FAIL CAIRO_TEST_XFAILURE
33 /* Test the idempotency of path construction and copying */
35 static cairo_test_status_t
36 draw (cairo_t *cr, int width, int height)
38 cairo_path_data_t path_data[] = {
39 { { CAIRO_PATH_MOVE_TO, 2 }, },
40 { { 95.000000, 40.000000 }, },
42 { { CAIRO_PATH_LINE_TO, 2 }, },
43 { { 94.960533, 41.255810 }, },
45 { { CAIRO_PATH_LINE_TO, 2 }, },
46 { { 94.842293, 42.50666 }, },
48 { { CAIRO_PATH_LINE_TO, 2 }, },
49 { { 94.645744, 43.747627 }, },
51 { { CAIRO_PATH_LINE_TO, 2 }, },
52 { { 94.371666, 44.973797 }, },
54 const cairo_test_context_t *ctx = cairo_test_get_context (cr);
55 cairo_path_t path, *path_copy;
57 cairo_test_status_t result = CAIRO_TEST_SUCCESS;
59 path.status = CAIRO_STATUS_SUCCESS;
60 path.num_data = ARRAY_LENGTH (path_data);
61 path.data = path_data;
64 cairo_append_path (cr, &path);
65 path_copy = cairo_copy_path (cr);
67 if (path_copy->status)
68 return cairo_test_status_from_status (ctx, path_copy->status);
71 i < path.num_data && j < path_copy->num_data;
72 i += path.data[i].header.length,
73 j += path_copy->data[j].header.length,
76 const cairo_path_data_t *src, *dst;
79 dst = &path_copy->data[j];
81 if (src->header.type != dst->header.type) {
83 "Paths differ in header type after %d operations.\n"
84 "Expected path operation %d, found %d.\n",
85 n, src->header.type, dst->header.type);
90 if (memcmp (&src[1].point, &dst[1].point, sizeof (src->point))) {
92 "Paths differ in coordinates after %d operations.\n"
93 "Expected point (%f, %f), found (%f, %f).\n",
95 src[1].point.x, src[1].point.y,
96 dst[1].point.x, dst[1].point.y);
102 cairo_path_destroy (path_copy);
106 CAIRO_TEST (path_precision,
107 "Check that the path append/copy is idempotent.",
108 "api", /* keywords */
109 NULL, /* requirements */