[cairo-commit] test/cairo-test.c

Chris Wilson ickle at kemper.freedesktop.org
Thu Sep 11 05:15:45 PDT 2008


 test/cairo-test.c |   83 ++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 63 insertions(+), 20 deletions(-)

New commits:
commit e9e439a7a84fab0b888029801f62ea8d7f0a2ecf
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Sep 11 10:33:23 2008 +0100

    [test] Check for updated reference images.
    
    Delete the results of previous runs if the reference images are more
    recent.
    
    There's still potential error if the conversion utility or its required
    libraries are modified...

diff --git a/test/cairo-test.c b/test/cairo-test.c
index b9eaf36..1049cdd 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -429,6 +429,26 @@ cairo_test_get_reference_image (cairo_test_context_t *ctx,
 }
 
 static cairo_bool_t
+cairo_test_file_is_older (const char *filename,
+	                  const char *ref_filename)
+{
+#ifdef HAVE_STAT
+    struct stat st, ref;
+
+    if (stat (filename, &st) < 0)
+	return FALSE;
+
+    if (stat (ref_filename, &ref) < 0)
+	return TRUE;
+
+    return st.m_time < ref.m_time;
+#else
+    /* XXX */
+    return FALSE;
+#endif
+}
+
+static cairo_bool_t
 cairo_test_files_equal (const char *test_filename,
 			const char *pass_filename)
 {
@@ -680,28 +700,26 @@ cairo_test_for_target (cairo_test_context_t		 *ctx,
 	    }
 	}
 
-	/* first *always* save the test output */
-	test_image = target->get_image_surface (surface,
-					       ctx->test->width,
-					       ctx->test->height);
-	if (cairo_surface_status (test_image)) {
-	    cairo_test_log (ctx, "Error: Failed to extract image: %s\n",
-			    cairo_status_to_string (cairo_surface_status (test_image)));
-	    cairo_surface_destroy (test_image);
-	    ret = CAIRO_TEST_FAILURE;
-	    goto UNWIND_CAIRO;
-	}
+	if (ref_name == NULL) {
+	    cairo_test_log (ctx, "Error: Cannot find reference image for %s\n",
+			    base_name);
 
-	_xunlink (ctx, png_name);
-	diff_status = cairo_surface_write_to_png (test_image, png_name);
-	if (diff_status) {
-	    cairo_test_log (ctx, "Error: Failed to write output image: %s\n",
-			    cairo_status_to_string (diff_status));
+	    /* we may be running this test to generate reference images */
+	    _xunlink (ctx, png_name);
+	    test_image = target->get_image_surface (surface,
+		    ctx->test->width,
+		    ctx->test->height);
+	    diff_status = cairo_surface_write_to_png (test_image, png_name);
+	    if (diff_status) {
+		cairo_test_log (ctx,
+			        "Error: Failed to write output image: %s\n",
+			        cairo_status_to_string (diff_status));
+	    }
 	    cairo_surface_destroy (test_image);
+
 	    ret = CAIRO_TEST_FAILURE;
 	    goto UNWIND_CAIRO;
 	}
-	have_output = TRUE;
 
 	if (target->file_extension != NULL) { /* compare vector surfaces */
 	    xasprintf (&test_filename, "%s-out%s",
@@ -710,6 +728,12 @@ cairo_test_for_target (cairo_test_context_t		 *ctx,
 		       base_name, target->file_extension);
 	    xasprintf (&fail_filename, "%s-fail%s",
 		       base_name, target->file_extension);
+
+	    if (cairo_test_file_is_older (pass_filename, ref_name))
+		_xunlink (ctx, pass_filename);
+	    if (cairo_test_file_is_older (fail_filename, ref_name))
+		_xunlink (ctx, pass_filename);
+
 	    if (cairo_test_files_equal (test_filename, pass_filename)) {
 		/* identical output as last known PASS */
 		cairo_test_log (ctx, "Vector surface matches last pass.\n");
@@ -727,13 +751,27 @@ cairo_test_for_target (cairo_test_context_t		 *ctx,
 	    }
 	}
 
-	if (ref_name == NULL) {
-	    cairo_test_log (ctx, "Error: Cannot find reference image for %s\n",
-			    base_name);
+	test_image = target->get_image_surface (surface,
+					       ctx->test->width,
+					       ctx->test->height);
+	if (cairo_surface_status (test_image)) {
+	    cairo_test_log (ctx, "Error: Failed to extract image: %s\n",
+			    cairo_status_to_string (cairo_surface_status (test_image)));
+	    cairo_surface_destroy (test_image);
+	    ret = CAIRO_TEST_FAILURE;
+	    goto UNWIND_CAIRO;
+	}
+
+	_xunlink (ctx, png_name);
+	diff_status = cairo_surface_write_to_png (test_image, png_name);
+	if (diff_status) {
+	    cairo_test_log (ctx, "Error: Failed to write output image: %s\n",
+			    cairo_status_to_string (diff_status));
 	    cairo_surface_destroy (test_image);
 	    ret = CAIRO_TEST_FAILURE;
 	    goto UNWIND_CAIRO;
 	}
+	have_output = TRUE;
 
 	/* binary compare png files (no decompression) */
 	if (target->file_extension == NULL) {
@@ -741,6 +779,11 @@ cairo_test_for_target (cairo_test_context_t		 *ctx,
 	    xasprintf (&pass_filename, "%s-pass.png", base_name);
 	    xasprintf (&fail_filename, "%s-fail.png", base_name);
 
+	    if (cairo_test_file_is_older (pass_filename, ref_name))
+		_xunlink (ctx, pass_filename);
+	    if (cairo_test_file_is_older (fail_filename, ref_name))
+		_xunlink (ctx, pass_filename);
+
 	    if (cairo_test_files_equal (test_filename, pass_filename)) {
 		/* identical output as last known PASS, pass */
 		cairo_test_log (ctx, "PNG file exactly matches last pass.\n");


More information about the cairo-commit mailing list