Rename GP_Context -> GP_Pixmap
[gfxprim.git] / tests / filters / FilterMirrorH.c
blob665bc4c31d503173b21490af5d77428136d19723
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 <errno.h>
25 #include <core/GP_Pixmap.h>
26 #include <filters/GP_Rotate.h>
28 #include "tst_test.h"
30 #include "common.h"
32 struct testcase {
33 GP_Size w, h;
35 GP_PixelType pixel_type;
37 uint8_t offset;
39 /* result */
40 const char *res;
42 /* source */
43 char src[];
46 static int test_mirror_h(struct testcase *t)
48 GP_Pixmap src, *c;
49 int err;
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);
60 if (c == NULL) {
61 tst_err("Failed to allocate pixmap");
62 return TST_UNTESTED;
65 GP_FilterMirrorH(&src, c, NULL);
67 err = compare_buffers(t->res, c);
69 GP_PixmapFree(c);
71 /* And with in-place variant */
72 // GP_FilterMirrorH(&src, &src, NULL);
74 // err |= compare_buffers(t->res, &src);
76 if (err)
77 return TST_FAILED;
79 return TST_SUCCESS;
82 struct testcase testcase_1x1 = {
83 .w = 1,
84 .h = 1,
86 .pixel_type = GP_PIXEL_G8,
88 .res = (const char[]) {
89 0xf0,
92 .src = {
93 0xf0,
97 struct testcase testcase_2x2 = {
98 .w = 2,
99 .h = 2,
101 .pixel_type = GP_PIXEL_G8,
103 .res = (const char[]) {
104 2, 3,
105 0, 1,
108 .src = {
109 0, 1,
110 2, 3,
114 struct testcase testcase_10x2 = {
115 .w = 10,
116 .h = 2,
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,
125 .src = {
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 = {
132 .w = 2,
133 .h = 3,
135 .pixel_type = GP_PIXEL_G8,
137 .res = (const char[]) {
138 4, 5,
139 2, 3,
140 0, 1,
143 .src = {
144 0, 1,
145 2, 3,
146 4, 5,
151 struct testcase testcase_3x3 = {
152 .w = 3,
153 .h = 3,
155 .pixel_type = GP_PIXEL_G8,
157 .res = (const char[]) {
158 6, 7, 8,
159 3, 4, 5,
160 0, 1, 2,
163 .src = {
164 0, 1, 2,
165 3, 4, 5,
166 6, 7, 8,
170 struct testcase testcase_4x4 = {
171 .w = 4,
172 .h = 4,
174 .pixel_type = GP_PIXEL_G8,
176 .res = (const char[]) {
177 12, 13, 14, 15,
178 8, 9, 10, 11,
179 4, 5, 6, 7,
180 0, 1, 2, 3,
183 .src = {
184 0, 1, 2, 3,
185 4, 5, 6, 7,
186 8, 9, 10, 11,
187 12, 13, 14, 15,
191 /* Now tests with pixel types that are not byte aligned */
192 //TODO: Fix comparsion
193 struct testcase testcase_G1_16x2 = {
194 .w = 3,
195 .h = 2,
197 .pixel_type = GP_PIXEL_G1,
199 .offset = 4,
201 .res = (const char[]) {
202 0x0f, 0xaa, 0xf0,
203 0xff, 0xff, 0xff,
206 .src = {
207 0x0f, 0xff, 0xf0,
208 0xff, 0xaa, 0xff,
212 static int abort_callback_fn(GP_ProgressCallback GP_UNUSED(*self))
214 return 1;
217 static GP_ProgressCallback abort_callback = {
218 .callback = abort_callback_fn,
221 static int test_abort(void)
223 int ret;
224 GP_Pixmap *c;
226 c = GP_PixmapAlloc(10, 10, GP_PIXEL_G8);
228 if (c == NULL) {
229 tst_err("Failed to allocate pixmap");
230 return TST_UNTESTED;
233 ret = GP_FilterMirrorH(c, c, &abort_callback);
235 if (ret == 0) {
236 tst_msg("Aborted filter haven't returned non-zero");
237 return TST_FAILED;
240 if (errno != ECANCELED) {
241 tst_msg("Errno wasn't set to ECANCELED");
242 return TST_FAILED;
245 return TST_SUCCESS;
248 static int all_pixels(void)
250 GP_Pixel pixel_type;
252 for (pixel_type = 1; pixel_type < GP_PIXEL_MAX; pixel_type++) {
253 GP_Pixmap *c;
255 tst_msg("Trying pixel %s", GP_PixelTypeName(pixel_type));
257 c = GP_PixmapAlloc(10, 10, pixel_type);
259 if (c == NULL) {
260 tst_err("Failed to allocate pixmap");
261 return TST_UNTESTED;
264 GP_FilterMirrorH(c, c, NULL);
266 GP_PixmapFree(c);
269 return TST_SUCCESS;
272 const struct tst_suite tst_suite = {
273 .suite_name = "MirrorH Filter Testsuite",
274 .tests = {
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},
309 {.name = NULL}