summaryrefslogtreecommitdiff
path: root/test
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
parent770d4c55b4b576875b73249f29ad7840fb5da7e5 (diff)
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')
-rw-r--r--test/.cvsignore1
-rw-r--r--test/Makefile.am3
-rw-r--r--test/buffer-diff.c6
-rw-r--r--test/buffer-diff.h4
-rw-r--r--test/cairo-test.c14
-rw-r--r--test/cairo-test.h2
-rw-r--r--test/create-for-png-ref.pngbin0 -> 100 bytes
-rw-r--r--test/create-for-png.c74
-rw-r--r--test/create-from-png-ref.pngbin0 -> 100 bytes
-rw-r--r--test/create-from-png.c74
-rw-r--r--test/write-png.c2
-rw-r--r--test/write-png.h2
12 files changed, 171 insertions, 11 deletions
diff --git a/test/.cvsignore b/test/.cvsignore
index 2eb69123..4a9186cc 100644
--- a/test/.cvsignore
+++ b/test/.cvsignore
@@ -4,6 +4,7 @@ Makefile
Makefile.in
clip-twice
coverage
+create-for-png
fill-rule
get-and-set
imagediff
diff --git a/test/Makefile.am b/test/Makefile.am
index 93d9c9df..e520152c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -2,6 +2,7 @@
TESTS = \
clip-twice \
coverage \
+create-for-png \
fill-rule \
get-and-set \
leaky-polygon \
@@ -18,6 +19,7 @@ user-data
# this list. Anyone know a good way to avoid it? Can I use a wildcard
# here?
EXTRA_DIST = \
+create-for-png-ref.png \
fill-rule-ref.png \
leaky-polygon-ref.png \
line-width-ref.png \
@@ -73,6 +75,7 @@ LDADDS = libcairotest.la $(top_builddir)/src/libcairo.la
# from autogen.sh. My, but this is painful...
clip_twice_LDADD = $(LDADDS)
coverage_LDADD = $(LDADDS)
+create_for_png_LDADD = $(LDADDS)
fill_rule_LDADD = $(LDADDS)
get_and_set_LDADD = $(LDADDS)
leaky_polygon_LDADD = $(LDADDS)
diff --git a/test/buffer-diff.c b/test/buffer-diff.c
index 486aff1d..98b914d3 100644
--- a/test/buffer-diff.c
+++ b/test/buffer-diff.c
@@ -31,8 +31,10 @@
* images differ.
*/
int
-buffer_diff (char *buf_a, char *buf_b, char *buf_diff,
- int width, int height, int stride)
+buffer_diff (unsigned char *buf_a,
+ unsigned char *buf_b,
+ unsigned char *buf_diff,
+ int width, int height, int stride)
{
int x, y;
int total_pixels_changed = 0;
diff --git a/test/buffer-diff.h b/test/buffer-diff.h
index 9ee51c3c..ab5d3bd9 100644
--- a/test/buffer-diff.h
+++ b/test/buffer-diff.h
@@ -32,7 +32,9 @@
* images differ.
*/
int
-buffer_diff (char *buf_a, char *buf_b, char *buf_diff,
+buffer_diff (unsigned char *buf_a,
+ unsigned char *buf_b,
+ unsigned char *buf_diff,
int width, int height, int stride);
#endif
diff --git a/test/cairo-test.c b/test/cairo-test.c
index 835bf38a..e2f781d1 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -32,6 +32,8 @@
#include "cairo-test.h"
+#include <cairo-png.h>
+
#include "buffer-diff.h"
#include "read-png.h"
#include "write-png.h"
@@ -42,7 +44,7 @@
#define CAIRO_TEST_REF_SUFFIX "-ref.png"
#define CAIRO_TEST_DIFF_SUFFIX "-diff.png"
-static void
+void
xasprintf (char **strp, const char *fmt, ...)
{
#ifdef HAVE_VASPRINTF
@@ -105,7 +107,7 @@ cairo_test (cairo_test_t *test, cairo_test_draw_function_t draw)
char *log_name, *png_name, *ref_name, *diff_name;
char *srcdir;
int pixels_changed;
- int ref_width, ref_height, ref_stride;
+ unsigned int ref_width, ref_height, ref_stride;
read_png_status_t png_status;
cairo_test_status_t ret;
FILE *png_file;
@@ -150,8 +152,6 @@ cairo_test (cairo_test_t *test, cairo_test_draw_function_t draw)
return CAIRO_TEST_FAILURE;
}
- cairo_destroy (cr);
-
/* Skip image check for tests with no image (width,height == 0,0) */
if (test->width == 0 || test->height == 0) {
free (png_buf);
@@ -160,9 +160,11 @@ cairo_test (cairo_test_t *test, cairo_test_draw_function_t draw)
}
png_file = fopen (png_name, "wb");
- write_png_argb32 (png_buf, png_file, test->width, test->height, stride);
+ cairo_surface_write_png (cairo_get_target_surface (cr), png_file);
fclose (png_file);
+ cairo_destroy (cr);
+
ref_buf = NULL;
png_status = (read_png_argb32 (ref_name, &ref_buf, &ref_width, &ref_height, &ref_stride));
if (png_status) {
@@ -236,7 +238,7 @@ cairo_test_create_png_pattern (cairo_t *cr, const char *filename)
cairo_surface_t *image;
cairo_pattern_t *pattern;
unsigned char *buffer;
- int w, h, stride;
+ unsigned int w, h, stride;
read_png_status_t status;
char *srcdir = getenv ("srcdir");
diff --git a/test/cairo-test.h b/test/cairo-test.h
index cc18a793..6bf9111d 100644
--- a/test/cairo-test.h
+++ b/test/cairo-test.h
@@ -50,6 +50,8 @@ cairo_test (cairo_test_t *test, cairo_test_draw_function_t draw);
cairo_pattern_t *
cairo_test_create_png_pattern (cairo_t *cr, const char *filename);
+void
+xasprintf (char **strp, const char *fmt, ...);
#endif
diff --git a/test/create-for-png-ref.png b/test/create-for-png-ref.png
new file mode 100644
index 00000000..765adc4a
--- /dev/null
+++ b/test/create-for-png-ref.png
Binary files differ
diff --git a/test/create-for-png.c b/test/create-for-png.c
new file mode 100644
index 00000000..41223f72
--- /dev/null
+++ b/test/create-for-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);
+}
diff --git a/test/create-from-png-ref.png b/test/create-from-png-ref.png
new file mode 100644
index 00000000..765adc4a
--- /dev/null
+++ b/test/create-from-png-ref.png
Binary files differ
diff --git a/test/create-from-png.c b/test/create-from-png.c
new file mode 100644
index 00000000..41223f72
--- /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);
+}
diff --git a/test/write-png.c b/test/write-png.c
index a5494b46..f5a27473 100644
--- a/test/write-png.c
+++ b/test/write-png.c
@@ -55,7 +55,7 @@ unpremultiply_data (png_structp png, png_row_infop row_info, png_bytep data)
}
void
-write_png_argb32 (char *buffer, FILE *file,
+write_png_argb32 (unsigned char *buffer, FILE *file,
int width, int height, int stride)
{
int i;
diff --git a/test/write-png.h b/test/write-png.h
index fe0e92b2..8074666a 100644
--- a/test/write-png.h
+++ b/test/write-png.h
@@ -29,7 +29,7 @@
#define WRITE_PNG_H
void
-write_png_argb32 (char *buffer, FILE * file,
+write_png_argb32 (unsigned char *buffer, FILE * file,
int width, int height, int stride);
#endif