1--TEST--
2Test vprintf() function : usage variations - unsigned formats with signed and other types of 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/*
10 * Test vprintf() when different unsigned formats and signed values and other types of values
11 * are passed to the '$format' and '$args' arguments of the function
12*/
13
14echo "*** Testing vprintf() : unsigned formats and signed & other types of values ***\n";
15
16// defining array of unsigned formats
17$formats =
18    '%u %+u %-u
19    %lu %4u %-4u
20    %10.4u %-10.4u %.4u
21    %\'#2u %\'2u %\'$2u %\'_2u
22    %3$u %4$u %1$u %2$u';
23
24// Arrays of signed and other type of values for the format defined in $format.
25// Each sub array contains signed values which correspond to each format in $format
26$args_array = array(
27
28  // array of float values
29  array(+2.2, +.2, +10.2,
30        +123456.234, +123456.234, +1234.6789,
31        +2e10, +2e12, +22e+12,
32        +12345.780, +12.000000011111, -12.00000111111, -123456.234,
33        +3.33, +4.44, +1.11,-2.22 ),
34
35  // array of strings
36  array(" ", ' ', 'hello',
37        '123hello', '-123hello', '+123hello',
38        "\12345678hello", "-\12345678hello", 'h123456ello',
39        "1234hello", "hello\0world", "NULL", "true",
40        "3", "4", '1', '2'),
41
42  // different arrays
43  array( array(0), array(1, 2), array(-1, -1),
44         array("123"), array('-123'), array("-123"),
45         array(true), array(TRUE), array(FALSE),
46         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
47         array("3"), array("4"), array("1"), array("2") ),
48
49  // array of boolean data
50  array( true, TRUE, false,
51         TRUE, FALSE, 1,
52         true, TRUE, FALSE,
53         0, 1, 1, 0,
54         1, TRUE, 0, FALSE),
55
56);
57
58// looping to test vprintf() with different unsigned formats from the above $format array
59// and with signed and other types of  values from the above $args_array array
60$counter = 1;
61foreach($args_array as $args) {
62  echo "\n-- Iteration $counter --\n";
63  $result = vprintf($formats, $args);
64  echo "\n";
65  var_dump($result);
66  $counter++;
67}
68
69?>
70--EXPECT--
71*** Testing vprintf() : unsigned formats and signed & other types of values ***
72
73-- Iteration 1 --
742 0 10
75    123456 123456 1234
76    20000000000 2000000000000 22000000000000
77    12345 12 18446744073709551604 18446744073709428160
78    10 123456 2 0
79int(147)
80
81-- Iteration 2 --
820 0 0
83    123 18446744073709551493 123
84             0 0          0
85    1234 0 $0 _0
86    0 123 0 0
87int(98)
88
89-- Iteration 3 --
901 1 1
91    1    1 1
92             1 1          1
93    #1 1 $1 _1
94    1 1 1 1
95int(76)
96
97-- Iteration 4 --
981 1 0
99    1    0 1
100             1 1          0
101    #0 1 $1 _0
102    0 1 1 1
103int(76)
104