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
11/* Prototype  : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
12 * Description: Return a formatted string
13 * Source code: ext/standard/formatted_print.c
14*/
15
16echo "*** Testing sprintf() : unsigned formats with integer values ***\n";
17
18// array of integer values
19$integer_values = array(
20  0,
21  1,
22  -1,
23  -2147483648, // max negative integer value
24  -2147483647,
25  2147483647,  // max positive integer value
26  +2147483640,
27  0x123B,      // integer as hexadecimal
28  0x12ab,
29  0Xfff,
30  0XFA,
31  -0x80000000, // max negative integer as hexadecimal
32  0x7fffffff,  // max positive integer as hexadecimal
33  0x7FFFFFFF,  // max positive integer as hexadecimal
34  0123,        // integer as octal
35  01,       // should be quivalent to octal 1
36  -020000000000, // max negative integer as octal
37  017777777777  // max positive integer as octal
38);
39
40// array of unsigned formats
41$unsigned_formats = array(
42  "%u", "%hu", "%lu",
43  "%Lu", " %u", "%u ",
44  "\t%u", "\n%u", "%4u",
45  "%30u", "%[0-9]", "%*u"
46);
47
48
49$count = 1;
50foreach($integer_values as $integer_value) {
51  echo "\n-- Iteration $count --\n";
52
53  foreach($unsigned_formats as $format) {
54    var_dump( sprintf($format, $integer_value) );
55  }
56  $count++;
57};
58
59echo "Done";
60?>
61--EXPECT--
62*** Testing sprintf() : unsigned formats with integer values ***
63
64-- Iteration 1 --
65string(1) "0"
66string(1) "u"
67string(1) "0"
68string(1) "u"
69string(2) " 0"
70string(2) "0 "
71string(2) "	0"
72string(2) "
730"
74string(4) "   0"
75string(30) "                             0"
76string(4) "0-9]"
77string(1) "u"
78
79-- Iteration 2 --
80string(1) "1"
81string(1) "u"
82string(1) "1"
83string(1) "u"
84string(2) " 1"
85string(2) "1 "
86string(2) "	1"
87string(2) "
881"
89string(4) "   1"
90string(30) "                             1"
91string(4) "0-9]"
92string(1) "u"
93
94-- Iteration 3 --
95string(10) "4294967295"
96string(1) "u"
97string(10) "4294967295"
98string(1) "u"
99string(11) " 4294967295"
100string(11) "4294967295 "
101string(11) "	4294967295"
102string(11) "
1034294967295"
104string(10) "4294967295"
105string(30) "                    4294967295"
106string(4) "0-9]"
107string(1) "u"
108
109-- Iteration 4 --
110string(10) "2147483648"
111string(1) "u"
112string(10) "2147483648"
113string(1) "u"
114string(11) " 2147483648"
115string(11) "2147483648 "
116string(11) "	2147483648"
117string(11) "
1182147483648"
119string(10) "2147483648"
120string(30) "                    2147483648"
121string(4) "0-9]"
122string(1) "u"
123
124-- Iteration 5 --
125string(10) "2147483649"
126string(1) "u"
127string(10) "2147483649"
128string(1) "u"
129string(11) " 2147483649"
130string(11) "2147483649 "
131string(11) "	2147483649"
132string(11) "
1332147483649"
134string(10) "2147483649"
135string(30) "                    2147483649"
136string(4) "0-9]"
137string(1) "u"
138
139-- Iteration 6 --
140string(10) "2147483647"
141string(1) "u"
142string(10) "2147483647"
143string(1) "u"
144string(11) " 2147483647"
145string(11) "2147483647 "
146string(11) "	2147483647"
147string(11) "
1482147483647"
149string(10) "2147483647"
150string(30) "                    2147483647"
151string(4) "0-9]"
152string(1) "u"
153
154-- Iteration 7 --
155string(10) "2147483640"
156string(1) "u"
157string(10) "2147483640"
158string(1) "u"
159string(11) " 2147483640"
160string(11) "2147483640 "
161string(11) "	2147483640"
162string(11) "
1632147483640"
164string(10) "2147483640"
165string(30) "                    2147483640"
166string(4) "0-9]"
167string(1) "u"
168
169-- Iteration 8 --
170string(4) "4667"
171string(1) "u"
172string(4) "4667"
173string(1) "u"
174string(5) " 4667"
175string(5) "4667 "
176string(5) "	4667"
177string(5) "
1784667"
179string(4) "4667"
180string(30) "                          4667"
181string(4) "0-9]"
182string(1) "u"
183
184-- Iteration 9 --
185string(4) "4779"
186string(1) "u"
187string(4) "4779"
188string(1) "u"
189string(5) " 4779"
190string(5) "4779 "
191string(5) "	4779"
192string(5) "
1934779"
194string(4) "4779"
195string(30) "                          4779"
196string(4) "0-9]"
197string(1) "u"
198
199-- Iteration 10 --
200string(4) "4095"
201string(1) "u"
202string(4) "4095"
203string(1) "u"
204string(5) " 4095"
205string(5) "4095 "
206string(5) "	4095"
207string(5) "
2084095"
209string(4) "4095"
210string(30) "                          4095"
211string(4) "0-9]"
212string(1) "u"
213
214-- Iteration 11 --
215string(3) "250"
216string(1) "u"
217string(3) "250"
218string(1) "u"
219string(4) " 250"
220string(4) "250 "
221string(4) "	250"
222string(4) "
223250"
224string(4) " 250"
225string(30) "                           250"
226string(4) "0-9]"
227string(1) "u"
228
229-- Iteration 12 --
230string(10) "2147483648"
231string(1) "u"
232string(10) "2147483648"
233string(1) "u"
234string(11) " 2147483648"
235string(11) "2147483648 "
236string(11) "	2147483648"
237string(11) "
2382147483648"
239string(10) "2147483648"
240string(30) "                    2147483648"
241string(4) "0-9]"
242string(1) "u"
243
244-- Iteration 13 --
245string(10) "2147483647"
246string(1) "u"
247string(10) "2147483647"
248string(1) "u"
249string(11) " 2147483647"
250string(11) "2147483647 "
251string(11) "	2147483647"
252string(11) "
2532147483647"
254string(10) "2147483647"
255string(30) "                    2147483647"
256string(4) "0-9]"
257string(1) "u"
258
259-- Iteration 14 --
260string(10) "2147483647"
261string(1) "u"
262string(10) "2147483647"
263string(1) "u"
264string(11) " 2147483647"
265string(11) "2147483647 "
266string(11) "	2147483647"
267string(11) "
2682147483647"
269string(10) "2147483647"
270string(30) "                    2147483647"
271string(4) "0-9]"
272string(1) "u"
273
274-- Iteration 15 --
275string(2) "83"
276string(1) "u"
277string(2) "83"
278string(1) "u"
279string(3) " 83"
280string(3) "83 "
281string(3) "	83"
282string(3) "
28383"
284string(4) "  83"
285string(30) "                            83"
286string(4) "0-9]"
287string(1) "u"
288
289-- Iteration 16 --
290string(1) "1"
291string(1) "u"
292string(1) "1"
293string(1) "u"
294string(2) " 1"
295string(2) "1 "
296string(2) "	1"
297string(2) "
2981"
299string(4) "   1"
300string(30) "                             1"
301string(4) "0-9]"
302string(1) "u"
303
304-- Iteration 17 --
305string(10) "2147483648"
306string(1) "u"
307string(10) "2147483648"
308string(1) "u"
309string(11) " 2147483648"
310string(11) "2147483648 "
311string(11) "	2147483648"
312string(11) "
3132147483648"
314string(10) "2147483648"
315string(30) "                    2147483648"
316string(4) "0-9]"
317string(1) "u"
318
319-- Iteration 18 --
320string(10) "2147483647"
321string(1) "u"
322string(10) "2147483647"
323string(1) "u"
324string(11) " 2147483647"
325string(11) "2147483647 "
326string(11) "	2147483647"
327string(11) "
3282147483647"
329string(10) "2147483647"
330string(30) "                    2147483647"
331string(4) "0-9]"
332string(1) "u"
333Done
334