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-2014 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
23 #ifndef TESTS_LOADER_H
24 #define TESTS_LOADER_H
26 #include "loaders/GP_IO.h"
35 static int test_check(struct testcase
*test
, GP_Pixmap
*img
)
37 unsigned int x
, y
, err
= 0;
39 if (img
->w
!= test
->w
|| img
->h
!= test
->h
) {
40 tst_msg("Invalid image size have %ux%u expected %ux%u",
41 img
->w
, img
->h
, test
->w
, test
->h
);
46 for (x
= 0; x
< img
->w
; x
++) {
47 for (y
= 0; y
< img
->h
; y
++) {
49 GP_Pixel pix
= GP_GetPixel(img
, x
, y
);
51 if (pix
!= test
->pix
) {
53 tst_msg("%08x instead of %08x (%ux%u)",
54 pix
, test
->pix
, x
, y
);
61 tst_msg("And %u errors...", err
);
69 static int test_read(struct testcase
*test
)
75 io
= GP_IOMem(test
->path
, strlen(test
->path
), NULL
);
78 tst_msg("Failed to initialize memory IO: %s", strerror(errno
));
87 tst_msg("Not Implemented");
91 tst_msg("Got %s", strerror(errno
));
97 err
= test_check(test
, img
);
107 static int test_load(struct testcase
*test
)
114 img
= LOAD(test
->path
, NULL
);
119 tst_msg("Not Implemented");
122 tst_msg("Got %s", strerror(errno
));
127 err
= test_check(test
, img
);
135 static int test_load_fail(const char *path
)
141 img
= LOAD(path
, NULL
);
144 tst_msg("Succeeded unexpectedly");
151 tst_msg("Not Implemented");
154 tst_msg("Load failed and errno == 0");
157 tst_msg("Got %s", strerror(errno
));
165 # if defined(SAVE) && defined(LOAD)
168 * Saves and loads image using the SAVE and LOAD functions
169 * and compares the results.
171 struct testcase_save_load
{
172 GP_PixelType pixel_type
;
176 static int test_save_load(struct testcase_save_load
*test
)
178 GP_Pixmap
*img
, *img2
;
181 img
= GP_PixmapAlloc(test
->w
, test
->h
, test
->pixel_type
);
184 tst_msg("Failed to allocate pixmap %ux%u %s",
185 test
->w
, test
->h
, GP_PixelTypeName(test
->pixel_type
));
189 for (x
= 0; x
< img
->w
; x
++)
190 for (y
= 0; y
< img
->w
; y
++)
191 GP_PutPixel(img
, x
, y
, 0);
195 if (SAVE(img
, "testfile", NULL
)) {
196 if (errno
== ENOSYS
) {
197 tst_msg("Not implemented");
201 tst_msg("Failed to save pixmap %ux%u %s: %s",
202 test
->w
, test
->h
, GP_PixelTypeName(test
->pixel_type
),
208 img2
= LOAD("testfile", NULL
);
213 tst_msg("Not Implemented");
217 tst_msg("Got %s", strerror(errno
));
223 if (img
->w
!= img2
->w
|| img
->h
!= img2
->h
) {
224 tst_msg("Source size %ux%u and loaded size %ux%u differs",
225 img
->w
, img
->h
, img2
->w
, img2
->h
);
231 if (img
->pixel_type
!= img2
->pixel_type
) {
234 tst_msg("Source pixel type %s and loaded type %s differs",
235 GP_PixelTypeName(img
->pixel_type
),
236 GP_PixelTypeName(img2
->pixel_type
));
240 if (GP_GetPixel(img2
, 0, 0) != 0) {
241 tst_msg("Pixel value is wrong %x", GP_GetPixel(img2
, 0, 0));
253 # endif /* SAVE && LOAD */
255 #endif /* TESTS_LOADER_H */