[cairo-commit] cairo/test buffer-diff.c, 1.4, 1.5 cairo-test.c, 1.29, 1.30 cairo-test.h, 1.8, 1.9 create-for-png.c, 1.4, 1.5 pdf-surface.c, 1.2, 1.3 read-png.c, 1.5, 1.6 trap-clip.c, 1.3, 1.4 xmalloc.c, 1.1, 1.2

Carl Worth commit at pdx.freedesktop.org
Tue May 10 20:25:40 PDT 2005


Committed by: cworth

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

Modified Files:
	buffer-diff.c cairo-test.c cairo-test.h create-for-png.c 
	pdf-surface.c read-png.c trap-clip.c xmalloc.c 
Log Message:

        * test/cairo-test.c:
        * test/cairo-test.h: Removing mucking around with stderr and add a
        cairo_test_log function instead.

        * test/buffer-diff.c:
        * test/create-for-png.c:
        * test/pdf-surface.c:
        * test/read-png.c:
        * test/trap-clip.c:
        * test/xmalloc.c: Switch all error messages from
        fprintf(stderr,...) to cairo_test_log(...).


Index: buffer-diff.c
===================================================================
RCS file: /cvs/cairo/cairo/test/buffer-diff.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- buffer-diff.c	27 Apr 2005 20:33:25 -0000	1.4
+++ buffer-diff.c	11 May 2005 03:25:38 -0000	1.5
@@ -28,6 +28,8 @@
 #include <errno.h>
 #include <string.h>
 
+#include "cairo-test.h"
+
 #include "buffer-diff.h"
 #include "read-png.h"
 #include "write-png.h"
@@ -37,8 +39,8 @@
 xunlink (const char *pathname)
 {
     if (unlink (pathname) < 0 && errno != ENOENT) {
-	fprintf (stderr, "  Error: Cannot remove %s: %s\n",
-		 pathname, strerror (errno));
+	cairo_test_log ("  Error: Cannot remove %s: %s\n",
+			pathname, strerror (errno));
 	exit (1);
     }
 }
