[check] Filter programlistings for check-doc-syntax.sh
[cairo/haiku.git] / test / cairo-test.h
blob6b6b373be9376abce5bca0f3ed8887be48da868f
1 /*
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"
32 CAIRO_BEGIN_DECLS
34 #if HAVE_STDINT_H
35 # include <stdint.h>
36 #elif HAVE_INTTYPES_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
51 # endif
52 #else
53 #error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, \etc.)
54 #endif
56 #ifdef _MSC_VER
57 #define _USE_MATH_DEFINES
58 #endif
60 #include <math.h>
62 typedef enum cairo_test_status {
63 CAIRO_TEST_SUCCESS = 0,
64 CAIRO_TEST_FAILURE,
65 CAIRO_TEST_UNTESTED,
66 CAIRO_TEST_CRASHED
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 {
72 const char *name;
73 const char *description;
74 int width;
75 int height;
76 cairo_test_draw_function_t *draw;
77 } cairo_test_t;
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
83 * each backend:
85 * 1) If draw() does not return CAIRO_TEST_SUCCESS then this backend
86 * fails.
88 * 2) Otherwise, if cairo_status(cr) indicates an error then this
89 * backend fails.
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
95 * fails.
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.
101 cairo_test_status_t
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.) */
112 void
113 cairo_test_init (const char *test_name);
115 /* Finalize test-specific resource. */
116 void
117 cairo_test_fini (void);
119 /* Print a message to the log file, ala printf. */
120 void
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
126 * exists). */
127 cairo_surface_t *
128 cairo_test_create_surface_from_png (const char *filename);
130 cairo_pattern_t *
131 cairo_test_create_pattern_from_png (const char *filename);
133 cairo_status_t
134 cairo_test_paint_checkered (cairo_t *cr);
136 #define CAIRO_TEST_DOUBLE_EQUALS(a,b) (fabs((a)-(b)) < 0.00001)
138 CAIRO_END_DECLS
140 #endif