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-2013 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
25 Very basic GP_Pixmap tests.
30 #include <core/GP_Pixmap.h>
35 * Check that Pixmap is correctly allocated and freed
37 static int Pixmap_Alloc_Free(void)
41 c
= GP_PixmapAlloc(100, 200, GP_PIXEL_RGB888
);
44 tst_msg("GP_PixmapAlloc() failed");
48 /* Assert pixmap properties */
50 tst_msg("Pixmap->bpp != 24 (== %i)", c
->bpp
);
54 if (c
->bytes_per_row
!= 3 * c
->w
) {
55 tst_msg("Pixmap->bytes_per_row != %i (== %i)",
56 3 * c
->w
, c
->bytes_per_row
);
61 tst_msg("Pixmap->w != 100 (== %i)", c
->w
);
66 tst_msg("Pixmap->h != 200 (== %i)", c
->h
);
71 tst_msg("Pixmap->offset != 0");
75 if (c
->pixel_type
!= GP_PIXEL_RGB888
) {
76 tst_msg("Pixmap->pixel_type != GP_PIXEL_RGB888");
80 if (c
->gamma
!= NULL
) {
81 tst_msg("Pixmap->gamma != NULL");
85 if (c
->axes_swap
!= 0 || c
->x_swap
!= 0 || c
->y_swap
!= 0) {
86 tst_msg("Wrong default orientation %i %i %i",
87 c
->axes_swap
, c
->x_swap
, c
->y_swap
);
91 /* access the pixel buffer */
92 *(char*)GP_PIXEL_ADDR(c
, 0, 0) = 0;
93 *(char*)GP_PIXEL_ADDR(c
, 100, 100) = 0;
101 * Asserts that subpixmap structure is initialized correctly
103 static int subpixmap_assert(const GP_Pixmap
*c
, const GP_Pixmap
*sc
,
104 GP_Size w
, GP_Size h
)
106 if (c
->bpp
!= sc
->bpp
) {
107 tst_msg("Pixmap->bpp != SubPixmap->bpp");
111 if (c
->bytes_per_row
!= sc
->bytes_per_row
) {
112 tst_msg("Pixmap->bytes_per_row != SubPixmap->bytes_per_row");
117 tst_msg("SubPixmap->w != %u (== %i)", w
, sc
->w
);
122 tst_msg("SubPixmap->h != %u (== %i)", h
, sc
->h
);
126 if (sc
->offset
!= 0) {
127 tst_msg("SubPixmap->offset != 0");
131 if (sc
->pixel_type
!= GP_PIXEL_RGB888
) {
132 tst_msg("SubPixmap->pixel_type != GP_PIXEL_RGB888");
136 if (sc
->gamma
!= NULL
) {
137 tst_msg("SubPixmap->gamma != NULL");
141 if (sc
->axes_swap
!= 0 || sc
->x_swap
!= 0 || sc
->y_swap
!= 0) {
142 tst_msg("Wrong default orientation %i %i %i",
143 sc
->axes_swap
, sc
->x_swap
, sc
->y_swap
);
147 /* access the start and end of the pixel buffer */
148 *(char*)GP_PIXEL_ADDR(sc
, 0, 0) = 0;
149 *(char*)GP_PIXEL_ADDR(sc
, sc
->w
- 1, sc
->h
- 1) = 0;
154 static int SubPixmap_Alloc_Free(void)
159 c
= GP_PixmapAlloc(300, 300, GP_PIXEL_RGB888
);
162 tst_msg("GP_PixmapAlloc() failed");
166 sc
= GP_SubPixmapAlloc(c
, 100, 100, 100, 100);
173 ret
= subpixmap_assert(c
, sc
, 100, 100);
184 static int SubPixmap_Create(void)
189 c
= GP_PixmapAlloc(300, 300, GP_PIXEL_RGB888
);
192 tst_msg("GP_PixmapAlloc() failed");
196 GP_SubPixmap(c
, &sc
, 100, 100, 100, 100);
198 ret
= subpixmap_assert(c
, &sc
, 100, 100);
208 static int pixmap_zero_w(void)
212 c
= GP_PixmapAlloc(0, 200, GP_PIXEL_G8
);
215 tst_msg("Pixmap with zero width successfuly allocated");
219 if (errno
!= EINVAL
) {
220 tst_msg("Expected errno set to EINVAL");
227 static int pixmap_zero_h(void)
231 c
= GP_PixmapAlloc(200, 0, GP_PIXEL_G8
);
234 tst_msg("Pixmap with zero height successfuly allocated");
238 if (errno
!= EINVAL
) {
239 tst_msg("Expected errno set to EINVAL");
246 static int pixmap_invalid_pixeltype1(void)
250 c
= GP_PixmapAlloc(100, 100, -1);
253 tst_msg("Pixmap with invalid pixel type (-1) succesfully allocated");
257 if (errno
!= EINVAL
) {
258 tst_msg("Expected errno set to EINVAL");
265 static int pixmap_invalid_pixeltype2(void)
269 c
= GP_PixmapAlloc(100, 100, GP_PIXEL_MAX
+ 1000);
272 tst_msg("Pixmap with invalid pixel type (-1) succesfully allocated");
276 if (errno
!= EINVAL
) {
277 tst_msg("Expected errno set to EINVAL");
284 const struct tst_suite tst_suite
= {
285 .suite_name
= "Pixmap Testsuite",
287 {.name
= "Pixmap Alloc Free", .tst_fn
= Pixmap_Alloc_Free
,
288 .flags
= TST_CHECK_MALLOC
},
289 {.name
= "SubPixmap Alloc Free",
290 .tst_fn
= SubPixmap_Alloc_Free
,
291 .flags
= TST_CHECK_MALLOC
},
292 {.name
= "SubPixmap Create",
293 .tst_fn
= SubPixmap_Create
},
294 {.name
= "Pixmap Create w = 0",
295 .tst_fn
= pixmap_zero_w
},
296 {.name
= "Pixmap Create h = 0",
297 .tst_fn
= pixmap_zero_h
},
298 {.name
= "Pixmap Create pixel_type = -1",
299 .tst_fn
= pixmap_invalid_pixeltype1
},
300 {.name
= "Pixmap Create invalid pixel_type",
301 .tst_fn
= pixmap_invalid_pixeltype2
},