Annotation of embedaddon/php/ext/standard/tests/file/fseek_ftell_rewind_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fseek(), ftell() & rewind() functions : usage variations - all r & a modes, default whence
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() without using argument whence
21: */
22: echo "*** Testing fseek(), ftell(), rewind() : default whence & all r and a modes ***\n";
23: $file_modes = array( "r","rb","rt","r+","r+b","r+t",
24: "a","ab","at","a+","a+b","a+t");
25: $file_content_types = array( "text_with_new_line","alphanumeric");
26:
27: $offset = array(-1, 0, 1, 513); // different offsets, including negative and beyond size
28:
29: $filename = dirname(__FILE__)."/fseek_ftell_rewind_variation1.tmp"; // this is name of the file created by create_files()
30:
31: /* open the file using $files_modes and perform fseek(),ftell() and rewind() on it */
32: foreach($file_content_types as $file_content_type){
33: echo "\n-- File having data of type ". $file_content_type ." --\n";
34:
35: foreach($file_modes as $file_mode) {
36: echo "-- File opened in mode ".$file_mode." --\n";
37:
38: create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 512, "w", "fseek_ftell_rewind_variation"
39: ,1,"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: echo "-- Testing fseek() without using argument whence --\n";
46: foreach($offset as $count){
47: var_dump( fseek($file_handle, $count) );
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() : default whence & all r and a modes ***
64:
65: -- File having data of type text_with_new_line --
66: -- File opened in mode r --
67: -- Testing fseek() without using argument whence --
68: int(-1)
69: int(0)
70: bool(false)
71: int(0)
72: int(0)
73: bool(false)
74: int(0)
75: int(1)
76: bool(false)
77: int(0)
78: int(513)
79: bool(false)
80: int(512)
81: -- File opened in mode rb --
82: -- Testing fseek() without using argument whence --
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(512)
96: -- File opened in mode rt --
97: -- Testing fseek() without using argument whence --
98: int(-1)
99: int(0)
100: bool(false)
101: int(0)
102: int(0)
103: bool(false)
104: int(0)
105: int(1)
106: bool(false)
107: int(0)
108: int(513)
109: bool(false)
110: int(512)
111: -- File opened in mode r+ --
112: -- Testing fseek() without using argument whence --
113: int(-1)
114: int(0)
115: bool(false)
116: int(0)
117: int(0)
118: bool(false)
119: int(0)
120: int(1)
121: bool(false)
122: int(0)
123: int(513)
124: bool(false)
125: int(512)
126: -- File opened in mode r+b --
127: -- Testing fseek() without using argument whence --
128: int(-1)
129: int(0)
130: bool(false)
131: int(0)
132: int(0)
133: bool(false)
134: int(0)
135: int(1)
136: bool(false)
137: int(0)
138: int(513)
139: bool(false)
140: int(512)
141: -- File opened in mode r+t --
142: -- Testing fseek() without using argument whence --
143: int(-1)
144: int(0)
145: bool(false)
146: int(0)
147: int(0)
148: bool(false)
149: int(0)
150: int(1)
151: bool(false)
152: int(0)
153: int(513)
154: bool(false)
155: int(512)
156: -- File opened in mode a --
157: -- Testing fseek() without using argument whence --
158: int(-1)
159: int(0)
160: bool(false)
161: int(0)
162: int(0)
163: bool(false)
164: int(0)
165: int(1)
166: bool(false)
167: int(0)
168: int(513)
169: bool(false)
170: int(512)
171: -- File opened in mode ab --
172: -- Testing fseek() without using argument whence --
173: int(-1)
174: int(0)
175: bool(false)
176: int(0)
177: int(0)
178: bool(false)
179: int(0)
180: int(1)
181: bool(false)
182: int(0)
183: int(513)
184: bool(false)
185: int(512)
186: -- File opened in mode at --
187: -- Testing fseek() without using argument whence --
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(513)
199: bool(false)
200: int(512)
201: -- File opened in mode a+ --
202: -- Testing fseek() without using argument whence --
203: int(-1)
204: int(0)
205: bool(false)
206: int(0)
207: int(0)
208: bool(false)
209: int(0)
210: int(1)
211: bool(false)
212: int(0)
213: int(513)
214: bool(false)
215: int(512)
216: -- File opened in mode a+b --
217: -- Testing fseek() without using argument whence --
218: int(-1)
219: int(0)
220: bool(false)
221: int(0)
222: int(0)
223: bool(false)
224: int(0)
225: int(1)
226: bool(false)
227: int(0)
228: int(513)
229: bool(false)
230: int(512)
231: -- File opened in mode a+t --
232: -- Testing fseek() without using argument whence --
233: int(-1)
234: int(0)
235: bool(false)
236: int(0)
237: int(0)
238: bool(false)
239: int(0)
240: int(1)
241: bool(false)
242: int(0)
243: int(513)
244: bool(false)
245: int(512)
246:
247: -- File having data of type alphanumeric --
248: -- File opened in mode r --
249: -- Testing fseek() without using argument whence --
250: int(-1)
251: int(0)
252: bool(false)
253: int(0)
254: int(0)
255: bool(false)
256: int(0)
257: int(1)
258: bool(false)
259: int(0)
260: int(513)
261: bool(false)
262: int(512)
263: -- File opened in mode rb --
264: -- Testing fseek() without using argument whence --
265: int(-1)
266: int(0)
267: bool(false)
268: int(0)
269: int(0)
270: bool(false)
271: int(0)
272: int(1)
273: bool(false)
274: int(0)
275: int(513)
276: bool(false)
277: int(512)
278: -- File opened in mode rt --
279: -- Testing fseek() without using argument whence --
280: int(-1)
281: int(0)
282: bool(false)
283: int(0)
284: int(0)
285: bool(false)
286: int(0)
287: int(1)
288: bool(false)
289: int(0)
290: int(513)
291: bool(false)
292: int(512)
293: -- File opened in mode r+ --
294: -- Testing fseek() without using argument whence --
295: int(-1)
296: int(0)
297: bool(false)
298: int(0)
299: int(0)
300: bool(false)
301: int(0)
302: int(1)
303: bool(false)
304: int(0)
305: int(513)
306: bool(false)
307: int(512)
308: -- File opened in mode r+b --
309: -- Testing fseek() without using argument whence --
310: int(-1)
311: int(0)
312: bool(false)
313: int(0)
314: int(0)
315: bool(false)
316: int(0)
317: int(1)
318: bool(false)
319: int(0)
320: int(513)
321: bool(false)
322: int(512)
323: -- File opened in mode r+t --
324: -- Testing fseek() without using argument whence --
325: int(-1)
326: int(0)
327: bool(false)
328: int(0)
329: int(0)
330: bool(false)
331: int(0)
332: int(1)
333: bool(false)
334: int(0)
335: int(513)
336: bool(false)
337: int(512)
338: -- File opened in mode a --
339: -- Testing fseek() without using argument whence --
340: int(-1)
341: int(0)
342: bool(false)
343: int(0)
344: int(0)
345: bool(false)
346: int(0)
347: int(1)
348: bool(false)
349: int(0)
350: int(513)
351: bool(false)
352: int(512)
353: -- File opened in mode ab --
354: -- Testing fseek() without using argument whence --
355: int(-1)
356: int(0)
357: bool(false)
358: int(0)
359: int(0)
360: bool(false)
361: int(0)
362: int(1)
363: bool(false)
364: int(0)
365: int(513)
366: bool(false)
367: int(512)
368: -- File opened in mode at --
369: -- Testing fseek() without using argument whence --
370: int(-1)
371: int(0)
372: bool(false)
373: int(0)
374: int(0)
375: bool(false)
376: int(0)
377: int(1)
378: bool(false)
379: int(0)
380: int(513)
381: bool(false)
382: int(512)
383: -- File opened in mode a+ --
384: -- Testing fseek() without using argument whence --
385: int(-1)
386: int(0)
387: bool(false)
388: int(0)
389: int(0)
390: bool(false)
391: int(0)
392: int(1)
393: bool(false)
394: int(0)
395: int(513)
396: bool(false)
397: int(512)
398: -- File opened in mode a+b --
399: -- Testing fseek() without using argument whence --
400: int(-1)
401: int(0)
402: bool(false)
403: int(0)
404: int(0)
405: bool(false)
406: int(0)
407: int(1)
408: bool(false)
409: int(0)
410: int(513)
411: bool(false)
412: int(512)
413: -- File opened in mode a+t --
414: -- Testing fseek() without using argument whence --
415: int(-1)
416: int(0)
417: bool(false)
418: int(0)
419: int(0)
420: bool(false)
421: int(0)
422: int(1)
423: bool(false)
424: int(0)
425: int(513)
426: bool(false)
427: int(512)
428: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>