Upload Tizen2.0 source
[framework/graphics/cairo.git] / test / path-precision.c
1 /*
2  * Copyright © 2008 Chris Wilson
3  *
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.
14  *
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.
22  *
23  * Author: Chris Wilson <chris@chris-wilson.co.uk>
24  *
25  * Based on an example by Dirk "krit" Schulze found during WebKit integration.
26  */
27
28 #include "cairo-test.h"
29
30 /* we know that this is an inherent limitation in cairo */
31 #define FAIL CAIRO_TEST_XFAILURE
32
33 /* Test the idempotency of path construction and copying */
34
35 static cairo_test_status_t
36 draw (cairo_t *cr, int width, int height)
37 {
38     cairo_path_data_t path_data[] = {
39         { { CAIRO_PATH_MOVE_TO, 2 }, },
40         { { 95.000000, 40.000000 }, },
41
42         { { CAIRO_PATH_LINE_TO, 2 }, },
43         { { 94.960533, 41.255810 }, },
44
45         { { CAIRO_PATH_LINE_TO, 2 }, },
46         { { 94.842293, 42.50666 }, },
47
48         { { CAIRO_PATH_LINE_TO, 2 }, },
49         { { 94.645744, 43.747627 }, },
50
51         { { CAIRO_PATH_LINE_TO, 2 }, },
52         { { 94.371666, 44.973797 }, },
53     };
54     const cairo_test_context_t *ctx = cairo_test_get_context (cr);
55     cairo_path_t path, *path_copy;
56     int i, j, n;
57     cairo_test_status_t result = CAIRO_TEST_SUCCESS;
58
59     path.status = CAIRO_STATUS_SUCCESS;
60     path.num_data = ARRAY_LENGTH (path_data);
61     path.data = path_data;
62
63     cairo_new_path (cr);
64     cairo_append_path (cr, &path);
65     path_copy = cairo_copy_path (cr);
66
67     if (path_copy->status)
68         return cairo_test_status_from_status (ctx, path_copy->status);
69
70     for (i = j = n = 0;
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,
74          n++)
75     {
76         const cairo_path_data_t *src, *dst;
77
78         src = &path.data[i];
79         dst = &path_copy->data[j];
80
81         if (src->header.type != dst->header.type) {
82             cairo_test_log (ctx,
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);
86             result = FAIL;
87             break;
88         }
89
90         if (memcmp (&src[1].point, &dst[1].point, sizeof (src->point))) {
91             cairo_test_log (ctx,
92                             "Paths differ in coordinates after %d operations.\n"
93                             "Expected point (%f, %f), found (%f, %f).\n",
94                             n,
95                             src[1].point.x, src[1].point.y,
96                             dst[1].point.x, dst[1].point.y);
97             result = FAIL;
98             break;
99         }
100     }
101
102     cairo_path_destroy (path_copy);
103     return result;
104 }
105
106 CAIRO_TEST (path_precision,
107             "Check that the path append/copy is idempotent.",
108             "api", /* keywords */
109             NULL, /* requirements */
110             0, 0,
111             NULL, draw)