1 /*
2 * Copyright © 2016 Adrian Johnson
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 * Authors:
25 * Adrian Johnson <ajohnson@redneon.com>
26 */
27
28 #include "cairo-test.h"
29
30 /* Check cairo_recording_surface_ink_extents() returns correct extents. */
31
32
33 static cairo_test_status_t
check_extents(cairo_test_context_t * cr,cairo_surface_t * recording_surface,const char * func_name,double expected_x,double expected_y,double expected_w,double expected_h)34 check_extents (cairo_test_context_t *cr,
35 cairo_surface_t *recording_surface,
36 const char * func_name,
37 double expected_x, double expected_y, double expected_w, double expected_h)
38 {
39 double x, y, w, h;
40 cairo_recording_surface_ink_extents (recording_surface, &x, &y, &w, &h);
41 if (x != expected_x ||
42 y != expected_y ||
43 w != expected_w ||
44 h != expected_h)
45 {
46 cairo_test_log (cr,
47 "%s: x: %f, y: %f, w: %f, h: %f\n"
48 " expected: x: %f, y: %f, w: %f, h: %f\n",
49 func_name,
50 x, y, w, h,
51 expected_x, expected_y,
52 expected_w, expected_h);
53 return CAIRO_TEST_ERROR;
54 }
55 return CAIRO_TEST_SUCCESS;
56 }
57
58 static cairo_test_status_t
unbounded_fill(cairo_test_context_t * test_cr)59 unbounded_fill (cairo_test_context_t *test_cr)
60 {
61 cairo_test_status_t status;
62 cairo_surface_t *surface;
63 cairo_t *cr;
64
65 surface = cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA, NULL);
66 cr = cairo_create (surface);
67
68 cairo_rectangle (cr, -300, -150, 900, 600);
69 cairo_fill (cr);
70
71 cairo_destroy(cr);
72
73 status = check_extents (test_cr, surface, __func__,
74 -300, -150, 900, 600);
75 cairo_surface_destroy (surface);
76 return status;
77 }
78
79 static cairo_test_status_t
bounded_fill(cairo_test_context_t * test_cr)80 bounded_fill (cairo_test_context_t *test_cr)
81 {
82 cairo_test_status_t status;
83 cairo_surface_t *surface;
84 cairo_t *cr;
85 cairo_rectangle_t extents = { -150, -100, 300, 200 };
86
87 surface = cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA, &extents);
88 cr = cairo_create (surface);
89
90 cairo_rectangle (cr, -300, -300, 650, 600);
91 cairo_fill (cr);
92
93 cairo_destroy(cr);
94
95 status = check_extents (test_cr, surface, __func__,
96 -150, -100, 300, 200);
97 cairo_surface_destroy (surface);
98 return status;
99 }
100
101 static cairo_test_status_t
unbounded_paint(cairo_test_context_t * test_cr)102 unbounded_paint (cairo_test_context_t *test_cr)
103 {
104 cairo_test_status_t status;
105 cairo_surface_t *surface;
106 cairo_t *cr;
107
108 surface = cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA, NULL);
109 cr = cairo_create (surface);
110
111 cairo_paint (cr);
112
113 cairo_destroy(cr);
114
115 status = check_extents (test_cr, surface, __func__,
116 -(1 << 23), -(1 << 23), -1, -1);
117 cairo_surface_destroy (surface);
118 return status;
119 }
120
121 static cairo_test_status_t
bounded_paint(cairo_test_context_t * test_cr)122 bounded_paint (cairo_test_context_t *test_cr)
123 {
124 cairo_test_status_t status;
125 cairo_surface_t *surface;
126 cairo_t *cr;
127 cairo_rectangle_t extents = { -150, -100, 300, 200 };
128
129 surface = cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA, &extents);
130 cr = cairo_create (surface);
131
132 cairo_paint (cr);
133
134 cairo_destroy(cr);
135
136 status = check_extents (test_cr, surface, __func__,
137 -150, -100, 300, 200);
138 cairo_surface_destroy (surface);
139 return status;
140 }
141
142 static cairo_test_status_t
preamble(cairo_test_context_t * cr)143 preamble (cairo_test_context_t *cr)
144 {
145 cairo_test_status_t status;
146
147 status = unbounded_fill (cr);
148 if (status != CAIRO_TEST_SUCCESS)
149 return status;
150
151 status = bounded_fill (cr);
152 if (status != CAIRO_TEST_SUCCESS)
153 return status;
154
155 status = unbounded_paint (cr);
156 if (status != CAIRO_TEST_SUCCESS)
157 return status;
158
159 status = bounded_paint (cr);
160 if (status != CAIRO_TEST_SUCCESS)
161 return status;
162
163 return CAIRO_TEST_SUCCESS;
164 }
165
166
167 CAIRO_TEST (recording_ink_extents,
168 "Test cairo_recording_surface_ink_extents()",
169 "api,recording,extents", /* keywords */
170 NULL, /* requirements */
171 0, 0,
172 preamble, NULL)
173