summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/fpassthru_variation.phpt
blob: 749eefb4c8f38ad180f78ec512ae5ada9217c4d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
--TEST--
Test fpassthru() function: Variations
--FILE--
<?php
/* 
Prototype: int fpassthru ( resource $handle );
Description: Reads to EOF on the given file pointer from the current position
  and writes the results to the output buffer.
*/

echo "*** Testing fpassthru() function with files ***\n\n";

echo "--- Testing with different offsets ---\n";

$file_name = dirname(__FILE__)."/passthru_variation.tmp";
$file_write = fopen($file_name, "w");
fwrite($file_write, "1234567890abcdefghijklmnopqrstuvwxyz");
fclose($file_write);

$file_read = fopen($file_name, "r");

$offset_arr = array(
  /* Positive offsets */
  0,
  1, 
  5,
  10,
  20,
  30,
  35,
  36,
  70,
  /* Negative offsets, the file pointer should be at the end of file 
  to get data */
  -1, 
  -5, 
  -10,
  -20,
  -35,
  -36,
  -70
);

for( $i=0; $i<count($offset_arr); $i++ ) {
  echo "-- Iteration $i --\n";
  if( $offset_arr[$i] >= 0 ) {
    fseek($file_read, $offset_arr[$i], SEEK_SET);
    var_dump(fpassthru($file_read) );
    rewind( $file_read );
  }else
    { 
      fseek($file_read, $offset_arr[$i], SEEK_END);
      var_dump( fpassthru($file_read) );
      rewind( $file_read );
    } 
} 

fclose($file_read);  // closing the handle

echo "\n--- Testing with binary mode file ---\n";
/* Opening the file in binary read mode */
$file_read = fopen($file_name, "rb");

fseek($file_read, 12, SEEK_SET);
var_dump(fpassthru($file_read) );
rewind( $file_read );
fclose($file_read);

unlink($file_name);

echo "\n*** Done ***\n";

?>
--EXPECTF--
*** Testing fpassthru() function with files ***

--- Testing with different offsets ---
-- Iteration 0 --
1234567890abcdefghijklmnopqrstuvwxyzint(36)
-- Iteration 1 --
234567890abcdefghijklmnopqrstuvwxyzint(35)
-- Iteration 2 --
67890abcdefghijklmnopqrstuvwxyzint(31)
-- Iteration 3 --
abcdefghijklmnopqrstuvwxyzint(26)
-- Iteration 4 --
klmnopqrstuvwxyzint(16)
-- Iteration 5 --
uvwxyzint(6)
-- Iteration 6 --
zint(1)
-- Iteration 7 --
int(0)
-- Iteration 8 --
int(0)
-- Iteration 9 --
zint(1)
-- Iteration 10 --
vwxyzint(5)
-- Iteration 11 --
qrstuvwxyzint(10)
-- Iteration 12 --
ghijklmnopqrstuvwxyzint(20)
-- Iteration 13 --
234567890abcdefghijklmnopqrstuvwxyzint(35)
-- Iteration 14 --
1234567890abcdefghijklmnopqrstuvwxyzint(36)
-- Iteration 15 --
1234567890abcdefghijklmnopqrstuvwxyzint(36)

--- Testing with binary mode file ---
cdefghijklmnopqrstuvwxyzint(24)

*** Done ***