2004-10-26 14:38:43 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2004 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
|
* appear in supporting documentation, and that the name of
|
|
|
|
|
* Red Hat, Inc. not be used in advertising or publicity pertaining to
|
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
|
* permission. Red Hat, Inc. makes no representations about the
|
|
|
|
|
* suitability of this software for any purpose. It is provided "as
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
|
|
|
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
|
|
|
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Author: Carl D. Worth <cworth@cworth.org>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _CAIRO_TEST_H_
|
|
|
|
|
#define _CAIRO_TEST_H_
|
|
|
|
|
|
2006-08-30 22:56:36 -07:00
|
|
|
#include "cairo-boilerplate.h"
|
|
|
|
|
|
2008-09-03 16:38:03 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
2005-12-14 19:56:09 +00:00
|
|
|
CAIRO_BEGIN_DECLS
|
|
|
|
|
|
2005-09-01 02:14:31 +00:00
|
|
|
#if HAVE_STDINT_H
|
|
|
|
|
# include <stdint.h>
|
|
|
|
|
#elif HAVE_INTTYPES_H
|
|
|
|
|
# include <inttypes.h>
|
|
|
|
|
#elif HAVE_SYS_INT_TYPES_H
|
|
|
|
|
# include <sys/int_types.h>
|
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
|
typedef __int8 int8_t;
|
|
|
|
|
typedef unsigned __int8 uint8_t;
|
|
|
|
|
typedef __int16 int16_t;
|
|
|
|
|
typedef unsigned __int16 uint16_t;
|
|
|
|
|
typedef __int32 int32_t;
|
|
|
|
|
typedef unsigned __int32 uint32_t;
|
|
|
|
|
typedef __int64 int64_t;
|
|
|
|
|
typedef unsigned __int64 uint64_t;
|
|
|
|
|
# ifndef HAVE_UINT64_T
|
|
|
|
|
# define HAVE_UINT64_T 1
|
|
|
|
|
# endif
|
|
|
|
|
#else
|
|
|
|
|
#error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, \etc.)
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-09-09 17:06:21 -07:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
#define _USE_MATH_DEFINES
|
2009-02-09 23:39:38 -05:00
|
|
|
|
|
|
|
|
#include <float.h>
|
|
|
|
|
#define isnan(x) _isnan(x)
|
|
|
|
|
|
2006-09-09 17:06:21 -07:00
|
|
|
#endif
|
|
|
|
|
|
2012-10-16 17:09:42 +02:00
|
|
|
#if HAVE_FENV_H
|
|
|
|
|
# include <fenv.h>
|
|
|
|
|
#endif
|
|
|
|
|
/* The following are optional in C99, so define them if they aren't yet */
|
|
|
|
|
#ifndef FE_DIVBYZERO
|
|
|
|
|
#define FE_DIVBYZERO 0
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef FE_INEXACT
|
|
|
|
|
#define FE_INEXACT 0
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef FE_INVALID
|
|
|
|
|
#define FE_INVALID 0
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef FE_OVERFLOW
|
|
|
|
|
#define FE_OVERFLOW 0
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef FE_UNDERFLOW
|
|
|
|
|
#define FE_UNDERFLOW 0
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-09-09 17:06:21 -07:00
|
|
|
#include <math.h>
|
|
|
|
|
|
2009-02-11 15:24:20 -05:00
|
|
|
static inline double
|
|
|
|
|
cairo_test_NaN (void)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
/* MSVC strtod("NaN", NULL) returns 0.0 */
|
|
|
|
|
union {
|
|
|
|
|
uint32_t i[2];
|
|
|
|
|
double d;
|
|
|
|
|
} nan = {{0xffffffff, 0x7fffffff}};
|
|
|
|
|
return nan.d;
|
|
|
|
|
#else
|
|
|
|
|
return strtod("NaN", NULL);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-16 16:48:18 +01:00
|
|
|
#ifndef MIN
|
|
|
|
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef MAX
|
|
|
|
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef ARRAY_LENGTH
|
|
|
|
|
#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0])))
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-07-13 14:31:43 +01:00
|
|
|
#define CAIRO_TEST_OUTPUT_DIR "output"
|
|
|
|
|
|
|
|
|
|
#define CAIRO_TEST_LOG_SUFFIX ".log"
|
|
|
|
|
|
2010-06-12 16:22:54 +02:00
|
|
|
#define CAIRO_TEST_FONT_FAMILY "DejaVu"
|
2010-06-12 16:20:37 +02:00
|
|
|
|
2009-07-13 14:31:43 +01:00
|
|
|
/* What is a fail and what isn't?
|
|
|
|
|
* When running the test suite we want to detect unexpected output. This
|
|
|
|
|
* can be caused by a change we have made to cairo itself, or a change
|
|
|
|
|
* in our environment. To capture this we classify the expected output into 3
|
|
|
|
|
* classes:
|
|
|
|
|
*
|
|
|
|
|
* REF -- Perfect output.
|
|
|
|
|
* Might be different for each backend, due to slight implementation
|
|
|
|
|
* differences.
|
|
|
|
|
*
|
|
|
|
|
* NEW -- A new failure. We have uncovered a bug within cairo and have
|
|
|
|
|
* recorded the current failure (along with the expected output
|
|
|
|
|
* if possible!) so we can detect any changes in our attempt to
|
|
|
|
|
* fix the bug.
|
|
|
|
|
*
|
|
|
|
|
* XFAIL -- An external failure. We believe the cairo output is perfect,
|
|
|
|
|
* but an external renderer is causing gross failure.
|
|
|
|
|
* (We also use this to capture current WONTFIX issues within cairo,
|
|
|
|
|
* such as overflow in internal coordinates, so as not to distract
|
|
|
|
|
* us when regression testing.)
|
|
|
|
|
*
|
|
|
|
|
* If no REF is given for a test, then it is assumed to be XFAIL.
|
|
|
|
|
*/
|
|
|
|
|
#define CAIRO_TEST_REF_SUFFIX ".ref"
|
|
|
|
|
#define CAIRO_TEST_XFAIL_SUFFIX ".xfail"
|
|
|
|
|
#define CAIRO_TEST_NEW_SUFFIX ".new"
|
|
|
|
|
|
|
|
|
|
#define CAIRO_TEST_OUT_SUFFIX ".out"
|
|
|
|
|
#define CAIRO_TEST_DIFF_SUFFIX ".diff"
|
|
|
|
|
|
|
|
|
|
#define CAIRO_TEST_PNG_EXTENSION ".png"
|
|
|
|
|
#define CAIRO_TEST_OUT_PNG CAIRO_TEST_OUT_SUFFIX CAIRO_TEST_PNG_EXTENSION
|
|
|
|
|
#define CAIRO_TEST_REF_PNG CAIRO_TEST_REF_SUFFIX CAIRO_TEST_PNG_EXTENSION
|
|
|
|
|
#define CAIRO_TEST_DIFF_PNG CAIRO_TEST_DIFF_SUFFIX CAIRO_TEST_PNG_EXTENSION
|
|
|
|
|
|
2004-10-26 14:38:43 +00:00
|
|
|
typedef enum cairo_test_status {
|
|
|
|
|
CAIRO_TEST_SUCCESS = 0,
|
2008-10-16 13:47:27 +01:00
|
|
|
CAIRO_TEST_NO_MEMORY,
|
2005-07-14 12:20:42 +00:00
|
|
|
CAIRO_TEST_FAILURE,
|
2009-07-13 14:31:43 +01:00
|
|
|
CAIRO_TEST_NEW,
|
|
|
|
|
CAIRO_TEST_XFAILURE,
|
2010-06-11 09:12:16 +01:00
|
|
|
CAIRO_TEST_ERROR,
|
2008-08-12 13:33:04 +01:00
|
|
|
CAIRO_TEST_CRASHED,
|
|
|
|
|
CAIRO_TEST_UNTESTED = 77 /* match automake's skipped exit status */
|
2004-10-26 14:38:43 +00:00
|
|
|
} cairo_test_status_t;
|
|
|
|
|
|
2008-08-11 21:12:45 +01:00
|
|
|
typedef struct _cairo_test_context cairo_test_context_t;
|
|
|
|
|
typedef struct _cairo_test cairo_test_t;
|
|
|
|
|
|
2008-09-03 16:38:03 +01:00
|
|
|
typedef cairo_test_status_t
|
|
|
|
|
(cairo_test_preamble_function_t) (cairo_test_context_t *ctx);
|
|
|
|
|
|
|
|
|
|
typedef cairo_test_status_t
|
|
|
|
|
(cairo_test_draw_function_t) (cairo_t *cr, int width, int height);
|
2006-07-11 22:19:39 -04:00
|
|
|
|
2008-08-11 21:12:45 +01:00
|
|
|
struct _cairo_test {
|
2006-07-11 22:19:39 -04:00
|
|
|
const char *name;
|
|
|
|
|
const char *description;
|
2008-09-03 16:38:03 +01:00
|
|
|
const char *keywords;
|
|
|
|
|
const char *requirements;
|
2009-06-27 17:53:18 +01:00
|
|
|
double width;
|
|
|
|
|
double height;
|
2008-09-03 16:38:03 +01:00
|
|
|
cairo_test_preamble_function_t *preamble;
|
2006-07-11 22:19:39 -04:00
|
|
|
cairo_test_draw_function_t *draw;
|
2008-08-11 21:12:45 +01:00
|
|
|
};
|
2004-10-26 14:38:43 +00:00
|
|
|
|
2005-09-13 12:11:32 +00:00
|
|
|
/* The standard test interface which works by examining result image.
|
|
|
|
|
*
|
2008-09-03 16:38:03 +01:00
|
|
|
* CAIRO_TEST() constructs a test which will be called once before (the
|
|
|
|
|
* preamble callback), and then once for each testable backend (the draw
|
|
|
|
|
* callback). The following checks will be performed for each backend:
|
|
|
|
|
*
|
|
|
|
|
* 1) If preamble() returns CAIRO_TEST_UNTESTED, the test is skipped.
|
2005-09-13 12:11:32 +00:00
|
|
|
*
|
2008-09-03 16:38:03 +01:00
|
|
|
* 2) If preamble() does not return CAIRO_TEST_SUCCESS, the test fails.
|
|
|
|
|
*
|
|
|
|
|
* 3) If draw() does not return CAIRO_TEST_SUCCESS then this backend
|
2005-09-13 12:11:32 +00:00
|
|
|
* fails.
|
|
|
|
|
*
|
2008-09-03 16:38:03 +01:00
|
|
|
* 4) Otherwise, if cairo_status(cr) indicates an error then this
|
2005-09-13 12:11:32 +00:00
|
|
|
* backend fails.
|
|
|
|
|
*
|
2008-09-03 16:38:03 +01:00
|
|
|
* 5) Otherwise, if the image size is 0, then this backend passes.
|
2005-09-13 12:11:32 +00:00
|
|
|
*
|
2008-09-03 16:38:03 +01:00
|
|
|
* 6) Otherwise, if every channel of every pixel exactly matches the
|
2005-09-13 12:11:32 +00:00
|
|
|
* reference image then this backend passes. If not, this backend
|
|
|
|
|
* fails.
|
|
|
|
|
*
|
|
|
|
|
* The overall test result is PASS if and only if there is at least
|
|
|
|
|
* one backend that is tested and if all tested backend pass according
|
|
|
|
|
* to the four criteria above.
|
|
|
|
|
*/
|
2008-09-03 16:38:03 +01:00
|
|
|
#define CAIRO_TEST(name, description, keywords, requirements, width, height, preamble, draw) \
|
|
|
|
|
void _register_##name (void); \
|
|
|
|
|
void _register_##name (void) { \
|
2010-05-03 20:39:34 +01:00
|
|
|
static cairo_test_t test = { \
|
2011-10-28 15:04:59 +02:00
|
|
|
#name, description, \
|
2008-09-03 16:38:03 +01:00
|
|
|
keywords, requirements, \
|
|
|
|
|
width, height, \
|
|
|
|
|
preamble, draw \
|
|
|
|
|
}; \
|
|
|
|
|
cairo_test_register (&test); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2010-05-03 20:39:34 +01:00
|
|
|
cairo_test_register (cairo_test_t *test);
|
2008-08-11 21:12:45 +01:00
|
|
|
|
|
|
|
|
/* The full context for the test.
|
2008-09-03 16:38:03 +01:00
|
|
|
* For ordinary tests (using the CAIRO_TEST()->draw interface) 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.
|
|
|
|
|
*
|
|
|
|
|
* In contrast, for the preamble phase the context is passed as the only
|
|
|
|
|
* parameter.
|
2008-08-11 21:12:45 +01:00
|
|
|
*/
|
|
|
|
|
struct _cairo_test_context {
|
|
|
|
|
const cairo_test_t *test;
|
|
|
|
|
const char *test_name;
|
|
|
|
|
|
|
|
|
|
FILE *log_file;
|
2011-09-15 14:07:00 +01:00
|
|
|
const char *output;
|
2008-08-11 21:12:45 +01:00
|
|
|
const char *srcdir; /* directory containing sources and input data */
|
|
|
|
|
const char *refdir; /* directory containing reference images */
|
|
|
|
|
|
2008-08-18 12:53:43 +01:00
|
|
|
char *ref_name; /* cache of the current reference image */
|
|
|
|
|
cairo_surface_t *ref_image;
|
|
|
|
|
cairo_surface_t *ref_image_flattened;
|
|
|
|
|
|
2008-08-11 21:12:45 +01:00
|
|
|
size_t num_targets;
|
|
|
|
|
cairo_bool_t limited_targets;
|
2009-06-12 12:32:51 +01:00
|
|
|
const cairo_boilerplate_target_t **targets_to_test;
|
2008-09-03 16:38:03 +01:00
|
|
|
cairo_bool_t own_targets;
|
2008-08-11 21:12:45 +01:00
|
|
|
|
2008-10-16 13:47:27 +01:00
|
|
|
int malloc_failure;
|
|
|
|
|
int last_fault_count;
|
|
|
|
|
|
2009-06-28 20:56:33 +01:00
|
|
|
int timeout;
|
2008-08-11 21:12:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
2005-04-14 10:02:58 +00:00
|
|
|
|
2005-09-13 12:11:32 +00:00
|
|
|
/* Print a message to the log file, ala printf. */
|
|
|
|
|
void
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_test_log (const cairo_test_context_t *ctx,
|
|
|
|
|
const char *fmt, ...) CAIRO_BOILERPLATE_PRINTF_FORMAT(2, 3);
|
2008-09-03 16:38:03 +01:00
|
|
|
void
|
|
|
|
|
cairo_test_logv (const cairo_test_context_t *ctx,
|
|
|
|
|
const char *fmt, va_list ap) CAIRO_BOILERPLATE_PRINTF_FORMAT(2, 0);
|
2005-09-13 12:11:32 +00:00
|
|
|
|
|
|
|
|
/* Helper functions that take care of finding source images even when
|
2008-09-03 16:38:03 +01:00
|
|
|
* building in a non-srcdir manner, (i.e. the tests will be run in a
|
2005-09-13 12:11:32 +00:00
|
|
|
* directory that is different from the one where the source image
|
|
|
|
|
* exists). */
|
2005-07-18 08:04:16 +00:00
|
|
|
cairo_surface_t *
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_test_create_surface_from_png (const cairo_test_context_t *ctx,
|
|
|
|
|
const char *filename);
|
2005-07-18 08:04:16 +00:00
|
|
|
|
2005-01-26 13:41:55 +00:00
|
|
|
cairo_pattern_t *
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_test_create_pattern_from_png (const cairo_test_context_t *ctx,
|
|
|
|
|
const char *filename);
|
2005-01-26 13:41:55 +00:00
|
|
|
|
2008-10-16 13:47:27 +01:00
|
|
|
void
|
2006-04-25 01:56:51 -07:00
|
|
|
cairo_test_paint_checkered (cairo_t *cr);
|
|
|
|
|
|
2008-01-28 21:24:56 -08:00
|
|
|
#define CAIRO_TEST_DOUBLE_EQUALS(a,b) (fabs((a)-(b)) < 0.00001)
|
|
|
|
|
|
2008-01-10 13:04:52 +00:00
|
|
|
cairo_bool_t
|
|
|
|
|
cairo_test_is_target_enabled (const cairo_test_context_t *ctx,
|
|
|
|
|
const char *target);
|
|
|
|
|
|
2008-09-03 16:38:03 +01:00
|
|
|
char *
|
|
|
|
|
cairo_test_get_name (const cairo_test_t *test);
|
|
|
|
|
|
2008-10-16 13:47:27 +01:00
|
|
|
cairo_bool_t
|
|
|
|
|
cairo_test_malloc_failure (const cairo_test_context_t *ctx,
|
|
|
|
|
cairo_status_t status);
|
|
|
|
|
|
2008-10-16 17:19:12 +01:00
|
|
|
cairo_test_status_t
|
|
|
|
|
cairo_test_status_from_status (const cairo_test_context_t *ctx,
|
|
|
|
|
cairo_status_t status);
|
|
|
|
|
|
2008-09-28 13:34:50 +01:00
|
|
|
char *
|
2009-07-13 14:31:43 +01:00
|
|
|
cairo_test_reference_filename (const cairo_test_context_t *ctx,
|
|
|
|
|
const char *base_name,
|
|
|
|
|
const char *test_name,
|
|
|
|
|
const char *target_name,
|
|
|
|
|
const char *base_target_name,
|
|
|
|
|
const char *format,
|
|
|
|
|
const char *suffix,
|
|
|
|
|
const char *extension);
|
2008-09-28 13:34:50 +01:00
|
|
|
|
|
|
|
|
cairo_surface_t *
|
|
|
|
|
cairo_test_get_reference_image (cairo_test_context_t *ctx,
|
|
|
|
|
const char *filename,
|
|
|
|
|
cairo_bool_t flatten);
|
|
|
|
|
|
2005-12-14 19:56:09 +00:00
|
|
|
CAIRO_END_DECLS
|
|
|
|
|
|
2004-10-26 14:38:43 +00:00
|
|
|
#endif
|