Rename GP_Context -> GP_Pixmap
[gfxprim.git] / tests / loaders / PCX.c
blobcf6ad0d8838125f2d44d94b6cf93d7f0a22e1214
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-2014 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 <core/GP_GetPutPixel.h>
29 #include <loaders/GP_PCX.h>
31 #include "tst_test.h"
33 struct testcase {
34 const char *path;
35 GP_Size w, h;
36 GP_PixelType pixel_type;
37 GP_Pixel pixel;
40 static int test_load_PCX(struct testcase *test)
42 GP_Pixmap *img;
44 errno = 0;
46 img = GP_LoadPCX(test->path, NULL);
48 if (img == NULL) {
49 switch (errno) {
50 case ENOSYS:
51 tst_msg("Not Implemented");
52 return TST_SKIPPED;
53 default:
54 tst_msg("Got %s", strerror(errno));
55 return TST_FAILED;
59 if (img->w != test->w || img->h != test->h) {
60 tst_msg("Wrong size have %ux%u expected %ux%u",
61 img->w, img->h, test->w, test->h);
62 GP_PixmapFree(img);
63 return TST_FAILED;
66 if (img->pixel_type != test->pixel_type) {
67 tst_msg("Wrong pixel type have %s expected %s",
68 GP_PixelTypeName(img->pixel_type),
69 GP_PixelTypeName(test->pixel_type));
70 GP_PixmapFree(img);
71 return TST_FAILED;
74 unsigned int x, y, fail = 0;
76 for (x = 0; x < img->w; x++) {
77 for (y = 0; y < img->w; y++) {
78 GP_Pixel p = GP_GetPixel(img, x, y);
80 if (p != test->pixel) {
81 if (!fail)
82 tst_msg("First failed at %u,%u %x %x",
83 x, y, p, test->pixel);
84 fail = 1;
89 if (!fail)
90 tst_msg("Pixmap pixels are correct");
92 GP_PixmapFree(img);
94 if (fail)
95 return TST_FAILED;
97 return TST_SUCCESS;
100 static struct testcase v3_0_1bpp_10x10_white = {
101 .path = "ver3_0_palette_1bpp_10x10_white.pcx",
102 .w = 10,
103 .h = 10,
104 .pixel_type = GP_PIXEL_G1,
105 .pixel = 0x000001,
108 static struct testcase v3_0_2bpp_10x10_white = {
109 .path = "ver3_0_palette_2bpp_10x10_white.pcx",
110 .w = 10,
111 .h = 10,
112 .pixel_type = GP_PIXEL_RGB888,
113 .pixel = 0xffffff,
116 static struct testcase v3_0_4bpp_10x10_white = {
117 .path = "ver3_0_palette_4bpp_10x10_white.pcx",
118 .w = 10,
119 .h = 10,
120 .pixel_type = GP_PIXEL_RGB888,
121 .pixel = 0xffffff,
124 static struct testcase v2_8_4bpp_10x10_white = {
125 .path = "ver2_8_palette_4bpp_10x10_white.pcx",
126 .w = 10,
127 .h = 10,
128 .pixel_type = GP_PIXEL_RGB888,
129 .pixel = 0xffffff,
132 static struct testcase v3_0_8bpp_10x10_white = {
133 .path = "ver3_0_palette_8bpp_10x10_white.pcx",
134 .w = 10,
135 .h = 10,
136 .pixel_type = GP_PIXEL_RGB888,
137 .pixel = 0xffffff,
140 static struct testcase v3_0_24bpp_10x10_white = {
141 .path = "ver3_0_palette_24bpp_10x10_white.pcx",
142 .w = 10,
143 .h = 10,
144 .pixel_type = GP_PIXEL_RGB888,
145 .pixel = 0xffffff,
148 const struct tst_suite tst_suite = {
149 .suite_name = "PCX",
150 .tests = {
151 {.name = "PCX Load ver3.0 1bpp 10x10 white",
152 .tst_fn = test_load_PCX,
153 .res_path = "data/pcx/valid/ver3_0_palette_1bpp_10x10_white.pcx",
154 .data = &v3_0_1bpp_10x10_white,
155 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
157 {.name = "PCX Load ver3.0 2bpp 10x10 white",
158 .tst_fn = test_load_PCX,
159 .res_path = "data/pcx/valid/ver3_0_palette_2bpp_10x10_white.pcx",
160 .data = &v3_0_2bpp_10x10_white,
161 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
163 {.name = "PCX Load ver3.0 4bpp 10x10 white",
164 .tst_fn = test_load_PCX,
165 .res_path = "data/pcx/valid/ver3_0_palette_4bpp_10x10_white.pcx",
166 .data = &v3_0_4bpp_10x10_white,
167 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
169 {.name = "PCX Load ver2.8 4bpp 10x10 white",
170 .tst_fn = test_load_PCX,
171 .res_path = "data/pcx/valid/ver2_8_palette_4bpp_10x10_white.pcx",
172 .data = &v2_8_4bpp_10x10_white,
173 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
175 {.name = "PCX Load ver3.0 8bpp 10x10 white",
176 .tst_fn = test_load_PCX,
177 .res_path = "data/pcx/valid/ver3_0_palette_8bpp_10x10_white.pcx",
178 .data = &v3_0_8bpp_10x10_white,
179 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
181 {.name = "PCX Load ver3.0 24bpp 10x10 white",
182 .tst_fn = test_load_PCX,
183 .res_path = "data/pcx/valid/ver3_0_palette_24bpp_10x10_white.pcx",
184 .data = &v3_0_24bpp_10x10_white,
185 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
186 {.name = NULL},