* MoonlightTypeConverter.cs: Convert CacheMode's from strings.
[moon.git] / cairo / test / pattern-getters.c
bloba42d47b5e67aba60f9c02cea4189c5e49c738684
1 /* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
2 /*
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>
27 #include <stdlib.h>
28 #include "cairo-test.h"
30 static cairo_test_draw_function_t draw;
32 static const cairo_test_t test = {
33 "pattern-getters",
34 "Tests calls to pattern getter functions",
35 1, 1,
36 draw
39 #define CHECK_SUCCESS do { if (status) return CAIRO_TEST_FAILURE; } while (0)
41 static int
42 double_buf_equal (const cairo_test_context_t *ctx, double *a, double *b, int nc)
44 int i;
45 for (i = 0; i < nc; i++) {
46 if (!CAIRO_TEST_DOUBLE_EQUALS(a[i],b[i])) {
47 cairo_test_log (ctx, "Error: doubles not equal: %g, %g\n",
48 a[i], b[i]);
49 return 0;
52 return 1;
55 static cairo_test_status_t
56 draw (cairo_t *cr, int width, int height)
58 const cairo_test_context_t *ctx = cairo_test_get_context (cr);
59 cairo_status_t status;
60 cairo_pattern_t *pat;
62 /* Test pattern_get_rgba */
64 double r, g, b, a;
65 pat = cairo_pattern_create_rgba (0.2, 0.3, 0.4, 0.5);
67 status = cairo_pattern_get_rgba (pat, &r, &g, &b, &a);
68 CHECK_SUCCESS;
70 if (!CAIRO_TEST_DOUBLE_EQUALS(r,0.2) ||
71 !CAIRO_TEST_DOUBLE_EQUALS(g,0.3) ||
72 !CAIRO_TEST_DOUBLE_EQUALS(b,0.4) ||
73 !CAIRO_TEST_DOUBLE_EQUALS(a,0.5)) {
74 cairo_test_log (ctx, "Error: cairo_pattern_get_rgba returned unexepcted results: %g, %g, %g, %g\n",
75 r, g, b, a);
76 return CAIRO_TEST_FAILURE;
79 cairo_pattern_destroy (pat);
82 /* Test pattern_get_surface */
84 cairo_surface_t *surf;
86 pat = cairo_pattern_create_for_surface (cairo_get_target (cr));
88 status = cairo_pattern_get_surface (pat, &surf);
89 CHECK_SUCCESS;
91 if (surf != cairo_get_target (cr)) {
92 cairo_test_log (ctx, "Error: cairo_pattern_get_resurface returned wrong surface\n");
93 return CAIRO_TEST_FAILURE;
96 cairo_pattern_destroy (pat);
99 /* Test get_color_stops & linear_get_points */
101 int i;
102 double x0, y0, x1, y1;
103 double expected_values[15] = { 0.0, 0.2, 0.4, 0.2, 1.0,
104 0.5, 0.4, 0.5, 0.2, 0.5,
105 1.0, 0.2, 0.4, 0.5, 0.2 };
106 double new_buf[15];
108 pat = cairo_pattern_create_linear (1.0, 2.0, 3.0, 4.0);
110 for (i = 0; i < 3; i++) {
111 cairo_pattern_add_color_stop_rgba (pat,
112 expected_values[i*5+0],
113 expected_values[i*5+1],
114 expected_values[i*5+2],
115 expected_values[i*5+3],
116 expected_values[i*5+4]);
119 status = cairo_pattern_get_linear_points (pat, &x0, &y0, &x1, &y1);
120 CHECK_SUCCESS;
122 if (!CAIRO_TEST_DOUBLE_EQUALS(x0,1.0) ||
123 !CAIRO_TEST_DOUBLE_EQUALS(y0,2.0) ||
124 !CAIRO_TEST_DOUBLE_EQUALS(x1,3.0) ||
125 !CAIRO_TEST_DOUBLE_EQUALS(y1,4.0))
126 return CAIRO_TEST_FAILURE;
128 status = cairo_pattern_get_color_stop_count (pat, &i);
129 CHECK_SUCCESS;
131 if (i != 3)
132 return CAIRO_TEST_FAILURE;
134 for (i = 0; i < 3; i++) {
135 status = cairo_pattern_get_color_stop_rgba (pat, i,
136 &new_buf[i*5+0],
137 &new_buf[i*5+1],
138 &new_buf[i*5+2],
139 &new_buf[i*5+3],
140 &new_buf[i*5+4]);
141 CHECK_SUCCESS;
144 status = cairo_pattern_get_color_stop_rgba (pat, 5, NULL, NULL, NULL, NULL, NULL);
145 if (status != CAIRO_STATUS_INVALID_INDEX)
146 return CAIRO_TEST_FAILURE;
148 if (!double_buf_equal (ctx, new_buf, expected_values, sizeof(expected_values)/sizeof(double)) != 0)
149 return CAIRO_TEST_FAILURE;
151 cairo_pattern_destroy (pat);
154 /* Test radial_get_circles */
156 double a, b, c, d, e, f;
157 pat = cairo_pattern_create_radial (1, 2, 3,
158 4, 5, 6);
160 status = cairo_pattern_get_radial_circles (pat, &a, &b, &c, &d, &e, &f);
161 CHECK_SUCCESS;
163 if (!CAIRO_TEST_DOUBLE_EQUALS(a,1.0) ||
164 !CAIRO_TEST_DOUBLE_EQUALS(b,2.0) ||
165 !CAIRO_TEST_DOUBLE_EQUALS(c,3.0) ||
166 !CAIRO_TEST_DOUBLE_EQUALS(d,4.0) ||
167 !CAIRO_TEST_DOUBLE_EQUALS(e,5.0) ||
168 !CAIRO_TEST_DOUBLE_EQUALS(f,6.0))
169 return CAIRO_TEST_FAILURE;
171 cairo_pattern_destroy (pat);
174 cairo_set_source_rgb (cr, 0, 1, 0);
175 cairo_paint (cr);
177 return CAIRO_TEST_SUCCESS;
181 main (void)
183 return cairo_test (&test);