tests: PNG: Add RGBA8888 save test.
[gfxprim/pasky.git] / tests / gfx / FillRect.c
blob87b720b46685bdaf33635cd7cc7fd72024d7a311
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-2013 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_Rect.h>
30 #include "tst_test.h"
32 #include "common.h"
34 struct testcase {
35 /* rect description */
36 GP_Coord x1;
37 GP_Coord y1;
38 GP_Coord x2;
39 GP_Coord y2;
41 /* expected result */
42 GP_Size w, h;
43 const char pixmap[];
46 static int test_rect(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_FillRect(c, t->x1, t->y1, t->x2, t->y2, 1);
63 err = compare_buffers(t->pixmap, c);
65 if (err)
66 return TST_FAILED;
68 return TST_SUCCESS;
71 struct testcase testcase_rect_1 = {
72 .x1 = 2,
73 .y1 = 2,
74 .x2 = 2,
75 .y2 = 2,
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 struct testcase testcase_rect_9a = {
90 .x1 = 1,
91 .y1 = 1,
92 .x2 = 3,
93 .y2 = 3,
95 .w = 5,
96 .h = 5,
98 .pixmap = {
99 0, 0, 0, 0, 0,
100 0, 1, 1, 1, 0,
101 0, 1, 1, 1, 0,
102 0, 1, 1, 1, 0,
103 0, 0, 0, 0, 0,
107 struct testcase testcase_rect_9b = {
108 .x1 = 3,
109 .y1 = 3,
110 .x2 = 1,
111 .y2 = 1,
113 .w = 5,
114 .h = 5,
116 .pixmap = {
117 0, 0, 0, 0, 0,
118 0, 1, 1, 1, 0,
119 0, 1, 1, 1, 0,
120 0, 1, 1, 1, 0,
121 0, 0, 0, 0, 0,
125 struct testcase testcase_rect_9lu = {
126 .x1 = -2147483648,
127 .y1 = -2147483648,
128 .x2 = 2,
129 .y2 = 2,
131 .w = 5,
132 .h = 5,
134 .pixmap = {
135 1, 1, 1, 0, 0,
136 1, 1, 1, 0, 0,
137 1, 1, 1, 0, 0,
138 0, 0, 0, 0, 0,
139 0, 0, 0, 0, 0,
143 struct testcase testcase_rect_9ld = {
144 .x1 = -2147483648,
145 .y1 = 2,
146 .x2 = 2,
147 .y2 = 2147483647,
149 .w = 5,
150 .h = 5,
152 .pixmap = {
153 0, 0, 0, 0, 0,
154 0, 0, 0, 0, 0,
155 1, 1, 1, 0, 0,
156 1, 1, 1, 0, 0,
157 1, 1, 1, 0, 0,
161 struct testcase testcase_rect_9ru = {
162 .x1 = 2,
163 .y1 = -2147483648,
164 .x2 = 2147483647,
165 .y2 = 2,
167 .w = 5,
168 .h = 5,
170 .pixmap = {
171 0, 0, 1, 1, 1,
172 0, 0, 1, 1, 1,
173 0, 0, 1, 1, 1,
174 0, 0, 0, 0, 0,
175 0, 0, 0, 0, 0,
179 struct testcase testcase_rect_9rd = {
180 .x1 = 2,
181 .y1 = 2,
182 .x2 = 2147483647,
183 .y2 = 2147483647,
185 .w = 5,
186 .h = 5,
188 .pixmap = {
189 0, 0, 0, 0, 0,
190 0, 0, 0, 0, 0,
191 0, 0, 1, 1, 1,
192 0, 0, 1, 1, 1,
193 0, 0, 1, 1, 1,
197 struct testcase testcase_rect_9r = {
198 .x1 = -2147483648,
199 .y1 = 3,
200 .x2 = 2,
201 .y2 = 1,
203 .w = 5,
204 .h = 5,
206 .pixmap = {
207 0, 0, 0, 0, 0,
208 1, 1, 1, 0, 0,
209 1, 1, 1, 0, 0,
210 1, 1, 1, 0, 0,
211 0, 0, 0, 0, 0,
215 struct testcase testcase_rect_9l = {
216 .x1 = 2,
217 .y1 = 3,
218 .x2 = 2147483647,
219 .y2 = 1,
221 .w = 5,
222 .h = 5,
224 .pixmap = {
225 0, 0, 0, 0, 0,
226 0, 0, 1, 1, 1,
227 0, 0, 1, 1, 1,
228 0, 0, 1, 1, 1,
229 0, 0, 0, 0, 0,
233 struct testcase testcase_rect_9u = {
234 .x1 = 1,
235 .y1 = -2147483648,
236 .x2 = 3,
237 .y2 = 2,
239 .w = 5,
240 .h = 5,
242 .pixmap = {
243 0, 1, 1, 1, 0,
244 0, 1, 1, 1, 0,
245 0, 1, 1, 1, 0,
246 0, 0, 0, 0, 0,
247 0, 0, 0, 0, 0,
251 struct testcase testcase_rect_9d = {
252 .x1 = 1,
253 .y1 = 2,
254 .x2 = 3,
255 .y2 = 2147483647,
257 .w = 5,
258 .h = 5,
260 .pixmap = {
261 0, 0, 0, 0, 0,
262 0, 0, 0, 0, 0,
263 0, 1, 1, 1, 0,
264 0, 1, 1, 1, 0,
265 0, 1, 1, 1, 0,
269 struct testcase testcase_rect_0a = {
270 .x1 = 2147483647,
271 .y1 = -2147483648,
272 .x2 = 2147483647,
273 .y2 = -2147483648,
275 .w = 5,
276 .h = 5,
278 .pixmap = {
279 0, 0, 0, 0, 0,
280 0, 0, 0, 0, 0,
281 0, 0, 0, 0, 0,
282 0, 0, 0, 0, 0,
283 0, 0, 0, 0, 0,
287 struct testcase testcase_rect_0b = {
288 .x1 = -2147483648,
289 .y1 = 2147483647,
290 .x2 = -2147483648,
291 .y2 = 2147483647,
293 .w = 5,
294 .h = 5,
296 .pixmap = {
297 0, 0, 0, 0, 0,
298 0, 0, 0, 0, 0,
299 0, 0, 0, 0, 0,
300 0, 0, 0, 0, 0,
301 0, 0, 0, 0, 0,
305 struct testcase testcase_rect_25 = {
306 .x1 = -2147483648,
307 .y1 = 2147483647,
308 .x2 = 2147483647,
309 .y2 = -2147483648,
311 .w = 5,
312 .h = 5,
314 .pixmap = {
315 1, 1, 1, 1, 1,
316 1, 1, 1, 1, 1,
317 1, 1, 1, 1, 1,
318 1, 1, 1, 1, 1,
319 1, 1, 1, 1, 1,
323 const struct tst_suite tst_suite = {
324 .suite_name = "FillRect Testsuite",
325 .tests = {
326 {.name = "FillRect x1=x2 y1=y2",
327 .tst_fn = test_rect,
328 .data = &testcase_rect_1},
330 {.name = "FillRect x1<x2 y1<y2",
331 .tst_fn = test_rect,
332 .data = &testcase_rect_9a},
334 {.name = "FillRect x1>x2 y1>y2",
335 .tst_fn = test_rect,
336 .data = &testcase_rect_9b},
338 {.name = "FillRect x1,y1 out of context",
339 .tst_fn = test_rect,
340 .data = &testcase_rect_9lu,
341 .timeout = 2},
343 {.name = "FillRect x1,y2 out of context",
344 .tst_fn = test_rect,
345 .data = &testcase_rect_9ld,
346 .timeout = 2},
348 {.name = "FillRect x2,y1 out of context",
349 .tst_fn = test_rect,
350 .data = &testcase_rect_9ru,
351 .timeout = 2},
353 {.name = "FillRect x2,y2 out of context",
354 .tst_fn = test_rect,
355 .data = &testcase_rect_9rd,
356 .timeout = 2},
358 {.name = "FillRect x1 out of context",
359 .tst_fn = test_rect,
360 .data = &testcase_rect_9r,
361 .timeout = 2},
363 {.name = "FillRect x2 out of context",
364 .tst_fn = test_rect,
365 .data = &testcase_rect_9l,
366 .timeout = 2},
368 {.name = "FillRect y1 out of context",
369 .tst_fn = test_rect,
370 .data = &testcase_rect_9u,
371 .timeout = 2},
373 {.name = "FillRect y2 out of context",
374 .tst_fn = test_rect,
375 .data = &testcase_rect_9d,
376 .timeout = 2},
378 {.name = "FillRect rect out of context 1",
379 .tst_fn = test_rect,
380 .data = &testcase_rect_0a,
381 .timeout = 2},
383 {.name = "FillRect rect out of context 2",
384 .tst_fn = test_rect,
385 .data = &testcase_rect_0b,
386 .timeout = 2},
388 {.name = "FillRect full rect",
389 .tst_fn = test_rect,
390 .data = &testcase_rect_25,
391 .timeout = 2},
393 {.name = NULL}