1--TEST--
2Test fflush() function: usage variations - files in different modes
3--SKIPIF--
4<?php
5if( substr(PHP_OS, 0, 3) != "WIN" )
6  die("skip.. only for Windows");
7?>
8--FILE--
9<?php
10
11/* test fflush() with handle to the files opened in different modes */
12
13$file_path = __DIR__;
14require $file_path.'/file.inc';
15
16echo "*** Testing fflush(): with various types of files ***\n";
17$file_types = array("empty", "numeric", "text", "text_with_new_line", "alphanumeric");
18$file_modes = array("w", "wb", "wt", "w+", "w+b", "w+t",
19                    "a", "ab", "at", "a+","a+b", "a+t",
20                    "x", "xb", "xt", "x+", "x+b", "x+t");
21
22$file_name = "$file_path/fflush_variation私はガラスを食べられます1.tmp";
23
24$count = 1;
25
26foreach( $file_types as $type ) {
27  echo "-- Iteration $count with file containing $type Data--\n";
28  foreach( $file_modes as $mode ) {
29    echo "-- File opened in $mode mode --\n";
30
31    // creating the file except for x mode
32    if( substr($mode, 0, 1) != "x" ) {
33      $file_handle = fopen($file_name, "w");
34      if($file_handle == false)
35        exit("Error:failed to open file $file_name");
36
37      // filling the file some data if mode is append mode
38      if( substr($mode, 0, 1) == "a")
39        fill_file($file_handle, $type, 10);
40      fclose($file_handle);
41    }
42
43    // opening the file in different modes
44    $file_handle = fopen($file_name, $mode);
45    if($file_handle == false)
46      exit("Error:failed to open file $file_name");
47
48    // writing data to the file
49    var_dump( fill_file($file_handle, $type, 50) );
50    var_dump( fflush($file_handle) );
51    fclose($file_handle);
52
53    // reading the contents of the file after flushing
54     var_dump( readfile($file_name) );
55     unlink($file_name);
56  }
57  $count++;
58}
59
60echo "\n*** Done ***";
61?>
62--EXPECT--
63*** Testing fflush(): with various types of files ***
64-- Iteration 1 with file containing empty Data--
65-- File opened in w mode --
66bool(true)
67bool(true)
68int(0)
69-- File opened in wb mode --
70bool(true)
71bool(true)
72int(0)
73-- File opened in wt mode --
74bool(true)
75bool(true)
76int(0)
77-- File opened in w+ mode --
78bool(true)
79bool(true)
80int(0)
81-- File opened in w+b mode --
82bool(true)
83bool(true)
84int(0)
85-- File opened in w+t mode --
86bool(true)
87bool(true)
88int(0)
89-- File opened in a mode --
90bool(true)
91bool(true)
92int(0)
93-- File opened in ab mode --
94bool(true)
95bool(true)
96int(0)
97-- File opened in at mode --
98bool(true)
99bool(true)
100int(0)
101-- File opened in a+ mode --
102bool(true)
103bool(true)
104int(0)
105-- File opened in a+b mode --
106bool(true)
107bool(true)
108int(0)
109-- File opened in a+t mode --
110bool(true)
111bool(true)
112int(0)
113-- File opened in x mode --
114bool(true)
115bool(true)
116int(0)
117-- File opened in xb mode --
118bool(true)
119bool(true)
120int(0)
121-- File opened in xt mode --
122bool(true)
123bool(true)
124int(0)
125-- File opened in x+ mode --
126bool(true)
127bool(true)
128int(0)
129-- File opened in x+b mode --
130bool(true)
131bool(true)
132int(0)
133-- File opened in x+t mode --
134bool(true)
135bool(true)
136int(0)
137-- Iteration 2 with file containing numeric Data--
138-- File opened in w mode --
139bool(true)
140bool(true)
14122222222222222222222222222222222222222222222222222int(50)
142-- File opened in wb mode --
143bool(true)
144bool(true)
14522222222222222222222222222222222222222222222222222int(50)
146-- File opened in wt mode --
147bool(true)
148bool(true)
14922222222222222222222222222222222222222222222222222int(50)
150-- File opened in w+ mode --
151bool(true)
152bool(true)
15322222222222222222222222222222222222222222222222222int(50)
154-- File opened in w+b mode --
155bool(true)
156bool(true)
15722222222222222222222222222222222222222222222222222int(50)
158-- File opened in w+t mode --
159bool(true)
160bool(true)
16122222222222222222222222222222222222222222222222222int(50)
162-- File opened in a mode --
163bool(true)
164bool(true)
165222222222222222222222222222222222222222222222222222222222222int(60)
166-- File opened in ab mode --
167bool(true)
168bool(true)
169222222222222222222222222222222222222222222222222222222222222int(60)
170-- File opened in at mode --
171bool(true)
172bool(true)
173222222222222222222222222222222222222222222222222222222222222int(60)
174-- File opened in a+ mode --
175bool(true)
176bool(true)
177222222222222222222222222222222222222222222222222222222222222int(60)
178-- File opened in a+b mode --
179bool(true)
180bool(true)
181222222222222222222222222222222222222222222222222222222222222int(60)
182-- File opened in a+t mode --
183bool(true)
184bool(true)
185222222222222222222222222222222222222222222222222222222222222int(60)
186-- File opened in x mode --
187bool(true)
188bool(true)
18922222222222222222222222222222222222222222222222222int(50)
190-- File opened in xb mode --
191bool(true)
192bool(true)
19322222222222222222222222222222222222222222222222222int(50)
194-- File opened in xt mode --
195bool(true)
196bool(true)
19722222222222222222222222222222222222222222222222222int(50)
198-- File opened in x+ mode --
199bool(true)
200bool(true)
20122222222222222222222222222222222222222222222222222int(50)
202-- File opened in x+b mode --
203bool(true)
204bool(true)
20522222222222222222222222222222222222222222222222222int(50)
206-- File opened in x+t mode --
207bool(true)
208bool(true)
20922222222222222222222222222222222222222222222222222int(50)
210-- Iteration 3 with file containing text Data--
211-- File opened in w mode --
212bool(true)
213bool(true)
214text text text text text text text text text text int(50)
215-- File opened in wb mode --
216bool(true)
217bool(true)
218text text text text text text text text text text int(50)
219-- File opened in wt mode --
220bool(true)
221bool(true)
222text text text text text text text text text text int(50)
223-- File opened in w+ mode --
224bool(true)
225bool(true)
226text text text text text text text text text text int(50)
227-- File opened in w+b mode --
228bool(true)
229bool(true)
230text text text text text text text text text text int(50)
231-- File opened in w+t mode --
232bool(true)
233bool(true)
234text text text text text text text text text text int(50)
235-- File opened in a mode --
236bool(true)
237bool(true)
238text text text text text text text text text text text text int(60)
239-- File opened in ab mode --
240bool(true)
241bool(true)
242text text text text text text text text text text text text int(60)
243-- File opened in at mode --
244bool(true)
245bool(true)
246text text text text text text text text text text text text int(60)
247-- File opened in a+ mode --
248bool(true)
249bool(true)
250text text text text text text text text text text text text int(60)
251-- File opened in a+b mode --
252bool(true)
253bool(true)
254text text text text text text text text text text text text int(60)
255-- File opened in a+t mode --
256bool(true)
257bool(true)
258text text text text text text text text text text text text int(60)
259-- File opened in x mode --
260bool(true)
261bool(true)
262text text text text text text text text text text int(50)
263-- File opened in xb mode --
264bool(true)
265bool(true)
266text text text text text text text text text text int(50)
267-- File opened in xt mode --
268bool(true)
269bool(true)
270text text text text text text text text text text int(50)
271-- File opened in x+ mode --
272bool(true)
273bool(true)
274text text text text text text text text text text int(50)
275-- File opened in x+b mode --
276bool(true)
277bool(true)
278text text text text text text text text text text int(50)
279-- File opened in x+t mode --
280bool(true)
281bool(true)
282text text text text text text text text text text int(50)
283-- Iteration 4 with file containing text_with_new_line Data--
284-- File opened in w mode --
285bool(true)
286bool(true)
287line
288line of text
289line
290line of text
291line
292line of tint(50)
293-- File opened in wb mode --
294bool(true)
295bool(true)
296line
297line of text
298line
299line of text
300line
301line of tint(50)
302-- File opened in wt mode --
303bool(true)
304bool(true)
305line
306line of text
307line
308line of text
309line
310line of tint(55)
311-- File opened in w+ mode --
312bool(true)
313bool(true)
314line
315line of text
316line
317line of text
318line
319line of tint(50)
320-- File opened in w+b mode --
321bool(true)
322bool(true)
323line
324line of text
325line
326line of text
327line
328line of tint(50)
329-- File opened in w+t mode --
330bool(true)
331bool(true)
332line
333line of text
334line
335line of text
336line
337line of tint(55)
338-- File opened in a mode --
339bool(true)
340bool(true)
341line
342line line
343line of text
344line
345line of text
346line
347line of tint(60)
348-- File opened in ab mode --
349bool(true)
350bool(true)
351line
352line line
353line of text
354line
355line of text
356line
357line of tint(60)
358-- File opened in at mode --
359bool(true)
360bool(true)
361line
362line line
363line of text
364line
365line of text
366line
367line of tint(65)
368-- File opened in a+ mode --
369bool(true)
370bool(true)
371line
372line line
373line of text
374line
375line of text
376line
377line of tint(60)
378-- File opened in a+b mode --
379bool(true)
380bool(true)
381line
382line line
383line of text
384line
385line of text
386line
387line of tint(60)
388-- File opened in a+t mode --
389bool(true)
390bool(true)
391line
392line line
393line of text
394line
395line of text
396line
397line of tint(65)
398-- File opened in x mode --
399bool(true)
400bool(true)
401line
402line of text
403line
404line of text
405line
406line of tint(50)
407-- File opened in xb mode --
408bool(true)
409bool(true)
410line
411line of text
412line
413line of text
414line
415line of tint(50)
416-- File opened in xt mode --
417bool(true)
418bool(true)
419line
420line of text
421line
422line of text
423line
424line of tint(55)
425-- File opened in x+ mode --
426bool(true)
427bool(true)
428line
429line of text
430line
431line of text
432line
433line of tint(50)
434-- File opened in x+b mode --
435bool(true)
436bool(true)
437line
438line of text
439line
440line of text
441line
442line of tint(50)
443-- File opened in x+t mode --
444bool(true)
445bool(true)
446line
447line of text
448line
449line of text
450line
451line of tint(55)
452-- Iteration 5 with file containing alphanumeric Data--
453-- File opened in w mode --
454bool(true)
455bool(true)
456ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
457-- File opened in wb mode --
458bool(true)
459bool(true)
460ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
461-- File opened in wt mode --
462bool(true)
463bool(true)
464ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
465-- File opened in w+ mode --
466bool(true)
467bool(true)
468ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
469-- File opened in w+b mode --
470bool(true)
471bool(true)
472ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
473-- File opened in w+t mode --
474bool(true)
475bool(true)
476ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
477-- File opened in a mode --
478bool(true)
479bool(true)
480ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
481-- File opened in ab mode --
482bool(true)
483bool(true)
484ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
485-- File opened in at mode --
486bool(true)
487bool(true)
488ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
489-- File opened in a+ mode --
490bool(true)
491bool(true)
492ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
493-- File opened in a+b mode --
494bool(true)
495bool(true)
496ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
497-- File opened in a+t mode --
498bool(true)
499bool(true)
500ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
501-- File opened in x mode --
502bool(true)
503bool(true)
504ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
505-- File opened in xb mode --
506bool(true)
507bool(true)
508ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
509-- File opened in xt mode --
510bool(true)
511bool(true)
512ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
513-- File opened in x+ mode --
514bool(true)
515bool(true)
516ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
517-- File opened in x+b mode --
518bool(true)
519bool(true)
520ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
521-- File opened in x+t mode --
522bool(true)
523bool(true)
524ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
525
526*** Done ***
527