From 8a95ba64c179dfd86fc2a298eda4b3181e741efc Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Fri, 9 Feb 2007 16:11:24 +0000 Subject: [PATCH] expand test to include simplified for of specification --- src/test_grabbag/picture/main.c | 24 ++++++++++++++++++------ test/picture.ok | 18 ++++++++++++++++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/test_grabbag/picture/main.c b/src/test_grabbag/picture/main.c index 4b179fa1..11675b3b 100644 --- a/src/test_grabbag/picture/main.c +++ b/src/test_grabbag/picture/main.c @@ -64,15 +64,22 @@ static FLAC__bool failed_(const char *msg) return false; } -static FLAC__bool test_one_picture(const char *prefix, const PictureFile *pf, const char *res) +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) #if defined _MSC_VER || defined __MINGW32__ - _snprintf(s, sizeof(s)-1, "%u|%s|%s|%s|%s/%s", (unsigned)pf->type, pf->mime_type, pf->description, res, prefix, pf->path); + _snprintf(s, sizeof(s)-1, "%s/%s", prefix, pf->path); #else - snprintf(s, sizeof(s)-1, "%u|%s|%s|%s|%s/%s", (unsigned)pf->type, pf->mime_type, pf->description, res, prefix, pf->path); + snprintf(s, sizeof(s)-1, "%s/%s", prefix, pf->path); +#endif + else +#if defined _MSC_VER || defined __MINGW32__ + _snprintf(s, sizeof(s)-1, "%u|%s|%s|%s|%s/%s", (unsigned)pf->type, pf->mime_type, pf->description, res, prefix, pf->path); +#else + snprintf(s, sizeof(s)-1, "%u|%s|%s|%s|%s/%s", (unsigned)pf->type, pf->mime_type, pf->description, res, prefix, pf->path); #endif printf("testing grabbag__picture_parse_specification(\"%s\")... ", s); @@ -92,7 +99,7 @@ static FLAC__bool test_one_picture(const char *prefix, const PictureFile *pf, co obj->data.picture.data_length ); } - if(obj->data.picture.type != pf->type) + 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"); @@ -179,16 +186,21 @@ static FLAC__bool do_picture(const char *prefix) 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, "", /*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, "")) + if(!test_one_picture(prefix, picturefiles+i, "", /*fn_only=*/false)) return false; picturefiles[0].width = 320; picturefiles[0].height = 240; picturefiles[0].depth = 3; picturefiles[0].colors = 2; - if(!test_one_picture(prefix, picturefiles+0, "320x240x3/2")) + if(!test_one_picture(prefix, picturefiles+0, "320x240x3/2", /*fn_only=*/false)) return false; return true; diff --git a/test/picture.ok b/test/picture.ok index b26009cb..4b7e55d6 100644 --- a/test/picture.ok +++ b/test/picture.ok @@ -1,8 +1,8 @@ +++ grabbag unit test: picture -testing grabbag__picture_parse_specification("")... OK (failed as expected, error: invalid picture specification) -testing grabbag__picture_parse_specification("||||")... OK (failed as expected: invalid MIME type) +testing grabbag__picture_parse_specification("")... OK (failed as expected, error: error opening picture file) +testing grabbag__picture_parse_specification("||||")... OK (failed as expected: error opening picture file) testing grabbag__picture_parse_specification("|image/gif|||")... OK (failed as expected: error opening picture file) testing grabbag__picture_parse_specification("|image/gif|desc|320|0.gif")... OK (failed as expected: invalid picture specification: can't parse resolution/color part) testing grabbag__picture_parse_specification("|image/gif|desc|320x240|0.gif")... OK (failed as expected: invalid picture specification: can't parse resolution/color part) @@ -11,6 +11,20 @@ testing grabbag__picture_parse_specification("|image/gif|desc|320x240x9/2345|0.g testing grabbag__picture_parse_specification("1|-->|desc|32x24x9|0.gif")... OK (failed as expected: type 1 icon must be a 32x32 pixel PNG) testing grabbag__picture_parse_specification("|-->|desc||http://blah.blah.blah/z.gif")... OK (failed as expected: unable to extract resolution and color info from URL, user must set explicitly) testing grabbag__picture_parse_specification("|-->|desc|320x240x9|http://blah.blah.blah/z.gif")... OK +testing grabbag__picture_parse_specification("pictures/0.gif")... OK +testing grabbag__picture_parse_specification("pictures/1.gif")... OK +testing grabbag__picture_parse_specification("pictures/2.gif")... OK +testing grabbag__picture_parse_specification("pictures/0.jpg")... OK +testing grabbag__picture_parse_specification("pictures/4.jpg")... OK +testing grabbag__picture_parse_specification("pictures/0.png")... OK +testing grabbag__picture_parse_specification("pictures/1.png")... OK +testing grabbag__picture_parse_specification("pictures/2.png")... OK +testing grabbag__picture_parse_specification("pictures/3.png")... OK +testing grabbag__picture_parse_specification("pictures/4.png")... OK +testing grabbag__picture_parse_specification("pictures/5.png")... OK +testing grabbag__picture_parse_specification("pictures/6.png")... OK +testing grabbag__picture_parse_specification("pictures/7.png")... OK +testing grabbag__picture_parse_specification("pictures/8.png")... OK testing grabbag__picture_parse_specification("3|image/gif|||pictures/0.gif")... OK testing grabbag__picture_parse_specification("4|image/gif|||pictures/1.gif")... OK testing grabbag__picture_parse_specification("0|image/gif|||pictures/2.gif")... OK