templates: Fix description block id, add description
[gfxprim/pasky.git] / tests / core / GetPutPixel.gen.c.t
bloba84350982333254cecba7e0ed1d47066b1486089
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 %% extends "base.test.c.t"
25 {% block descr %}GetPutPixel tests.{% endblock %}
27 %% block body
29 #include <stdio.h>
31 #include <core/GP_Context.h>
32 #include <core/GP_GetPutPixel.h>
34 #include "tst_test.h"
36 static void fill_context(GP_Context *c, GP_Pixel p)
38         GP_Coord x, y;
40         for (x = 0; x < (GP_Coord)c->w; x++)
41                 for (y = 0; y < (GP_Coord)c->h; y++)
42                         GP_PutPixel(c, x, y, p);
45 static int check_filled(GP_Context *c)
47         GP_Coord x, y;
48         GP_Pixel p;
50         p = GP_GetPixel(c, 0, 0);
52         for (x = 0; x < (GP_Coord)c->w; x++)
53                 for (y = 0; y < (GP_Coord)c->h; y++)
54                         if (p != GP_GetPixel(c, x, y)) {
55                                 tst_msg("Pixels different %i %i", x, y);
56                                 return 1;
57                         }
58         
59         return 0;
62 static int try_pattern(GP_Context *c, GP_Pixel p)
64         fill_context(c, p);
66         tst_msg("Filling pattern 0x%x", p);
68         if (check_filled(c))
69                 return 1;
71         return 0;
74 %% for pt in pixeltypes
75 %% if not pt.is_unknown()
76 static int GetPutPixel_{{ pt.name }}(void)
78         GP_Context *c;
79         int err = 0;
81         c = GP_ContextAlloc(100, 100, GP_PIXEL_{{ pt.name }});
83         if (c == NULL) {
84                 tst_msg("GP_ContextAlloc() failed");
85                 return TST_UNTESTED;
86         }
88         if (try_pattern(c, 0x55555555 & {{ 2 ** pt.pixelsize.size - 1}}))
89                 err++;
90         
91         if (try_pattern(c, 0xaaaaaaaa & {{ 2 ** pt.pixelsize.size - 1}}))
92                 err++;
93         
94         if (try_pattern(c, 0x0f0f0f0f & {{ 2 ** pt.pixelsize.size - 1}}))
95                 err++;
96         
97         if (try_pattern(c, 0xf0f0f0f0 & {{ 2 ** pt.pixelsize.size - 1}}))
98                 err++;
100         GP_ContextFree(c);
102         if (err)
103                 return TST_FAILED;
105         return TST_SUCCESS;
107 %% endif
108 %% endfor
110 %% for pt in pixeltypes
111 %% if not pt.is_unknown()
112 static int GetPutPixel_Clipping_{{ pt.name }}(void)
114         GP_Context *c;
115         
116         c = GP_ContextAlloc(100, 100, GP_PIXEL_{{ pt.name }});
118         if (c == NULL) {
119                 tst_msg("GP_ContextAlloc() failed");
120                 return TST_UNTESTED;
121         }
123         fill_context(c, 0xffffffff);
125         GP_Coord x, y;
126         int err = 0;
128         for (x = -1000; x < 200; x++) {
129                 for (y = -1000; y < 200; y++) {
130                         if (x > 0 && x < 100 && y > 0 && y < 100)
131                                 continue;
132                 
133                         /* Must be no-op */
134                         GP_PutPixel(c, x, y, 0);
136                         /* Must return 0 */
137                         if (GP_GetPixel(c, x, y) != 0) {
138                                 tst_msg("GP_GetPixel returned non-zero "
139                                         "at %i %i", x, y);
140                                 err++;
141                         }
142                 }
143         }
144         
145         GP_ContextFree(c);
146         
147         if (err)
148                 return TST_FAILED;
150         return TST_SUCCESS;
152 %% endif
153 %% endfor
155 const struct tst_suite tst_suite = {
156         .suite_name = "GetPutPixel Testsuite",
157         .tests = {
158 %% for pt in pixeltypes
159 %% if not pt.is_unknown()
160                 {.name = "GetPutPixel {{ pt.name }}", 
161                  .tst_fn = GetPutPixel_{{ pt.name }}},
162 %% endif
163 %% endfor
165 %% for pt in pixeltypes
166 %% if not pt.is_unknown()
167                 {.name = "GetPutPixel Clipping {{ pt.name }}", 
168                  .tst_fn = GetPutPixel_Clipping_{{ pt.name }}},
169 %% endif
170 %% endfor
171                 
172                 {.name = NULL}
173         }
176 %% endblock body