Rename GP_Context -> GP_Pixmap
[gfxprim.git] / tests / core / BlitClipped.c
blob8362f180fa480f3cba30e035da65e5c338761c1c
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 *****************************************************************************/
25 Clipped Blit tests.
28 #include <errno.h>
30 #include <core/GP_Pixmap.h>
31 #include <core/GP_Blit.h>
32 #include <core/GP_Fill.h>
34 #include "tst_test.h"
35 #include "tst_preload.h"
37 #include "../filters/common.c"
39 struct clipped_test {
40 /* size of the contexes */
41 GP_Size src_w, src_h;
42 GP_Size dst_w, dst_h;
44 /* Source rectangle */
45 GP_Coord x0, y0;
46 GP_Size w0, h0;
48 /* Destination offset */
49 GP_Coord x1, y1;
51 /* If set, is used to check assert correct result */
52 const char *dst;
55 static int clipped_test(struct clipped_test *test)
57 int ret = TST_SUCCESS;
58 GP_Pixmap *src, *dst;
60 src = GP_PixmapAlloc(test->src_w, test->src_h, GP_PIXEL_G8);
61 dst = GP_PixmapAlloc(test->dst_w, test->dst_h, GP_PIXEL_G8);
63 GP_Fill(src, 1);
64 GP_Fill(dst, 0);
66 if (!src || !dst) {
67 tst_msg("GP_PixmapAlloc() failed");
68 return TST_UNTESTED;
71 GP_BlitXYWH_Clipped(src, test->x0, test->y0, test->w0, test->h0,
72 dst, test->x1, test->y1);
74 if (test->dst) {
75 if (compare_buffers(test->dst, dst))
76 ret = TST_FAILED;
79 GP_PixmapFree(src);
80 GP_PixmapFree(dst);
82 return ret;
85 static int clipped_test_canaries(struct clipped_test *test)
87 int ret;
89 tst_malloc_canaries_set(MALLOC_CANARY_BEGIN);
90 ret = clipped_test(test);
92 tst_malloc_canaries_set(MALLOC_CANARY_END);
93 ret |= clipped_test(test);
95 tst_malloc_canaries_set(MALLOC_CANARY_OFF);
97 return ret;
100 static struct clipped_test off_by_one_1 = {
101 .src_w = 100,
102 .src_h = 100,
104 .dst_w = 100,
105 .dst_h = 100,
107 .x0 = 0,
108 .y0 = 0,
109 .w0 = 100,
110 .h0 = 100,
112 .x1 = 1,
113 .y1 = 1,
116 static struct clipped_test off_by_one_2 = {
117 .src_w = 100,
118 .src_h = 100,
120 .dst_w = 100,
121 .dst_h = 100,
123 .x0 = 0,
124 .y0 = 0,
125 .w0 = 100,
126 .h0 = 100,
128 .x1 = 1,
129 .y1 = 0,
132 static struct clipped_test off_by_one_3 = {
133 .src_w = 100,
134 .src_h = 100,
136 .dst_w = 100,
137 .dst_h = 100,
139 .x0 = 0,
140 .y0 = 0,
141 .w0 = 100,
142 .h0 = 100,
144 .x1 = 0,
145 .y1 = 1,
148 static const char empty[400] = {0};
150 static struct clipped_test empty_src = {
151 .src_w = 10,
152 .src_h = 10,
154 .dst_w = 20,
155 .dst_h = 20,
157 .x0 = 0,
158 .y0 = 0,
159 .w0 = 0,
160 .h0 = 0,
162 .x1 = 0,
163 .y1 = 0,
165 .dst = empty,
168 static struct clipped_test out_of_dst_1 = {
169 .src_w = 10,
170 .src_h = 10,
172 .dst_w = 20,
173 .dst_h = 20,
175 .x0 = 0,
176 .y0 = 0,
177 .w0 = 10,
178 .h0 = 10,
180 .x1 = 20,
181 .y1 = 0,
183 .dst = empty,
186 static struct clipped_test out_of_dst_2 = {
187 .src_w = 10,
188 .src_h = 10,
190 .dst_w = 20,
191 .dst_h = 20,
193 .x0 = 0,
194 .y0 = 0,
195 .w0 = 10,
196 .h0 = 10,
198 .x1 = 0,
199 .y1 = 20,
201 .dst = empty,
204 static struct clipped_test src_rect_out_of_src = {
205 .src_w = 10,
206 .src_h = 10,
208 .dst_w = 20,
209 .dst_h = 20,
211 .x0 = -10,
212 .y0 = -10,
213 .w0 = 10,
214 .h0 = 10,
216 .x1 = 0,
217 .y1 = 0,
219 .dst = empty,
222 static struct clipped_test dst_neg_coords1 = {
223 .src_w = 5,
224 .src_h = 5,
226 .dst_w = 5,
227 .dst_h = 5,
229 .x0 = 2,
230 .y0 = 2,
231 .w0 = 5,
232 .h0 = 5,
234 .x1 = -2,
235 .y1 = -2,
237 .dst = (const char []) {
238 1, 0, 0, 0, 0,
239 0, 0, 0, 0, 0,
240 0, 0, 0, 0, 0,
241 0, 0, 0, 0, 0,
242 0, 0, 0, 0, 0,
246 static struct clipped_test dst_big_coords = {
247 .src_w = 5,
248 .src_h = 5,
250 .dst_w = 5,
251 .dst_h = 5,
253 .x0 = 2,
254 .y0 = 2,
255 .w0 = 5,
256 .h0 = 5,
258 .x1 = 4,
259 .y1 = 4,
261 .dst = (const char []) {
262 0, 0, 0, 0, 0,
263 0, 0, 0, 0, 0,
264 0, 0, 0, 0, 0,
265 0, 0, 0, 0, 0,
266 0, 0, 0, 0, 1,
270 static struct clipped_test dst_neg_coords2 = {
271 .src_w = 10,
272 .src_h = 10,
274 .dst_w = 3,
275 .dst_h = 3,
277 .x0 = 0,
278 .y0 = 0,
279 .w0 = 8,
280 .h0 = 8,
282 .x1 = -5,
283 .y1 = -5,
285 .dst = (const char []) {
286 1, 1, 1,
287 1, 1, 1,
288 1, 1, 1,
292 static struct clipped_test dst_neg_coords3 = {
293 .src_w = 12,
294 .src_h = 12,
296 .dst_w = 3,
297 .dst_h = 3,
299 .x0 = 0,
300 .y0 = 0,
301 .w0 = 10,
302 .h0 = 10,
304 .x1 = -8,
305 .y1 = -8,
307 .dst = (const char []) {
308 1, 1, 0,
309 1, 1, 0,
310 0, 0, 0,
314 static struct clipped_test src_inside = {
315 .src_w = 3,
316 .src_h = 3,
318 .dst_w = 5,
319 .dst_h = 5,
321 .x0 = 0,
322 .y0 = 0,
323 .w0 = 3,
324 .h0 = 3,
326 .x1 = 1,
327 .y1 = 1,
329 .dst = (const char []) {
330 0, 0, 0, 0, 0,
331 0, 1, 1, 1, 0,
332 0, 1, 1, 1, 0,
333 0, 1, 1, 1, 0,
334 0, 0, 0, 0, 0,
338 const struct tst_suite tst_suite = {
339 .suite_name = "Blit Clipped Testsuite",
340 .tests = {
341 {.name = "Empty src",
342 .tst_fn = clipped_test_canaries,
343 .data = &empty_src,
344 .flags = TST_CHECK_MALLOC},
346 {.name = "Out of dst 1",
347 .tst_fn = clipped_test_canaries,
348 .data = &out_of_dst_1,
349 .flags = TST_CHECK_MALLOC},
351 {.name = "Out of dst 2",
352 .tst_fn = clipped_test_canaries,
353 .data = &out_of_dst_2,
354 .flags = TST_CHECK_MALLOC},
356 {.name = "Src rect out of src",
357 .tst_fn = clipped_test_canaries,
358 .data = &src_rect_out_of_src,
359 .flags = TST_CHECK_MALLOC},
361 {.name = "Dst negative coords 1",
362 .tst_fn = clipped_test_canaries,
363 .data = &dst_neg_coords1,
364 .flags = TST_CHECK_MALLOC},
366 {.name = "Dst negative coords 2",
367 .tst_fn = clipped_test_canaries,
368 .data = &dst_neg_coords2,
369 .flags = TST_CHECK_MALLOC},
371 {.name = "Dst negative coords 3",
372 .tst_fn = clipped_test_canaries,
373 .data = &dst_neg_coords3,
374 .flags = TST_CHECK_MALLOC},
376 {.name = "Dst big coords",
377 .tst_fn = clipped_test_canaries,
378 .data = &dst_big_coords,
379 .flags = TST_CHECK_MALLOC},
381 {.name = "Src inside dst",
382 .tst_fn = clipped_test_canaries,
383 .data = &src_inside,
384 .flags = TST_CHECK_MALLOC},
386 {.name = "Regression off by one 1",
387 .tst_fn = clipped_test_canaries,
388 .data = &off_by_one_1,
389 .flags = TST_CHECK_MALLOC},
391 {.name = "Regression off by one 2",
392 .tst_fn = clipped_test_canaries,
393 .data = &off_by_one_2,
394 .flags = TST_CHECK_MALLOC},
396 {.name = "Regression off by one 3",
397 .tst_fn = clipped_test_canaries,
398 .data = &off_by_one_3,
399 .flags = TST_CHECK_MALLOC},
401 {.name = NULL},