Annotation of embedaddon/php/ext/standard/tests/file/fseek_ftell_rewind_variation3.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fseek(), ftell() & rewind() functions : usage variations - all r and a modes, SEEK_SET
3: --FILE--
4: <?php
5: /* Prototype: int fseek ( resource $handle, int $offset [, int $whence] );
6: Description: Seeks on a file pointer
7:
8: Prototype: bool rewind ( resource $handle );
9: Description: Rewind the position of a file pointer
10:
11: Prototype: int ftell ( resource $handle );
12: Description: Tells file pointer read/write position
13: */
14:
15: // include the file.inc for common functions for test
16: include ("file.inc");
17:
18: /* Testing fseek(),ftell(),rewind() functions
19: 1. All read and append modes
20: 2. Testing fseek() with whence = SEEK_SET
21: */
22:
23: echo "*** Testing fseek(), ftell(), rewind() : whence = SEEK_SET & all r and a modes ***\n";
24:
25: $file_modes = array( "r","rb","rt","r+","r+b","r+t",
26: "a","ab","at","a+","a+b","a+t");
27: $file_content_types = array( "text_with_new_line","alphanumeric");
28:
29: $offset = array(-1, 0, 1, 512, 600); // different offsets
30:
31: $filename = dirname(__FILE__)."/fseek_ftell_rewind_variation3.tmp"; // this is name of the file created by create_files()
32:
33: /* open the file using $files_modes and perform fseek(),ftell() and rewind() on it */
34: echo "*** Testing fseek() with whence = SEEK_SET ***\n";
35: foreach($file_content_types as $file_content_type){
36: echo "\n-- File having data of type ". $file_content_type ." --\n";
37:
38: foreach($file_modes as $file_mode) {
39: echo "-- File opened in mode ".$file_mode." --\n";
40: create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 512, "w", "fseek_ftell_rewind_variation",
41: 3, "bytes", ".tmp"); //create a file with 512 bytes size
42: $file_handle = fopen($filename, $file_mode);
43: if (!$file_handle) {
44: echo "Error: failed to fopen() file: $filename!";
45: exit();
46: }
47: foreach($offset as $count){
48: var_dump( fseek($file_handle,$count,SEEK_SET) );
49: var_dump( ftell($file_handle) ); // confirm the file pointer position
50: var_dump( feof($file_handle) ); //ensure that file pointer is not at end
51: } //end of offset loop
52:
53: //close the file and check the size
54: fclose($file_handle);
55: var_dump( filesize($filename) );
56:
57: delete_file($filename); // delete file with name
58: } //end of file_mode loop
59: } //end of file_content_types loop
60:
61: echo "Done\n";
62: ?>
63: --EXPECTF--
64: *** Testing fseek(), ftell(), rewind() : whence = SEEK_SET & all r and a modes ***
65: *** Testing fseek() with whence = SEEK_SET ***
66:
67: -- File having data of type text_with_new_line --
68: -- File opened in mode r --
69: int(-1)
70: int(0)
71: bool(false)
72: int(0)
73: int(0)
74: bool(false)
75: int(0)
76: int(1)
77: bool(false)
78: int(0)
79: int(512)
80: bool(false)
81: int(0)
82: int(600)
83: bool(false)
84: int(512)
85: -- File opened in mode rb --
86: int(-1)
87: int(0)
88: bool(false)
89: int(0)
90: int(0)
91: bool(false)
92: int(0)
93: int(1)
94: bool(false)
95: int(0)
96: int(512)
97: bool(false)
98: int(0)
99: int(600)
100: bool(false)
101: int(512)
102: -- File opened in mode rt --
103: int(-1)
104: int(0)
105: bool(false)
106: int(0)
107: int(0)
108: bool(false)
109: int(0)
110: int(1)
111: bool(false)
112: int(0)
113: int(512)
114: bool(false)
115: int(0)
116: int(600)
117: bool(false)
118: int(512)
119: -- File opened in mode r+ --
120: int(-1)
121: int(0)
122: bool(false)
123: int(0)
124: int(0)
125: bool(false)
126: int(0)
127: int(1)
128: bool(false)
129: int(0)
130: int(512)
131: bool(false)
132: int(0)
133: int(600)
134: bool(false)
135: int(512)
136: -- File opened in mode r+b --
137: int(-1)
138: int(0)
139: bool(false)
140: int(0)
141: int(0)
142: bool(false)
143: int(0)
144: int(1)
145: bool(false)
146: int(0)
147: int(512)
148: bool(false)
149: int(0)
150: int(600)
151: bool(false)
152: int(512)
153: -- File opened in mode r+t --
154: int(-1)
155: int(0)
156: bool(false)
157: int(0)
158: int(0)
159: bool(false)
160: int(0)
161: int(1)
162: bool(false)
163: int(0)
164: int(512)
165: bool(false)
166: int(0)
167: int(600)
168: bool(false)
169: int(512)
170: -- File opened in mode a --
171: int(-1)
172: int(0)
173: bool(false)
174: int(0)
175: int(0)
176: bool(false)
177: int(0)
178: int(1)
179: bool(false)
180: int(0)
181: int(512)
182: bool(false)
183: int(0)
184: int(600)
185: bool(false)
186: int(512)
187: -- File opened in mode ab --
188: int(-1)
189: int(0)
190: bool(false)
191: int(0)
192: int(0)
193: bool(false)
194: int(0)
195: int(1)
196: bool(false)
197: int(0)
198: int(512)
199: bool(false)
200: int(0)
201: int(600)
202: bool(false)
203: int(512)
204: -- File opened in mode at --
205: int(-1)
206: int(0)
207: bool(false)
208: int(0)
209: int(0)
210: bool(false)
211: int(0)
212: int(1)
213: bool(false)
214: int(0)
215: int(512)
216: bool(false)
217: int(0)
218: int(600)
219: bool(false)
220: int(512)
221: -- File opened in mode a+ --
222: int(-1)
223: int(0)
224: bool(false)
225: int(0)
226: int(0)
227: bool(false)
228: int(0)
229: int(1)
230: bool(false)
231: int(0)
232: int(512)
233: bool(false)
234: int(0)
235: int(600)
236: bool(false)
237: int(512)
238: -- File opened in mode a+b --
239: int(-1)
240: int(0)
241: bool(false)
242: int(0)
243: int(0)
244: bool(false)
245: int(0)
246: int(1)
247: bool(false)
248: int(0)
249: int(512)
250: bool(false)
251: int(0)
252: int(600)
253: bool(false)
254: int(512)
255: -- File opened in mode a+t --
256: int(-1)
257: int(0)
258: bool(false)
259: int(0)
260: int(0)
261: bool(false)
262: int(0)
263: int(1)
264: bool(false)
265: int(0)
266: int(512)
267: bool(false)
268: int(0)
269: int(600)
270: bool(false)
271: int(512)
272:
273: -- File having data of type alphanumeric --
274: -- File opened in mode r --
275: int(-1)
276: int(0)
277: bool(false)
278: int(0)
279: int(0)
280: bool(false)
281: int(0)
282: int(1)
283: bool(false)
284: int(0)
285: int(512)
286: bool(false)
287: int(0)
288: int(600)
289: bool(false)
290: int(512)
291: -- File opened in mode rb --
292: int(-1)
293: int(0)
294: bool(false)
295: int(0)
296: int(0)
297: bool(false)
298: int(0)
299: int(1)
300: bool(false)
301: int(0)
302: int(512)
303: bool(false)
304: int(0)
305: int(600)
306: bool(false)
307: int(512)
308: -- File opened in mode rt --
309: int(-1)
310: int(0)
311: bool(false)
312: int(0)
313: int(0)
314: bool(false)
315: int(0)
316: int(1)
317: bool(false)
318: int(0)
319: int(512)
320: bool(false)
321: int(0)
322: int(600)
323: bool(false)
324: int(512)
325: -- File opened in mode r+ --
326: int(-1)
327: int(0)
328: bool(false)
329: int(0)
330: int(0)
331: bool(false)
332: int(0)
333: int(1)
334: bool(false)
335: int(0)
336: int(512)
337: bool(false)
338: int(0)
339: int(600)
340: bool(false)
341: int(512)
342: -- File opened in mode r+b --
343: int(-1)
344: int(0)
345: bool(false)
346: int(0)
347: int(0)
348: bool(false)
349: int(0)
350: int(1)
351: bool(false)
352: int(0)
353: int(512)
354: bool(false)
355: int(0)
356: int(600)
357: bool(false)
358: int(512)
359: -- File opened in mode r+t --
360: int(-1)
361: int(0)
362: bool(false)
363: int(0)
364: int(0)
365: bool(false)
366: int(0)
367: int(1)
368: bool(false)
369: int(0)
370: int(512)
371: bool(false)
372: int(0)
373: int(600)
374: bool(false)
375: int(512)
376: -- File opened in mode a --
377: int(-1)
378: int(0)
379: bool(false)
380: int(0)
381: int(0)
382: bool(false)
383: int(0)
384: int(1)
385: bool(false)
386: int(0)
387: int(512)
388: bool(false)
389: int(0)
390: int(600)
391: bool(false)
392: int(512)
393: -- File opened in mode ab --
394: int(-1)
395: int(0)
396: bool(false)
397: int(0)
398: int(0)
399: bool(false)
400: int(0)
401: int(1)
402: bool(false)
403: int(0)
404: int(512)
405: bool(false)
406: int(0)
407: int(600)
408: bool(false)
409: int(512)
410: -- File opened in mode at --
411: int(-1)
412: int(0)
413: bool(false)
414: int(0)
415: int(0)
416: bool(false)
417: int(0)
418: int(1)
419: bool(false)
420: int(0)
421: int(512)
422: bool(false)
423: int(0)
424: int(600)
425: bool(false)
426: int(512)
427: -- File opened in mode a+ --
428: int(-1)
429: int(0)
430: bool(false)
431: int(0)
432: int(0)
433: bool(false)
434: int(0)
435: int(1)
436: bool(false)
437: int(0)
438: int(512)
439: bool(false)
440: int(0)
441: int(600)
442: bool(false)
443: int(512)
444: -- File opened in mode a+b --
445: int(-1)
446: int(0)
447: bool(false)
448: int(0)
449: int(0)
450: bool(false)
451: int(0)
452: int(1)
453: bool(false)
454: int(0)
455: int(512)
456: bool(false)
457: int(0)
458: int(600)
459: bool(false)
460: int(512)
461: -- File opened in mode a+t --
462: int(-1)
463: int(0)
464: bool(false)
465: int(0)
466: int(0)
467: bool(false)
468: int(0)
469: int(1)
470: bool(false)
471: int(0)
472: int(512)
473: bool(false)
474: int(0)
475: int(600)
476: bool(false)
477: int(512)
478: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>