]> granicus.if.org Git - php/commitdiff
New image tests. Tested on Windows, LInux and Linux 64 bit
authorandy wharmby <wharmby@php.net>
Thu, 22 Jan 2009 13:27:22 +0000 (13:27 +0000)
committerandy wharmby <wharmby@php.net>
Thu, 22 Jan 2009 13:27:22 +0000 (13:27 +0000)
18 files changed:
ext/gd/tests/gd_info_error.phpt [new file with mode: 0644]
ext/gd/tests/gd_info_variation1.phpt [new file with mode: 0644]
ext/gd/tests/image_type_to_mime_type_error.phpt [new file with mode: 0644]
ext/gd/tests/image_type_to_mime_type_variation1.phpt [new file with mode: 0644]
ext/gd/tests/image_type_to_mime_type_variation2.phpt [new file with mode: 0644]
ext/gd/tests/image_type_to_mime_type_variation3.phpt [new file with mode: 0644]
ext/gd/tests/image_type_to_mime_type_variation4.phpt [new file with mode: 0644]
ext/gd/tests/imagecolorallocate_basic.phpt [new file with mode: 0644]
ext/gd/tests/imagecolorallocate_error.phpt [new file with mode: 0644]
ext/gd/tests/imagecolorallocate_variation1.phpt [new file with mode: 0644]
ext/gd/tests/imagecolorallocate_variation2.phpt [new file with mode: 0644]
ext/gd/tests/imagecolorallocate_variation3.phpt [new file with mode: 0644]
ext/gd/tests/imagecolorallocate_variation4.phpt [new file with mode: 0644]
ext/gd/tests/imagecolorallocate_variation5.phpt [new file with mode: 0644]
ext/gd/tests/imagecolorallocate_variation6.phpt [new file with mode: 0644]
ext/gd/tests/imagecolorstotal_basic.phpt [new file with mode: 0644]
ext/gd/tests/imagecolorstotal_error.phpt [new file with mode: 0644]
ext/gd/tests/php.gif [new file with mode: 0644]

