summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorwilson chen <willson.chenwx@gmail.com>2019-12-24 23:07:43 +0800
committerGitHub <noreply@github.com>2019-12-24 23:07:43 +0800
commit8321d47931251c680ea3492d60e97d93d56559ab (patch)
tree0ac74670869611fb717903aebae1d5ea04017073 /tests
parent13705fe80f9a39b21c1e1b605760937f7916a7e2 (diff)
downloadlibgd-8321d47931251c680ea3492d60e97d93d56559ab.tar.gz
add testcase for gdimagecreatefromgd2partptr
Diffstat (limited to 'tests')
-rw-r--r--tests/gd2/.gitignore1
-rw-r--r--tests/gd2/CMakeLists.txt1
-rw-r--r--tests/gd2/Makemodule.am1
-rw-r--r--tests/gd2/createimagefromgd2partptr.c59
4 files changed, 62 insertions, 0 deletions
diff --git a/tests/gd2/.gitignore b/tests/gd2/.gitignore
index ac13033..d21010c 100644
--- a/tests/gd2/.gitignore
+++ b/tests/gd2/.gitignore
@@ -3,6 +3,7 @@
/bug00309
/bug00354
/bug00383
+/createimagefromgd2partptr
/gd2_empty_file
/gd2_im2im
/gd2_null
diff --git a/tests/gd2/CMakeLists.txt b/tests/gd2/CMakeLists.txt
index 6639b7e..f52f0fe 100644
--- a/tests/gd2/CMakeLists.txt
+++ b/tests/gd2/CMakeLists.txt
@@ -6,6 +6,7 @@ LIST(APPEND TESTS_FILES
bug00309
bug00354
bug00383
+ createimagefromgd2partptr
gd2_empty_file
php_bug_72339
gd2_null
diff --git a/tests/gd2/Makemodule.am b/tests/gd2/Makemodule.am
index 0eddb58..10b4b95 100644
--- a/tests/gd2/Makemodule.am
+++ b/tests/gd2/Makemodule.am
@@ -6,6 +6,7 @@ libgd_test_programs += \
gd2/bug00309 \
gd2/bug00354 \
gd2/bug00383 \
+ gd2/createimagefromgd2partptr \
gd2/gd2_empty_file \
gd2/php_bug_72339 \
gd2/gd2_null \
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;
+}