1 /* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
3 * Copyright © 2005 Mozilla Corporation, Inc.
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without
7 * fee, provided that the above copyright notice appear in all copies
8 * and that both that copyright notice and this permission notice
9 * appear in supporting documentation, and that the name of
10 * Mozilla Corporation not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior
12 * permission. Mozilla Corporation makes no representations about the
13 * suitability of this software for any purpose. It is provided "as
14 * is" without express or implied warranty.
16 * MOZILLA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL MOZILLA CORPORATION BE LIABLE FOR ANY SPECIAL,
19 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
22 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Author: Vladimir Vukicevic <vladimir@pobox.com>
28 #include "cairo-test.h"
30 static cairo_test_draw_function_t draw
;
34 "Tests calls to pattern getter functions",
39 #define CHECK_SUCCESS do { if (status) return CAIRO_TEST_FAILURE; } while (0)
42 double_buf_equal (double *a
, double *b
, int nc
)
45 for (i
= 0; i
< nc
; i
++) {
46 if (!CAIRO_TEST_DOUBLE_EQUALS(a
[i
],b
[i
])) {
47 cairo_test_log ("Error: doubles not equal: %g, %g\n",
55 static cairo_test_status_t
56 draw (cairo_t
*cr
, int width
, int height
)
58 cairo_status_t status
;
61 /* Test pattern_get_rgba */
64 pat
= cairo_pattern_create_rgba (0.2, 0.3, 0.4, 0.5);
66 status
= cairo_pattern_get_rgba (pat
, &r
, &g
, &b
, &a
);
69 if (!CAIRO_TEST_DOUBLE_EQUALS(r
,0.2) ||
70 !CAIRO_TEST_DOUBLE_EQUALS(g
,0.3) ||
71 !CAIRO_TEST_DOUBLE_EQUALS(b
,0.4) ||
72 !CAIRO_TEST_DOUBLE_EQUALS(a
,0.5)) {
73 cairo_test_log ("Error: cairo_pattern_get_rgba returned unexepcted results: %g, %g, %g, %g\n",
75 return CAIRO_TEST_FAILURE
;
78 cairo_pattern_destroy (pat
);
81 /* Test pattern_get_surface */
83 cairo_surface_t
*surf
;
85 pat
= cairo_pattern_create_for_surface (cairo_get_target (cr
));
87 status
= cairo_pattern_get_surface (pat
, &surf
);
90 if (surf
!= cairo_get_target (cr
)) {
91 cairo_test_log ("Error: cairo_pattern_get_resurface returned wrong surface\n");
92 return CAIRO_TEST_FAILURE
;
95 cairo_pattern_destroy (pat
);
98 /* Test get_color_stops & linear_get_points */
101 double x0
, y0
, x1
, y1
;
102 double expected_values
[15] = { 0.0, 0.2, 0.4, 0.2, 1.0,
103 0.5, 0.4, 0.5, 0.2, 0.5,
104 1.0, 0.2, 0.4, 0.5, 0.2 };
107 pat
= cairo_pattern_create_linear (1.0, 2.0, 3.0, 4.0);
109 for (i
= 0; i
< 3; i
++) {
110 cairo_pattern_add_color_stop_rgba (pat
,
111 expected_values
[i
*5+0],
112 expected_values
[i
*5+1],
113 expected_values
[i
*5+2],
114 expected_values
[i
*5+3],
115 expected_values
[i
*5+4]);
118 status
= cairo_pattern_get_linear_points (pat
, &x0
, &y0
, &x1
, &y1
);
121 if (!CAIRO_TEST_DOUBLE_EQUALS(x0
,1.0) ||
122 !CAIRO_TEST_DOUBLE_EQUALS(y0
,2.0) ||
123 !CAIRO_TEST_DOUBLE_EQUALS(x1
,3.0) ||
124 !CAIRO_TEST_DOUBLE_EQUALS(y1
,4.0))
125 return CAIRO_TEST_FAILURE
;
127 status
= cairo_pattern_get_color_stop_count (pat
, &i
);
131 return CAIRO_TEST_FAILURE
;
133 for (i
= 0; i
< 3; i
++) {
134 status
= cairo_pattern_get_color_stop_rgba (pat
, i
,
143 status
= cairo_pattern_get_color_stop_rgba (pat
, 5, NULL
, NULL
, NULL
, NULL
, NULL
);
144 if (status
!= CAIRO_STATUS_INVALID_INDEX
)
145 return CAIRO_TEST_FAILURE
;
147 if (!double_buf_equal (new_buf
, expected_values
, sizeof(expected_values
)/sizeof(double)) != 0)
148 return CAIRO_TEST_FAILURE
;
150 cairo_pattern_destroy (pat
);
153 /* Test radial_get_circles */
155 double a
, b
, c
, d
, e
, f
;
156 pat
= cairo_pattern_create_radial (1, 2, 3,
159 status
= cairo_pattern_get_radial_circles (pat
, &a
, &b
, &c
, &d
, &e
, &f
);
162 if (!CAIRO_TEST_DOUBLE_EQUALS(a
,1.0) ||
163 !CAIRO_TEST_DOUBLE_EQUALS(b
,2.0) ||
164 !CAIRO_TEST_DOUBLE_EQUALS(c
,3.0) ||
165 !CAIRO_TEST_DOUBLE_EQUALS(d
,4.0) ||
166 !CAIRO_TEST_DOUBLE_EQUALS(e
,5.0) ||
167 !CAIRO_TEST_DOUBLE_EQUALS(f
,6.0))
168 return CAIRO_TEST_FAILURE
;
170 cairo_pattern_destroy (pat
);
173 cairo_set_source_rgb (cr
, 0, 1, 0);
176 return CAIRO_TEST_SUCCESS
;
182 return cairo_test (&test
);