Annotation of embedaddon/php/ext/gd/tests/imagecolorallocate_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test imagecolorallocate() function : usage variations - passing different data types to second argument
3: --SKIPIF--
4: <?php
5: if(!extension_loaded('gd')) {
6: die('skip gd extension is not loaded');
7: }
8: if(!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:
19: echo "*** 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;
29: unset ($unset_var);
30: // define some classes
31: class classWithToString
32: {
33: public function __toString() {
34: return "Class A object";
35: }
36: }
37:
38:
39: class classWithoutToString
40: {
41: }
42:
43: // heredoc string
44: $heredoc = <<<EOT
45: hello world
46: EOT;
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
102: foreach($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--
112: int(657930)
113:
114: --float -10.5--
115: bool(false)
116:
117: --float 10.1234567e10--
118: bool(false)
119:
120: --float 10.7654321E-10--
121: int(2570)
122:
123: --float .5--
124: int(2570)
125:
126: --empty array--
127:
128: Warning: imagecolorallocate() expects parameter 2 to be long, array given in %s on line %d
129: NULL
130:
131: --int indexed array--
132:
133: Warning: imagecolorallocate() expects parameter 2 to be long, array given in %s on line %d
134: NULL
135:
136: --associative array--
137:
138: Warning: imagecolorallocate() expects parameter 2 to be long, array given in %s on line %d
139: NULL
140:
141: --nested arrays--
142:
143: Warning: imagecolorallocate() expects parameter 2 to be long, array given in %s on line %d
144: NULL
145:
146: --uppercase NULL--
147: int(2570)
148:
149: --lowercase null--
150: int(2570)
151:
152: --lowercase true--
153: int(68106)
154:
155: --lowercase false--
156: int(2570)
157:
158: --uppercase TRUE--
159: int(68106)
160:
161: --uppercase FALSE--
162: int(2570)
163:
164: --empty string DQ--
165:
166: Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d
167: NULL
168:
169: --empty string SQ--
170:
171: Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d
172: NULL
173:
174: --string DQ--
175:
176: Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d
177: NULL
178:
179: --string SQ--
180:
181: Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d
182: NULL
183:
184: --mixed case string--
185:
186: Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d
187: NULL
188:
189: --heredoc--
190:
191: Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d
192: NULL
193:
194: --instance of classWithToString--
195:
196: Warning: imagecolorallocate() expects parameter 2 to be long, object given in %s on line %d
197: NULL
198:
199: --instance of classWithoutToString--
200:
201: Warning: imagecolorallocate() expects parameter 2 to be long, object given in %s on line %d
202: NULL
203:
204: --undefined var--
205: int(2570)
206:
207: --unset var--
208: int(2570)
209:
210: --file resource--
211:
212: Warning: imagecolorallocate() expects parameter 2 to be long, resource given in %s on line %d
213: NULL
214: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>