Rename GP_Context -> GP_Pixmap
[gfxprim.git] / tests / gfx / HLineAA.c
blobc1d3bc9fccc190d46abf235401de38dc64f187b4
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_Pixmap.h>
28 #include <gfx/GP_HLineAA.h>
30 #include "tst_test.h"
32 #include "common.h"
34 struct testcase {
35 /* line description */
36 GP_Coord x0;
37 GP_Coord x1;
38 GP_Coord y;
40 /* expected result */
41 GP_Size w, h;
42 const char pixmap[];
45 static int test_line(const struct testcase *t)
47 GP_Pixmap *c;
48 int err;
50 c = GP_PixmapAlloc(t->w, t->h, GP_PIXEL_G8);
52 if (c == NULL) {
53 tst_err("Failed to allocate pixmap");
54 return TST_UNTESTED;
57 /* zero the pixels buffer */
58 memset(c->pixels, 0, c->w * c->h);
59 GP_HLineAA(c, t->x0, t->x1, t->y, 0xff);
61 err = compare_buffers(t->pixmap, c);
63 if (err)
64 return TST_FAILED;
66 return TST_SUCCESS;
69 static struct testcase testcase_line_len_0_1 = {
70 .x0 = (1<<8),
71 .x1 = (1<<8),
72 .y = (1<<8),
74 .w = 3,
75 .h = 3,
77 .pixmap = {
78 0x00, 0x00, 0x00,
79 0x00, 0x00, 0x00,
80 0x00, 0x00, 0x00,
84 static struct testcase testcase_line_len_0_2 = {
85 .x0 = (1<<8) + (1<<7),
86 .x1 = (1<<8) + (1<<7),
87 .y = (1<<8),
89 .w = 3,
90 .h = 3,
92 .pixmap = {
93 0x00, 0x00, 0x00,
94 0x00, 0x00, 0x00,
95 0x00, 0x00, 0x00,
99 static struct testcase testcase_line_len_0_3 = {
100 .x0 = (1<<8),
101 .x1 = (1<<8),
102 .y = (1<<8) + (1<<7),
104 .w = 3,
105 .h = 3,
107 .pixmap = {
108 0x00, 0x00, 0x00,
109 0x00, 0x00, 0x00,
110 0x00, 0x00, 0x00,
114 static struct testcase testcase_line_len_0_4 = {
115 .x0 = (1<<8) + (1<<7),
116 .x1 = (1<<8) + (1<<7),
117 .y = (1<<8) + (1<<7),
119 .w = 3,
120 .h = 3,
122 .pixmap = {
123 0x00, 0x00, 0x00,
124 0x00, 0x00, 0x00,
125 0x00, 0x00, 0x00,
129 static struct testcase testcase_line_len_0_5 = {
130 .x0 = (1<<8) + (1<<3) + 1,
131 .x1 = (1<<8) + (1<<3),
132 .y = (1<<8) + (1<<2),
134 .w = 3,
135 .h = 3,
137 .pixmap = {
138 0x00, 0x00, 0x00,
139 0x00, 0x00, 0x00,
140 0x00, 0x00, 0x00,
144 static struct testcase testcase_line_len_05_1 = {
145 .x0 = (1<<8),
146 .x1 = (1<<8) + (1<<7),
147 .y = (1<<8),
149 .w = 3,
150 .h = 3,
152 .pixmap = {
153 0x00, 0x00, 0x00,
154 0x00, 0x80, 0x00,
155 0x00, 0x00, 0x00,
159 static struct testcase testcase_line_len_05_2 = {
160 .x0 = (1<<8),
161 .x1 = (1<<8) + (1<<7),
162 .y = (1<<8) + (1<<7),
164 .w = 3,
165 .h = 4,
167 .pixmap = {
168 0x00, 0x00, 0x00,
169 0x00, 0x40, 0x00,
170 0x00, 0x40, 0x00,
171 0x00, 0x00, 0x00,
175 static struct testcase testcase_line_len_1_1 = {
176 .x0 = (1<<8),
177 .x1 = (2<<8),
178 .y = (1<<8),
180 .w = 4,
181 .h = 3,
183 .pixmap = {
184 0x00, 0x00, 0x00, 0x00,
185 0x00, 0x80, 0x80, 0x00,
186 0x00, 0x00, 0x00, 0x00,
190 static struct testcase testcase_line_len_1_2 = {
191 .x0 = (1<<8) + (1<<7),
192 .x1 = (2<<8) + (1<<7),
193 .y = (1<<8),
195 .w = 4,
196 .h = 3,
198 .pixmap = {
199 0x00, 0x00, 0x00, 0x00,
200 0x00, 0x00, 0xff, 0x00,
201 0x00, 0x00, 0x00, 0x00,
205 static struct testcase testcase_line_len_1_3 = {
206 .x0 = (1<<8),
207 .x1 = (2<<8),
208 .y = (1<<8) + (1<<7),
210 .w = 4,
211 .h = 4,
213 .pixmap = {
214 0x00, 0x00, 0x00, 0x00,
215 0x00, 0x40, 0x40, 0x00,
216 0x00, 0x40, 0x40, 0x00,
217 0x00, 0x00, 0x00, 0x00,
221 static struct testcase testcase_line_len_1_4 = {
222 .x0 = (1<<8) + (1<<7),
223 .x1 = (2<<8) + (1<<7),
224 .y = (1<<8) + (1<<7),
226 .w = 4,
227 .h = 4,
229 .pixmap = {
230 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x80, 0x00,
232 0x00, 0x00, 0x80, 0x00,
233 0x00, 0x00, 0x00, 0x00,
237 static struct testcase testcase_line_len_4_1 = {
238 .x0 = (1<<8),
239 .x1 = (4<<8),
240 .y = (1<<8),
242 .w = 6,
243 .h = 3,
245 .pixmap = {
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247 0x00, 0x80, 0xff, 0xff, 0x80, 0x00,
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 static struct testcase testcase_line_len_4_2 = {
253 .x0 = (1<<8),
254 .x1 = (4<<8),
255 .y = (1<<8) + (1<<7),
257 .w = 6,
258 .h = 4,
260 .pixmap = {
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262 0x00, 0x40, 0x80, 0x80, 0x40, 0x00,
263 0x00, 0x40, 0x80, 0x80, 0x40, 0x00,
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268 const struct tst_suite tst_suite = {
269 .suite_name = "HLineAA Testsuite",
270 .tests = {
271 {.name = "HLineAA len=0 1",
272 .tst_fn = test_line,
273 .data = &testcase_line_len_0_1},
275 {.name = "HLineAA len=0 2",
276 .tst_fn = test_line,
277 .data = &testcase_line_len_0_2},
279 {.name = "HLineAA len=0 3",
280 .tst_fn = test_line,
281 .data = &testcase_line_len_0_3},
283 {.name = "HLineAA len=0 4",
284 .tst_fn = test_line,
285 .data = &testcase_line_len_0_4},
287 {.name = "HLineAA len=0 5",
288 .tst_fn = test_line,
289 .data = &testcase_line_len_0_5},
291 {.name = "HLineAA len=0.5 1",
292 .tst_fn = test_line,
293 .data = &testcase_line_len_05_1},
295 {.name = "HLineAA len=0.5 2",
296 .tst_fn = test_line,
297 .data = &testcase_line_len_05_2},
299 {.name = "LineAA len=1 1",
300 .tst_fn = test_line,
301 .data = &testcase_line_len_1_1},
303 {.name = "LineAA len=1 2",
304 .tst_fn = test_line,
305 .data = &testcase_line_len_1_2},
307 {.name = "LineAA len=1 3",
308 .tst_fn = test_line,
309 .data = &testcase_line_len_1_3},
311 {.name = "LineAA len=1 4",
312 .tst_fn = test_line,
313 .data = &testcase_line_len_1_4},
315 {.name = "LineAA len=4 1",
316 .tst_fn = test_line,
317 .data = &testcase_line_len_4_1},
319 {.name = "LineAA len=4 2",
320 .tst_fn = test_line,
321 .data = &testcase_line_len_4_2},
323 {.name = NULL}