Rename GP_Context -> GP_Pixmap
[gfxprim.git] / tests / gfx / VLine.c
blobddbd0691dc9208cf1ec1677588abbdf59cf6ed16
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>
26 #include <core/GP_Pixmap.h>
27 #include <gfx/GP_VLine.h>
29 #include "tst_test.h"
31 #include "common.h"
33 struct testcase {
34 /* VLine description */
35 GP_Coord x;
36 GP_Coord y0;
37 GP_Coord y1;
39 GP_Coord y;
40 GP_Size lh;
42 int flag;
44 /* expected result */
45 GP_Size w, h;
46 const char pixmap[];
49 static int test_vline(struct testcase *t)
51 GP_Pixmap *c;
52 int err;
54 c = GP_PixmapAlloc(t->w, t->h, GP_PIXEL_G8);
56 if (c == NULL) {
57 tst_err("Failed to allocate pixmap");
58 return TST_UNTESTED;
61 /* zero the pixels buffer */
62 memset(c->pixels, 0, c->w * c->h);
64 if (t->flag)
65 GP_VLineXYH(c, t->x, t->y, t->lh, 1);
66 else
67 GP_VLine(c, t->x, t->y0, t->y1, 1);
69 err = compare_buffers(t->pixmap, c);
71 if (err) {
72 tst_msg("Patterns are different");
73 return TST_FAILED;
76 return TST_SUCCESS;
79 static struct testcase testcase_1_px = {
80 .x = 1,
81 .y0 = 1,
82 .y1 = 1,
84 .w = 3,
85 .h = 3,
86 .pixmap = {
87 0, 0, 0,
88 0, 1, 0,
89 0, 0, 0,
93 static struct testcase testcase_3_px_1 = {
94 .x = 1,
95 .y0 = 1,
96 .y1 = 3,
98 .w = 3,
99 .h = 5,
100 .pixmap = {
101 0, 0, 0,
102 0, 1, 0,
103 0, 1, 0,
104 0, 1, 0,
105 0, 0, 0,
109 static struct testcase testcase_3_px_2 = {
110 .x = 1,
111 .y0 = 3,
112 .y1 = 1,
114 .w = 3,
115 .h = 5,
116 .pixmap = {
117 0, 0, 0,
118 0, 1, 0,
119 0, 1, 0,
120 0, 1, 0,
121 0, 0, 0,
125 static struct testcase testcase_clipping_1 = {
126 .x = 1,
127 .y0 = -10000,
128 .y1 = 10000,
130 .w = 3,
131 .h = 5,
132 .pixmap = {
133 0, 1, 0,
134 0, 1, 0,
135 0, 1, 0,
136 0, 1, 0,
137 0, 1, 0,
141 static struct testcase testcase_clipping_2 = {
142 .x = 4,
143 .y0 = -10000,
144 .y1 = 10000,
146 .w = 3,
147 .h = 5,
148 .pixmap = {
149 0, 0, 0,
150 0, 0, 0,
151 0, 0, 0,
152 0, 0, 0,
153 0, 0, 0,
157 static struct testcase testcase_clipping_3 = {
158 .x = -4,
159 .y0 = -100000,
160 .y1 = 100000,
162 .w = 3,
163 .h = 5,
164 .pixmap = {
165 0, 0, 0,
166 0, 0, 0,
167 0, 0, 0,
168 0, 0, 0,
169 0, 0, 0,
173 static struct testcase testcase_xyh_1 = {
174 .x = 1,
175 .y = 1,
176 .lh = 0,
178 .flag = 1,
180 .w = 3,
181 .h = 3,
182 .pixmap = {
183 0, 0, 0,
184 0, 0, 0,
185 0, 0, 0,
189 static struct testcase testcase_xyh_2 = {
190 .x = 1,
191 .y = 1,
192 .lh = 2,
194 .flag = 1,
196 .w = 4,
197 .h = 4,
198 .pixmap = {
199 0, 0, 0, 0,
200 0, 1, 0, 0,
201 0, 1, 0, 0,
202 0, 0, 0, 0,
206 static struct testcase testcase_xyh_clipp_1 = {
207 .x = 1,
208 .y = -10000,
209 .lh = 20000,
211 .flag = 1,
213 .w = 3,
214 .h = 3,
215 .pixmap = {
216 0, 1, 0,
217 0, 1, 0,
218 0, 1, 0,
222 static struct testcase testcase_xyh_clipp_2 = {
223 .x = 1,
224 .y = 1,
225 .lh = 200000,
227 .flag = 1,
229 .w = 3,
230 .h = 3,
231 .pixmap = {
232 0, 0, 0,
233 0, 1, 0,
234 0, 1, 0,
238 static struct testcase testcase_xyh_clipp_3 = {
239 .x = -10000,
240 .y = -10000,
241 .lh = -1,
243 .flag = 1,
245 .w = 3,
246 .h = 3,
247 .pixmap = {
248 0, 0, 0,
249 0, 0, 0,
250 0, 0, 0,
254 const struct tst_suite tst_suite = {
255 .suite_name = "VLine Testsuite",
256 .tests = {
257 {.name = "VLine 1px",
258 .tst_fn = test_vline,
259 .data = &testcase_1_px},
261 {.name = "VLine 3px 1",
262 .tst_fn = test_vline,
263 .data = &testcase_3_px_1},
265 {.name = "VLine 3px 2",
266 .tst_fn = test_vline,
267 .data = &testcase_3_px_2},
269 {.name = "VLine clipping 1",
270 .tst_fn = test_vline,
271 .data = &testcase_clipping_1},
273 {.name = "VLine clipping 2",
274 .tst_fn = test_vline,
275 .data = &testcase_clipping_2},
277 {.name = "VLine clipping 3",
278 .tst_fn = test_vline,
279 .data = &testcase_clipping_3},
281 {.name = "VLineXYH 1",
282 .tst_fn = test_vline,
283 .data = &testcase_xyh_1},
285 {.name = "VLineXYH 2",
286 .tst_fn = test_vline,
287 .data = &testcase_xyh_2},
289 {.name = "VLineXYH clipping 1",
290 .tst_fn = test_vline,
291 .data = &testcase_xyh_clipp_1},
293 {.name = "VLineXYH clipping 2",
294 .tst_fn = test_vline,
295 .data = &testcase_xyh_clipp_2},
297 {.name = "VLineXYH clipping 3",
298 .tst_fn = test_vline,
299 .data = &testcase_xyh_clipp_3},
301 {.name = NULL}