Annotation of embedaddon/php/ext/standard/tests/strings/vfprintf_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test vfprintf() function : variation functionality
3: --CREDITS--
4: Felix De Vliegher <felix.devliegher@gmail.com>
5: --INI--
6: precision=14
7: --FILE--
8: <?php
9: /* Prototype : int vfprintf(resource stream, string format, array args)
10: * Description: Output a formatted string into a stream
11: * Source code: ext/standard/formatted_print.c
12: * Alias to functions:
13: */
14:
15: echo "*** Testing vfprintf() : variation functionality ***\n";
16:
17: // Open handle
18: $file = 'vfprintf_test.txt';
19: $fp = fopen( $file, 'a+' );
20:
21: $funset = fopen( __FILE__, 'r' );
22: unset( $funset );
23:
24: class FooClass
25: {
26: public function __toString()
27: {
28: return "Object";
29: }
30: }
31:
32: // Output facilitating function
33: function writeAndDump($fp, $format, $args)
34: {
35: ftruncate( $fp, 0 );
36: $length = vfprintf( $fp, $format, $args );
37: rewind( $fp );
38: $content = stream_get_contents( $fp );
39: var_dump( $content );
40: var_dump( $length );
41: }
42:
43: // Test vfprintf()
44: writeAndDump( $fp, "format", null );
45: writeAndDump( $fp, "Foo is %d and %s", array( 30, 'bar' ) );
46: writeAndDump( $fp, "Foobar testing", array() );
47: writeAndDump( $fp, "%s %s %s", array( 'bar', 'bar', 'bar' ) );
48: writeAndDump( $fp, "%02d", array( 50 ) );
49: writeAndDump( $fp, "", array() );
50: writeAndDump( $fp, "Testing %b %d %f %o %s %x %X", array( 9, 6, 2.5502, 24, "foobar", 15, 65 ) );
51: @writeAndDump( $funset, "Foo with %s", array( 'string' ) );
52: @writeAndDump( new FooClass(), "Foo with %s", array( 'string' ) );
53:
54: // Close handle
55: fclose( $fp );
56:
57: ?>
58: ===DONE===
59: --CLEAN--
60: <?php
61:
62: $file = 'vfprintf_test.txt';
63: unlink( $file );
64:
65: ?>
66: --EXPECTF--
67: *** Testing vfprintf() : variation functionality ***
68: string(6) "format"
69: int(6)
70: string(17) "Foo is 30 and bar"
71: int(17)
72: string(14) "Foobar testing"
73: int(14)
74: string(11) "bar bar bar"
75: int(11)
76: string(2) "50"
77: int(2)
78: string(0) ""
79: int(0)
80: string(38) "Testing 1001 6 2.550200 30 foobar f 41"
81: int(38)
82: bool(false)
83: bool(false)
84: bool(false)
85: bool(false)
86: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>