diff options
author | Mike Frysinger <vapier@gentoo.org> | 2016-06-03 20:31:02 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2016-06-15 10:01:20 -0400 |
commit | d01056211e9edce7110a809304634d2dd23c76ed (patch) | |
tree | 5c2569fe00f173a9ee0670eb9e55fdbdf5d14873 /tests/gdimageline | |
parent | 81d94b1c66cdd0e89471cd6740c5db8cbd4aa8f8 (diff) | |
download | libgd-d01056211e9edce7110a809304634d2dd23c76ed.tar.gz |
tests: add helpers for accessing test data
A lot of tests want to read images/fonts that exist in tests/ for reading.
Rather than construct these paths by hand in every single test file, add a
few helper functions to quickly access them.
The helper functions are slightly slower (due to the repeated calls to the
strcat func), but they aren't terribly slow, especially relative to image
loading that these tests perform. They also make writing/maintaining the
tests a lot easier which is more important here.
Fixes #231.
Diffstat (limited to 'tests/gdimageline')
-rw-r--r-- | tests/gdimageline/bug00072.c | 7 | ||||
-rw-r--r-- | tests/gdimageline/bug00077.c | 8 | ||||
-rw-r--r-- | tests/gdimageline/bug00111.c | 5 | ||||
-rw-r--r-- | tests/gdimageline/gdImageAALine_thickness.c | 14 | ||||
-rw-r--r-- | tests/gdimageline/gdimageline_aa.c | 29 |
5 files changed, 15 insertions, 48 deletions
diff --git a/tests/gdimageline/bug00072.c b/tests/gdimageline/bug00072.c index c3a3137..72e9fca 100644 --- a/tests/gdimageline/bug00072.c +++ b/tests/gdimageline/bug00072.c @@ -4,12 +4,8 @@ int main() { gdImagePtr im; - const char *exp = "bug00072_exp.png"; int error = 0; - char path[1024]; - - im = gdImageCreateTrueColor(11, 11); gdImageFilledRectangle(im, 0, 0, 10, 10, 0xFFFFFF); gdImageSetThickness(im, 3); @@ -24,8 +20,7 @@ int main() gdImageLine(im, 0, 5, 11, 5, 0xFF0000); gdImageLine(im, 0, 0, 11, 11, 0xFF0000); - sprintf(path, "%s/gdimageline/%s", GDTEST_TOP_DIR, exp); - if (!gdAssertImageEqualsToFile(path, im)) { + if (!gdAssertImageEqualsToFile("gdimageline/bug00072_exp.png", im)) { error = 1; } diff --git a/tests/gdimageline/bug00077.c b/tests/gdimageline/bug00077.c index d69e881..7c52bbe 100644 --- a/tests/gdimageline/bug00077.c +++ b/tests/gdimageline/bug00077.c @@ -4,12 +4,8 @@ int main() { gdImagePtr im; - const char *exp = "bug00077_exp.png"; int error = 0; - char path[1024]; - - im = gdImageCreateTrueColor(11, 11); gdImageFilledRectangle(im, 0, 0, 10, 10, 0xFFFFFF); gdImageSetThickness(im, 1); @@ -19,9 +15,7 @@ int main() gdImageLine(im, 10, 5, 0, 5, 0x0); gdImageLine(im, 10, 10, 0, 10, 0x0); - sprintf(path, "%s/gdimageline/%s", GDTEST_TOP_DIR, exp); - - if (!gdAssertImageEqualsToFile(path, im)) { + if (!gdAssertImageEqualsToFile("gdimageline/bug00077_exp.png", im)) { error = 1; } diff --git a/tests/gdimageline/bug00111.c b/tests/gdimageline/bug00111.c index 4277534..0cf2d34 100644 --- a/tests/gdimageline/bug00111.c +++ b/tests/gdimageline/bug00111.c @@ -9,8 +9,6 @@ int main() { gdImagePtr im; int error = 0; - char path[2048]; - const char *file_exp = "bug00111_exp.png"; im = gdImageCreateTrueColor(10, 10); if (!im) { @@ -23,8 +21,7 @@ int main() gdImageLine(im, 0, 0, 0, 0, 0xFFFFFF); - sprintf(path, "%s/gdimageline/%s", GDTEST_TOP_DIR, file_exp); - if (!gdAssertImageEqualsToFile(path, im)) { + if (!gdAssertImageEqualsToFile("gdimageline/bug00111_exp.png", im)) { error = 1; printf("Reference image and destination differ\n"); } diff --git a/tests/gdimageline/gdImageAALine_thickness.c b/tests/gdimageline/gdImageAALine_thickness.c index 954e055..de9c254 100644 --- a/tests/gdimageline/gdImageAALine_thickness.c +++ b/tests/gdimageline/gdImageAALine_thickness.c @@ -5,8 +5,7 @@ int main(int argc, char **argv) { gdImagePtr im; - char path[2048]; - const char *file_exp = "gdimageline/gdImageAALine_thickness_exp.png"; + int error = 0; im = gdImageCreateTrueColor(100, 100); gdImageFilledRectangle(im, 0, 0, 99, 99, @@ -16,15 +15,10 @@ int main(int argc, char **argv) gdImageSetAntiAliased(im, gdImageColorExactAlpha(im, 0, 0, 0, 0)); gdImageLine(im, 0,0, 99, 99, gdAntiAliased); - sprintf(path, "%s/%s", GDTEST_TOP_DIR, file_exp); - - if (!gdAssertImageEqualsToFile(path, im)) { - printf("comparing rotated image to %s failed.\n", path); - gdImageDestroy(im); - return 1; - } + if (!gdAssertImageEqualsToFile("gdimageline/gdImageAALine_thickness_exp.png", im)) + error = 1; gdImageDestroy(im); - return 0; + return error; } diff --git a/tests/gdimageline/gdimageline_aa.c b/tests/gdimageline/gdimageline_aa.c index b0bea3a..f16bfb9 100644 --- a/tests/gdimageline/gdimageline_aa.c +++ b/tests/gdimageline/gdimageline_aa.c @@ -3,10 +3,6 @@ #include "gd.h" #include "gdtest.h" -#ifdef _MSC_VER -# define snprintf _snprintf -#endif - int gen_image(const char* filename, int idx, int reverse_x, int width, int height, int bgd) { double gradient = height / (width*2.0); @@ -49,28 +45,19 @@ int gen_image(const char* filename, int idx, int reverse_x, int width, int heigh int main() { int error = 0; - char path[1024]; - snprintf(path, sizeof(path)-1, "%s/gdimageline/gdimageline_aa_a_0_exp.png", GDTEST_TOP_DIR); - error |= gen_image(path,0,1,10,100, 1); + error |= gen_image("gdimageline/gdimageline_aa_a_0_exp.png", 0, 1, 10, 100, 1); - snprintf(path, sizeof(path)-1, "%s/gdimageline/gdimageline_aa_a_1_exp.png", GDTEST_TOP_DIR); - error |= gen_image(path,1,1,10,100, 2); + error |= gen_image("gdimageline/gdimageline_aa_a_1_exp.png", 1, 1, 10, 100, 2); - snprintf(path, sizeof(path)-1, "%s/gdimageline/gdimageline_aa_b_0_exp.png", GDTEST_TOP_DIR); - error |= gen_image(path,2,-1,10,100, 1); - snprintf(path, sizeof(path)-1, "%s/gdimageline/gdimageline_aa_b_1_exp.png", GDTEST_TOP_DIR); - error |= gen_image(path,1,-1,10,100, 2); + error |= gen_image("gdimageline/gdimageline_aa_b_0_exp.png", 2, -1, 10, 100, 1); + error |= gen_image("gdimageline/gdimageline_aa_b_1_exp.png", 1, -1, 10, 100, 2); - snprintf(path, sizeof(path)-1, "%s/gdimageline/gdimageline_aa_c_0_exp.png", GDTEST_TOP_DIR); - error |= gen_image(path,0,1,100,10, 1); - snprintf(path, sizeof(path)-1, "%s/gdimageline/gdimageline_aa_c_1_exp.png", GDTEST_TOP_DIR); - error |= gen_image(path,1,1,100,10, 2); + error |= gen_image("gdimageline/gdimageline_aa_c_0_exp.png", 0, 1, 100, 10, 1); + error |= gen_image("gdimageline/gdimageline_aa_c_1_exp.png", 1, 1, 100, 10, 2); - snprintf(path, sizeof(path)-1, "%s/gdimageline/gdimageline_aa_d_0_exp.png", GDTEST_TOP_DIR); - error |= gen_image(path,2,-1,100,10, 1); - snprintf(path, sizeof(path)-1, "%s/gdimageline/gdimageline_aa_d_1_exp.png", GDTEST_TOP_DIR); - error |= gen_image(path,1,-1,100,10, 2); + error |= gen_image("gdimageline/gdimageline_aa_d_0_exp.png", 2, -1, 100, 10, 1); + error |= gen_image("gdimageline/gdimageline_aa_d_1_exp.png", 1, -1, 100, 10, 2); return error; } |