From b05c85eafb953fbe082b67875865ae4e4ca56ed2 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 10 May 2005 20:25:38 +0000 Subject: [PATCH] Removing mucking around with stderr and add a cairo_test_log function instead. Switch all error messages from fprintf(stderr,...) to cairo_test_log(...). --- ChangeLog | 14 +++++++++++++ test/buffer-diff.c | 17 ++++++++-------- test/cairo-test.c | 45 +++++++++++++++++++++++++++--------------- test/cairo-test.h | 3 +++ test/create-for-png.c | 2 +- test/create-from-png.c | 2 +- test/pdf-surface.c | 2 +- test/read-png.c | 9 +++++---- test/trap-clip.c | 4 ++-- test/xmalloc.c | 5 +++-- 10 files changed, 68 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index d9332d89d..8c4dde406 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-05-10 Carl Worth + + * 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 * configure.in: Fix URLs for glitz and xlibs, (thanks to Jason diff --git a/test/buffer-diff.c b/test/buffer-diff.c index b4b42e28a..e540d2f9b 100644 --- a/test/buffer-diff.c +++ b/test/buffer-diff.c @@ -28,6 +28,8 @@ #include #include +#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; diff --git a/test/cairo-test.c b/test/cairo-test.c index 1330abb4d..e92ea47e5 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -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; } diff --git a/test/cairo-test.h b/test/cairo-test.h index 84fa4a7ea..fe70171c5 100644 --- a/test/cairo-test.h +++ b/test/cairo-test.h @@ -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, ...); diff --git a/test/create-for-png.c b/test/create-for-png.c index f77d906c8..ef3b6f62e 100644 --- a/test/create-for-png.c +++ b/test/create-for-png.c @@ -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; } diff --git a/test/create-from-png.c b/test/create-from-png.c index f77d906c8..ef3b6f62e 100644 --- a/test/create-from-png.c +++ b/test/create-from-png.c @@ -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; } diff --git a/test/pdf-surface.c b/test/pdf-surface.c index 970c77dab..320d26eb6 100644 --- a/test/pdf-surface.c +++ b/test/pdf-surface.c @@ -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; } diff --git a/test/read-png.c b/test/read-png.c index 4a3880f93..96259dfe8 100644 --- a/test/read-png.c +++ b/test/read-png.c @@ -43,6 +43,7 @@ #include #include +#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; } diff --git a/test/trap-clip.c b/test/trap-clip.c index 241680392..2ad43ea5f 100644 --- a/test/trap-clip.c +++ b/test/trap-clip.c @@ -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; } diff --git a/test/xmalloc.c b/test/xmalloc.c index 04ed38afa..f5721c5de 100644 --- a/test/xmalloc.c +++ b/test/xmalloc.c @@ -26,6 +26,7 @@ #include #include +#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); }