2 * Copyright © 2004 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Red Hat, Inc. makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: Carl D. Worth <cworth@cworth.org>
26 #ifndef _CAIRO_TEST_H_
27 #define _CAIRO_TEST_H_
29 #define CAIRO_BOILERPLATE_LOG(...) cairo_test_log (__VA_ARGS__)
30 #include "cairo-boilerplate.h"
37 # include <inttypes.h>
38 #elif HAVE_SYS_INT_TYPES_H
39 # include <sys/int_types.h>
40 #elif defined(_MSC_VER)
41 typedef __int8
int8_t;
42 typedef unsigned __int8
uint8_t;
43 typedef __int16
int16_t;
44 typedef unsigned __int16
uint16_t;
45 typedef __int32
int32_t;
46 typedef unsigned __int32
uint32_t;
47 typedef __int64
int64_t;
48 typedef unsigned __int64
uint64_t;
49 # ifndef HAVE_UINT64_T
50 # define HAVE_UINT64_T 1
53 #error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, \etc.)
57 #define _USE_MATH_DEFINES
62 typedef enum cairo_test_status
{
63 CAIRO_TEST_SUCCESS
= 0,
67 } cairo_test_status_t
;
69 typedef cairo_test_status_t (cairo_test_draw_function_t
) (cairo_t
*cr
, int width
, int height
);
71 typedef struct _cairo_test
{
73 const char *description
;
76 cairo_test_draw_function_t
*draw
;
79 /* The standard test interface which works by examining result image.
81 * cairo_test() accepts a test struct which will be called once for
82 * each testable backend. The following checks will be performed for
85 * 1) If draw() does not return CAIRO_TEST_SUCCESS then this backend
88 * 2) Otherwise, if cairo_status(cr) indicates an error then this
91 * 3) Otherwise, if the image size is 0, then this backend passes.
93 * 4) Otherwise, if every channel of every pixel exactly matches the
94 * reference image then this backend passes. If not, this backend
97 * The overall test result is PASS if and only if there is at least
98 * one backend that is tested and if all tested backend pass according
99 * to the four criteria above.
102 cairo_test (cairo_test_t
*test
);
104 /* cairo_test_init(), cairo_test_log(), and cairo_test_fini() exist to
105 * help in writing tests for which cairo_test() is not appropriate for
106 * one reason or another. For example, some tests might not be doing
107 * any drawing at all, or may need to create their own cairo_t rather
108 * than be handed one by cairo_test.
111 /* Initialize test-specific resources, (log files, etc.) */
113 cairo_test_init (const char *test_name
);
115 /* Finalize test-specific resource. */
117 cairo_test_fini (void);
119 /* Print a message to the log file, ala printf. */
121 cairo_test_log (const char *fmt
, ...) CAIRO_BOILERPLATE_PRINTF_FORMAT(1, 2);
123 /* Helper functions that take care of finding source images even when
124 * building in a non-srcdir manner, (ie. the tests will be run in a
125 * directory that is different from the one where the source image
128 cairo_test_create_surface_from_png (const char *filename
);
131 cairo_test_create_pattern_from_png (const char *filename
);
134 cairo_test_paint_checkered (cairo_t
*cr
);
136 #define CAIRO_TEST_DOUBLE_EQUALS(a,b) (fabs((a)-(b)) < 0.00001)