Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / php / ext / standard / tests / file / fpassthru_variation.phpt
blob56a039e628e745b70f13c7eb627faf2b7e08f92c
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 */
11 echo "*** Testing fpassthru() function with files ***\n\n";
13 echo "--- Testing with different offsets ---\n";
15 $file_name = dirname(__FILE__)."/passthru.tmp";
16 $file_write = fopen($file_name, "w");
17 fwrite($file_write, "1234567890abcdefghijklmnopqrstuvwxyz");
18 fclose($file_write);
20 $file_read = fopen($file_name, "r");
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
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
58 fclose($file_read);  // closing the handle
60 echo "\n--- Testing with binary mode file ---\n";
61 /* Opening the file in binary read mode */
62 $file_read = fopen($file_name, "rb");
64 fseek($file_read, 12, SEEK_SET);
65 var_dump(fpassthru($file_read) );
66 rewind( $file_read );
67 fclose($file_read);
69 unlink($file_name);
71 echo "\n*** Done ***\n";
74 --EXPECTF--
75 *** Testing fpassthru() function with files ***
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)
111 --- Testing with binary mode file ---
112 cdefghijklmnopqrstuvwxyzint(24)
114 *** Done ***