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