Rename GP_Context -> GP_Pixmap
[gfxprim.git] / tests / gfx / CircleSeg.c
blobb398c9afd51ea48dd84309bdb7512420047a754a
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-2012 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_CircleSeg.h>
30 #include "tst_test.h"
32 #include "common.h"
34 static const char circle_empty_11x11[] = {
35 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
48 static const char circle_r_0_11x11[] = {
49 0, 0, 0, 0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0, 0, 0, 0, 0, 0, 0, 0, 0,
84 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
86 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90 static const char circle_r_1_s_3_11x11[] = {
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
97 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104 static const char circle_r_1_s_4_11x11[] = {
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
111 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
118 static const char circle_r_2_s_1_2_11x11[] = {
119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
122 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
123 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
124 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
129 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132 static const char circle_r_2_s_1_3_11x11[] = {
133 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
134 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
135 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
136 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
137 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
138 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
139 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
140 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
146 static const char circle_r_2_s_1_4_11x11[] = {
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
150 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
151 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
152 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
153 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
154 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
156 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
157 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
160 static int test_circle(const char *pattern, GP_Size w, GP_Size h,
161 GP_Coord x, GP_Coord y, const int r, uint8_t seg_flag)
163 GP_Pixmap *c;
164 int err;
166 c = GP_PixmapAlloc(w, h, GP_PIXEL_G8);
168 if (c == NULL) {
169 tst_err("Failed to allocate pixmap");
170 return TST_UNTESTED;
173 /* zero the pixels buffer */
174 memset(c->pixels, 0, c->w * c->h);
176 GP_CircleSeg(c, x, y, r, seg_flag, 1);
178 err = compare_buffers(pattern, c);
180 if (err) {
181 tst_msg("Patterns are different");
182 return TST_FAILED;
185 return TST_SUCCESS;
188 static int test_circle_r_0_s_1(void)
190 return test_circle(circle_r_0_11x11, 11, 11, 5, 5, 0, GP_CIRCLE_SEG1);
193 static int test_circle_r_0_s_0(void)
195 return test_circle(circle_empty_11x11, 11, 11, 5, 5, 0, 0);
198 static int test_circle_r_1_s_1(void)
200 return test_circle(circle_r_1_s_1_11x11, 11, 11, 5, 5, 1, GP_CIRCLE_SEG1);
203 static int test_circle_r_1_s_2(void)
205 return test_circle(circle_r_1_s_2_11x11, 11, 11, 5, 5, 1, GP_CIRCLE_SEG2);
208 static int test_circle_r_1_s_3(void)
210 return test_circle(circle_r_1_s_3_11x11, 11, 11, 5, 5, 1, GP_CIRCLE_SEG3);
213 static int test_circle_r_1_s_4(void)
215 return test_circle(circle_r_1_s_4_11x11, 11, 11, 5, 5, 1, GP_CIRCLE_SEG4);
218 static int test_circle_r_2_s_1_2(void)
220 return test_circle(circle_r_2_s_1_2_11x11, 11, 11, 5, 5, 2,
221 GP_CIRCLE_SEG1|GP_CIRCLE_SEG2);
224 static int test_circle_r_2_s_1_3(void)
226 return test_circle(circle_r_2_s_1_3_11x11, 11, 11, 5, 5, 2,
227 GP_CIRCLE_SEG1|GP_CIRCLE_SEG3);
230 static int test_circle_r_2_s_1_4(void)
232 return test_circle(circle_r_2_s_1_4_11x11, 11, 11, 5, 5, 2,
233 GP_CIRCLE_SEG1|GP_CIRCLE_SEG4);
236 static int test_circle_r__2_s_1_3(void)
238 return test_circle(circle_r_2_s_1_3_11x11, 11, 11, 5, 5, -2,
239 GP_CIRCLE_SEG1|GP_CIRCLE_SEG3);
242 const struct tst_suite tst_suite = {
243 .suite_name = "GFX CircleSeg Testsuite",
244 .tests = {
245 {.name = "CircleSeg Seg0 r=0", .tst_fn = test_circle_r_0_s_0},
246 {.name = "CircleSeg Seg1 r=0", .tst_fn = test_circle_r_0_s_1},
247 {.name = "CircleSeg Seg1 r=1", .tst_fn = test_circle_r_1_s_1},
248 {.name = "CircleSeg Seg2 r=1", .tst_fn = test_circle_r_1_s_2},
249 {.name = "CircleSeg Seg3 r=1", .tst_fn = test_circle_r_1_s_3},
250 {.name = "CircleSeg Seg4 r=1", .tst_fn = test_circle_r_1_s_4},
251 {.name = "CircleSeg Seg1|2 r=2", .tst_fn = test_circle_r_2_s_1_2},
252 {.name = "CircleSeg Seg1|3 r=2", .tst_fn = test_circle_r_2_s_1_3},
253 {.name = "CircleSeg Seg1|4 r=2", .tst_fn = test_circle_r_2_s_1_4},
254 {.name = "CircleSeg Seg1|3 r=-2", .tst_fn = test_circle_r__2_s_1_3},
255 {.name = NULL}