summaryrefslogtreecommitdiff
path: root/tests/gdimagerotate
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2016-06-03 20:31:02 -0400
committerMike Frysinger <vapier@gentoo.org>2016-06-15 10:01:20 -0400
commitd01056211e9edce7110a809304634d2dd23c76ed (patch)
tree5c2569fe00f173a9ee0670eb9e55fdbdf5d14873 /tests/gdimagerotate
parent81d94b1c66cdd0e89471cd6740c5db8cbd4aa8f8 (diff)
downloadlibgd-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/gdimagerotate')
-rw-r--r--tests/gdimagerotate/bug00067.c21
-rw-r--r--tests/gdimagerotate/php_bug_64898.c29
2 files changed, 14 insertions, 36 deletions
diff --git a/tests/gdimagerotate/bug00067.c b/tests/gdimagerotate/bug00067.c
index cd455dc..add483d 100644
--- a/tests/gdimagerotate/bug00067.c
+++ b/tests/gdimagerotate/bug00067.c
@@ -7,29 +7,19 @@
int main()
{
gdImagePtr im, exp;
- char path[2048];
+ char *path, filename[2048];
const char *file_im = "gdimagerotate/remirh128.png";
- const char *file_exp = "gdimagerotate/bug00067";
FILE *fp;
int color;
int error = 0;
int angle;
- sprintf(path, "%s/%s", GDTEST_TOP_DIR, file_im);
-
- fp = fopen(path, "rb");
-
- if (!fp) {
- gdTestErrorMsg("opening Jpeg %s for reading failed.\n", path);
- return 1;
- }
-
+ fp = gdTestFileOpen(file_im);
im = gdImageCreateFromPng(fp);
-
fclose(fp);
if (!im) {
- gdTestErrorMsg("loading %s failed.\n", path);
+ gdTestErrorMsg("loading %s failed.\n", file_im);
return 1;
}
@@ -51,12 +41,13 @@ int main()
return 1;
}
- sprintf(path, "%s/%s_%03d_exp.png", GDTEST_TOP_DIR, file_exp, angle);
-
+ sprintf(filename, "bug00067_%03d_exp.png", angle);
+ path = gdTestFilePath2("gdimagerotate", filename);
if (!gdAssertImageEqualsToFile(path, exp)) {
gdTestErrorMsg("comparing rotated image to %s failed.\n", path);
error += 1;
}
+ free(path);
gdImageDestroy(exp);
}
diff --git a/tests/gdimagerotate/php_bug_64898.c b/tests/gdimagerotate/php_bug_64898.c
index 99bf04e..6b723df 100644
--- a/tests/gdimagerotate/php_bug_64898.c
+++ b/tests/gdimagerotate/php_bug_64898.c
@@ -7,24 +7,15 @@
int main()
{
gdImagePtr im, exp;
- char path[2048];
- const char *file_im = "gdimagerotate/php_bug_64898.png";
- const char *file_exp = "gdimagerotate/php_bug_64898_exp.png";
FILE *fp;
+ int error = 0;
- sprintf(path, "%s/%s", GDTEST_TOP_DIR, file_im);
-
- fp = fopen(path, "rb");
-
- if (!fp) {
- gdTestErrorMsg("opening PNG %s for reading failed.\n", path);
- return 1;
- }
-
+ fp = gdTestFileOpen("gdimagerotate/php_bug_64898.png");
+(void)fp;
im = gdImageCreateTrueColor(141, 200);
if (!im) {
- gdTestErrorMsg("loading %s failed.\n", path);
+ gdTestErrorMsg("loading failed.\n");
return 1;
}
@@ -41,17 +32,13 @@ int main()
return 1;
}
- sprintf(path, "%s/%s", GDTEST_TOP_DIR, file_exp);
-
- if (!gdAssertImageEqualsToFile(path, exp)) {
- printf("comparing rotated image to %s failed.\n", path);
- gdImageDestroy(im);
- gdImageDestroy(exp);
- return 1;
+ if (!gdAssertImageEqualsToFile("gdimagerotate/php_bug_64898_exp.png", exp)) {
+ printf("comparing rotated image failed.\n");
+ error = 1;
}
gdImageDestroy(exp);
gdImageDestroy(im);
- return 0;
+ return error;
}