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"
36 read_png_from_file (void *closure, unsigned char *data, unsigned int length)
41 bytes_read = fread (data, 1, length, file);
42 if (bytes_read != length)
43 return CAIRO_STATUS_READ_ERROR;
45 return CAIRO_STATUS_SUCCESS;
48 static cairo_test_status_t
49 draw (cairo_t *cr, int width, int height)
51 const cairo_test_context_t *ctx = cairo_test_get_context (cr);
54 cairo_surface_t *surface;
55 cairo_status_t status;
57 xasprintf (&filename, "%s/reference/%s", ctx->srcdir,
58 "create-from-png-stream.ref.png");
60 file = fopen (filename, "rb");
62 cairo_test_status_t ret;
64 ret = CAIRO_TEST_FAILURE;
66 ret = cairo_test_status_from_status (ctx, CAIRO_STATUS_NO_MEMORY);
68 if (ret != CAIRO_TEST_NO_MEMORY)
69 cairo_test_log (ctx, "Error: failed to open file: %s\n", filename);
75 surface = cairo_image_surface_create_from_png_stream (read_png_from_file,
80 status = cairo_surface_status (surface);
82 cairo_test_status_t ret;
84 cairo_surface_destroy (surface);
86 ret = cairo_test_status_from_status (ctx, status);
87 if (ret != CAIRO_TEST_NO_MEMORY) {
89 "Error: failed to create surface from PNG: %s - %s\n",
91 cairo_status_to_string (status));
101 /* Pretend we modify the surface data (which detaches the PNG mime data) */
102 cairo_surface_flush (surface);
103 cairo_surface_mark_dirty (surface);
105 cairo_set_source_surface (cr, surface, 0, 0);
106 cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
109 cairo_surface_destroy (surface);
111 return CAIRO_TEST_SUCCESS;
114 CAIRO_TEST (create_from_png_stream,
115 "Tests the creation of an image surface from a PNG using a FILE *",
116 "png", /* keywords */
117 NULL, /* requirements */