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