1--TEST--
2Test vprintf() function : usage variations - hexa formats with non-hexa values
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 8) die("skip this test is for 64bit 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 non-hexa values are passed to
16 * the '$format' and '$args' arguments of the function
17*/
18
19echo "*** Testing vprintf() : hexa formats and non-hexa values ***\n";
20
21// defining array of different hexa formats
22$formats =
23  '%x %+x %-x
24   %lx %Lx %4x %-4x
25   %10.4x %-10.4x %.4x
26   %\'#2x %\'2x %\'$2x %\'_2x
27   %3$x %4$x %1$x %2$x';
28
29// Arrays of non hexa values for the format defined in $format.
30// Each sub array contains non hexa values which correspond to each format in $format
31$args_array = array(
32
33  // array of float values
34  array(2.2, .2, 10.2,
35        123456.234, 123456.234, -1234.6789, +1234.6789,
36        2e10, +2e12, 22e+12,
37        12345.780, 12.000000011111, -12.00000111111, -123456.234,
38        3.33, +4.44, 1.11,-2.22 ),
39
40  // array of int values
41  array(2, -2, +2,
42        123456, 123456234, -12346789, +12346789,
43        123200, +20000, 22212,
44        12345780, 1211111, -12111111, -12345634,
45        3, +4, 1,-2 ),
46
47  // array of strings
48  array(" ", ' ', 'hello',
49        '123hello', "123hello", '-123hello', '+123hello',
50        "\12345678hello", "-\12345678hello", 'h123456ello',
51        "1234hello", "hello\0world", "NULL", "true",
52        "3", "4", '1', '2'),
53
54  // different arrays
55  array( array(0), array(1, 2), array(-1, -1),
56         array("123"), array('123'), array('-123'), array("-123"),
57         array(true), array(TRUE), array(FALSE),
58         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
59         array("3"), array("4"), array("1"), array("2") ),
60
61  // array of boolean data
62  array( true, TRUE, false,
63         TRUE, 0, FALSE, 1,
64         true, TRUE, FALSE,
65         0, 1, 1, 0,
66         1, TRUE, 0, FALSE),
67
68);
69
70// looping to test vprintf() with different hexa formats from the above $format array
71// and with non-hexa values from the above $args_array array
72
73$counter = 1;
74foreach($args_array as $args) {
75  echo "\n-- Iteration $counter --\n";
76  $result = vprintf($formats, $args);
77  echo "\n";
78  var_dump($result);
79  $counter++;
80}
81
82?>
83===DONE===
84--EXPECT--
85*** Testing vprintf() : hexa formats and non-hexa values ***
86
87-- Iteration 1 --
882 0 a
89   1e240 x fffffffffffffb2e 4d2
90
91   3039 c fffffffffffffff4 fffffffffffe1dc0
92   a 1e240 2 0
93int(125)
94
95-- Iteration 2 --
962 fffffffffffffffe 2
97   1e240 x ffffffffff439a5b bc65a5
98
99   bc61b4 127ae7 ffffffffff4732f9 ffffffffff439ede
100   2 1e240 2 fffffffffffffffe
101int(164)
102
103-- Iteration 3 --
1040 0 0
105   7b x ffffffffffffff85 7b
106
107   4d2 0 $0 _0
108   0 7b 0 0
109int(90)
110
111-- Iteration 4 --
1121 1 1
113   1 x    1 1
114
115   #1 1 $1 _1
116   1 1 1 1
117int(75)
118
119-- Iteration 5 --
1201 1 0
121   1 x    0 1
122
123   #0 1 $1 _0
124   0 1 1 1
125int(75)
126===DONE===
127