[check] Filter programlistings for check-doc-syntax.sh
[cairo/haiku.git] / test / invalid-matrix.c
blob42240bc9d2dfdcbb9efe4eda9933ea97a2762710
1 /*
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
22 * SOFTWARE.
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
31 #endif
33 static cairo_test_draw_function_t draw;
35 cairo_test_t test = {
36 "invalid-matrix",
37 "Test that all relevant public functions return CAIRO_STATUS_INVALID_MATRIX as appropriate",
38 0, 0,
39 draw
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;
51 cairo_t *cr2;
52 cairo_matrix_t identity, bogus, inf, invalid = {
53 4.0, 4.0,
54 4.0, 4.0,
55 4.0, 4.0
58 #define CHECK_STATUS(status, function_name) \
59 if ((status) == CAIRO_STATUS_SUCCESS) { \
60 cairo_test_log ("Error: %s with invalid matrix passed\n", \
61 (function_name)); \
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 " \
65 "(%d): %s\n", \
66 (function_name), \
67 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)");
78 #if HAVE_INFINITY
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)");
83 #endif
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);
99 cairo_destroy (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);
107 cairo_destroy (cr2);
108 CHECK_STATUS (status, "cairo_transform(NaN)");
110 #if HAVE_INFINITY
111 /* test cairo_transform with ∞ matrix */
112 cr2 = cairo_create (target);
113 cairo_transform (cr2, &inf);
115 status = cairo_status (cr2);
116 cairo_destroy (cr2);
117 CHECK_STATUS (status, "cairo_transform(infinity)");
118 #endif
121 /* test cairo_set_matrix with invalid matrix */
122 cr2 = cairo_create (target);
123 cairo_set_matrix (cr2, &invalid);
125 status = cairo_status (cr2);
126 cairo_destroy (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);
134 cairo_destroy (cr2);
135 CHECK_STATUS (status, "cairo_set_matrix(NaN)");
137 #if HAVE_INFINITY
138 /* test cairo_set_matrix with ∞ matrix */
139 cr2 = cairo_create (target);
140 cairo_set_matrix (cr2, &inf);
142 status = cairo_status (cr2);
143 cairo_destroy (cr2);
144 CHECK_STATUS (status, "cairo_set_matrix(infinity)");
145 #endif
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);
156 cairo_destroy (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);
167 cairo_destroy (cr2);
168 CHECK_STATUS (status, "cairo_set_font_matrix(NaN)");
170 #if HAVE_INFINITY
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);
179 cairo_destroy (cr2);
180 CHECK_STATUS (status, "cairo_set_font_matrix(infinity)");
181 #endif
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,
190 &invalid,
191 &identity,
192 font_options);
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,
199 &identity,
200 &invalid,
201 font_options);
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);
207 cairo_destroy (cr2);
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,
215 &bogus,
216 &identity,
217 font_options);
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,
224 &identity,
225 &bogus,
226 font_options);
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);
232 cairo_destroy (cr2);
234 #if HAVE_INFINITY
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,
241 &inf,
242 &identity,
243 font_options);
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,
250 &identity,
251 &inf,
252 font_options);
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);
258 cairo_destroy (cr2);
259 #endif
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);
276 #if HAVE_INFINITY
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);
283 #endif
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)");
290 cairo_destroy (cr2);
292 cr2 = cairo_create (target);
293 cairo_translate (cr2, 0, bogus.yy);
294 CHECK_STATUS (status, "cairo_translate(0, NaN)");
295 cairo_destroy (cr2);
297 cr2 = cairo_create (target);
298 cairo_translate (cr2, bogus.xx, 0);
299 CHECK_STATUS (status, "cairo_translate(NaN, 0)");
300 cairo_destroy (cr2);
302 #if HAVE_INFINITY
303 cr2 = cairo_create (target);
304 cairo_translate (cr2, inf.xx, inf.yy);
305 CHECK_STATUS (status, "cairo_translate(∞, ∞)");
306 cairo_destroy (cr2);
308 cr2 = cairo_create (target);
309 cairo_translate (cr2, 0, inf.yy);
310 CHECK_STATUS (status, "cairo_translate(0, ∞)");
311 cairo_destroy (cr2);
313 cr2 = cairo_create (target);
314 cairo_translate (cr2, inf.xx, 0);
315 CHECK_STATUS (status, "cairo_translate(∞, 0)");
316 cairo_destroy (cr2);
317 #endif
320 cr2 = cairo_create (target);
321 cairo_scale (cr2, bogus.xx, bogus.yy);
322 CHECK_STATUS (status, "cairo_scale(NaN, NaN)");
323 cairo_destroy (cr2);
325 cr2 = cairo_create (target);
326 cairo_scale (cr2, 1, bogus.yy);
327 CHECK_STATUS (status, "cairo_scale(1, NaN)");
328 cairo_destroy (cr2);
330 cr2 = cairo_create (target);
331 cairo_scale (cr2, bogus.xx, 1);
332 CHECK_STATUS (status, "cairo_scale(NaN, 1)");
333 cairo_destroy (cr2);
335 #if HAVE_INFINITY
336 cr2 = cairo_create (target);
337 cairo_scale (cr2, inf.xx, inf.yy);
338 CHECK_STATUS (status, "cairo_scale(∞, ∞)");
339 cairo_destroy (cr2);
341 cr2 = cairo_create (target);
342 cairo_scale (cr2, 1, inf.yy);
343 CHECK_STATUS (status, "cairo_scale(1, ∞)");
344 cairo_destroy (cr2);
346 cr2 = cairo_create (target);
347 cairo_scale (cr2, inf.xx, 1);
348 CHECK_STATUS (status, "cairo_scale(∞, 1)");
349 cairo_destroy (cr2);
350 #endif
352 cr2 = cairo_create (target);
353 cairo_scale (cr2, bogus.xx, bogus.yy);
354 CHECK_STATUS (status, "cairo_scale(0, 0)");
355 cairo_destroy (cr2);
357 cr2 = cairo_create (target);
358 cairo_scale (cr2, 1, bogus.yy);
359 CHECK_STATUS (status, "cairo_scale(1, 0)");
360 cairo_destroy (cr2);
362 cr2 = cairo_create (target);
363 cairo_scale (cr2, bogus.xx, 1);
364 CHECK_STATUS (status, "cairo_scale(0, 1)");
365 cairo_destroy (cr2);
368 cr2 = cairo_create (target);
369 cairo_rotate (cr2, bogus.xx);
370 CHECK_STATUS (status, "cairo_rotate(NaN)");
371 cairo_destroy (cr2);
373 #if HAVE_INFINITY
374 cr2 = cairo_create (target);
375 cairo_rotate (cr2, inf.xx);
376 CHECK_STATUS (status, "cairo_rotate(∞)");
377 cairo_destroy (cr2);
378 #endif
380 return CAIRO_TEST_SUCCESS;
384 main (void)
386 return cairo_test (&test);