1--TEST--
2Test imagecolorallocate() function : usage variations  - passing octal and hexa-decimal values
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 */
18echo "*** Testing imagecolorallocate() : usage variations ***\n";
19
20$im = imagecreatetruecolor(200, 200);
21$red = 10;
22$green = 10;
23$blue = 10;
24
25$values = array(
26      // octal integer data
27      "Octal 000" => 000,
28      "Octal 012" => 012,
29      "Octal -012" => -012,
30      "Octal 0377" => 0377,
31
32      // hexa-decimal integer data
33      "Hexa-decimal 0x0" => 0x0,
34      "Hexa-decimal 0xA" => 0xA,
35      "Hexa-decimal -0xA" => -0xA,
36      "Hexa-decimal 0xFF" => 0xFF,
37);
38
39// loop through each element of the array for blue
40foreach($values as $key => $value) {
41      echo "\n--$key--\n";
42      var_dump( imagecolorallocate($im, $value, $green, $blue) );
43      var_dump( imagecolorallocate($im, $red, $value, $blue) );
44      var_dump( imagecolorallocate($im, $red, $green, $value) );
45};
46?>
47===DONE===
48--EXPECTF--
49*** Testing imagecolorallocate() : usage variations ***
50
51--Octal 000--
52int(2570)
53int(655370)
54int(657920)
55
56--Octal 012--
57int(657930)
58int(657930)
59int(657930)
60
61--Octal -012--
62
63Warning: imagecolorallocate(): Red component is out of range in %s on line %d
64bool(false)
65
66Warning: imagecolorallocate(): Green component is out of range in %s on line %d
67bool(false)
68
69Warning: imagecolorallocate(): Blue component is out of range in %s on line %d
70bool(false)
71
72--Octal 0377--
73int(16714250)
74int(720650)
75int(658175)
76
77--Hexa-decimal 0x0--
78int(2570)
79int(655370)
80int(657920)
81
82--Hexa-decimal 0xA--
83int(657930)
84int(657930)
85int(657930)
86
87--Hexa-decimal -0xA--
88
89Warning: imagecolorallocate(): Red component is out of range in %s on line %d
90bool(false)
91
92Warning: imagecolorallocate(): Green component is out of range in %s on line %d
93bool(false)
94
95Warning: imagecolorallocate(): Blue component is out of range in %s on line %d
96bool(false)
97
98--Hexa-decimal 0xFF--
99int(16714250)
100int(720650)
101int(658175)
102===DONE===
103