diff options
author | Pierre Joye <pierre.php@gmail.com> | 2016-07-19 14:46:08 +0700 |
---|---|---|
committer | Pierre Joye <pierre.php@gmail.com> | 2016-07-19 14:46:08 +0700 |
commit | add47339448abb1141c9c279706037203d0a52ba (patch) | |
tree | 428192fed7c840fa88bca4216b81d37eb8097a62 /tests | |
parent | 0dd40abd6d5b3e53a6b745dd4d6cf94b70010989 (diff) | |
parent | d818ff9391546f9f89c832410afe1b5cb8845cc6 (diff) | |
download | libgd-add47339448abb1141c9c279706037203d0a52ba.tar.gz |
Merge branch 'master' of github.com:libgd/libgd
Diffstat (limited to 'tests')
71 files changed, 783 insertions, 222 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 369dec7..a115e6f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -50,6 +50,7 @@ if (BUILD_TEST) gdimagesetpixel gdimagestringft gdimagestringftex + gdimagetruecolortopalette gdinterpolatedscale gdnewfilectx gdtest diff --git a/tests/Makefile.am b/tests/Makefile.am index 5a0ebe8..e2de2c5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -44,6 +44,7 @@ include gdimagescatterex/Makemodule.am include gdimagesetpixel/Makemodule.am include gdimagestringft/Makemodule.am include gdimagestringftex/Makemodule.am +include gdimagetruecolortopalette/Makemodule.am include gdinterpolatedscale/Makemodule.am include gdnewfilectx/Makemodule.am include gdtest/Makemodule.am diff --git a/tests/bmp/bmp_im2im.c b/tests/bmp/bmp_im2im.c index 00e2123..692588c 100644 --- a/tests/bmp/bmp_im2im.c +++ b/tests/bmp/bmp_im2im.c @@ -12,7 +12,7 @@ int main() src = gdImageCreate(100, 100); if (src == NULL) { - printf("could not create src\n"); + gdTestErrorMsg("could not create src\n"); return 1; } r = gdImageColorAllocate(src, 0xFF, 0, 0); @@ -32,26 +32,26 @@ int main() p = gdImageBmpPtr(src, &size, 1); if (p == NULL) { status = 1; - printf("p is null\n"); + gdTestErrorMsg("p is null\n"); goto door0; } if (size <= 0) { status = 1; - printf("size is non-positive\n"); + gdTestErrorMsg("size is non-positive\n"); goto door1; } dst = gdImageCreateFromBmpPtr(size, p); if (dst == NULL) { status = 1; - printf("could not create dst\n"); + gdTestErrorMsg("could not create dst\n"); goto door1; } OUTPUT_BMP(dst); gdTestImageDiff(src, dst, NULL, &result); if (result.pixels_changed > 0) { status = 1; - printf("pixels changed: %d\n", result.pixels_changed); + gdTestErrorMsg("pixels changed: %d\n", result.pixels_changed); } gdImageDestroy(dst); door1: diff --git a/tests/freetype/bug00132.c b/tests/freetype/bug00132.c index da0585e..2c3d6bc 100644 --- a/tests/freetype/bug00132.c +++ b/tests/freetype/bug00132.c @@ -1,5 +1,3 @@ -/* $Id$ */ - #include "gd.h" #include <stdio.h> #include <stdlib.h> @@ -16,7 +14,7 @@ int main() im = gdImageCreateTrueColor(50, 30); if (!im) { - printf("can't get truecolor image\n"); + gdTestErrorMsg("can't get truecolor image\n"); return 1; } @@ -28,11 +26,11 @@ int main() free(path); if (ret) { error = 1; - printf("%s\n", ret); + gdTestErrorMsg("%s\n", ret); } else { if (!gdAssertImageEqualsToFile("freetype/bug00132_exp.png", im)) { error = 1; - printf("Reference image and destination differ\n"); + gdTestErrorMsg("Reference image and destination differ\n"); } } gdImageDestroy(im); diff --git a/tests/gd/gd_im2im.c b/tests/gd/gd_im2im.c index 990605d..385e503 100644 --- a/tests/gd/gd_im2im.c +++ b/tests/gd/gd_im2im.c @@ -12,7 +12,7 @@ int main() src = gdImageCreate(100, 100); if (src == NULL) { - printf("could not create src\n"); + gdTestErrorMsg("could not create src\n"); return 1; } r = gdImageColorAllocate(src, 0xFF, 0, 0); @@ -32,26 +32,26 @@ int main() p = gdImageGdPtr(src, &size); if (p == NULL) { status = 1; - printf("p is null\n"); + gdTestErrorMsg("p is null\n"); goto door0; } if (size <= 0) { status = 1; - printf("size is non-positive\n"); + gdTestErrorMsg("size is non-positive\n"); goto door1; } dst = gdImageCreateFromGdPtr(size, p); if (dst == NULL) { status = 1; - printf("could not create dst\n"); + gdTestErrorMsg("could not create dst\n"); goto door1; } OUTPUT_GD(dst); gdTestImageDiff(src, dst, NULL, &result); if (result.pixels_changed > 0) { status = 1; - printf("pixels changed: %d\n", result.pixels_changed); + gdTestErrorMsg("pixels changed: %d\n", result.pixels_changed); } gdImageDestroy(dst); door1: diff --git a/tests/gd2/CMakeLists.txt b/tests/gd2/CMakeLists.txt index b13489a..1e1e117 100644 --- a/tests/gd2/CMakeLists.txt +++ b/tests/gd2/CMakeLists.txt @@ -3,6 +3,8 @@ LIST(APPEND TESTS_FILES gd2_im2im gd2_null php_bug_72339 + gd2_read + gd2_read_corrupt ) ADD_GD_TESTS() diff --git a/tests/gd2/Makemodule.am b/tests/gd2/Makemodule.am index a8b6981..4c01990 100644 --- a/tests/gd2/Makemodule.am +++ b/tests/gd2/Makemodule.am @@ -1,37 +1,25 @@ -libgd_helper_programs += \ - gd2/gd2_read \ - gd2/gd2_read_corrupt - libgd_test_programs += \ gd2/gd2_empty_file \ - gd2/php_bug_72339 -TESTS += \ - gd2/invalid_header.sh + gd2/php_bug_72339 \ + gd2/gd2_read_corrupt if HAVE_LIBZ libgd_test_programs += \ gd2/gd2_null -TESTS += \ - gd2/invalid_neg_size.sh if HAVE_LIBPNG libgd_test_programs += \ - gd2/gd2_im2im -TESTS += \ - gd2/conv_test.sh + gd2/gd2_im2im \ + gd2/gd2_read endif - endif EXTRA_DIST += \ gd2/CMakeLists.txt \ gd2/conv_gd2_exp.gd2 \ gd2/conv_test.gd2 \ - gd2/conv_test.sh \ gd2/conv_test_exp.png \ gd2/empty.gd2 \ gd2/invalid_header.gd2 \ - gd2/invalid_header.sh \ gd2/invalid_neg_size.gd2 \ - gd2/invalid_neg_size.sh \ gd2/php_bug_72339_exp.gd2 diff --git a/tests/gd2/conv_test.sh b/tests/gd2/conv_test.sh deleted file mode 100755 index 20a5dcc..0000000 --- a/tests/gd2/conv_test.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -x -base=${0%.sh} -input="${base}.gd2" -exp="${base}_exp.png" -exec ./gd2/gd2_read "${input}" "${exp}" diff --git a/tests/gd2/gd2_empty_file.c b/tests/gd2/gd2_empty_file.c index c9ae9b6..9b1c5b2 100644 --- a/tests/gd2/gd2_empty_file.c +++ b/tests/gd2/gd2_empty_file.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include <stdio.h> #include <stdlib.h> diff --git a/tests/gd2/gd2_im2im.c b/tests/gd2/gd2_im2im.c index 72e99da..02a4420 100644 --- a/tests/gd2/gd2_im2im.c +++ b/tests/gd2/gd2_im2im.c @@ -12,7 +12,7 @@ int main() src = gdImageCreate(100, 100); if (src == NULL) { - printf("could not create src\n"); + gdTestErrorMsg("could not create src\n"); return 1; } r = gdImageColorAllocate(src, 0xFF, 0, 0); @@ -32,26 +32,26 @@ int main() p = gdImageGd2Ptr(src, (GD2_CHUNKSIZE_MIN+GD2_CHUNKSIZE_MAX)/2, GD2_FMT_COMPRESSED, &size); if (p == NULL) { status = 1; - printf("p is null\n"); + gdTestErrorMsg("p is null\n"); goto door0; } if (size <= 0) { status = 1; - printf("size is non-positive\n"); + gdTestErrorMsg("size is non-positive\n"); goto door1; } dst = gdImageCreateFromGd2Ptr(size, p); if (dst == NULL) { status = 1; - printf("could not create dst\n"); + gdTestErrorMsg("could not create dst\n"); goto door1; } OUTPUT_GD2(dst); gdTestImageDiff(src, dst, NULL, &result); if (result.pixels_changed > 0) { status = 1; - printf("pixels changed: %d\n", result.pixels_changed); + gdTestErrorMsg("pixels changed: %d\n", result.pixels_changed); } gdImageDestroy(dst); door1: diff --git a/tests/gd2/gd2_read.c b/tests/gd2/gd2_read.c index 7f3ee50..94fe069 100644 --- a/tests/gd2/gd2_read.c +++ b/tests/gd2/gd2_read.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include <stdio.h> #include <stdlib.h> @@ -6,38 +5,58 @@ int main(int argc, char *argv[]) { - int error; - gdImagePtr im; + int error, i = 0; + gdImagePtr im, exp; FILE *fp; - char *inpath, *exppath; - - if (argc != 3) { - printf("Usage: %s <input gd2> <expected png>\n", argv[0]); - return 1; - } - - inpath = argv[1]; - exppath = argv[2]; - - fp = fopen(inpath, "rb"); - if (!fp) { - printf("failed, cannot open file: %s\n", inpath); - return 1; - } - - im = gdImageCreateFromGd2(fp); - fclose(fp); + char *path[] = { + "conv_test.gd2", + "invalid_neg_size.gd2", + "invalid_header.gd2", + NULL + }; + char *path_exp[] = { + "conv_test_exp.png", + NULL, + NULL, + NULL + }; + while (path[i] != NULL) { + fp = gdTestFileOpen2("gd2", path[i]); + if (!fp) { + gdTestErrorMsg("failed, cannot open file: %s\n", path[0]); + return 1; + } + im = gdImageCreateFromGd2(fp); + fclose(fp); - if (!gdAssertImageEqualsToFile(exppath, im)) { - error = 1; - gdImageDestroy(im); - } else { - if (im) { - gdImageDestroy(im); - error = 0; + if (path_exp[i] != NULL) { + fp = gdTestFileOpen2("gd2", path_exp[i]); + if (!fp) { + gdTestErrorMsg("failed, cannot open file: %s\n", path_exp[i]); + return 1; + } + exp = gdImageCreateFromPng(fp); + if (!gdAssertImageEquals(exp, im)) { + gdTestErrorMsg("image %s differs from expected result\n", path[i]); + gdImageDestroy(im); + error = 1; + } else { + error = 0; + } + if (exp) { + gdImageDestroy(exp); + } } else { - error = 1; + /* expected to fail */ + if (im) { + gdTestErrorMsg("image %s should have failed to be loaded\n", path[i]); + gdImageDestroy(im); + error = 1; + } else { + error = 0; + } } + i++; } return error; } diff --git a/tests/gd2/gd2_read_corrupt.c b/tests/gd2/gd2_read_corrupt.c index 82b9587..7afc303 100644 --- a/tests/gd2/gd2_read_corrupt.c +++ b/tests/gd2/gd2_read_corrupt.c @@ -8,23 +8,21 @@ int main(int argc, char *argv[]) { gdImagePtr im; FILE *fp; - char *inpath; - if (argc != 2) { - printf("Usage: %s <input gd2>\n", argv[0]); - return 1; - } + fp = gdTestFileOpen2("gd2", "invalid_header.gd2"); - /* Read the corrupt image. */ - inpath = argv[1]; - fp = fopen(inpath, "rb"); if (!fp) { - printf("failed, cannot open file: %s\n", inpath); + gdTestErrorMsg("failed, cannot open file: %s\n", "invalid_header.gd2"); return 1; } im = gdImageCreateFromGd2(fp); fclose(fp); - /* Should have failed & rejected it. */ - return im == NULL ? 0 : 1; + if (im != NULL) { + gdTestErrorMsg("image should have failed to be loaded\n"); + gdImageDestroy(im); + return 1; + } else { + return 0; + } } diff --git a/tests/gd2/invalid_header.sh b/tests/gd2/invalid_header.sh deleted file mode 100755 index 733d9ce..0000000 --- a/tests/gd2/invalid_header.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -x -base=${0%.sh} -input="${base}.gd2" -exec ./gd2/gd2_read_corrupt "${input}" diff --git a/tests/gd2/invalid_neg_size.sh b/tests/gd2/invalid_neg_size.sh deleted file mode 100755 index 733d9ce..0000000 --- a/tests/gd2/invalid_neg_size.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -x -base=${0%.sh} -input="${base}.gd2" -exec ./gd2/gd2_read_corrupt "${input}" diff --git a/tests/gd2/php_bug_72339.c b/tests/gd2/php_bug_72339.c index f421e72..e15383e 100644 --- a/tests/gd2/php_bug_72339.c +++ b/tests/gd2/php_bug_72339.c @@ -8,8 +8,8 @@ int main() { gdImagePtr im; FILE *fp; - - fp = gdTestFileOpen("gdimagerotate/php_bug_64898.png"); + + fp = gdTestFileOpen2("gd2", "php_bug_72339_exp.gd2"); im = gdImageCreateFromGd2(fp); if (im == NULL) { return 0; diff --git a/tests/gdimagecolorreplace/gdimagecolorreplace.c b/tests/gdimagecolorreplace/gdimagecolorreplace.c index d4fe923..102a674 100644 --- a/tests/gdimagecolorreplace/gdimagecolorreplace.c +++ b/tests/gdimagecolorreplace/gdimagecolorreplace.c @@ -44,22 +44,22 @@ static void run_tests(gdImagePtr im, int *error) COLOR(yellow, 0xFF, 0xFF, 0); #undef COLOR -#define CHECK_VALUE(n, expected) do { \ - if (gdTestAssert((n) == (expected)) != 1) { \ - printf("%d is expected, but %d\n", expected, n); \ - *error = -1; \ - } \ +#define CHECK_VALUE(n, expected) do { \ + if (gdTestAssert((n) == (expected)) != 1) { \ + gdTestErrorMsg("%d is expected, but %d\n", expected, n);\ + *error = -1; \ + } \ } while (0) #define CHECK_PIXEL(x, y, expected) \ - do { \ - int pix; \ - gdImageSetClip(im, 0, 0, 4, 4); \ - pix = gdImageGetPixel(im, (x), (y)); \ - if (gdTestAssert(pix == (expected)) != 1) { \ - printf("%d is expected, but %d\n", expected, pix); \ - *error = -1; \ - } \ + do { \ + int pix; \ + gdImageSetClip(im, 0, 0, 4, 4); \ + pix = gdImageGetPixel(im, (x), (y)); \ + if (gdTestAssert(pix == (expected)) != 1) { \ + gdTestErrorMsg("%d is expected, but %d\n", expected, pix); \ + *error = -1; \ + } \ } while (0) c = gdImageColorAllocate(im, 0xFF, 0, 0xFF); diff --git a/tests/gdimagecopy/bug00081.c b/tests/gdimagecopy/bug00081.c index fb1740c..747e5a2 100644 --- a/tests/gdimagecopy/bug00081.c +++ b/tests/gdimagecopy/bug00081.c @@ -1,5 +1,3 @@ -/* $Id$ */ - #include "gd.h" #include <stdio.h> #include <stdlib.h> @@ -12,7 +10,7 @@ int main() im = gdImageCreateTrueColor(5, 5); if (!im) { - printf("can't create the src truecolor image\n"); + gdTestErrorMsg("can't create the src truecolor image\n"); return 1; } @@ -22,7 +20,7 @@ int main() im2 = gdImageCreateTrueColor(20, 20); if (!im2) { - printf("can't create the dst truecolor image\n"); + gdTestErrorMsg("can't create the dst truecolor image\n"); gdImageDestroy(im); return 1; } @@ -31,7 +29,7 @@ int main() if (!gdAssertImageEqualsToFile("gdimagecopy/bug00081_exp.png", im2)) { error = 1; - printf("Reference image and destination differ\n"); + gdTestErrorMsg("Reference image and destination differ\n"); } gdImageDestroy(im); diff --git a/tests/gdimagecopyrotated/bug00020.c b/tests/gdimagecopyrotated/bug00020.c index 0d833b0..fe8dfdf 100644 --- a/tests/gdimagecopyrotated/bug00020.c +++ b/tests/gdimagecopyrotated/bug00020.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include "gdtest.h" @@ -8,6 +7,7 @@ int main() { gdImagePtr im, im2; int error = 0; + char *path; im = gdImageCreateTrueColor(width, width); gdImageFilledRectangle(im, 0,0, width, width, 0xFF0000); @@ -18,12 +18,13 @@ int main() im2 = gdImageCreateTrueColor(width, width); gdImageCopyRotated(im2, im, width / 2, width / 2, 0,0, width, width, 60); - - if (!gdAssertImageEqualsToFile("gdimagecopyrotated/bug00020_exp.png", im2)) { + path = gdTestFilePath2("gdimagecopyrotated", "bug00020_exp.png"); + if (!gdAssertImageEqualsToFile(path, im2)) { error = 1; } gdImageDestroy(im2); gdImageDestroy(im); + free(path); return error; } diff --git a/tests/gdimagefile/gdnametest.c b/tests/gdimagefile/gdnametest.c index 4b8a267..40dbc30 100644 --- a/tests/gdimagefile/gdnametest.c +++ b/tests/gdimagefile/gdnametest.c @@ -121,9 +121,6 @@ do_test() { gdTestAssertMsg(!!copy, "Failed to load %s\n", full_filename); if (!copy) continue; - /* Debug printf. */ - //printf("%s -> %d\n", full_filename, gdMaxPixelDiff(orig, copy)); - gdTestAssertMsg(gdMaxPixelDiff(orig, copy) <= names[n].maxdiff,"Pixels different on %s\n", full_filename, full_filename); if (!names[n].readonly) { @@ -154,7 +151,7 @@ do_errortest() { }/* do_errortest*/ -int main(int argc, char **argv) +int main() { do_test(); diff --git a/tests/gdimagefill/bug00002_3.c b/tests/gdimagefill/bug00002_3.c index b9fa631..b11fbc9 100644 --- a/tests/gdimagefill/bug00002_3.c +++ b/tests/gdimagefill/bug00002_3.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include <stdio.h> #include "gdtest.h" diff --git a/tests/gdimagefilledellipse/bug00010.c b/tests/gdimagefilledellipse/bug00010.c index 6fead5b..65c7444 100644 --- a/tests/gdimagefilledellipse/bug00010.c +++ b/tests/gdimagefilledellipse/bug00010.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include "gdtest.h" diff --git a/tests/gdimagefilledellipse/bug00191.c b/tests/gdimagefilledellipse/bug00191.c index 2f5c86d..28e3d6c 100644 --- a/tests/gdimagefilledellipse/bug00191.c +++ b/tests/gdimagefilledellipse/bug00191.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include "gdtest.h" diff --git a/tests/gdimagefilltoborder/bug00037.c b/tests/gdimagefilltoborder/bug00037.c index 646adbd..ab7e1b8 100644 --- a/tests/gdimagefilltoborder/bug00037.c +++ b/tests/gdimagefilltoborder/bug00037.c @@ -22,7 +22,7 @@ int main() if (gdTestAssert(color==0x1000000)) { return 0; } else { - printf("c: %X, expected %X\n", color, 0x1000000); + gdTestErrorMsg("c: %X, expected %X\n", color, 0x1000000); return -1; } diff --git a/tests/gdimagefilter/gdCopyBlurred.c b/tests/gdimagefilter/gdCopyBlurred.c index a4442f0..dee2f1f 100644 --- a/tests/gdimagefilter/gdCopyBlurred.c +++ b/tests/gdimagefilter/gdCopyBlurred.c @@ -191,7 +191,7 @@ void do_crosstest() }/* do_crosstest*/ -int main(int argc, char **argv) +int main() { do_test(); diff --git a/tests/gdimageline/bug00111.c b/tests/gdimageline/bug00111.c index 0cf2d34..9b24113 100644 --- a/tests/gdimageline/bug00111.c +++ b/tests/gdimageline/bug00111.c @@ -1,5 +1,3 @@ -/* $Id$ */ - #include "gd.h" #include <stdio.h> #include <stdlib.h> @@ -12,7 +10,7 @@ int main() im = gdImageCreateTrueColor(10, 10); if (!im) { - printf("can't get truecolor image\n"); + gdTestErrorMsg("can't get truecolor image\n"); return 1; } @@ -23,7 +21,7 @@ int main() if (!gdAssertImageEqualsToFile("gdimageline/bug00111_exp.png", im)) { error = 1; - printf("Reference image and destination differ\n"); + gdTestErrorMsg("Reference image and destination differ\n"); } gdImageDestroy(im); diff --git a/tests/gdimageline/gdImageAALine_thickness.c b/tests/gdimageline/gdImageAALine_thickness.c index de9c254..1d3a564 100644 --- a/tests/gdimageline/gdImageAALine_thickness.c +++ b/tests/gdimageline/gdImageAALine_thickness.c @@ -2,7 +2,7 @@ #include "gd.h" #include "gdtest.h" -int main(int argc, char **argv) +int main() { gdImagePtr im; int error = 0; diff --git a/tests/gdimagepixelate/gdimagepixelate.c b/tests/gdimagepixelate/gdimagepixelate.c index 2a0a469..f8e6646 100644 --- a/tests/gdimagepixelate/gdimagepixelate.c +++ b/tests/gdimagepixelate/gdimagepixelate.c @@ -27,28 +27,28 @@ static const int expected_average[][3] = { } \ } while (0) -#define CHECK_PIXELS(im, expected) do { \ - int x, y; \ - for (y = 0; y < (im)->sy; y++) { \ - for (x = 0; x < (im)->sx; x++) { \ - int p = gdImageGetPixel(im, x, y); \ - int r = ((expected)[y/BLOCK_SIZE][x/BLOCK_SIZE]>>16)&0xFF; \ - int g = ((expected)[y/BLOCK_SIZE][x/BLOCK_SIZE]>> 8)&0xFF; \ - int b = ((expected)[y/BLOCK_SIZE][x/BLOCK_SIZE] )&0xFF; \ - if (r != gdImageRed(im, p)) { \ - printf("Red %x is expected, but %x\n", r, gdImageRed(im, p)); \ - return 0; \ - } \ - if (g != gdImageGreen(im, p)) { \ - printf("Green %x is expected, but %x\n", g, gdImageGreen(im, p)); \ - return 0; \ - } \ - if (b != gdImageBlue(im, p)) { \ - printf("Blue %x is expected, but %x\n", b, gdImageBlue(im, p)); \ - return 0; \ - } \ - } \ - } \ +#define CHECK_PIXELS(im, expected) do { \ + int x, y; \ + for (y = 0; y < (im)->sy; y++) { \ + for (x = 0; x < (im)->sx; x++) { \ + int p = gdImageGetPixel(im, x, y); \ + int r = ((expected)[y/BLOCK_SIZE][x/BLOCK_SIZE]>>16)&0xFF; \ + int g = ((expected)[y/BLOCK_SIZE][x/BLOCK_SIZE]>> 8)&0xFF; \ + int b = ((expected)[y/BLOCK_SIZE][x/BLOCK_SIZE] )&0xFF; \ + if (r != gdImageRed(im, p)) { \ + gdTestErrorMsg("Red %x is expected, but %x\n", r, gdImageRed(im, p)); \ + return 0; \ + } \ + if (g != gdImageGreen(im, p)) { \ + gdTestErrorMsg("Green %x is expected, but %x\n", g, gdImageGreen(im, p)); \ + return 0; \ + } \ + if (b != gdImageBlue(im, p)) { \ + gdTestErrorMsg("Blue %x is expected, but %x\n", b, gdImageBlue(im, p)); \ + return 0; \ + } \ + } \ + } \ } while (0) static int testPixelate(gdImagePtr im) diff --git a/tests/gdimagerotate/php_bug_64898.c b/tests/gdimagerotate/php_bug_64898.c index 6b723df..67f62a7 100644 --- a/tests/gdimagerotate/php_bug_64898.c +++ b/tests/gdimagerotate/php_bug_64898.c @@ -33,7 +33,7 @@ int main() } if (!gdAssertImageEqualsToFile("gdimagerotate/php_bug_64898_exp.png", exp)) { - printf("comparing rotated image failed.\n"); + gdTestErrorMsg("comparing rotated image failed.\n"); error = 1; } diff --git a/tests/gdimagescale/github_bug_00218.c b/tests/gdimagescale/github_bug_00218.c index dbbc860..a25793c 100644 --- a/tests/gdimagescale/github_bug_00218.c +++ b/tests/gdimagescale/github_bug_00218.c @@ -9,7 +9,7 @@ int main() im = gdImageCreate(5,5); dest = gdImageScale(im, 0, 1); if (dest != NULL) { - printf("expecting NULL result\n"); + gdTestErrorMsg("expecting NULL result\n"); status = 1; } else { status = 0; diff --git a/tests/gdimagescatterex/bug00208_1.c b/tests/gdimagescatterex/bug00208_1.c index 56fd2e2..3d02b2c 100644 --- a/tests/gdimagescatterex/bug00208_1.c +++ b/tests/gdimagescatterex/bug00208_1.c @@ -12,7 +12,7 @@ int main() im = gdImageCreateFromPng(fp); fclose(fp); if (!im) { - fprintf(stderr, "could not create image\n"); + gdTestErrorMsg("could not create image\n"); return 1; } @@ -22,7 +22,7 @@ int main() s.num_colors = 0; if (!gdImageScatterEx(im, &s)) { gdImageDestroy(im); - fprintf(stderr, "could not scatter\n"); + gdTestErrorMsg("could not scatter\n"); return 1; } @@ -30,7 +30,7 @@ int main() ex = gdImageCreateFromPng(fp); fclose(fp); if (!ex) { - fprintf(stderr, "could not create image\n"); + gdTestErrorMsg("could not create image\n"); gdImageDestroy(im); return 1; } @@ -39,7 +39,7 @@ int main() gdImageDestroy(ex); gdImageDestroy(im); if (r.pixels_changed > 10000) { - fprintf(stderr, "too much diff: %d\n", r.pixels_changed); + gdTestErrorMsg("too much diff: %d\n", r.pixels_changed); return 1; } return 0; diff --git a/tests/gdimagescatterex/bug00208_2.c b/tests/gdimagescatterex/bug00208_2.c index b376b10..58c1382 100644 --- a/tests/gdimagescatterex/bug00208_2.c +++ b/tests/gdimagescatterex/bug00208_2.c @@ -13,7 +13,7 @@ int main() im = gdImageCreateFromPng(fp); fclose(fp); if (!im) { - fprintf(stderr, "could not create image\n"); + gdTestErrorMsg("could not create image\n"); return 1; } @@ -24,7 +24,7 @@ int main() s.colors = colors; if (!gdImageScatterEx(im, &s)) { gdImageDestroy(im); - fprintf(stderr, "could not scatter\n"); + gdTestErrorMsg("could not scatter\n"); return 1; } @@ -32,7 +32,7 @@ int main() ex = gdImageCreateFromPng(fp); fclose(fp); if (!ex) { - fprintf(stderr, "could not create image\n"); + gdTestErrorMsg("could not create image\n"); gdImageDestroy(im); return 1; } @@ -41,7 +41,7 @@ int main() gdImageDestroy(ex); gdImageDestroy(im); if (r.pixels_changed > 10000) { - fprintf(stderr, "too much diff: %d\n", r.pixels_changed); + gdTestErrorMsg("too much diff: %d\n", r.pixels_changed); return 1; } return 0; diff --git a/tests/gdimagestringft/gdimagestringft_bbox.c b/tests/gdimagestringft/gdimagestringft_bbox.c index 5807918..bc2bdd0 100644 --- a/tests/gdimagestringft/gdimagestringft_bbox.c +++ b/tests/gdimagestringft/gdimagestringft_bbox.c @@ -53,7 +53,7 @@ int main() } for (j = 0; j < 8; j++) { if (brect[j] != EXPECT[i][j]) { - printf("(%d, %d) (%d, %d) (%d, %d) (%d, %d) expected, but (%d, %d) (%d, %d) (%d, %d) (%d, %d)\n", + 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], brect[0], brect[1], brect[2], brect[3], diff --git a/tests/gdimagetruecolortopalette/.gitignore b/tests/gdimagetruecolortopalette/.gitignore new file mode 100644 index 0000000..213f07c --- /dev/null +++ b/tests/gdimagetruecolortopalette/.gitignore @@ -0,0 +1 @@ +/php_bug_72512 diff --git a/tests/gdimagetruecolortopalette/CMakeLists.txt b/tests/gdimagetruecolortopalette/CMakeLists.txt new file mode 100644 index 0000000..606eb53 --- /dev/null +++ b/tests/gdimagetruecolortopalette/CMakeLists.txt @@ -0,0 +1,5 @@ +SET(TESTS_FILES + php_bug_72512 +) + +ADD_GD_TESTS() diff --git a/tests/gdimagetruecolortopalette/Makemodule.am b/tests/gdimagetruecolortopalette/Makemodule.am new file mode 100644 index 0000000..cd73f09 --- /dev/null +++ b/tests/gdimagetruecolortopalette/Makemodule.am @@ -0,0 +1,6 @@ + +libgd_test_programs += \ + gdimagetruecolortopalette/php_bug_72512 + +EXTRA_DIST += \ + gdimagetruecolortopalette/CMakeLists.txt diff --git a/tests/gdimagetruecolortopalette/php_bug_72512.c b/tests/gdimagetruecolortopalette/php_bug_72512.c new file mode 100644 index 0000000..d022a94 --- /dev/null +++ b/tests/gdimagetruecolortopalette/php_bug_72512.c @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <stdlib.h> +#include "gd.h" + +#include "gdtest.h" + +int main() +{ + gdImagePtr im, im2; + int error = 0; + + im = gdImageCreateTrueColor(100, 100); + + if (im == NULL) { + gdTestErrorMsg("gdImageCreateTruecolor failed"); + error = 1; + goto exit; + } + gdImageColorTransparent(im, -1); + gdImageTrueColorToPalette(im, 1, 3); + gdImageColorTransparent(im, 9); + im2 = gdImageScale(im, 1, 65535); + if (im2 == NULL) { + error = 1; + goto freeim; + } else { + gdImageDestroy(im2); + } + +freeim: + gdImageDestroy(im); +exit: + return error; +} diff --git a/tests/gdinterpolatedscale/gdTrivialResize.c b/tests/gdinterpolatedscale/gdTrivialResize.c index eb55da7..2b7baf1 100644 --- a/tests/gdinterpolatedscale/gdTrivialResize.c +++ b/tests/gdinterpolatedscale/gdTrivialResize.c @@ -84,7 +84,7 @@ void do_test(int x, int y, int nx, int ny) scaletest(x, y, nx, ny); } -int main(int argc, char **argv) +int main() { do_test(300, 300, 600, 600); do_test(1500, 1000, 600, 400); diff --git a/tests/gdtest/gdtest.c b/tests/gdtest/gdtest.c index e25d8be..f1b20ce 100644 --- a/tests/gdtest/gdtest.c +++ b/tests/gdtest/gdtest.c @@ -20,6 +20,10 @@ #include <sys/types.h> #endif +#ifdef _WIN32 +# include "readdir.h" +#endif + #include "gd.h" #include "gdtest.h" @@ -43,13 +47,20 @@ gdImagePtr gdTestImageFromPng(const char *filename) FILE *fp; /* If the path is relative, then assume it's in the tests/ dir. */ - if (filename[0] == '/') { + if (filename[0] == '/' +#ifdef _WIN32 + || filename[1] == ':' +#endif + ) { fp = fopen(filename, "rb"); - if (!fp) - return NULL; - } else + } else { fp = gdTestFileOpen(filename); + } + if (fp == NULL) { + return NULL; + } + image = gdImageCreateFromPng(fp); fclose(fp); return image; @@ -75,7 +86,20 @@ static void _clean_dir(const char *dir) if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; +#ifdef _WIN32 + { + WIN32_FILE_ATTRIBUTE_DATA data; + if (!GetFileAttributesEx(de->d_name, GetFileExInfoStandard, &data)) { + continue; + } + if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + _clean_dir(de->d_name); + } else { + unlink(de->d_name); + } + } +#else if (lstat(de->d_name, &st) != 0) continue; @@ -83,6 +107,7 @@ static void _clean_dir(const char *dir) _clean_dir(de->d_name); else unlink(de->d_name); +#endif } if (chdir("..")) { @@ -100,21 +125,158 @@ static void tmpdir_cleanup(void) free(tmpdir_base); } +#ifdef _WIN32 +char* strrstr (char* haystack, char* needle) +{ + int needle_length = strlen(needle); + char * haystack_end = haystack + strlen(haystack) - needle_length; + char * p; + int i; + + for(p = haystack_end; p >= haystack; --p) + { + for(i = 0; i < needle_length; ++i) { + if(p[i] != needle[i]) + goto next; + } + return p; + + next:; + } + return 0; +} + + +typedef VOID (WINAPI *MyGetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime); + +static MyGetSystemTimeAsFileTime get_time_func(void) +{ + MyGetSystemTimeAsFileTime timefunc = NULL; + HMODULE hMod = GetModuleHandle("kernel32.dll"); + + if (hMod) { + /* Max possible resolution <1us, win8/server2012 */ + timefunc = (MyGetSystemTimeAsFileTime)GetProcAddress(hMod, "GetSystemTimePreciseAsFileTime"); + + if(!timefunc) { + /* 100ns blocks since 01-Jan-1641 */ + timefunc = (MyGetSystemTimeAsFileTime)GetProcAddress(hMod, "GetSystemTimeAsFileTime"); + } + } + + return timefunc; +} +static MyGetSystemTimeAsFileTime timefunc = NULL; +static int getfilesystemtime(struct timeval *tv) +{ + FILETIME ft; + unsigned __int64 ff = 0; + ULARGE_INTEGER fft; + + if (timefunc == NULL) { + timefunc = get_time_func(); + } + timefunc(&ft); + + /* + * Do not cast a pointer to a FILETIME structure to either a + * ULARGE_INTEGER* or __int64* value because it can cause alignment faults on 64-bit Windows. + * via http://technet.microsoft.com/en-us/library/ms724284(v=vs.85).aspx + */ + fft.HighPart = ft.dwHighDateTime; + fft.LowPart = ft.dwLowDateTime; + ff = fft.QuadPart; + + ff /= 10Ui64; /* convert to microseconds */ + ff -= 11644473600000000Ui64; /* convert to unix epoch */ + + tv->tv_sec = (long)(ff / 1000000Ui64); + tv->tv_usec = (long)(ff % 1000000Ui64); + + return 0; +} + +static char * +mkdtemp (char *tmpl) +{ + static const char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + static const int NLETTERS = sizeof (letters) - 1; + static int counter = 0; + char *XXXXXX; + struct timeval tv; + _int64 value; + int count; + + /* find the last occurrence of "XXXXXX" */ + XXXXXX = strrstr(tmpl, "XXXXXX"); + + if (!XXXXXX || strncmp (XXXXXX, "XXXXXX", 6)) { + errno = EINVAL; + return NULL; + } + + /* Get some more or less random data. */ + getfilesystemtime(&tv); + value = (tv.tv_usec ^ tv.tv_sec) + counter++; + + for (count = 0; count < 100; value += 7777, ++count) { + _int64 v = value; + + /* Fill in the random bits. */ + XXXXXX[0] = letters[v % NLETTERS]; + v /= NLETTERS; + XXXXXX[1] = letters[v % NLETTERS]; + v /= NLETTERS; + XXXXXX[2] = letters[v % NLETTERS]; + v /= NLETTERS; + XXXXXX[3] = letters[v % NLETTERS]; + v /= NLETTERS; + XXXXXX[4] = letters[v % NLETTERS]; + v /= NLETTERS; + XXXXXX[5] = letters[v % NLETTERS]; + + /* tmpl is in UTF-8 on Windows, thus use g_mkdir() */ + if (mkdir(tmpl) == 0) { + return tmpl; + } + printf("failed to create directory\n"); + if (errno != EEXIST) + /* Any other error will apply also to other names we might + * try, and there are 2^32 or so of them, so give up now. + */ + return NULL; + } + + /* We got out of the loop because we ran out of combinations to try. */ + errno = EEXIST; + return NULL; +} +#endif + const char *gdTestTempDir(void) { if (tmpdir_base == NULL) { - char *tmpdir, *tmpdir_root; - + char *tmpdir; +#ifdef _WIN32 + char tmpdir_root[MAX_PATH]; + size_t tmpdir_root_len = GetTempPath(MAX_PATH, tmpdir_root); + gdTestAssert(!(tmpdir_root_len > MAX_PATH || (tmpdir_root_len == 0))); + gdTestAssert((tmpdir_root_len + 30 < MAX_PATH)); +#else + char *tmpdir_root; tmpdir_root = getenv("TMPDIR"); if (tmpdir_root == NULL) tmpdir_root = "/tmp"; +#endif /* The constant here is a lazy over-estimate. */ tmpdir = malloc(strlen(tmpdir_root) + 30); gdTestAssert(tmpdir != NULL); - +#ifdef _WIN32 + sprintf(tmpdir, "%sgdtest.XXXXXX", tmpdir_root); +#else sprintf(tmpdir, "%s/gdtest.XXXXXX", tmpdir_root); - +#endif tmpdir_base = mkdtemp(tmpdir); gdTestAssert(tmpdir_base != NULL); @@ -129,9 +291,27 @@ char *gdTestTempFile(const char *template) const char *tempdir = gdTestTempDir(); char *ret; - if (template == NULL) +#ifdef _WIN32 + { + char *tmpfilename; + UINT error; + + ret = malloc(MAX_PATH); + gdTestAssert(ret != NULL); + if (template == NULL) { + error = GetTempFileName(tempdir, + "gdtest", + 0, + ret); + gdTestAssert(error != 0); + } else { + sprintf(ret, "%s\\%s", tempdir, template); + } + } +#else + if (template == NULL) { template = "gdtemp.XXXXXX"; - + } ret = malloc(strlen(tempdir) + 10 + strlen(template)); gdTestAssert(ret != NULL); sprintf(ret, "%s/%s", tempdir, template); @@ -141,7 +321,7 @@ char *gdTestTempFile(const char *template) gdTestAssert(fd != -1); close(fd); } - +#endif return ret; } @@ -176,8 +356,13 @@ char *gdTestFilePathV(const char *path, va_list args) strcpy(file, GDTEST_TOP_DIR); p = path; do { +#ifdef _WIN32 + strcat(file, "\\"); +#else strcat(file, "/"); +#endif strcat(file, p); + } while ((p = va_arg(args, const char *)) != NULL); va_end(args); diff --git a/tests/gdtest/readdir.c b/tests/gdtest/readdir.c new file mode 100644 index 0000000..50fe66f --- /dev/null +++ b/tests/gdtest/readdir.c @@ -0,0 +1,199 @@ +#include <malloc.h> +#include <string.h> +#include <errno.h> +#include "readdir.h" + +/********************************************************************** + * Implement dirent-style opendir/readdir/rewinddir/closedir on Win32 + * + * Functions defined are opendir(), readdir(), rewinddir() and + * closedir() with the same prototypes as the normal dirent.h + * implementation. + * + * Does not implement telldir(), seekdir(), or scandir(). The dirent + * struct is compatible with Unix, except that d_ino is always 1 and + * d_off is made up as we go along. + * + * The DIR typedef is not compatible with Unix. + **********************************************************************/ + +DIR *opendir(const char *path) +{ + DIR *dp; + char *filespec; + HANDLE handle; + int index; + + if (path == NULL) { + return NULL; + } + + filespec = (char *)malloc(strlen(path) + 2 + 1); + if (filespec == NULL) { + return NULL; + } + strcpy(filespec, path); + index = (int)strlen(filespec) - 1; + if (index >= 0 && (filespec[index] == '/' || + (filespec[index] == '\\' && (index == 0 || !IsDBCSLeadByte(filespec[index-1]))))) + filespec[index] = '\0'; + strcat(filespec, "\\*"); + + dp = (DIR *) malloc(sizeof(DIR)); + if (dp == NULL) { + free(filespec); + return NULL; + } + dp->offset = 0; + dp->finished = 0; + + if ((handle = FindFirstFile(filespec, &(dp->fileinfo))) == INVALID_HANDLE_VALUE) { + DWORD err = GetLastError(); + if (err == ERROR_NO_MORE_FILES || err == ERROR_FILE_NOT_FOUND) { + dp->finished = 1; + } else { + free(dp); + free(filespec); + return NULL; + } + } + dp->dir = strdup(path); + dp->handle = handle; + free(filespec); + + return dp; +} + +size_t gd_strlcpy(char *dst, const char *src, size_t siz) +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} + +struct dirent *readdir(DIR *dp) +{ + if (!dp || dp->finished) + return NULL; + + if (dp->offset != 0) { + if (FindNextFile(dp->handle, &(dp->fileinfo)) == 0) { + dp->finished = 1; + return NULL; + } + } + dp->offset++; + + gd_strlcpy(dp->dent.d_name, dp->fileinfo.cFileName, _MAX_FNAME+1); + dp->dent.d_ino = 1; + dp->dent.d_reclen = (unsigned short)strlen(dp->dent.d_name); + dp->dent.d_off = dp->offset; + + return &(dp->dent); +} + +int readdir_r(DIR *dp, struct dirent *entry, struct dirent **result) +{ + if (!dp || dp->finished) { + *result = NULL; + return 0; + } + + if (dp->offset != 0) { + if (FindNextFile(dp->handle, &(dp->fileinfo)) == 0) { + dp->finished = 1; + *result = NULL; + return 0; + } + } + dp->offset++; + + gd_strlcpy(dp->dent.d_name, dp->fileinfo.cFileName, _MAX_FNAME+1); + dp->dent.d_ino = 1; + dp->dent.d_reclen = (unsigned short)strlen(dp->dent.d_name); + dp->dent.d_off = dp->offset; + + memcpy(entry, &dp->dent, sizeof(*entry)); + + *result = &dp->dent; + + return 0; +} + +int closedir(DIR *dp) +{ + if (!dp) + return 0; + /* It is valid to scan an empty directory but we have an invalid + handle in this case (no first file found). */ + if (dp->handle != INVALID_HANDLE_VALUE) { + FindClose(dp->handle); + } + if (dp->dir) + free(dp->dir); + if (dp) + free(dp); + + return 0; +} + +int rewinddir(DIR *dp) +{ + /* Re-set to the beginning */ + char *filespec; + HANDLE handle; + int index; + + FindClose(dp->handle); + + dp->offset = 0; + dp->finished = 0; + + filespec = (char *)malloc(strlen(dp->dir) + 2 + 1); + if (filespec == NULL) { + return -1; + } + + strcpy(filespec, dp->dir); + index = (int)strlen(filespec) - 1; + if (index >= 0 && (filespec[index] == '/' || + (filespec[index] == '\\' && (index == 0 || !IsDBCSLeadByte(filespec[index-1]))))) + filespec[index] = '\0'; + strcat(filespec, "/*"); + + if ((handle = FindFirstFile(filespec, &(dp->fileinfo))) == INVALID_HANDLE_VALUE) { + dp->finished = 1; + } + + dp->handle = handle; + free(filespec); + + return 0; +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/tests/gdtest/readdir.h b/tests/gdtest/readdir.h new file mode 100644 index 0000000..8927e07 --- /dev/null +++ b/tests/gdtest/readdir.h @@ -0,0 +1,44 @@ +#ifndef READDIR_H +#define READDIR_H +/* + * Structures and types used to implement opendir/readdir/closedir + * on Windows 95/NT. + */ +#include <windows.h> +#include <io.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <direct.h> + +#ifndef MAXPATHLEN +# define MAXPATHLEN _MAX_PATH +#endif +/* struct dirent - same as Unix */ + +struct dirent { + long d_ino; /* inode (always 1 in WIN32) */ + off_t d_off; /* offset to this dirent */ + unsigned short d_reclen; /* length of d_name */ + char d_name[_MAX_FNAME + 1]; /* filename (null terminated) */ +}; + + +/* typedef DIR - not the same as Unix */ +typedef struct { + HANDLE handle; /* _findfirst/_findnext handle */ + int offset; /* offset into directory */ + short finished; /* 1 if there are not more files */ + WIN32_FIND_DATA fileinfo; /* from _findfirst/_findnext */ + char *dir; /* the dir we are reading */ + struct dirent dent; /* the dirent to return */ +} DIR; + +/* Function prototypes */ +DIR *opendir(const char *); +struct dirent *readdir(DIR *); +int readdir_r(DIR *, struct dirent *, struct dirent **); +int closedir(DIR *); +int rewinddir(DIR *); + +#endif /* READDIR_H */ diff --git a/tests/gif/gif_im2im.c b/tests/gif/gif_im2im.c index b66dddf..00bd137 100644 --- a/tests/gif/gif_im2im.c +++ b/tests/gif/gif_im2im.c @@ -12,7 +12,7 @@ int main() src = gdImageCreate(100, 100); if (src == NULL) { - printf("could not create src\n"); + gdTestErrorMsg("could not create src\n"); return 1; } r = gdImageColorAllocate(src, 0xFF, 0, 0); @@ -32,26 +32,26 @@ int main() p = gdImageGifPtr(src, &size); if (p == NULL) { status = 1; - printf("p is null\n"); + gdTestErrorMsg("p is null\n"); goto door0; } if (size <= 0) { status = 1; - printf("size is non-positive\n"); + gdTestErrorMsg("size is non-positive\n"); goto door1; } dst = gdImageCreateFromGifPtr(size, p); if (dst == NULL) { status = 1; - printf("could not create dst\n"); + gdTestErrorMsg("could not create dst\n"); goto door1; } OUTPUT_GIF(dst); gdTestImageDiff(src, dst, NULL, &result); if (result.pixels_changed > 0) { status = 1; - printf("pixels changed: %d\n", result.pixels_changed); + gdTestErrorMsg("pixels changed: %d\n", result.pixels_changed); } gdImageDestroy(dst); door1: diff --git a/tests/jpeg/jpeg_empty_file.c b/tests/jpeg/jpeg_empty_file.c index bf7df8e..12ce241 100644 --- a/tests/jpeg/jpeg_empty_file.c +++ b/tests/jpeg/jpeg_empty_file.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include <stdio.h> #include <stdlib.h> diff --git a/tests/jpeg/jpeg_im2im.c b/tests/jpeg/jpeg_im2im.c index b361f4d..9d113d1 100644 --- a/tests/jpeg/jpeg_im2im.c +++ b/tests/jpeg/jpeg_im2im.c @@ -14,7 +14,7 @@ int main() src = gdImageCreateTrueColor(100, 100); if (src == NULL) { - printf("could not create src\n"); + gdTestErrorMsg("could not create src\n"); return 1; } r = gdImageColorAllocate(src, 0xFF, 0, 0); @@ -34,19 +34,19 @@ int main() p = gdImageJpegPtr(src, &size, 100); if (p == NULL) { status = 1; - printf("p is null\n"); + gdTestErrorMsg("p is null\n"); goto door0; } if (size <= 0) { status = 1; - printf("size is non-positive\n"); + gdTestErrorMsg("size is non-positive\n"); goto door1; } dst = gdImageCreateFromJpegPtr(size, p); if (dst == NULL) { status = 1; - printf("could not create dst\n"); + gdTestErrorMsg("could not create dst\n"); goto door1; } OUTPUT_JPEG(dst); @@ -54,7 +54,7 @@ int main() gdTestImageDiff(src, dst, NULL, &result); if (result.pixels_changed > 0) { status = 1; - printf("pixels changed: %d\n", result.pixels_changed); + gdTestErrorMsg("pixels changed: %d\n", result.pixels_changed); } #endif gdImageDestroy(dst); diff --git a/tests/jpeg/jpeg_read.c b/tests/jpeg/jpeg_read.c index d85a912..42098fd 100644 --- a/tests/jpeg/jpeg_read.c +++ b/tests/jpeg/jpeg_read.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include <stdio.h> #include <stdlib.h> diff --git a/tests/png/bug00011.c b/tests/png/bug00011.c index e0167f9..f58ab61 100644 --- a/tests/png/bug00011.c +++ b/tests/png/bug00011.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include <stdio.h> #include <stdlib.h> diff --git a/tests/png/bug00033.c b/tests/png/bug00033.c index 83c9013..faf0a18 100644 --- a/tests/png/bug00033.c +++ b/tests/png/bug00033.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include <stdio.h> #include <stdlib.h> diff --git a/tests/png/bug00086.c b/tests/png/bug00086.c index ef9d43b..f29b5d7 100644 --- a/tests/png/bug00086.c +++ b/tests/png/bug00086.c @@ -1,4 +1,3 @@ -/* $Id$ */ /* id: gdbad3.c, Xavier Roche, May. 2007 */ /* gcc gdbad3.c -o bad -lgd && ./bad */ @@ -17,7 +16,7 @@ int main(void) if ( ( im = gdImageCreateFromPngPtr(93, (char*) &pngdata[0]) ) == NULL) { return 0; } else { - fprintf(stderr, "failed!\n"); + gdTestErrorMsg("failed!\n"); gdImageDestroy(im); return 1; } diff --git a/tests/png/bug00088.c b/tests/png/bug00088.c index 72d37d2..5c0ab58 100644 --- a/tests/png/bug00088.c +++ b/tests/png/bug00088.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include <stdio.h> #include <stdlib.h> @@ -28,6 +27,7 @@ int main() } path = gdTestFilePath2("png", files_exp[i]); + if (!gdAssertImageEqualsToFile(path, im)) { error |= 1; } diff --git a/tests/png/png_im2im.c b/tests/png/png_im2im.c index df6037d..e02d057 100644 --- a/tests/png/png_im2im.c +++ b/tests/png/png_im2im.c @@ -12,7 +12,7 @@ int main() src = gdImageCreate(100, 100); if (src == NULL) { - printf("could not create src\n"); + gdTestErrorMsg("could not create src\n"); return 1; } r = gdImageColorAllocate(src, 0xFF, 0, 0); @@ -32,26 +32,26 @@ int main() p = gdImagePngPtr(src, &size); if (p == NULL) { status = 1; - printf("p is null\n"); + gdTestErrorMsg("p is null\n"); goto door0; } if (size <= 0) { status = 1; - printf("size is non-positive\n"); + gdTestErrorMsg("size is non-positive\n"); goto door1; } dst = gdImageCreateFromPngPtr(size, p); if (dst == NULL) { status = 1; - printf("could not create dst\n"); + gdTestErrorMsg("could not create dst\n"); goto door1; } OUTPUT_PNG(dst); gdTestImageDiff(src, dst, NULL, &result); if (result.pixels_changed > 0) { status = 1; - printf("pixels changed: %d\n", result.pixels_changed); + gdTestErrorMsg("pixels changed: %d\n", result.pixels_changed); } gdImageDestroy(dst); door1: diff --git a/tests/test_config.h.in b/tests/test_config.h.in index f29f20a..78a6588 100644 --- a/tests/test_config.h.in +++ b/tests/test_config.h.in @@ -1,7 +1,5 @@ #ifndef GD_TEST_CONFIG_H #define GD_TEST_CONFIG_H - - /* Define the full path to the top src dir, required to get the path * of each input data */ #define GDTEST_TOP_DIR "@srcdir@" diff --git a/tests/tga/.gitignore b/tests/tga/.gitignore index 7f3cff8..e88e124 100644 --- a/tests/tga/.gitignore +++ b/tests/tga/.gitignore @@ -1,2 +1,6 @@ /bug00084 +/bug00247 +/bug00247a +/bug00248 +/bug00248a /tga_null diff --git a/tests/tga/CMakeLists.txt b/tests/tga/CMakeLists.txt index 4869e8d..c3a589c 100644 --- a/tests/tga/CMakeLists.txt +++ b/tests/tga/CMakeLists.txt @@ -1,6 +1,10 @@ LIST(APPEND TESTS_FILES tga_null bug00084 + bug00247 + bug00247a + bug00248 + bug00248a ) ADD_GD_TESTS() diff --git a/tests/tga/Makemodule.am b/tests/tga/Makemodule.am index 1fa3e68..dff828f 100644 --- a/tests/tga/Makemodule.am +++ b/tests/tga/Makemodule.am @@ -1,7 +1,15 @@ libgd_test_programs += \ tga/bug00084 \ + tga/bug00247 \ + tga/bug00247a \ + tga/bug00248 \ + tga/bug00248a \ tga/tga_null EXTRA_DIST += \ tga/CMakeLists.txt \ - tga/bug00084.tga + tga/bug00084.tga \ + tga/bug00247.tga \ + tga/bug00247a.tga \ + tga/bug00248.tga \ + tga/bug00248a.tga diff --git a/tests/tga/bug00084.c b/tests/tga/bug00084.c index 1526e93..7d4ca92 100644 --- a/tests/tga/bug00084.c +++ b/tests/tga/bug00084.c @@ -3,7 +3,7 @@ #include "gd.h" #include "gdtest.h" -int main(int argc, char **argv) +int main() { gdImagePtr im; FILE *fp = gdTestFileOpen("tga/bug00084.tga"); diff --git a/tests/tga/bug00247.c b/tests/tga/bug00247.c new file mode 100644 index 0000000..49b1610 --- /dev/null +++ b/tests/tga/bug00247.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp = gdTestFileOpen("tga/bug00247.tga"); + im = gdImageCreateFromTga(fp); + gdTestAssert(im == NULL); + fclose(fp); + return gdNumFailures(); +} diff --git a/tests/tga/bug00247.tga b/tests/tga/bug00247.tga Binary files differnew file mode 100644 index 0000000..0fe4cac --- /dev/null +++ b/tests/tga/bug00247.tga diff --git a/tests/tga/bug00247a.c b/tests/tga/bug00247a.c new file mode 100644 index 0000000..1c825f9 --- /dev/null +++ b/tests/tga/bug00247a.c @@ -0,0 +1,19 @@ +/* +We test that a 8bpp TGA file will be gracefully rejected by +gdImageCreateFromTga(). +*/ + +#include <stdio.h> + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp = gdTestFileOpen("tga/bug00247a.tga"); + im = gdImageCreateFromTga(fp); + gdTestAssert(im == NULL); + fclose(fp); + return gdNumFailures(); +} diff --git a/tests/tga/bug00247a.tga b/tests/tga/bug00247a.tga Binary files differnew file mode 100644 index 0000000..65e55ab --- /dev/null +++ b/tests/tga/bug00247a.tga diff --git a/tests/tga/bug00248.c b/tests/tga/bug00248.c new file mode 100644 index 0000000..5eb6046 --- /dev/null +++ b/tests/tga/bug00248.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +#include "gd.h" +#include "gdtest.h" + +int main(int argc, char **argv) +{ + gdImagePtr im; + FILE *fp = gdTestFileOpen("tga/bug00248.tga"); + im = gdImageCreateFromTga(fp); + gdTestAssert(im == NULL); + fclose(fp); + return gdNumFailures(); +} diff --git a/tests/tga/bug00248.tga b/tests/tga/bug00248.tga Binary files differnew file mode 100644 index 0000000..f0a56f4 --- /dev/null +++ b/tests/tga/bug00248.tga diff --git a/tests/tga/bug00248a.c b/tests/tga/bug00248a.c new file mode 100644 index 0000000..8308eb5 --- /dev/null +++ b/tests/tga/bug00248a.c @@ -0,0 +1,16 @@ +/* See also <https://github.com/libgd/libgd/pull/257> */ + +#include <stdio.h> + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp = gdTestFileOpen("tga/bug00248a.tga"); + im = gdImageCreateFromTga(fp); + gdTestAssert(im == NULL); + fclose(fp); + return gdNumFailures(); +} diff --git a/tests/tga/bug00248a.tga b/tests/tga/bug00248a.tga Binary files differnew file mode 100644 index 0000000..29c4e26 --- /dev/null +++ b/tests/tga/bug00248a.tga diff --git a/tests/tiff/tiff_dpi.c b/tests/tiff/tiff_dpi.c index cdffe6d..347abf1 100644 --- a/tests/tiff/tiff_dpi.c +++ b/tests/tiff/tiff_dpi.c @@ -3,6 +3,14 @@ * 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" @@ -16,7 +24,7 @@ int main() src = gdImageCreate(100, 100); if (src == NULL) { - printf("could not create src\n"); + gdTestErrorMsg("could not create src\n"); return 1; } r = gdImageColorAllocate(src, 0xFF, 0, 0); @@ -40,30 +48,30 @@ int main() p = gdImageTiffPtr(src, &size); if (p == NULL) { status = 1; - printf("p is null\n"); + gdTestErrorMsg("p is null\n"); goto door0; } if (size <= 0) { status = 1; - printf("size is non-positive\n"); + gdTestErrorMsg("size is non-positive\n"); goto door1; } dst = gdImageCreateFromTiffPtr(size, p); if (dst == NULL) { status = 1; - printf("could not create dst\n"); + gdTestErrorMsg("could not create dst\n"); goto door1; } if (dst->res_x != res_x) { status = 1; - printf("mismatch in res_x (got %d, expected %d)", dst->res_x, res_x); + gdTestErrorMsg("mismatch in res_x (got %d, expected %d)", dst->res_x, res_x); } if (dst->res_y != res_y) { status = 1; - printf("mismatch in res_y (got %d, expected %d)", dst->res_y, res_y); + gdTestErrorMsg("mismatch in res_y (got %d, expected %d)", dst->res_y, res_y); } gdImageDestroy(dst); @@ -73,3 +81,4 @@ door0: gdImageDestroy(src); return status; } +#endif
\ No newline at end of file diff --git a/tests/tiff/tiff_im2im.c b/tests/tiff/tiff_im2im.c index 2fc113d..b6b240e 100644 --- a/tests/tiff/tiff_im2im.c +++ b/tests/tiff/tiff_im2im.c @@ -1,3 +1,11 @@ +#ifdef _WIN32 +#include <stdio.h> +int main() +{ + printf("skip"); + return 0; +} +#else #include "gd.h" #include "gdtest.h" @@ -8,13 +16,11 @@ int main() void *p; int size = 0; int status = 0; -#if 0 CuTestImageResult result = {0, 0}; -#endif src = gdImageCreate(100, 100); if (src == NULL) { - printf("could not create src\n"); + gdTestErrorMsg("could not create src\n"); return 1; } r = gdImageColorAllocate(src, 0xFF, 0, 0); @@ -34,29 +40,29 @@ int main() p = gdImageTiffPtr(src, &size); if (p == NULL) { status = 1; - printf("p is null\n"); + gdTestErrorMsg("p is null\n"); goto door0; } if (size <= 0) { status = 1; - printf("size is non-positive\n"); + gdTestErrorMsg("size is non-positive\n"); goto door1; } dst = gdImageCreateFromTiffPtr(size, p); if (dst == NULL) { status = 1; - printf("could not create dst\n"); + gdTestErrorMsg("could not create dst\n"); goto door1; } OUTPUT_TIFF(dst); -#if 0 + gdTestImageDiff(src, dst, NULL, &result); if (result.pixels_changed > 0) { status = 1; printf("pixels changed: %d\n", result.pixels_changed); } -#endif + gdImageDestroy(dst); door1: gdFree(p); @@ -64,3 +70,4 @@ door0: gdImageDestroy(src); return status; } +#endif
\ No newline at end of file diff --git a/tests/tiff/tiff_null.c b/tests/tiff/tiff_null.c index ccaade7..19b64f7 100644 --- a/tests/tiff/tiff_null.c +++ b/tests/tiff/tiff_null.c @@ -1,3 +1,11 @@ +#ifdef _WIN32 +#include <stdio.h> +int main() +{ + printf("skip"); + return 0; +} +#else #include "gd.h" int main() @@ -12,3 +20,4 @@ int main() gdImageTiff(im, NULL); /* noop safely */ return 0; } +#endif
\ No newline at end of file diff --git a/tests/wbmp/wbmp_im2im.c b/tests/wbmp/wbmp_im2im.c index 597f602..1b1ebb2 100644 --- a/tests/wbmp/wbmp_im2im.c +++ b/tests/wbmp/wbmp_im2im.c @@ -12,7 +12,7 @@ int main() src = gdImageCreate(100, 100); if (src == NULL) { - printf("could not create src\n"); + gdTestErrorMsg("could not create src\n"); return 1; } gdImageColorAllocate(src, 0xFF, 0xFF, 0xFF); /* allocate white for background color */ @@ -30,26 +30,26 @@ int main() p = gdImageWBMPPtr(src, &size, 1); if (p == NULL) { status = 1; - printf("p is null\n"); + gdTestErrorMsg("p is null\n"); goto door0; } if (size <= 0) { status = 1; - printf("size is non-positive\n"); + gdTestErrorMsg("size is non-positive\n"); goto door1; } dst = gdImageCreateFromWBMPPtr(size, p); if (dst == NULL) { status = 1; - printf("could not create dst\n"); + gdTestErrorMsg("could not create dst\n"); goto door1; } OUTPUT_WBMP(dst); gdTestImageDiff(src, dst, NULL, &result); if (result.pixels_changed > 0) { status = 1; - printf("pixels changed: %d\n", result.pixels_changed); + gdTestErrorMsg("pixels changed: %d\n", result.pixels_changed); } gdImageDestroy(dst); door1: diff --git a/tests/webp/bug00111.c b/tests/webp/bug00111.c index 42aa428..16f9504 100644 --- a/tests/webp/bug00111.c +++ b/tests/webp/bug00111.c @@ -1,8 +1,9 @@ -/* $Id$ */ #include "gd.h" #include <stdio.h> #include <stdlib.h> -#include <unistd.h> +#ifndef _WIN32 +# include <unistd.h> +#endif #include "gdtest.h" int main() diff --git a/tests/xbm/github_bug_170.c b/tests/xbm/github_bug_170.c index 144b3f8..3900da7 100644 --- a/tests/xbm/github_bug_170.c +++ b/tests/xbm/github_bug_170.c @@ -11,9 +11,16 @@ #include <inttypes.h> #include "gd.h" #include "gdtest.h" +#ifdef _WIN32 int main() { + /* skip for now */ + return 0; +} +#else +int main() +{ gdImagePtr im; int black; FILE *outFile; @@ -40,3 +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 diff --git a/tests/xpm/bug00166.c b/tests/xpm/bug00166.c index 87bd4d1..f4cf7d1 100644 --- a/tests/xpm/bug00166.c +++ b/tests/xpm/bug00166.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include <stdio.h> #include <stdlib.h> diff --git a/tests/xpm/bug00185.c b/tests/xpm/bug00185.c index 6d86268..3056ed9 100644 --- a/tests/xpm/bug00185.c +++ b/tests/xpm/bug00185.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include <stdio.h> #include <stdlib.h> diff --git a/tests/xpm/color_name.c b/tests/xpm/color_name.c index 9d70181..894b4b7 100644 --- a/tests/xpm/color_name.c +++ b/tests/xpm/color_name.c @@ -1,4 +1,3 @@ -/* $Id$ */ #include "gd.h" #include <stdio.h> #include <stdlib.h> |