core: Rename GP_Context.c -> GP_Pixmap.c
[gfxprim.git] / tests / loaders / ZIP.c
blob1632741299b3e9ef790776c984f7558bce399749
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-2013 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 <loaders/GP_Loaders.h>
30 #include "tst_test.h"
32 struct test {
33 GP_Size w, h;
34 const char *path;
37 static int test_load(struct test *test)
39 GP_Container *zip = GP_OpenZip(test->path);
40 GP_Pixmap *img;
41 int ret = TST_SUCCESS;
43 if (!zip) {
44 tst_msg("Failed to open zip");
45 return TST_FAILED;
48 img = GP_ContainerLoad(zip, NULL);
50 if (!img) {
51 tst_msg("Failed to load image");
52 return TST_FAILED;
55 if (img->w != test->w || img->h != test->h) {
56 tst_msg("Image has wrong size, expected %ux%u have %ux%u",
57 test->w, test->h, img->w, img->h);
58 ret = TST_FAILED;
61 GP_PixmapFree(img);
62 GP_ContainerClose(zip);
64 return ret;
67 struct test jpeg_deflated = {
68 .w = 100,
69 .h = 100,
70 .path = "jpeg_deflated.zip"
73 struct test jpeg_stored = {
74 .w = 100,
75 .h = 100,
76 .path = "jpeg_stored.zip"
79 struct test mixed_content = {
80 .w = 100,
81 .h = 100,
82 .path = "mixed_content.zip"
86 * Test ZIP with no images, we expect to get NULL with errno set to zero
88 static int no_images(const char *path)
90 GP_Container *zip = GP_OpenZip(path);
91 GP_Pixmap *img;
92 int ret = TST_SUCCESS;
94 if (!zip) {
95 tst_msg("Failed to open zip");
96 return TST_FAILED;
99 img = GP_ContainerLoad(zip, NULL);
101 if (img) {
102 tst_msg("Loaded image from zip without images");
103 ret = TST_FAILED;
106 if (errno) {
107 tst_msg("Get errno %d (%s)", errno, strerror(errno));
108 ret = TST_FAILED;
111 GP_ContainerClose(zip);
113 return ret;
116 const struct tst_suite tst_suite = {
117 .suite_name = "ZIP",
118 .tests = {
119 {.name = "Load JPEG deflated in ZIP",
120 .tst_fn = test_load,
121 .res_path = "data/zip/valid/jpeg_deflated.zip",
122 .data = &jpeg_deflated,
123 .flags = TST_TMPDIR | TST_MALLOC_CANARIES},
125 {.name = "Load JPEG stored in ZIP",
126 .tst_fn = test_load,
127 .res_path = "data/zip/valid/jpeg_stored.zip",
128 .data = &jpeg_stored,
129 .flags = TST_TMPDIR | TST_MALLOC_CANARIES},
131 {.name = "Load JPEG is second file in ZIP",
132 .tst_fn = test_load,
133 .res_path = "data/zip/valid/mixed_content.zip",
134 .data = &mixed_content,
135 .flags = TST_TMPDIR | TST_MALLOC_CANARIES},
137 {.name = "Load ZIP with no images",
138 .tst_fn = no_images,
139 .res_path = "data/zip/valid/no_images.zip",
140 .data = "no_images.zip",
141 .flags = TST_TMPDIR | TST_MALLOC_CANARIES},
143 {.name = NULL},