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 Worth <cworth@cworth.org>
26
#include "cairo-test.h"
33
static cairo_test_draw_function_t draw;
37
"Tests the creation of an image surface from a PNG file",
43
no_memory_error (void *closure, unsigned char *data, unsigned int size)
45
return CAIRO_STATUS_NO_MEMORY;
49
read_error (void *closure, unsigned char *data, unsigned int size)
51
return CAIRO_STATUS_READ_ERROR;
54
static cairo_test_status_t
55
draw (cairo_t *cr, int width, int height)
57
char *srcdir = getenv ("srcdir");
59
cairo_surface_t *surface;
61
xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
62
"create-from-png-ref.png");
64
surface = cairo_image_surface_create_from_png (filename);
65
if (cairo_surface_status (surface)) {
66
cairo_test_log ("Error reading PNG image %s: %s\n",
68
cairo_status_to_string (cairo_surface_status (surface)));
70
return CAIRO_TEST_FAILURE;
74
cairo_set_source_surface (cr, surface, 0, 0);
77
cairo_surface_destroy (surface);
79
return CAIRO_TEST_SUCCESS;
85
char *srcdir = getenv ("srcdir");
87
cairo_surface_t *surface;
88
cairo_status_t status;
90
surface = cairo_image_surface_create_from_png ("___THIS_FILE_DOES_NOT_EXIST___");
91
if (cairo_surface_status (surface) != CAIRO_STATUS_FILE_NOT_FOUND) {
92
cairo_test_log ("Error: expected \"file not found\", but got: %s\n",
93
cairo_status_to_string (cairo_surface_status (surface)));
94
cairo_surface_destroy (surface);
95
return CAIRO_TEST_FAILURE;
98
surface = cairo_image_surface_create_from_png_stream (no_memory_error, NULL);
99
if (cairo_surface_status (surface) != CAIRO_STATUS_NO_MEMORY) {
100
cairo_test_log ("Error: expected \"out of memory\", but got: %s\n",
101
cairo_status_to_string (cairo_surface_status (surface)));
102
cairo_surface_destroy (surface);
103
return CAIRO_TEST_FAILURE;
106
surface = cairo_image_surface_create_from_png_stream (read_error, NULL);
107
if (cairo_surface_status (surface) != CAIRO_STATUS_READ_ERROR) {
108
cairo_test_log ("Error: expected \"read error\", but got: %s\n",
109
cairo_status_to_string (cairo_surface_status (surface)));
110
cairo_surface_destroy (surface);
111
return CAIRO_TEST_FAILURE;
114
/* cheekily test error propagation from the user write funcs as well ... */
115
xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
116
"create-from-png-ref.png");
118
surface = cairo_image_surface_create_from_png (filename);
119
if (cairo_surface_status (surface)) {
120
cairo_test_log ("Error reading PNG image %s: %s\n",
122
cairo_status_to_string (cairo_surface_status (surface)));
124
return CAIRO_TEST_FAILURE;
128
status = cairo_surface_write_to_png_stream (surface,
129
(cairo_write_func_t) no_memory_error,
131
if (status != CAIRO_STATUS_NO_MEMORY) {
132
cairo_test_log ("Error: expected \"out of memory\", but got: %s\n",
133
cairo_status_to_string (status));
134
cairo_surface_destroy (surface);
135
return CAIRO_TEST_FAILURE;
137
status = cairo_surface_write_to_png_stream (surface,
138
(cairo_write_func_t) read_error,
140
if (status != CAIRO_STATUS_READ_ERROR) {
141
cairo_test_log ("Error: expected \"read error\", but got: %s\n",
142
cairo_status_to_string (status));
143
cairo_surface_destroy (surface);
144
return CAIRO_TEST_FAILURE;
146
cairo_surface_destroy (surface);
148
return cairo_test (&test);