diff options
Diffstat (limited to 'tests')
309 files changed, 3858 insertions, 723 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c4fa9ca..b279f63 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,3 @@ - if (BUILD_TEST) SET(DART_TESTING_TIMEOUT 5) @@ -18,6 +17,7 @@ if (BUILD_TEST) include_directories (BEFORE ${GD_INCLUDE_DIR} "${GDTEST_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}/tests/gdtest") SET(TESTS_DIRS + avif bmp fontconfig freetype @@ -28,16 +28,23 @@ if (BUILD_TEST) gdimageclone gdimagecolor gdimagecolorclosest + gdimagecolorclosesthwb gdimagecolordeallocate gdimagecolorexact + gdimagecolormatch gdimagecolorreplace gdimagecolorresolve gdimagecolortransparent + gdimagecompare gdimagecontrast gdimageconvolution gdimagecopy + gdimagecopymerge + gdimagecopymergegray gdimagecopyresampled + gdimagecopyresized gdimagecopyrotated + gdimagecreate gdimagecrop gdimagefile gdimagefill @@ -48,6 +55,7 @@ if (BUILD_TEST) gdimagefilltoborder gdimagefilter gdimageflip + gdimageellipse gdimagegrayscale gdimageline gdimagenegate @@ -58,16 +66,24 @@ if (BUILD_TEST) gdimagerotate gdimagescale gdimagescatterex + gdimagesetinterpolationmethod gdimagesetpixel + gdimagesquaretocircle + gdimagestring + gdimagestring16 gdimagestringft gdimagestringftex + gdimagestringup + gdimagestringup16 gdimagetruecolortopalette gdinterpolatedscale gdnewfilectx gdtest gdtiled gdtransformaffineboundingbox + gdtransformaffinecopy gif + heif jpeg png tga diff --git a/tests/Makefile.am b/tests/Makefile.am index fc5ed2b..3630810 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -13,6 +13,7 @@ CLEANFILES = EXTRA_DIST = TESTS = +include avif/Makemodule.am include bmp/Makemodule.am include fontconfig/Makemodule.am include freetype/Makemodule.am @@ -23,16 +24,23 @@ include gdimagebrightness/Makemodule.am include gdimageclone/Makemodule.am include gdimagecolor/Makemodule.am include gdimagecolorclosest/Makemodule.am +include gdimagecolorclosesthwb/Makemodule.am include gdimagecolordeallocate/Makemodule.am include gdimagecolorexact/Makemodule.am +include gdimagecolormatch/Makemodule.am include gdimagecolorreplace/Makemodule.am include gdimagecolorresolve/Makemodule.am include gdimagecolortransparent/Makemodule.am +include gdimagecompare/Makemodule.am include gdimagecontrast/Makemodule.am include gdimageconvolution/Makemodule.am include gdimagecopy/Makemodule.am +include gdimagecopymerge/Makemodule.am +include gdimagecopymergegray/Makemodule.am include gdimagecopyresampled/Makemodule.am +include gdimagecopyresized/Makemodule.am include gdimagecopyrotated/Makemodule.am +include gdimagecreate/Makemodule.am include gdimagecrop/Makemodule.am include gdimagefile/Makemodule.am include gdimagefill/Makemodule.am @@ -43,6 +51,7 @@ include gdimagefilledrectangle/Makemodule.am include gdimagefilltoborder/Makemodule.am include gdimagefilter/Makemodule.am include gdimageflip/Makemodule.am +include gdimageellipse/Makemodule.am include gdimagegrayscale/Makemodule.am include gdimageline/Makemodule.am include gdimagenegate/Makemodule.am @@ -53,16 +62,24 @@ include gdimagerectangle/Makemodule.am include gdimagerotate/Makemodule.am include gdimagescale/Makemodule.am include gdimagescatterex/Makemodule.am +include gdimagesetinterpolationmethod/Makemodule.am include gdimagesetpixel/Makemodule.am +include gdimagesquaretocircle/Makemodule.am +include gdimagestring/Makemodule.am +include gdimagestring16/Makemodule.am include gdimagestringft/Makemodule.am include gdimagestringftex/Makemodule.am +include gdimagestringup/Makemodule.am +include gdimagestringup16/Makemodule.am include gdimagetruecolortopalette/Makemodule.am include gdinterpolatedscale/Makemodule.am include gdnewfilectx/Makemodule.am include gdtest/Makemodule.am include gdtiled/Makemodule.am include gdtransformaffineboundingbox/Makemodule.am +include gdtransformaffinecopy/Makemodule.am include gif/Makemodule.am +include heif/Makemodule.am include jpeg/Makemodule.am include png/Makemodule.am include tga/Makemodule.am @@ -83,10 +100,12 @@ EXTRA_DIST += \ # We don't keep any media files in the top dir ... just generated outputs. CLEANFILES += \ + *.avif \ *.bmp \ *.gd \ *.gd2 \ *.gif \ + *.heif \ *.jpeg \ *.jpg \ *.png \ diff --git a/tests/avif/.gitignore b/tests/avif/.gitignore new file mode 100644 index 0000000..66233b0 --- /dev/null +++ b/tests/avif/.gitignore @@ -0,0 +1,5 @@ +/avif_im2im +/avif_null +/avif_ptr_double_free +/bad_input +/compare_avif_to_png diff --git a/tests/avif/CMakeLists.txt b/tests/avif/CMakeLists.txt new file mode 100644 index 0000000..e2df47b --- /dev/null +++ b/tests/avif/CMakeLists.txt @@ -0,0 +1,17 @@ +IF(AVIF_FOUND) +LIST(APPEND TESTS_FILES + avif_ptr_double_free + avif_im2im + avif_null + bad_input +) + +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + compare_avif_to_png +) +ENDIF(PNG_FOUND) + +ENDIF(AVIF_FOUND) + +ADD_GD_TESTS() diff --git a/tests/avif/Makemodule.am b/tests/avif/Makemodule.am new file mode 100644 index 0000000..f7b965a --- /dev/null +++ b/tests/avif/Makemodule.am @@ -0,0 +1,24 @@ +if HAVE_LIBAVIF +libgd_test_programs += \ + avif/avif_ptr_double_free + avif/avif_im2im + avif/avif_null + avif/bad_input + +if HAVE_LIBPNG +libgd_test_programs += \ + avif/compare_avif_to_png +endif + +endif + +EXTRA_DIST += \ + avif/CMakeLists.txt \ + avif/baboon.avif \ + avif/baboon.png \ + avif/dice_with_alpha.avif \ + avif/dice_with_alpha.png \ + avif/plum_blossom_12bit.avif \ + avif/plum_blossom_12bit.png \ + avif/sunset.avif \ + avif/sunset.png diff --git a/tests/avif/avif_im2im.c b/tests/avif/avif_im2im.c new file mode 100644 index 0000000..3a07ebd --- /dev/null +++ b/tests/avif/avif_im2im.c @@ -0,0 +1,67 @@ +/** + * File: avif_im2im + * + * Sanity check for AVIF encoding and decoding. + * We create a simple gd image, we encode it to AVIF, and we decode it back to gd. + * Then we make sure the image we started with and the image we finish with are the same. + * + */ + +#include "gd.h" +#include "gdtest.h" +#include <stdio.h> + +int main() +{ + gdImagePtr srcGdIm, destGdIm; + void *avifImageDataPtr; + FILE *fp; + int r, g, b; + int size = 0; + CuTestImageResult result = {0, 0}; + + // Create new gd image and add some shapes to it. + srcGdIm = gdImageCreateTrueColor(100, 100); + gdTestAssertMsg(srcGdIm != NULL, "could not create source image\n"); + + r = gdImageColorAllocate(srcGdIm, 0xFF, 0, 0); + g = gdImageColorAllocate(srcGdIm, 0, 0xFF, 0); + b = gdImageColorAllocate(srcGdIm, 0, 0, 0xFF); + gdImageFilledRectangle(srcGdIm, 0, 0, 99, 99, r); + gdImageRectangle(srcGdIm, 20, 20, 79, 79, g); + gdImageEllipse(srcGdIm, 70, 25, 30, 20, b); + + // Encode the gd image to a test AVIF file. + fp = gdTestTempFp(); + gdImageAvif(srcGdIm, fp); + fclose(fp); + + // Encode the gd image to an AVIF image in memory. + avifImageDataPtr = gdImageAvifPtrEx(srcGdIm, &size, 100, 10); + gdTestAssertMsg(avifImageDataPtr != NULL, "gdImageAvifPtr() returned null\n"); + gdTestAssertMsg(size > 0, "gdImageAvifPtr() returned a non-positive size\n"); + + // Encode the AVIF image back into a gd image. + destGdIm = gdImageCreateFromAvifPtr(size, avifImageDataPtr); + gdTestAssertMsg(destGdIm != NULL, "gdImageAvifPtr() returned null\n"); + + // Encode that gd image to a test AVIF file. + fp = gdTestTempFp(); + gdImageAvif(destGdIm, fp); + fclose(fp); + + // Make sure the image we started with is the same as the image after two conversions. + gdTestImageDiff(srcGdIm, destGdIm, NULL, &result); + gdTestAssertMsg(result.pixels_changed == 0, "pixels changed: %d\n", result.pixels_changed); + + if (srcGdIm) + gdImageDestroy(srcGdIm); + + if (destGdIm) + gdImageDestroy(destGdIm); + + if (avifImageDataPtr) + gdFree(avifImageDataPtr); + + return gdNumFailures(); +} diff --git a/tests/avif/avif_null.c b/tests/avif/avif_null.c new file mode 100644 index 0000000..bbcc9c6 --- /dev/null +++ b/tests/avif/avif_null.c @@ -0,0 +1,23 @@ +/** + * File: avif_null.c + * + * Simple test case, confirming that if you try to create an AVIF image from a + * null file pointer, the creation will fail, and it will return NULL. + */ + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im; + + im = gdImageCreateFromAvif(NULL); + if (!gdTestAssert(im == NULL)) + gdImageDestroy(im); + + gdImageAvif(im, NULL); /* noop safely */ + + return gdNumFailures(); +} diff --git a/tests/avif/avif_ptr_double_free.c b/tests/avif/avif_ptr_double_free.c new file mode 100644 index 0000000..8160950 --- /dev/null +++ b/tests/avif/avif_ptr_double_free.c @@ -0,0 +1,34 @@ +/** + * Test that failure to convert to AVIF returns NULL + * + * We are creating an image, set its width to zero, and pass this image to + * gdImageAvifPtr(). + * This is supposed to fail, and as such should return NULL. + * + * See also <https://github.com/libgd/libgd/issues/381> + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr src, dst; + int size; + + src = gdImageCreateTrueColor(1, 10); + gdTestAssert(src != NULL); + + src->sx = 0; // making the width 0 should cause gdImageAvifPtr() to fail + + dst = gdImageAvifPtr(src, &size); + gdTestAssert(dst == NULL); + + if (src) + gdImageDestroy(src); + + if (dst) + gdImageDestroy(dst); + + return gdNumFailures(); +} diff --git a/tests/avif/baboon.avif b/tests/avif/baboon.avif Binary files differnew file mode 100644 index 0000000..f5821db --- /dev/null +++ b/tests/avif/baboon.avif diff --git a/tests/avif/baboon.png b/tests/avif/baboon.png Binary files differnew file mode 100644 index 0000000..fdc5dcb --- /dev/null +++ b/tests/avif/baboon.png diff --git a/tests/avif/bad_input.c b/tests/avif/bad_input.c new file mode 100644 index 0000000..0f814c9 --- /dev/null +++ b/tests/avif/bad_input.c @@ -0,0 +1,57 @@ +/** + * File: bad_input.c + * + * Make sure that the AVIF encoding and decoding functions handle bad input gracefully. + */ + +#include <stdio.h> +#include <string.h> +#include "gd.h" +#include "gdtest.h" + +int main() { + FILE *fp; + int retval; + gdImagePtr realIm, badIm; + void *rv; + int size; + + // Read in an AVIF image for testing. + + 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 = gdTestFileOpen2("avif", "sunset.png"); + badIm = gdImageCreateFromAvif(fp); + fclose(fp); + gdTestAssertMsg(badIm == NULL, "gdImageCreateFromAvif() failed to return NULL when passed a non-AVIF file\n"); + + if (badIm) + gdImageDestroy(badIm); + + // 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"); + gdFree(rv); + + rv = gdImageAvifPtrEx(realIm, &size, -4, 10); + gdTestAssertMsg(rv != NULL, "gdImageAvifPtrEx() rejected a negative quality param instead of clamping it to a valid value"); + gdFree(rv); + + rv = gdImageAvifPtrEx(realIm, &size, 30, 30); + gdTestAssertMsg(rv != NULL, "gdImageAvifPtrEx() rejected an overly high speed param instead of clamping it to a valid value"); + gdFree(rv); + + rv = gdImageAvifPtrEx(realIm, &size, 30, -4); + gdTestAssertMsg(rv != NULL, "gdImageAvifPtrEx() rejected a negative speed param instead of clamping it to a valid value"); + gdFree(rv); + + gdImageDestroy(realIm); + + return gdNumFailures(); +} diff --git a/tests/avif/compare_avif_to_png.c b/tests/avif/compare_avif_to_png.c new file mode 100644 index 0000000..6330ea3 --- /dev/null +++ b/tests/avif/compare_avif_to_png.c @@ -0,0 +1,92 @@ +/** + * File: compare_avif_to_png + * + * Thorough check for AVIF encoding and decoding. + * This test reqiures a set of PNG images that have been losslessly encoded to AVIFs. + * For each such image, we encode the PNG into an AVIF, with the GD format as an intermediary, + * then compare the resulting AVIF with the original PNG. + * + * We then do this process in reverse, encoding the AVIF into a PNG, + * and compare the resulting PNG with the original AVIF. + * + * We report any discrepancies in the images, or any other errors that may occur. + */ + +#include <stdio.h> +#include <string.h> +#include "gd.h" +#include "gdtest.h" + +int main() { + FILE *fp; + gdImagePtr imFromPng = NULL, imFromAvif = NULL; + void *avifImDataPtr = NULL, *pngImDataPtr = NULL; + int size; + 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]); + + for (int i = 0; i < filesCount; i++) { + + // 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]); + + fp = gdTestFileOpen2("avif", pngFilename); + imFromPng = gdImageCreateFromPng(fp); + fclose(fp); + + strcat(strcpy(errMsg, filenames[i]), ".png: gdImageCreateFromPng failed\n"); + if (!gdTestAssertMsg(imFromPng != NULL, errMsg)) + goto avif2png; + + strcat(strcpy(errMsg, filenames[i]), ": gdImageAvifPtrEx failed\n"); + avifImDataPtr = gdImageAvifPtrEx(imFromPng, &size, 100, 0); + if (!gdTestAssertMsg(avifImDataPtr != NULL, errMsg)) + goto avif2png; + + strcat(strcpy(errMsg, filenames[i]), ": gdImageCreateFromAvifPtr failed\n"); + imFromAvif = gdImageCreateFromAvifPtr(size, avifImDataPtr); + if (!gdTestAssertMsg(imFromAvif != NULL, errMsg)) + goto avif2png; + + strcat(strcpy(errMsg, filenames[i]), ".png: Encoded AVIF image did not match original PNG\n"); + gdTestAssertMsg(gdAssertImageEquals(imFromPng, imFromAvif), errMsg); + + // Then, decode each AVIF into a GD format, and compare that with the orginal PNG. +avif2png: + + // 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); + + strcat(strcpy(errMsg, filenames[i]), ".avif: gdImageCreateFromAvif failed\n"); + if (!gdTestAssertMsg(imFromAvif != NULL, errMsg)) + 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); + + if (imFromAvif) + gdImageDestroy(imFromAvif); + + if (avifImDataPtr) + gdFree(avifImDataPtr); + + if (pngImDataPtr) + gdFree(pngImDataPtr); + + return gdNumFailures(); +} diff --git a/tests/avif/dice_with_alpha.avif b/tests/avif/dice_with_alpha.avif Binary files differnew file mode 100644 index 0000000..dce625b --- /dev/null +++ b/tests/avif/dice_with_alpha.avif diff --git a/tests/avif/dice_with_alpha.png b/tests/avif/dice_with_alpha.png Binary files differnew file mode 100644 index 0000000..d2809d1 --- /dev/null +++ b/tests/avif/dice_with_alpha.png diff --git a/tests/avif/plum_blossom_12bit.avif b/tests/avif/plum_blossom_12bit.avif Binary files differnew file mode 100644 index 0000000..7959d15 --- /dev/null +++ b/tests/avif/plum_blossom_12bit.avif diff --git a/tests/avif/plum_blossom_12bit.png b/tests/avif/plum_blossom_12bit.png Binary files differnew file mode 100644 index 0000000..e6901e2 --- /dev/null +++ b/tests/avif/plum_blossom_12bit.png diff --git a/tests/avif/sunset.avif b/tests/avif/sunset.avif Binary files differnew file mode 100644 index 0000000..4964558 --- /dev/null +++ b/tests/avif/sunset.avif diff --git a/tests/avif/sunset.png b/tests/avif/sunset.png Binary files differnew file mode 100644 index 0000000..21f45d5 --- /dev/null +++ b/tests/avif/sunset.png diff --git a/tests/bmp/.gitignore b/tests/bmp/.gitignore index 7c4edd0..c2cd2af 100644 --- a/tests/bmp/.gitignore +++ b/tests/bmp/.gitignore @@ -2,3 +2,4 @@ /bmp_null /bug00275 /bug00276 +/bug00450 diff --git a/tests/bmp/CMakeLists.txt b/tests/bmp/CMakeLists.txt index 82dfb67..0cc1d06 100644 --- a/tests/bmp/CMakeLists.txt +++ b/tests/bmp/CMakeLists.txt @@ -1,7 +1,8 @@ LIST(APPEND TESTS_FILES - bmp_im2im bmp_null bug00275 + bug00450 + bmp_im2im bug00276 ) diff --git a/tests/bmp/Makemodule.am b/tests/bmp/Makemodule.am index 27dc7ec..e7908f3 100644 --- a/tests/bmp/Makemodule.am +++ b/tests/bmp/Makemodule.am @@ -1,12 +1,10 @@ libgd_test_programs += \ bmp/bmp_null \ bmp/bug00275 \ + bmp/bug00450 \ + bmp/bmp_im2im \ bmp/bug00276 -if HAVE_LIBPNG -libgd_test_programs += \ - bmp/bmp_im2im -endif - EXTRA_DIST += \ + bmp/bug00450.bmp \ bmp/CMakeLists.txt diff --git a/tests/bmp/bug00275.c b/tests/bmp/bug00275.c index 710c084..775d849 100644 --- a/tests/bmp/bug00275.c +++ b/tests/bmp/bug00275.c @@ -6,7 +6,7 @@ #ifdef __GNUC__ -#define UNUSED __attribute__((unused)) +#define UNUSED __attribute__((__unused__)) #else #define UNUSED #endif @@ -49,5 +49,7 @@ int main() /* "save" the image as BMP */ gdImageBmpCtx(im, &ctx, 2); + gdImageDestroy(im); + return gdNumFailures(); } diff --git a/tests/bmp/bug00276.c b/tests/bmp/bug00276.c index 58ca423..dd5d513 100644 --- a/tests/bmp/bug00276.c +++ b/tests/bmp/bug00276.c @@ -28,5 +28,7 @@ int main() gdImageDestroy(im_orig); gdImageDestroy(im_saved); + gdFree(data); + return gdNumFailures(); } diff --git a/tests/bmp/bug00450.bmp b/tests/bmp/bug00450.bmp Binary files differnew file mode 100644 index 0000000..2db27a3 --- /dev/null +++ b/tests/bmp/bug00450.bmp diff --git a/tests/bmp/bug00450.c b/tests/bmp/bug00450.c new file mode 100644 index 0000000..e048845 --- /dev/null +++ b/tests/bmp/bug00450.c @@ -0,0 +1,40 @@ +#include <stdio.h> + +#include "gd.h" +#include "gdtest.h" + +int main(void) { + char *path = gdTestFilePath("bmp/bug00450.bmp"); + gdImagePtr im = gdImageCreateFromFile(path); + gdTestAssert(im != NULL); + + if (im) { + char const ref[] = + "# " + "## " + "### " + "#### " + "##### " + "###### " + "####### " + "######## " + "######### " + "##########" + ; + int x, y; + + for (y = 0; y < 10; ++y) { + for (x = 0; x < 10; ++x) { + int const expected_pixel = ref[x + y * 10] == '#'; + int const actual_pixel = gdImageGetPixel(im, x, y); + gdTestAssert(expected_pixel == actual_pixel); + } + } + + gdImageDestroy(im); + } + + free(path); + + return gdNumFailures(); +} diff --git a/tests/fontconfig/CMakeLists.txt b/tests/fontconfig/CMakeLists.txt index 159130d..f78c4cf 100644 --- a/tests/fontconfig/CMakeLists.txt +++ b/tests/fontconfig/CMakeLists.txt @@ -1,7 +1,9 @@ -IF(FREETYPE_FOUND AND FONTCONFIG_FOUND) +if(FONTCONFIG_FOUND) +IF(FREETYPE_FOUND) LIST(APPEND TESTS_FILES basic ) -ENDIF(FREETYPE_FOUND AND FONTCONFIG_FOUND) +ENDIF(FREETYPE_FOUND) +ENDIF(FONTCONFIG_FOUND) ADD_GD_TESTS() diff --git a/tests/freetype/CMakeLists.txt b/tests/freetype/CMakeLists.txt index a5d8086..9a1e018 100644 --- a/tests/freetype/CMakeLists.txt +++ b/tests/freetype/CMakeLists.txt @@ -1,7 +1,9 @@ IF(FREETYPE_FOUND) +IF(PNG_FOUND) LIST(APPEND TESTS_FILES bug00132 ) +ENDIF(PNG_FOUND) ENDIF(FREETYPE_FOUND) ADD_GD_TESTS() diff --git a/tests/freetype/Makemodule.am b/tests/freetype/Makemodule.am index d252493..a0dda49 100644 --- a/tests/freetype/Makemodule.am +++ b/tests/freetype/Makemodule.am @@ -1,7 +1,9 @@ if HAVE_LIBFREETYPE +if HAVE_LIBPNG libgd_test_programs += \ freetype/bug00132 endif +endif EXTRA_DIST += \ freetype/CMakeLists.txt \ diff --git a/tests/freetype/bug00132.c b/tests/freetype/bug00132.c index 713dd2d..42ed5b1 100644 --- a/tests/freetype/bug00132.c +++ b/tests/freetype/bug00132.c @@ -11,6 +11,9 @@ int main() char *path; char *ret = NULL; + /* disable subpixel hinting */ + putenv("FREETYPE_PROPERTIES=truetype:interpreter-version=35"); + im = gdImageCreateTrueColor(50, 30); if (!im) { diff --git a/tests/gd/.gitignore b/tests/gd/.gitignore index 5edc65c..8a7d284 100644 --- a/tests/gd/.gitignore +++ b/tests/gd/.gitignore @@ -1,3 +1,4 @@ +/bug00383 /gd_im2im /gd_null /gd_num_colors diff --git a/tests/gd/CMakeLists.txt b/tests/gd/CMakeLists.txt index 3b7ace2..e86c780 100644 --- a/tests/gd/CMakeLists.txt +++ b/tests/gd/CMakeLists.txt @@ -1,8 +1,14 @@ LIST(APPEND TESTS_FILES - gd_im2im + gd_versiontest +) + +IF(ENABLE_GD_FORMATS) +LIST(APPEND TESTS_FILES + bug00383 gd_null gd_num_colors - gd_versiontest + gd_im2im ) +ENDIF(ENABLE_GD_FORMATS) ADD_GD_TESTS() diff --git a/tests/gd/Makemodule.am b/tests/gd/Makemodule.am index e4a741f..4a45bc2 100644 --- a/tests/gd/Makemodule.am +++ b/tests/gd/Makemodule.am @@ -1,13 +1,15 @@ libgd_test_programs += \ - gd/gd_null \ - gd/gd_num_colors \ gd/gd_versiontest -if HAVE_LIBPNG +if ENABLE_GD_FORMATS libgd_test_programs += \ + gd/bug00383 \ + gd/gd_null \ + gd/gd_num_colors \ gd/gd_im2im endif EXTRA_DIST += \ + gd/bug00383.gd \ gd/crafted_num_colors.gd \ gd/CMakeLists.txt diff --git a/tests/gd/bug00383.c b/tests/gd/bug00383.c new file mode 100644 index 0000000..edcfd05 --- /dev/null +++ b/tests/gd/bug00383.c @@ -0,0 +1,32 @@ +/** + * Test that invalid transparent colors can't be read + * + * We're reading a corrupt palette image in GD format, which has only a single + * palette entry, but claims that the transparent color would be 1. We check + * that the transparency is simply ignored in this case. + * + * See also <https://github.com/libgd/libgd/issues/383> + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gd", "bug00383.gd"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGd(fp); + gdTestAssert(im != NULL); + fclose(fp); + + gdTestAssert(gdImageGetTransparent(im) == -1); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gd/bug00383.gd b/tests/gd/bug00383.gd Binary files differnew file mode 100644 index 0000000..7f8611c --- /dev/null +++ b/tests/gd/bug00383.gd diff --git a/tests/gd2/.gitignore b/tests/gd2/.gitignore index 136a2d5..a0e2fa3 100644 --- a/tests/gd2/.gitignore +++ b/tests/gd2/.gitignore @@ -1,8 +1,14 @@ /bug_289 +/bug00209 /bug00309 +/bug00354 +/bug00383 +/createimagefromgd2part +/createimagefromgd2partptr /gd2_empty_file /gd2_im2im /gd2_null /gd2_read /gd2_read_corrupt /php_bug_72339 +/too_few_image_data diff --git a/tests/gd2/CMakeLists.txt b/tests/gd2/CMakeLists.txt index 8fcc906..cc188ca 100644 --- a/tests/gd2/CMakeLists.txt +++ b/tests/gd2/CMakeLists.txt @@ -1,12 +1,27 @@ +IF(ENABLE_GD_FORMATS) +IF(ZLIB_FOUND) LIST(APPEND TESTS_FILES bug_289 + bug00209 bug00309 + bug00354 + bug00383 + createimagefromgd2part + createimagefromgd2partptr gd2_empty_file - gd2_im2im - gd2_null php_bug_72339 - gd2_read + gd2_null gd2_read_corrupt + too_few_image_data + gd2_im2im +) + +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + gd2_read ) +ENDIF(PNG_FOUND) +ENDIF(ZLIB_FOUND) +ENDIF(ENABLE_GD_FORMATS) ADD_GD_TESTS() diff --git a/tests/gd2/Makemodule.am b/tests/gd2/Makemodule.am index d69aee0..5cd29e6 100644 --- a/tests/gd2/Makemodule.am +++ b/tests/gd2/Makemodule.am @@ -1,26 +1,37 @@ +if ENABLE_GD_FORMATS +if HAVE_LIBZ libgd_test_programs += \ gd2/bug_289 \ + gd2/bug00209 \ gd2/bug00309 \ + gd2/bug00354 \ + gd2/bug00383 \ + gd2/createimagefromgd2part \ + gd2/createimagefromgd2partptr \ gd2/gd2_empty_file \ gd2/php_bug_72339 \ - gd2/gd2_read_corrupt - -if HAVE_LIBZ -libgd_test_programs += \ - gd2/gd2_null + gd2/gd2_null \ + gd2/gd2_read_corrupt \ + gd2/too_few_image_data \ + gd2/gd2_im2im if HAVE_LIBPNG libgd_test_programs += \ - gd2/gd2_im2im \ gd2/gd2_read endif endif +endif EXTRA_DIST += \ gd2/CMakeLists.txt \ + gd2/bug00209.gd2 \ + gd2/bug00354a.gd2 \ + gd2/bug00354b.gd2 \ + gd2/bug00383.gd2 \ gd2/conv_gd2_exp.gd2 \ gd2/conv_test.gd2 \ gd2/conv_test_exp.png \ gd2/empty.gd2 \ gd2/invalid_header.gd2 \ - gd2/invalid_neg_size.gd2 + gd2/invalid_neg_size.gd2 \ + gd2/too_few_image_data.gd2 diff --git a/tests/gd2/bug00209.c b/tests/gd2/bug00209.c new file mode 100644 index 0000000..7904d01 --- /dev/null +++ b/tests/gd2/bug00209.c @@ -0,0 +1,26 @@ +/** + * Regression test for github issue #209 + * + * We're testing that bug00209.gd2, which claims to have 12336 x 48 pixels, but + * actually provides not enough image data, is rejected, i.e. that + * gdImageCreateFromGd2() returns NULL + * + * See <https://github.com/libgd/libgd/issues/209>. + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gd2", "bug00209.gd2"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGd2(fp); + gdTestAssert(im == NULL); + fclose(fp); + + return gdNumFailures(); +} diff --git a/tests/gd2/bug00209.gd2 b/tests/gd2/bug00209.gd2 Binary files differnew file mode 100644 index 0000000..1c797d1 --- /dev/null +++ b/tests/gd2/bug00209.gd2 diff --git a/tests/gd2/bug00354.c b/tests/gd2/bug00354.c new file mode 100644 index 0000000..1bce091 --- /dev/null +++ b/tests/gd2/bug00354.c @@ -0,0 +1,30 @@ +/** + * We're testing GD2 image files which report illegal chunk counts. These should + * not cause integer overflows or other issues, but instead simply fail to be + * loaded. + * + * See also <https://github.com/libgd/libgd/issues/354>. + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gd2", "bug00354a.gd2"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGd2(fp); + gdTestAssert(im == NULL); + fclose(fp); + + fp = gdTestFileOpen2("gd2", "bug00354b.gd2"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGd2(fp); + gdTestAssert(im == NULL); + fclose(fp); + + return gdNumFailures(); +} diff --git a/tests/gd2/bug00354a.gd2 b/tests/gd2/bug00354a.gd2 Binary files differnew file mode 100644 index 0000000..5060bfd --- /dev/null +++ b/tests/gd2/bug00354a.gd2 diff --git a/tests/gd2/bug00354b.gd2 b/tests/gd2/bug00354b.gd2 Binary files differnew file mode 100644 index 0000000..8600126 --- /dev/null +++ b/tests/gd2/bug00354b.gd2 diff --git a/tests/gd2/bug00383.c b/tests/gd2/bug00383.c new file mode 100644 index 0000000..dbbf661 --- /dev/null +++ b/tests/gd2/bug00383.c @@ -0,0 +1,32 @@ +/** + * Test that invalid transparent colors can't be read + * + * We're reading a corrupt palette image in GD2 format, which has only a single + * palette entry, but claims that the transparent color would be 1. We check + * that the transparency is simply ignored in this case. + * + * See also <https://github.com/libgd/libgd/issues/383> + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gd2", "bug00383.gd2"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGd2(fp); + gdTestAssert(im != NULL); + fclose(fp); + + gdTestAssert(gdImageGetTransparent(im) == -1); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gd2/bug00383.gd2 b/tests/gd2/bug00383.gd2 Binary files differnew file mode 100644 index 0000000..dcb164d --- /dev/null +++ b/tests/gd2/bug00383.gd2 diff --git a/tests/gd2/bug_289.c b/tests/gd2/bug_289.c index ad311e9..9ca03cc 100644 --- a/tests/gd2/bug_289.c +++ b/tests/gd2/bug_289.c @@ -29,5 +29,7 @@ int main() gdTestAssertMsg(buffer[12] == 0, MSG, "1st", 0, buffer[12]); gdTestAssertMsg(buffer[13] == GD2_FMT_TRUECOLOR_COMPRESSED, MSG, "2nd", GD2_FMT_TRUECOLOR_COMPRESSED, buffer[13]); + gdFree(buffer); + return gdNumFailures(); } diff --git a/tests/gd2/createimagefromgd2part.c b/tests/gd2/createimagefromgd2part.c new file mode 100644 index 0000000..0c81ba6 --- /dev/null +++ b/tests/gd2/createimagefromgd2part.c @@ -0,0 +1,35 @@ +/** + *Base test for gdImageCreateFromGd2Part() + */ +#include "gd.h" +#include "gdtest.h" +#include <stdio.h> +#include <stdlib.h> + +int main() +{ + gdImagePtr im; + FILE *p; + int expected_color = 0xffffff; + int actual_color = 0; + + p = gdTestFileOpen2("gd2", "conv_test.gd2"); + + if (!p) { + gdTestErrorMsg("failed, connot open gd2 file: conv_test.gd2"); + return 1; + } + + im = gdImageCreateFromGd2Part(p, 3, 3, 3, 3); + fclose(p); + + if (!im) { + return 1; + } + + actual_color = gdImageGetPixel(im, 2, 2); + gdImageDestroy(im); + gdTestAssert(expected_color == actual_color); + + return gdNumFailures(); +} diff --git a/tests/gd2/createimagefromgd2partptr.c b/tests/gd2/createimagefromgd2partptr.c new file mode 100644 index 0000000..e432874 --- /dev/null +++ b/tests/gd2/createimagefromgd2partptr.c @@ -0,0 +1,59 @@ +/** + * Base test for gdImageCreateFromGd2PartPtr() + */ +#include "gd.h" +#include "gdtest.h" +#include <stdio.h> + +int main() +{ + FILE *p; + gdImagePtr im, partim; + void *pg; + int size = 0; + int status = 0; + int actual_color = 0; + int expected_color = 0xffffff; + + p = gdTestFileOpen2("gd2", "conv_test.gd2"); + if (!p) { + gdTestErrorMsg("failed, cannot open gd2 file:conv_test.gd2"); + return 1; + } + + im = gdImageCreateFromGd2(p); + fclose(p); + + if (!im) { + gdTestErrorMsg("failed, cannot create gd2 file."); + return 1; + } + + pg = gdImageGd2Ptr(im, (GD2_CHUNKSIZE_MIN + GD2_CHUNKSIZE_MAX) / 2, GD2_FMT_COMPRESSED, &size); + if (!pg) { + status = 1; + goto done1; + } + + if (size <= 0) { + status = 1; + goto done0; + } + + partim = gdImageCreateFromGd2PartPtr(size, pg, 3, 3, 3, 3); + if (!partim) { + status = 1; + goto done0; + } + + actual_color = gdImageGetPixel(partim, 2, 2); + status = (expected_color == actual_color) ? 0 : 1; + gdImageDestroy(partim); + +done0: + gdFree(pg); +done1: + gdImageDestroy(im); + + return status; +} diff --git a/tests/gd2/gd2_read.c b/tests/gd2/gd2_read.c index 8ce8bd1..9f2b808 100644 --- a/tests/gd2/gd2_read.c +++ b/tests/gd2/gd2_read.c @@ -33,17 +33,18 @@ int main(int argc, char *argv[]) fp = gdTestFileOpen2("gd2", path_exp[i]); if (!fp) { gdTestErrorMsg("failed, cannot open file: %s\n", path_exp[i]); + gdImageDestroy(im); return 1; } exp = gdImageCreateFromPng(fp); if (!gdAssertImageEquals(exp, im)) { gdTestErrorMsg("image %s differs from expected result\n", path[i]); - gdImageDestroy(im); error = 1; } if (exp) { gdImageDestroy(exp); } + gdImageDestroy(im); } else { /* expected to fail */ if (im) { diff --git a/tests/gd2/php_bug_72339.c b/tests/gd2/php_bug_72339.c index 7ce6028..8217c87 100644 --- a/tests/gd2/php_bug_72339.c +++ b/tests/gd2/php_bug_72339.c @@ -29,7 +29,7 @@ int main() im = gdImageCreateFromGd2(fp); fclose(fp); - + gdTestAssertMsg(im == NULL, "Image should have failed to be loaded\n"); return gdNumFailures(); diff --git a/tests/gd2/too_few_image_data.c b/tests/gd2/too_few_image_data.c new file mode 100644 index 0000000..3153a08 --- /dev/null +++ b/tests/gd2/too_few_image_data.c @@ -0,0 +1,22 @@ +/* +too_few_image_data.gd2 claims to have a size of 12336x48 pixels, but doesn't +provide as much image data. We test that gdImageCreateFromGd2Ctx() returns NULL +in this case. +*/ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gd2", "too_few_image_data.gd2"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGd2(fp); + gdTestAssert(im == NULL); + fclose(fp); + + return gdNumFailures(); +} diff --git a/tests/gd2/too_few_image_data.gd2 b/tests/gd2/too_few_image_data.gd2 Binary files differnew file mode 100644 index 0000000..1c797d1 --- /dev/null +++ b/tests/gd2/too_few_image_data.gd2 diff --git a/tests/gdimagearc/CMakeLists.txt b/tests/gdimagearc/CMakeLists.txt index 77117fb..fc8ca57 100644 --- a/tests/gdimagearc/CMakeLists.txt +++ b/tests/gdimagearc/CMakeLists.txt @@ -1,5 +1,7 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES bug00079 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagebrightness/CMakeLists.txt b/tests/gdimagebrightness/CMakeLists.txt index 381c74d..802c382 100644 --- a/tests/gdimagebrightness/CMakeLists.txt +++ b/tests/gdimagebrightness/CMakeLists.txt @@ -1,5 +1,7 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES basic ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagebrightness/basic.c b/tests/gdimagebrightness/basic.c index 8c3a73c..dfed242 100644 --- a/tests/gdimagebrightness/basic.c +++ b/tests/gdimagebrightness/basic.c @@ -1,41 +1,37 @@ -/**
- * Basic test for gdImageBrightness()
- */
-
-
-#include "gd.h"
-#include "gdtest.h"
-
-
-static void test_brightness(int brightness);
-
-
-int main()
-{
- test_brightness(+100);
- test_brightness(-100);
-
- return gdNumFailures();
-}
-
-
-static void test_brightness(int brightness)
-{
- gdImagePtr im;
- FILE *fp;
- char basename[256];
- char *path;
-
- fp = gdTestFileOpen2("gdimagebrightness", "basic.png");
- im = gdImageCreateFromPng(fp);
- fclose(fp);
-
- gdImageBrightness(im, brightness);
-
- sprintf(basename, "basic%+03d.png", brightness);
- path = gdTestFilePath2("gdimagebrightness", basename);
- gdAssertImageEqualsToFile(path, im);
- gdFree(path);
-
- gdImageDestroy(im);
-}
+/** + * Basic test for gdImageBrightness() + */ + +#include "gd.h" +#include "gdtest.h" + +static void test_brightness(int brightness); + +int main() +{ + test_brightness(+100); + test_brightness(-100); + + return gdNumFailures(); +} + +static void test_brightness(int brightness) +{ + gdImagePtr im; + FILE *fp; + char basename[256]; + char *path; + + fp = gdTestFileOpen2("gdimagebrightness", "basic.png"); + im = gdImageCreateFromPng(fp); + fclose(fp); + + gdImageBrightness(im, brightness); + + sprintf(basename, "basic%+03d.png", brightness); + path = gdTestFilePath2("gdimagebrightness", basename); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); +} diff --git a/tests/gdimageclone/.gitignore b/tests/gdimageclone/.gitignore index a70782d..f4129cc 100644 --- a/tests/gdimageclone/.gitignore +++ b/tests/gdimageclone/.gitignore @@ -1 +1,2 @@ /bug00300 +/style diff --git a/tests/gdimageclone/CMakeLists.txt b/tests/gdimageclone/CMakeLists.txt index e6ccc31..662f4e9 100644 --- a/tests/gdimageclone/CMakeLists.txt +++ b/tests/gdimageclone/CMakeLists.txt @@ -1,5 +1,6 @@ LIST(APPEND TESTS_FILES bug00300 + style ) ADD_GD_TESTS() diff --git a/tests/gdimageclone/Makemodule.am b/tests/gdimageclone/Makemodule.am index 4b1b54c..51abf5c 100644 --- a/tests/gdimageclone/Makemodule.am +++ b/tests/gdimageclone/Makemodule.am @@ -1,5 +1,6 @@ libgd_test_programs += \ - gdimageclone/bug00300 + gdimageclone/bug00300 \ + gdimageclone/style EXTRA_DIST += \ gdimageclone/CMakeLists.txt diff --git a/tests/gdimageclone/style.c b/tests/gdimageclone/style.c new file mode 100644 index 0000000..c2b246e --- /dev/null +++ b/tests/gdimageclone/style.c @@ -0,0 +1,30 @@ +/** + * Cloning an image should exactly reproduce all style related data + */ + + +#include <string.h> +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im, clone; + int style[] = {0, 0, 0}; + + im = gdImageCreate(8, 8); + gdImageSetStyle(im, style, sizeof(style)/sizeof(style[0])); + + clone = gdImageClone(im); + gdTestAssert(clone != NULL); + + gdTestAssert(clone->styleLength == im->styleLength); + gdTestAssert(clone->stylePos == im->stylePos); + gdTestAssert(!memcmp(clone->style, im->style, sizeof(style)/sizeof(style[0]))); + + gdImageDestroy(clone); + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gdimagecolor/CMakeLists.txt b/tests/gdimagecolor/CMakeLists.txt index 381c74d..802c382 100644 --- a/tests/gdimagecolor/CMakeLists.txt +++ b/tests/gdimagecolor/CMakeLists.txt @@ -1,5 +1,7 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES basic ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagecolor/basic.c b/tests/gdimagecolor/basic.c index 2ad0f3c..86c0aff 100644 --- a/tests/gdimagecolor/basic.c +++ b/tests/gdimagecolor/basic.c @@ -1,29 +1,27 @@ -/**
- * Basic test for gdImageColor()
- */
-
-
-#include "gd.h"
-#include "gdtest.h"
-
-
-int main()
-{
- gdImagePtr im;
- FILE *fp;
- char *path;
-
- fp = gdTestFileOpen2("gdimagecolor", "basic.png");
- im = gdImageCreateFromPng(fp);
- fclose(fp);
-
- gdImageColor(im, 127, -127, -127, 0);
-
- path = gdTestFilePath2("gdimagecolor", "basic_exp.png");
- gdAssertImageEqualsToFile(path, im);
- gdFree(path);
-
- gdImageDestroy(im);
-
- return gdNumFailures();
-}
+/** + * Basic test for gdImageColor() + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + char *path; + + fp = gdTestFileOpen2("gdimagecolor", "basic.png"); + im = gdImageCreateFromPng(fp); + fclose(fp); + + gdImageColor(im, 127, -127, -127, 0); + + path = gdTestFilePath2("gdimagecolor", "basic_exp.png"); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gdimagecolorclosest/Makemodule.am b/tests/gdimagecolorclosest/Makemodule.am index f4da8be..be42204 100644 --- a/tests/gdimagecolorclosest/Makemodule.am +++ b/tests/gdimagecolorclosest/Makemodule.am @@ -1,7 +1,5 @@ -if HAVE_LIBPNG libgd_test_programs += \ gdimagecolorclosest/gdimagecolorclosest -endif EXTRA_DIST += \ gdimagecolorclosest/CMakeLists.txt diff --git a/tests/gdimagecolorclosesthwb/.gitignore b/tests/gdimagecolorclosesthwb/.gitignore new file mode 100644 index 0000000..f46016c --- /dev/null +++ b/tests/gdimagecolorclosesthwb/.gitignore @@ -0,0 +1 @@ +/gdImageColorClosestHWB diff --git a/tests/gdimagecolorclosesthwb/CMakeLists.txt b/tests/gdimagecolorclosesthwb/CMakeLists.txt new file mode 100644 index 0000000..7a8afdc --- /dev/null +++ b/tests/gdimagecolorclosesthwb/CMakeLists.txt @@ -0,0 +1,7 @@ +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + gdImageColorClosestHWB +) +ENDIF(PNG_FOUND) + +ADD_GD_TESTS() diff --git a/tests/gdimagecolorclosesthwb/Makemodule.am b/tests/gdimagecolorclosesthwb/Makemodule.am new file mode 100644 index 0000000..14eddbd --- /dev/null +++ b/tests/gdimagecolorclosesthwb/Makemodule.am @@ -0,0 +1,7 @@ +if HAVE_LIBPNG +libgd_test_programs += \ + gdimagecolorclosesthwb/gdImageColorClosestHWB +endif + +EXTRA_DIST += \ + gdimagecolorclosesthwb/CMakeLists.txt diff --git a/tests/gdimagecolorclosesthwb/gdImageColorClosestHWB.c b/tests/gdimagecolorclosesthwb/gdImageColorClosestHWB.c new file mode 100644 index 0000000..ab20187 --- /dev/null +++ b/tests/gdimagecolorclosesthwb/gdImageColorClosestHWB.c @@ -0,0 +1,26 @@ +/** + * Basic test for gdImageColorClosestHWB() + **/ +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gdimageflip", "remi.png"); + im = gdImageCreateFromPng(fp); + fclose(fp); + + int result = gdImageColorClosestHWB(im, 255, 0, 255); + + if (gdTestAssert(result <= 0)) + { + gdImageDestroy(im); + return 1; + } + + gdImageDestroy(im); + return 0; +} diff --git a/tests/gdimagecolorexact/Makemodule.am b/tests/gdimagecolorexact/Makemodule.am index 835b25e..7427999 100644 --- a/tests/gdimagecolorexact/Makemodule.am +++ b/tests/gdimagecolorexact/Makemodule.am @@ -1,7 +1,5 @@ -if HAVE_LIBPNG libgd_test_programs += \ gdimagecolorexact/gdimagecolorexact -endif EXTRA_DIST += \ gdimagecolorexact/CMakeLists.txt diff --git a/tests/gdimagecolormatch/.gitignore b/tests/gdimagecolormatch/.gitignore new file mode 100644 index 0000000..f68c491 --- /dev/null +++ b/tests/gdimagecolormatch/.gitignore @@ -0,0 +1,2 @@ +/cve_2019_6977 +/gdimagecolormatch diff --git a/tests/gdimagecolormatch/CMakeLists.txt b/tests/gdimagecolormatch/CMakeLists.txt new file mode 100644 index 0000000..857b99a --- /dev/null +++ b/tests/gdimagecolormatch/CMakeLists.txt @@ -0,0 +1,6 @@ +LIST(APPEND TESTS_FILES + cve_2019_6977 + gdimagecolormatch +) + +ADD_GD_TESTS() diff --git a/tests/gdimagecolormatch/Makemodule.am b/tests/gdimagecolormatch/Makemodule.am new file mode 100644 index 0000000..4ed48ce --- /dev/null +++ b/tests/gdimagecolormatch/Makemodule.am @@ -0,0 +1,6 @@ +libgd_test_programs += \ + gdimagecolormatch/cve_2019_6977 \ + gdimagecolormatch/gdimagecolormatch + +EXTRA_DIST += \ + gdimagecolormatch/CMakeLists.txt diff --git a/tests/gdimagecolormatch/cve_2019_6977.c b/tests/gdimagecolormatch/cve_2019_6977.c new file mode 100644 index 0000000..fdd7af5 --- /dev/null +++ b/tests/gdimagecolormatch/cve_2019_6977.c @@ -0,0 +1,25 @@ +/** + * Test for CVE-2019-6977 + */ + +#include "gd.h" + +int main() +{ + gdImagePtr im1; + gdImagePtr im2; + + im1 = gdImageCreateTrueColor(0xfff, 0xfff); + im2 = gdImageCreate(0xfff, 0xfff); + if (gdImageColorAllocate(im2, 0, 0, 0) < 0) + { + gdImageDestroy(im1); + gdImageDestroy(im2); + return 1; + } + gdImageSetPixel(im2, 0, 0, 255); + gdImageColorMatch(im1, im2); + gdImageDestroy(im1); + gdImageDestroy(im2); + return 0; +} diff --git a/tests/gdimagecolormatch/gdimagecolormatch.c b/tests/gdimagecolormatch/gdimagecolormatch.c new file mode 100644 index 0000000..f59c769 --- /dev/null +++ b/tests/gdimagecolormatch/gdimagecolormatch.c @@ -0,0 +1,32 @@ +/** + * Basic test for gdImageColorMatch() + **/ +#include "gd.h" +#include "gdtest.h" + +int main(){ + gdImagePtr im1, im2; + + im1 = gdImageCreateTrueColor(80, 80); + im2 = gdImageCreate(80, 80); + + gdImageColorAllocate(im1, 255, 36, 74); + + gdImageColorAllocate(im2, 255, 36, 74); + gdImageColorAllocate(im2, 40, 0, 240); + gdImageColorAllocate(im2, 255, 100, 255); + gdImageColorAllocate(im2, 80, 60, 44); + + int ifMatch = gdImageColorMatch(im1, im2); + + gdImageDestroy(im1); + gdImageDestroy(im2); + + if (gdTestAssert(ifMatch != 0)) + { + gdTestErrorMsg("gdImageColorMatch failed.\n"); + return 1; + } + + return 0; +} diff --git a/tests/gdimagecolorreplace/Makemodule.am b/tests/gdimagecolorreplace/Makemodule.am index a8badb0..3ea38e5 100644 --- a/tests/gdimagecolorreplace/Makemodule.am +++ b/tests/gdimagecolorreplace/Makemodule.am @@ -1,7 +1,5 @@ -if HAVE_LIBPNG libgd_test_programs += \ gdimagecolorreplace/gdimagecolorreplace -endif EXTRA_DIST += \ gdimagecolorreplace/CMakeLists.txt diff --git a/tests/gdimagecolorresolve/Makemodule.am b/tests/gdimagecolorresolve/Makemodule.am index 316484c..a3e9442 100644 --- a/tests/gdimagecolorresolve/Makemodule.am +++ b/tests/gdimagecolorresolve/Makemodule.am @@ -1,7 +1,5 @@ -if HAVE_LIBPNG libgd_test_programs += \ gdimagecolorresolve/gdimagecolorresolve -endif EXTRA_DIST += \ gdimagecolorresolve/CMakeLists.txt diff --git a/tests/gdimagecompare/.gitignore b/tests/gdimagecompare/.gitignore new file mode 100755 index 0000000..312a8c8 --- /dev/null +++ b/tests/gdimagecompare/.gitignore @@ -0,0 +1 @@ +/gdimagecompare diff --git a/tests/gdimagecompare/CMakeLists.txt b/tests/gdimagecompare/CMakeLists.txt new file mode 100644 index 0000000..2974a07 --- /dev/null +++ b/tests/gdimagecompare/CMakeLists.txt @@ -0,0 +1,4 @@ +LIST(APPEND TESTS_FILES + gdimagecompare +) +ADD_GD_TESTS() diff --git a/tests/gdimagecompare/Makemodule.am b/tests/gdimagecompare/Makemodule.am new file mode 100644 index 0000000..b4b0ebb --- /dev/null +++ b/tests/gdimagecompare/Makemodule.am @@ -0,0 +1,5 @@ +libgd_test_programs += \ + gdimagecompare/gdimagecompare + +EXTRA_DIST += \ + gdimagecompare/CMakeLists.txt diff --git a/tests/gdimagecompare/gdimagecompare.c b/tests/gdimagecompare/gdimagecompare.c new file mode 100644 index 0000000..0e8367a --- /dev/null +++ b/tests/gdimagecompare/gdimagecompare.c @@ -0,0 +1,56 @@ +/** + * Base test for gdImageCompare() + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im1; + gdImagePtr im2; + int black; + int red1, red2; + int yellow1, yellow2; + int white; + int blue; + int ret; + + im1 = gdImageCreate(128, 128); + im2 = gdImageCreateTrueColor(256, 256); + + /* Set different interlace */ + gdImageInterlace(im1, 1); + gdImageInterlace(im2, 2); + + /* Set different transparent */ + gdImageColorTransparent(im1, 10); + gdImageColorTransparent(im2, 20); + + /* Allocate different color number */ + black = gdImageColorAllocate(im1, 0, 0, 0); + red1 = gdImageColorAllocate(im1, 255, 0, 0); + yellow1 = gdImageColorAllocate(im1, 255, 255, 0); + red2 = gdImageColorAllocate(im2, 255, 0, 0); + yellow2 = gdImageColorAllocate(im2, 255, 255, 0); + white = gdImageColorAllocate(im2, 255, 255, 255); + blue = gdImageColorAllocate(im2, 0, 0, 255); + + /* Filled different color */ + gdImageFilledRectangle(im1, 0, 0, 127, 8, black); + gdImageFilledRectangle(im1, 9, 0, 127, 16, red1); + gdImageFilledRectangle(im1, 17, 0, 127, 24, yellow1); + gdImageFilledRectangle(im2, 0, 0, 127, 8, red2); + gdImageFilledRectangle(im2, 9, 0, 127, 16, yellow2); + gdImageFilledRectangle(im2, 17, 0, 127, 24, white); + gdImageFilledRectangle(im2, 25, 0, 127, 32, blue); + + ret = gdImageCompare(im1, im2); + + gdTestAssert(ret == (GD_CMP_INTERLACE | GD_CMP_TRANSPARENT | GD_CMP_TRUECOLOR | GD_CMP_SIZE_X | GD_CMP_SIZE_Y | GD_CMP_COLOR | GD_CMP_IMAGE | GD_CMP_NUM_COLORS)); + + gdImageDestroy(im1); + gdImageDestroy(im2); + + return gdNumFailures(); +} diff --git a/tests/gdimagecontrast/CMakeLists.txt b/tests/gdimagecontrast/CMakeLists.txt index 381c74d..802c382 100644 --- a/tests/gdimagecontrast/CMakeLists.txt +++ b/tests/gdimagecontrast/CMakeLists.txt @@ -1,5 +1,7 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES basic ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagecontrast/basic.c b/tests/gdimagecontrast/basic.c index d001bf9..ef1f44a 100644 --- a/tests/gdimagecontrast/basic.c +++ b/tests/gdimagecontrast/basic.c @@ -1,41 +1,37 @@ -/**
- * Basic test for gdImageContrast()
- */
-
-
-#include "gd.h"
-#include "gdtest.h"
-
-
-static void test_contrast(double contrast);
-
-
-int main()
-{
- test_contrast(+50.0);
- test_contrast(-50.0);
-
- return gdNumFailures();
-}
-
-
-static void test_contrast(double contrast)
-{
- gdImagePtr im;
- FILE *fp;
- char basename[256];
- char *path;
-
- fp = gdTestFileOpen2("gdimagecontrast", "basic.png");
- im = gdImageCreateFromPng(fp);
- fclose(fp);
-
- gdImageContrast(im, contrast);
-
- sprintf(basename, "basic%+03.0f.png", contrast);
- path = gdTestFilePath2("gdimagecontrast", basename);
- gdAssertImageEqualsToFile(path, im);
- gdFree(path);
-
- gdImageDestroy(im);
-}
+/** + * Basic test for gdImageContrast() + */ + +#include "gd.h" +#include "gdtest.h" + +static void test_contrast(double contrast); + +int main() +{ + test_contrast(+50.0); + test_contrast(-50.0); + + return gdNumFailures(); +} + +static void test_contrast(double contrast) +{ + gdImagePtr im; + FILE *fp; + char basename[256]; + char *path; + + fp = gdTestFileOpen2("gdimagecontrast", "basic.png"); + im = gdImageCreateFromPng(fp); + fclose(fp); + + gdImageContrast(im, contrast); + + sprintf(basename, "basic%+03.0f.png", contrast); + path = gdTestFilePath2("gdimagecontrast", basename); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); +} diff --git a/tests/gdimageconvolution/.gitignore b/tests/gdimageconvolution/.gitignore index 1ffd796..6665df0 100644 --- a/tests/gdimageconvolution/.gitignore +++ b/tests/gdimageconvolution/.gitignore @@ -1 +1,2 @@ /basic +/bug00369 diff --git a/tests/gdimageconvolution/CMakeLists.txt b/tests/gdimageconvolution/CMakeLists.txt index 381c74d..dc1fc51 100644 --- a/tests/gdimageconvolution/CMakeLists.txt +++ b/tests/gdimageconvolution/CMakeLists.txt @@ -1,5 +1,9 @@ +LIST(APPEND TESTS_FILES bug00369) + +IF(PNG_FOUND) LIST(APPEND TESTS_FILES basic ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimageconvolution/Makemodule.am b/tests/gdimageconvolution/Makemodule.am index 8f65b0f..df5249d 100644 --- a/tests/gdimageconvolution/Makemodule.am +++ b/tests/gdimageconvolution/Makemodule.am @@ -1,3 +1,6 @@ +libgd_test_programs += \ + gdimageconvolution/bug00369 + if HAVE_LIBPNG libgd_test_programs += \ gdimageconvolution/basic diff --git a/tests/gdimageconvolution/basic.c b/tests/gdimageconvolution/basic.c index 7ca98be..5fe308c 100644 --- a/tests/gdimageconvolution/basic.c +++ b/tests/gdimageconvolution/basic.c @@ -1,62 +1,55 @@ -/**
- * Basic test for gdImageConvolution() and related functions
- */
-
-
-#include "gd.h"
-#include "gdtest.h"
-
-
-static void test_convolution(void (*convolution_func)(gdImagePtr im), const char *expected)
-{
- gdImagePtr im;
- FILE *fp;
- char *path;
-
- fp = gdTestFileOpen2("gdimageconvolution", "basic.png");
- im = gdImageCreateFromPng(fp);
- fclose(fp);
-
- convolution_func(im);
-
- path = gdTestFilePath2("gdimageconvolution", expected);
- gdAssertImageEqualsToFile(path, im);
- gdFree(path);
-
- gdImageDestroy(im);
-}
-
-
-static void test_edge_detect_quick(gdImagePtr im)
-{
- gdImageEdgeDetectQuick(im);
-}
-
-
-static void test_smooth(gdImagePtr im)
-{
- gdImageSmooth(im, 5);
-}
-
-
-static void test_emboss(gdImagePtr im)
-{
- gdImageEmboss(im);
-}
-
-
-static void test_mean_removal(gdImagePtr im)
-{
- gdImageMeanRemoval(im);
-}
-
-
-int main()
-{
- test_convolution(&test_edge_detect_quick, "basic_edge_detect_quick.png");
- test_convolution(&test_smooth, "basic_smooth.png");
- test_convolution(&test_emboss, "basic_emboss.png");
- test_convolution(&test_mean_removal, "basic_mean_removal.png");
-
- return gdNumFailures();
-}
+/** + * Basic test for gdImageConvolution() and related functions + */ + +#include "gd.h" +#include "gdtest.h" + +static void test_convolution(void (*convolution_func)(gdImagePtr im), const char *expected) +{ + gdImagePtr im; + FILE *fp; + char *path; + + fp = gdTestFileOpen2("gdimageconvolution", "basic.png"); + im = gdImageCreateFromPng(fp); + fclose(fp); + + convolution_func(im); + + path = gdTestFilePath2("gdimageconvolution", expected); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); +} + +static void test_edge_detect_quick(gdImagePtr im) +{ + gdImageEdgeDetectQuick(im); +} + +static void test_smooth(gdImagePtr im) +{ + gdImageSmooth(im, 5); +} + +static void test_emboss(gdImagePtr im) +{ + gdImageEmboss(im); +} + +static void test_mean_removal(gdImagePtr im) +{ + gdImageMeanRemoval(im); +} + +int main() +{ + test_convolution(&test_edge_detect_quick, "basic_edge_detect_quick.png"); + test_convolution(&test_smooth, "basic_smooth.png"); + test_convolution(&test_emboss, "basic_emboss.png"); + test_convolution(&test_mean_removal, "basic_mean_removal.png"); + + return gdNumFailures(); +} diff --git a/tests/gdimageconvolution/bug00369.c b/tests/gdimageconvolution/bug00369.c new file mode 100644 index 0000000..631cb7a --- /dev/null +++ b/tests/gdimageconvolution/bug00369.c @@ -0,0 +1,28 @@ +/** + * Test Issue #369 for gdImageConvolution() + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + float matrix[3][3] = { + {1, 0, 1}, + {0, 5, 0}, + {1, 0, 0} + }; + + im = gdImageCreateTrueColor(40, 40); + gdImageAlphaBlending(im, gdEffectReplace); + gdImageFilledRectangle(im, 0, 0, 39, 39, 0x7FFFFFFF); + gdImageFilledEllipse(im, 19, 19, 20, 20, 0x00FF00); + + gdImageConvolution(im, matrix, 9, 1); + gdTestAssert(0x7F010101 == gdImageGetPixel(im, 0, 0)); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gdimagecopy/CMakeLists.txt b/tests/gdimagecopy/CMakeLists.txt index d9d0eda..f586300 100644 --- a/tests/gdimagecopy/CMakeLists.txt +++ b/tests/gdimagecopy/CMakeLists.txt @@ -1,6 +1,11 @@ LIST(APPEND TESTS_FILES bug00007 +) + +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES bug00081 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagecopymerge/.gitignore b/tests/gdimagecopymerge/.gitignore new file mode 100644 index 0000000..c56b41b --- /dev/null +++ b/tests/gdimagecopymerge/.gitignore @@ -0,0 +1 @@ +/gdimagecopymerge diff --git a/tests/gdimagecopymerge/CMakeLists.txt b/tests/gdimagecopymerge/CMakeLists.txt new file mode 100644 index 0000000..df9bdc6 --- /dev/null +++ b/tests/gdimagecopymerge/CMakeLists.txt @@ -0,0 +1,7 @@ +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + gdimagecopymerge +) +ENDIF(PNG_FOUND) + +ADD_GD_TESTS() diff --git a/tests/gdimagecopymerge/Makemodule.am b/tests/gdimagecopymerge/Makemodule.am new file mode 100644 index 0000000..6751168 --- /dev/null +++ b/tests/gdimagecopymerge/Makemodule.am @@ -0,0 +1,8 @@ +if HAVE_LIBPNG +libgd_test_programs += \ + gdimagecopymerge/gdimagecopymerge +endif + +EXTRA_DIST += \ + gdimagecopymerge/CMakeLists.txt \ + gdimagecopymerge/gdimagecopymerge_exp.png diff --git a/tests/gdimagecopymerge/gdimagecopymerge.c b/tests/gdimagecopymerge/gdimagecopymerge.c new file mode 100644 index 0000000..9f08020 --- /dev/null +++ b/tests/gdimagecopymerge/gdimagecopymerge.c @@ -0,0 +1,38 @@ +/** + * Basic test for gdImageCopyMerge() + */ +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr dst = NULL; + gdImagePtr src = NULL; + int error = 0; + + dst = gdImageCreate(100, 100); + src = gdImageCreate(50, 50); + + if (gdTestAssert(!dst)) { + error = 1; + goto done; + } + if (gdTestAssert(!src)) { + error = 1; + goto done; + } + + gdImageColorAllocate(src, 255, 255, 255); + gdImageColorAllocate(dst, 0, 0, 0); + gdImageCopyMerge(dst, src, 25, 25, 0, 0, 50, 50, 50); + + if (!gdAssertImageEqualsToFile("gdimagecopymerge/gdimagecopymerge_exp.png", dst)) { + error = 1; + } + +done: + gdImageDestroy(dst); + gdImageDestroy(src); + + return error; +} diff --git a/tests/gdimagecopymerge/gdimagecopymerge_exp.png b/tests/gdimagecopymerge/gdimagecopymerge_exp.png Binary files differnew file mode 100644 index 0000000..1830281 --- /dev/null +++ b/tests/gdimagecopymerge/gdimagecopymerge_exp.png diff --git a/tests/gdimagecopymergegray/.gitignore b/tests/gdimagecopymergegray/.gitignore new file mode 100644 index 0000000..a85d2ac --- /dev/null +++ b/tests/gdimagecopymergegray/.gitignore @@ -0,0 +1 @@ +/gdimagecopymergegray diff --git a/tests/gdimagecopymergegray/CMakeLists.txt b/tests/gdimagecopymergegray/CMakeLists.txt new file mode 100644 index 0000000..e0656ef --- /dev/null +++ b/tests/gdimagecopymergegray/CMakeLists.txt @@ -0,0 +1,7 @@ +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + gdimagecopymergegray +) +ENDIF(PNG_FOUND) + +ADD_GD_TESTS() diff --git a/tests/gdimagecopymergegray/Makemodule.am b/tests/gdimagecopymergegray/Makemodule.am new file mode 100644 index 0000000..6856d75 --- /dev/null +++ b/tests/gdimagecopymergegray/Makemodule.am @@ -0,0 +1,8 @@ +if HAVE_LIBPNG +libgd_test_programs += \ + gdimagecopymergegray/gdimagecopymergegray +endif + +EXTRA_DIST += \ + gdimagecopymergegray/CMakeLists.txt \ + gdimagecopymergegray/gdimagecopymergegray_exp.png diff --git a/tests/gdimagecopymergegray/gdimagecopymergegray.c b/tests/gdimagecopymergegray/gdimagecopymergegray.c new file mode 100644 index 0000000..34a8923 --- /dev/null +++ b/tests/gdimagecopymergegray/gdimagecopymergegray.c @@ -0,0 +1,38 @@ +/** + * Basic test for gdImageCopyMergeGray() + */ +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr dst = NULL; + gdImagePtr src = NULL; + int error = 0; + + dst = gdImageCreate(100, 100); + src = gdImageCreate(50, 50); + + if (gdTestAssert(!dst)) { + error = 1; + goto done; + } + if (gdTestAssert(!src)) { + error = 1; + goto done; + } + + gdImageColorAllocate(src, 255, 255, 255); + gdImageColorAllocate(dst, 0, 0, 0); + gdImageCopyMergeGray(dst, src, 25, 25, 0, 0, 50, 50, 50); + + if (!gdAssertImageEqualsToFile("gdimagecopymergegray/gdimagecopymergegray_exp.png", dst)) { + error = 1; + } + +done: + gdImageDestroy(dst); + gdImageDestroy(src); + + return error; +} diff --git a/tests/gdimagecopymergegray/gdimagecopymergegray_exp.png b/tests/gdimagecopymergegray/gdimagecopymergegray_exp.png Binary files differnew file mode 100644 index 0000000..1830281 --- /dev/null +++ b/tests/gdimagecopymergegray/gdimagecopymergegray_exp.png diff --git a/tests/gdimagecopyresampled/CMakeLists.txt b/tests/gdimagecopyresampled/CMakeLists.txt index 636c811..00351ca 100644 --- a/tests/gdimagecopyresampled/CMakeLists.txt +++ b/tests/gdimagecopyresampled/CMakeLists.txt @@ -1,8 +1,12 @@ LIST(APPEND TESTS_FILES + exact_alpha +) +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES basic basic_alpha - exact_alpha bug00201 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagecopyresampled/Makemodule.am b/tests/gdimagecopyresampled/Makemodule.am index 5d0d714..d42eab5 100644 --- a/tests/gdimagecopyresampled/Makemodule.am +++ b/tests/gdimagecopyresampled/Makemodule.am @@ -1,8 +1,10 @@ +libgd_test_programs += \ + gdimagecopyresampled/exact_alpha + if HAVE_LIBPNG libgd_test_programs += \ gdimagecopyresampled/basic \ gdimagecopyresampled/basic_alpha \ - gdimagecopyresampled/exact_alpha \ gdimagecopyresampled/bug00201 endif diff --git a/tests/gdimagecopyresampled/bug00201.c b/tests/gdimagecopyresampled/bug00201.c index 053b6db..0287267 100644 --- a/tests/gdimagecopyresampled/bug00201.c +++ b/tests/gdimagecopyresampled/bug00201.c @@ -48,23 +48,23 @@ int main() fp = gdTestFileOpen2("gdimagecopyresampled", "bug00201_src.png"); logo_source = gdImageCreateFromPng(fp); fclose(fp); - + logo = blank_image(SRC_WIDTH,SRC_HEIGHT); gdImageAlphaBlending(logo, 0); gdImageCopy(logo, logo_source, 0,0, 0,0, SRC_WIDTH,SRC_HEIGHT); gdImageDestroy(logo_source); - + scaled_logo = blank_image(DEST_WIDTH,DEST_HEIGHT); gdImageAlphaBlending(scaled_logo, 0); gdImageCopyResampled(scaled_logo, logo, 0,0, 0,0, 200,105, SRC_WIDTH,SRC_HEIGHT); gdImageDestroy(logo); - + layers[0] = background; layers[1] = scaled_logo; img = flatten(layers, 2, DEST_WIDTH, DEST_HEIGHT); gdImageDestroy(background); gdImageDestroy(scaled_logo); - + gdAssertImageEqualsToFile("gdimagecopyresampled/bug00201_exp.png", img); gdImageDestroy(img); return gdNumFailures(); diff --git a/tests/gdimagecopyresized/.gitignore b/tests/gdimagecopyresized/.gitignore new file mode 100644 index 0000000..185cf1f --- /dev/null +++ b/tests/gdimagecopyresized/.gitignore @@ -0,0 +1 @@ +/gdimagecopyresized diff --git a/tests/gdimagecopyresized/CMakeLists.txt b/tests/gdimagecopyresized/CMakeLists.txt new file mode 100644 index 0000000..78b4fa9 --- /dev/null +++ b/tests/gdimagecopyresized/CMakeLists.txt @@ -0,0 +1,7 @@ +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + gdimagecopyresized +) +ENDIF(PNG_FOUND) + +ADD_GD_TESTS() diff --git a/tests/gdimagecopyresized/Makemodule.am b/tests/gdimagecopyresized/Makemodule.am new file mode 100644 index 0000000..9d83e40 --- /dev/null +++ b/tests/gdimagecopyresized/Makemodule.am @@ -0,0 +1,8 @@ +if HAVE_LIBPNG +libgd_test_programs += \ + gdimagecopyresized/gdimagecopyresized +endif + +EXTRA_DIST += \ + gdimagecopyresized/CMakeLists.txt \ + gdimagecopyresized/gdimagecopyresized_exp.png diff --git a/tests/gdimagecopyresized/gdimagecopyresized.c b/tests/gdimagecopyresized/gdimagecopyresized.c new file mode 100644 index 0000000..137f84b --- /dev/null +++ b/tests/gdimagecopyresized/gdimagecopyresized.c @@ -0,0 +1,35 @@ +/** + * add test case for gdImageCopyResized + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr src; + gdImagePtr dst; + gdImagePtr dst_tc; + + /* We prepare two image type: Palette and True Color */ + /* src image is white, while dst and dst_tc is black */ + src = gdImageCreate(64, 64); + gdImageColorAllocate(src, 255, 255, 255); + dst = gdImageCreate(128, 128); + gdImageColorAllocate(dst, 0, 0, 0); + dst_tc = gdImageCreateTrueColor(128, 128); + + /* Copy src to two image type separately */ + /* We copy src to the center of dst and dst_tc */ + gdImageCopyResized(dst, src, 32, 32, 0, 0, 64, 64, 64, 64); + gdImageCopyResized(dst_tc, src, 32, 32, 0, 0, 64, 64, 64, 64); + + gdAssertImageEqualsToFile("gdimagecopyresized/gdimagecopyresized_exp.png", dst); + gdAssertImageEqualsToFile("gdimagecopyresized/gdimagecopyresized_exp.png", dst_tc); + + gdImageDestroy(src); + gdImageDestroy(dst); + gdImageDestroy(dst_tc); + + return gdNumFailures(); +} diff --git a/tests/gdimagecopyresized/gdimagecopyresized_exp.png b/tests/gdimagecopyresized/gdimagecopyresized_exp.png Binary files differnew file mode 100644 index 0000000..32fa084 --- /dev/null +++ b/tests/gdimagecopyresized/gdimagecopyresized_exp.png diff --git a/tests/gdimagecopyrotated/CMakeLists.txt b/tests/gdimagecopyrotated/CMakeLists.txt index fc17e9d..7f1a678 100644 --- a/tests/gdimagecopyrotated/CMakeLists.txt +++ b/tests/gdimagecopyrotated/CMakeLists.txt @@ -1,5 +1,7 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES bug00020 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagecreate/.gitignore b/tests/gdimagecreate/.gitignore new file mode 100644 index 0000000..6300aed --- /dev/null +++ b/tests/gdimagecreate/.gitignore @@ -0,0 +1 @@ +/bug00340 diff --git a/tests/gdimagecreate/CMakeLists.txt b/tests/gdimagecreate/CMakeLists.txt new file mode 100644 index 0000000..1cd0c1a --- /dev/null +++ b/tests/gdimagecreate/CMakeLists.txt @@ -0,0 +1,5 @@ +LIST(APPEND TESTS_FILES + bug00340 +) + +ADD_GD_TESTS() diff --git a/tests/gdimagecreate/Makemodule.am b/tests/gdimagecreate/Makemodule.am new file mode 100644 index 0000000..8866086 --- /dev/null +++ b/tests/gdimagecreate/Makemodule.am @@ -0,0 +1,5 @@ +libgd_test_programs += \ + gdimagecreate/bug00340 + +EXTRA_DIST += \ + gdimagecreate/CMakeLists.txt diff --git a/tests/gdimagecreate/bug00340.c b/tests/gdimagecreate/bug00340.c new file mode 100644 index 0000000..9c6eff3 --- /dev/null +++ b/tests/gdimagecreate/bug00340.c @@ -0,0 +1,29 @@ +/** + * Regression test for <https://github.com/libgd/libgd/issues/340> + * + * We're testing that trying to create an oversized image fails early, + * triggering an appropriate warning. + */ + +#include <string.h> +#include "gd.h" +#include "gd_errors.h" +#include "gdtest.h" + +#define MSG "product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n" + +void error_handler(int priority, const char *format, ...) +{ + gdTestAssert(priority == GD_WARNING); + gdTestAssert(!strcmp(format, MSG)); +} + +int main() +{ + gdImagePtr im; + + im = gdImageCreate(64970, 65111); + gdTestAssert(im == NULL); + + return gdNumFailures(); +} diff --git a/tests/gdimagecrop/.gitignore b/tests/gdimagecrop/.gitignore index a90ef00..ada3cad 100644 --- a/tests/gdimagecrop/.gitignore +++ b/tests/gdimagecrop/.gitignore @@ -1,2 +1,6 @@ /bug00297 +/bug00432 +/bug00485_auto +/bug00485_threshold +/bug00486 /php_bug_72494 diff --git a/tests/gdimagecrop/CMakeLists.txt b/tests/gdimagecrop/CMakeLists.txt index 4b1e97e..43f6f6c 100644 --- a/tests/gdimagecrop/CMakeLists.txt +++ b/tests/gdimagecrop/CMakeLists.txt @@ -1,6 +1,10 @@ -SET(TESTS_FILES +LIST(APPEND TESTS_FILES bug00297 + bug00432 + bug00485_auto + bug00485_threshold php_bug_72494 + bug00486 ) ADD_GD_TESTS() diff --git a/tests/gdimagecrop/Makemodule.am b/tests/gdimagecrop/Makemodule.am index fe73c1d..1725f6c 100644 --- a/tests/gdimagecrop/Makemodule.am +++ b/tests/gdimagecrop/Makemodule.am @@ -1,5 +1,9 @@ libgd_test_programs += \ gdimagecrop/bug00297 \ + gdimagecrop/bug00432 \ + gdimagecrop/bug00485_auto \ + gdimagecrop/bug00485_threshold \ + gdimagecrop/bug00486 \ gdimagecrop/php_bug_72494 EXTRA_DIST += \ diff --git a/tests/gdimagecrop/bug00432.c b/tests/gdimagecrop/bug00432.c new file mode 100644 index 0000000..d3f681f --- /dev/null +++ b/tests/gdimagecrop/bug00432.c @@ -0,0 +1,45 @@ +/** + * Test that gdImageCrop() retains transparency + * + * We create an image with transparent pixels, crop the image, and check whether + * all pixels are identical to the respective source image. + * + * See <https://github.com/libgd/libgd/issues/432> + */ + + +#include "gd.h" +#include "gdtest.h" + + +#define WIDTH 10 +#define HEIGHT 10 +#define XOFF 1 +#define YOFF 1 + + +int main() +{ + gdImagePtr src, dst; + gdRect crop = {XOFF, YOFF, WIDTH-XOFF-1, HEIGHT-YOFF-1}; + int i, j; + + src = gdImageCreateTrueColor(WIDTH, HEIGHT); + gdImageAlphaBlending(src, gdEffectReplace); + gdImageFilledRectangle(src, 0, 0, WIDTH-1, HEIGHT-1, + gdTrueColorAlpha(gdRedMax, gdGreenMax, gdBlueMax, gdAlphaMax)); + + dst = gdImageCrop(src, &crop); + gdTestAssert(dst != NULL); + + for (i = 0; i < gdImageSX(dst); i++) { + for (j = 0; j < gdImageSY(dst); j++) { + gdTestAssert(gdImageGetPixel(dst, i, j) == gdImageGetPixel(src, i+XOFF, j+YOFF)); + } + } + + gdImageDestroy(src); + gdImageDestroy(dst); + + return gdNumFailures(); +} diff --git a/tests/gdimagecrop/bug00485_auto.c b/tests/gdimagecrop/bug00485_auto.c new file mode 100644 index 0000000..3c0627e --- /dev/null +++ b/tests/gdimagecrop/bug00485_auto.c @@ -0,0 +1,52 @@ +/** + * Test that gdImageCropAuto() works pixel precise + * + * We test that a single black pixel anywhere (but the corners) on an 8x8 pixel + * image with a white background is auto-cropped to a 1x1 pixel image with a + * black pixel. + * + * See <https://github.com/libgd/libgd/issues/485> + */ + + +#include "gd.h" +#include "gdtest.h" + + +gdImagePtr createWhiteImageWithBlackPixelAt(int x, int y) +{ + gdImagePtr im = gdImageCreateTrueColor(8, 8); + gdImageFilledRectangle(im, 0, 0, 7, 7, 0xffffff); + gdImageSetPixel(im, x, y, 0x000000); + return im; +} + + +int main() +{ + int x, y, height, width, color; + gdImagePtr orig, cropped; + + for (y = 0; y < 8; y++) { + for (x = 0; x < 8; x++) { + if ((x == 0 && (y == 0 || y == 7)) || (x == 7 && (y == 0 || y == 7))) { + continue; // skip the corners + } + orig = createWhiteImageWithBlackPixelAt(x, y); + cropped = gdImageCropAuto(orig, GD_CROP_SIDES); + gdTestAssertMsg(cropped != NULL, "Pixel at %d, %d: unexpected NULL crop\n", x, y); + if (cropped) { + width = gdImageSX(cropped); + gdTestAssertMsg(width == 1, "Pixel at %d, %d: unexpected width (%d)\n", x, y, width); + height = gdImageSY(cropped); + gdTestAssertMsg(height == 1, "Pixel at %d, %d: unexpected height (%d)\n", x, y, height); + color = gdImageGetPixel(cropped, 0, 0); + gdTestAssertMsg(color == 0x000000, "Pixel at %d, %d: unexpected color (%d)\n", x, y, color); + gdImageDestroy(cropped); + } + gdImageDestroy(orig); + } + } + + return gdNumFailures(); +} diff --git a/tests/gdimagecrop/bug00485_threshold.c b/tests/gdimagecrop/bug00485_threshold.c new file mode 100644 index 0000000..31ac38f --- /dev/null +++ b/tests/gdimagecrop/bug00485_threshold.c @@ -0,0 +1,48 @@ +/** + * Test that gdImageCropThreshold() works pixel precise + * + * We test that a single black pixel anywhere on an 8x8 pixel image with a white + * background is threshold-cropped to a 1x1 pixel image with a black pixel. + * + * See <https://github.com/libgd/libgd/issues/485> + */ + + +#include "gd.h" +#include "gdtest.h" + + +gdImagePtr createWhiteImageWithBlackPixelAt(int x, int y) +{ + gdImagePtr im = gdImageCreateTrueColor(8, 8); + gdImageFilledRectangle(im, 0, 0, 7, 7, 0xffffff); + gdImageSetPixel(im, x, y, 0x000000); + return im; +} + + +int main() +{ + int x, y, height, width, color; + gdImagePtr orig, cropped; + + for (y = 0; y < 8; y++) { + for (x = 0; x < 8; x++) { + orig = createWhiteImageWithBlackPixelAt(x, y); + cropped = gdImageCropThreshold(orig, 0xffffff, 1.0); + gdTestAssertMsg(cropped != NULL, "Pixel at %d, %d: unexpected NULL crop\n", x, y); + if (cropped) { + width = gdImageSX(cropped); + gdTestAssertMsg(width == 1, "Pixel at %d, %d: unexpected width (%d)\n", x, y, width); + height = gdImageSY(cropped); + gdTestAssertMsg(height == 1, "Pixel at %d, %d: unexpected height (%d)\n", x, y, height); + color = gdImageGetPixel(cropped, 0, 0); + gdTestAssertMsg(color == 0x000000, "Pixel at %d, %d: unexpected color (%d)\n", x, y, color); + gdImageDestroy(cropped); + } + gdImageDestroy(orig); + } + } + + return gdNumFailures(); +} diff --git a/tests/gdimagecrop/bug00486.c b/tests/gdimagecrop/bug00486.c new file mode 100644 index 0000000..289d88f --- /dev/null +++ b/tests/gdimagecrop/bug00486.c @@ -0,0 +1,48 @@ +/** + * Test that gdImageCropAuto() crops left and right as well + * + * We test that an image with four unicolored quadrants, where either both left + * quadrants or both right quadrants have the same color, but the remaining + * quadrants have different colors, are treated identically by + * gdImageCropAuto(…, GD_CROP_SIDES). + * + * See <https://github.com/libgd/libgd/issues/486> + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr orig, croppedLeft, croppedRight; + int red, green, blue; + + orig = gdImageCreateTrueColor(8, 8); + red = gdImageColorAllocate(orig, 255, 0, 0); + green = gdImageColorAllocate(orig, 0, 255, 0); + blue = gdImageColorAllocate(orig, 0, 0, 255); + + gdImageFilledRectangle(orig, 0, 0, 3, 3, green); // tl + gdImageFilledRectangle(orig, 4, 0, 7, 3, red); // tr + gdImageFilledRectangle(orig, 0, 4, 3, 7, green); // bl + gdImageFilledRectangle(orig, 4, 4, 7, 7, blue); // br + croppedLeft = gdImageCropAuto(orig, GD_CROP_SIDES); + gdTestAssert(croppedLeft != NULL); + + gdImageFilledRectangle(orig, 0, 0, 3, 3, red); // tl + gdImageFilledRectangle(orig, 4, 0, 7, 3, green); // tr + gdImageFilledRectangle(orig, 0, 4, 3, 7, blue); // bl + gdImageFilledRectangle(orig, 4, 4, 7, 7, green); // br + croppedRight = gdImageCropAuto(orig, GD_CROP_SIDES); + gdTestAssert(croppedRight != NULL); + + gdAssertImageEquals(croppedRight, croppedLeft); + + gdImageDestroy(orig); + gdImageDestroy(croppedLeft); + gdImageDestroy(croppedRight); + + return gdNumFailures(); +} diff --git a/tests/gdimageellipse/.gitignore b/tests/gdimageellipse/.gitignore new file mode 100644 index 0000000..58e31a6 --- /dev/null +++ b/tests/gdimageellipse/.gitignore @@ -0,0 +1 @@ +/bug00169 diff --git a/tests/gdimageellipse/CMakeLists.txt b/tests/gdimageellipse/CMakeLists.txt new file mode 100644 index 0000000..b7d79f2 --- /dev/null +++ b/tests/gdimageellipse/CMakeLists.txt @@ -0,0 +1,7 @@ +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + bug00169 +) +ENDIF(PNG_FOUND) + +ADD_GD_TESTS() diff --git a/tests/gdimageellipse/Makemodule.am b/tests/gdimageellipse/Makemodule.am new file mode 100644 index 0000000..11d2079 --- /dev/null +++ b/tests/gdimageellipse/Makemodule.am @@ -0,0 +1,8 @@ +if HAVE_LIBPNG +libgd_test_programs += \ + gdimageellipse/bug00169 +endif + +EXTRA_DIST += \ + gdimageellipse/CMakeLists.txt \ + gdimageellipse/bug00169_exp.png diff --git a/tests/gdimageellipse/bug00169.c b/tests/gdimageellipse/bug00169.c new file mode 100644 index 0000000..8246c8c --- /dev/null +++ b/tests/gdimageellipse/bug00169.c @@ -0,0 +1,22 @@ +/** + * add test case for gdImageEllipse + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + int white = 0; + + im = gdImageCreateTrueColor(2200, 2200); + white = gdImageColorAllocate(im, 255, 255, 255); + + gdImageEllipse(im, 1100, 1100, 2200, 2200, white); + gdAssertImageEqualsToFile("gdimageellipse/bug00169_exp.png", im); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gdimageellipse/bug00169_exp.png b/tests/gdimageellipse/bug00169_exp.png Binary files differnew file mode 100644 index 0000000..f844608 --- /dev/null +++ b/tests/gdimageellipse/bug00169_exp.png diff --git a/tests/gdimagefile/CMakeLists.txt b/tests/gdimagefile/CMakeLists.txt index 55ae374..8676264 100644 --- a/tests/gdimagefile/CMakeLists.txt +++ b/tests/gdimagefile/CMakeLists.txt @@ -1,5 +1,11 @@ +IF(TIFF_FOUND) +IF(WEBP_FOUND) +IF(ENABLE_GD_FORMATS) LIST(APPEND TESTS_FILES gdnametest ) +ENDIF(ENABLE_GD_FORMATS) +ENDIF(WEBP_FOUND) +ENDIF(TIFF_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagefile/Makemodule.am b/tests/gdimagefile/Makemodule.am index b537cbc..8c9e4d5 100644 --- a/tests/gdimagefile/Makemodule.am +++ b/tests/gdimagefile/Makemodule.am @@ -1,5 +1,11 @@ +if HAVE_LIBTIFF +if HAVE_LIBWEBP +if ENABLE_GD_FORMATS libgd_test_programs += \ gdimagefile/gdnametest +endif +endif +endif EXTRA_DIST += \ gdimagefile/CMakeLists.txt \ diff --git a/tests/gdimagefile/gdnametest.c b/tests/gdimagefile/gdnametest.c index 66da484..fcd040a 100644 --- a/tests/gdimagefile/gdnametest.c +++ b/tests/gdimagefile/gdnametest.c @@ -11,150 +11,145 @@ #define LY (HEIGHT/2) // Line Y #define HT 2 // Half of line-thickness - -gdImagePtr mkwhite(int x, int y) +static gdImagePtr +mkwhite(int x, int y) { - gdImagePtr im; + gdImagePtr im; im = gdImageCreateTrueColor(x, y); gdImageFilledRectangle(im, 0, 0, x-1, y-1, - gdImageColorExactAlpha(im, 255, 255, 255, 0)); + gdImageColorExactAlpha(im, 255, 255, 255, 0)); - gdTestAssert(im != NULL); + gdTestAssert(im != NULL); - gdImageSetInterpolationMethod(im, GD_BICUBIC); // FP interp'n + gdImageSetInterpolationMethod(im, GD_BICUBIC); // FP interp'n - return im; + return im; }/* mkwhite*/ +static gdImagePtr +mkcross(void) +{ + gdImagePtr im; + int fg, n; -gdImagePtr mkcross() { - gdImagePtr im; - int fg, n; - - im = mkwhite(WIDTH, HEIGHT); - fg = gdImageColorAllocate(im, 0, 0, 0); + im = mkwhite(WIDTH, HEIGHT); + fg = gdImageColorAllocate(im, 0, 0, 0); - for (n = -HT; n < HT; n++) { - gdImageLine(im, LX-n, 0, LX-n, HEIGHT-1, fg); - gdImageLine(im, 0, LY-n, WIDTH-1, LY-n, fg); - }/* for */ + for (n = -HT; n < HT; n++) { + gdImageLine(im, LX-n, 0, LX-n, HEIGHT-1, fg); + gdImageLine(im, 0, LY-n, WIDTH-1, LY-n, fg); + }/* for */ - return im; + return im; }/* mkcross*/ - - - -void -do_test() { - - gdTestAssertMsg(strchr("123",'2') != 0, "strchr() is not functional.\n"); - gdTestAssertMsg(strcasecmp("123abC","123Abc") == 0, "strcasecmp() is not functional.\n"); - - int n; - struct { - const char *nm; // Filename - unsigned maxdiff; // Maximum total pixel diff - int required; // 1 -> image type always supported, -1 -> skip it - int readonly; // 1 -> gd can only read this type - } names[] = { - {"img.png", 0, 0, 0}, - {"img.gif", 5, 1, 0}, // This seems to come from tc<->palette - {"img.GIF", 5, 1, 0}, // Test for case insensitivity - {"img.gd", 0, 1, 0}, - {"img.gd2", 0, 0, 0}, - {"img.jpg", 25, 0, 0}, - {"img.jpeg", 25, 0, 0}, - {"img.wbmp", 0, 1, 0}, - {"img.bmp", 0, 1, 0}, - {"img-ref.xpm", 0, 0, 1}, - - // These break the test so I'm skipping them since the point - // of this test is not those loaders. - {"img-ref.xbm", 0, -1, 1}, - {"img-ref.tga", 0, -1, 1}, - {"img.webp", 0, -1, 0}, - {"img.tiff", 0, -1, 0}, - - {NULL, 0} - }; - - for (n = 0; names[n].nm; n++) { - gdImagePtr orig, copy; - int status; - char *full_filename = NULL; - - /* Some image readers are buggy and crash the program so we - * skip them. Bug fixers should remove these from the list of - * skipped items as bugs are fixed. */ - if (names[n].required < 0) { - printf("Skipping test for '%s'. FIX THIS!\n", names[n].nm); - continue; - }/* if */ - - /* Skip this file if the current library build doesn't support - * it. (If it's one of the built-in types, *that* a different - * problem; we assert that here.) */ - if (!gdSupportsFileType(names[n].nm, 0)) { - gdTestAssertMsg(!names[n].required, "GD doesn't support required file type: %s\n", full_filename); - continue; - }/* if */ - - orig = mkcross(); - - /* Write the image unless writing is not supported. */ - if (!names[n].readonly) { - /* Prepend the test directory; this is expected to be run in - * the parent dir. */ - full_filename = gdTestTempFile(names[n].nm); - status = gdImageFile(orig, full_filename); - gdTestAssertMsg(status == GD_TRUE, "Failed to create %s\n", full_filename); - } else { - /* Prepend the test directory; this is expected to be run in - * the parent dir. */ - full_filename = gdTestFilePath2("gdimagefile", names[n].nm); - }/* if */ - - copy = gdImageCreateFromFile(full_filename); - gdTestAssertMsg(!!copy, "Failed to load %s\n", full_filename); - if (!copy) continue; - - gdTestAssertMsg(gdMaxPixelDiff(orig, copy) <= names[n].maxdiff,"Pixels different on %s\n", full_filename, full_filename); - - if (!names[n].readonly) { - status = remove(full_filename); - gdTestAssertMsg(status == 0, "Failed to delete %s\n", full_filename); - }/* if */ - - free(full_filename); - gdImageDestroy(orig); - gdImageDestroy(copy); - }/* for */ +static void +do_test(void) +{ + gdTestAssertMsg(strchr("123",'2') != 0, "strchr() is not functional.\n"); + gdTestAssertMsg(strcasecmp("123abC","123Abc") == 0, "strcasecmp() is not functional.\n"); + + int n; + struct { + const char *nm; // Filename + unsigned maxdiff; // Maximum total pixel diff + int required; // 1 -> image type always supported, -1 -> skip it + int readonly; // 1 -> gd can only read this type + } names[] = { + {"img.png", 0, 0, 0}, + {"img.gif", 5, 1, 0}, // This seems to come from tc<->palette + {"img.GIF", 5, 1, 0}, // Test for case insensitivity + {"img.gd", 0, 1, 0}, + {"img.gd2", 0, 0, 0}, + {"img.jpg", 25, 0, 0}, + {"img.jpeg", 25, 0, 0}, + {"img.wbmp", 0, 1, 0}, + {"img.bmp", 0, 1, 0}, + {"img-ref.xpm", 0, 0, 1}, + {"img-ref.xbm", 0, 1, 1}, + {"img-ref.tga", 0, 1, 1}, + {"img.webp", 10, 1, 0}, + {"img.tiff", 0, 1, 0}, + + {NULL, 0} + }; + + for (n = 0; names[n].nm; n++) { + gdImagePtr orig, copy; + int status; + char *full_filename = NULL; + unsigned int pixels; + + /* Some image readers are buggy and crash the program so we + * skip them. Bug fixers should remove these from the list of + * skipped items as bugs are fixed. */ + if (names[n].required < 0) { + printf("Skipping test for '%s'. FIX THIS!\n", names[n].nm); + continue; + }/* if */ + + /* Skip this file if the current library build doesn't support + * it. (If it's one of the built-in types, *that* a different + * problem; we assert that here.) */ + if (!gdSupportsFileType(names[n].nm, 0)) { + gdTestAssertMsg(!names[n].required, "GD doesn't support required file type: %s\n", names[n].nm); + continue; + }/* if */ + + orig = mkcross(); + + /* Write the image unless writing is not supported. */ + if (!names[n].readonly) { + /* Prepend the test directory; this is expected to be run in + * the parent dir. */ + full_filename = gdTestTempFile(names[n].nm); + status = gdImageFile(orig, full_filename); + gdTestAssertMsg(status == GD_TRUE, "Failed to create %s\n", full_filename); + } else { + /* Prepend the test directory; this is expected to be run in + * the parent dir. */ + full_filename = gdTestFilePath2("gdimagefile", names[n].nm); + }/* if */ + + copy = gdImageCreateFromFile(full_filename); + gdTestAssertMsg(!!copy, "Failed to load %s\n", full_filename); + if (!copy) continue; + + pixels = gdMaxPixelDiff(orig, copy); + gdTestAssertMsg(pixels <= names[n].maxdiff, "%u pixels different on %s\n", pixels, full_filename); + + if (!names[n].readonly) { + status = remove(full_filename); + gdTestAssertMsg(status == 0, "Failed to delete %s\n", full_filename); + }/* if */ + + free(full_filename); + gdImageDestroy(orig); + gdImageDestroy(copy); + }/* for */ }/* do_test*/ +static void +do_errortest(void) +{ + gdImagePtr im; -void -do_errortest() { - gdImagePtr im; - - im = mkcross(); + im = mkcross(); - gdTestAssert(!gdImageFile(im, "img.xpng")); - gdTestAssert(!gdImageFile(im, "bobo")); - gdTestAssert(!gdImageFile(im, "png")); - gdTestAssert(!gdImageFile(im, "")); + gdTestAssert(!gdImageFile(im, "img.xpng")); + gdTestAssert(!gdImageFile(im, "bobo")); + gdTestAssert(!gdImageFile(im, "png")); + gdTestAssert(!gdImageFile(im, "")); - gdImageDestroy(im); + gdImageDestroy(im); }/* do_errortest*/ - int main() { + do_test(); + do_errortest(); - do_test(); - do_errortest(); - - return gdNumFailures(); + return gdNumFailures(); } diff --git a/tests/gdimagefill/CMakeLists.txt b/tests/gdimagefill/CMakeLists.txt index c54281e..457fd8d 100644 --- a/tests/gdimagefill/CMakeLists.txt +++ b/tests/gdimagefill/CMakeLists.txt @@ -1,3 +1,4 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES bug00002_1 bug00002_2 @@ -5,5 +6,6 @@ LIST(APPEND TESTS_FILES bug00002_4 bug00104_1 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagefill/bug00002_1.c b/tests/gdimagefill/bug00002_1.c index 752178a..3feaf42 100644 --- a/tests/gdimagefill/bug00002_1.c +++ b/tests/gdimagefill/bug00002_1.c @@ -37,4 +37,3 @@ int main() return error; } - diff --git a/tests/gdimagefill/bug00002_2.c b/tests/gdimagefill/bug00002_2.c index 982ae8f..4edcd6a 100644 --- a/tests/gdimagefill/bug00002_2.c +++ b/tests/gdimagefill/bug00002_2.c @@ -46,4 +46,3 @@ int main() gdImageDestroy(tile); return error; } - diff --git a/tests/gdimagefill/bug00002_3.c b/tests/gdimagefill/bug00002_3.c index b11fbc9..1a1929e 100644 --- a/tests/gdimagefill/bug00002_3.c +++ b/tests/gdimagefill/bug00002_3.c @@ -51,4 +51,3 @@ int main() gdImageDestroy(tile); return error; } - diff --git a/tests/gdimagefill/bug00104_1.c b/tests/gdimagefill/bug00104_1.c index 13247ca..694788a 100644 --- a/tests/gdimagefill/bug00104_1.c +++ b/tests/gdimagefill/bug00104_1.c @@ -8,26 +8,26 @@ int main() gdImagePtr im, tile; int tile_red, tile_blue; int error = 0; - + im = gdImageCreate(200, 150); tile = gdImageCreateTrueColor(2, 2); - + tile_red = gdImageColorAllocate(tile, 255, 0, 0); tile_blue = gdImageColorAllocate(tile, 0, 0, 255); - + gdImageSetPixel(tile, 0, 0, tile_red); gdImageSetPixel(tile, 1, 1, tile_red); gdImageSetPixel(tile, 1, 0, tile_blue); gdImageSetPixel(tile, 0, 1, tile_blue); - + gdImageSetTile(im, tile); gdImageFill(im, 11, 12, gdTiled); if (!gdAssertImageEqualsToFile("gdimagefill/bug00104_1_exp.png", im)) { error = 1; } - + gdImageDestroy(im); gdImageDestroy(tile); return error; diff --git a/tests/gdimagefilledarc/.gitignore b/tests/gdimagefilledarc/.gitignore index e6d2cbe..da4b002 100644 --- a/tests/gdimagefilledarc/.gitignore +++ b/tests/gdimagefilledarc/.gitignore @@ -1 +1,2 @@ +/bug00351 /php_bug43828 diff --git a/tests/gdimagefilledarc/CMakeLists.txt b/tests/gdimagefilledarc/CMakeLists.txt index 1a0a204..4042df9 100644 --- a/tests/gdimagefilledarc/CMakeLists.txt +++ b/tests/gdimagefilledarc/CMakeLists.txt @@ -1,5 +1,8 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES + bug00351 php_bug43828 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagefilledarc/Makemodule.am b/tests/gdimagefilledarc/Makemodule.am index 4af6963..710c0a0 100644 --- a/tests/gdimagefilledarc/Makemodule.am +++ b/tests/gdimagefilledarc/Makemodule.am @@ -1,8 +1,10 @@ if HAVE_LIBPNG libgd_test_programs += \ + gdimagefilledarc/bug00351 \ gdimagefilledarc/php_bug43828 endif EXTRA_DIST += \ gdimagefilledarc/CMakeLists.txt \ + gdimagefilledarc/bug00351_exp.png \ gdimagefilledarc/php_bug43828_exp.png diff --git a/tests/gdimagefilledarc/bug00351.c b/tests/gdimagefilledarc/bug00351.c new file mode 100644 index 0000000..20b0fde --- /dev/null +++ b/tests/gdimagefilledarc/bug00351.c @@ -0,0 +1,30 @@ +/** + * Test drawing of pies starting and/or ending near 90° + * + * See <https://github.com/libgd/libgd/issues/351>. + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im; + int white, navy, red; + + im = gdImageCreateTrueColor(500, 500); + white = gdTrueColorAlpha(0xFF, 0xFF, 0xFF, gdAlphaOpaque); + navy = gdTrueColorAlpha(0x00, 0x00, 0x80, gdAlphaOpaque); + red = gdTrueColorAlpha(0xFF, 0x00, 0x00, gdAlphaOpaque); + + gdImageFilledArc(im, 250, 250, 500, 250, 0, 88, white, gdPie); + gdImageFilledArc(im, 250, 250, 500, 250, 88, 91 , navy, gdPie); + gdImageFilledArc(im, 250, 250, 500, 250, 91, 360 , red, gdPie); + + gdAssertImageEqualsToFile("gdimagefilledarc/bug00351_exp.png", im); + + gdImageDestroy(im); + return gdNumFailures(); +} diff --git a/tests/gdimagefilledarc/bug00351_exp.png b/tests/gdimagefilledarc/bug00351_exp.png Binary files differnew file mode 100644 index 0000000..16b2db2 --- /dev/null +++ b/tests/gdimagefilledarc/bug00351_exp.png diff --git a/tests/gdimagefilledellipse/.gitignore b/tests/gdimagefilledellipse/.gitignore index e039565..9adfb75 100644 --- a/tests/gdimagefilledellipse/.gitignore +++ b/tests/gdimagefilledellipse/.gitignore @@ -1,3 +1,4 @@ /bug00010 +/bug00169 /bug00191 /github_bug_00238 diff --git a/tests/gdimagefilledellipse/CMakeLists.txt b/tests/gdimagefilledellipse/CMakeLists.txt index 63f34f2..48286e4 100644 --- a/tests/gdimagefilledellipse/CMakeLists.txt +++ b/tests/gdimagefilledellipse/CMakeLists.txt @@ -1,7 +1,10 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES bug00010 + bug00169 bug00191 github_bug_00238 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagefilledellipse/Makemodule.am b/tests/gdimagefilledellipse/Makemodule.am index 6a5185a..0a88686 100644 --- a/tests/gdimagefilledellipse/Makemodule.am +++ b/tests/gdimagefilledellipse/Makemodule.am @@ -1,6 +1,7 @@ if HAVE_LIBPNG libgd_test_programs += \ gdimagefilledellipse/bug00010 \ + gdimagefilledellipse/bug00169 \ gdimagefilledellipse/bug00191 \ gdimagefilledellipse/github_bug_00238 endif @@ -8,5 +9,6 @@ endif EXTRA_DIST += \ gdimagefilledellipse/CMakeLists.txt \ gdimagefilledellipse/bug00010_exp.png \ + gdimagefilledellipse/bug00169_exp.png \ gdimagefilledellipse/bug00191.png \ gdimagefilledellipse/github_bug_00238_exp.png diff --git a/tests/gdimagefilledellipse/bug00169.c b/tests/gdimagefilledellipse/bug00169.c new file mode 100644 index 0000000..639e52f --- /dev/null +++ b/tests/gdimagefilledellipse/bug00169.c @@ -0,0 +1,22 @@ +/** + * add test case for gdImageFilledEllipse + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + int white = 0; + + im = gdImageCreateTrueColor(2200, 2200); + white = gdImageColorAllocate(im, 255, 255, 255); + + gdImageFilledEllipse(im, 1100, 1100, 2200, 2200, white); + gdAssertImageEqualsToFile("gdimagefilledellipse/bug00169_exp.png", im); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gdimagefilledellipse/bug00169_exp.png b/tests/gdimagefilledellipse/bug00169_exp.png Binary files differnew file mode 100644 index 0000000..db88390 --- /dev/null +++ b/tests/gdimagefilledellipse/bug00169_exp.png diff --git a/tests/gdimagefilledellipse/github_bug_00238.c b/tests/gdimagefilledellipse/github_bug_00238.c index 499923f..67c93fd 100644 --- a/tests/gdimagefilledellipse/github_bug_00238.c +++ b/tests/gdimagefilledellipse/github_bug_00238.c @@ -12,7 +12,7 @@ int main() goto exit; } - gdImageAlphaBlending(im, gdEffectNormal); + gdImageAlphaBlending(im, gdEffectNormal); gdImageFilledRectangle(im, 0, 0, 140, 199, gdTrueColorAlpha(0,0,0,127)); gdImageAlphaBlending(im, gdEffectAlphaBlend); diff --git a/tests/gdimagefilledpolygon/CMakeLists.txt b/tests/gdimagefilledpolygon/CMakeLists.txt index 97801e2..030a224 100644 --- a/tests/gdimagefilledpolygon/CMakeLists.txt +++ b/tests/gdimagefilledpolygon/CMakeLists.txt @@ -1,3 +1,4 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES gdimagefilledpolygon0 gdimagefilledpolygon1 @@ -7,5 +8,6 @@ LIST(APPEND TESTS_FILES php_bug_64641 self_intersecting ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagefilledpolygon/self_intersecting.c b/tests/gdimagefilledpolygon/self_intersecting.c index 6123cc1..f9b96da 100644 --- a/tests/gdimagefilledpolygon/self_intersecting.c +++ b/tests/gdimagefilledpolygon/self_intersecting.c @@ -1,31 +1,29 @@ -/**
- * We're testing the filling behavior of self-intersecting polygons, which is
- * *currently* using the even-odd fillrule.
- */
-
-
-#include "gd.h"
-#include "gdtest.h"
-
-
-int main()
-{
- gdImagePtr im;
- int black;
- gdPoint points[] = {{50, 5}, {24, 86}, {93, 36}, {7, 36}, {76, 86}};
- char *path;
-
- im = gdImageCreate(100, 100);
- gdImageColorAllocate(im, 255, 255, 255);
- black = gdImageColorAllocate(im, 0, 0, 0);
-
- gdImageFilledPolygon(im, points, 5, black);
-
- path = gdTestFilePath2("gdimagefilledpolygon", "self_intersecting_exp.png");
- gdAssertImageEqualsToFile(path, im);
- gdFree(path);
-
- gdImageDestroy(im);
-
- return gdNumFailures();
-}
+/** + * We're testing the filling behavior of self-intersecting polygons, which is + * *currently* using the even-odd fillrule. + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + int black; + gdPoint points[] = {{50, 5}, {24, 86}, {93, 36}, {7, 36}, {76, 86}}; + char *path; + + im = gdImageCreate(100, 100); + gdImageColorAllocate(im, 255, 255, 255); + black = gdImageColorAllocate(im, 0, 0, 0); + + gdImageFilledPolygon(im, points, 5, black); + + path = gdTestFilePath2("gdimagefilledpolygon", "self_intersecting_exp.png"); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gdimagefilledrectangle/bug00004.c b/tests/gdimagefilledrectangle/bug00004.c index 594e296..87e33dc 100644 --- a/tests/gdimagefilledrectangle/bug00004.c +++ b/tests/gdimagefilledrectangle/bug00004.c @@ -24,4 +24,3 @@ int main() return 1; } } - diff --git a/tests/gdimagefilledrectangle/bug00078.c b/tests/gdimagefilledrectangle/bug00078.c index adf244e..4cde698 100644 --- a/tests/gdimagefilledrectangle/bug00078.c +++ b/tests/gdimagefilledrectangle/bug00078.c @@ -36,4 +36,3 @@ int main() gdImageDestroy(im); return 0; } - diff --git a/tests/gdimagefilledrectangle/bug00106_gdimagefilledrectangle.c b/tests/gdimagefilledrectangle/bug00106_gdimagefilledrectangle.c index 24f5ceb..a6f5c06 100644 --- a/tests/gdimagefilledrectangle/bug00106_gdimagefilledrectangle.c +++ b/tests/gdimagefilledrectangle/bug00106_gdimagefilledrectangle.c @@ -24,4 +24,3 @@ int main() return 1; } } - diff --git a/tests/gdimagefilltoborder/Makemodule.am b/tests/gdimagefilltoborder/Makemodule.am index fc7ed3d..779bda0 100644 --- a/tests/gdimagefilltoborder/Makemodule.am +++ b/tests/gdimagefilltoborder/Makemodule.am @@ -1,8 +1,6 @@ -if HAVE_LIBPNG libgd_test_programs += \ gdimagefilltoborder/bug00037 \ gdimagefilltoborder/github_bug_215 -endif EXTRA_DIST += \ gdimagefilltoborder/CMakeLists.txt diff --git a/tests/gdimagefilltoborder/bug00037.c b/tests/gdimagefilltoborder/bug00037.c index ab7e1b8..72e58b7 100644 --- a/tests/gdimagefilltoborder/bug00037.c +++ b/tests/gdimagefilltoborder/bug00037.c @@ -27,4 +27,3 @@ int main() } } - diff --git a/tests/gdimagefilter/gdCopyBlurred.c b/tests/gdimagefilter/gdCopyBlurred.c index dee2f1f..aec49f5 100644 --- a/tests/gdimagefilter/gdCopyBlurred.c +++ b/tests/gdimagefilter/gdCopyBlurred.c @@ -143,7 +143,7 @@ void do_crosstest() { gdImagePtr im = mkcross(); gdImagePtr blurred; - const int RADIUS = 16; + const int RADIUS = 16; gdTestAssert(!!im); diff --git a/tests/gdimageflip/CMakeLists.txt b/tests/gdimageflip/CMakeLists.txt index 39caf08..c532f01 100644 --- a/tests/gdimageflip/CMakeLists.txt +++ b/tests/gdimageflip/CMakeLists.txt @@ -1,5 +1,7 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES gdimageflip ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimageflip/gdimageflip.c b/tests/gdimageflip/gdimageflip.c index a9dd187..da834ee 100644 --- a/tests/gdimageflip/gdimageflip.c +++ b/tests/gdimageflip/gdimageflip.c @@ -1,37 +1,34 @@ -/**
- * Testing the basic operation of the gdImageFlip*() functions
- */
-
-
-#include "gd.h"
-#include "gdtest.h"
-
-
-static void test_flip(void (*func)(gdImagePtr), const char *filename)
-{
- gdImagePtr im;
- FILE *fp;
- char *path;
-
- fp = gdTestFileOpen2("gdimageflip", "remi.png");
- im = gdImageCreateFromPng(fp);
- fclose(fp);
-
- func(im);
-
- path = gdTestFilePath2("gdimageflip", filename);
- gdAssertImageEqualsToFile(path, im);
- gdFree(path);
-
- gdImageDestroy(im);
-}
-
-
-int main()
-{
- test_flip(gdImageFlipVertical, "gdimageflipvertical_exp.png");
- test_flip(gdImageFlipHorizontal, "gdimagefliphorizontal_exp.png");
- test_flip(gdImageFlipBoth, "gdimageflipboth_exp.png");
-
- return gdNumFailures();
-}
+/** + * Testing the basic operation of the gdImageFlip*() functions + */ + +#include "gd.h" +#include "gdtest.h" + +static void test_flip(void (BGD_STDCALL *func)(gdImagePtr), const char *filename) +{ + gdImagePtr im; + FILE *fp; + char *path; + + fp = gdTestFileOpen2("gdimageflip", "remi.png"); + im = gdImageCreateFromPng(fp); + fclose(fp); + + func(im); + + path = gdTestFilePath2("gdimageflip", filename); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); +} + +int main() +{ + test_flip(gdImageFlipVertical, "gdimageflipvertical_exp.png"); + test_flip(gdImageFlipHorizontal, "gdimagefliphorizontal_exp.png"); + test_flip(gdImageFlipBoth, "gdimageflipboth_exp.png"); + + return gdNumFailures(); +} diff --git a/tests/gdimagegrayscale/.gitignore b/tests/gdimagegrayscale/.gitignore index 1ffd796..3e79ed7 100644 --- a/tests/gdimagegrayscale/.gitignore +++ b/tests/gdimagegrayscale/.gitignore @@ -1 +1,2 @@ /basic +/bug00386 diff --git a/tests/gdimagegrayscale/CMakeLists.txt b/tests/gdimagegrayscale/CMakeLists.txt index 381c74d..b83521d 100644 --- a/tests/gdimagegrayscale/CMakeLists.txt +++ b/tests/gdimagegrayscale/CMakeLists.txt @@ -1,5 +1,8 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES basic + bug00386 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagegrayscale/Makemodule.am b/tests/gdimagegrayscale/Makemodule.am index e715c5b..c6fec00 100644 --- a/tests/gdimagegrayscale/Makemodule.am +++ b/tests/gdimagegrayscale/Makemodule.am @@ -1,9 +1,11 @@ if HAVE_LIBPNG libgd_test_programs += \ - gdimagegrayscale/basic + gdimagegrayscale/basic \ + gdimagegrayscale/bug00386 endif EXTRA_DIST += \ gdimagegrayscale/CMakeLists.txt \ gdimagegrayscale/basic.png \ - gdimagegrayscale/basic_exp.png + gdimagegrayscale/basic_exp.png \ + gdimagegrayscale/bug00386.png diff --git a/tests/gdimagegrayscale/basic.c b/tests/gdimagegrayscale/basic.c index e3c21d8..3ecc482 100644 --- a/tests/gdimagegrayscale/basic.c +++ b/tests/gdimagegrayscale/basic.c @@ -1,29 +1,27 @@ -/**
- * Basic test for gdImageGrayScale()
- */
-
-
-#include "gd.h"
-#include "gdtest.h"
-
-
-int main()
-{
- gdImagePtr im;
- FILE *fp;
- char *path;
-
- fp = gdTestFileOpen2("gdimagegrayscale", "basic.png");
- im = gdImageCreateFromPng(fp);
- fclose(fp);
-
- gdImageGrayScale(im);
-
- path = gdTestFilePath2("gdimagegrayscale", "basic_exp.png");
- gdAssertImageEqualsToFile(path, im);
- gdFree(path);
-
- gdImageDestroy(im);
-
- return gdNumFailures();
-}
+/** + * Basic test for gdImageGrayScale() + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + char *path; + + fp = gdTestFileOpen2("gdimagegrayscale", "basic.png"); + im = gdImageCreateFromPng(fp); + fclose(fp); + + gdImageGrayScale(im); + + path = gdTestFilePath2("gdimagegrayscale", "basic_exp.png"); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gdimagegrayscale/bug00386.c b/tests/gdimagegrayscale/bug00386.c new file mode 100644 index 0000000..2e68ed4 --- /dev/null +++ b/tests/gdimagegrayscale/bug00386.c @@ -0,0 +1,53 @@ +/** + * Test that gdImageGrayScale() produces pure gray-scale images + * + * We are reading a PNG image with transparency, apply gdImageGrayScale() and + * test that each pixel has equal red, blue and green components. To avoid + * flooding the test log, we bail out after the first non gray-scale pixel. + * + * We also make sure that the image is a truecolor image, since otherwise it is + * not guaranteed that all pixels are actually gray-scale. + * + * See also <https://github.com/libgd/libgd/issues/386>. + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im; + FILE *fp; + int res; + int i, j; + + fp = gdTestFileOpen2("gdimagegrayscale", "bug00386.png"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromPng(fp); + gdTestAssert(im != NULL); + fclose(fp); + + res = gdImageTrueColor(im); + gdTestAssert(res != 0); + + res = gdImageGrayScale(im); + gdTestAssert(res != 0); + + for (i = 0; i < gdImageSX(im); i++) { + for (j = 0; j < gdImageSY(im); j++) { + int color = gdImageGetTrueColorPixel(im, i, j); + int red = gdImageRed(im, color); + int green = gdImageGreen(im, color); + int blue = gdImageBlue(im, color); + if (!gdTestAssert(red == green && green == blue)) { + return gdNumFailures(); + } + } + } + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gdimagegrayscale/bug00386.png b/tests/gdimagegrayscale/bug00386.png Binary files differnew file mode 100644 index 0000000..b5d5d1f --- /dev/null +++ b/tests/gdimagegrayscale/bug00386.png diff --git a/tests/gdimageline/CMakeLists.txt b/tests/gdimageline/CMakeLists.txt index 8e1b524..c345ed1 100644 --- a/tests/gdimageline/CMakeLists.txt +++ b/tests/gdimageline/CMakeLists.txt @@ -1,12 +1,18 @@ LIST(APPEND TESTS_FILES - gdimageline_aa gdimageline_aa_outofrange - gdImageAALine_thickness - github_bug_167 +) + +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES bug00077 bug00072 bug00111 bug00315 + gdimageline_aa + gdimageline_bug5 + gdImageAALine_thickness + github_bug_167 ) +ENDIF(PNG_FOUND) -ADD_GD_TESTS(m) +ADD_GD_TESTS() diff --git a/tests/gdimageline/bug00315.c b/tests/gdimageline/bug00315.c index 7c94e41..719d155 100644 --- a/tests/gdimageline/bug00315.c +++ b/tests/gdimageline/bug00315.c @@ -1,39 +1,37 @@ -/**
- * Regression test for <https://github.com/libgd/libgd/issues/315>
- *
- * We're testing that a single-pointed gdImageAALine() is drawn as a single
- * non-antialized pixel, according to (two-pointed) vertical and horizontal
- * lines.
- */
-
-
-#include "gd.h"
-#include "gdtest.h"
-
-
-int main()
-{
- gdImagePtr im;
- int white, black;
- char *path;
-
- im = gdImageCreateTrueColor(6, 6);
- white = gdImageColorAllocate(im, 255, 255, 255);
- black = gdImageColorAllocate(im, 0, 0, 0);
- gdImageFilledRectangle(im, 0,0, 5,5, white);
-
- gdImageLine(im, 4,4, 4,4, black);
- gdImageLine(im, 1,4, 2,4, black);
- gdImageLine(im, 4,1, 4,2, black);
-
- gdImageSetAntiAliased(im, black);
- gdImageLine(im, 1,1, 1,1, gdAntiAliased);
-
- path = gdTestFilePath2("gdimageline", "bug00315_exp.png");
- gdAssertImageEqualsToFile(path, im);
- gdFree(path);
-
- gdImageDestroy(im);
-
- return gdNumFailures();
-}
+/** + * Regression test for <https://github.com/libgd/libgd/issues/315> + * + * We're testing that a single-pointed gdImageAALine() is drawn as a single + * non-antialized pixel, according to (two-pointed) vertical and horizontal + * lines. + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + int white, black; + char *path; + + im = gdImageCreateTrueColor(6, 6); + white = gdImageColorAllocate(im, 255, 255, 255); + black = gdImageColorAllocate(im, 0, 0, 0); + gdImageFilledRectangle(im, 0,0, 5,5, white); + + gdImageLine(im, 4,4, 4,4, black); + gdImageLine(im, 1,4, 2,4, black); + gdImageLine(im, 4,1, 4,2, black); + + gdImageSetAntiAliased(im, black); + gdImageLine(im, 1,1, 1,1, gdAntiAliased); + + path = gdTestFilePath2("gdimageline", "bug00315_exp.png"); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gdimageline/gdimageline_bug5.c b/tests/gdimageline/gdimageline_bug5.c index 44adc8e..d055b0c 100644 --- a/tests/gdimageline/gdimageline_bug5.c +++ b/tests/gdimageline/gdimageline_bug5.c @@ -10,7 +10,13 @@ int main() { /* FILE *pngout; */ int black, white; + /* If the data seg size is less than 195000, + * gdImageCrateTrueColor will return NULL. + * See https://github.com/libgd/libgd/issues/621 */ im = gdImageCreateTrueColor(63318, 771); + if (gdTestAssertMsg(im != NULL, "gdImageCreateTrueColor() returns NULL\n") == 0) { + return gdNumFailures(); + } /* Allocate the color white (red, green and blue all maximum). */ white = gdImageColorAllocate(im, 255, 255, 255); diff --git a/tests/gdimagenegate/CMakeLists.txt b/tests/gdimagenegate/CMakeLists.txt index 381c74d..802c382 100644 --- a/tests/gdimagenegate/CMakeLists.txt +++ b/tests/gdimagenegate/CMakeLists.txt @@ -1,5 +1,7 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES basic ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagenegate/basic.c b/tests/gdimagenegate/basic.c index b904eb8..563eec6 100644 --- a/tests/gdimagenegate/basic.c +++ b/tests/gdimagenegate/basic.c @@ -1,29 +1,27 @@ -/**
- * Basic test for gdImageNegate()
- */
-
-
-#include "gd.h"
-#include "gdtest.h"
-
-
-int main()
-{
- gdImagePtr im;
- FILE *fp;
- char *path;
-
- fp = gdTestFileOpen2("gdimagenegate", "basic.png");
- im = gdImageCreateFromPng(fp);
- fclose(fp);
-
- gdImageNegate(im);
-
- path = gdTestFilePath2("gdimagenegate", "basic_exp.png");
- gdAssertImageEqualsToFile(path, im);
- gdFree(path);
-
- gdImageDestroy(im);
-
- return gdNumFailures();
-}
+/** + * Basic test for gdImageNegate() + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + char *path; + + fp = gdTestFileOpen2("gdimagenegate", "basic.png"); + im = gdImageCreateFromPng(fp); + fclose(fp); + + gdImageNegate(im); + + path = gdTestFilePath2("gdimagenegate", "basic_exp.png"); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gdimageopenpolygon/CMakeLists.txt b/tests/gdimageopenpolygon/CMakeLists.txt index 03c288d..5b3e069 100644 --- a/tests/gdimageopenpolygon/CMakeLists.txt +++ b/tests/gdimageopenpolygon/CMakeLists.txt @@ -1,8 +1,10 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES gdimageopenpolygon0 gdimageopenpolygon1 gdimageopenpolygon2 gdimageopenpolygon3 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagepolygon/CMakeLists.txt b/tests/gdimagepolygon/CMakeLists.txt index 1b4ee83..647636a 100644 --- a/tests/gdimagepolygon/CMakeLists.txt +++ b/tests/gdimagepolygon/CMakeLists.txt @@ -1,8 +1,10 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES gdimagepolygon0 gdimagepolygon1 gdimagepolygon2 gdimagepolygon3 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagerectangle/CMakeLists.txt b/tests/gdimagerectangle/CMakeLists.txt index 2567ae3..e2a2b81 100644 --- a/tests/gdimagerectangle/CMakeLists.txt +++ b/tests/gdimagerectangle/CMakeLists.txt @@ -1,9 +1,14 @@ LIST(APPEND TESTS_FILES bug00003 bug00106_gdimagerectangle - bug00299 github_bug_00172 point_ordering ) +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + bug00299 +) +ENDIF(PNG_FOUND) + ADD_GD_TESTS() diff --git a/tests/gdimagerectangle/Makemodule.am b/tests/gdimagerectangle/Makemodule.am index ea9d52b..cd49b73 100644 --- a/tests/gdimagerectangle/Makemodule.am +++ b/tests/gdimagerectangle/Makemodule.am @@ -1,10 +1,14 @@ libgd_test_programs += \ gdimagerectangle/bug00003 \ gdimagerectangle/bug00106_gdimagerectangle \ - gdimagerectangle/bug00299 \ gdimagerectangle/github_bug_00172 \ gdimagerectangle/point_ordering +if HAVE_LIBPNG +libgd_test_programs += \ + gdimagerectangle/bug00299 +endif + EXTRA_DIST += \ gdimagerectangle/CMakeLists.txt \ gdimagerectangle/bug00299_exp.png diff --git a/tests/gdimagerotate/CMakeLists.txt b/tests/gdimagerotate/CMakeLists.txt index e5ea84a..7b8ab14 100644 --- a/tests/gdimagerotate/CMakeLists.txt +++ b/tests/gdimagerotate/CMakeLists.txt @@ -1,7 +1,9 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES bug00067 php_bug_64898 php_bug_65070 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagerotate/Makemodule.am b/tests/gdimagerotate/Makemodule.am index 99b2398..116c851 100644 --- a/tests/gdimagerotate/Makemodule.am +++ b/tests/gdimagerotate/Makemodule.am @@ -1,10 +1,6 @@ -if HAVE_LIBJPEG -libgd_test_programs += \ - gdimagerotate/bug00067 -endif - if HAVE_LIBPNG libgd_test_programs += \ + gdimagerotate/bug00067 \ gdimagerotate/php_bug_64898 \ gdimagerotate/php_bug_65070 endif diff --git a/tests/gdimagerotate/php_bug_65070.c b/tests/gdimagerotate/php_bug_65070.c index f1b5504..87a43ea 100644 --- a/tests/gdimagerotate/php_bug_65070.c +++ b/tests/gdimagerotate/php_bug_65070.c @@ -1,35 +1,33 @@ -/**
- * Regression test for <https://github.com/libgd/libgd/issues/319>
- *
- * We're testing that the rotated image actually has the requested background
- * color.
- */
-
-
-#include "gd.h"
-#include "gdtest.h"
-
-
-int main()
-{
- gdImagePtr src, dst;
- FILE *fp;
- int black;
- char *path;
-
- fp = gdTestFileOpen2("gdimagerotate", "php_bug_65070.gif");
- src = gdImageCreateFromGif(fp);
- fclose(fp);
-
- black = gdImageColorAllocateAlpha(src, 0, 0, 0, 0);
- dst = gdImageRotateInterpolated(src, 30.0, black);
-
- path = gdTestFilePath2("gdimagerotate", "php_bug_65070_exp.png");
- gdAssertImageEqualsToFile(path, dst);
- gdFree(path);
-
- gdImageDestroy(src);
- gdImageDestroy(dst);
-
- return gdNumFailures();
-}
+/** + * Regression test for <https://github.com/libgd/libgd/issues/319> + * + * We're testing that the rotated image actually has the requested background + * color. + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr src, dst; + FILE *fp; + int black; + char *path; + + fp = gdTestFileOpen2("gdimagerotate", "php_bug_65070.gif"); + src = gdImageCreateFromGif(fp); + fclose(fp); + + black = gdImageColorAllocateAlpha(src, 0, 0, 0, 0); + dst = gdImageRotateInterpolated(src, 30.0, black); + + path = gdTestFilePath2("gdimagerotate", "php_bug_65070_exp.png"); + gdAssertImageEqualsToFile(path, dst); + gdFree(path); + + gdImageDestroy(src); + gdImageDestroy(dst); + + return gdNumFailures(); +} diff --git a/tests/gdimagerotate/php_bug_65070_exp.png b/tests/gdimagerotate/php_bug_65070_exp.png Binary files differindex fba85f6..64b8b10 100644 --- a/tests/gdimagerotate/php_bug_65070_exp.png +++ b/tests/gdimagerotate/php_bug_65070_exp.png diff --git a/tests/gdimagescale/.gitignore b/tests/gdimagescale/.gitignore index cfa5549..e75e0bc 100644 --- a/tests/gdimagescale/.gitignore +++ b/tests/gdimagescale/.gitignore @@ -1,2 +1,4 @@ +/bug00329 +/bug00330 /github_bug_00218 /bug_overflow_large_new_size diff --git a/tests/gdimagescale/CMakeLists.txt b/tests/gdimagescale/CMakeLists.txt index f5ebf2e..1174e65 100644 --- a/tests/gdimagescale/CMakeLists.txt +++ b/tests/gdimagescale/CMakeLists.txt @@ -1,4 +1,6 @@ LIST(APPEND TESTS_FILES + bug00329 + bug00330 github_bug_00218 bug_overflow_large_new_size ) diff --git a/tests/gdimagescale/Makemodule.am b/tests/gdimagescale/Makemodule.am index 23b8924..432ddbe 100644 --- a/tests/gdimagescale/Makemodule.am +++ b/tests/gdimagescale/Makemodule.am @@ -1,5 +1,6 @@ - libgd_test_programs += \ + gdimagescale/bug00329 \ + gdimagescale/bug00330 \ gdimagescale/github_bug_00218 \ gdimagescale/bug_overflow_large_new_size diff --git a/tests/gdimagescale/bug00329.c b/tests/gdimagescale/bug00329.c new file mode 100644 index 0000000..67a1561 --- /dev/null +++ b/tests/gdimagescale/bug00329.c @@ -0,0 +1,50 @@ +/** + * Regression test for <https://github.com/libgd/libgd/issues/329> + * + * We're testing that for truecolor as well as palette images after + * GD_BILINEAR_FIXED scaling the corner pixels of the scaled image have the + * expected color. + */ + +#include <string.h> +#include "gd.h" +#include "gdtest.h" + +static void test(const char *mode) +{ + gdImagePtr src, dst; + int expected, actual; + + if (strcmp(mode, "palette")) { + src = gdImageCreateTrueColor(100, 100); + expected = gdTrueColorAlpha(255, 255, 255, gdAlphaOpaque); + gdImageFilledRectangle(src, 0,0, 99,99, expected); + } else { + src = gdImageCreate(100, 100); + gdImageColorAllocate(src, 255, 255, 255); + expected = gdImageGetTrueColorPixel(src, 49, 49); + } + + gdImageSetInterpolationMethod(src, GD_BILINEAR_FIXED); + dst = gdImageScale(src, 200, 200); + + actual = gdImageGetPixel(dst, 0, 0); + gdTestAssertMsg(actual == expected, "%s: wrong color; expected %x, but got %x", mode, expected, actual); + actual = gdImageGetPixel(dst, 0, 199); + gdTestAssertMsg(actual == expected, "%s: wrong color; expected %x, but got %x", mode, expected, actual); + actual = gdImageGetPixel(dst, 199, 199); + gdTestAssertMsg(actual == expected, "%s: wrong color; expected %x, but got %x", mode, expected, actual); + actual = gdImageGetPixel(dst, 199, 0); + gdTestAssertMsg(actual == expected, "%s: wrong color; expected %x, but got %x", mode, expected, actual); + + gdImageDestroy(src); + gdImageDestroy(dst); +} + +int main() +{ + test("palette"); + test("truecolor"); + + return gdNumFailures(); +} diff --git a/tests/gdimagescale/bug00330.c b/tests/gdimagescale/bug00330.c new file mode 100644 index 0000000..44ba2f4 --- /dev/null +++ b/tests/gdimagescale/bug00330.c @@ -0,0 +1,30 @@ +/** + * Regression test for <https://github.com/libgd/libgd/issues/330>. + * + * We're testing that after scaling a palette image, the center pixel actually + * has the expected color value. + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr src, dst; + int color; + + src = gdImageCreate(100, 100); + gdImageColorAllocate(src, 255, 255, 255); + + gdImageSetInterpolationMethod(src, GD_BILINEAR_FIXED); + dst = gdImageScale(src, 200, 200); + + color = gdImageGetPixel(dst, 99, 99); + gdTestAssertMsg(color == 0xffffff, + "expected color ffffff, but got %x\n", color); + + gdImageDestroy(src); + gdImageDestroy(dst); + + return 0; +} diff --git a/tests/gdimagescale/bug_overflow_large_new_size.c b/tests/gdimagescale/bug_overflow_large_new_size.c index 0a8503b..20cda1d 100644 --- a/tests/gdimagescale/bug_overflow_large_new_size.c +++ b/tests/gdimagescale/bug_overflow_large_new_size.c @@ -15,13 +15,14 @@ int main() return 1; } gdImageSetInterpolationMethod(im, GD_BELL); - + /* here the call may pass if the system has enough memory (physical or swap) or fails (overflow check or alloc fails. in both cases the tests pass */ im2 = gdImageScale(im,0x15555556, 1); if (im2 == NULL) { printf("gdImageScale failed, expected (out of memory or overflow validation\n"); + gdImageDestroy(im); return 0; } gdImageDestroy(im); diff --git a/tests/gdimagescatterex/CMakeLists.txt b/tests/gdimagescatterex/CMakeLists.txt index 22c46a7..479afe5 100644 --- a/tests/gdimagescatterex/CMakeLists.txt +++ b/tests/gdimagescatterex/CMakeLists.txt @@ -1,6 +1,8 @@ +IF(PNG_FOUND) LIST(APPEND TESTS_FILES bug00208_1 bug00208_2 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdimagesetinterpolationmethod/.gitignore b/tests/gdimagesetinterpolationmethod/.gitignore new file mode 100644 index 0000000..db7b3af --- /dev/null +++ b/tests/gdimagesetinterpolationmethod/.gitignore @@ -0,0 +1 @@ +/github_bug_00584 diff --git a/tests/gdimagesetinterpolationmethod/CMakeLists.txt b/tests/gdimagesetinterpolationmethod/CMakeLists.txt new file mode 100644 index 0000000..6551062 --- /dev/null +++ b/tests/gdimagesetinterpolationmethod/CMakeLists.txt @@ -0,0 +1,5 @@ +LIST(APPEND TESTS_FILES + github_bug_00584 +) + +ADD_GD_TESTS() diff --git a/tests/gdimagesetinterpolationmethod/Makemodule.am b/tests/gdimagesetinterpolationmethod/Makemodule.am new file mode 100644 index 0000000..1b83336 --- /dev/null +++ b/tests/gdimagesetinterpolationmethod/Makemodule.am @@ -0,0 +1,5 @@ +libgd_test_programs += \ + gdimagesetinterpolationmethod/github_bug_00584 + +EXTRA_DIST += \ + gdimagesetinterpolationmethod/CMakeLists.txt diff --git a/tests/gdimagesetinterpolationmethod/github_bug_00584.c b/tests/gdimagesetinterpolationmethod/github_bug_00584.c new file mode 100644 index 0000000..e11f9f0 --- /dev/null +++ b/tests/gdimagesetinterpolationmethod/github_bug_00584.c @@ -0,0 +1,31 @@ +/** + * Test that gdImageSetInterpolationMethod(im, GD_DEFAULT) is consistent + * + * See <https://github.com/libgd/libgd/issues/584> + */ + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im; + gdInterpolationMethod old_m, new_m; + interpolation_method old_f, new_f; + + im = gdImageCreateTrueColor(8, 8); + gdTestAssert(im != NULL); + gdTestAssert(gdImageSetInterpolationMethod(im, GD_SINC)); + old_m = gdImageGetInterpolationMethod(im); + gdTestAssert(old_m == GD_SINC); + old_f = im->interpolation; + gdTestAssert(gdImageSetInterpolationMethod(im, GD_DEFAULT)); + new_m = gdImageGetInterpolationMethod(im); + gdTestAssert(new_m == GD_LINEAR); + new_f = im->interpolation; + gdTestAssert(new_m != old_m); + gdTestAssert(new_f != old_f); + gdImageDestroy(im); + return gdNumFailures(); +} diff --git a/tests/gdimagesetpixel/CMakeLists.txt b/tests/gdimagesetpixel/CMakeLists.txt index f363899..675bbfd 100644 --- a/tests/gdimagesetpixel/CMakeLists.txt +++ b/tests/gdimagesetpixel/CMakeLists.txt @@ -1,8 +1,13 @@ LIST(APPEND TESTS_FILES - alpha_blending bug00186 gdeffectoverlay gdeffectmultiply ) +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + alpha_blending +) +ENDIF(PNG_FOUND) + ADD_GD_TESTS() diff --git a/tests/gdimagesetpixel/Makemodule.am b/tests/gdimagesetpixel/Makemodule.am index 0a574ad..1eb0224 100644 --- a/tests/gdimagesetpixel/Makemodule.am +++ b/tests/gdimagesetpixel/Makemodule.am @@ -1,9 +1,13 @@ libgd_test_programs += \ - gdimagesetpixel/alpha_blending \ gdimagesetpixel/bug00186 \ gdimagesetpixel/gdeffectmultiply \ gdimagesetpixel/gdeffectoverlay +if HAVE_LIBPNG +libgd_test_programs += \ + gdimagesetpixel/alpha_blending +endif + EXTRA_DIST += \ gdimagesetpixel/CMakeLists.txt \ gdimagesetpixel/alphablending_exp.png diff --git a/tests/gdimagesetpixel/alpha_blending.c b/tests/gdimagesetpixel/alpha_blending.c index 394ced5..f182d59 100644 --- a/tests/gdimagesetpixel/alpha_blending.c +++ b/tests/gdimagesetpixel/alpha_blending.c @@ -1,54 +1,52 @@ -/**
- * Testing all effects
- */
-
-
-#include "gd.h"
-#include "gdtest.h"
-
-
-int main()
-{
- gdImagePtr im;
- int effects[] = {
- gdEffectReplace, gdEffectAlphaBlend, gdEffectNormal,
- gdEffectOverlay, gdEffectMultiply
- };
- int red[3], blue[3];
- int x, y, i, j;
- char *path;
-
- red[0] = gdTrueColorAlpha(0, 0, 255, 127);
- red[1] = gdTrueColorAlpha(0, 0, 255, 63);
- red[2] = gdTrueColorAlpha(0, 0, 255, 0);
- blue[0] = gdTrueColorAlpha(255, 0, 0, 127);
- blue[1] = gdTrueColorAlpha(255, 0, 0, 63);
- blue[2] = gdTrueColorAlpha(255, 0, 0, 0);
-
- im = gdImageCreateTrueColor(120, 180);
-
- gdImageAlphaBlending(im, gdEffectReplace);
- for (j = 0; j < 3; j++) {
- y = 60 * j;
- gdImageFilledRectangle(im, 0,y, 119,y+59, red[j]);
- }
-
- for (i = 0; i < 5; i++) {
- x = 20 * i;
- gdImageAlphaBlending(im, effects[i]);
- for (j = 0; j < 9; j++) {
- y = 20 * j;
- gdImageFilledRectangle(im, x+20,y, x+39,y+19, blue[j % 3]);
- }
- }
-
- gdImageSaveAlpha(im, 1);
-
- path = gdTestFilePath2("gdimagesetpixel", "alphablending_exp.png");
- gdAssertImageEqualsToFile(path, im);
- gdFree(path);
-
- gdImageDestroy(im);
-
- return gdNumFailures();
-}
+/** + * Testing all effects + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + int effects[] = { + gdEffectReplace, gdEffectAlphaBlend, gdEffectNormal, + gdEffectOverlay, gdEffectMultiply + }; + int red[3], blue[3]; + int x, y, i, j; + char *path; + + red[0] = gdTrueColorAlpha(0, 0, 255, 127); + red[1] = gdTrueColorAlpha(0, 0, 255, 63); + red[2] = gdTrueColorAlpha(0, 0, 255, 0); + blue[0] = gdTrueColorAlpha(255, 0, 0, 127); + blue[1] = gdTrueColorAlpha(255, 0, 0, 63); + blue[2] = gdTrueColorAlpha(255, 0, 0, 0); + + im = gdImageCreateTrueColor(120, 180); + + gdImageAlphaBlending(im, gdEffectReplace); + for (j = 0; j < 3; j++) { + y = 60 * j; + gdImageFilledRectangle(im, 0,y, 119,y+59, red[j]); + } + + for (i = 0; i < 5; i++) { + x = 20 * i; + gdImageAlphaBlending(im, effects[i]); + for (j = 0; j < 9; j++) { + y = 20 * j; + gdImageFilledRectangle(im, x+20,y, x+39,y+19, blue[j % 3]); + } + } + + gdImageSaveAlpha(im, 1); + + path = gdTestFilePath2("gdimagesetpixel", "alphablending_exp.png"); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gdimagesquaretocircle/.gitignore b/tests/gdimagesquaretocircle/.gitignore new file mode 100644 index 0000000..bf6e191 --- /dev/null +++ b/tests/gdimagesquaretocircle/.gitignore @@ -0,0 +1 @@ +/gdimagesquaretocircle diff --git a/tests/gdimagesquaretocircle/CMakeLists.txt b/tests/gdimagesquaretocircle/CMakeLists.txt new file mode 100644 index 0000000..a8c9430 --- /dev/null +++ b/tests/gdimagesquaretocircle/CMakeLists.txt @@ -0,0 +1,7 @@ +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + gdimagesquaretocircle +) +ENDIF(PNG_FOUND) + +ADD_GD_TESTS() diff --git a/tests/gdimagesquaretocircle/Makemodule.am b/tests/gdimagesquaretocircle/Makemodule.am new file mode 100644 index 0000000..77b7a30 --- /dev/null +++ b/tests/gdimagesquaretocircle/Makemodule.am @@ -0,0 +1,8 @@ +if HAVE_LIBPNG +libgd_test_programs += \ + gdimagesquaretocircle/gdimagesquaretocircle +endif + +EXTRA_DIST += \ + gdimagesquaretocircle/CMakeLists.txt \ + gdimagesquaretocircle/gdimagesquaretocircle_exp.png diff --git a/tests/gdimagesquaretocircle/gdimagesquaretocircle.c b/tests/gdimagesquaretocircle/gdimagesquaretocircle.c new file mode 100644 index 0000000..f8fba91 --- /dev/null +++ b/tests/gdimagesquaretocircle/gdimagesquaretocircle.c @@ -0,0 +1,32 @@ +/** + * Basic test for gdImageSquareToCircle() + */ +#include "gd.h" +#include "gdfx.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im1, im2; + int white; + int black; + + im1 = gdImageCreateTrueColor(128, 128); + white = gdImageColorAllocate(im1, 255, 255, 255); + black = gdImageColorAllocate(im1, 0, 0, 0); + gdImageFilledRectangle(im1, 0, 0, 127, 127, white); + + /* Draw a cross line in the middle of im1 */ + /* The horizonal line will become a circle in im2 */ + /* The vertical line will become a horizonal with half len in im2 */ + gdImageLine(im1, 0, 63, 127, 63, black); + gdImageLine(im1, 63, 0, 63, 127, black); + im2 = gdImageSquareToCircle(im1, 64); + + gdAssertImageEqualsToFile("gdimagesquaretocircle/gdimagesquaretocircle_exp.png", im2); + + gdImageDestroy(im1); + gdImageDestroy(im2); + + return gdNumFailures(); +} diff --git a/tests/gdimagesquaretocircle/gdimagesquaretocircle_exp.png b/tests/gdimagesquaretocircle/gdimagesquaretocircle_exp.png Binary files differnew file mode 100644 index 0000000..222bb13 --- /dev/null +++ b/tests/gdimagesquaretocircle/gdimagesquaretocircle_exp.png diff --git a/tests/gdimagestring/.gitignore b/tests/gdimagestring/.gitignore new file mode 100644 index 0000000..ecd076c --- /dev/null +++ b/tests/gdimagestring/.gitignore @@ -0,0 +1 @@ +/gdimagestring diff --git a/tests/gdimagestring/CMakeLists.txt b/tests/gdimagestring/CMakeLists.txt new file mode 100644 index 0000000..3cabaec --- /dev/null +++ b/tests/gdimagestring/CMakeLists.txt @@ -0,0 +1,7 @@ +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + gdimagestring +) +ENDIF(PNG_FOUND) + +ADD_GD_TESTS() diff --git a/tests/gdimagestring/Makemodule.am b/tests/gdimagestring/Makemodule.am new file mode 100644 index 0000000..84ca656 --- /dev/null +++ b/tests/gdimagestring/Makemodule.am @@ -0,0 +1,8 @@ +if HAVE_LIBPNG +libgd_test_programs += \ + gdimagestring/gdimagestring +endif + +EXTRA_DIST += \ + gdimagestring/CMakeLists.txt \ + gdimagestring/gdimagestring_exp.png diff --git a/tests/gdimagestring/gdimagestring.c b/tests/gdimagestring/gdimagestring.c new file mode 100644 index 0000000..c4b4aa1 --- /dev/null +++ b/tests/gdimagestring/gdimagestring.c @@ -0,0 +1,34 @@ +/** + * Base test for gdImageString() + */ +#include <gd.h> +#include <gdfontl.h> +#include "gdtest.h" +#include <string.h> + +int main() +{ + /* Declare the image */ + gdImagePtr im = NULL; + char *s = "Hello gd"; + int foreground = 0; + int error = 0; + gdFontPtr fontptr = gdFontGetLarge(); + + im = gdImageCreate(100, 50); + gdImageColorAllocate(im, 202, 202, 0); + foreground = gdImageColorAllocate(im, 22, 4, 238); + + gdImageString(im, fontptr, + im->sx / 2 - (strlen(s) * fontptr->w / 2), + im->sy / 2 - fontptr->h / 2, + (unsigned char*)s, foreground); + + if (!gdAssertImageEqualsToFile("gdimagestring/gdimagestring_exp.png", im)) + error= 1; + + /* Destroy the image in memory. */ + gdImageDestroy(im); + + return error; +} diff --git a/tests/gdimagestring/gdimagestring_exp.png b/tests/gdimagestring/gdimagestring_exp.png Binary files differnew file mode 100644 index 0000000..2435626 --- /dev/null +++ b/tests/gdimagestring/gdimagestring_exp.png diff --git a/tests/gdimagestring16/.gitignore b/tests/gdimagestring16/.gitignore new file mode 100644 index 0000000..5ebaa0b --- /dev/null +++ b/tests/gdimagestring16/.gitignore @@ -0,0 +1 @@ +/gdimagestring16 diff --git a/tests/gdimagestring16/CMakeLists.txt b/tests/gdimagestring16/CMakeLists.txt new file mode 100644 index 0000000..e85db9b --- /dev/null +++ b/tests/gdimagestring16/CMakeLists.txt @@ -0,0 +1,7 @@ +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + gdimagestring16 +) +ENDIF(PNG_FOUND) + +ADD_GD_TESTS() diff --git a/tests/gdimagestring16/Makemodule.am b/tests/gdimagestring16/Makemodule.am new file mode 100644 index 0000000..84b6b5f --- /dev/null +++ b/tests/gdimagestring16/Makemodule.am @@ -0,0 +1,8 @@ +if HAVE_LIBPNG +libgd_test_programs += \ + gdimagestring16/gdimagestring16 +endif + +EXTRA_DIST += \ + gdimagestring16/CMakeLists.txt \ + gdimagestring16/gdimagestring16_exp.png diff --git a/tests/gdimagestring16/gdimagestring16.c b/tests/gdimagestring16/gdimagestring16.c new file mode 100644 index 0000000..0ca0668 --- /dev/null +++ b/tests/gdimagestring16/gdimagestring16.c @@ -0,0 +1,30 @@ +/** + * Base test for gdImageString16() + */ +#include <gd.h> +#include <gdfontl.h> +#include "gdtest.h" + +int main() +{ + /* Declare the image */ + gdImagePtr im = NULL; + unsigned short s[2] = {'H', 0}; + int foreground; + int errorcode = 0; + gdFontPtr fontptr = gdFontGetLarge(); + + im = gdImageCreate(20, 20); + gdImageColorAllocate(im, 255, 255, 255); + foreground = gdImageColorAllocate(im, 22, 4, 238); + + gdImageString16(im, fontptr, 2, 2, s, foreground); + + if (!gdAssertImageEqualsToFile("gdimagestring16/gdimagestring16_exp.png", im)) + errorcode = 1; + + /* Destroy the image in memory */ + gdImageDestroy(im); + + return errorcode; +} diff --git a/tests/gdimagestring16/gdimagestring16_exp.png b/tests/gdimagestring16/gdimagestring16_exp.png Binary files differnew file mode 100644 index 0000000..5700578 --- /dev/null +++ b/tests/gdimagestring16/gdimagestring16_exp.png diff --git a/tests/gdimagestringft/.gitignore b/tests/gdimagestringft/.gitignore index f9f01f0..efe5e61 100644 --- a/tests/gdimagestringft/.gitignore +++ b/tests/gdimagestringft/.gitignore @@ -1 +1,2 @@ +/bug00615 /gdimagestringft_bbox diff --git a/tests/gdimagestringft/CMakeLists.txt b/tests/gdimagestringft/CMakeLists.txt index f46b900..42868a2 100644 --- a/tests/gdimagestringft/CMakeLists.txt +++ b/tests/gdimagestringft/CMakeLists.txt @@ -1,5 +1,6 @@ IF(FREETYPE_FOUND) LIST(APPEND TESTS_FILES + bug00615 gdimagestringft_bbox ) ENDIF(FREETYPE_FOUND) diff --git a/tests/gdimagestringft/Makemodule.am b/tests/gdimagestringft/Makemodule.am index 0dfe26f..a62081f 100644 --- a/tests/gdimagestringft/Makemodule.am +++ b/tests/gdimagestringft/Makemodule.am @@ -1,5 +1,6 @@ if HAVE_LIBFREETYPE libgd_test_programs += \ + gdimagestringft/bug00615 \ gdimagestringft/gdimagestringft_bbox endif diff --git a/tests/gdimagestringft/bug00615.c b/tests/gdimagestringft/bug00615.c new file mode 100644 index 0000000..0da51da --- /dev/null +++ b/tests/gdimagestringft/bug00615.c @@ -0,0 +1,25 @@ +/** + * Test that rendering an empty string does not fail + * + * Rendering an empty string with gdImageStringFT() is not supposed to fail; + * it is just a no-op. + * + * See <https://github.com/libgd/libgd/issues/615> + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im = gdImageCreate(100, 100); + + int rect[8]; + int fg = gdImageColorAllocate(im, 255, 255, 255); + char *path = gdTestFilePath("freetype/DejaVuSans.ttf"); + char *res = gdImageStringFT(im, rect, fg, path, 12, 0, 10, 10, ""); + + gdTestAssert(res == NULL); + + return gdNumFailures(); +} diff --git a/tests/gdimagestringft/gdimagestringft_bbox.c b/tests/gdimagestringft/gdimagestringft_bbox.c index 0161ec8..e75248a 100644 --- a/tests/gdimagestringft/gdimagestringft_bbox.c +++ b/tests/gdimagestringft/gdimagestringft_bbox.c @@ -8,22 +8,22 @@ #define DELTA (PI/8) static int EXPECT[16][8] = { - {498, 401, 630, 401, 630, 374, 498, 374}, - {491, 364, 613, 313, 602, 288, 481, 338}, - {470, 332, 563, 239, 544, 219, 451, 312}, - {438, 310, 488, 189, 463, 178, 412, 300}, - {401, 303, 401, 171, 374, 171, 374, 303}, - {365, 310, 314, 188, 289, 199, 339, 320}, - {334, 331, 241, 238, 221, 257, 314, 350}, - {313, 362, 192, 312, 181, 337, 303, 388}, - {306, 398, 174, 398, 174, 425, 306, 425}, - {313, 433, 191, 484, 202, 509, 323, 459}, - {333, 463, 240, 556, 259, 576, 352, 483}, - {363, 484, 313, 605, 338, 616, 389, 494}, - {398, 490, 398, 622, 425, 622, 425, 490}, - {432, 483, 483, 605, 508, 594, 458, 473}, - {461, 464, 554, 557, 574, 538, 481, 445}, - {481, 435, 602, 485, 613, 460, 491, 409}, + {500, 400, 628, 400, 628, 376, 500, 376}, + {492, 362, 611, 312, 601, 290, 483, 339}, + {470, 330, 561, 239, 544, 221, 453, 312}, + {437, 308, 486, 189, 464, 180, 414, 299}, + {400, 301, 400, 173, 376, 173, 376, 301}, + {363, 309, 313, 190, 291, 200, 340, 318}, + {332, 331, 241, 240, 223, 257, 314, 348}, + {311, 363, 192, 314, 183, 336, 302, 386}, + {304, 399, 176, 399, 176, 423, 304, 423}, + {312, 435, 193, 485, 203, 507, 321, 458}, + {333, 465, 242, 556, 259, 574, 350, 483}, + {364, 486, 315, 605, 337, 614, 387, 495}, + {399, 492, 399, 620, 423, 620, 423, 492}, + {434, 484, 484, 603, 506, 593, 457, 475}, + {463, 464, 554, 555, 572, 538, 481, 447}, + {483, 434, 602, 483, 611, 461, 492, 411}, }; int main() @@ -38,6 +38,9 @@ int main() int error = 0; FILE *fp; + /* disable subpixel hinting */ + putenv("FREETYPE_PROPERTIES=truetype:interpreter-version=35"); + path = gdTestFilePath("freetype/DejaVuSans.ttf"); im = gdImageCreate(800, 800); gdImageColorAllocate(im, 0xFF, 0xFF, 0xFF); /* allocate white for background color */ @@ -52,7 +55,7 @@ int main() goto done; } for (j = 0; j < 8; j++) { - if (brect[j] != EXPECT[i][j]) { + if (brect[j] < EXPECT[i][j] - 1 || brect[j] > EXPECT[i][j] + 1) { gdTestErrorMsg("(%d, %d) (%d, %d) (%d, %d) (%d, %d) expected, but (%d, %d) (%d, %d) (%d, %d) (%d, %d)\n", EXPECT[i][0], EXPECT[i][1], EXPECT[i][2], EXPECT[i][3], EXPECT[i][4], EXPECT[i][5], EXPECT[i][6], EXPECT[i][7], diff --git a/tests/gdimagestringup/.gitignore b/tests/gdimagestringup/.gitignore new file mode 100644 index 0000000..4b4bb43 --- /dev/null +++ b/tests/gdimagestringup/.gitignore @@ -0,0 +1 @@ +/gdimagestringup diff --git a/tests/gdimagestringup/CMakeLists.txt b/tests/gdimagestringup/CMakeLists.txt new file mode 100644 index 0000000..424cb83 --- /dev/null +++ b/tests/gdimagestringup/CMakeLists.txt @@ -0,0 +1,7 @@ +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + gdimagestringup +) +ENDIF(PNG_FOUND) + +ADD_GD_TESTS() diff --git a/tests/gdimagestringup/Makemodule.am b/tests/gdimagestringup/Makemodule.am new file mode 100644 index 0000000..b136c80 --- /dev/null +++ b/tests/gdimagestringup/Makemodule.am @@ -0,0 +1,8 @@ +if HAVE_LIBPNG +libgd_test_programs += \ + gdimagestringup/gdimagestringup +endif + +EXTRA_DIST += \ + gdimagestringup/CMakeLists.txt \ + gdimagestringup/gdimagestringup_exp.png diff --git a/tests/gdimagestringup/gdimagestringup.c b/tests/gdimagestringup/gdimagestringup.c new file mode 100644 index 0000000..0832bd7 --- /dev/null +++ b/tests/gdimagestringup/gdimagestringup.c @@ -0,0 +1,34 @@ +/** + * Base test for gdImageStringUp() + */ +#include <gd.h> +#include <gdfontl.h> +#include "gdtest.h" +#include <string.h> + +int main() +{ + /* Declare the image */ + gdImagePtr im = NULL; + char *s = "Hello gd"; + int errorcode = 0; + int foreground; + gdFontPtr fontptr = gdFontGetLarge(); + + im = gdImageCreate(50, 100); + gdImageColorAllocate(im, 202, 202, 0); + foreground = gdImageColorAllocate(im, 22, 4, 238); + + gdImageStringUp(im, fontptr, + im->sx / 2 - fontptr->h / 2, + im->sy / 2 + (strlen(s) * fontptr->w / 2), + (unsigned char*)s, foreground); + + if (!gdAssertImageEqualsToFile("gdimagestringup/gdimagestringup_exp.png", im)) + errorcode = 1; + + /* Destroy the image im memory */ + gdImageDestroy(im); + + return errorcode; +} diff --git a/tests/gdimagestringup/gdimagestringup_exp.png b/tests/gdimagestringup/gdimagestringup_exp.png Binary files differnew file mode 100644 index 0000000..d1f6d66 --- /dev/null +++ b/tests/gdimagestringup/gdimagestringup_exp.png diff --git a/tests/gdimagestringup16/.gitignore b/tests/gdimagestringup16/.gitignore new file mode 100644 index 0000000..1c009a5 --- /dev/null +++ b/tests/gdimagestringup16/.gitignore @@ -0,0 +1 @@ +/gdimagestringup16 diff --git a/tests/gdimagestringup16/CMakeLists.txt b/tests/gdimagestringup16/CMakeLists.txt new file mode 100644 index 0000000..08f4ff8 --- /dev/null +++ b/tests/gdimagestringup16/CMakeLists.txt @@ -0,0 +1,7 @@ +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + gdimagestringup16 +) +ENDIF(PNG_FOUND) + +ADD_GD_TESTS() diff --git a/tests/gdimagestringup16/Makemodule.am b/tests/gdimagestringup16/Makemodule.am new file mode 100644 index 0000000..7735432 --- /dev/null +++ b/tests/gdimagestringup16/Makemodule.am @@ -0,0 +1,8 @@ +if HAVE_LIBPNG +libgd_test_programs += \ + gdimagestringup16/gdimagestringup16 +endif + +EXTRA_DIST += \ + gdimagestringup16/CMakeLists.txt \ + gdimagestringup16/gdimagestringup16_exp.png diff --git a/tests/gdimagestringup16/gdimagestringup16.c b/tests/gdimagestringup16/gdimagestringup16.c new file mode 100644 index 0000000..c24639f --- /dev/null +++ b/tests/gdimagestringup16/gdimagestringup16.c @@ -0,0 +1,29 @@ +/** + * Base test for gdImageStringUp16() + */ +#include <gd.h> +#include <gdfontl.h> +#include "gdtest.h" + +int main() +{ + /* Declare the image */ + gdImagePtr im = NULL; + unsigned short s[2] = {'H', 0}; + int foreground; + int errorcode = 0; + gdFontPtr fontptr = gdFontGetLarge(); + + im = gdImageCreate(20, 20); + gdImageColorAllocate(im, 255, 255, 255); + foreground = gdImageColorAllocate(im, 22, 4, 238); + + gdImageStringUp16(im, fontptr, 2, 18, s, foreground); + + if (!gdAssertImageEqualsToFile("gdimagestringup16/gdimagestringup16_exp.png", im)) + errorcode = 1; + + gdImageDestroy(im); + + return errorcode; +} diff --git a/tests/gdimagestringup16/gdimagestringup16_exp.png b/tests/gdimagestringup16/gdimagestringup16_exp.png Binary files differnew file mode 100644 index 0000000..a1a4570 --- /dev/null +++ b/tests/gdimagestringup16/gdimagestringup16_exp.png diff --git a/tests/gdimagetruecolortopalette/CMakeLists.txt b/tests/gdimagetruecolortopalette/CMakeLists.txt index b23d2a1..fc7f6f7 100644 --- a/tests/gdimagetruecolortopalette/CMakeLists.txt +++ b/tests/gdimagetruecolortopalette/CMakeLists.txt @@ -1,4 +1,4 @@ -SET(TESTS_FILES +LIST(APPEND TESTS_FILES bug00307 php_bug_72512 ) diff --git a/tests/gdimagetruecolortopalette/Makemodule.am b/tests/gdimagetruecolortopalette/Makemodule.am index 31f0362..ac9eedc 100644 --- a/tests/gdimagetruecolortopalette/Makemodule.am +++ b/tests/gdimagetruecolortopalette/Makemodule.am @@ -1,4 +1,3 @@ - libgd_test_programs += \ gdimagetruecolortopalette/bug00307 \ gdimagetruecolortopalette/php_bug_72512 diff --git a/tests/gdimagetruecolortopalette/bug00307.c b/tests/gdimagetruecolortopalette/bug00307.c index a5c6a04..a01eb5a 100644 --- a/tests/gdimagetruecolortopalette/bug00307.c +++ b/tests/gdimagetruecolortopalette/bug00307.c @@ -5,7 +5,7 @@ * GD_QUANT_NEUQUANT has its trueColor flag unset. */ - + #include "gd.h" #include "gdtest.h" diff --git a/tests/gdtest/CMakeLists.txt b/tests/gdtest/CMakeLists.txt index 4b05262..ff9fd7d 100644 --- a/tests/gdtest/CMakeLists.txt +++ b/tests/gdtest/CMakeLists.txt @@ -1,3 +1,7 @@ add_definitions(-DGDTEST_TOP_DIR="${CMAKE_CURRENT_SOURCE_DIR}/..") -add_library (gdTest STATIC gdtest.c) +SET(GDTEST_FILES gdtest.c) +if(WIN32) + LIST(APPEND GDTEST_FILES readdir.c) +endif() +add_library(gdTest STATIC ${GDTEST_FILES}) target_link_libraries(gdTest ${GD_LIB}) diff --git a/tests/gdtest/gdtest.c b/tests/gdtest/gdtest.c index d173975..832f27a 100644 --- a/tests/gdtest/gdtest.c +++ b/tests/gdtest/gdtest.c @@ -1,4 +1,6 @@ +#ifdef HAVE_CONFIG_H #include <config.h> +#endif #include <assert.h> #include <setjmp.h> #include <stdlib.h> @@ -21,7 +23,14 @@ #endif #ifdef _WIN32 -# include "readdir.h" +#include "readdir.h" +#include <errno.h> +#endif + +/* GDTEST_TOP_DIR is defined in other compile ways except msys + * test_config.h is created by windows/msys/run_test.sh*/ +#ifndef GDTEST_TOP_DIR +#include <test_config.h> #endif #include "gd.h" @@ -59,7 +68,7 @@ gdImagePtr gdTestImageFromPng(const char *filename) if (fp == NULL) { return NULL; } - + image = gdImageCreateFromPng(fp); fclose(fp); return image; @@ -186,11 +195,11 @@ static int getfilesystemtime(struct timeval *tv) fft.LowPart = ft.dwLowDateTime; ff = fft.QuadPart; - ff /= 10Ui64; /* convert to microseconds */ - ff -= 11644473600000000Ui64; /* convert to unix epoch */ + ff /= 10ULL; /* convert to microseconds */ + ff -= 11644473600000000ULL; /* convert to unix epoch */ - tv->tv_sec = (long)(ff / 1000000Ui64); - tv->tv_usec = (long)(ff % 1000000Ui64); + tv->tv_sec = (long)(ff / 1000000ULL); + tv->tv_usec = (long)(ff % 1000000ULL); return 0; } @@ -203,7 +212,7 @@ mkdtemp (char *tmpl) static int counter = 0; char *XXXXXX; struct timeval tv; - _int64 value; + __int64 value; int count; /* find the last occurrence of "XXXXXX" */ @@ -219,7 +228,7 @@ mkdtemp (char *tmpl) value = (tv.tv_usec ^ tv.tv_sec) + counter++; for (count = 0; count < 100; value += 7777, ++count) { - _int64 v = value; + __int64 v = value; /* Fill in the random bits. */ XXXXXX[0] = letters[v % NLETTERS]; @@ -304,7 +313,7 @@ char *gdTestTempFile(const char *template) ret); gdTestAssert(error != 0); } else { - sprintf(ret, "%s\\%s", tempdir, template); + sprintf(ret, "%s\\%s", tempdir, template); } } #else @@ -501,7 +510,6 @@ unsigned int gdMaxPixelDiff(gdImagePtr a, gdImagePtr b) return diff; } - int gdTestImageCompareToImage(const char* file, unsigned int line, const char* message, gdImagePtr expected, gdImagePtr actual) { @@ -561,6 +569,7 @@ int gdTestImageCompareToImage(const char* file, unsigned int line, const char* m if (!fp) goto fail; gdImagePng(surface_diff,fp); fclose(fp); + gdImageDestroy(surface_diff); fp = fopen(file_out, "wb"); if (!fp) goto fail; @@ -578,13 +587,13 @@ fail: if (surface_diff) { gdImageDestroy(surface_diff); } - return 0; + return 1; } int gdTestImageCompareToFile(const char* file, unsigned int line, const char* message, const char *expected_file, gdImagePtr actual) { - gdImagePtr expected; + gdImagePtr expected = 0; int res = 1; expected = gdTestImageFromPng(expected_file); @@ -599,7 +608,6 @@ int gdTestImageCompareToFile(const char* file, unsigned int line, const char* me return res; } - static int failureCount = 0; int gdNumFailures() { diff --git a/tests/gdtest/gdtest.h b/tests/gdtest/gdtest.h index eecf5f6..16d89aa 100644 --- a/tests/gdtest/gdtest.h +++ b/tests/gdtest/gdtest.h @@ -63,10 +63,8 @@ int _gdTestErrorMsg(const char* file, unsigned int line, const char* string, ... /* public assert functions */ #define gdAssertImageEqualsToFile(ex,ac) gdTestImageCompareToFile(__FILE__,__LINE__,NULL,(ex),(ac)) -#define gdAssertImageFileEqualsMsg(ex,ac,ms) gdTestImageCompareFiles(__FILE__,__LINE__,(ms),(ex),(ac)) #define gdAssertImageEquals(ex,ac) gdTestImageCompareToImage(__FILE__,__LINE__,NULL,(ex),(ac)) -#define gdAssertImageEqualsMsg(ex,ac,ms) gdTestImageCompareToImage(__FILE__,__LINE__,(ms),(ex),(ac)) #define gdTestAssert(cond) _gdTestAssert(__FILE__, __LINE__, (cond)) diff --git a/tests/gdtiled/CMakeLists.txt b/tests/gdtiled/CMakeLists.txt index 921d00e..25f6045 100644 --- a/tests/gdtiled/CMakeLists.txt +++ b/tests/gdtiled/CMakeLists.txt @@ -1,5 +1,9 @@ +IF(PNG_FOUND) +IF(ZLIB_FOUND) LIST(APPEND TESTS_FILES bug00032 ) +ENDIF(ZLIB_FOUND) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gdtiled/bug00032.c b/tests/gdtiled/bug00032.c index 4c788e2..7a2b5cc 100644 --- a/tests/gdtiled/bug00032.c +++ b/tests/gdtiled/bug00032.c @@ -29,4 +29,3 @@ int main() gdImageDestroy(tile); return 0; } - diff --git a/tests/gdtransformaffineboundingbox/Makemodule.am b/tests/gdtransformaffineboundingbox/Makemodule.am index e70b073..2566ed5 100644 --- a/tests/gdtransformaffineboundingbox/Makemodule.am +++ b/tests/gdtransformaffineboundingbox/Makemodule.am @@ -1,4 +1,3 @@ - libgd_test_programs += \ gdtransformaffineboundingbox/github_bug_00221 diff --git a/tests/gdtransformaffineboundingbox/github_bug_00221.c b/tests/gdtransformaffineboundingbox/github_bug_00221.c index c327789..9e75d0e 100644 --- a/tests/gdtransformaffineboundingbox/github_bug_00221.c +++ b/tests/gdtransformaffineboundingbox/github_bug_00221.c @@ -10,7 +10,7 @@ int main() gdRect bbox; gdRect area; double affine[6]; - + affine[0] = -0.965926; affine[1] = -0.258819; affine[2] = 0.258819; @@ -24,7 +24,7 @@ int main() if (gdTransformAffineBoundingBox(&area, affine, &bbox) != GD_TRUE) { return 1; } - if (!(bbox.x ==-253 && bbox.y ==-228 && bbox.width == 298 && bbox.height == 230)) { + if (!(bbox.x ==-253 && bbox.y ==-228 && bbox.width == 297 && bbox.height == 229)) { return 1; } diff --git a/tests/gdtransformaffinecopy/.gitignore b/tests/gdtransformaffinecopy/.gitignore new file mode 100644 index 0000000..2af21d5 --- /dev/null +++ b/tests/gdtransformaffinecopy/.gitignore @@ -0,0 +1,4 @@ +/github_bug_00583 +/github_bug_00585 +/github_bug_00586 +/github_bug_00596 diff --git a/tests/gdtransformaffinecopy/CMakeLists.txt b/tests/gdtransformaffinecopy/CMakeLists.txt new file mode 100644 index 0000000..4af9fcc --- /dev/null +++ b/tests/gdtransformaffinecopy/CMakeLists.txt @@ -0,0 +1,8 @@ +LIST(APPEND TESTS_FILES + github_bug_00583 + github_bug_00585 + github_bug_00586 + github_bug_00596 +) + +ADD_GD_TESTS() diff --git a/tests/gdtransformaffinecopy/Makemodule.am b/tests/gdtransformaffinecopy/Makemodule.am new file mode 100644 index 0000000..494ec80 --- /dev/null +++ b/tests/gdtransformaffinecopy/Makemodule.am @@ -0,0 +1,8 @@ +libgd_test_programs += \ + gdtransformaffinecopy/github_bug_00583 \ + gdtransformaffinecopy/github_bug_00585 \ + gdtransformaffinecopy/github_bug_00586 \ + gdtransformaffinecopy/github_bug_00596 + +EXTRA_DIST += \ + gdtransformaffinecopy/CMakeLists.txt diff --git a/tests/gdtransformaffinecopy/github_bug_00583.c b/tests/gdtransformaffinecopy/github_bug_00583.c new file mode 100644 index 0000000..6b0fd53 --- /dev/null +++ b/tests/gdtransformaffinecopy/github_bug_00583.c @@ -0,0 +1,30 @@ +/** + * Test that a zero determinant matrix causes gdTransformAffineCopy() to fail + * + * See <https://github.com/libgd/libgd/issues/583> + */ + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr src, dst; + gdRect rect = {0, 0, 8, 8}; + double matrix[] = {1, 1, 1, 1, 1, 1}; + int white; + int res; + + src = gdImageCreateTrueColor(8, 8); + gdTestAssert(src != NULL); + dst = gdImageCreateTrueColor(8, 8); + gdTestAssert(dst != NULL); + white = gdImageColorAllocate(src, 255, 255, 255); + gdImageFilledRectangle(src, 0, 0, 7, 7, white); + res = gdTransformAffineCopy(dst, 0, 0, src, &rect, matrix); + gdTestAssert(res == GD_FALSE); + gdImageDestroy(dst); + gdImageDestroy(src); + return gdNumFailures(); +} diff --git a/tests/gdtransformaffinecopy/github_bug_00585.c b/tests/gdtransformaffinecopy/github_bug_00585.c new file mode 100644 index 0000000..e83910c --- /dev/null +++ b/tests/gdtransformaffinecopy/github_bug_00585.c @@ -0,0 +1,33 @@ +/* + * Test that gdTransformAffineCopy() does not change the interpolation method + * + * See <https://github.com/libgd/libgd/issues/585> + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr src, dst; + gdRect rect = {0, 0, 8, 8}; + double matrix[] = {1, 1, 1, 1, 1, 1}; + int res; + gdInterpolationMethod old_m, new_m; + + src = gdImageCreateTrueColor(8, 8); + gdTestAssert(src != NULL); + dst = gdImageCreateTrueColor(8, 8); + gdTestAssert(dst != NULL); + + res = gdImageSetInterpolationMethod(src, GD_CATMULLROM); + gdTestAssert(res == GD_TRUE); + old_m = gdImageGetInterpolationMethod(src); + gdTransformAffineCopy(dst, 0, 0, src, &rect, matrix); + new_m = gdImageGetInterpolationMethod(src); + gdTestAssert(new_m == old_m); + + gdImageDestroy(src); + gdImageDestroy(dst); + return gdNumFailures(); +} diff --git a/tests/gdtransformaffinecopy/github_bug_00586.c b/tests/gdtransformaffinecopy/github_bug_00586.c new file mode 100644 index 0000000..4cf2f2e --- /dev/null +++ b/tests/gdtransformaffinecopy/github_bug_00586.c @@ -0,0 +1,26 @@ +/* + * Test that gdTransformAffineCopy() does not segfault for palette images + * + * See <> + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr src, dst; + gdRect rect = {0, 0, 8, 8}; + double matrix[] = {1, 0, 0, 1, 0, 0}; + + src = gdImageCreate(8, 8); + gdTestAssert(src != NULL); + dst = gdImageCreate(8, 8); + gdTestAssert(dst != NULL); + + gdTransformAffineCopy(dst, 0, 0, src, &rect, matrix); + + gdImageDestroy(dst); + gdImageDestroy(src); + return gdNumFailures(); +} diff --git a/tests/gdtransformaffinecopy/github_bug_00596.c b/tests/gdtransformaffinecopy/github_bug_00596.c new file mode 100644 index 0000000..51912e1 --- /dev/null +++ b/tests/gdtransformaffinecopy/github_bug_00596.c @@ -0,0 +1,42 @@ +/** + * Test gdTransformAffineCopy() run error + * + * See <https://github.com/libgd/libgd/issues/596> + * + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + double matrix[] = {1, 0, 0, 1, 0, 0}; + gdImagePtr src, dst; + gdRect rect = {0, 0, 16, 16}; + int white, green; + int status = 0; + int res; + int actual_color = 0; + int expected_color = 0x00ff00; + + src = gdImageCreateTrueColor(16, 16); + gdTestAssert(src != NULL); + white = gdImageColorAllocate(src, 255, 255, 255); + gdImageFilledRectangle(src, 0, 0, 16, 16, white); + + dst = gdImageCreateTrueColor(50, 50); + gdTestAssert(dst != NULL); + green = gdImageColorAllocate(dst, 0, 255, 0); + gdImageFilledRectangle(dst, 0, 0, 50, 50, green); + + res = gdTransformAffineCopy(dst, 4, 4, src, &rect, matrix); + gdTestAssert(res != GD_FALSE); + + status = gdNumFailures(); + actual_color = gdImageGetPixel(dst, 20, 5); + status = (actual_color == expected_color) ? status : 1; + + gdImageDestroy(src); + gdImageDestroy(dst); + return status; +} diff --git a/tests/gif/.gitignore b/tests/gif/.gitignore index d18444d..d30118f 100644 --- a/tests/gif/.gitignore +++ b/tests/gif/.gitignore @@ -5,5 +5,10 @@ /bug00066 /bug00181 /bug00227 +/bug00499 /gif_im2im /gif_null +/gif_nocolormaps +/ossfuzz5700 +/php_bug_75571 +/uninitialized_memory_read diff --git a/tests/gif/CMakeLists.txt b/tests/gif/CMakeLists.txt index 92010c3..d071874 100644 --- a/tests/gif/CMakeLists.txt +++ b/tests/gif/CMakeLists.txt @@ -1,13 +1,23 @@ LIST(APPEND TESTS_FILES - gif_im2im - gif_null - bug00005 bug00005_2 + bug00181 + bug00227 + bug00499 + gif_null + gif_nocolormaps + ossfuzz5700 + php_bug_75571 + uninitialized_memory_read bug00006 bug00060 + gif_im2im +) + +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + bug00005 bug00066 - bug00181 - bug00227 ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/gif/Makemodule.am b/tests/gif/Makemodule.am index 50f671f..c616b3e 100644 --- a/tests/gif/Makemodule.am +++ b/tests/gif/Makemodule.am @@ -2,15 +2,20 @@ libgd_test_programs += \ gif/bug00005_2 \ gif/bug00181 \ gif/bug00227 \ - gif/gif_null + gif/bug00499 \ + gif/gif_null \ + gif/gif_nocolormaps \ + gif/ossfuzz5700 \ + gif/php_bug_75571 \ + gif/uninitialized_memory_read \ + gif/bug00006 \ + gif/bug00060 \ + gif/gif_im2im if HAVE_LIBPNG libgd_test_programs += \ gif/bug00005 \ - gif/bug00006 \ - gif/bug00060 \ - gif/bug00066 \ - gif/gif_im2im + gif/bug00066 endif EXTRA_DIST += \ @@ -22,4 +27,8 @@ EXTRA_DIST += \ gif/bug00005_3.gif \ gif/bug00060.gif \ gif/bug00066.gif \ - gif/bug00066_exp.png + gif/bug00066_exp.png \ + gif/gif_nocolormaps.gif \ + gif/ossfuzz5700.gif \ + gif/php_bug_75571.gif \ + gif/unitialized_memory_read.gif diff --git a/tests/gif/bug00006.c b/tests/gif/bug00006.c index f1a7fe8..95f7620 100644 --- a/tests/gif/bug00006.c +++ b/tests/gif/bug00006.c @@ -27,6 +27,10 @@ int main() gdTestErrorMsg("Cannot open <%s> for writing\n", file); return 1; } + + gdImageTrueColorToPaletteSetMethod(im, GD_QUANT_JQUANT, 0); + gdImageTrueColorToPalette(im, 1, 256); + gdImageGif(im,fp); fclose(fp); @@ -60,5 +64,6 @@ int main() /* Destroy it */ gdImageDestroy(im); + free(file); return error; } diff --git a/tests/gif/bug00181.c b/tests/gif/bug00181.c index 43b9e3b..878537f 100644 --- a/tests/gif/bug00181.c +++ b/tests/gif/bug00181.c @@ -92,6 +92,7 @@ int main() } error = !im->interlace; gdImageDestroy(im); + free(file); return error; } diff --git a/tests/gif/bug00227.c b/tests/gif/bug00227.c index e25bd9a..aa20645 100644 --- a/tests/gif/bug00227.c +++ b/tests/gif/bug00227.c @@ -65,5 +65,7 @@ int main() if (buf[PROBE_SIZE-1] & 0x80) return 1; free(buf); fclose(fp); + + free(file); return 0; } diff --git a/tests/gif/bug00499.c b/tests/gif/bug00499.c new file mode 100644 index 0000000..0fedb92 --- /dev/null +++ b/tests/gif/bug00499.c @@ -0,0 +1,51 @@ +/** + * Test that adding identical images to GIF animations do no double-free + * + * We are adding two frames to a GIF animation in gdDisposalNone mode, were the + * second frame is identical to the first, which result in that image to have + * zero extent. This program must not cause any memory issues. + * + * See also <https://github.com/libgd/libgd/issues/499>. + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im; + int black; + int size; + void * res; + + im = gdImageCreate(100, 100); + black = gdImageColorAllocate(im, 0, 0, 0); + gdImageRectangle(im, 0, 0, 10, 10, black); + + res = gdImageGifAnimBeginPtr(im, &size, 1, 3); + if (res != NULL) { + gdFree(res); + } + + res = gdImageGifAnimAddPtr(im, &size, 0, 0, 0, 100, gdDisposalNone, NULL); + if (res != NULL) { + gdFree(res); + } + + res = gdImageGifAnimAddPtr(im, &size, 0, 0, 0, 100, gdDisposalNone, im); + gdTestAssert(res == NULL); + if (res != NULL) { + gdFree(res); + } + + res = gdImageGifAnimEndPtr(&size); + if (res != NULL) { + gdFree(res); + } + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gif/gif_nocolormaps.c b/tests/gif/gif_nocolormaps.c new file mode 100644 index 0000000..4419904 --- /dev/null +++ b/tests/gif/gif_nocolormaps.c @@ -0,0 +1,25 @@ +/** + * Ensure that a GIF without any Global or Local color tables is still decoded + * + * GIF89a spec indicates conforming image files need not have Global or Local color tables at all + * + * See also: https://www.w3.org/Graphics/GIF/spec-gif89a.txt + * http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gif", "gif_nocolormaps.gif"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGif(fp); + gdTestAssert(im != NULL); + fclose(fp); + + return gdNumFailures(); +} diff --git a/tests/gif/gif_nocolormaps.gif b/tests/gif/gif_nocolormaps.gif Binary files differnew file mode 100644 index 0000000..b3aa80d --- /dev/null +++ b/tests/gif/gif_nocolormaps.gif diff --git a/tests/gif/ossfuzz5700.c b/tests/gif/ossfuzz5700.c new file mode 100644 index 0000000..8fc9f88 --- /dev/null +++ b/tests/gif/ossfuzz5700.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp = gdTestFileOpen("gif/ossfuzz5700.gif"); + im = gdImageCreateFromGif(fp); + fclose(fp); + gdImageDestroy(im); + return 0; +} diff --git a/tests/gif/ossfuzz5700.gif b/tests/gif/ossfuzz5700.gif Binary files differnew file mode 100644 index 0000000..315c5a8 --- /dev/null +++ b/tests/gif/ossfuzz5700.gif diff --git a/tests/gif/php_bug_75571.c b/tests/gif/php_bug_75571.c new file mode 100644 index 0000000..ec1f37e --- /dev/null +++ b/tests/gif/php_bug_75571.c @@ -0,0 +1,28 @@ +/** + * Test that GIF reading does not loop infinitely + * + * We are reading a crafted GIF image which has been truncated. This would + * trigger an infinite loop formerly, but know bails out early, returning + * NULL from gdImageCreateFromGif(). + * + * See also https://bugs.php.net/bug.php?id=75571. + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gif", "php_bug_75571.gif"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGif(fp); + gdTestAssert(im == NULL); + fclose(fp); + + return gdNumFailures(); +} diff --git a/tests/gif/php_bug_75571.gif b/tests/gif/php_bug_75571.gif Binary files differnew file mode 100644 index 0000000..3c30b40 --- /dev/null +++ b/tests/gif/php_bug_75571.gif diff --git a/tests/gif/uninitialized_memory_read.c b/tests/gif/uninitialized_memory_read.c new file mode 100644 index 0000000..566fc4a --- /dev/null +++ b/tests/gif/uninitialized_memory_read.c @@ -0,0 +1,42 @@ +/** + * Test for uninitialized color map entries + * + * We're reading a crafted GIF which consists of 16x16 color blocks and which + * has only two palette entries in the global color map, but uses other palette + * indexes as well. We verify whether all undefined palette indexes produce the + * color black. + * + * See also <CAKm_7a-AO++B6cXYWM_DtycPENG5WNWK7NSEvQ5OmZziMY_JyA@mail.gmail.com> + * which had been sent to security@libgd.org. + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im; + FILE *fp; + int i, j, col; + + fp = gdTestFileOpen2("gif", "unitialized_memory_read.gif"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGif(fp); + gdTestAssert(im != NULL); + fclose(fp); + + for (i = 0; i < gdImageSX(im); i += 16) { + for (j = 0; j < gdImageSY(im); j += 16) { + if (gdImageGetPixel(im, i, j) >= 2) { + col = gdImageGetTrueColorPixel(im, i, j); + gdTestAssertMsg(col == 0, "(%d,%d): expected color 0, but got %d\n", i, j, col); + } + } + } + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gif/unitialized_memory_read.gif b/tests/gif/unitialized_memory_read.gif Binary files differnew file mode 100644 index 0000000..92fbb7f --- /dev/null +++ b/tests/gif/unitialized_memory_read.gif diff --git a/tests/heif/CMakeLists.txt b/tests/heif/CMakeLists.txt new file mode 100644 index 0000000..4a41528 --- /dev/null +++ b/tests/heif/CMakeLists.txt @@ -0,0 +1,11 @@ +IF(HEIF_FOUND) +LIST(APPEND TESTS_FILES + avif_ptr_double_free + heif_im2im + heif_null + heif_ptr_double_free + heif_read +) +ENDIF(HEIF_FOUND) + +ADD_GD_TESTS() diff --git a/tests/heif/Makemodule.am b/tests/heif/Makemodule.am new file mode 100644 index 0000000..8ab60c4 --- /dev/null +++ b/tests/heif/Makemodule.am @@ -0,0 +1,12 @@ +if HAVE_LIBHEIF +libgd_test_programs += \ + heif/avif_ptr_double_free \ + heif/heif_im2im \ + heif/heif_null \ + heif/heif_ptr_double_free \ + heif/heif_read +endif + +EXTRA_DIST += \ + heif/CMakeLists.txt \ + heif/label.heic diff --git a/tests/heif/avif_ptr_double_free.c b/tests/heif/avif_ptr_double_free.c new file mode 100644 index 0000000..f294929 --- /dev/null +++ b/tests/heif/avif_ptr_double_free.c @@ -0,0 +1,31 @@ +/** + * Test that failure to convert to AVIF returns NULL + * + * We are creating an image, set its width to zero, and pass this image to + * `gdImageAvifPtr()` which is supposed to fail, and as such should return NULL. + * + * See also <https://github.com/libgd/libgd/issues/381> + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr src, dst; + int size; + + src = gdImageCreateTrueColor(1, 10); + gdTestAssert(src != NULL); + + src->sx = 0; + + dst = gdImageHeifPtrEx(src, &size, 100, GD_HEIF_CODEC_AV1, GD_HEIF_CHROMA_444); + gdTestAssert(dst == NULL); + + gdImageDestroy(src); + + return gdNumFailures(); +} diff --git a/tests/heif/heif_im2im.c b/tests/heif/heif_im2im.c new file mode 100644 index 0000000..01abf02 --- /dev/null +++ b/tests/heif/heif_im2im.c @@ -0,0 +1,57 @@ +/** + * Check if it's any difference between the original bitmap and a encoded and + * decoded `4:4:4` HEIF lossless image. + */ + + +#include "gd.h" +#include "gdtest.h" + +#include <libheif/heif.h> + +int main() +{ + gdImagePtr src, dst; + int r, g, b; + void *p; + int size = 0; + CuTestImageResult result = {0, 0}; + + if (!gdTestAssertMsg(heif_get_version_number_major() == 1 && heif_get_version_number_minor() >= 9, "changing chroma subsampling is not supported in this libheif version\n")) + return 77; + + if (!gdTestAssertMsg(heif_have_decoder_for_format(heif_compression_HEVC) && heif_have_encoder_for_format(heif_compression_HEVC), "HEVC codec support missing from libheif\n")) + return 77; + + src = gdImageCreateTrueColor(100, 100); + gdTestAssertMsg(src != NULL, "could not create src\n"); + /* libheif seems to have some rounding issues */ + r = gdImageColorAllocate(src, 0xFE, 0, 0); + g = gdImageColorAllocate(src, 0, 0xFE, 0); + b = gdImageColorAllocate(src, 0, 0, 0xFE); + gdImageFilledRectangle(src, 0, 0, 99, 99, r); + gdImageRectangle(src, 20, 20, 79, 79, g); + gdImageEllipse(src, 70, 25, 30, 20, b); + + p = gdImageHeifPtrEx(src, &size, 200, GD_HEIF_CODEC_HEVC, GD_HEIF_CHROMA_444); + gdTestAssertMsg(p != NULL, "return value of gdImageHeifPtrEx() is null\n"); + gdTestAssertMsg(size > 0, "gdImageHeifPtrEx() output size is non-positive\n"); + + dst = gdImageCreateFromHeifPtr(size, p); + gdTestAssertMsg(dst != NULL, "return value of gdImageCreateFromHeifPtr() is null\n"); + + if (gdTestAssertMsg(src != NULL && dst != NULL, "cannot compare with NULL buffer")) + gdTestImageDiff(src, dst, NULL, &result); + else + result.pixels_changed = 0; + gdTestAssertMsg(result.pixels_changed == 0, "pixels changed: %d\n", result.pixels_changed); + + if (dst != NULL) + gdImageDestroy(dst); + if (p != NULL) + gdFree(p); + if (src != NULL) + gdImageDestroy(src); + + return gdNumFailures(); +} diff --git a/tests/heif/heif_null.c b/tests/heif/heif_null.c new file mode 100644 index 0000000..0b5eac5 --- /dev/null +++ b/tests/heif/heif_null.c @@ -0,0 +1,20 @@ +/** + * Simple test case that confirms the failure of using `gdImageCreateFromHeif` + * with a NULL pointer. + */ + + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + + im = gdImageCreateFromHeif(NULL); + if (!gdTestAssert(im == NULL)) + gdImageDestroy(im); + gdImageHeif(im, NULL); /* noop safely */ + + return gdNumFailures(); +} diff --git a/tests/heif/heif_ptr_double_free.c b/tests/heif/heif_ptr_double_free.c new file mode 100644 index 0000000..14f1d25 --- /dev/null +++ b/tests/heif/heif_ptr_double_free.c @@ -0,0 +1,31 @@ +/** + * Test that failure to convert to HEIF returns NULL + * + * We are creating an image, set its width to zero, and pass this image to + * `gdImageHeifPtr()` which is supposed to fail, and as such should return NULL. + * + * See also <https://github.com/libgd/libgd/issues/381> + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr src, dst; + int size; + + src = gdImageCreateTrueColor(1, 10); + gdTestAssert(src != NULL); + + src->sx = 0; + + dst = gdImageHeifPtrEx(src, &size, 0, GD_HEIF_CODEC_HEVC, GD_HEIF_CHROMA_444); + gdTestAssert(dst == NULL); + + gdImageDestroy(src); + + return gdNumFailures(); +} diff --git a/tests/heif/heif_read.c b/tests/heif/heif_read.c new file mode 100644 index 0000000..6ecb5f0 --- /dev/null +++ b/tests/heif/heif_read.c @@ -0,0 +1,28 @@ +/** + * Simple test case that confirms the failure of using `gdImageCreateFromHeif` + * with a NULL pointer. + */ + + +#include "gd.h" +#include "gdtest.h" + +#include <libheif/heif.h> + +int main() +{ + gdImagePtr im; + FILE *fp; + + if (!gdTestAssertMsg(heif_have_decoder_for_format(heif_compression_HEVC), "HEVC codec support missing from libheif\n")) + return 77; + + fp = gdTestFileOpen2("heif", "label.heic"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromHeif(fp); + if (gdTestAssert(im != NULL)) + gdImageDestroy(im); + fclose(fp); + + return gdNumFailures(); +} diff --git a/tests/heif/label.avif b/tests/heif/label.avif Binary files differnew file mode 100644 index 0000000..2e84362 --- /dev/null +++ b/tests/heif/label.avif diff --git a/tests/heif/label.heic b/tests/heif/label.heic Binary files differnew file mode 100644 index 0000000..12814f7 --- /dev/null +++ b/tests/heif/label.heic diff --git a/tests/jpeg/.gitignore b/tests/jpeg/.gitignore index 06cc9b2..13bcf04 100644 --- a/tests/jpeg/.gitignore +++ b/tests/jpeg/.gitignore @@ -1,6 +1,8 @@ +/bug00338 /bug_github_18 /jpeg_empty_file /jpeg_im2im /jpeg_null +/jpeg_ptr_double_free /jpeg_read /jpeg_resolution diff --git a/tests/jpeg/CMakeLists.txt b/tests/jpeg/CMakeLists.txt index e8ecf63..ff188a9 100644 --- a/tests/jpeg/CMakeLists.txt +++ b/tests/jpeg/CMakeLists.txt @@ -1,12 +1,19 @@ IF(JPEG_FOUND) LIST(APPEND TESTS_FILES + jpeg_empty_file jpeg_im2im + jpeg_ptr_double_free jpeg_null - jpeg_read - jpeg_empty_file jpeg_resolution +) + +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES bug_github_18 + jpeg_read + bug00338 ) +ENDIF(PNG_FOUND) ENDIF(JPEG_FOUND) ADD_GD_TESTS() diff --git a/tests/jpeg/Makemodule.am b/tests/jpeg/Makemodule.am index bc196b1..b778470 100644 --- a/tests/jpeg/Makemodule.am +++ b/tests/jpeg/Makemodule.am @@ -1,14 +1,16 @@ if HAVE_LIBJPEG libgd_test_programs += \ - jpeg/bug_github_18 \ jpeg/jpeg_empty_file \ jpeg/jpeg_im2im \ - jpeg/jpeg_null + jpeg/jpeg_null \ + jpeg/jpeg_ptr_double_free \ + jpeg/jpeg_resolution if HAVE_LIBPNG libgd_test_programs += \ - jpeg/jpeg_read \ - jpeg/jpeg_resolution + jpeg/bug_github_18 \ + jpeg/bug00338 \ + jpeg/jpeg_read endif endif diff --git a/tests/jpeg/bug00338.c b/tests/jpeg/bug00338.c new file mode 100644 index 0000000..7874df2 --- /dev/null +++ b/tests/jpeg/bug00338.c @@ -0,0 +1,46 @@ +/** + * Regression test for <https://github.com/libgd/libgd/issues/338> + * + * We're testing that reading a JPEG image with gdImageCreateFromJpeg() + * raises a GD_WARNING for the fatal libjpeg error, but not a GD_ERROR. + * We also make sure, that the fatal libjpeg error is actually reported. + * + * See also ../png/bug00338.c + */ + +#include <string.h> +#include "gd.h" +#include "gd_errors.h" +#include "gdtest.h" + +#define MSG "gd-jpeg: JPEG library reports unrecoverable error: %s" + +static int error_handler_called = 0; + +static void error_handler(int priority, const char *format, va_list args) +{ + if (!strcmp(format, MSG)) { + gdTestAssertMsg(priority == GD_WARNING, "expected priority %d, but got %d", GD_WARNING, priority); + error_handler_called = 1; + } +} + +int main() +{ + gdImagePtr im; + FILE *fp; + + gdSetErrorMethod(error_handler); + + im = gdImageCreateTrueColor(10, 10); + fp = gdTestTempFp(); + gdImagePng(im, fp); + gdImageDestroy(im); + + im = gdImageCreateFromJpeg(fp); + gdTestAssert(im == NULL); + + gdTestAssert(error_handler_called); + + return gdNumFailures(); +} diff --git a/tests/jpeg/jpeg_ptr_double_free.c b/tests/jpeg/jpeg_ptr_double_free.c new file mode 100644 index 0000000..df5a510 --- /dev/null +++ b/tests/jpeg/jpeg_ptr_double_free.c @@ -0,0 +1,31 @@ +/** + * Test that failure to convert to JPEG returns NULL + * + * We are creating an image, set its width to zero, and pass this image to + * `gdImageJpegPtr()` which is supposed to fail, and as such should return NULL. + * + * See also <https://github.com/libgd/libgd/issues/381> + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr src, dst; + int size; + + src = gdImageCreateTrueColor(1, 10); + gdTestAssert(src != NULL); + + src->sx = 0; /* this hack forces gdImageJpegPtr() to fail */ + + dst = gdImageJpegPtr(src, &size, 0); + gdTestAssert(dst == NULL); + + gdImageDestroy(src); + + return gdNumFailures(); +} diff --git a/tests/png/.gitignore b/tests/png/.gitignore index 28eb412..d226591 100644 --- a/tests/png/.gitignore +++ b/tests/png/.gitignore @@ -3,6 +3,9 @@ /bug00086 /bug00088 /bug00193 +/bug00338 +/bug00381_1 +/bug00381_2 /png_im2im /png_null /png_resolution diff --git a/tests/png/CMakeLists.txt b/tests/png/CMakeLists.txt index 228474e..6d618a0 100644 --- a/tests/png/CMakeLists.txt +++ b/tests/png/CMakeLists.txt @@ -8,7 +8,15 @@ LIST(APPEND TESTS_FILES bug00086 bug00088 bug00193 + bug00338 + bug00381_1 ) + +IF(ENABLE_GD_FORMATS) +LIST(APPEND TESTS_FILES + bug00381_2 +) +ENDIF(ENABLE_GD_FORMATS) ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/png/Makemodule.am b/tests/png/Makemodule.am index 01c4803..d28253e 100644 --- a/tests/png/Makemodule.am +++ b/tests/png/Makemodule.am @@ -5,9 +5,16 @@ libgd_test_programs += \ png/bug00086 \ png/bug00088 \ png/bug00193 \ + png/bug00338 \ + png/bug00381_1 \ png/png_im2im \ png/png_null \ png/png_resolution + +if ENABLE_GD_FORMATS +libgd_test_programs += \ + png/bug00381_2 +endif endif EXTRA_DIST += \ @@ -17,4 +24,5 @@ EXTRA_DIST += \ png/bug00088_1_exp.png \ png/bug00088_2.png \ png/bug00088_2_exp.png \ + png/bug00381_2.gd \ png/emptyfile diff --git a/tests/png/bug00338.c b/tests/png/bug00338.c new file mode 100644 index 0000000..f439d8c --- /dev/null +++ b/tests/png/bug00338.c @@ -0,0 +1,44 @@ +/** + * Regression test for <https://github.com/libgd/libgd/issues/338> + * + * We're testing that writing a PNG image with an unsupported quality + * raises a GD_WARNING for the fatal libpng error, but not a GD_ERROR. + * We also make sure, that the fatal libpng error is actually reported. + * + * See also ../jpeg/bug00338.c + */ + +#include <string.h> +#include "gd.h" +#include "gd_errors.h" +#include "gdtest.h" + +#define MSG "gd-png: fatal libpng error: %s\n" + +static int error_handler_called = 0; + +static void error_handler(int priority, const char *format, va_list args) +{ + if (!strcmp(format, MSG)) { + gdTestAssertMsg(priority == GD_WARNING, "expected priority %d, but got %d", GD_WARNING, priority); + error_handler_called = 1; + } +} + +int main() +{ + gdImagePtr im; + FILE *fp; + + gdSetErrorMethod(error_handler); + + im = gdImageCreateTrueColor(10, 10); + fp = gdTestTempFp(); + gdImagePngEx(im, fp, 100); + gdImageDestroy(im); + fclose(fp); + + gdTestAssert(error_handler_called); + + return gdNumFailures(); +} diff --git a/tests/png/bug00381_1.c b/tests/png/bug00381_1.c new file mode 100644 index 0000000..d8f375b --- /dev/null +++ b/tests/png/bug00381_1.c @@ -0,0 +1,31 @@ +/** + * Test that failure to convert to PNG returns NULL + * + * We are creating a palette image without allocating any colors in the palette, + * and pass this image to `gdImagePngPtr()` which is supposed to fail, and as + * such should return NULL. + * + * See also <https://github.com/libgd/libgd/issues/381> + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im; + void *data; + int size = 0; + + im = gdImageCreate(100, 100); + gdTestAssert(im != NULL); + + data = gdImagePngPtr(im, &size); + gdTestAssert(data == NULL); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/png/bug00381_2.c b/tests/png/bug00381_2.c new file mode 100644 index 0000000..84c7bb1 --- /dev/null +++ b/tests/png/bug00381_2.c @@ -0,0 +1,35 @@ +/** + * Test that failure to convert to PNG returns NULL + * + * We are reading a palette image without any colors in the palette, and pass + * this image to `gdImagePngPtr()` which is supposed to fail, and as such should + * return NULL. + * + * See also <https://github.com/libgd/libgd/issues/381> + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im; + FILE *fp; + void *data; + int size = 0; + + fp = gdTestFileOpen2("png", "bug00381_2.gd"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGd(fp); + gdTestAssert(im != NULL); + fclose(fp); + + data = gdImagePngPtr(im, &size); + gdTestAssert(data == NULL); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/png/bug00381_2.gd b/tests/png/bug00381_2.gd Binary files differnew file mode 100644 index 0000000..c18480a --- /dev/null +++ b/tests/png/bug00381_2.gd diff --git a/tests/png/png_resolution.c b/tests/png/png_resolution.c index aed7545..bfc944d 100644 --- a/tests/png/png_resolution.c +++ b/tests/png/png_resolution.c @@ -24,7 +24,7 @@ int main() gdImageDestroy(im); return 1; } - + gdImageDestroy(im); return 0; } diff --git a/tests/source/README.md b/tests/source/README.md new file mode 100644 index 0000000..fce3ac9 --- /dev/null +++ b/tests/source/README.md @@ -0,0 +1,3 @@ +These are tests/lints for the source code itself. +They aren't included in the default `make check` so they aren't run against +releases, but we run them against Github PRs in Travis. diff --git a/tests/source/run.sh b/tests/source/run.sh new file mode 100755 index 0000000..8d7f9c3 --- /dev/null +++ b/tests/source/run.sh @@ -0,0 +1,46 @@ +#!/bin/bash -e + +if [[ -z "${top_srcdir}" ]] ; then + cd "${0%/*}/../.." + top_srcdir="${PWD}" +fi +TEST_DIR="${top_srcdir}/tests/source" + +cd "${top_srcdir}" + +ret=0 + +# Force a basic environment regardless of how we're configured. +export GIT_PAGER=cat +export LC_ALL=C + +# List all the non-binary files we know about in the tree. +read -r -d'\n' -a files < <( + git ls-tree -r --name-only HEAD | \ + grep -Ev '\.(avif|bin|bmp|gd|gd2|gif|heic|jpg|jpeg|png|pic|sgi|tga|tiff|ttf|xbm|xpm)$' +) || : + +banner() { + echo + echo "### $*" +} + +do_grep() { + # Use -a so UTF-8 files don't get flagged as binary & skipped. + if git grep -aHnE "$@" "${files[@]}" ; then + ret=1 + fi +} + +# Run some tests. + +banner "Check for trailing whitespace." +do_grep '[[:space:]]+$' + +banner "Check for Windows line endings." +do_grep $'\r$' + +banner "Checking trailing lines." +"${TEST_DIR}"/whitespace.py "${files[@]}" + +exit ${ret} diff --git a/tests/source/whitespace.py b/tests/source/whitespace.py new file mode 100755 index 0000000..2d979fd --- /dev/null +++ b/tests/source/whitespace.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""Helper for checking whitespace. + +These operations aren't easy to do in pure shell. +""" + +from __future__ import print_function + +import sys + + +def check(path): + with open(path, 'rb') as fp: + # Skip 0 byte files. + first_byte = fp.read(1) + if not first_byte: + return 0 + + # Check for leading blank lines. + if b'\n' == first_byte: + print('%s: trim leading blank lines' % (path,), file=sys.stderr) + return 1 + + # Check for missing trailing new line. + fp.seek(-1, 2) + if b'\n' != fp.read(1): + print('%s: missing trailing new line' % (path,), file=sys.stderr) + return 1 + elif fp.tell() == 1: + print('%s: dummy file' % (path,), file=sys.stderr) + return 1 + + # Check for trailing blank lines. + fp.seek(-2, 2) + if b'\n\n' == fp.read(2): + print('%s: trim trailing blank lines' % (path,), file=sys.stderr) + return 1 + + return 0 + + +def main(argv): + ret = 0 + for path in argv: + ret |= check(path) + return ret + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/tests/tga/.gitignore b/tests/tga/.gitignore index 7a659b1..cf0556b 100644 --- a/tests/tga/.gitignore +++ b/tests/tga/.gitignore @@ -3,5 +3,6 @@ /bug00247a /bug00248 /bug00248a +/heap_overflow /tga_null /tga_read diff --git a/tests/tga/CMakeLists.txt b/tests/tga/CMakeLists.txt index 789fb14..ca191a6 100644 --- a/tests/tga/CMakeLists.txt +++ b/tests/tga/CMakeLists.txt @@ -1,11 +1,17 @@ LIST(APPEND TESTS_FILES - tga_null bug00084 bug00247 bug00247a bug00248 bug00248a + heap_overflow + tga_null +) + +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES tga_read ) +ENDIF(PNG_FOUND) ADD_GD_TESTS() diff --git a/tests/tga/Makemodule.am b/tests/tga/Makemodule.am index a1e6af6..091e3be 100644 --- a/tests/tga/Makemodule.am +++ b/tests/tga/Makemodule.am @@ -4,8 +4,13 @@ libgd_test_programs += \ tga/bug00247a \ tga/bug00248 \ tga/bug00248a \ - tga/tga_null \ + tga/heap_overflow \ + tga/tga_null + +if HAVE_LIBPNG +libgd_test_programs += \ tga/tga_read +endif EXTRA_DIST += \ tga/CMakeLists.txt \ @@ -14,6 +19,8 @@ EXTRA_DIST += \ tga/bug00247a.tga \ tga/bug00248.tga \ tga/bug00248a.tga \ + tga/heap_overflow_1.tga \ + tga/heap_overflow_2.tga \ tga/tga_read_rgb.png \ tga/tga_read_rgb.tga \ tga/tga_read_rgb_rle.tga diff --git a/tests/tga/heap_overflow.c b/tests/tga/heap_overflow.c new file mode 100644 index 0000000..ddd4b63 --- /dev/null +++ b/tests/tga/heap_overflow.c @@ -0,0 +1,59 @@ +/** + * Test that crafted TGA files don't trigger OOB reads. + */ + + +#include "gd.h" +#include "gdtest.h" + + +static void check_file(char *basename); +static size_t read_test_file(char **buffer, char *basename); + + +int main() +{ + check_file("heap_overflow_1.tga"); + check_file("heap_overflow_2.tga"); + + return gdNumFailures(); +} + + +static void check_file(char *basename) +{ + gdImagePtr im; + char *buffer; + size_t size; + + size = read_test_file(&buffer, basename); + im = gdImageCreateFromTgaPtr(size, (void *) buffer); + gdTestAssert(im == NULL); + free(buffer); +} + + +static size_t read_test_file(char **buffer, char *basename) +{ + char *filename; + FILE *fp; + size_t exp_size, act_size; + + filename = gdTestFilePath2("tga", basename); + fp = fopen(filename, "rb"); + gdTestAssert(fp != NULL); + + fseek(fp, 0, SEEK_END); + exp_size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + *buffer = malloc(exp_size); + gdTestAssert(*buffer != NULL); + act_size = fread(*buffer, sizeof(**buffer), exp_size, fp); + gdTestAssert(act_size == exp_size); + + fclose(fp); + free(filename); + + return act_size; +} diff --git a/tests/tga/heap_overflow.tga b/tests/tga/heap_overflow.tga Binary files differnew file mode 100644 index 0000000..e9bc0ec --- /dev/null +++ b/tests/tga/heap_overflow.tga diff --git a/tests/tga/heap_overflow_1.tga b/tests/tga/heap_overflow_1.tga Binary files differnew file mode 100644 index 0000000..e9bc0ec --- /dev/null +++ b/tests/tga/heap_overflow_1.tga diff --git a/tests/tga/heap_overflow_2.tga b/tests/tga/heap_overflow_2.tga Binary files differnew file mode 100644 index 0000000..2b681f2 --- /dev/null +++ b/tests/tga/heap_overflow_2.tga diff --git a/tests/tiff/.gitignore b/tests/tiff/.gitignore index 7cf35ee..5f4eb55 100644 --- a/tests/tiff/.gitignore +++ b/tests/tiff/.gitignore @@ -1,3 +1,5 @@ /tiff_dpi /tiff_im2im /tiff_null +/tiff_invalid_read +/tiff_read_bw diff --git a/tests/tiff/CMakeLists.txt b/tests/tiff/CMakeLists.txt index 03f630c..b1ce8a8 100644 --- a/tests/tiff/CMakeLists.txt +++ b/tests/tiff/CMakeLists.txt @@ -1,9 +1,16 @@ IF(TIFF_FOUND) LIST(APPEND TESTS_FILES tiff_im2im + tiff_invalid_read tiff_null tiff_dpi ) + +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + tiff_read_bw +) +ENDIF(PNG_FOUND) ENDIF(TIFF_FOUND) ADD_GD_TESTS() diff --git a/tests/tiff/Makemodule.am b/tests/tiff/Makemodule.am index fd39699..a136439 100644 --- a/tests/tiff/Makemodule.am +++ b/tests/tiff/Makemodule.am @@ -2,8 +2,19 @@ if HAVE_LIBTIFF libgd_test_programs += \ tiff/tiff_dpi \ tiff/tiff_im2im \ + tiff/tiff_invalid_read \ tiff/tiff_null + +if HAVE_LIBPNG +libgd_test_programs += \ + tiff/tiff_read_bw +endif endif EXTRA_DIST += \ - tiff/CMakeLists.txt + tiff/CMakeLists.txt \ + tiff/tiff_invalid_read_1.tiff \ + tiff/tiff_invalid_read_2.tiff \ + tiff/tiff_invalid_read_3.tiff \ + tiff/tiff_read_bw.tiff \ + tiff/tiff_read_bw_exp.png diff --git a/tests/tiff/tiff_dpi.c b/tests/tiff/tiff_dpi.c index d639839..7362646 100644 --- a/tests/tiff/tiff_dpi.c +++ b/tests/tiff/tiff_dpi.c @@ -1,16 +1,9 @@ -/* +/* * Test that reading and writing image resolution values to/from TIFF files * works correctly. Set the image resolution, write the file, read the file * back and test that the image resolution comes back correct. */ -#ifdef _WIN32 -#include <stdio.h> -int main() -{ - printf("skip"); - return 0; -} -#else + #include "gd.h" #include "gdtest.h" @@ -30,7 +23,7 @@ int main() r = gdImageColorAllocate(src, 0xFF, 0, 0); gdImageFilledRectangle(src, 0, 0, 99, 99, r); - // gd default DPI is 96; libtiff default is 72. + // gd default DPI is 96; libtiff default is 72. // Use something else so we know the value has been // written / read correctly. res_x = 100; @@ -81,4 +74,3 @@ door0: gdImageDestroy(src); return status; } -#endif diff --git a/tests/tiff/tiff_im2im.c b/tests/tiff/tiff_im2im.c index b6b240e..7b6c4cb 100644 --- a/tests/tiff/tiff_im2im.c +++ b/tests/tiff/tiff_im2im.c @@ -1,11 +1,3 @@ -#ifdef _WIN32 -#include <stdio.h> -int main() -{ - printf("skip"); - return 0; -} -#else #include "gd.h" #include "gdtest.h" @@ -70,4 +62,3 @@ door0: gdImageDestroy(src); return status; } -#endif
\ No newline at end of file diff --git a/tests/tiff/tiff_invalid_read.c b/tests/tiff/tiff_invalid_read.c new file mode 100644 index 0000000..bed5389 --- /dev/null +++ b/tests/tiff/tiff_invalid_read.c @@ -0,0 +1,61 @@ +/* +We're testing that reading corrupt TIFF files doesn't cause any memory issues, +and that the operation gracefully fails (i.e. gdImageCreateFromTiffPtr() returns +NULL). +*/ + +#include "gd.h" +#include "gdtest.h" + + +static void check_file(char *basename); +static size_t read_test_file(char **buffer, char *basename); + + +int main() +{ + check_file("tiff_invalid_read_1.tiff"); + check_file("tiff_invalid_read_2.tiff"); + check_file("tiff_invalid_read_3.tiff"); + + return gdNumFailures(); +} + + +static void check_file(char *basename) +{ + gdImagePtr im; + char *buffer; + size_t size; + + size = read_test_file(&buffer, basename); + im = gdImageCreateFromTiffPtr(size, (void *) buffer); + gdTestAssert(im == NULL); + free(buffer); +} + + +static size_t read_test_file(char **buffer, char *basename) +{ + char *filename; + FILE *fp; + size_t exp_size, act_size; + + filename = gdTestFilePath2("tiff", basename); + fp = fopen(filename, "rb"); + gdTestAssert(fp != NULL); + + fseek(fp, 0, SEEK_END); + exp_size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + *buffer = malloc(exp_size); + gdTestAssert(*buffer != NULL); + act_size = fread(*buffer, sizeof(**buffer), exp_size, fp); + gdTestAssert(act_size == exp_size); + + fclose(fp); + free(filename); + + return act_size; +} diff --git a/tests/tiff/tiff_invalid_read_1.tiff b/tests/tiff/tiff_invalid_read_1.tiff Binary files differnew file mode 100644 index 0000000..b3877e3 --- /dev/null +++ b/tests/tiff/tiff_invalid_read_1.tiff diff --git a/tests/tiff/tiff_invalid_read_2.tiff b/tests/tiff/tiff_invalid_read_2.tiff Binary files differnew file mode 100644 index 0000000..f9967e5 --- /dev/null +++ b/tests/tiff/tiff_invalid_read_2.tiff diff --git a/tests/tiff/tiff_invalid_read_3.tiff b/tests/tiff/tiff_invalid_read_3.tiff Binary files differnew file mode 100644 index 0000000..67ca2a7 --- /dev/null +++ b/tests/tiff/tiff_invalid_read_3.tiff diff --git a/tests/tiff/tiff_null.c b/tests/tiff/tiff_null.c index 19b64f7..ccaade7 100644 --- a/tests/tiff/tiff_null.c +++ b/tests/tiff/tiff_null.c @@ -1,11 +1,3 @@ -#ifdef _WIN32 -#include <stdio.h> -int main() -{ - printf("skip"); - return 0; -} -#else #include "gd.h" int main() @@ -20,4 +12,3 @@ int main() gdImageTiff(im, NULL); /* noop safely */ return 0; } -#endif
\ No newline at end of file diff --git a/tests/tiff/tiff_read_bw.c b/tests/tiff/tiff_read_bw.c new file mode 100644 index 0000000..93b646d --- /dev/null +++ b/tests/tiff/tiff_read_bw.c @@ -0,0 +1,25 @@ +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + char *path; + + fp = gdTestFileOpen2("tiff", "tiff_read_bw.tiff"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromTiff(fp); + fclose(fp); + + gdTestAssert(im != NULL); + gdTestAssert(!gdImageTrueColor(im)); + + path = gdTestFilePath2("tiff", "tiff_read_bw_exp.png"); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/tiff/tiff_read_bw.tiff b/tests/tiff/tiff_read_bw.tiff Binary files differnew file mode 100644 index 0000000..69813f0 --- /dev/null +++ b/tests/tiff/tiff_read_bw.tiff diff --git a/tests/tiff/tiff_read_bw_exp.png b/tests/tiff/tiff_read_bw_exp.png Binary files differnew file mode 100644 index 0000000..b43daf9 --- /dev/null +++ b/tests/tiff/tiff_read_bw_exp.png diff --git a/tests/wbmp/CMakeLists.txt b/tests/wbmp/CMakeLists.txt index 787227c..4ec45bd 100644 --- a/tests/wbmp/CMakeLists.txt +++ b/tests/wbmp/CMakeLists.txt @@ -1,6 +1,6 @@ LIST(APPEND TESTS_FILES - wbmp_im2im wbmp_null + wbmp_im2im ) ADD_GD_TESTS() diff --git a/tests/wbmp/Makemodule.am b/tests/wbmp/Makemodule.am index fb12272..37f09e1 100644 --- a/tests/wbmp/Makemodule.am +++ b/tests/wbmp/Makemodule.am @@ -1,10 +1,6 @@ libgd_test_programs += \ - wbmp/wbmp_null - -if HAVE_LIBPNG -libgd_test_programs += \ + wbmp/wbmp_null \ wbmp/wbmp_im2im -endif EXTRA_DIST += \ wbmp/CMakeLists.txt diff --git a/tests/webp/.gitignore b/tests/webp/.gitignore index f5816bc..b167630 100644 --- a/tests/webp/.gitignore +++ b/tests/webp/.gitignore @@ -1,2 +1,4 @@ /bug00111 +/bug_double_free /webp_ll_im2im +/gdImageWebpEx diff --git a/tests/webp/CMakeLists.txt b/tests/webp/CMakeLists.txt index e114f80..6a4431c 100644 --- a/tests/webp/CMakeLists.txt +++ b/tests/webp/CMakeLists.txt @@ -1,8 +1,14 @@ IF(WEBP_FOUND) LIST(APPEND TESTS_FILES bug00111 + gdImageWebpEx webp_ll_im2im ) +IF(JPEG_FOUND) +LIST(APPEND TESTS_FILES + bug_double_free +) +ENDIF(JPEG_FOUND) ENDIF(WEBP_FOUND) ADD_GD_TESTS() diff --git a/tests/webp/Makemodule.am b/tests/webp/Makemodule.am index 741e8f2..c6c9528 100644 --- a/tests/webp/Makemodule.am +++ b/tests/webp/Makemodule.am @@ -1,8 +1,14 @@ if HAVE_LIBWEBP libgd_test_programs += \ webp/bug00111 \ + webp/gdImageWebpEx \ webp/webp_ll_im2im +if HAVE_LIBJPEG +libgd_test_programs += \ + webp/bug_double_free +endif endif EXTRA_DIST += \ - webp/CMakeLists.txt + webp/CMakeLists.txt \ + webp/bug_double_free.jpg diff --git a/tests/webp/bug_double_free.c b/tests/webp/bug_double_free.c new file mode 100644 index 0000000..43eecec --- /dev/null +++ b/tests/webp/bug_double_free.c @@ -0,0 +1,29 @@ +/** + * Test that a too large image doesn't trigger an double-free when written + * to memory. + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im1, im2; + FILE *fp; + int size; + + fp = gdTestFileOpen2("webp", "bug_double_free.jpg"); + gdTestAssert(fp != NULL); + im1 = gdImageCreateFromJpeg(fp); + gdTestAssert(im1 != NULL); + fclose(fp); + + im2 = gdImageWebpPtr(im1, &size); + gdTestAssert(im2 == NULL); + + gdImageDestroy(im1); + + return gdNumFailures(); +} diff --git a/tests/webp/bug_double_free.jpg b/tests/webp/bug_double_free.jpg Binary files differnew file mode 100644 index 0000000..9b792fb --- /dev/null +++ b/tests/webp/bug_double_free.jpg diff --git a/tests/webp/gdImageWebpEx.c b/tests/webp/gdImageWebpEx.c new file mode 100644 index 0000000..43011de --- /dev/null +++ b/tests/webp/gdImageWebpEx.c @@ -0,0 +1,26 @@ +/** + * Basic testcase for gdImageWebpEx() + **/ +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp1; + int size = 1; + + im = gdImageCreateTrueColor(20, 20); + if (!im) { + return 1; + } + + fp1 = gdTestTempFp(); + gdImageWebpEx(im, fp1, 8); + gdImageWebpPtrEx(im, &size, 9); + + fclose(fp1); + + gdImageDestroy(im); + return 0; +} diff --git a/tests/xbm/.gitignore b/tests/xbm/.gitignore index 313d503..8a2565a 100644 --- a/tests/xbm/.gitignore +++ b/tests/xbm/.gitignore @@ -1 +1,4 @@ +/github_bug_109 /github_bug_170 +/github_bug_501 +/x10_basic_read diff --git a/tests/xbm/CMakeLists.txt b/tests/xbm/CMakeLists.txt index 183cf5e..2447fd5 100644 --- a/tests/xbm/CMakeLists.txt +++ b/tests/xbm/CMakeLists.txt @@ -1,5 +1,13 @@ LIST(APPEND TESTS_FILES + github_bug_501 github_bug_170 ) +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + github_bug_109 + x10_basic_read +) +ENDIF(PNG_FOUND) + ADD_GD_TESTS() diff --git a/tests/xbm/Makemodule.am b/tests/xbm/Makemodule.am index ba1eabd..4d14916 100644 --- a/tests/xbm/Makemodule.am +++ b/tests/xbm/Makemodule.am @@ -1,5 +1,17 @@ libgd_test_programs += \ + xbm/github_bug_501 \ xbm/github_bug_170 +if HAVE_LIBPNG +libgd_test_programs += \ + xbm/github_bug_109 \ + xbm/x10_basic_read +endif + EXTRA_DIST += \ - xbm/CMakeLists.txt + xbm/CMakeLists.txt \ + xbm/github_bug_109.xbm \ + xbm/github_bug_109_exp.png \ + xbm/x10_basic_read.xbm \ + xbm/x10_basic_read_exp.png \ + xbm/github_bug_501.xbm diff --git a/tests/xbm/github_bug_109.c b/tests/xbm/github_bug_109.c new file mode 100644 index 0000000..70b7937 --- /dev/null +++ b/tests/xbm/github_bug_109.c @@ -0,0 +1,33 @@ +/** + * Test reading of XBM images with a width that is not a multiple of 8 + * + * We're reading such an XBM image, and check that we got what we've expected, + * instead of an error message. + * + * See also <https://github.com/libgd/libgd/issues/109>. + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + char *path; + + fp = gdTestFileOpen2("xbm", "github_bug_109.xbm"); + im = gdImageCreateFromXbm(fp); + fclose(fp); + gdTestAssert(im != NULL); + gdTestAssert(gdImageGetTrueColorPixel(im, 0, 0) == 0); + gdTestAssert(gdImageGetTrueColorPixel(im, 0, 1) == 0xffffff); + + path = gdTestFilePath2("xbm", "github_bug_109_exp.png"); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/xbm/github_bug_109.xbm b/tests/xbm/github_bug_109.xbm new file mode 100644 index 0000000..f427d86 --- /dev/null +++ b/tests/xbm/github_bug_109.xbm @@ -0,0 +1,5 @@ +#define test_width 10 +#define test_height 10 +static unsigned char test_bits[] = { + 0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, + 0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00}; diff --git a/tests/xbm/github_bug_109_exp.png b/tests/xbm/github_bug_109_exp.png Binary files differnew file mode 100644 index 0000000..505b545 --- /dev/null +++ b/tests/xbm/github_bug_109_exp.png diff --git a/tests/xbm/github_bug_170.c b/tests/xbm/github_bug_170.c index 3900da7..8134fb8 100644 --- a/tests/xbm/github_bug_170.c +++ b/tests/xbm/github_bug_170.c @@ -47,4 +47,4 @@ int main() gdTestAssertMsg(length == 250, "expected to write 250 bytes; %jd bytes written", (intmax_t) length); return gdNumFailures(); } -#endif
\ No newline at end of file +#endif diff --git a/tests/xbm/github_bug_501.c b/tests/xbm/github_bug_501.c new file mode 100644 index 0000000..5d8bfd7 --- /dev/null +++ b/tests/xbm/github_bug_501.c @@ -0,0 +1,39 @@ +/* + Test reading an invalid XBM image. + + The pixels of the XBM image are invalid hex which makes the uninitialezed + variable be encoded into the output image i.e. information disclosure. + The image is 8*2. + + See also <https://github.com/libgd/libgd/issues/501>. +*/ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("xbm", "github_bug_501.xbm"); + im = gdImageCreateFromXbm(fp); + + gdTestAssert(im == NULL); + + if (im) { + gdTestErrorMsg("Info Disclosed\n"); + int i; + for (i = 0; i < 8; i++) { + printf("Pixel(%d, 0) %0x\n", i, gdImageGetPixel(im, i, 0)); + } + for (i = 0; i < 8; i++) { + printf("Pixel(%d, 1) %0x\n", i, gdImageGetPixel(im, i, 1)); + } + gdImageDestroy(im); + } + + fclose(fp); + return gdNumFailures(); +} diff --git a/tests/xbm/github_bug_501.xbm b/tests/xbm/github_bug_501.xbm new file mode 100644 index 0000000..41ad301 --- /dev/null +++ b/tests/xbm/github_bug_501.xbm @@ -0,0 +1,4 @@ +#define width 8 +#define height 2 +static char bits[] ={ +xzzxzz diff --git a/tests/xbm/x10_basic_read.c b/tests/xbm/x10_basic_read.c new file mode 100644 index 0000000..f7c505e --- /dev/null +++ b/tests/xbm/x10_basic_read.c @@ -0,0 +1,30 @@ +/** + * Test reading of an X10 style XBM file + * + * X10 style XBMs define a short[] instead of a char[] array. We're testing + * that such files are read correctly, particularly regarding the line padding, + * which is 2 bytes instead of 1, and the endianess. + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + char *path; + + fp = gdTestFileOpen2("xbm", "x10_basic_read.xbm"); + im = gdImageCreateFromXbm(fp); + fclose(fp); + gdTestAssert(im != NULL); + + path = gdTestFilePath2("xbm", "x10_basic_read_exp.png"); + gdAssertImageEqualsToFile(path, im); + gdFree(path); + + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/xbm/x10_basic_read.xbm b/tests/xbm/x10_basic_read.xbm new file mode 100644 index 0000000..d8ca2cd --- /dev/null +++ b/tests/xbm/x10_basic_read.xbm @@ -0,0 +1,4 @@ +#define x10_basic_read_width 17 +#define x10_basic_read_height 3 +static unsigned short x10_basic_read_bits[] = { + 0xFFFF, 0x0001, 0x0000, 0x0000, 0xFFFF, 0x0001}; diff --git a/tests/xbm/x10_basic_read_exp.png b/tests/xbm/x10_basic_read_exp.png Binary files differnew file mode 100644 index 0000000..fbcdf0c --- /dev/null +++ b/tests/xbm/x10_basic_read_exp.png |