diff --git a/ext/gd/tests/gd_info_error.phpt b/ext/gd/tests/gd_info_error.phpt
new file mode 100644 (file)
index 0000000..514530c
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--
+Test gd_info() function : error conditions - with more than expected number of arguments
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+    die('skip gd extension is not loaded');
+}
+if(!function_exists('gd_info')) {
+    die('skip gd_info function is not available');
+}
+?>
+--FILE--
+<?php
+/* Prototype  : array gd_info()
+ * Description: Retrieve information about the currently installed GD library
+ * Source code: ext/gd/gd.c
+ */
+$extra_arg_number = 10;
+$extra_arg_string = "Hello";
+
+echo "*** Testing gd_info() : error conditions ***\n";
+
+echo "\n-- Testing gd_info() function with more than expected number of arguments --\n";
+var_dump(gd_info($extra_arg_number));
+var_dump(gd_info($extra_arg_string, $extra_arg_number));
+?>
+===DONE===
+--EXPECTF--
+*** Testing gd_info() : error conditions ***
+
+-- Testing gd_info() function with more than expected number of arguments --
+
+Warning: Wrong parameter count for gd_info() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for gd_info() in %s on line %d
+NULL
+===DONE===
\ No newline at end of file
diff --git a/ext/gd/tests/gd_info_variation1.phpt b/ext/gd/tests/gd_info_variation1.phpt
new file mode 100644 (file)
index 0000000..5430ced
--- /dev/null
@@ -0,0 +1,50 @@
+--TEST--
+Test gd_info() function : variation - Checking all the values in returned array
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+    die('skip gd extension is not loaded');
+}
+if(!function_exists('gd_info')) {
+    die('skip gd_info function is not available');
+}
+?>
+--FILE--
+<?php
+/* Prototype  : array gd_info()
+ * Description: Retrieve information about the currently installed GD library
+ * Source code: ext/gd/gd.c
+ */
+
+echo "*** Testing gd_info() : variation ***\n";
+
+var_dump(gd_info());
+?>
+===DONE===
+--EXPECTF--
+*** Testing gd_info() : variation ***
+array(%d) {
+  ["GD Version"]=>
+  string(%d) "%s"
+  ["FreeType Support"]=>
+  bool(%s)%A
+  ["T1Lib Support"]=>
+  bool(%s)
+  ["GIF Read Support"]=>
+  bool(%s)
+  ["GIF Create Support"]=>
+  bool(%s)
+  ["JPG Support"]=>
+  bool(%s)
+  ["PNG Support"]=>
+  bool(%s)
+  ["WBMP Support"]=>
+  bool(%s)
+  ["XPM Support"]=>
+  bool(%s)
+  ["XBM Support"]=>
+  bool(%s)
+  ["JIS-mapped Japanese Font Support"]=>
+  bool(%s)
+}
+===DONE===
\ No newline at end of file
diff --git a/ext/gd/tests/image_type_to_mime_type_error.phpt b/ext/gd/tests/image_type_to_mime_type_error.phpt
new file mode 100644 (file)
index 0000000..5ecdce7
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Test image_type_to_mime_type() function : error conditions  - Pass incorrect number of arguments
+--FILE--
+<?php
+/* Prototype  : proto string image_type_to_mime_type(int imagetype)
+ * Description: Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype 
+ * Source code: ext/standard/image.c
+ */
+
+$imagetype = IMAGETYPE_GIF;
+$extra_arg = 10;
+echo "*** Testing image_type_to_mime_type() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing image_type_to_mime_type() function with Zero arguments --\n";
+var_dump( image_type_to_mime_type() );
+
+//Test image_type_to_mime_type with one more than the expected number of arguments
+echo "\n-- Testing image_type_to_mime_type() function with more than expected no. of arguments --\n";
+var_dump( image_type_to_mime_type($imagetype, $extra_arg) );
+?>
+===DONE===
+--EXPECTF--
+*** Testing image_type_to_mime_type() : error conditions ***
+
+-- Testing image_type_to_mime_type() function with Zero arguments --
+
+Warning: Wrong parameter count for image_type_to_mime_type() in %s on line %d
+bool(false)
+
+-- Testing image_type_to_mime_type() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for image_type_to_mime_type() in %s on line %d
+bool(false)
+===DONE===
\ No newline at end of file
diff --git a/ext/gd/tests/image_type_to_mime_type_variation1.phpt b/ext/gd/tests/image_type_to_mime_type_variation1.phpt
new file mode 100644 (file)
index 0000000..1747524
--- /dev/null
@@ -0,0 +1,138 @@
+--TEST--
+Test image_type_to_mime_type() function : usage variations  - Pass different data types as imagetype
+--FILE--
+<?php
+/* Prototype  : string image_type_to_mime_type(int imagetype)
+ * Description: Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype 
+ * Source code: ext/standard/image.c
+ */
+
+echo "*** Testing image_type_to_mime_type() : usage variations ***\n";
+
+error_reporting(E_ALL ^ E_NOTICE);
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+class MyClass
+{
+  function __toString() {
+    return "MyClass";
+  }
+}
+
+//array of values to iterate over
+$values = array(
+
+      // float data
+      100.5,
+      -100.5,
+      100.1234567e10,
+      100.7654321E-10,
+      .5,
+
+      // array data
+      array(),
+      array('color' => 'red', 'item' => 'pen'),
+
+      // null data
+      NULL,
+      null,
+
+      // boolean data
+      true,
+      false,
+      TRUE,
+      FALSE,
+
+      // empty data
+      "",
+      '',
+
+      // string data
+      "string",
+      'string',
+
+      // object data
+      new MyClass(),
+
+      // undefined data
+      @$undefined_var,
+
+      // unset data
+      @$unset_var,
+);
+
+// loop through each element of the array for imagetype
+$iterator = 1;
+foreach($values as $value) {
+      echo "\n-- Iteration $iterator --\n";
+      var_dump( image_type_to_mime_type($value) );
+      $iterator++;
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing image_type_to_mime_type() : usage variations ***
+
+-- Iteration 1 --
+string(24) "application/octet-stream"
+
+-- Iteration 2 --
+string(24) "application/octet-stream"
+
+-- Iteration 3 --
+string(24) "application/octet-stream"
+
+-- Iteration 4 --
+string(24) "application/octet-stream"
+
+-- Iteration 5 --
+string(24) "application/octet-stream"
+
+-- Iteration 6 --
+string(24) "application/octet-stream"
+
+-- Iteration 7 --
+string(9) "image/gif"
+
+-- Iteration 8 --
+string(24) "application/octet-stream"
+
+-- Iteration 9 --
+string(24) "application/octet-stream"
+
+-- Iteration 10 --
+string(9) "image/gif"
+
+-- Iteration 11 --
+string(24) "application/octet-stream"
+
+-- Iteration 12 --
+string(9) "image/gif"
+
+-- Iteration 13 --
+string(24) "application/octet-stream"
+
+-- Iteration 14 --
+string(24) "application/octet-stream"
+
+-- Iteration 15 --
+string(24) "application/octet-stream"
+
+-- Iteration 16 --
+string(24) "application/octet-stream"
+
+-- Iteration 17 --
+string(24) "application/octet-stream"
+
+-- Iteration 18 --
+string(9) "image/gif"
+
+-- Iteration 19 --
+string(24) "application/octet-stream"
+
+-- Iteration 20 --
+string(24) "application/octet-stream"
+===DONE===
\ No newline at end of file
diff --git a/ext/gd/tests/image_type_to_mime_type_variation2.phpt b/ext/gd/tests/image_type_to_mime_type_variation2.phpt
new file mode 100644 (file)
index 0000000..141bc57
--- /dev/null
@@ -0,0 +1,80 @@
+--TEST--
+Test image_type_to_mime_type() function : usage variations  - Pass decimal, octal, and hexadecimal values as imagetype
+--FILE--
+<?php
+/* Prototype  : string image_type_to_mime_type(int imagetype)
+ * Description: Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype 
+ * Source code: ext/standard/image.c
+ */
+
+echo "*** Testing image_type_to_mime_type() : usage variations ***\n";
+
+error_reporting(E_ALL ^ E_NOTICE);
+$values =  array (
+  //Decimal values
+  0,
+  1,
+  12345,
+  -12345,
+  
+  //Octal values
+  02,
+  010,
+  030071,
+  -030071,
+  
+  //Hexadecimal values
+  0x0,
+  0x1,
+  0xABCD,
+  -0xABCD
+);
+
+// loop through each element of the array for imagetype
+$iterator = 1;
+foreach($values as $value) {
+      echo "\n-- Iteration $iterator --\n";
+      var_dump( image_type_to_mime_type($value) );
+      $iterator++;
+};
+?>
+===DONE===
+--EXPECT--
+*** Testing image_type_to_mime_type() : usage variations ***
+
+-- Iteration 1 --
+string(24) "application/octet-stream"
+
+-- Iteration 2 --
+string(9) "image/gif"
+
+-- Iteration 3 --
+string(24) "application/octet-stream"
+
+-- Iteration 4 --
+string(24) "application/octet-stream"
+
+-- Iteration 5 --
+string(10) "image/jpeg"
+
+-- Iteration 6 --
+string(10) "image/tiff"
+
+-- Iteration 7 --
+string(24) "application/octet-stream"
+
+-- Iteration 8 --
+string(24) "application/octet-stream"
+
+-- Iteration 9 --
+string(24) "application/octet-stream"
+
+-- Iteration 10 --
+string(9) "image/gif"
+
+-- Iteration 11 --
+string(24) "application/octet-stream"
+
+-- Iteration 12 --
+string(24) "application/octet-stream"
+===DONE===
diff --git a/ext/gd/tests/image_type_to_mime_type_variation3.phpt b/ext/gd/tests/image_type_to_mime_type_variation3.phpt
new file mode 100644 (file)
index 0000000..4838904
--- /dev/null
@@ -0,0 +1,76 @@
+--TEST--
+Test image_type_to_mime_type() function : usage variations  - Pass equivalent imagetype constant integer values
+--FILE--
+<?php
+/* Prototype  : string image_type_to_mime_type(int imagetype)
+ * Description: Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype 
+ * Source code: ext/standard/image.c
+ */
+
+echo "*** Testing image_type_to_mime_type() : usage variations ***\n";
+
+//There are 17 imagetypes
+$number_of_imagetypes = 17;
+
+$iterator = 1;
+for($imagetype = 1; $imagetype<=$number_of_imagetypes; $imagetype++) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( image_type_to_mime_type($imagetype) );
+  $iterator++;
+}
+?>
+===DONE===
+--EXPECTREGEX--
+\*\*\* Testing image_type_to_mime_type\(\) : usage variations \*\*\*
+
+-- Iteration 1 --
+string\(9\) "image\/gif"
+
+-- Iteration 2 --
+string\(10\) "image\/jpeg"
+
+-- Iteration 3 --
+string\(9\) "image\/png"
+
+-- Iteration 4 --
+string\(29\) "application\/x-shockwave-flash"
+
+-- Iteration 5 --
+string\(9\) "image\/psd"
+
+-- Iteration 6 --
+string\(9\) "image\/bmp"
+
+-- Iteration 7 --
+string\(10\) "image\/tiff"
+
+-- Iteration 8 --
+string\(10\) "image\/tiff"
+
+-- Iteration 9 --
+string\(24\) "application\/octet-stream"
+
+-- Iteration 10 --
+string\(9\) "image\/jp2"
+
+-- Iteration 11 --
+string\(24\) "application\/octet-stream"
+
+-- Iteration 12 --
+string\(24\) "application\/octet-stream"
+
+-- Iteration 13 --
+string\(2[49]\) "application\/(x-shockwave-flash|octet-stream)"
+
+-- Iteration 14 --
+string\(9\) "image\/iff"
+
+-- Iteration 15 --
+string\(18\) "image\/vnd.wap.wbmp"
+
+-- Iteration 16 --
+string\(9\) "image\/xbm"
+
+-- Iteration 17 --
+string\(24\) "application\/octet-stream"
+===DONE===
diff --git a/ext/gd/tests/image_type_to_mime_type_variation4.phpt b/ext/gd/tests/image_type_to_mime_type_variation4.phpt
new file mode 100644 (file)
index 0000000..90ae17b
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Test image_type_to_mime_type() function : usage variations  - Passing IMAGETYPE_ICO and IMAGETYPE_SWC
+--FILE--
+<?php
+/* Prototype  : string image_type_to_mime_type(int imagetype)
+ * Description: Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype 
+ * Source code: ext/standard/image.c
+ */
+
+
+echo "*** Testing image_type_to_mime_type() : usage variations ***\n";
+
+error_reporting(E_ALL ^ E_NOTICE);
+
+var_dump( image_type_to_mime_type(IMAGETYPE_ICO) );
+var_dump( image_type_to_mime_type(IMAGETYPE_SWC) );
+?>
+===DONE===
+--EXPECTREGEX--
+\*\*\* Testing image_type_to_mime_type\(\) : usage variations \*\*\*
+string\(24\) "application\/octet-stream"
+string\(2[49]\) "application\/(x-shockwave-flash|octet-stream)"
+===DONE===
\ No newline at end of file
diff --git a/ext/gd/tests/imagecolorallocate_basic.phpt b/ext/gd/tests/imagecolorallocate_basic.phpt
new file mode 100644 (file)
index 0000000..25b2821
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Test imagecolorallocate() function : basic functionality
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+    die('skip gd extension is not loaded');
+}
+if(!function_exists('imagecreatetruecolor')) {
+    die('skip imagecreatetruecolor function is not available');
+}
+?> 
+--FILE--
+<?php
+/* Prototype  : int imagecolorallocate(resource im, int red, int green, int blue)
+ * Description: Allocate a color for an image
+ * Source code: ext/gd/gd.c
+ */
+
+echo "*** Testing imagecolorallocate() : basic functionality ***\n";
+
+$im = imagecreatetruecolor(200, 200);
+// Calling imagecolorallocate() with all possible arguments
+var_dump( imagecolorallocate($im, 255, 0, 0) );
+var_dump( imagecolorallocate($im, 0, 255, 0) );
+var_dump( imagecolorallocate($im, 0, 0, 255) );
+var_dump( imagecolorallocate($im, 255, 255, 255) );
+?>
+===DONE===
+--EXPECTF--
+*** Testing imagecolorallocate() : basic functionality ***
+int(16711680)
+int(65280)
+int(255)
+int(16777215)
+===DONE===
\ No newline at end of file
diff --git a/ext/gd/tests/imagecolorallocate_error.phpt b/ext/gd/tests/imagecolorallocate_error.phpt
new file mode 100644 (file)
index 0000000..fa05e91
--- /dev/null
@@ -0,0 +1,51 @@
+--TEST--
+Test imagecolorallocate() function : error conditions 
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+    die('skip gd extension is not loaded');
+}
+?> 
+--FILE--
+<?php
+/* Prototype  : int imagecolorallocate(resource im, int red, int green, int blue)
+ * Description: Allocate a color for an image
+ * Source code: ext/gd/gd.c
+ */
+
+$red = 10;
+$green = 10;
+$blue = 10;
+$extra_arg = 10;
+$im = imagecreate(200, 200);
+
+echo "*** Testing imagecolorallocate() : error conditions ***\n";
+
+//Test imagecolorallocate with one more than the expected number of arguments
+echo "\n-- Testing imagecolorallocate() function with more than expected no. of arguments --\n";
+var_dump( imagecolorallocate($im, $red, $green, $blue, $extra_arg) );
+
+// Testing imagecolorallocate with one less than the expected number of arguments
+echo "\n-- Testing imagecolorallocate() function with less than expected no. of arguments --\n";
+var_dump( imagecolorallocate() );
+var_dump( imagecolorallocate($im, $red, $green) );
+?>
+===DONE===
+--EXPECTF--
+*** Testing imagecolorallocate() : error conditions ***
+
+-- Testing imagecolorallocate() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for imagecolorallocate() in %s on line %d
+NULL
+
+-- Testing imagecolorallocate() function with less than expected no. of arguments --
+
+Warning: Wrong parameter count for imagecolorallocate() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for imagecolorallocate() in %s on line %d
+NULL
+===DONE===
+
+
diff --git a/ext/gd/tests/imagecolorallocate_variation1.phpt b/ext/gd/tests/imagecolorallocate_variation1.phpt
new file mode 100644 (file)
index 0000000..b08aece
--- /dev/null
@@ -0,0 +1,267 @@
+--TEST--
+Test imagecolorallocate() function : usage variations  - passing different data types to first argument
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+    die('skip gd extension is not loaded');
+}
+?> 
+--FILE--
+<?php
+/* Prototype  : int imagecolorallocate(resource im, int red, int green, int blue)
+ * Description: Allocate a color for an image
+ * Source code: ext/gd/gd.c
+ */
+
+echo "*** Testing imagecolorallocate() : usage variations ***\n";
+
+// Initialise function arguments not being substituted (if any)
+$red = 10;
+$green = 10;
+$blue = 10;
+
+$fp = tmpfile();
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+
+// define some classes
+class classWithToString
+{
+        public function __toString() {
+                return "Class A object";
+        }
+}
+
+
+class classWithoutToString
+{
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// add arrays
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+//array of values to iterate over
+$values = array(
+
+      // int data
+      'int 0' => 0,
+      'int 1' => 1,
+      'int 12345' => 12345,
+      'int -12345' => -12345,
+
+      // float data
+      'float 10.5' => 10.5,
+      'float -10.5' => -10.5,
+      'float 10.1234567e10' => 10.1234567e10,
+      'float 10.7654321E-10' => 10.7654321E-10,
+      'float .5' => .5,
+
+      // array data
+      'empty array' => array(),
+      'int indexed array' => $index_array,
+      'associative array' => $assoc_array,
+         'nested arrays' => array('foo', $index_array, $assoc_array),
+      
+      // null data
+         'uppercase NULL' => NULL,
+      'lowercase null' => null,
+
+      // boolean data
+      'lowercase true' => true,
+      'lowercase false' =>false,
+      'uppercase TRUE' =>TRUE,
+      'uppercase FALSE' =>FALSE,
+
+      // empty data
+      'empty string DQ' => "",
+      'empty string SQ' => '',
+
+      // string data
+      'string DQ' => "string",
+      'string SQ' => 'string',
+      'mixed case string' => "sTrInG",
+      'heredoc' => $heredoc,
+
+      // object data
+      'instance of classWithToString' => new classWithToString(),
+      'instance of classWithoutToString' => new classWithoutToString(),
+
+      // undefined data
+      'undefined var' => @$undefined_var,
+
+      // unset data
+      'unset var' => @$unset_var,
+      
+      //resource 
+      "file resource" => $fp
+);
+
+// loop through each element of the array for im
+foreach($values as $key => $value) {
+      echo "\n-- $key --\n";
+      var_dump( imagecolorallocate($value, $red, $green, $blue) );
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing imagecolorallocate() : usage variations ***
+
+-- int 0 --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- int 1 --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- int 12345 --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- int -12345 --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- float 10.5 --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- float -10.5 --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- float 10.1234567e10 --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- float 10.7654321E-10 --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- float .5 --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- empty array --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- int indexed array --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- associative array --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- nested arrays --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- uppercase NULL --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- lowercase null --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- lowercase true --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- lowercase false --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- uppercase TRUE --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- uppercase FALSE --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- empty string DQ --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- empty string SQ --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- string DQ --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- string SQ --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- mixed case string --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- heredoc --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- instance of classWithToString --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- instance of classWithoutToString --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- undefined var --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- unset var --
+
+Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d
+bool(false)
+
+-- file resource --
+
+Warning: imagecolorallocate(): supplied resource is not a valid Image resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/gd/tests/imagecolorallocate_variation2.phpt b/ext/gd/tests/imagecolorallocate_variation2.phpt
new file mode 100644 (file)
index 0000000..d8885f3
--- /dev/null
@@ -0,0 +1,192 @@
+--TEST--
+Test imagecolorallocate() function : usage variations  - passing different data types to second argument
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+    die('skip gd extension is not loaded');
+}
+if(!function_exists('imagecreatetruecolor')) {
+    die('skip imagecreatetruecolor function is not available');
+}
+?> 
+--FILE--
+<?php
+/* Prototype  : int imagecolorallocate(resource im, int red, int green, int blue)
+ * Description: Allocate a color for an image
+ * Source code: ext/gd/gd.c
+ */
+
+echo "*** Testing imagecolorallocate() : usage variations ***\n";
+
+$im = imagecreatetruecolor(200, 200);
+$green = 10;
+$blue = 10;
+
+$fp = tmpfile();
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+// define some classes
+class classWithToString
+{
+        public function __toString() {
+                return "Class A object";
+        }
+}
+
+
+class classWithoutToString
+{
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// add arrays
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+//array of values to iterate over
+$values = array(
+
+      // float data
+      'float 10.5' => 10.5,
+      'float -10.5' => -10.5,
+      'float 10.1234567e10' => 10.1234567e10,
+      'float 10.7654321E-10' => 10.7654321E-10,
+      'float .5' => .5,
+
+      // array data
+      'empty array' => array(),
+      'int indexed array' => $index_array,
+      'associative array' => $assoc_array,
+         'nested arrays' => array('foo', $index_array, $assoc_array),
+      
+      // null data
+         'uppercase NULL' => NULL,
+      'lowercase null' => null,
+
+      // boolean data
+      'lowercase true' => true,
+      'lowercase false' =>false,
+      'uppercase TRUE' =>TRUE,
+      'uppercase FALSE' =>FALSE,
+
+      // empty data
+      'empty string DQ' => "",
+      'empty string SQ' => '',
+
+      // string data
+      'string DQ' => "string",
+      'string SQ' => 'string',
+      'mixed case string' => "sTrInG",
+      'heredoc' => $heredoc,
+
+      // object data
+      'instance of classWithToString' => new classWithToString(),
+      'instance of classWithoutToString' => new classWithoutToString(),
+
+      // undefined data
+      'undefined var' => @$undefined_var,
+
+      // unset data
+      'unset var' => @$unset_var,
+      
+      //resource 
+      "file resource" => $fp
+);
+// loop through each element of the array for red
+foreach($values as $key => $value) {
+      echo "\n--$key--\n";
+      var_dump( imagecolorallocate($im, $value, $green, $blue) );
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing imagecolorallocate() : usage variations ***
+
+--float 10.5--
+int(657930)
+
+--float -10.5--
+bool(false)
+
+--float 10.1234567e10--
+bool(false)
+
+--float 10.7654321E-10--
+int(2570)
+
+--float .5--
+int(2570)
+
+--empty array--
+int(2570)
+
+--int indexed array--
+int(68106)
+
+--associative array--
+int(68106)
+
+--nested arrays--
+int(68106)
+
+--uppercase NULL--
+int(2570)
+
+--lowercase null--
+int(2570)
+
+--lowercase true--
+int(68106)
+
+--lowercase false--
+int(2570)
+
+--uppercase TRUE--
+int(68106)
+
+--uppercase FALSE--
+int(2570)
+
+--empty string DQ--
+int(2570)
+
+--empty string SQ--
+int(2570)
+
+--string DQ--
+int(2570)
+
+--string SQ--
+int(2570)
+
+--mixed case string--
+int(2570)
+
+--heredoc--
+int(2570)
+
+--instance of classWithToString--
+
+Notice: Object of class classWithToString could not be converted to int in %s on line %d
+int(68106)
+
+--instance of classWithoutToString--
+
+Notice: Object of class classWithoutToString could not be converted to int in %s on line %d
+int(68106)
+
+--undefined var--
+int(2570)
+
+--unset var--
+int(2570)
+
+--file resource--
+int(330250)
+===DONE===
diff --git a/ext/gd/tests/imagecolorallocate_variation3.phpt b/ext/gd/tests/imagecolorallocate_variation3.phpt
new file mode 100644 (file)
index 0000000..6bdf259
--- /dev/null
@@ -0,0 +1,192 @@
+--TEST--
+Test imagecolorallocate() function : usage variations  - passing different data types to third argument
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+    die('skip gd extension is not loaded');
+}
+if(!function_exists('imagecreatetruecolor')) {
+    die('skip imagecreatetruecolor function is not available');
+}
+?> 
+--FILE--
+<?php
+/* Prototype  : imagecolorallocate(resource im, int red, int green, int blue)
+ * Description: Allocate a color for an image
+ * Source code: ext/gd/gd.c
+ */
+
+echo "*** Testing imagecolorallocate() : usage variations ***\n";
+
+$im = imagecreatetruecolor(200, 200);
+$red = 10;
+$blue = 10;
+
+$fp = tmpfile();
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+// define some classes
+class classWithToString
+{
+        public function __toString() {
+                return "Class A object";
+        }
+}
+
+
+class classWithoutToString
+{
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// add arrays
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+//array of values to iterate over
+$values = array(
+
+      // float data
+      'float 10.5' => 10.5,
+      'float -10.5' => -10.5,
+      'float 10.1234567e10' => 10.1234567e10,
+      'float 10.7654321E-10' => 10.7654321E-10,
+      'float .5' => .5,
+
+      // array data
+      'empty array' => array(),
+      'int indexed array' => $index_array,
+      'associative array' => $assoc_array,
+         'nested arrays' => array('foo', $index_array, $assoc_array),
+      
+      // null data
+         'uppercase NULL' => NULL,
+      'lowercase null' => null,
+
+      // boolean data
+      'lowercase true' => true,
+      'lowercase false' =>false,
+      'uppercase TRUE' =>TRUE,
+      'uppercase FALSE' =>FALSE,
+
+      // empty data
+      'empty string DQ' => "",
+      'empty string SQ' => '',
+
+      // string data
+      'string DQ' => "string",
+      'string SQ' => 'string',
+      'mixed case string' => "sTrInG",
+      'heredoc' => $heredoc,
+
+      // object data
+      'instance of classWithToString' => new classWithToString(),
+      'instance of classWithoutToString' => new classWithoutToString(),
+
+      // undefined data
+      'undefined var' => @$undefined_var,
+
+      // unset data
+      'unset var' => @$unset_var,
+      
+      //resource 
+      "file resource" => $fp
+);
+// loop through each element of the array for red
+foreach($values as $key => $value) {
+      echo "\n--$key--\n";
+      var_dump( imagecolorallocate($im, $red, $value, $blue) );
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing imagecolorallocate() : usage variations ***
+
+--float 10.5--
+int(657930)
+
+--float -10.5--
+int(652810)
+
+--float 10.1234567e10--
+int(217143306)
+
+--float 10.7654321E-10--
+int(655370)
+
+--float .5--
+int(655370)
+
+--empty array--
+int(655370)
+
+--int indexed array--
+int(655626)
+
+--associative array--
+int(655626)
+
+--nested arrays--
+int(655626)
+
+--uppercase NULL--
+int(655370)
+
+--lowercase null--
+int(655370)
+
+--lowercase true--
+int(655626)
+
+--lowercase false--
+int(655370)
+
+--uppercase TRUE--
+int(655626)
+
+--uppercase FALSE--
+int(655370)
+
+--empty string DQ--
+int(655370)
+
+--empty string SQ--
+int(655370)
+
+--string DQ--
+int(655370)
+
+--string SQ--
+int(655370)
+
+--mixed case string--
+int(655370)
+
+--heredoc--
+int(655370)
+
+--instance of classWithToString--
+
+Notice: Object of class classWithToString could not be converted to int in %s on line %d
+int(655626)
+
+--instance of classWithoutToString--
+
+Notice: Object of class classWithoutToString could not be converted to int in %s on line %d
+int(655626)
+
+--undefined var--
+int(655370)
+
+--unset var--
+int(655370)
+
+--file resource--
+int(656650)
+===DONE===
\ No newline at end of file
diff --git a/ext/gd/tests/imagecolorallocate_variation4.phpt b/ext/gd/tests/imagecolorallocate_variation4.phpt
new file mode 100644 (file)
index 0000000..f170e4a
--- /dev/null
@@ -0,0 +1,191 @@
+--TEST--
+Test imagecolorallocate() function : usage variations  - passing different data types to fourth argument
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+    die('skip gd extension is not loaded');
+}
+if(!function_exists('imagecreatetruecolor')) {
+    die('skip imagecreatetruecolor function is not available');
+}
+?>
+--FILE--
+<?php
+/* Prototype  : int imagecolorallocate(resource im, int red, int green, int blue)
+ * Description:  Allocate a color for an image
+ * Source code: ext/gd/gd.c
+ */
+echo "*** Testing imagecolorallocate() : usage variations ***\n";
+
+$im = imagecreatetruecolor(200, 200);
+$red = 10;
+$green = 10;
+
+$fp = tmpfile();
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+// define some classes
+class classWithToString
+{
+        public function __toString() {
+                return "Class A object";
+        }
+}
+
+
+class classWithoutToString
+{
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// add arrays
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+//array of values to iterate over
+$values = array(
+
+      // float data
+      'float 10.5' => 10.5,
+      'float -10.5' => -10.5,
+      'float 10.1234567e10' => 10.1234567e10,
+      'float 10.7654321E-10' => 10.7654321E-10,
+      'float .5' => .5,
+
+      // array data
+      'empty array' => array(),
+      'int indexed array' => $index_array,
+      'associative array' => $assoc_array,
+         'nested arrays' => array('foo', $index_array, $assoc_array),
+      
+      // null data
+         'uppercase NULL' => NULL,
+      'lowercase null' => null,
+
+      // boolean data
+      'lowercase true' => true,
+      'lowercase false' =>false,
+      'uppercase TRUE' =>TRUE,
+      'uppercase FALSE' =>FALSE,
+
+      // empty data
+      'empty string DQ' => "",
+      'empty string SQ' => '',
+
+      // string data
+      'string DQ' => "string",
+      'string SQ' => 'string',
+      'mixed case string' => "sTrInG",
+      'heredoc' => $heredoc,
+
+      // object data
+      'instance of classWithToString' => new classWithToString(),
+      'instance of classWithoutToString' => new classWithoutToString(),
+
+      // undefined data
+      'undefined var' => @$undefined_var,
+
+      // unset data
+      'unset var' => @$unset_var,
+      
+      //resource 
+      "file resource" => $fp
+);
+// loop through each element of the array for red
+foreach($values as $key => $value) {
+      echo "\n--$key--\n";
+      var_dump( imagecolorallocate($im, $red, $green, $value) );
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing imagecolorallocate() : usage variations ***
+
+--float 10.5--
+int(657930)
+
+--float -10.5--
+int(657910)
+
+--float 10.1234567e10--
+bool(false)
+
+--float 10.7654321E-10--
+int(657920)
+
+--float .5--
+int(657920)
+
+--empty array--
+int(657920)
+
+--int indexed array--
+int(657921)
+
+--associative array--
+int(657921)
+
+--nested arrays--
+int(657921)
+
+--uppercase NULL--
+int(657920)
+
+--lowercase null--
+int(657920)
+
+--lowercase true--
+int(657921)
+
+--lowercase false--
+int(657920)
+
+--uppercase TRUE--
+int(657921)
+
+--uppercase FALSE--
+int(657920)
+
+--empty string DQ--
+int(657920)
+
+--empty string SQ--
+int(657920)
+
+--string DQ--
+int(657920)
+
+--string SQ--
+int(657920)
+
+--mixed case string--
+int(657920)
+
+--heredoc--
+int(657920)
+
+--instance of classWithToString--
+
+Notice: Object of class classWithToString could not be converted to int in %s on line %d
+int(657921)
+
+--instance of classWithoutToString--
+
+Notice: Object of class classWithoutToString could not be converted to int in %s on line %d
+int(657921)
+
+--undefined var--
+int(657920)
+
+--unset var--
+int(657920)
+
+--file resource--
+int(657925)
+===DONE===
diff --git a/ext/gd/tests/imagecolorallocate_variation5.phpt b/ext/gd/tests/imagecolorallocate_variation5.phpt
new file mode 100644 (file)
index 0000000..794abb3
--- /dev/null
@@ -0,0 +1,90 @@
+--TEST--
+Test imagecolorallocate() function : usage variations  - passing octal and hexa-decimal values
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+    die('skip gd extension is not loaded');
+}
+if(!function_exists('imagecreatetruecolor')) {
+    die('skip imagecreatetruecolor function is not available');
+}
+?>
+--FILE--
+<?php
+/* Prototype  : int imagecolorallocate(resource im, int red, int green, int blue)
+ * Description:  Allocate a color for an image
+ * Source code: ext/gd/gd.c
+ */
+echo "*** Testing imagecolorallocate() : usage variations ***\n";
+
+$im = imagecreatetruecolor(200, 200);
+$red = 10;
+$green = 10;
+$blue = 10;
+
+$values = array(
+      // octal integer data
+      "Octal 000" => 000,
+      "Octal 012" => 012,
+      "Octal -012" => -012,
+      "Octal 0377" => 0377,
+     
+      // hexa-decimal integer data
+      "Hexa-decimal 0x0" => 0x0,
+      "Hexa-decimal 0xA" => 0xA,
+      "Hexa-decimal -0xA" => -0xA,
+      "Hexa-decimal 0xFF" => 0xFF,
+);
+
+// loop through each element of the array for blue
+foreach($values as $key => $value) {
+      echo "\n--$key--\n";
+      var_dump( imagecolorallocate($im, $value, $green, $blue) );
+      var_dump( imagecolorallocate($im, $red, $value, $blue) );
+      var_dump( imagecolorallocate($im, $red, $green, $value) );
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing imagecolorallocate() : usage variations ***
+
+--Octal 000--
+int(2570)
+int(655370)
+int(657920)
+
+--Octal 012--
+int(657930)
+int(657930)
+int(657930)
+
+--Octal -012--
+bool(false)
+int(652810)
+int(657910)
+
+--Octal 0377--
+int(16714250)
+int(720650)
+int(658175)
+
+--Hexa-decimal 0x0--
+int(2570)
+int(655370)
+int(657920)
+
+--Hexa-decimal 0xA--
+int(657930)
+int(657930)
+int(657930)
+
+--Hexa-decimal -0xA--
+bool(false)
+int(652810)
+int(657910)
+
+--Hexa-decimal 0xFF--
+int(16714250)
+int(720650)
+int(658175)
+===DONE===
diff --git a/ext/gd/tests/imagecolorallocate_variation6.phpt b/ext/gd/tests/imagecolorallocate_variation6.phpt
new file mode 100644 (file)
index 0000000..bc939c9
--- /dev/null
@@ -0,0 +1,56 @@
+--TEST--
+Test imagecolorallocate() function : usage variations  - passing RED, GREEN, BLUE values more than 255
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+    die('skip gd extension is not loaded');
+}
+if(!function_exists('imagecreatetruecolor')) {
+    die('skip imagecreatetruecolor function is not available');
+}
+?>
+--FILE--
+<?php
+/* Prototype  : int imagecolorallocate(resource im, int red, int green, int blue)
+ * Description:  Allocate a color for an image
+ * Source code: ext/gd/gd.c
+ */
+echo "*** Testing imagecolorallocate() : usage variations ***\n";
+
+$values = array(
+      //Decimal integera data  
+      "Decimal 256" => 256,
+      
+      // octal integer data
+      "Octal 0400" => 0400,
+     
+      // hexa-decimal integer data
+      "Hexa-decimal 0x100" => 0x100
+);
+
+// loop through each element of the array for blue
+foreach($values as $key => $value) {
+      echo "\n--$key--\n";
+      //Need to be created every time to get expected return value
+      $im_palette = imagecreate(200, 200);
+      $im_true_color = imagecreatetruecolor(200, 200);
+      var_dump( imagecolorallocate($im_palette, $value, $value, $value) );
+      var_dump( imagecolorallocate($im_true_color, $value, $value, $value) );
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing imagecolorallocate() : usage variations ***
+
+--Decimal 256--
+int(0)
+int(16843008)
+
+--Octal 0400--
+int(0)
+int(16843008)
+
+--Hexa-decimal 0x100--
+int(0)
+int(16843008)
+===DONE===
diff --git a/ext/gd/tests/imagecolorstotal_basic.phpt b/ext/gd/tests/imagecolorstotal_basic.phpt
new file mode 100644 (file)
index 0000000..472a10d
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+Test imagecolorstotal() function : basic functionality
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+    die('skip gd extension is not loaded');
+}
+
+if(!function_exists('imagecolorstotal') || !function_exists('imagecreatefromgif')) {
+    die('skip imagecolorstotal and imagecreatefromgif functions not available in this build');
+}
+?> 
+--FILE--
+<?php
+/* Prototype  : int imagecolorstotal  ( resource $image  )
+ * Description: Find out the number of colors in an image's palette
+ * Source code: ext/gd/gd.c
+ */
+
+echo "*** Testing imagecolorstotal() : basic functionality ***\n";
+
+// Get an image 
+$gif = dirname(__FILE__)."/php.gif";
+$im = imagecreatefromgif($gif);
+
+echo 'Total colors in image: ' . imagecolorstotal($im);
+
+// Free image
+imagedestroy($im);
+?>
+
+===DONE===
+--EXPECTF--
+*** Testing imagecolorstotal() : basic functionality ***
+Total colors in image: 128
+===DONE===
\ No newline at end of file
diff --git a/ext/gd/tests/imagecolorstotal_error.phpt b/ext/gd/tests/imagecolorstotal_error.phpt
new file mode 100644 (file)
index 0000000..995fa40
--- /dev/null
@@ -0,0 +1,54 @@
+--TEST--
+Test imagecolorstotal() function : error conditions  - Pass incorrect number of arguments
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+    die('skip gd extension is not loaded');
+}
+if(!function_exists('imagecolorstotal')) {
+    die('skip imagecolorstotal function is not available');
+}
+?> 
+--FILE--
+<?php
+/* Prototype  : int imagecolorstotal  ( resource $image  )
+ * Description: Find out the number of colors in an image's palette
+ * Source code: ext/gd/gd.c
+ */
+
+echo "*** Testing imagecolorstotal() : error conditions ***\n";
+
+// Get a resource
+$im = fopen(__FILE__, 'r');
+
+echo "\n-- Testing imagecolorstotal() function with Zero arguments --\n";
+var_dump( imagecolorstotal() );
+
+echo "\n-- Testing imagecolorstotal() function with more than expected no. of arguments --\n";
+$extra_arg = false;
+var_dump( imagecolorstotal($im, $extra_arg) );
+
+echo "\n-- Testing imagecolorstotal() function with a invalid resource\n";
+var_dump( imagecolorstotal($im) );
+
+fclose($im); 
+?>
+===DONE===
+--EXPECTF--
+*** Testing imagecolorstotal() : error conditions ***
+
+-- Testing imagecolorstotal() function with Zero arguments --
+
+Warning: Wrong parameter count for imagecolorstotal() in %s on line %d
+NULL
+
+-- Testing imagecolorstotal() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for imagecolorstotal() in %s on line %d
+NULL
+
+-- Testing imagecolorstotal() function with a invalid resource
+
+Warning: imagecolorstotal(): supplied resource is not a valid Image resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/gd/tests/php.gif b/ext/gd/tests/php.gif
new file mode 100644 (file)
index 0000000..f352c73
Binary files /dev/null and b/ext/gd/tests/php.gif differ