Rename GP_Context -> GP_Pixmap
[gfxprim.git] / tests / gfx / FillCircle.c
blob49e0b9fd83e15a66e9b06a9af8e587b4d32ee57e
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #include <string.h>
24 #include <errno.h>
25 #include <sys/stat.h>
27 #include <core/GP_Pixmap.h>
28 #include <gfx/GP_Circle.h>
30 #include "tst_test.h"
32 #include "common.h"
34 struct testcase {
35 /* cicle description */
36 GP_Coord x;
37 GP_Coord y;
38 GP_Size r;
40 /* expected result */
41 GP_Size w, h;
42 const char pixmap[];
45 static int test_circle(const struct testcase *t)
47 GP_Pixmap *c;
48 int err;
50 c = GP_PixmapAlloc(t->w, t->h, GP_PIXEL_G8);
52 if (c == NULL) {
53 tst_err("Failed to allocate pixmap");
54 return TST_UNTESTED;
57 /* zero the pixels buffer */
58 memset(c->pixels, 0, c->w * c->h);
60 GP_FillCircle(c, t->x, t->y, t->r, 1);
62 err = compare_buffers(t->pixmap, c);
64 if (err)
65 return TST_FAILED;
67 return TST_SUCCESS;
70 struct testcase testcase_circle_r_0 = {
71 .x = 2,
72 .y = 2,
73 .r = 0,
75 .w = 5,
76 .h = 5,
78 .pixmap = {
79 0, 0, 0, 0, 0,
80 0, 0, 0, 0, 0,
81 0, 0, 1, 0, 0,
82 0, 0, 0, 0, 0,
83 0, 0, 0, 0, 0,
87 struct testcase testcase_circle_r_1 = {
88 .x = 2,
89 .y = 2,
90 .r = 1,
92 .w = 5,
93 .h = 5,
95 .pixmap = {
96 0, 0, 0, 0, 0,
97 0, 0, 1, 0, 0,
98 0, 1, 1, 1, 0,
99 0, 0, 1, 0, 0,
100 0, 0, 0, 0, 0,
104 struct testcase testcase_circle_r_2 = {
105 .x = 3,
106 .y = 3,
107 .r = 2,
109 .w = 7,
110 .h = 7,
112 .pixmap = {
113 0, 0, 0, 0, 0, 0, 0,
114 0, 0, 1, 1, 1, 0, 0,
115 0, 1, 1, 1, 1, 1, 0,
116 0, 1, 1, 1, 1, 1, 0,
117 0, 1, 1, 1, 1, 1, 0,
118 0, 0, 1, 1, 1, 0, 0,
119 0, 0, 0, 0, 0, 0, 0,
123 struct testcase testcase_circle_r_3 = {
124 .x = 4,
125 .y = 4,
126 .r = 3,
128 .w = 9,
129 .h = 9,
131 .pixmap = {
132 0, 0, 0, 0, 0, 0, 0, 0, 0,
133 0, 0, 0, 1, 1, 1, 0, 0, 0,
134 0, 0, 1, 1, 1, 1, 1, 0, 0,
135 0, 1, 1, 1, 1, 1, 1, 1, 0,
136 0, 1, 1, 1, 1, 1, 1, 1, 0,
137 0, 1, 1, 1, 1, 1, 1, 1, 0,
138 0, 0, 1, 1, 1, 1, 1, 0, 0,
139 0, 0, 0, 1, 1, 1, 0, 0, 0,
140 0, 0, 0, 0, 0, 0, 0, 0, 0,
144 struct testcase testcase_circle_r_4 = {
145 .x = 5,
146 .y = 5,
147 .r = 4,
149 .w = 11,
150 .h = 11,
152 .pixmap = {
153 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
154 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
155 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0,
156 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0,
157 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
158 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
159 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
160 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0,
161 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0,
162 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
163 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
167 struct testcase testcase_circle_r_5_clip = {
168 .x = 0,
169 .y = 5,
170 .r = 5,
172 .w = 11,
173 .h = 11,
175 .pixmap = {
176 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
177 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
178 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
179 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
180 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
181 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
182 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
183 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
184 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
185 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
186 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
190 struct testcase testcase_circle_r_6_clip = {
191 .x = 0,
192 .y = 0,
193 .r = 6,
195 .w = 8,
196 .h = 8,
198 .pixmap = {
199 1, 1, 1, 1, 1, 1, 1, 0,
200 1, 1, 1, 1, 1, 1, 1, 0,
201 1, 1, 1, 1, 1, 1, 1, 0,
202 1, 1, 1, 1, 1, 1, 0, 0,
203 1, 1, 1, 1, 1, 1, 0, 0,
204 1, 1, 1, 1, 1, 0, 0, 0,
205 1, 1, 1, 0, 0, 0, 0, 0,
206 0, 0, 0, 0, 0, 0, 0, 0,
210 const struct tst_suite tst_suite = {
211 .suite_name = "FillCircle Testsuite",
212 .tests = {
213 {.name = "FillCircle r=0",
214 .tst_fn = test_circle,
215 .data = &testcase_circle_r_0},
217 {.name = "FillCircle r=1",
218 .tst_fn = test_circle,
219 .data = &testcase_circle_r_1},
221 {.name = "FillCircle r=2",
222 .tst_fn = test_circle,
223 .data = &testcase_circle_r_2},
225 {.name = "FillCircle r=3",
226 .tst_fn = test_circle,
227 .data = &testcase_circle_r_3},
229 {.name = "FillCircle r=4",
230 .tst_fn = test_circle,
231 .data = &testcase_circle_r_4},
233 {.name = "FillCircle r=5 + clipping",
234 .tst_fn = test_circle,
235 .data = &testcase_circle_r_5_clip},
237 {.name = "FillCircle r=6 + clipping",
238 .tst_fn = test_circle,
239 .data = &testcase_circle_r_6_clip},
241 {.name = NULL}