tests: PNG: Add RGBA8888 save test.
[gfxprim/pasky.git] / tests / gfx / Ellipse.c
blob5b0add6b0548533e0cbc138c536bc510c08e1ed8
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_Context.h>
28 #include <gfx/GP_Ellipse.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 a;
39 GP_Size b;
41 /* expected result */
42 GP_Size w, h;
43 const char pixmap[];
46 static int test_ellipse(const struct testcase *t)
48 GP_Context *c;
49 int err;
51 c = GP_ContextAlloc(t->w, t->h, GP_PIXEL_G8);
53 if (c == NULL) {
54 tst_err("Failed to allocate context");
55 return TST_UNTESTED;
58 /* zero the pixels buffer */
59 memset(c->pixels, 0, c->w * c->h);
61 GP_Ellipse(c, t->x, t->y, t->a, t->b, 1);
63 err = compare_buffers(t->pixmap, c);
65 if (err)
66 return TST_FAILED;
68 return TST_SUCCESS;
71 static struct testcase testcase_ellipse_a0_b0 = {
72 .x = 2,
73 .y = 2,
74 .a = 0,
75 .b = 0,
77 .w = 5,
78 .h = 5,
80 .pixmap = {
81 0, 0, 0, 0, 0,
82 0, 0, 0, 0, 0,
83 0, 0, 1, 0, 0,
84 0, 0, 0, 0, 0,
85 0, 0, 0, 0, 0,
89 static struct testcase testcase_ellipse_a1_b0 = {
90 .x = 2,
91 .y = 2,
92 .a = 1,
93 .b = 0,
95 .w = 5,
96 .h = 5,
98 .pixmap = {
99 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0,
101 0, 1, 1, 1, 0,
102 0, 0, 0, 0, 0,
103 0, 0, 0, 0, 0,
107 static struct testcase testcase_ellipse_a0_b1 = {
108 .x = 2,
109 .y = 2,
110 .a = 0,
111 .b = 1,
113 .w = 5,
114 .h = 5,
116 .pixmap = {
117 0, 0, 0, 0, 0,
118 0, 0, 1, 0, 0,
119 0, 0, 1, 0, 0,
120 0, 0, 1, 0, 0,
121 0, 0, 0, 0, 0,
125 static struct testcase testcase_ellipse_a1_b1 = {
126 .x = 2,
127 .y = 2,
128 .a = 1,
129 .b = 1,
131 .w = 5,
132 .h = 5,
134 .pixmap = {
135 0, 0, 0, 0, 0,
136 0, 0, 1, 0, 0,
137 0, 1, 0, 1, 0,
138 0, 0, 1, 0, 0,
139 0, 0, 0, 0, 0,
143 static struct testcase testcase_ellipse_a2_b1 = {
144 .x = 3,
145 .y = 3,
146 .a = 2,
147 .b = 1,
149 .w = 7,
150 .h = 7,
152 .pixmap = {
153 0, 0, 0, 0, 0, 0, 0,
154 0, 0, 0, 0, 0, 0, 0,
155 0, 0, 1, 1, 1, 0, 0,
156 0, 1, 0, 0, 0, 1, 0,
157 0, 0, 1, 1, 1, 0, 0,
158 0, 0, 0, 0, 0, 0, 0,
159 0, 0, 0, 0, 0, 0, 0,
163 static struct testcase testcase_ellipse_a1_b2 = {
164 .x = 3,
165 .y = 3,
166 .a = 1,
167 .b = 2,
169 .w = 7,
170 .h = 7,
172 .pixmap = {
173 0, 0, 0, 0, 0, 0, 0,
174 0, 0, 0, 1, 0, 0, 0,
175 0, 0, 1, 0, 1, 0, 0,
176 0, 0, 1, 0, 1, 0, 0,
177 0, 0, 1, 0, 1, 0, 0,
178 0, 0, 0, 1, 0, 0, 0,
179 0, 0, 0, 0, 0, 0, 0,
183 static struct testcase testcase_ellipse_a2_b2 = {
184 .x = 3,
185 .y = 3,
186 .a = 2,
187 .b = 2,
189 .w = 7,
190 .h = 7,
192 .pixmap = {
193 0, 0, 0, 0, 0, 0, 0,
194 0, 0, 1, 1, 1, 0, 0,
195 0, 1, 0, 0, 0, 1, 0,
196 0, 1, 0, 0, 0, 1, 0,
197 0, 1, 0, 0, 0, 1, 0,
198 0, 0, 1, 1, 1, 0, 0,
199 0, 0, 0, 0, 0, 0, 0,
203 static struct testcase testcase_ellipse_a1_b3 = {
204 .x = 4,
205 .y = 4,
206 .a = 1,
207 .b = 3,
209 .w = 9,
210 .h = 9,
212 .pixmap = {
213 0, 0, 0, 0, 0, 0, 0, 0, 0,
214 0, 0, 0, 0, 1, 0, 0, 0, 0,
215 0, 0, 0, 1, 0, 1, 0, 0, 0,
216 0, 0, 0, 1, 0, 1, 0, 0, 0,
217 0, 0, 0, 1, 0, 1, 0, 0, 0,
218 0, 0, 0, 1, 0, 1, 0, 0, 0,
219 0, 0, 0, 1, 0, 1, 0, 0, 0,
220 0, 0, 0, 0, 1, 0, 0, 0, 0,
221 0, 0, 0, 0, 0, 0, 0, 0, 0,
225 static struct testcase testcase_ellipse_a3_b2 = {
226 .x = 4,
227 .y = 4,
228 .a = 3,
229 .b = 2,
231 .w = 9,
232 .h = 9,
234 .pixmap = {
235 0, 0, 0, 0, 0, 0, 0, 0, 0,
236 0, 0, 0, 0, 0, 0, 0, 0, 0,
237 0, 0, 0, 1, 1, 1, 0, 0, 0,
238 0, 1, 1, 0, 0, 0, 1, 1, 0,
239 0, 1, 0, 0, 0, 0, 0, 1, 0,
240 0, 1, 1, 0, 0, 0, 1, 1, 0,
241 0, 0, 0, 1, 1, 1, 0, 0, 0,
242 0, 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0, 0,
247 static struct testcase testcase_ellipse_a3_b3 = {
248 .x = 4,
249 .y = 4,
250 .a = 3,
251 .b = 3,
253 .w = 9,
254 .h = 9,
256 .pixmap = {
257 0, 0, 0, 0, 0, 0, 0, 0, 0,
258 0, 0, 0, 1, 1, 1, 0, 0, 0,
259 0, 0, 1, 0, 0, 0, 1, 0, 0,
260 0, 1, 0, 0, 0, 0, 0, 1, 0,
261 0, 1, 0, 0, 0, 0, 0, 1, 0,
262 0, 1, 0, 0, 0, 0, 0, 1, 0,
263 0, 0, 1, 0, 0, 0, 1, 0, 0,
264 0, 0, 0, 1, 1, 1, 0, 0, 0,
265 0, 0, 0, 0, 0, 0, 0, 0, 0,
269 static struct testcase testcase_ellipse_a6_b6_clip = {
270 .x = 0,
271 .y = 0,
272 .a = 6,
273 .b = 6,
275 .w = 8,
276 .h = 8,
278 .pixmap = {
279 0, 0, 0, 0, 0, 0, 1, 0,
280 0, 0, 0, 0, 0, 0, 1, 0,
281 0, 0, 0, 0, 0, 0, 1, 0,
282 0, 0, 0, 0, 0, 1, 0, 0,
283 0, 0, 0, 0, 0, 1, 0, 0,
284 0, 0, 0, 1, 1, 0, 0, 0,
285 1, 1, 1, 0, 0, 0, 0, 0,
286 0, 0, 0, 0, 0, 0, 0, 0,
290 static struct testcase testcase_ellipse_a5_b5_clip = {
291 .x = 0,
292 .y = 5,
293 .a = 5,
294 .b = 5,
296 .w = 11,
297 .h = 11,
299 .pixmap = {
300 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
301 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
302 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
303 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
304 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
305 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
306 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
307 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
308 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
309 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
310 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
314 const struct tst_suite tst_suite = {
315 .suite_name = "Ellipse Testsuite",
316 .tests = {
317 {.name = "Ellipse a=0 b=0",
318 .tst_fn = test_ellipse,
319 .data = &testcase_ellipse_a0_b0},
321 {.name = "Ellipse a=1 b=0",
322 .tst_fn = test_ellipse,
323 .data = &testcase_ellipse_a1_b0},
325 {.name = "Ellipse a=0 b=1",
326 .tst_fn = test_ellipse,
327 .data = &testcase_ellipse_a0_b1},
329 {.name = "Ellipse a=1 b=1",
330 .tst_fn = test_ellipse,
331 .data = &testcase_ellipse_a1_b1},
333 {.name = "Ellipse a=2 b=1",
334 .tst_fn = test_ellipse,
335 .data = &testcase_ellipse_a2_b1},
337 {.name = "Ellipse a=1 b=2",
338 .tst_fn = test_ellipse,
339 .data = &testcase_ellipse_a1_b2},
341 {.name = "Ellipse a=2 b=2",
342 .tst_fn = test_ellipse,
343 .data = &testcase_ellipse_a2_b2},
345 {.name = "Ellipse a=1 b=3",
346 .tst_fn = test_ellipse,
347 .data = &testcase_ellipse_a1_b3},
349 {.name = "Ellipse a=3 b=2",
350 .tst_fn = test_ellipse,
351 .data = &testcase_ellipse_a3_b2},
353 {.name = "Ellipse a=3 b=3",
354 .tst_fn = test_ellipse,
355 .data = &testcase_ellipse_a3_b3},
357 {.name = "Ellipse a=5 b=5 clipped",
358 .tst_fn = test_ellipse,
359 .data = &testcase_ellipse_a5_b5_clip},
361 {.name = "Ellipse a=6 b=6 clipped",
362 .tst_fn = test_ellipse,
363 .data = &testcase_ellipse_a6_b6_clip},
365 {.name = NULL}