Rename GP_Context -> GP_Pixmap
[gfxprim.git] / tests / loaders / PBM.c
blob7840c1153b017fe9771559e298155c4c5678ccea
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_LoadPBM
34 #define SAVE GP_SavePBM
35 #define READ GP_ReadPBM
36 #include "Loader.h"
37 #include "PBM.h"
39 struct testcase black_1x1_1 = {
40 .w = 1,
41 .h = 1,
42 .pix = 0,
43 .path = "black_1x1_1.pbm",
46 struct testcase black_1x1_2 = {
47 .w = 1,
48 .h = 1,
49 .pix = 0,
50 .path = "black_1x1_2.pbm",
53 struct testcase black_1x1_3 = {
54 .w = 1,
55 .h = 1,
56 .pix = 0,
57 .path = "black_1x1_3.pbm",
60 struct testcase black_1x1_4 = {
61 .w = 1,
62 .h = 1,
63 .pix = 0,
64 .path = "black_1x1_4.pbm",
67 struct testcase white_1x1 = {
68 .w = 1,
69 .h = 1,
70 .pix = 1,
71 .path = "white_1x1.pbm",
74 struct testcase black_1x1_bin = {
75 .w = 1,
76 .h = 1,
77 .pix = 0,
78 .path = "black_1x1_bin.pbm",
81 struct testcase black_2x2_bin = {
82 .w = 2,
83 .h = 2,
84 .pix = 0,
85 .path = "black_2x2_bin.pbm",
88 struct testcase black_3x9_bin = {
89 .w = 3,
90 .h = 9,
91 .pix = 0,
92 .path = "black_3x9_bin.pbm",
95 struct testcase_save_load save_load = {
96 .w = 100,
97 .h = 100,
98 .pixel_type = GP_PIXEL_G1,
101 const struct tst_suite tst_suite = {
102 .suite_name = "PBM",
103 .tests = {
104 {.name = "PBM Load 1x1 (black)",
105 .tst_fn = test_load,
106 //TODO: Add copy to to res path
107 .res_path = "data/pbm/valid/black_1x1_1.pbm",
108 .data = &black_1x1_1,
109 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
111 {.name = "PBM Load 1x1 (white)",
112 .tst_fn = test_load,
113 .res_path = "data/pbm/valid/white_1x1.pbm",
114 .data = &white_1x1,
115 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
117 {.name = "PBM Load 1x1 +comments",
118 .tst_fn = test_load,
119 .res_path = "data/pbm/valid/black_1x1_2.pbm",
120 .data = &black_1x1_2,
121 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
123 {.name = "PBM Load 1x1 +comments +whitespaces",
124 .tst_fn = test_load,
125 .res_path = "data/pbm/valid/black_1x1_3.pbm",
126 .data = &black_1x1_3,
127 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
129 {.name = "PBM Load 1x1 (invalid loadable)",
130 .tst_fn = test_load,
131 .res_path = "data/pbm/valid/black_1x1_4.pbm",
132 .data = &black_1x1_4,
133 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
135 {.name = "PBM Load 1x1 (black) Raw",
136 .tst_fn = test_load,
137 .res_path = "data/pbm/valid/black_1x1_bin.pbm",
138 .data = &black_1x1_bin,
139 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
141 {.name = "PBM Load 2x2 (black) Raw",
142 .tst_fn = test_load,
143 .res_path = "data/pbm/valid/black_2x2_bin.pbm",
144 .data = &black_2x2_bin,
145 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
147 {.name = "PBM Load 3x9 (black) Raw",
148 .tst_fn = test_load,
149 .res_path = "data/pbm/valid/black_3x9_bin.pbm",
150 .data = &black_3x9_bin,
151 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
153 {.name = "PBM Read 1x1 (black)",
154 .tst_fn = test_read,
155 .data = &PBM_ascii_1x1_black,
156 .flags = TST_CHECK_MALLOC},
158 {.name = "PBM Read 1x1 (white)",
159 .tst_fn = test_read,
160 .data = &PBM_ascii_1x1_white,
161 .flags = TST_CHECK_MALLOC},
163 {.name = "PBM Read 1x1 (black) Raw",
164 .tst_fn = test_read,
165 .data = &PBM_bin_1x1_black,
166 .flags = TST_CHECK_MALLOC},
168 {.name = "PBM Read 1x1 (white) Raw",
169 .tst_fn = test_read,
170 .data = &PBM_bin_1x1_white,
171 .flags = TST_CHECK_MALLOC},
173 {.name = "PBM Load corrupt",
174 .tst_fn = test_load_fail,
175 .res_path = "data/pbm/corrupt/short.pbm",
176 .data = "short.pbm",
177 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
179 {.name = "PBM Load wrong header",
180 .tst_fn = test_load_fail,
181 .res_path = "data/pbm/corrupt/wrong_header.pbm",
182 .data = "wrong_header.pbm",
183 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
185 {.name = "PBM Load empty",
186 .tst_fn = test_load_fail,
187 .res_path = "data/pbm/corrupt/empty.pbm",
188 .data = "empty.pbm",
189 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
191 {.name = "PBM Save Load",
192 .tst_fn = test_save_load,
193 .data = &save_load,
194 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
196 {.name = NULL},