1 /*****************************************************************************
2 * This file is part of gfxprim library. *
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. *
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. *
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 *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
25 #include <core/GP_Pixmap.h>
26 #include <filters/GP_Rotate.h>
35 GP_PixelType pixel_type
;
46 static int test_mirror_h(struct testcase
*t
)
51 /* Initialize source pixmap */
52 GP_PixmapInit(&src
, t
->w
, t
->h
, t
->pixel_type
, t
->src
);
54 /* Set offset to emulate non-byte aligned subpixmaps */
55 src
.offset
= t
->offset
;
57 /* Test with allocated destination */
58 c
= GP_PixmapAlloc(t
->w
, t
->h
, t
->pixel_type
);
61 tst_err("Failed to allocate pixmap");
65 GP_FilterMirrorH(&src
, c
, NULL
);
67 err
= compare_buffers(t
->res
, c
);
71 /* And with in-place variant */
72 // GP_FilterMirrorH(&src, &src, NULL);
74 // err |= compare_buffers(t->res, &src);
82 struct testcase testcase_1x1
= {
86 .pixel_type
= GP_PIXEL_G8
,
88 .res
= (const char[]) {
97 struct testcase testcase_2x2
= {
101 .pixel_type
= GP_PIXEL_G8
,
103 .res
= (const char[]) {
114 struct testcase testcase_10x2
= {
118 .pixel_type
= GP_PIXEL_G8
,
120 .res
= (const char[]) {
121 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
122 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
126 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
127 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
131 struct testcase testcase_2x3
= {
135 .pixel_type
= GP_PIXEL_G8
,
137 .res
= (const char[]) {
151 struct testcase testcase_3x3
= {
155 .pixel_type
= GP_PIXEL_G8
,
157 .res
= (const char[]) {
170 struct testcase testcase_4x4
= {
174 .pixel_type
= GP_PIXEL_G8
,
176 .res
= (const char[]) {
191 /* Now tests with pixel types that are not byte aligned */
192 //TODO: Fix comparsion
193 struct testcase testcase_G1_16x2
= {
197 .pixel_type
= GP_PIXEL_G1
,
201 .res
= (const char[]) {
212 static int abort_callback_fn(GP_ProgressCallback
GP_UNUSED(*self
))
217 static GP_ProgressCallback abort_callback
= {
218 .callback
= abort_callback_fn
,
221 static int test_abort(void)
226 c
= GP_PixmapAlloc(10, 10, GP_PIXEL_G8
);
229 tst_err("Failed to allocate pixmap");
233 ret
= GP_FilterMirrorH(c
, c
, &abort_callback
);
236 tst_msg("Aborted filter haven't returned non-zero");
240 if (errno
!= ECANCELED
) {
241 tst_msg("Errno wasn't set to ECANCELED");
248 static int all_pixels(void)
252 for (pixel_type
= 1; pixel_type
< GP_PIXEL_MAX
; pixel_type
++) {
255 tst_msg("Trying pixel %s", GP_PixelTypeName(pixel_type
));
257 c
= GP_PixmapAlloc(10, 10, pixel_type
);
260 tst_err("Failed to allocate pixmap");
264 GP_FilterMirrorH(c
, c
, NULL
);
272 const struct tst_suite tst_suite
= {
273 .suite_name
= "MirrorH Filter Testsuite",
275 {.name
= "MirrorH 1x1",
276 .tst_fn
= test_mirror_h
,
277 .data
= &testcase_1x1
},
279 {.name
= "MirrorH 2x2",
280 .tst_fn
= test_mirror_h
,
281 .data
= &testcase_2x2
},
283 {.name
= "MirrorH 10x2",
284 .tst_fn
= test_mirror_h
,
285 .data
= &testcase_10x2
},
287 {.name
= "MirrorH 2x3",
288 .tst_fn
= test_mirror_h
,
289 .data
= &testcase_2x3
},
291 {.name
= "MirrorH 3x3",
292 .tst_fn
= test_mirror_h
,
293 .data
= &testcase_3x3
},
295 {.name
= "MirrorH 4x4",
296 .tst_fn
= test_mirror_h
,
297 .data
= &testcase_3x3
},
299 {.name
= "MirrorH G1 16x2",
300 .tst_fn
= test_mirror_h
,
301 .data
= &testcase_G1_16x2
},
303 {.name
= "MirrorH Callback Abort",
304 .tst_fn
= test_abort
},
306 {.name
= "MirrorH x Pixels",
307 .tst_fn
= all_pixels
},