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