1--TEST--
2Test sprintf() function : usage variations - unsigned formats with integer values
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4) {
6        die("skip this test is for 32bit platform only");
7}
8?>
9--FILE--
10<?php
11echo "*** Testing sprintf() : unsigned formats with integer values ***\n";
12
13// array of integer values
14$integer_values = array(
15  0,
16  1,
17  -1,
18  -2147483648, // max negative integer value
19  -2147483647,
20  2147483647,  // max positive integer value
21  +2147483640,
22  0x123B,      // integer as hexadecimal
23  0x12ab,
24  0Xfff,
25  0XFA,
26  -0x80000000, // max negative integer as hexadecimal
27  0x7fffffff,  // max positive integer as hexadecimal
28  0x7FFFFFFF,  // max positive integer as hexadecimal
29  0123,        // integer as octal
30  01,       // should be quivalent to octal 1
31  -020000000000, // max negative integer as octal
32  017777777777  // max positive integer as octal
33);
34
35// array of unsigned formats
36$unsigned_formats = array(
37  "%u", "%lu", " %u", "%u ",
38  "\t%u", "\n%u", "%4u", "%30u",
39);
40
41
42$count = 1;
43foreach($integer_values as $integer_value) {
44  echo "\n-- Iteration $count --\n";
45
46  foreach($unsigned_formats as $format) {
47    var_dump( sprintf($format, $integer_value) );
48  }
49  $count++;
50};
51
52echo "Done";
53?>
54--EXPECT--
55*** Testing sprintf() : unsigned formats with integer values ***
56
57-- Iteration 1 --
58string(1) "0"
59string(1) "0"
60string(2) " 0"
61string(2) "0 "
62string(2) "	0"
63string(2) "
640"
65string(4) "   0"
66string(30) "                             0"
67
68-- Iteration 2 --
69string(1) "1"
70string(1) "1"
71string(2) " 1"
72string(2) "1 "
73string(2) "	1"
74string(2) "
751"
76string(4) "   1"
77string(30) "                             1"
78
79-- Iteration 3 --
80string(10) "4294967295"
81string(10) "4294967295"
82string(11) " 4294967295"
83string(11) "4294967295 "
84string(11) "	4294967295"
85string(11) "
864294967295"
87string(10) "4294967295"
88string(30) "                    4294967295"
89
90-- Iteration 4 --
91string(10) "2147483648"
92string(10) "2147483648"
93string(11) " 2147483648"
94string(11) "2147483648 "
95string(11) "	2147483648"
96string(11) "
972147483648"
98string(10) "2147483648"
99string(30) "                    2147483648"
100
101-- Iteration 5 --
102string(10) "2147483649"
103string(10) "2147483649"
104string(11) " 2147483649"
105string(11) "2147483649 "
106string(11) "	2147483649"
107string(11) "
1082147483649"
109string(10) "2147483649"
110string(30) "                    2147483649"
111
112-- Iteration 6 --
113string(10) "2147483647"
114string(10) "2147483647"
115string(11) " 2147483647"
116string(11) "2147483647 "
117string(11) "	2147483647"
118string(11) "
1192147483647"
120string(10) "2147483647"
121string(30) "                    2147483647"
122
123-- Iteration 7 --
124string(10) "2147483640"
125string(10) "2147483640"
126string(11) " 2147483640"
127string(11) "2147483640 "
128string(11) "	2147483640"
129string(11) "
1302147483640"
131string(10) "2147483640"
132string(30) "                    2147483640"
133
134-- Iteration 8 --
135string(4) "4667"
136string(4) "4667"
137string(5) " 4667"
138string(5) "4667 "
139string(5) "	4667"
140string(5) "
1414667"
142string(4) "4667"
143string(30) "                          4667"
144
145-- Iteration 9 --
146string(4) "4779"
147string(4) "4779"
148string(5) " 4779"
149string(5) "4779 "
150string(5) "	4779"
151string(5) "
1524779"
153string(4) "4779"
154string(30) "                          4779"
155
156-- Iteration 10 --
157string(4) "4095"
158string(4) "4095"
159string(5) " 4095"
160string(5) "4095 "
161string(5) "	4095"
162string(5) "
1634095"
164string(4) "4095"
165string(30) "                          4095"
166
167-- Iteration 11 --
168string(3) "250"
169string(3) "250"
170string(4) " 250"
171string(4) "250 "
172string(4) "	250"
173string(4) "
174250"
175string(4) " 250"
176string(30) "                           250"
177
178-- Iteration 12 --
179string(10) "2147483648"
180string(10) "2147483648"
181string(11) " 2147483648"
182string(11) "2147483648 "
183string(11) "	2147483648"
184string(11) "
1852147483648"
186string(10) "2147483648"
187string(30) "                    2147483648"
188
189-- Iteration 13 --
190string(10) "2147483647"
191string(10) "2147483647"
192string(11) " 2147483647"
193string(11) "2147483647 "
194string(11) "	2147483647"
195string(11) "
1962147483647"
197string(10) "2147483647"
198string(30) "                    2147483647"
199
200-- Iteration 14 --
201string(10) "2147483647"
202string(10) "2147483647"
203string(11) " 2147483647"
204string(11) "2147483647 "
205string(11) "	2147483647"
206string(11) "
2072147483647"
208string(10) "2147483647"
209string(30) "                    2147483647"
210
211-- Iteration 15 --
212string(2) "83"
213string(2) "83"
214string(3) " 83"
215string(3) "83 "
216string(3) "	83"
217string(3) "
21883"
219string(4) "  83"
220string(30) "                            83"
221
222-- Iteration 16 --
223string(1) "1"
224string(1) "1"
225string(2) " 1"
226string(2) "1 "
227string(2) "	1"
228string(2) "
2291"
230string(4) "   1"
231string(30) "                             1"
232
233-- Iteration 17 --
234string(10) "2147483648"
235string(10) "2147483648"
236string(11) " 2147483648"
237string(11) "2147483648 "
238string(11) "	2147483648"
239string(11) "
2402147483648"
241string(10) "2147483648"
242string(30) "                    2147483648"
243
244-- Iteration 18 --
245string(10) "2147483647"
246string(10) "2147483647"
247string(11) " 2147483647"
248string(11) "2147483647 "
249string(11) "	2147483647"
250string(11) "
2512147483647"
252string(10) "2147483647"
253string(30) "                    2147483647"
254Done
255