[cairo-commit] cairo/test Makefile.am,1.1,1.2 cairo_test.c,1.1,1.2

Carl Worth commit at pdx.freedesktop.org
Tue Oct 26 18:19:57 PDT 2004


Committed by: cworth

Update of /cvs/cairo/cairo/test
In directory gabe:/tmp/cvs-serv10714/test

Modified Files:
	Makefile.am cairo_test.c 
Log Message:

        * test/cairo_test.c (cairo_test): Find reference images in
         so that make distcheck will work.

        * test/Makefile.am (cairo_test_lib): Add header files so that make
        distcheck is happy.
        (INCLUDES): Add -D_GNU_SOURCE for asprintf. Someone motivated may
        want to find a more portable approach.
        (EXTRA_DIST): Add reference images for the sake of make distcheck.


Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/cairo/test/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile.am	26 Oct 2004 21:38:43 -0000	1.1
+++ Makefile.am	27 Oct 2004 01:19:55 -0000	1.2
@@ -13,17 +13,33 @@
 XFAIL_TESTS = \
 move_to_show_surface
 
+# Ugh, don't like having to repeat this list so much. Can I use a
+# wildcard here?
+EXTRA_DIST = \
+line_width-ref.png \
+move_to_show_surface-ref.png
+
 check_PROGRAMS = $(TESTS)
 
-INCLUDES = -I$(srcdir) $(CAIRO_CFLAGS) -I$(srcdir)/../src
+# We're using _GNU_SOURCE to get the prototype for asprintf. This may
+# not be the most portable approach, but it is pragmatic and I'm
+# willing to do something cleaner as soon as it causes someone a
+# problem.
+INCLUDES = -D_GNU_SOURCE -I$(srcdir) $(CAIRO_CFLAGS) -I$(srcdir)/../src
 
 AM_LDFLAGS = $(CAIRO_LIBS) -L../src -lcairo
 
-cairo_test_lib = cairo_test.c read_png.c write_png.c xmalloc.c
+cairo_test_lib =\
+cairo_test.c	\
+cairo_test.h	\
+read_png.c	\
+read_png.h	\
+write_png.c	\
+write_png.h	\
+xmalloc.c	\
+xmalloc.h
 
 line_width_SOURCES = line_width.c $(cairo_test_lib)
 move_to_show_surface_SOURCES = move_to_show_surface.c $(cairo_test_lib)
 
-
-
-
+CLEANFILES = *-out.png *-diff.png

Index: cairo_test.c
===================================================================
RCS file: /cvs/cairo/cairo/test/cairo_test.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cairo_test.c	26 Oct 2004 21:38:43 -0000	1.1
+++ cairo_test.c	27 Oct 2004 01:19:55 -0000	1.2
@@ -36,16 +36,20 @@
 #define CAIRO_TEST_REF_SUFFIX "-ref.png"
 #define CAIRO_TEST_DIFF_SUFFIX "-diff.png"
 
-static char *
-xstrcat_alloc (const char *s1, const char *s2)
+static void
+xasprintf (char **strp, const char *fmt, ...)
 {
-    char *ret;
+    va_list va;
+    int ret;
 
-    ret = xmalloc (strlen (s1) + strlen (s2) + 1);
-    strcpy (ret, s1);
-    strcat (ret, s2);
+    va_start (va, fmt);
+    ret = vasprintf (strp, fmt, va);
+    va_end (va);
 
-    return ret;
+    if (ret < 0) {
+	fprintf (stderr, "Out of memory\n");
+	exit (1);
+    }
 }
 
 /* Image comparison code courttesy of Richard Worth.
@@ -102,6 +106,7 @@
     int stride;
     unsigned char *png_buf, *ref_buf, *diff_buf;
     char *png_name, *ref_name, *diff_name;
+    char *srcdir;
     int pixels_changed;
     int ref_width, ref_height, ref_stride;
     read_png_status_t png_status;
@@ -123,10 +128,12 @@
     cairo_destroy (cr);
 
     /* Then we've got a bunch of string manipulation and file I/O for the check */
-
-    png_name = xstrcat_alloc (test->name, CAIRO_TEST_PNG_SUFFIX);
-    ref_name = xstrcat_alloc (test->name, CAIRO_TEST_REF_SUFFIX);
-    diff_name = xstrcat_alloc (test->name, CAIRO_TEST_DIFF_SUFFIX);
+    srcdir = getenv ("srcdir");
+    if (!srcdir)
+	srcdir = "";
+    xasprintf (&png_name, "%s%s", test->name, CAIRO_TEST_PNG_SUFFIX);
+    xasprintf (&ref_name, "%s/%s%s", srcdir, test->name, CAIRO_TEST_REF_SUFFIX);
+    xasprintf (&diff_name, "%s%s", test->name, CAIRO_TEST_DIFF_SUFFIX);
 
     write_png_argb32 (png_buf, png_name, test->width, test->height, stride);
 




More information about the cairo-commit mailing list