Removing mucking around with stderr and add a cairo_test_log function instead.

Switch all error messages from fprintf(stderr,...) to cairo_test_log(...).
This commit is contained in:
Carl Worth 2005-05-10 20:25:38 +00:00
parent 40796148b8
commit b05c85eafb
10 changed files with 68 additions and 35 deletions

View file

@ -1,3 +1,17 @@
2005-05-10 Carl Worth <cworth@cworth.org>
* 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(...).
2005-05-10 Carl Worth <cworth@cworth.org>
* configure.in: Fix URLs for glitz and xlibs, (thanks to Jason

View file

@ -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 @@ static void
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 @@ image_diff (const char *filename_a,
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;

View file

@ -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 @@ xasprintf (char **strp, const char *fmt, ...)
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 @@ xasprintf (char **strp, const char *fmt, ...)
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 @@ static void
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 @@ create_xlib_surface (int width, int height, void **closure)
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 @@ cairo_test_for_target (cairo_test_t *test,
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 @@ cairo_test_for_target (cairo_test_t *test,
/* 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 @@ cairo_test_for_target (cairo_test_t *test,
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 @@ static cairo_test_status_t
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 @@ cairo_test_real (cairo_test_t *test, cairo_test_draw_function_t draw)
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 @@ cairo_test_real (cairo_test_t *test, cairo_test_draw_function_t draw)
}
}
fclose (stderr);
stderr = stderr_saved;
fclose (cairo_test_log_file);
return ret;
}

View file

@ -57,6 +57,9 @@ cairo_test_expect_failure (cairo_test_t *test,
cairo_pattern_t *
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, ...);

View file

@ -50,7 +50,7 @@ draw (cairo_t *cr, int width, int height)
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;
}

View file

@ -50,7 +50,7 @@ draw (cairo_t *cr, int width, int height)
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;
}

View file

@ -41,7 +41,7 @@ main (void)
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;
}

View file

@ -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 @@ read_png_argb32 (const char *filename,
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 @@ read_png_argb32 (const char *filename,
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 @@ read_png_argb32 (const char *filename,
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;
}

View file

@ -186,7 +186,7 @@ draw (cairo_t *cr, int width, int height)
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 @@ draw (cairo_t *cr, int width, int height)
}
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;
}

View file

@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "cairo-test.h"
#include "xmalloc.h"
void *
@ -35,7 +36,7 @@ xmalloc (size_t size)
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 @@ xcalloc (size_t nmemb, size_t size)
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);
}