2 * Copyright © 2005 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: Carl D. Worth <cworth@cworth.org>
26 #include "cairo-test.h"
29 /* Test to verify fixes for the following similar bugs:
31 * https://bugs.freedesktop.org/show_bug.cgi?id=4088
32 * https://bugs.freedesktop.org/show_bug.cgi?id=3915
33 * https://bugs.freedesktop.org/show_bug.cgi?id=9906
36 static cairo_test_draw_function_t draw
;
40 "Test that nil surfaces do not make cairo crash.",
45 static cairo_test_status_t
46 draw (cairo_t
*cr
, int width
, int height
)
48 cairo_surface_t
*surface
;
49 cairo_pattern_t
*pattern
;
53 * 1. Test file-not-found from surface->pattern->cairo_t
56 /* Make a custom context to not interfere with the one passed in. */
57 cr2
= cairo_create (cairo_get_target (cr
));
59 /* First, let's make a nil surface. */
60 surface
= cairo_image_surface_create_from_png ("___THIS_FILE_DOES_NOT_EXIST___");
62 /* Let the error propagate into a nil pattern. */
63 pattern
= cairo_pattern_create_for_surface (surface
);
65 /* Then let it propagate into the cairo_t. */
66 cairo_set_source (cr2
, pattern
);
69 cairo_pattern_destroy (pattern
);
70 cairo_surface_destroy (surface
);
72 /* Check that the error made it all that way. */
73 if (cairo_status (cr2
) != CAIRO_STATUS_FILE_NOT_FOUND
) {
74 cairo_test_log ("Error: Received status of \"%s\" rather than expected \"%s\"\n",
75 cairo_status_to_string (cairo_status (cr2
)),
76 cairo_status_to_string (CAIRO_STATUS_FILE_NOT_FOUND
));
78 return CAIRO_TEST_FAILURE
;
84 * 2. Test NULL pointer pattern->cairo_t
86 cr2
= cairo_create (cairo_get_target (cr
));
88 /* First, trigger the NULL pointer status. */
89 pattern
= cairo_pattern_create_for_surface (NULL
);
91 /* Then let it propagate into the cairo_t. */
92 cairo_set_source (cr2
, pattern
);
95 cairo_pattern_destroy (pattern
);
97 /* Check that the error made it all that way. */
98 if (cairo_status (cr2
) != CAIRO_STATUS_NULL_POINTER
) {
99 cairo_test_log ("Error: Received status of \"%s\" rather than expected \"%s\"\n",
100 cairo_status_to_string (cairo_status (cr2
)),
101 cairo_status_to_string (CAIRO_STATUS_NULL_POINTER
));
103 return CAIRO_TEST_FAILURE
;
109 * 3. Test that cairo_surface_finish can accept NULL or a nil
110 * surface without crashing.
113 cairo_surface_finish (NULL
);
115 surface
= cairo_image_surface_create_from_png ("___THIS_FILE_DOES_NOT_EXIST___");
116 cairo_surface_finish (surface
);
117 cairo_surface_destroy (surface
);
120 * 4. OK, we're straying from the original name, but it's still a
121 * similar kind of testing of error paths. Here we're making sure
122 * we can still call a cairo_get_* function after triggering an
123 * INVALID_RESTORE error.
125 cr2
= cairo_create (cairo_get_target (cr
));
127 /* Trigger invalid restore. */
129 if (cairo_status (cr2
) != CAIRO_STATUS_INVALID_RESTORE
) {
130 cairo_test_log ("Error: Received status of \"%s\" rather than expected \"%s\"\n",
131 cairo_status_to_string (cairo_status (cr2
)),
132 cairo_status_to_string (CAIRO_STATUS_INVALID_RESTORE
));
134 return CAIRO_TEST_FAILURE
;
137 /* Test that we can still call cairo_get_fill_rule without crashing. */
138 cairo_get_fill_rule (cr2
);
143 * 5. Create a cairo_t for the NULL surface.
145 cr2
= cairo_create (NULL
);
147 if (cairo_status (cr2
) != CAIRO_STATUS_NULL_POINTER
) {
148 cairo_test_log ("Error: Received status of \"%s\" rather than expected \"%s\"\n",
149 cairo_status_to_string (cairo_status (cr2
)),
150 cairo_status_to_string (CAIRO_STATUS_NULL_POINTER
));
152 return CAIRO_TEST_FAILURE
;
155 /* Test that get_target returns something valid */
156 if (cairo_get_target (cr2
) == NULL
) {
157 cairo_test_log ("Error: cairo_get_target() returned NULL\n");
159 return CAIRO_TEST_FAILURE
;
162 /* Test that push_group doesn't crash */
163 cairo_push_group (cr2
);
165 cairo_pop_group (cr2
);
169 return CAIRO_TEST_SUCCESS
;
175 return cairo_test (&test
);