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/* 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 unsigned formats and signed values and other types of values
16 * are passed to the '$format' and '$args' arguments of the function
17*/
18
19echo "*** Testing vprintf() : unsigned formats and signed & other types of values ***\n";
20
21// defining array of unsigned formats
22$formats =
23  '%u %+u %-u
24   %lu %Lu %4u %-4u
25   %10.4u %-10.4u %.4u
26   %\'#2u %\'2u %\'$2u %\'_2u
27   %3$u %4$u %1$u %2$u';
28
29// Arrays of signed and other type of values for the format defined in $format.
30// Each sub array contains signed 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,
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 strings
41  array(" ", ' ', 'hello',
42        '123hello', "123hello", '-123hello', '+123hello',
43        "\12345678hello", "-\12345678hello", 'h123456ello',
44        "1234hello", "hello\0world", "NULL", "true",
45        "3", "4", '1', '2'),
46
47  // different arrays
48  array( array(0), array(1, 2), array(-1, -1),
49         array("123"), array('123'), array('-123'), array("-123"),
50         array(true), array(TRUE), array(FALSE),
51         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
52         array("3"), array("4"), array("1"), array("2") ),
53
54  // array of boolean data
55  array( true, TRUE, false,
56         TRUE, 0, FALSE, 1,
57         true, TRUE, FALSE,
58         0, 1, 1, 0,
59         1, TRUE, 0, FALSE),
60
61);
62
63// looping to test vprintf() with different unsigned formats from the above $format array
64// and with signed and other types of  values from the above $args_array array
65$counter = 1;
66foreach($args_array as $args) {
67  echo "\n-- Iteration $counter --\n";
68  $result = vprintf($formats, $args);
69  echo "\n";
70  var_dump($result);
71  $counter++;
72}
73
74?>
75===DONE===
76--EXPECT--
77*** Testing vprintf() : unsigned formats and signed & other types of values ***
78
79-- Iteration 1 --
802 0 10
81   123456 u 1234 20000000000
82   2000000000000 22000000000000 12345
83   12 18446744073709551604 18446744073709428160 _3
84   10 123456 2 0
85int(143)
86
87-- Iteration 2 --
880 0 0
89   123 u 18446744073709551493 123
90            0 0          0
91   1234 0 $0 _0
92   0 123 0 0
93int(98)
94
95-- Iteration 3 --
961 1 1
97   1 u    1 1
98            1 1          1
99   #1 1 $1 _1
100   1 1 1 1
101int(76)
102
103-- Iteration 4 --
1041 1 0
105   1 u    0 1
106            1 1          0
107   #0 1 $1 _0
108   0 1 1 1
109int(76)
110===DONE===
111