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_status_t
37 draw (cairo_t *cr, int width, int height)
39 const cairo_test_context_t *ctx = cairo_test_get_context (cr);
40 cairo_surface_t *surface;
41 cairo_pattern_t *pattern;
45 * 1. Test file-not-found from surface->pattern->cairo_t
48 /* Make a custom context to not interfere with the one passed in. */
49 cr2 = cairo_create (cairo_get_target (cr));
51 /* First, let's make a nil surface. */
52 surface = cairo_image_surface_create_from_png ("___THIS_FILE_DOES_NOT_EXIST___");
54 /* Let the error propagate into a nil pattern. */
55 pattern = cairo_pattern_create_for_surface (surface);
57 /* Then let it propagate into the cairo_t. */
58 cairo_set_source (cr2, pattern);
61 cairo_pattern_destroy (pattern);
62 cairo_surface_destroy (surface);
64 /* Check that the error made it all that way. */
65 if (cairo_status (cr2) != CAIRO_STATUS_FILE_NOT_FOUND) {
66 cairo_test_log (ctx, "Error: Received status of \"%s\" rather than expected \"%s\"\n",
67 cairo_status_to_string (cairo_status (cr2)),
68 cairo_status_to_string (CAIRO_STATUS_FILE_NOT_FOUND));
70 return CAIRO_TEST_FAILURE;
76 * 2. Test NULL pointer pattern->cairo_t
78 cr2 = cairo_create (cairo_get_target (cr));
80 /* First, trigger the NULL pointer status. */
81 pattern = cairo_pattern_create_for_surface (NULL);
83 /* Then let it propagate into the cairo_t. */
84 cairo_set_source (cr2, pattern);
87 cairo_pattern_destroy (pattern);
89 /* Check that the error made it all that way. */
90 if (cairo_status (cr2) != CAIRO_STATUS_NULL_POINTER) {
91 cairo_test_log (ctx, "Error: Received status of \"%s\" rather than expected \"%s\"\n",
92 cairo_status_to_string (cairo_status (cr2)),
93 cairo_status_to_string (CAIRO_STATUS_NULL_POINTER));
95 return CAIRO_TEST_FAILURE;
101 * 3. Test that cairo_surface_finish can accept NULL or a nil
102 * surface without crashing.
105 cairo_surface_finish (NULL);
107 surface = cairo_image_surface_create_from_png ("___THIS_FILE_DOES_NOT_EXIST___");
108 cairo_surface_finish (surface);
109 cairo_surface_destroy (surface);
112 * 4. OK, we're straying from the original name, but it's still a
113 * similar kind of testing of error paths. Here we're making sure
114 * we can still call a cairo_get_* function after triggering an
115 * INVALID_RESTORE error.
117 cr2 = cairo_create (cairo_get_target (cr));
119 /* Trigger invalid restore. */
121 if (cairo_status (cr2) != CAIRO_STATUS_INVALID_RESTORE) {
122 cairo_test_log (ctx, "Error: Received status of \"%s\" rather than expected \"%s\"\n",
123 cairo_status_to_string (cairo_status (cr2)),
124 cairo_status_to_string (CAIRO_STATUS_INVALID_RESTORE));
126 return CAIRO_TEST_FAILURE;
129 /* Test that we can still call cairo_get_fill_rule without crashing. */
130 cairo_get_fill_rule (cr2);
135 * 5. Create a cairo_t for the NULL surface.
137 cr2 = cairo_create (NULL);
139 if (cairo_status (cr2) != CAIRO_STATUS_NULL_POINTER) {
140 cairo_test_log (ctx, "Error: Received status of \"%s\" rather than expected \"%s\"\n",
141 cairo_status_to_string (cairo_status (cr2)),
142 cairo_status_to_string (CAIRO_STATUS_NULL_POINTER));
144 return CAIRO_TEST_FAILURE;
147 /* Test that get_target returns something valid */
148 if (cairo_get_target (cr2) == NULL) {
149 cairo_test_log (ctx, "Error: cairo_get_target() returned NULL\n");
151 return CAIRO_TEST_FAILURE;
154 /* Test that push_group doesn't crash */
155 cairo_push_group (cr2);
157 pattern = cairo_pop_group (cr2);
158 cairo_pattern_destroy (pattern);
162 return CAIRO_TEST_SUCCESS;
165 CAIRO_TEST (nil_surface,
166 "Test that nil surfaces do not make cairo crash.",
167 "api", /* keywords */
168 NULL, /* requirements */