Annotation of embedaddon/php/ext/standard/tests/file/fpassthru_variation.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test fpassthru() function: Variations
3: --FILE--
4: <?php
5: /*
6: Prototype: int fpassthru ( resource $handle );
7: Description: Reads to EOF on the given file pointer from the current position
8: and writes the results to the output buffer.
9: */
10:
11: echo "*** Testing fpassthru() function with files ***\n\n";
12:
13: echo "--- Testing with different offsets ---\n";
14:
1.1.1.2 ! misho 15: $file_name = dirname(__FILE__)."/passthru_variation.tmp";
1.1 misho 16: $file_write = fopen($file_name, "w");
17: fwrite($file_write, "1234567890abcdefghijklmnopqrstuvwxyz");
18: fclose($file_write);
19:
20: $file_read = fopen($file_name, "r");
21:
22: $offset_arr = array(
23: /* Positive offsets */
24: 0,
25: 1,
26: 5,
27: 10,
28: 20,
29: 30,
30: 35,
31: 36,
32: 70,
33: /* Negative offsets, the file pointer should be at the end of file
34: to get data */
35: -1,
36: -5,
37: -10,
38: -20,
39: -35,
40: -36,
41: -70
42: );
43:
44: for( $i=0; $i<count($offset_arr); $i++ ) {
45: echo "-- Iteration $i --\n";
46: if( $offset_arr[$i] >= 0 ) {
47: fseek($file_read, $offset_arr[$i], SEEK_SET);
48: var_dump(fpassthru($file_read) );
49: rewind( $file_read );
50: }else
51: {
52: fseek($file_read, $offset_arr[$i], SEEK_END);
53: var_dump( fpassthru($file_read) );
54: rewind( $file_read );
55: }
56: }
57:
58: fclose($file_read); // closing the handle
59:
60: echo "\n--- Testing with binary mode file ---\n";
61: /* Opening the file in binary read mode */
62: $file_read = fopen($file_name, "rb");
63:
64: fseek($file_read, 12, SEEK_SET);
65: var_dump(fpassthru($file_read) );
66: rewind( $file_read );
67: fclose($file_read);
68:
69: unlink($file_name);
70:
71: echo "\n*** Done ***\n";
72:
73: ?>
74: --EXPECTF--
75: *** Testing fpassthru() function with files ***
76:
77: --- Testing with different offsets ---
78: -- Iteration 0 --
79: 1234567890abcdefghijklmnopqrstuvwxyzint(36)
80: -- Iteration 1 --
81: 234567890abcdefghijklmnopqrstuvwxyzint(35)
82: -- Iteration 2 --
83: 67890abcdefghijklmnopqrstuvwxyzint(31)
84: -- Iteration 3 --
85: abcdefghijklmnopqrstuvwxyzint(26)
86: -- Iteration 4 --
87: klmnopqrstuvwxyzint(16)
88: -- Iteration 5 --
89: uvwxyzint(6)
90: -- Iteration 6 --
91: zint(1)
92: -- Iteration 7 --
93: int(0)
94: -- Iteration 8 --
95: int(0)
96: -- Iteration 9 --
97: zint(1)
98: -- Iteration 10 --
99: vwxyzint(5)
100: -- Iteration 11 --
101: qrstuvwxyzint(10)
102: -- Iteration 12 --
103: ghijklmnopqrstuvwxyzint(20)
104: -- Iteration 13 --
105: 234567890abcdefghijklmnopqrstuvwxyzint(35)
106: -- Iteration 14 --
107: 1234567890abcdefghijklmnopqrstuvwxyzint(36)
108: -- Iteration 15 --
109: 1234567890abcdefghijklmnopqrstuvwxyzint(36)
110:
111: --- Testing with binary mode file ---
112: cdefghijklmnopqrstuvwxyzint(24)
113:
114: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>