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