Annotation of embedaddon/php/ext/standard/tests/strings/vfprintf_variation6.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test vfprintf() function : usage variations - float formats with non-float 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 float formats and non-float values are passed to
12: * the '$format' and '$args' arguments of the function
13: */
14:
15: echo "*** Testing vfprintf() : float formats and non-float values ***\n";
16:
17: // defining array of float formats
18: $formats =
19: '%f %+f %-f
20: %lf %Lf %4f %-4f
21: %10.4f %-10.4f %04f %04.4f
22: %\'#2f %\'2f %\'$2f %\'_2f
23: %3$f %4$f %1$f %2$f';
24:
25: // Arrays of non float values for the format defined in $format.
26: // Each sub array contains non float values which correspond to each format in $format
27: $args_array = array(
28:
29: // array of int values
30: array(2, -2, +2,
31: 123456, 123456234, -12346789, +12346789,
32: 123200, +20000, -40000, 22212,
33: 12345780, 1211111, -12111111, -12345634,
34: 3, +4, 1,-2 ),
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 */
1.1.1.2 ! misho 60: $data_file = dirname(__FILE__) . '/vfprintf_variation6.txt';
1.1 misho 61: if (!($fp = fopen($data_file, 'wt')))
62: return;
63:
64: // looping to test vfprintf() with different float formats from the above $format array
65: // and with non-float values from the above $args_array array
66: $counter = 1;
67: foreach($args_array as $args) {
68: fprintf($fp, "\n-- Iteration %d --\n",$counter);
69: vfprintf($fp, $formats, $args);
70: $counter++;
71: }
72:
73: fclose($fp);
74: print_r(file_get_contents($data_file));
75: echo "\n";
76:
77: unlink($data_file);
78:
79: ?>
80: ===DONE===
81: --EXPECT--
82: *** Testing vfprintf() : float formats and non-float values ***
83:
84: -- Iteration 1 --
85: 2.000000 -2.000000 2.000000
86: 123456.000000 f -12346789.000000 12346789.000000
87: 123200.0000 20000.0000 -40000.000000 22212.0000
88: 12345780.000000 1211111.000000 -12111111.000000 -12345634.000000
89: 2.000000 123456.000000 2.000000 -2.000000
90: -- Iteration 2 --
91: 0.000000 +0.000000 0.000000
92: 123.000000 f -123.000000 123.000000
93: 0.0000 0.0000 123456.000000 0.0000
94: 1234.000000 0.000000 0.000000 0.000000
95: 0.000000 123.000000 0.000000 0.000000
96: -- Iteration 3 --
97: 1.000000 +1.000000 1.000000
98: 1.000000 f 1.000000 1.000000
99: 1.0000 1.0000 1.000000 1.0000
100: 1.000000 1.000000 1.000000 1.000000
101: 1.000000 1.000000 1.000000 1.000000
102: -- Iteration 4 --
103: 1.000000 +1.000000 0.000000
104: 1.000000 f 0.000000 1.000000
105: 1.0000 0.0000 1.000000 0.0000
106: 0.000000 1.000000 1.000000 0.000000
107: 0.000000 1.000000 1.000000 1.000000
108: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>