Rename GP_Context -> GP_Pixmap
[gfxprim.git] / tests / loaders / JPG.c
blob077eb1bbde3f980bf6c66483087c435bc4c695f8
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 static int test_load_JPG(const char *path)
35 GP_Pixmap *img;
37 errno = 0;
39 img = GP_LoadJPG(path, NULL);
41 if (img == NULL) {
42 switch (errno) {
43 case ENOSYS:
44 tst_msg("Not Implemented");
45 return TST_SKIPPED;
46 default:
47 tst_msg("Got %s", strerror(errno));
48 return TST_FAILED;
53 * TODO: check correct data.
56 GP_PixmapFree(img);
58 return TST_SUCCESS;
61 static int test_save_JPG(GP_PixelType pixel_type)
63 GP_Pixmap *pixmap;
64 int ret;
66 pixmap = GP_PixmapAlloc(100, 100, pixel_type);
68 if (pixmap == NULL) {
69 tst_msg("Failed to allocate pixmap");
70 return TST_UNTESTED;
73 errno = 0;
75 ret = GP_SaveJPG(pixmap, "/dev/null", NULL);
77 if (ret == 0) {
78 tst_msg("Saved successfully");
79 GP_PixmapFree(pixmap);
80 return TST_SUCCESS;
83 switch (errno) {
84 case ENOSYS:
85 tst_msg("Not Implemented");
86 GP_PixmapFree(pixmap);
87 return TST_SKIPPED;
88 default:
89 tst_msg("Failed and errno is not ENOSYS (%i)", errno);
90 GP_PixmapFree(pixmap);
91 return TST_FAILED;
95 const struct tst_suite tst_suite = {
96 .suite_name = "JPEG",
97 .tests = {
98 /* JPEG loader tests */
99 {.name = "JPEG Load 100x100 CMYK",
100 .tst_fn = test_load_JPG,
101 .res_path = "data/jpeg/valid/100x100-cmyk-red.jpeg",
102 .data = "100x100-cmyk-red.jpeg",
103 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
105 {.name = "JPEG Load 100x100 RGB",
106 .tst_fn = test_load_JPG,
107 .res_path = "data/jpeg/valid/100x100-red.jpeg",
108 .data = "100x100-red.jpeg",
109 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
111 {.name = "JPEG Load 100x100 G8",
112 .tst_fn = test_load_JPG,
113 .res_path = "data/jpeg/valid/100x100-grayscale-white.jpeg",
114 .data = "100x100-grayscale-white.jpeg",
115 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
117 {.name = "JPEG Load 100x100 G8",
118 .tst_fn = test_load_JPG,
119 .res_path = "data/jpeg/valid/100x100-grayscale-black.jpeg",
120 .data = "100x100-grayscale-black.jpeg",
121 .flags = TST_TMPDIR | TST_CHECK_MALLOC},
123 /* JPEG save tests */
124 {.name = "JPEG Save 100x100 G8",
125 .tst_fn = test_save_JPG,
126 .data = (void*)GP_PIXEL_G8,
127 .flags = TST_CHECK_MALLOC},
129 {.name = "JPEG Save 100x100 RGB888",
130 .tst_fn = test_save_JPG,
131 .data = (void*)GP_PIXEL_RGB888,
132 .flags = TST_CHECK_MALLOC},
134 {.name = "JPEG Save 100x100 BGR888",
135 .tst_fn = test_save_JPG,
136 .data = (void*)GP_PIXEL_BGR888,
137 .flags = TST_CHECK_MALLOC},
139 {.name = NULL},