1 /*****************************************************************************
2 * This file is part of gfxprim library. *
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. *
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. *
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 *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
23 %% extends "base.test.c.t"
25 {% block descr %}GetPutPixel tests.{% endblock %}
31 #include <core/GP_Context.h>
32 #include <core/GP_GetPutPixel.h>
36 static void fill_context(GP_Context *c, GP_Pixel p)
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)
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);
62 static int try_pattern(GP_Context *c, GP_Pixel p)
66 tst_msg("Filling pattern 0x%x", p);
74 %% for pt in pixeltypes
75 %% if not pt.is_unknown()
76 static int GetPutPixel_{{ pt.name }}(void)
81 c = GP_ContextAlloc(100, 100, GP_PIXEL_{{ pt.name }});
84 tst_msg("GP_ContextAlloc() failed");
88 if (try_pattern(c, 0x55555555 & {{ 2 ** pt.pixelsize.size - 1}}))
91 if (try_pattern(c, 0xaaaaaaaa & {{ 2 ** pt.pixelsize.size - 1}}))
94 if (try_pattern(c, 0x0f0f0f0f & {{ 2 ** pt.pixelsize.size - 1}}))
97 if (try_pattern(c, 0xf0f0f0f0 & {{ 2 ** pt.pixelsize.size - 1}}))
110 %% for pt in pixeltypes
111 %% if not pt.is_unknown()
112 static int GetPutPixel_Clipping_{{ pt.name }}(void)
116 c = GP_ContextAlloc(100, 100, GP_PIXEL_{{ pt.name }});
119 tst_msg("GP_ContextAlloc() failed");
123 fill_context(c, 0xffffffff);
128 for (x = -1000; x < 200; x++) {
129 for (y = -1000; y < 200; y++) {
130 if (x > 0 && x < 100 && y > 0 && y < 100)
134 GP_PutPixel(c, x, y, 0);
137 if (GP_GetPixel(c, x, y) != 0) {
138 tst_msg("GP_GetPixel returned non-zero "
155 const struct tst_suite tst_suite = {
156 .suite_name = "GetPutPixel Testsuite",
158 %% for pt in pixeltypes
159 %% if not pt.is_unknown()
160 {.name = "GetPutPixel {{ pt.name }}",
161 .tst_fn = GetPutPixel_{{ pt.name }}},
165 %% for pt in pixeltypes
166 %% if not pt.is_unknown()
167 {.name = "GetPutPixel Clipping {{ pt.name }}",
168 .tst_fn = GetPutPixel_Clipping_{{ pt.name }}},