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