core: Rename GP_Context.c -> GP_Pixmap.c
[gfxprim.git] / tests / loaders / PGM.c
blob197badb443e01d1e4f3f509afb4917ba90fe3a73
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_Loaders.h>
31 #include "tst_test.h"
33 #define LOAD GP_LoadPGM
34 #define SAVE GP_SavePGM
35 #define READ GP_ReadPGM
36 #include "Loader.h"
37 #include "PGM.h"
39 struct testcase black_1x1_1bpp = {
40 .w = 1,
41 .h = 1,
42 .pix = 0,
43 .path = "black_1x1_1bpp.pgm",
46 struct testcase black_1x1_2bpp = {
47 .w = 1,
48 .h = 1,
49 .pix = 0,
50 .path = "black_1x1_2bpp.pgm",
53 struct testcase black_1x1_4bpp = {
54 .w = 1,
55 .h = 1,
56 .pix = 0,
57 .path = "black_1x1_4bpp.pgm",
60 struct testcase black_1x1_8bpp = {
61 .w = 1,
62 .h = 1,
63 .pix = 0,
64 .path = "black_1x1_8bpp.pgm",
67 struct testcase_save_load save_load_1bpp = {
68 .w = 100,
69 .h = 100,
70 .pixel_type = GP_PIXEL_G1,
73 struct testcase_save_load save_load_2bpp = {
74 .w = 100,
75 .h = 100,
76 .pixel_type = GP_PIXEL_G2,
79 struct testcase_save_load save_load_4bpp = {
80 .w = 100,
81 .h = 100,
82 .pixel_type = GP_PIXEL_G4,
85 struct testcase_save_load save_load_8bpp = {
86 .w = 100,
87 .h = 100,
88 .pixel_type = GP_PIXEL_G8,
91 const struct tst_suite tst_suite = {
92 .suite_name = "PGM",
93 .tests = {
94 {.name = "PGM Load 1x1 1bpp (black)",
95 .tst_fn = test_load,
96 .res_path = "data/pgm/valid/black_1x1_1bpp.pgm",
97 .data = &black_1x1_1bpp,
98 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
100 {.name = "PGM Load 1x1 2bpp (black)",
101 .tst_fn = test_load,
102 .res_path = "data/pgm/valid/black_1x1_2bpp.pgm",
103 .data = &black_1x1_2bpp,
104 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
106 {.name = "PGM Load 1x1 4bpp (black)",
107 .tst_fn = test_load,
108 .res_path = "data/pgm/valid/black_1x1_4bpp.pgm",
109 .data = &black_1x1_4bpp,
110 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
112 {.name = "PGM Load 1x1 8bpp (black)",
113 .tst_fn = test_load,
114 .res_path = "data/pgm/valid/black_1x1_8bpp.pgm",
115 .data = &black_1x1_8bpp,
116 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
118 {.name = "PGM Read 1x1 1bpp (black)",
119 .tst_fn = test_read,
120 .data = &PGM_ascii_1x1_1bpp_black,
121 .flags = TST_CHECK_MALLOC},
123 {.name = "PGM Read 1x1 2bpp (black)",
124 .tst_fn = test_read,
125 .data = &PGM_ascii_1x1_2bpp_black,
126 .flags = TST_CHECK_MALLOC},
128 {.name = "PGM Read 1x1 4bpp (black)",
129 .tst_fn = test_read,
130 .data = &PGM_ascii_1x1_4bpp_black,
131 .flags = TST_CHECK_MALLOC},
133 {.name = "PGM Read 1x1 8bpp (black)",
134 .tst_fn = test_read,
135 .data = &PGM_ascii_1x1_8bpp_black,
136 .flags = TST_CHECK_MALLOC},
138 {.name = "PGM Read 1x1 1bpp (white)",
139 .tst_fn = test_read,
140 .data = &PGM_ascii_1x1_1bpp_white,
141 .flags = TST_CHECK_MALLOC},
143 {.name = "PGM Read 1x1 2bpp (white)",
144 .tst_fn = test_read,
145 .data = &PGM_ascii_1x1_2bpp_white,
146 .flags = TST_CHECK_MALLOC},
148 {.name = "PGM Read 1x1 4bpp (white)",
149 .tst_fn = test_read,
150 .data = &PGM_ascii_1x1_4bpp_white,
151 .flags = TST_CHECK_MALLOC},
153 {.name = "PGM Read 1x1 8bpp (white)",
154 .tst_fn = test_read,
155 .data = &PGM_ascii_1x1_8bpp_white,
156 .flags = TST_CHECK_MALLOC},
158 {.name = "PGM Read 1x1 1bpp (white) Raw",
159 .tst_fn = test_read,
160 .data = &PGM_bin_1x1_1bpp_white,
161 .flags = TST_CHECK_MALLOC},
163 {.name = "PGM Read 1x1 2bpp (white) Raw",
164 .tst_fn = test_read,
165 .data = &PGM_bin_1x1_2bpp_white,
166 .flags = TST_CHECK_MALLOC},
168 {.name = "PGM Read 1x1 4bpp (white) Raw",
169 .tst_fn = test_read,
170 .data = &PGM_bin_1x1_4bpp_white,
171 .flags = TST_CHECK_MALLOC},
173 {.name = "PGM Read 1x1 8bpp (white) Raw",
174 .tst_fn = test_read,
175 .data = &PGM_bin_1x1_8bpp_white,
176 .flags = TST_CHECK_MALLOC},
178 {.name = "PGM Save Load 1bpp",
179 .tst_fn = test_save_load,
180 .data = &save_load_1bpp,
181 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
183 {.name = "PGM Save Load 2bpp",
184 .tst_fn = test_save_load,
185 .data = &save_load_2bpp,
186 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
188 {.name = "PGM Save Load 4bpp",
189 .tst_fn = test_save_load,
190 .data = &save_load_4bpp,
191 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
193 {.name = "PGM Save Load 8bpp",
194 .tst_fn = test_save_load,
195 .data = &save_load_8bpp,
196 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
198 {.name = "PGM Load wrong header",
199 .tst_fn = test_load_fail,
200 .res_path = "data/pgm/corrupt/wrong_header.pgm",
201 .data = "wrong_header.pgm",
202 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
204 {.name = "PGM Load incomplete",
205 .tst_fn = test_load_fail,
206 .res_path = "data/pgm/corrupt/incomplete.pgm",
207 .data = "incomplete.pgm",
208 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
210 {.name = NULL},