1--TEST--
2Test vprintf() function : usage variations - hexa formats with hexa values
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
6?>
7--FILE--
8<?php
9/* Prototype  : string vprintf(string format, array args)
10 * Description: Output a formatted string
11 * Source code: ext/standard/formatted_print.c
12*/
13
14/*
15 * Test vprintf() when different hexa formats and hexa values are passed to
16 * the '$format' and '$args' arguments of the function
17*/
18
19echo "*** Testing vprintf() : hexa formats with hexa values ***\n";
20
21// defining array of different hexa formats
22$formats = array(
23  "%x",
24  "%+x %-x %X",
25  "%lx %Lx, %4x %-4x",
26  "%10.4x %-10.4x %04x %04.4x",
27  "%'#2x %'2x %'$2x %'_2x",
28  "%x %x %x %x",
29  "% %%x x%",
30  '%3$x %4$x %1$x %2$x'
31);
32
33// Arrays of hexa values for the format defined in $format.
34// Each sub array contains hexa values which correspond to each format string in $format
35$args_array = array(
36  array(0x0),
37  array(-0x1, 0x1, +0x22),
38  array(0x7FFFFFFF, -0x7fffffff, +0x7000000, -0x80000000),
39  array(123456, 12345678, -1234567, 1234567),
40  array(1, 0x2222, 0333333, -0x44444444),
41  array(0x123b, 0xfAb, "0xaxz", 01293),
42  array(0x1234, 0x34, 0x2ff),
43  array(0x3, 0x4, 0x1, 0x2)
44
45);
46
47// looping to test vprintf() with different char octal from the above $format array
48// and with octal values from the above $args_array array
49$counter = 1;
50foreach($formats as $format) {
51  echo "\n-- Iteration $counter --\n";
52  $result = vprintf($format, $args_array[$counter-1]);
53  echo "\n";
54  var_dump($result);
55  $counter++;
56}
57
58?>
59===DONE===
60--EXPECT--
61*** Testing vprintf() : hexa formats with hexa values ***
62
63-- Iteration 1 --
640
65int(1)
66
67-- Iteration 2 --
68ffffffff 1 22
69int(13)
70
71-- Iteration 3 --
727fffffff x, 7000000 80000000
73int(28)
74
75-- Iteration 4 --
76                      ffed2979 0000
77int(35)
78
79-- Iteration 5 --
80#1 2222 1b6db bbbbbbbc
81int(22)
82
83-- Iteration 6 --
84123b fab 0 a
85int(12)
86
87-- Iteration 7 --
88%34 x
89int(5)
90
91-- Iteration 8 --
921 2 3 4
93int(7)
94===DONE===
95