#ifndef _CAIRO_TEST_H_
#define _CAIRO_TEST_H_
#include "cairo-boilerplate.h"
#include <stdarg.h>
CAIRO_BEGIN_DECLS
#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
#ifdef _MSC_VER
#define _USE_MATH_DEFINES
#include <float.h>
#define isnan(x) _isnan(x)
#endif
#include <math.h>
static inline double
cairo_test_NaN (void)
{
#ifdef _MSC_VER
union {
uint32_t i[2];
double d;
} nan = {{0xffffffff, 0x7fffffff}};
return nan.d;
#else
return strtod("NaN", NULL);
#endif
}
#define CAIRO_TEST_OUTPUT_DIR "output"
#define CAIRO_TEST_LOG_SUFFIX ".log"
#define CAIRO_TEST_FONT_FAMILY "DejaVu"
#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
typedef enum cairo_test_status {
CAIRO_TEST_SUCCESS = 0,
CAIRO_TEST_NO_MEMORY,
CAIRO_TEST_FAILURE,
CAIRO_TEST_NEW,
CAIRO_TEST_XFAILURE,
CAIRO_TEST_ERROR,
CAIRO_TEST_CRASHED,
CAIRO_TEST_UNTESTED = 77
} 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_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);
struct _cairo_test {
struct _cairo_test *next;
const char *name;
const char *description;
const char *keywords;
const char *requirements;
double width;
double height;
cairo_test_preamble_function_t *preamble;
cairo_test_draw_function_t *draw;
};
#define CAIRO_TEST(name, description, keywords, requirements, width, height, preamble, draw) \
void _register_##name (void); \
void _register_##name (void) { \
static cairo_test_t test = { \
NULL, #name, description, \
keywords, requirements, \
width, height, \
preamble, draw \
}; \
cairo_test_register (&test); \
}
void
cairo_test_register (cairo_test_t *test);
struct _cairo_test_context {
const cairo_test_t *test;
const char *test_name;
FILE *log_file;
const char *srcdir;
const char *refdir;
char *ref_name;
cairo_surface_t *ref_image;
cairo_surface_t *ref_image_flattened;
size_t num_targets;
cairo_bool_t limited_targets;
const cairo_boilerplate_target_t **targets_to_test;
cairo_bool_t own_targets;
int malloc_failure;
int last_fault_count;
int timeout;
int thread;
};
const cairo_test_context_t *
cairo_test_get_context (cairo_t *cr);
void
cairo_test_log (const cairo_test_context_t *ctx,
const char *fmt, ...) CAIRO_BOILERPLATE_PRINTF_FORMAT(2, 3);
void
cairo_test_logv (const cairo_test_context_t *ctx,
const char *fmt, va_list ap) CAIRO_BOILERPLATE_PRINTF_FORMAT(2, 0);
void
cairo_test_log_path (const cairo_test_context_t *ctx,
const cairo_path_t *path);
cairo_surface_t *
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 cairo_test_context_t *ctx,
const char *filename);
void
cairo_test_paint_checkered (cairo_t *cr);
#define CAIRO_TEST_DOUBLE_EQUALS(a,b) (fabs((a)-(b)) < 0.00001)
cairo_bool_t
cairo_test_is_target_enabled (const cairo_test_context_t *ctx,
const char *target);
char *
cairo_test_get_name (const cairo_test_t *test);
cairo_bool_t
cairo_test_malloc_failure (const cairo_test_context_t *ctx,
cairo_status_t status);
cairo_test_status_t
cairo_test_status_from_status (const cairo_test_context_t *ctx,
cairo_status_t status);
char *
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);
cairo_surface_t *
cairo_test_get_reference_image (cairo_test_context_t *ctx,
const char *filename,
cairo_bool_t flatten);
CAIRO_END_DECLS
#endif