Commits

Anonymous committed b8bb1e6

- initial commit of the GD test suites
See README.TESTING for more details or how to run it

Comments (0)

Files changed (54)

src/tests/gd2/CMakeLists.txt

+
+SET(TESTS_FILES
+	gd2_read
+	gd2_empty_file
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	ADD_TEST(${test_name} ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)
Add a comment to this file

src/tests/gd2/conv_gd2_exp.gd2

Empty file added.

Add a comment to this file

src/tests/gd2/conv_test.gd2

Binary file added.

Add a comment to this file

src/tests/gd2/conv_test_exp.png

Added
New image
Add a comment to this file

src/tests/gd2/empty.gd2

Empty file added.

src/tests/gd2/gd2_empty_file.c

+/* $Id$ */
+#include "gd.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "gdtest.h"
+
+int main()
+{
+ 	gdImagePtr im;
+	FILE *fp;
+
+	fp = fopen("empty.gd2", "rb");
+	if (!fp) {
+		printf("failed, cannot open file\n");
+		return 1;
+	}
+
+	im = gdImageCreateFromJpeg(fp);
+	fclose(fp);
+
+	if (!im) {
+		return 0;
+	} else {
+		gdImageDestroy(im);
+		return 1;
+	}
+}

src/tests/gd2/gd2_read.c

+/* $Id$ */
+#include "gd.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "gdtest.h"
+
+int main()
+{
+	int error;
+ 	gdImagePtr im;
+	FILE *fp;
+
+	fp = fopen("conv_test.gd2", "rb");
+	if (!fp) {
+		printf("failed, cannot open file\n");
+		return 1;
+	}
+
+	im = gdImageCreateFromGd2(fp);
+	fclose(fp);
+
+	if (!gdAssertImageEqualsToFile("conv_test_exp.png", im)) {
+		error = 1;
+		gdImageDestroy(im);
+	} else {
+		if (im) {
+			gdImageDestroy(im);
+			error = 0;
+		} else {
+			error = 1;
+		}
+	}
+	return error;
+}

src/tests/gdimagecolorclosest/CMakeLists.txt

+SET(TESTS_FILES
+	gdimagecolorclosest
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	ADD_TEST("${test_name}" ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)

src/tests/gdimagecolorclosest/gdimagecolorclosest.c

+#include <gd.h>
+#include <stdio.h>
+#include "gdtest.h"
+
+int main()
+{
+	gdImagePtr im;
+	int error = 0;
+	int c, i;
+
+	im = gdImageCreateTrueColor(5, 5);
+	c = gdImageColorClosest(im, 255, 0, 255);
+	gdImageDestroy(im);
+
+	if (gdTestAssert(c==0xFF00FF) != 1) {
+		error = -1;
+	}
+
+	im = gdImageCreate(5, 5);
+	c = gdImageColorClosest(im, 255, 0, 255);
+	if (gdTestAssert(c==-1) != 1) {
+		error = -1;
+	}
+	gdImageDestroy(im);
+
+	im = gdImageCreate(5, 5);
+	c = gdImageColorAllocate(im, 255, 0, 255);
+	c = gdImageColorClosest(im, 255, 0, 255);
+	c = gdTrueColorAlpha(gdImageRed(im, c), gdImageGreen(im, c), gdImageBlue(im, c), 0);
+	gdImageDestroy(im);
+	if (gdTestAssert(c==0xFF00FF) != 1) {
+		error = -1;
+	}
+
+
+	im = gdImageCreate(5, 5);
+	for (i=0; i < 255; i++) {
+		c = gdImageColorAllocate(im, 255, 0, 0);
+	}
+	c = gdImageColorClosest(im, 255, 0, 0);
+	c = gdTrueColorAlpha(gdImageRed(im, c), gdImageGreen(im, c), gdImageBlue(im, c), 0);
+	gdImageDestroy(im);
+	if (gdTestAssert(c==0xFF0000) != 1) {
+		error = -1;
+	}
+
+	im = gdImageCreate(5, 5);
+	for (i=0; i < 256; i++) {
+		c = gdImageColorAllocate(im, 255, 0, 0);
+	}
+	c = gdImageColorClosest(im, 255, 0, 0);
+	c = gdTrueColorAlpha(gdImageRed(im, c), gdImageGreen(im, c), gdImageBlue(im, c), 0);
+	gdImageDestroy(im);
+	if (gdTestAssert(c==0xFF0000) != 1) {
+		error = -1;
+	}
+
+	return error;
+}

src/tests/gdimagecolorexact/CMakeLists.txt

+SET(TESTS_FILES
+	gdimagecolorexact
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	ADD_TEST("${test_name}" ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)

src/tests/gdimagecolorexact/gdimagecolorexact.c

+#include <gd.h>
+#include <stdio.h>
+#include "gdtest.h"
+
+int main()
+{
+	gdImagePtr im;
+	int error = 0;
+	int c, c1, c2, c3, c4, color, i;
+
+	im = gdImageCreateTrueColor(5, 5);
+	c = gdImageColorExact(im, 255, 0, 255);
+	c2 = gdImageColorExactAlpha(im, 255, 0, 255, 100);
+	gdImageDestroy(im);
+
+	if (gdTestAssert(c == 0xFF00FF) != 1) {
+		error = -1;
+	}
+	if (gdTestAssert(c2 == 0x64FF00FF) != 1) {
+		error = -1;
+	}
+
+	im = gdImageCreate(5, 5);
+	c1 = gdImageColorAllocate(im, 255, 0, 255);
+	c2 = gdImageColorAllocate(im, 255, 200, 0);
+	c3 = gdImageColorAllocateAlpha(im, 255, 0, 255, 100);
+
+	c1 = gdImageColorExact(im, 255, 0, 255);
+	c2 = gdImageColorExact(im, 255, 200, 0);
+	c3 = gdImageColorExactAlpha(im, 255, 0, 255, 100);
+	c4 = gdImageColorExactAlpha(im, 255, 34, 255, 100);
+
+	if (gdTestAssert(c1 == 0) != 1) {
+		error = -1;
+	}
+	if (gdTestAssert(c2 == 1) != 1) {
+		error = -1;
+	}
+	if (gdTestAssert(c3 == 2) != 1) {
+		error = -1;
+	}
+	if (gdTestAssert(c4 == -1) != 1) {
+		error = -1;
+	}
+
+	color = gdTrueColorAlpha(gdImageRed(im, c1), gdImageGreen(im, c1),
+					gdImageBlue(im, c1), 0);
+	if (gdTestAssert(color == 0xFF00FF) != 1) {
+		error = -1;
+	}
+	color = gdTrueColorAlpha(gdImageRed(im, c2), gdImageGreen(im, c2),
+					gdImageBlue(im, c2), 0);
+	if (gdTestAssert(color == 0xFFC800) != 1) {
+		error = -1;
+	}
+	color = gdTrueColorAlpha(gdImageRed(im, c3), gdImageGreen(im, c3),
+					gdImageBlue(im, c3), 0);
+	if (gdTestAssert(color == 0xFF00FF) != 1) {
+		error = -1;
+	}
+	gdImageDestroy(im);
+
+	return error;
+}

src/tests/gdimagecolorresolve/CMakeLists.txt

+SET(TESTS_FILES
+	gdimagecolorresolve
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	ADD_TEST("${test_name}" ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)

src/tests/gdimagecolorresolve/gdimagecolorresolve.c

+#include <gd.h>
+#include <stdio.h>
+#include "gdtest.h"
+
+int main()
+{
+	gdImagePtr im;
+	int error = 0;
+	int c, c1, c2, c3, c4, color, i;
+
+	im = gdImageCreateTrueColor(5, 5);
+	c = gdImageColorResolve(im, 255, 0, 255);
+	c2 = gdImageColorResolveAlpha(im, 255, 0, 255, 100);
+	gdImageDestroy(im);
+
+	if (gdTestAssert(c == 0xFF00FF) != 1) {
+		error = -1;
+	}
+	if (gdTestAssert(c2 == 0x64FF00FF) != 1) {
+		error = -1;
+	}
+
+	im = gdImageCreate(5, 5);
+
+	c1 = gdImageColorResolve(im, 255, 0, 255);
+	c2 = gdImageColorResolve(im, 255, 200, 0);
+	c3 = gdImageColorResolveAlpha(im, 255, 0, 255, 100);
+	c4 = gdImageColorResolveAlpha(im, 255, 34, 255, 100);
+
+	if (gdTestAssert(c1 == 0) != 1) {
+		error = -1;
+	}
+	if (gdTestAssert(c2 == 1) != 1) {
+		error = -1;
+	}
+	if (gdTestAssert(c3 == 2) != 1) {
+		error = -1;
+	}
+	if (gdTestAssert(c4 == 3) != 1) {
+		error = -1;
+	}
+
+	color = gdTrueColorAlpha(gdImageRed(im, c1), gdImageGreen(im, c1),
+					gdImageBlue(im, c1), 0);
+	if (gdTestAssert(color == 0xFF00FF) != 1) {
+		error = -1;
+	}
+	color = gdTrueColorAlpha(gdImageRed(im, c2), gdImageGreen(im, c2),
+					gdImageBlue(im, c2), 0);
+	if (gdTestAssert(color == 0xFFC800) != 1) {
+		error = -1;
+	}
+	color = gdTrueColorAlpha(gdImageRed(im, c3), gdImageGreen(im, c3),
+					gdImageBlue(im, c3), 0);
+	if (gdTestAssert(color == 0xFF00FF) != 1) {
+		error = -1;
+	}
+	color = gdTrueColorAlpha(gdImageRed(im, c4), gdImageGreen(im, c4),
+					gdImageBlue(im, c4), 0);
+	if (gdTestAssert(color == 0xFF22FF) != 1) {
+		error = -1;
+	}
+	gdImageDestroy(im);
+
+	return error;
+}

src/tests/gdimagecopy/CMakeLists.txt

+add_executable(bug00007 bug00007.c)
+target_link_libraries (bug00007 gdTest ${GD_LIB})
+ADD_TEST(bug00007 ${EXECUTABLE_OUTPUT_PATH}/bug00007)

src/tests/gdimagecopy/bug00007.c

+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <gd.h>
+
+#include "gdtest.h"
+
+int main()
+{
+ 	gdImagePtr dst_tc, src;
+	int c0,c1;
+
+	src = gdImageCreate(5,5);
+	gdImageAlphaBlending(src, 0);
+
+	c0 = gdImageColorAllocate(src, 255,255,255);
+	c1 = gdImageColorAllocateAlpha(src, 255,0,0,70);
+
+	gdImageFilledRectangle(src, 0,0, 4,4, c1);
+
+	dst_tc  = gdImageCreateTrueColor(5,5);
+	gdImageAlphaBlending(dst_tc, 0);
+	gdImageCopy(dst_tc, src, 0,0, 0,0, gdImageSX(src), gdImageSY(src));
+
+	//CuAssertImageEquals(tc, src, dst_tc);
+
+ 	/* Destroy it */
+ 	gdImageDestroy(dst_tc);
+	gdImageDestroy(src);
+	return 0;
+}

src/tests/gdimagecopyrotated/CMakeLists.txt

+
+SET(TESTS_FILES
+	bug00020
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	ADD_TEST(${test_name} ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)

src/tests/gdimagecopyrotated/bug00020.c

+/* $Id$ */
+#include "gd.h"
+#include "gdtest.h"
+
+#define exp_img "bug00020_exp.png"
+#define width 50
+
+int main()
+{
+ 	gdImagePtr im, im2;
+ 	int error = 0;
+
+	im = gdImageCreateTrueColor(width, width);
+	gdImageFilledRectangle(im, 0,0, width, width, 0xFF0000);
+	gdImageColorTransparent(im, 0xFF0000);
+	gdImageFilledEllipse(im, width/2, width/2, width - 20, width - 10,
+				0x50FFFFFF);
+
+	im2 = gdImageCreateTrueColor(width, width);
+
+	gdImageCopyRotated(im2, im, width / 2, width / 2, 0,0, width, width, 60);
+
+	if (!gdAssertImageEqualsToFile(exp_img, im2)) {
+		error = 1;
+	}
+
+	gdImageDestroy(im2);
+ 	gdImageDestroy(im);
+ 	return error;
+}
Add a comment to this file

src/tests/gdimagecopyrotated/bug00020_exp.png

Added
New image

src/tests/gdimagefill/CMakeLists.txt

+
+SET(TESTS_FILES
+	bug00002_1
+	bug00002_2
+	bug00002_3
+	bug00002_4
+)
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	ADD_TEST(${test_name} ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)

src/tests/gdimagefill/bug00002_1.c

+#include <gd.h>
+#include <stdio.h>
+#include "gdtest.h"
+
+int main()
+{
+	gdImagePtr im;
+	int error = 0;
+	FILE *fp;
+
+	fputs("flag 0\n", stdout);
+	im = gdImageCreateTrueColor(100, 100);
+
+	fputs("flag 1\n", stdout);
+	gdImageFill(im, 0, 0, 0xffffff);
+	fputs("flag 2\n", stdout);
+	gdImageFill(im, 0, 0, 0xffffff);
+	fputs("flag 3\n", stdout);
+
+	fp = fopen("a.png", "wb");
+ 	/* Write img to stdout */
+ 	gdImagePng(im,fp);
+	fclose(fp);
+
+	if (!gdAssertImageEqualsToFile("bug00002_1_exp.png", im)) {
+		error = 1;
+	}
+
+ 	/* Destroy it */
+ 	gdImageDestroy(im);
+	return error;
+}
+
Add a comment to this file

src/tests/gdimagefill/bug00002_1_exp.png

Added
New image

src/tests/gdimagefill/bug00002_2.c

+#include <gd.h>
+#include <stdio.h>
+#include "gdtest.h"
+
+int main()
+{
+	gdImagePtr im, tile;
+	int im_white, im_black, tile_white, tile_black;
+	int x,y, error = 0;
+	FILE *fp;
+
+	fputs("flag 0\n", stdout);
+	im = gdImageCreate(150, 150);
+	tile = gdImageCreate(36, 36);
+	tile_white = gdImageColorAllocate(tile,255,255,255);
+	tile_black = gdImageColorAllocate(tile,0,0,0);
+	im_white = gdImageColorAllocate(im,255,255,255);
+	im_black = gdImageColorAllocate(im,0,0,0);
+
+
+	/* create the dots pattern */
+	for (x=0;x<36;x+=2) {
+		for (y=0;y<36;y+=2) {
+			gdImageSetPixel(tile,x,y,tile_black);
+		}
+	}
+
+	gdImageSetTile(im,tile);
+	gdImageRectangle(im, 9,9,139,139, im_black);
+	gdImageLine(im, 9,9,139,139, im_black);
+	gdImageFill(im, 11,12, gdTiled);
+
+
+	fputs("flag 1\n", stdout);
+	gdImageFill(im, 0, 0, 0xffffff);
+	fputs("flag 2\n", stdout);
+	gdImageFill(im, 0, 0, 0xffffff);
+	fputs("flag 2\n", stdout);
+
+	if (!gdAssertImageEqualsToFile("bug00002_2_exp.png", im)) {
+		error = 1;
+	}
+
+ 	/* Destroy it */
+ 	gdImageDestroy(im);
+	return error;
+}
+
Add a comment to this file

src/tests/gdimagefill/bug00002_2_exp.png

Added
New image

src/tests/gdimagefill/bug00002_3.c

+/* $Id$ */
+#include <gd.h>
+#include <stdio.h>
+#include "gdtest.h"
+
+int main()
+{
+	gdImagePtr im, tile;
+	int im_white, im_black, tile_white, tile_black;
+	int x,y, error = 0;
+	FILE *fp;
+
+	fputs("flag 0\n", stdout);
+	im = gdImageCreate(150, 150);
+
+
+	tile = gdImageCreateTrueColor(36, 36);
+
+	tile_white = gdImageColorAllocate(tile,255,255,255);
+	tile_black = gdImageColorAllocate(tile,55,0,0);
+	im_white = gdImageColorAllocate(im,255,255,255);
+	im_black = gdImageColorAllocate(im,0,0,0);
+
+	gdImageFill(tile, 0,0, tile_white);
+	gdImageColorTransparent(tile, tile_black);
+	gdImageColorTransparent(im, im_black);
+
+	/* create the dots pattern */
+	for (x=0;x<36;x+=2) {
+		for (y=0;y<36;y+=2) {
+			gdImageSetPixel(tile,x,y,tile_black);
+		}
+	}
+
+	gdImageSetTile(im,tile);
+	gdImageRectangle(im, 9,9,139,139, im_black);
+	gdImageLine(im, 9,9,139,139, im_black);
+	gdImageFill(im, 11,12, gdTiled);
+
+
+	fputs("flag 1\n", stdout);
+	gdImageFill(im, 0, 0, 0xffffff);
+	fputs("flag 2\n", stdout);
+	gdImageFill(im, 0, 0, 0xffffff);
+	fputs("flag 3\n", stdout);
+
+	if (!gdAssertImageEqualsToFile("bug00002_3_exp.png", im)) {
+		error = 1;
+	}
+
+ 	/* Destroy it */
+ 	gdImageDestroy(im);
+	return error;
+}
+
Add a comment to this file

src/tests/gdimagefill/bug00002_3_exp.png

Added
New image

src/tests/gdimagefill/bug00002_4.c

+/*ImageFill Pattern fill */
+
+#include "gd.h"
+#include "gdtest.h"
+
+int main()
+{
+ 	gdImagePtr im;
+	FILE *fp;
+	int red, blue, white, black, error = 0;
+
+	im = gdImageCreate(50,100);
+	red = gdImageColorAllocate(im, 255, 0, 0);
+	blue = gdImageColorAllocate(im, 0,0,255);
+	white  = gdImageColorAllocate(im, 255,255,255);
+	black = gdImageColorAllocate(im, 0,0,0);
+	gdImageFill(im, 0,0, black);
+
+	gdImageLine(im, 20,20,180,20, white);
+	gdImageLine(im, 20,20,20,70, blue);
+	gdImageLine(im, 20,70,180,70, red);
+	gdImageLine(im, 180,20,180,45, white);
+	gdImageLine(im, 180,70,180,45, red);
+	gdImageLine(im, 20,20,100,45, blue);
+	gdImageLine(im, 20,70,100,45, blue);
+	gdImageLine(im, 100,45,180,45, red);
+
+	gdImageFill(im, 21,45, blue);
+	gdImageFill(im, 100,69, red);
+	gdImageFill(im, 100,21, white);
+
+	if (!gdAssertImageEqualsToFile("bug00002_4_exp.png", im)) {
+		error = 1;
+	}
+
+ 	/* Destroy it */
+ 	gdImageDestroy(im);
+ 	return error;
+}
Add a comment to this file

src/tests/gdimagefill/bug00002_4_exp.png

Added
New image

src/tests/gdimagefilledellipse/CMakeLists.txt

+
+SET(TESTS_FILES
+	bug00010
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	ADD_TEST(${test_name} ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)

src/tests/gdimagefilledellipse/bug00010.c

+/* $Id$ */
+#include "gd.h"
+#include "gdtest.h"
+
+#define exp_img "bug00010_exp.png"
+
+int main()
+{
+ 	gdImagePtr im;
+ 	int error = 0;
+
+	im = gdImageCreateTrueColor(100,100);
+	gdImageFilledEllipse(im, 50,50, 70, 90, 0x50FFFFFF);
+	if (!gdAssertImageEqualsToFile(exp_img, im)) {
+		error = 1;
+	}
+
+ 	gdImageDestroy(im);
+ 	return error;
+}
Add a comment to this file

src/tests/gdimagefilledellipse/bug00010_exp.png

Added
New image

src/tests/gdimagefilledrectangle/CMakeLists.txt

+
+add_executable(bug00004 bug00004.c)
+target_link_libraries (bug00004 gdTest ${GD_LIB})
+ADD_TEST(bug00004 ${EXECUTABLE_OUTPUT_PATH}/bug00004)

src/tests/gdimagefilledrectangle/bug00004.c

+#include "gd.h"
+#include "gdtest.h"
+
+int main()
+{
+ 	gdImagePtr im;
+	int c1,c2,c3,c4,c5;
+
+	im = gdImageCreateTrueColor(100,100);
+	gdImageFilledRectangle(im, 2,2, 80,95, 0x50FFFFFF);
+
+	c1 = gdImageGetTrueColorPixel(im, 2, 2);
+	c2 = gdImageGetTrueColorPixel(im, 80, 95);
+	c3 = gdImageGetTrueColorPixel(im, 80, 2);
+	c4 = gdImageGetTrueColorPixel(im, 2, 95);
+	c5 = gdImageGetTrueColorPixel(im, 49, 49);
+
+	gdImageDestroy(im);
+	if (0x005e5e5e == c1 && 0x005e5e5e == c2 &&
+	 0x005e5e5e == c3 && 0x005e5e5e == c4) {
+	 	return 0;
+	} else {
+		return 1;
+	}
+}
+

src/tests/gdimagefilltoborder/CMakeLists.txt

+
+SET(TESTS_FILES
+	bug00037
+)
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	ADD_TEST(${test_name} ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)

src/tests/gdimagefilltoborder/bug00037.c

+#include <gd.h>
+#include <stdio.h>
+#include "gdtest.h"
+
+int main()
+{
+	gdImagePtr im;
+	int bordercolor, color;
+
+	im = gdImageCreateTrueColor(100, 100);
+
+	gdImageAlphaBlending(im, 1);
+	gdImageSaveAlpha(im, 1);
+	bordercolor = gdImageColorAllocateAlpha(im, 0, 0, 0, 2);
+	color = gdImageColorAllocateAlpha(im, 0, 0, 0, 1);
+
+	gdImageFillToBorder(im, 5, 5, bordercolor, color);
+
+	color = gdImageGetPixel(im, 5, 5);
+
+ 	gdImageDestroy(im);
+	if (gdTestAssert(color==0x1000000)) {
+		return 0;
+	} else {
+		printf("c: %X, expected %X\n", color, 0x1000000);
+		return -1;
+	}
+
+}
+

src/tests/gdimageline/CMakeLists.txt

+SET(TESTS_FILES
+	gdimageline_aa
+	gdimageline_aa_outofrange
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	ADD_TEST(${test_name} ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)

src/tests/gdimageline/gdimageline_aa.c

+#include <gd.h>
+#include <stdio.h>
+#include <math.h>
+#include "gdtest.h"
+
+
+int gen_image(const char* filename, int idx, int reverse_x, int width, int height, int bgd)
+{
+   double gradient = height / (width*2.0);
+   int offset = idx*width;
+	int x1,y1,x2,y2, error = 0;
+
+   gdImagePtr im = gdImageCreateTrueColor(width,height);
+   if (bgd==1) {
+		gdImageFilledRectangle(im,0,0,width-1,height-1, gdTrueColorAlpha(255, 255, 255, 0));
+   } else {
+   	gdImageFilledRectangle(im,0,0,width-1,height-1, gdTrueColorAlpha(255, 255, 0, 0));
+   }
+
+   gdImageSetAntiAliased(im, gdTrueColorAlpha(0,0,0,0));
+
+   // test for potential segfault (introduced with AA improvements, fixed
+   // with the same patch - but I didn't notice it until later).
+   gdImageLine(im,-1,-1,-1,-1,gdAntiAliased);
+
+	x1 = floor(reverse_x * -width + 0.5);
+	y1 = (offset-width) * gradient + 0.5;
+
+	x2 = floor(reverse_x *  width*2 + 0.5);
+	y2 = floor((offset+width*2) * gradient + 0.5);
+
+   // draw an AA line
+   gdImageLine(im, x1, y1, x2, y2, gdAntiAliased);
+
+	gdImageLine(im, 0,im->sy - 1, im->sx, im->sy - 1, 0x40FF0000);
+
+	if (!gdAssertImageEqualsToFile(filename, im)) {
+		error = 1;
+	}
+   gdImageDestroy(im);
+   return error;
+}
+
+int main()
+{
+	int i;
+	int error = 0;
+
+	error |= gen_image("gdimageline_aa_a_0_exp.png",0,1,10,100, 1);
+	error |= gen_image("gdimageline_aa_a_1_exp.png",1,1,10,100, 2);
+
+	error |= gen_image("gdimageline_aa_b_0_exp.png",2,-1,10,100, 1);
+	error |= gen_image("gdimageline_aa_b_1_exp.png",1,-1,10,100, 2);
+
+
+	error |= gen_image("gdimageline_aa_c_0_exp.png",0,1,100,10, 1);
+	error |= gen_image("gdimageline_aa_c_1_exp.png",1,1,100,10, 2);
+
+	error |= gen_image("gdimageline_aa_d_0_exp.png",2,-1,100,10, 1);
+	error |= gen_image("gdimageline_aa_d_1_exp.png",1,-1,100,10, 2);
+
+   return error;
+}
Add a comment to this file

src/tests/gdimageline/gdimageline_aa_a_0_exp.png

Added
New image
Add a comment to this file

src/tests/gdimageline/gdimageline_aa_a_1_exp.png

Added
New image
Add a comment to this file

src/tests/gdimageline/gdimageline_aa_b_0_exp.png

Added
New image
Add a comment to this file

src/tests/gdimageline/gdimageline_aa_b_1_exp.png

Added
New image
Add a comment to this file

src/tests/gdimageline/gdimageline_aa_c_0_exp.png

Added
New image
Add a comment to this file

src/tests/gdimageline/gdimageline_aa_c_1_exp.png

Added
New image
Add a comment to this file

src/tests/gdimageline/gdimageline_aa_d_0_exp.png

Added
New image
Add a comment to this file

src/tests/gdimageline/gdimageline_aa_d_1_exp.png

Added
New image

src/tests/gdimageline/gdimageline_aa_outofrange.c

+#include <gd.h>
+#include <stdio.h>
+#include "gdtest.h"
+
+int main()
+{
+	gdImagePtr im;
+	int bordercolor, color;
+
+	im = gdImageCreateTrueColor(300, 300);
+
+   gdImageSetAntiAliased(im, gdTrueColorAlpha(255, 255, 255, 0));
+
+   gdImageLine(im, -1, -1, -1, -1, gdAntiAliased);
+   gdImageLine(im, 299, 299, 0, 299, gdAntiAliased);
+	gdImageLine(im, 1,1, 50, 50, gdAntiAliased);
+
+	/* Test for segfaults, if we reach this point, the test worked */
+	return 0;
+}

src/tests/gdimagerectangle/CMakeLists.txt

+
+add_executable(bug00003 bug00003.c)
+target_link_libraries (bug00003 gdTest ${GD_LIB})
+ADD_TEST(bug00003 ${EXECUTABLE_OUTPUT_PATH}/bug00003)

src/tests/gdimagerectangle/bug00003.c

+#include "gd.h"
+#include "gdtest.h"
+
+int main()
+{
+	gdImagePtr im;
+	FILE *fp;
+	int c1,c2,c3,c4;
+
+	im = gdImageCreateTrueColor(100,100);
+	gdImageRectangle(im, 2,2, 80,95, 0x50FFFFFF);
+	c1 = gdImageGetTrueColorPixel(im, 2, 2);
+	c2 = gdImageGetTrueColorPixel(im, 80, 95);
+	c3 = gdImageGetTrueColorPixel(im, 80, 2);
+	c4 = gdImageGetTrueColorPixel(im, 2, 95);
+
+	gdImageDestroy(im);
+	if (0x005e5e5e == c1 && 0x005e5e5e == c2 &&
+	 0x005e5e5e == c3 && 0x005e5e5e == c4) {
+	 	return 0;
+	} else {
+		return 1;
+	}
+}

src/tests/gdtest/CMakeLists.txt

+include_directories (${GDTEST_SOURCE_DIR}/cutest)
+add_library (gdTest gdtest.c)

src/tests/gdtest/gdtest.c

+#include <assert.h>
+#include <setjmp.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <gd.h>
+
+#include "gdtest.h"
+
+gdImagePtr gdTestImageFromPng(const char *filename)
+{
+	gdImagePtr image;
+
+	FILE *fp;
+
+	fp = fopen(filename, "rb");
+
+	if (!fp) {
+		return NULL;
+	}
+	image = gdImageCreateFromPng(fp);
+	fclose(fp);
+	return image;
+}
+
+/* Compare two buffers, returning the number of pixels that are
+ * different and the maximum difference of any single color channel in
+ * result_ret.
+ *
+ * This function should be rewritten to compare all formats supported by
+ * cairo_format_t instead of taking a mask as a parameter.
+ */
+void gdTestImageDiff(gdImagePtr buf_a, gdImagePtr buf_b,
+	gdImagePtr buf_diff, CuTestImageResult *result_ret)
+{
+	int x, y;
+	CuTestImageResult result = {0, 0};
+
+	int c1, c2;
+
+	for (y = 0; y < gdImageSY(buf_a); y++) {
+		for (x = 0; x < gdImageSX(buf_a); x++) {
+			c1 = gdImageGetTrueColorPixel(buf_a, x, y);
+			c2 = gdImageGetTrueColorPixel(buf_b, x, y);
+
+			/* check if the pixels are the same */
+			if (c1 != c2) {
+				int r1,b1,g1,a1,r2,b2,g2,a2;
+				unsigned int diff_a,diff_r,diff_g,diff_b;
+
+				a1 = gdTrueColorGetAlpha(c1);
+				a2 = gdTrueColorGetAlpha(c2);
+				diff_a = abs (a1 - a2);
+				diff_a *= 4;  /* emphasize */
+
+				if (diff_a) {
+					diff_a += 128; /* make sure it's visible */
+				}
+				if (diff_a > gdAlphaMax) {
+					diff_a = gdAlphaMax/2;
+				}
+
+				r1 = gdTrueColorGetRed(c1);
+				r2 = gdTrueColorGetRed(c2);
+				diff_r = abs (r1 - r2);
+				//diff_r *= 4;  /* emphasize */
+				if (diff_r) {
+					diff_r += gdRedMax/2; /* make sure it's visible */
+				}
+				if (diff_r > 255) {
+					diff_r = 255;
+				}
+
+				g1 = gdTrueColorGetGreen(c1);
+				g2 = gdTrueColorGetGreen(c2);
+				diff_g = abs (g1 - g2);
+				diff_g *= 4;  /* emphasize */
+				if (diff_g) {
+					diff_g += gdGreenMax/2; /* make sure it's visible */
+				}
+				if (diff_g > 255) {
+					diff_g = 255;
+				}
+
+				b1 = gdTrueColorGetBlue(c1);
+				b2 = gdTrueColorGetBlue(c2);
+				diff_b = abs (b1 - b2);
+				diff_b *= 4;  /* emphasize */
+				if (diff_b) {
+					diff_b += gdBlueMax/2; /* make sure it's visible */
+				}
+				if (diff_b > 255) {
+					diff_b = 255;
+				}
+
+				result.pixels_changed++;
+				gdImageSetPixel(buf_diff, x,y, gdTrueColorAlpha(diff_r, diff_g, diff_b, diff_a));
+			} else {
+				gdImageSetPixel(buf_diff, x,y, gdTrueColorAlpha(255,255,255,0));
+			}
+		}
+	}
+
+	*result_ret = result;
+}
+
+int gdTestImageCompareToImage(const char* file, int line, const char* message,
+	gdImagePtr expected, gdImagePtr actual)
+{
+	char buf[GDTEST_STRING_MAX];
+	unsigned int width_a, height_a;
+	unsigned int width_b, height_b;
+	gdImagePtr surface_diff = NULL;
+	CuTestImageResult result;
+
+	width_a  = gdImageSX(expected);
+	height_a = gdImageSY(expected);
+	width_b  = gdImageSX(actual);
+	height_b = gdImageSY(actual);
+
+	if (width_a  != width_b  || height_a != height_b) {
+		fprintf(stderr, "Image size mismatch: (%ux%u) vs. (%ux%u)\n       for %s vs. buffer\n",
+								width_a, height_a,
+								width_b, height_b,
+								file);
+		goto fail;
+	}
+
+	surface_diff = gdImageCreateTrueColor(width_a, height_a);
+
+	gdTestImageDiff(expected, actual, surface_diff, &result);
+	if (result.pixels_changed>0) {
+		char file_diff[255];
+		FILE *fp;
+
+		sprintf(buf, "Total pixels changed: %d with a maximum channel difference of %d.\n",
+			result.pixels_changed,
+			result.max_diff
+		);
+		sprintf(file_diff, "%s_%u_diff.png", file, line);
+		fp = fopen(file_diff, "wb");
+		gdImagePng(surface_diff,fp);
+		fclose(fp);
+	} else {
+		if (surface_diff) {
+			gdImageDestroy(surface_diff);
+		}
+		return 1;
+	}
+
+fail:
+	if (surface_diff) {
+		gdImageDestroy(surface_diff);
+	}
+	return 0;
+}
+
+int gdTestImageCompareToFile(const char* file, int line, const char* message,
+	const char *expected_file, gdImagePtr actual)
+{
+	char buf[GDTEST_STRING_MAX];
+	gdImagePtr expected;
+	int res = 1;
+
+	expected = gdTestImageFromPng(expected_file);
+
+	if (!expected) {
+		gdTestErrorMsg("Cannot open PNG <%s>", expected_file, file, line);
+		res = 0;
+	} else {
+		res = gdTestImageCompareToImage(file, line, message, expected, actual);
+		gdImageDestroy(expected);
+	}
+	return res;
+}
+
+int _gdTestAssert(const char* file, int line, const char* message, int condition)
+{
+	if (condition) return 1;
+	gdTestErrorMsg(message, file, line);
+	return 0;
+}
+
+int _gdTestErrorMsg(const char* file, int line, const char* format, ...) /* {{{ */
+{
+ char output_buf[512];
+ va_list args;
+ char *debug;
+
+ va_start (args, format);
+ vsnprintf (output_buf, sizeof (output_buf), format, args);
+ va_end (args);
+
+ fputs (output_buf, stderr);
+ fflush (stderr);
+}
+/* }}} */

src/tests/gdtest/gdtest.h

+#ifndef GD_TEST_H
+#define GD_TEST_H
+
+#include <stdarg.h>
+#include <gd.h>
+#define GDTEST_STRING_MAX 1024
+typedef struct CuTestImageResult CuTestImageResult;
+struct CuTestImageResult {
+    unsigned int pixels_changed;
+    unsigned int max_diff;
+};
+
+
+/* Internal versions of assert functions -- use the public versions */
+gdImagePtr gdTestImageFromPng(const char *filename);
+
+void gdTestImageDiff(gdImagePtr buf_a, gdImagePtr buf_b,
+	gdImagePtr buf_diff, CuTestImageResult *result_ret);
+
+int gdTestImageCompareToImage(const char* file, int line, const char* message,
+	gdImagePtr expected, gdImagePtr actual);
+
+int gdTestImageCompareToFile(const char* file, int line, const char* message,
+	const char *expected_file, gdImagePtr actual);
+
+int _gdTestErrorMsg(const char* file, int line, const char* string, ...);
+
+/* public assert functions */
+#define gdAssertImageEqualsToFile(ex,ac) gdTestImageCompareToFile(__FILE__,__LINE__,NULL,(ex),(ac))
+#define gdAssertImageFileEqualsMsg(ex,ac) gdTestImageCompareFiles(__FILE__,__LINE__,(ms),(ex),(ac))
+
+#define gdAssertImageEquals(tc,ex,ac) CuAssertImageEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
+#define gdAssertImageEqualsMsg(tc,ex,ac) CuAssertImageEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
+
+#define gdTestAssert(cond) _gdTestAssert(__FILE__, __LINE__, "assert failed in <%s:%i>\n", (cond))
+
+#define gdTestErrorMsg(format, ...) _gdTestErrorMsg(__FILE__, __LINE__, format, ## __VA_ARGS__)
+
+#endif /* GD_TEST_H */

src/tests/gdtiled/CMakeLists.txt

+add_executable(bug00032 bug00032.c)
+
+target_link_libraries (bug00032 gdTest ${GD_LIB})
+
+ADD_TEST(bug00032 ${EXECUTABLE_OUTPUT_PATH}/bug00032)

src/tests/gdtiled/bug00032.c

+#include <gd.h>
+#include <stdio.h>
+#include "gdtest.h"
+
+#define exp_img "bug00032_exp.png"
+
+int main()
+{
+	gdImagePtr im, tile;
+	char exp[] = "bug00032_exp.png";
+	FILE *fp;
+
+	tile = gdImageCreateTrueColor(10, 10);
+	gdImageFill(tile, 0, 0, 0xFFFFFF);
+	gdImageLine(tile, 0,0, 9,9, 0xff0000);
+	gdImageColorTransparent(tile, 0xFFFFFF);
+
+	im = gdImageCreateTrueColor(50, 50);
+	gdImageFilledRectangle(im, 0, 0, 25, 25, 0x00FF00);
+
+	gdImageSetTile(im, tile);
+	gdImageFilledRectangle(im, 10, 10, 49, 49, gdTiled);
+
+	gdAssertImageEqualsToFile(exp_img, im);
+
+ 	/* Destroy it */
+ 	gdImageDestroy(im);
+ 	gdImageDestroy(tile);
+	return 0;
+}
+
Add a comment to this file

src/tests/gdtiled/bug00032_exp.png

Added
New image

src/tests/gif/CMakeLists.txt

+
+SET(TESTS_FILES
+	bug00005
+	bug00005_2
+	bug00006
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	ADD_TEST(${test_name} ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.