Beispiel #1
0
static FLAC__bool test_one_picture(const char *prefix, const PictureFile *pf, const char *res, FLAC__bool fn_only)
{
	FLAC__StreamMetadata *obj;
	const char *error;
	char s[4096];
	if(fn_only)
		flac_snprintf(s, sizeof(s), "%s/%s", prefix, pf->path);
	else
		flac_snprintf(s, sizeof(s), "%u|%s|%s|%s|%s/%s", (unsigned)pf->type, pf->mime_type, pf->description, res, prefix, pf->path);

	printf("testing grabbag__picture_parse_specification(\"%s\")... ", s);
	if(0 == (obj = grabbag__picture_parse_specification(s, &error)))
		return failed_(error);
	if(debug_) {
		printf("\ntype=%u (%s)\nmime_type=%s\ndescription=%s\nwidth=%u\nheight=%u\ndepth=%u\ncolors=%u\ndata_length=%u\n",
			obj->data.picture.type,
			obj->data.picture.type < FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED?
				FLAC__StreamMetadata_Picture_TypeString[obj->data.picture.type] : "UNDEFINED",
			obj->data.picture.mime_type,
			obj->data.picture.description,
			obj->data.picture.width,
			obj->data.picture.height,
			obj->data.picture.depth,
			obj->data.picture.colors,
			obj->data.picture.data_length
		);
	}
	if(obj->data.picture.type != (fn_only? FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER : pf->type))
		return failed_("picture type mismatch");
	if(strcmp(obj->data.picture.mime_type, pf->mime_type))
		return failed_("picture MIME type mismatch");
	if(strcmp((const char *)obj->data.picture.description, (const char *)pf->description))
		return failed_("picture description mismatch");
	if(obj->data.picture.width != pf->width)
		return failed_("picture width mismatch");
	if(obj->data.picture.height != pf->height)
		return failed_("picture height mismatch");
	if(obj->data.picture.depth != pf->depth)
		return failed_("picture depth mismatch");
	if(obj->data.picture.colors != pf->colors)
		return failed_("picture colors mismatch");
	printf("OK\n");
	FLAC__metadata_object_delete(obj);
	return true;
}
FLAC__bool import_pic_from(const char *filename, FLAC__StreamMetadata **picture, const char *specification, FLAC__bool *needs_write)
{
	const char *error_message;

	if(0 == specification || strlen(specification) == 0) {
		fprintf(stderr, "%s: ERROR: empty picture specification\n", filename);
		return false;
	}

	*picture = grabbag__picture_parse_specification(specification, &error_message);

	if(0 == *picture) {
		fprintf(stderr, "%s: ERROR: while parsing picture specification \"%s\": %s\n", filename, specification, error_message);
		return false;
	}

	if(!FLAC__format_picture_is_legal(&(*picture)->data.picture, &error_message)) {
		fprintf(stderr, "%s: ERROR: new PICTURE block for \"%s\" is illegal: %s\n", filename, specification, error_message);
		return false;
	}

	*needs_write = true;
	return true;
}
Beispiel #3
0
Datei: main.c Projekt: ACUVE/flac
static FLAC__bool do_picture(const char *prefix)
{
	FLAC__StreamMetadata *obj;
	PictureResolution res;
	const char *error;
	size_t i;

	printf("\n+++ grabbag unit test: picture\n\n");

	/* invalid spec: no filename */
	printf("testing grabbag__picture_parse_specification(\"\")... ");
	if(0 != (obj = grabbag__picture_parse_specification("", &error)))
		return failed_("expected error, got object");
	printf("OK (failed as expected, error: %s)\n", error);

	/* invalid spec: no filename */
	printf("testing grabbag__picture_parse_specification(\"||||\")... ");
	if(0 != (obj = grabbag__picture_parse_specification("||||", &error)))
		return failed_("expected error, got object");
	printf("OK (failed as expected: %s)\n", error);

	/* invalid spec: no filename */
	printf("testing grabbag__picture_parse_specification(\"|image/gif|||\")... ");
	if(0 != (obj = grabbag__picture_parse_specification("|image/gif|||", &error)))
		return failed_("expected error, got object");
	printf("OK (failed as expected: %s)\n", error);

	/* invalid spec: bad resolution */
	printf("testing grabbag__picture_parse_specification(\"|image/gif|desc|320|0.gif\")... ");
	if(0 != (obj = grabbag__picture_parse_specification("|image/gif|desc|320|0.gif", &error)))
		return failed_("expected error, got object");
	printf("OK (failed as expected: %s)\n", error);

	/* invalid spec: bad resolution */
	printf("testing grabbag__picture_parse_specification(\"|image/gif|desc|320x240|0.gif\")... ");
	if(0 != (obj = grabbag__picture_parse_specification("|image/gif|desc|320x240|0.gif", &error)))
		return failed_("expected error, got object");
	printf("OK (failed as expected: %s)\n", error);

	/* invalid spec: no filename */
	printf("testing grabbag__picture_parse_specification(\"|image/gif|desc|320x240x9|\")... ");
	if(0 != (obj = grabbag__picture_parse_specification("|image/gif|desc|320x240x9|", &error)))
		return failed_("expected error, got object");
	printf("OK (failed as expected: %s)\n", error);

	/* invalid spec: #colors exceeds color depth */
	printf("testing grabbag__picture_parse_specification(\"|image/gif|desc|320x240x9/2345|0.gif\")... ");
	if(0 != (obj = grabbag__picture_parse_specification("|image/gif|desc|320x240x9/2345|0.gif", &error)))
		return failed_("expected error, got object");
	printf("OK (failed as expected: %s)\n", error);

	/* invalid spec: standard icon has to be 32x32 PNG */
	printf("testing grabbag__picture_parse_specification(\"1|-->|desc|32x24x9|0.gif\")... ");
	if(0 != (obj = grabbag__picture_parse_specification("1|-->|desc|32x24x9|0.gif", &error)))
		return failed_("expected error, got object");
	printf("OK (failed as expected: %s)\n", error);

	/* invalid spec: need resolution for linked URL */
	printf("testing grabbag__picture_parse_specification(\"|-->|desc||http://blah.blah.blah/z.gif\")... ");
	if(0 != (obj = grabbag__picture_parse_specification("|-->|desc||http://blah.blah.blah/z.gif", &error)))
		return failed_("expected error, got object");
	printf("OK (failed as expected: %s)\n", error);

	printf("testing grabbag__picture_parse_specification(\"|-->|desc|320x240x9|http://blah.blah.blah/z.gif\")... ");
	if(0 == (obj = grabbag__picture_parse_specification("|-->|desc|320x240x9|http://blah.blah.blah/z.gif", &error)))
		return failed_(error);
	printf("OK\n");
	FLAC__metadata_object_delete(obj);

	/* test automatic parsing of picture files from only the file name */
	for(i = 0; i < sizeof(picturefiles)/sizeof(picturefiles[0]); i++)
		if(!test_one_picture(prefix, picturefiles+i, NULL, /*fn_only=*/true))
			return false;

	/* test automatic parsing of picture files to get resolution/color info */
	for(i = 0; i < sizeof(picturefiles)/sizeof(picturefiles[0]); i++)
		if(!test_one_picture(prefix, picturefiles+i, NULL, /*fn_only=*/false))
			return false;

	res.width = picturefiles[0].width = 320;
	res.height = picturefiles[0].height = 240;
	res.depth = picturefiles[0].depth = 3;
	res.colors = picturefiles[0].colors = 2;
	if(!test_one_picture(prefix, picturefiles+0, &res, /*fn_only=*/false))
		return false;

	return true;
}