1--TEST--
2Test fgetc() function : basic functionality
3--FILE--
4<?php
5// include the header for common test function
6include ("file.inc");
7
8echo "*** Testing fgetc() : basic operations ***\n";
9/* read character from different files which are opened in different modes */
10$file_modes = array( "r", "rb", "rt", "r+", "r+b", "r+t");
11
12/* create file with following type of contents */
13$file_content_types = array("numeric", "text", "text_with_new_line");
14
15for($outerloop_counter = 0; $outerloop_counter < count($file_content_types); $outerloop_counter++) {
16  echo "--- Outerloop iteration ";
17  echo $outerloop_counter + 1;
18  echo " ---\n";
19  // create file file
20  create_files(__DIR__, 1, $file_content_types[$outerloop_counter], 0755, 1, "w", "fgetc_basic", 1);
21
22  //open the file in different modes and check the working of fgetc
23  for($innerloop_counter = 0; $innerloop_counter < count($file_modes); $innerloop_counter++) {
24    echo "-- Innerloop iteration ";
25    echo $innerloop_counter + 1;
26    echo " of Outerloop Iteration ";
27    echo $outerloop_counter + 1;
28    echo " --\n";
29
30    // open the file using the $file_modes
31    $filename = __DIR__."/fgetc_basic1.tmp"; // file name that is created by create_files
32    echo "-- Testing fgetc() : file opened using $file_modes[$innerloop_counter] mode --\n";
33    $file_handle = fopen($filename, $file_modes[$innerloop_counter]);
34    if ( !$file_handle ) {
35      echo "Error: failed to open file $filename!";
36      exit();
37    }
38
39    // perform the read file at least 6 char and check
40    for( $counter = 1; $counter <= 6; $counter++ ) {
41      // read data from the file and check, file pointer position, feof etc
42      var_dump( fgetc($file_handle) ); // read a char
43      var_dump( ftell($file_handle) ); // file pointer position
44      var_dump( feof($file_handle) );  // is it eof()
45      var_dump($file_handle); // dump the $file_handle to see if any thing got modified
46    } // end of for
47
48    // close the file
49    fclose ( $file_handle);
50
51  } // end of innerloop for
52
53  // delete the file
54  delete_files(__DIR__, 1, "fgetc_basic", 1, ".tmp");
55
56} // end of outerloop for
57
58echo "Done\n";
59?>
60--EXPECTF--
61*** Testing fgetc() : basic operations ***
62--- Outerloop iteration 1 ---
63-- Innerloop iteration 1 of Outerloop Iteration 1 --
64-- Testing fgetc() : file opened using r mode --
65string(1) "2"
66int(1)
67bool(false)
68resource(%d) of type (stream)
69string(1) "2"
70int(2)
71bool(false)
72resource(%d) of type (stream)
73string(1) "2"
74int(3)
75bool(false)
76resource(%d) of type (stream)
77string(1) "2"
78int(4)
79bool(false)
80resource(%d) of type (stream)
81string(1) "2"
82int(5)
83bool(false)
84resource(%d) of type (stream)
85string(1) "2"
86int(6)
87bool(false)
88resource(%d) of type (stream)
89-- Innerloop iteration 2 of Outerloop Iteration 1 --
90-- Testing fgetc() : file opened using rb mode --
91string(1) "2"
92int(1)
93bool(false)
94resource(%d) of type (stream)
95string(1) "2"
96int(2)
97bool(false)
98resource(%d) of type (stream)
99string(1) "2"
100int(3)
101bool(false)
102resource(%d) of type (stream)
103string(1) "2"
104int(4)
105bool(false)
106resource(%d) of type (stream)
107string(1) "2"
108int(5)
109bool(false)
110resource(%d) of type (stream)
111string(1) "2"
112int(6)
113bool(false)
114resource(%d) of type (stream)
115-- Innerloop iteration 3 of Outerloop Iteration 1 --
116-- Testing fgetc() : file opened using rt mode --
117string(1) "2"
118int(1)
119bool(false)
120resource(%d) of type (stream)
121string(1) "2"
122int(2)
123bool(false)
124resource(%d) of type (stream)
125string(1) "2"
126int(3)
127bool(false)
128resource(%d) of type (stream)
129string(1) "2"
130int(4)
131bool(false)
132resource(%d) of type (stream)
133string(1) "2"
134int(5)
135bool(false)
136resource(%d) of type (stream)
137string(1) "2"
138int(6)
139bool(false)
140resource(%d) of type (stream)
141-- Innerloop iteration 4 of Outerloop Iteration 1 --
142-- Testing fgetc() : file opened using r+ mode --
143string(1) "2"
144int(1)
145bool(false)
146resource(%d) of type (stream)
147string(1) "2"
148int(2)
149bool(false)
150resource(%d) of type (stream)
151string(1) "2"
152int(3)
153bool(false)
154resource(%d) of type (stream)
155string(1) "2"
156int(4)
157bool(false)
158resource(%d) of type (stream)
159string(1) "2"
160int(5)
161bool(false)
162resource(%d) of type (stream)
163string(1) "2"
164int(6)
165bool(false)
166resource(%d) of type (stream)
167-- Innerloop iteration 5 of Outerloop Iteration 1 --
168-- Testing fgetc() : file opened using r+b mode --
169string(1) "2"
170int(1)
171bool(false)
172resource(%d) of type (stream)
173string(1) "2"
174int(2)
175bool(false)
176resource(%d) of type (stream)
177string(1) "2"
178int(3)
179bool(false)
180resource(%d) of type (stream)
181string(1) "2"
182int(4)
183bool(false)
184resource(%d) of type (stream)
185string(1) "2"
186int(5)
187bool(false)
188resource(%d) of type (stream)
189string(1) "2"
190int(6)
191bool(false)
192resource(%d) of type (stream)
193-- Innerloop iteration 6 of Outerloop Iteration 1 --
194-- Testing fgetc() : file opened using r+t mode --
195string(1) "2"
196int(1)
197bool(false)
198resource(%d) of type (stream)
199string(1) "2"
200int(2)
201bool(false)
202resource(%d) of type (stream)
203string(1) "2"
204int(3)
205bool(false)
206resource(%d) of type (stream)
207string(1) "2"
208int(4)
209bool(false)
210resource(%d) of type (stream)
211string(1) "2"
212int(5)
213bool(false)
214resource(%d) of type (stream)
215string(1) "2"
216int(6)
217bool(false)
218resource(%d) of type (stream)
219--- Outerloop iteration 2 ---
220-- Innerloop iteration 1 of Outerloop Iteration 2 --
221-- Testing fgetc() : file opened using r mode --
222string(1) "t"
223int(1)
224bool(false)
225resource(%d) of type (stream)
226string(1) "e"
227int(2)
228bool(false)
229resource(%d) of type (stream)
230string(1) "x"
231int(3)
232bool(false)
233resource(%d) of type (stream)
234string(1) "t"
235int(4)
236bool(false)
237resource(%d) of type (stream)
238string(1) " "
239int(5)
240bool(false)
241resource(%d) of type (stream)
242string(1) "t"
243int(6)
244bool(false)
245resource(%d) of type (stream)
246-- Innerloop iteration 2 of Outerloop Iteration 2 --
247-- Testing fgetc() : file opened using rb mode --
248string(1) "t"
249int(1)
250bool(false)
251resource(%d) of type (stream)
252string(1) "e"
253int(2)
254bool(false)
255resource(%d) of type (stream)
256string(1) "x"
257int(3)
258bool(false)
259resource(%d) of type (stream)
260string(1) "t"
261int(4)
262bool(false)
263resource(%d) of type (stream)
264string(1) " "
265int(5)
266bool(false)
267resource(%d) of type (stream)
268string(1) "t"
269int(6)
270bool(false)
271resource(%d) of type (stream)
272-- Innerloop iteration 3 of Outerloop Iteration 2 --
273-- Testing fgetc() : file opened using rt mode --
274string(1) "t"
275int(1)
276bool(false)
277resource(%d) of type (stream)
278string(1) "e"
279int(2)
280bool(false)
281resource(%d) of type (stream)
282string(1) "x"
283int(3)
284bool(false)
285resource(%d) of type (stream)
286string(1) "t"
287int(4)
288bool(false)
289resource(%d) of type (stream)
290string(1) " "
291int(5)
292bool(false)
293resource(%d) of type (stream)
294string(1) "t"
295int(6)
296bool(false)
297resource(%d) of type (stream)
298-- Innerloop iteration 4 of Outerloop Iteration 2 --
299-- Testing fgetc() : file opened using r+ mode --
300string(1) "t"
301int(1)
302bool(false)
303resource(%d) of type (stream)
304string(1) "e"
305int(2)
306bool(false)
307resource(%d) of type (stream)
308string(1) "x"
309int(3)
310bool(false)
311resource(%d) of type (stream)
312string(1) "t"
313int(4)
314bool(false)
315resource(%d) of type (stream)
316string(1) " "
317int(5)
318bool(false)
319resource(%d) of type (stream)
320string(1) "t"
321int(6)
322bool(false)
323resource(%d) of type (stream)
324-- Innerloop iteration 5 of Outerloop Iteration 2 --
325-- Testing fgetc() : file opened using r+b mode --
326string(1) "t"
327int(1)
328bool(false)
329resource(%d) of type (stream)
330string(1) "e"
331int(2)
332bool(false)
333resource(%d) of type (stream)
334string(1) "x"
335int(3)
336bool(false)
337resource(%d) of type (stream)
338string(1) "t"
339int(4)
340bool(false)
341resource(%d) of type (stream)
342string(1) " "
343int(5)
344bool(false)
345resource(%d) of type (stream)
346string(1) "t"
347int(6)
348bool(false)
349resource(%d) of type (stream)
350-- Innerloop iteration 6 of Outerloop Iteration 2 --
351-- Testing fgetc() : file opened using r+t mode --
352string(1) "t"
353int(1)
354bool(false)
355resource(%d) of type (stream)
356string(1) "e"
357int(2)
358bool(false)
359resource(%d) of type (stream)
360string(1) "x"
361int(3)
362bool(false)
363resource(%d) of type (stream)
364string(1) "t"
365int(4)
366bool(false)
367resource(%d) of type (stream)
368string(1) " "
369int(5)
370bool(false)
371resource(%d) of type (stream)
372string(1) "t"
373int(6)
374bool(false)
375resource(%d) of type (stream)
376--- Outerloop iteration 3 ---
377-- Innerloop iteration 1 of Outerloop Iteration 3 --
378-- Testing fgetc() : file opened using r mode --
379string(1) "l"
380int(1)
381bool(false)
382resource(%d) of type (stream)
383string(1) "i"
384int(2)
385bool(false)
386resource(%d) of type (stream)
387string(1) "n"
388int(3)
389bool(false)
390resource(%d) of type (stream)
391string(1) "e"
392int(4)
393bool(false)
394resource(%d) of type (stream)
395string(1) "
396"
397int(5)
398bool(false)
399resource(%d) of type (stream)
400string(1) "l"
401int(6)
402bool(false)
403resource(%d) of type (stream)
404-- Innerloop iteration 2 of Outerloop Iteration 3 --
405-- Testing fgetc() : file opened using rb mode --
406string(1) "l"
407int(1)
408bool(false)
409resource(%d) of type (stream)
410string(1) "i"
411int(2)
412bool(false)
413resource(%d) of type (stream)
414string(1) "n"
415int(3)
416bool(false)
417resource(%d) of type (stream)
418string(1) "e"
419int(4)
420bool(false)
421resource(%d) of type (stream)
422string(1) "
423"
424int(5)
425bool(false)
426resource(%d) of type (stream)
427string(1) "l"
428int(6)
429bool(false)
430resource(%d) of type (stream)
431-- Innerloop iteration 3 of Outerloop Iteration 3 --
432-- Testing fgetc() : file opened using rt mode --
433string(1) "l"
434int(1)
435bool(false)
436resource(%d) of type (stream)
437string(1) "i"
438int(2)
439bool(false)
440resource(%d) of type (stream)
441string(1) "n"
442int(3)
443bool(false)
444resource(%d) of type (stream)
445string(1) "e"
446int(4)
447bool(false)
448resource(%d) of type (stream)
449string(1) "
450"
451int(5)
452bool(false)
453resource(%d) of type (stream)
454string(1) "l"
455int(6)
456bool(false)
457resource(%d) of type (stream)
458-- Innerloop iteration 4 of Outerloop Iteration 3 --
459-- Testing fgetc() : file opened using r+ mode --
460string(1) "l"
461int(1)
462bool(false)
463resource(%d) of type (stream)
464string(1) "i"
465int(2)
466bool(false)
467resource(%d) of type (stream)
468string(1) "n"
469int(3)
470bool(false)
471resource(%d) of type (stream)
472string(1) "e"
473int(4)
474bool(false)
475resource(%d) of type (stream)
476string(1) "
477"
478int(5)
479bool(false)
480resource(%d) of type (stream)
481string(1) "l"
482int(6)
483bool(false)
484resource(%d) of type (stream)
485-- Innerloop iteration 5 of Outerloop Iteration 3 --
486-- Testing fgetc() : file opened using r+b mode --
487string(1) "l"
488int(1)
489bool(false)
490resource(%d) of type (stream)
491string(1) "i"
492int(2)
493bool(false)
494resource(%d) of type (stream)
495string(1) "n"
496int(3)
497bool(false)
498resource(%d) of type (stream)
499string(1) "e"
500int(4)
501bool(false)
502resource(%d) of type (stream)
503string(1) "
504"
505int(5)
506bool(false)
507resource(%d) of type (stream)
508string(1) "l"
509int(6)
510bool(false)
511resource(%d) of type (stream)
512-- Innerloop iteration 6 of Outerloop Iteration 3 --
513-- Testing fgetc() : file opened using r+t mode --
514string(1) "l"
515int(1)
516bool(false)
517resource(%d) of type (stream)
518string(1) "i"
519int(2)
520bool(false)
521resource(%d) of type (stream)
522string(1) "n"
523int(3)
524bool(false)
525resource(%d) of type (stream)
526string(1) "e"
527int(4)
528bool(false)
529resource(%d) of type (stream)
530string(1) "
531"
532int(5)
533bool(false)
534resource(%d) of type (stream)
535string(1) "l"
536int(6)
537bool(false)
538resource(%d) of type (stream)
539Done
540