diff options
author | Mike Frysinger <vapier@gentoo.org> | 2021-03-06 13:55:40 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2021-03-06 13:55:40 -0500 |
commit | 6ca52e78bc5dccedd16f177cce53c96191401b59 (patch) | |
tree | d12028737075ce5c454419df42839f94e3ed7a00 /tests/avif | |
parent | b04ff8dbc74ca233e07da964ed6863f2b8500eb8 (diff) | |
download | libgd-6ca52e78bc5dccedd16f177cce53c96191401b59.tar.gz |
avif: simplify tests with gdtest helpers
Diffstat (limited to 'tests/avif')
-rw-r--r-- | tests/avif/bad_input.c | 25 | ||||
-rw-r--r-- | tests/avif/compare_avif_to_png.c | 30 |
2 files changed, 16 insertions, 39 deletions
diff --git a/tests/avif/bad_input.c b/tests/avif/bad_input.c index a9f976b..0f814c9 100644 --- a/tests/avif/bad_input.c +++ b/tests/avif/bad_input.c @@ -9,38 +9,23 @@ #include "gd.h" #include "gdtest.h" -#define PATH "avif/" -#define MAX_FILEPATH_LENGTH 50 - -#define NON_AVIF_FILE_NAME "sunset.png" -#define AVIF_FILE_NAME "sunset.avif" - int main() { FILE *fp; int retval; - char nonAvifFilePath[MAX_FILEPATH_LENGTH], avifFilePath[MAX_FILEPATH_LENGTH]; gdImagePtr realIm, badIm; void *rv; int size; -// Create paths for our files. - strcpy(avifFilePath, PATH); - strcat(avifFilePath, AVIF_FILE_NAME); - - strcpy(nonAvifFilePath, PATH); - strcat(nonAvifFilePath, NON_AVIF_FILE_NAME); + // Read in an AVIF image for testing. -// Read in an AVIF image for testing. - - fp = gdTestFileOpen(avifFilePath); + fp = gdTestFileOpen2("avif", "sunset.avif"); realIm = gdImageCreateFromAvif(fp); fclose(fp); if (!gdTestAssertMsg(realIm != NULL, "gdImageCreateFromAvif() failed\n")) return 1; -// Try to decode a non-AVIF file. - - fp = gdTestFileOpen(nonAvifFilePath); + // Try to decode a non-AVIF file. + fp = gdTestFileOpen2("avif", "sunset.png"); badIm = gdImageCreateFromAvif(fp); fclose(fp); gdTestAssertMsg(badIm == NULL, "gdImageCreateFromAvif() failed to return NULL when passed a non-AVIF file\n"); @@ -48,7 +33,7 @@ int main() { if (badIm) gdImageDestroy(badIm); - // Try to encode a valid image with bad quality parameters. This should still work. + // Try to encode a valid image with bad quality parameters. This should still work. rv = gdImageAvifPtrEx(realIm, &size, 400, 10); gdTestAssertMsg(rv != NULL, "gdImageAvifPtrEx() rejected an overly high quality param instead of clamping it to a valid value"); diff --git a/tests/avif/compare_avif_to_png.c b/tests/avif/compare_avif_to_png.c index 099078a..6330ea3 100644 --- a/tests/avif/compare_avif_to_png.c +++ b/tests/avif/compare_avif_to_png.c @@ -17,16 +17,13 @@ #include "gd.h" #include "gdtest.h" -#define PATH "avif/" -#define MAX_FILEPATH_LENGTH 200 - int main() { FILE *fp; gdImagePtr imFromPng = NULL, imFromAvif = NULL; void *avifImDataPtr = NULL, *pngImDataPtr = NULL; int size; - char filePath[MAX_FILEPATH_LENGTH], pngFilePath[MAX_FILEPATH_LENGTH], avifFilePath[MAX_FILEPATH_LENGTH]; - char errMsg[MAX_FILEPATH_LENGTH + 100]; + char pngFilename[100], avifFilename[100], *pngFilePath; + char errMsg[4096]; static const char * const filenames[] = {"baboon", "dice_with_alpha", "plum_blossom_12bit", "sunset"}; const int filesCount = sizeof(filenames) / sizeof(filenames[0]); @@ -35,13 +32,9 @@ int main() { // First, encode each PNG into an AVIF (with the GD format as an intermediary), // then compare the result with the original PNG. + sprintf(pngFilename, "%s.png", filenames[i]); - strcpy(filePath, PATH); - strcat(filePath, filenames[i]); - strcat(strcpy(pngFilePath, filePath), ".png"); - strcat(strcpy(avifFilePath, filePath), ".avif"); - - fp = gdTestFileOpen(pngFilePath); + fp = gdTestFileOpen2("avif", pngFilename); imFromPng = gdImageCreateFromPng(fp); fclose(fp); @@ -63,14 +56,12 @@ int main() { gdTestAssertMsg(gdAssertImageEquals(imFromPng, imFromAvif), errMsg); // Then, decode each AVIF into a GD format, and compare that with the orginal PNG. - avif2png: - continue; -/* Skip this reverse test for now, until we can find images that encode to PNGs - losslessly. - - fp = gdTestFileOpen(avifFilePath); + // Skip this reverse test for now, until we can find images that encode to PNGs losslessly. +if (0) { + sprintf(avifFilename, "%s.avif", filenames[i]); + fp = gdTestFileOpen2("avif", avifFilename); imFromAvif = gdImageCreateFromAvif(fp); fclose(fp); @@ -79,10 +70,11 @@ avif2png: continue; strcat(strcpy(errMsg, filenames[i]), ".avif: Encoded PNG image did not match original AVIF\n"); + pngFilePath = gdTestFilePath2("avif", pngFilename); gdTestAssertMsg(gdAssertImageEqualsToFile(pngFilePath, imFromAvif), errMsg); -*/ - + free(pngFilePath); } + } if (imFromPng) gdImageDestroy(imFromPng); |