diff options
author | Carl Worth <cworth@cworth.org> | 2007-03-02 11:31:13 -0800 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2007-03-02 11:31:13 -0800 |
commit | b52dda62fea0745cc28d6149dc4688ade524b4df (patch) | |
tree | e39fea2b93b977ad0b232b8cda4f732c3d972764 /test | |
parent | 7d6e21c7e298e1795f36fdf021d61ef4ed0ca0fa (diff) |
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.
Diffstat (limited to 'test')
-rwxr-xr-x | test/cairo-test.c | 8 | ||||
-rwxr-xr-x | test/cairo-test.h | 14 | ||||
-rw-r--r-- | test/copy-path.c | 2 | ||||
-rw-r--r-- | test/create-for-stream.c | 2 | ||||
-rw-r--r-- | test/in-fill-empty-trapezoid.c | 2 | ||||
-rw-r--r-- | test/multi-page.c | 2 | ||||
-rw-r--r-- | test/pattern-get-type.c | 2 | ||||
-rw-r--r-- | test/svg-clip.c | 2 | ||||
-rw-r--r-- | test/svg-surface.c | 2 | ||||
-rw-r--r-- | test/truetype-tables.c | 2 | ||||
-rw-r--r-- | test/xlib-surface.c | 32 |
11 files changed, 45 insertions, 25 deletions
diff --git a/test/cairo-test.c b/test/cairo-test.c index 16173b667..738bd63f6 100755 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -105,6 +105,12 @@ cairo_test_init (const char *test_name) } void +cairo_test_fini (void) +{ + fclose (cairo_test_log_file); +} + +void cairo_test_log (const char *fmt, ...) { va_list va; @@ -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); diff --git a/test/cairo-test.h b/test/cairo-test.h index a2d0285b0..d3612ba40 100755 --- a/test/cairo-test.h +++ b/test/cairo-test.h @@ -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); diff --git a/test/copy-path.c b/test/copy-path.c index b7635468f..142bfa57d 100644 --- a/test/copy-path.c +++ b/test/copy-path.c @@ -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 */ diff --git a/test/create-for-stream.c b/test/create-for-stream.c index cbe820048..937eaf5b2 100644 --- a/test/create-for-stream.c +++ b/test/create-for-stream.c @@ -223,5 +223,7 @@ main (void) return status; #endif + cairo_test_fini (); + return CAIRO_TEST_SUCCESS; } diff --git a/test/in-fill-empty-trapezoid.c b/test/in-fill-empty-trapezoid.c index 58d347ac7..61fdb70ea 100644 --- a/test/in-fill-empty-trapezoid.c +++ b/test/in-fill-empty-trapezoid.c @@ -94,5 +94,7 @@ main (void) return CAIRO_TEST_FAILURE; } + cairo_test_fini (); + return CAIRO_TEST_SUCCESS; } diff --git a/test/multi-page.c b/test/multi-page.c index 86cf188bb..f0265e25d 100644 --- a/test/multi-page.c +++ b/test/multi-page.c @@ -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; } diff --git a/test/pattern-get-type.c b/test/pattern-get-type.c index a6aba03aa..d64dd881a 100644 --- a/test/pattern-get-type.c +++ b/test/pattern-get-type.c @@ -70,5 +70,7 @@ main (void) cairo_pattern_destroy (linear); cairo_pattern_destroy (radial); + cairo_test_fini (); + return CAIRO_TEST_SUCCESS; } diff --git a/test/svg-clip.c b/test/svg-clip.c index dcdf02818..81af1040f 100644 --- a/test/svg-clip.c +++ b/test/svg-clip.c @@ -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; } diff --git a/test/svg-surface.c b/test/svg-surface.c index 355394c6d..99b7b4ea0 100644 --- a/test/svg-surface.c +++ b/test/svg-surface.c @@ -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; } diff --git a/test/truetype-tables.c b/test/truetype-tables.c index 851db9023..c279c8b8a 100644 --- a/test/truetype-tables.c +++ b/test/truetype-tables.c @@ -55,5 +55,7 @@ main (void) check (tt_composite_glyph_t, 18); check (tt_glyph_data_t, 28); + cairo_test_fini (); + return ret; } diff --git a/test/xlib-surface.c b/test/xlib-surface.c index 44bea9275..3b6d1b503 100644 --- a/test/xlib-surface.c +++ b/test/xlib-surface.c @@ -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; } |