Augment cairo_test_init with cairo_test_fini to avoid leak

Without this, any tests that were using cairo_test_init rather than
cairo_test would end up leaking a FILE* for the log file. So this
keeps valgrind much more happy with the test suite.
This commit is contained in:
Carl Worth 2007-03-02 11:31:13 -08:00
parent 7d6e21c7e2
commit b52dda62fe
11 changed files with 45 additions and 25 deletions

View file

@ -104,6 +104,12 @@ cairo_test_init (const char *test_name)
printf ("\nTESTING %s\n", test_name);
}
void
cairo_test_fini (void)
{
fclose (cairo_test_log_file);
}
void
cairo_test_log (const char *fmt, ...)
{
@ -552,7 +558,7 @@ cairo_test_expecting (cairo_test_t *test,
ret = CAIRO_TEST_FAILURE;
}
fclose (cairo_test_log_file);
cairo_test_fini ();
free (targets_to_test);

View file

@ -101,17 +101,21 @@ typedef struct _cairo_test {
cairo_test_status_t
cairo_test (cairo_test_t *test);
/* cairo_test_init() and cairo_test_log() exist to help in writing
* tests for which cairo_test() is not appropriate for one reason or
* another. For example, some tests might not be doing any drawing at
* all, or may need to create their own cairo_t rather than be handed
* one by cairo_test.
/* cairo_test_init(), cairo_test_log(), and cairo_test_fini() exist to
* help in writing tests for which cairo_test() is not appropriate for
* one reason or another. For example, some tests might not be doing
* any drawing at all, or may need to create their own cairo_t rather
* than be handed one by cairo_test.
*/
/* Initialize test-specific resources, (log files, etc.) */
void
cairo_test_init (const char *test_name);
/* Finalize test-specific resource. */
void
cairo_test_fini (void);
/* Print a message to the log file, ala printf. */
void
cairo_test_log (const char *fmt, ...) CAIRO_PRINTF_FORMAT(1, 2);

View file

@ -124,6 +124,8 @@ draw (cairo_t *cr, int width, int height)
}
cairo_path_destroy (path);
cairo_destroy (cr_error);
/* We draw in the default black, so paint white first. */
cairo_save (cr);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */

View file

@ -223,5 +223,7 @@ main (void)
return status;
#endif
cairo_test_fini ();
return CAIRO_TEST_SUCCESS;
}

View file

@ -94,5 +94,7 @@ main (void)
return CAIRO_TEST_FAILURE;
}
cairo_test_fini ();
return CAIRO_TEST_SUCCESS;
}

View file

@ -174,5 +174,7 @@ main (void)
printf ("multi-page: Please check %s to ensure it looks happy.\n", filename);
#endif
cairo_test_fini ();
return CAIRO_TEST_SUCCESS;
}

View file

@ -70,5 +70,7 @@ main (void)
cairo_pattern_destroy (linear);
cairo_pattern_destroy (radial);
cairo_test_fini ();
return CAIRO_TEST_SUCCESS;
}

View file

@ -130,5 +130,7 @@ main (void)
printf ("svg-surface: Please check %s to make sure it looks happy.\n",
filename);
cairo_test_fini ();
return 0;
}

View file

@ -113,5 +113,7 @@ main (void)
printf ("svg-surface: Please check svg-surface.svg to make sure it looks happy.\n");
cairo_test_fini ();
return 0;
}

View file

@ -55,5 +55,7 @@ main (void)
check (tt_composite_glyph_t, 18);
check (tt_glyph_data_t, 28);
cairo_test_fini ();
return ret;
}

View file

@ -38,7 +38,6 @@
#define OFFSCREEN_OFFSET 50
cairo_bool_t result = 0;
FILE *log_file = NULL;
static void
draw_pattern (cairo_surface_t *surface)
@ -177,14 +176,14 @@ do_test (Display *dpy,
&result);
}
fprintf (log_file, "xlib-surface: %s, %s, %s%s: %s\n",
use_render ? " render" : "no-render",
set_size ? " size" : "no-size",
use_pixmap ? "pixmap" : "window",
use_pixmap ?
" " :
(offscreen ? ", offscreen" : ", onscreen"),
result.pixels_changed ? "FAIL" : "PASS");
cairo_test_log ("xlib-surface: %s, %s, %s%s: %s\n",
use_render ? " render" : "no-render",
set_size ? " size" : "no-size",
use_pixmap ? "pixmap" : "window",
use_pixmap ?
" " :
(offscreen ? ", offscreen" : ", onscreen"),
result.pixels_changed ? "FAIL" : "PASS");
if (result.pixels_changed)
return CAIRO_TEST_FAILURE;
@ -222,22 +221,17 @@ main (void)
cairo_test_status_t status, result = CAIRO_TEST_SUCCESS;
cairo_test_init ("xlib-surface");
log_file = fopen ("xlib-surface.log", "w");
if (log_file == NULL) {
fprintf (stderr, "Error opening log file: %s\n", "xlib-surface.log");
log_file = stderr;
}
dpy = XOpenDisplay (NULL);
if (!dpy) {
fprintf (log_file, "xlib-surface: Cannot open display, skipping\n");
fclose (log_file);
cairo_test_log ("xlib-surface: Cannot open display, skipping\n");
cairo_test_fini ();
return 0;
}
if (!check_visual (dpy)) {
fprintf (log_file, "xlib-surface: default visual is not RGB24 or BGR24, skipping\n");
fclose (log_file);
cairo_test_log ("xlib-surface: default visual is not RGB24 or BGR24, skipping\n");
cairo_test_fini ();
return 0;
}
@ -283,7 +277,7 @@ main (void)
cairo_debug_reset_static_data ();
fclose (log_file);
cairo_test_fini ();
return result;
}