1--TEST--
2Test vfprintf() function : usage variations - scientific formats with non-scientific values
3--FILE--
4<?php
5/* Prototype  : int vfprintf  ( resource $handle  , string $format , array $args  )
6 * Description: Write a formatted string to a stream
7 * Source code: ext/standard/formatted_print.c
8*/
9
10/*
11 * Test vfprintf() when different scientific formats and non-scientific values are passed to
12 * the '$format' and '$args' arguments of the function
13*/
14
15echo "*** Testing vfprintf() : scientific formats and non-scientific values ***\n";
16
17// defining array of non-scientific formats
18$formats =
19  '%e %+e %-e
20   %le %Le %4e %-4e
21   %10.4e %-10.4e %04e %04.4e
22   %\'#2e %\'2e %\'$2e %\'_2e
23   %3$e %4$e %1$e %2$e';
24
25// Arrays of non scientific values for the format defined in $format.
26// Each sub array contains non scientific values which correspond to each format in $format
27$args_array = array(
28
29  // array of float values
30  array(2.2, .2, 10.2,
31        123456.234, 123456.234, -1234.6789, +1234.6789,
32        20.00, +212.2, -411000000000, 2212.000000000001,
33        12345.780, 12.000000011111, -12.00000111111, -123456.234,
34        3.33, +4.44, 1.11,-2.22 ),
35
36  // array of strings
37  array(" ", ' ', 'hello',
38        '123hello', "123hello", '-123hello', '+123hello',
39        "\12345678hello", "-\12345678hello", '0123456hello', 'h123456ello',
40        "1234hello", "hello\0world", "NULL", "true",
41        "3", "4", '1', '2'),
42
43  // different arrays
44  array( array(0), array(1, 2), array(-1, -1),
45         array("123"), array('123'), array('-123'), array("-123"),
46         array(true), array(false), array(TRUE), array(FALSE),
47         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
48         array("3"), array("4"), array("1"), array("2") ),
49
50  // array of boolean data
51  array( true, TRUE, false,
52         TRUE, 0, FALSE, 1,
53         true, false, TRUE, FALSE,
54         0, 1, 1, 0,
55         1, TRUE, 0, FALSE),
56
57);
58
59/* creating dumping file */
60$data_file = dirname(__FILE__) . '/vfprintf_variation18.txt';
61if (!($fp = fopen($data_file, 'wt')))
62   return;
63
64// looping to test vfprintf() with different scientific formats from the above $format array
65// and with non-scientific values from the above $args_array array
66$counter = 1;
67foreach($args_array as $args) {
68  fprintf($fp, "\n-- Iteration %d --\n",$counter);
69  vfprintf($fp, $formats, $args);
70  $counter++;
71}
72
73fclose($fp);
74print_r(file_get_contents($data_file));
75echo "\n";
76
77unlink($data_file);
78?>
79===DONE===
80--EXPECT--
81*** Testing vfprintf() : scientific formats and non-scientific values ***
82
83-- Iteration 1 --
842.200000e+0 +2.000000e-1 1.020000e+1
85   1.234562e+5 e -1.234679e+3 1.234679e+3
86    2.0000e+1 2.1220e+2  -4.110000e+11 2.2120e+3
87   1.234578e+4 1.200000e+1 -1.200000e+1 -1.234562e+5
88   1.020000e+1 1.234562e+5 2.200000e+0 2.000000e-1
89-- Iteration 2 --
900.000000e+0 +0.000000e+0 0.000000e+0
91   1.230000e+2 e -1.230000e+2 1.230000e+2
92    0.0000e+0 0.0000e+0  1.234560e+5 0.0000e+0
93   1.234000e+3 0.000000e+0 0.000000e+0 0.000000e+0
94   0.000000e+0 1.230000e+2 0.000000e+0 0.000000e+0
95-- Iteration 3 --
961.000000e+0 +1.000000e+0 1.000000e+0
97   1.000000e+0 e 1.000000e+0 1.000000e+0
98    1.0000e+0 1.0000e+0  1.000000e+0 1.0000e+0
99   1.000000e+0 1.000000e+0 1.000000e+0 1.000000e+0
100   1.000000e+0 1.000000e+0 1.000000e+0 1.000000e+0
101-- Iteration 4 --
1021.000000e+0 +1.000000e+0 0.000000e+0
103   1.000000e+0 e 0.000000e+0 1.000000e+0
104    1.0000e+0 0.0000e+0  1.000000e+0 0.0000e+0
105   0.000000e+0 1.000000e+0 1.000000e+0 0.000000e+0
106   0.000000e+0 1.000000e+0 1.000000e+0 1.000000e+0
107===DONE===
108