2 * Copyright © 2010 Red Hat Inc.
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 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Red Hat, Inc. 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 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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: Benjamin Otte <otte@redhat.com>
29 * This test tests that for all public APIs Cairo behaves correct, consistent
30 * and most of all doesn't crash. It does this by calling all APIs that take
31 * surfaces or contexts and calling them on specially prepared arguments that
32 * should fail when called on this function.
34 * ADDING NEW FUNCTIONS
36 * You need (for adding the function cairo_surface_foo):
37 * 1) A surface_test_func_t named test_cairo_surface_foo that gets passed the
38 * prepared surface and has the job of calling the function and checking
39 * the return value (if one exists) for correctness. The top of this file
40 * contains all these shim functions.
41 * 2) Knowledge if the function behaves like a setter or like a getter. A
42 * setter should set an error status on the surface, a getter does not
43 * modify the function.
44 * 3) Knowledge if the function only works for a specific surface type and for
46 * 4) An entry in the tests array using the TEST() macro. It takes as arguments:
48 * - TRUE if the function modifies the surface, FALSE otherwise
49 * - the surface type for which the function is valid or -1 if it is valid
50 * for all surface types.
54 * The test will dump failures notices into the api-special-cases.log file (when
55 * it doesn't crash). These should be pretty self-explanatory. Usually it is
56 * enough to just add a new check to the function it complained about.
66 #include "cairo-test.h"
68 #if CAIRO_HAS_GL_SURFACE
71 #if CAIRO_HAS_OS2_SURFACE
72 #include <cairo-os2.h>
74 #if CAIRO_HAS_PDF_SURFACE
75 #include <cairo-pdf.h>
77 #if CAIRO_HAS_PS_SURFACE
80 #if CAIRO_HAS_QUARTZ_SURFACE
81 #define Cursor QuartzCursor
82 #include <cairo-quartz.h>
85 #if CAIRO_HAS_SVG_SURFACE
86 #include <cairo-svg.h>
88 #if CAIRO_HAS_TEE_SURFACE
89 #include <cairo-tee.h>
91 #if CAIRO_HAS_XCB_SURFACE
92 #include <cairo-xcb.h>
94 #if CAIRO_HAS_XLIB_SURFACE
95 #define Cursor XCursor
96 #include <cairo-xlib.h>
100 #define surface_has_type(surface,type) (cairo_surface_get_type (surface) == (type))
102 typedef cairo_test_status_t (* surface_test_func_t) (cairo_surface_t *surface);
103 typedef cairo_test_status_t (* context_test_func_t) (cairo_t *cr);
105 static cairo_test_status_t
106 test_cairo_reference (cairo_t *cr)
108 cairo_destroy (cairo_reference (cr));
110 return CAIRO_TEST_SUCCESS;
113 static cairo_test_status_t
114 test_cairo_get_reference_count (cairo_t *cr)
116 unsigned int refcount = cairo_get_reference_count (cr);
118 return CAIRO_TEST_SUCCESS;
119 /* inert error context have a refcount of 0 */
120 return cairo_status (cr) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
123 static cairo_test_status_t
124 test_cairo_set_user_data (cairo_t *cr)
126 static cairo_user_data_key_t key;
127 cairo_status_t status;
129 status = cairo_set_user_data (cr, &key, &key, NULL);
130 if (status == CAIRO_STATUS_NO_MEMORY)
131 return CAIRO_TEST_NO_MEMORY;
133 return CAIRO_TEST_SUCCESS;
135 if (cairo_get_user_data (cr, &key) != &key)
136 return CAIRO_TEST_ERROR;
138 return CAIRO_TEST_SUCCESS;
141 static cairo_test_status_t
142 test_cairo_save (cairo_t *cr)
147 return CAIRO_TEST_SUCCESS;
150 static cairo_test_status_t
151 test_cairo_push_group (cairo_t *cr)
153 cairo_pattern_t *pattern;
154 cairo_status_t status;
156 cairo_push_group (cr);
157 pattern = cairo_pop_group (cr);
158 status = cairo_pattern_status (pattern);
159 cairo_pattern_destroy (pattern);
161 return status == CAIRO_STATUS_SUCCESS || status == cairo_status (cr) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
164 static cairo_test_status_t
165 test_cairo_push_group_with_content (cairo_t *cr)
167 cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
168 cairo_pop_group_to_source (cr);
170 return CAIRO_TEST_SUCCESS;
173 static cairo_test_status_t
174 test_cairo_set_operator (cairo_t *cr)
176 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
178 return CAIRO_TEST_SUCCESS;
181 static cairo_test_status_t
182 test_cairo_set_source (cairo_t *cr)
184 cairo_pattern_t *source = cairo_pattern_create_rgb (0, 0, 0);
185 cairo_set_source (cr, source);
186 cairo_pattern_destroy (source);
188 return CAIRO_TEST_SUCCESS;
191 static cairo_test_status_t
192 test_cairo_set_source_rgb (cairo_t *cr)
194 cairo_set_source_rgb (cr, 0, 0, 0);
196 return CAIRO_TEST_SUCCESS;
199 static cairo_test_status_t
200 test_cairo_set_source_rgba (cairo_t *cr)
202 cairo_set_source_rgba (cr, 0, 0, 0, 1);
204 return CAIRO_TEST_SUCCESS;
207 static cairo_test_status_t
208 test_cairo_set_source_surface (cairo_t *cr)
210 cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
211 cairo_set_source_surface (cr, surface, 0, 0);
212 cairo_surface_destroy (surface);
214 return CAIRO_TEST_SUCCESS;
217 static cairo_test_status_t
218 test_cairo_set_tolerance (cairo_t *cr)
220 cairo_set_tolerance (cr, 42);
222 return CAIRO_TEST_SUCCESS;
225 static cairo_test_status_t
226 test_cairo_set_antialias (cairo_t *cr)
228 cairo_set_antialias (cr, CAIRO_ANTIALIAS_BEST);
230 return CAIRO_TEST_SUCCESS;
233 static cairo_test_status_t
234 test_cairo_set_fill_rule (cairo_t *cr)
236 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
238 return CAIRO_TEST_SUCCESS;
241 static cairo_test_status_t
242 test_cairo_set_line_width (cairo_t *cr)
244 cairo_set_line_width (cr, 42);
246 return CAIRO_TEST_SUCCESS;
249 static cairo_test_status_t
250 test_cairo_set_line_cap (cairo_t *cr)
252 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
254 return CAIRO_TEST_SUCCESS;
257 static cairo_test_status_t
258 test_cairo_set_line_join (cairo_t *cr)
260 cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
262 return CAIRO_TEST_SUCCESS;
265 static cairo_test_status_t
266 test_cairo_set_dash (cairo_t *cr)
268 cairo_set_dash (cr, NULL, 0, 0);
270 return CAIRO_TEST_SUCCESS;
273 static cairo_test_status_t
274 test_cairo_set_miter_limit (cairo_t *cr)
276 cairo_set_miter_limit (cr, 2);
278 return CAIRO_TEST_SUCCESS;
281 static cairo_test_status_t
282 test_cairo_translate (cairo_t *cr)
284 cairo_translate (cr, 2, 2);
286 return CAIRO_TEST_SUCCESS;
289 static cairo_test_status_t
290 test_cairo_scale (cairo_t *cr)
292 cairo_scale (cr, 2, 2);
294 return CAIRO_TEST_SUCCESS;
297 static cairo_test_status_t
298 test_cairo_rotate (cairo_t *cr)
300 cairo_rotate (cr, 2);
302 return CAIRO_TEST_SUCCESS;
305 static cairo_test_status_t
306 test_cairo_transform (cairo_t *cr)
308 cairo_matrix_t matrix;
310 cairo_matrix_init_translate (&matrix, 1, 1);
311 cairo_transform (cr, &matrix);
313 return CAIRO_TEST_SUCCESS;
316 static cairo_test_status_t
317 test_cairo_set_matrix (cairo_t *cr)
319 cairo_matrix_t matrix;
321 cairo_matrix_init_translate (&matrix, 1, 1);
322 cairo_set_matrix (cr, &matrix);
324 return CAIRO_TEST_SUCCESS;
327 static cairo_test_status_t
328 test_cairo_identity_matrix (cairo_t *cr)
330 cairo_identity_matrix (cr);
332 return CAIRO_TEST_SUCCESS;
335 static cairo_test_status_t
336 test_cairo_user_to_device (cairo_t *cr)
338 double x = 42, y = 42;
340 cairo_user_to_device (cr, &x, &y);
342 return CAIRO_TEST_SUCCESS;
345 static cairo_test_status_t
346 test_cairo_user_to_device_distance (cairo_t *cr)
348 double x = 42, y = 42;
350 cairo_user_to_device_distance (cr, &x, &y);
352 return CAIRO_TEST_SUCCESS;
355 static cairo_test_status_t
356 test_cairo_device_to_user (cairo_t *cr)
358 double x = 42, y = 42;
360 cairo_device_to_user (cr, &x, &y);
362 return CAIRO_TEST_SUCCESS;
365 static cairo_test_status_t
366 test_cairo_device_to_user_distance (cairo_t *cr)
368 double x = 42, y = 42;
370 cairo_device_to_user_distance (cr, &x, &y);
372 return CAIRO_TEST_SUCCESS;
375 static cairo_test_status_t
376 test_cairo_new_path (cairo_t *cr)
380 return CAIRO_TEST_SUCCESS;
383 static cairo_test_status_t
384 test_cairo_move_to (cairo_t *cr)
386 cairo_move_to (cr, 2, 2);
388 return CAIRO_TEST_SUCCESS;
391 static cairo_test_status_t
392 test_cairo_new_sub_path (cairo_t *cr)
394 cairo_new_sub_path (cr);
396 return CAIRO_TEST_SUCCESS;
399 static cairo_test_status_t
400 test_cairo_line_to (cairo_t *cr)
402 cairo_line_to (cr, 2, 2);
404 return CAIRO_TEST_SUCCESS;
407 static cairo_test_status_t
408 test_cairo_curve_to (cairo_t *cr)
410 cairo_curve_to (cr, 2, 2, 3, 3, 4, 4);
412 return CAIRO_TEST_SUCCESS;
415 static cairo_test_status_t
416 test_cairo_arc (cairo_t *cr)
418 cairo_arc (cr, 2, 2, 3, 0, 2 * M_PI);
420 return CAIRO_TEST_SUCCESS;
423 static cairo_test_status_t
424 test_cairo_arc_negative (cairo_t *cr)
426 cairo_arc_negative (cr, 2, 2, 3, 0, 2 * M_PI);
428 return CAIRO_TEST_SUCCESS;
431 static cairo_test_status_t
432 test_cairo_rel_move_to (cairo_t *cr)
434 cairo_rel_move_to (cr, 2, 2);
436 return CAIRO_TEST_SUCCESS;
439 static cairo_test_status_t
440 test_cairo_rel_line_to (cairo_t *cr)
442 cairo_rel_line_to (cr, 2, 2);
444 return CAIRO_TEST_SUCCESS;
447 static cairo_test_status_t
448 test_cairo_rel_curve_to (cairo_t *cr)
450 cairo_rel_curve_to (cr, 2, 2, 3, 3, 4, 4);
452 return CAIRO_TEST_SUCCESS;
455 static cairo_test_status_t
456 test_cairo_rectangle (cairo_t *cr)
458 cairo_rectangle (cr, 2, 2, 3, 3);
460 return CAIRO_TEST_SUCCESS;
463 static cairo_test_status_t
464 test_cairo_close_path (cairo_t *cr)
466 cairo_close_path (cr);
468 return CAIRO_TEST_SUCCESS;
471 static cairo_test_status_t
472 test_cairo_path_extents (cairo_t *cr)
474 double x1, y1, x2, y2;
475 cairo_path_extents (cr, &x1, &y1, &x2, &y2);
477 return CAIRO_TEST_SUCCESS;
480 static cairo_test_status_t
481 test_cairo_paint (cairo_t *cr)
485 return CAIRO_TEST_SUCCESS;
488 static cairo_test_status_t
489 test_cairo_paint_with_alpha (cairo_t *cr)
491 cairo_paint_with_alpha (cr, 0.5);
493 return CAIRO_TEST_SUCCESS;
496 static cairo_test_status_t
497 test_cairo_mask (cairo_t *cr)
499 cairo_pattern_t *pattern;
501 pattern = cairo_pattern_create_rgb (0.5, 0.5, 0.5);
502 cairo_mask (cr, pattern);
504 cairo_pattern_destroy (pattern);
505 return CAIRO_TEST_SUCCESS;
508 static cairo_test_status_t
509 test_cairo_mask_surface (cairo_t *cr)
511 cairo_surface_t *surface;
513 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
514 cairo_mask_surface (cr, surface, 0, 0);
516 cairo_surface_destroy (surface);
517 return CAIRO_TEST_SUCCESS;
520 static cairo_test_status_t
521 test_cairo_stroke (cairo_t *cr)
525 return CAIRO_TEST_SUCCESS;
528 static cairo_test_status_t
529 test_cairo_stroke_preserve (cairo_t *cr)
531 cairo_stroke_preserve (cr);
533 return CAIRO_TEST_SUCCESS;
536 static cairo_test_status_t
537 test_cairo_fill (cairo_t *cr)
541 return CAIRO_TEST_SUCCESS;
544 static cairo_test_status_t
545 test_cairo_fill_preserve (cairo_t *cr)
547 cairo_fill_preserve (cr);
549 return CAIRO_TEST_SUCCESS;
552 static cairo_test_status_t
553 test_cairo_copy_page (cairo_t *cr)
555 cairo_copy_page (cr);
557 return CAIRO_TEST_SUCCESS;
560 static cairo_test_status_t
561 test_cairo_show_page (cairo_t *cr)
563 cairo_show_page (cr);
565 return CAIRO_TEST_SUCCESS;
568 static cairo_test_status_t
569 test_cairo_in_stroke (cairo_t *cr)
571 cairo_in_stroke (cr, 1, 1);
573 return CAIRO_TEST_SUCCESS;
576 static cairo_test_status_t
577 test_cairo_in_fill (cairo_t *cr)
579 cairo_in_fill (cr, 1, 1);
581 return CAIRO_TEST_SUCCESS;
584 static cairo_test_status_t
585 test_cairo_in_clip (cairo_t *cr)
587 cairo_in_clip (cr, 1, 1);
589 return CAIRO_TEST_SUCCESS;
592 static cairo_test_status_t
593 test_cairo_stroke_extents (cairo_t *cr)
595 double x1, y1, x2, y2;
596 cairo_stroke_extents (cr, &x1, &y1, &x2, &y2);
598 return CAIRO_TEST_SUCCESS;
601 static cairo_test_status_t
602 test_cairo_fill_extents (cairo_t *cr)
604 double x1, y1, x2, y2;
605 cairo_fill_extents (cr, &x1, &y1, &x2, &y2);
607 return CAIRO_TEST_SUCCESS;
610 static cairo_test_status_t
611 test_cairo_reset_clip (cairo_t *cr)
613 cairo_reset_clip (cr);
615 return CAIRO_TEST_SUCCESS;
618 static cairo_test_status_t
619 test_cairo_clip (cairo_t *cr)
623 return CAIRO_TEST_SUCCESS;
626 static cairo_test_status_t
627 test_cairo_clip_preserve (cairo_t *cr)
629 cairo_clip_preserve (cr);
631 return CAIRO_TEST_SUCCESS;
634 static cairo_test_status_t
635 test_cairo_clip_extents (cairo_t *cr)
637 double x1, y1, x2, y2;
638 cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
640 return CAIRO_TEST_SUCCESS;
643 static cairo_test_status_t
644 test_cairo_copy_clip_rectangle_list (cairo_t *cr)
646 cairo_rectangle_list_destroy (cairo_copy_clip_rectangle_list (cr));
648 return CAIRO_TEST_SUCCESS;
651 static cairo_test_status_t
652 test_cairo_select_font_face (cairo_t *cr)
654 cairo_select_font_face (cr, "Arial", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
656 return CAIRO_TEST_SUCCESS;
659 static cairo_test_status_t
660 test_cairo_set_font_size (cairo_t *cr)
662 cairo_set_font_size (cr, 42);
664 return CAIRO_TEST_SUCCESS;
667 static cairo_test_status_t
668 test_cairo_set_font_matrix (cairo_t *cr)
670 cairo_matrix_t matrix;
672 cairo_matrix_init_translate (&matrix, 1, 1);
673 cairo_set_font_matrix (cr, &matrix);
675 return CAIRO_TEST_SUCCESS;
678 static cairo_test_status_t
679 test_cairo_get_font_matrix (cairo_t *cr)
681 cairo_matrix_t matrix;
683 cairo_get_font_matrix (cr, &matrix);
685 return CAIRO_TEST_SUCCESS;
688 static cairo_test_status_t
689 test_cairo_set_font_options (cairo_t *cr)
691 cairo_font_options_t *opt = cairo_font_options_create ();
692 cairo_set_font_options (cr, opt);
693 cairo_font_options_destroy (opt);
695 return CAIRO_TEST_SUCCESS;
698 static cairo_test_status_t
699 test_cairo_get_font_options (cairo_t *cr)
701 cairo_font_options_t *opt = cairo_font_options_create ();
702 cairo_get_font_options (cr, opt);
703 cairo_font_options_destroy (opt);
705 return CAIRO_TEST_SUCCESS;
708 static cairo_test_status_t
709 test_cairo_set_font_face (cairo_t *cr)
711 cairo_set_font_face (cr, cairo_get_font_face (cr));
713 return CAIRO_TEST_SUCCESS;
716 static cairo_test_status_t
717 test_cairo_set_scaled_font (cairo_t *cr)
719 cairo_set_scaled_font (cr, cairo_get_scaled_font (cr));
721 return CAIRO_TEST_SUCCESS;
724 static cairo_test_status_t
725 test_cairo_show_text (cairo_t *cr)
727 cairo_show_text (cr, "Cairo");
729 return CAIRO_TEST_SUCCESS;
732 static cairo_test_status_t
733 test_cairo_show_glyphs (cairo_t *cr)
741 cairo_show_glyphs (cr, &glyph, 1);
743 return CAIRO_TEST_SUCCESS;
746 static cairo_test_status_t
747 test_cairo_show_text_glyphs (cairo_t *cr)
750 cairo_text_cluster_t cluster;
756 cluster.num_bytes = 1;
757 cluster.num_glyphs = 1;
759 cairo_show_text_glyphs (cr, "a", -1, &glyph, 1, &cluster, 1, 0);
761 return CAIRO_TEST_SUCCESS;
764 static cairo_test_status_t
765 test_cairo_text_path (cairo_t *cr)
767 cairo_text_path (cr, "Cairo");
769 return CAIRO_TEST_SUCCESS;
772 static cairo_test_status_t
773 test_cairo_glyph_path (cairo_t *cr)
781 cairo_glyph_path (cr, &glyph, 1);
783 return CAIRO_TEST_SUCCESS;
786 static cairo_test_status_t
787 test_cairo_text_extents (cairo_t *cr)
789 cairo_text_extents_t extents;
791 cairo_text_extents (cr, "Cairo", &extents);
793 return CAIRO_TEST_SUCCESS;
796 static cairo_test_status_t
797 test_cairo_glyph_extents (cairo_t *cr)
800 cairo_text_extents_t extents;
806 cairo_glyph_extents (cr, &glyph, 1, &extents);
808 return CAIRO_TEST_SUCCESS;
811 static cairo_test_status_t
812 test_cairo_font_extents (cairo_t *cr)
814 cairo_font_extents_t extents;
816 cairo_font_extents (cr, &extents);
818 return CAIRO_TEST_SUCCESS;
821 static cairo_test_status_t
822 test_cairo_get_operator (cairo_t *cr)
824 cairo_get_operator (cr);
826 return CAIRO_TEST_SUCCESS;
829 static cairo_test_status_t
830 test_cairo_get_source (cairo_t *cr)
832 cairo_get_source (cr);
834 return CAIRO_TEST_SUCCESS;
837 static cairo_test_status_t
838 test_cairo_get_tolerance (cairo_t *cr)
840 cairo_get_tolerance (cr);
842 return CAIRO_TEST_SUCCESS;
845 static cairo_test_status_t
846 test_cairo_get_antialias (cairo_t *cr)
848 cairo_get_antialias (cr);
850 return CAIRO_TEST_SUCCESS;
853 static cairo_test_status_t
854 test_cairo_has_current_point (cairo_t *cr)
856 cairo_has_current_point (cr);
858 return CAIRO_TEST_SUCCESS;
861 static cairo_test_status_t
862 test_cairo_get_current_point (cairo_t *cr)
866 cairo_get_current_point (cr, &x, &y);
868 return CAIRO_TEST_SUCCESS;
871 static cairo_test_status_t
872 test_cairo_get_fill_rule (cairo_t *cr)
874 cairo_get_fill_rule (cr);
876 return CAIRO_TEST_SUCCESS;
879 static cairo_test_status_t
880 test_cairo_get_line_width (cairo_t *cr)
882 cairo_get_line_width (cr);
884 return CAIRO_TEST_SUCCESS;
887 static cairo_test_status_t
888 test_cairo_get_line_cap (cairo_t *cr)
890 cairo_get_line_cap (cr);
892 return CAIRO_TEST_SUCCESS;
895 static cairo_test_status_t
896 test_cairo_get_line_join (cairo_t *cr)
898 cairo_get_line_join (cr);
900 return CAIRO_TEST_SUCCESS;
903 static cairo_test_status_t
904 test_cairo_get_miter_limit (cairo_t *cr)
906 cairo_get_miter_limit (cr);
908 return CAIRO_TEST_SUCCESS;
911 static cairo_test_status_t
912 test_cairo_get_dash_count (cairo_t *cr)
914 cairo_get_dash_count (cr);
916 return CAIRO_TEST_SUCCESS;
919 static cairo_test_status_t
920 test_cairo_get_dash (cairo_t *cr)
925 cairo_get_dash (cr, &dashes[0], &offset);
927 return CAIRO_TEST_SUCCESS;
930 static cairo_test_status_t
931 test_cairo_get_matrix (cairo_t *cr)
933 cairo_matrix_t matrix;
935 cairo_get_matrix (cr, &matrix);
937 return CAIRO_TEST_SUCCESS;
940 static cairo_test_status_t
941 test_cairo_get_target (cairo_t *cr)
943 cairo_get_target (cr);
945 return CAIRO_TEST_SUCCESS;
948 static cairo_test_status_t
949 test_cairo_get_group_target (cairo_t *cr)
951 cairo_get_group_target (cr);
953 return CAIRO_TEST_SUCCESS;
956 static cairo_test_status_t
957 test_cairo_copy_path (cairo_t *cr)
959 cairo_path_destroy (cairo_copy_path (cr));
961 return CAIRO_TEST_SUCCESS;
964 static cairo_test_status_t
965 test_cairo_copy_path_flat (cairo_t *cr)
967 cairo_path_destroy (cairo_copy_path_flat (cr));
969 return CAIRO_TEST_SUCCESS;
972 static cairo_test_status_t
973 test_cairo_append_path (cairo_t *cr)
975 cairo_path_data_t data[3];
978 path.status = CAIRO_STATUS_SUCCESS;
979 path.data = &data[0];
980 path.num_data = ARRAY_LENGTH(data);
982 data[0].header.type = CAIRO_PATH_MOVE_TO;
983 data[0].header.length = 2;
986 data[2].header.type = CAIRO_PATH_CLOSE_PATH;
987 data[2].header.length = 1;
989 cairo_append_path (cr, &path);
991 return CAIRO_TEST_SUCCESS;
994 static cairo_test_status_t
995 test_cairo_surface_create_similar (cairo_surface_t *surface)
997 cairo_surface_t *similar;
999 similar = cairo_surface_create_similar (surface, CAIRO_CONTENT_ALPHA, 100, 100);
1001 cairo_surface_destroy (similar);
1002 return CAIRO_TEST_SUCCESS;
1005 static cairo_test_status_t
1006 test_cairo_surface_create_for_rectangle (cairo_surface_t *surface)
1008 cairo_surface_t *similar;
1010 similar = cairo_surface_create_for_rectangle (surface, 1, 1, 8, 8);
1012 cairo_surface_destroy (similar);
1013 return CAIRO_TEST_SUCCESS;
1016 static cairo_test_status_t
1017 test_cairo_surface_reference (cairo_surface_t *surface)
1019 cairo_surface_destroy (cairo_surface_reference (surface));
1020 return CAIRO_TEST_SUCCESS;
1023 static cairo_test_status_t
1024 test_cairo_surface_finish (cairo_surface_t *surface)
1026 cairo_surface_finish (surface);
1027 return CAIRO_TEST_SUCCESS;
1030 static cairo_test_status_t
1031 test_cairo_surface_get_device (cairo_surface_t *surface)
1033 /* cairo_device_t *device = */cairo_surface_get_device (surface);
1034 return CAIRO_TEST_SUCCESS;
1037 static cairo_test_status_t
1038 test_cairo_surface_get_reference_count (cairo_surface_t *surface)
1040 unsigned int refcount = cairo_surface_get_reference_count (surface);
1042 return CAIRO_TEST_SUCCESS;
1043 /* inert error surfaces have a refcount of 0 */
1044 return cairo_surface_status (surface) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1047 static cairo_test_status_t
1048 test_cairo_surface_status (cairo_surface_t *surface)
1050 cairo_status_t status = cairo_surface_status (surface);
1051 return status < CAIRO_STATUS_LAST_STATUS ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1054 static cairo_test_status_t
1055 test_cairo_surface_get_type (cairo_surface_t *surface)
1057 /* cairo_surface_type_t type = */cairo_surface_get_type (surface);
1058 return CAIRO_TEST_SUCCESS;
1061 static cairo_test_status_t
1062 test_cairo_surface_get_content (cairo_surface_t *surface)
1064 cairo_content_t content = cairo_surface_get_content (surface);
1067 case CAIRO_CONTENT_COLOR:
1068 case CAIRO_CONTENT_ALPHA:
1069 case CAIRO_CONTENT_COLOR_ALPHA:
1070 return CAIRO_TEST_SUCCESS;
1072 return CAIRO_TEST_ERROR;
1076 static cairo_test_status_t
1077 test_cairo_surface_set_user_data (cairo_surface_t *surface)
1079 static cairo_user_data_key_t key;
1080 cairo_status_t status;
1082 status = cairo_surface_set_user_data (surface, &key, &key, NULL);
1083 if (status == CAIRO_STATUS_NO_MEMORY)
1084 return CAIRO_TEST_NO_MEMORY;
1086 return CAIRO_TEST_SUCCESS;
1088 if (cairo_surface_get_user_data (surface, &key) != &key)
1089 return CAIRO_TEST_ERROR;
1091 return CAIRO_TEST_SUCCESS;
1094 static cairo_test_status_t
1095 test_cairo_surface_set_mime_data (cairo_surface_t *surface)
1097 const char *mimetype = "text/x-uri";
1098 const char *data = "http://www.cairographics.org";
1099 cairo_status_t status;
1101 status = cairo_surface_set_mime_data (surface,
1103 (const unsigned char *) data,
1106 return status ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1109 static cairo_test_status_t
1110 test_cairo_surface_get_mime_data (cairo_surface_t *surface)
1112 const char *mimetype = "text/x-uri";
1113 const unsigned char *data;
1114 unsigned long length;
1116 cairo_surface_get_mime_data (surface, mimetype, &data, &length);
1117 return data == NULL && length == 0 ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1120 static cairo_test_status_t
1121 test_cairo_surface_get_font_options (cairo_surface_t *surface)
1123 cairo_font_options_t *options;
1124 cairo_status_t status;
1126 options = cairo_font_options_create ();
1127 if (likely (!cairo_font_options_status (options)))
1128 cairo_surface_get_font_options (surface, options);
1129 status = cairo_font_options_status (options);
1130 cairo_font_options_destroy (options);
1131 return status ? CAIRO_TEST_ERROR : CAIRO_TEST_SUCCESS;
1134 static cairo_test_status_t
1135 test_cairo_surface_flush (cairo_surface_t *surface)
1137 cairo_surface_flush (surface);
1138 return CAIRO_TEST_SUCCESS;
1141 static cairo_test_status_t
1142 test_cairo_surface_mark_dirty (cairo_surface_t *surface)
1144 cairo_surface_mark_dirty (surface);
1145 return CAIRO_TEST_SUCCESS;
1148 static cairo_test_status_t
1149 test_cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface)
1151 cairo_surface_mark_dirty_rectangle (surface, 1, 1, 8, 8);
1152 return CAIRO_TEST_SUCCESS;
1155 static cairo_test_status_t
1156 test_cairo_surface_set_device_offset (cairo_surface_t *surface)
1158 cairo_surface_set_device_offset (surface, 5, 5);
1159 return CAIRO_TEST_SUCCESS;
1162 static cairo_test_status_t
1163 test_cairo_surface_get_device_offset (cairo_surface_t *surface)
1167 cairo_surface_get_device_offset (surface, &x, &y);
1168 return CAIRO_TEST_SUCCESS;
1171 static cairo_test_status_t
1172 test_cairo_surface_set_fallback_resolution (cairo_surface_t *surface)
1174 cairo_surface_set_fallback_resolution (surface, 42, 42);
1175 return CAIRO_TEST_SUCCESS;
1178 static cairo_test_status_t
1179 test_cairo_surface_get_fallback_resolution (cairo_surface_t *surface)
1183 cairo_surface_get_fallback_resolution (surface, &x, &y);
1184 return CAIRO_TEST_SUCCESS;
1187 static cairo_test_status_t
1188 test_cairo_surface_copy_page (cairo_surface_t *surface)
1190 cairo_surface_copy_page (surface);
1191 return CAIRO_TEST_SUCCESS;
1194 static cairo_test_status_t
1195 test_cairo_surface_show_page (cairo_surface_t *surface)
1197 cairo_surface_show_page (surface);
1198 return CAIRO_TEST_SUCCESS;
1201 static cairo_test_status_t
1202 test_cairo_surface_has_show_text_glyphs (cairo_surface_t *surface)
1204 cairo_surface_has_show_text_glyphs (surface);
1205 return CAIRO_TEST_SUCCESS;
1208 static cairo_test_status_t
1209 test_cairo_image_surface_get_data (cairo_surface_t *surface)
1211 unsigned char *data = cairo_image_surface_get_data (surface);
1212 return data == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1215 static cairo_test_status_t
1216 test_cairo_image_surface_get_format (cairo_surface_t *surface)
1218 cairo_format_t format = cairo_image_surface_get_format (surface);
1219 return format == CAIRO_FORMAT_INVALID || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1222 static cairo_test_status_t
1223 test_cairo_image_surface_get_width (cairo_surface_t *surface)
1225 unsigned int width = cairo_image_surface_get_width (surface);
1226 return width == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1229 static cairo_test_status_t
1230 test_cairo_image_surface_get_height (cairo_surface_t *surface)
1232 unsigned int height = cairo_image_surface_get_height (surface);
1233 return height == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1236 static cairo_test_status_t
1237 test_cairo_image_surface_get_stride (cairo_surface_t *surface)
1239 unsigned int stride = cairo_image_surface_get_stride (surface);
1240 return stride == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1243 #if CAIRO_HAS_PNG_FUNCTIONS
1245 static cairo_test_status_t
1246 test_cairo_surface_write_to_png (cairo_surface_t *surface)
1248 cairo_status_t status;
1250 status = cairo_surface_write_to_png (surface, "/this/file/will/definitely/not/exist.png");
1252 return status ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1255 static cairo_status_t
1256 write_func_that_always_fails (void *closure, const unsigned char *data, unsigned int length)
1258 return CAIRO_STATUS_WRITE_ERROR;
1261 static cairo_test_status_t
1262 test_cairo_surface_write_to_png_stream (cairo_surface_t *surface)
1264 cairo_status_t status;
1266 status = cairo_surface_write_to_png_stream (surface,
1267 write_func_that_always_fails,
1270 return status && status != CAIRO_STATUS_WRITE_ERROR ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1273 #endif /* CAIRO_HAS_PNG_FUNCTIONS */
1275 static cairo_test_status_t
1276 test_cairo_recording_surface_ink_extents (cairo_surface_t *surface)
1280 cairo_recording_surface_ink_extents (surface, &x, &y, &w, &h);
1281 return x == 0 && y == 0 && w == 0 && h == 0 ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1284 #if CAIRO_HAS_TEE_SURFACE
1286 static cairo_test_status_t
1287 test_cairo_tee_surface_add (cairo_surface_t *surface)
1289 cairo_surface_t *image = cairo_image_surface_create (CAIRO_FORMAT_A8, 10, 10);
1291 cairo_tee_surface_add (surface, image);
1292 cairo_surface_destroy (image);
1293 return CAIRO_TEST_SUCCESS;
1296 static cairo_test_status_t
1297 test_cairo_tee_surface_remove (cairo_surface_t *surface)
1299 cairo_surface_t *image = cairo_image_surface_create (CAIRO_FORMAT_A8, 10, 10);
1301 cairo_tee_surface_remove (surface, image);
1302 cairo_surface_destroy (image);
1303 return CAIRO_TEST_SUCCESS;
1306 static cairo_test_status_t
1307 test_cairo_tee_surface_index (cairo_surface_t *surface)
1309 cairo_surface_t *master;
1310 cairo_status_t status;
1312 master = cairo_tee_surface_index (surface, 0);
1313 status = cairo_surface_status (master);
1314 cairo_surface_destroy (master);
1315 return status ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1318 #endif /* CAIRO_HAS_TEE_SURFACE */
1320 #if CAIRO_HAS_GL_SURFACE
1322 static cairo_test_status_t
1323 test_cairo_gl_surface_set_size (cairo_surface_t *surface)
1325 cairo_gl_surface_set_size (surface, 5, 5);
1326 return CAIRO_TEST_SUCCESS;
1329 static cairo_test_status_t
1330 test_cairo_gl_surface_get_width (cairo_surface_t *surface)
1332 unsigned int width = cairo_gl_surface_get_width (surface);
1333 return width == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_GL) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1336 static cairo_test_status_t
1337 test_cairo_gl_surface_get_height (cairo_surface_t *surface)
1339 unsigned int height = cairo_gl_surface_get_height (surface);
1340 return height == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_GL) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1343 static cairo_test_status_t
1344 test_cairo_gl_surface_swapbuffers (cairo_surface_t *surface)
1346 cairo_gl_surface_swapbuffers (surface);
1347 return CAIRO_TEST_SUCCESS;
1350 #endif /* CAIRO_HAS_GL_SURFACE */
1352 #if CAIRO_HAS_PDF_SURFACE
1354 static cairo_test_status_t
1355 test_cairo_pdf_surface_restrict_to_version (cairo_surface_t *surface)
1357 cairo_pdf_surface_restrict_to_version (surface, CAIRO_PDF_VERSION_1_4);
1358 return CAIRO_TEST_SUCCESS;
1361 static cairo_test_status_t
1362 test_cairo_pdf_surface_set_size (cairo_surface_t *surface)
1364 cairo_pdf_surface_set_size (surface, 5, 5);
1365 return CAIRO_TEST_SUCCESS;
1368 #endif /* CAIRO_HAS_PDF_SURFACE */
1370 #if CAIRO_HAS_PS_SURFACE
1372 static cairo_test_status_t
1373 test_cairo_ps_surface_restrict_to_level (cairo_surface_t *surface)
1375 cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_2);
1376 return CAIRO_TEST_SUCCESS;
1379 static cairo_test_status_t
1380 test_cairo_ps_surface_set_eps (cairo_surface_t *surface)
1382 cairo_ps_surface_set_eps (surface, TRUE);
1383 return CAIRO_TEST_SUCCESS;
1386 static cairo_test_status_t
1387 test_cairo_ps_surface_get_eps (cairo_surface_t *surface)
1389 cairo_bool_t eps = cairo_ps_surface_get_eps (surface);
1390 return eps ? CAIRO_TEST_ERROR : CAIRO_TEST_SUCCESS;
1393 static cairo_test_status_t
1394 test_cairo_ps_surface_set_size (cairo_surface_t *surface)
1396 cairo_ps_surface_set_size (surface, 5, 5);
1397 return CAIRO_TEST_SUCCESS;
1400 static cairo_test_status_t
1401 test_cairo_ps_surface_dsc_comment (cairo_surface_t *surface)
1403 cairo_ps_surface_dsc_comment (surface, "54, 74, 90, 2010");
1404 return CAIRO_TEST_SUCCESS;
1407 static cairo_test_status_t
1408 test_cairo_ps_surface_dsc_begin_setup (cairo_surface_t *surface)
1410 cairo_ps_surface_dsc_begin_setup (surface);
1411 return CAIRO_TEST_SUCCESS;
1414 static cairo_test_status_t
1415 test_cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface)
1417 cairo_ps_surface_dsc_begin_page_setup (surface);
1418 return CAIRO_TEST_SUCCESS;
1421 #endif /* CAIRO_HAS_PS_SURFACE */
1423 #if CAIRO_HAS_QUARTZ_SURFACE
1425 static cairo_test_status_t
1426 test_cairo_quartz_surface_get_cg_context (cairo_surface_t *surface)
1428 CGContextRef context = cairo_quartz_surface_get_cg_context (surface);
1429 return context == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_QUARTZ) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1432 #endif /* CAIRO_HAS_QUARTZ_SURFACE */
1434 #if CAIRO_HAS_SVG_SURFACE
1436 static cairo_test_status_t
1437 test_cairo_svg_surface_restrict_to_version (cairo_surface_t *surface)
1439 cairo_svg_surface_restrict_to_version (surface, CAIRO_SVG_VERSION_1_1);
1440 return CAIRO_TEST_SUCCESS;
1443 #endif /* CAIRO_HAS_SVG_SURFACE */
1445 #if CAIRO_HAS_XCB_SURFACE
1447 static cairo_test_status_t
1448 test_cairo_xcb_surface_set_size (cairo_surface_t *surface)
1450 cairo_xcb_surface_set_size (surface, 5, 5);
1451 return CAIRO_TEST_SUCCESS;
1454 static cairo_test_status_t
1455 test_cairo_xcb_surface_set_drawable (cairo_surface_t *surface)
1457 cairo_xcb_surface_set_drawable (surface, 0, 5, 5);
1458 return CAIRO_TEST_SUCCESS;
1463 #if CAIRO_HAS_XLIB_SURFACE
1465 static cairo_test_status_t
1466 test_cairo_xlib_surface_set_size (cairo_surface_t *surface)
1468 cairo_xlib_surface_set_size (surface, 5, 5);
1469 return CAIRO_TEST_SUCCESS;
1472 static cairo_test_status_t
1473 test_cairo_xlib_surface_set_drawable (cairo_surface_t *surface)
1475 cairo_xlib_surface_set_drawable (surface, 0, 5, 5);
1476 return CAIRO_TEST_SUCCESS;
1479 static cairo_test_status_t
1480 test_cairo_xlib_surface_get_display (cairo_surface_t *surface)
1482 Display *display = cairo_xlib_surface_get_display (surface);
1483 return display == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1486 static cairo_test_status_t
1487 test_cairo_xlib_surface_get_screen (cairo_surface_t *surface)
1489 Screen *screen = cairo_xlib_surface_get_screen (surface);
1490 return screen == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1493 static cairo_test_status_t
1494 test_cairo_xlib_surface_get_visual (cairo_surface_t *surface)
1496 Visual *visual = cairo_xlib_surface_get_visual (surface);
1497 return visual == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1500 static cairo_test_status_t
1501 test_cairo_xlib_surface_get_drawable (cairo_surface_t *surface)
1503 Drawable drawable = cairo_xlib_surface_get_drawable (surface);
1504 return drawable == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1507 static cairo_test_status_t
1508 test_cairo_xlib_surface_get_depth (cairo_surface_t *surface)
1510 int depth = cairo_xlib_surface_get_depth (surface);
1511 return depth == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1514 static cairo_test_status_t
1515 test_cairo_xlib_surface_get_width (cairo_surface_t *surface)
1517 int width = cairo_xlib_surface_get_width (surface);
1518 return width == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1521 static cairo_test_status_t
1522 test_cairo_xlib_surface_get_height (cairo_surface_t *surface)
1524 int height = cairo_xlib_surface_get_height (surface);
1525 return height == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
1530 #define TEST(name) { #name, test_ ## name }
1534 context_test_func_t func;
1535 } context_tests[] = {
1536 TEST (cairo_reference),
1537 TEST (cairo_get_reference_count),
1538 TEST (cairo_set_user_data),
1540 TEST (cairo_push_group),
1541 TEST (cairo_push_group_with_content),
1542 TEST (cairo_set_operator),
1543 TEST (cairo_set_source),
1544 TEST (cairo_set_source_rgb),
1545 TEST (cairo_set_source_rgba),
1546 TEST (cairo_set_source_surface),
1547 TEST (cairo_set_tolerance),
1548 TEST (cairo_set_antialias),
1549 TEST (cairo_set_fill_rule),
1550 TEST (cairo_set_line_width),
1551 TEST (cairo_set_line_cap),
1552 TEST (cairo_set_line_join),
1553 TEST (cairo_set_dash),
1554 TEST (cairo_set_miter_limit),
1555 TEST (cairo_translate),
1557 TEST (cairo_rotate),
1558 TEST (cairo_transform),
1559 TEST (cairo_set_matrix),
1560 TEST (cairo_identity_matrix),
1561 TEST (cairo_user_to_device),
1562 TEST (cairo_user_to_device_distance),
1563 TEST (cairo_device_to_user),
1564 TEST (cairo_device_to_user_distance),
1565 TEST (cairo_new_path),
1566 TEST (cairo_move_to),
1567 TEST (cairo_new_sub_path),
1568 TEST (cairo_line_to),
1569 TEST (cairo_curve_to),
1571 TEST (cairo_arc_negative),
1572 TEST (cairo_rel_move_to),
1573 TEST (cairo_rel_line_to),
1574 TEST (cairo_rel_curve_to),
1575 TEST (cairo_rectangle),
1576 TEST (cairo_close_path),
1577 TEST (cairo_path_extents),
1579 TEST (cairo_paint_with_alpha),
1581 TEST (cairo_mask_surface),
1582 TEST (cairo_stroke),
1583 TEST (cairo_stroke_preserve),
1585 TEST (cairo_fill_preserve),
1586 TEST (cairo_copy_page),
1587 TEST (cairo_show_page),
1588 TEST (cairo_in_stroke),
1589 TEST (cairo_in_fill),
1590 TEST (cairo_in_clip),
1591 TEST (cairo_stroke_extents),
1592 TEST (cairo_fill_extents),
1593 TEST (cairo_reset_clip),
1595 TEST (cairo_clip_preserve),
1596 TEST (cairo_clip_extents),
1597 TEST (cairo_copy_clip_rectangle_list),
1598 TEST (cairo_select_font_face),
1599 TEST (cairo_set_font_size),
1600 TEST (cairo_set_font_matrix),
1601 TEST (cairo_get_font_matrix),
1602 TEST (cairo_set_font_options),
1603 TEST (cairo_get_font_options),
1604 TEST (cairo_set_font_face),
1605 TEST (cairo_set_scaled_font),
1606 TEST (cairo_show_text),
1607 TEST (cairo_show_glyphs),
1608 TEST (cairo_show_text_glyphs),
1609 TEST (cairo_text_path),
1610 TEST (cairo_glyph_path),
1611 TEST (cairo_text_extents),
1612 TEST (cairo_glyph_extents),
1613 TEST (cairo_font_extents),
1614 TEST (cairo_get_operator),
1615 TEST (cairo_get_source),
1616 TEST (cairo_get_tolerance),
1617 TEST (cairo_get_antialias),
1618 TEST (cairo_has_current_point),
1619 TEST (cairo_get_current_point),
1620 TEST (cairo_get_fill_rule),
1621 TEST (cairo_get_line_width),
1622 TEST (cairo_get_line_cap),
1623 TEST (cairo_get_line_join),
1624 TEST (cairo_get_miter_limit),
1625 TEST (cairo_get_dash_count),
1626 TEST (cairo_get_dash),
1627 TEST (cairo_get_matrix),
1628 TEST (cairo_get_target),
1629 TEST (cairo_get_group_target),
1630 TEST (cairo_copy_path),
1631 TEST (cairo_copy_path_flat),
1632 TEST (cairo_append_path),
1637 #define TEST(name, surface_type, sets_status) { #name, test_ ## name, surface_type, sets_status }
1641 surface_test_func_t func;
1642 int surface_type; /* cairo_surface_type_t or -1 */
1643 cairo_bool_t modifies_surface;
1644 } surface_tests[] = {
1645 TEST (cairo_surface_create_similar, -1, FALSE),
1646 TEST (cairo_surface_create_for_rectangle, -1, FALSE),
1647 TEST (cairo_surface_reference, -1, FALSE),
1648 TEST (cairo_surface_finish, -1, TRUE),
1649 TEST (cairo_surface_get_device, -1, FALSE),
1650 TEST (cairo_surface_get_reference_count, -1, FALSE),
1651 TEST (cairo_surface_status, -1, FALSE),
1652 TEST (cairo_surface_get_type, -1, FALSE),
1653 TEST (cairo_surface_get_content, -1, FALSE),
1654 TEST (cairo_surface_set_user_data, -1, FALSE),
1655 TEST (cairo_surface_set_mime_data, -1, TRUE),
1656 TEST (cairo_surface_get_mime_data, -1, FALSE),
1657 TEST (cairo_surface_get_font_options, -1, FALSE),
1658 TEST (cairo_surface_flush, -1, TRUE),
1659 TEST (cairo_surface_mark_dirty, -1, TRUE),
1660 TEST (cairo_surface_mark_dirty_rectangle, -1, TRUE),
1661 TEST (cairo_surface_set_device_offset, -1, TRUE),
1662 TEST (cairo_surface_get_device_offset, -1, FALSE),
1663 TEST (cairo_surface_set_fallback_resolution, -1, TRUE),
1664 TEST (cairo_surface_get_fallback_resolution, -1, FALSE),
1665 TEST (cairo_surface_copy_page, -1, TRUE),
1666 TEST (cairo_surface_show_page, -1, TRUE),
1667 TEST (cairo_surface_has_show_text_glyphs, -1, FALSE),
1668 TEST (cairo_image_surface_get_data, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
1669 TEST (cairo_image_surface_get_format, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
1670 TEST (cairo_image_surface_get_width, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
1671 TEST (cairo_image_surface_get_height, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
1672 TEST (cairo_image_surface_get_stride, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
1673 #if CAIRO_HAS_PNG_FUNCTIONS
1674 TEST (cairo_surface_write_to_png, -1, FALSE),
1675 TEST (cairo_surface_write_to_png_stream, -1, FALSE),
1677 TEST (cairo_recording_surface_ink_extents, CAIRO_SURFACE_TYPE_RECORDING, FALSE),
1678 #if CAIRO_HAS_TEE_SURFACE
1679 TEST (cairo_tee_surface_add, CAIRO_SURFACE_TYPE_TEE, TRUE),
1680 TEST (cairo_tee_surface_remove, CAIRO_SURFACE_TYPE_TEE, TRUE),
1681 TEST (cairo_tee_surface_index, CAIRO_SURFACE_TYPE_TEE, FALSE),
1683 #if CAIRO_HAS_GL_SURFACE
1684 TEST (cairo_gl_surface_set_size, CAIRO_SURFACE_TYPE_GL, TRUE),
1685 TEST (cairo_gl_surface_get_width, CAIRO_SURFACE_TYPE_GL, FALSE),
1686 TEST (cairo_gl_surface_get_height, CAIRO_SURFACE_TYPE_GL, FALSE),
1687 TEST (cairo_gl_surface_swapbuffers, CAIRO_SURFACE_TYPE_GL, TRUE),
1689 #if CAIRO_HAS_PDF_SURFACE
1690 TEST (cairo_pdf_surface_restrict_to_version, CAIRO_SURFACE_TYPE_PDF, TRUE),
1691 TEST (cairo_pdf_surface_set_size, CAIRO_SURFACE_TYPE_PDF, TRUE),
1693 #if CAIRO_HAS_PS_SURFACE
1694 TEST (cairo_ps_surface_restrict_to_level, CAIRO_SURFACE_TYPE_PS, TRUE),
1695 TEST (cairo_ps_surface_set_eps, CAIRO_SURFACE_TYPE_PS, TRUE),
1696 TEST (cairo_ps_surface_get_eps, CAIRO_SURFACE_TYPE_PS, FALSE),
1697 TEST (cairo_ps_surface_set_size, CAIRO_SURFACE_TYPE_PS, TRUE),
1698 TEST (cairo_ps_surface_dsc_comment, CAIRO_SURFACE_TYPE_PS, TRUE),
1699 TEST (cairo_ps_surface_dsc_begin_setup, CAIRO_SURFACE_TYPE_PS, TRUE),
1700 TEST (cairo_ps_surface_dsc_begin_page_setup, CAIRO_SURFACE_TYPE_PS, TRUE),
1702 #if CAIRO_HAS_QUARTZ_SURFACE
1703 TEST (cairo_quartz_surface_get_cg_context, CAIRO_SURFACE_TYPE_QUARTZ, FALSE),
1705 #if CAIRO_HAS_SVG_SURFACE
1706 TEST (cairo_svg_surface_restrict_to_version, CAIRO_SURFACE_TYPE_SVG, TRUE),
1708 #if CAIRO_HAS_XCB_SURFACE
1709 TEST (cairo_xcb_surface_set_size, CAIRO_SURFACE_TYPE_XCB, TRUE),
1710 TEST (cairo_xcb_surface_set_drawable, CAIRO_SURFACE_TYPE_XCB, TRUE),
1712 #if CAIRO_HAS_XLIB_SURFACE
1713 TEST (cairo_xlib_surface_set_size, CAIRO_SURFACE_TYPE_XLIB, TRUE),
1714 TEST (cairo_xlib_surface_set_drawable, CAIRO_SURFACE_TYPE_XLIB, TRUE),
1715 TEST (cairo_xlib_surface_get_display, CAIRO_SURFACE_TYPE_XLIB, FALSE),
1716 TEST (cairo_xlib_surface_get_drawable, CAIRO_SURFACE_TYPE_XLIB, FALSE),
1717 TEST (cairo_xlib_surface_get_screen, CAIRO_SURFACE_TYPE_XLIB, FALSE),
1718 TEST (cairo_xlib_surface_get_visual, CAIRO_SURFACE_TYPE_XLIB, FALSE),
1719 TEST (cairo_xlib_surface_get_depth, CAIRO_SURFACE_TYPE_XLIB, FALSE),
1720 TEST (cairo_xlib_surface_get_width, CAIRO_SURFACE_TYPE_XLIB, FALSE),
1721 TEST (cairo_xlib_surface_get_height, CAIRO_SURFACE_TYPE_XLIB, FALSE),
1725 static cairo_test_status_t
1726 preamble (cairo_test_context_t *ctx)
1728 cairo_surface_t *surface;
1730 cairo_test_status_t test_status;
1731 cairo_status_t status_before, status_after;
1734 /* Test an error surface */
1735 for (i = 0; i < ARRAY_LENGTH (surface_tests); i++) {
1736 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, INT_MAX, INT_MAX);
1737 status_before = cairo_surface_status (surface);
1738 assert (status_before);
1740 test_status = surface_tests[i].func (surface);
1742 status_after = cairo_surface_status (surface);
1743 cairo_surface_destroy (surface);
1745 if (test_status != CAIRO_TEST_SUCCESS) {
1746 cairo_test_log (ctx,
1747 "Failed test %s with %d\n",
1748 surface_tests[i].name, (int) test_status);
1752 if (status_before != status_after) {
1753 cairo_test_log (ctx,
1754 "Failed test %s: Modified surface status from %u (%s) to %u (%s)\n",
1755 surface_tests[i].name,
1756 status_before, cairo_status_to_string (status_before),
1757 status_after, cairo_status_to_string (status_after));
1758 return CAIRO_TEST_ERROR;
1762 /* Test an error context */
1763 for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
1764 cr = cairo_create (NULL);
1765 status_before = cairo_status (cr);
1766 assert (status_before);
1768 test_status = context_tests[i].func (cr);
1770 status_after = cairo_status (cr);
1773 if (test_status != CAIRO_TEST_SUCCESS) {
1774 cairo_test_log (ctx,
1775 "Failed test %s with %d\n",
1776 context_tests[i].name, (int) test_status);
1780 if (status_before != status_after) {
1781 cairo_test_log (ctx,
1782 "Failed test %s: Modified context status from %u (%s) to %u (%s)\n",
1783 context_tests[i].name,
1784 status_before, cairo_status_to_string (status_before),
1785 status_after, cairo_status_to_string (status_after));
1786 return CAIRO_TEST_ERROR;
1790 /* Test a context for an error surface */
1791 for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
1792 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, INT_MAX, INT_MAX);
1793 cr = cairo_create (surface);
1794 cairo_surface_destroy (surface);
1795 status_before = cairo_status (cr);
1796 assert (status_before);
1798 test_status = context_tests[i].func (cr);
1800 status_after = cairo_status (cr);
1803 if (test_status != CAIRO_TEST_SUCCESS) {
1804 cairo_test_log (ctx,
1805 "Failed test %s with %d\n",
1806 context_tests[i].name, (int) test_status);
1810 if (status_before != status_after) {
1811 cairo_test_log (ctx,
1812 "Failed test %s: Modified context status from %u (%s) to %u (%s)\n",
1813 context_tests[i].name,
1814 status_before, cairo_status_to_string (status_before),
1815 status_after, cairo_status_to_string (status_after));
1816 return CAIRO_TEST_ERROR;
1820 return CAIRO_TEST_SUCCESS;
1823 static cairo_test_status_t
1824 test_context (const cairo_test_context_t *ctx, cairo_t *cr, const char *name, unsigned int i)
1826 cairo_test_status_t test_status;
1827 cairo_status_t status_before, status_after;
1829 /* Make sure that there is a current point */
1830 cairo_move_to (cr, 0, 0);
1832 status_before = cairo_status (cr);
1833 test_status = context_tests[i].func (cr);
1834 status_after = cairo_status (cr);
1836 if (test_status != CAIRO_TEST_SUCCESS) {
1837 cairo_test_log (ctx,
1838 "Failed test %s on %s with %d\n",
1839 context_tests[i].name, name, (int) test_status);
1843 if (status_after != CAIRO_STATUS_SURFACE_FINISHED && status_before != status_after) {
1844 cairo_test_log (ctx,
1845 "Failed test %s on %s: Modified context status from %u (%s) to %u (%s)\n",
1846 context_tests[i].name, name,
1847 status_before, cairo_status_to_string (status_before),
1848 status_after, cairo_status_to_string (status_after));
1849 return CAIRO_TEST_ERROR;
1852 return CAIRO_TEST_SUCCESS;
1855 static cairo_test_status_t
1856 draw (cairo_t *cr, int width, int height)
1858 const cairo_test_context_t *ctx = cairo_test_get_context (cr);
1859 cairo_surface_t *similar, *target;
1860 cairo_test_status_t test_status;
1861 cairo_status_t status;
1865 target = cairo_get_target (cr);
1867 /* Test a finished similar surface */
1868 for (i = 0; i < ARRAY_LENGTH (surface_tests); i++) {
1869 similar = cairo_surface_create_similar (target,
1870 cairo_surface_get_content (target),
1872 cairo_surface_finish (similar);
1873 test_status = surface_tests[i].func (similar);
1874 status = cairo_surface_status (similar);
1875 cairo_surface_destroy (similar);
1877 if (test_status != CAIRO_TEST_SUCCESS) {
1878 cairo_test_log (ctx,
1879 "Failed test %s with %d\n",
1880 surface_tests[i].name, (int) test_status);
1884 if (surface_tests[i].modifies_surface &&
1885 strcmp (surface_tests[i].name, "cairo_surface_finish") &&
1886 strcmp (surface_tests[i].name, "cairo_surface_flush") &&
1887 status != CAIRO_STATUS_SURFACE_FINISHED) {
1888 cairo_test_log (ctx,
1889 "Failed test %s: Finished surface not set into error state\n",
1890 surface_tests[i].name);
1891 return CAIRO_TEST_ERROR;
1895 /* Test a context for a finished similar surface */
1896 for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
1897 similar = cairo_surface_create_similar (target,
1898 cairo_surface_get_content (target),
1900 cairo_surface_finish (similar);
1901 cr2 = cairo_create (similar);
1902 test_status = test_context (ctx, cr2, "finished surface", i);
1903 cairo_surface_destroy (similar);
1904 cairo_destroy (cr2);
1906 if (test_status != CAIRO_TEST_SUCCESS)
1910 /* Test a context for a similar surface finished later */
1911 for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
1912 similar = cairo_surface_create_similar (target,
1913 cairo_surface_get_content (target),
1915 cr2 = cairo_create (similar);
1916 cairo_surface_finish (similar);
1917 test_status = test_context (ctx, cr2, "finished surface after create", i);
1918 cairo_surface_destroy (similar);
1919 cairo_destroy (cr2);
1921 if (test_status != CAIRO_TEST_SUCCESS)
1925 /* Test a context for a similar surface finished later with a path */
1926 for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
1927 similar = cairo_surface_create_similar (target,
1928 cairo_surface_get_content (target),
1930 cr2 = cairo_create (similar);
1931 cairo_rectangle (cr2, 2, 2, 4, 4);
1932 cairo_surface_finish (similar);
1933 test_status = test_context (ctx, cr2, "finished surface with path", i);
1934 cairo_surface_destroy (similar);
1935 cairo_destroy (cr2);
1937 if (test_status != CAIRO_TEST_SUCCESS)
1941 /* Test a normal surface for functions that have the wrong type */
1942 for (i = 0; i < ARRAY_LENGTH (surface_tests); i++) {
1943 cairo_status_t desired_status;
1945 if (surface_tests[i].surface_type == -1)
1947 similar = cairo_surface_create_similar (target,
1948 cairo_surface_get_content (target),
1950 if (cairo_surface_get_type (similar) == (cairo_surface_type_t) surface_tests[i].surface_type) {
1951 cairo_surface_destroy (similar);
1955 test_status = surface_tests[i].func (similar);
1956 status = cairo_surface_status (similar);
1957 cairo_surface_destroy (similar);
1959 if (test_status != CAIRO_TEST_SUCCESS) {
1960 cairo_test_log (ctx,
1961 "Failed test %s with %d\n",
1962 surface_tests[i].name, (int) test_status);
1966 desired_status = surface_tests[i].modifies_surface ? CAIRO_STATUS_SURFACE_TYPE_MISMATCH : CAIRO_STATUS_SUCCESS;
1967 if (status != desired_status) {
1968 cairo_test_log (ctx,
1969 "Failed test %s: Surface status should be %u (%s), but is %u (%s)\n",
1970 surface_tests[i].name,
1971 desired_status, cairo_status_to_string (desired_status),
1972 status, cairo_status_to_string (status));
1973 return CAIRO_TEST_ERROR;
1977 /* 565-compatible gray background */
1978 cairo_set_source_rgb (cr, 0.51613, 0.55555, 0.51613);
1981 return CAIRO_TEST_SUCCESS;
1984 CAIRO_TEST (api_special_cases,
1985 "Check surface functions properly handle wrong surface arguments",
1986 "api", /* keywords */
1987 NULL, /* requirements */