2004-10-26 14:38:43 +00:00
|
|
|
/*
|
2005-08-05 10:05:29 +00:00
|
|
|
* Copyright © 2004 Red Hat, Inc.
|
2004-10-26 14:38:43 +00:00
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
|
* appear in supporting documentation, and that the name of
|
|
|
|
|
* Red Hat, Inc. not be used in advertising or publicity pertaining to
|
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
|
* permission. Red Hat, Inc. makes no representations about the
|
|
|
|
|
* suitability of this software for any purpose. It is provided "as
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
|
|
|
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
|
|
|
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Author: Carl D. Worth <cworth@cworth.org>
|
|
|
|
|
*/
|
|
|
|
|
|
2005-08-05 10:40:32 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-01-20 20:45:38 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdarg.h>
|
2006-06-16 19:01:20 -04:00
|
|
|
#include <ctype.h>
|
2006-06-30 22:01:24 +02:00
|
|
|
#include <setjmp.h>
|
2006-08-17 22:02:02 -04:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
2006-06-30 22:01:24 +02:00
|
|
|
#include <signal.h>
|
2006-08-17 22:02:02 -04:00
|
|
|
#endif
|
2005-10-08 11:58:20 +00:00
|
|
|
#include <assert.h>
|
2005-08-05 07:48:18 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-10-26 14:38:43 +00:00
|
|
|
#include <unistd.h>
|
2005-08-05 07:48:18 +00:00
|
|
|
#endif
|
2004-10-26 14:38:43 +00:00
|
|
|
#include <errno.h>
|
2005-01-20 20:45:38 +00:00
|
|
|
#include <string.h>
|
2005-08-31 19:11:22 +00:00
|
|
|
#if HAVE_FCFINI
|
2005-08-01 13:33:47 +00:00
|
|
|
#include <fontconfig/fontconfig.h>
|
2005-08-31 19:11:22 +00:00
|
|
|
#endif
|
2004-10-26 14:38:43 +00:00
|
|
|
|
2005-03-29 00:02:19 +00:00
|
|
|
#include "cairo-test.h"
|
2004-10-26 14:38:43 +00:00
|
|
|
|
2005-03-29 00:02:19 +00:00
|
|
|
#include "buffer-diff.h"
|
2004-10-26 14:38:43 +00:00
|
|
|
#include "xmalloc.h"
|
|
|
|
|
|
2005-08-05 07:48:18 +00:00
|
|
|
#ifdef _MSC_VER
|
2006-09-09 23:54:40 -07:00
|
|
|
#include <crtdbg.h>
|
2005-08-05 07:48:18 +00:00
|
|
|
#define vsnprintf _vsnprintf
|
2005-12-14 19:56:09 +00:00
|
|
|
#define access _access
|
|
|
|
|
#define F_OK 0
|
2005-08-05 07:48:18 +00:00
|
|
|
#endif
|
2006-06-30 22:01:24 +02:00
|
|
|
#ifndef FALSE
|
|
|
|
|
#define FALSE 0
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef TRUE
|
|
|
|
|
#define TRUE !FALSE
|
|
|
|
|
#endif
|
2005-08-05 07:48:18 +00:00
|
|
|
|
2005-09-13 12:11:32 +00:00
|
|
|
static void
|
|
|
|
|
xunlink (const char *pathname);
|
|
|
|
|
|
2006-04-25 09:03:26 -04:00
|
|
|
static const char *fail_face = "", *normal_face = "";
|
|
|
|
|
|
2005-03-08 13:44:14 +00:00
|
|
|
#define CAIRO_TEST_LOG_SUFFIX ".log"
|
2004-10-26 14:38:43 +00:00
|
|
|
#define CAIRO_TEST_PNG_SUFFIX "-out.png"
|
|
|
|
|
#define CAIRO_TEST_REF_SUFFIX "-ref.png"
|
|
|
|
|
#define CAIRO_TEST_DIFF_SUFFIX "-diff.png"
|
|
|
|
|
|
2006-02-15 13:46:52 -08:00
|
|
|
#define NUM_DEVICE_OFFSETS 2
|
|
|
|
|
|
2007-04-19 20:36:14 -04:00
|
|
|
static const char *vector_ignored_tests[] = {
|
|
|
|
|
/* We can't match the results of tests that depend on
|
|
|
|
|
* CAIRO_ANTIALIAS_NONE/SUBPIXEL for vector backends
|
|
|
|
|
* (nor do we care). */
|
2008-01-18 12:41:57 -08:00
|
|
|
"a1-image-sample",
|
|
|
|
|
"a1-traps-sample",
|
2007-04-19 20:36:14 -04:00
|
|
|
"ft-text-antialias-none",
|
|
|
|
|
"rectangle-rounding-error",
|
|
|
|
|
"text-antialias-gray",
|
|
|
|
|
"text-antialias-none",
|
|
|
|
|
"text-antialias-subpixel",
|
|
|
|
|
"unantialiased-shapes",
|
|
|
|
|
|
|
|
|
|
/* Nor do we care about rendering anomalies in external renderers. */
|
|
|
|
|
"fill-degenerate-sort-order",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
2005-05-10 20:25:38 +00:00
|
|
|
/* 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). */
|
2006-04-26 12:36:22 -07:00
|
|
|
FILE *cairo_test_log_file = NULL;
|
2006-08-08 01:16:49 -07:00
|
|
|
const char *srcdir;
|
2007-11-10 01:34:03 +00:00
|
|
|
const char *refdir;
|
2006-06-30 22:01:24 +02:00
|
|
|
|
|
|
|
|
/* Used to catch crashes in a test, such that we report it as such and
|
|
|
|
|
* continue testing, although one crasher may already have corrupted memory in
|
|
|
|
|
* an nonrecoverable fashion. */
|
|
|
|
|
jmp_buf jmpbuf;
|
2005-05-10 20:25:38 +00:00
|
|
|
|
2005-09-13 12:11:32 +00:00
|
|
|
void
|
|
|
|
|
cairo_test_init (const char *test_name)
|
|
|
|
|
{
|
|
|
|
|
char *log_name;
|
|
|
|
|
|
|
|
|
|
xasprintf (&log_name, "%s%s", test_name, CAIRO_TEST_LOG_SUFFIX);
|
|
|
|
|
xunlink (log_name);
|
|
|
|
|
|
|
|
|
|
cairo_test_log_file = fopen (log_name, "a");
|
|
|
|
|
if (cairo_test_log_file == NULL) {
|
|
|
|
|
fprintf (stderr, "Error opening log file: %s\n", log_name);
|
|
|
|
|
cairo_test_log_file = stderr;
|
|
|
|
|
}
|
|
|
|
|
free (log_name);
|
2006-07-11 22:19:39 -04:00
|
|
|
|
|
|
|
|
printf ("\nTESTING %s\n", test_name);
|
2005-09-13 12:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
2007-03-02 11:31:13 -08:00
|
|
|
void
|
|
|
|
|
cairo_test_fini (void)
|
|
|
|
|
{
|
|
|
|
|
fclose (cairo_test_log_file);
|
2007-03-02 12:30:14 -08:00
|
|
|
cairo_debug_reset_static_data ();
|
|
|
|
|
#if HAVE_FCFINI
|
|
|
|
|
FcFini ();
|
|
|
|
|
#endif
|
2007-03-02 11:31:13 -08:00
|
|
|
}
|
|
|
|
|
|
2005-05-10 20:25:38 +00:00
|
|
|
void
|
|
|
|
|
cairo_test_log (const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list va;
|
2006-04-26 12:36:22 -07:00
|
|
|
FILE *file = cairo_test_log_file ? cairo_test_log_file : stderr;
|
2005-05-10 20:25:38 +00:00
|
|
|
|
|
|
|
|
va_start (va, fmt);
|
2006-04-26 12:36:22 -07:00
|
|
|
vfprintf (file, fmt, va);
|
2005-05-10 20:25:38 +00:00
|
|
|
va_end (va);
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-08 13:44:14 +00:00
|
|
|
static void
|
|
|
|
|
xunlink (const char *pathname)
|
|
|
|
|
{
|
|
|
|
|
if (unlink (pathname) < 0 && errno != ENOENT) {
|
2006-08-01 20:39:56 -04:00
|
|
|
cairo_test_log ("Error: Cannot remove %s: %s\n",
|
2005-05-10 20:25:38 +00:00
|
|
|
pathname, strerror (errno));
|
2005-03-08 13:44:14 +00:00
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-08 01:16:49 -07:00
|
|
|
static char *
|
2006-08-01 20:39:56 -04:00
|
|
|
cairo_ref_name_for_test_target_format (const char *test_name,
|
|
|
|
|
const char *target_name,
|
|
|
|
|
const char *format)
|
|
|
|
|
{
|
|
|
|
|
char *ref_name = NULL;
|
|
|
|
|
|
2007-11-10 01:34:03 +00:00
|
|
|
/* First look for a previous build for comparison. */
|
|
|
|
|
if (refdir) {
|
|
|
|
|
xasprintf (&ref_name, "%s/%s-%s-%s%s", refdir,
|
|
|
|
|
test_name,
|
|
|
|
|
target_name,
|
|
|
|
|
format,
|
|
|
|
|
CAIRO_TEST_PNG_SUFFIX);
|
|
|
|
|
if (access (ref_name, F_OK) != 0)
|
|
|
|
|
free (ref_name);
|
|
|
|
|
else
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Next look for a target/format-specific reference image. */
|
2006-08-01 20:39:56 -04:00
|
|
|
xasprintf (&ref_name, "%s/%s-%s-%s%s", srcdir,
|
|
|
|
|
test_name,
|
|
|
|
|
target_name,
|
|
|
|
|
format,
|
|
|
|
|
CAIRO_TEST_REF_SUFFIX);
|
|
|
|
|
if (access (ref_name, F_OK) != 0)
|
|
|
|
|
free (ref_name);
|
|
|
|
|
else
|
|
|
|
|
goto done;
|
|
|
|
|
|
2008-04-14 20:11:44 +01:00
|
|
|
/* Next, look for target-specific reference image. */
|
2006-08-01 20:39:56 -04:00
|
|
|
xasprintf (&ref_name, "%s/%s-%s%s", srcdir,
|
|
|
|
|
test_name,
|
|
|
|
|
target_name,
|
|
|
|
|
CAIRO_TEST_REF_SUFFIX);
|
|
|
|
|
if (access (ref_name, F_OK) != 0)
|
|
|
|
|
free (ref_name);
|
|
|
|
|
else
|
|
|
|
|
goto done;
|
|
|
|
|
|
2008-04-14 20:11:44 +01:00
|
|
|
/* Next, look for format-specific reference image. */
|
2006-08-01 20:39:56 -04:00
|
|
|
xasprintf (&ref_name, "%s/%s-%s%s", srcdir,
|
|
|
|
|
test_name,
|
|
|
|
|
format,
|
|
|
|
|
CAIRO_TEST_REF_SUFFIX);
|
|
|
|
|
if (access (ref_name, F_OK) != 0)
|
|
|
|
|
free (ref_name);
|
|
|
|
|
else
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
|
|
/* Finally, look for the standard reference image. */
|
|
|
|
|
xasprintf (&ref_name, "%s/%s%s", srcdir,
|
|
|
|
|
test_name,
|
|
|
|
|
CAIRO_TEST_REF_SUFFIX);
|
|
|
|
|
if (access (ref_name, F_OK) != 0)
|
|
|
|
|
free (ref_name);
|
|
|
|
|
else
|
|
|
|
|
goto done;
|
|
|
|
|
|
2006-08-10 14:58:33 -04:00
|
|
|
ref_name = NULL;
|
2006-08-01 20:39:56 -04:00
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
return ref_name;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-19 22:26:28 +01:00
|
|
|
static cairo_bool_t
|
|
|
|
|
cairo_test_target_has_similar (const cairo_test_t *test, cairo_boilerplate_target_t *target)
|
|
|
|
|
{
|
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
cairo_bool_t has_similar = FALSE;
|
|
|
|
|
|
2008-04-08 01:34:37 -07:00
|
|
|
/* ignore image intermediate targets */
|
|
|
|
|
if (target->expected_type == CAIRO_SURFACE_TYPE_IMAGE)
|
2007-10-19 22:26:28 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (getenv ("CAIRO_TEST_IGNORE_SIMILAR"))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
surface = (target->create_surface) (test->name,
|
|
|
|
|
target->content,
|
|
|
|
|
test->width,
|
|
|
|
|
test->height,
|
|
|
|
|
CAIRO_BOILERPLATE_MODE_TEST,
|
|
|
|
|
&target->closure);
|
|
|
|
|
if (surface != NULL) {
|
|
|
|
|
cairo_t * cr = cairo_create (surface);
|
|
|
|
|
cairo_surface_t *similar;
|
2008-04-11 11:36:24 +01:00
|
|
|
cairo_push_group_with_content (cr, cairo_boilerplate_content (target->content));
|
2007-12-20 18:15:48 +00:00
|
|
|
similar = cairo_get_group_target (cr);
|
2007-10-19 22:26:28 +01:00
|
|
|
has_similar = cairo_surface_get_type (similar) == cairo_surface_get_type (surface);
|
|
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
|
|
if (target->cleanup)
|
|
|
|
|
target->cleanup (target->closure);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return has_similar;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-27 13:33:25 +00:00
|
|
|
static cairo_test_status_t
|
2006-09-09 14:55:57 -07:00
|
|
|
cairo_test_for_target (cairo_test_t *test,
|
|
|
|
|
cairo_boilerplate_target_t *target,
|
2007-10-19 22:26:28 +01:00
|
|
|
int dev_offset,
|
2008-04-08 01:34:37 -07:00
|
|
|
cairo_bool_t similar)
|
2004-10-26 14:38:43 +00:00
|
|
|
{
|
2005-03-09 13:58:20 +00:00
|
|
|
cairo_test_status_t status;
|
2007-04-19 20:36:14 -04:00
|
|
|
cairo_surface_t *surface = NULL;
|
2004-10-26 14:38:43 +00:00
|
|
|
cairo_t *cr;
|
2006-02-15 13:46:52 -08:00
|
|
|
char *png_name, *ref_name, *diff_name, *offset_str;
|
2007-04-19 20:36:14 -04:00
|
|
|
cairo_test_status_t ret = CAIRO_TEST_SUCCESS;
|
2006-05-24 17:05:51 -07:00
|
|
|
cairo_content_t expected_content;
|
2006-07-31 15:17:15 -04:00
|
|
|
cairo_font_options_t *font_options;
|
2006-08-01 20:39:56 -04:00
|
|
|
const char *format;
|
2004-10-26 14:38:43 +00:00
|
|
|
|
2005-03-09 14:34:26 +00:00
|
|
|
/* Get the strings ready that we'll need. */
|
2007-04-18 19:15:16 -04:00
|
|
|
format = cairo_boilerplate_content_name (target->content);
|
2006-05-04 01:45:41 -07:00
|
|
|
if (dev_offset)
|
|
|
|
|
xasprintf (&offset_str, "-%d", dev_offset);
|
|
|
|
|
else
|
|
|
|
|
offset_str = strdup("");
|
|
|
|
|
|
2007-10-19 22:26:28 +01:00
|
|
|
xasprintf (&png_name, "%s-%s-%s%s%s%s",
|
2006-08-01 20:39:56 -04:00
|
|
|
test->name,
|
|
|
|
|
target->name,
|
|
|
|
|
format,
|
2008-04-08 01:34:37 -07:00
|
|
|
similar ? "-similar" : "",
|
2006-08-01 20:39:56 -04:00
|
|
|
offset_str, CAIRO_TEST_PNG_SUFFIX);
|
|
|
|
|
ref_name = cairo_ref_name_for_test_target_format (test->name, target->name, format);
|
2007-10-19 22:26:28 +01:00
|
|
|
xasprintf (&diff_name, "%s-%s-%s%s%s%s",
|
2006-08-01 20:39:56 -04:00
|
|
|
test->name,
|
|
|
|
|
target->name,
|
|
|
|
|
format,
|
2008-04-08 01:34:37 -07:00
|
|
|
similar ? "-similar" : "",
|
2006-08-01 20:39:56 -04:00
|
|
|
offset_str, CAIRO_TEST_DIFF_SUFFIX);
|
2005-03-10 09:22:20 +00:00
|
|
|
|
2007-04-19 20:36:14 -04:00
|
|
|
if (target->is_vector) {
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; vector_ignored_tests[i] != NULL; i++)
|
|
|
|
|
if (strcmp (test->name, vector_ignored_tests[i]) == 0) {
|
|
|
|
|
cairo_test_log ("Error: Skipping for vector target %s\n", target->name);
|
|
|
|
|
ret = CAIRO_TEST_UNTESTED;
|
|
|
|
|
goto UNWIND_STRINGS;
|
|
|
|
|
}
|
2006-02-15 13:46:52 -08:00
|
|
|
}
|
|
|
|
|
|
2007-04-19 20:36:14 -04:00
|
|
|
if (ret == CAIRO_TEST_SUCCESS) {
|
|
|
|
|
/* Run the actual drawing code. */
|
|
|
|
|
|
|
|
|
|
if (test->width && test->height) {
|
|
|
|
|
test->width += dev_offset;
|
|
|
|
|
test->height += dev_offset;
|
|
|
|
|
}
|
2006-02-15 13:46:52 -08:00
|
|
|
|
2007-04-19 20:36:14 -04:00
|
|
|
surface = (target->create_surface) (test->name,
|
|
|
|
|
target->content,
|
|
|
|
|
test->width,
|
|
|
|
|
test->height,
|
|
|
|
|
CAIRO_BOILERPLATE_MODE_TEST,
|
|
|
|
|
&target->closure);
|
|
|
|
|
|
|
|
|
|
if (test->width && test->height) {
|
|
|
|
|
test->width -= dev_offset;
|
|
|
|
|
test->height -= dev_offset;;
|
|
|
|
|
}
|
2006-02-15 13:46:52 -08:00
|
|
|
}
|
|
|
|
|
|
2005-05-06 13:23:41 +00:00
|
|
|
if (surface == NULL) {
|
2005-05-10 20:25:38 +00:00
|
|
|
cairo_test_log ("Error: Failed to set %s target\n", target->name);
|
2005-07-14 12:20:42 +00:00
|
|
|
ret = CAIRO_TEST_UNTESTED;
|
2005-07-14 11:11:15 +00:00
|
|
|
goto UNWIND_STRINGS;
|
2005-04-27 13:33:25 +00:00
|
|
|
}
|
2004-10-26 14:38:43 +00:00
|
|
|
|
2006-05-24 17:05:51 -07:00
|
|
|
/* Check that we created a surface of the expected type. */
|
2006-02-28 00:55:27 -08:00
|
|
|
if (cairo_surface_get_type (surface) != target->expected_type) {
|
|
|
|
|
cairo_test_log ("Error: Created surface is of type %d (expected %d)\n",
|
|
|
|
|
cairo_surface_get_type (surface), target->expected_type);
|
|
|
|
|
ret = CAIRO_TEST_FAILURE;
|
|
|
|
|
goto UNWIND_SURFACE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-24 17:05:51 -07:00
|
|
|
/* Check that we created a surface of the expected content,
|
2008-04-14 20:11:44 +01:00
|
|
|
* (ignore the artificial CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED value).
|
2006-05-24 17:05:51 -07:00
|
|
|
*/
|
2008-04-11 11:36:24 +01:00
|
|
|
expected_content = cairo_boilerplate_content (target->content);
|
2006-05-24 17:05:51 -07:00
|
|
|
|
|
|
|
|
if (cairo_surface_get_content (surface) != expected_content) {
|
|
|
|
|
cairo_test_log ("Error: Created surface has content %d (expected %d)\n",
|
|
|
|
|
cairo_surface_get_content (surface), expected_content);
|
|
|
|
|
ret = CAIRO_TEST_FAILURE;
|
|
|
|
|
goto UNWIND_SURFACE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-15 13:46:52 -08:00
|
|
|
cairo_surface_set_device_offset (surface, dev_offset, dev_offset);
|
|
|
|
|
|
2005-05-06 13:23:41 +00:00
|
|
|
cr = cairo_create (surface);
|
2008-04-08 01:34:37 -07:00
|
|
|
if (similar)
|
2008-04-11 11:36:24 +01:00
|
|
|
cairo_push_group_with_content (cr, expected_content);
|
2005-05-06 13:23:41 +00:00
|
|
|
|
Big change to the test infrastructure and supporting internals. The goal now is to test both a COLOR_ALPHA and a COLOR content for each surface backend, (since the semantics are different and we probably need to support both in each backend.
The PS/PDF backends don't allow a content to be passed in right now, so they fail against the rgb24 tests, but the trivial addition to the constructors will allow them to pass all tests with both content values.
And new constructors (currently internal only) to create an image surface with a cairo_content_t rather than a cairo_format_t.
Add a cairo_content_t argument to the constructor.
Add a cairo_content_t to the constructor and use this content value when constructing intermediate image surfaces in acquire_source, show_page, copy_page, and snapshot.
Add image flattening by compositing over white, as is done in cairo-ps-surface.c.
Track changes to cairo-paginates-surface which now requires a cairo_content_t value (no change to public PS/PDF constructors yet).
Track change in meta-surface and paginated-surface interfaces by now accepting a cairo_content_t rather than a cairo_format_t.
Ignore new output files (argb32 from pdf and ps as well as rgb24 from test-fallback, test-meta, and test-paginated).
Add new utility for flattening PNG images in order to generate the -argbf-ref.png images.
Add image_diff_flattened for comparing flattened output from PS and PDF backend with ARGB reference images by first blending the reference images over white.
Get rid of conditional, format-specific background-color initialization before running tests. Now uses ARGB(0,0,0,0) in all cases. Switch from specifying tests with a format value to specifying tests with a content value. Add support for a 'fake' COLOR_ALPHA_FLATTENED content for testing the PS and PDF output against a flattened version of the argb32 reference images (first blended over white).
Track change in cairo_ps_surface_create (now requires cairo_content_t value).
Adjust tests that draw in default (black) to first paint white so that the results are visible.
Adjust ARGB32 reference images for new white background for changed tests.
Adjust RGB24 reference images for new black background due to changed initialization (and the tests themselves being unchanged).
2006-01-17 16:59:08 +00:00
|
|
|
/* Clear to transparent (or black) depending on whether the target
|
|
|
|
|
* surface supports alpha. */
|
2006-04-06 08:54:59 -07:00
|
|
|
cairo_save (cr);
|
2006-04-06 09:43:39 -07:00
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
|
2006-04-06 08:54:59 -07:00
|
|
|
cairo_paint (cr);
|
|
|
|
|
cairo_restore (cr);
|
2004-10-26 14:38:43 +00:00
|
|
|
|
2006-07-31 15:17:15 -04:00
|
|
|
/* Set all components of font_options to avoid backend differences
|
|
|
|
|
* and reduce number of needed reference images. */
|
|
|
|
|
font_options = cairo_font_options_create ();
|
|
|
|
|
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
|
|
|
|
|
cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_ON);
|
|
|
|
|
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
|
|
|
|
|
cairo_set_font_options (cr, font_options);
|
|
|
|
|
cairo_font_options_destroy (font_options);
|
|
|
|
|
|
2007-12-20 17:49:06 +00:00
|
|
|
cairo_save (cr);
|
2006-07-11 22:19:39 -04:00
|
|
|
status = (test->draw) (cr, test->width, test->height);
|
2007-12-20 17:49:06 +00:00
|
|
|
cairo_restore (cr);
|
2005-03-09 14:34:26 +00:00
|
|
|
|
|
|
|
|
/* Then, check all the different ways it could fail. */
|
2005-03-09 13:58:20 +00:00
|
|
|
if (status) {
|
2005-05-10 20:25:38 +00:00
|
|
|
cairo_test_log ("Error: Function under test failed\n");
|
2005-07-14 11:11:15 +00:00
|
|
|
ret = status;
|
|
|
|
|
goto UNWIND_CAIRO;
|
2005-03-09 13:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-19 22:26:28 +01:00
|
|
|
if (similar) {
|
|
|
|
|
cairo_pop_group_to_source (cr);
|
2007-12-20 17:11:03 +00:00
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
2007-10-19 22:26:28 +01:00
|
|
|
cairo_paint (cr);
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-09 13:58:20 +00:00
|
|
|
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
|
2005-06-15 10:56:31 +00:00
|
|
|
cairo_test_log ("Error: Function under test left cairo status in an error state: %s\n",
|
2005-06-15 10:58:52 +00:00
|
|
|
cairo_status_to_string (cairo_status (cr)));
|
2005-07-14 11:11:15 +00:00
|
|
|
ret = CAIRO_TEST_FAILURE;
|
|
|
|
|
goto UNWIND_CAIRO;
|
2005-03-09 13:58:20 +00:00
|
|
|
}
|
2004-10-26 14:38:43 +00:00
|
|
|
|
2004-11-23 12:53:46 +00:00
|
|
|
/* Skip image check for tests with no image (width,height == 0,0) */
|
2005-07-14 11:11:15 +00:00
|
|
|
if (test->width != 0 && test->height != 0) {
|
2006-08-31 04:01:10 -07:00
|
|
|
buffer_diff_result_t result;
|
|
|
|
|
cairo_status_t diff_status;
|
2006-04-04 11:17:25 -07:00
|
|
|
xunlink (png_name);
|
2005-09-29 14:31:08 +00:00
|
|
|
(target->write_to_png) (surface, png_name);
|
2006-08-10 14:58:33 -04:00
|
|
|
|
2007-11-10 01:33:47 +00:00
|
|
|
cairo_test_log ("OUTPUT: %s\n", png_name);
|
2006-08-10 14:58:33 -04:00
|
|
|
if (!ref_name) {
|
|
|
|
|
cairo_test_log ("Error: Cannot find reference image for %s/%s-%s-%s%s\n",srcdir,
|
|
|
|
|
test->name,
|
|
|
|
|
target->name,
|
|
|
|
|
format,
|
|
|
|
|
CAIRO_TEST_REF_SUFFIX);
|
|
|
|
|
ret = CAIRO_TEST_FAILURE;
|
|
|
|
|
goto UNWIND_CAIRO;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-10 01:33:47 +00:00
|
|
|
cairo_test_log ("REFERENCE: %s\n", ref_name);
|
|
|
|
|
cairo_test_log ("DIFFERENCE: %s\n", diff_name);
|
2006-12-14 04:17:07 -08:00
|
|
|
|
2006-08-31 04:01:10 -07:00
|
|
|
if (target->content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED) {
|
|
|
|
|
diff_status= image_diff_flattened (png_name, ref_name, diff_name,
|
|
|
|
|
dev_offset, dev_offset, 0, 0, &result);
|
|
|
|
|
} else {
|
|
|
|
|
diff_status = image_diff (png_name, ref_name, diff_name,
|
|
|
|
|
dev_offset, dev_offset, 0, 0, &result);
|
|
|
|
|
}
|
|
|
|
|
if (diff_status) {
|
|
|
|
|
cairo_test_log ("Error: Failed to compare images: %s\n",
|
|
|
|
|
cairo_status_to_string (diff_status));
|
2005-07-14 11:11:15 +00:00
|
|
|
ret = CAIRO_TEST_FAILURE;
|
|
|
|
|
goto UNWIND_CAIRO;
|
|
|
|
|
}
|
2006-12-14 04:17:07 -08:00
|
|
|
if (result.pixels_changed && result.max_diff > target->error_tolerance) {
|
|
|
|
|
ret = CAIRO_TEST_FAILURE;
|
|
|
|
|
goto UNWIND_CAIRO;
|
2006-08-31 04:01:10 -07:00
|
|
|
}
|
2004-11-23 12:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
2005-07-14 11:11:15 +00:00
|
|
|
UNWIND_CAIRO:
|
2005-04-04 09:47:12 +00:00
|
|
|
cairo_destroy (cr);
|
2006-02-28 00:55:27 -08:00
|
|
|
UNWIND_SURFACE:
|
2005-05-06 13:23:41 +00:00
|
|
|
cairo_surface_destroy (surface);
|
2005-08-01 13:33:47 +00:00
|
|
|
|
|
|
|
|
cairo_debug_reset_static_data ();
|
|
|
|
|
|
2006-09-09 14:55:57 -07:00
|
|
|
if (target->cleanup)
|
|
|
|
|
target->cleanup (target->closure);
|
2005-03-08 13:44:14 +00:00
|
|
|
|
2005-07-14 11:11:15 +00:00
|
|
|
UNWIND_STRINGS:
|
2006-08-10 14:58:33 -04:00
|
|
|
if (png_name)
|
|
|
|
|
free (png_name);
|
|
|
|
|
if (ref_name)
|
|
|
|
|
free (ref_name);
|
|
|
|
|
if (diff_name)
|
|
|
|
|
free (diff_name);
|
|
|
|
|
if (offset_str)
|
|
|
|
|
free (offset_str);
|
2004-10-26 14:38:43 +00:00
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2005-01-26 13:41:55 +00:00
|
|
|
|
2006-08-17 22:02:02 -04:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
2006-06-30 22:01:24 +02:00
|
|
|
static void
|
|
|
|
|
segfault_handler (int signal)
|
|
|
|
|
{
|
|
|
|
|
longjmp (jmpbuf, signal);
|
|
|
|
|
}
|
2006-08-17 22:02:02 -04:00
|
|
|
#endif
|
2006-06-30 22:01:24 +02:00
|
|
|
|
2005-04-27 13:33:25 +00:00
|
|
|
static cairo_test_status_t
|
2006-07-11 22:19:39 -04:00
|
|
|
cairo_test_expecting (cairo_test_t *test,
|
2005-07-14 12:50:28 +00:00
|
|
|
cairo_test_status_t expectation)
|
2005-04-27 13:33:25 +00:00
|
|
|
{
|
2006-07-11 22:19:39 -04:00
|
|
|
/* we use volatile here to make sure values are not clobbered
|
|
|
|
|
* by longjmp */
|
2008-04-08 01:34:37 -07:00
|
|
|
volatile size_t i, j, num_targets, similar, has_similar;
|
2006-07-13 15:21:02 -07:00
|
|
|
volatile cairo_bool_t limited_targets = FALSE, print_fail_on_stdout = TRUE;
|
2006-08-17 22:02:02 -04:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
2006-07-05 04:22:32 +02:00
|
|
|
void (*old_segfault_handler)(int);
|
2006-08-17 22:02:02 -04:00
|
|
|
#endif
|
2006-07-11 22:19:39 -04:00
|
|
|
volatile cairo_test_status_t status, ret;
|
2006-09-09 14:55:57 -07:00
|
|
|
cairo_boilerplate_target_t ** volatile targets_to_test;
|
2005-04-27 13:33:25 +00:00
|
|
|
|
2006-06-30 22:01:24 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2006-07-11 22:19:39 -04:00
|
|
|
if (isatty (2)) {
|
2006-06-30 22:01:24 +02:00
|
|
|
fail_face = "\033[41m\033[37m\033[1m";
|
|
|
|
|
normal_face = "\033[m";
|
2006-07-13 13:22:49 -04:00
|
|
|
if (isatty (1))
|
2006-07-13 15:21:02 -07:00
|
|
|
print_fail_on_stdout = FALSE;
|
2006-06-30 22:01:24 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
srcdir = getenv ("srcdir");
|
|
|
|
|
if (!srcdir)
|
|
|
|
|
srcdir = ".";
|
2007-11-10 01:34:03 +00:00
|
|
|
refdir = getenv ("CAIRO_REF_DIR");
|
2006-06-30 22:01:24 +02:00
|
|
|
|
2006-07-11 22:19:39 -04:00
|
|
|
cairo_test_init (test->name);
|
|
|
|
|
printf ("%s\n", test->description);
|
|
|
|
|
|
|
|
|
|
if (expectation == CAIRO_TEST_FAILURE)
|
|
|
|
|
printf ("Expecting failure\n");
|
|
|
|
|
|
2007-04-18 19:46:30 -04:00
|
|
|
{
|
|
|
|
|
int tmp_num_targets;
|
|
|
|
|
cairo_bool_t tmp_limited_targets;
|
|
|
|
|
targets_to_test = cairo_boilerplate_get_targets (&tmp_num_targets, &tmp_limited_targets);
|
|
|
|
|
num_targets = tmp_num_targets;
|
|
|
|
|
limited_targets = tmp_limited_targets;
|
2005-12-12 11:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
2005-07-14 12:20:42 +00:00
|
|
|
/* The intended logic here is that we return overall SUCCESS
|
2005-07-14 12:25:41 +00:00
|
|
|
* iff. there is at least one tested backend and that all tested
|
2007-03-13 16:51:34 -04:00
|
|
|
* backends return SUCCESS, OR, there's backends were manually
|
|
|
|
|
* limited, and none were tested.
|
2006-07-06 13:48:18 -04:00
|
|
|
* In other words:
|
2005-07-14 12:20:42 +00:00
|
|
|
*
|
2007-03-13 16:51:34 -04:00
|
|
|
* if backends limited and no backend tested
|
2006-07-06 13:48:18 -04:00
|
|
|
* -> SUCCESS
|
|
|
|
|
* else if any backend not SUCCESS
|
2005-07-14 12:20:42 +00:00
|
|
|
* -> FAILURE
|
|
|
|
|
* else if all backends UNTESTED
|
|
|
|
|
* -> FAILURE
|
|
|
|
|
* else (== some backend SUCCESS)
|
|
|
|
|
* -> SUCCESS
|
2007-05-08 14:18:42 -04:00
|
|
|
*
|
|
|
|
|
* Also, on a crash, run no further tests.
|
2005-07-14 12:20:42 +00:00
|
|
|
*/
|
2007-05-08 14:18:42 -04:00
|
|
|
status = ret = CAIRO_TEST_UNTESTED;
|
2007-10-19 22:26:28 +01:00
|
|
|
for (i = 0; i < num_targets; i++) {
|
2006-02-15 13:46:52 -08:00
|
|
|
for (j = 0; j < NUM_DEVICE_OFFSETS; j++) {
|
2008-04-08 01:34:37 -07:00
|
|
|
cairo_boilerplate_target_t * volatile target = targets_to_test[i];
|
2006-07-11 22:19:39 -04:00
|
|
|
volatile int dev_offset = j * 25;
|
2008-04-08 01:34:37 -07:00
|
|
|
has_similar = cairo_test_target_has_similar (test, target);
|
|
|
|
|
for (similar = 0; similar <= has_similar ; similar++) {
|
|
|
|
|
cairo_test_log ("Testing %s with %s%s target (dev offset %d)\n", test->name, similar ? " (similar)" : "", target->name, dev_offset);
|
|
|
|
|
printf ("%s-%s-%s [%d]%s:\t", test->name, target->name,
|
2007-10-19 22:26:28 +01:00
|
|
|
cairo_boilerplate_content_name (target->content),
|
|
|
|
|
dev_offset,
|
2008-04-08 01:34:37 -07:00
|
|
|
similar ? " (similar)": "");
|
2006-02-15 13:46:52 -08:00
|
|
|
|
2006-08-17 22:02:02 -04:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
2007-10-19 22:26:28 +01:00
|
|
|
/* Set up a checkpoint to get back to in case of segfaults. */
|
|
|
|
|
old_segfault_handler = signal (SIGSEGV, segfault_handler);
|
|
|
|
|
if (0 == setjmp (jmpbuf))
|
2006-08-17 22:02:02 -04:00
|
|
|
#endif
|
2007-10-19 22:26:28 +01:00
|
|
|
status = cairo_test_for_target (test, target, dev_offset, similar);
|
2006-08-17 22:02:02 -04:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
2007-10-19 22:26:28 +01:00
|
|
|
else
|
|
|
|
|
status = CAIRO_TEST_CRASHED;
|
|
|
|
|
signal (SIGSEGV, old_segfault_handler);
|
2006-08-17 22:02:02 -04:00
|
|
|
#endif
|
2006-02-15 13:46:52 -08:00
|
|
|
|
2007-10-19 22:26:28 +01:00
|
|
|
cairo_test_log ("TEST: %s TARGET: %s FORMAT: %s OFFSET: %d SIMILAR: %d RESULT: ",
|
|
|
|
|
test->name, target->name,
|
|
|
|
|
cairo_boilerplate_content_name (target->content),
|
|
|
|
|
dev_offset, similar);
|
|
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
case CAIRO_TEST_SUCCESS:
|
|
|
|
|
printf ("PASS\n");
|
|
|
|
|
cairo_test_log ("PASS\n");
|
|
|
|
|
if (ret == CAIRO_TEST_UNTESTED)
|
|
|
|
|
ret = CAIRO_TEST_SUCCESS;
|
|
|
|
|
break;
|
|
|
|
|
case CAIRO_TEST_UNTESTED:
|
|
|
|
|
printf ("UNTESTED\n");
|
|
|
|
|
cairo_test_log ("UNTESTED\n");
|
|
|
|
|
break;
|
|
|
|
|
case CAIRO_TEST_CRASHED:
|
2006-07-13 15:21:02 -07:00
|
|
|
if (print_fail_on_stdout) {
|
2007-10-19 22:26:28 +01:00
|
|
|
printf ("!!!CRASHED!!!\n");
|
2006-07-13 15:21:02 -07:00
|
|
|
} else {
|
2006-07-13 18:17:39 -04:00
|
|
|
/* eat the test name */
|
|
|
|
|
printf ("\r");
|
2006-07-14 20:06:34 -04:00
|
|
|
fflush (stdout);
|
2006-07-13 15:21:02 -07:00
|
|
|
}
|
2007-10-19 22:26:28 +01:00
|
|
|
cairo_test_log ("CRASHED\n");
|
|
|
|
|
fprintf (stderr, "%s-%s-%s [%d]%s:\t%s!!!CRASHED!!!%s\n",
|
2006-07-11 22:19:39 -04:00
|
|
|
test->name, target->name,
|
2008-04-08 01:34:37 -07:00
|
|
|
cairo_boilerplate_content_name (target->content), dev_offset, similar ? " (similar)" : "",
|
2006-07-11 22:19:39 -04:00
|
|
|
fail_face, normal_face);
|
2007-10-19 22:26:28 +01:00
|
|
|
ret = CAIRO_TEST_FAILURE;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
case CAIRO_TEST_FAILURE:
|
|
|
|
|
if (expectation == CAIRO_TEST_FAILURE) {
|
|
|
|
|
printf ("XFAIL\n");
|
|
|
|
|
cairo_test_log ("XFAIL\n");
|
|
|
|
|
} else {
|
|
|
|
|
if (print_fail_on_stdout) {
|
|
|
|
|
printf ("FAIL\n");
|
|
|
|
|
} else {
|
|
|
|
|
/* eat the test name */
|
|
|
|
|
printf ("\r");
|
|
|
|
|
fflush (stdout);
|
|
|
|
|
}
|
|
|
|
|
fprintf (stderr, "%s-%s-%s [%d]%s:\t%sFAIL%s\n",
|
|
|
|
|
test->name, target->name,
|
2008-04-08 01:34:37 -07:00
|
|
|
cairo_boilerplate_content_name (target->content), dev_offset, similar ? " (similar)" : "",
|
2007-10-19 22:26:28 +01:00
|
|
|
fail_face, normal_face);
|
|
|
|
|
cairo_test_log ("FAIL\n");
|
|
|
|
|
}
|
|
|
|
|
ret = status;
|
|
|
|
|
break;
|
2006-02-15 13:46:52 -08:00
|
|
|
}
|
2007-10-19 22:26:28 +01:00
|
|
|
|
|
|
|
|
if (status == CAIRO_TEST_CRASHED)
|
|
|
|
|
goto out;
|
2005-12-12 11:56:40 +00:00
|
|
|
}
|
2005-04-27 13:33:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-10-19 22:26:28 +01:00
|
|
|
out:
|
2006-07-11 22:19:39 -04:00
|
|
|
|
2006-08-10 15:11:46 -04:00
|
|
|
if (ret != CAIRO_TEST_SUCCESS)
|
|
|
|
|
printf ("Check %s%s out for more information.\n", test->name, CAIRO_TEST_LOG_SUFFIX);
|
|
|
|
|
|
2007-03-13 16:51:34 -04:00
|
|
|
/* if the set of targets to test was limited using CAIRO_TEST_TARGET, we
|
|
|
|
|
* behave slightly differently, to ensure that limiting the targets does
|
|
|
|
|
* not increase the number of tests failing. */
|
|
|
|
|
if (limited_targets) {
|
|
|
|
|
|
|
|
|
|
/* if all untested, success */
|
|
|
|
|
if (ret == CAIRO_TEST_UNTESTED) {
|
|
|
|
|
printf ("None of the tested backends passed, but tested targets are manually limited.\n"
|
|
|
|
|
"Passing the test, to not fail the suite.\n");
|
|
|
|
|
ret = CAIRO_TEST_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if all passed, but expecting failure, return failure to not
|
|
|
|
|
* trigger an XPASS failure */
|
|
|
|
|
if (expectation == CAIRO_TEST_FAILURE && ret == CAIRO_TEST_SUCCESS) {
|
|
|
|
|
printf ("All tested backends passed, but tested targets are manually limited\n"
|
|
|
|
|
"and the test suite expects this test to fail for at least one target.\n"
|
|
|
|
|
"Intentionally failing the test, to not fail the suite.\n");
|
|
|
|
|
ret = CAIRO_TEST_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
if (ret == CAIRO_TEST_UNTESTED)
|
|
|
|
|
ret = CAIRO_TEST_FAILURE;
|
|
|
|
|
|
2006-07-11 22:19:39 -04:00
|
|
|
}
|
|
|
|
|
|
2007-03-02 11:31:13 -08:00
|
|
|
cairo_test_fini ();
|
2005-04-27 13:33:25 +00:00
|
|
|
|
2007-04-18 19:46:30 -04:00
|
|
|
cairo_boilerplate_free_targets (targets_to_test);
|
2005-12-12 11:56:40 +00:00
|
|
|
|
2005-04-27 13:33:25 +00:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_test_status_t
|
2006-07-11 22:19:39 -04:00
|
|
|
cairo_test (cairo_test_t *test)
|
2005-04-27 13:33:25 +00:00
|
|
|
{
|
2006-07-11 22:19:39 -04:00
|
|
|
cairo_test_status_t expectation = CAIRO_TEST_SUCCESS;
|
2006-07-13 11:27:05 -04:00
|
|
|
const char *xfails;
|
2005-04-27 13:33:25 +00:00
|
|
|
|
2006-09-09 23:54:40 -07:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
/* We don't want an assert dialog, we want stderr */
|
|
|
|
|
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
|
|
|
|
|
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-07-11 22:19:39 -04:00
|
|
|
if ((xfails = getenv ("CAIRO_XFAIL_TESTS")) != NULL) {
|
|
|
|
|
while (*xfails) {
|
2006-07-13 11:27:05 -04:00
|
|
|
const char *end = strpbrk (xfails, " \t\r\n;:,");
|
2006-07-11 22:19:39 -04:00
|
|
|
if (!end)
|
|
|
|
|
end = xfails + strlen (xfails);
|
|
|
|
|
|
2006-07-13 11:27:05 -04:00
|
|
|
if (0 == strncmp (test->name, xfails, end - xfails) &&
|
|
|
|
|
'\0' == test->name[end - xfails]) {
|
2006-07-11 22:19:39 -04:00
|
|
|
expectation = CAIRO_TEST_FAILURE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-13 11:27:05 -04:00
|
|
|
if (*end)
|
|
|
|
|
end++;
|
2006-07-11 22:19:39 -04:00
|
|
|
xfails = end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cairo_test_expecting (test, expectation);
|
2005-04-27 13:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
2005-07-18 08:04:16 +00:00
|
|
|
cairo_surface_t *
|
|
|
|
|
cairo_test_create_surface_from_png (const char *filename)
|
2005-01-26 13:41:55 +00:00
|
|
|
{
|
|
|
|
|
cairo_surface_t *image;
|
2005-03-08 19:25:39 +00:00
|
|
|
char *srcdir = getenv ("srcdir");
|
2005-01-26 13:41:55 +00:00
|
|
|
|
2005-07-14 16:18:39 +00:00
|
|
|
image = cairo_image_surface_create_from_png (filename);
|
2006-06-06 15:41:31 -07:00
|
|
|
if (cairo_surface_status(image)) {
|
2006-06-06 15:35:48 -07:00
|
|
|
/* expect not found when running with srcdir != builddir
|
2005-07-28 11:22:36 +00:00
|
|
|
* such as when 'make distcheck' is run
|
|
|
|
|
*/
|
2005-03-08 19:25:39 +00:00
|
|
|
if (srcdir) {
|
|
|
|
|
char *srcdir_filename;
|
|
|
|
|
xasprintf (&srcdir_filename, "%s/%s", srcdir, filename);
|
2005-07-14 16:18:39 +00:00
|
|
|
image = cairo_image_surface_create_from_png (srcdir_filename);
|
2005-03-08 19:25:39 +00:00
|
|
|
free (srcdir_filename);
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-01-26 13:41:55 +00:00
|
|
|
|
2005-07-18 08:04:16 +00:00
|
|
|
return image;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_pattern_t *
|
|
|
|
|
cairo_test_create_pattern_from_png (const char *filename)
|
|
|
|
|
{
|
|
|
|
|
cairo_surface_t *image;
|
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
|
|
|
|
|
|
image = cairo_test_create_surface_from_png (filename);
|
|
|
|
|
|
2005-01-26 13:41:55 +00:00
|
|
|
pattern = cairo_pattern_create_for_surface (image);
|
2005-07-14 16:18:39 +00:00
|
|
|
|
2005-05-06 13:32:53 +00:00
|
|
|
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
|
2005-01-26 13:41:55 +00:00
|
|
|
|
2005-07-14 16:18:39 +00:00
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
|
2005-01-26 13:41:55 +00:00
|
|
|
return pattern;
|
|
|
|
|
}
|
2006-04-25 01:56:51 -07:00
|
|
|
|
|
|
|
|
static cairo_status_t
|
|
|
|
|
_draw_check (cairo_surface_t *surface, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
cairo_t *cr;
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
cairo_set_source_rgb (cr, 0.75, 0.75, 0.75); /* light gray */
|
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
|
|
cairo_set_source_rgb (cr, 0.25, 0.25, 0.25); /* dark gray */
|
|
|
|
|
cairo_rectangle (cr, width / 2, 0, width / 2, height / 2);
|
|
|
|
|
cairo_rectangle (cr, 0, height / 2, width / 2, height / 2);
|
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
|
|
status = cairo_status (cr);
|
|
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_status_t
|
|
|
|
|
cairo_test_paint_checkered (cairo_t *cr)
|
|
|
|
|
{
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
cairo_surface_t *check;
|
|
|
|
|
|
|
|
|
|
check = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 12, 12);
|
|
|
|
|
status = _draw_check (check, 12, 12);
|
2007-05-08 14:01:00 +01:00
|
|
|
if (status) {
|
|
|
|
|
cairo_surface_destroy (check);
|
2006-04-25 01:56:51 -07:00
|
|
|
return status;
|
2007-05-08 14:01:00 +01:00
|
|
|
}
|
2006-04-25 01:56:51 -07:00
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
cairo_set_source_surface (cr, check, 0, 0);
|
|
|
|
|
cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
|
|
|
|
|
cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
|
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
|
|
|
|
|
|
cairo_surface_destroy (check);
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|