1 /* test_picture - Simple tester for cuesheet routines in grabbag
2 * Copyright (C) 2006 Josh Coalson
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "FLAC/assert.h"
25 #include "share/grabbag.h"
29 const char *mime_type;
30 const char *description;
37 PictureFile picturefiles[] = {
38 { "0.gif", "image/gif" , "", 24, 24, 24, 2 },
39 { "1.gif", "image/gif" , "", 12, 8, 24, 256 },
40 { "2.gif", "image/gif" , "", 16, 14, 24, 128 },
41 { "0.jpg", "image/jpeg", "", 30, 20, 8, 0 },
42 { "4.jpg", "image/jpeg", "", 31, 47, 24, 0 },
43 { "0.png", "image/png" , "", 30, 20, 8, 0 },
44 { "1.png", "image/png" , "", 30, 20, 8, 0 },
45 { "2.png", "image/png" , "", 30, 20, 24, 7 },
46 { "3.png", "image/png" , "", 30, 20, 24, 7 },
47 { "4.png", "image/png" , "", 31, 47, 24, 0 },
48 { "5.png", "image/png" , "", 31, 47, 24, 0 },
49 { "6.png", "image/png" , "", 31, 47, 24, 23 },
50 { "7.png", "image/png" , "", 31, 47, 24, 23 },
51 { "8.png", "image/png" , "", 32, 32, 32, 0 }
54 static FLAC__bool debug_ = false;
56 static FLAC__bool failed_(const char *msg)
59 printf("FAILED, %s\n", msg);
66 static FLAC__bool test_one_picture(const char *prefix, const PictureFile *pf, const char *res)
68 FLAC__StreamMetadata *obj;
71 snprintf(s, sizeof(s)-1, "%s|%s|%s|%s/%s", pf->mime_type, pf->description, res, prefix, pf->path);
73 printf("testing grabbag__picture_parse_specification(\"%s\")... ", s);
74 if(0 == (obj = grabbag__picture_parse_specification(s, &error)))
75 return failed_(error);
77 printf("\nmime_type=%s\ndescription=%s\nwidth=%u\nheight=%u\ndepth=%u\ncolors=%u\ndata_length=%u\n",
78 obj->data.picture.mime_type,
79 obj->data.picture.description,
80 obj->data.picture.width,
81 obj->data.picture.height,
82 obj->data.picture.depth,
83 obj->data.picture.colors,
84 obj->data.picture.data_length
87 if(strcmp(obj->data.picture.mime_type, pf->mime_type))
88 return failed_("picture MIME type mismatch");
89 if(strcmp((const char *)obj->data.picture.description, (const char *)pf->description))
90 return failed_("picture description mismatch");
91 if(obj->data.picture.width != pf->width)
92 return failed_("picture width mismatch");
93 if(obj->data.picture.height != pf->height)
94 return failed_("picture height mismatch");
95 if(obj->data.picture.depth != pf->depth)
96 return failed_("picture depth mismatch");
97 if(obj->data.picture.colors != pf->colors)
98 return failed_("picture colors mismatch");
100 FLAC__metadata_object_delete(obj);
104 static FLAC__bool do_picture(const char *prefix)
106 FLAC__StreamMetadata *obj;
110 printf("\n+++ grabbag unit test: picture\n\n");
112 /* invalid spec: no filename */
113 printf("testing grabbag__picture_parse_specification(\"\")... ");
114 if(0 != (obj = grabbag__picture_parse_specification("", &error)))
115 return failed_("expected error, got object");
116 printf("OK (failed as expected, error: %s)\n", error);
118 /* invalid spec: no filename */
119 printf("testing grabbag__picture_parse_specification(\"|||\")... ");
120 if(0 != (obj = grabbag__picture_parse_specification("|||", &error)))
121 return failed_("expected error, got object");
122 printf("OK (failed as expected: %s)\n", error);
124 /* invalid spec: no filename */
125 printf("testing grabbag__picture_parse_specification(\"image/gif|||\")... ");
126 if(0 != (obj = grabbag__picture_parse_specification("image/gif|||", &error)))
127 return failed_("expected error, got object");
128 printf("OK (failed as expected: %s)\n", error);
130 /* invalid spec: bad resolution */
131 printf("testing grabbag__picture_parse_specification(\"image/gif|desc|320|0.gif\")... ");
132 if(0 != (obj = grabbag__picture_parse_specification("image/gif|desc|320|0.gif", &error)))
133 return failed_("expected error, got object");
134 printf("OK (failed as expected: %s)\n", error);
136 /* invalid spec: bad resolution */
137 printf("testing grabbag__picture_parse_specification(\"image/gif|desc|320x240|0.gif\")... ");
138 if(0 != (obj = grabbag__picture_parse_specification("image/gif|desc|320x240|0.gif", &error)))
139 return failed_("expected error, got object");
140 printf("OK (failed as expected: %s)\n", error);
142 /* invalid spec: no filename */
143 printf("testing grabbag__picture_parse_specification(\"image/gif|desc|320x240x9|\")... ");
144 if(0 != (obj = grabbag__picture_parse_specification("image/gif|desc|320x240x9|", &error)))
145 return failed_("expected error, got object");
146 printf("OK (failed as expected: %s)\n", error);
148 /* invalid spec: #colors exceeds color depth */
149 printf("testing grabbag__picture_parse_specification(\"image/gif|desc|320x240x9/2345|0.gif\")... ");
150 if(0 != (obj = grabbag__picture_parse_specification("image/gif|desc|320x240x9/2345|0.gif", &error)))
151 return failed_("expected error, got object");
152 printf("OK (failed as expected: %s)\n", error);
154 /* invalid spec: need resolution for linked URL */
155 printf("testing grabbag__picture_parse_specification(\"-->|desc||http://blah.blah.blah/z.gif\")... ");
156 if(0 != (obj = grabbag__picture_parse_specification("-->|desc||http://blah.blah.blah/z.gif", &error)))
157 return failed_("expected error, got object");
158 printf("OK (failed as expected: %s)\n", error);
160 printf("testing grabbag__picture_parse_specification(\"-->|desc|320x240x9|http://blah.blah.blah/z.gif\")... ");
161 if(0 == (obj = grabbag__picture_parse_specification("-->|desc|320x240x9|http://blah.blah.blah/z.gif", &error)))
162 return failed_(error);
165 /* test automatic parsing of picture files to get resolution/color info */
166 for(i = 0; i < sizeof(picturefiles)/sizeof(picturefiles[0]); i++)
167 if(!test_one_picture(prefix, picturefiles+i, ""))
170 picturefiles[0].width = 320;
171 picturefiles[0].height = 240;
172 picturefiles[0].depth = 3;
173 picturefiles[0].colors = 2;
174 if(!test_one_picture(prefix, picturefiles+0, "320x240x3/2"))
180 int main(int argc, char *argv[])
182 const char *usage = "usage: test_pictures path_prefix\n";
184 if(argc > 1 && 0 == strcmp(argv[1], "-h")) {
190 fprintf(stderr, usage);
194 return do_picture(argv[1])? 0 : 1;