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