1--TEST--
2Test imagecolorallocate() function : usage variations  - passing different data types to second argument
3--SKIPIF--
4<?php
5if(!extension_loaded('gd')) {
6    die('skip gd extension is not loaded');
7}
8if(!function_exists('imagecreatetruecolor')) {
9    die('skip imagecreatetruecolor function is not available');
10}
11?>
12--FILE--
13<?php
14/* Prototype  : int imagecolorallocate(resource im, int red, int green, int blue)
15 * Description: Allocate a color for an image
16 * Source code: ext/gd/gd.c
17 */
18
19echo "*** Testing imagecolorallocate() : usage variations ***\n";
20
21$im = imagecreatetruecolor(200, 200);
22$green = 10;
23$blue = 10;
24
25$fp = tmpfile();
26
27//get an unset variable
28$unset_var = 10;
29unset ($unset_var);
30// define some classes
31class classWithToString
32{
33        public function __toString() {
34                return "Class A object";
35        }
36}
37
38
39class classWithoutToString
40{
41}
42
43// heredoc string
44$heredoc = <<<EOT
45hello world
46EOT;
47
48// add arrays
49$index_array = array (1, 2, 3);
50$assoc_array = array ('one' => 1, 'two' => 2);
51
52//array of values to iterate over
53$values = array(
54
55      // float data
56      'float 10.5' => 10.5,
57      'float -10.5' => -10.5,
58      'float 10.1234567e10' => 10.1234567e10,
59      'float 10.7654321E-10' => 10.7654321E-10,
60      'float .5' => .5,
61
62      // array data
63      'empty array' => array(),
64      'int indexed array' => $index_array,
65      'associative array' => $assoc_array,
66	  'nested arrays' => array('foo', $index_array, $assoc_array),
67
68      // null data
69	  'uppercase NULL' => NULL,
70      'lowercase null' => null,
71
72      // boolean data
73      'lowercase true' => true,
74      'lowercase false' =>false,
75      'uppercase TRUE' =>TRUE,
76      'uppercase FALSE' =>FALSE,
77
78      // empty data
79      'empty string DQ' => "",
80      'empty string SQ' => '',
81
82      // string data
83      'string DQ' => "string",
84      'string SQ' => 'string',
85      'mixed case string' => "sTrInG",
86      'heredoc' => $heredoc,
87
88      // object data
89      'instance of classWithToString' => new classWithToString(),
90      'instance of classWithoutToString' => new classWithoutToString(),
91
92      // undefined data
93      'undefined var' => @$undefined_var,
94
95      // unset data
96      'unset var' => @$unset_var,
97
98      //resource
99      "file resource" => $fp
100);
101// loop through each element of the array for red
102foreach($values as $key => $value) {
103      echo "\n--$key--\n";
104      var_dump( imagecolorallocate($im, $value, $green, $blue) );
105};
106?>
107===DONE===
108--EXPECTF--
109*** Testing imagecolorallocate() : usage variations ***
110
111--float 10.5--
112int(657930)
113
114--float -10.5--
115bool(false)
116
117--float 10.1234567e10--
118bool(false)
119
120--float 10.7654321E-10--
121int(2570)
122
123--float .5--
124int(2570)
125
126--empty array--
127
128Warning: imagecolorallocate() expects parameter 2 to be long, array given in %s on line %d
129NULL
130
131--int indexed array--
132
133Warning: imagecolorallocate() expects parameter 2 to be long, array given in %s on line %d
134NULL
135
136--associative array--
137
138Warning: imagecolorallocate() expects parameter 2 to be long, array given in %s on line %d
139NULL
140
141--nested arrays--
142
143Warning: imagecolorallocate() expects parameter 2 to be long, array given in %s on line %d
144NULL
145
146--uppercase NULL--
147int(2570)
148
149--lowercase null--
150int(2570)
151
152--lowercase true--
153int(68106)
154
155--lowercase false--
156int(2570)
157
158--uppercase TRUE--
159int(68106)
160
161--uppercase FALSE--
162int(2570)
163
164--empty string DQ--
165
166Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d
167NULL
168
169--empty string SQ--
170
171Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d
172NULL
173
174--string DQ--
175
176Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d
177NULL
178
179--string SQ--
180
181Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d
182NULL
183
184--mixed case string--
185
186Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d
187NULL
188
189--heredoc--
190
191Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d
192NULL
193
194--instance of classWithToString--
195
196Warning: imagecolorallocate() expects parameter 2 to be long, object given in %s on line %d
197NULL
198
199--instance of classWithoutToString--
200
201Warning: imagecolorallocate() expects parameter 2 to be long, object given in %s on line %d
202NULL
203
204--undefined var--
205int(2570)
206
207--unset var--
208int(2570)
209
210--file resource--
211
212Warning: imagecolorallocate() expects parameter 2 to be long, resource given in %s on line %d
213NULL
214===DONE===
215