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