summaryrefslogtreecommitdiff
path: root/test/create-from-png.c
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2005-04-04 09:47:12 +0000
committerCarl Worth <cworth@cworth.org>2005-04-04 09:47:12 +0000
commita6d9b6a671faf6cc726af12d4f4e706262c2bd6b (patch)
treee1e6943aa108a39d579f32b579a48c8d6e1bd6d6 /test/create-from-png.c
parent770d4c55b4b576875b73249f29ad7840fb5da7e5 (diff)
downloadcairo-a6d9b6a671faf6cc726af12d4f4e706262c2bd6b.tar.gz
Change type of data parameter from char* to unsigned char*.
Propagate the unsigned char* change down the stack. Add cast since XImage uses char* rather than unsigned char*. Fix memory leak of image data. Switch to use cairo_surface_write_png rather than a custom write_png_argb32. Add test to exercise the cairo_image_surface_create_for_png function.
Diffstat (limited to 'test/create-from-png.c')
-rw-r--r--test/create-from-png.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/create-from-png.c b/test/create-from-png.c
new file mode 100644
index 000000000..41223f728
--- /dev/null
+++ b/test/create-from-png.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2005 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Carl Worth <cworth@cworth.org>
+ */
+
+#include "cairo-test.h"
+
+#include <stdlib.h>
+#include <cairo-png.h>
+
+#define WIDTH 2
+#define HEIGHT 2
+
+cairo_test_t test = {
+ "create-for-png",
+ "Tests the creation of an image surface from a PNG file",
+ WIDTH, HEIGHT
+};
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+ char *srcdir = getenv ("srcdir");
+ char *filename;
+ FILE *file;
+ cairo_surface_t *surface;
+ int surface_width, surface_height;
+
+ xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
+ "create-for-png-ref.png");
+ file = fopen (filename, "r");
+ if (file == NULL) {
+ fprintf (stderr, "Error: failed to open file %s\n", filename);
+ free (filename);
+ return CAIRO_TEST_FAILURE;
+ }
+ free (filename);
+
+ surface = cairo_image_surface_create_for_png (file,
+ &surface_width,
+ &surface_height);
+
+ cairo_show_surface (cr, surface, surface_width, surface_height);
+
+ cairo_surface_destroy (surface);
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+ return cairo_test (&test, draw);
+}