@@ -117,12 +119,11 @@
 	height_a != height_b ||
 	stride_a != stride_b)
     {
-	fprintf (stderr,
-		 "Error: Image size mismatch: (%dx%d@%d) vs. (%dx%d@%d)\n"
-		 "       for %s vs. %s\n",
-		 width_a, height_a, stride_a,
-		 width_b, height_b, stride_b,
-		 filename_a, filename_b);
+	cairo_test_log ("Error: Image size mismatch: (%dx%d@%d) vs. (%dx%d@%d)\n"
+			"       for %s vs. %s\n",
+			width_a, height_a, stride_a,
+			width_b, height_b, stride_b,
+			filename_a, filename_b);
 	free (buf_a);
 	free (buf_b);
 	return -1;

Index: cairo-test.c
===================================================================
RCS file: /cvs/cairo/cairo/test/cairo-test.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- cairo-test.c	7 May 2005 04:33:22 -0000	1.29
+++ cairo-test.c	11 May 2005 03:25:38 -0000	1.30
@@ -42,6 +42,21 @@
 #define CAIRO_TEST_REF_SUFFIX "-ref.png"
 #define CAIRO_TEST_DIFF_SUFFIX "-diff.png"
 
+/* Static data is messy, but we're coding for tests here, not a
+ * general-purpose library, and it keeps the tests cleaner to avoid a
+ * context object there, (though not a whole lot). */
+FILE *cairo_test_log_file;
+
+void
+cairo_test_log (const char *fmt, ...)
+{
+    va_list va;
+
+    va_start (va, fmt);
+    vfprintf (cairo_test_log_file, fmt, va);
+    va_end (va);
+}
+
 void
 xasprintf (char **strp, const char *fmt, ...)
 {
@@ -54,7 +69,7 @@
     va_end (va);
 
     if (ret < 0) {
-	fprintf (stderr, "Out of memory\n");
+	cairo_test_log ("Out of memory\n");
 	exit (1);
     }
 #else /* !HAVE_VASNPRINTF */
@@ -68,18 +83,18 @@
     va_end (va);
 
     if (ret < 0) {
-	fprintf (stderr, "Failure in vsnprintf\n");
+	cairo_test_log ("Failure in vsnprintf\n");
 	exit (1);
     }
     
     if (strlen (buffer) == sizeof(buffer) - 1) {
-	fprintf (stderr, "Overflowed fixed buffer\n");
+	cairo_test_log ("Overflowed fixed buffer\n");
 	exit (1);
     }
     
     *strp = strdup (buffer);
     if (!*strp) {
-	fprintf (stderr, "Out of memory\n");
+	cairo_test_log ("Out of memory\n");
 	exit (1);
     }
 #endif /* !HAVE_VASNPRINTF */
@@ -89,8 +104,8 @@
 xunlink (const char *pathname)
 {
     if (unlink (pathname) < 0 && errno != ENOENT) {
-	fprintf (stderr, "  Error: Cannot remove %s: %s\n",
-		 pathname, strerror (errno));
+	cairo_test_log ("  Error: Cannot remove %s: %s\n",
+			pathname, strerror (errno));
 	exit (1);
     }
 }
@@ -211,7 +226,7 @@
 
     xtc->dpy = dpy = XOpenDisplay (0);
     if (xtc->dpy == NULL) {
-	fprintf (stderr, "Failed to open display: %s\n", XDisplayName(0));
+	cairo_test_log ("Failed to open display: %s\n", XDisplayName(0));
 	return NULL;
     }
 
@@ -263,7 +278,7 @@
     surface = (target->create_target_surface) (test->width, test->height,
 					       &target->closure);
     if (surface == NULL) {
-	fprintf (stderr, "Error: Failed to set %s target\n", target->name);
+	cairo_test_log ("Error: Failed to set %s target\n", target->name);
 	return CAIRO_TEST_FAILURE;
     }
 
@@ -279,12 +294,12 @@
 
     /* Then, check all the different ways it could fail. */
     if (status) {
-	fprintf (stderr, "Error: Function under test failed\n");
+	cairo_test_log ("Error: Function under test failed\n");
 	return status;
     }
 
     if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
-	fprintf (stderr, "Error: Function under test left cairo status in an error state: %s\n", cairo_status_string (cr));
+	cairo_test_log ("Error: Function under test left cairo status in an error state: %s\n", cairo_status_string (cr));
 	return CAIRO_TEST_FAILURE;
     }
 
@@ -307,7 +322,7 @@
     if (pixels_changed) {
 	ret = CAIRO_TEST_FAILURE;
 	if (pixels_changed > 0)
-	    fprintf (stderr, "Error: %d pixels differ from reference image %s\n",
+	    cairo_test_log ("Error: %d pixels differ from reference image %s\n",
 		     pixels_changed, ref_name);
     } else {
 	ret = CAIRO_TEST_SUCCESS;
@@ -324,7 +339,6 @@
 cairo_test_real (cairo_test_t *test, cairo_test_draw_function_t draw)
 {
     int i;
-    FILE *stderr_saved = stderr;
     cairo_test_status_t status, ret;
     cairo_test_target_t targets[] = 
 	{
@@ -350,12 +364,12 @@
     xasprintf (&log_name, "%s%s", test->name, CAIRO_TEST_LOG_SUFFIX);
     xunlink (log_name);
 
-    stderr = fopen (log_name, "a");
+    cairo_test_log_file = fopen (log_name, "a");
 
     ret = CAIRO_TEST_SUCCESS;
     for (i=0; i < sizeof(targets)/sizeof(targets[0]); i++) {
 	cairo_test_target_t *target = &targets[i];
-	fprintf (stderr, "Testing %s with %s target\n", test->name, target->name);
+	cairo_test_log ("Testing %s with %s target\n", test->name, target->name);
 	printf ("%s-%s:\t", test->name, target->name);
 	status = cairo_test_for_target (test, draw, target);
 	if (status) {
@@ -366,8 +380,7 @@
 	}
     }
 
-    fclose (stderr);
-    stderr = stderr_saved;
+    fclose (cairo_test_log_file);
 
     return ret;
 }

Index: cairo-test.h
===================================================================
RCS file: /cvs/cairo/cairo/test/cairo-test.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- cairo-test.h	27 Apr 2005 20:33:25 -0000	1.8
+++ cairo-test.h	11 May 2005 03:25:38 -0000	1.9
@@ -58,6 +58,9 @@
 cairo_test_create_png_pattern (cairo_t *cr, const char *filename);
 
 void
+cairo_test_log (const char *fmt, ...);
+
+void
 xasprintf (char **strp, const char *fmt, ...);
 
 #endif

Index: create-for-png.c
===================================================================
RCS file: /cvs/cairo/cairo/test/create-for-png.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- create-for-png.c	3 May 2005 15:33:32 -0000	1.4
+++ create-for-png.c	11 May 2005 03:25:38 -0000	1.5
@@ -50,7 +50,7 @@
     free (filename);
 
     if (surface == NULL) {
-	fprintf (stderr, "Error: failed to open file %s\n", filename);
+	cairo_test_log ("Error: failed to open file %s\n", filename);
 	return CAIRO_TEST_FAILURE;
     }
 

Index: pdf-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/test/pdf-surface.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pdf-surface.c	6 May 2005 20:23:41 -0000	1.2
+++ pdf-surface.c	11 May 2005 03:25:38 -0000	1.3
@@ -41,7 +41,7 @@
 
     file = fopen (filename, "w");
     if (!file) {
-	fprintf (stderr, "Failed to open file %s\n", filename);
+	cairo_test_log ("Failed to open file %s\n", filename);
 	return CAIRO_TEST_FAILURE;
     }
 

Index: read-png.c
===================================================================
RCS file: /cvs/cairo/cairo/test/read-png.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- read-png.c	10 May 2005 19:42:32 -0000	1.5
+++ read-png.c	11 May 2005 03:25:38 -0000	1.6
@@ -43,6 +43,7 @@
 #include <stdlib.h>
 #include <png.h>
 
+#include "cairo-test.h"
 #include "read-png.h"
 #include "xmalloc.h"
 
@@ -90,14 +91,14 @@
 
     file = fopen (filename, "rb");
     if (file == NULL) {
-	fprintf (stderr, "Error: File not found: %s\n", filename);
+	cairo_test_log ("Error: File not found: %s\n", filename);
 	return READ_PNG_FILE_NOT_FOUND;
     }
 
     sig_bytes = fread (png_sig, 1, PNG_SIG_SIZE, file);
     if (png_check_sig (png_sig, sig_bytes) == 0) {
         fclose (file);
-	fprintf (stderr, "Error: File is not a PNG image: %s\n", filename);
+	cairo_test_log ("Error: File is not a PNG image: %s\n", filename);
 	return READ_PNG_FILE_NOT_PNG;
     }
 
@@ -108,7 +109,7 @@
                                   NULL);
     if (png == NULL) {
         fclose (file);
-	fprintf (stderr, "Error: Out of memory while reading %s\n", filename);
+	cairo_test_log ("Error: Out of memory while reading %s\n", filename);
 	return READ_PNG_NO_MEMORY;
     }
 
@@ -116,7 +117,7 @@
     if (info == NULL) {
         fclose (file);
         png_destroy_read_struct (&png, NULL, NULL);
-	fprintf (stderr, "Error: Out of memory while reading %s\n", filename);
+	cairo_test_log ("Error: Out of memory while reading %s\n", filename);
 	return READ_PNG_NO_MEMORY;
     }
 

Index: trap-clip.c
===================================================================
RCS file: /cvs/cairo/cairo/test/trap-clip.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- trap-clip.c	6 May 2005 20:32:53 -0000	1.3
+++ trap-clip.c	11 May 2005 03:25:38 -0000	1.4
@@ -186,7 +186,7 @@
 		pattern_funcs[i] (cr, x, y);
 		draw_funcs[j] (cr, x, y);
 		if (cairo_status (cr))
-		    fprintf (stderr, "%d %d HERE!\n", i, j);
+		    cairo_test_log ("%d %d HERE!\n", i, j);
 
 		cairo_restore (cr);
 	    }
@@ -194,7 +194,7 @@
     }
 
     if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
-	fprintf (stderr, "%d %d .HERE!\n", i, j);
+	cairo_test_log ("%d %d .HERE!\n", i, j);
 
     return CAIRO_TEST_SUCCESS;
 }

Index: xmalloc.c
===================================================================
RCS file: /cvs/cairo/cairo/test/xmalloc.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- xmalloc.c	26 Oct 2004 21:38:43 -0000	1.1
+++ xmalloc.c	11 May 2005 03:25:38 -0000	1.2
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "cairo-test.h"
 #include "xmalloc.h"
 
 void *
@@ -35,7 +36,7 @@
 
     buf = malloc (size);
     if (!buf) {
-	fprintf (stderr, "Error: Out of memory. Exiting.\n");
+	cairo_test_log ("Error: Out of memory. Exiting.\n");
 	exit (1);
     }
 
@@ -49,7 +50,7 @@
 
     buf = calloc (nmemb, size);
     if (!buf) {
-	fprintf (stderr, "Error: Out of memory. Exiting\n");
+	cairo_test_log ("Error: Out of memory. Exiting\n");
 	exit (1);
     }
 




More information about the cairo-commit mailing list