[test] Preparatory work for running under memfault.

In order to run under memfault, the framework is first extended to handle
running concurrent tests - i.e. multi-threading. (Not that this is a
requirement for memfault, instead it shares a common goal of storing
per-test data).  To that end all the global data is moved into a per-test
context and the targets are adjusted to avoid overlap on shared, global
resources (such as output files and frame buffers). In order to preserve
the simplicity of the standard draw routines, the context is not passed
explicitly as a parameter to the routines, but is instead attached to the
cairo_t via the user_data.

For the masochist, to enable the tests to be run across multiple threads
simply set the environment variable CAIRO_TEST_NUM_THREADS to the desired
number.

In the long run, we can hope the need for memfault (runtime testing of
error paths) will be mitigated by static analysis. A promising candidate
for this task would appear to be http://hal.cs.berkeley.edu/cil/.
This commit is contained in:
Chris Wilson 2008-08-11 21:12:45 +01:00
parent c73b3e43e1
commit 436c0c8be2
213 changed files with 1730 additions and 1077 deletions

View file

@ -12,7 +12,10 @@ _cairo_boilerplate_beos_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
extern void
@ -23,7 +26,10 @@ _cairo_boilerplate_beos_create_surface_for_bitmap (const char *name
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
extern void

View file

@ -12,7 +12,10 @@ _cairo_boilerplate_directfb_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
extern void

View file

@ -43,7 +43,7 @@ static DFBInfo *init(void) {
DFBDisplayLayerConfig layer_config;
DFBGraphicsDeviceDescription desc;
int err;
DFBInfo *info = calloc(1,sizeof(DFBInfo));
DFBInfo *info = xcalloc(1,sizeof(DFBInfo));
if( !info )
return NULL;
@ -142,7 +142,10 @@ _cairo_boilerplate_directfb_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{

View file

@ -40,9 +40,6 @@
#include "cairo-boilerplate-getopt.h"
static const char* ID = "$Id: getopt.c,v 1.2 2003/10/26 03:10:20 vindaci Exp $";
char* optarg = NULL;
int optind = 0;
int opterr = 1;
@ -57,7 +54,7 @@ static int opt_offset = 0; /* Index into compounded "-option" */
static int dashdash = 0; /* True if "--" option reached */
static int nonopt = 0; /* How many nonopts we've found */
static void increment_index()
static void increment_index(void)
{
/* Move onto the next option */
if(argv_index < argv_index2)
@ -74,7 +71,7 @@ static void increment_index()
* Permutes argv[] so that the argument currently being processed is moved
* to the end.
*/
static int permute_argv_once()
static int permute_argv_once(void)
{
/* Movability check */
if(argv_index + nonopt >= prev_argc) return 1;

View file

@ -37,7 +37,10 @@ _cairo_boilerplate_glitz_glx_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
void
@ -50,7 +53,10 @@ _cairo_boilerplate_glitz_agl_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
void
@ -63,7 +69,10 @@ _cairo_boilerplate_glitz_wgl_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
void

View file

@ -148,6 +148,7 @@ _cairo_boilerplate_glitz_glx_create_surface_internal (glitz_format_name_t form
glitz_drawable_destroy (drawable);
return sr;
DESTROY_DRAWABLE:
glitz_drawable_destroy (drawable);
DESTROY_WINDOW:
@ -162,12 +163,16 @@ _cairo_boilerplate_glitz_glx_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
glitz_glx_target_closure_t *gxtc;
glitz_surface_t * glitz_surface;
cairo_surface_t * surface;
cairo_surface_t * surface = NULL;
cairo_status_t status;
*closure = gxtc = xmalloc (sizeof (glitz_glx_target_closure_t));
@ -204,19 +209,28 @@ _cairo_boilerplate_glitz_glx_create_surface (const char *name,
}
surface = cairo_glitz_surface_create (glitz_surface);
glitz_surface_destroy (glitz_surface);
if (cairo_surface_status (surface))
goto FAIL_CLOSE_DISPLAY;
gxtc->base.width = width;
gxtc->base.height = height;
gxtc->base.content = content;
cairo_surface_set_user_data (surface, &glitz_closure_key,
gxtc, NULL);
status = cairo_boilerplate_surface_set_user_data (surface,
&glitz_closure_key, gxtc, NULL);
if (status == CAIRO_STATUS_SUCCESS)
return surface;
return surface;
cairo_surface_destroy (surface);
surface = cairo_boilerplate_surface_create_in_error (status);
FAIL_CLOSE_DISPLAY:
glitz_glx_fini ();
XCloseDisplay (gxtc->dpy);
FAIL:
return NULL;
free (gxtc);
return surface;
}
void
@ -298,9 +312,10 @@ _cairo_boilerplate_glitz_agl_create_surface_internal (glitz_format_name_t form
DESTROY_DRAWABLE:
glitz_drawable_destroy (gdraw);
return sr;
FAIL:
return sr; /* will be NULL unless we create it and attach */
return NULL;
}
cairo_surface_t *
@ -308,11 +323,14 @@ _cairo_boilerplate_glitz_agl_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
glitz_surface_t *glitz_surface;
cairo_surface_t *surface;
cairo_surface_t *surface = NULL;
glitz_agl_target_closure_t *aglc;
glitz_agl_init ();
@ -335,16 +353,25 @@ _cairo_boilerplate_glitz_agl_create_surface (const char *name,
goto FAIL;
surface = cairo_glitz_surface_create (glitz_surface);
glitz_surface_destroy (glitz_surface);
if (cairo_surface_status (surface))
goto FAIL;
aglc->base.width = width;
aglc->base.height = height;
aglc->base.content = content;
cairo_surface_set_user_data (surface, &glitz_closure_key, aglc, NULL);
status = cairo_boilerplate_surface_set_user_data (surface,
&glitz_closure_key, aglc, NULL);
if (status == CAIRO_STATUS_SUCCESS)
return surface;
return surface;
cairo_surface_destroy (surface);
surface = cairo_boilerplate_surface_create_in_error (status);
FAIL:
return NULL;
glitz_agl_fini ();
return surface;
}
void
@ -428,11 +455,14 @@ _cairo_boilerplate_glitz_wgl_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
glitz_surface_t *glitz_surface;
cairo_surface_t *surface;
cairo_surface_t *surface = NULL;
glitz_wgl_target_closure_t *wglc;
glitz_wgl_init (NULL);
@ -455,16 +485,26 @@ _cairo_boilerplate_glitz_wgl_create_surface (const char *name,
goto FAIL;
surface = cairo_glitz_surface_create (glitz_surface);
glitz_surface_destroy (glitz_surface);
if (cairo_surface_status (surface))
goto FAIL;
wglc->base.width = width;
wglc->base.height = height;
wglc->base.content = content;
cairo_surface_set_user_data (surface, &glitz_closure_key, wglc, NULL);
status = cairo_boilerplate_surface_set_user_data (surface,
&glitz_closure_key, wglc, NULL);
if (status == CAIRO_STATUS_SUCCESS)
return surface;
return surface;
cairo_surface_destroy (surface);
surface = cairo_boilerplate_surface_create_in_error (status);
FAIL:
return NULL;
glitz_wgl_fini ();
free (wglc);
return surface;
}
void

View file

@ -32,7 +32,10 @@ _cairo_boilerplate_pdf_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
void

View file

@ -49,11 +49,15 @@ _cairo_boilerplate_pdf_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
pdf_target_closure_t *ptc;
cairo_surface_t *surface;
cairo_status_t status;
/* Sanitize back to a real cairo_content_t value. */
if (content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED)
@ -64,15 +68,13 @@ _cairo_boilerplate_pdf_create_surface (const char *name,
ptc->width = width;
ptc->height = height;
xasprintf (&ptc->filename, "%s-pdf-%s-out.pdf",
name, cairo_boilerplate_content_name (content));
xasprintf (&ptc->filename, "%s-pdf-%s-%d-out.pdf",
name, cairo_boilerplate_content_name (content), id);
surface = cairo_pdf_surface_create (ptc->filename, width, height);
if (cairo_surface_status (surface)) {
free (ptc->filename);
free (ptc);
return NULL;
}
if (cairo_surface_status (surface))
goto CLEANUP_FILENAME;
cairo_surface_set_fallback_resolution (surface, 72., 72.);
if (content == CAIRO_CONTENT_COLOR) {
@ -80,14 +82,24 @@ _cairo_boilerplate_pdf_create_surface (const char *name,
surface = cairo_surface_create_similar (ptc->target,
CAIRO_CONTENT_COLOR,
width, height);
if (cairo_surface_status (surface))
goto CLEANUP_TARGET;
} else {
ptc->target = NULL;
}
cairo_boilerplate_surface_set_user_data (surface,
&pdf_closure_key,
ptc, NULL);
status = cairo_surface_set_user_data (surface, &pdf_closure_key, ptc, NULL);
if (status == CAIRO_STATUS_SUCCESS)
return surface;
cairo_surface_destroy (surface);
surface = cairo_boilerplate_surface_create_in_error (status);
CLEANUP_TARGET:
cairo_surface_destroy (ptc->target);
CLEANUP_FILENAME:
free (ptc->filename);
free (ptc);
return surface;
}
@ -96,6 +108,7 @@ _cairo_boilerplate_pdf_surface_write_to_png (cairo_surface_t *surface, const cha
{
pdf_target_closure_t *ptc = cairo_surface_get_user_data (surface, &pdf_closure_key);
char command[4096];
cairo_status_t status;
/* Both surface and ptc->target were originally created at the
* same dimensions. We want a 1:1 copy here, so we first clear any
@ -112,13 +125,25 @@ _cairo_boilerplate_pdf_surface_write_to_png (cairo_surface_t *surface, const cha
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
cairo_show_page (cr);
status = cairo_status (cr);
cairo_destroy (cr);
if (status)
return status;
cairo_surface_finish (surface);
status = cairo_surface_status (surface);
if (status)
return status;
surface = ptc->target;
}
cairo_surface_finish (surface);
status = cairo_surface_status (surface);
if (status)
return status;
sprintf (command, "./pdf2png %s %s 1",
ptc->filename, filename);

View file

@ -32,7 +32,10 @@ _cairo_boilerplate_ps_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
void

View file

@ -47,11 +47,15 @@ _cairo_boilerplate_ps_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
ps_target_closure_t *ptc;
cairo_surface_t *surface;
cairo_status_t status;
/* Sanitize back to a real cairo_content_t value. */
if (content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED)
@ -59,18 +63,16 @@ _cairo_boilerplate_ps_create_surface (const char *name,
*closure = ptc = xmalloc (sizeof (ps_target_closure_t));
xasprintf (&ptc->filename, "%s-ps-%s-out.ps",
name, cairo_boilerplate_content_name (content));
xasprintf (&ptc->filename, "%s-ps-%s-%d-out.ps",
name, cairo_boilerplate_content_name (content), id);
ptc->width = width;
ptc->height = height;
surface = cairo_ps_surface_create (ptc->filename, width, height);
if (cairo_surface_status (surface)) {
free (ptc->filename);
free (ptc);
return NULL;
}
if (cairo_surface_status (surface))
goto CLEANUP_FILENAME;
cairo_surface_set_fallback_resolution (surface, 72., 72.);
if (content == CAIRO_CONTENT_COLOR) {
@ -78,22 +80,24 @@ _cairo_boilerplate_ps_create_surface (const char *name,
surface = cairo_surface_create_similar (ptc->target,
CAIRO_CONTENT_COLOR,
width, height);
if (cairo_surface_status (surface))
goto CLEANUP_TARGET;
} else {
ptc->target = NULL;
}
if (cairo_surface_set_user_data (surface,
&ps_closure_key,
ptc,
NULL) != CAIRO_STATUS_SUCCESS) {
cairo_surface_destroy (surface);
if (ptc->target != NULL)
cairo_surface_destroy (ptc->target);
free (ptc->filename);
free (ptc);
return NULL;
}
status = cairo_surface_set_user_data (surface, &ps_closure_key, ptc, NULL);
if (status == CAIRO_STATUS_SUCCESS)
return surface;
cairo_surface_destroy (surface);
surface = cairo_boilerplate_surface_create_in_error (status);
CLEANUP_TARGET:
cairo_surface_destroy (ptc->target);
CLEANUP_FILENAME:
free (ptc->filename);
free (ptc);
return surface;
}
@ -102,6 +106,7 @@ _cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char
{
ps_target_closure_t *ptc = cairo_surface_get_user_data (surface, &ps_closure_key);
char command[4096];
cairo_status_t status;
/* Both surface and ptc->target were originally created at the
* same dimensions. We want a 1:1 copy here, so we first clear any
@ -118,17 +123,30 @@ _cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
cairo_show_page (cr);
status = cairo_status (cr);
cairo_destroy (cr);
if (status)
return status;
cairo_surface_finish (surface);
status = cairo_surface_status (surface);
if (status)
return status;
surface = ptc->target;
}
cairo_surface_finish (surface);
status = cairo_surface_status (surface);
if (status)
return status;
sprintf (command, "gs -q -r72 -g%dx%d -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=%s %s",
ptc->width, ptc->height, filename, ptc->filename);
if (system (command) == 0)
return CAIRO_STATUS_SUCCESS;
return CAIRO_STATUS_WRITE_ERROR;
}

View file

@ -28,12 +28,15 @@
#define _CAIRO_BOILERPLATE_QUARTZ_PRIVATE_H_
cairo_surface_t *
_cairo_boilerplate_quartz_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
_cairo_boilerplate_quartz_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
void **closure);
int id,
void **closure);
void
_cairo_boilerplate_quartz_cleanup (void *closure);

View file

@ -34,7 +34,10 @@ _cairo_boilerplate_quartz_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
cairo_format_t format;

View file

@ -32,7 +32,10 @@ _cairo_boilerplate_svg_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
void

View file

@ -46,26 +46,28 @@ _cairo_boilerplate_svg_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
svg_target_closure_t *ptc;
cairo_surface_t *surface;
cairo_status_t status;
*closure = ptc = xmalloc (sizeof (svg_target_closure_t));
ptc->width = width;
ptc->height = height;
xasprintf (&ptc->filename, "%s-svg-%s-out.svg",
name, cairo_boilerplate_content_name (content));
xasprintf (&ptc->filename, "%s-svg-%s-%d-out.svg",
name, cairo_boilerplate_content_name (content), id);
surface = cairo_svg_surface_create (ptc->filename, width, height);
if (cairo_surface_status (surface)) {
free (ptc->filename);
free (ptc);
return NULL;
}
if (cairo_surface_status (surface))
goto CLEANUP_FILENAME;
cairo_surface_set_fallback_resolution (surface, 72., 72.);
if (content == CAIRO_CONTENT_COLOR) {
@ -73,14 +75,24 @@ _cairo_boilerplate_svg_create_surface (const char *name,
surface = cairo_surface_create_similar (ptc->target,
CAIRO_CONTENT_COLOR,
width, height);
if (cairo_surface_status (surface))
goto CLEANUP_TARGET;
} else {
ptc->target = NULL;
}
cairo_boilerplate_surface_set_user_data (surface,
&svg_closure_key,
ptc, NULL);
status = cairo_surface_set_user_data (surface, &svg_closure_key, ptc, NULL);
if (status == CAIRO_STATUS_SUCCESS)
return surface;
cairo_surface_destroy (surface);
surface = cairo_boilerplate_surface_create_in_error (status);
CLEANUP_TARGET:
cairo_surface_destroy (ptc->target);
CLEANUP_FILENAME:
free (ptc->filename);
free (ptc);
return surface;
}
@ -89,6 +101,7 @@ _cairo_boilerplate_svg_surface_write_to_png (cairo_surface_t *surface, const cha
{
svg_target_closure_t *ptc = cairo_surface_get_user_data (surface, &svg_closure_key);
char command[4096];
cairo_status_t status;
/* Both surface and ptc->target were originally created at the
* same dimensions. We want a 1:1 copy here, so we first clear any
@ -105,13 +118,25 @@ _cairo_boilerplate_svg_surface_write_to_png (cairo_surface_t *surface, const cha
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
cairo_show_page (cr);
status = cairo_status (cr);
cairo_destroy (cr);
if (status)
return status;
cairo_surface_finish (surface);
status = cairo_surface_status (surface);
if (status)
return status;
surface = ptc->target;
}
cairo_surface_finish (surface);
status = cairo_surface_status (surface);
if (status)
return status;
sprintf (command, "./svg2png %s %s",
ptc->filename, filename);

View file

@ -32,7 +32,10 @@ _cairo_boilerplate_test_fallback_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
@ -41,7 +44,10 @@ _cairo_boilerplate_test_meta_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
@ -50,7 +56,10 @@ _cairo_boilerplate_test_paginated_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
cairo_status_t

View file

@ -38,7 +38,10 @@ _cairo_boilerplate_test_fallback_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
*closure = NULL;
@ -50,7 +53,10 @@ _cairo_boilerplate_test_meta_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
*closure = NULL;
@ -72,11 +78,15 @@ _cairo_boilerplate_test_paginated_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
test_paginated_closure_t *tpc;
cairo_surface_t *surface;
cairo_status_t status;
*closure = tpc = xmalloc (sizeof (test_paginated_closure_t));
@ -92,11 +102,21 @@ _cairo_boilerplate_test_paginated_create_surface (const char *name,
tpc->width,
tpc->height,
tpc->stride);
if (cairo_surface_status (surface))
goto CLEANUP;
cairo_boilerplate_surface_set_user_data (surface,
&test_paginated_closure_key,
tpc, NULL);
status = cairo_surface_set_user_data (surface,
&test_paginated_closure_key,
tpc, NULL);
if (status == CAIRO_STATUS_SUCCESS)
return surface;
cairo_surface_destroy (surface);
surface = cairo_boilerplate_surface_create_in_error (status);
CLEANUP:
free (tpc->data);
free (tpc);
return surface;
}
@ -137,16 +157,9 @@ _cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface
tpc->stride);
status = cairo_surface_write_to_png (image, filename);
if (status) {
CAIRO_BOILERPLATE_LOG ("Error writing %s: %s. Exiting\n",
filename,
cairo_status_to_string (status));
exit (1);
}
cairo_surface_destroy (image);
return CAIRO_STATUS_SUCCESS;
return status;
}
void

View file

@ -32,7 +32,10 @@ _cairo_boilerplate_win32_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
cairo_surface_t *

View file

@ -34,7 +34,10 @@ _cairo_boilerplate_win32_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
cairo_format_t format;

View file

@ -32,7 +32,10 @@ _cairo_boilerplate_xcb_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
void

View file

@ -52,12 +52,14 @@ _cairo_boilerplate_xcb_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
xcb_screen_t *root;
xcb_target_closure_t *xtc;
cairo_surface_t *surface;
xcb_connection_t *c;
xcb_render_pictforminfo_t *render_format;
xcb_pict_standard_t format;
@ -97,11 +99,10 @@ _cairo_boilerplate_xcb_create_surface (const char *name,
render_format = xcb_render_util_find_standard_format (xcb_render_util_query_formats (c), format);
if (render_format->id == 0)
return NULL;
surface = cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root,
render_format,
width, height);
return surface;
return cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root,
render_format,
width, height);
}
void

View file

@ -33,7 +33,10 @@ _cairo_boilerplate_xlib_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
#endif
@ -42,7 +45,10 @@ _cairo_boilerplate_xlib_fallback_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
void

View file

@ -190,13 +190,17 @@ _cairo_boilerplate_xlib_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
xlib_target_closure_t *xtc;
Display *dpy;
cairo_surface_t *surface;
*closure = xtc = xmalloc (sizeof (xlib_target_closure_t));
*closure = xtc = xcalloc (1, sizeof (xlib_target_closure_t));
if (width == 0)
width = 1;
@ -205,14 +209,20 @@ _cairo_boilerplate_xlib_create_surface (const char *name,
xtc->dpy = dpy = XOpenDisplay (NULL);
if (xtc->dpy == NULL) {
free (xtc);
CAIRO_BOILERPLATE_LOG ("Failed to open display: %s\n", XDisplayName(0));
return NULL;
}
if (mode == CAIRO_BOILERPLATE_MODE_TEST)
return _cairo_boilerplate_xlib_test_create_surface (dpy, content, width, height, xtc);
surface = _cairo_boilerplate_xlib_test_create_surface (dpy, content, width, height, xtc);
else /* mode == CAIRO_BOILERPLATE_MODE_PERF */
return _cairo_boilerplate_xlib_perf_create_surface (dpy, content, width, height, xtc);
surface = _cairo_boilerplate_xlib_perf_create_surface (dpy, content, width, height, xtc);
if (surface == NULL || cairo_surface_status (surface))
_cairo_boilerplate_xlib_cleanup (xtc);
return surface;
}
#endif
@ -230,12 +240,16 @@ _cairo_boilerplate_xlib_fallback_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
xlib_target_closure_t *xtc;
Display *dpy;
int screen;
Screen *scr;
int screen, x, y;
XSetWindowAttributes attr;
cairo_surface_t *surface;
@ -277,9 +291,25 @@ _cairo_boilerplate_xlib_fallback_create_surface (const char *name,
return NULL;
}
/* tile the windows so threads do not overlap */
scr = XScreenOfDisplay (dpy, screen);
x = y = 0;
if (id-- > 1) do {
x += max_width;
if (x + max_width > WidthOfScreen (scr)) {
x = 0;
y += max_height;
if (y + max_height > HeightOfScreen (scr)) {
XCloseDisplay (dpy);
free (xtc);
return NULL;
}
}
} while (--id);
attr.override_redirect = True;
xtc->drawable = XCreateWindow (dpy, DefaultRootWindow (dpy),
0, 0,
x, y,
width, height, 0,
DefaultDepth (dpy, screen),
InputOutput,
@ -304,10 +334,12 @@ _cairo_boilerplate_xlib_cleanup (void *closure)
{
xlib_target_closure_t *xtc = closure;
if (xtc->drawable_is_pixmap)
XFreePixmap (xtc->dpy, xtc->drawable);
else
XDestroyWindow (xtc->dpy, xtc->drawable);
if (xtc->drawable) {
if (xtc->drawable_is_pixmap)
XFreePixmap (xtc->dpy, xtc->drawable);
else
XDestroyWindow (xtc->dpy, xtc->drawable);
}
XCloseDisplay (xtc->dpy);
free (xtc);
}

View file

@ -118,10 +118,14 @@ _cairo_boilerplate_image_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
cairo_format_t format;
*closure = NULL;
if (content == CAIRO_CONTENT_COLOR_ALPHA) {
@ -448,22 +452,29 @@ cairo_boilerplate_free_targets (cairo_boilerplate_target_t **targets)
free (targets);
}
void
cairo_boilerplate_surface_set_user_data (cairo_surface_t *surface,
const cairo_user_data_key_t *key,
void *user_data,
cairo_destroy_func_t destroy)
cairo_surface_t *
cairo_boilerplate_surface_create_in_error (cairo_status_t status)
{
cairo_status_t status;
cairo_surface_t *surface = NULL;
status = cairo_surface_set_user_data (surface,
key, user_data,
destroy);
if (status) {
CAIRO_BOILERPLATE_LOG ("Error: %s. Exiting\n",
cairo_status_to_string (status));
exit (1);
}
do {
cairo_surface_t *intermediate;
cairo_t *cr;
cairo_path_t path;
intermediate = cairo_image_surface_create (CAIRO_FORMAT_A8, 0, 0);
cr = cairo_create (intermediate);
cairo_surface_destroy (intermediate);
path.status = status;
cairo_append_path (cr, &path);
cairo_surface_destroy (surface);
surface = cairo_get_target (cr);
cairo_destroy (cr);
} while (cairo_surface_status (surface) != status);
return surface;
}
void

View file

@ -114,7 +114,10 @@ typedef cairo_surface_t *
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
typedef cairo_status_t
@ -137,7 +140,6 @@ typedef struct _cairo_boilerplate_target
cairo_boilerplate_cleanup_t cleanup;
cairo_boilerplate_wait_t synchronize;
cairo_bool_t is_vector;
void *closure;
} cairo_boilerplate_target_t;
cairo_boilerplate_target_t **
@ -146,11 +148,8 @@ cairo_boilerplate_get_targets (int *num_targets, cairo_bool_t *limited_targets);
void
cairo_boilerplate_free_targets (cairo_boilerplate_target_t **targets);
void
cairo_boilerplate_surface_set_user_data (cairo_surface_t *surface,
const cairo_user_data_key_t *key,
void *user_data,
cairo_destroy_func_t destroy);
cairo_surface_t *
cairo_boilerplate_surface_create_in_error (cairo_status_t status);
#include "xmalloc.h"

View file

@ -35,8 +35,11 @@ xmalloc (size_t size)
{
void *buf;
if (size == 0)
return NULL;
buf = malloc (size);
if (buf == NULL && size != 0) {
if (buf == NULL) {
CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting.\n");
exit (1);
}
@ -49,8 +52,11 @@ xcalloc (size_t nmemb, size_t size)
{
void *buf;
if (nmemb == 0 || size == 0)
return NULL;
buf = calloc (nmemb, size);
if (buf == NULL && nmemb != 0 && size != 0) {
if (buf == NULL) {
CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting\n");
exit (1);
}

View file

@ -113,7 +113,7 @@ dnl ===========================================================================
AC_CHECK_LIBM
LIBS="$LIBS $LIBM"
AC_CHECK_FUNCS(vasnprintf ctime_r drand48)
AC_CHECK_FUNCS(vasnprintf ctime_r drand48 flockfile)
AC_MSG_CHECKING([for Sun Solaris (non-POSIX ctime_r)])
case "$host" in
@ -731,7 +731,7 @@ AC_CACHE_SAVE
dnl ===========================================================================
dnl Checks for precise integer types
AC_CHECK_HEADERS([stdint.h signal.h inttypes.h sys/int_types.h])
AC_CHECK_HEADERS([stdint.h signal.h setjmp.h inttypes.h sys/int_types.h])
AC_CHECK_TYPES([uint64_t, uint128_t])
dnl ===========================================================================

View file

@ -397,11 +397,15 @@ main (int argc, char *argv[])
perf.size <= perf_case->max_size;
perf.size *= 2)
{
void *closure;
surface = (target->create_surface) (NULL,
target->content,
perf.size, perf.size,
perf.size, perf.size,
CAIRO_BOILERPLATE_MODE_PERF,
&target->closure);
0,
&closure);
if (surface == NULL) {
fprintf (stderr,
"Error: Failed to create target surface: %s\n",
@ -410,8 +414,7 @@ main (int argc, char *argv[])
exit (1);
}
cairo_perf_timer_set_synchronize (target->synchronize,
target->closure);
cairo_perf_timer_set_synchronize (target->synchronize, closure);
perf.cr = cairo_create (surface);
@ -428,7 +431,7 @@ main (int argc, char *argv[])
cairo_surface_destroy (surface);
if (target->cleanup)
target->cleanup (target->closure);
target->cleanup (closure);
}
}
}

View file

@ -886,11 +886,12 @@ EXTRA_PROGRAMS += $(TESTS) $(DISABLED_TESTS)
# and TARGETS make var on the command line. Same for the rest.
TARGETS = $(CAIRO_TEST_TARGET)
TARGETS_EXCLUDE = $(CAIRO_TEST_TARGET_EXCLUDE)
NUM_THREADS = $(CAIRO_TEST_NUM_THREADS)
# Same about ENV vs CAIRO_TEST_ENV. ENV is used with "make run" only
ENV = $(CAIRO_TEST_ENV)
TESTS_ENVIRONMENT = CAIRO_XFAIL_TESTS="$(XFAIL_TESTS:$(EXEEXT)=)" CAIRO_TEST_TARGET="$(TARGETS)" CAIRO_TEST_TARGET_EXCLUDE="$(TARGETS_EXCLUDE)" $(ENV)
TESTS_ENVIRONMENT = CAIRO_XFAIL_TESTS="$(XFAIL_TESTS:$(EXEEXT)=)" CAIRO_TEST_TARGET="$(TARGETS)" CAIRO_TEST_TARGET_EXCLUDE="$(TARGETS_EXCLUDE)" CAIRO_TEST_NUM_THREADS="$(NUM_THREADS)" $(ENV)
EXTRA_VALGRIND_FLAGS = $(CAIRO_EXTRA_VALGRIND_FLAGS)
VALGRIND_FLAGS = \

View file

@ -34,7 +34,7 @@ static cairo_test_draw_function_t draw;
#define WIDTH (PAD + POINTS * 2 + PAD)
#define HEIGHT (WIDTH)
cairo_test_t test = {
static const cairo_test_t test = {
"a1-image-sample",
"Test sample position when drawing images with FILTER_NEAREST",
WIDTH, HEIGHT,

View file

@ -48,7 +48,7 @@ static unsigned char mask[(MASK_WIDTH + 7) / 8 * MASK_HEIGHT] = {
MASK,
};
cairo_test_t test = {
static const cairo_test_t test = {
"a1-mask",
"test masks of CAIRO_FORMAT_A1",
MASK_WIDTH, MASK_HEIGHT,
@ -57,12 +57,15 @@ cairo_test_t test = {
static cairo_test_status_t
check_status (cairo_status_t status, cairo_status_t expected)
check_status (const cairo_test_context_t *ctx,
cairo_status_t status,
cairo_status_t expected)
{
if (status == expected)
return CAIRO_TEST_SUCCESS;
cairo_test_log ("Error: Expected status value %d (%s), received %d (%s)\n",
cairo_test_log (ctx,
"Error: Expected status value %d (%s), received %d (%s)\n",
expected,
cairo_status_to_string (expected),
status,
@ -71,7 +74,8 @@ check_status (cairo_status_t status, cairo_status_t expected)
}
static cairo_test_status_t
test_surface_with_width_and_stride (int width, int stride,
test_surface_with_width_and_stride (const cairo_test_context_t *ctx,
int width, int stride,
cairo_status_t expected)
{
cairo_test_status_t status;
@ -80,7 +84,8 @@ test_surface_with_width_and_stride (int width, int stride,
int len;
unsigned char *data;
cairo_test_log ("Creating surface with width %d and stride %d\n",
cairo_test_log (ctx,
"Creating surface with width %d and stride %d\n",
width, stride);
len = stride;
@ -94,11 +99,11 @@ test_surface_with_width_and_stride (int width, int stride,
cairo_paint (cr);
status = check_status (cairo_surface_status (surface), expected);
status = check_status (ctx, cairo_surface_status (surface), expected);
if (status)
goto BAIL;
status = check_status (cairo_status (cr), expected);
status = check_status (ctx, cairo_status (cr), expected);
if (status)
goto BAIL;
@ -146,9 +151,10 @@ draw (cairo_t *cr, int dst_width, int dst_height)
int
main (void)
{
cairo_test_context_t ctx;
int test_width;
cairo_test_init ("a1-mask");
cairo_test_init (&ctx, "a1-mask");
/* first check the API strictness */
for (test_width = 0; test_width < 40; test_width++) {
@ -164,13 +170,15 @@ main (void)
expected = (stride == test_stride) ?
CAIRO_STATUS_SUCCESS : CAIRO_STATUS_INVALID_STRIDE;
status = test_surface_with_width_and_stride (test_width,
status = test_surface_with_width_and_stride (&ctx,
test_width,
test_stride,
expected);
if (status)
return status;
status = test_surface_with_width_and_stride (test_width,
status = test_surface_with_width_and_stride (&ctx,
test_width,
-test_stride,
expected);
if (status)
@ -180,20 +188,22 @@ main (void)
/* Then create a surface using the correct stride,
* (should always succeed).
*/
status = test_surface_with_width_and_stride (test_width,
status = test_surface_with_width_and_stride (&ctx,
test_width,
stride,
CAIRO_STATUS_SUCCESS);
if (status)
return status;
status = test_surface_with_width_and_stride (test_width,
status = test_surface_with_width_and_stride (&ctx,
test_width,
-stride,
CAIRO_STATUS_SUCCESS);
if (status)
return status;
}
cairo_test_fini ();
cairo_test_fini (&ctx);
return cairo_test (&test);
}

View file

@ -34,7 +34,7 @@ static cairo_test_draw_function_t draw;
#define WIDTH (PAD + POINTS * 2 + PAD)
#define HEIGHT (WIDTH)
cairo_test_t test = {
static const cairo_test_t test = {
"a1-traps-sample",
"Test sample position when drawing trapezoids with ANTIALIAS_NONE",
WIDTH, HEIGHT,

View file

@ -28,7 +28,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"a8-mask",
"test masks of CAIRO_FORMAT_A8",
8, 8,
@ -50,12 +50,15 @@ static unsigned char mask[MASK_WIDTH * MASK_HEIGHT] = {
};
static cairo_test_status_t
check_status (cairo_status_t status, cairo_status_t expected)
check_status (const cairo_test_context_t *ctx,
cairo_status_t status,
cairo_status_t expected)
{
if (status == expected)
return CAIRO_TEST_SUCCESS;
cairo_test_log ("Error: Expected status value %d (%s), received %d (%s)\n",
cairo_test_log (ctx,
"Error: Expected status value %d (%s), received %d (%s)\n",
expected,
cairo_status_to_string (expected),
status,
@ -64,7 +67,8 @@ check_status (cairo_status_t status, cairo_status_t expected)
}
static cairo_test_status_t
test_surface_with_width_and_stride (int width, int stride,
test_surface_with_width_and_stride (const cairo_test_context_t *ctx,
int width, int stride,
cairo_status_t expected)
{
cairo_test_status_t status;
@ -73,7 +77,8 @@ test_surface_with_width_and_stride (int width, int stride,
int len;
unsigned char *data;
cairo_test_log ("Creating surface with width %d and stride %d\n",
cairo_test_log (ctx,
"Creating surface with width %d and stride %d\n",
width, stride);
len = stride;
@ -87,11 +92,11 @@ test_surface_with_width_and_stride (int width, int stride,
cairo_paint (cr);
status = check_status (cairo_surface_status (surface), expected);
status = check_status (ctx, cairo_surface_status (surface), expected);
if (status)
goto BAIL;
status = check_status (cairo_status (cr), expected);
status = check_status (ctx, cairo_status (cr), expected);
if (status)
goto BAIL;
@ -147,9 +152,10 @@ draw (cairo_t *cr, int dst_width, int dst_height)
int
main (void)
{
cairo_test_context_t ctx;
int test_width;
cairo_test_init ("a8-mask");
cairo_test_init (&ctx, "a8-mask");
for (test_width = 0; test_width < 40; test_width++) {
int stride = cairo_format_stride_for_width (CAIRO_FORMAT_A8,
@ -163,13 +169,15 @@ main (void)
expected = (stride == test_width) ?
CAIRO_STATUS_SUCCESS : CAIRO_STATUS_INVALID_STRIDE;
status = test_surface_with_width_and_stride (test_width,
status = test_surface_with_width_and_stride (&ctx,
test_width,
test_width,
expected);
if (status)
return status;
status = test_surface_with_width_and_stride (test_width,
status = test_surface_with_width_and_stride (&ctx,
test_width,
-test_width,
expected);
if (status)
@ -179,20 +187,22 @@ main (void)
/* Then create a surface using the correct stride,
* (should always succeed).
*/
status = test_surface_with_width_and_stride (test_width,
status = test_surface_with_width_and_stride (&ctx,
test_width,
stride,
CAIRO_STATUS_SUCCESS);
if (status)
return status;
status = test_surface_with_width_and_stride (test_width,
status = test_surface_with_width_and_stride (&ctx,
test_width,
-stride,
CAIRO_STATUS_SUCCESS);
if (status)
return status;
}
cairo_test_fini ();
cairo_test_fini (&ctx);
return cairo_test (&test);
}

View file

@ -27,7 +27,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"big-line",
"Test drawing of simple lines with positive and negative coordinates > 2^16\n"
"This currently fails because of 16-bit limitations in pixman.",

View file

@ -60,7 +60,7 @@ static cairo_test_draw_function_t draw;
* will prevent the hiding of internal library symbols.
*/
cairo_test_t test = {
static const cairo_test_t test = {
"big-trap",
"Test oversize trapezoid with a clip region"
"\nTest needs to be adjusted to trigger the original bug",

View file

@ -27,7 +27,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"bilevel-image",
"Test that PS can embed an RGB image with a bilevel alpha channel.",
12, 4,
@ -39,7 +39,7 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
static uint32_t data[] = {
uint32_t data[] = {
RGBx, RGBx, RGBx,
RGBx, RGBx, RGBx,
RGBx, RGBx, RGBx,

View file

@ -38,7 +38,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"bitmap-font",
"Test drawing with a font consisting only of bitmaps",
246 + 1, 2 * TEXT_SIZE,
@ -58,14 +58,14 @@ font_extents_equal (const cairo_font_extents_t *A,
}
static cairo_test_status_t
check_font_extents (cairo_t *cr, const char *comment)
check_font_extents (const cairo_test_context_t *ctx, cairo_t *cr, const char *comment)
{
cairo_font_extents_t font_extents, ref_font_extents = {11, 2, 13, 6, 0};
memset (&font_extents, 0xff, sizeof (cairo_font_extents_t));
cairo_font_extents (cr, &font_extents);
if (! font_extents_equal (&font_extents, &ref_font_extents)) {
cairo_test_log ("Error: %s: cairo_font_extents(); extents (%g, %g, %g, %g, %g)\n",
cairo_test_log (ctx, "Error: %s: cairo_font_extents(); extents (%g, %g, %g, %g, %g)\n",
comment,
font_extents.ascent, font_extents.descent,
font_extents.height,
@ -79,30 +79,27 @@ check_font_extents (cairo_t *cr, const char *comment)
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
FcPattern *pattern;
cairo_font_face_t *font_face;
cairo_font_extents_t font_extents;
cairo_font_options_t *font_options;
cairo_status_t status;
const char *srcdir = getenv ("srcdir");
char *filename;
int face_count;
struct stat stat_buf;
if (! srcdir)
srcdir = ".";
xasprintf (&filename, "%s/%s", srcdir, FONT);
xasprintf (&filename, "%s/%s", ctx->srcdir, FONT);
if (stat (filename, &stat_buf) || ! S_ISREG (stat_buf.st_mode)) {
cairo_test_log ("Error finding font: %s: file not found?\n", filename);
cairo_test_log (ctx, "Error finding font: %s: file not found?\n", filename);
return CAIRO_TEST_FAILURE;
}
pattern = FcFreeTypeQuery ((unsigned char *)filename, 0, NULL, &face_count);
free (filename);
if (! pattern) {
cairo_test_log ("FcFreeTypeQuery failed.\n");
cairo_test_log (ctx, "FcFreeTypeQuery failed.\n");
return CAIRO_TEST_FAILURE;
}
@ -110,14 +107,14 @@ draw (cairo_t *cr, int width, int height)
status = cairo_font_face_status (font_face);
if (status) {
cairo_test_log ("Error creating font face for %s: %s\n",
cairo_test_log (ctx, "Error creating font face for %s: %s\n",
filename,
cairo_status_to_string (status));
return CAIRO_TEST_FAILURE;
}
if (cairo_font_face_get_type (font_face) != CAIRO_FONT_TYPE_FT) {
cairo_test_log ("Unexpected value from cairo_font_face_get_type: %d (expected %d)\n",
cairo_test_log (ctx, "Unexpected value from cairo_font_face_get_type: %d (expected %d)\n",
cairo_font_face_get_type (font_face), CAIRO_FONT_TYPE_FT);
cairo_font_face_destroy (font_face);
return CAIRO_TEST_FAILURE;
@ -125,7 +122,7 @@ draw (cairo_t *cr, int width, int height)
cairo_set_font_face (cr, font_face);
#define CHECK_FONT_EXTENTS(comment) if (check_font_extents (cr, (comment)) != CAIRO_TEST_SUCCESS) return CAIRO_TEST_FAILURE
#define CHECK_FONT_EXTENTS(comment) if (check_font_extents (ctx, cr, (comment)) != CAIRO_TEST_SUCCESS) return CAIRO_TEST_FAILURE
cairo_font_extents (cr, &font_extents);
CHECK_FONT_EXTENTS ("default");

View file

@ -47,12 +47,12 @@
#define PERCEPTUAL_DIFF_THRESHOLD 25
static void
xunlink (const char *pathname)
xunlink (const cairo_test_context_t *ctx, const char *pathname)
{
if (unlink (pathname) < 0 && errno != ENOENT) {
cairo_test_log (" Error: Cannot remove %s: %s\n",
cairo_test_log (ctx, " Error: Cannot remove %s: %s\n",
pathname, strerror (errno));
exit (1);
exit (CAIRO_TEST_FAILURE);
}
}
@ -122,7 +122,8 @@ buffer_diff_core (unsigned char *_buf_a,
}
void
compare_surfaces (cairo_surface_t *surface_a,
compare_surfaces (const cairo_test_context_t *ctx,
cairo_surface_t *surface_a,
cairo_surface_t *surface_b,
cairo_surface_t *surface_diff,
buffer_diff_result_t *result)
@ -150,14 +151,15 @@ compare_surfaces (cairo_surface_t *surface_a,
if (result->pixels_changed == 0)
return;
cairo_test_log ("%d pixels differ (with maximum difference of %d) from reference image\n",
cairo_test_log (ctx,
"%d pixels differ (with maximum difference of %d) from reference image\n",
result->pixels_changed, result->max_diff);
/* Then, if there are any different pixels, we give the pdiff code
* a crack at the images. If it decides that there are no visually
* discernible differences in any pixels, then we accept this
* result as good enough.
*
*
* Only let pdiff have a crack at the comparison if the max difference
* is lower than a threshold, otherwise some problems could be masked.
*/
@ -166,7 +168,8 @@ compare_surfaces (cairo_surface_t *surface_a,
gamma, luminance, field_of_view);
if (discernible_pixels_changed == 0) {
result->pixels_changed = 0;
cairo_test_log ("But perceptual diff finds no visually discernible difference.\n"
cairo_test_log (ctx,
"But perceptual diff finds no visually discernible difference.\n"
"Accepting result.\n");
}
}
@ -208,7 +211,9 @@ stdio_write_func (void *closure, const unsigned char *data, unsigned int length)
* extending from (x,y) to (width,height).
*/
static void
flatten_surface (cairo_surface_t **surface, int x, int y)
flatten_surface (const cairo_test_context_t *ctx,
cairo_surface_t **surface,
int x, int y)
{
cairo_surface_t *flat;
cairo_t *cr;
@ -219,14 +224,17 @@ flatten_surface (cairo_surface_t **surface, int x, int y)
cairo_surface_set_device_offset (flat, -x, -y);
cr = cairo_create (flat);
cairo_surface_destroy (flat);
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_paint (cr);
cairo_set_source_surface (cr, *surface, 0, 0);
cairo_paint (cr);
cairo_destroy (cr);
cairo_set_source_surface (cr, *surface, 0, 0);
cairo_surface_destroy (*surface);
*surface = flat;
cairo_paint (cr);
*surface = cairo_surface_reference (cairo_get_target (cr));
cairo_destroy (cr);
}
/* Given an image surface, create a new surface that has the same
@ -235,7 +243,9 @@ flatten_surface (cairo_surface_t **surface, int x, int y)
* The original surface will be destroyed.
*/
static void
extract_sub_surface (cairo_surface_t **surface, int x, int y)
extract_sub_surface (const cairo_test_context_t *ctx,
cairo_surface_t **surface,
int x, int y)
{
cairo_surface_t *sub;
cairo_t *cr;
@ -250,13 +260,15 @@ extract_sub_surface (cairo_surface_t **surface, int x, int y)
* time, so I'm leaving both here so I can look at both to see
* which I like better. */
cr = cairo_create (sub);
cairo_surface_destroy (sub);
cairo_set_source_surface (cr, *surface, -x, -y);
cairo_surface_destroy (*surface);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_paint (cr);
cairo_destroy (cr);
cairo_surface_destroy (*surface);
*surface = sub;
*surface = cairo_surface_reference (cairo_get_target (cr));
cairo_destroy (cr);
}
/* Image comparison code courtesy of Richard Worth <richard@theworths.org>
@ -275,7 +287,8 @@ extract_sub_surface (cairo_surface_t **surface, int x, int y)
* oh well).
*/
static cairo_status_t
image_diff_core (const char *filename_a,
image_diff_core (const cairo_test_context_t *ctx,
const char *filename_a,
const char *filename_b,
const char *filename_diff,
int ax,
@ -293,7 +306,7 @@ image_diff_core (const char *filename_a,
surface_a = cairo_image_surface_create_from_png (filename_a);
status = cairo_surface_status (surface_a);
if (status) {
cairo_test_log ("Error: Failed to create surface from %s: %s\n",
cairo_test_log (ctx, "Error: Failed to create surface from %s: %s\n",
filename_a, cairo_status_to_string (status));
return status;
}
@ -301,28 +314,45 @@ image_diff_core (const char *filename_a,
surface_b = cairo_image_surface_create_from_png (filename_b);
status = cairo_surface_status (surface_b);
if (status) {
cairo_test_log ("Error: Failed to create surface from %s: %s\n",
cairo_test_log (ctx, "Error: Failed to create surface from %s: %s\n",
filename_b, cairo_status_to_string (status));
cairo_surface_destroy (surface_a);
return status;
}
if (flatten) {
flatten_surface (&surface_a, ax, ay);
flatten_surface (&surface_b, bx, by);
flatten_surface (ctx, &surface_a, ax, ay);
flatten_surface (ctx, &surface_b, bx, by);
ax = ay = bx = by = 0;
}
if (ax || ay) {
extract_sub_surface (&surface_a, ax, ay);
extract_sub_surface (ctx, &surface_a, ax, ay);
ax = ay = 0;
}
if (bx || by) {
extract_sub_surface (&surface_b, bx, by);
extract_sub_surface (ctx, &surface_b, bx, by);
bx = by = 0;
}
status = cairo_surface_status (surface_a);
if (status) {
cairo_test_log (ctx, "Error: Failed to extract surface from %s: %s\n",
filename_a, cairo_status_to_string (status));
cairo_surface_destroy (surface_a);
cairo_surface_destroy (surface_b);
return status;
}
status = cairo_surface_status (surface_b);
if (status) {
cairo_test_log (ctx, "Error: Failed to extract surface from %s: %s\n",
filename_b, cairo_status_to_string (status));
cairo_surface_destroy (surface_a);
cairo_surface_destroy (surface_b);
return status;
}
width_a = cairo_image_surface_get_width (surface_a);
height_a = cairo_image_surface_get_height (surface_a);
stride_a = cairo_image_surface_get_stride (surface_a);
@ -334,7 +364,7 @@ image_diff_core (const char *filename_a,
height_a != height_b ||
stride_a != stride_b)
{
cairo_test_log ("Error: Image size mismatch: (%dx%d) vs. (%dx%d)\n"
cairo_test_log (ctx, "Error: Image size mismatch: (%dx%d) vs. (%dx%d)\n"
" for %s vs. %s\n",
width_a, height_a,
width_b, height_b,
@ -346,25 +376,49 @@ image_diff_core (const char *filename_a,
surface_diff = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
width_a, height_a);
status = cairo_surface_status (surface_diff);
if (status) {
cairo_test_log (ctx, "Error: Failed to allocate surface to hold differences\n");
cairo_surface_destroy (surface_a);
cairo_surface_destroy (surface_b);
return CAIRO_STATUS_NO_MEMORY;
}
compare_surfaces (surface_a, surface_b, surface_diff, result);
compare_surfaces (ctx, surface_a, surface_b, surface_diff, result);
status = CAIRO_STATUS_SUCCESS;
if (result->pixels_changed) {
FILE *png_file;
if (filename_diff)
if (filename_diff) {
png_file = fopen (filename_diff, "wb");
else
if (png_file == NULL) {
int err = errno;
cairo_surface_destroy (surface_a);
cairo_surface_destroy (surface_b);
cairo_surface_destroy (surface_diff);
switch (err) {
case ENOMEM:
return CAIRO_STATUS_NO_MEMORY;
default:
return CAIRO_STATUS_WRITE_ERROR;
}
}
} else
png_file = stdout;
status = cairo_surface_write_to_png_stream (surface_diff, stdio_write_func, png_file);
status = cairo_surface_write_to_png_stream (surface_diff,
stdio_write_func,
png_file);
if (png_file != stdout)
fclose (png_file);
} else {
if (filename_diff)
xunlink (filename_diff);
xunlink (ctx, filename_diff);
}
cairo_surface_destroy (surface_a);
@ -375,7 +429,8 @@ image_diff_core (const char *filename_a,
}
cairo_status_t
image_diff (const char *filename_a,
image_diff (const cairo_test_context_t *ctx,
const char *filename_a,
const char *filename_b,
const char *filename_diff,
int ax,
@ -384,13 +439,15 @@ image_diff (const char *filename_a,
int by,
buffer_diff_result_t *result)
{
return image_diff_core (filename_a, filename_b, filename_diff,
return image_diff_core (ctx,
filename_a, filename_b, filename_diff,
ax, ay, bx, by,
result, FALSE);
}
cairo_status_t
image_diff_flattened (const char *filename_a,
image_diff_flattened (const cairo_test_context_t *ctx,
const char *filename_a,
const char *filename_b,
const char *filename_diff,
int ax,
@ -399,7 +456,8 @@ image_diff_flattened (const char *filename_a,
int by,
buffer_diff_result_t *result)
{
return image_diff_core (filename_a, filename_b, filename_diff,
return image_diff_core (ctx,
filename_a, filename_b, filename_diff,
ax, ay, bx, by,
result, TRUE);
}

View file

@ -45,7 +45,8 @@ typedef struct _buffer_diff_result {
* images differ.
*/
void
compare_surfaces (cairo_surface_t *surface_a,
compare_surfaces (const cairo_test_context_t *ctx,
cairo_surface_t *surface_a,
cairo_surface_t *surface_b,
cairo_surface_t *surface_diff,
buffer_diff_result_t *result);
@ -81,7 +82,8 @@ buffer_diff_noalpha (unsigned char *buf_a,
* images differ.
*/
cairo_status_t
image_diff (const char *filename_a,
image_diff (const cairo_test_context_t *ctx,
const char *filename_a,
const char *filename_b,
const char *filename_diff,
int ax,
@ -92,7 +94,8 @@ image_diff (const char *filename_a,
/* Like image_diff, but blending the contents of b over white first. */
cairo_status_t
image_diff_flattened (const char *filename_a,
image_diff_flattened (const cairo_test_context_t *ctx,
const char *filename_a,
const char *filename_b,
const char *filename_diff,
int ax,

File diff suppressed because it is too large Load diff

View file

@ -66,15 +66,18 @@ typedef enum cairo_test_status {
CAIRO_TEST_CRASHED
} cairo_test_status_t;
typedef struct _cairo_test_context cairo_test_context_t;
typedef struct _cairo_test cairo_test_t;
typedef cairo_test_status_t (cairo_test_draw_function_t) (cairo_t *cr, int width, int height);
typedef struct _cairo_test {
struct _cairo_test {
const char *name;
const char *description;
int width;
int height;
cairo_test_draw_function_t *draw;
} cairo_test_t;
};
/* The standard test interface which works by examining result image.
*
@ -99,7 +102,35 @@ typedef struct _cairo_test {
* to the four criteria above.
*/
cairo_test_status_t
cairo_test (cairo_test_t *test);
cairo_test (const cairo_test_t *test);
/* The full context for the test.
* For ordinary tests (using cairo_test()) the context is passed to the draw
* routine via user_data on the cairo_t. The reason why the context is not
* passed as an explicit parameter is that it is rarely required by the test
* itself and by removing the parameter we can keep the draw routines simple
* and serve as example code.
*/
struct _cairo_test_context {
const cairo_test_t *test;
const char *test_name;
cairo_test_status_t expectation;
FILE *log_file;
const char *srcdir; /* directory containing sources and input data */
const char *refdir; /* directory containing reference images */
size_t num_targets;
cairo_bool_t limited_targets;
cairo_boilerplate_target_t **targets_to_test;
int thread;
};
/* Retrieve the test context from the cairo_t, used for logging, paths etc */
const cairo_test_context_t *
cairo_test_get_context (cairo_t *cr);
/* cairo_test_init(), cairo_test_log(), and cairo_test_fini() exist to
* help in writing tests for which cairo_test() is not appropriate for
@ -108,30 +139,37 @@ cairo_test (cairo_test_t *test);
* than be handed one by cairo_test.
*/
/* Initialize test-specific resources, (log files, etc.) */
void
cairo_test_init (const char *test_name);
cairo_test_init (cairo_test_context_t *ctx,
const char *test_name);
/* Finalize test-specific resource. */
void
cairo_test_fini (void);
cairo_test_fini (cairo_test_context_t *ctx);
/* Print a message to the log file, ala printf. */
void
cairo_test_log (const char *fmt, ...) CAIRO_BOILERPLATE_PRINTF_FORMAT(1, 2);
cairo_test_log (const cairo_test_context_t *ctx,
const char *fmt, ...) CAIRO_BOILERPLATE_PRINTF_FORMAT(2, 3);
void
cairo_test_log_path (const cairo_path_t *path);
cairo_test_log_path (const cairo_test_context_t *ctx,
const cairo_path_t *path);
/* Helper functions that take care of finding source images even when
* building in a non-srcdir manner, (ie. the tests will be run in a
* directory that is different from the one where the source image
* exists). */
cairo_surface_t *
cairo_test_create_surface_from_png (const char *filename);
cairo_test_create_surface_from_png (const cairo_test_context_t *ctx,
const char *filename);
cairo_pattern_t *
cairo_test_create_pattern_from_png (const char *filename);
cairo_test_create_pattern_from_png (const cairo_test_context_t *ctx,
const char *filename);
cairo_status_t
cairo_test_paint_checkered (cairo_t *cr);

View file

@ -32,7 +32,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"caps-joins-alpha",
"Test caps and joins with some source alpha",
3 * (PAD + SIZE) + PAD,

View file

@ -31,7 +31,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"caps-joins",
"Test caps and joins",
3 * (PAD + SIZE) + PAD,

View file

@ -32,7 +32,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"caps-sub-paths",
"Test that sub-paths receive caps.",
20, 20,

View file

@ -30,7 +30,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"clip-all",
"Test clipping with everything clipped out",
SIZE, SIZE,

View file

@ -29,7 +29,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"clip-empty",
"Test clipping with an empty clip path",
SIZE, SIZE,

View file

@ -30,7 +30,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"clip-fill-rule-pixel-aligned",
"Tests interaction of clipping and cairo_set_fill_rule with a pixel-aligned path",
PAD + (SIZE*4) + PAD + (SIZE*4) + PAD,

View file

@ -29,7 +29,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"clip-fill-rule",
"Tests interaction of clipping with cairo_set_fill_rule",
STAR_SIZE * 2 + 2, STAR_SIZE + 2,

View file

@ -33,7 +33,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"clip-nesting",
"Test clipping with multiple contexts for the same surface",
SIZE, SIZE,

View file

@ -115,7 +115,7 @@ draw_rects (cairo_t *cr, int x, int y)
cairo_fill (cr);
}
static void (*draw_funcs[])(cairo_t *cr, int x, int y) = {
static void (* const draw_funcs[])(cairo_t *cr, int x, int y) = {
draw_mask,
draw_glyphs,
draw_polygon,
@ -130,7 +130,7 @@ static void (*draw_funcs[])(cairo_t *cr, int x, int y) = {
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"clip-operator",
"Surface clipping with different operators",
IMAGE_WIDTH, IMAGE_HEIGHT,
@ -140,6 +140,7 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
size_t j, x, y;
cairo_operator_t op;
cairo_pattern_t *pattern;
@ -178,14 +179,14 @@ draw (cairo_t *cr, int width, int height)
draw_funcs[j] (cr, x, y);
if (cairo_status (cr))
cairo_test_log ("%d %d HERE!\n", op, (int)j);
cairo_test_log (ctx, "%d %d HERE!\n", op, (int)j);
cairo_restore (cr);
}
}
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
cairo_test_log ("%d %d .HERE!\n", op, (int)j);
cairo_test_log (ctx, "%d %d .HERE!\n", op, (int)j);
return CAIRO_TEST_SUCCESS;
}

View file

@ -38,7 +38,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"clip-push-group",
"Test that push_group doesn't crash after setting a surface-based clip",
SIZE, SIZE,

View file

@ -30,7 +30,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"clip-twice",
"Verifies that the clip mask is updated correctly when it constructed by setting the clip path twice.",
WIDTH, HEIGHT,

View file

@ -28,7 +28,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"clip-zero",
"Verifies that 0x0 surfaces or clips don't cause problems.",
0, 0,

View file

@ -30,7 +30,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"clipped-group",
"Test that a clipped group ends up in the right place",
WIDTH, HEIGHT,

View file

@ -28,7 +28,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"close-path",
"Test some corner cases related to cairo_close_path",
32, 16,

View file

@ -34,7 +34,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"composite-integer-translate-over-repeat",
"Test simple compositing: integer-translation 32->32 OVER, with repeat",
SIZE, SIZE,

View file

@ -32,7 +32,7 @@ const char png_filename[] = "romedalen.png";
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"composite-integer-translate-over",
"Test simple compositing: integer-translation 32->32 OVER",
SIZE, SIZE,
@ -42,9 +42,10 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
cairo_surface_t *image;
image = cairo_test_create_surface_from_png (png_filename);
image = cairo_test_create_surface_from_png (ctx, png_filename);
cairo_set_source_rgba (cr, 0, 0, 0, 1);
cairo_rectangle (cr, 0, 0, SIZE, SIZE);

View file

@ -35,7 +35,7 @@ const char png_filename[] = "romedalen.png";
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"composite-integer-translate-source",
"Test simple compositing: integer-translation 32->32 SOURCE",
SIZE, SIZE,
@ -45,9 +45,10 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
cairo_surface_t *image;
image = cairo_test_create_surface_from_png (png_filename);
image = cairo_test_create_surface_from_png (ctx, png_filename);
cairo_set_source_rgba (cr, 0, 0, 0, 1);
cairo_rectangle (cr, 0, 0, SIZE, SIZE);

View file

@ -28,7 +28,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"copy-path",
"Tests calls to path_data functions: cairo_copy_path, cairo_copy_path_flat, and cairo_append_path",
45, 53,
@ -96,6 +96,7 @@ make_path (cairo_t *cr)
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
cairo_path_t *path;
cairo_t *cr_error;
@ -105,7 +106,8 @@ draw (cairo_t *cr, int width, int height)
path = cairo_copy_path (cr_error);
if (path->status == CAIRO_STATUS_SUCCESS ||
path->status != cairo_status (cr_error)) {
cairo_test_log ("Error: cairo_copy_path returned status of %s rather than propagating %s\n",
cairo_test_log (ctx,
"Error: cairo_copy_path returned status of %s rather than propagating %s\n",
cairo_status_to_string (path->status),
cairo_status_to_string (cairo_status (cr_error)));
cairo_path_destroy (path);
@ -116,7 +118,8 @@ draw (cairo_t *cr, int width, int height)
path = cairo_copy_path_flat (cr_error);
if (path->status == CAIRO_STATUS_SUCCESS ||
path->status != cairo_status (cr_error)) {
cairo_test_log ("Error: cairo_copy_path_flat returned status of %s rather than propagating %s\n",
cairo_test_log (ctx,
"Error: cairo_copy_path_flat returned status of %s rather than propagating %s\n",
cairo_status_to_string (path->status),
cairo_status_to_string (cairo_status (cr_error)));
cairo_path_destroy (path);
@ -125,18 +128,20 @@ draw (cairo_t *cr, int width, int height)
cairo_path_destroy (path);
cairo_destroy (cr_error);
/* first check that we can copy an empty path */
cairo_new_path (cr);
path = cairo_copy_path (cr);
if (path->status != CAIRO_STATUS_SUCCESS) {
cairo_test_log ("Error: cairo_copy_path returned status of %s\n",
cairo_test_log (ctx,
"Error: cairo_copy_path returned status of %s\n",
cairo_status_to_string (path->status));
cairo_path_destroy (path);
return CAIRO_TEST_FAILURE;
}
if (path->num_data != 0) {
cairo_test_log ("Error: cairo_copy_path did not copy an empty path, returned path contains %d elements\n",
cairo_test_log (ctx,
"Error: cairo_copy_path did not copy an empty path, returned path contains %d elements\n",
path->num_data);
cairo_path_destroy (path);
return CAIRO_TEST_FAILURE;
@ -144,7 +149,8 @@ draw (cairo_t *cr, int width, int height)
cairo_append_path (cr, path);
cairo_path_destroy (path);
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
cairo_test_log ("Error: cairo_append_path failed with a copy of an empty path, returned status of %s\n",
cairo_test_log (ctx,
"Error: cairo_append_path failed with a copy of an empty path, returned status of %s\n",
cairo_status_to_string (cairo_status (cr)));
return CAIRO_TEST_FAILURE;
}
@ -197,51 +203,75 @@ draw (cairo_t *cr, int width, int height)
int
main (void)
{
cairo_test_context_t ctx;
cairo_t *cr;
cairo_path_data_t data;
cairo_path_t path;
cairo_surface_t *surface;
cairo_status_t status;
cairo_test_init (&ctx, "copy-path");
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
/* Test a few error cases for cairo_append_path_data */
cr = cairo_create (surface);
cairo_append_path (cr, NULL);
if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER)
return 1;
status = cairo_status (cr);
cairo_destroy (cr);
if (status != CAIRO_STATUS_NULL_POINTER) {
cairo_surface_destroy (surface);
cairo_test_fini (&ctx);
return CAIRO_TEST_FAILURE;
}
cr = cairo_create (surface);
path.status = -1;
cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_INVALID_STATUS)
return 1;
status = cairo_status (cr);
cairo_destroy (cr);
if (status != CAIRO_STATUS_INVALID_STATUS) {
cairo_surface_destroy (surface);
cairo_test_fini (&ctx);
return CAIRO_TEST_FAILURE;
}
cr = cairo_create (surface);
path.status = CAIRO_STATUS_NO_MEMORY;
cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_NO_MEMORY)
return 1;
status = cairo_status (cr);
cairo_destroy (cr);
if (status != CAIRO_STATUS_NO_MEMORY) {
cairo_surface_destroy (surface);
cairo_test_fini (&ctx);
return CAIRO_TEST_FAILURE;
}
cr = cairo_create (surface);
path.data = NULL;
path.num_data = 0;
path.status = CAIRO_STATUS_SUCCESS;
cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
return 1;
status = cairo_status (cr);
cairo_destroy (cr);
if (status != CAIRO_STATUS_SUCCESS) {
cairo_surface_destroy (surface);
cairo_test_fini (&ctx);
return CAIRO_TEST_FAILURE;
}
cr = cairo_create (surface);
path.data = NULL;
path.num_data = 1;
path.status = CAIRO_STATUS_SUCCESS;
cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER)
return 1;
status = cairo_status (cr);
cairo_destroy (cr);
if (status != CAIRO_STATUS_NULL_POINTER) {
cairo_surface_destroy (surface);
cairo_test_fini (&ctx);
return CAIRO_TEST_FAILURE;
}
cr = cairo_create (surface);
/* Intentionally insert bogus header.length value (otherwise would be 2) */
@ -250,19 +280,28 @@ main (void)
path.data = &data;
path.num_data = 1;
cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_INVALID_PATH_DATA)
return 1;
status = cairo_status (cr);
cairo_destroy (cr);
if (status != CAIRO_STATUS_INVALID_PATH_DATA) {
cairo_surface_destroy (surface);
cairo_test_fini (&ctx);
return CAIRO_TEST_FAILURE;
}
/* And test the degnerate case */
cr = cairo_create (surface);
path.num_data = 0;
cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
return 1;
status = cairo_status (cr);
cairo_destroy (cr);
if (status != CAIRO_STATUS_SUCCESS) {
cairo_surface_destroy (surface);
cairo_test_fini (&ctx);
return CAIRO_TEST_FAILURE;
}
cairo_surface_destroy (surface);
cairo_test_fini (&ctx);
return cairo_test (&test);
}

View file

@ -85,6 +85,7 @@ draw_to (cairo_surface_t *surface)
}
typedef struct _write_closure {
const cairo_test_context_t *ctx;
char buffer[MAX_OUTPUT_SIZE];
size_t index;
cairo_test_status_t status;
@ -106,7 +107,7 @@ test_write (void *closure,
write_closure_t *wc = closure;
if (wc->index + length >= sizeof wc->buffer) {
cairo_test_log ("Error: out of bounds in write callback\n");
cairo_test_log (wc->ctx, "Error: out of bounds in write callback\n");
wc->status = CAIRO_TEST_FAILURE;
return CAIRO_STATUS_SUCCESS;
}
@ -130,7 +131,8 @@ typedef cairo_surface_t *
double height_in_points);
static cairo_test_status_t
test_surface (const char *backend,
test_surface (const cairo_test_context_t *ctx,
const char *backend,
const char *filename,
file_constructor_t file_constructor,
stream_constructor_t stream_constructor)
@ -147,7 +149,9 @@ test_surface (const char *backend,
status = cairo_surface_status (surface);
if (status) {
cairo_test_log ("%s: Failed to create surface for stream.\n", backend);
cairo_test_log (ctx,
"%s: Failed to create surface for stream.\n",
backend);
return CAIRO_TEST_FAILURE;
}
@ -158,12 +162,14 @@ test_surface (const char *backend,
cairo_surface_destroy (surface);
if (status != CAIRO_STATUS_WRITE_ERROR) {
cairo_test_log ("%s: Error: expected \"write error\", but received \"%s\".\n",
cairo_test_log (ctx,
"%s: Error: expected \"write error\", but received \"%s\".\n",
backend, cairo_status_to_string (status));
return CAIRO_TEST_FAILURE;
}
/* construct the real surface */
wc.ctx = ctx;
wc.status = CAIRO_TEST_SUCCESS;
wc.index = 0;
@ -172,7 +178,8 @@ test_surface (const char *backend,
status = cairo_surface_status (surface);
if (status) {
cairo_test_log ("%s: Failed to create surface for stream.\n", backend);
cairo_test_log (ctx,
"%s: Failed to create surface for stream.\n", backend);
return CAIRO_TEST_FAILURE;
}
@ -190,7 +197,7 @@ test_surface (const char *backend,
status = cairo_surface_status (surface);
if (status) {
cairo_test_log ("%s: Failed to create surface for file %s: %s.\n",
cairo_test_log (ctx, "%s: Failed to create surface for file %s: %s.\n",
backend, filename, cairo_status_to_string (status));
return CAIRO_TEST_FAILURE;
}
@ -201,20 +208,20 @@ test_surface (const char *backend,
fp = fopen (filename, "r");
if (fp == NULL) {
cairo_test_log ("%s: Failed to open %s for reading: %s.\n",
cairo_test_log (ctx, "%s: Failed to open %s for reading: %s.\n",
backend, filename, strerror (errno));
return CAIRO_TEST_FAILURE;
}
if (fread (file_contents, 1, wc.index, fp) != wc.index) {
cairo_test_log ("%s: Failed to read %s: %s.\n",
cairo_test_log (ctx, "%s: Failed to read %s: %s.\n",
backend, filename, strerror (errno));
fclose (fp);
return CAIRO_TEST_FAILURE;
}
if (memcmp (file_contents, wc.buffer, wc.index) != 0) {
cairo_test_log ("%s: Stream based output differ from file output for %s.\n",
cairo_test_log (ctx, "%s: Stream based output differ from file output for %s.\n",
backend, filename);
fclose (fp);
return CAIRO_TEST_FAILURE;
@ -228,17 +235,18 @@ test_surface (const char *backend,
int
main (void)
{
cairo_test_context_t ctx;
cairo_test_status_t status = CAIRO_TEST_SUCCESS;
cairo_test_status_t test_status;
const char test_name[] = "create-for-stream";
cairo_test_init (test_name);
cairo_test_init (&ctx, test_name);
#if CAIRO_HAS_PS_SURFACE
test_status = test_surface ("ps", "create-for-stream.ps",
test_status = test_surface (&ctx, "ps", "create-for-stream.ps",
cairo_ps_surface_create,
cairo_ps_surface_create_for_stream);
cairo_test_log ("TEST: %s TARGET: %s RESULT: %s\n",
cairo_test_log (&ctx, "TEST: %s TARGET: %s RESULT: %s\n",
test_name, "ps",
test_status ? "FAIL" : "PASS");
if (status == CAIRO_TEST_SUCCESS)
@ -246,10 +254,10 @@ main (void)
#endif
#if CAIRO_HAS_PDF_SURFACE
test_status = test_surface ("pdf", "create-for-stream.pdf",
test_status = test_surface (&ctx, "pdf", "create-for-stream.pdf",
cairo_pdf_surface_create,
cairo_pdf_surface_create_for_stream);
cairo_test_log ("TEST: %s TARGET: %s RESULT: %s\n",
cairo_test_log (&ctx, "TEST: %s TARGET: %s RESULT: %s\n",
test_name, "pdf",
test_status ? "FAIL" : "PASS");
if (status == CAIRO_TEST_SUCCESS)
@ -257,17 +265,17 @@ main (void)
#endif
#if CAIRO_HAS_SVG_SURFACE
test_status = test_surface ("svg", "create-for-stream.svg",
test_status = test_surface (&ctx, "svg", "create-for-stream.svg",
cairo_svg_surface_create,
cairo_svg_surface_create_for_stream);
cairo_test_log ("TEST: %s TARGET: %s RESULT: %s\n",
cairo_test_log (&ctx, "TEST: %s TARGET: %s RESULT: %s\n",
test_name, "svg",
test_status ? "FAIL" : "PASS");
if (status == CAIRO_TEST_SUCCESS)
status = test_status;
#endif
cairo_test_fini ();
cairo_test_fini (&ctx);
return status;
}

View file

@ -33,7 +33,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"create-from-png-stream",
"Tests the creation of an image surface from a PNG using a FILE *",
WIDTH, HEIGHT,
@ -56,17 +56,17 @@ read_png_from_file (void *closure, unsigned char *data, unsigned int length)
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
char *srcdir = getenv ("srcdir");
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
char *filename;
FILE *file;
cairo_surface_t *surface;
xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
xasprintf (&filename, "%s/%s", ctx->srcdir,
"create-from-png-stream-ref.png");
file = fopen (filename, "rb");
if (file == NULL) {
cairo_test_log ("Error: failed to open file: %s\n", filename);
cairo_test_log (ctx, "Error: failed to open file: %s\n", filename);
return CAIRO_TEST_FAILURE;
}
@ -76,7 +76,9 @@ draw (cairo_t *cr, int width, int height)
fclose (file);
if (surface == NULL) {
cairo_test_log ("Error: failed to create surface from PNG: %s\n", filename);
cairo_test_log (ctx,
"Error: failed to create surface from PNG: %s\n",
filename);
free (filename);
return CAIRO_TEST_FAILURE;
}

View file

@ -32,7 +32,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"create-from-png",
"Tests the creation of an image surface from a PNG file",
WIDTH, HEIGHT,
@ -54,16 +54,16 @@ read_error (void *closure, unsigned char *data, unsigned int size)
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
char *srcdir = getenv ("srcdir");
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
char *filename;
cairo_surface_t *surface;
xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
xasprintf (&filename, "%s/%s", ctx->srcdir,
"create-from-png-ref.png");
surface = cairo_image_surface_create_from_png (filename);
if (cairo_surface_status (surface)) {
cairo_test_log ("Error reading PNG image %s: %s\n",
cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
filename,
cairo_status_to_string (cairo_surface_status (surface)));
free (filename);
@ -82,189 +82,177 @@ draw (cairo_t *cr, int width, int height)
int
main (void)
{
char *srcdir = getenv ("srcdir");
cairo_test_context_t ctx;
char *filename;
cairo_surface_t *surface;
cairo_status_t status;
cairo_test_status_t result = CAIRO_TEST_SUCCESS;
cairo_test_init (&ctx, "create-from-png");
surface = cairo_image_surface_create_from_png ("___THIS_FILE_DOES_NOT_EXIST___");
if (cairo_surface_status (surface) != CAIRO_STATUS_FILE_NOT_FOUND) {
cairo_test_log ("Error: expected \"file not found\", but got: %s\n",
cairo_test_log (&ctx, "Error: expected \"file not found\", but got: %s\n",
cairo_status_to_string (cairo_surface_status (surface)));
cairo_surface_destroy (surface);
return CAIRO_TEST_FAILURE;
result = CAIRO_TEST_FAILURE;
}
cairo_surface_destroy (surface);
surface = cairo_image_surface_create_from_png_stream (no_memory_error, NULL);
if (cairo_surface_status (surface) != CAIRO_STATUS_NO_MEMORY) {
cairo_test_log ("Error: expected \"out of memory\", but got: %s\n",
cairo_test_log (&ctx, "Error: expected \"out of memory\", but got: %s\n",
cairo_status_to_string (cairo_surface_status (surface)));
cairo_surface_destroy (surface);
return CAIRO_TEST_FAILURE;
result = CAIRO_TEST_FAILURE;
}
cairo_surface_destroy (surface);
surface = cairo_image_surface_create_from_png_stream (read_error, NULL);
if (cairo_surface_status (surface) != CAIRO_STATUS_READ_ERROR) {
cairo_test_log ("Error: expected \"read error\", but got: %s\n",
cairo_test_log (&ctx, "Error: expected \"read error\", but got: %s\n",
cairo_status_to_string (cairo_surface_status (surface)));
cairo_surface_destroy (surface);
return CAIRO_TEST_FAILURE;
result = CAIRO_TEST_FAILURE;
}
cairo_surface_destroy (surface);
/* cheekily test error propagation from the user write funcs as well ... */
xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
xasprintf (&filename, "%s/%s", ctx.srcdir,
"create-from-png-ref.png");
surface = cairo_image_surface_create_from_png (filename);
if (cairo_surface_status (surface)) {
cairo_test_log ("Error reading PNG image %s: %s\n",
cairo_test_log (&ctx, "Error reading PNG image %s: %s\n",
filename,
cairo_status_to_string (cairo_surface_status (surface)));
free (filename);
return CAIRO_TEST_FAILURE;
}
free (filename);
result = CAIRO_TEST_FAILURE;
} else {
status = cairo_surface_write_to_png_stream (surface,
(cairo_write_func_t) no_memory_error,
NULL);
if (status != CAIRO_STATUS_NO_MEMORY) {
cairo_test_log (&ctx, "Error: expected \"out of memory\", but got: %s\n",
cairo_status_to_string (status));
result = CAIRO_TEST_FAILURE;
}
status = cairo_surface_write_to_png_stream (surface,
(cairo_write_func_t) no_memory_error,
NULL);
if (status != CAIRO_STATUS_NO_MEMORY) {
cairo_test_log ("Error: expected \"out of memory\", but got: %s\n",
cairo_status_to_string (status));
cairo_surface_destroy (surface);
return CAIRO_TEST_FAILURE;
}
status = cairo_surface_write_to_png_stream (surface,
(cairo_write_func_t) read_error,
NULL);
if (status != CAIRO_STATUS_READ_ERROR) {
cairo_test_log ("Error: expected \"read error\", but got: %s\n",
cairo_status_to_string (status));
cairo_surface_destroy (surface);
return CAIRO_TEST_FAILURE;
status = cairo_surface_write_to_png_stream (surface,
(cairo_write_func_t) read_error,
NULL);
if (status != CAIRO_STATUS_READ_ERROR) {
cairo_test_log (&ctx, "Error: expected \"read error\", but got: %s\n",
cairo_status_to_string (status));
result = CAIRO_TEST_FAILURE;
}
/* and check that error has not propagated to the surface */
if (cairo_surface_status (surface)) {
cairo_test_log (&ctx, "Error: user write error propagated to surface: %s",
cairo_status_to_string (cairo_surface_status (surface)));
result = CAIRO_TEST_FAILURE;
}
}
cairo_surface_destroy (surface);
free (filename);
/* check that loading alpha/opaque PNGs generate the correct surfaces */
xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
xasprintf (&filename, "%s/%s", ctx.srcdir,
"create-from-png-alpha-ref.png");
surface = cairo_image_surface_create_from_png (filename);
if (cairo_surface_status (surface)) {
cairo_test_log ("Error reading PNG image %s: %s\n",
cairo_test_log (&ctx, "Error reading PNG image %s: %s\n",
filename,
cairo_status_to_string (cairo_surface_status (surface)));
free (filename);
return CAIRO_TEST_FAILURE;
}
if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) {
cairo_test_log ("Error reading PNG image %s: did not create an ARGB32 image\n",
filename);
cairo_surface_destroy (surface);
return CAIRO_TEST_FAILURE;
result = CAIRO_TEST_FAILURE;
} else if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) {
cairo_test_log (&ctx, "Error reading PNG image %s: did not create an ARGB32 image\n",
filename);
result = CAIRO_TEST_FAILURE;
}
free (filename);
cairo_surface_destroy (surface);
xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
xasprintf (&filename, "%s/%s", ctx.srcdir,
"create-from-png-ref.png");
surface = cairo_image_surface_create_from_png (filename);
if (cairo_surface_status (surface)) {
cairo_test_log ("Error reading PNG image %s: %s\n",
cairo_test_log (&ctx, "Error reading PNG image %s: %s\n",
filename,
cairo_status_to_string (cairo_surface_status (surface)));
free (filename);
return CAIRO_TEST_FAILURE;
}
if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_RGB24) {
cairo_test_log ("Error reading PNG image %s: did not create an RGB24 image\n",
filename);
cairo_surface_destroy (surface);
return CAIRO_TEST_FAILURE;
result = CAIRO_TEST_FAILURE;
} else if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_RGB24) {
cairo_test_log (&ctx, "Error reading PNG image %s: did not create an RGB24 image\n",
filename);
result = CAIRO_TEST_FAILURE;
}
free (filename);
cairo_surface_destroy (surface);
/* check paletted PNGs */
xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
xasprintf (&filename, "%s/%s", ctx.srcdir,
"create-from-png-indexed-alpha-ref.png");
surface = cairo_image_surface_create_from_png (filename);
if (cairo_surface_status (surface)) {
cairo_test_log ("Error reading PNG image %s: %s\n",
cairo_test_log (&ctx, "Error reading PNG image %s: %s\n",
filename,
cairo_status_to_string (cairo_surface_status (surface)));
free (filename);
return CAIRO_TEST_FAILURE;
}
if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) {
cairo_test_log ("Error reading PNG image %s: did not create an ARGB32 image\n",
filename);
free (filename);
cairo_surface_destroy (surface);
return CAIRO_TEST_FAILURE;
result = CAIRO_TEST_FAILURE;
} else if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) {
cairo_test_log (&ctx, "Error reading PNG image %s: did not create an ARGB32 image\n",
filename);
result = CAIRO_TEST_FAILURE;
}
free (filename);
cairo_surface_destroy (surface);
xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
xasprintf (&filename, "%s/%s", ctx.srcdir,
"create-from-png-indexed-ref.png");
surface = cairo_image_surface_create_from_png (filename);
if (cairo_surface_status (surface)) {
cairo_test_log ("Error reading PNG image %s: %s\n",
cairo_test_log (&ctx, "Error reading PNG image %s: %s\n",
filename,
cairo_status_to_string (cairo_surface_status (surface)));
free (filename);
return CAIRO_TEST_FAILURE;
}
if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_RGB24) {
cairo_test_log ("Error reading PNG image %s: did not create an RGB24 image\n",
filename);
free (filename);
cairo_surface_destroy (surface);
return CAIRO_TEST_FAILURE;
result = CAIRO_TEST_FAILURE;
} else if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_RGB24) {
cairo_test_log (&ctx, "Error reading PNG image %s: did not create an RGB24 image\n",
filename);
result = CAIRO_TEST_FAILURE;
}
free (filename);
cairo_surface_destroy (surface);
/* check grayscale PNGs */
xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
xasprintf (&filename, "%s/%s", ctx.srcdir,
"create-from-png-gray-alpha-ref.png");
surface = cairo_image_surface_create_from_png (filename);
if (cairo_surface_status (surface)) {
cairo_test_log ("Error reading PNG image %s: %s\n",
cairo_test_log (&ctx, "Error reading PNG image %s: %s\n",
filename,
cairo_status_to_string (cairo_surface_status (surface)));
free (filename);
return CAIRO_TEST_FAILURE;
}
if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) {
cairo_test_log ("Error reading PNG image %s: did not create an ARGB32 image\n",
filename);
free (filename);
cairo_surface_destroy (surface);
return CAIRO_TEST_FAILURE;
result = CAIRO_TEST_FAILURE;
} else if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) {
cairo_test_log (&ctx, "Error reading PNG image %s: did not create an ARGB32 image\n",
filename);
result = CAIRO_TEST_FAILURE;
}
free (filename);
cairo_surface_destroy (surface);
xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
xasprintf (&filename, "%s/%s", ctx.srcdir,
"create-from-png-gray-ref.png");
surface = cairo_image_surface_create_from_png (filename);
if (cairo_surface_status (surface)) {
cairo_test_log ("Error reading PNG image %s: %s\n",
cairo_test_log (&ctx, "Error reading PNG image %s: %s\n",
filename,
cairo_status_to_string (cairo_surface_status (surface)));
free (filename);
return CAIRO_TEST_FAILURE;
}
if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_RGB24) {
cairo_test_log ("Error reading PNG image %s: did not create an RGB24 image\n",
filename);
free (filename);
cairo_surface_destroy (surface);
return CAIRO_TEST_FAILURE;
result = CAIRO_TEST_FAILURE;
} else if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_RGB24) {
cairo_test_log (&ctx, "Error reading PNG image %s: did not create an RGB24 image\n",
filename);
result = CAIRO_TEST_FAILURE;
}
free (filename);
cairo_surface_destroy (surface);
cairo_test_fini (&ctx);
return cairo_test (&test);
}

View file

@ -37,7 +37,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"dash-caps-joins",
"Test caps and joins when dashing",
3 * (PAD + SIZE) + PAD,

View file

@ -27,7 +27,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"dash-curve",
"Tries to explore the state space of the dashing code along curves",
25*60, 4*60,

View file

@ -33,7 +33,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"dash-no-dash",
"Tests that we can actually turn dashing on and off again",
WIDTH, HEIGHT,

View file

@ -36,7 +36,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"dash-offset-negative",
"Tests cairo_set_dash with a negative offset",
IMAGE_WIDTH, IMAGE_HEIGHT,

View file

@ -31,7 +31,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"dash-scale",
"Test interactions of cairo_set_dash and cairo_scale, (in particular with a non-uniformly scaled pen)",
3 * (PAD + SIZE) + PAD,

View file

@ -27,7 +27,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"dash-state",
"Tries to explore the state space of the dashing code",
25*60, 4*60,

View file

@ -35,7 +35,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"dash-zero-length",
"Tests cairo_set_dash with zero length",
IMAGE_WIDTH, IMAGE_HEIGHT,

View file

@ -32,7 +32,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"degenerate-arc",
"Tests the behaviour of degenerate arcs",
40, 40,

View file

@ -32,7 +32,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"degenerate-path",
"Tests the behaviour of degenerate paths with different cap types",
3*(PAD+LINE_WIDTH+PAD), 8*(LINE_WIDTH+PAD) + PAD,

View file

@ -50,7 +50,7 @@ static cairo_test_draw_function_t draw;
* pen doing slope comparisons.
*/
cairo_test_t test = {
static const cairo_test_t test = {
"degenerate-pen",
"Test round joins with a pen that's transformed to a line",
WIDTH, HEIGHT,

View file

@ -31,7 +31,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"device-offset-positive",
"Simple test using a surface with a positive device-offset as a source.",
SIZE, SIZE,

View file

@ -30,7 +30,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"device-offset-scale",
"Test that the device-offset transform is transformed by the ctm.",
WIDTH, HEIGHT,

View file

@ -31,7 +31,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"device-offset",
"Simple test using a surface with a negative device-offset as a source.",
SIZE, SIZE,

View file

@ -32,7 +32,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"extend-pad",
"Test CAIRO_EXTEND_PAD for surface patterns",
SIZE, SIZE,

View file

@ -4,7 +4,7 @@ const char png_filename[] = "romedalen.png";
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"extend-reflect-similar",
"Test CAIRO_EXTEND_REFLECT for surface patterns",
256 + 32*2, 192 + 32*2,
@ -22,9 +22,11 @@ clone_similar_surface (cairo_surface_t * target, cairo_surface_t *surface)
cairo_image_surface_get_width (surface),
cairo_image_surface_get_height (surface));
cr = cairo_create (similar);
cairo_surface_destroy (similar);
cairo_set_source_surface (cr, surface, 0, 0);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_paint (cr);
similar = cairo_surface_reference (cairo_get_target (cr));
cairo_destroy (cr);
return similar;
@ -33,10 +35,11 @@ clone_similar_surface (cairo_surface_t * target, cairo_surface_t *surface)
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
cairo_surface_t *surface;
cairo_surface_t *similar;
surface = cairo_test_create_surface_from_png (png_filename);
surface = cairo_test_create_surface_from_png (ctx, png_filename);
similar = clone_similar_surface (cairo_get_group_target (cr), surface);
cairo_set_source_surface (cr, similar, 32, 32);
cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REFLECT);

View file

@ -6,7 +6,7 @@ const char png_filename[] = "romedalen.png";
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"extend-reflect",
"Test CAIRO_EXTEND_REFLECT for surface patterns",
256 + 32*2, 192 + 32*2,
@ -16,9 +16,10 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
cairo_surface_t *surface;
surface = cairo_test_create_surface_from_png (png_filename);
surface = cairo_test_create_surface_from_png (ctx, png_filename);
cairo_set_source_surface (cr, surface, 32, 32);
cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REFLECT);

View file

@ -4,7 +4,7 @@ const char png_filename[] = "romedalen.png";
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"extend-repeat-similar",
"Test CAIRO_EXTEND_REPEAT for surface patterns",
256 + 32*2, 192 + 32*2,
@ -22,9 +22,11 @@ clone_similar_surface (cairo_surface_t * target, cairo_surface_t *surface)
cairo_image_surface_get_width (surface),
cairo_image_surface_get_height (surface));
cr = cairo_create (similar);
cairo_surface_destroy (similar);
cairo_set_source_surface (cr, surface, 0, 0);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_paint (cr);
similar = cairo_surface_reference (cairo_get_target (cr));
cairo_destroy (cr);
return similar;
@ -33,10 +35,11 @@ clone_similar_surface (cairo_surface_t * target, cairo_surface_t *surface)
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
cairo_surface_t *surface;
cairo_surface_t *similar;
surface = cairo_test_create_surface_from_png (png_filename);
surface = cairo_test_create_surface_from_png (ctx, png_filename);
similar = clone_similar_surface (cairo_get_group_target (cr), surface);
cairo_set_source_surface (cr, similar, 32, 32);
cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);

View file

@ -4,7 +4,7 @@ const char png_filename[] = "romedalen.png";
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"extend-repeat",
"Test CAIRO_EXTEND_REPEAT for surface patterns",
256 + 32*2, 192 + 32*2,
@ -14,9 +14,10 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
cairo_surface_t *surface;
surface = cairo_test_create_surface_from_png (png_filename);
surface = cairo_test_create_surface_from_png (ctx, png_filename);
cairo_set_source_surface (cr, surface, 32, 32);
cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);

View file

@ -88,6 +88,7 @@ static const char *backend_filename[NUM_BACKENDS] = {
int
main (void)
{
cairo_test_context_t ctx;
cairo_surface_t *surface = NULL;
cairo_t *cr;
cairo_status_t status;
@ -98,7 +99,7 @@ main (void)
num_pages = sizeof (ppi) / sizeof (ppi[0]);
cairo_test_init ("fallback-resolution");
cairo_test_init (&ctx, "fallback-resolution");
for (backend=0; backend < NUM_BACKENDS; backend++) {
@ -166,7 +167,7 @@ main (void)
cairo_surface_destroy (surface);
if (status) {
cairo_test_log ("Failed to create pdf surface for file %s: %s\n",
cairo_test_log (&ctx, "Failed to create pdf surface for file %s: %s\n",
backend_filename[backend],
cairo_status_to_string (status));
ret = CAIRO_TEST_FAILURE;
@ -177,7 +178,7 @@ main (void)
backend_filename[backend]);
}
cairo_test_fini ();
cairo_test_fini (&ctx);
return ret;
}

View file

@ -31,7 +31,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"fill-and-stroke-alpha-add",
"Use a group to fill/stroke a path (each with different alpha) using DEST_OUT and ADD to combine",
2 * SIZE + 4 * PAD, SIZE + 2 * PAD,

View file

@ -31,7 +31,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"fill-and-stroke-alpha",
"Use a group to fill/stroke a path then blend the result with alpha onto the destination",
2 * SIZE + 4 * PAD, SIZE + 2 * PAD,

View file

@ -30,7 +30,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"fill-and-stroke",
"Tests using cairo_fill_preserve/cairo_stroke to fill/stroke the same path",
2 * SIZE + 4 * PAD, SIZE + 2 * PAD,

View file

@ -38,7 +38,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"fill-degenerate-sort-order",
"Tests the tessellator's event comparator with degenerate input",
190, 120,

View file

@ -40,7 +40,7 @@
static cairo_test_draw_function_t draw;
#define SIZE 50
cairo_test_t test = {
static const cairo_test_t test = {
"fill-missed-stop",
"Tests that the tessellator doesn't miss stop events when generating trapezoids",
SIZE+3, SIZE+3,

View file

@ -68,7 +68,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"fill-rule",
"Tests cairo_set_fill_rule with some star shapes",
BIG_STAR_SIZE * 2 + 3, BIG_STAR_SIZE + LITTLE_STAR_SIZE + 3,

View file

@ -44,7 +44,7 @@ static cairo_test_draw_function_t draw;
#define WIDTH (PAD + 3 * SCALE + PAD)
#define HEIGHT WIDTH
cairo_test_t test = {
static const cairo_test_t test = {
"filter-bilinear-extents",
"Test that pattern extents are properly computed for CAIRO_FILTER_BILINEAR",
WIDTH, HEIGHT,

View file

@ -36,7 +36,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"filter-nearest-offset",
"Test sampling offset of CAIRO_FILTER_NEAREST"
"\nwrong sampling location for nearest-neighbor filter in libpixman and Render",
@ -48,7 +48,7 @@ static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
cairo_surface_t *surface;
static uint32_t data[STAMP_WIDTH * STAMP_HEIGHT] = {
uint32_t data[STAMP_WIDTH * STAMP_HEIGHT] = {
0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000,
0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000,

View file

@ -33,7 +33,7 @@ static cairo_test_draw_function_t draw;
#define WIDTH (CIRCLE_SIZE*6.5 + PAD)
#define HEIGHT (CIRCLE_SIZE*3.5 + PAD)
cairo_test_t test = {
static const cairo_test_t test = {
"finer-grained-fallbacks",
"Test that multiple PS/PDF fallback images in various locations are correct",
WIDTH, HEIGHT,

View file

@ -28,14 +28,15 @@
int
main (void)
{
cairo_test_context_t ctx;
cairo_surface_t *surface;
cairo_t *cr;
cairo_font_face_t *font_face;
cairo_scaled_font_t *scaled_font;
cairo_test_init ("font-face-get-type");
cairo_test_init (&ctx, "font-face-get-type");
cairo_test_log ("Creating cairo context and obtaining a font face\n");
cairo_test_log (&ctx, "Creating cairo context and obtaining a font face\n");
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
cr = cairo_create (surface);
@ -44,29 +45,31 @@ main (void)
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_test_log ("Testing return value of cairo_font_face_get_type\n");
cairo_test_log (&ctx, "Testing return value of cairo_font_face_get_type\n");
font_face = cairo_get_font_face (cr);
if (cairo_font_face_get_type (font_face) != CAIRO_FONT_TYPE_TOY) {
cairo_test_log ("Unexpected value %d from cairo_font_face_get_type (expected %d)\n",
cairo_test_log (&ctx, "Unexpected value %d from cairo_font_face_get_type (expected %d)\n",
cairo_font_face_get_type (font_face), CAIRO_FONT_TYPE_TOY);
cairo_test_fini (&ctx);
return CAIRO_TEST_FAILURE;
}
cairo_test_log ("Testing return value of cairo_get_scaled_font\n");
cairo_test_log (&ctx, "Testing return value of cairo_get_scaled_font\n");
scaled_font = cairo_get_scaled_font (cr);
if (cairo_scaled_font_get_font_face (scaled_font) != font_face) {
cairo_test_log ("Font face returned from the scaled font is different from that returned by the context\n");
cairo_test_log (&ctx, "Font face returned from the scaled font is different from that returned by the context\n");
cairo_test_fini (&ctx);
return CAIRO_TEST_FAILURE;
}
cairo_destroy (cr);
cairo_surface_destroy (surface);
cairo_test_fini ();
cairo_test_fini (&ctx);
return CAIRO_TEST_SUCCESS;
}

View file

@ -31,7 +31,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"font-matrix-translation",
"Test that translation in a font matrix can be used to offset a string",
38, 34,
@ -51,7 +51,9 @@ text_extents_equal (const cairo_text_extents_t *A,
}
static cairo_test_status_t
box_text (cairo_t *cr, const char *utf8, double x, double y)
box_text (const cairo_test_context_t *ctx, cairo_t *cr,
const char *utf8,
double x, double y)
{
double line_width;
cairo_text_extents_t extents = {0}, scaled_extents = {0};
@ -64,7 +66,8 @@ box_text (cairo_t *cr, const char *utf8, double x, double y)
scaled_font = cairo_get_scaled_font (cr);
cairo_scaled_font_text_extents (scaled_font, TEXT, &scaled_extents);
if (! text_extents_equal (&extents, &scaled_extents)) {
cairo_test_log ("Error: extents differ when they shouldn't:\n"
cairo_test_log (ctx,
"Error: extents differ when they shouldn't:\n"
"cairo_text_extents(); extents (%g, %g, %g, %g, %g, %g)\n"
"cairo_scaled_font_text_extents(); extents (%g, %g, %g, %g, %g, %g)\n",
extents.x_bearing, extents.y_bearing,
@ -95,6 +98,7 @@ box_text (cairo_t *cr, const char *utf8, double x, double y)
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
cairo_test_status_t status;
cairo_text_extents_t extents;
cairo_matrix_t matrix;
@ -114,7 +118,7 @@ draw (cairo_t *cr, int width, int height)
/* Draw text and bounding box */
cairo_set_source_rgb (cr, 0, 0, 0); /* black */
status = box_text (cr, TEXT, 0, - extents.y_bearing);
status = box_text (ctx, cr, TEXT, 0, - extents.y_bearing);
if (status)
return status;
@ -126,7 +130,7 @@ draw (cairo_t *cr, int width, int height)
cairo_set_font_matrix (cr, &matrix);
cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
status = box_text (cr, TEXT, 0, - extents.y_bearing);
status = box_text (ctx, cr, TEXT, 0, - extents.y_bearing);
if (status)
return status;

View file

@ -28,7 +28,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"ft-font-create-for-ft-face",
"Simple test to verify that cairo_ft_font_create_for_ft_face doesn't crash.",
0, 0,
@ -38,6 +38,7 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
FcPattern *pattern, *resolved;
FcResult result;
cairo_font_face_t *font_face;
@ -55,7 +56,7 @@ draw (cairo_t *cr, int width, int height)
* Do not use this in production code! */
pattern = FcPatternCreate ();
if (! pattern) {
cairo_test_log ("FcPatternCreate failed.\n");
cairo_test_log (ctx, "FcPatternCreate failed.\n");
return CAIRO_TEST_FAILURE;
}
@ -63,14 +64,14 @@ draw (cairo_t *cr, int width, int height)
FcDefaultSubstitute (pattern);
resolved = FcFontMatch (NULL, pattern, &result);
if (! resolved) {
cairo_test_log ("FcFontMatch failed.\n");
cairo_test_log (ctx, "FcFontMatch failed.\n");
return CAIRO_TEST_FAILURE;
}
font_face = cairo_ft_font_face_create_for_pattern (resolved);
if (cairo_font_face_get_type (font_face) != CAIRO_FONT_TYPE_FT) {
cairo_test_log ("Unexpected value from cairo_font_face_get_type: %d (expected %d)\n",
cairo_test_log (ctx, "Unexpected value from cairo_font_face_get_type: %d (expected %d)\n",
cairo_font_face_get_type (font_face), CAIRO_FONT_TYPE_FT);
cairo_font_face_destroy (font_face);
return CAIRO_TEST_FAILURE;
@ -97,14 +98,14 @@ draw (cairo_t *cr, int width, int height)
FcPatternDestroy (resolved);
if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_FT) {
cairo_test_log ("Unexpected value from cairo_scaled_font_get_type: %d (expected %d)\n",
cairo_test_log (ctx, "Unexpected value from cairo_scaled_font_get_type: %d (expected %d)\n",
cairo_scaled_font_get_type (scaled_font), CAIRO_FONT_TYPE_FT);
cairo_scaled_font_destroy (scaled_font);
return CAIRO_TEST_FAILURE;
}
if (!ft_face) {
cairo_test_log ("Failed to get an ft_face with cairo_ft_scaled_font_lock_face\n");
cairo_test_log (ctx, "Failed to get an ft_face with cairo_ft_scaled_font_lock_face\n");
cairo_scaled_font_destroy (scaled_font);
return CAIRO_TEST_FAILURE;
}

View file

@ -31,7 +31,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"ft-show-glyphs-positioning",
"Test that the PS/PDF glyph positioning optimizations are correct",
235, (TEXT_SIZE + 4)*2,

View file

@ -56,7 +56,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"ft-show-glyphs-table",
"Test cairo_show_glyphs with cairo-ft backend and glyphs laid out in a table",
WIDTH, HEIGHT,

View file

@ -35,7 +35,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"ft-text-antialias-none",
"Tests text rendering with no antialiasing",
WIDTH, HEIGHT,
@ -99,7 +99,7 @@ draw (cairo_t *cr, int width, int height)
{
cairo_text_extents_t extents;
cairo_scaled_font_t * scaled_font;
static char black[] = "black", blue[] = "blue";
const char black[] = "black", blue[] = "blue";
/* We draw in the default black, so paint white first. */
cairo_save (cr);

View file

@ -35,7 +35,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"ft-text-vertical-layout-type1",
"Tests text rendering for vertical layout with Type1 fonts"
"\nCan fail if an incorrect font is loaded---need to bundle the desired font",
@ -101,7 +101,7 @@ draw (cairo_t *cr, int width, int height)
{
cairo_text_extents_t extents;
cairo_scaled_font_t * scaled_font;
static char text[] = "i-W";
const char text[] = "i-W";
double line_width, x, y;
line_width = cairo_get_line_width (cr);

View file

@ -35,7 +35,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"ft-text-vertical-layout-type3",
"Tests text rendering for vertical layout with TrueType fonts",
WIDTH, HEIGHT,
@ -100,7 +100,7 @@ draw (cairo_t *cr, int width, int height)
{
cairo_text_extents_t extents;
cairo_scaled_font_t * scaled_font;
static char text[] = "i-W";
const char text[] = "i-W";
double line_width, x, y;
line_width = cairo_get_line_width (cr);

View file

@ -28,7 +28,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"get-and-set",
"Tests calls to the most trivial cairo_get and cairo_set functions",
0, 0,
@ -49,7 +49,7 @@ typedef struct {
} settings_t;
/* Two sets of settings, no defaults */
settings_t settings[] = {
static const settings_t settings[] = {
{
CAIRO_OPERATOR_IN,
2.0,
@ -77,7 +77,7 @@ settings_t settings[] = {
};
static void
settings_set (cairo_t *cr, settings_t *settings)
settings_set (cairo_t *cr, const settings_t *settings)
{
cairo_set_operator (cr, settings->op);
cairo_set_tolerance (cr, settings->tolerance);
@ -114,7 +114,7 @@ settings_get (cairo_t *cr, settings_t *settings)
}
static int
settings_equal (settings_t *a, settings_t *b)
settings_equal (const settings_t *a, const settings_t *b)
{
return (a->op == b->op &&
a->tolerance == b->tolerance &&

View file

@ -28,7 +28,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"get-clip",
"Test cairo_copy_clip_rectangle_list and cairo_clip_extents",
0, 0,
@ -36,7 +36,8 @@ cairo_test_t test = {
};
static cairo_bool_t
check_count (const char *message, cairo_bool_t uses_clip_rects,
check_count (const cairo_test_context_t *ctx,
const char *message, cairo_bool_t uses_clip_rects,
cairo_rectangle_list_t *list, int expected)
{
if (!uses_clip_rects) {
@ -46,29 +47,29 @@ check_count (const char *message, cairo_bool_t uses_clip_rects,
return 1;
if (list->status == CAIRO_STATUS_CLIP_NOT_REPRESENTABLE)
return 1;
cairo_test_log ("Error: %s; cairo_copy_clip_rectangle_list unexpectedly got %d rectangles\n",
cairo_test_log (ctx, "Error: %s; cairo_copy_clip_rectangle_list unexpectedly got %d rectangles\n",
message, list->num_rectangles);
return 0;
}
if (list->status != CAIRO_STATUS_SUCCESS) {
cairo_test_log ("Error: %s; cairo_copy_clip_rectangle_list failed with \"%s\"\n",
cairo_test_log (ctx, "Error: %s; cairo_copy_clip_rectangle_list failed with \"%s\"\n",
message, cairo_status_to_string(list->status));
return 0;
}
if (list->num_rectangles == expected)
return 1;
cairo_test_log ("Error: %s; expected %d rectangles, got %d\n", message,
cairo_test_log (ctx, "Error: %s; expected %d rectangles, got %d\n", message,
expected, list->num_rectangles);
return 0;
}
static cairo_bool_t
check_unrepresentable (const char *message, cairo_rectangle_list_t *list)
check_unrepresentable (const cairo_test_context_t *ctx, const char *message, cairo_rectangle_list_t *list)
{
if (list->status != CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) {
cairo_test_log ("Error: %s; cairo_copy_clip_rectangle_list got unexpected result \"%s\"\n"
cairo_test_log (ctx, "Error: %s; cairo_copy_clip_rectangle_list got unexpected result \"%s\"\n"
" (we expected CAIRO_STATUS_CLIP_NOT_REPRESENTABLE)",
message, cairo_status_to_string(list->status));
return 0;
@ -77,7 +78,8 @@ check_unrepresentable (const char *message, cairo_rectangle_list_t *list)
}
static cairo_bool_t
check_rectangles_contain (const char *message, cairo_bool_t uses_clip_rects,
check_rectangles_contain (const cairo_test_context_t *ctx,
const char *message, cairo_bool_t uses_clip_rects,
cairo_rectangle_list_t *list,
double x, double y, double width, double height)
{
@ -91,20 +93,21 @@ check_rectangles_contain (const char *message, cairo_bool_t uses_clip_rects,
list->rectangles[i].width == width && list->rectangles[i].height == height)
return 1;
}
cairo_test_log ("Error: %s; rectangle list does not contain rectangle %f,%f,%f,%f\n",
cairo_test_log (ctx, "Error: %s; rectangle list does not contain rectangle %f,%f,%f,%f\n",
message, x, y, width, height);
return 0;
}
static cairo_bool_t
check_clip_extents (const char *message, cairo_t *cr,
check_clip_extents (const cairo_test_context_t *ctx,
const char *message, cairo_t *cr,
double x, double y, double width, double height)
{
double ext_x1, ext_y1, ext_x2, ext_y2;
cairo_clip_extents (cr, &ext_x1, &ext_y1, &ext_x2, &ext_y2);
if (ext_x1 == x && ext_y1 == y && ext_x2 == x + width && ext_y2 == y + height)
return 1;
cairo_test_log ("Error: %s; clip extents %f,%f,%f,%f should be %f,%f,%f,%f\n",
cairo_test_log (ctx, "Error: %s; clip extents %f,%f,%f,%f should be %f,%f,%f,%f\n",
message, ext_x1, ext_y1, ext_x2 - ext_x1, ext_y2 - ext_y1,
x, y, width, height);
return 0;
@ -113,6 +116,7 @@ check_clip_extents (const char *message, cairo_t *cr,
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
cairo_surface_t *surface;
cairo_t *cr2;
cairo_rectangle_list_t *rectangle_list;
@ -154,9 +158,9 @@ draw (cairo_t *cr, int width, int height)
return the surface rectangle. */
phase = "No clip set";
rectangle_list = cairo_copy_clip_rectangle_list (cr2);
if (!check_count (phase, uses_clip_rects, rectangle_list, 1) ||
!check_clip_extents (phase, cr2, 0, 0, 100, 100) ||
!check_rectangles_contain(phase, uses_clip_rects, rectangle_list, 0, 0, 100, 100)) {
if (!check_count (ctx, phase, uses_clip_rects, rectangle_list, 1) ||
!check_clip_extents (ctx, phase, cr2, 0, 0, 100, 100) ||
!check_rectangles_contain (ctx, phase, uses_clip_rects, rectangle_list, 0, 0, 100, 100)) {
cairo_rectangle_list_destroy (rectangle_list);
return CAIRO_TEST_FAILURE;
}
@ -168,9 +172,9 @@ draw (cairo_t *cr, int width, int height)
cairo_rectangle (cr2, 10, 10, 80, 80);
cairo_clip (cr2);
rectangle_list = cairo_copy_clip_rectangle_list (cr2);
if (!check_count (phase, uses_clip_rects, rectangle_list, 1) ||
!check_clip_extents (phase, cr2, 10, 10, 80, 80) ||
!check_rectangles_contain(phase, uses_clip_rects, rectangle_list, 10, 10, 80, 80)) {
if (!check_count (ctx, phase, uses_clip_rects, rectangle_list, 1) ||
!check_clip_extents (ctx, phase, cr2, 10, 10, 80, 80) ||
!check_rectangles_contain (ctx, phase, uses_clip_rects, rectangle_list, 10, 10, 80, 80)) {
cairo_rectangle_list_destroy (rectangle_list);
return CAIRO_TEST_FAILURE;
}
@ -182,7 +186,7 @@ draw (cairo_t *cr, int width, int height)
cairo_save (cr2);
cairo_clip (cr2);
rectangle_list = cairo_copy_clip_rectangle_list (cr2);
if (!check_count (phase, uses_clip_rects, rectangle_list, 0)) {
if (!check_count (ctx, phase, uses_clip_rects, rectangle_list, 0)) {
cairo_rectangle_list_destroy (rectangle_list);
return CAIRO_TEST_FAILURE;
}
@ -198,10 +202,10 @@ draw (cairo_t *cr, int width, int height)
cairo_rectangle (cr2, 15, 15, 10, 10);
cairo_clip (cr2);
rectangle_list = cairo_copy_clip_rectangle_list (cr2);
if (!check_count (phase, uses_clip_rects, rectangle_list, 2) ||
!check_clip_extents (phase, cr2, 15, 15, 10, 10) ||
!check_rectangles_contain(phase, uses_clip_rects, rectangle_list, 15, 15, 5, 5) ||
!check_rectangles_contain(phase, uses_clip_rects, rectangle_list, 20, 20, 5, 5)) {
if (!check_count (ctx, phase, uses_clip_rects, rectangle_list, 2) ||
!check_clip_extents (ctx, phase, cr2, 15, 15, 10, 10) ||
!check_rectangles_contain (ctx, phase, uses_clip_rects, rectangle_list, 15, 15, 5, 5) ||
!check_rectangles_contain (ctx, phase, uses_clip_rects, rectangle_list, 20, 20, 5, 5)) {
cairo_rectangle_list_destroy (rectangle_list);
return CAIRO_TEST_FAILURE;
}
@ -218,8 +222,8 @@ draw (cairo_t *cr, int width, int height)
cairo_clip (cr2);
rectangle_list = cairo_copy_clip_rectangle_list (cr2);
/* can't get this in one tight user-space rectangle */
if (!check_unrepresentable (phase, rectangle_list) ||
!check_clip_extents (phase, cr2, 0, 0, 100, 100)) {
if (!check_unrepresentable (ctx, phase, rectangle_list) ||
!check_clip_extents (ctx, phase, cr2, 0, 0, 100, 100)) {
cairo_rectangle_list_destroy (rectangle_list);
return CAIRO_TEST_FAILURE;
}
@ -232,9 +236,9 @@ draw (cairo_t *cr, int width, int height)
cairo_rectangle (cr2, 5, 5, 40, 40);
cairo_clip (cr2);
rectangle_list = cairo_copy_clip_rectangle_list (cr2);
if (!check_count (phase, uses_clip_rects, rectangle_list, 1) ||
!check_clip_extents (phase, cr2, 5, 5, 40, 40) ||
!check_rectangles_contain(phase, uses_clip_rects, rectangle_list, 5, 5, 40, 40)) {
if (!check_count (ctx, phase, uses_clip_rects, rectangle_list, 1) ||
!check_clip_extents (ctx, phase, cr2, 5, 5, 40, 40) ||
!check_rectangles_contain (ctx, phase, uses_clip_rects, rectangle_list, 5, 5, 40, 40)) {
cairo_rectangle_list_destroy (rectangle_list);
return CAIRO_TEST_FAILURE;
}
@ -249,9 +253,9 @@ draw (cairo_t *cr, int width, int height)
cairo_restore (cr2);
cairo_clip (cr2);
rectangle_list = cairo_copy_clip_rectangle_list (cr2);
if (!check_count (phase, uses_clip_rects, rectangle_list, 1) ||
!check_clip_extents (phase, cr2, 10, 10, 80, 80) ||
!check_rectangles_contain(phase, uses_clip_rects, rectangle_list, 10, 10, 80, 80)) {
if (!check_count (ctx, phase, uses_clip_rects, rectangle_list, 1) ||
!check_clip_extents (ctx, phase, cr2, 10, 10, 80, 80) ||
!check_rectangles_contain (ctx, phase, uses_clip_rects, rectangle_list, 10, 10, 80, 80)) {
cairo_rectangle_list_destroy (rectangle_list);
return CAIRO_TEST_FAILURE;
}
@ -266,7 +270,7 @@ draw (cairo_t *cr, int width, int height)
cairo_restore (cr2);
cairo_clip (cr2);
rectangle_list = cairo_copy_clip_rectangle_list (cr2);
if (!check_unrepresentable (phase, rectangle_list)) {
if (!check_unrepresentable (ctx, phase, rectangle_list)) {
cairo_rectangle_list_destroy (rectangle_list);
return CAIRO_TEST_FAILURE;
}

View file

@ -30,7 +30,7 @@
static cairo_test_draw_function_t draw;
cairo_test_t test = {
static const cairo_test_t test = {
"get-group-target",
"Test of both cairo_get_group_target and cairo_surface_get_device_offset",
SIZE, SIZE,

Some files were not shown because too many files have changed in this diff Show more