2 * Copyright © 2007 Red Hat, Inc.
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 * Author: Carl Worth <cworth@cworth.org>
27 #include "cairo-test.h"
29 #if _XOPEN_SOURCE >= 600 || defined (_ISOC99_SOURCE)
30 #define HAVE_INFINITY 1
33 static cairo_test_draw_function_t draw
;
37 "Test that all relevant public functions return CAIRO_STATUS_INVALID_MATRIX as appropriate",
42 static cairo_test_status_t
43 draw (cairo_t
*cr
, int width
, int height
)
45 cairo_status_t status
;
46 cairo_surface_t
*target
;
47 cairo_font_face_t
*font_face
;
48 cairo_font_options_t
*font_options
;
49 cairo_scaled_font_t
*scaled_font
;
50 cairo_pattern_t
*pattern
;
52 cairo_matrix_t identity
, bogus
, inf
, invalid
= {
58 #define CHECK_STATUS(status, function_name) \
59 if ((status) == CAIRO_STATUS_SUCCESS) { \
60 cairo_test_log ("Error: %s with invalid matrix passed\n", \
62 return CAIRO_TEST_FAILURE; \
63 } else if ((status) != CAIRO_STATUS_INVALID_MATRIX) { \
64 cairo_test_log ("Error: %s with invalid matrix returned unexpected status " \
68 cairo_status_to_string (status)); \
69 return CAIRO_TEST_FAILURE; \
72 /* create a bogus matrix and check results of attempted inversion */
73 bogus
.x0
= bogus
.xy
= bogus
.xx
= strtod ("NaN", NULL
);
74 bogus
.y0
= bogus
.yx
= bogus
.yy
= bogus
.xx
;
75 status
= cairo_matrix_invert (&bogus
);
76 CHECK_STATUS (status
, "cairo_matrix_invert(NaN)");
79 inf
.x0
= inf
.xy
= inf
.xx
= INFINITY
;
80 inf
.y0
= inf
.yx
= inf
.yy
= inf
.xx
;
81 status
= cairo_matrix_invert (&inf
);
82 CHECK_STATUS (status
, "cairo_matrix_invert(infinity)");
85 /* test cairo_matrix_invert with invalid matrix */
86 status
= cairo_matrix_invert (&invalid
);
87 CHECK_STATUS (status
, "cairo_matrix_invert(invalid)");
90 cairo_matrix_init_identity (&identity
);
92 target
= cairo_get_group_target (cr
);
94 /* test cairo_transform with invalid matrix */
95 cr2
= cairo_create (target
);
96 cairo_transform (cr2
, &invalid
);
98 status
= cairo_status (cr2
);
100 CHECK_STATUS (status
, "cairo_transform(invalid)");
102 /* test cairo_transform with bogus matrix */
103 cr2
= cairo_create (target
);
104 cairo_transform (cr2
, &bogus
);
106 status
= cairo_status (cr2
);
108 CHECK_STATUS (status
, "cairo_transform(NaN)");
111 /* test cairo_transform with ∞ matrix */
112 cr2
= cairo_create (target
);
113 cairo_transform (cr2
, &inf
);
115 status
= cairo_status (cr2
);
117 CHECK_STATUS (status
, "cairo_transform(infinity)");
121 /* test cairo_set_matrix with invalid matrix */
122 cr2
= cairo_create (target
);
123 cairo_set_matrix (cr2
, &invalid
);
125 status
= cairo_status (cr2
);
127 CHECK_STATUS (status
, "cairo_set_matrix(invalid)");
129 /* test cairo_set_matrix with bogus matrix */
130 cr2
= cairo_create (target
);
131 cairo_set_matrix (cr2
, &bogus
);
133 status
= cairo_status (cr2
);
135 CHECK_STATUS (status
, "cairo_set_matrix(NaN)");
138 /* test cairo_set_matrix with ∞ matrix */
139 cr2
= cairo_create (target
);
140 cairo_set_matrix (cr2
, &inf
);
142 status
= cairo_status (cr2
);
144 CHECK_STATUS (status
, "cairo_set_matrix(infinity)");
148 /* test cairo_set_font_matrix with invalid matrix */
149 cr2
= cairo_create (target
);
150 cairo_set_font_matrix (cr2
, &invalid
);
152 /* draw some text to force the font to be resolved */
153 cairo_show_text (cr2
, "hello");
155 status
= cairo_status (cr2
);
157 CHECK_STATUS (status
, "cairo_set_font_matrix(invalid)");
159 /* test cairo_set_font_matrix with bogus matrix */
160 cr2
= cairo_create (target
);
161 cairo_set_font_matrix (cr2
, &bogus
);
163 /* draw some text to force the font to be resolved */
164 cairo_show_text (cr2
, "hello");
166 status
= cairo_status (cr2
);
168 CHECK_STATUS (status
, "cairo_set_font_matrix(NaN)");
171 /* test cairo_set_font_matrix with ∞ matrix */
172 cr2
= cairo_create (target
);
173 cairo_set_font_matrix (cr2
, &inf
);
175 /* draw some text to force the font to be resolved */
176 cairo_show_text (cr2
, "hello");
178 status
= cairo_status (cr2
);
180 CHECK_STATUS (status
, "cairo_set_font_matrix(infinity)");
184 /* test cairo_scaled_font_create with invalid matrix */
185 cr2
= cairo_create (target
);
186 font_face
= cairo_get_font_face (cr2
);
187 font_options
= cairo_font_options_create ();
188 cairo_get_font_options (cr
, font_options
);
189 scaled_font
= cairo_scaled_font_create (font_face
,
193 status
= cairo_scaled_font_status (scaled_font
);
194 CHECK_STATUS (status
, "cairo_scaled_font_create(invalid)");
196 cairo_scaled_font_destroy (scaled_font
);
198 scaled_font
= cairo_scaled_font_create (font_face
,
202 status
= cairo_scaled_font_status (scaled_font
);
203 CHECK_STATUS (status
, "cairo_scaled_font_create(invalid)");
205 cairo_scaled_font_destroy (scaled_font
);
206 cairo_font_options_destroy (font_options
);
209 /* test cairo_scaled_font_create with bogus matrix */
210 cr2
= cairo_create (target
);
211 font_face
= cairo_get_font_face (cr2
);
212 font_options
= cairo_font_options_create ();
213 cairo_get_font_options (cr
, font_options
);
214 scaled_font
= cairo_scaled_font_create (font_face
,
218 status
= cairo_scaled_font_status (scaled_font
);
219 CHECK_STATUS (status
, "cairo_scaled_font_create(NaN)");
221 cairo_scaled_font_destroy (scaled_font
);
223 scaled_font
= cairo_scaled_font_create (font_face
,
227 status
= cairo_scaled_font_status (scaled_font
);
228 CHECK_STATUS (status
, "cairo_scaled_font_create(NaN)");
230 cairo_scaled_font_destroy (scaled_font
);
231 cairo_font_options_destroy (font_options
);
235 /* test cairo_scaled_font_create with ∞ matrix */
236 cr2
= cairo_create (target
);
237 font_face
= cairo_get_font_face (cr2
);
238 font_options
= cairo_font_options_create ();
239 cairo_get_font_options (cr
, font_options
);
240 scaled_font
= cairo_scaled_font_create (font_face
,
244 status
= cairo_scaled_font_status (scaled_font
);
245 CHECK_STATUS (status
, "cairo_scaled_font_create(infinity)");
247 cairo_scaled_font_destroy (scaled_font
);
249 scaled_font
= cairo_scaled_font_create (font_face
,
253 status
= cairo_scaled_font_status (scaled_font
);
254 CHECK_STATUS (status
, "cairo_scaled_font_create(infinity)");
256 cairo_scaled_font_destroy (scaled_font
);
257 cairo_font_options_destroy (font_options
);
262 /* test cairo_pattern_set_matrix with invalid matrix */
263 pattern
= cairo_pattern_create_rgb (1.0, 1.0, 1.0);
264 cairo_pattern_set_matrix (pattern
, &invalid
);
265 status
= cairo_pattern_status (pattern
);
266 CHECK_STATUS (status
, "cairo_pattern_set_matrix(invalid)");
267 cairo_pattern_destroy (pattern
);
269 /* test cairo_pattern_set_matrix with bogus matrix */
270 pattern
= cairo_pattern_create_rgb (1.0, 1.0, 1.0);
271 cairo_pattern_set_matrix (pattern
, &bogus
);
272 status
= cairo_pattern_status (pattern
);
273 CHECK_STATUS (status
, "cairo_pattern_set_matrix(NaN)");
274 cairo_pattern_destroy (pattern
);
277 /* test cairo_pattern_set_matrix with ∞ matrix */
278 pattern
= cairo_pattern_create_rgb (1.0, 1.0, 1.0);
279 cairo_pattern_set_matrix (pattern
, &inf
);
280 status
= cairo_pattern_status (pattern
);
281 CHECK_STATUS (status
, "cairo_pattern_set_matrix(infinity)");
282 cairo_pattern_destroy (pattern
);
286 /* test invalid transformations */
287 cr2
= cairo_create (target
);
288 cairo_translate (cr2
, bogus
.xx
, bogus
.yy
);
289 CHECK_STATUS (status
, "cairo_translate(NaN, NaN)");
292 cr2
= cairo_create (target
);
293 cairo_translate (cr2
, 0, bogus
.yy
);
294 CHECK_STATUS (status
, "cairo_translate(0, NaN)");
297 cr2
= cairo_create (target
);
298 cairo_translate (cr2
, bogus
.xx
, 0);
299 CHECK_STATUS (status
, "cairo_translate(NaN, 0)");
303 cr2
= cairo_create (target
);
304 cairo_translate (cr2
, inf
.xx
, inf
.yy
);
305 CHECK_STATUS (status
, "cairo_translate(∞, ∞)");
308 cr2
= cairo_create (target
);
309 cairo_translate (cr2
, 0, inf
.yy
);
310 CHECK_STATUS (status
, "cairo_translate(0, ∞)");
313 cr2
= cairo_create (target
);
314 cairo_translate (cr2
, inf
.xx
, 0);
315 CHECK_STATUS (status
, "cairo_translate(∞, 0)");
320 cr2
= cairo_create (target
);
321 cairo_scale (cr2
, bogus
.xx
, bogus
.yy
);
322 CHECK_STATUS (status
, "cairo_scale(NaN, NaN)");
325 cr2
= cairo_create (target
);
326 cairo_scale (cr2
, 1, bogus
.yy
);
327 CHECK_STATUS (status
, "cairo_scale(1, NaN)");
330 cr2
= cairo_create (target
);
331 cairo_scale (cr2
, bogus
.xx
, 1);
332 CHECK_STATUS (status
, "cairo_scale(NaN, 1)");
336 cr2
= cairo_create (target
);
337 cairo_scale (cr2
, inf
.xx
, inf
.yy
);
338 CHECK_STATUS (status
, "cairo_scale(∞, ∞)");
341 cr2
= cairo_create (target
);
342 cairo_scale (cr2
, 1, inf
.yy
);
343 CHECK_STATUS (status
, "cairo_scale(1, ∞)");
346 cr2
= cairo_create (target
);
347 cairo_scale (cr2
, inf
.xx
, 1);
348 CHECK_STATUS (status
, "cairo_scale(∞, 1)");
352 cr2
= cairo_create (target
);
353 cairo_scale (cr2
, bogus
.xx
, bogus
.yy
);
354 CHECK_STATUS (status
, "cairo_scale(0, 0)");
357 cr2
= cairo_create (target
);
358 cairo_scale (cr2
, 1, bogus
.yy
);
359 CHECK_STATUS (status
, "cairo_scale(1, 0)");
362 cr2
= cairo_create (target
);
363 cairo_scale (cr2
, bogus
.xx
, 1);
364 CHECK_STATUS (status
, "cairo_scale(0, 1)");
368 cr2
= cairo_create (target
);
369 cairo_rotate (cr2
, bogus
.xx
);
370 CHECK_STATUS (status
, "cairo_rotate(NaN)");
374 cr2
= cairo_create (target
);
375 cairo_rotate (cr2
, inf
.xx
);
376 CHECK_STATUS (status
, "cairo_rotate(∞)");
380 return CAIRO_TEST_SUCCESS
;
386 return cairo_test (&test
);